Search in sources :

Example 91 with Account

use of android.accounts.Account in project android-volley by mcxiaoke.

the class AndroidAuthenticatorTest method setUp.

@Before
public void setUp() {
    mAccountManager = mock(AccountManager.class);
    mFuture = mock(AccountManagerFuture.class);
    mAccount = new Account("coolperson", "cooltype");
    mAuthenticator = new AndroidAuthenticator(mAccountManager, mAccount, "cooltype", false);
}
Also used : Account(android.accounts.Account) AccountManager(android.accounts.AccountManager) AccountManagerFuture(android.accounts.AccountManagerFuture) Before(org.junit.Before)

Example 92 with Account

use of android.accounts.Account in project Signal-Android by WhisperSystems.

the class DirectoryHelper method createAccount.

private static Optional<AccountHolder> createAccount(Context context) {
    AccountManager accountManager = AccountManager.get(context);
    Account account = new Account(context.getString(R.string.app_name), "org.thoughtcrime.securesms");
    if (accountManager.addAccountExplicitly(account, null, null)) {
        Log.w(TAG, "Created new account...");
        ContentResolver.setIsSyncable(account, ContactsContract.AUTHORITY, 1);
        return Optional.of(new AccountHolder(account, true));
    } else {
        Log.w(TAG, "Failed to create account!");
        return Optional.absent();
    }
}
Also used : Account(android.accounts.Account) SignalServiceAccountManager(org.whispersystems.signalservice.api.SignalServiceAccountManager) AccountManager(android.accounts.AccountManager)

Example 93 with Account

use of android.accounts.Account in project FastDev4Android by jiangqqlmj.

the class AndroidAuthenticatorTest method setUp.

@Before
public void setUp() {
    mAccountManager = mock(AccountManager.class);
    mFuture = mock(AccountManagerFuture.class);
    mAccount = new Account("coolperson", "cooltype");
    mAuthenticator = new AndroidAuthenticator(mAccountManager, mAccount, "cooltype", false);
}
Also used : Account(android.accounts.Account) AccountManager(android.accounts.AccountManager) AccountManagerFuture(android.accounts.AccountManagerFuture) Before(org.junit.Before)

Example 94 with Account

use of android.accounts.Account in project PushSms by koush.

the class MyActivity method onCreate.

/**
     * Called when the activity is first created.
     */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    accounts = getSharedPreferences("accounts", MODE_PRIVATE);
    settings = getSharedPreferences("settings", MODE_PRIVATE);
    ListView lv = (ListView) findViewById(R.id.list);
    View header = getLayoutInflater().inflate(R.layout.header, null);
    lv.addHeaderView(header);
    lv.setAdapter(accountAdapter = new AccountAdapter());
    final Switch toggle = (Switch) header.findViewById(R.id.toggle);
    toggle.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            settings.edit().putBoolean("enabled", toggle.isChecked()).commit();
        }
    });
    toggle.setChecked(settings.getBoolean("enabled", true));
    final Button phoneNumber = (Button) header.findViewById(R.id.phone_number);
    phoneNumber.setText(getNumber());
    phoneNumber.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            final EditText input = new EditText(MyActivity.this);
            new AlertDialog.Builder(MyActivity.this).setTitle(R.string.phone_number).setView(input).setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int whichButton) {
                    settings.edit().putString("phone_number", input.getText().toString()).commit();
                    phoneNumber.setText(getNumber());
                }
            }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int whichButton) {
                // Do nothing.
                }
            }).show();
        }
    });
    for (Account account : AccountManager.get(this).getAccountsByType("com.google")) {
        accountAdapter.add(account);
    }
    lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            CheckedTextView tv = (CheckedTextView) view.findViewById(android.R.id.text1);
            Account account = accountAdapter.getItem((int) id);
            if (tv.isChecked()) {
                accounts.edit().putBoolean(account.name, false).commit();
                tv.toggle();
                reregister();
                return;
            }
            login(account.name);
        }
    });
    startService(new Intent(this, MiddlewareService.class));
    Button button = (Button) findViewById(R.id.button);
    button.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            new Thread() {

                @Override
                public void run() {
                    try {
                        GoogleCloudMessaging.getInstance(MyActivity.this).unregister();
                    } catch (Exception e) {
                    }
                }
            }.start();
        }
    });
}
Also used : EditText(android.widget.EditText) Account(android.accounts.Account) DialogInterface(android.content.DialogInterface) CheckedTextView(android.widget.CheckedTextView) Intent(android.content.Intent) View(android.view.View) AdapterView(android.widget.AdapterView) CheckedTextView(android.widget.CheckedTextView) ListView(android.widget.ListView) GoogleAuthException(com.google.android.gms.auth.GoogleAuthException) UserRecoverableAuthException(com.google.android.gms.auth.UserRecoverableAuthException) GooglePlayServicesAvailabilityException(com.google.android.gms.auth.GooglePlayServicesAvailabilityException) IOException(java.io.IOException) ListView(android.widget.ListView) Switch(android.widget.Switch) Button(android.widget.Button) AdapterView(android.widget.AdapterView)

Example 95 with Account

use of android.accounts.Account in project SeriesGuide by UweTrottmann.

the class TraktCredentials method getAccessToken.

/**
     * Get the access token. Avoid keeping this in memory, maybe calling {@link #hasCredentials()}
     * is sufficient.
     */
public String getAccessToken() {
    Account account = AccountUtils.getAccount(mContext);
    if (account == null) {
        return null;
    }
    AccountManager manager = AccountManager.get(mContext);
    return manager.getPassword(account);
}
Also used : Account(android.accounts.Account) AccountManager(android.accounts.AccountManager)

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