Java Code Examples for com.android.contacts.model.AccountTypeManager

Following code examples demonstrate how to use com.android.contacts.model.AccountTypeManagerfrom android. These examples are extracted from various highly rated open source projects. You can directly use these code snippets or view their entire linked source code. These snippets are extracted to provide contextual information about how to use this class in the real world. These samples also let you understand some good practices on how to use com.android.contacts.model.AccountTypeManagerand various code implementation of this class.

    }

    public static void bindGroupSourceView(Context context, View view, String accountTypeString,
            String dataSet) {
        AccountTypeManager accountTypeManager = AccountTypeManager.getInstance(context);
        AccountType accountType = accountTypeManager.getAccountType(accountTypeString, dataSet);

        TextView label = (TextView) view.findViewById(android.R.id.title);
        if (label == null) {
            throw new IllegalStateException("Group source view must contain a TextView with id"
                    + "android.R.id.label");
        }
        label.setText(accountType.getViewGroupLabel(context));

        ImageView accountIcon = (ImageView) view.findViewById(android.R.id.icon);
        if (accountIcon == null) {
            throw new IllegalStateException("Group source view must contain an ImageView with id"
                    + "android.R.id.icon");
        }
        accountIcon.setImageDrawable(accountType.getDisplayIcon(context));
    } 


    }

    public static void show(FragmentManager fragmentManager, int titleResourceId,
            AccountTypeManager.AccountFilter filter, Bundle extraArgs, String tag) {
        final Bundle args = new Bundle();
        args.putInt(KEY_TITLE_RES_ID, titleResourceId);
        args.putBundle(KEY_EXTRA_ARGS, (extraArgs == null) ? Bundle.EMPTY : extraArgs);
        args.putSerializable(KEY_LIST_FILTER, filter);

        final SelectAccountDialogFragment instance = new SelectAccountDialogFragment();
        instance.setArguments(args);
        instance.show(fragmentManager, tag);
    } 

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        final Bundle args = getArguments();
        mFilter = (AccountTypeManager.AccountFilter) args.getSerializable(KEY_LIST_FILTER);
        if (mFilter == null) {
            mFilter = AccountTypeManager.AccountFilter.ALL;
        }
    } 

    
    public static void show(FragmentManager fragmentManager, int titleResourceId,
            AccountTypeManager.AccountFilter filter, Bundle extraArgs) {
        show(fragmentManager, titleResourceId, filter, extraArgs,  null);
    } 

        protected Void doInBackground(Void... params) {
            final Context context = ContactsApplication.this;

            PreferenceManager.getDefaultSharedPreferences(context);
            AccountTypeManager.getInstance(context);
            getContentResolver().getType(ContentUris.withAppendedId(Contacts.CONTENT_URI, 1));
            return null;
        } 

    public Object getSystemService(String name) {
        if (sInjectedServices != null) {
            Object service = sInjectedServices.getSystemService(name);
            if (service != null) {
                return service;
            }
        }

        if (AccountTypeManager.ACCOUNT_TYPE_SERVICE.equals(name)) {
            if (mAccountTypeManager == null) {
                mAccountTypeManager = AccountTypeManager.createAccountTypeManager(this);
            }
            return mAccountTypeManager;
        }

        if (ContactPhotoManager.CONTACT_PHOTO_SERVICE.equals(name)) {
            if (mContactPhotoManager == null) {
                mContactPhotoManager = ContactPhotoManager.createContactPhotoManager(this);
                registerComponentCallbacks(mContactPhotoManager);
                mContactPhotoManager.preloadPhotosInBackground();
            }
            return mContactPhotoManager;
        }

        if (ContactListFilterController.CONTACT_LIST_FILTER_SERVICE.equals(name)) {
            if (mContactListFilterController == null) {
                mContactListFilterController =
                        ContactListFilterController.createContactListFilterController(this);
            }
            return mContactListFilterController;
        }

        if (T9SearchCache.T9_CACHE_SERVICE.equals(name)) {
            if (mT9Cache == null) {
                mT9Cache = T9SearchCache.createT9Cache(this);
            }
            return mT9Cache;
        }

        return super.getSystemService(name);
    } 

    public static boolean handleImportFromSDCardRequest(Activity aContext, Fragment targetFragment) {
        List<AccountWithDataSet> lAccountList = AccountTypeManager.getInstance(aContext).getAccountsExcludeSim(true);
        int size = lAccountList.size();
        if (size > 1) {
            Bundle args = new Bundle();
            args.putInt("resourceId", R.string.import_from_sdcard);
            args.putBoolean("EXCLUDE_SIM", true);
            args.putInt("resId", R.string.import_from_sdcard);
            HAPSelectAccountDialogFragment.show(aContext.getFragmentManager(), targetFragment, R.string.Import_from_storage, AccountListFilter.ACCOUNTS_CONTACT_WRITABLE, args, null, "accounts_chooser_tag_mcu");
            return false;
        }
        AccountWithDataSet accountWithDataSet;
        if (size == 1) {
            accountWithDataSet = (AccountWithDataSet) lAccountList.get(0);
        } else {
            accountWithDataSet = null;
        }
        AccountSelectionUtil.doImport(aContext, R.string.import_from_sdcard, accountWithDataSet);
        return true;
    } 

Advertisement
Javadoc
Singleton holder for all parsed AccountType available on the system, typically filled through Packag

eManager queries.

Read More
Advertisement