This commit is contained in:
JerryXiao 2023-08-18 12:24:07 +08:00
parent 9abaeb4776
commit f0cd85370f
Signed by: Jerry
GPG key ID: 22618F758B5BE2E5
3 changed files with 19 additions and 13 deletions

View file

@ -15,6 +15,8 @@ android {
versionName "1.0" versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
} }
buildTypes { buildTypes {

View file

@ -2,7 +2,6 @@
package cc.jerryxiao.easterscrsaver package cc.jerryxiao.easterscrsaver
import android.app.Activity
import android.content.Context import android.content.Context
import android.graphics.Canvas import android.graphics.Canvas
import android.graphics.drawable.Drawable import android.graphics.drawable.Drawable
@ -57,13 +56,13 @@ fun releaseIdentifiedCOLREmoji() {
cachedDrawable.clear() cachedDrawable.clear()
} }
fun Array<Bubble>.identifierCOLREmoji(activity: Activity) { fun Array<Bubble>.identifierCOLREmoji(context: Context) {
val list = ArrayList<CharSequence>() val list = ArrayList<CharSequence>()
for (bubble in this) { for (bubble in this) {
val drawable = activity.identifierEmojiDrawable(bubble.text, list) val drawable = context.identifierEmojiDrawable(bubble.text, list)
if (drawable != null) { if (drawable != null) {
bubble.drawable = drawable bubble.drawable = drawable
bubble.text = null bubble.text = null
} }
} }
} }

View file

@ -35,18 +35,15 @@ public class EasterDream extends DreamService {
private static String TAG = "easter_daydream"; private static String TAG = "easter_daydream";
private Drawable wallPaperDrawable = null; private Drawable wallPaperDrawable = null;
private FrameLayout last = null; private FrameLayout last = null;
private boolean enabled = false;
public void refresh() { public void refresh() {
final ImageView mLogo; final ImageView mLogo;
final BubblesDrawable mBg; final BubblesDrawable mBg;
final FrameLayout layout = new FrameLayout(this); final FrameLayout layout = new FrameLayout(this);
Point size = new Point();
getWindowManager().getDefaultDisplay().getRealSize(size);
final DisplayMetrics dm = getResources().getDisplayMetrics(); final DisplayMetrics dm = getResources().getDisplayMetrics();
final float dp = dm.density; final float dp = dm.density;
//final int minSide = Math.min(dm.widthPixels, dm.heightPixels); final int minSide = Math.min(dm.widthPixels, dm.heightPixels);
final int minSide = Math.min(size.x, size.y);
final int widgetSize = (int) (minSide * 0.75); final int widgetSize = (int) (minSide * 0.75);
final FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(widgetSize, widgetSize); final FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(widgetSize, widgetSize);
@ -77,7 +74,7 @@ public class EasterDream extends DreamService {
else { else {
layout.setAlpha(0f); layout.setAlpha(0f);
layout.setVisibility(View.VISIBLE); layout.setVisibility(View.VISIBLE);
addContentView(layout, new ViewGroup.LayoutParams(size.x, size.y)); addContentView(layout, new ViewGroup.LayoutParams(last.getWidth(), last.getHeight()));
int animDuration = getResources().getInteger(android.R.integer.config_longAnimTime); int animDuration = getResources().getInteger(android.R.integer.config_longAnimTime);
animDuration = Math.max(animDuration, 1500); animDuration = Math.max(animDuration, 1500);
layout.animate().alpha(1f).setDuration(animDuration).setListener(null); layout.animate().alpha(1f).setDuration(animDuration).setListener(null);
@ -96,6 +93,11 @@ public class EasterDream extends DreamService {
last = layout; last = layout;
} }
@Override
public void onDetachedFromWindow() {
super.onDetachedFromWindow();
enabled = false;
}
@Override @Override
public void onAttachedToWindow() { public void onAttachedToWindow() {
super.onAttachedToWindow(); super.onAttachedToWindow();
@ -106,6 +108,8 @@ public class EasterDream extends DreamService {
setFullscreen(true); setFullscreen(true);
// Set the dream layout // Set the dream layout
enabled = true;
WallpaperManager wallPaperManager = WallpaperManager.getInstance(this); WallpaperManager wallPaperManager = WallpaperManager.getInstance(this);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && wallPaperManager.isWallpaperSupported()) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && wallPaperManager.isWallpaperSupported()) {
if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
@ -229,13 +233,14 @@ class BubblesDrawable extends Drawable {
drawn++; drawn++;
} }
timer.schedule(new TimerTask() { if (timer != null) timer.schedule(new TimerTask() {
@Override @Override
public void run() { public void run() {
timer.cancel(); timer.cancel();
timer.purge(); timer.purge();
timer = null;
new Handler(Looper.getMainLooper()).post(() -> { new Handler(Looper.getMainLooper()).post(() -> {
context.refresh(); if (context.enabled) try { context.refresh(); } catch (Exception ignored) {}
}); });
//randomize(); //randomize();
//chooseEmojiSet(); //chooseEmojiSet();
@ -263,7 +268,7 @@ class BubblesDrawable extends Drawable {
} }
// support code // support code
if (!supportCOLR) { if (!supportCOLR) {
COLREmojiCompat.identifierCOLREmoji(mBubbs, null); COLREmojiCompat.identifierCOLREmoji(mBubbs, this.context);
} }
invalidateSelf(); invalidateSelf();
} }