20250531_213355_576
This commit is contained in:
parent
934d54963a
commit
56692db142
@ -1,8 +1,8 @@
|
||||
#Created by .winboll/winboll_app_build.gradle
|
||||
#Fri May 30 01:41:12 GMT 2025
|
||||
#Sat May 31 13:31:02 GMT 2025
|
||||
stageCount=2
|
||||
libraryProject=libappbase
|
||||
baseVersion=15.8
|
||||
publishVersion=15.8.1
|
||||
buildCount=12
|
||||
buildCount=25
|
||||
baseBetaVersion=15.8.2
|
||||
|
@ -166,7 +166,7 @@ public class MainActivity extends WinBoLLActivity implements IWinBoLLActivity {
|
||||
}
|
||||
|
||||
public void onTestOpenNewActivity(View view) {
|
||||
GlobalApplication.getWinBoLLActivityManager().startWinBoLLActivity(this, NewActivity.class);
|
||||
GlobalApplication.getWinBoLLActivityManager().startWinBoLLActivity(NewActivity.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -59,7 +59,7 @@ public class New2Activity extends WinBoLLActivity implements IWinBoLLActivity {
|
||||
}
|
||||
|
||||
public void onNewActivity(View view) {
|
||||
GlobalApplication.getWinBoLLActivityManager().startWinBoLLActivity(this, NewActivity.class);
|
||||
GlobalApplication.getWinBoLLActivityManager().startWinBoLLActivity(NewActivity.class);
|
||||
}
|
||||
|
||||
|
||||
|
@ -57,7 +57,7 @@ public class NewActivity extends WinBoLLActivity implements IWinBoLLActivity {
|
||||
}
|
||||
|
||||
public void onNew2Activity(View view) {
|
||||
GlobalApplication.getWinBoLLActivityManager().startWinBoLLActivity(this, New2Activity.class);
|
||||
GlobalApplication.getWinBoLLActivityManager().startWinBoLLActivity(New2Activity.class);
|
||||
}
|
||||
|
||||
|
||||
|
@ -6,6 +6,7 @@ package cc.winboll.studio.appbase.activities;
|
||||
* @Describe WinBoLL 窗口基础类
|
||||
*/
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.view.MenuItem;
|
||||
import cc.winboll.studio.appbase.R;
|
||||
import cc.winboll.studio.libappbase.GlobalApplication;
|
||||
@ -24,16 +25,27 @@ public class WinBoLLActivity extends Activity implements IWinBoLLActivity {
|
||||
public String getTag() {
|
||||
return TAG;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
if (item.getItemId() == R.id.item_log) {
|
||||
GlobalApplication.getWinBoLLActivityManager().startLogActivity(this);
|
||||
GlobalApplication.getWinBoLLActivityManager().startLogActivity();
|
||||
return true;
|
||||
}
|
||||
// 在switch语句中处理每个ID,并在处理完后返回true,未处理的情况返回false。
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onPostCreate(Bundle savedInstanceState) {
|
||||
super.onPostCreate(savedInstanceState);
|
||||
GlobalApplication.getWinBoLLActivityManager().add(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
GlobalApplication.getWinBoLLActivityManager().registeRemove(this);
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
#Created by .winboll/winboll_app_build.gradle
|
||||
#Fri May 30 01:41:12 GMT 2025
|
||||
#Sat May 31 13:31:02 GMT 2025
|
||||
stageCount=2
|
||||
libraryProject=libappbase
|
||||
baseVersion=15.8
|
||||
publishVersion=15.8.1
|
||||
buildCount=12
|
||||
buildCount=25
|
||||
baseBetaVersion=15.8.2
|
||||
|
@ -47,7 +47,7 @@ public class GlobalApplication extends Application {
|
||||
}
|
||||
|
||||
public static WinBoLLActivityManager getWinBoLLActivityManager() {
|
||||
return WinBoLLActivityManager.getInstance(_GlobalApplication);
|
||||
return WinBoLLActivityManager.getInstance();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -22,11 +22,11 @@ import java.util.Map;
|
||||
|
||||
public class WinBoLLActivityManager {
|
||||
|
||||
public static final String TAG = "IWinBoLLActivityManager";
|
||||
public static final String TAG = "WinBoLLActivityManager";
|
||||
|
||||
public static final String EXTRA_TAG = "EXTRA_TAG";
|
||||
|
||||
|
||||
|
||||
public enum WinBoLLUI_TYPE { Aplication, Service }
|
||||
|
||||
Context mContext;
|
||||
@ -41,14 +41,14 @@ public class WinBoLLActivityManager {
|
||||
public static WinBoLLUI_TYPE getWinBoLLUI_TYPE() {
|
||||
return _WinBoLLUI_TYPE;
|
||||
}
|
||||
WinBoLLActivityManager(Context context) {
|
||||
mContext = context;
|
||||
WinBoLLActivityManager() {
|
||||
mContext = GlobalApplication.getInstance();
|
||||
mActivityListMap = new HashMap<String, IWinBoLLActivity>();
|
||||
}
|
||||
|
||||
public static synchronized WinBoLLActivityManager getInstance(Context context) {
|
||||
public static synchronized WinBoLLActivityManager getInstance() {
|
||||
if (_mIWinBoLLActivityManager == null) {
|
||||
_mIWinBoLLActivityManager = new WinBoLLActivityManager(context);
|
||||
_mIWinBoLLActivityManager = new WinBoLLActivityManager();
|
||||
}
|
||||
return _mIWinBoLLActivityManager;
|
||||
}
|
||||
@ -71,134 +71,105 @@ public class WinBoLLActivityManager {
|
||||
// activity: 不为 null 时,
|
||||
// intent.putExtra 函数 "tag" 参数为 activity.getTag()
|
||||
//
|
||||
public <T extends IWinBoLLActivity> void startWinBoLLActivity(Context context, Class<T> clazz) {
|
||||
try {
|
||||
// 如果窗口已存在就重启窗口
|
||||
String tag = clazz.newInstance().getTag();
|
||||
if (isActive(tag)) {
|
||||
resumeActivity(context, tag);
|
||||
return;
|
||||
}
|
||||
|
||||
public <T extends IWinBoLLActivity> void startWinBoLLActivity(Class<T> clazz) {
|
||||
// 如果窗口已存在就重启窗口
|
||||
if (!resumeActivity(clazz)) {
|
||||
// 新建一个任务窗口
|
||||
Intent intent = new Intent(context, clazz);
|
||||
Intent intent = new Intent(mContext, clazz);
|
||||
//打开多任务窗口 flags
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
|
||||
intent.putExtra("tag", tag);
|
||||
//intent.putExtra("tag", tag);
|
||||
mContext.startActivity(intent);
|
||||
} catch (InstantiationException | IllegalAccessException e) {
|
||||
LogUtils.d(TAG, e, Thread.currentThread().getStackTrace());
|
||||
}
|
||||
}
|
||||
|
||||
public <T extends IWinBoLLActivity> void startWinBoLLActivity(Context context, Intent intent, Class<T> clazz) {
|
||||
try {
|
||||
// 如果窗口已存在就重启窗口
|
||||
String tag = clazz.newInstance().getTag();
|
||||
if (isActive(tag)) {
|
||||
resumeActivity(context, tag);
|
||||
return;
|
||||
}
|
||||
|
||||
public <T extends IWinBoLLActivity> void startWinBoLLActivity(Intent intent, Class<T> clazz) {
|
||||
// 如果窗口已存在就重启窗口
|
||||
if (!resumeActivity(clazz)) {
|
||||
// 新建一个任务窗口
|
||||
//Intent intent = new Intent(context, clazz);
|
||||
//打开多任务窗口 flags
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
|
||||
intent.putExtra("tag", tag);
|
||||
//intent.putExtra("tag", tag);
|
||||
mContext.startActivity(intent);
|
||||
} catch (InstantiationException | IllegalAccessException e) {
|
||||
LogUtils.d(TAG, e, Thread.currentThread().getStackTrace());
|
||||
}
|
||||
}
|
||||
|
||||
public <T extends IWinBoLLActivity> void startLogActivity(Context context) {
|
||||
// 如果窗口已存在就重启窗口
|
||||
String tag = LogActivity.TAG;
|
||||
if (isActive(tag)) {
|
||||
resumeActivity(context, tag);
|
||||
return;
|
||||
}
|
||||
|
||||
// 新建一个任务窗口
|
||||
Intent intent = new Intent(context, LogActivity.class);
|
||||
//打开多任务窗口 flags
|
||||
// Define the bounds.
|
||||
public <T extends IWinBoLLActivity> void startLogActivity() {
|
||||
// 如果窗口已存在就重启窗口
|
||||
if (!resumeActivity(LogActivity.class)) {
|
||||
// 新建一个任务窗口
|
||||
Intent intent = new Intent(mContext, LogActivity.class);
|
||||
//打开多任务窗口 flags
|
||||
// Define the bounds.
|
||||
// Rect bounds = new Rect(0, 0, 800, 200);
|
||||
// // Set the bounds as an activity option.
|
||||
// ActivityOptions options = ActivityOptions.makeBasic();
|
||||
// options.setLaunchBounds(bounds);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
|
||||
|
||||
intent.putExtra(EXTRA_TAG, tag);
|
||||
//intent.putExtra(EXTRA_TAG, tag);
|
||||
|
||||
//context.startActivity(intent, options.toBundle());
|
||||
context.startActivity(intent);
|
||||
//context.startActivity(intent, options.toBundle());
|
||||
mContext.startActivity(intent);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断 tag绑定的 MyActivity是否存在
|
||||
*/
|
||||
//
|
||||
// 判断 tag 绑定的 Activity 是否已经创建
|
||||
//
|
||||
public boolean isActive(String tag) {
|
||||
//printAvtivityListInfo();
|
||||
IWinBoLLActivity iWinBoLLActivity = getIWinBoLLActivity(tag);
|
||||
if (iWinBoLLActivity != null) {
|
||||
Activity activity = iWinBoLLActivity.getActivity();
|
||||
if (activity != null) {
|
||||
LogUtils.d(TAG, "isActive(...) activity != null tag " + tag);
|
||||
//ToastUtils.show("activity != null tag " + tag);
|
||||
//判断是否为 BaseActivity,如果已经销毁,则移除
|
||||
if (activity.isFinishing() || activity.isDestroyed()) {
|
||||
mActivityListMap.remove(iWinBoLLActivity.getTag());
|
||||
//_mIWinBoLLActivityList.remove(activity);
|
||||
LogUtils.d(TAG, String.format("isActive(...) remove activity.\ntag : %s", tag));
|
||||
return false;
|
||||
} else {
|
||||
LogUtils.d(TAG, String.format("isActive(...) activity is exist.\ntag : %s", tag));
|
||||
return true;
|
||||
}
|
||||
Activity activity = getActivityByTag(tag);
|
||||
if (activity != null) {
|
||||
//判断是否正在关闭
|
||||
if (activity.isFinishing() || activity.isDestroyed()) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
IWinBoLLActivity getIWinBoLLActivity(String tag) {
|
||||
return mActivityListMap.get(tag);
|
||||
Activity getActivityByTag(String tag) {
|
||||
return (mActivityListMap.get(tag) == null) ?null: mActivityListMap.get(tag).getActivity();
|
||||
}
|
||||
|
||||
/**
|
||||
* 找到tag 绑定的 BaseActivity ,通过 getTaskId() 移动到前台
|
||||
*/
|
||||
public <T extends IWinBoLLActivity> void resumeActivity(Context context, String tag) {
|
||||
LogUtils.d(TAG, "resumeActivty");
|
||||
T iWinBoLLActivity = (T)getIWinBoLLActivity(tag);
|
||||
LogUtils.d(TAG, "activity " + iWinBoLLActivity.getTag());
|
||||
if (iWinBoLLActivity != null && iWinBoLLActivity.getActivity() != null && !iWinBoLLActivity.getActivity().isFinishing() && !iWinBoLLActivity.getActivity().isDestroyed()) {
|
||||
resumeActivity(context, iWinBoLLActivity);
|
||||
//
|
||||
// 找到tag 绑定的 BaseActivity ,通过 getTaskId() 移动到前台
|
||||
//
|
||||
public <T extends IWinBoLLActivity> boolean resumeActivity(Class<T> clazz) {
|
||||
try {
|
||||
Activity activity = getActivityByTag(clazz.newInstance().getTag());
|
||||
if (activity != null && !activity.isFinishing() && !activity.isDestroyed()) {
|
||||
return resumeActivity(activity);
|
||||
}
|
||||
} catch (InstantiationException | IllegalAccessException e) {
|
||||
LogUtils.d(TAG, e, Thread.currentThread().getStackTrace());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 找到tag 绑定的 BaseActivity ,通过 getTaskId() 移动到前台
|
||||
*/
|
||||
public <T extends IWinBoLLActivity> void resumeActivity(Context context, T activity) {
|
||||
ActivityManager am = (ActivityManager) activity.getActivity().getSystemService(Context.ACTIVITY_SERVICE);
|
||||
//
|
||||
// 找到tag 绑定的 BaseActivity ,通过 getTaskId() 移动到前台
|
||||
//
|
||||
public <T extends IWinBoLLActivity> boolean resumeActivity(Activity activity) {
|
||||
ActivityManager am = (ActivityManager) activity.getSystemService(Context.ACTIVITY_SERVICE);
|
||||
//返回启动它的根任务(home 或者 MainActivity)
|
||||
Intent intent = new Intent(context, activity.getClass());
|
||||
TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
|
||||
Intent intent = new Intent(mContext, activity.getClass());
|
||||
TaskStackBuilder stackBuilder = TaskStackBuilder.create(mContext);
|
||||
stackBuilder.addNextIntentWithParentStack(intent);
|
||||
stackBuilder.startActivities();
|
||||
//moveTaskToFront(YourTaskId, 0);
|
||||
LogUtils.d(TAG, "am.moveTaskToFront");
|
||||
//ToastUtils.show("resumeActivity am.moveTaskToFront");
|
||||
am.moveTaskToFront(activity.getActivity().getTaskId(), ActivityManager.MOVE_TASK_NO_USER_ACTION);
|
||||
am.moveTaskToFront(activity.getTaskId(), ActivityManager.MOVE_TASK_NO_USER_ACTION);
|
||||
ToastUtils.show("resumeActivity");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -250,10 +221,10 @@ public class WinBoLLActivityManager {
|
||||
// ★:0 1 2 [3] 4 >> 2
|
||||
// ★:0 1 2 3 [4] >> 3
|
||||
// ★:[0] >> 直接关闭当前窗口
|
||||
IWinBoLLActivity preActivity = getPreActivity(iWinBoLLActivity);
|
||||
Activity preActivity = getPreActivity(iWinBoLLActivity);
|
||||
iWinBoLLActivity.getActivity().finish();
|
||||
if (preActivity != null) {
|
||||
resumeActivity(mContext, preActivity);
|
||||
resumeActivity(preActivity);
|
||||
}
|
||||
}
|
||||
|
||||
@ -262,7 +233,7 @@ public class WinBoLLActivityManager {
|
||||
}
|
||||
}
|
||||
|
||||
IWinBoLLActivity getPreActivity(IWinBoLLActivity iWinBoLLActivity) {
|
||||
Activity getPreActivity(IWinBoLLActivity iWinBoLLActivity) {
|
||||
try {
|
||||
boolean bingo = false;
|
||||
IWinBoLLActivity preIWinBoLLActivity = null;
|
||||
@ -276,7 +247,7 @@ public class WinBoLLActivityManager {
|
||||
}
|
||||
|
||||
if (bingo) {
|
||||
return preIWinBoLLActivity;
|
||||
return preIWinBoLLActivity.getActivity();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LogUtils.d(TAG, e, Thread.currentThread().getStackTrace());
|
||||
|
Loading…
x
Reference in New Issue
Block a user