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