SetupWizard: Bring back software nav keys option

Issue-id: OPO-402

Change-Id: Id04105a48dfbb494dddc757f8fe9bcad16796937
This commit is contained in:
cretin45 2016-02-01 14:30:20 -08:00
parent d40d8b83c3
commit 5b276ea335

View File

@ -18,19 +18,16 @@ package com.cyanogenmod.setupwizard.setup;
import android.app.Fragment; import android.app.Fragment;
import android.app.FragmentManager; import android.app.FragmentManager;
import android.content.ComponentName;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.ThemeUtils;
import android.content.res.ThemeConfig; import android.content.res.ThemeConfig;
import android.content.res.ThemeManager; import android.content.res.ThemeManager;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.os.RemoteException; import android.os.RemoteException;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.provider.Settings;
import android.text.Spannable; import android.text.Spannable;
import android.text.SpannableString; import android.text.SpannableString;
import android.text.SpannableStringBuilder; import android.text.SpannableStringBuilder;
@ -49,26 +46,20 @@ import com.cyanogenmod.setupwizard.R;
import com.cyanogenmod.setupwizard.SetupWizardApp; import com.cyanogenmod.setupwizard.SetupWizardApp;
import com.cyanogenmod.setupwizard.cmstats.SetupStats; import com.cyanogenmod.setupwizard.cmstats.SetupStats;
import com.cyanogenmod.setupwizard.ui.SetupPageFragment; import com.cyanogenmod.setupwizard.ui.SetupPageFragment;
import com.cyanogenmod.setupwizard.ui.WebViewDialogFragment;
import com.cyanogenmod.setupwizard.util.SetupWizardUtils; import com.cyanogenmod.setupwizard.util.SetupWizardUtils;
import com.cyanogenmod.setupwizard.util.WhisperPushUtils;
import cyanogenmod.providers.CMSettings;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
import cyanogenmod.hardware.CMHardwareManager; import cyanogenmod.hardware.CMHardwareManager;
import cyanogenmod.providers.CMSettings;
public class CyanogenSettingsPage extends SetupPage { public class CyanogenSettingsPage extends SetupPage {
public static final String TAG = "CyanogenSettingsPage"; public static final String TAG = "CyanogenSettingsPage";
public static final String KEY_SEND_METRICS = "send_metrics"; public static final String KEY_SEND_METRICS = "send_metrics";
public static final String KEY_ENABLE_NAV_KEYS = "enable_nav_keys"; public static final String DISABLE_NAV_KEYS = "disable_nav_keys";
public static final String KEY_APPLY_DEFAULT_THEME = "apply_default_theme"; public static final String KEY_APPLY_DEFAULT_THEME = "apply_default_theme";
public static final String KEY_BUTTON_BACKLIGHT = "pre_navbar_button_backlight";
public static final String SETTING_METRICS = "settings.cyanogen.allow_metrics";
public static final String PRIVACY_POLICY_URI = "https://cyngn.com/oobe-legal?hideHeader=1"; public static final String PRIVACY_POLICY_URI = "https://cyngn.com/oobe-legal?hideHeader=1";
public CyanogenSettingsPage(Context context, SetupDataCallbacks callbacks) { public CyanogenSettingsPage(Context context, SetupDataCallbacks callbacks) {
@ -100,47 +91,37 @@ public class CyanogenSettingsPage extends SetupPage {
private static void writeDisableNavkeysOption(Context context, boolean enabled) { private static void writeDisableNavkeysOption(Context context, boolean enabled) {
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
/*final int defaultBrightness = context.getResources().getInteger(
com.android.internal.R.integer.config_buttonBrightnessSettingDefault);*/
/*Settings.Secure.putInt(context.getContentResolver(), CMSettings.Secure.putInt(context.getContentResolver(),
Settings.Secure.DEV_FORCE_SHOW_NAVBAR, enabled ? 1 : 0); CMSettings.Secure.DEV_FORCE_SHOW_NAVBAR, enabled ? 1 : 0);
final CMHardwareManager hardware = CMHardwareManager.getInstance(context); CMHardwareManager hardware = CMHardwareManager.getInstance(context);
hardware.set(CMHardwareManager.FEATURE_KEY_DISABLE, enabled);*/ hardware.set(CMHardwareManager.FEATURE_KEY_DISABLE, enabled);
/* Save/restore button timeouts to disable them in softkey mode */ /* Save/restore button timeouts to disable them in softkey mode */
SharedPreferences.Editor editor = prefs.edit();
if (enabled) { if (enabled) {
int currentBrightness = CMSettings.Secure.getInt(context.getContentResolver(),
CMSettings.Secure.BUTTON_BRIGHTNESS, 100);
if (!prefs.contains("pre_navbar_button_backlight")) {
editor.putInt("pre_navbar_button_backlight", currentBrightness);
}
CMSettings.Secure.putInt(context.getContentResolver(), CMSettings.Secure.putInt(context.getContentResolver(),
CMSettings.Secure.BUTTON_BRIGHTNESS, 0); CMSettings.Secure.BUTTON_BRIGHTNESS, 0);
} else { } else {
int oldBright = prefs.getInt("pre_navbar_button_backlight", -1); int currentBrightness = CMSettings.Secure.getInt(context.getContentResolver(),
if (oldBright != -1) { CMSettings.Secure.BUTTON_BRIGHTNESS, 100);
int oldBright = prefs.getInt(KEY_BUTTON_BACKLIGHT,
currentBrightness);
CMSettings.Secure.putInt(context.getContentResolver(), CMSettings.Secure.putInt(context.getContentResolver(),
CMSettings.Secure.BUTTON_BRIGHTNESS, oldBright); CMSettings.Secure.BUTTON_BRIGHTNESS, oldBright);
editor.remove("pre_navbar_button_backlight");
} }
} }
editor.commit();
}
@Override @Override
public void onFinishSetup() { public void onFinishSetup() {
getCallbacks().addFinishRunnable(new Runnable() { getCallbacks().addFinishRunnable(new Runnable() {
@Override @Override
public void run() { public void run() {
if (getData().containsKey(KEY_ENABLE_NAV_KEYS)) { if (getData().containsKey(DISABLE_NAV_KEYS)) {
SetupStats.addEvent(SetupStats.Categories.SETTING_CHANGED, SetupStats.addEvent(SetupStats.Categories.SETTING_CHANGED,
SetupStats.Action.ENABLE_NAV_KEYS, SetupStats.Action.ENABLE_NAV_KEYS,
SetupStats.Label.CHECKED, SetupStats.Label.CHECKED,
String.valueOf(getData().getBoolean(KEY_ENABLE_NAV_KEYS))); String.valueOf(getData().getBoolean(DISABLE_NAV_KEYS)));
writeDisableNavkeysOption(mContext, getData().getBoolean(KEY_ENABLE_NAV_KEYS)); writeDisableNavkeysOption(mContext, getData().getBoolean(DISABLE_NAV_KEYS));
} }
} }
}); });
@ -230,7 +211,7 @@ public class CyanogenSettingsPage extends SetupPage {
public void onClick(View view) { public void onClick(View view) {
boolean checked = !mNavKeys.isChecked(); boolean checked = !mNavKeys.isChecked();
mNavKeys.setChecked(checked); mNavKeys.setChecked(checked);
mPage.getData().putBoolean(KEY_ENABLE_NAV_KEYS, checked); mPage.getData().putBoolean(DISABLE_NAV_KEYS, checked);
} }
}; };
@ -310,11 +291,11 @@ public class CyanogenSettingsPage extends SetupPage {
mNavKeysRow.setOnClickListener(mNavKeysClickListener); mNavKeysRow.setOnClickListener(mNavKeysClickListener);
mNavKeys = (CheckBox) mRootView.findViewById(R.id.nav_keys_checkbox); mNavKeys = (CheckBox) mRootView.findViewById(R.id.nav_keys_checkbox);
boolean needsNavBar = true; boolean needsNavBar = true;
/*try { try {
IWindowManager windowManager = WindowManagerGlobal.getWindowManagerService(); IWindowManager windowManager = WindowManagerGlobal.getWindowManagerService();
needsNavBar = windowManager.needsNavigationBar(); needsNavBar = windowManager.needsNavigationBar();
} catch (RemoteException e) { } catch (RemoteException e) {
}*/ }
mHideNavKeysRow = hideKeyDisabler(getActivity()); mHideNavKeysRow = hideKeyDisabler(getActivity());
if (mHideNavKeysRow || needsNavBar) { if (mHideNavKeysRow || needsNavBar) {
mNavKeysRow.setVisibility(View.GONE); mNavKeysRow.setVisibility(View.GONE);
@ -333,7 +314,7 @@ public class CyanogenSettingsPage extends SetupPage {
@Override @Override
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
/*updateDisableNavkeysOption();*/ updateDisableNavkeysOption();
updateMetricsOption(); updateMetricsOption();
updateThemeOption(); updateThemeOption();
} }
@ -362,18 +343,18 @@ public class CyanogenSettingsPage extends SetupPage {
} }
} }
/*private void updateDisableNavkeysOption() { private void updateDisableNavkeysOption() {
if (!mHideNavKeysRow) { if (!mHideNavKeysRow) {
final Bundle myPageBundle = mPage.getData(); final Bundle myPageBundle = mPage.getData();
boolean enabled = Settings.Secure.getInt(getActivity().getContentResolver(), boolean enabled = CMSettings.Secure.getInt(getActivity().getContentResolver(),
Settings.Secure.DEV_FORCE_SHOW_NAVBAR, 0) != 0; CMSettings.Secure.DEV_FORCE_SHOW_NAVBAR, 0) != 0;
boolean checked = myPageBundle.containsKey(KEY_ENABLE_NAV_KEYS) ? boolean checked = myPageBundle.containsKey(DISABLE_NAV_KEYS) ?
myPageBundle.getBoolean(KEY_ENABLE_NAV_KEYS) : myPageBundle.getBoolean(DISABLE_NAV_KEYS) :
enabled; enabled;
mNavKeys.setChecked(checked); mNavKeys.setChecked(checked);
myPageBundle.putBoolean(KEY_ENABLE_NAV_KEYS, checked); myPageBundle.putBoolean(DISABLE_NAV_KEYS, checked);
}
} }
}*/
private static boolean hideKillSwitch() { private static boolean hideKillSwitch() {
return !SetupWizardUtils.hasKillSwitch(); return !SetupWizardUtils.hasKillSwitch();