use of android.graphics.drawable.DrawableContainer in project material-components-android by material-components.
the class TextInputLayout method ensureBackgroundDrawableStateWorkaround.
private void ensureBackgroundDrawableStateWorkaround() {
final int sdk = Build.VERSION.SDK_INT;
if (sdk != 21 && sdk != 22) {
// The workaround is only required on API 21-22
return;
}
final Drawable bg = mEditText.getBackground();
if (bg == null) {
return;
}
if (!mHasReconstructedEditTextBackground) {
// This is gross. There is an issue in the platform which affects container Drawables
// where the first drawable retrieved from resources will propagate any changes
// (like color filter) to all instances from the cache. We'll try to workaround it...
final Drawable newBg = bg.getConstantState().newDrawable();
if (bg instanceof DrawableContainer) {
// If we have a Drawable container, we can try and set it's constant state via
// reflection from the new Drawable
mHasReconstructedEditTextBackground = DrawableUtils.setContainerConstantState((DrawableContainer) bg, newBg.getConstantState());
}
if (!mHasReconstructedEditTextBackground) {
// If we reach here then we just need to set a brand new instance of the Drawable
// as the background. This has the unfortunate side-effect of wiping out any
// user set padding, but I'd hope that use of custom padding on an EditText
// is limited.
ViewCompat.setBackground(mEditText, newBg);
mHasReconstructedEditTextBackground = true;
}
}
}
use of android.graphics.drawable.DrawableContainer in project wire-android by wireapp.
the class AddPhoneNumberPreferenceDialogFragment method ensureBackgroundDrawableStateWorkaround.
// from TextInputLayout
private void ensureBackgroundDrawableStateWorkaround(EditText editText) {
final int sdk = Build.VERSION.SDK_INT;
if (sdk != 21 && sdk != 22) {
// The workaround is only required on API 21-22
return;
}
final Drawable bg = editText.getBackground();
if (bg == null) {
return;
}
// There is an issue in the platform which affects container Drawables
// where the first drawable retrieved from resources will propogate any changes
// (like color filter) to all instances from the cache. We'll try to workaround it...
final Drawable newBg = bg.getConstantState().newDrawable();
boolean hasReconstructedEditTextBackground = false;
if (bg instanceof DrawableContainer) {
// If we have a Drawable container, we can try and set it's constant state via
// reflection from the new Drawable
hasReconstructedEditTextBackground = DrawableUtils.setContainerConstantState((DrawableContainer) bg, newBg.getConstantState());
}
if (!hasReconstructedEditTextBackground) {
// If we reach here then we just need to set a brand new instance of the Drawable
// as the background. This has the unfortunate side-effect of wiping out any
// user set padding, but I'd hope that use of custom padding on an EditText
// is limited.
editText.setBackgroundDrawable(newBg);
}
}
use of android.graphics.drawable.DrawableContainer in project wire-android by wireapp.
the class AddPhoneNumberPreferenceDialogFragment method clearColorFilter.
// from TextInputLayout
@TargetApi(Build.VERSION_CODES.KITKAT)
private static void clearColorFilter(@NonNull Drawable drawable) {
drawable.clearColorFilter();
if (Build.VERSION.SDK_INT == 21 || Build.VERSION.SDK_INT == 22) {
// children manually
if (drawable instanceof InsetDrawable) {
clearColorFilter(((InsetDrawable) drawable).getDrawable());
} else if (drawable instanceof DrawableWrapper) {
clearColorFilter(((DrawableWrapper) drawable).getWrappedDrawable());
} else if (drawable instanceof DrawableContainer) {
final DrawableContainer container = (DrawableContainer) drawable;
final DrawableContainer.DrawableContainerState state = (DrawableContainer.DrawableContainerState) container.getConstantState();
if (state != null) {
for (int i = 0, count = state.getChildCount(); i < count; i++) {
clearColorFilter(state.getChild(i));
}
}
}
}
}
Aggregations