1 package org.robolectric.android; 2 3 import android.content.Context; 4 import android.util.AttributeSet; 5 import android.widget.TextView; 6 import org.robolectric.R; 7 8 public class CustomStateView extends TextView { 9 10 private static final int[] STATE_FOO = {R.attr.stateFoo}; 11 12 public boolean isFoo; 13 CustomStateView(Context context)14 public CustomStateView(Context context) { 15 super(context); 16 } 17 CustomStateView(Context context, AttributeSet attrs)18 public CustomStateView(Context context, AttributeSet attrs) { 19 super(context, attrs); 20 } 21 CustomStateView(Context context, AttributeSet attrs, int defStyle)22 public CustomStateView(Context context, AttributeSet attrs, int defStyle) { 23 super(context, attrs, defStyle); 24 } 25 26 @Override onCreateDrawableState(int extraSpace)27 protected int[] onCreateDrawableState(int extraSpace) { 28 final int[] drawableState = super.onCreateDrawableState(extraSpace + 1); 29 if (isFoo) { 30 mergeDrawableStates(drawableState, STATE_FOO); 31 } 32 return drawableState; 33 } 34 } 35