Skip to content

Commit

Permalink
Not Only Apple Can Do
Browse files Browse the repository at this point in the history
✨ Android:图标切换功能
  • Loading branch information
Stapxs committed Dec 25, 2024
1 parent 5d6718f commit d47521c
Show file tree
Hide file tree
Showing 57 changed files with 153 additions and 6 deletions.
8 changes: 8 additions & 0 deletions src/mobile/android/.idea/deploymentTargetSelector.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions src/mobile/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,34 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity-alias
android:targetActivity=".MainActivity"
android:enabled="false"
android:icon="@mipmap/ic_launcher_capacitor"
android:name=".MainActivityCapacitor"
android:roundIcon="@mipmap/ic_launcher_capacitor_round"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|smallestScreenSize|screenLayout|uiMode"
android:theme="@style/AppTheme.NoActionBarLaunch"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity-alias>
<activity-alias
android:targetActivity=".MainActivity"
android:enabled="false"
android:icon="@mipmap/ic_launcher_napcat"
android:name=".MainActivityNapcat"
android:roundIcon="@mipmap/ic_launcher_napcat_round"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|smallestScreenSize|screenLayout|uiMode"
android:theme="@style/AppTheme.NoActionBarLaunch"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity-alias>

<provider
android:name="androidx.core.content.FileProvider"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background>
<inset android:drawable="@mipmap/ic_launcher_capacitor_background" android:inset="16.7%" />
</background>
<foreground>
<inset android:drawable="@mipmap/ic_launcher_capacitor_foreground" android:inset="16.7%" />
</foreground>
</adaptive-icon>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background>
<inset android:drawable="@mipmap/ic_launcher_capacitor_background" android:inset="16.7%" />
</background>
<foreground>
<inset android:drawable="@mipmap/ic_launcher_capacitor_foreground" android:inset="16.7%" />
</foreground>
</adaptive-icon>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background>
<inset android:drawable="@mipmap/ic_launcher_napcat_background" android:inset="16.7%" />
</background>
<foreground>
<inset android:drawable="@mipmap/ic_launcher_napcat_foreground" android:inset="16.7%" />
</foreground>
</adaptive-icon>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background>
<inset android:drawable="@mipmap/ic_launcher_napcat_background" android:inset="16.7%" />
</background>
<foreground>
<inset android:drawable="@mipmap/ic_launcher_napcat_foreground" android:inset="16.7%" />
</foreground>
</adaptive-icon>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions src/renderer/src/pages/options/OptView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -357,11 +357,11 @@
// 获取当前使用的图标
const Onebot = window.Capacitor?.Plugins?.Onebot
if (Onebot) {
Onebot.getUsedIcon()
Onebot.addListener('onebot:icon', (data: any) => {
debugger
this.usedIcon = data.name.replace('AppIcon', '')
})
Onebot.getUsedIcon()
}
},
methods: {
Expand Down Expand Up @@ -477,7 +477,7 @@
if(!runtimeData.tags.darkMode && !name.endsWith('Dark')) {
iconListInfo.push({ name: name, icon: (iconList[key] as any).default })
} else if(runtimeData.tags.darkMode && name.endsWith('Dark')) {
iconListInfo.push({ name: name, icon: (iconList[key] as any).default })
iconListInfo.push({ name: name.replace('Dark', ''), icon: (iconList[key] as any).default })
}
}
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
package cn.stapxs.qqweb.connector;

import static android.content.Context.MODE_PRIVATE;

import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.util.Log;

public class Onebot {
public WebSocketClient connect(OnebotPlugin plugin, WebSocketClient webSocketClient, String value) {
Expand Down Expand Up @@ -31,4 +38,50 @@ public Boolean findService(OnebotPlugin plugin) {
scanNetwork.scanNetwork();
return true;
}

public Boolean changeIcon(OnebotPlugin plugin, String name) {
Context context = plugin.getBridge().getContext();
PackageManager packageManager = context.getPackageManager();

name = name.replace("AppIcon", "");

SharedPreferences prefs = context.getSharedPreferences("AppPrefs", MODE_PRIVATE);
String lastActivity = prefs.getString("enabled_activity", "");

try {
// 启用目标 Activity
packageManager.setComponentEnabledSetting(
new ComponentName(context.getPackageName(), getFullClassName(context, "MainActivity" + name)),
PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
PackageManager.DONT_KILL_APP
);
// 记录 Activity 状态
prefs.edit().putString("enabled_activity", name).apply();
// 停用上个 Activity
packageManager.setComponentEnabledSetting(
new ComponentName(context.getPackageName(), getFullClassName(context, "MainActivity" + lastActivity)),
PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
PackageManager.DONT_KILL_APP
);
} catch (Exception ex) {
Log.e("OneBot", "启用 Activity 失败:" + ex.getMessage());
}

return true;
}

public Boolean getUsedIcon(OnebotPlugin plugin) {
Context context = plugin.getBridge().getContext();

SharedPreferences prefs = context.getSharedPreferences("AppPrefs", MODE_PRIVATE);
String lastActivity = prefs.getString("enabled_activity", "");
plugin.sendIcon(lastActivity);

return true;
}

// ==========================
private static String getFullClassName(Context context, String activitySimpleName) {
return context.getPackageName() + "." + activitySimpleName;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ public void sendNotify(String type, String data) {
this.notifyListeners("onebot:event", ret);
}

public void sendIcon(String name) {
JSObject ret = new JSObject();
ret.put("name", name);
this.notifyListeners("onebot:icon", ret);
}

@Override
public void load() {
super.load();
Expand All @@ -40,7 +46,7 @@ public void connect(PluginCall call) {

JSObject ret = new JSObject();
webSocketClient = implementation.connect(this, webSocketClient, value);
ret.put("value", true);
ret.put("success", true);
call.resolve(ret);
}

Expand All @@ -49,21 +55,37 @@ public void send(PluginCall call) {
String value = call.getString("data");

JSObject ret = new JSObject();
ret.put("value", implementation.send(webSocketClient, value));
ret.put("success", implementation.send(webSocketClient, value));
call.resolve(ret);
}

@PluginMethod
public void close(PluginCall call) {
JSObject ret = new JSObject();
ret.put("value", implementation.close(webSocketClient));
ret.put("success", implementation.close(webSocketClient));
call.resolve(ret);
}

@PluginMethod
public void findService(PluginCall call) {
JSObject ret = new JSObject();
ret.put("value", implementation.findService(this));
ret.put("success", implementation.findService(this));
call.resolve(ret);
}

@PluginMethod
public void changeIcon(PluginCall call) {
String name = call.getString("name");

JSObject ret = new JSObject();
ret.put("success", implementation.changeIcon(this, name));
call.resolve(ret);
}

@PluginMethod
public void getUsedIcon(PluginCall call) {
JSObject ret = new JSObject();
ret.put("success", implementation.getUsedIcon(this));
call.resolve(ret);
}
}

0 comments on commit d47521c

Please sign in to comment.