设置与应用级别与入口级别概念。在附加组件添加与删除时,就是应用入口的添加与删除问题。应用组件根据应用级别来组合,应用视图元素根据应用入口级别来组合。
This commit is contained in:
@@ -47,8 +47,6 @@ android {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
api fileTree(dir: 'libs', include: ['*.jar'])
|
||||
|
||||
// https://mvnrepository.com/artifact/com.jzxiang.pickerview/TimePickerDialog
|
||||
api 'com.jzxiang.pickerview:TimePickerDialog:1.0.1'
|
||||
|
||||
@@ -76,4 +74,5 @@ dependencies {
|
||||
|
||||
api 'cc.winboll.studio:libaes:15.11.0'
|
||||
api 'cc.winboll.studio:libappbase:15.11.0'
|
||||
api fileTree(dir: 'libs', include: ['*.jar'])
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#Created by .winboll/winboll_app_build.gradle
|
||||
#Thu Nov 13 16:25:50 HKT 2025
|
||||
#Sat Nov 15 08:45:48 GMT 2025
|
||||
stageCount=2
|
||||
libraryProject=
|
||||
baseVersion=15.11
|
||||
publishVersion=15.11.1
|
||||
buildCount=0
|
||||
buildCount=21
|
||||
baseBetaVersion=15.11.2
|
||||
|
||||
@@ -9,9 +9,9 @@
|
||||
android:shortcutLongLabel="@string/open_appplus"
|
||||
android:shortcutDisabledMessage="@string/appplus_open_disabled">
|
||||
<intent
|
||||
android:action="cc.winboll.studio.positions.MainActivity.ACTION_OPEN_APPPLUS"
|
||||
android:action="cc.winboll.studio.positions.App.ACTION_OPEN_APPPLUS"
|
||||
android:targetPackage="cc.winboll.studio.positions.beta"
|
||||
android:targetClass="cc.winboll.studio.positions.MainActivity"
|
||||
android:targetClass="cc.winboll.studio.positions.activities.ShortcutActionActivity"
|
||||
android:data="open_appplus" />
|
||||
|
||||
<categories android:name="android.shortcut.conversation" />
|
||||
|
||||
@@ -9,9 +9,9 @@
|
||||
android:shortcutLongLabel="@string/close_appplus"
|
||||
android:shortcutDisabledMessage="@string/appplus_close_disabled">
|
||||
<intent
|
||||
android:action="cc.winboll.studio.positions.MainActivity.ACTION_CLOSE_APPPLUS"
|
||||
android:action="cc.winboll.studio.positions.App.ACTION_CLOSE_APPPLUS"
|
||||
android:targetPackage="cc.winboll.studio.positions.beta"
|
||||
android:targetClass="cc.winboll.studio.positions.MainActivity"
|
||||
android:targetClass="cc.winboll.studio.positions.activities.ShortcutActionActivity"
|
||||
android:data="close_appplus" />
|
||||
|
||||
<categories android:name="android.shortcut.conversation" />
|
||||
|
||||
@@ -3,17 +3,32 @@
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="cc.winboll.studio.positions">
|
||||
|
||||
<!-- 权限配置 -->
|
||||
<!-- 只能在前台获取精确的位置信息 -->
|
||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
|
||||
|
||||
<!-- 只有在前台运行时才能获取大致位置信息 -->
|
||||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
|
||||
|
||||
<!-- 在后台使用位置信息 -->
|
||||
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION"/>
|
||||
|
||||
<!-- 运行前台服务 -->
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
|
||||
|
||||
<!-- 运行“location”类型的前台服务 -->
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_LOCATION"/>
|
||||
|
||||
<!-- 拥有完全的网络访问权限 -->
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
<!-- 仅保留Android 8.0以下所需权限,若最低版本≥API26可移除 -->
|
||||
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
|
||||
<!-- 安装快捷方式 -->
|
||||
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>
|
||||
|
||||
<!-- 读取您共享存储空间中的内容 -->
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
|
||||
|
||||
<!-- 修改或删除您共享存储空间中的内容 -->
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
|
||||
|
||||
<uses-feature
|
||||
android:name="android.hardware.location.gps"
|
||||
@@ -27,12 +42,11 @@
|
||||
android:resizeableActivity="true"
|
||||
android:name=".App">
|
||||
|
||||
<!-- 主Activity(核心页面,非启动入口) -->
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:label="@string/app_name"
|
||||
android:exported="true">
|
||||
|
||||
android:exported="true">
|
||||
|
||||
<intent-filter>
|
||||
|
||||
<category android:name="android.intent.category.DEFAULT"/>
|
||||
@@ -48,12 +62,11 @@
|
||||
<data android:mimeType="text/x-json"/>
|
||||
|
||||
</intent-filter>
|
||||
|
||||
</activity>
|
||||
|
||||
<!-- 独立CrashActivity(替换内部类声明,避免实例化失败) -->
|
||||
<activity android:name=".activities.CrashActivity"/>
|
||||
|
||||
<!-- Wukong 别名入口(默认禁用,通过代码启用) -->
|
||||
<activity-alias
|
||||
android:name=".MainActivityWukong"
|
||||
android:targetActivity=".MainActivity"
|
||||
@@ -63,17 +76,19 @@
|
||||
android:enabled="true">
|
||||
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER"/>
|
||||
|
||||
</intent-filter>
|
||||
|
||||
<!-- 长按图标快捷菜单 -->
|
||||
<meta-data
|
||||
android:name="android.app.shortcuts"
|
||||
android:resource="@xml/shortcutsmain" />
|
||||
android:resource="@xml/shortcutsmain"/>
|
||||
|
||||
</activity-alias>
|
||||
|
||||
<!-- Laojun 别名入口(默认禁用,通过代码启用) -->
|
||||
<activity-alias
|
||||
android:name=".MainActivityLaojun"
|
||||
android:targetActivity=".MainActivity"
|
||||
@@ -83,59 +98,65 @@
|
||||
android:enabled="false">
|
||||
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER"/>
|
||||
|
||||
</intent-filter>
|
||||
|
||||
<!-- 长按图标快捷菜单 -->
|
||||
<meta-data
|
||||
android:name="android.app.shortcuts"
|
||||
android:resource="@xml/shortcutsplus" />
|
||||
android:resource="@xml/shortcutsplus"/>
|
||||
|
||||
</activity-alias>
|
||||
|
||||
<!-- 屏幕适配配置 -->
|
||||
<meta-data
|
||||
android:name="android.max_aspect"
|
||||
android:value="4.0"/>
|
||||
|
||||
<!-- 其他Activity -->
|
||||
<activity android:name="cc.winboll.studio.positions.activities.LocationActivity"/>
|
||||
|
||||
<!-- Google服务版本配置 -->
|
||||
<meta-data
|
||||
android:name="com.google.android.gms.version"
|
||||
android:value="@integer/google_play_services_version"/>
|
||||
|
||||
<!-- 服务声明 -->
|
||||
<service
|
||||
android:name=".services.MainService"
|
||||
android:exported="false"/>
|
||||
|
||||
<service
|
||||
android:name=".services.AssistantService"
|
||||
android:exported="false"/>
|
||||
|
||||
<service
|
||||
android:name=".services.DistanceRefreshService"
|
||||
android:exported="false"/>
|
||||
|
||||
<!-- 广播接收器 -->
|
||||
<receiver android:name="cc.winboll.studio.positions.receivers.MotionStatusReceiver">
|
||||
|
||||
<intent-filter>
|
||||
|
||||
<action android:name="cc.winboll.studio.positions.receivers.MotionStatusReceiver"/>
|
||||
|
||||
</intent-filter>
|
||||
|
||||
</receiver>
|
||||
|
||||
<!-- 声明文件提供者(如需对外分享保存的文件,可选) -->
|
||||
<provider
|
||||
android:name="androidx.core.content.FileProvider"
|
||||
android:authorities="${applicationId}.fileprovider"
|
||||
android:exported="false"
|
||||
android:grantUriPermissions="true">
|
||||
<meta-data
|
||||
android:name="android.support.FILE_PROVIDER_PATHS"
|
||||
android:resource="@xml/file_paths" />
|
||||
</provider>
|
||||
|
||||
|
||||
<provider
|
||||
android:name="androidx.core.content.FileProvider"
|
||||
android:authorities="${applicationId}.fileprovider"
|
||||
android:exported="false"
|
||||
android:grantUriPermissions="true">
|
||||
|
||||
<meta-data
|
||||
android:name="android.support.FILE_PROVIDER_PATHS"
|
||||
android:resource="@xml/file_paths"/>
|
||||
|
||||
</provider>
|
||||
|
||||
<activity android:name="cc.winboll.studio.positions.activities.ShortcutActionActivity"/>
|
||||
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
|
||||
</manifest>
|
||||
@@ -23,9 +23,8 @@ import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
import cc.winboll.studio.libaes.utils.WinBoLLActivityManager;
|
||||
import cc.winboll.studio.libappbase.GlobalApplication;
|
||||
import cc.winboll.studio.libappbase.LogUtils;
|
||||
import cc.winboll.studio.libappbase.ToastUtils;
|
||||
import cc.winboll.studio.positions.activities.WinBoLLActivity;
|
||||
import cc.winboll.studio.positions.utils.MyActivityLifecycleCallbacks;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.Closeable;
|
||||
@@ -47,8 +46,15 @@ public class App extends GlobalApplication {
|
||||
|
||||
public static volatile AppLevel _mAppLevel = AppLevel.WUKONG;
|
||||
|
||||
private static Handler MAIN_HANDLER = new Handler(Looper.getMainLooper());
|
||||
public static final String COMPONENT_WUKONG = "cc.winboll.studio.positions.MainActivityWukong";
|
||||
public static final String COMPONENT_LAOJUN = "cc.winboll.studio.positions.MainActivityLaojun";
|
||||
public static final String ACTION_OPEN_APPPLUS = "cc.winboll.studio.positions.App.ACTION_OPEN_APPPLUS";
|
||||
public static final String ACTION_CLOSE_APPPLUS = "cc.winboll.studio.positions.App.ACTION_CLOSE_APPPLUS";
|
||||
|
||||
private static Handler MAIN_HANDLER = new Handler(Looper.getMainLooper());
|
||||
|
||||
MyActivityLifecycleCallbacks mMyActivityLifecycleCallbacks;
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
@@ -66,28 +72,9 @@ public class App extends GlobalApplication {
|
||||
|
||||
//CrashHandler.getInstance().registerGlobal(this);
|
||||
//CrashHandler.getInstance().registerPart(this);
|
||||
mMyActivityLifecycleCallbacks = new MyActivityLifecycleCallbacks();
|
||||
registerActivityLifecycleCallbacks(mMyActivityLifecycleCallbacks);
|
||||
}
|
||||
|
||||
|
||||
public static void setAppLevel(WinBoLLActivity activity) {
|
||||
// 根据应用当前启动入口设定整体应用级别
|
||||
String launchComponent = activity.getComponentName().getClassName();
|
||||
boolean isAliasLaunch = launchComponent.endsWith("MainActivityLaojun");
|
||||
|
||||
if (isAliasLaunch) {
|
||||
// Alias入口启动逻辑(如切换应用级别、加载专属配置)
|
||||
LogUtils.d(TAG, "通过Alias入口启动,切换为LAOJUN级别");
|
||||
//ToastUtils.show("通过Alias入口启动,切换为LAOJUN级别");
|
||||
App._mAppLevel = AppLevel.LAOJUN; // 结合之前定义的枚举
|
||||
// 执行Alias专属初始化...
|
||||
} else {
|
||||
// 原入口启动逻辑
|
||||
LogUtils.d(TAG, "通过原入口启动,默认WUKONG级别");
|
||||
//ToastUtils.show("通过原入口启动,默认WUKONG级别");
|
||||
App._mAppLevel = AppLevel.WUKONG;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void write(InputStream input, OutputStream output) throws IOException {
|
||||
byte[] buf = new byte[1024 * 8];
|
||||
|
||||
@@ -34,11 +34,8 @@ import cc.winboll.studio.positions.utils.ServiceUtil;
|
||||
*/
|
||||
public class MainActivity extends WinBoLLActivity implements IWinBoLLActivity {
|
||||
public static final String TAG = "MainActivity";
|
||||
public static final String COMPONENT_WUKONG = "cc.winboll.studio.positions.MainActivityWukong";
|
||||
public static final String COMPONENT_LAOJUN = "cc.winboll.studio.positions.MainActivityLaojun";
|
||||
public static final String ACTION_OPEN_APPPLUS = "cc.winboll.studio.positions.MainActivity.ACTION_OPEN_APPPLUS";
|
||||
public static final String ACTION_CLOSE_APPPLUS = "cc.winboll.studio.positions.MainActivity.ACTION_CLOSE_APPPLUS";
|
||||
// 权限请求码(建议定义为类常量,避免魔法值)
|
||||
|
||||
// 权限请求码(建议定义为类常量,避免魔法值)
|
||||
private static final int REQUEST_LOCATION_PERMISSIONS = 1001;
|
||||
private static final int REQUEST_BACKGROUND_LOCATION_PERMISSION = 1002;
|
||||
|
||||
@@ -48,7 +45,7 @@ public class MainActivity extends WinBoLLActivity implements IWinBoLLActivity {
|
||||
private Toolbar mToolbar;
|
||||
// 服务相关:服务实例、绑定状态标记
|
||||
//private DistanceRefreshService mDistanceService;
|
||||
private boolean isServiceBound = false;
|
||||
//private boolean isServiceBound = false;
|
||||
|
||||
|
||||
@Override
|
||||
@@ -89,13 +86,10 @@ public class MainActivity extends WinBoLLActivity implements IWinBoLLActivity {
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main); // 关联主页面布局
|
||||
// 处理应用级别的切换请求
|
||||
handleSwitchRequest();
|
||||
|
||||
// 处理启动时的分享 Intent
|
||||
handleShareIntent(getIntent());
|
||||
|
||||
// 设置当前应用级别
|
||||
App.setAppLevel(this);
|
||||
|
||||
// 1. 初始化顶部 Toolbar(保留原逻辑,设置页面标题)
|
||||
initToolbar();
|
||||
@@ -109,22 +103,6 @@ public class MainActivity extends WinBoLLActivity implements IWinBoLLActivity {
|
||||
//bindDistanceService();
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理应用图标快捷菜单的请求
|
||||
*/
|
||||
private void handleSwitchRequest() {
|
||||
Intent intent = getIntent();
|
||||
if (intent != null && "open_appplus".equals(intent.getDataString())) {
|
||||
ToastUtils.show("已添加" + getString(R.string.app_name) + "附加组件");
|
||||
APPPlusUtils.openAPPPlus(this);
|
||||
moveTaskToBack(true);
|
||||
}
|
||||
if (intent != null && "close_appplus".equals(intent.getDataString())) {
|
||||
ToastUtils.show("已移除" + getString(R.string.app_name) + "附加组件");
|
||||
APPPlusUtils.closeAPPPlus(this);
|
||||
moveTaskToBack(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onNewIntent(Intent intent) {
|
||||
@@ -169,9 +147,9 @@ public class MainActivity extends WinBoLLActivity implements IWinBoLLActivity {
|
||||
mToolbar = (Toolbar) findViewById(R.id.toolbar); // Java 7 显式 findViewById + 强转
|
||||
setSupportActionBar(mToolbar);
|
||||
// 给ActionBar设置标题(先判断非空,避免空指针异常)
|
||||
/*if (getSupportActionBar() != null) {
|
||||
getSupportActionBar().setTitle(getString(R.string.app_name));
|
||||
}*/
|
||||
AppLevel appLevel = AppConfigsUtil.getInstance(getApplicationContext()).getAppLevel(true);
|
||||
getSupportActionBar().setTitle(getString(R.string.app_name));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
package cc.winboll.studio.positions;
|
||||
|
||||
/**
|
||||
* @Author ZhanGSKen&豆包大模型<zhangsken@qq.com>
|
||||
* @Date 2025/11/15 15:14
|
||||
* @Describe 应用入口级别类型枚举
|
||||
*/
|
||||
public enum PointLevel {
|
||||
DORAEMON("doraemon", "叮铛级别"),
|
||||
WUKONG("wukong", "悟空级别"),
|
||||
LAOJUN("laojun", "老君级别");
|
||||
|
||||
public static final String TAG = "PointLevel";
|
||||
|
||||
// 枚举属性
|
||||
private final String code; // 编码(如 "wukong")
|
||||
private final String desc; // 描述
|
||||
|
||||
// 构造方法(Java 7 需显式定义)
|
||||
PointLevel(String code, String desc) {
|
||||
this.code = code;
|
||||
this.desc = desc;
|
||||
}
|
||||
|
||||
// Getter 方法(获取枚举属性)
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getDesc() {
|
||||
return desc;
|
||||
}
|
||||
|
||||
// 可选:根据 code 获取枚举项(便于业务使用)
|
||||
public static PointLevel getByCode(String code) {
|
||||
for (PointLevel level : values()) {
|
||||
if (level.code.equals(code)) {
|
||||
return level;
|
||||
}
|
||||
}
|
||||
return null; // 或抛出异常,根据业务需求调整
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package cc.winboll.studio.positions.activities;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.PersistableBundle;
|
||||
import cc.winboll.studio.libappbase.ToastUtils;
|
||||
import cc.winboll.studio.positions.R;
|
||||
import cc.winboll.studio.positions.utils.APPPlusUtils;
|
||||
import cc.winboll.studio.positions.utils.AppConfigsUtil;
|
||||
import cc.winboll.studio.positions.AppLevel;
|
||||
|
||||
/**
|
||||
* @Author ZhanGSKen&豆包大模型<zhangsken@qq.com>
|
||||
* @Date 2025/11/15 13:45
|
||||
* @Describe 应用快捷方式活动类
|
||||
*/
|
||||
public class ShortcutActionActivity extends Activity {
|
||||
|
||||
public static final String TAG = "ShortcutActionActivity";
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
// 处理应用级别的切换请求
|
||||
handleSwitchRequest();
|
||||
finish();
|
||||
}
|
||||
|
||||
|
||||
|
||||
// @Override
|
||||
// public void onPostCreate(Bundle savedInstanceState, PersistableBundle persistentState) {
|
||||
// super.onPostCreate(savedInstanceState, persistentState);
|
||||
// finish();
|
||||
// }
|
||||
|
||||
// @Override
|
||||
// protected void onStart() {
|
||||
// super.onStart();
|
||||
// }
|
||||
|
||||
/**
|
||||
* 处理应用图标快捷菜单的请求
|
||||
*/
|
||||
private void handleSwitchRequest() {
|
||||
Intent intent = getIntent();
|
||||
if (intent != null && "open_appplus".equals(intent.getDataString())) {
|
||||
ToastUtils.show("已添加" + getString(R.string.app_name) + "附加组件");
|
||||
AppConfigsUtil.getInstance(getApplicationContext()).setAppLevel(AppLevel.LAOJUN);
|
||||
APPPlusUtils.openAPPPlus(this);
|
||||
//moveTaskToBack(true);
|
||||
}
|
||||
if (intent != null && "close_appplus".equals(intent.getDataString())) {
|
||||
ToastUtils.show("已移除" + getString(R.string.app_name) + "附加组件");
|
||||
AppConfigsUtil.getInstance(getApplicationContext()).setAppLevel(AppLevel.WUKONG);
|
||||
APPPlusUtils.closeAPPPlus(this);
|
||||
//moveTaskToBack(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,11 +12,19 @@ import androidx.appcompat.app.AppCompatActivity;
|
||||
import cc.winboll.studio.libaes.interfaces.IWinBoLLActivity;
|
||||
import cc.winboll.studio.libaes.utils.WinBoLLActivityManager;
|
||||
import cc.winboll.studio.libappbase.LogUtils;
|
||||
import cc.winboll.studio.libappbase.ToastUtils;
|
||||
import cc.winboll.studio.positions.App;
|
||||
import cc.winboll.studio.positions.PointLevel;
|
||||
import cc.winboll.studio.positions.R;
|
||||
import cc.winboll.studio.positions.utils.ActivityAliasUtils;
|
||||
import cc.winboll.studio.positions.utils.AppConfigsUtil;
|
||||
|
||||
public class WinBoLLActivity extends AppCompatActivity implements IWinBoLLActivity {
|
||||
|
||||
public static final String TAG = "WinBoLLActivity";
|
||||
|
||||
public static volatile PointLevel _mPointLevel = PointLevel.WUKONG;
|
||||
|
||||
@Override
|
||||
public Activity getActivity() {
|
||||
return this;
|
||||
@@ -30,18 +38,67 @@ public class WinBoLLActivity extends AppCompatActivity implements IWinBoLLActivi
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
//ToastUtils.show("onResume");
|
||||
|
||||
// ActivityAliasUtils 工具使用示例
|
||||
//
|
||||
// // 获取真实的目标组件名(即使通过 alias 启动,也能拿到 OriginalActivity)
|
||||
// String realTargetName = ActivityAliasUtils.getRealTargetNameFromIntent(this);
|
||||
// LogUtils.d("AliasActivity", "真实组件名:" + realTargetName);
|
||||
// 获取真实的目标组件名(即使通过 alias 启动,也能拿到 OriginalActivity)
|
||||
// String realTargetName = ActivityAliasUtils.getRealTargetNameFromIntent(this);
|
||||
// LogUtils.d(TAG, "真实组件名:" + realTargetName);
|
||||
// ToastUtils.show(realTargetName);
|
||||
// // 判断某个组件是否为 alias
|
||||
// String componentName = "com.winboll.app.AliasActivity";
|
||||
// boolean isAlias = ActivityAliasUtils.isActivityAlias(getApplicationContext(), componentName);
|
||||
// LogUtils.d("判断结果", componentName + " 是否为 alias:" + isAlias); // true
|
||||
// // 获取启动当前 Activity 的组件名(兼容 alias 场景)
|
||||
// String launchComponent = ActivityAliasUtils.getLaunchComponentName(this);
|
||||
// LogUtils.d("MainActivity", "启动组件名:" + launchComponent);
|
||||
|
||||
/*
|
||||
* 应用入口逻辑模块
|
||||
*/
|
||||
//
|
||||
// 检查当前活动的启动组件名,设置应用入口级别。
|
||||
String launchComponent = ActivityAliasUtils.getLaunchComponentName(this);
|
||||
LogUtils.d("MainActivity", "启动组件名:" + launchComponent);
|
||||
ToastUtils.show(launchComponent);
|
||||
// 当前应用处于活动暂停的状态时,就检查应用的入口组件名称,设置应用入口级别。
|
||||
if (WinBoLLActivity._mPointLevel == PointLevel.DORAEMON) {
|
||||
if (launchComponent.equals(App.COMPONENT_WUKONG)) {
|
||||
getSupportActionBar().setTitle(getString(R.string.appplus_name));
|
||||
ToastUtils.show("WUKONG");
|
||||
_mPointLevel = PointLevel.WUKONG;
|
||||
} else if (launchComponent.equals(App.COMPONENT_LAOJUN)) {
|
||||
getSupportActionBar().setTitle(getString(R.string.app_name));
|
||||
ToastUtils.show("LAOJUN");
|
||||
_mPointLevel = PointLevel.LAOJUN;
|
||||
} else {
|
||||
// 如果是其他应用组件入口,就关闭活动
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 应用级别设置模块
|
||||
*/
|
||||
// 读取并配置应用级别
|
||||
App._mAppLevel = AppConfigsUtil.getInstance(getApplicationContext()).getAppLevel(true);
|
||||
|
||||
LogUtils.d(TAG, String.format("onResume %s", getTag()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
/*if (item.getItemId() == R.id.item_log) {
|
||||
WinBoLLActivityManager.getInstance().startLogActivity(this);
|
||||
return true;
|
||||
} else if (item.getItemId() == R.id.item_home) {
|
||||
startActivity(new Intent(this, MainActivity.class));
|
||||
return true;
|
||||
}*/
|
||||
WinBoLLActivityManager.getInstance().startLogActivity(this);
|
||||
return true;
|
||||
} else if (item.getItemId() == R.id.item_home) {
|
||||
startActivity(new Intent(this, MainActivity.class));
|
||||
return true;
|
||||
}*/
|
||||
// 在switch语句中处理每个ID,并在处理完后返回true,未处理的情况返回false。
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
@@ -9,12 +9,14 @@ package cc.winboll.studio.positions.models;
|
||||
import android.util.JsonWriter;
|
||||
import android.util.JsonReader;
|
||||
import java.io.IOException;
|
||||
import cc.winboll.studio.positions.AppLevel;
|
||||
|
||||
public class AppConfigsModel extends BaseBean {
|
||||
|
||||
public static final String TAG = "AppConfigsModel";
|
||||
|
||||
boolean isEnableMainService;
|
||||
AppLevel appLevel;
|
||||
|
||||
public AppConfigsModel(boolean isEnableMainService) {
|
||||
this.isEnableMainService = isEnableMainService;
|
||||
@@ -24,6 +26,14 @@ public class AppConfigsModel extends BaseBean {
|
||||
this.isEnableMainService = false;
|
||||
}
|
||||
|
||||
public void setAppLevel(AppLevel appLevel) {
|
||||
this.appLevel = appLevel;
|
||||
}
|
||||
|
||||
public AppLevel getAppLevel() {
|
||||
return appLevel;
|
||||
}
|
||||
|
||||
public void setIsEnableMainService(boolean isEnableMainService) {
|
||||
this.isEnableMainService = isEnableMainService;
|
||||
}
|
||||
@@ -42,6 +52,7 @@ public class AppConfigsModel extends BaseBean {
|
||||
public void writeThisToJsonWriter(JsonWriter jsonWriter) throws IOException {
|
||||
super.writeThisToJsonWriter(jsonWriter);
|
||||
jsonWriter.name("isEnableDistanceRefreshService").value(isEnableMainService());
|
||||
jsonWriter.name("appLevel").value(getAppLevel().ordinal());
|
||||
}
|
||||
|
||||
// JSON反序列化(加载位置数据,校验字段)
|
||||
@@ -52,6 +63,8 @@ public class AppConfigsModel extends BaseBean {
|
||||
} else {
|
||||
if (name.equals("isEnableDistanceRefreshService")) {
|
||||
setIsEnableMainService(jsonReader.nextBoolean());
|
||||
} else if (name.equals("appLevel")) {
|
||||
setAppLevel((AppLevel.values()[jsonReader.nextInt()]));
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import android.content.pm.PackageManager;
|
||||
import android.os.Build;
|
||||
import android.widget.Toast;
|
||||
import cc.winboll.studio.libappbase.LogUtils;
|
||||
import cc.winboll.studio.positions.App;
|
||||
import cc.winboll.studio.positions.MainActivity;
|
||||
|
||||
public class APPPlusUtils {
|
||||
@@ -32,11 +33,11 @@ public class APPPlusUtils {
|
||||
}
|
||||
|
||||
PackageManager pm = context.getPackageManager();
|
||||
ComponentName plusComponentLaojun = new ComponentName(context, MainActivity.COMPONENT_LAOJUN);
|
||||
ComponentName plusComponentWuKong = new ComponentName(context, MainActivity.COMPONENT_WUKONG);
|
||||
ComponentName plusComponentLaojun = new ComponentName(context, App.COMPONENT_LAOJUN);
|
||||
//ComponentName plusComponentWuKong = new ComponentName(context, MainActivity.COMPONENT_WUKONG);
|
||||
|
||||
try {
|
||||
disableComponent(pm, plusComponentWuKong);
|
||||
//disableComponent(pm, plusComponentWuKong);
|
||||
enableComponent(pm, plusComponentLaojun);
|
||||
|
||||
// 2. 创建 Laojun 组件对应的快捷方式(自动去重)
|
||||
@@ -75,11 +76,11 @@ public class APPPlusUtils {
|
||||
}
|
||||
|
||||
PackageManager pm = context.getPackageManager();
|
||||
ComponentName plusComponentLaojun = new ComponentName(context, MainActivity.COMPONENT_LAOJUN);
|
||||
ComponentName plusComponentWuKong = new ComponentName(context, MainActivity.COMPONENT_WUKONG);
|
||||
ComponentName plusComponentLaojun = new ComponentName(context, App.COMPONENT_LAOJUN);
|
||||
//ComponentName plusComponentWuKong = new ComponentName(context, MainActivity.COMPONENT_WUKONG);
|
||||
|
||||
disableComponent(pm, plusComponentLaojun);
|
||||
enableComponent(pm, plusComponentWuKong);
|
||||
//enableComponent(pm, plusComponentWuKong);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,148 @@
|
||||
package cc.winboll.studio.positions.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.text.TextUtils;
|
||||
import cc.winboll.studio.libappbase.LogUtils;
|
||||
|
||||
/**
|
||||
* @Author ZhanGSKen&豆包大模型<zhangsken@qq.com>
|
||||
* @Date 2025/11/15 15:23
|
||||
* @Describe Activity Alias 工具类(兼容 Android 所有版本,Java 7 语法)
|
||||
* 用于获取 activity-alias 对应的原始 Activity 组件名、判断 alias 类型、获取启动组件名等
|
||||
*/
|
||||
public class ActivityAliasUtils {
|
||||
private static final String TAG = "ActivityAliasUtils";
|
||||
|
||||
/**
|
||||
* 获取 activity-alias 指向的原始 Activity 组件名
|
||||
*
|
||||
* @param context 上下文(建议用 ApplicationContext)
|
||||
* @param aliasName activity-alias 的组件名(完整路径,如 ".AliasActivity" 或 "com.winboll.app.AliasActivity")
|
||||
* @return 原始 Activity 的完整组件名(如 "com.winboll.app.OriginalActivity"),失败返回 null
|
||||
*/
|
||||
public static String getTargetActivityName(Context context, String aliasName) {
|
||||
// 校验参数
|
||||
if (context == null || TextUtils.isEmpty(aliasName)) {
|
||||
LogUtils.e(TAG, "getTargetActivityName: context is null or aliasName is empty");
|
||||
return null;
|
||||
}
|
||||
|
||||
// 补全组件名(若传入的是短名,自动拼接包名)
|
||||
String fullAliasName = aliasName.startsWith(".")
|
||||
? context.getPackageName() + aliasName
|
||||
: aliasName;
|
||||
|
||||
try {
|
||||
// 1. 获取 PackageManager
|
||||
PackageManager packageManager = context.getPackageManager();
|
||||
|
||||
// 2. 解析 activity-alias 的 ActivityInfo(flag 必须设为 PackageManager.GET_META_DATA,否则可能获取不到 targetActivity)
|
||||
ActivityInfo aliasActivityInfo = packageManager.getActivityInfo(
|
||||
new android.content.ComponentName(context.getPackageName(), fullAliasName),
|
||||
PackageManager.GET_META_DATA
|
||||
);
|
||||
|
||||
// 3. 获取 targetActivity(原始 Activity 组件名)
|
||||
String targetActivity = aliasActivityInfo.targetActivity;
|
||||
if (TextUtils.isEmpty(targetActivity)) {
|
||||
LogUtils.e(TAG, "getTargetActivityName: targetActivity is empty for alias " + fullAliasName);
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. 补全原始 Activity 的完整包名(若 targetActivity 是短名)
|
||||
String fullTargetName = targetActivity.startsWith(".")
|
||||
? context.getPackageName() + targetActivity
|
||||
: targetActivity;
|
||||
|
||||
LogUtils.d(TAG, "getTargetActivityName: alias=" + fullAliasName + ", target=" + fullTargetName);
|
||||
return fullTargetName;
|
||||
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
LogUtils.e(TAG, "getTargetActivityName: alias not found - " + fullAliasName, e);
|
||||
} catch (Exception e) {
|
||||
LogUtils.e(TAG, "getTargetActivityName: unknown error", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断某个组件名是否为 activity-alias(而非原始 Activity)
|
||||
*
|
||||
* @param context 上下文
|
||||
* @param componentName 待判断的组件名(完整路径)
|
||||
* @return true:是 activity-alias;false:不是或判断失败
|
||||
*/
|
||||
public static boolean isActivityAlias(Context context, String componentName) {
|
||||
// 调用 getTargetActivityName,若返回非空,则说明是 alias
|
||||
return !TextUtils.isEmpty(getTargetActivityName(context, componentName));
|
||||
}
|
||||
|
||||
/**
|
||||
* 从启动的 Intent 中获取实际的目标组件名(处理 alias 场景)
|
||||
* 适用于 Activity 中获取自身真实组件名(原始 Activity 名)
|
||||
*
|
||||
* @param context 当前 Activity 上下文
|
||||
* @return 真实的目标组件名(原始 Activity 名,若为 alias 启动则返回原始 Activity,否则返回自身)
|
||||
*/
|
||||
public static String getRealTargetNameFromIntent(Context context) {
|
||||
if (context == null) {
|
||||
LogUtils.e(TAG, "getRealTargetNameFromIntent: context is null");
|
||||
return null;
|
||||
}
|
||||
|
||||
// 获取当前 Activity 的组件名(可能是 alias)
|
||||
String currentComponentName = context.getClass().getName();
|
||||
// 检查是否为 alias,若是则返回 target,否则返回自身
|
||||
String targetName = getTargetActivityName(context, currentComponentName);
|
||||
return TextUtils.isEmpty(targetName) ? currentComponentName : targetName;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前活动上下文(Activity)的启动组件名(即启动时使用的组件名,可能是 alias 或原始 Activity)
|
||||
* 场景:若通过 alias 启动 Activity,返回 alias 名;若直接启动原始 Activity,返回原始 Activity 名
|
||||
*
|
||||
* @param context 当前 Activity 上下文(必须是 Activity 实例,不能是 ApplicationContext)
|
||||
* @return 启动组件的完整名,失败返回 null
|
||||
*/
|
||||
public static String getLaunchComponentName(Context context) {
|
||||
// 1. 校验上下文类型(必须是 Activity,否则无法获取启动 Intent)
|
||||
if (context == null) {
|
||||
LogUtils.e(TAG, "getLaunchComponentName: context is null");
|
||||
return null;
|
||||
}
|
||||
if (!(context instanceof android.app.Activity)) {
|
||||
LogUtils.e(TAG, "getLaunchComponentName: context must be Activity instance, current is " + context.getClass().getName());
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
// 2. 获取启动当前 Activity 的 Intent
|
||||
android.app.Activity activity = (android.app.Activity) context;
|
||||
Intent launchIntent = activity.getIntent();
|
||||
if (launchIntent == null) {
|
||||
LogUtils.e(TAG, "getLaunchComponentName: launch Intent is null");
|
||||
return null;
|
||||
}
|
||||
|
||||
// 3. 从 Intent 中获取启动组件名(ComponentName)
|
||||
android.content.ComponentName componentName = launchIntent.getComponent();
|
||||
if (componentName == null) {
|
||||
LogUtils.e(TAG, "getLaunchComponentName: ComponentName is null in launch Intent");
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. 获取组件的完整类名(即启动时使用的组件名)
|
||||
String launchComponentName = componentName.getClassName();
|
||||
LogUtils.d(TAG, "getLaunchComponentName: current launch component is " + launchComponentName);
|
||||
return launchComponentName;
|
||||
|
||||
} catch (Exception e) {
|
||||
LogUtils.e(TAG, "getLaunchComponentName: failed to get launch component name", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package cc.winboll.studio.positions.utils;
|
||||
import android.content.Context;
|
||||
import cc.winboll.studio.positions.AppLevel;
|
||||
import cc.winboll.studio.positions.models.AppConfigsModel;
|
||||
import cc.winboll.studio.positions.App;
|
||||
|
||||
/**
|
||||
* @Author ZhanGSKen&豆包大模型<zhangsken@qq.com>
|
||||
@@ -58,11 +60,27 @@ public class AppConfigsUtil {
|
||||
}
|
||||
|
||||
public void setIsEnableMainService(boolean isEnableMainService) {
|
||||
if(mAppConfigsModel == null) {
|
||||
if (mAppConfigsModel == null) {
|
||||
mAppConfigsModel = new AppConfigsModel();
|
||||
}
|
||||
mAppConfigsModel.setIsEnableMainService(isEnableMainService);
|
||||
saveConfigs();
|
||||
}
|
||||
|
||||
public AppLevel getAppLevel(boolean isReloadConfigs) {
|
||||
if (isReloadConfigs) {
|
||||
loadConfigs();
|
||||
}
|
||||
return (mAppConfigsModel == null) ?AppLevel.WUKONG: mAppConfigsModel.getAppLevel();
|
||||
}
|
||||
|
||||
public void setAppLevel(AppLevel appLevel) {
|
||||
if (mAppConfigsModel == null) {
|
||||
mAppConfigsModel = new AppConfigsModel();
|
||||
}
|
||||
App._mAppLevel = appLevel;
|
||||
mAppConfigsModel.setAppLevel(appLevel);
|
||||
saveConfigs();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
package cc.winboll.studio.positions.utils;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Application;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import cc.winboll.studio.libappbase.LogUtils;
|
||||
import cc.winboll.studio.libappbase.ToastUtils;
|
||||
import cc.winboll.studio.positions.PointLevel;
|
||||
import cc.winboll.studio.positions.activities.WinBoLLActivity;
|
||||
|
||||
/**
|
||||
* @Author ZhanGSKen&豆包大模型<zhangsken@qq.com>
|
||||
* @Date 2025/11/15 15:59
|
||||
* @Describe 应用活动窗口状态响应类
|
||||
* 主要用于设置应用级别与组件状态
|
||||
*/
|
||||
public class MyActivityLifecycleCallbacks implements Application.ActivityLifecycleCallbacks {
|
||||
|
||||
public static final String TAG = "MyActivityLifecycleCallbacks";
|
||||
|
||||
public String mInfo = "";
|
||||
|
||||
public MyActivityLifecycleCallbacks() {
|
||||
|
||||
}
|
||||
|
||||
void createActivityeInfo(Activity activity) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
Intent receivedIntent = activity.getIntent();
|
||||
sb.append("\nCallingActivity : \n");
|
||||
if (activity.getCallingActivity() != null) {
|
||||
sb.append(activity.getCallingActivity().getPackageName());
|
||||
}
|
||||
sb.append("\nReceived Intent Package : \n");
|
||||
sb.append(receivedIntent.getPackage());
|
||||
|
||||
Bundle extras = receivedIntent.getExtras();
|
||||
if (extras != null) {
|
||||
for (String key : extras.keySet()) {
|
||||
sb.append("\nIntentInfo");
|
||||
sb.append("\n键: ");
|
||||
sb.append(key);
|
||||
sb.append(", 值: ");
|
||||
sb.append(extras.get(key));
|
||||
//Log.d("IntentInfo", "键: " + key + ", 值: " + extras.get(key));
|
||||
}
|
||||
}
|
||||
mInfo = sb.toString();
|
||||
//Log.d("IntentInfo", "发送Intent的应用包名: " + senderPackage);
|
||||
}
|
||||
|
||||
public void showActivityeInfo() {
|
||||
//ToastUtils.show("ActivityeInfo : " + mInfo);
|
||||
LogUtils.d(TAG, "ActivityeInfo : " + mInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
|
||||
// 在这里可以做一些初始化相关的操作,例如记录Activity的创建时间等
|
||||
//System.out.println(activity.getLocalClassName() + " was created");
|
||||
LogUtils.d(TAG, activity.getLocalClassName() + " was created");
|
||||
createActivityeInfo(activity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityStarted(Activity activity) {
|
||||
//System.out.println(activity.getLocalClassName() + " was started");
|
||||
LogUtils.d(TAG, activity.getLocalClassName() + " was started");
|
||||
//createActivityeInfo(activity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResumed(Activity activity) {
|
||||
//System.out.println(activity.getLocalClassName() + " was resumed");
|
||||
LogUtils.d(TAG, activity.getLocalClassName() + " was resumed");
|
||||
//createActivityeInfo(activity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityPaused(Activity activity) {
|
||||
ToastUtils.show("Activity Paused");
|
||||
// 应用从正在活动状态抽离出来时,设置应用入口级别状态,设置为时空虚幻而不确定的哆啦A梦级别。
|
||||
WinBoLLActivity._mPointLevel = PointLevel.DORAEMON;
|
||||
//System.out.println(activity.getLocalClassName() + " was paused");
|
||||
LogUtils.d(TAG, activity.getLocalClassName() + " was paused");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityStopped(Activity activity) {
|
||||
//System.out.println(activity.getLocalClassName() + " was stopped");
|
||||
LogUtils.d(TAG, activity.getLocalClassName() + " was stopped");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivitySaveInstanceState(Activity activity, Bundle outState) {
|
||||
// 可以在这里添加保存状态的自定义逻辑
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityDestroyed(Activity activity) {
|
||||
//System.out.println(activity.getLocalClassName() + " was destroyed");
|
||||
LogUtils.d(TAG, activity.getLocalClassName() + " was destroyed");
|
||||
}
|
||||
}
|
||||
@@ -35,6 +35,8 @@ import java.util.List;
|
||||
import java.util.Locale;
|
||||
import cc.winboll.studio.positions.App;
|
||||
import cc.winboll.studio.positions.AppLevel;
|
||||
import cc.winboll.studio.positions.activities.WinBoLLActivity;
|
||||
import cc.winboll.studio.positions.PointLevel;
|
||||
|
||||
public class PositionTaskListView extends LinearLayout {
|
||||
// 视图模式常量
|
||||
@@ -486,9 +488,9 @@ public class PositionTaskListView extends LinearLayout {
|
||||
Button btnCancel = dialogView.findViewById(R.id.btn_dialog_cancel);
|
||||
Button btnSave = dialogView.findViewById(R.id.btn_dialog_save);
|
||||
HourglassView hourglassView = dialogView.findViewById(R.id.hourglassView);
|
||||
if (App._mAppLevel == AppLevel.WUKONG) {
|
||||
if (WinBoLLActivity._mPointLevel == PointLevel.WUKONG) {
|
||||
hourglassView.setVisibility(View.GONE);
|
||||
} else if (App._mAppLevel == AppLevel.WUKONG) {
|
||||
} else if (WinBoLLActivity._mPointLevel == PointLevel.LAOJUN) {
|
||||
hourglassView.setHourglassId("hourglass_001");
|
||||
hourglassView.setHour(1);
|
||||
hourglassView.setMinute(30);
|
||||
|
||||
@@ -9,9 +9,9 @@
|
||||
android:shortcutLongLabel="@string/open_appplus"
|
||||
android:shortcutDisabledMessage="@string/appplus_open_disabled">
|
||||
<intent
|
||||
android:action="cc.winboll.studio.positions.MainActivity.ACTION_OPEN_APPPLUS"
|
||||
android:action="cc.winboll.studio.positions.App.ACTION_OPEN_APPPLUS"
|
||||
android:targetPackage="cc.winboll.studio.positions"
|
||||
android:targetClass="cc.winboll.studio.positions.MainActivity"
|
||||
android:targetClass="cc.winboll.studio.positions.activities.ShortcutActionActivity"
|
||||
android:data="open_appplus" />
|
||||
|
||||
<categories android:name="android.shortcut.conversation" />
|
||||
|
||||
@@ -9,9 +9,9 @@
|
||||
android:shortcutLongLabel="@string/close_appplus"
|
||||
android:shortcutDisabledMessage="@string/appplus_close_disabled">
|
||||
<intent
|
||||
android:action="cc.winboll.studio.positions.MainActivity.ACTIO_CLOSE_APPPLUS"
|
||||
android:action="cc.winboll.studio.positions.App.ACTION_CLOSE_APPPLUS"
|
||||
android:targetPackage="cc.winboll.studio.positions"
|
||||
android:targetClass="cc.winboll.studio.positions.MainActivity"
|
||||
android:targetClass="cc.winboll.studio.positions.activities.ShortcutActionActivity"
|
||||
android:data="close_appplus" />
|
||||
|
||||
<categories android:name="android.shortcut.conversation" />
|
||||
|
||||
Reference in New Issue
Block a user