| /* |
| * SPDX-FileCopyrightText: 2016 The CyanogenMod Project |
| * SPDX-FileCopyrightText: 2017-2024 The LineageOS Project |
| * SPDX-FileCopyrightText: 2022-2024 The LeafOS Project |
| * SPDX-License-Identifier: Apache-2.0 |
| */ |
| |
| package org.lineageos.setupwizard; |
| |
| import static android.os.Binder.getCallingUserHandle; |
| import static android.os.UserHandle.USER_CURRENT; |
| |
| import static org.lineageos.setupwizard.Manifest.permission.FINISH_SETUP; |
| import static org.lineageos.setupwizard.SetupWizardApp.LOGV; |
| import static org.lineageos.setupwizard.SetupWizardApp.NAVIGATION_OPTION_KEY; |
| |
| import android.animation.Animator; |
| import android.animation.AnimatorListenerAdapter; |
| import android.content.pm.ActivityInfo; |
| import android.os.Bundle; |
| import android.os.Handler; |
| import android.os.Looper; |
| import android.util.Log; |
| import android.view.View; |
| import android.view.ViewAnimationUtils; |
| import android.view.ViewGroup.MarginLayoutParams; |
| import android.view.Window; |
| |
| import androidx.core.graphics.Insets; |
| import androidx.core.view.ViewCompat; |
| import androidx.core.view.WindowInsetsCompat; |
| |
| import org.lineageos.setupwizard.util.SetupWizardUtils; |
| |
| public class FinishActivity extends BaseSetupWizardActivity { |
| |
| public static final String TAG = FinishActivity.class.getSimpleName(); |
| |
| private final Handler mHandler = new Handler(Looper.getMainLooper()); |
| |
| private boolean mIsFinishing; |
| |
| @Override |
| protected void onCreate(Bundle savedInstanceState) { |
| super.onCreate(savedInstanceState); |
| overrideActivityTransition(OVERRIDE_TRANSITION_CLOSE, R.anim.translucent_enter, |
| R.anim.translucent_exit); |
| if (LOGV) { |
| logActivityState("onCreate savedInstanceState=" + savedInstanceState); |
| } |
| setNextText(R.string.start); |
| |
| // Edge-to-edge. Needed for the background view to fill the full screen. |
| final Window window = getWindow(); |
| window.setDecorFitsSystemWindows(false); |
| |
| // Make sure 3-button navigation bar is the same color as the rest of the screen. |
| window.setNavigationBarContrastEnforced(false); |
| |
| // Ensure the main layout (not including the background view) does not get obscured by bars. |
| final View rootView = findViewById(R.id.root); |
| ViewCompat.setOnApplyWindowInsetsListener(rootView, (view, windowInsets) -> { |
| final View linearLayout = findViewById(R.id.linear_layout); |
| final Insets insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars()); |
| final MarginLayoutParams params = (MarginLayoutParams) linearLayout.getLayoutParams(); |
| params.leftMargin = insets.left; |
| params.topMargin = insets.top; |
| params.rightMargin = insets.right; |
| params.bottomMargin = insets.bottom; |
| linearLayout.setLayoutParams(params); |
| return WindowInsetsCompat.CONSUMED; |
| }); |
| } |
| |
| @Override |
| protected int getLayoutResId() { |
| return R.layout.finish_activity; |
| } |
| |
| @Override |
| public void onNavigateNext() { |
| startFinishSequence(); |
| } |
| |
| private void startFinishSequence() { |
| if (mIsFinishing) { |
| return; |
| } |
| mIsFinishing = true; |
| |
| setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED); |
| hideNextButton(); |
| |
| // Begin outro animation. |
| animateOut(); |
| } |
| |
| 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 float fullRadius = (float) Math.hypot(cx, cy); |
| Animator anim = |
| ViewAnimationUtils.createCircularReveal(rootView, cx, cy, fullRadius, 0f); |
| anim.setDuration(900); |
| anim.addListener(new AnimatorListenerAdapter() { |
| @Override |
| public void onAnimationStart(Animator animation) { |
| rootView.setVisibility(View.VISIBLE); |
| } |
| |
| @Override |
| public void onAnimationEnd(Animator animation) { |
| rootView.setVisibility(View.INVISIBLE); |
| mHandler.post(() -> { |
| if (LOGV) { |
| Log.v(TAG, "Animation ended"); |
| } |
| SetupWizardUtils.finishSetupWizard(FinishActivity.this); |
| }); |
| } |
| }); |
| anim.start(); |
| } |
| } |