From f0cd85370fe2761f6e786b4d9c391865b0474e11 Mon Sep 17 00:00:00 2001 From: Jerry Date: Fri, 18 Aug 2023 12:24:07 +0800 Subject: [PATCH] upd --- app/build.gradle | 2 ++ .../easterscrsaver/COLREmojiCompat.kt | 7 +++--- .../jerryxiao/easterscrsaver/EasterDream.java | 23 +++++++++++-------- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index b15dbad..32bb92b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -15,6 +15,8 @@ android { versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + + vectorDrawables.useSupportLibrary = true } buildTypes { diff --git a/app/src/main/java/cc/jerryxiao/easterscrsaver/COLREmojiCompat.kt b/app/src/main/java/cc/jerryxiao/easterscrsaver/COLREmojiCompat.kt index 1c8aeb4..2b1c252 100644 --- a/app/src/main/java/cc/jerryxiao/easterscrsaver/COLREmojiCompat.kt +++ b/app/src/main/java/cc/jerryxiao/easterscrsaver/COLREmojiCompat.kt @@ -2,7 +2,6 @@ package cc.jerryxiao.easterscrsaver -import android.app.Activity import android.content.Context import android.graphics.Canvas import android.graphics.drawable.Drawable @@ -57,13 +56,13 @@ fun releaseIdentifiedCOLREmoji() { cachedDrawable.clear() } -fun Array.identifierCOLREmoji(activity: Activity) { +fun Array.identifierCOLREmoji(context: Context) { val list = ArrayList() for (bubble in this) { - val drawable = activity.identifierEmojiDrawable(bubble.text, list) + val drawable = context.identifierEmojiDrawable(bubble.text, list) if (drawable != null) { bubble.drawable = drawable bubble.text = null } } -} \ No newline at end of file +} diff --git a/app/src/main/java/cc/jerryxiao/easterscrsaver/EasterDream.java b/app/src/main/java/cc/jerryxiao/easterscrsaver/EasterDream.java index a04d47b..cd8a742 100644 --- a/app/src/main/java/cc/jerryxiao/easterscrsaver/EasterDream.java +++ b/app/src/main/java/cc/jerryxiao/easterscrsaver/EasterDream.java @@ -35,18 +35,15 @@ public class EasterDream extends DreamService { private static String TAG = "easter_daydream"; private Drawable wallPaperDrawable = null; private FrameLayout last = null; + private boolean enabled = false; public void refresh() { final ImageView mLogo; final BubblesDrawable mBg; final FrameLayout layout = new FrameLayout(this); - Point size = new Point(); - getWindowManager().getDefaultDisplay().getRealSize(size); - final DisplayMetrics dm = getResources().getDisplayMetrics(); final float dp = dm.density; - //final int minSide = Math.min(dm.widthPixels, dm.heightPixels); - final int minSide = Math.min(size.x, size.y); + final int minSide = Math.min(dm.widthPixels, dm.heightPixels); final int widgetSize = (int) (minSide * 0.75); final FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(widgetSize, widgetSize); @@ -77,7 +74,7 @@ public class EasterDream extends DreamService { else { layout.setAlpha(0f); 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); animDuration = Math.max(animDuration, 1500); layout.animate().alpha(1f).setDuration(animDuration).setListener(null); @@ -96,6 +93,11 @@ public class EasterDream extends DreamService { last = layout; } + @Override + public void onDetachedFromWindow() { + super.onDetachedFromWindow(); + enabled = false; + } @Override public void onAttachedToWindow() { super.onAttachedToWindow(); @@ -106,6 +108,8 @@ public class EasterDream extends DreamService { setFullscreen(true); // Set the dream layout + enabled = true; + WallpaperManager wallPaperManager = WallpaperManager.getInstance(this); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && wallPaperManager.isWallpaperSupported()) { if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { @@ -229,13 +233,14 @@ class BubblesDrawable extends Drawable { drawn++; } - timer.schedule(new TimerTask() { + if (timer != null) timer.schedule(new TimerTask() { @Override public void run() { timer.cancel(); timer.purge(); + timer = null; new Handler(Looper.getMainLooper()).post(() -> { - context.refresh(); + if (context.enabled) try { context.refresh(); } catch (Exception ignored) {} }); //randomize(); //chooseEmojiSet(); @@ -263,7 +268,7 @@ class BubblesDrawable extends Drawable { } // support code if (!supportCOLR) { - COLREmojiCompat.identifierCOLREmoji(mBubbs, null); + COLREmojiCompat.identifierCOLREmoji(mBubbs, this.context); } invalidateSelf(); }