mirror of
https://gitee.com/replugin/RePlugin.git
synced 2024-11-30 02:38:34 +08:00
Merge pull request #241 from jiongxuan/master
Support "package name" and "alias" to use plugin
This commit is contained in:
commit
25ec5d1c3a
@ -327,7 +327,11 @@ public class MP {
|
||||
} else {
|
||||
addTo = info;
|
||||
}
|
||||
array.add(addTo);
|
||||
|
||||
// 避免加了两次,毕竟包名和别名都会加进来
|
||||
if (!array.contains(addTo)) {
|
||||
array.add(addTo);
|
||||
}
|
||||
}
|
||||
}
|
||||
return array;
|
||||
|
@ -41,6 +41,7 @@ import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static com.qihoo360.i.Factory.loadPluginActivity;
|
||||
@ -634,9 +635,11 @@ public class PluginLibraryInternalProxy {
|
||||
* @return
|
||||
*/
|
||||
public JSONArray fetchPlugins(String name) {
|
||||
// 先获取List,然后再逐步搞JSON
|
||||
List<PluginInfo> l = MP.getPlugins(false);
|
||||
JSONArray ja = new JSONArray();
|
||||
synchronized (PluginTable.PLUGINS) {
|
||||
for (PluginInfo info : PluginTable.PLUGINS.values()) {
|
||||
for (PluginInfo info : l) {
|
||||
if (TextUtils.isEmpty(name) || TextUtils.equals(info.getName(), name)) {
|
||||
JSONObject jo = info.getJSON();
|
||||
ja.put(jo);
|
||||
|
@ -16,13 +16,14 @@
|
||||
|
||||
package com.qihoo360.loader2;
|
||||
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.qihoo360.replugin.RePlugin;
|
||||
import com.qihoo360.replugin.helper.LogDebug;
|
||||
import com.qihoo360.replugin.model.PluginInfo;
|
||||
|
||||
import java.io.FileDescriptor;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -43,7 +44,8 @@ class PluginTable {
|
||||
static final void dump(FileDescriptor fd, PrintWriter writer, String[] args) {
|
||||
if (LogDebug.DUMP_ENABLED) {
|
||||
writer.println("--- PluginTable.size = " + PLUGINS.size() + " ---");
|
||||
for (PluginInfo r : PLUGINS.values()) {
|
||||
List<PluginInfo> l = MP.getPlugins(false);
|
||||
for (PluginInfo r : l) {
|
||||
writer.println(r);
|
||||
}
|
||||
writer.println();
|
||||
@ -53,7 +55,7 @@ class PluginTable {
|
||||
static final void initPlugins(Map<String, Plugin> plugins) {
|
||||
synchronized (PLUGINS) {
|
||||
for (Plugin plugin : plugins.values()) {
|
||||
PLUGINS.put(plugin.mInfo.getName(), plugin.mInfo);
|
||||
putPluginInfo(plugin.mInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -73,7 +75,7 @@ class PluginTable {
|
||||
}
|
||||
|
||||
// 此处直接使用该插件,没有考虑是否只采用最新版
|
||||
PLUGINS.put(info.getName(), info);
|
||||
putPluginInfo(info);
|
||||
}
|
||||
}
|
||||
|
||||
@ -84,7 +86,7 @@ class PluginTable {
|
||||
pi = PLUGINS.get(info.getName());
|
||||
if (pi != null) {
|
||||
if (pi.canReplaceForPn(info)) {
|
||||
PLUGINS.put(info.getName(), info);
|
||||
putPluginInfo(info);
|
||||
rc = true;
|
||||
}
|
||||
}
|
||||
@ -100,7 +102,7 @@ class PluginTable {
|
||||
synchronized (PLUGINS) {
|
||||
pi = PLUGINS.get(info.getName());
|
||||
if (pi != null) {
|
||||
PLUGINS.remove(info.getName());
|
||||
removePluginInfo(info);
|
||||
rc = true;
|
||||
}
|
||||
}
|
||||
@ -120,16 +122,25 @@ class PluginTable {
|
||||
LogDebug.d(PLUGIN_TAG, "build plugins");
|
||||
}
|
||||
|
||||
synchronized (PLUGINS) {
|
||||
ArrayList<PluginInfo> lst = new ArrayList<PluginInfo>(PLUGINS.size());
|
||||
for (PluginInfo p : PLUGINS.values()) {
|
||||
lst.add(p);
|
||||
}
|
||||
if (LOG) {
|
||||
LogDebug.d(PLUGIN_TAG, "build " + lst.size() + " plugins");
|
||||
}
|
||||
return lst;
|
||||
List<PluginInfo> lst = MP.getPlugins(false);
|
||||
if (LOG) {
|
||||
LogDebug.d(PLUGIN_TAG, "build " + lst.size() + " plugins");
|
||||
}
|
||||
return lst;
|
||||
}
|
||||
|
||||
private static void putPluginInfo(PluginInfo info) {
|
||||
// 同时加入PackageName和Alias(如有)
|
||||
PLUGINS.put(info.getPackageName(), info);
|
||||
if (!TextUtils.isEmpty(info.getAlias())) {
|
||||
// 即便Alias和包名相同也可以再Put一次,反正只是覆盖了相同Value而已
|
||||
PLUGINS.put(info.getAlias(), info);
|
||||
}
|
||||
}
|
||||
|
||||
private static void removePluginInfo(PluginInfo info) {
|
||||
PLUGINS.remove(info.getPackageName());
|
||||
PLUGINS.remove(info.getAlias());
|
||||
}
|
||||
|
||||
// /**
|
||||
|
@ -352,7 +352,17 @@ class PmBase {
|
||||
return;
|
||||
}
|
||||
for (PluginInfo info : plugins) {
|
||||
mPlugins.put(info.getName(), Plugin.build(info));
|
||||
Plugin plugin = Plugin.build(info);
|
||||
putPluginObject(info, plugin);
|
||||
}
|
||||
}
|
||||
|
||||
private void putPluginObject(PluginInfo info, Plugin plugin) {
|
||||
// 同时加入PackageName和Alias(如有)
|
||||
mPlugins.put(info.getPackageName(), plugin);
|
||||
if (!TextUtils.isEmpty(info.getAlias())) {
|
||||
// 即便Alias和包名相同也可以再Put一次,反正只是覆盖了相同Value而已
|
||||
mPlugins.put(info.getAlias(), plugin);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1087,7 +1097,9 @@ class PmBase {
|
||||
}
|
||||
Plugin plugin = Plugin.build(info);
|
||||
plugin.attach(mContext, mClassLoader, mLocal);
|
||||
mPlugins.put(info.getName(), plugin);
|
||||
|
||||
// 同时加入PackageName和Alias(如有)
|
||||
putPluginObject(info, plugin);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -37,13 +37,15 @@ public class MainActivity extends Activity {
|
||||
findViewById(R.id.btn_start_demo1).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
RePlugin.startActivity(MainActivity.this, RePlugin.createIntent("demo1", "com.qihoo360.replugin.sample.demo1.MainActivity"));
|
||||
// 刻意以“包名”来打开
|
||||
RePlugin.startActivity(MainActivity.this, RePlugin.createIntent("com.qihoo360.replugin.sample.demo1", "com.qihoo360.replugin.sample.demo1.MainActivity"));
|
||||
}
|
||||
});
|
||||
|
||||
findViewById(R.id.btn_start_plugin_for_result).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
// 刻意以“Alias(别名)”来打开
|
||||
Intent intent = new Intent();
|
||||
intent.setComponent(new ComponentName("demo1", "com.qihoo360.replugin.sample.demo1.activity.for_result.ForResultActivity"));
|
||||
RePlugin.startActivityForResult(MainActivity.this, intent, REQUEST_CODE_DEMO1, null);
|
||||
|
Loading…
Reference in New Issue
Block a user