android.accounts.OnAccountsUpdateListener Java Examples

The following examples show how to use android.accounts.OnAccountsUpdateListener. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AccountManagerHelper.java    From moVirt with Apache License 2.0 6 votes vote down vote up
/**
 * This method should be called only from Singletons so the lifecycle
 * is tied with the application, so we don't have to cleanup the listeners
 *
 * @param callback to be called on accounts updated
 */
public void addOnAccountsUpdatedListener(OnAccountsUpdatedListener callback) {
    try {
        OnAccountsUpdateListener listener = accounts -> {
            Set<MovirtAccount> filtered = new HashSet<>();
            for (Account account : accounts) {
                if (Constants.ACCOUNT_TYPE.equals(account.type)) {
                    try {
                        filtered.add(asMoAccount(account));
                    } catch (IllegalStateException incompatibleAccount) {
                        removeAccount(new MovirtAccount("", account), null); // remove old account
                    }
                }
            }
            callback.onAccountsUpdated(filtered);
        };

        accountManager.addOnAccountsUpdatedListener(listener, null, true);
    } catch (SecurityException e) {
        commonMessageHelper.showError(ErrorType.NORMAL, resources.getMissingAccountsPermissionError());
    }
}
 
Example #2
Source File: Listactivity.java    From ImapNote2 with GNU General Public License v3.0 4 votes vote down vote up
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

// Accounts spinner
this.accountSpinner = (Spinner) findViewById(R.id.accountSpinner);
Listactivity.currentList = new ArrayList<String>();
// Spinner item selection Listener
this.accountSpinner.setOnItemSelectedListener(this);

imapNotes2Account = new ImapNotes2Account();
Listactivity.accountManager = AccountManager.get(getApplicationContext());
Listactivity.accountManager.addOnAccountsUpdatedListener((OnAccountsUpdateListener)
    new AccountsUpdateListener(), null, true);

status = (TextView)findViewById(R.id.status);

this.spinnerList = new ArrayAdapter<String>
    (this, android.R.layout.simple_spinner_item,Listactivity.currentList);
spinnerList.setDropDownViewResource
    (android.R.layout.simple_spinner_dropdown_item);
this.accountSpinner.setAdapter(spinnerList);

this.noteList = new ArrayList<OneNote>();
((ImapNotes2)this.getApplicationContext()).SetNotesList(this.noteList);
this.listToView = new NotesListAdapter(
    getApplicationContext(),
    this.noteList,
    R.layout.note_element,
    new String[]{"title","date"},
    new int[]{R.id.noteTitle, R.id.noteInformation});
listview = (ListView) findViewById(R.id.notesList);
listview.setAdapter(this.listToView);

listview.setTextFilterEnabled(true);

this.imapFolder = new Imaper();
((ImapNotes2)this.getApplicationContext()).SetImaper(this.imapFolder);

if (Listactivity.storedNotes == null)
    storedNotes = new NotesDb(getApplicationContext());

// When item is clicked, we go to NoteDetailActivity
listview.setOnItemClickListener(new OnItemClickListener() {
    public void onItemClick(AdapterView<?> arg0, View widget, int selectedNote, long arg3) {
        Intent toDetail = new Intent(widget.getContext(), NoteDetailActivity.class);
        toDetail.putExtra("selectedNote", (OneNote)arg0.getItemAtPosition(selectedNote));
        toDetail.putExtra("useSticky", Listactivity.imapNotes2Account.GetUsesticky());
        startActivityForResult(toDetail,SEE_DETAIL); 
    }
  });

  editAccountButton = (Button) findViewById(R.id.editAccountButton);
  editAccountButton.setOnClickListener(clickListenerEditAccount);

}
 
Example #3
Source File: XAccountManager.java    From XPrivacy with GNU General Public License v3.0 4 votes vote down vote up
public XOnAccountsUpdateListener(OnAccountsUpdateListener listener, int uid) {
	mListener = listener;
	mUid = uid;
}