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

Commit ab9f1bab authored by Alan Viverette's avatar Alan Viverette Committed by Android (Google) Code Review
Browse files

Merge "Add callback to track and thumb drawables, propagate state in ASLD" into lmp-dev

parents 820eab3e b067405b
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;
        }