diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 6ca7a7d2f..33978cfc0 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -38,8 +38,8 @@ diff --git a/app/src/main/java/io/legado/app/help/LauncherIconHelp.kt b/app/src/main/java/io/legado/app/help/LauncherIconHelp.kt new file mode 100644 index 000000000..c079ad665 --- /dev/null +++ b/app/src/main/java/io/legado/app/help/LauncherIconHelp.kt @@ -0,0 +1,54 @@ +package io.legado.app.help + +import android.content.ComponentName +import android.content.pm.PackageManager +import android.os.Build +import io.legado.app.App +import io.legado.app.ui.welcome.Launcher1 +import io.legado.app.ui.welcome.WelcomeActivity +import org.jetbrains.anko.toast + +/** + * Created by GKF on 2018/2/27. + * 更换图标 + */ +object LauncherIconHelp { + private val packageManager: PackageManager = App.INSTANCE.packageManager + private val componentNames = arrayListOf( + ComponentName(App.INSTANCE, Launcher1::class.java.name) + ) + + fun changeIcon(icon: String?) { + if (icon.isNullOrEmpty()) return + if (Build.VERSION.SDK_INT < 26) { + App.INSTANCE.toast("图标为矢量图标,Android8.0一下不支持") + return + } + var hasEnabled = false + componentNames.forEach { + if (it.className.equals(icon, true)) { + hasEnabled = true + //启用 + packageManager.setComponentEnabledSetting( + it, + PackageManager.COMPONENT_ENABLED_STATE_ENABLED, + PackageManager.DONT_KILL_APP + ) + } else { + //禁用 + packageManager.setComponentEnabledSetting( + it, + PackageManager.COMPONENT_ENABLED_STATE_DISABLED, + PackageManager.DONT_KILL_APP + ) + } + } + if (!hasEnabled) { + packageManager.setComponentEnabledSetting( + ComponentName(App.INSTANCE, WelcomeActivity::class.java.name), + PackageManager.COMPONENT_ENABLED_STATE_ENABLED, + PackageManager.DONT_KILL_APP + ) + } + } +} \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt index c90db122d..ebd65a1c5 100644 --- a/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt @@ -11,6 +11,7 @@ import io.legado.app.App import io.legado.app.R import io.legado.app.constant.EventBus import io.legado.app.help.AppConfig +import io.legado.app.help.LauncherIconHelp import io.legado.app.lib.dialogs.alert import io.legado.app.lib.dialogs.noButton import io.legado.app.lib.dialogs.yesButton @@ -26,7 +27,7 @@ class ThemeConfigFragment : PreferenceFragmentCompat(), SharedPreferences.OnShar override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { addPreferencesFromResource(R.xml.pref_config_theme) - findPreference("defaultTheme")?.summary = "${items[getPrefInt("default_theme", 0)]}" + findPreference("defaultTheme")?.summary = items[getPrefInt("default_theme", 0)] } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { @@ -47,6 +48,7 @@ class ThemeConfigFragment : PreferenceFragmentCompat(), SharedPreferences.OnShar override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) { sharedPreferences ?: return when (key) { + "launcherIcon" -> LauncherIconHelp.changeIcon(getPrefString(key)) "transparentStatusBar" -> { recreateActivities() } diff --git a/app/src/main/java/io/legado/app/ui/welcome/WelcomeActivity.kt b/app/src/main/java/io/legado/app/ui/welcome/WelcomeActivity.kt index 90245b5bc..ddc7d6422 100644 --- a/app/src/main/java/io/legado/app/ui/welcome/WelcomeActivity.kt +++ b/app/src/main/java/io/legado/app/ui/welcome/WelcomeActivity.kt @@ -48,4 +48,4 @@ open class WelcomeActivity : BaseActivity(R.layout.activity_welcome) { } -class Icon1Activity : WelcomeActivity() \ No newline at end of file +class Launcher1 : WelcomeActivity() \ No newline at end of file diff --git a/app/src/main/res/mipmap-anydpi-v26/ic_launcher_1.xml b/app/src/main/res/mipmap-anydpi-v26/launcher1.xml similarity index 100% rename from app/src/main/res/mipmap-anydpi-v26/ic_launcher_1.xml rename to app/src/main/res/mipmap-anydpi-v26/launcher1.xml diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml index 325ca9e1d..ecf038c80 100644 --- a/app/src/main/res/values/arrays.xml +++ b/app/src/main/res/values/arrays.xml @@ -139,7 +139,7 @@ ic_launcher - ic_launcher_1 + launcher1