Java 类android.accounts.AuthenticatorDescription 实例源码

项目:VirtualHook    文件:VAccountManagerService.java   
private void generateServicesMap(List<ResolveInfo> services, Map<String, AuthenticatorInfo> map,
                                 IAccountParser accountParser) {
    for (ResolveInfo info : services) {
        XmlResourceParser parser = accountParser.getParser(mContext, info.serviceInfo,
                AccountManager.AUTHENTICATOR_META_DATA_NAME);
        if (parser != null) {
            try {
                AttributeSet attributeSet = Xml.asAttributeSet(parser);
                int type;
                while ((type = parser.next()) != XmlPullParser.END_DOCUMENT && type != XmlPullParser.START_TAG) {
                    // Nothing to do
                }
                if (AccountManager.AUTHENTICATOR_ATTRIBUTES_NAME.equals(parser.getName())) {
                    AuthenticatorDescription desc = parseAuthenticatorDescription(
                            accountParser.getResources(mContext, info.serviceInfo.applicationInfo),
                            info.serviceInfo.packageName, attributeSet);
                    if (desc != null) {
                        map.put(desc.type, new AuthenticatorInfo(desc, info.serviceInfo));
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
项目:container    文件:VAccountManagerService.java   
private void generateServicesMap(List<ResolveInfo> services, Map<String, AuthenticatorInfo> map,
        IAccountParser accountParser) {
    for (ResolveInfo info : services) {
        XmlResourceParser parser = accountParser.getParser(mContext, info.serviceInfo,
                AccountManager.AUTHENTICATOR_META_DATA_NAME);
        if (parser != null) {
            try {
                AttributeSet attributeSet = Xml.asAttributeSet(parser);
                int type;
                while ((type = parser.next()) != XmlPullParser.END_DOCUMENT && type != XmlPullParser.START_TAG) {
                    // Nothing to do
                }
                if (AccountManager.AUTHENTICATOR_ATTRIBUTES_NAME.equals(parser.getName())) {
                    AuthenticatorDescription desc = parseAuthenticatorDescription(
                            accountParser.getResources(mContext, info.serviceInfo.applicationInfo),
                            info.serviceInfo.packageName, attributeSet);
                    if (desc != null) {
                        map.put(desc.type, new AuthenticatorInfo(desc, info.serviceInfo));
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
项目:buildAPKsSamples    文件:ContactAdder.java   
/**
 * Updates account list spinner when the list of Accounts on the system changes. Satisfies
 * OnAccountsUpdateListener implementation.
 */
public void onAccountsUpdated(Account[] a) {
    Log.i(TAG, "Account list update detected");
    // Clear out any old data to prevent duplicates
    mAccounts.clear();

    // Get account data from system
    AuthenticatorDescription[] accountTypes = AccountManager.get(this).getAuthenticatorTypes();

    // Populate tables
    for (int i = 0; i < a.length; i++) {
        // The user may have multiple accounts with the same name, so we need to construct a
        // meaningful display name for each.
        String systemAccountType = a[i].type;
        AuthenticatorDescription ad = getAuthenticatorDescription(systemAccountType,
                accountTypes);
        AccountData data = new AccountData(a[i].name, ad);
        mAccounts.add(data);
    }

    // Update the account spinner
    mAccountAdapter.notifyDataSetChanged();
}
项目:VirtualHook    文件:VAccountManagerService.java   
private static AuthenticatorDescription parseAuthenticatorDescription(Resources resources, String packageName,
                                                                      AttributeSet attributeSet) {
    TypedArray array = resources.obtainAttributes(attributeSet, R_Hide.styleable.AccountAuthenticator.get());
    try {
        String accountType = array.getString(R_Hide.styleable.AccountAuthenticator_accountType.get());
        int label = array.getResourceId(R_Hide.styleable.AccountAuthenticator_label.get(), 0);
        int icon = array.getResourceId(R_Hide.styleable.AccountAuthenticator_icon.get(), 0);
        int smallIcon = array.getResourceId(R_Hide.styleable.AccountAuthenticator_smallIcon.get(), 0);
        int accountPreferences = array.getResourceId(R_Hide.styleable.AccountAuthenticator_accountPreferences.get(), 0);
        boolean customTokens = array.getBoolean(R_Hide.styleable.AccountAuthenticator_customTokens.get(), false);
        if (TextUtils.isEmpty(accountType)) {
            return null;
        }
        return new AuthenticatorDescription(accountType, packageName, label, icon, smallIcon, accountPreferences,
                customTokens);
    } finally {
        array.recycle();
    }
}
项目:TPlayer    文件:ChooseTypeAndAccountActivity.java   
/**
 * Return a set of account types specified 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;
    final String[] allowedAccountTypes =
            intent.getStringArrayExtra(EXTRA_ALLOWABLE_ACCOUNT_TYPES_STRING_ARRAY);
    AuthenticatorDescription[] descs = VAccountManager.get().getAuthenticatorTypes();
    Set<String> supportedAccountTypes = new HashSet<String>(descs.length);
    for (AuthenticatorDescription desc : descs) {
        supportedAccountTypes.add(desc.type);
    }
    if (allowedAccountTypes != null) {
        setOfRelevantAccountTypes = new HashSet<>();
        Collections.addAll(setOfRelevantAccountTypes, allowedAccountTypes);
        setOfRelevantAccountTypes.retainAll(supportedAccountTypes);
    } else {
        setOfRelevantAccountTypes = supportedAccountTypes;
    }
    return setOfRelevantAccountTypes;
}
项目:TPlayer    文件:ChooseAccountTypeActivity.java   
private void buildTypeToAuthDescriptionMap() {
    for(AuthenticatorDescription desc : VAccountManager.get().getAuthenticatorTypes()) {
        String name = null;
        Drawable icon = null;
        try {
            Resources res = VirtualCore.get().getResources(desc.packageName);
            icon = res.getDrawable(desc.iconId);
            final CharSequence sequence = res.getText(desc.labelId);
            name = sequence.toString();
            name = sequence.toString();
        } catch (Resources.NotFoundException e) {
            // Nothing we can do much here, just log
            VLog.w(TAG, "No icon resource for account type " + desc.type);
        }
        AuthInfo authInfo = new AuthInfo(desc, name, icon);
        mTypeToAuthenticatorInfo.put(desc.type, authInfo);
    }
}
项目:TPlayer    文件:VAccountManagerService.java   
private static AuthenticatorDescription parseAuthenticatorDescription(Resources resources, String packageName,
                                                                      AttributeSet attributeSet) {
    TypedArray array = resources.obtainAttributes(attributeSet, R_Hide.styleable.AccountAuthenticator.get());
    try {
        String accountType = array.getString(R_Hide.styleable.AccountAuthenticator_accountType.get());
        int label = array.getResourceId(R_Hide.styleable.AccountAuthenticator_label.get(), 0);
        int icon = array.getResourceId(R_Hide.styleable.AccountAuthenticator_icon.get(), 0);
        int smallIcon = array.getResourceId(R_Hide.styleable.AccountAuthenticator_smallIcon.get(), 0);
        int accountPreferences = array.getResourceId(R_Hide.styleable.AccountAuthenticator_accountPreferences.get(), 0);
        boolean customTokens = array.getBoolean(R_Hide.styleable.AccountAuthenticator_customTokens.get(), false);
        if (TextUtils.isEmpty(accountType)) {
            return null;
        }
        return new AuthenticatorDescription(accountType, packageName, label, icon, smallIcon, accountPreferences,
                customTokens);
    } finally {
        array.recycle();
    }
}
项目:container    文件:VAccountManagerService.java   
private static AuthenticatorDescription parseAuthenticatorDescription(Resources resources, String packageName,
        AttributeSet attributeSet) {
    TypedArray array = resources.obtainAttributes(attributeSet, R_Hide.styleable.AccountAuthenticator.get());
    try {
        String accountType = array.getString(R_Hide.styleable.AccountAuthenticator_accountType.get());
        int label = array.getResourceId(R_Hide.styleable.AccountAuthenticator_label.get(), 0);
        int icon = array.getResourceId(R_Hide.styleable.AccountAuthenticator_icon.get(), 0);
        int smallIcon = array.getResourceId(R_Hide.styleable.AccountAuthenticator_smallIcon.get(), 0);
        int accountPreferences = array.getResourceId(R_Hide.styleable.AccountAuthenticator_accountPreferences.get(), 0);
        boolean customTokens = array.getBoolean(R_Hide.styleable.AccountAuthenticator_customTokens.get(), false);
        if (TextUtils.isEmpty(accountType)) {
            return null;
        }
        return new AuthenticatorDescription(accountType, packageName, label, icon, smallIcon, accountPreferences,
                customTokens);
    } finally {
        array.recycle();
    }
}
项目:SyncSettings    文件:Util.java   
public static String accountToReadableString(Context context, Account account, boolean detailed) {
    PackageManager pm = context.getPackageManager();
    String result = null;
    for (AuthenticatorDescription d: AccountManager.get(context).getAuthenticatorTypes()) {
        if (account.type.equals(d.type)) {
            try {
                result = pm.getResourcesForApplication(d.packageName).getString(d.labelId);
            } catch (Exception e) {
                if (DEBUG) {
                    Log.i(LOG_TAG, "accountToReadableString() got exception: "
                            + e.getMessage());
                }
            }
            break;
        }
    }
    if (TextUtils.isEmpty(result)) {
        result = account.type;
    } else if (detailed) {
        result = context.getString(R.string.sync_account_detailed, result, account.type);
    }
    return context.getString(R.string.sync_account, account.name, result);
}
项目:asstudydemo    文件:ContactAdderFragment.java   
/**
 * Updates account list spinner when the list of Accounts on the system changes. Satisfies OnAccountsUpdateListener implementation.
 *
 * @param accounts
 */
@Override
public void onAccountsUpdated(Account[] accounts) {
    LogUtils.i("Account list update detected");
    // Clear out any old data to prevent duplicates.
    mAccounts.clear();

    // Get account data from system
    AuthenticatorDescription[] accountTypes = AccountManager.get(getContext()).getAuthenticatorTypes();
    // Populate tables
    for (int i = 0; i < accounts.length; i++) {
        // The user may have multiple accounts with the same name, so we need to construct a meaningful display name for each.
        String systemAccountType = accounts[i].type;
        AuthenticatorDescription ad = getAuthenticatorDescription(systemAccountType, accountTypes);
        AccountData data = new AccountData(accounts[i].name, ad);
        mAccounts.add(data);
    }

    // Update the account spinner
    mAccountAdapter.notifyDataSetChanged();
}
项目:asstudydemo    文件:ContactAdderFragment.java   
public AccountData(String name, AuthenticatorDescription description) {
    mName = name;
    if (null != description) {
        mType = description.type;
        // The type string is stored in a resource, so we need to convert it into something human readable.
        String packageName = description.packageName;
        PackageManager pm = getActivity().getPackageManager();
        if (description.labelId != 0) {
            mTypeLabel = pm.getText(packageName, description.labelId, null);
            if (null == mTypeLabel) {
                throw new IllegalArgumentException("LabelID provided, but label not fount");
            }
        } else {
            mTypeLabel = "";
        }

        if (description.iconId != 0) {
            mIcon = pm.getDrawable(packageName, description.iconId, null);
            if (null == mIcon) {
                throw new IllegalArgumentException("IconID provided, but drawable not found");
            }
        } else {
            mIcon = getResources().getDrawable(android.R.drawable.sym_def_app_icon);
        }
    }
}
项目:AndroidSampleCode    文件:ContactAdder.java   
/**
 * Updates account list spinner when the list of Accounts on the system changes. Satisfies
 * OnAccountsUpdateListener implementation.
 */
public void onAccountsUpdated(Account[] a) {
    Log.i(TAG, "Account list update detected");
    // Clear out any old data to prevent duplicates
    mAccounts.clear();

    // Get account data from system
    AuthenticatorDescription[] accountTypes = AccountManager.get(this).getAuthenticatorTypes();

    // Populate tables
    for (int i = 0; i < a.length; i++) {
        // The user may have multiple accounts with the same name, so we need to construct a
        // meaningful display name for each.
        String systemAccountType = a[i].type;
        AuthenticatorDescription ad = getAuthenticatorDescription(systemAccountType,
                accountTypes);
        AccountData data = new AccountData(a[i].name, ad);
        mAccounts.add(data);
    }

    // Update the account spinner
    mAccountAdapter.notifyDataSetChanged();
}
项目:kidsdialer    文件:ContactAdderActivity.java   
/**
 * Updates account list spinner when the list of Accounts on the system
 * changes. Satisfies OnAccountsUpdateListener implementation.
 */
public void onAccountsUpdated(Account[] a) {
    Log.i("Account list update detected");
    // Clear out any old data to prevent duplicates
    mAccounts.clear();

    // Get account data from system
    AuthenticatorDescription[] accountTypes = AccountManager.get(this)
            .getAuthenticatorTypes();

    // Populate tables
    for (int i = 0; i < a.length; i++) {
        // The user may have multiple accounts with the same name, so we
        // need to construct a
        // meaningful display name for each.
        String systemAccountType = a[i].type;
        AuthenticatorDescription ad = getAuthenticatorDescription(
                systemAccountType, accountTypes);
        AccountData data = new AccountData(a[i].name, ad);
        mAccounts.add(data);
    }

    // Update the account spinner
    mAccountAdapter.notifyDataSetChanged();
}
项目:opentasks    文件:XmlModel.java   
public XmlModel(Context context, AuthenticatorDescription authenticator) throws ModelInflaterException
{
    super(context, authenticator.type);
    mPackageName = authenticator.packageName;
    mPackageManager = context.getPackageManager();
    try
    {
        mModelContext = context.createPackageContext(authenticator.packageName, 0);
        AccountManager am = AccountManager.get(context);
        mAccountLabel = mModelContext.getString(authenticator.labelId);
    }
    catch (NameNotFoundException e)
    {
        throw new ModelInflaterException("No model definition found for package " + mPackageName);
    }

}
项目:Android-AccountChooser    文件:ChooseTypeAndAccountActivity.java   
/**
 * 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;
}
项目:letv    文件:LogonManager.java   
private boolean hasLetvAuthenticator() {
    for (AuthenticatorDescription authenticatorType : this.accountManager.getAuthenticatorTypes()) {
        if (this.ACCOUNT_TYPE.equals(authenticatorType.type)) {
            return true;
        }
    }
    return false;
}
项目:buildAPKsSamples    文件:ContactAdder.java   
/**
 * Obtain the AuthenticatorDescription for a given account type.
 * @param type The account type to locate.
 * @param dictionary An array of AuthenticatorDescriptions, as returned by AccountManager.
 * @return The description for the specified account type.
 */
private static AuthenticatorDescription getAuthenticatorDescription(String type,
        AuthenticatorDescription[] dictionary) {
    for (int i = 0; i < dictionary.length; i++) {
        if (dictionary[i].type.equals(type)) {
            return dictionary[i];
        }
    }
    // No match found
    throw new RuntimeException("Unable to find matching authenticator");
}
项目:buildAPKsSamples    文件:ContactAdder.java   
/**
 * @param name The name of the account. This is usually the user's email address or
 *        username.
 * @param description The description for this account. This will be dictated by the
 *        type of account returned, and can be obtained from the system AccountManager.
 */
public AccountData(String name, AuthenticatorDescription description) {
    mName = name;
    if (description != null) {
        mType = description.type;

        // The type string is stored in a resource, so we need to convert it into something
        // human readable.
        String packageName = description.packageName;
        PackageManager pm = getPackageManager();

        if (description.labelId != 0) {
            mTypeLabel = pm.getText(packageName, description.labelId, null);
            if (mTypeLabel == null) {
                throw new IllegalArgumentException("LabelID provided, but label not found");
            }
        } else {
            mTypeLabel = "";
        }

        if (description.iconId != 0) {
            mIcon = pm.getDrawable(packageName, description.iconId, null);
            if (mIcon == null) {
                throw new IllegalArgumentException("IconID provided, but drawable not " +
                        "found");
            }
        } else {
            mIcon = getResources().getDrawable(android.R.drawable.sym_def_app_icon);
        }
    }
}
项目:VirtualHook    文件:VAccountManager.java   
public AuthenticatorDescription[] getAuthenticatorTypes() {
    try {
        return getRemote().getAuthenticatorTypes(VUserHandle.myUserId());
    } catch (RemoteException e) {
        return VirtualRuntime.crash(e);
    }
}
项目:VirtualHook    文件:VAccountManagerService.java   
@Override
public AuthenticatorDescription[] getAuthenticatorTypes(int userId) {
    synchronized (cache) {
        AuthenticatorDescription[] descArray = new AuthenticatorDescription[cache.authenticators.size()];
        int i = 0;
        for (AuthenticatorInfo info : cache.authenticators.values()) {
            descArray[i] = info.desc;
            i++;
        }
        return descArray;
    }
}
项目:TPlayer    文件:VAccountManager.java   
public AuthenticatorDescription[] getAuthenticatorTypes() {
    try {
        return getRemote().getAuthenticatorTypes(VUserHandle.myUserId());
    } catch (RemoteException e) {
        return VirtualRuntime.crash(e);
    }
}
项目:TPlayer    文件:VAccountManagerService.java   
@Override
public AuthenticatorDescription[] getAuthenticatorTypes(int userId) {
    synchronized (cache) {
        AuthenticatorDescription[] descArray = new AuthenticatorDescription[cache.authenticators.size()];
        int i = 0;
        for (AuthenticatorInfo info : cache.authenticators.values()) {
            descArray[i] = info.desc;
            i++;
        }
        return descArray;
    }
}
项目:container    文件:VAccountManager.java   
public AuthenticatorDescription[] getAuthenticatorTypes() {
    try {
        return getRemote().getAuthenticatorTypes(VUserHandle.myUserId());
    } catch (RemoteException e) {
        return VirtualRuntime.crash(e);
    }
}
项目:container    文件:VAccountManagerService.java   
@Override
public AuthenticatorDescription[] getAuthenticatorTypes(int userId) {
    synchronized (cache) {
        AuthenticatorDescription[] descArray = new AuthenticatorDescription[cache.authenticators.size()];
        int i = 0;
        for (AuthenticatorInfo info : cache.authenticators.values()) {
            descArray[i] = info.desc;
            i++;
        }
        return descArray;
    }
}
项目:asstudydemo    文件:ContactAdderFragment.java   
private AuthenticatorDescription getAuthenticatorDescription(String type, AuthenticatorDescription[] dictionary) {
    for (int i = 0; i < dictionary.length; i++) {
        if (dictionary[i].type.equals(type)) {
            return dictionary[i];
        }
    }
    // No match found
    throw new RuntimeException("Unable to find matching authenticator");
}
项目:365browser    文件:AccountManagerHelper.java   
/**
 * @return Whether or not there is an account authenticator for Google accounts.
 */
public boolean hasGoogleAccountAuthenticator() {
    AuthenticatorDescription[] descs = mDelegate.getAuthenticatorTypes();
    for (AuthenticatorDescription desc : descs) {
        if (GOOGLE_ACCOUNT_TYPE.equals(desc.type)) return true;
    }
    return false;
}
项目:FullRobolectricTestSample    文件:AccountManagerTest.java   
@Test
public void testAddAuthenticator() {
  Robolectric.shadowOf(am).addAuthenticator("type");
  AuthenticatorDescription[] result = am.getAuthenticatorTypes();
  assertThat(result.length).isEqualTo(1);
  assertThat(result[0].type).isEqualTo("type");
}
项目:SafeSlinger-Android    文件:SaveActivity.java   
private AuthenticatorDescription getAuthenticatorDescription(String type,
        AuthenticatorDescription[] dictionary) {
    for (int i = 0; i < dictionary.length; i++) {
        if (dictionary[i].type.equals(type)) {
            return dictionary[i];
        }
    }
    // No match found
    return null;
}
项目:SafeSlinger-Android    文件:SettingsActivity.java   
private static AuthenticatorDescription getAuthenticatorDescription(String type,
        AuthenticatorDescription[] dictionary) {
    for (int i = 0; i < dictionary.length; i++) {
        if (dictionary[i].type.equals(type)) {
            return dictionary[i];
        }
    }
    // No match found
    return null;
}
项目:SafeSlinger-Android    文件:AccountData.java   
public AccountData(Context ctx, String name, AuthenticatorDescription description) {
    mName = name;
    if (description != null) {
        mType = description.type;

        // The type string is stored in a resource, so we need to
        // convert it into something
        // human readable.
        String packageName = description.packageName;
        PackageManager pm = ctx.getPackageManager();

        if (description.labelId != 0) {
            mTypeLabel = pm.getText(packageName, description.labelId, null);
            if (mTypeLabel == null) {
                mTypeLabel = ctx.getString(R.string.label_undefinedTypeLabel);
            }
        } else {
            mTypeLabel = "";
        }

        if (description.iconId != 0) {
            mIcon = pm.getDrawable(packageName, description.iconId, null);
        } else {
            mIcon = ctx.getResources().getDrawable(android.R.drawable.sym_def_app_icon);
        }
    }
}
项目:AndroidSampleCode    文件:ContactAdder.java   
/**
 * Obtain the AuthenticatorDescription for a given account type.
 * @param type The account type to locate.
 * @param dictionary An array of AuthenticatorDescriptions, as returned by AccountManager.
 * @return The description for the specified account type.
 */
private static AuthenticatorDescription getAuthenticatorDescription(String type,
        AuthenticatorDescription[] dictionary) {
    for (int i = 0; i < dictionary.length; i++) {
        if (dictionary[i].type.equals(type)) {
            return dictionary[i];
        }
    }
    // No match found
    throw new RuntimeException("Unable to find matching authenticator");
}
项目:AndroidSampleCode    文件:ContactAdder.java   
/**
 * @param name The name of the account. This is usually the user's email address or
 *        username.
 * @param description The description for this account. This will be dictated by the
 *        type of account returned, and can be obtained from the system AccountManager.
 */
public AccountData(String name, AuthenticatorDescription description) {
    mName = name;
    if (description != null) {
        mType = description.type;

        // The type string is stored in a resource, so we need to convert it into something
        // human readable.
        String packageName = description.packageName;
        PackageManager pm = getPackageManager();

        if (description.labelId != 0) {
            mTypeLabel = pm.getText(packageName, description.labelId, null);
            if (mTypeLabel == null) {
                throw new IllegalArgumentException("LabelID provided, but label not found");
            }
        } else {
            mTypeLabel = "";
        }

        if (description.iconId != 0) {
            mIcon = pm.getDrawable(packageName, description.iconId, null);
            if (mIcon == null) {
                throw new IllegalArgumentException("IconID provided, but drawable not " +
                        "found");
            }
        } else {
            mIcon = getResources().getDrawable(android.R.drawable.sym_def_app_icon);
        }
    }
}
项目:haxsync    文件:ContactUtil.java   
private static void fillIcons(Context c){
    AccountManager am = AccountManager.get(c);
    AuthenticatorDescription[] auths = am.getAuthenticatorTypes();
    PackageManager pm = c.getPackageManager();
    for (AuthenticatorDescription auth : auths){
        accountIcons.put(auth.type, pm.getDrawable(auth.packageName,  auth.iconId, null));
    /*  Log.i("Account:", auth.type);
        Log.i("pkg:", auth.packageName);
        Log.i("icon:", String.valueOf(auth.smallIconId));*/

    }
}
项目:kidsdialer    文件:ContactAdderActivity.java   
/**
 * Obtain the AuthenticatorDescription for a given account type.
 * 
 * @param type
 *            The account type to locate.
 * @param dictionary
 *            An array of AuthenticatorDescriptions, as returned by
 *            AccountManager.
 * @return The description for the specified account type.
 */
private static AuthenticatorDescription getAuthenticatorDescription(
        String type, AuthenticatorDescription[] dictionary) {
    for (int i = 0; i < dictionary.length; i++) {
        if (dictionary[i].type.equals(type)) {
            return dictionary[i];
        }
    }
    // No match found
    throw new RuntimeException("Unable to find matching authenticator");
}
项目:kidsdialer    文件:ContactAdderActivity.java   
/**
 * @param name
 *            The name of the account. This is usually the user's email
 *            address or username.
 * @param description
 *            The description for this account. This will be dictated by
 *            the type of account returned, and can be obtained from the
 *            system AccountManager.
 */
public AccountData(String name, AuthenticatorDescription description) {
    mName = name;
    if (description != null) {
        mType = description.type;

        // The type string is stored in a resource, so we need to
        // convert it into something
        // human readable.
        String packageName = description.packageName;
        PackageManager pm = getPackageManager();

        if (description.labelId != 0) {
            mTypeLabel = pm.getText(packageName, description.labelId,
                    null);
            if (mTypeLabel == null) {
                throw new IllegalArgumentException(
                        "LabelID provided, but label not found");
            }
        } else {
            mTypeLabel = "";
        }

        if (description.iconId != 0) {
            mIcon = pm.getDrawable(packageName, description.iconId,
                    null);
            if (mIcon == null) {
                throw new IllegalArgumentException(
                        "IconID provided, but drawable not " + "found");
            }
        } else {
            mIcon = getResources().getDrawable(
                    android.R.drawable.sym_def_app_icon);
        }
    }
}
项目:android-chromium    文件:AccountManagerHelper.java   
/**
 * @return Whether or not there is an account authenticator for Google accounts.
 */
public boolean hasGoogleAccountAuthenticator() {
    AuthenticatorDescription[] descs = mAccountManager.getAuthenticatorTypes();
    for (AuthenticatorDescription desc : descs) {
        if (GOOGLE_ACCOUNT_TYPE.equals(desc.type)) return true;
    }
    return false;
}
项目:opentasks    文件:Sources.java   
/**
 * Return the {@link AuthenticatorDescription} for the given account type.
 *
 * @param accountType
 *         The account type to find.
 *
 * @return The {@link AuthenticatorDescription} for the given account type or {@code null} if no such account exists.
 */
private AuthenticatorDescription getAuthenticator(AuthenticatorDescription[] authenticators, String accountType)
{
    for (AuthenticatorDescription auth : authenticators)
    {
        if (TextUtils.equals(accountType, auth.type))
        {
            return auth;
        }
    }
    // no authenticator for that account type found
    return null;
}
项目:Calendar_lunar    文件:SelectSyncedCalendarsMultiAccountAdapter.java   
/**
 * 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.
 */
protected CharSequence getLabelForType(final String accountType) {
    CharSequence label = null;
    if (mTypeToAuthDescription.containsKey(accountType)) {
         try {
             AuthenticatorDescription desc = mTypeToAuthDescription.get(accountType);
             Context authContext = mActivity.createPackageContext(desc.packageName, 0);
             label = authContext.getResources().getText(desc.labelId);
         } catch (PackageManager.NameNotFoundException e) {
             Log.w(TAG, "No label for account type " + ", type " + accountType);
         }
    }
    return label;
}
项目:cordova-android-chromium    文件:AccountManagerHelper.java   
/**
 * @return Whether or not there is an account authenticator for Google accounts.
 */
public boolean hasGoogleAccountAuthenticator() {
    AuthenticatorDescription[] descs = mAccountManager.getAuthenticatorTypes();
    for (AuthenticatorDescription desc : descs) {
        if (GOOGLE_ACCOUNT_TYPE.equals(desc.type)) return true;
    }
    return false;
}
项目:triallibary    文件:IdentityResolver.java   
private Drawable getIconForAccountType(String accountType, AccountManager manager) {
     AuthenticatorDescription[] descriptions =  manager.getAuthenticatorTypes();
     for (AuthenticatorDescription description: descriptions) {
         if (description.type.equals(accountType)) {
             PackageManager pm = mContext.getPackageManager();
             return pm.getDrawable(description.packageName, description.iconId, null); 
         }
     }
     return null;
}