content: package androidx.appcompat.widget;
  
  import android.content.Context;
  import android.content.ContextWrapper;
  import android.content.res.AssetManager;
  import android.content.res.Resources;
  import android.os.Build;
  import java.lang.ref.WeakReference;
  import java.util.ArrayList;
  
  public class TintContextWrapper extends ContextWrapper {
      private static final Object CACHE_LOCK = new Object();
      private static ArrayList<WeakReference<TintContextWrapper>> sCache;
      private final Resources mResources;
      private final Resources.Theme mTheme;
  
      private TintContextWrapper(Context base) {
          super(base);
          if (VectorEnabledTintResources.shouldBeUsed()) {
              VectorEnabledTintResources vectorEnabledTintResources = new VectorEnabledTintResources(this, base.getResources());
              this.mResources = vectorEnabledTintResources;
              Resources.Theme newTheme = vectorEnabledTintResources.newTheme();
              this.mTheme = newTheme;
              newTheme.setTo(base.getTheme());
              return;
          }
          this.mResources = new TintResources(this, base.getResources());
          this.mTheme = null;
      }
  
      private static boolean shouldWrap(Context context) {
          if ((context instanceof TintContextWrapper) || (context.getResources() instanceof TintResources) || (context.getResources() instanceof VectorEnabledTintResources)) {
              return false;
          }
          return Build.VERSION.SDK_INT < 21 || VectorEnabledTintResources.shouldBeUsed();
      }
  
      public static Context wrap(Context context) {
          if (!shouldWrap(context)) {
              return context;
          }
          synchronized (CACHE_LOCK) {
              ArrayList<WeakReference<TintContextWrapper>> arrayList = sCache;
              if (arrayList == null) {
                  sCache = new ArrayList<>();
              } else {
                  for (int size = arrayList.size() - 1; size >= 0; size--) {
                      WeakReference weakReference = sCache.get(size);
                      if (weakReference == null || weakReference.get() == null) {
                          sCache.remove(size);
                      }
                  }
                  for (int size2 = sCache.size() - 1; size2 >= 0; size2--) {
                      WeakReference weakReference2 = sCache.get(size2);
                      TintContextWrapper tintContextWrapper = weakReference2 != null ? (TintContextWrapper) weakReference2.get() : null;
                      if (tintContextWrapper != null && tintContextWrapper.getBaseContext() == context) {
                          return tintContextWrapper;
                      }
                  }
              }
              TintContextWrapper tintContextWrapper2 = new TintContextWrapper(context);
              sCache.add(new WeakReference(tintContextWrapper2));
              return tintContextWrapper2;
          }
      }
  
      public AssetManager getAssets() {
          return this.mResources.getAssets();
      }
  
      public Resources getResources() {
          return this.mResources;
      }
  
      public Resources.Theme getTheme() {
          Resources.Theme theme = this.mTheme;
          return theme == null ? super.getTheme() : theme;
      }
  
      public void setTheme(int resid) {
          Resources.Theme theme = this.mTheme;
          if (theme == null) {
              super.setTheme(resid);
          } else {
              theme.applyStyle(resid, true);
          }
      }
  }
  