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