| Timi Rautamäki | e83f9e1 | 2022-03-16 13:21:30 +0000 | [diff] [blame] | 1 | /* |
| Michael Bestas | ec05005 | 2024-02-14 20:35:43 +0200 | [diff] [blame] | 2 | * SPDX-FileCopyrightText: 2022-2024 The LineageOS Project |
| 3 | * SPDX-License-Identifier: Apache-2.0 |
| Timi Rautamäki | e83f9e1 | 2022-03-16 13:21:30 +0000 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | package org.lineageos.setupwizard; |
| 7 | |
| Timi Rautamäki | e83f9e1 | 2022-03-16 13:21:30 +0000 | [diff] [blame] | 8 | import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_3BUTTON_OVERLAY; |
| 9 | import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_GESTURAL_OVERLAY; |
| 10 | |
| 11 | import static org.lineageos.internal.util.DeviceKeysConstants.KEY_MASK_APP_SWITCH; |
| 12 | import static org.lineageos.setupwizard.SetupWizardApp.DISABLE_NAV_KEYS; |
| 13 | import static org.lineageos.setupwizard.SetupWizardApp.NAVIGATION_OPTION_KEY; |
| 14 | |
| 15 | import android.animation.Animator; |
| 16 | import android.animation.AnimatorListenerAdapter; |
| Timi Rautamäki | e83f9e1 | 2022-03-16 13:21:30 +0000 | [diff] [blame] | 17 | import android.os.Bundle; |
| 18 | import android.os.UserHandle; |
| Timi Rautamäki | e83f9e1 | 2022-03-16 13:21:30 +0000 | [diff] [blame] | 19 | import android.view.View; |
| 20 | import android.widget.CheckBox; |
| 21 | import android.widget.RadioButton; |
| 22 | import android.widget.RadioGroup; |
| Timi Rautamäki | e83f9e1 | 2022-03-16 13:21:30 +0000 | [diff] [blame] | 23 | |
| 24 | import com.airbnb.lottie.LottieAnimationView; |
| Timi Rautamäki | e83f9e1 | 2022-03-16 13:21:30 +0000 | [diff] [blame] | 25 | |
| 26 | import lineageos.providers.LineageSettings; |
| 27 | |
| 28 | import org.lineageos.setupwizard.util.SetupWizardUtils; |
| 29 | |
| 30 | public class NavigationSettingsActivity extends BaseSetupWizardActivity { |
| 31 | |
| Timi Rautamäki | e83f9e1 | 2022-03-16 13:21:30 +0000 | [diff] [blame] | 32 | private SetupWizardApp mSetupWizardApp; |
| 33 | |
| 34 | private String mSelection = NAV_BAR_MODE_GESTURAL_OVERLAY; |
| 35 | |
| 36 | private CheckBox mHideGesturalHint; |
| 37 | |
| 38 | @Override |
| 39 | protected void onCreate(Bundle savedInstanceState) { |
| 40 | super.onCreate(savedInstanceState); |
| 41 | |
| 42 | mSetupWizardApp = (SetupWizardApp) getApplication(); |
| 43 | boolean navBarEnabled = false; |
| 44 | if (mSetupWizardApp.getSettingsBundle().containsKey(DISABLE_NAV_KEYS)) { |
| 45 | navBarEnabled = mSetupWizardApp.getSettingsBundle().getBoolean(DISABLE_NAV_KEYS); |
| 46 | } |
| 47 | |
| 48 | int deviceKeys = getResources().getInteger( |
| 49 | org.lineageos.platform.internal.R.integer.config_deviceHardwareKeys); |
| 50 | boolean hasHomeKey = (deviceKeys & KEY_MASK_APP_SWITCH) != 0; |
| 51 | |
| 52 | getGlifLayout().setDescriptionText(getString(R.string.navigation_summary)); |
| 53 | setNextText(R.string.next); |
| 54 | |
| 55 | int available = 3; |
| 56 | // Hide unavailable navigation modes |
| Bruno Martins | 7055198 | 2022-03-22 20:07:33 +0000 | [diff] [blame] | 57 | if (!SetupWizardUtils.isPackageInstalled(this, NAV_BAR_MODE_GESTURAL_OVERLAY)) { |
| Timi Rautamäki | e83f9e1 | 2022-03-16 13:21:30 +0000 | [diff] [blame] | 58 | findViewById(R.id.radio_gesture).setVisibility(View.GONE); |
| 59 | ((RadioButton) findViewById(R.id.radio_sw_keys)).setChecked(true); |
| 60 | available--; |
| 61 | } |
| 62 | |
| Bruno Martins | 7055198 | 2022-03-22 20:07:33 +0000 | [diff] [blame] | 63 | if (!SetupWizardUtils.isPackageInstalled(this, NAV_BAR_MODE_3BUTTON_OVERLAY)) { |
| Timi Rautamäki | e83f9e1 | 2022-03-16 13:21:30 +0000 | [diff] [blame] | 64 | findViewById(R.id.radio_sw_keys).setVisibility(View.GONE); |
| 65 | available--; |
| 66 | } |
| 67 | |
| Timi Rautamäki | e83f9e1 | 2022-03-16 13:21:30 +0000 | [diff] [blame] | 68 | // Hide this page if the device has hardware keys but didn't enable navbar |
| 69 | // or if there's <= 1 available navigation modes |
| 70 | if (!navBarEnabled && hasHomeKey || available <= 1) { |
| 71 | mSetupWizardApp.getSettingsBundle().putString(NAVIGATION_OPTION_KEY, |
| 72 | NAV_BAR_MODE_3BUTTON_OVERLAY); |
| Oliver Scott | f58c0f4 | 2024-01-08 14:52:12 -0500 | [diff] [blame] | 73 | finishAction(RESULT_OK); |
| Timi Rautamäki | e83f9e1 | 2022-03-16 13:21:30 +0000 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | final LottieAnimationView navigationIllustration = |
| 77 | findViewById(R.id.navigation_illustration); |
| 78 | final RadioGroup radioGroup = findViewById(R.id.navigation_radio_group); |
| 79 | mHideGesturalHint = findViewById(R.id.hide_navigation_hint); |
| Michael Bestas | a5ba5df | 2023-07-15 16:19:36 +0300 | [diff] [blame] | 80 | |
| Oliver Scott | 7664461 | 2024-01-10 17:16:28 -0500 | [diff] [blame] | 81 | radioGroup.setOnCheckedChangeListener((group, checkedId) -> { |
| 82 | switch (checkedId) { |
| Timi Rautamäki | e83f9e1 | 2022-03-16 13:21:30 +0000 | [diff] [blame] | 83 | case R.id.radio_gesture: |
| 84 | mSelection = NAV_BAR_MODE_GESTURAL_OVERLAY; |
| 85 | navigationIllustration |
| 86 | .setAnimation(R.raw.lottie_system_nav_fully_gestural); |
| 87 | revealHintCheckbox(); |
| 88 | break; |
| Timi Rautamäki | e83f9e1 | 2022-03-16 13:21:30 +0000 | [diff] [blame] | 89 | case R.id.radio_sw_keys: |
| 90 | mSelection = NAV_BAR_MODE_3BUTTON_OVERLAY; |
| 91 | navigationIllustration.setAnimation(R.raw.lottie_system_nav_3_button); |
| 92 | hideHintCheckBox(); |
| 93 | break; |
| Timi Rautamäki | e83f9e1 | 2022-03-16 13:21:30 +0000 | [diff] [blame] | 94 | } |
| Oliver Scott | 7664461 | 2024-01-10 17:16:28 -0500 | [diff] [blame] | 95 | |
| 96 | navigationIllustration.playAnimation(); |
| Timi Rautamäki | e83f9e1 | 2022-03-16 13:21:30 +0000 | [diff] [blame] | 97 | }); |
| 98 | } |
| 99 | |
| 100 | private void revealHintCheckbox() { |
| Alessandro Astone | 0fa8417 | 2022-04-04 17:33:18 +0200 | [diff] [blame] | 101 | mHideGesturalHint.animate().cancel(); |
| 102 | |
| Timi Rautamäki | e83f9e1 | 2022-03-16 13:21:30 +0000 | [diff] [blame] | 103 | if (mHideGesturalHint.getVisibility() == View.VISIBLE) { |
| 104 | return; |
| 105 | } |
| 106 | |
| 107 | mHideGesturalHint.setVisibility(View.VISIBLE); |
| 108 | mHideGesturalHint.setAlpha(0.0f); |
| 109 | mHideGesturalHint.animate() |
| Oliver Scott | 7664461 | 2024-01-10 17:16:28 -0500 | [diff] [blame] | 110 | .translationY(0) |
| 111 | .alpha(1.0f) |
| 112 | .setListener(null); |
| Timi Rautamäki | e83f9e1 | 2022-03-16 13:21:30 +0000 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | private void hideHintCheckBox() { |
| 116 | if (mHideGesturalHint.getVisibility() == View.INVISIBLE) { |
| 117 | return; |
| 118 | } |
| 119 | |
| 120 | mHideGesturalHint.animate() |
| Oliver Scott | 7664461 | 2024-01-10 17:16:28 -0500 | [diff] [blame] | 121 | .translationY(-mHideGesturalHint.getHeight()) |
| 122 | .alpha(0.0f) |
| 123 | .setListener(new AnimatorListenerAdapter() { |
| 124 | @Override |
| 125 | public void onAnimationEnd(Animator animation) { |
| 126 | super.onAnimationEnd(animation); |
| 127 | mHideGesturalHint.setVisibility(View.INVISIBLE); |
| 128 | } |
| 129 | }); |
| Timi Rautamäki | e83f9e1 | 2022-03-16 13:21:30 +0000 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | @Override |
| 133 | protected void onNextPressed() { |
| 134 | mSetupWizardApp.getSettingsBundle().putString(NAVIGATION_OPTION_KEY, mSelection); |
| LuK1337 | 78e7d4e | 2025-03-24 14:56:53 +0100 | [diff] [blame] | 135 | boolean hideHint = mHideGesturalHint.isChecked(); |
| 136 | LineageSettings.System.putIntForUser(getContentResolver(), |
| 137 | LineageSettings.System.NAVIGATION_BAR_HINT, hideHint ? 0 : 1, |
| 138 | UserHandle.USER_CURRENT); |
| Oliver Scott | 04c9f46 | 2024-01-06 20:36:13 -0500 | [diff] [blame] | 139 | super.onNextPressed(); |
| Timi Rautamäki | e83f9e1 | 2022-03-16 13:21:30 +0000 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | @Override |
| 143 | protected int getLayoutResId() { |
| 144 | return R.layout.setup_navigation; |
| 145 | } |
| 146 | |
| 147 | @Override |
| 148 | protected int getTitleResId() { |
| 149 | return R.string.setup_navigation; |
| 150 | } |
| 151 | |
| 152 | @Override |
| 153 | protected int getIconResId() { |
| 154 | return R.drawable.ic_navigation; |
| 155 | } |
| Timi Rautamäki | e83f9e1 | 2022-03-16 13:21:30 +0000 | [diff] [blame] | 156 | } |