Search in sources :

Example 46 with Account

use of android.accounts.Account in project PocketHub by pockethub.

the class UserComparatorTest method testNoLoginMatch.

/**
     * Test sorting of users that don't match login
     */
public void testNoLoginMatch() {
    Account account = new Account("m", "t");
    UserComparator comparator = new UserComparator(account);
    assertTrue(comparator.compare(createUser("a"), createUser("c")) < 0);
    assertTrue(comparator.compare(createUser("db"), createUser("da")) > 0);
}
Also used : Account(android.accounts.Account) UserComparator(com.github.pockethub.android.core.user.UserComparator)

Example 47 with Account

use of android.accounts.Account in project PocketHub by pockethub.

the class PocketHubModule method account.

@Provides
Account account(Context context) {
    AccountManager accountManager = (AccountManager) context.getSystemService(Context.ACCOUNT_SERVICE);
    Account[] accounts = accountManager.getAccountsByType(context.getString(R.string.account_type));
    return accounts[0];
}
Also used : Account(android.accounts.Account) AccountManager(android.accounts.AccountManager) Provides(com.google.inject.Provides)

Example 48 with Account

use of android.accounts.Account in project platform_frameworks_base by android.

the class ContentResolver method startSync.

/**
     * Start an asynchronous sync operation. If you want to monitor the progress
     * of the sync you may register a SyncObserver. Only values of the following
     * types may be used in the extras bundle:
     * <ul>
     * <li>Integer</li>
     * <li>Long</li>
     * <li>Boolean</li>
     * <li>Float</li>
     * <li>Double</li>
     * <li>String</li>
     * <li>Account</li>
     * <li>null</li>
     * </ul>
     *
     * @param uri the uri of the provider to sync or null to sync all providers.
     * @param extras any extras to pass to the SyncAdapter.
     * @deprecated instead use
     * {@link #requestSync(android.accounts.Account, String, android.os.Bundle)}
     */
@Deprecated
public void startSync(Uri uri, Bundle extras) {
    Account account = null;
    if (extras != null) {
        String accountName = extras.getString(SYNC_EXTRAS_ACCOUNT);
        if (!TextUtils.isEmpty(accountName)) {
            // TODO: No references to Google in AOSP
            account = new Account(accountName, "com.google");
        }
        extras.remove(SYNC_EXTRAS_ACCOUNT);
    }
    requestSync(account, uri != null ? uri.getAuthority() : null, extras);
}
Also used : Account(android.accounts.Account)

Example 49 with Account

use of android.accounts.Account in project platform_frameworks_base by android.

the class ConfirmUserCreationActivity method checkUserCreationRequirements.

private String checkUserCreationRequirements() {
    final String callingPackage = getCallingPackage();
    if (callingPackage == null) {
        throw new SecurityException("User Creation intent must be launched with startActivityForResult");
    }
    final ApplicationInfo appInfo;
    try {
        appInfo = getPackageManager().getApplicationInfo(callingPackage, 0);
    } catch (NameNotFoundException nnfe) {
        throw new SecurityException("Cannot find the calling package");
    }
    final String message;
    // Check the user restrictions
    boolean cantCreateUser = mUserManager.hasUserRestriction(UserManager.DISALLOW_ADD_USER) || !mUserManager.isAdminUser();
    // Check the system state and user count
    boolean cantCreateAnyMoreUsers = !mUserManager.canAddMoreUsers();
    // Check the account existence
    final Account account = new Account(mAccountName, mAccountType);
    boolean accountExists = mAccountName != null && mAccountType != null && (AccountManager.get(this).someUserHasAccount(account) | mUserManager.someUserHasSeedAccount(mAccountName, mAccountType));
    mCanProceed = true;
    final String appName = appInfo.loadLabel(getPackageManager()).toString();
    if (cantCreateUser) {
        setResult(UserManager.USER_CREATION_FAILED_NOT_PERMITTED);
        return null;
    } else if (cantCreateAnyMoreUsers) {
        setResult(UserManager.USER_CREATION_FAILED_NO_MORE_USERS);
        return null;
    } else if (accountExists) {
        message = getString(R.string.user_creation_account_exists, appName, mAccountName);
    } else {
        message = getString(R.string.user_creation_adding, appName, mAccountName);
    }
    return message;
}
Also used : Account(android.accounts.Account) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) ApplicationInfo(android.content.pm.ApplicationInfo)

Example 50 with Account

use of android.accounts.Account in project JamsMusicPlayer by psaravan.

the class GooglePlayMusicFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    mContext = getActivity().getApplicationContext();
    mApp = (Common) mContext;
    View rootView = (View) inflater.inflate(R.layout.fragment_welcome_screen_5, null);
    welcomeHeader = (TextView) rootView.findViewById(R.id.welcome_header);
    welcomeHeader.setTypeface(TypefaceHelper.getTypeface(getActivity(), "Roboto-Light"));
    welcomeText1 = (TextView) rootView.findViewById(R.id.welcome_text_1);
    welcomeText1.setTypeface(TypefaceHelper.getTypeface(getActivity(), "Roboto-Regular"));
    googlePlayMusicDisclaimer = (TextView) rootView.findViewById(R.id.google_play_music_disclaimer);
    googlePlayMusicDisclaimer.setTypeface(TypefaceHelper.getTypeface(getActivity(), "Roboto-Regular"));
    radioGroup = (RadioGroup) rootView.findViewById(R.id.google_play_music_radio_group);
    final AccountManager accountManager = AccountManager.get(getActivity().getApplicationContext());
    final Account[] accounts = accountManager.getAccountsByType("com.google");
    //We're adding 1 here to account (no pun intended) for the extra "Don't use Google Play Music" option.
    final int size = accounts.length + 1;
    final RadioButton[] radioButton = new RadioButton[size];
    //Add a new radio button the group for each username.
    for (int i = 0; i < size; i++) {
        radioButton[i] = new RadioButton(getActivity());
        radioGroup.addView(radioButton[i]);
        //The first radio button will always be "Don't use Google Play Music".
        if (i == 0) {
            radioButton[i].setChecked(true);
            radioButton[i].setText(R.string.dont_use_google_play_music);
        } else {
            radioButton[i].setText(accounts[i - 1].name);
        }
        radioButton[i].setTag(i);
        radioButton[i].setTypeface(TypefaceHelper.getTypeface(mContext, "Roboto-Regular"));
    }
    radioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            int radioButtonID = group.getCheckedRadioButtonId();
            View radioButton = group.findViewById(radioButtonID);
            int index = group.indexOfChild(radioButton);
            if (index != 0) {
                account = accounts[index - 1];
                mApp.getSharedPreferences().edit().putString("GOOGLE_PLAY_MUSIC_ACCOUNT", account.name).commit();
                AsyncGoogleMusicAuthenticationTask task = new AsyncGoogleMusicAuthenticationTask(mContext, getActivity(), true, account.name);
                task.execute();
            } else {
                mApp.getSharedPreferences().edit().putString("GOOGLE_PLAY_MUSIC_ACCOUNT", "").commit();
                mApp.getSharedPreferences().edit().putBoolean("GOOGLE_PLAY_MUSIC_ENABLED", false).commit();
            }
        }
    });
    return rootView;
}
Also used : Account(android.accounts.Account) OnCheckedChangeListener(android.widget.RadioGroup.OnCheckedChangeListener) RadioGroup(android.widget.RadioGroup) AsyncGoogleMusicAuthenticationTask(com.jams.music.player.AsyncTasks.AsyncGoogleMusicAuthenticationTask) AccountManager(android.accounts.AccountManager) RadioButton(android.widget.RadioButton) TextView(android.widget.TextView) View(android.view.View) Paint(android.graphics.Paint)

Aggregations

Account (android.accounts.Account)550 Bundle (android.os.Bundle)108 AccountManager (android.accounts.AccountManager)79 Test (org.junit.Test)53 ArrayList (java.util.ArrayList)49 Intent (android.content.Intent)40 File (java.io.File)37 Cursor (android.database.Cursor)31 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)29 PersistableBundle (android.os.PersistableBundle)27 UserInfo (android.content.pm.UserInfo)22 MockContentResolver (android.test.mock.MockContentResolver)22 HashMap (java.util.HashMap)20 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)20 RemoteException (android.os.RemoteException)19 FileOutputStream (java.io.FileOutputStream)19 IOException (java.io.IOException)19 SmallTest (android.test.suitebuilder.annotation.SmallTest)18 HashSet (java.util.HashSet)16 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)16