use of android.accounts.AuthenticatorDescription in project Android-AccountChooser by frakbot.
the class ChooseTypeAndAccountActivity method getReleventAccountTypes.
/**
* Return a set of account types speficied by the intent as well as supported by the
* AccountManager.
*/
private Set<String> getReleventAccountTypes(final Intent intent) {
// An account type is relevant iff it is allowed by the caller and supported by the account
// manager.
Set<String> setOfRelevantAccountTypes = null;
final String[] allowedAccountTypes = intent.getStringArrayExtra(EXTRA_ALLOWABLE_ACCOUNT_TYPES_STRING_ARRAY);
if (allowedAccountTypes != null) {
setOfRelevantAccountTypes = Sets.newHashSet(allowedAccountTypes);
AuthenticatorDescription[] descs = AccountManager.get(this).getAuthenticatorTypes();
Set<String> supportedAccountTypes = new HashSet<String>(descs.length);
for (AuthenticatorDescription desc : descs) {
supportedAccountTypes.add(desc.type);
}
setOfRelevantAccountTypes.retainAll(supportedAccountTypes);
}
return setOfRelevantAccountTypes;
}
use of android.accounts.AuthenticatorDescription in project platform_frameworks_base by android.
the class AccountAuthenticatorCache method parseServiceAttributes.
public AuthenticatorDescription parseServiceAttributes(Resources res, String packageName, AttributeSet attrs) {
TypedArray sa = res.obtainAttributes(attrs, com.android.internal.R.styleable.AccountAuthenticator);
try {
final String accountType = sa.getString(com.android.internal.R.styleable.AccountAuthenticator_accountType);
final int labelId = sa.getResourceId(com.android.internal.R.styleable.AccountAuthenticator_label, 0);
final int iconId = sa.getResourceId(com.android.internal.R.styleable.AccountAuthenticator_icon, 0);
final int smallIconId = sa.getResourceId(com.android.internal.R.styleable.AccountAuthenticator_smallIcon, 0);
final int prefId = sa.getResourceId(com.android.internal.R.styleable.AccountAuthenticator_accountPreferences, 0);
final boolean customTokens = sa.getBoolean(com.android.internal.R.styleable.AccountAuthenticator_customTokens, false);
if (TextUtils.isEmpty(accountType)) {
return null;
}
return new AuthenticatorDescription(accountType, packageName, labelId, iconId, smallIconId, prefId, customTokens);
} finally {
sa.recycle();
}
}
use of android.accounts.AuthenticatorDescription in project android_frameworks_base by ParanoidAndroid.
the class AccountAuthenticatorCache method parseServiceAttributes.
public AuthenticatorDescription parseServiceAttributes(Resources res, String packageName, AttributeSet attrs) {
TypedArray sa = res.obtainAttributes(attrs, com.android.internal.R.styleable.AccountAuthenticator);
try {
final String accountType = sa.getString(com.android.internal.R.styleable.AccountAuthenticator_accountType);
final int labelId = sa.getResourceId(com.android.internal.R.styleable.AccountAuthenticator_label, 0);
final int iconId = sa.getResourceId(com.android.internal.R.styleable.AccountAuthenticator_icon, 0);
final int smallIconId = sa.getResourceId(com.android.internal.R.styleable.AccountAuthenticator_smallIcon, 0);
final int prefId = sa.getResourceId(com.android.internal.R.styleable.AccountAuthenticator_accountPreferences, 0);
final boolean customTokens = sa.getBoolean(com.android.internal.R.styleable.AccountAuthenticator_customTokens, false);
if (TextUtils.isEmpty(accountType)) {
return null;
}
return new AuthenticatorDescription(accountType, packageName, labelId, iconId, smallIconId, prefId, customTokens);
} finally {
sa.recycle();
}
}
use of android.accounts.AuthenticatorDescription in project platform_frameworks_base by android.
the class AuthenticatorHelper method getLabelForType.
/**
* Gets the label associated with a particular account type. If none found, return null.
* @param accountType the type of account
* @return a CharSequence for the label or null if one cannot be found.
*/
public CharSequence getLabelForType(Context context, final String accountType) {
CharSequence label = null;
if (mTypeToAuthDescription.containsKey(accountType)) {
try {
AuthenticatorDescription desc = mTypeToAuthDescription.get(accountType);
Context authContext = context.createPackageContextAsUser(desc.packageName, 0, mUserHandle);
label = authContext.getResources().getText(desc.labelId);
} catch (PackageManager.NameNotFoundException e) {
Log.w(TAG, "No label name for account type " + accountType);
} catch (Resources.NotFoundException e) {
Log.w(TAG, "No label icon for account type " + accountType);
}
}
return label;
}
use of android.accounts.AuthenticatorDescription in project platform_frameworks_base by android.
the class AuthenticatorHelper method getDrawableForType.
/**
* Gets an icon associated with a particular account type. If none found, return null.
* @param accountType the type of account
* @return a drawable for the icon or a default icon returned by
* {@link PackageManager#getDefaultActivityIcon} if one cannot be found.
*/
public Drawable getDrawableForType(Context context, final String accountType) {
Drawable icon = null;
synchronized (mAccTypeIconCache) {
if (mAccTypeIconCache.containsKey(accountType)) {
return mAccTypeIconCache.get(accountType);
}
}
if (mTypeToAuthDescription.containsKey(accountType)) {
try {
AuthenticatorDescription desc = mTypeToAuthDescription.get(accountType);
Context authContext = context.createPackageContextAsUser(desc.packageName, 0, mUserHandle);
icon = mContext.getPackageManager().getUserBadgedIcon(authContext.getDrawable(desc.iconId), mUserHandle);
synchronized (mAccTypeIconCache) {
mAccTypeIconCache.put(accountType, icon);
}
} catch (PackageManager.NameNotFoundException | Resources.NotFoundException e) {
// Ignore
}
}
if (icon == null) {
icon = context.getPackageManager().getDefaultActivityIcon();
}
return icon;
}
Aggregations