| 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 | |
| Timi Rautamäki | e83f9e1 | 2022-03-16 13:21:30 +0000 | [diff] [blame] | 112 | radioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() { |
| 113 | @Override |
| 114 | public void onCheckedChanged(RadioGroup group, int checkedId) { |
| 115 | switch (checkedId) { |
| 116 | case R.id.radio_gesture: |
| 117 | mSelection = NAV_BAR_MODE_GESTURAL_OVERLAY; |
| 118 | navigationIllustration |
| 119 | .setAnimation(R.raw.lottie_system_nav_fully_gestural); |
| 120 | revealHintCheckbox(); |
| 121 | break; |
| 122 | case R.id.radio_two_button: |
| 123 | mSelection = NAV_BAR_MODE_2BUTTON_OVERLAY; |
| 124 | navigationIllustration.setAnimation(R.raw.lottie_system_nav_2_button); |
| 125 | hideHintCheckBox(); |
| 126 | break; |
| 127 | case R.id.radio_sw_keys: |
| 128 | mSelection = NAV_BAR_MODE_3BUTTON_OVERLAY; |
| 129 | navigationIllustration.setAnimation(R.raw.lottie_system_nav_3_button); |
| 130 | hideHintCheckBox(); |
| 131 | break; |
| 132 | } |
| 133 | |
| 134 | navigationIllustration.playAnimation(); |
| 135 | } |
| 136 | }); |
| 137 | } |
| 138 | |
| 139 | private void revealHintCheckbox() { |
| Michael Bestas | a5ba5df | 2023-07-15 16:19:36 +0300 | [diff] [blame] | 140 | if (mIsTaskbarEnabled) { |
| 141 | return; |
| 142 | } |
| 143 | |
| Alessandro Astone | 0fa8417 | 2022-04-04 17:33:18 +0200 | [diff] [blame] | 144 | mHideGesturalHint.animate().cancel(); |
| 145 | |
| Timi Rautamäki | e83f9e1 | 2022-03-16 13:21:30 +0000 | [diff] [blame] | 146 | if (mHideGesturalHint.getVisibility() == View.VISIBLE) { |
| 147 | return; |
| 148 | } |
| 149 | |
| 150 | mHideGesturalHint.setVisibility(View.VISIBLE); |
| 151 | mHideGesturalHint.setAlpha(0.0f); |
| 152 | mHideGesturalHint.animate() |
| 153 | .translationY(0) |
| 154 | .alpha(1.0f) |
| 155 | .setListener(null); |
| 156 | } |
| 157 | |
| 158 | private void hideHintCheckBox() { |
| Michael Bestas | a5ba5df | 2023-07-15 16:19:36 +0300 | [diff] [blame] | 159 | if (mIsTaskbarEnabled) { |
| 160 | return; |
| 161 | } |
| 162 | |
| Timi Rautamäki | e83f9e1 | 2022-03-16 13:21:30 +0000 | [diff] [blame] | 163 | if (mHideGesturalHint.getVisibility() == View.INVISIBLE) { |
| 164 | return; |
| 165 | } |
| 166 | |
| 167 | mHideGesturalHint.animate() |
| 168 | .translationY(-mHideGesturalHint.getHeight()) |
| 169 | .alpha(0.0f) |
| 170 | .setListener(new AnimatorListenerAdapter() { |
| 171 | @Override |
| 172 | public void onAnimationEnd(Animator animation) { |
| 173 | super.onAnimationEnd(animation); |
| 174 | mHideGesturalHint.setVisibility(View.INVISIBLE); |
| 175 | } |
| 176 | }); |
| 177 | } |
| 178 | |
| 179 | @Override |
| 180 | protected void onNextPressed() { |
| 181 | mSetupWizardApp.getSettingsBundle().putString(NAVIGATION_OPTION_KEY, mSelection); |
| Michael Bestas | a5ba5df | 2023-07-15 16:19:36 +0300 | [diff] [blame] | 182 | if (!mIsTaskbarEnabled) { |
| 183 | boolean hideHint = mHideGesturalHint.isChecked(); |
| 184 | LineageSettings.System.putIntForUser(getContentResolver(), |
| 185 | LineageSettings.System.NAVIGATION_BAR_HINT, hideHint ? 0 : 1, |
| 186 | UserHandle.USER_CURRENT); |
| 187 | } |
| Oliver Scott | 04c9f46 | 2024-01-06 20:36:13 -0500 | [diff] [blame] | 188 | super.onNextPressed(); |
| Timi Rautamäki | e83f9e1 | 2022-03-16 13:21:30 +0000 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | @Override |
| 192 | protected int getLayoutResId() { |
| 193 | return R.layout.setup_navigation; |
| 194 | } |
| 195 | |
| 196 | @Override |
| 197 | protected int getTitleResId() { |
| 198 | return R.string.setup_navigation; |
| 199 | } |
| 200 | |
| 201 | @Override |
| 202 | protected int getIconResId() { |
| 203 | return R.drawable.ic_navigation; |
| 204 | } |
| Timi Rautamäki | e83f9e1 | 2022-03-16 13:21:30 +0000 | [diff] [blame] | 205 | } |