/** * @return true if the Account for the current filter exists. */ private boolean filterAccountExists() { final AccountTypeManager accountTypeManager = AccountTypeManager.getInstance(mContext); final AccountWithDataSet filterAccount = new AccountWithDataSet( mFilter.accountName, mFilter.accountType, mFilter.dataSet); return accountTypeManager.contains(filterAccount, false); } }
public final AccountType getAccountTypeForAccount(AccountWithDataSet account) { if (account != null) { return getAccountType(account.getAccountTypeWithDataSet()); } return getAccountType(null, null); }
/** * @return google accounts with "com.google" account type and null data set. */ private List<Account> getFocusGoogleAccounts() { List<Account> focusGoogleAccounts = new ArrayList<Account>(); final AccountTypeManager accountTypeManager = AccountTypeManager.getInstance(mContext); List<AccountWithDataSet> accounts = accountTypeManager.getAccounts(true); for (AccountWithDataSet account : accounts) { if (GoogleAccountType.ACCOUNT_TYPE.equals(account.type) && account.dataSet == null) { focusGoogleAccounts.add(account.getAccountOrNull()); } } return focusGoogleAccounts; }
public static boolean areGroupWritableAccountsAvailable(Context context) { final List<AccountWithDataSet> accounts = AccountTypeManager.getInstance(context).getGroupWritableAccounts(); return !accounts.isEmpty(); }
private List<AccountWithDataSet> getAccounts(AccountListFilter accountListFilter) { if (accountListFilter == AccountListFilter.ACCOUNTS_GROUP_WRITABLE) { return new ArrayList<AccountWithDataSet>(mAccountTypes.getGroupWritableAccounts()); } return new ArrayList<AccountWithDataSet>(mAccountTypes.getAccounts( accountListFilter == AccountListFilter.ACCOUNTS_CONTACT_WRITABLE)); }
private static List<ContactListFilter> loadAccountFilters(Context context) { final ArrayList<ContactListFilter> result = Lists.newArrayList(); final ArrayList<ContactListFilter> accountFilters = Lists.newArrayList(); final AccountTypeManager accountTypes = AccountTypeManager.getInstance(context); List<AccountWithDataSet> accounts = accountTypes.getAccounts(false); for (AccountWithDataSet account : accounts) { AccountType accountType = accountTypes.getAccountType(account.type, account.dataSet); if (accountType.isExtension() && !account.hasData(context)) { // Hide extensions with no raw_contacts. continue; } Drawable icon = accountType != null ? accountType.getDisplayIcon(context) : null; accountFilters.add(ContactListFilter.createAccountFilter( account.type, account.name, account.dataSet, icon)); } // Always show "All", even when there's no accounts. (We may have local contacts) result.add(ContactListFilter.createFilterWithType( ContactListFilter.FILTER_TYPE_ALL_ACCOUNTS)); final int count = accountFilters.size(); if (count >= 1) { // If we only have one account, don't show it as "account", instead show it as "all" if (count > 1) { result.addAll(accountFilters); } result.add(ContactListFilter.createFilterWithType( ContactListFilter.FILTER_TYPE_CUSTOM)); } return result; }
@Override public AccountSet loadInBackground() { Context context = getContext(); final AccountTypeManager accountTypes = AccountTypeManager.getInstance(context); final ContentResolver resolver = context.getContentResolver(); for (AccountWithDataSet account : accountTypes.getAccounts(false)) { final AccountType accountType = accountTypes.getAccountTypeForAccount(account); if (accountType.isExtension() && !account.hasData(context)) {
/** * Return the AccountType that this raw-contact belongs to. */ public AccountType getRawContactAccountType(Context context) { ContentValues entityValues = getValues().getCompleteValues(); String type = entityValues.getAsString(RawContacts.ACCOUNT_TYPE); String dataSet = entityValues.getAsString(RawContacts.DATA_SET); return AccountTypeManager.getInstance(context).getAccountType(type, dataSet); }
/** * Sets the "invitable" account types to {@link Contact#mInvitableAccountTypes}. */ private void loadInvitableAccountTypes(Contact contactData) { final ImmutableList.Builder<AccountType> resultListBuilder = new ImmutableList.Builder<AccountType>(); if (!contactData.isUserProfile()) { Map<AccountTypeWithDataSet, AccountType> invitables = AccountTypeManager.getInstance(getContext()).getUsableInvitableAccountTypes(); if (!invitables.isEmpty()) { final Map<AccountTypeWithDataSet, AccountType> resultMap = Maps.newHashMap(invitables); // Remove the ones that already have a raw contact in the current contact for (RawContact rawContact : contactData.getRawContacts()) { final AccountTypeWithDataSet type = AccountTypeWithDataSet.get( rawContact.getAccountTypeString(), rawContact.getDataSet()); resultMap.remove(type); } resultListBuilder.addAll(resultMap.values()); } } // Set to mInvitableAccountTypes contactData.setInvitableAccountTypes(resultListBuilder.build()); }
public AccountTypeManager getAccountTypeManager(Context context) { if (mAccountTypeManager == null) { mAccountTypeManager = AccountTypeManager.getInstance(context); } return mAccountTypeManager; }
/** * @param contactWritableOnly if true, it only returns ones that support writing contacts. * @return true when this instance contains the given account. */ public boolean contains(AccountWithDataSet account, boolean contactWritableOnly) { for (AccountWithDataSet account_2 : getAccounts(false)) { if (account.equals(account_2)) { return true; } } return false; } }
public DisplayAdapter(Context context) { mContext = context; mInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); mAccountTypes = AccountTypeManager.getInstance(context); }
final AccountTypeManager accountTypes = AccountTypeManager.getInstance(this); final List<AccountWithDataSet> accountList = accountTypes.getAccounts(true); if (accountList.size() == 0) { Log.w(LOG_TAG, "Account does not exist");
public final AccountType getAccountType(String accountType, String dataSet) { return getAccountType(AccountTypeWithDataSet.get(accountType, dataSet)); }
public FilterListAdapter( Context context, List<ContactListFilter> filters, ContactListFilter current) { mLayoutInflater = (LayoutInflater) context.getSystemService (Context.LAYOUT_INFLATER_SERVICE); mFilters = filters; mCurrentFilter = current; mAccountTypes = AccountTypeManager.getInstance(context); }
private void prepare() { mPreferences = new ContactsPreferences(getContext()); mAccountMap = new HashMap<>(); final AccountTypeManager accountTypeManager = AccountTypeManager.getInstance(getContext()); List<AccountWithDataSet> accounts = accountTypeManager.getAccounts(true); for (AccountWithDataSet account : accounts) { mAccountMap.put(account.name, account); } final Set<String> accountNames = mAccountMap.keySet(); final String[] accountNamesArray = accountNames.toArray(new String[accountNames.size()]); setEntries(accountNamesArray); setEntryValues(accountNamesArray); final String defaultAccount = String.valueOf(mPreferences.getDefaultAccount()); if (accounts.size() == 1) { setValue(accounts.get(0).name); } else if (accountNames.contains(defaultAccount)) { setValue(defaultAccount); } else { setValue(null); } }
@Override public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) { if (convertView == null) { convertView = mInflater.inflate( R.layout.custom_contact_list_filter_account, parent, false); } final TextView text1 = (TextView)convertView.findViewById(android.R.id.text1); final TextView text2 = (TextView)convertView.findViewById(android.R.id.text2); final AccountDisplay account = (AccountDisplay)this.getGroup(groupPosition); final AccountType accountType = mAccountTypes.getAccountType( account.mType, account.mDataSet); text1.setText(account.mName); text1.setVisibility(account.mName == null ? View.GONE : View.VISIBLE); text2.setText(accountType.getDisplayLabel(mContext)); return convertView; }
/** * @param currentAccount the Account currently selected by the user, which should come * first in the list. Can be null. */ public AccountsListAdapter(Context context, AccountListFilter accountListFilter, AccountWithDataSet currentAccount) { mContext = context; mAccountTypes = AccountTypeManager.getInstance(context); mAccounts = getAccounts(accountListFilter); if (currentAccount != null && !mAccounts.isEmpty() && !mAccounts.get(0).equals(currentAccount) && mAccounts.remove(currentAccount)) { mAccounts.add(0, currentAccount); } mInflater = LayoutInflater.from(context); }
DialogInterface.OnClickListener onClickListener, DialogInterface.OnCancelListener onCancelListener) { final AccountTypeManager accountTypes = AccountTypeManager.getInstance(context); final List<AccountWithDataSet> writableAccountList = accountTypes.getAccounts(true);
@Override public View getView(int position, View convertView, ViewGroup parent) { final View resultView = convertView != null ? convertView : mInflater.inflate(mCustomLayout > 0 ? mCustomLayout : R.layout.account_selector_list_item, parent, false); final TextView text1 = (TextView) resultView.findViewById(android.R.id.text1); final TextView text2 = (TextView) resultView.findViewById(android.R.id.text2); final ImageView icon = (ImageView) resultView.findViewById(android.R.id.icon); final AccountWithDataSet account = mAccounts.get(position); final AccountType accountType = mAccountTypes.getAccountType(account.type, account.dataSet); text1.setText(accountType.getDisplayLabel(mContext)); // For email addresses, we don't want to truncate at end, which might cut off the domain // name. text2.setText(account.name); text2.setEllipsize(TruncateAt.MIDDLE); icon.setImageDrawable(accountType.getDisplayIcon(mContext)); return resultView; }