mobile/android/base/widget/TabRow.java

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial