blob: 974bd155d1ad8570e97967d7af31423b73327957 [file] [log] [blame]
cretin453593f032016-04-20 16:21:05 -07001/*
Michael Bestasec050052024-02-14 20:35:43 +02002 * SPDX-FileCopyrightText: 2016 The CyanogenMod Project
3 * SPDX-FileCopyrightText: 2017-2024 The LineageOS Project
4 * SPDX-License-Identifier: Apache-2.0
cretin453593f032016-04-20 16:21:05 -07005 */
6
Michael Bestasc83309e2018-02-03 17:42:13 +02007package org.lineageos.setupwizard;
cretin453593f032016-04-20 16:21:05 -07008
Michael Bestasc83309e2018-02-03 17:42:13 +02009import static org.lineageos.setupwizard.SetupWizardApp.DISABLE_NAV_KEYS;
Michael Bestasc83309e2018-02-03 17:42:13 +020010import static org.lineageos.setupwizard.SetupWizardApp.KEY_SEND_METRICS;
cretin453593f032016-04-20 16:21:05 -070011
cretin453593f032016-04-20 16:21:05 -070012import android.content.Context;
cretin453593f032016-04-20 16:21:05 -070013import android.os.Bundle;
Bruno Martinsa8e278d2018-09-28 08:50:50 +010014import android.os.UserHandle;
cretin453593f032016-04-20 16:21:05 -070015import android.text.Spannable;
cretin453593f032016-04-20 16:21:05 -070016import android.text.SpannableStringBuilder;
cretin453593f032016-04-20 16:21:05 -070017import android.view.View;
cretin453593f032016-04-20 16:21:05 -070018import android.widget.CheckBox;
cretin453593f032016-04-20 16:21:05 -070019import android.widget.TextView;
20
Abhisek Devkotacc839c92018-01-29 12:41:42 -080021import lineageos.hardware.LineageHardwareManager;
22import lineageos.providers.LineageSettings;
cretin453593f032016-04-20 16:21:05 -070023
24public class LineageSettingsActivity extends BaseSetupWizardActivity {
25
cretin453593f032016-04-20 16:21:05 -070026 private SetupWizardApp mSetupWizardApp;
27
cretin453593f032016-04-20 16:21:05 -070028 private CheckBox mMetrics;
cretin453593f032016-04-20 16:21:05 -070029 private CheckBox mNavKeys;
cretin453593f032016-04-20 16:21:05 -070030
Bruno Martins33636d12018-09-17 13:53:31 +010031 private boolean mSupportsKeyDisabler = false;
cretin453593f032016-04-20 16:21:05 -070032
Michael Bestasb7b34b92021-08-25 19:13:30 +030033 private final View.OnClickListener mMetricsClickListener = view -> {
Michael W2236d292018-07-15 15:09:20 +020034 boolean checked = !mMetrics.isChecked();
35 mMetrics.setChecked(checked);
36 mSetupWizardApp.getSettingsBundle().putBoolean(KEY_SEND_METRICS, checked);
cretin453593f032016-04-20 16:21:05 -070037 };
38
Michael Bestasb7b34b92021-08-25 19:13:30 +030039 private final View.OnClickListener mNavKeysClickListener = view -> {
Michael W2236d292018-07-15 15:09:20 +020040 boolean checked = !mNavKeys.isChecked();
41 mNavKeys.setChecked(checked);
42 mSetupWizardApp.getSettingsBundle().putBoolean(DISABLE_NAV_KEYS, checked);
cretin453593f032016-04-20 16:21:05 -070043 };
44
cretin453593f032016-04-20 16:21:05 -070045 @Override
46 protected void onCreate(Bundle savedInstanceState) {
47 super.onCreate(savedInstanceState);
48 mSetupWizardApp = (SetupWizardApp) getApplication();
cretin453593f032016-04-20 16:21:05 -070049 setNextText(R.string.next);
Timi Rautamäki9b2f1372021-11-15 18:01:38 +000050
Michael Bestas070a8522021-09-22 01:26:02 +030051 String os_name = getString(R.string.os_name);
Timi Rautamäki9b2f1372021-11-15 18:01:38 +000052 String privacyPolicy = getString(R.string.services_pp_explanation, os_name);
Alexander Martinz60324842022-10-17 16:30:25 +020053 String privacyPolicyUri = getString(R.string.services_privacy_policy_uri);
54 String policySummary = getString(R.string.services_find_privacy_policy, privacyPolicyUri);
Timi Rautamäki3ca81562022-01-15 16:42:42 +000055 String servicesFullDescription = getString(R.string.services_full_description,
56 privacyPolicy, policySummary);
57 getGlifLayout().setDescriptionText(servicesFullDescription);
cretin453593f032016-04-20 16:21:05 -070058
Michael W2236d292018-07-15 15:09:20 +020059 View metricsRow = findViewById(R.id.metrics);
60 metricsRow.setOnClickListener(mMetricsClickListener);
Timi Rautamäkidaef80e2022-01-15 09:25:02 +000061 metricsRow.requestFocus();
Michael Bestasc83309e2018-02-03 17:42:13 +020062 String metricsHelpImproveLineage =
Michael Bestas070a8522021-09-22 01:26:02 +030063 getString(R.string.services_help_improve_cm, os_name);
cretin453593f032016-04-20 16:21:05 -070064 String metricsSummary = getString(R.string.services_metrics_label,
Michael Bestas070a8522021-09-22 01:26:02 +030065 metricsHelpImproveLineage, os_name, os_name);
cretin453593f032016-04-20 16:21:05 -070066 final SpannableStringBuilder metricsSpan = new SpannableStringBuilder(metricsSummary);
67 metricsSpan.setSpan(new android.text.style.StyleSpan(android.graphics.Typeface.BOLD),
Michael Bestasc83309e2018-02-03 17:42:13 +020068 0, metricsHelpImproveLineage.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
Oliver Scott51fde0a2024-01-06 22:15:26 -050069 TextView metrics = findViewById(R.id.enable_metrics_summary);
cretin453593f032016-04-20 16:21:05 -070070 metrics.setText(metricsSpan);
Oliver Scott51fde0a2024-01-06 22:15:26 -050071 mMetrics = findViewById(R.id.enable_metrics_checkbox);
cretin453593f032016-04-20 16:21:05 -070072
Michael W2236d292018-07-15 15:09:20 +020073 View navKeysRow = findViewById(R.id.nav_keys);
74 navKeysRow.setOnClickListener(mNavKeysClickListener);
Oliver Scott51fde0a2024-01-06 22:15:26 -050075 mNavKeys = findViewById(R.id.nav_keys_checkbox);
Bruno Martins33636d12018-09-17 13:53:31 +010076 mSupportsKeyDisabler = isKeyDisablerSupported(this);
77 if (mSupportsKeyDisabler) {
Bruno Martins0277e732019-01-18 10:42:41 +000078 mNavKeys.setChecked(LineageSettings.System.getIntForUser(getContentResolver(),
79 LineageSettings.System.FORCE_SHOW_NAVBAR, 0, UserHandle.USER_CURRENT) != 0);
Bruno Martins33636d12018-09-17 13:53:31 +010080 } else {
81 navKeysRow.setVisibility(View.GONE);
cretin453593f032016-04-20 16:21:05 -070082 }
cretin453593f032016-04-20 16:21:05 -070083 }
84
85 @Override
86 public void onResume() {
87 super.onResume();
88 updateDisableNavkeysOption();
89 updateMetricsOption();
cretin453593f032016-04-20 16:21:05 -070090 }
91
92 @Override
cretin45d4cea552016-04-25 11:00:04 -070093 protected int getLayoutResId() {
94 return R.layout.setup_lineage_settings;
95 }
96
97 @Override
98 protected int getTitleResId() {
99 return R.string.setup_services;
100 }
101
102 @Override
103 protected int getIconResId() {
104 return R.drawable.ic_features;
105 }
106
cretin453593f032016-04-20 16:21:05 -0700107 private void updateMetricsOption() {
108 final Bundle myPageBundle = mSetupWizardApp.getSettingsBundle();
109 boolean metricsChecked =
110 !myPageBundle.containsKey(KEY_SEND_METRICS) || myPageBundle
111 .getBoolean(KEY_SEND_METRICS);
112 mMetrics.setChecked(metricsChecked);
113 myPageBundle.putBoolean(KEY_SEND_METRICS, metricsChecked);
114 }
115
cretin453593f032016-04-20 16:21:05 -0700116 private void updateDisableNavkeysOption() {
Bruno Martins33636d12018-09-17 13:53:31 +0100117 if (mSupportsKeyDisabler) {
cretin453593f032016-04-20 16:21:05 -0700118 final Bundle myPageBundle = mSetupWizardApp.getSettingsBundle();
Bruno Martinsa8e278d2018-09-28 08:50:50 +0100119 boolean enabled = LineageSettings.System.getIntForUser(getContentResolver(),
120 LineageSettings.System.FORCE_SHOW_NAVBAR, 0, UserHandle.USER_CURRENT) != 0;
cretin453593f032016-04-20 16:21:05 -0700121 boolean checked = myPageBundle.containsKey(DISABLE_NAV_KEYS) ?
122 myPageBundle.getBoolean(DISABLE_NAV_KEYS) :
123 enabled;
124 mNavKeys.setChecked(checked);
125 myPageBundle.putBoolean(DISABLE_NAV_KEYS, checked);
126 }
127 }
128
Bruno Martins33636d12018-09-17 13:53:31 +0100129 private static boolean isKeyDisablerSupported(Context context) {
Abhisek Devkotacc839c92018-01-29 12:41:42 -0800130 final LineageHardwareManager hardware = LineageHardwareManager.getInstance(context);
Bruno Martins33636d12018-09-17 13:53:31 +0100131 return hardware.isSupported(LineageHardwareManager.FEATURE_KEY_DISABLE);
cretin453593f032016-04-20 16:21:05 -0700132 }
cretin453593f032016-04-20 16:21:05 -0700133}