|
2 | 2 |
|
3 | 3 | import android.content.Context;
|
4 | 4 | import android.os.Build;
|
| 5 | +import android.util.Log; |
5 | 6 |
|
6 | 7 | public class PluginCompat {
|
7 | 8 |
|
8 | 9 | /**
|
9 | 10 | *
|
10 | 11 | * @param pluginContext
|
11 |
| - * @param resId 宿主程序中定义的主题资源ID |
| 12 | + * @param resId 主题资源ID |
12 | 13 | * @param clazz
|
13 | 14 | */
|
14 |
| - public static void applyHostTheme(Context pluginContext, int resId, @SuppressWarnings("rawtypes") Class clazz) { |
15 |
| - //使用主程序资源Id不需要区分版本 |
16 |
| - pluginContext.setTheme(resId); |
17 |
| - } |
18 |
| - |
19 |
| - /** |
20 |
| - * |
21 |
| - * @param pluginContext |
22 |
| - * @param resId 插件程序中定义的主题资源ID |
23 |
| - * @param clazz |
24 |
| - */ |
25 |
| - public static void applyPluginTheme(Context pluginContext, int resId, @SuppressWarnings("rawtypes") Class clazz) { |
26 |
| - //使用插件程序主题资源Id的时候需要区分版本 |
27 |
| - if (Build.VERSION.SDK_INT >= 14 && Build.VERSION.SDK_INT <= 20) { |
| 15 | + public static void setTheme(Context pluginContext, int resId, @SuppressWarnings("rawtypes") Class clazz) { |
| 16 | + |
| 17 | + boolean isThemeInHostResouce = false; |
| 18 | + try { |
| 19 | + String themeEntryName = PluginLoader.getApplicatoin().getResources().getResourceEntryName(resId); |
| 20 | + Log.v("PluginCompat", "" +themeEntryName); |
| 21 | + |
| 22 | + //“main_style_”是在pluglic.xml文件中定义的! |
| 23 | + if (themeEntryName != null && !themeEntryName.startsWith("main_style_")) { |
| 24 | + isThemeInHostResouce = true; |
| 25 | + } |
| 26 | + } catch (Exception e) { |
| 27 | + } |
| 28 | + |
| 29 | + if (isThemeInHostResouce) { |
| 30 | + //使用主程序资源Id不需要区分版本 |
28 | 31 | pluginContext.setTheme(resId);
|
29 | 32 | } else {
|
30 |
| - PluginDescriptor pd = PluginLoader.getPluginDescriptorByClassName(clazz.getName()); |
31 |
| - ((PluginContextTheme)pluginContext).mResources = PluginCreator.createPluginResourceFor5(PluginLoader.getApplicatoin(), pd.getInstalledPath()); |
32 |
| - ((PluginContextTheme)pluginContext).mTheme = null; |
33 |
| - pluginContext.setTheme(resId); |
| 33 | + //使用插件程序主题资源Id的时候需要区分版本 |
| 34 | + if (Build.VERSION.SDK_INT >= 14 && Build.VERSION.SDK_INT <= 20) { |
| 35 | + pluginContext.setTheme(resId); |
| 36 | + } else { |
| 37 | + PluginDescriptor pd = PluginLoader.getPluginDescriptorByClassName(clazz.getName()); |
| 38 | + ((PluginContextTheme)pluginContext).mResources = PluginCreator.createPluginResourceFor5(PluginLoader.getApplicatoin(), pd.getInstalledPath()); |
| 39 | + ((PluginContextTheme)pluginContext).mTheme = null; |
| 40 | + pluginContext.setTheme(resId); |
| 41 | + } |
34 | 42 | }
|
35 | 43 | }
|
36 |
| - |
37 | 44 |
|
38 | 45 | }
|
0 commit comments