Skip to content

Commit

Permalink
Fixes a bug in gms
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 482613746
  • Loading branch information
sjudd authored and glide-copybara-robot committed Oct 20, 2022
1 parent 26a393b commit e1366e5
Showing 1 changed file with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import android.content.res.Resources;
import android.content.res.Resources.Theme;
import android.graphics.drawable.Drawable;
import android.os.Build.VERSION;
import android.os.Build.VERSION_CODES;
import androidx.annotation.DrawableRes;
import androidx.annotation.Nullable;
import androidx.appcompat.content.res.AppCompatResources;
Expand Down Expand Up @@ -65,13 +67,19 @@ private static Drawable getDrawable(

private static Drawable loadDrawableV7(
Context context, @DrawableRes int id, @Nullable Theme theme) {
Context resourceContext = theme != null ? new ContextThemeWrapper(context, theme) : context;
Context resourceContext;
if (theme != null && VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) {
ContextThemeWrapper contextThemeWrapper = new ContextThemeWrapper(context, theme);
contextThemeWrapper.applyOverrideConfiguration(theme.getResources().getConfiguration());
resourceContext = contextThemeWrapper;
} else {
resourceContext = context;
}
return AppCompatResources.getDrawable(resourceContext, id);
}

private static Drawable loadDrawableV4(
Context context, @DrawableRes int id, @Nullable Theme theme) {
Resources resources = context.getResources();
return ResourcesCompat.getDrawable(resources, id, theme);
return ResourcesCompat.getDrawable(context.getResources(), id, theme);
}
}

0 comments on commit e1366e5

Please sign in to comment.