GameBar: Implemented show/hide launcher icon
This commit is contained in:
@@ -67,10 +67,6 @@
|
||||
android:icon="@mipmap/ic_gamebar_launcher"
|
||||
android:theme="@style/Theme.SubSettingsBase.Expressive"
|
||||
android:exported="true">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
<intent-filter>
|
||||
<action android:name="com.android.settings.action.IA_SETTINGS" />
|
||||
</intent-filter>
|
||||
@@ -82,6 +78,18 @@
|
||||
android:resource="@drawable/ic_gamebar" />
|
||||
</activity>
|
||||
|
||||
<activity-alias
|
||||
android:name="com.android.gamebar.GameBarLauncher"
|
||||
android:targetActivity=".GameBarSettingsActivity"
|
||||
android:label="@string/app_title"
|
||||
android:icon="@mipmap/ic_gamebar_launcher"
|
||||
android:exported="true">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity-alias>
|
||||
|
||||
<!-- GameBar Overlay Tile Service -->
|
||||
<service
|
||||
android:name=".GameBarTileService"
|
||||
|
||||
@@ -4,6 +4,11 @@
|
||||
SPDX-License-Identifier: Apache-2.0
|
||||
-->
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item
|
||||
android:id="@+id/menu_show_launcher_icon"
|
||||
android:title="@string/show_launcher_icon"
|
||||
android:checkable="true"
|
||||
android:showAsAction="never" />
|
||||
<item
|
||||
android:id="@+id/menu_log_monitor"
|
||||
android:title="Log Monitor"
|
||||
|
||||
@@ -161,4 +161,7 @@
|
||||
<string name="warning_proceed">Proceed</string>
|
||||
<string name="warning_cancel">Cancel</string>
|
||||
|
||||
<!-- Show/Hide Launcher Icon -->
|
||||
<string name="show_launcher_icon">Show launcher icon</string>
|
||||
|
||||
</resources>
|
||||
@@ -3,10 +3,12 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
|
||||
package com.android.gamebar
|
||||
|
||||
import android.content.ComponentName
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.provider.Settings
|
||||
@@ -17,10 +19,14 @@ import com.android.settingslib.collapsingtoolbar.CollapsingToolbarBaseActivity
|
||||
import com.android.gamebar.R
|
||||
|
||||
class GameBarSettingsActivity : CollapsingToolbarBaseActivity() {
|
||||
|
||||
private val LAUNCHER_ALIAS_NAME = "com.android.gamebar.GameBarLauncher"
|
||||
|
||||
companion object {
|
||||
private const val OVERLAY_PERMISSION_REQUEST_CODE = 1234
|
||||
private const val REQUEST_CODE_OPEN_CSV = 1001
|
||||
private const val PREFS_NAME = "GameBarSettings"
|
||||
private const val KEY_SHOW_LAUNCHER_ICON = "show_launcher_icon"
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
@@ -60,11 +66,22 @@ class GameBarSettingsActivity : CollapsingToolbarBaseActivity() {
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||
menuInflater.inflate(R.menu.gamebar_settings_menu, menu)
|
||||
val showLauncherIconItem = menu.findItem(R.id.menu_show_launcher_icon)
|
||||
val prefs = getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE)
|
||||
showLauncherIconItem.isChecked = prefs.getBoolean(KEY_SHOW_LAUNCHER_ICON, true)
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
return when (item.itemId) {
|
||||
R.id.menu_show_launcher_icon -> {
|
||||
val prefs = getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE)
|
||||
val isChecked = !item.isChecked
|
||||
item.isChecked = isChecked
|
||||
prefs.edit().putBoolean(KEY_SHOW_LAUNCHER_ICON, isChecked).apply()
|
||||
setLauncherIconEnabled(isChecked)
|
||||
true
|
||||
}
|
||||
R.id.menu_log_monitor -> {
|
||||
try {
|
||||
startActivity(Intent(this, GameBarLogActivity::class.java))
|
||||
@@ -92,6 +109,16 @@ class GameBarSettingsActivity : CollapsingToolbarBaseActivity() {
|
||||
else -> super.onOptionsItemSelected(item)
|
||||
}
|
||||
}
|
||||
|
||||
private fun setLauncherIconEnabled(enabled: Boolean) {
|
||||
val componentName = ComponentName(this, LAUNCHER_ALIAS_NAME)
|
||||
val state = if (enabled) {
|
||||
PackageManager.COMPONENT_ENABLED_STATE_ENABLED
|
||||
} else {
|
||||
PackageManager.COMPONENT_ENABLED_STATE_DISABLED
|
||||
}
|
||||
packageManager.setComponentEnabledSetting(componentName, state, PackageManager.DONT_KILL_APP)
|
||||
}
|
||||
|
||||
private fun openExternalLogFile() {
|
||||
val intent = Intent(Intent.ACTION_OPEN_DOCUMENT).apply {
|
||||
|
||||
Reference in New Issue
Block a user