From a4dd79f78d64b8f57283cb67f16e95d9dec83e38 Mon Sep 17 00:00:00 2001 From: Tommy Webb Date: Thu, 25 Jul 2024 18:16:20 +0000 Subject: [PATCH] Adapt FinishActivity and outro for 14 QPR3 windowShowWallpaper behaves unexpectedly with transitions as of 14 QPR3. As a result, the changes of "Revamp outro animation" were causing the transition into the final page of the wizard to instantaneously have a transparent wallpaper background, even before the animation finished. This was jarring and odd, so now we use a regular theme until we are ready to start our animation, at which point we recreate the activity with the EdgeToEdgeWallpaperBackground (windowShowWallpaper) theme before running the animation. Change-Id: Ib19918d7d2a615aff44a48066b17ec9d2f04bac6 --- AndroidManifest.xml | 1 - .../lineageos/setupwizard/FinishActivity.java | 90 +++++++++++++++---- 2 files changed, 74 insertions(+), 17 deletions(-) diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 30d53571..f9fdd4a6 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -284,7 +284,6 @@ { + mRootView = findViewById(R.id.root); + ViewCompat.setOnApplyWindowInsetsListener(mRootView, (view, windowInsets) -> { final View linearLayout = findViewById(R.id.linear_layout); final Insets insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars()); final MarginLayoutParams params = (MarginLayoutParams) linearLayout.getLayoutParams(); @@ -64,6 +72,29 @@ public class FinishActivity extends BaseSetupWizardActivity { linearLayout.setLayoutParams(params); return WindowInsetsCompat.CONSUMED; }); + + if (sIsFinishing) { + startFinishSequence(); + } + } + + private void disableActivityTransitions() { + overrideActivityTransition(OVERRIDE_TRANSITION_OPEN, 0, 0); + overrideActivityTransition(OVERRIDE_TRANSITION_CLOSE, 0, 0); + } + + @Override + protected void applyForwardTransition() { + if (!sIsFinishing) { + super.applyForwardTransition(); + } + } + + @Override + protected void applyBackwardTransition() { + if (!sIsFinishing) { + super.applyBackwardTransition(); + } } @Override @@ -71,41 +102,68 @@ public class FinishActivity extends BaseSetupWizardActivity { return R.layout.finish_activity; } + @Override + public Resources.Theme getTheme() { + Resources.Theme theme = super.getTheme(); + if (sIsFinishing) { + if (mEdgeToEdgeWallpaperBackgroundTheme == null) { + theme.applyStyle(R.style.EdgeToEdgeWallpaperBackground, true); + mEdgeToEdgeWallpaperBackgroundTheme = theme; + } + return mEdgeToEdgeWallpaperBackgroundTheme; + } + return theme; + } + @Override public void onNavigateNext() { - startFinishSequence(); + if (!sIsFinishing) { + sIsFinishing = true; + startActivity(getIntent()); + finish(); + disableActivityTransitions(); + } + hideNextButton(); } private void startFinishSequence() { - if (mIsFinishing) { - return; - } - mIsFinishing = true; - setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED); hideNextButton(); // Begin outro animation. - animateOut(); + if (mRootView.isAttachedToWindow()) { + mHandler.post(() -> animateOut()); + } else { + mRootView.addOnAttachStateChangeListener(new View.OnAttachStateChangeListener() { + @Override + public void onViewAttachedToWindow(View v) { + mHandler.post(() -> animateOut()); + } + + @Override + public void onViewDetachedFromWindow(View v) { + // Do nothing + } + }); + } } private void animateOut() { - final View rootView = findViewById(R.id.root); - final int cx = (rootView.getLeft() + rootView.getRight()) / 2; - final int cy = (rootView.getTop() + rootView.getBottom()) / 2; + final int cx = (mRootView.getLeft() + mRootView.getRight()) / 2; + final int cy = (mRootView.getTop() + mRootView.getBottom()) / 2; final float fullRadius = (float) Math.hypot(cx, cy); Animator anim = - ViewAnimationUtils.createCircularReveal(rootView, cx, cy, fullRadius, 0f); + ViewAnimationUtils.createCircularReveal(mRootView, cx, cy, fullRadius, 0f); anim.setDuration(900); anim.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationStart(Animator animation) { - rootView.setVisibility(View.VISIBLE); + mRootView.setVisibility(View.VISIBLE); } @Override public void onAnimationEnd(Animator animation) { - rootView.setVisibility(View.INVISIBLE); + mRootView.setVisibility(View.INVISIBLE); mHandler.post(() -> { if (LOGV) { Log.v(TAG, "Animation ended");