OSDN Git Service

Move global sync settings dialogs to the right screen
authorAlexandra Gherghina <alexgherghina@google.com>
Mon, 28 Jul 2014 20:40:35 +0000 (21:40 +0100)
committerAlexandra Gherghina <alexgherghina@google.com>
Tue, 29 Jul 2014 15:19:26 +0000 (16:19 +0100)
Bug: 16076571
Change-Id: I4ba01ece6e5054d699342ff2c1270fc2fc51c5a9

res/values/strings.xml
src/com/android/settings/DataUsageSummary.java
src/com/android/settings/accounts/AccountSettings.java

index 7a3953b..5a87472 100644 (file)
     <!--  Title of dialog shown when user enables global auto sync [CHAR LIMIT=32] -->
     <string name="data_usage_auto_sync_on_dialog_title">Turn auto-sync data on?</string>
     <!--  Body of dialog shown when user enables global auto sync, for tablet [CHAR LIMIT=none] -->
-    <string name="data_usage_auto_sync_on_dialog" product="tablet">Any changes you make to your accounts on the web will be automatically copied to your tablet.\n\nSome accounts may also automatically copy any changes you make on the tablet to the web. A Google Account works this way.\n\nTo choose which kinds of information to sync within each account, go to Settings &gt; Accounts.</string>
+    <string name="data_usage_auto_sync_on_dialog" product="tablet">Any changes you make to your accounts on the web will be automatically copied to your tablet.\n\nSome accounts may also automatically copy any changes you make on the tablet to the web. A Google Account works this way.</string>
     <!--  Body of dialog shown when user enables global auto sync [CHAR LIMIT=none] -->
-    <string name="data_usage_auto_sync_on_dialog" product="default">Any changes you make to your accounts on the web will be automatically copied to your phone.\n\nSome accounts may also automatically copy any changes you make on the phone to the web. A Google Account works this way.\n\nTo choose which kinds of information to sync within each account, go to Settings &gt; Accounts.</string>
+    <string name="data_usage_auto_sync_on_dialog" product="default">Any changes you make to your accounts on the web will be automatically copied to your phone.\n\nSome accounts may also automatically copy any changes you make on the phone to the web. A Google Account works this way.</string>
     <!--  Title of dialog shown when user disables global auto sync [CHAR LIMIT=32] -->
     <string name="data_usage_auto_sync_off_dialog_title">Turn auto-sync data off?</string>
     <!--  Body of dialog shown when user disables global auto sync [CHAR LIMIT=none] -->
index ac9344c..c8691e1 100644 (file)
@@ -56,7 +56,6 @@ import android.app.Fragment;
 import android.app.FragmentTransaction;
 import android.app.LoaderManager.LoaderCallbacks;
 import android.content.ComponentName;
-import android.content.ContentResolver;
 import android.content.Context;
 import android.content.DialogInterface;
 import android.content.Intent;
@@ -176,7 +175,6 @@ public class DataUsageSummary extends HighlightingFragment implements Indexable
     private static final String TAG_CONFIRM_RESTRICT = "confirmRestrict";
     private static final String TAG_DENIED_RESTRICT = "deniedRestrict";
     private static final String TAG_CONFIRM_APP_RESTRICT = "confirmAppRestrict";
-    private static final String TAG_CONFIRM_AUTO_SYNC_CHANGE = "confirmAutoSyncChange";
     private static final String TAG_APP_DETAILS = "appDetails";
 
     private static final String DATA_USAGE_ENABLE_MOBILE_KEY = "data_usage_enable_mobile";
@@ -487,7 +485,6 @@ public class DataUsageSummary extends HighlightingFragment implements Indexable
         final boolean isOwner = ActivityManager.getCurrentUser() == UserHandle.USER_OWNER;
 
         mMenuShowWifi = menu.findItem(R.id.data_usage_menu_show_wifi);
-        // TODO: Define behavior of this sync button. See: http://b/16076571
         if (hasWifiRadio(context) && hasReadyMobileRadio(context)) {
             mMenuShowWifi.setVisible(!appDetailMode);
         } else {
@@ -2166,56 +2163,6 @@ public class DataUsageSummary extends HighlightingFragment implements Indexable
     }
 
     /**
-     * Dialog to inform user about changing auto-sync setting
-     */
-    public static class ConfirmAutoSyncChangeFragment extends DialogFragment {
-        private static final String SAVE_ENABLING = "enabling";
-        private boolean mEnabling;
-
-        public static void show(DataUsageSummary parent, boolean enabling) {
-            if (!parent.isAdded()) return;
-
-            final ConfirmAutoSyncChangeFragment dialog = new ConfirmAutoSyncChangeFragment();
-            dialog.mEnabling = enabling;
-            dialog.setTargetFragment(parent, 0);
-            dialog.show(parent.getFragmentManager(), TAG_CONFIRM_AUTO_SYNC_CHANGE);
-        }
-
-        @Override
-        public Dialog onCreateDialog(Bundle savedInstanceState) {
-            final Context context = getActivity();
-            if (savedInstanceState != null) {
-                mEnabling = savedInstanceState.getBoolean(SAVE_ENABLING);
-            }
-
-            final AlertDialog.Builder builder = new AlertDialog.Builder(context);
-            if (!mEnabling) {
-                builder.setTitle(R.string.data_usage_auto_sync_off_dialog_title);
-                builder.setMessage(R.string.data_usage_auto_sync_off_dialog);
-            } else {
-                builder.setTitle(R.string.data_usage_auto_sync_on_dialog_title);
-                builder.setMessage(R.string.data_usage_auto_sync_on_dialog);
-            }
-
-            builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
-                @Override
-                public void onClick(DialogInterface dialog, int which) {
-                    ContentResolver.setMasterSyncAutomatically(mEnabling);
-                }
-            });
-            builder.setNegativeButton(android.R.string.cancel, null);
-
-            return builder.create();
-        }
-
-        @Override
-        public void onSaveInstanceState(Bundle outState) {
-            super.onSaveInstanceState(outState);
-            outState.putBoolean(SAVE_ENABLING, mEnabling);
-        }
-    }
-
-    /**
      * Compute default tab that should be selected, based on
      * {@link NetworkPolicyManager#EXTRA_NETWORK_TEMPLATE} extra.
      */
index 47eb063..ffd6037 100644 (file)
@@ -20,9 +20,13 @@ package com.android.settings.accounts;
 import android.accounts.Account;
 import android.accounts.AccountManager;
 import android.app.ActivityManager;
+import android.app.AlertDialog;
+import android.app.Dialog;
+import android.app.DialogFragment;
 import android.content.BroadcastReceiver;
 import android.content.ContentResolver;
 import android.content.Context;
+import android.content.DialogInterface;
 import android.content.Intent;
 import android.content.IntentFilter;
 import android.graphics.drawable.Drawable;
@@ -35,7 +39,6 @@ import android.view.Menu;
 import android.view.MenuInflater;
 import android.view.MenuItem;
 import android.preference.Preference;
-import android.preference.Preference.OnPreferenceChangeListener;
 import android.preference.Preference.OnPreferenceClickListener;
 import android.preference.PreferenceGroup;
 import android.preference.PreferenceScreen;
@@ -73,6 +76,9 @@ public class AccountSettings extends SettingsPreferenceFragment
 
     private static final ArrayList<String> EMPTY_LIST = new ArrayList<String>();
 
+    private static final String TAG_CONFIRM_AUTO_SYNC_CHANGE = "confirmAutoSyncChange";
+
+
     private UserManager mUm;
     private SparseArray<ProfileData> mProfiles;
     private ManagedProfileBroadcastReceiver mManagedProfileBroadcastReceiver
@@ -430,18 +436,68 @@ public class AccountSettings extends SettingsPreferenceFragment
 
         @Override
         public boolean onMenuItemClick(MenuItem item) {
-            // TODO: Add confirmation dialogs. See: http://b/16076571
             if (ActivityManager.isUserAMonkey()) {
                 Log.d(TAG, "ignoring monkey's attempt to flip sync state");
             } else {
-                boolean newSyncState = !item.isChecked();
-                item.setChecked(newSyncState);
-                ContentResolver.setMasterSyncAutomaticallyAsUser(newSyncState,
-                        mUserHandle.getIdentifier());
+                ConfirmAutoSyncChangeFragment.show(AccountSettings.this, !item.isChecked(),
+                        mUserHandle);
             }
             return true;
         }
     }
+
+    /**
+     * Dialog to inform user about changing auto-sync setting
+     */
+    public static class ConfirmAutoSyncChangeFragment extends DialogFragment {
+        private static final String SAVE_ENABLING = "enabling";
+        private boolean mEnabling;
+        private UserHandle mUserHandle;
+
+        public static void show(AccountSettings parent, boolean enabling, UserHandle userHandle) {
+            if (!parent.isAdded()) return;
+
+            final ConfirmAutoSyncChangeFragment dialog = new ConfirmAutoSyncChangeFragment();
+            dialog.mEnabling = enabling;
+            dialog.mUserHandle = userHandle;
+            dialog.setTargetFragment(parent, 0);
+            dialog.show(parent.getFragmentManager(), TAG_CONFIRM_AUTO_SYNC_CHANGE);
+        }
+
+        @Override
+        public Dialog onCreateDialog(Bundle savedInstanceState) {
+            final Context context = getActivity();
+            if (savedInstanceState != null) {
+                mEnabling = savedInstanceState.getBoolean(SAVE_ENABLING);
+            }
+
+            final AlertDialog.Builder builder = new AlertDialog.Builder(context);
+            if (!mEnabling) {
+                builder.setTitle(R.string.data_usage_auto_sync_off_dialog_title);
+                builder.setMessage(R.string.data_usage_auto_sync_off_dialog);
+            } else {
+                builder.setTitle(R.string.data_usage_auto_sync_on_dialog_title);
+                builder.setMessage(R.string.data_usage_auto_sync_on_dialog);
+            }
+
+            builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
+                @Override
+                public void onClick(DialogInterface dialog, int which) {
+                    ContentResolver.setMasterSyncAutomaticallyAsUser(mEnabling,
+                            mUserHandle.getIdentifier());
+                }
+            });
+            builder.setNegativeButton(android.R.string.cancel, null);
+
+            return builder.create();
+        }
+
+        @Override
+        public void onSaveInstanceState(Bundle outState) {
+            super.onSaveInstanceState(outState);
+            outState.putBoolean(SAVE_ENABLING, mEnabling);
+        }
+    }
     // TODO Implement a {@link SearchIndexProvider} to allow Indexing and Search of account types
     // See http://b/15403806
 }