am 143631f0: am d3957f25: am a6958574: am 63756956: Merge "Add callback to track and thumb drawables, propagate state in ASLD" into lmp-dev

* commit '143631f0d4a5f69b73ae9019e6a1ccbc895dc12e':
  Add callback to track and thumb drawables, propagate state in ASLD
This commit is contained in:
Alan Viverette
2014-09-26 23:42:07 +00:00
committed by Android Git Automerger
2 changed files with 25 additions and 2 deletions

View File

@@ -208,7 +208,13 @@ public class Switch extends CompoundButton {
final TypedArray a = context.obtainStyledAttributes(
attrs, com.android.internal.R.styleable.Switch, defStyleAttr, defStyleRes);
mThumbDrawable = a.getDrawable(com.android.internal.R.styleable.Switch_thumb);
if (mThumbDrawable != null) {
mThumbDrawable.setCallback(this);
}
mTrackDrawable = a.getDrawable(com.android.internal.R.styleable.Switch_track);
if (mTrackDrawable != null) {
mTrackDrawable.setCallback(this);
}
mTextOn = a.getText(com.android.internal.R.styleable.Switch_textOn);
mTextOff = a.getText(com.android.internal.R.styleable.Switch_textOff);
mShowText = a.getBoolean(com.android.internal.R.styleable.Switch_showText, true);
@@ -433,7 +439,13 @@ public class Switch extends CompoundButton {
* @attr ref android.R.styleable#Switch_track
*/
public void setTrackDrawable(Drawable track) {
if (mTrackDrawable != null) {
mTrackDrawable.setCallback(null);
}
mTrackDrawable = track;
if (track != null) {
track.setCallback(this);
}
requestLayout();
}
@@ -468,7 +480,13 @@ public class Switch extends CompoundButton {
* @attr ref android.R.styleable#Switch_thumb
*/
public void setThumbDrawable(Drawable thumb) {
if (mThumbDrawable != null) {
mThumbDrawable.setCallback(null);
}
mThumbDrawable = thumb;
if (thumb != null) {
thumb.setCallback(this);
}
requestLayout();
}

View File

@@ -91,7 +91,8 @@ public class AnimatedStateListDrawable extends StateListDrawable {
if (visible) {
mTransition.start();
} else {
mTransition.stop();
// Ensure we're showing the correct state when visible.
jumpToCurrentState();
}
}
@@ -140,7 +141,11 @@ public class AnimatedStateListDrawable extends StateListDrawable {
protected boolean onStateChange(int[] stateSet) {
final int keyframeIndex = mState.indexOfKeyframe(stateSet);
if (keyframeIndex == getCurrentIndex()) {
// No transition needed.
// Propagate state change to current keyframe.
final Drawable current = getCurrent();
if (current != null) {
return current.setState(stateSet);
}
return false;
}