use of com.owncloud.android.lib.common.OwnCloudAccount in project android by owncloud.
the class ReceiveExternalFilesActivity method onCreateDialog.
@Override
protected Dialog onCreateDialog(final int id) {
final AlertDialog.Builder builder = new Builder(this);
switch(id) {
case DIALOG_NO_ACCOUNT:
builder.setIcon(R.drawable.ic_warning);
builder.setTitle(R.string.uploader_wrn_no_account_title);
builder.setMessage(String.format(getString(R.string.uploader_wrn_no_account_text), getString(R.string.app_name)));
builder.setCancelable(false);
builder.setPositiveButton(R.string.uploader_wrn_no_account_setup_btn_text, new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.ECLAIR_MR1) {
// using string value since in API7 this
// constatn is not defined
// in API7 < this constatant is defined in
// Settings.ADD_ACCOUNT_SETTINGS
// and Settings.EXTRA_AUTHORITIES
Intent intent = new Intent(android.provider.Settings.ACTION_ADD_ACCOUNT);
intent.putExtra("authorities", new String[] { MainApp.getAuthTokenType() });
startActivityForResult(intent, REQUEST_CODE__SETUP_ACCOUNT);
} else {
// since in API7 there is no direct call for
// account setup, so we need to
// show our own AccountSetupAcricity, get
// desired results and setup
// everything for ourself
Intent intent = new Intent(getBaseContext(), AccountAuthenticator.class);
startActivityForResult(intent, REQUEST_CODE__SETUP_ACCOUNT);
}
}
});
builder.setNegativeButton(R.string.uploader_wrn_no_account_quit_btn_text, new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
finish();
}
});
return builder.create();
case DIALOG_MULTIPLE_ACCOUNT:
Account[] accounts = mAccountManager.getAccountsByType(MainApp.getAccountType());
CharSequence[] dialogItems = new CharSequence[accounts.length];
OwnCloudAccount oca;
for (int i = 0; i < dialogItems.length; ++i) {
try {
oca = new OwnCloudAccount(accounts[i], this);
dialogItems[i] = oca.getDisplayName() + " @ " + DisplayUtils.convertIdn(accounts[i].name.substring(accounts[i].name.lastIndexOf("@") + 1), false);
} catch (Exception e) {
Log_OC.w(TAG, "Couldn't read display name of account; using account name instead");
dialogItems[i] = DisplayUtils.convertIdn(accounts[i].name, false);
}
}
builder.setTitle(R.string.common_choose_account);
builder.setItems(dialogItems, new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
setAccount(mAccountManager.getAccountsByType(MainApp.getAccountType())[which]);
onAccountSet(mAccountWasRestored);
dialog.dismiss();
mAccountSelected = true;
mAccountSelectionShowing = false;
}
});
builder.setCancelable(true);
builder.setOnCancelListener(new OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
mAccountSelectionShowing = false;
dialog.cancel();
finish();
}
});
return builder.create();
default:
throw new IllegalArgumentException("Unknown dialog id: " + id);
}
}
Aggregations