Search in sources :

Example 11 with OwnCloudAccount

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);
    }
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) Account(android.accounts.Account) OwnCloudAccount(com.owncloud.android.lib.common.OwnCloudAccount) DialogInterface(android.content.DialogInterface) Builder(android.support.v7.app.AlertDialog.Builder) Builder(android.support.v7.app.AlertDialog.Builder) Intent(android.content.Intent) AccountAuthenticator(com.owncloud.android.authentication.AccountAuthenticator) OwnCloudAccount(com.owncloud.android.lib.common.OwnCloudAccount) SuppressLint(android.annotation.SuppressLint) NotFoundException(android.content.res.Resources.NotFoundException) AuthenticatorException(android.accounts.AuthenticatorException) OnClickListener(android.content.DialogInterface.OnClickListener) OnCancelListener(android.content.DialogInterface.OnCancelListener)

Aggregations

OwnCloudAccount (com.owncloud.android.lib.common.OwnCloudAccount)11 Account (android.accounts.Account)4 FileDataStorageManager (com.owncloud.android.datamodel.FileDataStorageManager)4 RemoteOperationResult (com.owncloud.android.lib.common.operations.RemoteOperationResult)4 Intent (android.content.Intent)3 TextView (android.widget.TextView)3 LayoutInflater (android.view.LayoutInflater)2 View (android.view.View)2 ImageView (android.widget.ImageView)2 OCFile (com.owncloud.android.datamodel.OCFile)2 OwnCloudClient (com.owncloud.android.lib.common.OwnCloudClient)2 AccountManager (android.accounts.AccountManager)1 AccountsException (android.accounts.AccountsException)1 AuthenticatorException (android.accounts.AuthenticatorException)1 SuppressLint (android.annotation.SuppressLint)1 DialogInterface (android.content.DialogInterface)1 OnCancelListener (android.content.DialogInterface.OnCancelListener)1 OnClickListener (android.content.DialogInterface.OnClickListener)1 NotFoundException (android.content.res.Resources.NotFoundException)1 Bitmap (android.graphics.Bitmap)1