blob: 8e9f58c617620c86306f0ecada0797f22257aee2 [file] [log] [blame]
Winson Chung97d85d22011-04-13 11:27:36 -07001/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.launcher2;
18
19import android.content.Context;
20import android.util.AttributeSet;
21import android.view.View;
22import android.widget.TabWidget;
23
24public class FocusOnlyTabWidget extends TabWidget {
25 public FocusOnlyTabWidget(Context context) {
26 super(context);
27 }
28
29 public FocusOnlyTabWidget(Context context, AttributeSet attrs) {
30 super(context, attrs);
31 }
32
33 public FocusOnlyTabWidget(Context context, AttributeSet attrs, int defStyle) {
34 super(context, attrs, defStyle);
35 }
36
37 public View getSelectedTab() {
38 final int count = getTabCount();
39 for (int i = 0; i < count; ++i) {
40 View v = getChildTabViewAt(i);
41 if (v.isSelected()) {
42 return v;
43 }
44 }
45 return null;
46 }
47
48 public int getChildTabIndex(View v) {
49 final int tabCount = getTabCount();
50 for (int i = 0; i < tabCount; ++i) {
51 if (getChildTabViewAt(i) == v) {
52 return i;
53 }
54 }
55 return -1;
56 }
57
58 public void setCurrentTabToFocusedTab() {
59 View tab = null;
60 int index = -1;
61 final int count = getTabCount();
62 for (int i = 0; i < count; ++i) {
63 View v = getChildTabViewAt(i);
64 if (v.hasFocus()) {
65 tab = v;
66 index = i;
67 break;
68 }
69 }
70 if (index > -1) {
71 super.setCurrentTab(index);
72 super.onFocusChange(tab, true);
73 }
74 }
75 public void superOnFocusChange(View v, boolean hasFocus) {
76 super.onFocusChange(v, hasFocus);
77 }
78
79 @Override
80 public void onFocusChange(android.view.View v, boolean hasFocus) {
81 if (v == this && hasFocus && getTabCount() > 0) {
82 getSelectedTab().requestFocus();
83 return;
84 }
85 }
86}