Skip to content

Commit b97b212

Browse files
committed
feat: Add Cat Editor, Rocket Launcher shortcuts (#550)
Signed-off-by: Hu Shenghao <dede.hu@qq.com>
1 parent c859ff1 commit b97b212

File tree

26 files changed

+163
-13
lines changed

26 files changed

+163
-13
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
- Add to favorites in Cat Editor
99
- Add Bengali translation, Thanks for [@ChildishRifty7](https://github.com/childishrifty7) 's contribution
1010
- Rocket Launcher add icon collection selection [#554](https://github.com/hushenghao/AndroidEasterEggs/issues/554)
11+
- Add Cat Editor, Rocket Launcher shortcuts [#550](https://github.com/hushenghao/AndroidEasterEggs/issues/550)
1112
- Cat Editor bottom menu bar optimization
1213
- Fix Cat Editor draw problem on Android N [#37138664](https://issuetracker.google.com/issues/37138664)
1314
- Fix Cat Editor color hvs palette maxWidth [#522](https://github.com/hushenghao/AndroidEasterEggs/issues/522)

CHANGELOG_zh.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
- 新增 Cat Editor 收藏功能
99
- 新增孟加拉语翻译,感谢 [@ChildishRifty7](https://github.com/childishrifty7) 的贡献
1010
- Rocket Launcher 添加图标集选择 [#554](https://github.com/hushenghao/AndroidEasterEggs/issues/554)
11+
- 添加 Cat Editor, Rocket Launcher 快捷方式 [#550](https://github.com/hushenghao/AndroidEasterEggs/issues/550)
1112
- Cat Editor 底部菜单栏优化
1213
- 修复 Cat Editor 在 Android N 的绘制问题 [#37138664](https://issuetracker.google.com/issues/37138664)
1314
- 修复 Cat Editor hvs颜色选择器最大宽度 [#522](https://github.com/hushenghao/AndroidEasterEggs/issues/522)

app/src/main/AndroidManifest.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@
6767
<category android:name="android.intent.category.DEFAULT" />
6868
</intent-filter>
6969

70+
<meta-data
71+
android:name="android.app.shortcuts"
72+
android:resource="@xml/shortcuts" />
7073
</activity>
7174
</application>
7275

app/src/main/java/com/dede/android_eggs/views/main/EasterEggsNavHost.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import com.dede.android_eggs.views.main.compose.rememberKonfettiState
3030
import com.dede.android_eggs.views.timeline.TimelineListDialog
3131
import com.dede.basic.Utils
3232

33+
const val ACTION_CAT_EDITOR = "com.dede.android_eggs.action.CAT_EDITOR"
3334

3435
private const val TRANSITION_DURATION = 400
3536

@@ -100,5 +101,9 @@ fun EasterEggsNavHost(
100101
LocalEvent.Receiver(ACTION_SHOE_ANDROID_NEXT_DIALOG) {
101102
navController.navigate(AndroidNextTimelineDialog.route)
102103
}
104+
105+
LocalEvent.Receiver(ACTION_CAT_EDITOR) {
106+
navController.navigate(CatEditorScreen.route)
107+
}
103108
}
104109
}

app/src/main/java/com/dede/android_eggs/views/main/util/IntentHandler.kt

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ import android.net.Uri
66
import android.os.Build
77
import android.os.Bundle
88
import android.util.Log
9+
import com.dede.android_eggs.util.LocalEvent
10+
import com.dede.android_eggs.views.main.ACTION_CAT_EDITOR
11+
import com.dede.android_eggs.views.settings.compose.prefs.launchRocketLauncher
12+
import com.dede.basic.delay
913
import com.dede.basic.provider.EasterEgg
1014
import dagger.hilt.android.qualifiers.ActivityContext
1115
import java.util.Calendar
@@ -17,14 +21,16 @@ class IntentHandler @Inject constructor(@ActivityContext val context: Context) {
1721

1822
private const val TAG = "IntentHandler"
1923

20-
// from widget module
21-
const val EXTRA_FROM_WIDGET = "extra_from_widget"
2224
}
2325

2426
@Inject
2527
lateinit var easterEggs: List<@JvmSuppressWildcards EasterEgg>
2628

27-
private val eggHandlers: Array<EggHandler> = arrayOf(FromWidgetHandler(), UriHandler())
29+
private val eggHandlers: Array<EggHandler> = arrayOf(
30+
StaticShortcutHandler(),
31+
FromWidgetHandler(),
32+
UriHandler(),
33+
)
2834

2935
fun handleIntent(intent: Intent?): Boolean {
3036
if (intent == null) return false
@@ -38,9 +44,40 @@ class IntentHandler @Inject constructor(@ActivityContext val context: Context) {
3844
return false
3945
}
4046

47+
private class StaticShortcutHandler : EggHandler {
48+
49+
companion object {
50+
// from static shortcut
51+
const val EXTRA_STATIC_SHORTCUT_ACTION = "extra_static_shortcut_action"
52+
53+
private const val ACTION_ROCKET_LAUNCHER = "com.dede.android_eggs.action.ROCKET_LAUNCHER"
54+
}
55+
56+
override fun handleEggIntent(eggIntent: EggIntent): Boolean {
57+
val action = eggIntent.extras.getString(EXTRA_STATIC_SHORTCUT_ACTION)
58+
when (action) {
59+
ACTION_CAT_EDITOR -> {
60+
delay(500L) {
61+
// await for the app to be ready
62+
LocalEvent.poster().post(ACTION_CAT_EDITOR)
63+
}
64+
return true
65+
}
66+
ACTION_ROCKET_LAUNCHER -> {
67+
launchRocketLauncher(eggIntent.context)
68+
return true
69+
}
70+
}
71+
return false
72+
}
73+
}
74+
4175
private class FromWidgetHandler : EggHandler {
4276

4377
companion object {
78+
// from widget module
79+
private const val EXTRA_FROM_WIDGET = "extra_from_widget"
80+
4481
private val hourApiLevelArray: IntArray = intArrayOf(
4582
// Calendar.HOUR [0-11]
4683
Build.VERSION_CODES.S,// 0:00

app/src/main/java/com/dede/android_eggs/views/settings/compose/prefs/RocketLauncherPref.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.dede.android_eggs.views.settings.compose.prefs
22

3+
import android.content.Context
34
import android.content.Intent
45
import androidx.compose.animation.core.animateFloatAsState
56
import androidx.compose.material.icons.Icons
@@ -27,6 +28,10 @@ import com.dede.android_eggs.views.settings.compose.basic.imageVectorIconBlock
2728
import com.dede.android_eggs.views.settings.compose.basic.rememberPrefIntState
2829
import com.dede.android_eggs.resources.R as StringR
2930

31+
fun launchRocketLauncher(context: Context) {
32+
context.startActivity(Intent(context, RocketLauncher::class.java))
33+
}
34+
3035
@Composable
3136
fun RocketLauncherPref() {
3237
val context = LocalContext.current
@@ -38,10 +43,10 @@ fun RocketLauncherPref() {
3843
ExpandOptionsPref(
3944
expandedState = expandedState,
4045
leadingIcon = Icons.Rounded.RocketLaunch,
41-
title = stringResource(com.android.launcher2.R.string.dream_name),
46+
title = stringResource(com.android.launcher2.R.string.rocket_launcher_dream_name),
4247
desc = stringResource(com.android.launcher2.R.string.rocket_launcher_desc),
4348
onClick = {
44-
context.startActivity(Intent(context, RocketLauncher::class.java))
49+
launchRocketLauncher(context)
4550
},
4651
trailingContent = { expanded ->
4752
val rotate by animateFloatAsState(

app/src/main/res/xml/shortcuts.xml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<shortcuts xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:tools="http://schemas.android.com/tools"
4+
tools:targetApi="25">
5+
6+
<shortcut
7+
android:enabled="true"
8+
android:icon="@mipmap/ic_rocket_launcher"
9+
android:shortcutId="shortcut_rocket_launcher"
10+
android:shortcutLongLabel="@string/rocket_launcher_desc"
11+
android:shortcutShortLabel="@string/rocket_launcher_dream_name">
12+
<intent
13+
android:action="android.intent.action.VIEW"
14+
android:targetClass="com.dede.android_eggs.views.main.EasterEggsActivity"
15+
android:targetPackage="com.dede.android_eggs">
16+
<extra
17+
android:name="extra_static_shortcut_action"
18+
android:value="com.dede.android_eggs.action.ROCKET_LAUNCHER" />
19+
</intent>
20+
</shortcut>
21+
22+
<shortcut
23+
android:enabled="true"
24+
android:icon="@mipmap/ic_cat_editor_launcher"
25+
android:shortcutId="shortcut_cat_editor"
26+
android:shortcutLongLabel="@string/cat_editor"
27+
android:shortcutShortLabel="@string/cat_editor">
28+
<intent
29+
android:action="android.intent.action.VIEW"
30+
android:targetClass="com.dede.android_eggs.views.main.EasterEggsActivity"
31+
android:targetPackage="com.dede.android_eggs">
32+
<extra
33+
android:name="extra_static_shortcut_action"
34+
android:value="com.dede.android_eggs.action.CAT_EDITOR" />
35+
</intent>
36+
</shortcut>
37+
38+
</shortcuts>

core/shortcut/src/main/java/com/dede/android_eggs/views/main/util/EasterEggShortcutsHelp.kt

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,14 @@ import com.dede.basic.delay
2424
import com.dede.basic.dp
2525
import com.dede.basic.provider.EasterEgg
2626
import com.dede.basic.toast
27+
import kotlin.math.max
2728
import kotlin.math.min
2829

2930
object EasterEggShortcutsHelp {
3031

3132
private const val EXTRA_SHORTCUT_ID = "extra_shortcut_id"
3233

33-
private const val DEFAULT_SHORTCUT_COUNT = 3
34+
private const val DEFAULT_MAX_SHORTCUT_COUNT = 3
3435

3536
private const val FORMAT_DYNAMIC_SHORTCUT_ID = "dynamic_shortcut_android_%d"
3637
private const val FORMAT_PIN_SHORTCUT_ID = "android_%d"
@@ -41,12 +42,17 @@ object EasterEggShortcutsHelp {
4142
) : Runnable {
4243

4344
override fun run() {
44-
val shortcutCount = min(
45+
val maxShortcutCount = min(
4546
ShortcutManagerCompat.getMaxShortcutCountPerActivity(context),
46-
DEFAULT_SHORTCUT_COUNT
47+
DEFAULT_MAX_SHORTCUT_COUNT
4748
)
48-
val subEggs = if (eggs.size > shortcutCount) {
49-
eggs.subList(0, shortcutCount)
49+
val staticShortcuts = ShortcutManagerCompat.getShortcuts(
50+
context,
51+
ShortcutManagerCompat.FLAG_MATCH_MANIFEST
52+
)
53+
val dynamicShortcutCount = max(maxShortcutCount - staticShortcuts.size, 0)
54+
val subEggs = if (eggs.size > dynamicShortcutCount) {
55+
eggs.subList(0, dynamicShortcutCount)
5056
} else {
5157
eggs
5258
}

eggs/RocketLauncher/src/main/AndroidManifest.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
android:name=".RocketLauncher"
1414
android:exported="true"
1515
android:icon="@mipmap/ic_rocket_launcher"
16-
android:label="@string/dream_name"
16+
android:label="@string/rocket_launcher_dream_name"
1717
android:roundIcon="@mipmap/ic_rocket_launcher_round"
1818
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen">
1919
<intent-filter>
@@ -28,7 +28,7 @@
2828
android:name=".RocketLauncherDream"
2929
android:exported="true"
3030
android:icon="@mipmap/ic_rocket_launcher"
31-
android:label="@string/dream_name"
31+
android:label="@string/rocket_launcher_dream_name"
3232
android:permission="android.permission.BIND_DREAM_SERVICE"
3333
android:roundIcon="@mipmap/ic_rocket_launcher_round">
3434
<intent-filter>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<resources>
33
<!-- Title of the Android Dreams (screensaver) module -->
4-
<string name="dream_name">Rocket Launcher</string>
4+
<string name="rocket_launcher_dream_name">Rocket Launcher</string>
55
<string name="rocket_launcher_desc">Easter Egg of the Launcher in Android 4.0 (Ice Cream Sandwich)</string>
66
</resources>

0 commit comments

Comments
 (0)