Support hiding app icon (#492)

This commit is contained in:
Zongle Wang 2025-04-10 10:19:19 -04:00 committed by GitHub
parent efb2df507d
commit 6f521d5ac1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 86 additions and 5 deletions

View file

@ -45,15 +45,23 @@
android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.LEANBACK_LAUNCHER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="android.service.quicksettings.action.QS_TILE_PREFERENCES" />
</intent-filter>
</activity>
<activity-alias
android:name=".MainActivityAlias"
android:exported="true"
android:targetActivity=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.LEANBACK_LAUNCHER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity-alias>
<activity
android:name=".ExternalControlActivity"
android:exported="true"
@ -197,5 +205,14 @@
<action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
</intent-filter>
</receiver>
<receiver android:name=".DialerReceiver"
android:exported="true">
<intent-filter>
<action android:name="android.provider.Telephony.SECRET_CODE" />
<!-- 252746382 is the name of Clash Meta in T9 -->
<data android:scheme="android_secret_code" android:host="252746382" />
</intent-filter>
</receiver>
</application>
</manifest>

View file

@ -1,5 +1,6 @@
package com.github.kr328.clash
import android.content.ComponentName
import android.content.pm.PackageManager
import com.github.kr328.clash.common.util.componentName
import com.github.kr328.clash.design.AppSettingsDesign
@ -17,6 +18,7 @@ class AppSettingsActivity : BaseActivity<AppSettingsDesign>(), Behavior {
ServiceStore(this),
this,
clashRunning,
::onHideIconChange,
)
setContentDesign(design)
@ -59,4 +61,17 @@ class AppSettingsActivity : BaseActivity<AppSettingsDesign>(), Behavior {
PackageManager.DONT_KILL_APP,
)
}
private fun onHideIconChange(hide: Boolean) {
val newState = if (hide) {
PackageManager.COMPONENT_ENABLED_STATE_DISABLED
} else {
PackageManager.COMPONENT_ENABLED_STATE_ENABLED
}
packageManager.setComponentEnabledSetting(
ComponentName(this, mainActivityAlias),
newState,
PackageManager.DONT_KILL_APP
)
}
}

View file

@ -0,0 +1,13 @@
package com.github.kr328.clash
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
class DialerReceiver : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
val intent = Intent(context, MainActivity::class.java)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
context.startActivity(intent)
}
}

View file

@ -158,4 +158,6 @@ class MainActivity : BaseActivity<MainDesign>() {
}
}
}
}
}
val mainActivityAlias = "${MainActivity::class.java.name}Alias"

View file

@ -19,6 +19,7 @@ class AppSettingsDesign(
srvStore: ServiceStore,
behavior: Behavior,
running: Boolean,
onHideIconChange: (hide: Boolean) -> Unit,
) : Design<AppSettingsDesign.Request>(context) {
enum class Request {
ReCreateAllActivities
@ -65,6 +66,17 @@ class AppSettingsDesign(
}
}
switch(
value = uiStore::hideAppIcon,
icon = R.drawable.ic_baseline_hide,
title = R.string.hide_app_icon_title,
summary = R.string.hide_app_icon_desc,
) {
listener = OnChangedListener {
onHideIconChange(uiStore::hideAppIcon.get())
}
}
category(R.string.service)
switch(

View file

@ -25,6 +25,11 @@ class UiStore(context: Context) {
values = DarkMode.values()
)
var hideAppIcon: Boolean by store.boolean(
key = "hide_app_icon",
defaultValue = false
)
var proxyExcludeNotSelectable by store.boolean(
key = "proxy_exclude_not_selectable",
defaultValue = false,

View file

@ -0,0 +1,12 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="?attr/colorControlNormal"
android:viewportWidth="1024"
android:viewportHeight="1024">
<path
android:fillColor="@android:color/white"
android:pathData="M825.9,134.2l51.7,51.7 -655.1,655.1 -51.7,-51.7 655.1,-655.1zM804.4,325.8c41.3,39.5 81.3,87.9 120,145.3a73.1,73.1 0,0 1,2.8 77.4l-2.8,4.4 -6.9,10.1C795.2,740.3 660,829 512,829c-58.4,0 -114.9,-13.8 -169.3,-41.4l55.1,-55.1c37.4,15.7 75.5,23.4 114.2,23.4 120.9,0 235.5,-75.1 345.1,-234l6.7,-9.8 -6.7,-9.8c-34.3,-49.7 -69,-91.2 -104.4,-124.7l51.7,-51.7zM512,195c51.4,0 101.3,10.7 149.7,32.1l-56.5,56.5A289.4,289.4 0,0 0,512 268.2c-120.9,0 -235.5,75.1 -345.1,234L160.2,512l6.7,9.8c29.5,42.8 59.4,79.5 89.7,110.3l-51.7,51.7c-36.1,-36.7 -71.3,-80.3 -105.4,-130.9a73.1,73.1 0,0 1,-2.8 -77.4l2.8,-4.4 6.9,-10.1C228.8,283.7 364,195 512,195zM664.8,465.4a161.7,161.7 0,0 1,-205.8 205.8l65.1,-65.1a88.6,88.6 0,0 0,75.6 -75.6l65.1,-65.1zM512,356.7c6.4,0 12.8,0.4 19,1.1l-179.5,179.6A161.7,161.7 0,0 1,512 356.7z" />
</vector>

View file

@ -37,6 +37,8 @@
<string name="format_profile_activated">%s 已激活</string>
<string name="format_traffic_forwarded">%s 已转发</string>
<string name="global_mode">全局模式</string>
<string name="hide_app_icon_title">隐藏应用图标</string>
<string name="hide_app_icon_desc">可以在拨号盘输入 *#*#252746382#*#* 打开应用</string>
<string name="history">历史</string>
<string name="import_from_file">从文件导入</string>
<string name="import_from_url">从 URL 导入</string>

View file

@ -341,4 +341,7 @@
<string name="external_control_activity">External Control</string>
<string name="external_control_started">Clash.Meta service started</string>
<string name="external_control_stopped">Clash.Meta service stopped</string>
<string name="hide_app_icon_title">Hide App Icon</string>
<string name="hide_app_icon_desc">You can dial *#*#252746382#*#* to open this App</string>
</resources>