1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/mobile/android/base/widget/TabRow.java Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,59 @@ 1.4 +/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*- 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this file, 1.7 + * You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +package org.mozilla.gecko.widget; 1.10 + 1.11 +import android.content.Context; 1.12 +import android.util.AttributeSet; 1.13 +import android.view.View; 1.14 +import android.widget.Checkable; 1.15 +import android.widget.LinearLayout; 1.16 + 1.17 +public class TabRow extends LinearLayout 1.18 + implements Checkable { 1.19 + private static final String LOGTAG = "GeckoTabRow"; 1.20 + private static final int[] STATE_CHECKED = { android.R.attr.state_checked }; 1.21 + private boolean mChecked; 1.22 + 1.23 + public TabRow(Context context, AttributeSet attrs) { 1.24 + super(context, attrs); 1.25 + mChecked = false; 1.26 + } 1.27 + 1.28 + @Override 1.29 + public int[] onCreateDrawableState(int extraSpace) { 1.30 + final int[] drawableState = super.onCreateDrawableState(extraSpace + 1); 1.31 + 1.32 + if (mChecked) 1.33 + mergeDrawableStates(drawableState, STATE_CHECKED); 1.34 + 1.35 + return drawableState; 1.36 + } 1.37 + 1.38 + @Override 1.39 + public boolean isChecked() { 1.40 + return mChecked; 1.41 + } 1.42 + 1.43 + @Override 1.44 + public void setChecked(boolean checked) { 1.45 + if (mChecked != checked) { 1.46 + mChecked = checked; 1.47 + refreshDrawableState(); 1.48 + 1.49 + int count = getChildCount(); 1.50 + for (int i=0; i < count; i++) { 1.51 + final View child = getChildAt(i); 1.52 + if (child instanceof Checkable) 1.53 + ((Checkable) child).setChecked(checked); 1.54 + } 1.55 + } 1.56 + } 1.57 + 1.58 + @Override 1.59 + public void toggle() { 1.60 + mChecked = !mChecked; 1.61 + } 1.62 +}