20251110_205526_555

This commit is contained in:
ZhanGSKen
2025-11-10 20:55:31 +08:00
parent 17d2422690
commit 53271b21cf
13 changed files with 168 additions and 154 deletions

View File

@@ -1,8 +1,8 @@
#Created by .winboll/winboll_app_build.gradle
#Mon Nov 10 03:35:32 GMT 2025
#Mon Nov 10 12:54:12 GMT 2025
stageCount=18
libraryProject=
baseVersion=15.0
publishVersion=15.0.17
buildCount=71
buildCount=76
baseBetaVersion=15.0.18

View File

@@ -1,34 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<shortcuts xmlns:android="http://schemas.android.com/apk/res/android">
<!-- 切换启动入口的快捷菜单 -->
<shortcut
android:shortcutId="switch_launcher_main"
android:enabled="true"
android:icon="@mipmap/ic_launcher"
android:shortcutShortLabel="@string/switch_to_main"
android:shortcutLongLabel="@string/switch_to_main"
android:shortcutDisabledMessage="@string/switch_disabled">
<intent
android:action="cc.winboll.studio.positions.MainActivity"
android:targetPackage="cc.winboll.studio.positions.beta"
android:targetClass="cc.winboll.studio.positions.MainActivity"
android:data="switch_launcher_main" />
<categories android:name="android.shortcut.conversation" />
</shortcut>
<shortcut
android:shortcutId="switch_launcher_laojun"
android:enabled="true"
android:icon="@mipmap/ic_launcher"
android:shortcutShortLabel="@string/switch_to_laojun"
android:shortcutLongLabel="@string/switch_to_laojun"
android:shortcutDisabledMessage="@string/switch_disabled">
<intent
android:action="cc.winboll.studio.positions.MainActivityLaojun"
android:targetPackage="cc.winboll.studio.positions.beta"
android:targetClass="cc.winboll.studio.positions.MainActivity"
android:data="switch_launcher_laojun" />
<categories android:name="android.shortcut.conversation" />
</shortcut>
</shortcuts>

View File

@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<shortcuts xmlns:android="http://schemas.android.com/apk/res/android">
<!-- 切换启动入口的快捷菜单 -->
<shortcut
android:shortcutId="open_app_plus"
android:enabled="true"
android:icon="@mipmap/ic_launcher"
android:shortcutShortLabel="@string/open_app_plus"
android:shortcutLongLabel="@string/open_app_plus"
android:shortcutDisabledMessage="@string/app_plus_switch_disabled">
<intent
android:action="cc.winboll.studio.positions.MainActivity"
android:targetPackage="cc.winboll.studio.positions.beta"
android:targetClass="cc.winboll.studio.positions.MainActivity"
android:data="open_app_plus" />
<categories android:name="android.shortcut.conversation" />
</shortcut>
</shortcuts>

View File

@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<shortcuts xmlns:android="http://schemas.android.com/apk/res/android">
<!-- 切换启动入口的快捷菜单 -->
<shortcut
android:shortcutId="hide_app_plus"
android:enabled="true"
android:icon="@mipmap/ic_launcher"
android:shortcutShortLabel="@string/hide_app_plus"
android:shortcutLongLabel="@string/hide_app_plus"
android:shortcutDisabledMessage="@string/app_plus_switch_disabled">
<intent
android:action="cc.winboll.studio.positions.PlusActivity.ACTION_HIDE_APP_PLUS"
android:targetPackage="cc.winboll.studio.positions.beta"
android:targetClass="cc.winboll.studio.positions.PlusActivity"
android:data="hide_app_plus" />
<categories android:name="android.shortcut.conversation" />
</shortcut>
</shortcuts>

View File

@@ -48,15 +48,15 @@
<!-- 长按图标快捷菜单 -->
<meta-data
android:name="android.app.shortcuts"
android:resource="@xml/shortcuts" />
android:resource="@xml/shortcutsmain" />
</activity-alias>
<!-- Laojun 别名入口(默认禁用,通过代码启用) -->
<activity-alias
android:name=".MainActivityLaojun"
android:targetActivity=".MainActivity"
android:name=".PlusActivity"
android:targetActivity=".PlusActivity"
android:exported="true"
android:label="@string/app_laojun_name"
android:label="@string/app_plus_name"
android:icon="@mipmap/ic_launcher"
android:enabled="false"> <!-- 默认禁用,避免桌面显示 -->
@@ -68,7 +68,7 @@
<!-- 长按图标快捷菜单 -->
<meta-data
android:name="android.app.shortcuts"
android:resource="@xml/shortcuts" />
android:resource="@xml/shortcutsplus" />
</activity-alias>
<!-- 其他配置不变 -->

View File

@@ -22,7 +22,7 @@ import cc.winboll.studio.positions.activities.LocationActivity;
import cc.winboll.studio.positions.activities.WinBoLLActivity;
import cc.winboll.studio.positions.utils.AppConfigsUtil;
import cc.winboll.studio.positions.utils.ServiceUtil;
import cc.winboll.studio.positions.utils.AppIconSwitcher;
import cc.winboll.studio.positions.utils.AppIconUtils;
/**
* 主页面:仅负责
@@ -102,16 +102,13 @@ public class MainActivity extends WinBoLLActivity implements IWinBoLLActivity {
}
/**
* 处理快捷菜单的「切换入口」请求
* 处理应用图标快捷菜单的请求
*/
private void handleSwitchRequest() {
Intent intent = getIntent();
if (intent != null && "switch_launcher_main".equals(intent.getDataString())) {
ToastUtils.show("应用级别切换到悟空笔记");
AppIconSwitcher.switchToWukongIcon(this);
} else if (intent != null && "switch_launcher_laojun".equals(intent.getDataString())) {
ToastUtils.show("應用級別切換到老君道說");
AppIconSwitcher.switchToLaojunIcon(this);
if (intent != null && "open_app_plus".equals(intent.getDataString())) {
ToastUtils.show("已添加" + getString(R.string.app_name) + "附加组件");
AppIconUtils.addPlusIcon(this);
}
}

View File

@@ -0,0 +1,36 @@
package cc.winboll.studio.positions.activities;
import android.content.Intent;
import android.os.Bundle;
import cc.winboll.studio.libappbase.ToastUtils;
import cc.winboll.studio.positions.MainActivity;
import cc.winboll.studio.positions.R;
import cc.winboll.studio.positions.utils.AppIconUtils;
/**
* @Author ZhanGSKen&豆包大模型<zhangsken@qq.com>
* @Date 2025/11/10 18:17
*/
public class PlusActivity extends MainActivity {
public static final String TAG = "PlusActivity";
public static final String ACTION_HIDE_APP_PLUS = "cc.winboll.studio.positions.PlusActivity.ACTION_HIDE_APP_PLUS";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
handleSwitchRequest();
}
/**
* 处理应用图标快捷菜单的请求
*/
private void handleSwitchRequest() {
Intent intent = getIntent();
if (intent != null && "hide_app_plus".equals(intent.getDataString())) {
ToastUtils.show("已移除" + getString(R.string.app_name) + "附加组件");
AppIconUtils.addPlusIcon(this);
}
}
}

View File

@@ -12,104 +12,77 @@ import android.content.pm.PackageManager;
import android.os.Build;
import android.util.Log;
import android.widget.Toast;
import cc.winboll.studio.libappbase.LogUtils;
import cc.winboll.studio.positions.R;
import cc.winboll.studio.positions.activities.PlusActivity;
public class AppIconSwitcher {
public static final String TAG = "AppIconSwitcher";
// 组件名常量需与 AndroidManifest 一致
private static final String WUKONG_ACTIVITY = "cc.winboll.studio.positions.MainActivityWukong";
private static final String LAOJUN_ACTIVITY = "cc.winboll.studio.positions.MainActivityLaojun";
public class AppIconUtils {
public static final String TAG = "AppIconUtils";
// 快捷方式配置名称+图标需与实际资源匹配
private static final String WUKONG_SHORTCUT_NAME = "位置服务-Wukong";
private static final int WUKONG_SHORTCUT_ICON = R.drawable.ic_launcher; // Wukong 图标资源
private static final String LAOJUN_SHORTCUT_NAME = "位置服务-Laojun";
private static final int LAOJUN_SHORTCUT_ICON = R.mipmap.ic_launcher; // Laojun 图标资源
// private static final String PLUS_SHORTCUT_NAME = "位置服务-Laojun";
// private static final int PLUS_SHORTCUT_ICON = R.mipmap.ic_launcher; // Laojun 图标资源
/**
* 切换到 Laojun 图标禁用 Wukong启用 Laojun + 创建 Laojun 快捷方式
* 添加Plus组件与图标
*/
public static boolean switchToLaojunIcon(Context context) {
public static boolean addPlusIcon(Context context) {
if (context == null) {
Log.e(TAG, "切换失败:上下文为空");
LogUtils.d(TAG, "切换失败:上下文为空");
Toast.makeText(context, "图标切换失败", Toast.LENGTH_SHORT).show();
return false;
}
PackageManager pm = context.getPackageManager();
ComponentName wukongComponent = new ComponentName(context, WUKONG_ACTIVITY);
ComponentName laojunComponent = new ComponentName(context, LAOJUN_ACTIVITY);
ComponentName plusComponent = new ComponentName(context, PlusActivity.ACTION_HIDE_APP_PLUS);
try {
// 1. 禁用 Wukong 组件启用 Laojun 组件
disableComponent(pm, wukongComponent);
enableComponent(pm, laojunComponent);
enableComponent(pm, plusComponent);
// 2. 创建 Laojun 组件对应的快捷方式自动去重
boolean shortcutCreated = createComponentShortcut(context, laojunComponent, LAOJUN_SHORTCUT_NAME, LAOJUN_SHORTCUT_ICON);
// 3. 通知桌面刷新图标
context.sendBroadcast(new Intent(Intent.ACTION_PACKAGE_CHANGED)
.setData(android.net.Uri.parse("package:" + context.getPackageName())));
// 4. 反馈结果
String logMsg = shortcutCreated ? "启用 Laojun + 快捷方式创建成功" : "启用 Laojun 成功,快捷方式创建失败";
String toastMsg = shortcutCreated ? "图标切换为 Laojun已创建快捷方式" : "图标切换为 Laojun快捷方式创建失败";
Log.d(TAG, logMsg);
Toast.makeText(context, toastMsg, Toast.LENGTH_SHORT).show();
// boolean shortcutCreated = createComponentShortcut(context, plusComponent, PLUS_SHORTCUT_NAME, PLUS_SHORTCUT_ICON);
//
// // 3. 通知桌面刷新图标
// context.sendBroadcast(new Intent(Intent.ACTION_PACKAGE_CHANGED)
// .setData(android.net.Uri.parse("package:" + context.getPackageName())));
//
// // 4. 反馈结果
// String logMsg = shortcutCreated ? "启用 Laojun + 快捷方式创建成功" : "启用 Laojun 成功,快捷方式创建失败";
// String toastMsg = shortcutCreated ? "图标切换为 Laojun已创建快捷方式" : "图标切换为 Laojun快捷方式创建失败";
// LogUtils.d(TAG, logMsg);
// Toast.makeText(context, toastMsg, Toast.LENGTH_SHORT).show();
//
return true;
} catch (Exception e) {
Log.e(TAG, "Laojun 图标切换失败:" + e.getMessage());
LogUtils.e(TAG, "Laojun 图标切换失败:" + e.getMessage());
// 失败兜底启用 Wukong 组件
enableComponent(pm, wukongComponent);
Toast.makeText(context, "图标切换失败", Toast.LENGTH_SHORT).show();
//enableComponent(pm, wukongComponent);
Toast.makeText(context, "图标切换失败" + e.getMessage(), Toast.LENGTH_SHORT).show();
return false;
}
}
/**
* 切换到 Wukong 图标启用 Wukong禁用 Laojun + 创建 Wukong 快捷方式
* 移除Plus组件
*/
public static boolean switchToWukongIcon(Context context) {
public static boolean removePlusIcon(Context context) {
if (context == null) {
Log.e(TAG, "切换失败:上下文为空");
LogUtils.d(TAG, "切换失败:上下文为空");
Toast.makeText(context, "图标切换失败", Toast.LENGTH_SHORT).show();
return false;
}
PackageManager pm = context.getPackageManager();
ComponentName wukongComponent = new ComponentName(context, WUKONG_ACTIVITY);
ComponentName laojunComponent = new ComponentName(context, LAOJUN_ACTIVITY);
ComponentName plusComponent = new ComponentName(context, PlusActivity.ACTION_HIDE_APP_PLUS);
try {
// 1. 启用 Wukong 组件禁用 Laojun 组件
enableComponent(pm, wukongComponent);
disableComponent(pm, laojunComponent);
// 2. 创建 Wukong 组件对应的快捷方式自动去重
boolean shortcutCreated = createComponentShortcut(context, wukongComponent, WUKONG_SHORTCUT_NAME, WUKONG_SHORTCUT_ICON);
// 3. 通知桌面刷新图标
context.sendBroadcast(new Intent(Intent.ACTION_PACKAGE_CHANGED)
.setData(android.net.Uri.parse("package:" + context.getPackageName())));
// 4. 反馈结果
String logMsg = shortcutCreated ? "启用 Wukong + 快捷方式创建成功" : "启用 Wukong 成功,快捷方式创建失败";
String toastMsg = shortcutCreated ? "图标切换为 Wukong已创建快捷方式" : "图标切换为 Wukong快捷方式创建失败";
Log.d(TAG, logMsg);
Toast.makeText(context, toastMsg, Toast.LENGTH_SHORT).show();
return true;
disableComponent(pm, plusComponent);
return true;
} catch (Exception e) {
Log.e(TAG, "Wukong 图标切换失败:" + e.getMessage());
// 失败兜底启用 Wukong 组件
enableComponent(pm, wukongComponent);
Toast.makeText(context, "图标切换失败", Toast.LENGTH_SHORT).show();
return false;
LogUtils.d(TAG, e, Thread.currentThread().getStackTrace());
return false;
}
}
@@ -122,7 +95,7 @@ public class AppIconSwitcher {
*/
private static boolean createComponentShortcut(Context context, ComponentName component, String name, int iconRes) {
if (context == null || component == null || name == null || iconRes == 0) {
Log.e(TAG, "快捷方式创建失败:参数为空");
LogUtils.d(TAG, "快捷方式创建失败:参数为空");
return false;
}
@@ -132,14 +105,14 @@ public class AppIconSwitcher {
PackageManager pm = context.getPackageManager();
android.content.pm.ShortcutManager shortcutManager = context.getSystemService(android.content.pm.ShortcutManager.class);
if (shortcutManager == null || !shortcutManager.isRequestPinShortcutSupported()) {
Log.e(TAG, "系统不支持创建快捷方式");
LogUtils.d(TAG, "系统不支持创建快捷方式");
return false;
}
// 检查是否已存在该组件的快捷方式去重
for (android.content.pm.ShortcutInfo info : shortcutManager.getPinnedShortcuts()) {
if (component.getClassName().equals(info.getIntent().getComponent().getClassName())) {
Log.d(TAG, "快捷方式已存在:" + component.getClassName());
LogUtils.d(TAG, "快捷方式已存在:" + component.getClassName());
return true;
}
}
@@ -163,7 +136,7 @@ public class AppIconSwitcher {
return true;
} catch (Exception e) {
Log.e(TAG, "Android O+ 快捷方式创建失败:" + e.getMessage());
LogUtils.d(TAG, "Android O+ 快捷方式创建失败:" + e.getMessage());
return false;
}
} else {
@@ -187,7 +160,7 @@ public class AppIconSwitcher {
return true;
} catch (Exception e) {
Log.e(TAG, "Android O- 快捷方式创建失败:" + e.getMessage());
LogUtils.d(TAG, "Android O- 快捷方式创建失败:" + e.getMessage());
return false;
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

View File

@@ -1,7 +1,7 @@
<resources>
<string name="app_name">Positions</string>
<string name="app_laojun_name">Positions</string>
<string name="switch_to_main">切换到悟空笔记</string>
<string name="switch_to_laojun">切换到老君道說</string>
<string name="switch_disabled">切换功能不可用</string>
<string name="app_plus_name">PositionsPlus</string>
<string name="hide_app_plus">隐藏附加组件</string>
<string name="open_app_plus">开启隐藏组件</string>
<string name="app_plus_switch_disabled">隐藏组件切换功能不可用</string>
</resources>

View File

@@ -1,34 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<shortcuts xmlns:android="http://schemas.android.com/apk/res/android">
<!-- 切换启动入口的快捷菜单 -->
<shortcut
android:shortcutId="switch_launcher_main"
android:enabled="true"
android:icon="@mipmap/ic_launcher"
android:shortcutShortLabel="@string/switch_to_main"
android:shortcutLongLabel="@string/switch_to_main"
android:shortcutDisabledMessage="@string/switch_disabled">
<intent
android:action="cc.winboll.studio.positions.MainActivity"
android:targetPackage="cc.winboll.studio.positions"
android:targetClass="cc.winboll.studio.positions.MainActivity"
android:data="switch_launcher" />
<categories android:name="android.shortcut.conversation" />
</shortcut>
<shortcut
android:shortcutId="switch_launcher_laojun"
android:enabled="true"
android:icon="@mipmap/ic_launcher"
android:shortcutShortLabel="@string/switch_to_laojun"
android:shortcutLongLabel="@string/switch_to_laojun"
android:shortcutDisabledMessage="@string/switch_disabled">
<intent
android:action="cc.winboll.studio.positions.MainActivityLaojun"
android:targetPackage="cc.winboll.studio.positions"
android:targetClass="cc.winboll.studio.positions.MainActivity"
android:data="switch_launcher" />
<categories android:name="android.shortcut.conversation" />
</shortcut>
</shortcuts>

View File

@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<shortcuts xmlns:android="http://schemas.android.com/apk/res/android">
<!-- 切换启动入口的快捷菜单 -->
<shortcut
android:shortcutId="open_app_plus"
android:enabled="true"
android:icon="@mipmap/ic_launcher"
android:shortcutShortLabel="@string/open_app_plus"
android:shortcutLongLabel="@string/open_app_plus"
android:shortcutDisabledMessage="@string/app_plus_switch_disabled">
<intent
android:action="cc.winboll.studio.positions.MainActivity"
android:targetPackage="cc.winboll.studio.positions"
android:targetClass="cc.winboll.studio.positions.MainActivity"
android:data="open_app_plus" />
<categories android:name="android.shortcut.conversation" />
</shortcut>
</shortcuts>

View File

@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<shortcuts xmlns:android="http://schemas.android.com/apk/res/android">
<!-- 切换启动入口的快捷菜单 -->
<shortcut
android:shortcutId="hide_app_plus"
android:enabled="true"
android:icon="@mipmap/ic_launcher"
android:shortcutShortLabel="@string/hide_app_plus"
android:shortcutLongLabel="@string/hide_app_plus"
android:shortcutDisabledMessage="@string/app_plus_switch_disabled">
<intent
android:action="cc.winboll.studio.positions.PlusActivity.ACTION_HIDE_APP_PLUS"
android:targetPackage="cc.winboll.studio.positions"
android:targetClass="cc.winboll.studio.positions.PlusActivity"
android:data="hide_app_plus" />
<categories android:name="android.shortcut.conversation" />
</shortcut>
</shortcuts>