| Timi Rautamäki | e83f9e1 | 2022-03-16 13:21:30 +0000 | [diff] [blame] | 1 | /* |
| Michael Bestas | a5ba5df | 2023-07-15 16:19:36 +0300 | [diff] [blame^] | 2 | * Copyright (C) 2022-2023 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; |
| 31 | import android.app.Activity; |
| 32 | import android.content.Intent; |
| 33 | import android.os.Bundle; |
| 34 | import android.os.UserHandle; |
| 35 | import android.content.Context; |
| 36 | import android.view.View; |
| 37 | import android.widget.CheckBox; |
| 38 | import android.widget.RadioButton; |
| 39 | import android.widget.RadioGroup; |
| 40 | import android.widget.RadioGroup.OnCheckedChangeListener; |
| 41 | |
| 42 | import com.airbnb.lottie.LottieAnimationView; |
| 43 | import com.google.android.setupcompat.util.WizardManagerHelper; |
| 44 | |
| 45 | import lineageos.providers.LineageSettings; |
| 46 | |
| 47 | import org.lineageos.setupwizard.util.SetupWizardUtils; |
| 48 | |
| 49 | public class NavigationSettingsActivity extends BaseSetupWizardActivity { |
| 50 | |
| 51 | public static final String TAG = NavigationSettingsActivity.class.getSimpleName(); |
| 52 | |
| 53 | private SetupWizardApp mSetupWizardApp; |
| 54 | |
| Michael Bestas | a5ba5df | 2023-07-15 16:19:36 +0300 | [diff] [blame^] | 55 | private boolean mIsTaskbarEnabled; |
| 56 | |
| Timi Rautamäki | e83f9e1 | 2022-03-16 13:21:30 +0000 | [diff] [blame] | 57 | private String mSelection = NAV_BAR_MODE_GESTURAL_OVERLAY; |
| 58 | |
| 59 | private CheckBox mHideGesturalHint; |
| 60 | |
| 61 | @Override |
| 62 | protected void onCreate(Bundle savedInstanceState) { |
| 63 | super.onCreate(savedInstanceState); |
| 64 | |
| 65 | mSetupWizardApp = (SetupWizardApp) getApplication(); |
| 66 | boolean navBarEnabled = false; |
| 67 | if (mSetupWizardApp.getSettingsBundle().containsKey(DISABLE_NAV_KEYS)) { |
| 68 | navBarEnabled = mSetupWizardApp.getSettingsBundle().getBoolean(DISABLE_NAV_KEYS); |
| 69 | } |
| Michael Bestas | a5ba5df | 2023-07-15 16:19:36 +0300 | [diff] [blame^] | 70 | mIsTaskbarEnabled = LineageSettings.System.getInt(getContentResolver(), |
| 71 | LineageSettings.System.ENABLE_TASKBAR, isLargeScreen(this) ? 1 : 0) == 1; |
| Timi Rautamäki | e83f9e1 | 2022-03-16 13:21:30 +0000 | [diff] [blame] | 72 | |
| 73 | int deviceKeys = getResources().getInteger( |
| 74 | org.lineageos.platform.internal.R.integer.config_deviceHardwareKeys); |
| 75 | boolean hasHomeKey = (deviceKeys & KEY_MASK_APP_SWITCH) != 0; |
| 76 | |
| 77 | getGlifLayout().setDescriptionText(getString(R.string.navigation_summary)); |
| 78 | setNextText(R.string.next); |
| 79 | |
| 80 | int available = 3; |
| 81 | // Hide unavailable navigation modes |
| Bruno Martins | 7055198 | 2022-03-22 20:07:33 +0000 | [diff] [blame] | 82 | if (!SetupWizardUtils.isPackageInstalled(this, NAV_BAR_MODE_GESTURAL_OVERLAY)) { |
| Timi Rautamäki | e83f9e1 | 2022-03-16 13:21:30 +0000 | [diff] [blame] | 83 | findViewById(R.id.radio_gesture).setVisibility(View.GONE); |
| 84 | ((RadioButton) findViewById(R.id.radio_sw_keys)).setChecked(true); |
| 85 | available--; |
| 86 | } |
| 87 | |
| Bruno Martins | 7055198 | 2022-03-22 20:07:33 +0000 | [diff] [blame] | 88 | if (!SetupWizardUtils.isPackageInstalled(this, NAV_BAR_MODE_2BUTTON_OVERLAY)) { |
| Timi Rautamäki | e83f9e1 | 2022-03-16 13:21:30 +0000 | [diff] [blame] | 89 | findViewById(R.id.radio_two_button).setVisibility(View.GONE); |
| 90 | available--; |
| 91 | } |
| 92 | |
| Bruno Martins | 7055198 | 2022-03-22 20:07:33 +0000 | [diff] [blame] | 93 | if (!SetupWizardUtils.isPackageInstalled(this, NAV_BAR_MODE_3BUTTON_OVERLAY)) { |
| Timi Rautamäki | e83f9e1 | 2022-03-16 13:21:30 +0000 | [diff] [blame] | 94 | findViewById(R.id.radio_sw_keys).setVisibility(View.GONE); |
| 95 | available--; |
| 96 | } |
| 97 | |
| Timi Rautamäki | e83f9e1 | 2022-03-16 13:21:30 +0000 | [diff] [blame] | 98 | // Hide this page if the device has hardware keys but didn't enable navbar |
| 99 | // or if there's <= 1 available navigation modes |
| 100 | if (!navBarEnabled && hasHomeKey || available <= 1) { |
| 101 | mSetupWizardApp.getSettingsBundle().putString(NAVIGATION_OPTION_KEY, |
| 102 | NAV_BAR_MODE_3BUTTON_OVERLAY); |
| 103 | Intent intent = WizardManagerHelper.getNextIntent(getIntent(), Activity.RESULT_OK); |
| 104 | finishAction(RESULT_OK, intent); |
| 105 | } |
| 106 | |
| 107 | final LottieAnimationView navigationIllustration = |
| 108 | findViewById(R.id.navigation_illustration); |
| 109 | final RadioGroup radioGroup = findViewById(R.id.navigation_radio_group); |
| 110 | mHideGesturalHint = findViewById(R.id.hide_navigation_hint); |
| Michael Bestas | a5ba5df | 2023-07-15 16:19:36 +0300 | [diff] [blame^] | 111 | |
| 112 | // Hide navigation hint checkbox when taskbar is enabled |
| 113 | if (mIsTaskbarEnabled) { |
| 114 | mHideGesturalHint.setVisibility(View.GONE); |
| 115 | } |
| 116 | |
| Timi Rautamäki | e83f9e1 | 2022-03-16 13:21:30 +0000 | [diff] [blame] | 117 | radioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() { |
| 118 | @Override |
| 119 | public void onCheckedChanged(RadioGroup group, int checkedId) { |
| 120 | switch (checkedId) { |
| 121 | case R.id.radio_gesture: |
| 122 | mSelection = NAV_BAR_MODE_GESTURAL_OVERLAY; |
| 123 | navigationIllustration |
| 124 | .setAnimation(R.raw.lottie_system_nav_fully_gestural); |
| 125 | revealHintCheckbox(); |
| 126 | break; |
| 127 | case R.id.radio_two_button: |
| 128 | mSelection = NAV_BAR_MODE_2BUTTON_OVERLAY; |
| 129 | navigationIllustration.setAnimation(R.raw.lottie_system_nav_2_button); |
| 130 | hideHintCheckBox(); |
| 131 | break; |
| 132 | case R.id.radio_sw_keys: |
| 133 | mSelection = NAV_BAR_MODE_3BUTTON_OVERLAY; |
| 134 | navigationIllustration.setAnimation(R.raw.lottie_system_nav_3_button); |
| 135 | hideHintCheckBox(); |
| 136 | break; |
| 137 | } |
| 138 | |
| 139 | navigationIllustration.playAnimation(); |
| 140 | } |
| 141 | }); |
| 142 | } |
| 143 | |
| 144 | private void revealHintCheckbox() { |
| Michael Bestas | a5ba5df | 2023-07-15 16:19:36 +0300 | [diff] [blame^] | 145 | if (mIsTaskbarEnabled) { |
| 146 | return; |
| 147 | } |
| 148 | |
| Alessandro Astone | 0fa8417 | 2022-04-04 17:33:18 +0200 | [diff] [blame] | 149 | mHideGesturalHint.animate().cancel(); |
| 150 | |
| Timi Rautamäki | e83f9e1 | 2022-03-16 13:21:30 +0000 | [diff] [blame] | 151 | if (mHideGesturalHint.getVisibility() == View.VISIBLE) { |
| 152 | return; |
| 153 | } |
| 154 | |
| 155 | mHideGesturalHint.setVisibility(View.VISIBLE); |
| 156 | mHideGesturalHint.setAlpha(0.0f); |
| 157 | mHideGesturalHint.animate() |
| 158 | .translationY(0) |
| 159 | .alpha(1.0f) |
| 160 | .setListener(null); |
| 161 | } |
| 162 | |
| 163 | private void hideHintCheckBox() { |
| Michael Bestas | a5ba5df | 2023-07-15 16:19:36 +0300 | [diff] [blame^] | 164 | if (mIsTaskbarEnabled) { |
| 165 | return; |
| 166 | } |
| 167 | |
| Timi Rautamäki | e83f9e1 | 2022-03-16 13:21:30 +0000 | [diff] [blame] | 168 | if (mHideGesturalHint.getVisibility() == View.INVISIBLE) { |
| 169 | return; |
| 170 | } |
| 171 | |
| 172 | mHideGesturalHint.animate() |
| 173 | .translationY(-mHideGesturalHint.getHeight()) |
| 174 | .alpha(0.0f) |
| 175 | .setListener(new AnimatorListenerAdapter() { |
| 176 | @Override |
| 177 | public void onAnimationEnd(Animator animation) { |
| 178 | super.onAnimationEnd(animation); |
| 179 | mHideGesturalHint.setVisibility(View.INVISIBLE); |
| 180 | } |
| 181 | }); |
| 182 | } |
| 183 | |
| 184 | @Override |
| 185 | protected void onNextPressed() { |
| 186 | mSetupWizardApp.getSettingsBundle().putString(NAVIGATION_OPTION_KEY, mSelection); |
| Michael Bestas | a5ba5df | 2023-07-15 16:19:36 +0300 | [diff] [blame^] | 187 | if (!mIsTaskbarEnabled) { |
| 188 | boolean hideHint = mHideGesturalHint.isChecked(); |
| 189 | LineageSettings.System.putIntForUser(getContentResolver(), |
| 190 | LineageSettings.System.NAVIGATION_BAR_HINT, hideHint ? 0 : 1, |
| 191 | UserHandle.USER_CURRENT); |
| 192 | } |
| Timi Rautamäki | e83f9e1 | 2022-03-16 13:21:30 +0000 | [diff] [blame] | 193 | Intent intent = WizardManagerHelper.getNextIntent(getIntent(), Activity.RESULT_OK); |
| 194 | nextAction(NEXT_REQUEST, intent); |
| 195 | } |
| 196 | |
| 197 | @Override |
| 198 | protected int getLayoutResId() { |
| 199 | return R.layout.setup_navigation; |
| 200 | } |
| 201 | |
| 202 | @Override |
| 203 | protected int getTitleResId() { |
| 204 | return R.string.setup_navigation; |
| 205 | } |
| 206 | |
| 207 | @Override |
| 208 | protected int getIconResId() { |
| 209 | return R.drawable.ic_navigation; |
| 210 | } |
| Timi Rautamäki | e83f9e1 | 2022-03-16 13:21:30 +0000 | [diff] [blame] | 211 | } |