Merge "Refactoring in Settings/Applications"
This commit is contained in:
committed by
Android (Google) Code Review
commit
2c12ed9e4b
@@ -16,23 +16,17 @@
|
||||
|
||||
package com.android.settings;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Configuration;
|
||||
import android.os.Bundle;
|
||||
import android.preference.CheckBoxPreference;
|
||||
import android.preference.ListPreference;
|
||||
import android.preference.Preference;
|
||||
import android.preference.PreferenceScreen;
|
||||
import android.preference.Preference.OnPreferenceChangeListener;
|
||||
import android.preference.PreferenceScreen;
|
||||
import android.provider.Settings;
|
||||
import android.util.Log;
|
||||
|
||||
public class ApplicationSettings extends SettingsPreferenceFragment implements
|
||||
DialogInterface.OnClickListener {
|
||||
public class ApplicationSettings extends SettingsPreferenceFragment {
|
||||
|
||||
private static final String KEY_TOGGLE_INSTALL_APPLICATIONS = "toggle_install_applications";
|
||||
private static final String KEY_TOGGLE_ADVANCED_SETTINGS = "toggle_advanced_settings";
|
||||
private static final String KEY_APP_INSTALL_LOCATION = "app_install_location";
|
||||
|
||||
@@ -45,10 +39,8 @@ public class ApplicationSettings extends SettingsPreferenceFragment implements
|
||||
private static final String APP_INSTALL_SDCARD_ID = "sdcard";
|
||||
private static final String APP_INSTALL_AUTO_ID = "auto";
|
||||
|
||||
private CheckBoxPreference mToggleAppInstallation;
|
||||
private CheckBoxPreference mToggleAdvancedSettings;
|
||||
private ListPreference mInstallLocation;
|
||||
private DialogInterface mWarnInstallApps;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
@@ -56,10 +48,6 @@ public class ApplicationSettings extends SettingsPreferenceFragment implements
|
||||
|
||||
addPreferencesFromResource(R.xml.application_settings);
|
||||
|
||||
mToggleAppInstallation = (CheckBoxPreference)findPreference(
|
||||
KEY_TOGGLE_INSTALL_APPLICATIONS);
|
||||
mToggleAppInstallation.setChecked(isNonMarketAppsAllowed());
|
||||
|
||||
mToggleAdvancedSettings = (CheckBoxPreference)findPreference(
|
||||
KEY_TOGGLE_ADVANCED_SETTINGS);
|
||||
mToggleAdvancedSettings.setChecked(isAdvancedSettingsEnabled());
|
||||
@@ -106,24 +94,9 @@ public class ApplicationSettings extends SettingsPreferenceFragment implements
|
||||
mInstallLocation.setValue(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
if (mWarnInstallApps != null) {
|
||||
mWarnInstallApps.dismiss();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
|
||||
if (preference == mToggleAppInstallation) {
|
||||
if (mToggleAppInstallation.isChecked()) {
|
||||
mToggleAppInstallation.setChecked(false);
|
||||
warnAppInstallation();
|
||||
} else {
|
||||
setNonMarketAppsAllowed(false);
|
||||
}
|
||||
} else if (preference == mToggleAdvancedSettings) {
|
||||
if (preference == mToggleAdvancedSettings) {
|
||||
boolean value = mToggleAdvancedSettings.isChecked();
|
||||
setAdvancedSettingsEnabled(value);
|
||||
}
|
||||
@@ -131,19 +104,6 @@ public class ApplicationSettings extends SettingsPreferenceFragment implements
|
||||
return super.onPreferenceTreeClick(preferenceScreen, preference);
|
||||
}
|
||||
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
if (dialog == mWarnInstallApps && which == DialogInterface.BUTTON_POSITIVE) {
|
||||
setNonMarketAppsAllowed(true);
|
||||
mToggleAppInstallation.setChecked(true);
|
||||
}
|
||||
}
|
||||
|
||||
private void setNonMarketAppsAllowed(boolean enabled) {
|
||||
// Change the system setting
|
||||
Settings.Secure.putInt(getContentResolver(), Settings.Secure.INSTALL_NON_MARKET_APPS,
|
||||
enabled ? 1 : 0);
|
||||
}
|
||||
|
||||
private boolean isAdvancedSettingsEnabled() {
|
||||
return Settings.System.getInt(getContentResolver(),
|
||||
Settings.System.ADVANCED_SETTINGS,
|
||||
@@ -160,11 +120,6 @@ public class ApplicationSettings extends SettingsPreferenceFragment implements
|
||||
getActivity().sendBroadcast(intent);
|
||||
}
|
||||
|
||||
private boolean isNonMarketAppsAllowed() {
|
||||
return Settings.Secure.getInt(getContentResolver(),
|
||||
Settings.Secure.INSTALL_NON_MARKET_APPS, 0) > 0;
|
||||
}
|
||||
|
||||
private String getAppInstallLocation() {
|
||||
int selectedLocation = Settings.System.getInt(getContentResolver(),
|
||||
Settings.Secure.DEFAULT_INSTALL_LOCATION, APP_INSTALL_AUTO);
|
||||
@@ -179,15 +134,4 @@ public class ApplicationSettings extends SettingsPreferenceFragment implements
|
||||
return APP_INSTALL_AUTO_ID;
|
||||
}
|
||||
}
|
||||
|
||||
private void warnAppInstallation() {
|
||||
// TODO: DialogFragment?
|
||||
mWarnInstallApps = new AlertDialog.Builder(getActivity()).setTitle(
|
||||
getResources().getString(R.string.error_title))
|
||||
.setIcon(com.android.internal.R.drawable.ic_dialog_alert)
|
||||
.setMessage(getResources().getString(R.string.install_all_warning))
|
||||
.setPositiveButton(android.R.string.yes, this)
|
||||
.setNegativeButton(android.R.string.no, null)
|
||||
.show();
|
||||
}
|
||||
}
|
||||
|
@@ -19,8 +19,10 @@ package com.android.settings;
|
||||
|
||||
import static android.provider.Settings.System.SCREEN_OFF_TIMEOUT;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.app.admin.DevicePolicyManager;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.Vibrator;
|
||||
@@ -43,7 +45,7 @@ import java.util.ArrayList;
|
||||
* Gesture lock pattern settings.
|
||||
*/
|
||||
public class SecuritySettings extends SettingsPreferenceFragment
|
||||
implements OnPreferenceChangeListener {
|
||||
implements OnPreferenceChangeListener, DialogInterface.OnClickListener {
|
||||
|
||||
// Lock Settings
|
||||
private static final String KEY_UNLOCK_SET_OR_CHANGE = "unlock_set_or_change";
|
||||
@@ -58,6 +60,7 @@ public class SecuritySettings extends SettingsPreferenceFragment
|
||||
private static final String KEY_SIM_LOCK = "sim_lock";
|
||||
private static final String KEY_SHOW_PASSWORD = "show_password";
|
||||
private static final String KEY_RESET_CREDENTIALS = "reset_credentials";
|
||||
private static final String KEY_TOGGLE_INSTALL_APPLICATIONS = "toggle_install_applications";
|
||||
|
||||
DevicePolicyManager mDPM;
|
||||
|
||||
@@ -72,6 +75,9 @@ public class SecuritySettings extends SettingsPreferenceFragment
|
||||
|
||||
private Preference mResetCredentials;
|
||||
|
||||
private CheckBoxPreference mToggleAppInstallation;
|
||||
private DialogInterface mWarnInstallApps;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@@ -167,9 +173,50 @@ public class SecuritySettings extends SettingsPreferenceFragment
|
||||
// Credential storage
|
||||
mResetCredentials = root.findPreference(KEY_RESET_CREDENTIALS);
|
||||
|
||||
mToggleAppInstallation = (CheckBoxPreference) findPreference(
|
||||
KEY_TOGGLE_INSTALL_APPLICATIONS);
|
||||
mToggleAppInstallation.setChecked(isNonMarketAppsAllowed());
|
||||
|
||||
return root;
|
||||
}
|
||||
|
||||
private boolean isNonMarketAppsAllowed() {
|
||||
return Settings.Secure.getInt(getContentResolver(),
|
||||
Settings.Secure.INSTALL_NON_MARKET_APPS, 0) > 0;
|
||||
}
|
||||
|
||||
private void setNonMarketAppsAllowed(boolean enabled) {
|
||||
// Change the system setting
|
||||
Settings.Secure.putInt(getContentResolver(), Settings.Secure.INSTALL_NON_MARKET_APPS,
|
||||
enabled ? 1 : 0);
|
||||
}
|
||||
|
||||
private void warnAppInstallation() {
|
||||
// TODO: DialogFragment?
|
||||
mWarnInstallApps = new AlertDialog.Builder(getActivity()).setTitle(
|
||||
getResources().getString(R.string.error_title))
|
||||
.setIcon(com.android.internal.R.drawable.ic_dialog_alert)
|
||||
.setMessage(getResources().getString(R.string.install_all_warning))
|
||||
.setPositiveButton(android.R.string.yes, this)
|
||||
.setNegativeButton(android.R.string.no, null)
|
||||
.show();
|
||||
}
|
||||
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
if (dialog == mWarnInstallApps && which == DialogInterface.BUTTON_POSITIVE) {
|
||||
setNonMarketAppsAllowed(true);
|
||||
mToggleAppInstallation.setChecked(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
if (mWarnInstallApps != null) {
|
||||
mWarnInstallApps.dismiss();
|
||||
}
|
||||
}
|
||||
|
||||
private void setupLockAfterPreference() {
|
||||
// Compatible with pre-Froyo
|
||||
long currentTimeout = Settings.Secure.getLong(getContentResolver(),
|
||||
@@ -272,6 +319,13 @@ public class SecuritySettings extends SettingsPreferenceFragment
|
||||
} else if (preference == mShowPassword) {
|
||||
Settings.System.putInt(getContentResolver(), Settings.System.TEXT_SHOW_PASSWORD,
|
||||
mShowPassword.isChecked() ? 1 : 0);
|
||||
} else if (preference == mToggleAppInstallation) {
|
||||
if (mToggleAppInstallation.isChecked()) {
|
||||
mToggleAppInstallation.setChecked(false);
|
||||
warnAppInstallation();
|
||||
} else {
|
||||
setNonMarketAppsAllowed(false);
|
||||
}
|
||||
} else {
|
||||
// If we didn't handle it, let preferences handle it.
|
||||
return super.onPreferenceTreeClick(preferenceScreen, preference);
|
||||
|
Reference in New Issue
Block a user