From cfc7f9d9600f7b4514ce9608314874bf1023eb21 Mon Sep 17 00:00:00 2001 From: Alexandra Gherghina Date: Fri, 4 Jul 2014 12:25:38 +0100 Subject: [PATCH] Remove old accounts tile, replaced by a separate screen Bug: 15815948 Bug: 15819268 Change-Id: I3b6978cff346c73cca1d6a2c209ffe4c71808244 --- res/xml/dashboard_categories.xml | 14 --- .../android/settings/SettingsActivity.java | 108 +----------------- .../accounts/AuthenticatorHelper.java | 5 +- .../settings/dashboard/DashboardSummary.java | 55 +-------- 4 files changed, 10 insertions(+), 172 deletions(-) diff --git a/res/xml/dashboard_categories.xml b/res/xml/dashboard_categories.xml index f5df4a2dd3b..53a6d5a6928 100644 --- a/res/xml/dashboard_categories.xml +++ b/res/xml/dashboard_categories.xml @@ -188,20 +188,6 @@ - - - - - - - - - getDashboardCategories() { if (mNeedToRebuildCategories || mCategories.size() == 0) { buildDashboardCategories(mCategories); @@ -482,13 +465,6 @@ public class SettingsActivity extends Activity if (intent.hasExtra(EXTRA_UI_OPTIONS)) { getWindow().setUiOptions(intent.getIntExtra(EXTRA_UI_OPTIONS, 0)); } - // TODO: Delete accounts tile once we have the new screen working - // See: http://b/15815948 - final UserManager um = (UserManager) getSystemService(Context.USER_SERVICE); - mAuthenticatorHelper = new AuthenticatorHelper( - this, UserHandle.getCallingUserHandle(), um, this); - mAuthenticatorHelper.updateAuthDescriptions(this); - mAuthenticatorHelper.onAccountsUpdated(null); mDevelopmentPreferences = getSharedPreferences(DevelopmentSettings.PREF_FILE, Context.MODE_PRIVATE); @@ -743,10 +719,6 @@ public class SettingsActivity extends Activity mDevelopmentPreferences.unregisterOnSharedPreferenceChangeListener( mDevelopmentPreferencesListener); mDevelopmentPreferencesListener = null; - - if (mListeningToAccountUpdates) { - AccountManager.get(this).removeOnAccountsUpdatedListener(this); - } } protected boolean isValidFragment(String fragmentName) { @@ -1071,10 +1043,6 @@ public class SettingsActivity extends Activity // Ids are integers, so downcasting is ok int id = (int) category.id; - if (id == R.id.account_settings) { - insertAccountsTiles(category); - continue; - } int n = category.getTilesCount() - 1; while (n >= 0) { @@ -1146,10 +1114,6 @@ public class SettingsActivity extends Activity UserManager.DISALLOW_DEBUGGING_FEATURES)) { category.removeTile(n); } - } else if (id == R.id.account_add) { - if (um.hasUserRestriction(UserManager.DISALLOW_MODIFY_ACCOUNTS)) { - category.removeTile(n); - } } if (UserHandle.MU_ENABLED && UserHandle.myUserId() != 0 @@ -1201,62 +1165,6 @@ public class SettingsActivity extends Activity return true; } - private void insertAccountsTiles(DashboardCategory target) { - String[] accountTypes = mAuthenticatorHelper.getEnabledAccountTypes(); - List dashboardTiles = new ArrayList(accountTypes.length); - for (String accountType : accountTypes) { - CharSequence label = mAuthenticatorHelper.getLabelForType(this, accountType); - if (label == null) { - continue; - } - - Account[] accounts = AccountManager.get(this).getAccountsByType(accountType); - boolean skipToAccount = accounts.length == 1 - && !mAuthenticatorHelper.hasAccountPreferences(accountType); - DashboardTile accountTile = new DashboardTile(); - accountTile.title = label; - if (accountTile.extras == null) { - accountTile.extras = new Bundle(); - } - if (skipToAccount) { - accountTile.fragment = AccountSyncSettings.class.getName(); - accountTile.fragmentArguments = new Bundle(); - // Need this for the icon - accountTile.extras.putString(ManageAccountsSettings.KEY_ACCOUNT_TYPE, accountType); - accountTile.extras.putParcelable(AccountSyncSettings.ACCOUNT_KEY, accounts[0]); - accountTile.fragmentArguments.putParcelable(AccountSyncSettings.ACCOUNT_KEY, - accounts[0]); - } else { - accountTile.fragment = ManageAccountsSettings.class.getName(); - accountTile.fragmentArguments = new Bundle(); - accountTile.extras.putString(ManageAccountsSettings.KEY_ACCOUNT_TYPE, accountType); - accountTile.fragmentArguments.putString(ManageAccountsSettings.KEY_ACCOUNT_TYPE, - accountType); - accountTile.fragmentArguments.putString(ManageAccountsSettings.KEY_ACCOUNT_LABEL, - label.toString()); - } - dashboardTiles.add(accountTile); - mAuthenticatorHelper.preloadDrawableForType(this, accountType); - } - - // Sort by label - Collections.sort(dashboardTiles, new Comparator() { - @Override - public int compare(DashboardTile t1, DashboardTile t2) { - return t1.title.toString().compareTo(t2.title.toString()); - } - }); - int index = 0; - for (DashboardTile tile : dashboardTiles) { - target.addTile(index, tile); - index++; - } - if (!mListeningToAccountUpdates) { - AccountManager.get(this).addOnAccountsUpdatedListener(this, null, true); - mListeningToAccountUpdates = true; - } - } - private void getMetaData() { try { ActivityInfo ai = getPackageManager().getActivityInfo(getComponentName(), @@ -1283,18 +1191,6 @@ public class SettingsActivity extends Activity return super.shouldUpRecreateTask(new Intent(this, SettingsActivity.class)); } - @Override - public void onAccountsUpdated(Account[] accounts) { - // TODO: watch for package upgrades to invalidate cache; see 7206643 - mAuthenticatorHelper.updateAuthDescriptions(this); - invalidateCategories(); - } - - @Override - public void onAccountsUpdate(UserHandle userHandle) { - invalidateCategories(); - } - public static void requestHomeNotice() { sShowNoHomeNotice = true; } diff --git a/src/com/android/settings/accounts/AuthenticatorHelper.java b/src/com/android/settings/accounts/AuthenticatorHelper.java index e74c8d5f619..7ea2f12f076 100644 --- a/src/com/android/settings/accounts/AuthenticatorHelper.java +++ b/src/com/android/settings/accounts/AuthenticatorHelper.java @@ -171,9 +171,7 @@ final public class AuthenticatorHelper extends BroadcastReceiver { return false; } - public void onAccountsUpdated(Account[] accounts) { - // TODO: Revert to non-public once no longer needed in SettingsActivity - // See http://b/15819268 + void onAccountsUpdated(Account[] accounts) { updateAuthDescriptions(mContext); if (accounts == null) { accounts = AccountManager.get(mContext).getAccountsAsUser(mUserHandle.getIdentifier()); @@ -193,6 +191,7 @@ final public class AuthenticatorHelper extends BroadcastReceiver { @Override public void onReceive(final Context context, final Intent intent) { + // TODO: watch for package upgrades to invalidate cache; see http://b/7206643 final Account[] accounts = AccountManager.get(mContext) .getAccountsAsUser(mUserHandle.getIdentifier()); onAccountsUpdated(accounts); diff --git a/src/com/android/settings/dashboard/DashboardSummary.java b/src/com/android/settings/dashboard/DashboardSummary.java index ece32f6829f..ed89d89f794 100644 --- a/src/com/android/settings/dashboard/DashboardSummary.java +++ b/src/com/android/settings/dashboard/DashboardSummary.java @@ -16,13 +16,9 @@ package com.android.settings.dashboard; -import android.accounts.Account; -import android.accounts.AccountManager; -import android.accounts.OnAccountsUpdateListener; import android.app.Fragment; import android.content.Context; import android.content.res.Resources; -import android.graphics.drawable.Drawable; import android.os.Bundle; import android.os.Handler; import android.os.Message; @@ -35,18 +31,14 @@ import android.widget.ImageView; import android.widget.TextView; import com.android.settings.R; import com.android.settings.SettingsActivity; -import com.android.settings.accounts.AuthenticatorHelper; -import com.android.settings.accounts.ManageAccountsSettings; import java.util.List; -public class DashboardSummary extends Fragment implements OnAccountsUpdateListener { +public class DashboardSummary extends Fragment { private static final String LOG_TAG = "DashboardSummary"; private LayoutInflater mLayoutInflater; private ViewGroup mDashboard; - private AuthenticatorHelper mAuthHelper; - private boolean mAccountListenerAdded; private static final int MSG_REBUILD_UI = 1; private Handler mHandler = new Handler() { @@ -72,8 +64,6 @@ public class DashboardSummary extends Fragment implements OnAccountsUpdateListen final View rootView = inflater.inflate(R.layout.dashboard, container, false); mDashboard = (ViewGroup) rootView.findViewById(R.id.dashboard_container); - mAuthHelper = ((SettingsActivity) context).getAuthenticatorHelper(); - return rootView; } @@ -129,45 +119,19 @@ public class DashboardSummary extends Fragment implements OnAccountsUpdateListen public void onResume() { super.onResume(); - if (!mAccountListenerAdded) { - AccountManager.get(getActivity()).addOnAccountsUpdatedListener(this, null, false); - mAccountListenerAdded = true; - } - sendRebuildUI(); } - @Override - public void onDestroy() { - super.onDestroy(); - - if (mAccountListenerAdded) { - AccountManager.get(getActivity()).removeOnAccountsUpdatedListener(this); - mAccountListenerAdded = false; - } - } - private void updateTileView(Context context, Resources res, DashboardTile tile, ImageView tileIcon, TextView tileTextView, TextView statusTextView) { - if (tile.extras != null - && tile.extras.containsKey(ManageAccountsSettings.KEY_ACCOUNT_TYPE)) { - String accType = tile.extras.getString(ManageAccountsSettings.KEY_ACCOUNT_TYPE); - Drawable drawable = mAuthHelper.getDrawableForType(context, accType); - tileIcon.setImageDrawable(drawable); + if (tile.iconRes > 0) { + tileIcon.setImageResource(tile.iconRes); } else { - if (tile.iconRes > 0) { - tileIcon.setImageResource(tile.iconRes); - } else { - tileIcon.setImageDrawable(null); - } - } - if (tileIcon != null) { - if (tile.iconRes > 0) { - } else { - tileIcon.setBackground(null); - } + tileIcon.setImageDrawable(null); + tileIcon.setBackground(null); } + tileTextView.setText(tile.getTitle(res)); CharSequence summary = tile.getSummary(res); @@ -184,11 +148,4 @@ public class DashboardSummary extends Fragment implements OnAccountsUpdateListen mHandler.sendEmptyMessage(MSG_REBUILD_UI); } } - - @Override - public void onAccountsUpdated(Account[] accounts) { - final SettingsActivity sa = (SettingsActivity) getActivity(); - sa.setNeedToRebuildCategories(true); - sendRebuildUI(); - } }