mobile/android/base/widget/TabRow.java

branch
TOR_BUG_3246
changeset 4
fc2d59ddac77
equal deleted inserted replaced
-1:000000000000 0:9f6f5a82c60a
1 /* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
4 * You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6 package org.mozilla.gecko.widget;
7
8 import android.content.Context;
9 import android.util.AttributeSet;
10 import android.view.View;
11 import android.widget.Checkable;
12 import android.widget.LinearLayout;
13
14 public class TabRow extends LinearLayout
15 implements Checkable {
16 private static final String LOGTAG = "GeckoTabRow";
17 private static final int[] STATE_CHECKED = { android.R.attr.state_checked };
18 private boolean mChecked;
19
20 public TabRow(Context context, AttributeSet attrs) {
21 super(context, attrs);
22 mChecked = false;
23 }
24
25 @Override
26 public int[] onCreateDrawableState(int extraSpace) {
27 final int[] drawableState = super.onCreateDrawableState(extraSpace + 1);
28
29 if (mChecked)
30 mergeDrawableStates(drawableState, STATE_CHECKED);
31
32 return drawableState;
33 }
34
35 @Override
36 public boolean isChecked() {
37 return mChecked;
38 }
39
40 @Override
41 public void setChecked(boolean checked) {
42 if (mChecked != checked) {
43 mChecked = checked;
44 refreshDrawableState();
45
46 int count = getChildCount();
47 for (int i=0; i < count; i++) {
48 final View child = getChildAt(i);
49 if (child instanceof Checkable)
50 ((Checkable) child).setChecked(checked);
51 }
52 }
53 }
54
55 @Override
56 public void toggle() {
57 mChecked = !mChecked;
58 }
59 }

mercurial