Revert "Move global sync settings to AccountSettings."
This reverts commit 64fde6f4e9
.
Change-Id: I61940b6e2936c7c7f048af222602226e5588c268
This commit is contained in:
@@ -1485,19 +1485,6 @@
|
|||||||
android:resource="@id/battery_settings" />
|
android:resource="@id/battery_settings" />
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
<activity android:name="Settings$AccountSettingsActivity"
|
|
||||||
android:label="@string/account_settings_title"
|
|
||||||
android:taskAffinity=""
|
|
||||||
android:parentActivityName="Settings">
|
|
||||||
<intent-filter>
|
|
||||||
<action android:name="android.intent.action.MAIN" />
|
|
||||||
<action android:name="android.settings.SYNC_SETTINGS" />
|
|
||||||
<category android:name="android.intent.category.DEFAULT" />
|
|
||||||
</intent-filter>
|
|
||||||
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
|
|
||||||
android:value="com.android.settings.accounts.AccountSettings" />
|
|
||||||
</activity>
|
|
||||||
|
|
||||||
<activity android:name="Settings$AccountSyncSettingsActivity"
|
<activity android:name="Settings$AccountSyncSettingsActivity"
|
||||||
android:label="@string/account_sync_settings_title"
|
android:label="@string/account_sync_settings_title"
|
||||||
android:taskAffinity=""
|
android:taskAffinity=""
|
||||||
@@ -1513,6 +1500,19 @@
|
|||||||
android:resource="@id/account_settings" />
|
android:resource="@id/account_settings" />
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
|
<activity android:name=".accounts.SyncSettingsActivity"
|
||||||
|
android:label="@string/account_sync_settings_title">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
<action android:name="android.settings.SYNC_SETTINGS" />
|
||||||
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
|
</intent-filter>
|
||||||
|
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
|
||||||
|
android:value="com.android.settings.accounts.AccountSyncSettings" />
|
||||||
|
<meta-data android:name="com.android.settings.TOP_LEVEL_HEADER_ID"
|
||||||
|
android:resource="@id/account_settings" />
|
||||||
|
</activity>
|
||||||
|
|
||||||
<activity android:name="com.android.settings.accounts.AddAccountSettings"
|
<activity android:name="com.android.settings.accounts.AddAccountSettings"
|
||||||
android:theme="@android:style/Theme.Translucent.NoTitleBar"
|
android:theme="@android:style/Theme.Translucent.NoTitleBar"
|
||||||
android:configChanges="orientation|keyboardHidden|screenSize"
|
android:configChanges="orientation|keyboardHidden|screenSize"
|
||||||
|
@@ -1,30 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<!-- Copyright (C) 2014 The Android Open Source Project
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
-->
|
|
||||||
|
|
||||||
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
|
||||||
<item
|
|
||||||
android:id="@+id/account_settings_menu_auto_sync"
|
|
||||||
android:title="@string/account_settings_menu_auto_sync"
|
|
||||||
android:checkable="true" />
|
|
||||||
<item
|
|
||||||
android:id="@+id/account_settings_menu_auto_sync_personal"
|
|
||||||
android:title="@string/account_settings_menu_auto_sync_personal"
|
|
||||||
android:checkable="true" />
|
|
||||||
<item
|
|
||||||
android:id="@+id/account_settings_menu_auto_sync_work"
|
|
||||||
android:title="@string/account_settings_menu_auto_sync_work"
|
|
||||||
android:checkable="true" />
|
|
||||||
</menu>
|
|
@@ -4798,12 +4798,6 @@
|
|||||||
<string name="data_usage_menu_metered">Mobile hotspots</string>
|
<string name="data_usage_menu_metered">Mobile hotspots</string>
|
||||||
<!-- Title for menu option to enable global auto-sync of account data -->
|
<!-- Title for menu option to enable global auto-sync of account data -->
|
||||||
<string name="data_usage_menu_auto_sync">Auto-sync data</string>
|
<string name="data_usage_menu_auto_sync">Auto-sync data</string>
|
||||||
<!-- Title for menu option to enable global auto-sync of personal account data [CHAR LIMIT=30] -->
|
|
||||||
<string name="account_settings_menu_auto_sync">Auto-sync data</string>
|
|
||||||
<!-- Title for menu option to enable global auto-sync of personal account data [CHAR LIMIT=30] -->
|
|
||||||
<string name="account_settings_menu_auto_sync_personal">Auto-sync personal data</string>
|
|
||||||
<!-- Title for menu option to enable global auto-sync of work account data [CHAR LIMIT=30] -->
|
|
||||||
<string name="account_settings_menu_auto_sync_work">Auto-sync work data</string>
|
|
||||||
|
|
||||||
<!-- Title for option to change data usage cycle day. [CHAR LIMIT=32] -->
|
<!-- Title for option to change data usage cycle day. [CHAR LIMIT=32] -->
|
||||||
<string name="data_usage_change_cycle">Change cycle\u2026</string>
|
<string name="data_usage_change_cycle">Change cycle\u2026</string>
|
||||||
|
@@ -489,7 +489,6 @@ public class DataUsageSummary extends HighlightingFragment implements Indexable
|
|||||||
hasReadyMobileRadio(context) && isOwner && !appDetailMode);
|
hasReadyMobileRadio(context) && isOwner && !appDetailMode);
|
||||||
mMenuRestrictBackground.setChecked(mPolicyManager.getRestrictBackground());
|
mMenuRestrictBackground.setChecked(mPolicyManager.getRestrictBackground());
|
||||||
|
|
||||||
// TODO: Define behavior of this sync button. See: http://b/16076571
|
|
||||||
mMenuAutoSync = menu.findItem(R.id.data_usage_menu_auto_sync);
|
mMenuAutoSync = menu.findItem(R.id.data_usage_menu_auto_sync);
|
||||||
mMenuAutoSync.setChecked(ContentResolver.getMasterSyncAutomatically());
|
mMenuAutoSync.setChecked(ContentResolver.getMasterSyncAutomatically());
|
||||||
mMenuAutoSync.setVisible(!appDetailMode);
|
mMenuAutoSync.setVisible(!appDetailMode);
|
||||||
|
@@ -69,7 +69,6 @@ public class Settings extends SettingsActivity {
|
|||||||
public static class PowerUsageSummaryActivity extends SettingsActivity { /* empty */ }
|
public static class PowerUsageSummaryActivity extends SettingsActivity { /* empty */ }
|
||||||
public static class BatterySaverSettingsActivity extends SettingsActivity { /* empty */ }
|
public static class BatterySaverSettingsActivity extends SettingsActivity { /* empty */ }
|
||||||
public static class AccountSyncSettingsActivity extends SettingsActivity { /* empty */ }
|
public static class AccountSyncSettingsActivity extends SettingsActivity { /* empty */ }
|
||||||
public static class AccountSettingsActivity extends SettingsActivity { /* empty */ }
|
|
||||||
public static class AccountSyncSettingsInAddAccountActivity extends SettingsActivity { /* empty */ }
|
public static class AccountSyncSettingsInAddAccountActivity extends SettingsActivity { /* empty */ }
|
||||||
public static class CryptKeeperSettingsActivity extends SettingsActivity { /* empty */ }
|
public static class CryptKeeperSettingsActivity extends SettingsActivity { /* empty */ }
|
||||||
public static class DeviceAdminSettingsActivity extends SettingsActivity { /* empty */ }
|
public static class DeviceAdminSettingsActivity extends SettingsActivity { /* empty */ }
|
||||||
|
@@ -66,7 +66,6 @@ import com.android.internal.util.ArrayUtils;
|
|||||||
import com.android.internal.util.XmlUtils;
|
import com.android.internal.util.XmlUtils;
|
||||||
import com.android.settings.accessibility.AccessibilitySettings;
|
import com.android.settings.accessibility.AccessibilitySettings;
|
||||||
import com.android.settings.accessibility.CaptionPropertiesFragment;
|
import com.android.settings.accessibility.CaptionPropertiesFragment;
|
||||||
import com.android.settings.accounts.AccountSettings;
|
|
||||||
import com.android.settings.accounts.AccountSyncSettings;
|
import com.android.settings.accounts.AccountSyncSettings;
|
||||||
import com.android.settings.applications.InstalledAppDetails;
|
import com.android.settings.applications.InstalledAppDetails;
|
||||||
import com.android.settings.applications.ManageApplications;
|
import com.android.settings.applications.ManageApplications;
|
||||||
@@ -263,7 +262,6 @@ public class SettingsActivity extends Activity
|
|||||||
WifiDisplaySettings.class.getName(),
|
WifiDisplaySettings.class.getName(),
|
||||||
PowerUsageSummary.class.getName(),
|
PowerUsageSummary.class.getName(),
|
||||||
AccountSyncSettings.class.getName(),
|
AccountSyncSettings.class.getName(),
|
||||||
AccountSettings.class.getName(),
|
|
||||||
CryptKeeperSettings.class.getName(),
|
CryptKeeperSettings.class.getName(),
|
||||||
DataUsageSummary.class.getName(),
|
DataUsageSummary.class.getName(),
|
||||||
DreamSettings.class.getName(),
|
DreamSettings.class.getName(),
|
||||||
|
@@ -19,9 +19,7 @@ package com.android.settings.accounts;
|
|||||||
|
|
||||||
import android.accounts.Account;
|
import android.accounts.Account;
|
||||||
import android.accounts.AccountManager;
|
import android.accounts.AccountManager;
|
||||||
import android.app.ActivityManager;
|
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.ContentResolver;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
@@ -31,11 +29,7 @@ import android.os.UserHandle;
|
|||||||
import android.os.UserManager;
|
import android.os.UserManager;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.util.SparseArray;
|
import android.util.SparseArray;
|
||||||
import android.view.Menu;
|
|
||||||
import android.view.MenuInflater;
|
|
||||||
import android.view.MenuItem;
|
|
||||||
import android.preference.Preference;
|
import android.preference.Preference;
|
||||||
import android.preference.Preference.OnPreferenceChangeListener;
|
|
||||||
import android.preference.Preference.OnPreferenceClickListener;
|
import android.preference.Preference.OnPreferenceClickListener;
|
||||||
import android.preference.PreferenceGroup;
|
import android.preference.PreferenceGroup;
|
||||||
|
|
||||||
@@ -60,6 +54,7 @@ public class AccountSettings extends SettingsPreferenceFragment
|
|||||||
implements AuthenticatorHelper.OnAccountsUpdateListener,
|
implements AuthenticatorHelper.OnAccountsUpdateListener,
|
||||||
OnPreferenceClickListener {
|
OnPreferenceClickListener {
|
||||||
public static final String TAG = "AccountSettings";
|
public static final String TAG = "AccountSettings";
|
||||||
|
|
||||||
private static final String KEY_ACCOUNT = "account";
|
private static final String KEY_ACCOUNT = "account";
|
||||||
private static final String KEY_ADD_ACCOUNT = "add_account";
|
private static final String KEY_ADD_ACCOUNT = "add_account";
|
||||||
|
|
||||||
@@ -73,7 +68,6 @@ public class AccountSettings extends SettingsPreferenceFragment
|
|||||||
private UserManager mUm;
|
private UserManager mUm;
|
||||||
private SparseArray<ProfileData> mProfiles;
|
private SparseArray<ProfileData> mProfiles;
|
||||||
private ManagedProfileBroadcastReceiver mManagedProfileBroadcastReceiver;
|
private ManagedProfileBroadcastReceiver mManagedProfileBroadcastReceiver;
|
||||||
private boolean mIsSingleProfileUi = true;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds data related to the accounts belonging to one profile.
|
* Holds data related to the accounts belonging to one profile.
|
||||||
@@ -103,50 +97,6 @@ public class AccountSettings extends SettingsPreferenceFragment
|
|||||||
mUm = (UserManager) getSystemService(Context.USER_SERVICE);
|
mUm = (UserManager) getSystemService(Context.USER_SERVICE);
|
||||||
mProfiles = new SparseArray<ProfileData>(2);
|
mProfiles = new SparseArray<ProfileData>(2);
|
||||||
updateUi();
|
updateUi();
|
||||||
setHasOptionsMenu(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
|
||||||
inflater.inflate(R.menu.account_settings, menu);
|
|
||||||
final UserHandle currentProfile = UserHandle.getCallingUserHandle();
|
|
||||||
if (mIsSingleProfileUi) {
|
|
||||||
menu.findItem(R.id.account_settings_menu_auto_sync)
|
|
||||||
.setVisible(true)
|
|
||||||
.setOnMenuItemClickListener(new MasterSyncStateClickListener(currentProfile));
|
|
||||||
menu.removeItem(R.id.account_settings_menu_auto_sync_personal);
|
|
||||||
menu.removeItem(R.id.account_settings_menu_auto_sync_work);
|
|
||||||
} else {
|
|
||||||
final UserHandle managedProfile = Utils.getManagedProfile(mUm);
|
|
||||||
|
|
||||||
menu.findItem(R.id.account_settings_menu_auto_sync_personal)
|
|
||||||
.setVisible(true)
|
|
||||||
.setOnMenuItemClickListener(new MasterSyncStateClickListener(currentProfile));
|
|
||||||
menu.findItem(R.id.account_settings_menu_auto_sync_work)
|
|
||||||
.setVisible(true)
|
|
||||||
.setOnMenuItemClickListener(new MasterSyncStateClickListener(managedProfile));
|
|
||||||
menu.removeItem(R.id.account_settings_menu_auto_sync);
|
|
||||||
}
|
|
||||||
super.onCreateOptionsMenu(menu, inflater);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPrepareOptionsMenu(Menu menu) {
|
|
||||||
final UserHandle currentProfile = UserHandle.getCallingUserHandle();
|
|
||||||
if (mIsSingleProfileUi) {
|
|
||||||
menu.findItem(R.id.account_settings_menu_auto_sync)
|
|
||||||
.setChecked(ContentResolver.getMasterSyncAutomaticallyAsUser(
|
|
||||||
currentProfile.getIdentifier()));
|
|
||||||
} else {
|
|
||||||
final UserHandle managedProfile = Utils.getManagedProfile(mUm);
|
|
||||||
|
|
||||||
menu.findItem(R.id.account_settings_menu_auto_sync_personal)
|
|
||||||
.setChecked(ContentResolver.getMasterSyncAutomaticallyAsUser(
|
|
||||||
currentProfile.getIdentifier()));
|
|
||||||
menu.findItem(R.id.account_settings_menu_auto_sync_work)
|
|
||||||
.setChecked(ContentResolver.getMasterSyncAutomaticallyAsUser(
|
|
||||||
managedProfile.getIdentifier()));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void updateUi() {
|
void updateUi() {
|
||||||
@@ -167,13 +117,12 @@ public class AccountSettings extends SettingsPreferenceFragment
|
|||||||
if (managedProfile == null) {
|
if (managedProfile == null) {
|
||||||
updateSingleProfileUi();
|
updateSingleProfileUi();
|
||||||
} else {
|
} else {
|
||||||
mIsSingleProfileUi = false;
|
updateProfileUi(currentProfile,
|
||||||
updateProfileUi(currentProfile, KEY_CATEGORY_PERSONAL, KEY_ADD_ACCOUNT_PERSONAL,
|
KEY_CATEGORY_PERSONAL, KEY_ADD_ACCOUNT_PERSONAL, new ArrayList<String>());
|
||||||
new ArrayList<String>());
|
final ArrayList<String> unusedPreferences = new ArrayList<String>(1);
|
||||||
final ArrayList<String> unusedPreferences = new ArrayList<String>(2);
|
|
||||||
unusedPreferences.add(KEY_ADD_ACCOUNT);
|
unusedPreferences.add(KEY_ADD_ACCOUNT);
|
||||||
updateProfileUi(managedProfile, KEY_CATEGORY_WORK, KEY_ADD_ACCOUNT_WORK,
|
updateProfileUi(managedProfile,
|
||||||
unusedPreferences);
|
KEY_CATEGORY_WORK, KEY_ADD_ACCOUNT_WORK, unusedPreferences);
|
||||||
mManagedProfileBroadcastReceiver = new ManagedProfileBroadcastReceiver();
|
mManagedProfileBroadcastReceiver = new ManagedProfileBroadcastReceiver();
|
||||||
mManagedProfileBroadcastReceiver.register(getActivity());
|
mManagedProfileBroadcastReceiver.register(getActivity());
|
||||||
}
|
}
|
||||||
@@ -192,8 +141,8 @@ public class AccountSettings extends SettingsPreferenceFragment
|
|||||||
unusedPreferences);
|
unusedPreferences);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateProfileUi(final UserHandle userHandle, String categoryKey,
|
private void updateProfileUi(UserHandle userHandle, String categoryKey, String addAccountKey,
|
||||||
String addAccountKey, ArrayList<String> unusedPreferences) {
|
ArrayList<String> unusedPreferences) {
|
||||||
final int count = unusedPreferences.size();
|
final int count = unusedPreferences.size();
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
removePreference(unusedPreferences.get(i));
|
removePreference(unusedPreferences.get(i));
|
||||||
@@ -396,28 +345,6 @@ public class AccountSettings extends SettingsPreferenceFragment
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class MasterSyncStateClickListener implements MenuItem.OnMenuItemClickListener {
|
|
||||||
private final UserHandle mUserHandle;
|
|
||||||
|
|
||||||
public MasterSyncStateClickListener(UserHandle userHandle) {
|
|
||||||
mUserHandle = userHandle;
|
|
||||||
}
|
|
||||||
|
|
||||||
@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());
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// TODO Implement a {@link SearchIndexProvider} to allow Indexing and Search of account types
|
// TODO Implement a {@link SearchIndexProvider} to allow Indexing and Search of account types
|
||||||
// See http://b/15403806
|
// See http://b/15403806
|
||||||
}
|
}
|
||||||
|
179
src/com/android/settings/accounts/SyncSettings.java
Normal file
179
src/com/android/settings/accounts/SyncSettings.java
Normal file
@@ -0,0 +1,179 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2008 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.settings.accounts;
|
||||||
|
|
||||||
|
import android.accounts.Account;
|
||||||
|
import android.accounts.AccountManager;
|
||||||
|
import android.accounts.OnAccountsUpdateListener;
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.app.ActivityManager;
|
||||||
|
import android.content.ContentResolver;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.graphics.drawable.Drawable;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.preference.CheckBoxPreference;
|
||||||
|
import android.preference.Preference;
|
||||||
|
import android.preference.Preference.OnPreferenceChangeListener;
|
||||||
|
import android.preference.PreferenceScreen;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import com.android.settings.AccountPreference;
|
||||||
|
import com.android.settings.DialogCreatable;
|
||||||
|
import com.android.settings.R;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
public class SyncSettings extends AccountPreferenceBase
|
||||||
|
implements OnAccountsUpdateListener, DialogCreatable {
|
||||||
|
|
||||||
|
private static final String KEY_SYNC_SWITCH = "sync_switch";
|
||||||
|
|
||||||
|
private String[] mAuthorities;
|
||||||
|
|
||||||
|
private SettingsDialogFragment mDialogFragment;
|
||||||
|
private CheckBoxPreference mAutoSyncPreference;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(Bundle icicle) {
|
||||||
|
super.onCreate(icicle);
|
||||||
|
|
||||||
|
addPreferencesFromResource(R.xml.sync_settings);
|
||||||
|
mAutoSyncPreference =
|
||||||
|
(CheckBoxPreference) getPreferenceScreen().findPreference(KEY_SYNC_SWITCH);
|
||||||
|
mAutoSyncPreference.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||||
|
if (ActivityManager.isUserAMonkey()) {
|
||||||
|
Log.d("SyncSettings", "ignoring monkey's attempt to flip sync state");
|
||||||
|
} else {
|
||||||
|
ContentResolver.setMasterSyncAutomatically((Boolean) newValue);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
setHasOptionsMenu(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onStart() {
|
||||||
|
super.onStart();
|
||||||
|
Activity activity = getActivity();
|
||||||
|
AccountManager.get(activity).addOnAccountsUpdatedListener(this, null, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onActivityCreated(Bundle savedInstanceState) {
|
||||||
|
super.onActivityCreated(savedInstanceState);
|
||||||
|
|
||||||
|
final Activity activity = getActivity();
|
||||||
|
mAutoSyncPreference.setChecked(ContentResolver.getMasterSyncAutomatically());
|
||||||
|
mAuthorities = activity.getIntent().getStringArrayExtra(AUTHORITIES_FILTER_KEY);
|
||||||
|
|
||||||
|
updateAuthDescriptions();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onStop() {
|
||||||
|
super.onStop();
|
||||||
|
final Activity activity = getActivity();
|
||||||
|
AccountManager.get(activity).removeOnAccountsUpdatedListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onPreferenceTreeClick(PreferenceScreen preferences, Preference preference) {
|
||||||
|
if (preference instanceof AccountPreference) {
|
||||||
|
startAccountSettings((AccountPreference) preference);
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void startAccountSettings(AccountPreference acctPref) {
|
||||||
|
Intent intent = new Intent("android.settings.ACCOUNT_SYNC_SETTINGS");
|
||||||
|
intent.putExtra(AccountSyncSettings.ACCOUNT_KEY, acctPref.getAccount());
|
||||||
|
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
|
startActivity(intent);
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void showDialog(int dialogId) {
|
||||||
|
if (mDialogFragment != null) {
|
||||||
|
Log.e(TAG, "Old dialog fragment not null!");
|
||||||
|
}
|
||||||
|
mDialogFragment = new SettingsDialogFragment(this, dialogId);
|
||||||
|
mDialogFragment.show(getActivity().getFragmentManager(), Integer.toString(dialogId));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void removeAccountPreferences() {
|
||||||
|
PreferenceScreen parent = getPreferenceScreen();
|
||||||
|
for (int i = 0; i < parent.getPreferenceCount(); ) {
|
||||||
|
if (parent.getPreference(i) instanceof AccountPreference) {
|
||||||
|
parent.removePreference(parent.getPreference(i));
|
||||||
|
} else {
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAccountsUpdated(Account[] accounts) {
|
||||||
|
if (getActivity() == null) return;
|
||||||
|
|
||||||
|
removeAccountPreferences();
|
||||||
|
for (int i = 0, n = accounts.length; i < n; i++) {
|
||||||
|
final Account account = accounts[i];
|
||||||
|
final ArrayList<String> auths = getAuthoritiesForAccountType(account.type);
|
||||||
|
|
||||||
|
boolean showAccount = true;
|
||||||
|
if (mAuthorities != null && auths != null) {
|
||||||
|
showAccount = false;
|
||||||
|
for (String requestedAuthority : mAuthorities) {
|
||||||
|
if (auths.contains(requestedAuthority)) {
|
||||||
|
showAccount = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (showAccount) {
|
||||||
|
final Drawable icon = getDrawableForType(account.type);
|
||||||
|
final AccountPreference preference =
|
||||||
|
new AccountPreference(getActivity(), account, icon, auths, true);
|
||||||
|
getPreferenceScreen().addPreference(preference);
|
||||||
|
preference.setSummary(getLabelForType(account.type));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
onSyncStateUpdated();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onAuthDescriptionsUpdated() {
|
||||||
|
// Update account icons for all account preference items
|
||||||
|
for (int i = 0; i < getPreferenceScreen().getPreferenceCount(); i++) {
|
||||||
|
Preference pref = getPreferenceScreen().getPreference(i);
|
||||||
|
if (pref instanceof AccountPreference) {
|
||||||
|
AccountPreference accPref = (AccountPreference)
|
||||||
|
getPreferenceScreen().getPreference(i);
|
||||||
|
accPref.setIcon(getDrawableForType(accPref.getAccount().type));
|
||||||
|
accPref.setSummary(getLabelForType(accPref.getAccount().type));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
40
src/com/android/settings/accounts/SyncSettingsActivity.java
Normal file
40
src/com/android/settings/accounts/SyncSettingsActivity.java
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2012 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.settings.accounts;
|
||||||
|
|
||||||
|
import android.content.Intent;
|
||||||
|
|
||||||
|
import com.android.settings.SettingsActivity;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Launcher activity for the SyncSettings fragment.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class SyncSettingsActivity extends SettingsActivity {
|
||||||
|
@Override
|
||||||
|
public Intent getIntent() {
|
||||||
|
Intent modIntent = new Intent(super.getIntent());
|
||||||
|
modIntent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT, SyncSettings.class.getName());
|
||||||
|
return modIntent;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean isValidFragment(String fragmentName) {
|
||||||
|
if (SyncSettings.class.getName().equals(fragmentName)) return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user