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

Commit b7244809 authored by Chris Craik's avatar Chris Craik
Browse files

Check api level before throwing in drawable setters

bug:25801789

TextureView started throwing in these in N.

Change-Id: I538d1c57deb0a5a6a25c297833af06d3f237600c
parent 33e9b426
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -297,7 +297,7 @@ public class TextureView extends View {

    @Override
    public void setForeground(Drawable foreground) {
        if (foreground != null) {
        if (foreground != null && !sTextureViewIgnoresDrawableSetters) {
            throw new UnsupportedOperationException(
                    "TextureView doesn't support displaying a foreground drawable");
        }
@@ -305,7 +305,7 @@ public class TextureView extends View {

    @Override
    public void setBackgroundDrawable(Drawable background) {
        if (background != null) {
        if (background != null && !sTextureViewIgnoresDrawableSetters) {
            throw new UnsupportedOperationException(
                    "TextureView doesn't support displaying a background drawable");
        }
+10 −0
Original line number Diff line number Diff line
@@ -811,6 +811,12 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
     */
    private static boolean sLayoutParamsAlwaysChanged = false;
    /**
     * Allow setForeground/setBackground to be called (and ignored) on a textureview,
     * without throwing
     */
    static boolean sTextureViewIgnoresDrawableSetters = false;
    /**
     * This view does not want keystrokes. Use with TAKES_FOCUS_MASK when
     * calling setFlags.
@@ -3984,6 +3990,10 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
            // work. Partial layout breaks this assumption.
            sLayoutParamsAlwaysChanged = targetSdkVersion <= M;
            // Prior to N, TextureView would silently ignore calls to setBackground/setForeground.
            // On N+, we throw, but that breaks compatibility with apps that use these methods.
            sTextureViewIgnoresDrawableSetters = targetSdkVersion <= M;
            sCompatibilityDone = true;
        }
    }