Skip to content

Commit e168cd9

Browse files
committed
Rename PluginDispater to PluginFragmentHelper
Signed-off-by: limpoxe <405977146@163.com>
1 parent 91c6afd commit e168cd9

11 files changed

+48
-46
lines changed

PluginCore/src/com/plugin/core/PluginAppTrace.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public boolean handleMessage(Message msg) {
4040
private static void hackReceiverIfNeed(Object msgObj) {
4141
Intent intent = (Intent)RefInvoker.getFieldObject(msgObj, "android.app.ActivityThread$ReceiverData", "intent");
4242
if (intent.getComponent().getClassName().equals(PluginStubReceiver.class.getName())) {
43-
Intent realIntent = (Intent)(intent.getParcelableExtra(PluginDispatcher.RECEIVER_ID_IN_PLUGIN));
43+
Intent realIntent = (Intent)(intent.getParcelableExtra(PluginFragmentHelper.RECEIVER_ID_IN_PLUGIN));
4444
LogUtil.d("receiver", realIntent.toUri(0));
4545
intent.putExtras(realIntent.getExtras());
4646
String realClassName = PluginLoader.isMatchPlugin(realIntent);

PluginCore/src/com/plugin/core/PluginApplication.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,18 @@ private void injectClassLoader() {
6666
public void sendBroadcast(Intent intent) {
6767
LogUtil.d("sendBroadcast", intent.toUri(0));
6868
Intent realIntent = intent;
69-
if (PluginDispatcher.hackClassLoadForReceiverIfNeeded(intent)) {
69+
if (PluginFragmentHelper.hackClassLoadForReceiverIfNeeded(intent)) {
7070
realIntent = new Intent();
7171
realIntent.setClass(PluginLoader.getApplicatoin(), PluginStubReceiver.class);
72-
realIntent.putExtra(PluginDispatcher.RECEIVER_ID_IN_PLUGIN, intent);
72+
realIntent.putExtra(PluginFragmentHelper.RECEIVER_ID_IN_PLUGIN, intent);
7373
}
7474
super.sendBroadcast(realIntent);
7575
}
7676

7777
@Override
7878
public ComponentName startService(Intent service) {
7979
LogUtil.d("startService", service.toUri(0));
80-
if (PluginDispatcher.hackClassLoadForServiceIfNeeded(service)) {
80+
if (PluginFragmentHelper.hackClassLoadForServiceIfNeeded(service)) {
8181
service.setClass(PluginLoader.getApplicatoin(), PluginStubService.class);
8282
}
8383
return super.startService(service);
@@ -86,7 +86,7 @@ public ComponentName startService(Intent service) {
8686
@Override
8787
public boolean stopService(Intent name) {
8888
LogUtil.d("stopService", name.toUri(0));
89-
if (PluginDispatcher.hackClassLoadForServiceIfNeeded(name)) {
89+
if (PluginFragmentHelper.hackClassLoadForServiceIfNeeded(name)) {
9090
name.setClass(PluginLoader.getApplicatoin(), PluginStubService.class);
9191
}
9292
return super.stopService(name);

PluginCore/src/com/plugin/core/PluginContextTheme.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -102,18 +102,18 @@ private void initializeTheme() {
102102
public void sendBroadcast(Intent intent) {
103103
LogUtil.d("sendBroadcast", intent.toUri(0));
104104
Intent realIntent = intent;
105-
if (PluginDispatcher.hackClassLoadForReceiverIfNeeded(intent)) {
105+
if (PluginFragmentHelper.hackClassLoadForReceiverIfNeeded(intent)) {
106106
realIntent = new Intent();
107107
realIntent.setClass(PluginLoader.getApplicatoin(), PluginStubReceiver.class);
108-
realIntent.putExtra(PluginDispatcher.RECEIVER_ID_IN_PLUGIN, intent);
108+
realIntent.putExtra(PluginFragmentHelper.RECEIVER_ID_IN_PLUGIN, intent);
109109
}
110110
super.sendBroadcast(realIntent);
111111
}
112112

113113
@Override
114114
public ComponentName startService(Intent service) {
115115
LogUtil.d("startService", service.toUri(0));
116-
if (PluginDispatcher.hackClassLoadForServiceIfNeeded(service)) {
116+
if (PluginFragmentHelper.hackClassLoadForServiceIfNeeded(service)) {
117117
service.setClass(PluginLoader.getApplicatoin(), PluginStubService.class);
118118
}
119119
return super.startService(service);
@@ -122,7 +122,7 @@ public ComponentName startService(Intent service) {
122122
@Override
123123
public boolean stopService(Intent name) {
124124
LogUtil.d("stopService", name.toUri(0));
125-
if (PluginDispatcher.hackClassLoadForServiceIfNeeded(name)) {
125+
if (PluginFragmentHelper.hackClassLoadForServiceIfNeeded(name)) {
126126
name.setClass(PluginLoader.getApplicatoin(), PluginStubService.class);
127127
}
128128
return super.stopService(name);

PluginCore/src/com/plugin/core/PluginDispatcher.java renamed to PluginCore/src/com/plugin/core/PluginFragmentHelper.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* @author cailiming
2323
*
2424
*/
25-
public class PluginDispatcher {
25+
public class PluginFragmentHelper {
2626

2727
public static final String FRAGMENT_ID_IN_PLUGIN = "PluginDispatcher.fragmentId";
2828
public static final String ACTIVITY_ID_IN_PLUGIN = "PluginDispatcher.proxy.activity";

PluginCore/src/com/plugin/core/PluginInstrumentionWrapper.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public void callActivityOnCreate(Activity activity, Bundle icicle) {
104104
Context pluginContext = null;
105105
if (activity.getClass().getName().equals(PluginSpecFragmentActivity.class.getName())) {
106106
// 为了能够在宿主中的Activiy里面展示来自插件的普通Fragment,我们将宿主程序中用来展示插件普通Fragment的Activity的Context也替换掉
107-
String classId = activity.getIntent().getStringExtra(PluginDispatcher.FRAGMENT_ID_IN_PLUGIN);
107+
String classId = activity.getIntent().getStringExtra(PluginFragmentHelper.FRAGMENT_ID_IN_PLUGIN);
108108
LogUtil.d("findPluginContext ", classId);
109109
@SuppressWarnings("rawtypes")
110110
Class clazz = PluginLoader.loadPluginClassById(classId);

PluginCore/src/com/plugin/core/PluginMainActiviyContextWrapper.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -393,10 +393,10 @@ public void startIntentSender(IntentSender intent, Intent fillInIntent, int flag
393393
public void sendBroadcast(Intent intent) {
394394
LogUtil.d(intent);
395395
Intent realIntent = intent;
396-
if (PluginDispatcher.hackClassLoadForReceiverIfNeeded(intent)) {
396+
if (PluginFragmentHelper.hackClassLoadForReceiverIfNeeded(intent)) {
397397
realIntent = new Intent();
398398
realIntent.setClass(PluginLoader.getApplicatoin(), PluginStubReceiver.class);
399-
realIntent.putExtra(PluginDispatcher.RECEIVER_ID_IN_PLUGIN, intent);
399+
realIntent.putExtra(PluginFragmentHelper.RECEIVER_ID_IN_PLUGIN, intent);
400400
}
401401
mBase.sendBroadcast(realIntent);
402402
}
@@ -522,7 +522,7 @@ public void unregisterReceiver(BroadcastReceiver receiver) {
522522
@Override
523523
public ComponentName startService(Intent service) {
524524
LogUtil.d(service);
525-
if (PluginDispatcher.hackClassLoadForServiceIfNeeded(service)) {
525+
if (PluginFragmentHelper.hackClassLoadForServiceIfNeeded(service)) {
526526
service.setClass(this, PluginStubService.class);
527527
}
528528
return mBase.startService(service);
@@ -531,7 +531,7 @@ public ComponentName startService(Intent service) {
531531
@Override
532532
public boolean stopService(Intent name) {
533533
LogUtil.d(name);
534-
if (PluginDispatcher.hackClassLoadForServiceIfNeeded(name)) {
534+
if (PluginFragmentHelper.hackClassLoadForServiceIfNeeded(name)) {
535535
name.setClass(this, PluginStubService.class);
536536
}
537537
return mBase.stopService(name);
@@ -540,7 +540,7 @@ public boolean stopService(Intent name) {
540540
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
541541
public ComponentName startServiceAsUser(Intent service, UserHandle user) {
542542
LogUtil.d(service);
543-
if (PluginDispatcher.hackClassLoadForServiceIfNeeded(service)) {
543+
if (PluginFragmentHelper.hackClassLoadForServiceIfNeeded(service)) {
544544
service.setClass(this, PluginStubService.class);
545545
}
546546
return (ComponentName) RefInvoker.invokeMethod(mBase, Context.class.getName(), "startServiceAsUser",
@@ -550,7 +550,7 @@ public ComponentName startServiceAsUser(Intent service, UserHandle user) {
550550
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
551551
public boolean stopServiceAsUser(Intent name, UserHandle user) {
552552
LogUtil.d(name);
553-
if (PluginDispatcher.hackClassLoadForServiceIfNeeded(name)) {
553+
if (PluginFragmentHelper.hackClassLoadForServiceIfNeeded(name)) {
554554
name.setClass(this, PluginStubService.class);
555555
}
556556
return (Boolean) RefInvoker.invokeMethod(mBase, Context.class.getName(), "stopServiceAsUser", new Class[] {

PluginCore/src/com/plugin/core/ui/PluginNormalFragmentActivity.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import android.widget.FrameLayout;
99
import android.widget.FrameLayout.LayoutParams;
1010

11-
import com.plugin.core.PluginDispatcher;
11+
import com.plugin.core.PluginFragmentHelper;
1212
import com.plugin.core.PluginLoader;
1313
import com.plugin.util.LogUtil;
1414

@@ -35,7 +35,7 @@ public void onCreate(Bundle savedInstanceState) {
3535

3636
private void loadPluginFragment() {
3737
try {
38-
String classId = getIntent().getStringExtra(PluginDispatcher.FRAGMENT_ID_IN_PLUGIN);
38+
String classId = getIntent().getStringExtra(PluginFragmentHelper.FRAGMENT_ID_IN_PLUGIN);
3939
LogUtil.d(LOG_TAG, "loadPluginFragment, classId is " + classId);
4040
@SuppressWarnings("rawtypes")
4141
Class clazz = PluginLoader.loadPluginClassById(classId);

PluginCore/src/com/plugin/core/ui/PluginProxyActivity.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import android.widget.FrameLayout.LayoutParams;
1414

1515
import com.plugin.core.PluginContextTheme;
16-
import com.plugin.core.PluginDispatcher;
16+
import com.plugin.core.PluginFragmentHelper;
1717
import com.plugin.core.PluginLoader;
1818
import com.plugin.util.LogUtil;
1919
import com.plugin.util.RefInvoker;
@@ -56,7 +56,7 @@ protected void onPostCreate(Bundle savedInstanceState) {
5656
}
5757

5858
private Context findPluginContext() {
59-
String classId = getIntent().getStringExtra(PluginDispatcher.ACTIVITY_ID_IN_PLUGIN);
59+
String classId = getIntent().getStringExtra(PluginFragmentHelper.ACTIVITY_ID_IN_PLUGIN);
6060
LogUtil.d("findPluginContext ", classId);
6161
@SuppressWarnings("rawtypes")
6262
Class clazz = PluginLoader.loadPluginClassById(classId);
@@ -248,7 +248,7 @@ private void set(String name) {
248248

249249
private void loadPluginActivity() {
250250
try {
251-
String classId = getIntent().getStringExtra(PluginDispatcher.ACTIVITY_ID_IN_PLUGIN);
251+
String classId = getIntent().getStringExtra(PluginFragmentHelper.ACTIVITY_ID_IN_PLUGIN);
252252
LogUtil.d("classId ", classId);
253253
@SuppressWarnings("rawtypes")
254254
Class clazz = PluginLoader.loadPluginClassById(classId);

PluginCore/src/com/plugin/core/ui/PluginSpecFragmentActivity.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import android.os.Bundle;
77

88
import com.plugin.core.PluginContextTheme;
9-
import com.plugin.core.PluginDispatcher;
9+
import com.plugin.core.PluginFragmentHelper;
1010
import com.plugin.core.PluginLoader;
1111
import com.plugin.util.LogUtil;
1212

@@ -30,7 +30,7 @@ public void onCreate(Bundle savedInstanceState) {
3030
}
3131

3232
private Context findPluginContext() {
33-
String classId = getIntent().getStringExtra(PluginDispatcher.FRAGMENT_ID_IN_PLUGIN);
33+
String classId = getIntent().getStringExtra(PluginFragmentHelper.FRAGMENT_ID_IN_PLUGIN);
3434
LogUtil.d("findPluginContext ", classId);
3535
@SuppressWarnings("rawtypes")
3636
Class clazz = PluginLoader.loadPluginClassById(classId);

PluginMain/src/com/example/pluginmain/PluginDebugHelper.java

+19-19
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import android.text.TextUtils;
1212
import android.util.Log;
1313

14-
import com.plugin.core.PluginDispatcher;
14+
import com.plugin.core.PluginFragmentHelper;
1515
import com.plugin.core.PluginLoader;
1616

1717
/**
@@ -22,34 +22,34 @@
2222
* 否则的话我们在调试的时候需要更新插件apk就比较麻烦
2323
*
2424
* @author cailiming
25-
*
25+
*
2626
*/
2727
public class PluginDebugHelper extends BroadcastReceiver {
2828

2929
@Override
3030
public void onReceive(Context context, Intent intent) {
31-
31+
3232
String pluginApkPath = getSource(context, intent);
33-
33+
3434
String defaultTarget = getDefaultTarget(context, intent);
35-
35+
3636
if (!TextUtils.isEmpty(pluginApkPath) && !TextUtils.isEmpty(defaultTarget)) {
3737
boolean success = PluginLoader.installPlugin(pluginApkPath);
3838
if (success) {
39-
PluginDispatcher.startFragmentWithSimpleActivity(context, defaultTarget);
39+
PluginFragmentHelper.startFragmentWithSimpleActivity(context, defaultTarget);
4040
}
4141
}
42-
42+
4343
}
44-
44+
4545
private String getSource(Context context, Intent intent) {
46-
46+
4747
Log.v("PluginInstaller", intent.toUri(0));
48-
48+
4949
if (intent.getAction().equals(Intent.ACTION_PACKAGE_ADDED)) {
50-
50+
5151
Log.e("PluginInstaller", "onReceive " + intent.getData().getSchemeSpecificPart());
52-
52+
5353
try {
5454
ApplicationInfo pinfo = context.getPackageManager().getApplicationInfo(
5555
intent.getData().getSchemeSpecificPart(), PackageManager.GET_META_DATA);
@@ -63,18 +63,18 @@ private String getSource(Context context, Intent intent) {
6363
|| intent.getAction().equals(Intent.ACTION_PACKAGE_RESTARTED)) {
6464

6565
}
66-
66+
6767
return null;
6868
}
69-
69+
7070
private String getDefaultTarget(Context context, Intent intent) {
71-
71+
7272
Log.v("PluginInstaller", intent.toUri(0));
73-
73+
7474
if (intent.getAction().equals(Intent.ACTION_PACKAGE_ADDED)) {
75-
75+
7676
Log.e("PluginInstaller", "onReceive " + intent.getData().getSchemeSpecificPart());
77-
77+
7878
try {
7979
ApplicationInfo pinfo = context.getPackageManager().getApplicationInfo(
8080
intent.getData().getSchemeSpecificPart(), PackageManager.GET_META_DATA);
@@ -94,7 +94,7 @@ private String getDefaultTarget(Context context, Intent intent) {
9494
|| intent.getAction().equals(Intent.ACTION_PACKAGE_RESTARTED)) {
9595

9696
}
97-
97+
9898
return null;
9999
}
100100
}

PluginMain/src/com/example/pluginmain/PluginDetailActivity.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import android.widget.Toast;
1818

1919
import com.plugin.content.PluginDescriptor;
20-
import com.plugin.core.PluginDispatcher;
20+
import com.plugin.core.PluginFragmentHelper;
2121
import com.plugin.core.PluginLoader;
2222

2323
public class PluginDetailActivity extends Activity {
@@ -78,11 +78,13 @@ public void onClick(View v) {
7878
// 第二类是在宿主提供的Activity中展示,分为普通Fragment和特别处理过的fragment
7979
// 下面演示第二类插件Fragment的两种情况
8080
if (entry.getKey().equals("fragmentTest1")) {
81-
PluginDispatcher.startFragmentWithSimpleActivity(PluginDetailActivity.this, entry.getKey());
81+
PluginFragmentHelper.startFragmentWithSimpleActivity(PluginDetailActivity.this,
82+
entry.getKey());
8283
}
8384
if (entry.getKey().equals("fragmentTest2")) {
8485
// 这种写法暂时还不兼容coolpad等手机
85-
PluginDispatcher.startFragmentWithBuildInActivity(PluginDetailActivity.this, entry.getKey());
86+
PluginFragmentHelper.startFragmentWithBuildInActivity(PluginDetailActivity.this,
87+
entry.getKey());
8688
}
8789
}
8890
});

0 commit comments

Comments
 (0)