blob: 20d1b48fc0c72b8fc5fe4af144a98fe230c806da [file] [log] [blame]
Timi Rautamäkie83f9e12022-03-16 13:21:30 +00001/*
2 * Copyright (C) 2022 The LineageOS Project
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
17package org.lineageos.setupwizard;
18
19import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_2BUTTON_OVERLAY;
20import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_3BUTTON_OVERLAY;
21import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_GESTURAL_OVERLAY;
22
23import static org.lineageos.internal.util.DeviceKeysConstants.KEY_MASK_APP_SWITCH;
24import static org.lineageos.setupwizard.SetupWizardApp.DISABLE_NAV_KEYS;
25import static org.lineageos.setupwizard.SetupWizardApp.NAVIGATION_OPTION_KEY;
26
27import android.animation.Animator;
28import android.animation.AnimatorListenerAdapter;
29import android.app.Activity;
30import android.content.Intent;
31import android.os.Bundle;
32import android.os.UserHandle;
33import android.content.Context;
34import android.view.View;
35import android.widget.CheckBox;
36import android.widget.RadioButton;
37import android.widget.RadioGroup;
38import android.widget.RadioGroup.OnCheckedChangeListener;
39
40import com.airbnb.lottie.LottieAnimationView;
41import com.google.android.setupcompat.util.WizardManagerHelper;
42
43import lineageos.providers.LineageSettings;
44
45import org.lineageos.setupwizard.util.SetupWizardUtils;
46
47public class NavigationSettingsActivity extends BaseSetupWizardActivity {
48
49 public static final String TAG = NavigationSettingsActivity.class.getSimpleName();
50
51 private SetupWizardApp mSetupWizardApp;
52
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 }
66
67 int deviceKeys = getResources().getInteger(
68 org.lineageos.platform.internal.R.integer.config_deviceHardwareKeys);
69 boolean hasHomeKey = (deviceKeys & KEY_MASK_APP_SWITCH) != 0;
70
71 getGlifLayout().setDescriptionText(getString(R.string.navigation_summary));
72 setNextText(R.string.next);
73
74 int available = 3;
75 // Hide unavailable navigation modes
Bruno Martins70551982022-03-22 20:07:33 +000076 if (!SetupWizardUtils.isPackageInstalled(this, NAV_BAR_MODE_GESTURAL_OVERLAY)) {
Timi Rautamäkie83f9e12022-03-16 13:21:30 +000077 findViewById(R.id.radio_gesture).setVisibility(View.GONE);
78 ((RadioButton) findViewById(R.id.radio_sw_keys)).setChecked(true);
79 available--;
80 }
81
Bruno Martins70551982022-03-22 20:07:33 +000082 if (!SetupWizardUtils.isPackageInstalled(this, NAV_BAR_MODE_2BUTTON_OVERLAY)) {
Timi Rautamäkie83f9e12022-03-16 13:21:30 +000083 findViewById(R.id.radio_two_button).setVisibility(View.GONE);
84 available--;
85 }
86
Bruno Martins70551982022-03-22 20:07:33 +000087 if (!SetupWizardUtils.isPackageInstalled(this, NAV_BAR_MODE_3BUTTON_OVERLAY)) {
Timi Rautamäkie83f9e12022-03-16 13:21:30 +000088 findViewById(R.id.radio_sw_keys).setVisibility(View.GONE);
89 available--;
90 }
91
92
93 // Hide this page if the device has hardware keys but didn't enable navbar
94 // or if there's <= 1 available navigation modes
95 if (!navBarEnabled && hasHomeKey || available <= 1) {
96 mSetupWizardApp.getSettingsBundle().putString(NAVIGATION_OPTION_KEY,
97 NAV_BAR_MODE_3BUTTON_OVERLAY);
98 Intent intent = WizardManagerHelper.getNextIntent(getIntent(), Activity.RESULT_OK);
99 finishAction(RESULT_OK, intent);
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);
106 radioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {
107 @Override
108 public void onCheckedChanged(RadioGroup group, int checkedId) {
109 switch (checkedId) {
110 case R.id.radio_gesture:
111 mSelection = NAV_BAR_MODE_GESTURAL_OVERLAY;
112 navigationIllustration
113 .setAnimation(R.raw.lottie_system_nav_fully_gestural);
114 revealHintCheckbox();
115 break;
116 case R.id.radio_two_button:
117 mSelection = NAV_BAR_MODE_2BUTTON_OVERLAY;
118 navigationIllustration.setAnimation(R.raw.lottie_system_nav_2_button);
119 hideHintCheckBox();
120 break;
121 case R.id.radio_sw_keys:
122 mSelection = NAV_BAR_MODE_3BUTTON_OVERLAY;
123 navigationIllustration.setAnimation(R.raw.lottie_system_nav_3_button);
124 hideHintCheckBox();
125 break;
126 }
127
128 navigationIllustration.playAnimation();
129 }
130 });
131 }
132
133 private void revealHintCheckbox() {
Alessandro Astone0fa84172022-04-04 17:33:18 +0200134 mHideGesturalHint.animate().cancel();
135
Timi Rautamäkie83f9e12022-03-16 13:21:30 +0000136 if (mHideGesturalHint.getVisibility() == View.VISIBLE) {
137 return;
138 }
139
140 mHideGesturalHint.setVisibility(View.VISIBLE);
141 mHideGesturalHint.setAlpha(0.0f);
142 mHideGesturalHint.animate()
143 .translationY(0)
144 .alpha(1.0f)
145 .setListener(null);
146 }
147
148 private void hideHintCheckBox() {
149 if (mHideGesturalHint.getVisibility() == View.INVISIBLE) {
150 return;
151 }
152
153 mHideGesturalHint.animate()
154 .translationY(-mHideGesturalHint.getHeight())
155 .alpha(0.0f)
156 .setListener(new AnimatorListenerAdapter() {
157 @Override
158 public void onAnimationEnd(Animator animation) {
159 super.onAnimationEnd(animation);
160 mHideGesturalHint.setVisibility(View.INVISIBLE);
161 }
162 });
163 }
164
165 @Override
166 protected void onNextPressed() {
167 mSetupWizardApp.getSettingsBundle().putString(NAVIGATION_OPTION_KEY, mSelection);
168 boolean hideHint = mHideGesturalHint.isChecked();
169 LineageSettings.System.putIntForUser(getContentResolver(),
170 LineageSettings.System.NAVIGATION_BAR_HINT, hideHint ? 0 : 1,
171 UserHandle.USER_CURRENT);
172 Intent intent = WizardManagerHelper.getNextIntent(getIntent(), Activity.RESULT_OK);
173 nextAction(NEXT_REQUEST, intent);
174 }
175
176 @Override
177 protected int getLayoutResId() {
178 return R.layout.setup_navigation;
179 }
180
181 @Override
182 protected int getTitleResId() {
183 return R.string.setup_navigation;
184 }
185
186 @Override
187 protected int getIconResId() {
188 return R.drawable.ic_navigation;
189 }
Timi Rautamäkie83f9e12022-03-16 13:21:30 +0000190}