• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package com.android.mail.browse;
2 
3 import android.content.Context;
4 import android.util.AttributeSet;
5 import android.widget.ImageView;
6 
7 import com.android.mail.R;
8 
9 /**
10  * An image view that respects a custom drawable state (state_starred)
11  * that enables a src or background drawable to use to automatically
12  * switch between the starred and unstarred state.
13  */
14 public class StarView extends ImageView {
15 
16     private static final int[] STATE_STARRED = {R.attr.state_starred};
17 
18     private boolean mIsStarred;
19 
StarView(Context context)20     public StarView(Context context) {
21         super(context);
22     }
23 
StarView(Context context, AttributeSet attrs)24     public StarView(Context context, AttributeSet attrs) {
25         super(context, attrs);
26     }
27 
StarView(Context context, AttributeSet attrs, int defStyle)28     public StarView(Context context, AttributeSet attrs, int defStyle) {
29         super(context, attrs, defStyle);
30     }
31 
32     /**
33      * Set the starred state of the view.
34      */
setStarred(boolean isStarred)35     public void setStarred(boolean isStarred) {
36         mIsStarred = isStarred;
37         refreshDrawableState();
38     }
39 
40     @Override
onCreateDrawableState(int extraSpace)41     public int[] onCreateDrawableState(int extraSpace) {
42         final int[] drawableState = super.onCreateDrawableState(extraSpace + 1);
43         if (mIsStarred) {
44             mergeDrawableStates(drawableState, STATE_STARRED);
45         }
46         return drawableState;
47     }
48 }
49