Removed shortcuts.xml, Changed shortcut icon, to lower case "Start stopwatch".

This commit is contained in:
MohitMaliDeveloper
2022-11-21 12:57:55 +05:30
parent 260fb70612
commit ea217b9988
47 changed files with 99 additions and 72 deletions

View File

@ -51,23 +51,6 @@ class App : Application(), LifecycleObserver {
}
checkUseEnglish()
if (isNougatMR1Plus()) {
val shortcutManager = getSystemService(ShortcutManager::class.java)
val intent = Intent(this, SplashActivity::class.java).apply {
putExtra(OPEN_TAB, TAB_STOPWATCH)
putExtra(TOGGLE_STOPWATCH, true)
action = STOPWATCH_TOGGLE_ACTION
}
val shortcut = ShortcutInfo.Builder(this, STOPWATCH_SHORTCUT_ID)
.setShortLabel(getString(R.string.stopwatch))
.setLongLabel(getString(R.string.start_stopwatch))
.setIcon(Icon.createWithResource(this, R.drawable.ic_stopwatch_vector))
.setIntent(
intent
)
.build()
shortcutManager.dynamicShortcuts = listOf(shortcut)
}
}
override fun onTerminate() {

View File

@ -1,7 +1,11 @@
package com.simplemobiletools.clock.activities
import android.annotation.SuppressLint
import android.content.Intent
import android.content.pm.ShortcutInfo
import android.graphics.drawable.ColorDrawable
import android.graphics.drawable.Icon
import android.graphics.drawable.LayerDrawable
import android.os.Bundle
import android.view.WindowManager
import android.widget.ImageView
@ -69,8 +73,44 @@ class MainActivity : SimpleActivity() {
}
setupTabColors()
checkShortcuts()
}
@SuppressLint("NewApi")
private fun checkShortcuts() {
val appIconColor = config.appIconColor
if (isNougatMR1Plus() && config.lastHandledShortcutColor != appIconColor) {
val launchDialpad = getLaunchStopwatchShortcut(appIconColor)
try {
shortcutManager.dynamicShortcuts = listOf(launchDialpad)
config.lastHandledShortcutColor = appIconColor
} catch (ignored: Exception) {
}
}
}
@SuppressLint("NewApi")
private fun getLaunchStopwatchShortcut(appIconColor: Int): ShortcutInfo {
val newEvent = getString(R.string.start_stopwatch)
val drawable = resources.getDrawable(R.drawable.shortcut_stopwatch)
(drawable as LayerDrawable).findDrawableByLayerId(R.id.shortcut_stopwatch_background).applyColorFilter(appIconColor)
val bmp = drawable.convertToBitmap()
val intent = Intent(this, SplashActivity::class.java).apply {
putExtra(OPEN_TAB, TAB_STOPWATCH)
putExtra(TOGGLE_STOPWATCH, true)
action = STOPWATCH_TOGGLE_ACTION
}
return ShortcutInfo.Builder(this, STOPWATCH_SHORTCUT_ID)
.setShortLabel(newEvent)
.setLongLabel(newEvent)
.setIcon(Icon.createWithBitmap(bmp))
.setIntent(intent)
.build()
}
override fun onPause() {
super.onPause()
storeStateVariables()