From c1e6416c93a0abf615168f2ed2724eb2315d73e2 Mon Sep 17 00:00:00 2001 From: Jerry Date: Fri, 24 Nov 2023 00:24:07 +0800 Subject: [PATCH] rewrite --- .../jerryxiao/easterdream13/EasterDream.java | 40 ++++++++++++------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/com/jerryxiao/easterdream13/EasterDream.java b/app/src/main/java/com/jerryxiao/easterdream13/EasterDream.java index 6417d53..f6936fc 100644 --- a/app/src/main/java/com/jerryxiao/easterdream13/EasterDream.java +++ b/app/src/main/java/com/jerryxiao/easterdream13/EasterDream.java @@ -40,12 +40,14 @@ public class EasterDream extends DreamService { private SharedPreferences prefs; private Drawable wallPaperDrawable = null; - private FrameLayout last = null; + private FrameLayout rootLayout = null; + private FrameLayout lastDreamLayout = null; private boolean enabled = false; public void refresh() { final ImageView mLogo; final BubblesDrawable mBg; - final FrameLayout layout = new FrameLayout(this); + final FrameLayout dreamLayout = new FrameLayout(this); + dreamLayout.setVisibility(View.GONE); final DisplayMetrics dm = getResources().getDisplayMetrics(); final float dp = dm.density; @@ -58,7 +60,7 @@ public class EasterDream extends DreamService { mLogo = new ImageView(this); mLogo.setVisibility(View.GONE); mLogo.setImageResource(R.drawable.t_platlogo); - layout.addView(mLogo, lp); + dreamLayout.addView(mLogo, lp); mBg = new BubblesDrawable(this); mBg.setLevel(0); @@ -66,37 +68,41 @@ public class EasterDream extends DreamService { mBg.padding = 0.5f * dp; mBg.minR = 1 * dp; if (wallPaperDrawable != null) { - layout.setBackground(new LayerDrawable(new Drawable[]{wallPaperDrawable, mBg})); + dreamLayout.setBackground(new LayerDrawable(new Drawable[]{wallPaperDrawable, mBg})); } else { - layout.setBackground(mBg); + dreamLayout.setBackground(mBg); } mBg.chooseEmojiSet(); mLogo.setVisibility(View.VISIBLE); mBg.setLevel(10000); - if (last == null) setContentView(layout); + + if (lastDreamLayout == null) { + dreamLayout.setVisibility(View.VISIBLE); + rootLayout.addView(dreamLayout); + } else { - layout.setAlpha(0f); - layout.setVisibility(View.VISIBLE); - addContentView(layout, new ViewGroup.LayoutParams(last.getWidth(), last.getHeight())); + dreamLayout.setAlpha(0f); + dreamLayout.setVisibility(View.VISIBLE); + rootLayout.addView(dreamLayout); int animDuration = getResources().getInteger(android.R.integer.config_longAnimTime); animDuration = Math.max(animDuration, 1500); - layout.animate().alpha(1f).setDuration(animDuration).setListener(null); - last.animate() + dreamLayout.animate().alpha(1f).setDuration(animDuration).setListener(null); + final FrameLayout lastDreamLayoutFinal = lastDreamLayout; + lastDreamLayoutFinal.animate() .alpha(0f) .setDuration(animDuration) .setListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { - last.setVisibility(View.GONE); - setContentView(layout); - layout.setVisibility(View.VISIBLE); + lastDreamLayoutFinal.setVisibility(View.GONE); + rootLayout.removeView(lastDreamLayoutFinal); } }); } - last = layout; + lastDreamLayout = dreamLayout; } @Override @@ -124,6 +130,10 @@ public class EasterDream extends DreamService { wallPaperDrawable = wallPaperManager.getDrawable(); } } + + rootLayout = new FrameLayout(this); + setContentView(rootLayout); + refresh(); }