Java Code Examples for android.content.pm.activityinfo#getThemeResource()

The following examples show how to use android.content.pm.activityinfo#getThemeResource() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PluginPackageInfo.java    From Neptune with Apache License 2.0 6 votes vote down vote up
public int getThemeResource(String activity) {
    ActivityInfo info = getActivityInfo(activity);
    if (info == null || info.getThemeResource() == 0) {
        // 支持不同系统的默认Theme
        if (Build.VERSION.SDK_INT >= 24) {
            return android.R.style.Theme_DeviceDefault_Light_DarkActionBar;
        } else if (Build.VERSION.SDK_INT >= 14) {
            return android.R.style.Theme_DeviceDefault;
        } else if (Build.VERSION.SDK_INT >= 11) {
            return android.R.style.Theme_Holo;
        } else {
            return android.R.style.Theme;
        }
    }
    return info.getThemeResource();
}
 
Example 2
Source File: InstrActivityProxy1.java    From Neptune with Apache License 2.0 6 votes vote down vote up
@Override
public void setTheme(int resId) {
    if (VersionUtils.hasNougat()) {
        String[] temp = parsePkgAndClsFromIntent();
        if (mNeedUpdateConfiguration && (temp != null || mLoadedApk != null)) {
            if (null != temp && temp.length == 2) {
                tryToInitPluginLoadApk(temp[0]);
            }
            if (mLoadedApk != null && temp != null) {
                ActivityInfo actInfo = mLoadedApk.getActivityInfoByClassName(temp[1]);
                if (actInfo != null) {
                    int resTheme = actInfo.getThemeResource();
                    if (mNeedUpdateConfiguration) {
                        changeActivityInfo(InstrActivityProxy1.this, temp[0], actInfo);
                        super.setTheme(resTheme);
                        mNeedUpdateConfiguration = false;
                        return;
                    }
                }
            }
        }
        super.setTheme(resId);
    } else {
        getTheme().applyStyle(resId, true);
    }
}
 
Example 3
Source File: ApkTargetMapping.java    From GPT with Apache License 2.0 6 votes vote down vote up
@Override
public int getThemeResource(String activity) {
    if (activity == null) {
        return android.R.style.Theme;
    }
    ActivityInfo info = mAcitivtyMap.get(activity);

    /**
     * 指定默认theme为android.R.style.Theme
     * 有些OPPO手机上,把theme设置成0,其实会把Theme设置成holo主题,带ActionBar,导致插件黑屏,目前插件SDK不支持ActionBar。
     *
     * ### 以上注释为 megapp 框架,新框架已经没有问题,gpt框架支持actionbar。
     */
    if (info == null || info.getThemeResource() == 0) {
        return 0; // 使用系统默认
    }
    return info.getThemeResource();
}
 
Example 4
Source File: PluginInjector.java    From Android-Plugin-Framework with MIT License 6 votes vote down vote up
/**
 * 主题的选择顺序为 先选择插件Activity配置的主题,再选择插件Application配置的主题,
 * 如果是非独立插件,再选择宿主Activity主题
 * 如果是独立插件,再选择系统默认主题
 * @param activityInfo
 * @param pluginActivityInfo
 * @param pd
 * @return
 */
private static int getPluginTheme(ActivityInfo activityInfo, PluginActivityInfo pluginActivityInfo, PluginDescriptor pd) {
	int pluginAppTheme = 0;
	if (pluginActivityInfo != null ) {
		pluginAppTheme = ResourceUtil.parseResId(pluginActivityInfo.getTheme());
	}
	if (pluginAppTheme == 0) {
		pluginAppTheme = pd.getApplicationTheme();
	}

	if (pluginAppTheme == 0 && pd.isStandalone()) {
		pluginAppTheme = android.R.style.Theme_DeviceDefault;
	}

	if (pluginAppTheme == 0) {
		//If the activity defines a theme, that is used; else, the application theme is used.
		pluginAppTheme = activityInfo.getThemeResource();
	}
	return pluginAppTheme;
}
 
Example 5
Source File: PluginInjector.java    From PluginLoader with Apache License 2.0 5 votes vote down vote up
private static int getPluginTheme(ActivityInfo activityInfo, PluginActivityInfo pluginActivityInfo, PluginDescriptor pd) {
	int pluginAppTheme = 0;
	if (pluginActivityInfo != null ) {
		pluginAppTheme = ResourceUtil.getResourceId(pluginActivityInfo.getTheme());
	}
	if (pluginAppTheme == 0) {
		pluginAppTheme = pd.getApplicationTheme();
	}
	if (pluginAppTheme == 0) {
		pluginAppTheme = activityInfo.getThemeResource();
	}
	return pluginAppTheme;
}
 
Example 6
Source File: LaunchModeManager.java    From Phantom with Apache License 2.0 4 votes vote down vote up
/**
 * 获取一个占位activity
 *
 * @param pluginActivity 插件activity
 * @param launchMode     插件activity启动模式
 * @param isFixed        是否建立固定映射关系
 * @return 占位activity
 * @throws ProxyActivityLessException 占位activity不够异常
 */
private String findActivity(String pluginActivity, int launchMode, boolean isFixed)
        throws ProxyActivityLessException {

    String activity = MODE_STANDARD;
    ActivityPool pool = null;

    switch (launchMode) {
        case ActivityInfo.LAUNCH_MULTIPLE:
            final PhantomCore phantomCore = PhantomCore.getInstance();
            final ComponentName componentName = ComponentName.unflattenFromString(pluginActivity);
            if (componentName != null) {
                final ActivityInfo ai = phantomCore.findActivityInfo(componentName);
                final PluginInfo pluginInfo = phantomCore.findPluginInfoByActivityName(componentName);
                final int themeResourceId = ai == null ? -1 : ai.getThemeResource();
                if (themeResourceId != -1 && pluginInfo != null) {
                    final Resources resources = pluginInfo.getPluginResources();
                    if (resources != null) {
                        final Resources.Theme theme = resources.newTheme();
                        theme.applyStyle(themeResourceId, true);
                        final TypedArray sa = theme.obtainStyledAttributes(
                                new int[]{android.R.attr.windowIsTranslucent});
                        final boolean translucent = sa.getBoolean(0, false);
                        sa.recycle();
                        activity = translucent ? MODE_STANDARD_TRANSLUCENT : MODE_STANDARD;
                    }
                }
            }
            break;
        case ActivityInfo.LAUNCH_SINGLE_TOP:
            pool = mSingleTopPool;
            break;
        case ActivityInfo.LAUNCH_SINGLE_INSTANCE:
            pool = mSingleInstancePool;
            break;
        case ActivityInfo.LAUNCH_SINGLE_TASK:
            pool = mSingleTaskPool;
            break;
        default:
            break;
    }

    if (null != pool) {
        activity = isFixed ? pool.resolveFixedActivity(pluginActivity) : pool.resolveActivity(pluginActivity);
    }

    String msg = String.format("resolve %s Activity for %s proxy is %s, fixed is %s",
            launchModeToString(launchMode), pluginActivity, activity, isFixed);
    VLog.d(msg);
    if (null == activity) {
        //占位activity不够使用, 这种情况不做处理,宿主提供足够的占位activity
        //这里不做主动回收,如果做主动回收可能会使程序正常执行流程发送改变
        ProxyActivityLessException pae = new ProxyActivityLessException(msg);
        LogReporter.reportException(pae, null);
        mCache.clean();
        throw pae;
    }

    return activity;
}