private void fillPluginTheme(LActivityPlugin plugin) {

    Theme pluginTheme = plugin.from().pluginRes.newTheme();
    pluginTheme.setTo(super.getTheme());
    plugin.setTheme(pluginTheme);

    PackageInfo packageInfo = plugin.from().pluginPkgInfo;
    String mClass = plugin.getTopActivityName();

    Log.i(
        TAG,
        "Before fill Plugin 's Theme,We check the plugin:info = "
            + packageInfo
            + "topActivityName = "
            + mClass);

    int defaultTheme = packageInfo.applicationInfo.theme;
    ActivityInfo curActivityInfo = null;
    for (ActivityInfo a : packageInfo.activities) {
      if (a.name.equals(mClass)) {
        curActivityInfo = a;
        if (a.theme != 0) {
          defaultTheme = a.theme;
        } else if (defaultTheme != 0) {
          // ignore
        } else {
          // 支持不同系统的默认Theme
          if (Build.VERSION.SDK_INT >= 14) {
            defaultTheme = android.R.style.Theme_DeviceDefault;
          } else {
            defaultTheme = android.R.style.Theme;
          }
        }
        break;
      }
    }

    pluginTheme.applyStyle(defaultTheme, true);

    setTheme(defaultTheme);
    if (curActivityInfo != null) {
      getWindow().setSoftInputMode(curActivityInfo.softInputMode);
    }

    if (LPluginConfig.usePluginTitle) {
      CharSequence title = null;
      try {
        title = LPluginTool.getAppName(this, plugin.getPluginPath());
      } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
      }
      if (title != null) setTitle(title);
    }
  }
Ejemplo n.º 2
0
  protected void loadResources() {
    try {
      AssetManager assetManager = AssetManager.class.newInstance();
      Method addAssetPath = assetManager.getClass().getMethod("addAssetPath", String.class);
      addAssetPath.invoke(assetManager, dexpath);
      mAssetManager = assetManager;
    } catch (Exception e) {
      e.printStackTrace();
    }
    Resources superRes = super.getResources();
    superRes.getDisplayMetrics();
    superRes.getConfiguration();
    mResources =
        new Resources(mAssetManager, superRes.getDisplayMetrics(), superRes.getConfiguration());
    mTheme = mResources.newTheme();
    mTheme.setTo(super.getTheme());

    Log.d("DEMO", "mAssetManager: " + mAssetManager);
    Log.d("DEMO", "mResources: " + mResources);
    Log.d("DEMO", "mTheme: " + mTheme);
  }