Account types at toplevel of Settings
Reorganized Account settings to show account types at the top-level
of Settings. Only account types that have accounts added are visible
here. There is an Add account button to add a new account.
Master sync toggle has moved to Data Usage screen in the overflow menu.
It shows additional detail of the function of the auto-sync toggle when
it is toggled by the user.
Account type screen (ManageAccountsSettings) shows list of accounts of
that type and any available authenticator settings. It additionally
verifies any Intents can be resolved before showing the corresponding
entry. This screen now shows last synced time for each account.
You can now sync all accounts of a type by selecting Sync now in the
Account type screen.
Account Sync screen that shows the list of syncable items has minor
tweaks:
- "Last synced...", "Sync is OFF"
- Doesn't show the authenticator settings here anymore.
Bug: 6579937
Change-Id: I8139a4c992b525a3e1efc24d2d223c3f5caddc76
diff --git a/src/com/android/settings/Settings.java b/src/com/android/settings/Settings.java
index b36364d..a8599bf 100644
--- a/src/com/android/settings/Settings.java
+++ b/src/com/android/settings/Settings.java
@@ -18,6 +18,8 @@
import com.android.internal.util.ArrayUtils;
import com.android.settings.accounts.AccountSyncSettings;
+import com.android.settings.accounts.AuthenticatorHelper;
+import com.android.settings.accounts.ManageAccountsSettings;
import com.android.settings.applications.ManageApplications;
import com.android.settings.bluetooth.BluetoothEnabler;
import com.android.settings.deviceinfo.Memory;
@@ -30,6 +32,7 @@
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
+import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.INetworkManagementService;
import android.os.RemoteException;
@@ -37,6 +40,7 @@
import android.os.UserId;
import android.preference.Preference;
import android.preference.PreferenceActivity;
+import android.preference.PreferenceActivity.Header;
import android.preference.PreferenceFragment;
import android.text.TextUtils;
import android.util.Log;
@@ -52,6 +56,8 @@
import android.widget.TextView;
import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
@@ -89,7 +95,7 @@
R.id.sound_settings,
R.id.display_settings,
R.id.security_settings,
- R.id.sync_settings,
+ R.id.account_settings,
R.id.about_settings
};
@@ -100,6 +106,9 @@
protected HashMap<Integer, Integer> mHeaderIndexMap = new HashMap<Integer, Integer>();
private List<Header> mHeaders;
+ private AuthenticatorHelper mAuthenticatorHelper;
+ private Header mLastHeader;
+
@Override
protected void onCreate(Bundle savedInstanceState) {
if (getIntent().getBooleanExtra(EXTRA_CLEAR_UI_OPTIONS, false)) {
@@ -111,13 +120,17 @@
mEnableUserManagement = true;
}
+ mAuthenticatorHelper = new AuthenticatorHelper();
+ mAuthenticatorHelper.updateAuthDescriptions(this);
+ mAuthenticatorHelper.onAccountsUpdated(this, null);
+
getMetaData();
mInLocalHeaderSwitch = true;
super.onCreate(savedInstanceState);
mInLocalHeaderSwitch = false;
if (!onIsHidingHeaders() && onIsMultiPane()) {
- highlightHeader();
+ highlightHeader(mTopLevelHeaderId);
// Force the title so that it doesn't get overridden by a direct launch of
// a specific settings screen.
setTitle(R.string.settings_label);
@@ -217,7 +230,7 @@
mCurrentHeader = parentHeader;
switchToHeaderLocal(parentHeader);
- highlightHeader();
+ highlightHeader(mTopLevelHeaderId);
mParentHeader = new Header();
mParentHeader.fragment
@@ -240,9 +253,9 @@
}
}
- private void highlightHeader() {
- if (mTopLevelHeaderId != 0) {
- Integer index = mHeaderIndexMap.get(mTopLevelHeaderId);
+ private void highlightHeader(int id) {
+ if (id != 0) {
+ Integer index = mHeaderIndexMap.get(id);
if (index != null) {
getListView().setItemChecked(index, true);
getListView().smoothScrollToPosition(index);
@@ -326,7 +339,8 @@
ManageApplications.class.getName().equals(fragmentName) ||
WirelessSettings.class.getName().equals(fragmentName) ||
SoundSettings.class.getName().equals(fragmentName) ||
- PrivacySettings.class.getName().equals(fragmentName)) {
+ PrivacySettings.class.getName().equals(fragmentName) ||
+ ManageAccountsSettings.class.getName().equals(fragmentName)) {
intent.putExtra(EXTRA_CLEAR_UI_OPTIONS, true);
}
@@ -378,6 +392,9 @@
} catch (RemoteException e) {
// ignored
}
+ } else if (id == R.id.account_settings) {
+ int headerIndex = i + 1;
+ i = insertAccountsHeaders(target, headerIndex);
} else if (id == R.id.user_settings) {
if (!mEnableUserManagement
|| !UserId.MU_ENABLED || UserId.myUserId() != 0
@@ -404,6 +421,44 @@
}
}
+ private int insertAccountsHeaders(List<Header> target, int headerIndex) {
+ String[] accountTypes = mAuthenticatorHelper.getEnabledAccountTypes();
+ List<Header> accountHeaders = new ArrayList<Header>(accountTypes.length);
+ for (String accountType : accountTypes) {
+ CharSequence label = mAuthenticatorHelper.getLabelForType(this, accountType);
+ Header accHeader = new Header();
+ accHeader.title = label;
+ if (accHeader.extras == null) {
+ accHeader.extras = new Bundle();
+ }
+ accHeader.extras.putString(ManageAccountsSettings.KEY_ACCOUNT_TYPE, accountType);
+ accHeader.breadCrumbTitle = label;
+ accHeader.breadCrumbShortTitle = label;
+ accHeader.fragment = ManageAccountsSettings.class.getName();
+ accHeader.fragmentArguments = new Bundle();
+ accHeader.fragmentArguments.putString(ManageAccountsSettings.KEY_ACCOUNT_TYPE,
+ accountType);
+ if (!isMultiPane()) {
+ accHeader.fragmentArguments.putString(ManageAccountsSettings.KEY_ACCOUNT_LABEL,
+ label.toString());
+ }
+ accountHeaders.add(accHeader);
+ }
+
+ // Sort by label
+ Collections.sort(accountHeaders, new Comparator<Header>() {
+ @Override
+ public int compare(Header h1, Header h2) {
+ return h1.title.toString().compareTo(h2.title.toString());
+ }
+ });
+
+ for (Header header : accountHeaders) {
+ target.add(headerIndex++, header);
+ }
+ return headerIndex;
+ }
+
private boolean needsDockSettings() {
return getResources().getBoolean(R.bool.has_dock_settings);
}
@@ -415,7 +470,7 @@
if (ai == null || ai.metaData == null) return;
mTopLevelHeaderId = ai.metaData.getInt(META_DATA_KEY_HEADER_ID);
mFragmentClass = ai.metaData.getString(META_DATA_KEY_FRAGMENT_CLASS);
-
+
// Check if it has a parent specified and create a Header object
final int parentHeaderTitleRes = ai.metaData.getInt(META_DATA_KEY_PARENT_TITLE);
String parentFragmentClass = ai.metaData.getString(META_DATA_KEY_PARENT_FRAGMENT_CLASS);
@@ -449,6 +504,7 @@
private final WifiEnabler mWifiEnabler;
private final BluetoothEnabler mBluetoothEnabler;
+ private AuthenticatorHelper mAuthHelper;
private static class HeaderViewHolder {
ImageView icon;
@@ -495,10 +551,13 @@
return true;
}
- public HeaderAdapter(Context context, List<Header> objects) {
+ public HeaderAdapter(Context context, List<Header> objects,
+ AuthenticatorHelper authenticatorHelper) {
super(context, 0, objects);
+
+ mAuthHelper = authenticatorHelper;
mInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
-
+
// Temp Switches provided as placeholder until the adapter replaces these with actual
// Switches inflated from their layouts. Must be done before adapter is set in super
mWifiEnabler = new WifiEnabler(context, new Switch(context));
@@ -566,7 +625,20 @@
//$FALL-THROUGH$
case HEADER_TYPE_NORMAL:
- holder.icon.setImageResource(header.iconRes);
+ if (header.extras != null && header.extras.containsKey(
+ ManageAccountsSettings.KEY_ACCOUNT_TYPE)) {
+ String accType = header.extras.getString(
+ ManageAccountsSettings.KEY_ACCOUNT_TYPE);
+ ViewGroup.LayoutParams lp = holder.icon.getLayoutParams();
+ lp.width = getContext().getResources().getDimensionPixelSize(
+ R.dimen.header_icon_width);
+ lp.height = lp.width;
+ holder.icon.setLayoutParams(lp);
+ Drawable icon = mAuthHelper.getDrawableForType(getContext(), accType);
+ holder.icon.setImageDrawable(icon);
+ } else {
+ holder.icon.setImageResource(header.iconRes);
+ }
holder.title.setText(header.getTitle(getContext().getResources()));
CharSequence summary = header.getSummary(getContext().getResources());
if (!TextUtils.isEmpty(summary)) {
@@ -593,6 +665,22 @@
}
@Override
+ public void onHeaderClick(Header header, int position) {
+ boolean revert = false;
+ if (header.id == R.id.account_add) {
+ revert = true;
+ }
+
+ super.onHeaderClick(header, position);
+
+ if (revert && mLastHeader != null) {
+ highlightHeader((int) mLastHeader.id);
+ } else {
+ mLastHeader = header;
+ }
+ }
+
+ @Override
public boolean onPreferenceStartFragment(PreferenceFragment caller, Preference pref) {
// Override the fragment title for Wallpaper settings
int titleRes = pref.getTitleRes();
@@ -620,7 +708,7 @@
}
// Ignore the adapter provided by PreferenceActivity and substitute ours instead
- super.setListAdapter(new HeaderAdapter(this, mHeaders));
+ super.setListAdapter(new HeaderAdapter(this, mHeaders, mAuthenticatorHelper));
}
/*