Merge "Load account type icons in a background thread before scrolling down" into klp-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
d462e86866
@@ -516,9 +516,11 @@ public class Settings extends PreferenceActivity
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onBuildHeaders(List<Header> headers) {
|
public void onBuildHeaders(List<Header> headers) {
|
||||||
|
if (!onIsHidingHeaders()) {
|
||||||
loadHeadersFromResource(R.xml.settings_headers, headers);
|
loadHeadersFromResource(R.xml.settings_headers, headers);
|
||||||
updateHeaderList(headers);
|
updateHeaderList(headers);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void updateHeaderList(List<Header> target) {
|
private void updateHeaderList(List<Header> target) {
|
||||||
final boolean showDev = mDevelopmentPreferences.getBoolean(
|
final boolean showDev = mDevelopmentPreferences.getBoolean(
|
||||||
@@ -655,6 +657,7 @@ public class Settings extends PreferenceActivity
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
accountHeaders.add(accHeader);
|
accountHeaders.add(accHeader);
|
||||||
|
mAuthenticatorHelper.preloadDrawableForType(this, accountType);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sort by label
|
// Sort by label
|
||||||
|
@@ -23,6 +23,7 @@ import android.content.Context;
|
|||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
|
import android.os.AsyncTask;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -45,6 +46,16 @@ public class AuthenticatorHelper {
|
|||||||
return mEnabledAccountTypes.toArray(new String[mEnabledAccountTypes.size()]);
|
return mEnabledAccountTypes.toArray(new String[mEnabledAccountTypes.size()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void preloadDrawableForType(final Context context, final String accountType) {
|
||||||
|
new AsyncTask<Void, Void, Void>() {
|
||||||
|
@Override
|
||||||
|
protected Void doInBackground(Void... params) {
|
||||||
|
getDrawableForType(context, accountType);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void[]) null);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets an icon associated with a particular account type. If none found, return null.
|
* Gets an icon associated with a particular account type. If none found, return null.
|
||||||
* @param accountType the type of account
|
* @param accountType the type of account
|
||||||
@@ -52,15 +63,19 @@ public class AuthenticatorHelper {
|
|||||||
*/
|
*/
|
||||||
public Drawable getDrawableForType(Context context, final String accountType) {
|
public Drawable getDrawableForType(Context context, final String accountType) {
|
||||||
Drawable icon = null;
|
Drawable icon = null;
|
||||||
|
synchronized (mAccTypeIconCache) {
|
||||||
if (mAccTypeIconCache.containsKey(accountType)) {
|
if (mAccTypeIconCache.containsKey(accountType)) {
|
||||||
return mAccTypeIconCache.get(accountType);
|
return mAccTypeIconCache.get(accountType);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (mTypeToAuthDescription.containsKey(accountType)) {
|
if (mTypeToAuthDescription.containsKey(accountType)) {
|
||||||
try {
|
try {
|
||||||
AuthenticatorDescription desc = mTypeToAuthDescription.get(accountType);
|
AuthenticatorDescription desc = mTypeToAuthDescription.get(accountType);
|
||||||
Context authContext = context.createPackageContext(desc.packageName, 0);
|
Context authContext = context.createPackageContext(desc.packageName, 0);
|
||||||
icon = authContext.getResources().getDrawable(desc.iconId);
|
icon = authContext.getResources().getDrawable(desc.iconId);
|
||||||
|
synchronized (mAccTypeIconCache) {
|
||||||
mAccTypeIconCache.put(accountType, icon);
|
mAccTypeIconCache.put(accountType, icon);
|
||||||
|
}
|
||||||
} catch (PackageManager.NameNotFoundException e) {
|
} catch (PackageManager.NameNotFoundException e) {
|
||||||
} catch (Resources.NotFoundException e) {
|
} catch (Resources.NotFoundException e) {
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user