コード例 #1
0
 @Override
 public AssetManager getAssets() {
   if (remotePlugin == null) return super.getAssets();
   return remotePlugin.from().pluginAssets == null
       ? super.getAssets()
       : remotePlugin.from().pluginAssets;
 }
コード例 #2
0
 @Override
 public Resources getResources() {
   if (remotePlugin == null) return super.getResources();
   return remotePlugin.from().pluginRes == null
       ? super.getResources()
       : remotePlugin.from().pluginRes;
 }
コード例 #3
0
 @Override
 public ClassLoader getClassLoader() {
   if (remotePlugin == null) {
     return super.getClassLoader();
   }
   if (remotePlugin.from().canUse()) {
     return remotePlugin.from().pluginLoader;
   }
   return super.getClassLoader();
 }
コード例 #4
0
  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);
    }
  }
コード例 #5
0
  /**
   * 装载插件的Activity
   *
   * @param plugin
   */
  private void fillPluginActivity(LActivityPlugin plugin) {
    try {
      String top = plugin.getTopActivityName();
      if (top == null) {
        top = plugin.from().pluginPkgInfo.activities[0].name;
        plugin.setTopActivityName(top);
      }
      Activity myPlugin =
          (Activity)
              plugin.from().pluginLoader.loadClass(plugin.getTopActivityName()).newInstance();
      plugin.setCurrentPluginActivity(myPlugin);

    } catch (Exception e) {
      throw new LaunchPluginException(e.getMessage());
    }
  }
コード例 #6
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {

    Thread.setDefaultUncaughtExceptionHandler(
        new Thread.UncaughtExceptionHandler() {
          @Override
          public void uncaughtException(Thread thread, final Throwable ex) {

            LPluginBug bug = new LPluginBug();
            bug.error = ex;
            bug.errorTime = System.currentTimeMillis();
            bug.errorThread = thread;
            bug.errorPlugin = remotePlugin;
            bug.processId = android.os.Process.myPid();
            LPluginBugManager.callAllBugListener(bug);
          }
        });
    super.onCreate(savedInstanceState);
    final Bundle pluginMessage = getIntent().getExtras();

    String pluginActivityName;
    String pluginDexPath;
    if (pluginMessage != null) {
      pluginActivityName =
          pluginMessage.getString(
              LPluginConfig.KEY_PLUGIN_ACT_NAME, LPluginConfig.DEF_PLUGIN_CLASS_NAME);
      pluginDexPath =
          pluginMessage.getString(
              LPluginConfig.KEY_PLUGIN_DEX_PATH, LPluginConfig.DEF_PLUGIN_DEX_PATH);
    } else {
      throw new PluginCreateFailedException("Please put the Plugin Path!");
    }
    if (pluginDexPath == LPluginConfig.DEF_PLUGIN_DEX_PATH) {
      throw new PluginCreateFailedException("Please put the Plugin Path!");
    }

    remotePlugin = loadPlugin(LActivityProxy.this, pluginDexPath);

    if (pluginActivityName != LPluginConfig.DEF_PLUGIN_CLASS_NAME) {
      remotePlugin.setTopActivityName(pluginActivityName);
    }

    fillPlugin(remotePlugin);
    // remotePlugin.from().debug();

    PluginActivityControl control =
        new PluginActivityControl(
            LActivityProxy.this,
            remotePlugin.getCurrentPluginActivity(),
            remotePlugin.from().pluginApplication);
    remotePlugin.setControl(control);
    control.dispatchProxyToPlugin();
    try {
      control.callOnCreate(savedInstanceState);
      LCallbackManager.callAllOnCreate(savedInstanceState);
    } catch (Exception e) {
      processError(e);
    }
  }
コード例 #7
0
  /**
   * 装载插件
   *
   * @param plugin
   */
  @Override
  public void fillPlugin(LActivityPlugin plugin) {
    if (plugin == null) {
      throw new PluginNotExistException("Plugin is null!");
    }
    String apkPath = plugin.getPluginPath();
    File apk = new File(apkPath);
    if (!apk.exists()) throw new NotFoundPluginException(apkPath);

    if (!this.remotePlugin.from().canUse()) {
      Log.i(TAG, "Plugin is not been init,init it now!");
      LApkManager.initApk(plugin.from(), this);
      // remotePlugin.from().debug();

    } else {
      Log.i(TAG, "Plugin have been init.");
    }
    fillPluginTheme(plugin);
    fillPluginActivity(plugin);
  }