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);
}
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];
}
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);
}
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;
}
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;
}
Aggregations