Bug 1400858 - Introduce class CheckableFadedSingleColorTextView for supporting 'Checkable' status. r?nechen
MozReview-Commit-ID: ILGByeZdyV8
--- a/mobile/android/app/src/photon/res/layout/tab_strip_item_view.xml
+++ b/mobile/android/app/src/photon/res/layout/tab_strip_item_view.xml
@@ -16,17 +16,17 @@
style="@style/TabStrip.Favicon"
android:layout_width="@dimen/browser_toolbar_favicon_size"
android:layout_height="@dimen/browser_toolbar_favicon_size"
android:layout_gravity="center"
android:duplicateParentState="true"
android:scaleType="centerInside"
tools:src="@drawable/toolbar_favicon_default"/>
- <org.mozilla.gecko.widget.FadedSingleColorTextView
+ <org.mozilla.gecko.widget.CheckableFadedSingleColorTextView
android:id="@+id/title"
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight="1.0"
android:duplicateParentState="true"
android:ellipsize="end"
android:gravity="center_vertical"
android:maxLines="1"
new file mode 100644
--- /dev/null
+++ b/mobile/android/base/java/org/mozilla/gecko/widget/CheckableFadedSingleColorTextView.java
@@ -0,0 +1,58 @@
+/* -*- 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.widget.Checkable;
+
+public class CheckableFadedSingleColorTextView extends FadedSingleColorTextView implements Checkable {
+
+ private static final int[] STATE_CHECKED = {
+ android.R.attr.state_checked
+ };
+
+ private boolean checked;
+
+ public CheckableFadedSingleColorTextView(Context context) {
+ this(context, null);
+ }
+
+ public CheckableFadedSingleColorTextView(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ }
+
+ @Override
+ public int[] onCreateDrawableState(int extraSpace) {
+ final int[] drawableState = super.onCreateDrawableState(extraSpace + 1);
+
+ if (checked) {
+ mergeDrawableStates(drawableState, STATE_CHECKED);
+ }
+
+ return drawableState;
+ }
+
+ @Override
+ public boolean isChecked() {
+ return checked;
+ }
+
+ @Override
+ public void setChecked(boolean checked) {
+ if (this.checked == checked) {
+ return;
+ }
+
+ this.checked = checked;
+ refreshDrawableState();
+ }
+
+ @Override
+ public void toggle() {
+ setChecked(!checked);
+ }
+}
--- a/mobile/android/base/moz.build
+++ b/mobile/android/base/moz.build
@@ -952,16 +952,17 @@ gbjar.sources += ['java/org/mozilla/geck
'webapps/WebApps.java',
'widget/ActionModePresenter.java',
'widget/ActivityChooserModel.java',
'widget/AllCapsTextView.java',
'widget/AnchoredPopup.java',
'widget/AnimatedHeightLayout.java',
'widget/AnimatedProgressBar.java',
'widget/BasicColorPicker.java',
+ 'widget/CheckableFadedSingleColorTextView.java',
'widget/CheckableLinearLayout.java',
'widget/ClickableWhenDisabledEditText.java',
'widget/ContentSecurityDoorHanger.java',
'widget/CropImageView.java',
'widget/DateTimePicker.java',
'widget/DefaultDoorHanger.java',
'widget/DefaultItemAnimatorBase.java',
'widget/DoorHanger.java',