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

Commit e724ee4b authored by Gilles Debunne's avatar Gilles Debunne
Browse files

Fix for NPE in Switch

Happens when the checked state is set in XML in the CompoundButton
constructor. The drawable are not yet loaded at that point.

This still work since the Switch constructor calls setChecked, which
will invalidate.

Change-Id: I76459307e77596ce0f2759e9449eb42287c6bad7
parent 38e1c7a8
Loading
Loading
Loading
Loading
+4 −2
Original line number Original line Diff line number Diff line
@@ -161,6 +161,7 @@ public class Switch extends CompoundButton {
        mMinFlingVelocity = config.getScaledMinimumFlingVelocity();
        mMinFlingVelocity = config.getScaledMinimumFlingVelocity();


        // Refresh display with current params
        // Refresh display with current params
        refreshDrawableState();
        setChecked(isChecked());
        setChecked(isChecked());
    }
    }


@@ -632,8 +633,9 @@ public class Switch extends CompoundButton {
        int[] myDrawableState = getDrawableState();
        int[] myDrawableState = getDrawableState();


        // Set the state of the Drawable
        // Set the state of the Drawable
        mThumbDrawable.setState(myDrawableState);
        // Drawable may be null when checked state is set from XML, from super constructor
        mTrackDrawable.setState(myDrawableState);
        if (mThumbDrawable != null) mThumbDrawable.setState(myDrawableState);
        if (mTrackDrawable != null) mTrackDrawable.setState(myDrawableState);


        invalidate();
        invalidate();
    }
    }