Last active
December 16, 2015 02:58
-
-
Save rharter/5366076 to your computer and use it in GitHub Desktop.
The issue here is that the View.setBackgroundDrawable method has been deprecated but the replacement method, View.setBackground, just delegates to the deprecated method. How can I handle this in a safe manner?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* This won't work because it just relies on the deprecated method. | |
*/ | |
@Override | |
public void setDrawable(Drawable drawable) { | |
setBackgroundDrawable(drawable); | |
} | |
@Override | |
public void setBackgroundDrawable(Drawable drawable) { | |
if (drawable != null) { | |
drawable = new DrawableWrapper(drawable); | |
} | |
super.setBackgroundDrawable(drawable); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* This won't work because super.setDrawable() just delegates to | |
* setBackgroundDrawable(), which duplicates things. | |
*/ | |
@Override | |
public void setDrawable(Drawable drawable) { | |
if (drawable != null) { | |
drawable = new DrawableWrapper(drawable); | |
} | |
super.setDrawable(drawable); | |
} | |
@Override | |
public void setBackgroundDrawable(Drawable drawable) { | |
if (drawable != null) { | |
drawable = new DrawableWrapper(drawable); | |
} | |
super.setBackgroundDrawable(drawable); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Unless I'm mistaken, this should never happen. If you deprecate a method | |
* to replace it with another, shouldn't the actual functionality be moved | |
* to the new method and the deprecated method be made to delegate to the | |
* replacement method? | |
*/ | |
public void setBackground(Drawable background) { | |
//noinspection deprecation | |
setBackgroundDrawable(background); | |
} | |
/** | |
* @deprecated use {@link #setBackground(Drawable)} instead | |
*/ | |
@Deprecated | |
public void setBackgroundDrawable(Drawable background) { | |
... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment