Skip to content

Commit 815676b

Browse files
committed
feat: Add Rocked Launcher
Signed-off-by: Hu Shenghao <dede.hu@qq.com>
1 parent f929185 commit 815676b

File tree

12 files changed

+235
-31
lines changed

12 files changed

+235
-31
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
### v3.2.1
44

5+
- Add Rocked Launcher Easter Egg
56
- Optimize the setting of theme logic
67
- Optimize APK file size
78
- Project modularization

CHANGELOG_zh.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
### v3.2.1
44

5+
- 添加 Rocked Launcher 彩蛋
56
- 优化设置主题逻辑
67
- 优化 APK 文件大小
78
- 项目模块化

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

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

3+
import android.content.Intent
4+
import androidx.compose.foundation.layout.Spacer
5+
import androidx.compose.foundation.layout.height
36
import androidx.compose.foundation.layout.size
47
import androidx.compose.material.icons.Icons
8+
import androidx.compose.material.icons.outlined.RocketLaunch
59
import androidx.compose.material.icons.rounded.AppRegistration
610
import androidx.compose.runtime.Composable
711
import androidx.compose.ui.Modifier
@@ -11,12 +15,14 @@ import androidx.compose.ui.res.stringResource
1115
import androidx.compose.ui.unit.dp
1216
import androidx.lifecycle.ViewModel
1317
import androidx.lifecycle.viewmodel.compose.viewModel
14-
import com.dede.android_eggs.R
18+
import com.android.launcher2.RocketLauncher
1519
import com.dede.android_eggs.views.main.compose.EasterEggLogo
1620
import com.dede.android_eggs.views.main.util.EasterEggHelp.VersionFormatter
1721
import com.dede.android_eggs.views.settings.compose.basic.ExpandOptionsPref
22+
import com.dede.android_eggs.views.settings.compose.basic.Option
1823
import com.dede.android_eggs.views.settings.compose.basic.OptionShapes
1924
import com.dede.android_eggs.views.settings.compose.basic.SwitchOption
25+
import com.dede.android_eggs.views.settings.compose.basic.imageVectorIconBlock
2026
import com.dede.basic.provider.ComponentProvider
2127
import dagger.hilt.android.lifecycle.HiltViewModel
2228
import javax.inject.Inject
@@ -33,8 +39,20 @@ fun ComponentManagerPref(viewModel: ComponentManagerViewModel = viewModel()) {
3339
leadingIcon = Icons.Rounded.AppRegistration,
3440
title = stringResource(id = StringsR.string.label_component_manager),
3541
) {
36-
val componentCount = componentList.size
3742
val context = LocalContext.current
43+
Option(
44+
shape = OptionShapes.borderShape,
45+
leadingIcon = imageVectorIconBlock(imageVector = Icons.Outlined.RocketLaunch),
46+
title = stringResource(com.android.launcher2.R.string.dream_name),
47+
desc = stringResource(com.android.launcher2.R.string.rocket_launcher_desc),
48+
onClick = {
49+
context.startActivity(Intent(context, RocketLauncher::class.java))
50+
}
51+
)
52+
53+
Spacer(modifier = Modifier.height(1.dp))
54+
55+
val componentCount = componentList.size
3856
componentList.forEachIndexed { index, component ->
3957
val formatter = VersionFormatter.create(component.apiLevelRange, component.nicknameRes)
4058
SwitchOption(

eggs/RockedLauncher/build.gradle.kts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,4 @@ plugins {
44

55
android {
66
namespace = "com.android.launcher2"
7-
resourcePrefix("")
87
}

eggs/RockedLauncher/src/main/AndroidManifest.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
33

4-
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" />
5-
64
<application>
75
<activity
86
android:name="com.android.launcher2.RocketLauncher"
97
android:exported="true"
8+
android:icon="@drawable/ic_rocket_launch"
109
android:label="@string/dream_name"
1110
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen">
1211
<intent-filter>
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
package android.support.v13.dreams;
2+
3+
import android.content.BroadcastReceiver;
4+
import android.content.Context;
5+
import android.content.Intent;
6+
import android.content.IntentFilter;
7+
import android.graphics.Canvas;
8+
import android.os.BatteryManager;
9+
import android.util.AttributeSet;
10+
import android.util.Log;
11+
import android.view.View;
12+
import android.view.WindowManager;
13+
14+
import androidx.activity.ComponentActivity;
15+
import androidx.annotation.NonNull;
16+
17+
public class Hilt_BasicDream extends ComponentActivity {
18+
/** A simple Dream implementation that can be subclassed to write your own Dreams. Any Activity
19+
* may be used as a Dream, so this class isn't strictly necessary. However, it does take care of
20+
* a number of housekeeping tasks that most screensavers will want:
21+
* <ul>
22+
* <li>Keep the screen on as long as the device is plugged in
23+
* <li>Exit (using <code>finish()</code>) as soon as any user activity is detected
24+
* <li>Hide the system UI (courtesy its inner {@link BasicDreamView} class)
25+
* </ul>
26+
* Finally, it exposes an {@link Hilt_BasicDream#onDraw(Canvas)} method that you can override to do
27+
* your own drawing. As with a <code>View,</code> call {@link Hilt_BasicDream#invalidate()} any time
28+
* to request that a new frame be drawn.
29+
*/
30+
private final static String TAG = "BasicDream";
31+
private final static boolean DEBUG = true;
32+
33+
private View mView;
34+
private boolean mPlugged = false;
35+
36+
public class BasicDreamView extends View {
37+
/** A simple view that just calls back to {@link Hilt_BasicDream#onDraw(Canvas) onDraw} on its
38+
* parent BasicDream Activity. It also hides the system UI if this feature is available on
39+
* the current device.
40+
*/
41+
public BasicDreamView(Context c) {
42+
super(c);
43+
}
44+
45+
public BasicDreamView(Context c, AttributeSet at) {
46+
super(c, at);
47+
}
48+
49+
@Override
50+
public void onAttachedToWindow() {
51+
super.onAttachedToWindow();
52+
setSystemUiVisibility(View.STATUS_BAR_HIDDEN);
53+
}
54+
55+
@Override
56+
public void onDraw(@NonNull Canvas c) {
57+
Hilt_BasicDream.this.onDraw(c);
58+
}
59+
}
60+
61+
private final BroadcastReceiver mPowerIntentReceiver = new BroadcastReceiver() {
62+
@Override
63+
public void onReceive(Context context, Intent intent) {
64+
final String action = intent.getAction();
65+
if (Intent.ACTION_BATTERY_CHANGED.equals(action)) {
66+
// Only keep the screen on if we're plugged in.
67+
boolean plugged = (1 == intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, 0));
68+
69+
if (plugged != mPlugged) {
70+
if (DEBUG) Log.d(TAG, "now " + (plugged ? "plugged in" : "unplugged"));
71+
72+
mPlugged = plugged;
73+
if (mPlugged) {
74+
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
75+
} else {
76+
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
77+
}
78+
}
79+
}
80+
}
81+
};
82+
83+
@Override
84+
public void onStart() {
85+
super.onStart();
86+
setContentView(new BasicDreamView(this));
87+
getWindow().addFlags(
88+
WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON
89+
| WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
90+
);
91+
IntentFilter filter = new IntentFilter();
92+
filter.addAction(Intent.ACTION_BATTERY_CHANGED);
93+
registerReceiver(mPowerIntentReceiver, filter);
94+
}
95+
96+
@Override
97+
public void onPause() {
98+
super.onPause();
99+
// Anything that would pause this activity should probably end the screensaver.
100+
if (DEBUG) Log.d(TAG, "exiting onPause");
101+
finish();
102+
}
103+
104+
@Override
105+
public void onStop() {
106+
super.onStop();
107+
unregisterReceiver(mPowerIntentReceiver);
108+
}
109+
110+
protected View getContentView() {
111+
return mView;
112+
}
113+
114+
@Override
115+
public void setContentView(View v) {
116+
super.setContentView(v);
117+
mView = v;
118+
}
119+
120+
protected void invalidate() {
121+
getContentView().invalidate();
122+
}
123+
124+
public void onDraw(Canvas c) {
125+
}
126+
127+
public void onUserInteraction() {
128+
if (DEBUG) Log.d(TAG, "exiting onUserInteraction");
129+
finish();
130+
}
131+
}

eggs/RockedLauncher/src/main/java/com/android/launcher2/RocketLauncher.java

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,11 @@
2626
import android.content.ComponentName;
2727
import android.content.Context;
2828
import android.content.Intent;
29-
import android.content.pm.ApplicationInfo;
30-
import android.content.pm.PackageManager;
3129
import android.graphics.Point;
3230
import android.graphics.Rect;
3331
import android.graphics.drawable.Drawable;
3432
import android.os.Handler;
35-
import android.support.v13.dreams.BasicDream;
33+
import android.support.v13.dreams.Hilt_BasicDream;
3634
import android.util.AttributeSet;
3735
import android.util.DisplayMetrics;
3836
import android.view.MotionEvent;
@@ -41,14 +39,21 @@
4139
import android.widget.FrameLayout;
4240
import android.widget.ImageView;
4341

42+
import com.dede.basic.provider.EasterEgg;
43+
4444
import java.util.HashMap;
4545
import java.util.List;
4646
import java.util.Random;
4747

48+
import javax.inject.Inject;
49+
50+
import dagger.hilt.android.AndroidEntryPoint;
4851

49-
public class RocketLauncher extends BasicDream {
52+
@AndroidEntryPoint
53+
public class RocketLauncher extends Hilt_BasicDream {
5054
public static final boolean ROCKET_LAUNCHER = true;
5155

56+
@AndroidEntryPoint
5257
public static class Board extends FrameLayout {
5358
public static final boolean FIXED_STARS = true;
5459
public static final boolean FLYING_STARS = true;
@@ -246,33 +251,15 @@ public void randomize() {
246251

247252
TimeAnimator mAnim;
248253

254+
@Inject
255+
List<EasterEgg> mEasterEggs;
256+
249257
public Board(Context context, AttributeSet as) {
250258
super(context, as);
251259

252260
setBackgroundColor(0xFF000000);
253261

254-
// todo May be slow, ANR
255-
List<ApplicationInfo> list = context.getPackageManager().getInstalledApplications(PackageManager.GET_ACTIVITIES);
256-
HashMap<ComponentName, Drawable> icons = new HashMap<>(50);
257-
for (ApplicationInfo info : list) {
258-
if (!info.enabled) {
259-
continue;
260-
}
261-
Intent launchIntent = context.getPackageManager().getLaunchIntentForPackage(info.packageName);
262-
if (launchIntent == null) {
263-
continue;
264-
}
265-
Drawable drawable = null;
266-
try {
267-
drawable = context.getPackageManager().getApplicationIcon(info.packageName);
268-
} catch (PackageManager.NameNotFoundException ignore) {
269-
}
270-
if (drawable == null) {
271-
continue;
272-
}
273-
icons.put(launchIntent.getComponent(), drawable);
274-
}
275-
mIcons = icons;
262+
mIcons = Utils.convertComponentNameDrawableIcons(getContext(), mEasterEggs);
276263
// LauncherApplication app = (LauncherApplication)context.getApplicationContext();
277264
// mIcons = app.getIconCache().getAllIcons();
278265
mComponentNames = new ComponentName[mIcons.size()];
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package com.android.launcher2
2+
3+
import android.Manifest
4+
import android.content.ComponentName
5+
import android.content.Context
6+
import android.content.pm.PackageManager
7+
import android.graphics.drawable.Drawable
8+
import androidx.annotation.RequiresPermission
9+
import com.dede.basic.provider.EasterEgg
10+
import com.dede.basic.requireDrawable
11+
12+
object Utils {
13+
14+
@JvmStatic
15+
@RequiresPermission(Manifest.permission.QUERY_ALL_PACKAGES)
16+
fun queryAllPackagesComponentNameDrawableIcons(context: Context): HashMap<ComponentName, Drawable> {
17+
val packageManager = context.packageManager
18+
val list = packageManager
19+
.getInstalledApplications(PackageManager.GET_ACTIVITIES)
20+
val icons = HashMap<ComponentName, Drawable>()
21+
for (info in list) {
22+
if (!info.enabled) {
23+
continue
24+
}
25+
val launchComponent = packageManager
26+
.getLaunchIntentForPackage(info.packageName)?.component ?: continue
27+
val drawable: Drawable
28+
try {
29+
drawable = packageManager.getApplicationIcon(info.packageName);
30+
} catch (ignore: PackageManager.NameNotFoundException) {
31+
continue
32+
}
33+
icons[launchComponent] = drawable;
34+
}
35+
return icons
36+
}
37+
38+
@JvmStatic
39+
fun convertComponentNameDrawableIcons(
40+
context: Context,
41+
easterEggs: List<EasterEgg>
42+
): HashMap<ComponentName, Drawable> {
43+
val icons = HashMap<ComponentName, Drawable>()
44+
for (egg in easterEggs) {
45+
val drawable: Drawable = context.requireDrawable(egg.iconRes)
46+
val aClass = egg.actionClass
47+
val componentName: ComponentName = if (aClass != null) {
48+
ComponentName(context, aClass)
49+
} else {
50+
createNotFoundComponent(context, egg.hashCode())
51+
}
52+
icons[componentName] = drawable
53+
}
54+
return icons
55+
}
56+
57+
private fun createNotFoundComponent(context: Context, hash: Int): ComponentName {
58+
return ComponentName(context, "NotFound%d".format(hash))
59+
}
60+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="56dp" android:tint="#000000" android:viewportHeight="24" android:viewportWidth="24" android:width="56dp">
2+
3+
<path android:fillColor="@android:color/white" android:pathData="M9.19,6.35c-2.04,2.29 -3.44,5.58 -3.57,5.89L2,10.69l4.05,-4.05c0.47,-0.47 1.15,-0.68 1.81,-0.55L9.19,6.35L9.19,6.35zM11.17,17c0,0 3.74,-1.55 5.89,-3.7c5.4,-5.4 4.5,-9.62 4.21,-10.57c-0.95,-0.3 -5.17,-1.19 -10.57,4.21C8.55,9.09 7,12.83 7,12.83L11.17,17zM17.65,14.81c-2.29,2.04 -5.58,3.44 -5.89,3.57L13.31,22l4.05,-4.05c0.47,-0.47 0.68,-1.15 0.55,-1.81L17.65,14.81L17.65,14.81zM9,18c0,0.83 -0.34,1.58 -0.88,2.12C6.94,21.3 2,22 2,22s0.7,-4.94 1.88,-6.12C4.42,15.34 5.17,15 6,15C7.66,15 9,16.34 9,18zM13,9c0,-1.1 0.9,-2 2,-2s2,0.9 2,2s-0.9,2 -2,2S13,10.1 13,9z"/>
4+
5+
</vector>

eggs/RockedLauncher/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
<resources>
33
<!-- Title of the Android Dreams (screensaver) module -->
44
<string name="dream_name">Rocket Launcher</string>
5+
<string name="rocket_launcher_desc">Easter Egg of the Launcher in Android 4.0 (Ice Cream Sandwich)</string>
56
</resources>

0 commit comments

Comments
 (0)