Methods Summary |
---|
public void | addState(int[] stateSet, Drawable drawable)Add a new image/string ID to the set of images.
if (drawable != null) {
mStateListState.addStateSet(stateSet, drawable);
// in case the new state matches our current state...
onStateChange(getState());
}
|
public void | applyTheme(android.content.res.Resources.Theme theme)
super.applyTheme(theme);
onStateChange(getState());
|
public void | clearMutated()
super.clearMutated();
mMutated = false;
|
android.graphics.drawable.StateListDrawable$StateListState | cloneConstantState()
return new StateListState(mStateListState, this, null);
|
int[] | extractStateSet(android.util.AttributeSet attrs)Extracts state_ attributes from an attribute set.
int j = 0;
final int numAttrs = attrs.getAttributeCount();
int[] states = new int[numAttrs];
for (int i = 0; i < numAttrs; i++) {
final int stateResId = attrs.getAttributeNameResource(i);
switch (stateResId) {
case 0:
break;
case R.attr.drawable:
case R.attr.id:
// Ignore attributes from StateListDrawableItem and
// AnimatedStateListDrawableItem.
continue;
default:
states[j++] = attrs.getAttributeBooleanValue(i, false)
? stateResId : -stateResId;
}
}
states = StateSet.trimStateSet(states, j);
return states;
|
public int | getStateCount()Gets the number of states contained in this drawable.
return mStateListState.getChildCount();
|
public Drawable | getStateDrawable(int index)Gets the drawable at an index.
return mStateListState.getChild(index);
|
public int | getStateDrawableIndex(int[] stateSet)Gets the index of the drawable with the provided state set.
return mStateListState.indexOfStateSet(stateSet);
|
android.graphics.drawable.StateListDrawable$StateListState | getStateListState()
return mStateListState;
|
public int[] | getStateSet(int index)Gets the state set at an index.
return mStateListState.mStateSets[index];
|
public void | inflate(android.content.res.Resources r, org.xmlpull.v1.XmlPullParser parser, android.util.AttributeSet attrs, android.content.res.Resources.Theme theme)
final TypedArray a = obtainAttributes(r, theme, attrs, R.styleable.StateListDrawable);
super.inflateWithAttributes(r, parser, a, R.styleable.StateListDrawable_visible);
updateStateFromTypedArray(a);
a.recycle();
inflateChildElements(r, parser, attrs, theme);
onStateChange(getState());
|
private void | inflateChildElements(android.content.res.Resources r, org.xmlpull.v1.XmlPullParser parser, android.util.AttributeSet attrs, android.content.res.Resources.Theme theme)Inflates child elements from XML.
final StateListState state = mStateListState;
final int innerDepth = parser.getDepth() + 1;
int type;
int depth;
while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
&& ((depth = parser.getDepth()) >= innerDepth
|| type != XmlPullParser.END_TAG)) {
if (type != XmlPullParser.START_TAG) {
continue;
}
if (depth > innerDepth || !parser.getName().equals("item")) {
continue;
}
// This allows state list drawable item elements to be themed at
// inflation time but does NOT make them work for Zygote preload.
final TypedArray a = obtainAttributes(r, theme, attrs,
R.styleable.StateListDrawableItem);
Drawable dr = a.getDrawable(R.styleable.StateListDrawableItem_drawable);
a.recycle();
final int[] states = extractStateSet(attrs);
// Loading child elements modifies the state of the AttributeSet's
// underlying parser, so it needs to happen after obtaining
// attributes and extracting states.
if (dr == null) {
while ((type = parser.next()) == XmlPullParser.TEXT) {
}
if (type != XmlPullParser.START_TAG) {
throw new XmlPullParserException(
parser.getPositionDescription()
+ ": <item> tag requires a 'drawable' attribute or "
+ "child tag defining a drawable");
}
dr = Drawable.createFromXmlInner(r, parser, attrs, theme);
}
state.addStateSet(states, dr);
}
|
public boolean | isStateful()
return true;
|
public Drawable | mutate()
if (!mMutated && super.mutate() == this) {
mStateListState.mutate();
mMutated = true;
}
return this;
|
protected boolean | onStateChange(int[] stateSet)
int idx = mStateListState.indexOfStateSet(stateSet);
if (DEBUG) android.util.Log.i(TAG, "onStateChange " + this + " states "
+ Arrays.toString(stateSet) + " found " + idx);
if (idx < 0) {
idx = mStateListState.indexOfStateSet(StateSet.WILD_CARD);
}
if (selectDrawable(idx)) {
return true;
}
return super.onStateChange(stateSet);
|
protected void | setConstantState(DrawableContainerState state)
super.setConstantState(state);
if (state instanceof StateListState) {
mStateListState = (StateListState) state;
}
|
public void | setLayoutDirection(int layoutDirection)
super.setLayoutDirection(layoutDirection);
// Let the container handle setting its own layout direction. Otherwise,
// we're accessing potentially unused states.
mStateListState.setLayoutDirection(layoutDirection);
|
private void | updateStateFromTypedArray(android.content.res.TypedArray a)Updates the constant state from the values in the typed array.
final StateListState state = mStateListState;
// Account for any configuration changes.
state.mChangingConfigurations |= a.getChangingConfigurations();
// Extract the theme attributes, if any.
state.mThemeAttrs = a.extractThemeAttrs();
state.mVariablePadding = a.getBoolean(
R.styleable.StateListDrawable_variablePadding, state.mVariablePadding);
state.mConstantSize = a.getBoolean(
R.styleable.StateListDrawable_constantSize, state.mConstantSize);
state.mEnterFadeDuration = a.getInt(
R.styleable.StateListDrawable_enterFadeDuration, state.mEnterFadeDuration);
state.mExitFadeDuration = a.getInt(
R.styleable.StateListDrawable_exitFadeDuration, state.mExitFadeDuration);
state.mDither = a.getBoolean(
R.styleable.StateListDrawable_dither, state.mDither);
state.mAutoMirrored = a.getBoolean(
R.styleable.StateListDrawable_autoMirrored, state.mAutoMirrored);
|