| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
package android.content.res; |
| 16 |
|
| 17 |
import android.annotation.ColorRes; |
| 18 |
import android.annotation.DrawableRes; |
| 19 |
import android.content.Context; |
| 20 |
import android.graphics.drawable.Drawable; |
| 21 |
|
| 22 |
import java.lang.ref.WeakReference; |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
public class CompatResources extends Resources { |
| 29 |
|
| 30 |
private WeakReference<Context> mContext; |
| 31 |
|
| 32 |
public CompatResources(ClassLoader cls) { |
| 33 |
super(cls); |
| 34 |
mContext = new WeakReference<>(null); |
| 35 |
} |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
public void setContext(Context context) { |
| 41 |
mContext = new WeakReference<>(context); |
| 42 |
} |
| 43 |
|
| 44 |
@Override |
| 45 |
public Drawable getDrawable(@DrawableRes int id) throws NotFoundException { |
| 46 |
return getDrawable(id, getTheme()); |
| 47 |
} |
| 48 |
|
| 49 |
@Override |
| 50 |
public Drawable getDrawableForDensity(@DrawableRes int id, int density) |
| 51 |
throws NotFoundException { |
| 52 |
return getDrawableForDensity(id, density, getTheme()); |
| 53 |
} |
| 54 |
|
| 55 |
@Override |
| 56 |
public int getColor(@ColorRes int id) throws NotFoundException { |
| 57 |
return getColor(id, getTheme()); |
| 58 |
} |
| 59 |
|
| 60 |
@Override |
| 61 |
public ColorStateList getColorStateList(@ColorRes int id) throws NotFoundException { |
| 62 |
return getColorStateList(id, getTheme()); |
| 63 |
} |
| 64 |
|
| 65 |
private Theme getTheme() { |
| 66 |
Context c = mContext.get(); |
| 67 |
return c != null ? c.getTheme() : null; |
| 68 |
} |
| 69 |
} |