+ public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
+ if (mShowContextMenu) {
+ getMenuInflater().inflate(R.menu.account_picker_long_click, menu);
+ mShowContextMenu = false;
+ }
+ super.onCreateContextMenu(menu, v, menuInfo);
+ }
+
+ /**
+ * Called when the user clicked on an item into the context menu created at
+ * {@link #onCreateContextMenu(ContextMenu, View, ContextMenuInfo)} for
+ * every ownCloud {@link Account} , containing 'secondary actions' for them.
+ *
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean onContextItemSelected(android.view.MenuItem item) {
+ AccountManager am = (AccountManager) getSystemService(ACCOUNT_SERVICE);
+ Account accounts[] = am.getAccountsByType(MainApp.getAccountType());
+ for (Account a : accounts) {
+ if (a.name.equals(mAccountName)) {
+ if (item.getItemId() == R.id.change_password) {
+ Intent updateAccountCredentials = new Intent(this, AuthenticatorActivity.class);
+ updateAccountCredentials.putExtra(AuthenticatorActivity.EXTRA_ACCOUNT, a);
+ updateAccountCredentials.putExtra(AuthenticatorActivity.EXTRA_ACTION,
+ AuthenticatorActivity.ACTION_UPDATE_TOKEN);
+ startActivity(updateAccountCredentials);
+
+ } else if (item.getItemId() == R.id.delete_account) {
+ am.removeAccount(a, this, mHandler);
+ }
+ }
+ }
+
+ return true;
+ }
+
+ @Override
+ public void run(AccountManagerFuture<Boolean> future) {
+ if (future.isDone()) {
+ Account a = AccountUtils.getCurrentOwnCloudAccount(this);
+ String accountName = "";
+ if (a == null) {
+ Account[] accounts = AccountManager.get(this).getAccountsByType(MainApp.getAccountType());
+ if (accounts.length != 0)
+ accountName = accounts[0].name;
+ AccountUtils.setCurrentOwnCloudAccount(this, accountName);
+ }
+ createAccountsCheckboxPreferences();
+ }
+ }
+
+ @Override