Offset 1, 41 lines modifiedOffset 1, 137 lines modified
  
1 package·androidx.core.content.res;1 package·androidx.core.content.res;
  
2 import·org.xmlpull.v1.XmlPullParserException;2 import·org.xmlpull.v1.XmlPullParserException;
3 import·java.io.IOException;3 import·java.io.IOException;
4 import·android.util.Log; 
5 import·org.xmlpull.v1.XmlPullParser; 
6 import·androidx.core.graphics.TypefaceCompat;4 import·androidx.core.graphics.TypefaceCompat;
7 import·android.content.res.Resources$NotFoundException;5 import·android.content.res.Resources$NotFoundException;
 6 import·android.content.res.XmlResourceParser;
 7 import·android.util.Log;
 8 import·org.xmlpull.v1.XmlPullParser;
8 import·android.os.Handler;9 import·android.os.Handler;
9 import·android.graphics.Typeface;10 import·android.graphics.Typeface;
10 import·android.util.TypedValue;11 import·android.util.TypedValue;
11 import·android.content.Context;12 import·android.content.Context;
12 import·android.os.Build$VERSION; 
13 import·android.graphics.drawable.Drawable;13 import·android.graphics.drawable.Drawable;
 14 import·android.os.Build$VERSION;
14 import·android.content.res.Resources$Theme;15 import·android.content.res.Resources$Theme;
 16 import·android.util.SparseArray;
 17 import·android.content.res.ColorStateList;
15 import·android.content.res.Resources;18 import·android.content.res.Resources;
 19 import·java.util.WeakHashMap;
  
16 public·final·class·ResourcesCompat20 public·final·class·ResourcesCompat
17 {21 {
 22 ····private·static·final·Object·sColorStateCacheLock;
 23 ····private·static·final·WeakHashMap·sColorStateCaches;
 24 ····private·static·final·ThreadLocal·sTempTypedValue;
 25 ····
 26 ····static·{
 27 ········sTempTypedValue·=·new·ThreadLocal();
 28 ········sColorStateCaches·=·new·WeakHashMap(0);
 29 ········sColorStateCacheLock·=·new·Object();
 30 ····}
 31 ····
 32 ····private·static·void·addColorStateListToCache(final·Resources·resources,·final·int·n,·final·ColorStateList·list)·{
 33 ········synchronized·(ResourcesCompat.sColorStateCacheLock)·{
 34 ············SparseArray·value·=·(SparseArray)ResourcesCompat.sColorStateCaches.get(resources);
 35 ············if·(value·==·null)·{
 36 ················value·=·new·SparseArray();
 37 ················ResourcesCompat.sColorStateCaches.put(resources,·value);
 38 ············}
 39 ············value.append(n,·(Object)new·ResourcesCompat$ColorStateListCacheEntry(list,·resources.getConfiguration()));
 40 ········}
 41 ····}
 42 ····
 43 ····private·static·ColorStateList·getCachedColorStateList(final·Resources·key,·final·int·n)·{
 44 ········synchronized·(ResourcesCompat.sColorStateCacheLock)·{
 45 ············final·SparseArray·sparseArray·=·(SparseArray)ResourcesCompat.sColorStateCaches.get(key);
 46 ············if·(sparseArray·!=·null·&&·sparseArray.size()·>·0)·{
 47 ················final·ResourcesCompat$ColorStateListCacheEntry·resourcesCompat$ColorStateListCacheEntry·=·(ResourcesCompat$ColorStateListCacheEntry)sparseArray.get(n);
 48 ················if·(resourcesCompat$ColorStateListCacheEntry·!=·null)·{
 49 ····················if·(resourcesCompat$ColorStateListCacheEntry.mConfiguration.equals(key.getConfiguration()))·{
 50 ························return·resourcesCompat$ColorStateListCacheEntry.mValue;
 51 ····················}
 52 ····················sparseArray.remove(n);
 53 ················}
 54 ············}
 55 ············return·null;
 56 ········}
 57 ····}
 58 ····
 59 ····public·static·ColorStateList·getColorStateList(final·Resources·resources,·final·int·n,·final·Resources$Theme·resources$Theme)·{
 60 ········if·(Build$VERSION.SDK_INT·>=·23)·{
 61 ············return·resources.getColorStateList(n,·resources$Theme);
 62 ········}
 63 ········final·ColorStateList·cachedColorStateList·=·getCachedColorStateList(resources,·n);
 64 ········if·(cachedColorStateList·!=·null)·{
 65 ············return·cachedColorStateList;
 66 ········}
 67 ········final·ColorStateList·inflateColorStateList·=·inflateColorStateList(resources,·n,·resources$Theme);
 68 ········if·(inflateColorStateList·!=·null)·{
 69 ············addColorStateListToCache(resources,·n,·inflateColorStateList);
 70 ············return·inflateColorStateList;
 71 ········}
 72 ········return·resources.getColorStateList(n);
 73 ····}
 74 ····
18 ····public·static·Drawable·getDrawable(final·Resources·resources,·final·int·n,·final·Resources$Theme·resources$Theme)·{75 ····public·static·Drawable·getDrawable(final·Resources·resources,·final·int·n,·final·Resources$Theme·resources$Theme)·{
19 ········if·(Build$VERSION.SDK_INT·>=·21)·{76 ········if·(Build$VERSION.SDK_INT·>=·21)·{
20 ············return·resources.getDrawable(n,·resources$Theme);77 ············return·resources.getDrawable(n,·resources$Theme);
21 ········}78 ········}
22 ········return·resources.getDrawable(n);79 ········return·resources.getDrawable(n);
23 ····}80 ····}
24 ····81 ····
25 ····public·static·Typeface·getFont(final·Context·context,·final·int·n,·final·TypedValue·typedValue,·final·int·n2,·final·ResourcesCompat$FontCallback·resourcesCompat$FontCallback)·{82 ····public·static·Typeface·getFont(final·Context·context,·final·int·n,·final·TypedValue·typedValue,·final·int·n2,·final·ResourcesCompat$FontCallback·resourcesCompat$FontCallback)·{
26 ········if·(context.isRestricted())·{83 ········if·(context.isRestricted())·{
27 ············return·null;84 ············return·null;
28 ········}85 ········}
29 ········return·loadFont(context,·n,·typedValue,·n2,·resourcesCompat$FontCallback,·null,·true);86 ········return·loadFont(context,·n,·typedValue,·n2,·resourcesCompat$FontCallback,·null,·true);
30 ····}87 ····}
31 ····88 ····
 89 ····private·static·TypedValue·getTypedValue()·{
 90 ········TypedValue·value·=·(TypedValue)ResourcesCompat.sTempTypedValue.get();
 91 ········if·(value·==·null)·{
 92 ············value·=·new·TypedValue();
 93 ············ResourcesCompat.sTempTypedValue.set(value);
 94 ········}
 95 ········return·value;
 96 ····}
 97 ····
 98 ····private·static·ColorStateList·inflateColorStateList(final·Resources·resources,·final·int·n,·final·Resources$Theme·resources$Theme)·{
 99 ········if·(isColorInt(resources,·n))·{
 100 ············return·null;
 101 ········}
 102 ········final·XmlResourceParser·xml·=·resources.getXml(n);
 103 ········try·{
 104 ············return·ColorStateListInflaterCompat.createFromXml(resources,·(XmlPullParser)xml,·resources$Theme);
 105 ········}
 106 ········catch·(Exception·ex)·{
 107 ············Log.e("ResourcesCompat",·"Failed·to·inflate·ColorStateList,·leaving·it·to·the·framework",·(Throwable)ex);
 108 ············return·null;
 109 ········}
 110 ····}
 111 ····
 112 ····private·static·boolean·isColorInt(final·Resources·resources,·int·n)·{
 113 ········final·TypedValue·typedValue·=·getTypedValue();
 114 ········boolean·b·=·true;
 115 ········resources.getValue(n,·typedValue,·b);
 116 ········final·int·type·=·typedValue.type;
 117 ········n·=·28;
 118 ········if·(type·>=·n)·{
 119 ············n·=·31;
 120 ············if·(type·<=·n)·{
 121 ················return·b;
 122 ············}
 123 ········}
 124 ········b·=·false;
 125 ········return·b;
 126 ····}
 127 ····
32 ····private·static·Typeface·loadFont(final·Context·context,·final·int·i,·final·TypedValue·typedValue,·final·int·n,·final·ResourcesCompat$FontCallback·resourcesCompat$FontCallback,·final·Handler·handler,·final·boolean·b)·{128 ····private·static·Typeface·loadFont(final·Context·context,·final·int·i,·final·TypedValue·typedValue,·final·int·n,·final·ResourcesCompat$FontCallback·resourcesCompat$FontCallback,·final·Handler·handler,·final·boolean·b)·{
33 ········final·Resources·resources·=·context.getResources();129 ········final·Resources·resources·=·context.getResources();
34 ········resources.getValue(i,·typedValue,·true);130 ········resources.getValue(i,·typedValue,·true);
35 ········final·Typeface·loadFont·=·loadFont(context,·resources,·typedValue,·i,·n,·resourcesCompat$FontCallback,·handler,·b);131 ········final·Typeface·loadFont·=·loadFont(context,·resources,·typedValue,·i,·n,·resourcesCompat$FontCallback,·handler,·b);
36 ········if·(loadFont·==·null·&&·resourcesCompat$FontCallback·==·null)·{132 ········if·(loadFont·==·null·&&·resourcesCompat$FontCallback·==·null)·{
37 ············final·StringBuilder·sb·=·new·StringBuilder();133 ············final·StringBuilder·sb·=·new·StringBuilder();
38 ············sb.append("Font·resource·ID·#0x");134 ············sb.append("Font·resource·ID·#0x");