am 25daca00: Merge "Provide a preference to delete data from cloud."

* commit '25daca00531e79c7bae9d5508644aaa2e677f0f5':
  Provide a preference to delete data from cloud.
main
Jatin Matani 2014-12-12 19:49:03 +00:00 committed by Android Git Automerger
commit 28a1d4d5da
4 changed files with 57 additions and 2 deletions

View File

@ -63,4 +63,13 @@ public class AccountStateChangedListener {
*/
public static void forceSync(@Nullable String account) {
}
/**
* Forces an immediate deletion of user's data.
* This should only be used for debugging purposes.
*
* @param account the account to use for sync.
*/
public static void forceDelete(@Nullable String account) {
}
}

View File

@ -61,6 +61,11 @@
<string name="cloud_sync_summary" translatable="false">Sync your personal dictionary across devices</string>
<string name="cloud_sync_summary_disabled_signed_out" translatable="false">Select an account to enable sync</string>
<string name="sync_now_title" translatable="false">[DEBUG] Sync Now</string>
<string name="clear_sync_data_title" translatable="false">[DEBUG] Delete Google Keyboard cloud data</string>
<string name="clear_sync_data_summary" translable="false">Deletes your synced data from Google</string>
<string name="clear_sync_data_confirmation" translable="false">Your synced data will be deleted. Are you sure?</string>
<string name="clear_sync_data_ok" translable="false">Delete</string>
<string name="clear_sync_data_cancel" translable="false">Cancel</string>
<!-- Option name for including other IMEs in the language switch list [CHAR LIMIT=30] -->
<string name="include_other_imes_in_language_switch_list">Switch to other input methods</string>

View File

@ -48,4 +48,11 @@
android:persistent="false"
android:title="@string/sync_now_title"
android:dependency="pref_enable_cloud_sync" />
<!-- This preference (acts like a button) enables the user to clear data from the cloud. -->
<Preference android:key="pref_beanstalk_clear_data"
android:persistent="false"
android:title="@string/clear_sync_data_title"
android:summary="@string/clear_sync_data_summary"
android:dependency="pref_enable_cloud_sync" />
</PreferenceScreen>

View File

@ -50,12 +50,15 @@ import javax.annotation.Nullable;
*/
public final class AccountsSettingsFragment extends SubScreenFragment {
private static final String PREF_SYNC_NOW = "pref_beanstalk";
private static final String PREF_CLEAR_SYNC_DATA = "pref_beanstalk_clear_data";
static final String PREF_ACCCOUNT_SWITCHER = "account_switcher";
private final DialogInterface.OnClickListener mAccountChangedListener =
new AccountChangedListener();
private final Preference.OnPreferenceClickListener mSyncNowListener = new SyncNowListener();
private final Preference.OnPreferenceClickListener mClearSyncDataListener =
new ClearSyncDataListener();
@Override
public void onCreate(final Bundle icicle) {
@ -86,13 +89,18 @@ public final class AccountsSettingsFragment extends SubScreenFragment {
removePreference(PREF_ACCCOUNT_SWITCHER);
removePreference(PREF_ENABLE_CLOUD_SYNC);
removePreference(PREF_SYNC_NOW);
removePreference(PREF_CLEAR_SYNC_DATA);
}
if (!ProductionFlags.ENABLE_PERSONAL_DICTIONARY_SYNC) {
removePreference(PREF_ENABLE_CLOUD_SYNC);
removePreference(PREF_SYNC_NOW);
removePreference(PREF_CLEAR_SYNC_DATA);
} else {
final Preference syncNowPreference = findPreference(PREF_SYNC_NOW);
syncNowPreference.setOnPreferenceClickListener(mSyncNowListener);
final Preference clearSyncDataPreference = findPreference(PREF_CLEAR_SYNC_DATA);
clearSyncDataPreference.setOnPreferenceClickListener(mClearSyncDataListener);
}
}
@ -136,7 +144,7 @@ public final class AccountsSettingsFragment extends SubScreenFragment {
final String[] accountsForLogin = LoginAccountUtils.getAccountsForLogin(context);
accountSwitcher.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
public boolean onPreferenceClick(final Preference preference) {
if (accountsForLogin.length == 0) {
// TODO: Handle account addition.
Toast.makeText(getActivity(), getString(R.string.account_select_cancel),
@ -229,7 +237,7 @@ public final class AccountsSettingsFragment extends SubScreenFragment {
*/
class AccountChangedListener implements DialogInterface.OnClickListener {
@Override
public void onClick(DialogInterface dialog, int which) {
public void onClick(final DialogInterface dialog, final int which) {
final String oldAccount = getSignedInAccountName();
switch (which) {
case DialogInterface.BUTTON_POSITIVE: // Signed in
@ -263,4 +271,30 @@ public final class AccountsSettingsFragment extends SubScreenFragment {
return true;
}
}
/**
* Listener that initiates the process of deleting user's data from the cloud.
*/
class ClearSyncDataListener implements Preference.OnPreferenceClickListener {
@Override
public boolean onPreferenceClick(final Preference preference) {
final AlertDialog confirmationDialog = new AlertDialog.Builder(getActivity())
.setTitle(R.string.clear_sync_data_title)
.setMessage(R.string.clear_sync_data_confirmation)
.setPositiveButton(R.string.clear_sync_data_ok,
new DialogInterface.OnClickListener() {
@Override
public void onClick(final DialogInterface dialog, final int which) {
if (which == DialogInterface.BUTTON_POSITIVE) {
AccountStateChangedListener.forceDelete(
getSignedInAccountName());
}
}
})
.setNegativeButton(R.string.clear_sync_data_cancel, null /* OnClickListener */)
.create();
confirmationDialog.show();
return true;
}
}
}