| Timi Rautamäki | e83f9e1 | 2022-03-16 13:21:30 +0000 | [diff] [blame] | 1 | /* |
| Oliver Scott | f58c0f4 | 2024-01-08 14:52:12 -0500 | [diff] [blame] | 2 | * Copyright (C) 2022-2024 The LineageOS Project |
| Timi Rautamäki | e83f9e1 | 2022-03-16 13:21:30 +0000 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package org.lineageos.setupwizard; |
| 18 | |
| 19 | import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_2BUTTON_OVERLAY; |
| 20 | import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_3BUTTON_OVERLAY; |
| 21 | import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_GESTURAL_OVERLAY; |
| 22 | |
| Michael Bestas | a5ba5df | 2023-07-15 16:19:36 +0300 | [diff] [blame] | 23 | import static com.android.systemui.shared.recents.utilities.Utilities.isLargeScreen; |
| 24 | |
| Timi Rautamäki | e83f9e1 | 2022-03-16 13:21:30 +0000 | [diff] [blame] | 25 | import static org.lineageos.internal.util.DeviceKeysConstants.KEY_MASK_APP_SWITCH; |
| 26 | import static org.lineageos.setupwizard.SetupWizardApp.DISABLE_NAV_KEYS; |
| 27 | import static org.lineageos.setupwizard.SetupWizardApp.NAVIGATION_OPTION_KEY; |
| 28 | |
| 29 | import android.animation.Animator; |
| 30 | import android.animation.AnimatorListenerAdapter; |
| Timi Rautamäki | e83f9e1 | 2022-03-16 13:21:30 +0000 | [diff] [blame] | 31 | import android.os.Bundle; |
| 32 | import android.os.UserHandle; |
| Timi Rautamäki | e83f9e1 | 2022-03-16 13:21:30 +0000 | [diff] [blame] | 33 | import android.view.View; |
| 34 | import android.widget.CheckBox; |
| 35 | import android.widget.RadioButton; |
| 36 | import android.widget.RadioGroup; |
| 37 | import android.widget.RadioGroup.OnCheckedChangeListener; |
| 38 | |
| 39 | import com.airbnb.lottie.LottieAnimationView; |
| Timi Rautamäki | e83f9e1 | 2022-03-16 13:21:30 +0000 | [diff] [blame] | 40 | |
| 41 | import lineageos.providers.LineageSettings; |
| 42 | |
| 43 | import org.lineageos.setupwizard.util.SetupWizardUtils; |
| 44 | |
| 45 | public class NavigationSettingsActivity extends BaseSetupWizardActivity { |
| 46 | |
| 47 | public static final String TAG = NavigationSettingsActivity.class.getSimpleName(); |
| 48 | |
| 49 | private SetupWizardApp mSetupWizardApp; |
| 50 | |
| Michael Bestas | a5ba5df | 2023-07-15 16:19:36 +0300 | [diff] [blame] | 51 | private boolean mIsTaskbarEnabled; |
| 52 | |
| Timi Rautamäki | e83f9e1 | 2022-03-16 13:21:30 +0000 | [diff] [blame] | 53 | private String mSelection = NAV_BAR_MODE_GESTURAL_OVERLAY; |
| 54 | |
| 55 | private CheckBox mHideGesturalHint; |
| 56 | |
| 57 | @Override |
| 58 | protected void onCreate(Bundle savedInstanceState) { |
| 59 | super.onCreate(savedInstanceState); |
| 60 | |
| 61 | mSetupWizardApp = (SetupWizardApp) getApplication(); |
| 62 | boolean navBarEnabled = false; |
| 63 | if (mSetupWizardApp.getSettingsBundle().containsKey(DISABLE_NAV_KEYS)) { |
| 64 | navBarEnabled = mSetupWizardApp.getSettingsBundle().getBoolean(DISABLE_NAV_KEYS); |
| 65 | } |
| Michael Bestas | a5ba5df | 2023-07-15 16:19:36 +0300 | [diff] [blame] | 66 | mIsTaskbarEnabled = LineageSettings.System.getInt(getContentResolver(), |
| 67 | LineageSettings.System.ENABLE_TASKBAR, isLargeScreen(this) ? 1 : 0) == 1; |
| Timi Rautamäki | e83f9e1 | 2022-03-16 13:21:30 +0000 | [diff] [blame] | 68 | |
| 69 | int deviceKeys = getResources().getInteger( |
| 70 | org.lineageos.platform.internal.R.integer.config_deviceHardwareKeys); |
| 71 | boolean hasHomeKey = (deviceKeys & KEY_MASK_APP_SWITCH) != 0; |
| 72 | |
| 73 | getGlifLayout().setDescriptionText(getString(R.string.navigation_summary)); |
| 74 | setNextText(R.string.next); |
| 75 | |
| 76 | int available = 3; |
| 77 | // Hide unavailable navigation modes |
| Bruno Martins | 7055198 | 2022-03-22 20:07:33 +0000 | [diff] [blame] | 78 | if (!SetupWizardUtils.isPackageInstalled(this, NAV_BAR_MODE_GESTURAL_OVERLAY)) { |
| Timi Rautamäki | e83f9e1 | 2022-03-16 13:21:30 +0000 | [diff] [blame] | 79 | findViewById(R.id.radio_gesture).setVisibility(View.GONE); |
| 80 | ((RadioButton) findViewById(R.id.radio_sw_keys)).setChecked(true); |
| 81 | available--; |
| 82 | } |
| 83 | |
| Bruno Martins | 7055198 | 2022-03-22 20:07:33 +0000 | [diff] [blame] | 84 | if (!SetupWizardUtils.isPackageInstalled(this, NAV_BAR_MODE_2BUTTON_OVERLAY)) { |
| Timi Rautamäki | e83f9e1 | 2022-03-16 13:21:30 +0000 | [diff] [blame] | 85 | findViewById(R.id.radio_two_button).setVisibility(View.GONE); |
| 86 | available--; |
| 87 | } |
| 88 | |
| Bruno Martins | 7055198 | 2022-03-22 20:07:33 +0000 | [diff] [blame] | 89 | if (!SetupWizardUtils.isPackageInstalled(this, NAV_BAR_MODE_3BUTTON_OVERLAY)) { |
| Timi Rautamäki | e83f9e1 | 2022-03-16 13:21:30 +0000 | [diff] [blame] | 90 | findViewById(R.id.radio_sw_keys).setVisibility(View.GONE); |
| 91 | available--; |
| 92 | } |
| 93 | |
| Timi Rautamäki | e83f9e1 | 2022-03-16 13:21:30 +0000 | [diff] [blame] | 94 | // Hide this page if the device has hardware keys but didn't enable navbar |
| 95 | // or if there's <= 1 available navigation modes |
| 96 | if (!navBarEnabled && hasHomeKey || available <= 1) { |
| 97 | mSetupWizardApp.getSettingsBundle().putString(NAVIGATION_OPTION_KEY, |
| 98 | NAV_BAR_MODE_3BUTTON_OVERLAY); |
| Oliver Scott | f58c0f4 | 2024-01-08 14:52:12 -0500 | [diff] [blame] | 99 | finishAction(RESULT_OK); |
| Timi Rautamäki | e83f9e1 | 2022-03-16 13:21:30 +0000 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | final LottieAnimationView navigationIllustration = |
| 103 | findViewById(R.id.navigation_illustration); |
| 104 | final RadioGroup radioGroup = findViewById(R.id.navigation_radio_group); |
| 105 | mHideGesturalHint = findViewById(R.id.hide_navigation_hint); |
| Michael Bestas | a5ba5df | 2023-07-15 16:19:36 +0300 | [diff] [blame] | 106 | |
| 107 | // Hide navigation hint checkbox when taskbar is enabled |
| 108 | if (mIsTaskbarEnabled) { |
| 109 | mHideGesturalHint.setVisibility(View.GONE); |
| 110 | } |
| 111 | |
| Oliver Scott | 7664461 | 2024-01-10 17:16:28 -0500 | [diff] [blame^] | 112 | radioGroup.setOnCheckedChangeListener((group, checkedId) -> { |
| 113 | switch (checkedId) { |
| Timi Rautamäki | e83f9e1 | 2022-03-16 13:21:30 +0000 | [diff] [blame] | 114 | case R.id.radio_gesture: |
| 115 | mSelection = NAV_BAR_MODE_GESTURAL_OVERLAY; |
| 116 | navigationIllustration |
| 117 | .setAnimation(R.raw.lottie_system_nav_fully_gestural); |
| 118 | revealHintCheckbox(); |
| 119 | break; |
| 120 | case R.id.radio_two_button: |
| 121 | mSelection = NAV_BAR_MODE_2BUTTON_OVERLAY; |
| 122 | navigationIllustration.setAnimation(R.raw.lottie_system_nav_2_button); |
| 123 | hideHintCheckBox(); |
| 124 | break; |
| 125 | case R.id.radio_sw_keys: |
| 126 | mSelection = NAV_BAR_MODE_3BUTTON_OVERLAY; |
| 127 | navigationIllustration.setAnimation(R.raw.lottie_system_nav_3_button); |
| 128 | hideHintCheckBox(); |
| 129 | break; |
| Timi Rautamäki | e83f9e1 | 2022-03-16 13:21:30 +0000 | [diff] [blame] | 130 | } |
| Oliver Scott | 7664461 | 2024-01-10 17:16:28 -0500 | [diff] [blame^] | 131 | |
| 132 | navigationIllustration.playAnimation(); |
| Timi Rautamäki | e83f9e1 | 2022-03-16 13:21:30 +0000 | [diff] [blame] | 133 | }); |
| 134 | } |
| 135 | |
| 136 | private void revealHintCheckbox() { |
| Michael Bestas | a5ba5df | 2023-07-15 16:19:36 +0300 | [diff] [blame] | 137 | if (mIsTaskbarEnabled) { |
| Oliver Scott | 7664461 | 2024-01-10 17:16:28 -0500 | [diff] [blame^] | 138 | return; |
| Michael Bestas | a5ba5df | 2023-07-15 16:19:36 +0300 | [diff] [blame] | 139 | } |
| 140 | |
| Alessandro Astone | 0fa8417 | 2022-04-04 17:33:18 +0200 | [diff] [blame] | 141 | mHideGesturalHint.animate().cancel(); |
| 142 | |
| Timi Rautamäki | e83f9e1 | 2022-03-16 13:21:30 +0000 | [diff] [blame] | 143 | if (mHideGesturalHint.getVisibility() == View.VISIBLE) { |
| 144 | return; |
| 145 | } |
| 146 | |
| 147 | mHideGesturalHint.setVisibility(View.VISIBLE); |
| 148 | mHideGesturalHint.setAlpha(0.0f); |
| 149 | mHideGesturalHint.animate() |
| Oliver Scott | 7664461 | 2024-01-10 17:16:28 -0500 | [diff] [blame^] | 150 | .translationY(0) |
| 151 | .alpha(1.0f) |
| 152 | .setListener(null); |
| Timi Rautamäki | e83f9e1 | 2022-03-16 13:21:30 +0000 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | private void hideHintCheckBox() { |
| Michael Bestas | a5ba5df | 2023-07-15 16:19:36 +0300 | [diff] [blame] | 156 | if (mIsTaskbarEnabled) { |
| Oliver Scott | 7664461 | 2024-01-10 17:16:28 -0500 | [diff] [blame^] | 157 | return; |
| Michael Bestas | a5ba5df | 2023-07-15 16:19:36 +0300 | [diff] [blame] | 158 | } |
| 159 | |
| Timi Rautamäki | e83f9e1 | 2022-03-16 13:21:30 +0000 | [diff] [blame] | 160 | if (mHideGesturalHint.getVisibility() == View.INVISIBLE) { |
| 161 | return; |
| 162 | } |
| 163 | |
| 164 | mHideGesturalHint.animate() |
| Oliver Scott | 7664461 | 2024-01-10 17:16:28 -0500 | [diff] [blame^] | 165 | .translationY(-mHideGesturalHint.getHeight()) |
| 166 | .alpha(0.0f) |
| 167 | .setListener(new AnimatorListenerAdapter() { |
| 168 | @Override |
| 169 | public void onAnimationEnd(Animator animation) { |
| 170 | super.onAnimationEnd(animation); |
| 171 | mHideGesturalHint.setVisibility(View.INVISIBLE); |
| 172 | } |
| 173 | }); |
| Timi Rautamäki | e83f9e1 | 2022-03-16 13:21:30 +0000 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | @Override |
| 177 | protected void onNextPressed() { |
| 178 | mSetupWizardApp.getSettingsBundle().putString(NAVIGATION_OPTION_KEY, mSelection); |
| Michael Bestas | a5ba5df | 2023-07-15 16:19:36 +0300 | [diff] [blame] | 179 | if (!mIsTaskbarEnabled) { |
| 180 | boolean hideHint = mHideGesturalHint.isChecked(); |
| 181 | LineageSettings.System.putIntForUser(getContentResolver(), |
| 182 | LineageSettings.System.NAVIGATION_BAR_HINT, hideHint ? 0 : 1, |
| 183 | UserHandle.USER_CURRENT); |
| 184 | } |
| Oliver Scott | 04c9f46 | 2024-01-06 20:36:13 -0500 | [diff] [blame] | 185 | super.onNextPressed(); |
| Timi Rautamäki | e83f9e1 | 2022-03-16 13:21:30 +0000 | [diff] [blame] | 186 | } |
| 187 | |
| 188 | @Override |
| 189 | protected int getLayoutResId() { |
| 190 | return R.layout.setup_navigation; |
| 191 | } |
| 192 | |
| 193 | @Override |
| 194 | protected int getTitleResId() { |
| 195 | return R.string.setup_navigation; |
| 196 | } |
| 197 | |
| 198 | @Override |
| 199 | protected int getIconResId() { |
| 200 | return R.drawable.ic_navigation; |
| 201 | } |
| Timi Rautamäki | e83f9e1 | 2022-03-16 13:21:30 +0000 | [diff] [blame] | 202 | } |