Update Backup/reset UI
BUG: 20489775 Change-Id: I2c97fdf240ddd3e9f0a518478d5da91b91abe394
This commit is contained in:
@@ -16,12 +16,9 @@
|
||||
|
||||
package com.android.settings;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.app.backup.IBackupManager;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.Process;
|
||||
@@ -49,8 +46,7 @@ import java.util.Set;
|
||||
/**
|
||||
* Gesture lock pattern settings.
|
||||
*/
|
||||
public class PrivacySettings extends SettingsPreferenceFragment implements
|
||||
DialogInterface.OnClickListener, Indexable {
|
||||
public class PrivacySettings extends SettingsPreferenceFragment implements Indexable {
|
||||
|
||||
// Vendor specific
|
||||
private static final String GSETTINGS_PROVIDER = "com.google.settings";
|
||||
@@ -61,15 +57,11 @@ public class PrivacySettings extends SettingsPreferenceFragment implements
|
||||
private static final String FACTORY_RESET = "factory_reset";
|
||||
private static final String TAG = "PrivacySettings";
|
||||
private IBackupManager mBackupManager;
|
||||
private SwitchPreference mBackup;
|
||||
private PreferenceScreen mBackup;
|
||||
private SwitchPreference mAutoRestore;
|
||||
private Dialog mConfirmDialog;
|
||||
private PreferenceScreen mConfigure;
|
||||
private boolean mEnabled;
|
||||
|
||||
private static final int DIALOG_ERASE_BACKUP = 2;
|
||||
private int mDialogType;
|
||||
|
||||
@Override
|
||||
protected int getMetricsCategory() {
|
||||
return MetricsLogger.PRIVACY;
|
||||
@@ -89,8 +81,7 @@ public class PrivacySettings extends SettingsPreferenceFragment implements
|
||||
mBackupManager = IBackupManager.Stub.asInterface(
|
||||
ServiceManager.getService(Context.BACKUP_SERVICE));
|
||||
|
||||
mBackup = (SwitchPreference) screen.findPreference(BACKUP_DATA);
|
||||
mBackup.setOnPreferenceChangeListener(preferenceChangeListener);
|
||||
mBackup = (PreferenceScreen) screen.findPreference(BACKUP_DATA);
|
||||
|
||||
mAutoRestore = (SwitchPreference) screen.findPreference(AUTO_RESTORE);
|
||||
mAutoRestore.setOnPreferenceChangeListener(preferenceChangeListener);
|
||||
@@ -120,16 +111,6 @@ public class PrivacySettings extends SettingsPreferenceFragment implements
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
if (mConfirmDialog != null && mConfirmDialog.isShowing()) {
|
||||
mConfirmDialog.dismiss();
|
||||
}
|
||||
mConfirmDialog = null;
|
||||
mDialogType = 0;
|
||||
super.onStop();
|
||||
}
|
||||
|
||||
private OnPreferenceChangeListener preferenceChangeListener = new OnPreferenceChangeListener() {
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
@@ -138,16 +119,7 @@ public class PrivacySettings extends SettingsPreferenceFragment implements
|
||||
}
|
||||
boolean nextValue = (Boolean) newValue;
|
||||
boolean result = false;
|
||||
if (preference == mBackup) {
|
||||
if (nextValue == false) {
|
||||
// Don't change Switch status until user makes choice in dialog
|
||||
// so return false here.
|
||||
showEraseBackupDialog();
|
||||
} else {
|
||||
setBackupEnabled(true);
|
||||
result = true;
|
||||
}
|
||||
} else if (preference == mAutoRestore) {
|
||||
if (preference == mAutoRestore) {
|
||||
try {
|
||||
mBackupManager.setAutoRestore(nextValue);
|
||||
result = true;
|
||||
@@ -159,19 +131,9 @@ public class PrivacySettings extends SettingsPreferenceFragment implements
|
||||
}
|
||||
};
|
||||
|
||||
private void showEraseBackupDialog() {
|
||||
mDialogType = DIALOG_ERASE_BACKUP;
|
||||
CharSequence msg = getResources().getText(R.string.backup_erase_dialog_message);
|
||||
// TODO: DialogFragment?
|
||||
mConfirmDialog = new AlertDialog.Builder(getActivity()).setMessage(msg)
|
||||
.setTitle(R.string.backup_erase_dialog_title)
|
||||
.setPositiveButton(android.R.string.ok, this)
|
||||
.setNegativeButton(android.R.string.cancel, this)
|
||||
.show();
|
||||
}
|
||||
|
||||
/*
|
||||
* Creates toggles for each available location provider
|
||||
* Creates toggles for each backup/reset preference.
|
||||
*/
|
||||
private void updateToggles() {
|
||||
ContentResolver res = getContentResolver();
|
||||
@@ -184,11 +146,14 @@ public class PrivacySettings extends SettingsPreferenceFragment implements
|
||||
String transport = mBackupManager.getCurrentTransport();
|
||||
configIntent = mBackupManager.getConfigurationIntent(transport);
|
||||
configSummary = mBackupManager.getDestinationString(transport);
|
||||
|
||||
mBackup.setSummary(backupEnabled
|
||||
? R.string.accessibility_feature_state_on
|
||||
: R.string.accessibility_feature_state_off);
|
||||
} catch (RemoteException e) {
|
||||
// leave it 'false' and disable the UI; there's no backup manager
|
||||
mBackup.setEnabled(false);
|
||||
}
|
||||
mBackup.setChecked(backupEnabled);
|
||||
|
||||
mAutoRestore.setChecked(Settings.Secure.getInt(res,
|
||||
Settings.Secure.BACKUP_AUTO_RESTORE, 1) == 1);
|
||||
@@ -208,54 +173,6 @@ public class PrivacySettings extends SettingsPreferenceFragment implements
|
||||
}
|
||||
}
|
||||
|
||||
private void updateConfigureSummary() {
|
||||
try {
|
||||
String transport = mBackupManager.getCurrentTransport();
|
||||
String summary = mBackupManager.getDestinationString(transport);
|
||||
setConfigureSummary(summary);
|
||||
} catch (RemoteException e) {
|
||||
// Not much we can do here
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
// Dialog is triggered before Switch status change, that means marking the Switch to
|
||||
// true in showEraseBackupDialog() method will be override by following status change.
|
||||
// So we do manual switching here due to users' response.
|
||||
if (mDialogType == DIALOG_ERASE_BACKUP) {
|
||||
// Accept turning off backup
|
||||
if (which == DialogInterface.BUTTON_POSITIVE) {
|
||||
setBackupEnabled(false);
|
||||
} else if (which == DialogInterface.BUTTON_NEGATIVE) {
|
||||
// Reject turning off backup
|
||||
setBackupEnabled(true);
|
||||
}
|
||||
updateConfigureSummary();
|
||||
}
|
||||
mDialogType = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Informs the BackupManager of a change in backup state - if backup is disabled,
|
||||
* the data on the server will be erased.
|
||||
* @param enable whether to enable backup
|
||||
*/
|
||||
private void setBackupEnabled(boolean enable) {
|
||||
if (mBackupManager != null) {
|
||||
try {
|
||||
mBackupManager.setBackupEnabled(enable);
|
||||
} catch (RemoteException e) {
|
||||
mBackup.setChecked(!enable);
|
||||
mAutoRestore.setEnabled(!enable);
|
||||
return;
|
||||
}
|
||||
}
|
||||
mBackup.setChecked(enable);
|
||||
mAutoRestore.setEnabled(enable);
|
||||
mConfigure.setEnabled(enable);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getHelpResource() {
|
||||
return R.string.help_url_backup_reset;
|
||||
|
174
src/com/android/settings/backup/ToggleBackupSettingFragment.java
Normal file
174
src/com/android/settings/backup/ToggleBackupSettingFragment.java
Normal file
@@ -0,0 +1,174 @@
|
||||
package com.android.settings.backup;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.app.backup.IBackupManager;
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.os.RemoteException;
|
||||
import android.os.ServiceManager;
|
||||
import android.preference.Preference;
|
||||
import android.preference.PreferenceScreen;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.android.internal.logging.MetricsLogger;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
import com.android.settings.widget.SwitchBar;
|
||||
import com.android.settings.widget.ToggleSwitch;
|
||||
|
||||
/**
|
||||
* Fragment to display a bunch of text about backup and restore, and allow the user to enable/
|
||||
* disable it.
|
||||
*/
|
||||
public class ToggleBackupSettingFragment extends SettingsPreferenceFragment
|
||||
implements DialogInterface.OnClickListener {
|
||||
private static final String TAG = "ToggleBackupSettingFragment";
|
||||
|
||||
private static final String BACKUP_TOGGLE = "toggle_backup";
|
||||
|
||||
private IBackupManager mBackupManager;
|
||||
|
||||
protected SwitchBar mSwitchBar;
|
||||
protected ToggleSwitch mToggleSwitch;
|
||||
|
||||
private Preference mSummaryPreference;
|
||||
|
||||
private Dialog mConfirmDialog;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
mBackupManager = IBackupManager.Stub.asInterface(
|
||||
ServiceManager.getService(Context.BACKUP_SERVICE));
|
||||
|
||||
PreferenceScreen preferenceScreen = getPreferenceManager().createPreferenceScreen(
|
||||
getActivity());
|
||||
setPreferenceScreen(preferenceScreen);
|
||||
mSummaryPreference = new Preference(getActivity()) {
|
||||
@Override
|
||||
protected void onBindView(View view) {
|
||||
super.onBindView(view);
|
||||
final TextView summaryView = (TextView) view.findViewById(android.R.id.summary);
|
||||
summaryView.setText(getSummary());
|
||||
}
|
||||
};
|
||||
mSummaryPreference.setPersistent(false);
|
||||
mSummaryPreference.setLayoutResource(R.layout.text_description_preference);
|
||||
preferenceScreen.addPreference(mSummaryPreference);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(View view, Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
|
||||
SettingsActivity activity = (SettingsActivity) getActivity();
|
||||
mSwitchBar = activity.getSwitchBar();
|
||||
mToggleSwitch = mSwitchBar.getSwitch();
|
||||
|
||||
// Set up UI.
|
||||
mSummaryPreference.setSummary(R.string.fullbackup_data_summary);
|
||||
try {
|
||||
boolean backupEnabled = mBackupManager == null ?
|
||||
false : mBackupManager.isBackupEnabled();
|
||||
mSwitchBar.setCheckedInternal(backupEnabled);
|
||||
} catch (RemoteException e) {
|
||||
// The world is aflame, turn it off.
|
||||
mSwitchBar.setEnabled(false);
|
||||
}
|
||||
getActivity().setTitle(R.string.backup_data_title);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
|
||||
mToggleSwitch.setOnBeforeCheckedChangeListener(null);
|
||||
mSwitchBar.hide();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityCreated(Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
|
||||
// Set up toggle listener. We need this b/c we have to intercept the toggle event in order
|
||||
// to pop up the dialogue.
|
||||
mToggleSwitch.setOnBeforeCheckedChangeListener(
|
||||
new ToggleSwitch.OnBeforeCheckedChangeListener() {
|
||||
@Override
|
||||
public boolean onBeforeCheckedChanged(
|
||||
ToggleSwitch toggleSwitch, boolean checked) {
|
||||
if (!checked) {
|
||||
// Don't change Switch status until user makes choice in dialog
|
||||
// so return false here.
|
||||
showEraseBackupDialog();
|
||||
return false;
|
||||
} else {
|
||||
setBackupEnabled(true);
|
||||
mSwitchBar.setCheckedInternal(true);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
});
|
||||
mSwitchBar.show();
|
||||
}
|
||||
|
||||
/** Get rid of the dialog if it's still showing. */
|
||||
@Override
|
||||
public void onStop() {
|
||||
if (mConfirmDialog != null && mConfirmDialog.isShowing()) {
|
||||
mConfirmDialog.dismiss();
|
||||
}
|
||||
mConfirmDialog = null;
|
||||
super.onStop();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
// Accept turning off backup
|
||||
if (which == DialogInterface.BUTTON_POSITIVE) {
|
||||
setBackupEnabled(false);
|
||||
mSwitchBar.setCheckedInternal(false);
|
||||
} else if (which == DialogInterface.BUTTON_NEGATIVE) {
|
||||
// Reject turning off backup
|
||||
setBackupEnabled(true);
|
||||
mSwitchBar.setCheckedInternal(true);
|
||||
}
|
||||
}
|
||||
|
||||
private void showEraseBackupDialog() {
|
||||
CharSequence msg = getResources().getText(R.string.fullbackup_erase_dialog_message);
|
||||
// TODO: DialogFragment?
|
||||
mConfirmDialog = new AlertDialog.Builder(getActivity()).setMessage(msg)
|
||||
.setTitle(R.string.backup_erase_dialog_title)
|
||||
.setPositiveButton(android.R.string.ok, this)
|
||||
.setNegativeButton(android.R.string.cancel, this)
|
||||
.show();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getMetricsCategory() {
|
||||
return MetricsLogger.PRIVACY;
|
||||
}
|
||||
|
||||
/**
|
||||
* Informs the BackupManager of a change in backup state - if backup is disabled,
|
||||
* the data on the server will be erased.
|
||||
* @param enable whether to enable backup
|
||||
*/
|
||||
private void setBackupEnabled(boolean enable) {
|
||||
if (mBackupManager != null) {
|
||||
try {
|
||||
mBackupManager.setBackupEnabled(enable);
|
||||
} catch (RemoteException e) {
|
||||
Log.e(TAG, "Error communicating with BackupManager", e);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user