Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(186)

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/appmenu/AppMenuItemIcon.java

Issue 2951133003: Clean up tinted ImageView subclasses (Closed)
Patch Set: Comments Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.chrome.browser.appmenu; 5 package org.chromium.chrome.browser.appmenu;
6 6
7 import android.content.Context; 7 import android.content.Context;
8 import android.util.AttributeSet; 8 import android.util.AttributeSet;
9 import android.widget.ImageView; 9 import android.widget.Checkable;
10
11 import org.chromium.chrome.browser.widget.TintedImageView;
10 12
11 /** 13 /**
12 * A menu icon that supports the checkable state. 14 * A TintedImageView that supports the checkable state.
13 */ 15 */
14 public class AppMenuItemIcon extends ImageView { 16 public class AppMenuItemIcon extends TintedImageView implements Checkable {
15 private static final int[] CHECKED_STATE_SET = new int[] {android.R.attr.sta te_checked}; 17 private static final int[] CHECKED_STATE_SET = new int[] {android.R.attr.sta te_checked};
16 private boolean mCheckedState; 18 private boolean mCheckedState;
17 19
18 public AppMenuItemIcon(Context context, AttributeSet attrs) { 20 public AppMenuItemIcon(Context context, AttributeSet attrs) {
19 super(context, attrs); 21 super(context, attrs);
20 } 22 }
21 23
22 /** 24 @Override
23 * Sets whether the item is checked and refreshes the View if necessary. 25 public void setChecked(boolean state) {
24 */
25 protected void setChecked(boolean state) {
26 if (state == mCheckedState) return; 26 if (state == mCheckedState) return;
27 mCheckedState = state; 27 mCheckedState = state;
28 refreshDrawableState(); 28 refreshDrawableState();
29 } 29 }
30 30
31 @Override 31 @Override
32 public void setPressed(boolean state) {
33 // We don't want to highlight the checkbox icon since the parent item is already
34 // highlighted.
35 return;
36 }
37
38 @Override
39 public int[] onCreateDrawableState(int extraSpace) { 32 public int[] onCreateDrawableState(int extraSpace) {
40 final int[] drawableState = super.onCreateDrawableState(extraSpace + 1); 33 final int[] drawableState = super.onCreateDrawableState(extraSpace + 1);
41 if (mCheckedState) { 34 if (mCheckedState) {
42 mergeDrawableStates(drawableState, CHECKED_STATE_SET); 35 mergeDrawableStates(drawableState, CHECKED_STATE_SET);
43 } 36 }
44 return drawableState; 37 return drawableState;
45 } 38 }
39
40 @Override
41 public boolean isChecked() {
42 return mCheckedState;
43 }
44
45 @Override
46 public void toggle() {
47 setChecked(!mCheckedState);
48 }
46 } 49 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698