Example usage for android.accounts AccountManager get

List of usage examples for android.accounts AccountManager get

Introduction

In this page you can find the example usage for android.accounts AccountManager get.

Prototype

public static AccountManager get(Context context) 

Source Link

Document

Gets an AccountManager instance associated with a Context.

Usage

From source file:com.nextgis.maplibui.SelectNGWResourceDialog.java

protected Connections fillConnections() {
    Connections connections = new Connections(getString(R.string.accounts));
    final AccountManager accountManager = AccountManager.get(getActivity());
    for (Account account : accountManager.getAccountsByType(NGW_ACCOUNT_TYPE)) {
        String url = accountManager.getUserData(account, "url");
        String password = accountManager.getPassword(account);
        String login = accountManager.getUserData(account, "login");
        connections.add(new Connection(account.name, login, password, url));
    }//from   ww w. j ava  2 s .  co  m
    return connections;
}

From source file:com.lambdasoup.watchlater.test.AddActivityTest.java

@Before
public void setUp() throws Exception {

    // inject retrofit http executor for espresso idling resource
    Field httpExecutor = AddActivity.class.getDeclaredField("OPTIONAL_RETROFIT_HTTP_EXECUTOR");
    httpExecutor.setAccessible(true);/*from   w w  w  .  ja  v a 2  s .co m*/
    idlingExecutor = new RetrofitHttpExecutorIdlingResource();
    httpExecutor.set(AddActivity.class, idlingExecutor);
    registerIdlingResources(idlingExecutor);

    // inject test account type
    Field accountType = AddActivity.class.getDeclaredField("ACCOUNT_TYPE_GOOGLE");
    accountType.setAccessible(true);
    accountType.set(AddActivity.class, TEST_ACCOUNT_TYPE);

    // clear accounts
    AccountManager accountManager = AccountManager
            .get(InstrumentationRegistry.getInstrumentation().getContext());
    //noinspection ResourceType,deprecation
    accountManager.removeAccount(ACCOUNT_1, null, null).getResult();
    //noinspection ResourceType,deprecation
    accountManager.removeAccount(ACCOUNT_2, null, null).getResult();

    // inject mock backend
    Field endpoint = AddActivity.class.getDeclaredField("YOUTUBE_ENDPOINT");
    endpoint.setAccessible(true);
    endpoint.set(AddActivity.class, mockWebServer.url("/").toString());
}

From source file:com.honestme.animetasteex.login.LoginFragment.java

@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
    switch (checkedId) {
    case R.id.rb_login:
        mLoginButton.setText(R.string.login_login);
        mPhoneAutoComplete.setVisibility(View.GONE);
        break;//from  w  w w .java2 s .  co m
    case R.id.rb_create:
        mLoginButton.setText(R.string.login_register);
        mPhoneAutoComplete.setVisibility(View.VISIBLE);

        if (mPhoneAutoComplete.getAdapter() == null) {
            final Set<String> phoneSet = new HashSet<>();
            for (Account account : AccountManager.get(getActivity()).getAccounts()) {
                if (Patterns.EMAIL_ADDRESS.matcher(account.name).matches()) {
                    phoneSet.add(account.name);
                }
            }
            List<String> emails = new ArrayList<>(phoneSet);
            mPhoneAutoComplete.setAdapter(
                    new ArrayAdapter<>(getActivity(), android.R.layout.simple_spinner_dropdown_item, emails));
        }
        break;
    }

}

From source file:ru.orangesoftware.financisto.activity.FlowzrSyncActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    FlowzrSyncActivity.me = this;

    mNotifyBuilder = new NotificationCompat.Builder(getApplicationContext());
    nm = (NotificationManager) getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
    setContentView(R.layout.flowzr_sync);
    restoreUIFromPref();//  ww w . j a  v a  2s  .  c om

    AccountManager accountManager = AccountManager.get(getApplicationContext());
    final Account[] accounts = accountManager.getAccountsByType("com.google");
    if (accounts.length < 1) {
        new AlertDialog.Builder(this).setTitle(getString(R.string.flowzr_sync_error))
                .setMessage(R.string.account_required)
                .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                        finish();
                    }
                }).show();
    }
    //checkbox
    CheckBox chk = (CheckBox) findViewById(R.id.chk_sync_from_zero);
    OnClickListener chk_listener = new OnClickListener() {
        public void onClick(View v) {
            lastSyncLocalTimestamp = 0;
            renderLastTime(0);
            flowzrSyncEngine.resetLastTime(getApplicationContext());
        }
    };
    chk.setOnClickListener(chk_listener);
    //radio crendentials
    RadioGroup radioGroupCredentials = (RadioGroup) findViewById(R.id.radioCredentials);
    OnClickListener radio_listener = new OnClickListener() {
        public void onClick(View v) {
            RadioButton radioButtonSelected = (RadioButton) findViewById(v.getId());
            for (Account account : accounts) {
                if (account.name == radioButtonSelected.getText()) {
                    lastSyncLocalTimestamp = 0;
                    renderLastTime(0);
                    flowzrSyncEngine.resetLastTime(getApplicationContext());
                    useCredential = account;
                }
            }
        }
    };
    radioGroupCredentials.setOnClickListener(radio_listener);
    //initialize value
    for (int i = 0; i < accounts.length; i++) {
        RadioButton rb = new RadioButton(this);
        radioGroupCredentials.addView(rb); //, 0, lp); 
        rb.setOnClickListener(radio_listener);
        rb.setText(((Account) accounts[i]).name);
        String prefAccount = MyPreferences.getFlowzrAccount(this);
        if (prefAccount != null) {
            if (accounts[i].name.equals(prefAccount)) {
                useCredential = accounts[i];
                rb.toggle(); //.setChecked(true);
            }
        }
    }

    bOk = (Button) findViewById(R.id.bOK);
    bOk.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            startSync();

        }
    });

    Button bCancel = (Button) findViewById(R.id.bCancel);
    bCancel.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            if (flowzrSyncEngine != null) {
                flowzrSyncEngine.isCanceled = true;
            }
            isRunning = false;
            setResult(RESULT_CANCELED);
            setReady();
            startActivity(new Intent(getApplicationContext(), MainActivity.class));
            //finish();
        }
    });

    Button textViewAbout = (Button) findViewById(R.id.buySubscription);
    textViewAbout.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            if (isOnline(FlowzrSyncActivity.this)) {
                visitFlowzr(useCredential);
            } else {
                showErrorPopup(FlowzrSyncActivity.this, R.string.flowzr_sync_error_no_network);
            }
        }
    });

    Button textViewAboutAnon = (Button) findViewById(R.id.visitFlowzr);
    textViewAboutAnon.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            if (isOnline(FlowzrSyncActivity.this)) {
                visitFlowzr(null);
            } else {
                showErrorPopup(FlowzrSyncActivity.this, R.string.flowzr_sync_error_no_network);
            }
        }
    });

    TextView textViewNotes = (TextView) findViewById(R.id.flowzrPleaseNote);
    textViewNotes.setMovementMethod(LinkMovementMethod.getInstance());
    textViewNotes.setText(Html.fromHtml(getString(R.string.flowzr_terms_of_use)));
    if (MyPreferences.isAutoSync(this)) {
        if (checkPlayServices()) {
            gcm = GoogleCloudMessaging.getInstance(this);
            regid = getRegistrationId(getApplicationContext());

            if (regid.equals("")) {
                registerInBackground();
            }
            Log.i(TAG, "Google Cloud Messaging registered as :" + regid);
        } else {
            Log.i(TAG, "No valid Google Play Services APK found.");
        }
    }
}

From source file:com.android.browser.GoogleAccountLogin.java

private void invalidateTokens() {
    AccountManager am = AccountManager.get(mActivity);
    am.invalidateAuthToken(GOOGLE, mSid);
    am.invalidateAuthToken(GOOGLE, mLsid);
    mTokensInvalidated = true;//from w  w w.j av a 2  s  .  c  o m
    mState = 1; // SID
    am.getAuthToken(mAccount, "SID", null, mActivity, this, null);
}

From source file:net.vleu.par.android.rpc.Transceiver.java

/**
 * Lists all Google accounts on this device
 * /*  w w w  . ja  v  a2s.c  om*/
 * @param context
 *            Won't be kept anywhere
 * @return A possibly empty array of Google Accounts
 */
public static Account[] listGoogleAccounts(final Context context) {
    final AccountManager am = AccountManager.get(context);
    return am.getAccountsByType(GOOGLE_ACCOUNT_TYPE);
}

From source file:com.nextgis.mobile.fragment.LayersFragment.java

protected void setupSyncOptions() {
    mAccounts.clear();/*from   w w  w .j a va  2 s . c  om*/
    final AccountManager accountManager = AccountManager.get(getActivity().getApplicationContext());
    Log.d(TAG, "LayersFragment: AccountManager.get(" + getActivity().getApplicationContext() + ")");
    final IGISApplication application = (IGISApplication) getActivity().getApplication();
    List<INGWLayer> layers = new ArrayList<>();

    for (Account account : accountManager.getAccountsByType(NGW_ACCOUNT_TYPE)) {
        layers.clear();
        MapContentProviderHelper.getLayersByAccount(application.getMap(), account.name, layers);

        if (layers.size() > 0)
            mAccounts.add(account);
    }

    if (mAccounts.isEmpty()) {
        if (null != mSyncButton) {
            mSyncButton.setEnabled(false);
            mSyncButton.setVisibility(View.GONE);
        }
        if (null != mInfoText) {
            mInfoText.setVisibility(View.INVISIBLE);
        }
    } else {
        if (null != mSyncButton) {
            mSyncButton.setVisibility(View.VISIBLE);
            mSyncButton.setEnabled(true);
            mSyncButton.setOnClickListener(this);
        }
        if (null != mInfoText) {
            mInfoText.setVisibility(View.VISIBLE);
        }
    }
}

From source file:de.unclenet.dehabewe.CalendarActivity.java

@Override
protected Dialog onCreateDialog(int id) {
    switch (id) {
    case DIALOG_ACCOUNTS:
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("Select a Google account");
        final AccountManager manager = AccountManager.get(this);
        final Account[] accounts = manager.getAccountsByType("com.google");
        final int size = accounts.length;
        String[] names = new String[size];
        for (int i = 0; i < size; i++) {
            names[i] = accounts[i].name;
        }/*w  ww . ja v a  2s  .co m*/
        builder.setItems(names, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                gotAccount(manager, accounts[which]);
            }
        });
        return builder.create();
    }
    return null;
}

From source file:com.owncloud.android.ui.fragment.FileDetailActivitiesFragment.java

@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    file = getArguments().getParcelable(ARG_FILE);
    account = getArguments().getParcelable(ARG_ACCOUNT);

    if (savedInstanceState != null) {
        file = savedInstanceState.getParcelable(FileActivity.EXTRA_FILE);
        account = savedInstanceState.getParcelable(FileActivity.EXTRA_ACCOUNT);
    }//  w  w  w.  j  ava2 s . c o  m

    View view = inflater.inflate(R.layout.file_details_activities_fragment, container, false);
    unbinder = ButterKnife.bind(this, view);

    setupView();

    onCreateSwipeToRefresh(swipeEmptyListRefreshLayout);
    onCreateSwipeToRefresh(swipeListRefreshLayout);

    fetchAndSetData(null);

    swipeListRefreshLayout.setOnRefreshListener(() -> onRefreshListLayout(swipeListRefreshLayout));
    swipeEmptyListRefreshLayout.setOnRefreshListener(() -> onRefreshListLayout(swipeEmptyListRefreshLayout));

    AccountManager accountManager = AccountManager.get(getContext());
    userId = accountManager.getUserData(account,
            com.owncloud.android.lib.common.accounts.AccountUtils.Constants.KEY_USER_ID);

    callback = new VersionListInterface.CommentCallback() {

        @Override
        public void onSuccess() {
            commentInput.getText().clear();
            fetchAndSetData(null);
        }

        @Override
        public void onError(int error) {
            Snackbar.make(recyclerView, error, Snackbar.LENGTH_LONG).show();
        }
    };

    commentInput.getBackground().setColorFilter(ThemeUtils.primaryAccentColor(getContext()),
            PorterDuff.Mode.SRC_ATOP);

    return view;
}

From source file:app.philm.in.fragments.LoginFragment.java

@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
    switch (checkedId) {
    case R.id.rb_login:
        mLoginButton.setText(R.string.account_login);
        mEmailAutoComplete.setVisibility(View.GONE);
        break;/* w w  w  .  ja  v a 2s. c o  m*/
    case R.id.rb_create:
        mLoginButton.setText(R.string.account_register);
        mEmailAutoComplete.setVisibility(View.VISIBLE);

        if (mEmailAutoComplete.getAdapter() == null) {
            final Set<String> emailSet = new HashSet<>();
            for (Account account : AccountManager.get(getActivity()).getAccounts()) {
                if (Patterns.EMAIL_ADDRESS.matcher(account.name).matches()) {
                    emailSet.add(account.name);
                }
            }
            List<String> emails = new ArrayList<>(emailSet);
            mEmailAutoComplete.setAdapter(
                    new ArrayAdapter<>(getActivity(), android.R.layout.simple_spinner_dropdown_item, emails));
        }
        break;
    }
}