Home | History | Annotate | Download | only in browse
      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 
     20     public StarView(Context context) {
     21         super(context);
     22     }
     23 
     24     public StarView(Context context, AttributeSet attrs) {
     25         super(context, attrs);
     26     }
     27 
     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      */
     35     public void setStarred(boolean isStarred) {
     36         mIsStarred = isStarred;
     37         setContentDescription(
     38                 getResources().getString(mIsStarred ? R.string.remove_star : R.string.add_star));
     39         refreshDrawableState();
     40     }
     41 
     42     @Override
     43     public int[] onCreateDrawableState(int extraSpace) {
     44         final int[] drawableState = super.onCreateDrawableState(extraSpace + 1);
     45         if (mIsStarred) {
     46             mergeDrawableStates(drawableState, STATE_STARRED);
     47         }
     48         return drawableState;
     49     }
     50 }
     51