1package com.android.mail.browse; 2 3import android.content.Context; 4import android.util.AttributeSet; 5import android.widget.ImageView; 6 7import 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 */ 14public 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 refreshDrawableState(); 38 } 39 40 @Override 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