Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

支持startActvity直接调起插件Activity和应用上下文 #107

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package com.ryg.dynamicload;

import android.content.Context;
import android.content.ContextWrapper;
import android.content.Intent;
import android.content.res.AssetManager;
import android.content.res.Resources;

import com.ryg.dynamicload.internal.DLIntent;
import com.ryg.dynamicload.internal.DLPluginManager;
import com.ryg.dynamicload.internal.DLPluginPackage;

/**
* 插件app的application上下文
* 主要用在单例中对applicaiton上下文的使用
*/
public class DLApplicationContext extends ContextWrapper {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

很好的想法和实现,但是目前已经有很多更加优秀的新框架出现了,dl框架不再接受pr了。


DLPluginPackage mPluginPackage;

public DLApplicationContext(Context base, DLPluginPackage pluginPkg) {
super(base);
mPluginPackage = pluginPkg;
}


@Override
public Resources getResources() {
if(mPluginPackage != null){
return mPluginPackage.resources;
}else{
return super.getResources();
}
}

@Override
public Context getApplicationContext() {
if(mPluginPackage != null){
return this;
}else{
return super.getApplicationContext();
}
}

@Override
public String getPackageName() {
if(mPluginPackage != null){
return mPluginPackage.packageName;
}else{
return super.getPackageName();
}
}

@Override
public AssetManager getAssets() {
if(mPluginPackage != null){
return mPluginPackage.assetManager;
}else{
return super.getAssets();
}
}

@Override
public void startActivity(Intent intent) {
if(mPluginPackage != null){
startPluginActivity((DLIntent) intent);
}else{
super.startActivity(intent);
}
}

public void startPluginActivity(DLIntent dlIntent) {
startPluginActivityForResult(dlIntent, -1);
}

public void startPluginActivityForResult(DLIntent dlIntent, int requestCode) {
if (dlIntent.getPluginPackage() == null) {
dlIntent.setPluginPackage(mPluginPackage.packageName);
}
DLPluginManager plMgr = DLPluginManager.getInstance(this);
plMgr.startPluginActivityForResult(this, dlIntent, requestCode);
}

}
156 changes: 95 additions & 61 deletions DynamicLoadApk/lib/src/com/ryg/dynamicload/DLBasePluginActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@
package com.ryg.dynamicload;

import android.app.Activity;
import android.content.ComponentName;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.ServiceConnection;
import android.content.SharedPreferences;
import android.content.res.Resources;
Expand Down Expand Up @@ -363,30 +364,23 @@ public boolean onOptionsItemSelected(MenuItem item) {
return false;
}

/**
* @param dlIntent
* @return may be {@link #START_RESULT_SUCCESS},
* {@link #START_RESULT_NO_PKG}, {@link #START_RESULT_NO_CLASS},
* {@link #START_RESULT_TYPE_ERROR}
*/
public int startPluginActivity(DLIntent dlIntent) {
return startPluginActivityForResult(dlIntent, -1);
}

/**
* @param dlIntent
* @return may be {@link #START_RESULT_SUCCESS},
* {@link #START_RESULT_NO_PKG}, {@link #START_RESULT_NO_CLASS},
* {@link #START_RESULT_TYPE_ERROR}
*/
public int startPluginActivityForResult(DLIntent dlIntent, int requestCode) {
if (mFrom == DLConstants.FROM_EXTERNAL) {
if (dlIntent.getPluginPackage() == null) {
dlIntent.setPluginPackage(mPluginPackage.packageName);
}
}
return mPluginManager.startPluginActivityForResult(that, dlIntent, requestCode);
}
@Override
public void startActivity(Intent intent) {
if (mFrom == DLConstants.FROM_INTERNAL) {
super.startActivity(intent);
} else {
mProxyActivity.startActivity(intent);
}
}

@Override
public void startActivityForResult(Intent intent, int requestCode) {
if (mFrom == DLConstants.FROM_INTERNAL) {
super.startActivityForResult(intent, requestCode);
} else {
mProxyActivity.startActivityForResult(intent, requestCode);
}
}

public int startPluginService(DLIntent dlIntent) {
if (mFrom == DLConstants.FROM_EXTERNAL) {
Expand All @@ -397,14 +391,24 @@ public int startPluginService(DLIntent dlIntent) {
return mPluginManager.startPluginService(that, dlIntent);
}

public int bindPluginService(DLIntent dlIntent, ServiceConnection conn, int flags) {
if (mFrom == DLConstants.FROM_EXTERNAL) {
if (dlIntent.getPluginPackage() == null) {
dlIntent.setPluginPackage(mPluginPackage.packageName);
}
}
return mPluginManager.bindPluginService(that, dlIntent, conn, flags);
}
// public int stopPluginService(DLIntent dlIntent) {
// if (mFrom == DLConstants.FROM_EXTERNAL) {
// if (dlIntent.getPluginPackage() == null) {
// dlIntent.setPluginPackage(mPluginPackage.packageName);
// }
// }
// return mPluginManager.stopPluginService(that, dlIntent);
// }

public int bindPluginService(DLIntent dlIntent, ServiceConnection conn,
int flags) {
if (mFrom == DLConstants.FROM_EXTERNAL) {
if (dlIntent.getPluginPackage() == null) {
dlIntent.setPluginPackage(mPluginPackage.packageName);
}
}
return mPluginManager.bindPluginService(that, dlIntent, conn, flags);
}

public int unBindPluginService(DLIntent dlIntent, ServiceConnection conn) {
if (mFrom == DLConstants.FROM_EXTERNAL) {
Expand All @@ -414,33 +418,63 @@ public int unBindPluginService(DLIntent dlIntent, ServiceConnection conn) {
return mPluginManager.unBindPluginService(that, dlIntent, conn);
}

// /**
// * 直接调用that.startService
// * that 可能有两种情况
// * 1.指向this
// * 2.指向DLProxyActivity
// */
// public ComponentName startService(Intent service) {
// return that.startService(service);
// }
//
// @Override
// public boolean stopService(Intent name) {
// // TODO Auto-generated method stub
// return super.stopService(name);
// }
//
// @Override
// public boolean bindService(Intent service, ServiceConnection conn, int
// flags) {
// // TODO Auto-generated method stub
// return super.bindService(service, conn, flags);
// }
//
// @Override
// public void unbindService(ServiceConnection conn) {
// // TODO Auto-generated method stub
// super.unbindService(conn);
// }
@Override
public int checkPermission(String permission, int pid, int uid) {
if (mFrom == DLConstants.FROM_INTERNAL) {
return super.checkPermission(permission, pid, uid);
} else {
return mProxyActivity.checkPermission(permission, pid, uid);
}
}

@Override
public boolean isFinishing() {
if (mFrom == DLConstants.FROM_INTERNAL) {
return super.isFinishing();
} else {
return mProxyActivity.isFinishing();
}
}

@Override
public void sendBroadcast(Intent intent) {
if (mFrom == DLConstants.FROM_INTERNAL) {
super.sendBroadcast(intent);
} else {
mProxyActivity.sendBroadcast(intent);
}
}

@Override
public Intent registerReceiver(BroadcastReceiver receiver,
IntentFilter filter) {
if (mFrom == DLConstants.FROM_INTERNAL) {
return super.registerReceiver(receiver, filter);
} else {
return mProxyActivity.registerReceiver(receiver, filter);
}
}

@Override
public void unregisterReceiver(BroadcastReceiver receiver) {
if (mFrom == DLConstants.FROM_INTERNAL) {
super.unregisterReceiver(receiver);
} else {
mProxyActivity.unregisterReceiver(receiver);
}
}

@Override
public void onClick(View view) {

}

public View getCurrentFocus(){
if(mFrom == DLConstants.FROM_INTERNAL){
return super.getCurrentFocus();
}else{
return mProxyActivity.getCurrentFocus();
}
}

}
Loading