Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d171090c authored by Alan Viverette's avatar Alan Viverette Committed by The Android Automerger
Browse files

Add callback to track and thumb drawables, propagate state in ASLD

BUG: 17665424
Change-Id: I22da4530f3e2869d856102e804f020461a46fe49
parent 8f71b9df
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
@@ -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();
    }

+7 −2
Original line number Diff line number Diff line
@@ -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;
        }