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

Dev #78

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open

Dev #78

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
49 changes: 49 additions & 0 deletions DynamicLoadApk/lib/src/com/ryg/dynamicload/DLActivities.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright (C) 2014 singwhatiwanna(任玉刚) <singwhatiwanna@gmail.com>
*
* collaborator:Sizon(赵海洋)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ryg.dynamicload;
import java.io.File;
import java.util.HashMap;
import java.util.Map;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.os.Environment;

import com.ryg.utils.DLUtils;

public class DLActivities {

public static Map<String,Integer> Acts = new HashMap<String,Integer>();

public static void initData(Context context) {
String pluginFolder = Environment.getExternalStorageDirectory()
+ "/DynamicLoadHost";
File file = new File(pluginFolder);
File[] plugins = file.listFiles();

for (File plugin : plugins) {
PackageInfo packageInfo = DLUtils.getPackageInfo(context, plugin.getAbsolutePath());
if (packageInfo.activities != null
&& packageInfo.activities.length > 0) {
for (int i = 0; i < packageInfo.activities.length; i++) {
Acts.put(packageInfo.activities[i].name,packageInfo.activities[i].launchMode );
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,16 @@
import java.io.File;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import android.annotation.TargetApi;
import android.app.Activity;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.res.AssetManager;
Expand All @@ -35,6 +39,7 @@
import android.text.TextUtils;
import android.util.Log;

import com.ryg.dynamicload.DLActivities;
import com.ryg.dynamicload.DLBasePluginActivity;
import com.ryg.dynamicload.DLBasePluginFragmentActivity;
import com.ryg.dynamicload.DLBasePluginService;
Expand Down Expand Up @@ -439,6 +444,32 @@ private Class<? extends Service> getProxyServiceClass(Class<?> clazz) {

private void performStartActivityForResult(Context context, DLIntent dlIntent, int requestCode) {
Log.d(TAG, "launch " + dlIntent.getPluginClass());
//每次开启新界面时获取下所有界面的activitys和launchmode,以防在使用中更新了插件。
DLActivities.initData(context);
if(DLActivities.Acts != null){
Map<String,Integer> actAndMode = DLActivities.Acts;
Set<String> keySet = actAndMode.keySet();
int mode = 0;
for(String name : keySet) {
if(name.equals(dlIntent.getPluginClass())) {
mode = actAndMode.get(name);
break;
}
}
if (mode == ActivityInfo.LAUNCH_SINGLE_TASK) {
//如果activity在task存在,拿到最顶端,不会启动新的Activity
dlIntent.addFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
//如果activity在task存在,将Activity之上的所有Activity结束掉
dlIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
}else if(mode == ActivityInfo.LAUNCH_SINGLE_TOP) {
dlIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
}else if(mode == ActivityInfo.LAUNCH_SINGLE_INSTANCE) {
dlIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
}
}else {
Log.e(TAG, "Acts is null");
}

if (context instanceof Activity) {
((Activity) context).startActivityForResult(dlIntent, requestCode);
} else {
Expand Down
6 changes: 4 additions & 2 deletions DynamicLoadApk/sample/main/main-plugin-a/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
<activity
android:name="com.ryg.dynamicload.sample.mainplugin.MainActivity"
android:label="@string/app_name"
android:theme="@android:style/Theme.Light" >
android:theme="@android:style/Theme.Light"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand All @@ -26,7 +27,8 @@
<activity
android:name="com.ryg.dynamicload.sample.mainplugin.TestFragmentActivity"
android:label="@string/app_name"
android:theme="@android:style/Theme.Light.NoTitleBar.Fullscreen" >
android:theme="@android:style/Theme.Light.NoTitleBar.Fullscreen"
android:launchMode="singleTask" >
<intent-filter>
<action android:name="android.intent.action.VIEW" />

Expand Down