This commit is contained in:
JerryXiao 2023-11-24 00:24:07 +08:00
parent 19d785d1e9
commit c1e6416c93
Signed by: Jerry
GPG key ID: 22618F758B5BE2E5

View file

@ -40,12 +40,14 @@ public class EasterDream extends DreamService {
private SharedPreferences prefs; private SharedPreferences prefs;
private Drawable wallPaperDrawable = null; private Drawable wallPaperDrawable = null;
private FrameLayout last = null; private FrameLayout rootLayout = null;
private FrameLayout lastDreamLayout = null;
private boolean enabled = false; 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 dreamLayout = new FrameLayout(this);
dreamLayout.setVisibility(View.GONE);
final DisplayMetrics dm = getResources().getDisplayMetrics(); final DisplayMetrics dm = getResources().getDisplayMetrics();
final float dp = dm.density; final float dp = dm.density;
@ -58,7 +60,7 @@ public class EasterDream extends DreamService {
mLogo = new ImageView(this); mLogo = new ImageView(this);
mLogo.setVisibility(View.GONE); mLogo.setVisibility(View.GONE);
mLogo.setImageResource(R.drawable.t_platlogo); mLogo.setImageResource(R.drawable.t_platlogo);
layout.addView(mLogo, lp); dreamLayout.addView(mLogo, lp);
mBg = new BubblesDrawable(this); mBg = new BubblesDrawable(this);
mBg.setLevel(0); mBg.setLevel(0);
@ -66,37 +68,41 @@ public class EasterDream extends DreamService {
mBg.padding = 0.5f * dp; mBg.padding = 0.5f * dp;
mBg.minR = 1 * dp; mBg.minR = 1 * dp;
if (wallPaperDrawable != null) { if (wallPaperDrawable != null) {
layout.setBackground(new LayerDrawable(new Drawable[]{wallPaperDrawable, mBg})); dreamLayout.setBackground(new LayerDrawable(new Drawable[]{wallPaperDrawable, mBg}));
} }
else { else {
layout.setBackground(mBg); dreamLayout.setBackground(mBg);
} }
mBg.chooseEmojiSet(); mBg.chooseEmojiSet();
mLogo.setVisibility(View.VISIBLE); mLogo.setVisibility(View.VISIBLE);
mBg.setLevel(10000); mBg.setLevel(10000);
if (last == null) setContentView(layout);
if (lastDreamLayout == null) {
dreamLayout.setVisibility(View.VISIBLE);
rootLayout.addView(dreamLayout);
}
else { else {
layout.setAlpha(0f); dreamLayout.setAlpha(0f);
layout.setVisibility(View.VISIBLE); dreamLayout.setVisibility(View.VISIBLE);
addContentView(layout, new ViewGroup.LayoutParams(last.getWidth(), last.getHeight())); rootLayout.addView(dreamLayout);
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); dreamLayout.animate().alpha(1f).setDuration(animDuration).setListener(null);
last.animate() final FrameLayout lastDreamLayoutFinal = lastDreamLayout;
lastDreamLayoutFinal.animate()
.alpha(0f) .alpha(0f)
.setDuration(animDuration) .setDuration(animDuration)
.setListener(new AnimatorListenerAdapter() { .setListener(new AnimatorListenerAdapter() {
@Override @Override
public void onAnimationEnd(Animator animation) { public void onAnimationEnd(Animator animation) {
last.setVisibility(View.GONE); lastDreamLayoutFinal.setVisibility(View.GONE);
setContentView(layout); rootLayout.removeView(lastDreamLayoutFinal);
layout.setVisibility(View.VISIBLE);
} }
}); });
} }
last = layout; lastDreamLayout = dreamLayout;
} }
@Override @Override
@ -124,6 +130,10 @@ public class EasterDream extends DreamService {
wallPaperDrawable = wallPaperManager.getDrawable(); wallPaperDrawable = wallPaperManager.getDrawable();
} }
} }
rootLayout = new FrameLayout(this);
setContentView(rootLayout);
refresh(); refresh();
} }