Example usage for android.app AlertDialog findViewById

List of usage examples for android.app AlertDialog findViewById

Introduction

In this page you can find the example usage for android.app AlertDialog findViewById.

Prototype

@Nullable
public <T extends View> T findViewById(@IdRes int id) 

Source Link

Document

Finds the first descendant view with the given ID or null if the ID is invalid (< 0), there is no matching view in the hierarchy, or the dialog has not yet been fully created (for example, via #show() or #create() ).

Usage

From source file:systems.soapbox.ombuds.client.ui.WalletActivity.java

private void prepareRestoreWalletDialog(final Dialog dialog) {
    final AlertDialog alertDialog = (AlertDialog) dialog;

    final List<File> files = new LinkedList<File>();

    // external storage
    if (Constants.Files.EXTERNAL_WALLET_BACKUP_DIR.exists()
            && Constants.Files.EXTERNAL_WALLET_BACKUP_DIR.isDirectory())
        for (final File file : Constants.Files.EXTERNAL_WALLET_BACKUP_DIR.listFiles())
            if (Crypto.OPENSSL_FILE_FILTER.accept(file))
                files.add(file);/*from  ww w .j  a v a2 s.c  o  m*/

    // internal storage
    for (final String filename : fileList())
        if (filename.startsWith(Constants.Files.WALLET_KEY_BACKUP_PROTOBUF + '.'))
            files.add(new File(getFilesDir(), filename));

    // sort
    Collections.sort(files, new Comparator<File>() {
        @Override
        public int compare(final File lhs, final File rhs) {
            return lhs.getName().compareToIgnoreCase(rhs.getName());
        }
    });

    final View replaceWarningView = alertDialog
            .findViewById(R.id.restore_wallet_from_storage_dialog_replace_warning);
    final boolean hasCoins = wallet.getBalance(BalanceType.ESTIMATED).signum() > 0;
    replaceWarningView.setVisibility(hasCoins ? View.VISIBLE : View.GONE);

    final Spinner fileView = (Spinner) alertDialog.findViewById(R.id.import_keys_from_storage_file);
    final FileAdapter adapter = (FileAdapter) fileView.getAdapter();
    adapter.setFiles(files);
    fileView.setEnabled(!adapter.isEmpty());

    final EditText passwordView = (EditText) alertDialog.findViewById(R.id.import_keys_from_storage_password);
    passwordView.setText(null);

    final ImportDialogButtonEnablerListener dialogButtonEnabler = new ImportDialogButtonEnablerListener(
            passwordView, alertDialog) {
        @Override
        protected boolean hasFile() {
            return fileView.getSelectedItem() != null;
        }

        @Override
        protected boolean needsPassword() {
            final File selectedFile = (File) fileView.getSelectedItem();
            return selectedFile != null ? Crypto.OPENSSL_FILE_FILTER.accept(selectedFile) : false;
        }
    };
    passwordView.addTextChangedListener(dialogButtonEnabler);
    fileView.setOnItemSelectedListener(dialogButtonEnabler);

    final CheckBox showView = (CheckBox) alertDialog.findViewById(R.id.import_keys_from_storage_show);
    showView.setOnCheckedChangeListener(new ShowPasswordCheckListener(passwordView));
}

From source file:ca.mimic.apphangar.Settings.java

protected void launchThanks(int which) {
    String thankYouMsg = getResources().getString(R.string.donate_thanks);
    if (which == THANK_YOU_PAYPAL)
        thankYouMsg += "\n\n" + getResources().getString(R.string.donate_thanks_paypal);

    AlertDialog alert = new AlertDialog.Builder(Settings.this).setTitle(R.string.donate_thanks_title)
            .setIcon(R.drawable.ic_logo).setMessage(thankYouMsg)
            .setPositiveButton(R.string.donate_thanks_continue, null).show();

    TextView msgTxt = (TextView) alert.findViewById(android.R.id.message);
    msgTxt.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14);
}

From source file:com.android.launcher3.Utilities.java

public static void licenseAlertDialog(Context context) {
    AlertDialog builder = new AlertDialog.Builder(context, R.style.AlertDialogCustom)
            .setTitle(context.getResources().getString(R.string.app_name)).setCancelable(false)
            .setIcon(R.mipmap.ic_launcher_home).setMessage(R.string.license_dialog_message).setPositiveButton(
                    context.getResources().getString(R.string.ok), new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {
                            dialog.dismiss();
                        }/*from  w ww .  j a  v  a2s.  c  o  m*/
                    })
            .create();
    builder.show();
    ((TextView) builder.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance());
    ((TextView) builder.findViewById(android.R.id.message)).setGravity(Gravity.CENTER_VERTICAL);
    builder.getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT,
            WindowManager.LayoutParams.WRAP_CONTENT);
}

From source file:com.android.launcher3.Utilities.java

public static void aboutAlertDialog(Context context) {
    AlertDialog builder = new AlertDialog.Builder(context, R.style.AlertDialogCustom)
            .setTitle(context.getResources().getString(R.string.app_name)).setCancelable(false)
            .setIcon(R.mipmap.ic_launcher_home).setMessage(R.string.disclaimer_dialog_message)
            .setPositiveButton(context.getResources().getString(R.string.ok),
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {
                            dialog.dismiss();
                        }/*from w  ww.  j a  va  2  s .  co m*/
                    })
            .create();
    builder.show();
    ((TextView) builder.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance());
    ((TextView) builder.findViewById(android.R.id.message)).setGravity(Gravity.CENTER_VERTICAL);
    builder.getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT,
            WindowManager.LayoutParams.WRAP_CONTENT);
}

From source file:com.android.launcher3.Utilities.java

public static void upgradeToPROAlertDialog(Context context) {
    AlertDialog builder = new AlertDialog.Builder(context, R.style.AlertDialogCustom)
            .setTitle(context.getResources().getString(R.string.app_name)).setCancelable(false)
            .setIcon(R.mipmap.ic_launcher_home).setMessage(R.string.license_dialog_message_pro)
            .setPositiveButton(context.getResources().getString(R.string.ok),
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {
                            dialog.dismiss();
                        }/*from  w w  w .j a  va 2s .c om*/
                    })
            .create();
    builder.show();
    ((TextView) builder.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance());
    ((TextView) builder.findViewById(android.R.id.message)).setGravity(Gravity.CENTER_VERTICAL);
    builder.getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT,
            WindowManager.LayoutParams.WRAP_CONTENT);
}

From source file:com.mantz_it.rfanalyzer.ui.activity.MainActivity.java

public void showInfoDialog() {
    AlertDialog dialog = new AlertDialog.Builder(this)
            .setTitle(Html.fromHtml(getString(R.string.info_title, versionName)))
            .setMessage(Html.fromHtml(getString(R.string.info_msg_body)))
            .setPositiveButton("OK", (dialog1, whichButton) -> {
                // Do nothing
            }).create();//from w  w  w . j ava 2  s.com
    dialog.show();

    // make links clickable:
    ((TextView) dialog.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance());
}

From source file:no.barentswatch.fiskinfo.BaseActivity.java

/**
 * This function creates a "<code>positive</code>:see google docs" pop up
 * dialog which takes in the context of the current activity
 * /* w w w  .j  a  va2 s  .  co  m*/
 * @param activityContext
 *            the context of the current activity
 * @param rPathToTitleOfPopup
 *            The R.path to the title
 * @param rPathToTextInTheBodyOfThePopup
 *            The R.path to the text which will be contained in the body
 */
public void createNewPositiveDialog(Context activityContext, int rPathToTitleOfPopup,
        int rPathToTextInTheBodyOfThePopup) {
    AlertDialog.Builder builder = new AlertDialog.Builder(activityContext);
    builder.setTitle(rPathToTitleOfPopup);
    builder.setMessage(rPathToTextInTheBodyOfThePopup);
    builder.setPositiveButton("OK", null);
    AlertDialog dialog = builder.show();
    dialog.setCanceledOnTouchOutside(false);

    dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {

        @Override
        public void onDismiss(DialogInterface dialog) {
            // TODO Auto-generated method stub
            actionBar.setSelectedNavigationItem(adapter.getCount());
        }
    });

    TextView messageView = (TextView) dialog.findViewById(android.R.id.message);
    messageView.setGravity(Gravity.CENTER);
}

From source file:de.syss.MifareClassicTool.Activities.MainMenu.java

/**
 * Check for NFC hardware, Mifare Classic support and for external storage.
 * If the directory structure and the std. keys files is not already there
 * it will be created. Also, at the first run of this App, a warning
 * notice and a donate message will be displayed.
 * @see #copyStdKeysFilesIfNecessary()// ww w .ja  v a  2 s  .com
 */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main_menu);

    // Show App version and footer.
    TextView tv = (TextView) findViewById(R.id.textViewMainFooter);
    tv.setText(getString(R.string.app_version) + ": " + Common.getVersionCode());

    // Add the context menu to the tools button.
    Button tools = (Button) findViewById(R.id.buttonMainTools);
    registerForContextMenu(tools);

    // Bind main layout buttons.
    mReadTag = (Button) findViewById(R.id.buttonMainReadTag);
    mWriteTag = (Button) findViewById(R.id.buttonMainWriteTag);
    mKeyEditor = (Button) findViewById(R.id.buttonMainEditKeyDump);
    mDumpEditor = (Button) findViewById(R.id.buttonMainEditCardDump);

    // Check if the user granted the app write permissions.
    if (Common.hasWritePermissionToExternalStorage(this)) {
        initFolders();
    } else {
        enableMenuButtons(false);
        // Request the permission.
        ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE },
                REQUEST_WRITE_STORAGE_CODE);
    }

    // Check if there is an NFC hardware component.
    Common.setNfcAdapter(NfcAdapter.getDefaultAdapter(this));
    if (Common.getNfcAdapter() == null) {
        createNfcEnableDialog();
        mEnableNfc.show();
        mReadTag.setEnabled(false);
        mWriteTag.setEnabled(false);
        mResume = false;
    }

    // Show first usage notice.
    SharedPreferences sharedPref = getPreferences(Context.MODE_PRIVATE);
    final Editor sharedEditor = sharedPref.edit();
    boolean isFirstRun = sharedPref.getBoolean("is_first_run", true);
    if (isFirstRun) {
        new AlertDialog.Builder(this).setTitle(R.string.dialog_first_run_title)
                .setIcon(android.R.drawable.ic_dialog_alert).setMessage(R.string.dialog_first_run)
                .setPositiveButton(R.string.action_ok, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.cancel();
                    }
                }).setOnCancelListener(new DialogInterface.OnCancelListener() {
                    @Override
                    public void onCancel(DialogInterface dialog) {
                        if (Common.IS_DONATE_VERSION) {
                            mResume = true;
                            checkNfc();
                        }
                        sharedEditor.putBoolean("is_first_run", false);
                        sharedEditor.apply();
                    }
                }).show();
        mResume = false;
    }

    if (Common.IS_DONATE_VERSION) {
        // Do not show the donate dialog.
        return;
    }
    // Show donate dialog.
    int currentVersion = 0;
    try {
        currentVersion = getPackageManager().getPackageInfo(getPackageName(), 0).versionCode;
    } catch (NameNotFoundException e) {
        Log.d(LOG_TAG, "Version not found.");
    }
    int lastVersion = sharedPref.getInt("mct_version", currentVersion - 1);
    boolean showDonateDialog = sharedPref.getBoolean("show_donate_dialog", true);
    if (lastVersion < currentVersion || showDonateDialog) {
        // This is either a new version of MCT or the user wants to see
        // the donate dialog.
        if (lastVersion < currentVersion) {
            // Update the version.
            sharedEditor.putInt("mct_version", currentVersion);
            sharedEditor.putBoolean("show_donate_dialog", true);
            sharedEditor.apply();
        }
        View dialogLayout = getLayoutInflater().inflate(R.layout.dialog_donate,
                (ViewGroup) findViewById(android.R.id.content), false);
        final CheckBox showDonateDialogCheckBox = (CheckBox) dialogLayout
                .findViewById(R.id.checkBoxDonateDialog);
        new AlertDialog.Builder(this).setTitle(R.string.dialog_donate_title)
                .setIcon(android.R.drawable.ic_dialog_info).setView(dialogLayout)
                .setPositiveButton(R.string.action_beer_sounds_fine, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        // Open Google Play for the donate version of MCT.
                        Uri uri = Uri.parse("market://details?id=de." + "syss.MifareClassicToolDonate");
                        Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri);
                        try {
                            startActivity(goToMarket);
                        } catch (ActivityNotFoundException e) {
                            startActivity(
                                    new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store"
                                            + "/apps/details?id=de.syss.Mifare" + "ClassicToolDonate")));
                        }
                        if (showDonateDialogCheckBox.isChecked()) {
                            // Do not show the donate dialog again.
                            sharedEditor.putBoolean("show_donate_dialog", false);
                            sharedEditor.apply();
                        }
                        mResume = true;
                        checkNfc();
                    }
                }).setNegativeButton(R.string.action_cancel, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.cancel();
                    }
                }).setOnCancelListener(new DialogInterface.OnCancelListener() {
                    @Override
                    public void onCancel(DialogInterface dialog) {
                        if (showDonateDialogCheckBox.isChecked()) {
                            // Do not show the donate dialog again.
                            sharedEditor.putBoolean("show_donate_dialog", false);
                            sharedEditor.apply();
                        }
                        mResume = true;
                        checkNfc();
                    }
                }).show();
        mResume = false;
    }

    // Check if there is Mifare Classic support.
    if (!Common.useAsEditorOnly() && !Common.hasMifareClassicSupport()) {
        // Disable read/write tag options.
        mReadTag.setEnabled(false);
        mWriteTag.setEnabled(false);
        CharSequence styledText = Html.fromHtml(getString(R.string.dialog_no_mfc_support_device));
        AlertDialog ad = new AlertDialog.Builder(this).setTitle(R.string.dialog_no_mfc_support_device_title)
                .setMessage(styledText).setIcon(android.R.drawable.ic_dialog_alert)
                .setPositiveButton(R.string.action_exit_app, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        finish();
                    }
                }).setNegativeButton(R.string.action_continue, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                        mResume = true;
                        checkNfc();
                    }
                }).setOnCancelListener(new DialogInterface.OnCancelListener() {
                    @Override
                    public void onCancel(DialogInterface dialog) {
                        finish();
                    }
                }).show();
        // Make links clickable.
        ((TextView) ad.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance());
        mResume = false;
    }
}

From source file:net.zjy.zxcardumper.Activities.MainMenu.java

/**
 * Check for NFC hardware, MIFARE Classic support and for external storage.
 * If the directory structure and the std. keys files is not already there
 * it will be created. Also, at the first run of this App, a warning
 * notice and a donate message will be displayed.
 * @see #copyStdKeysFilesIfNecessary()/*from   w w w.  j a  v  a2  s  .  c  o m*/
 */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main_menu);

    // Show App version and footer.
    TextView tv = (TextView) findViewById(R.id.textViewMainFooter);
    tv.setText(getString(R.string.app_version) + ": " + Common.getVersionCode());

    // Add the context menu to the tools button.
    Button tools = (Button) findViewById(R.id.buttonMainTools);
    registerForContextMenu(tools);

    // Bind main layout buttons.
    mReadTag = (Button) findViewById(R.id.buttonMainReadTag);
    mWriteTag = (Button) findViewById(R.id.buttonMainWriteTag);
    mKeyEditor = (Button) findViewById(R.id.buttonMainEditKeyDump);
    mDumpEditor = (Button) findViewById(R.id.buttonMainEditCardDump);

    // Check if the user granted the app write permissions.
    if (Common.hasWritePermissionToExternalStorage(this)) {
        initFolders();
    } else {
        enableMenuButtons(false);
        // Request the permission.
        ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE },
                REQUEST_WRITE_STORAGE_CODE);
    }

    // Check if there is an NFC hardware component.
    Common.setNfcAdapter(NfcAdapter.getDefaultAdapter(this));
    if (Common.getNfcAdapter() == null) {
        createNfcEnableDialog();
        mEnableNfc.show();
        mReadTag.setEnabled(false);
        mWriteTag.setEnabled(false);
        mResume = false;
    }

    // Show first usage notice.
    SharedPreferences sharedPref = getPreferences(Context.MODE_PRIVATE);
    final Editor sharedEditor = sharedPref.edit();
    boolean isFirstRun = sharedPref.getBoolean("is_first_run", true);
    if (isFirstRun) {
        new AlertDialog.Builder(this).setTitle(R.string.dialog_first_run_title)
                .setIcon(android.R.drawable.ic_dialog_alert).setMessage(R.string.dialog_first_run)
                .setPositiveButton(R.string.action_ok, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.cancel();
                    }
                }).setOnCancelListener(new DialogInterface.OnCancelListener() {
                    @Override
                    public void onCancel(DialogInterface dialog) {
                        if (Common.IS_DONATE_VERSION) {
                            mResume = true;
                            checkNfc();
                        }
                        sharedEditor.putBoolean("is_first_run", false);
                        sharedEditor.apply();
                    }
                }).show();
        mResume = false;
    }

    if (Common.IS_DONATE_VERSION) {
        // Do not show the donate dialog.
        return;
    }
    // Show donate dialog.
    int currentVersion = 0;
    try {
        currentVersion = getPackageManager().getPackageInfo(getPackageName(), 0).versionCode;
    } catch (NameNotFoundException e) {
        Log.d(LOG_TAG, "Version not found.");
    }
    int lastVersion = sharedPref.getInt("mct_version", currentVersion - 1);
    boolean showDonateDialog = sharedPref.getBoolean("show_donate_dialog", true);
    if (lastVersion < currentVersion || showDonateDialog) {
        // This is either a new version of MCT or the user wants to see
        // the donate dialog.
        if (lastVersion < currentVersion) {
            // Update the version.
            sharedEditor.putInt("mct_version", currentVersion);
            sharedEditor.putBoolean("show_donate_dialog", true);
            sharedEditor.apply();
        }
        View dialogLayout = getLayoutInflater().inflate(R.layout.dialog_donate,
                (ViewGroup) findViewById(android.R.id.content), false);
        final CheckBox showDonateDialogCheckBox = (CheckBox) dialogLayout
                .findViewById(R.id.checkBoxDonateDialog);
        new AlertDialog.Builder(this).setTitle(R.string.dialog_donate_title)
                .setIcon(android.R.drawable.ic_dialog_info).setView(dialogLayout)
                .setPositiveButton(R.string.action_beer_sounds_fine, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        // Open Google Play for the donate version of MCT.
                        Uri uri = Uri.parse("market://details?id=de." + "syss.MifareClassicToolDonate");
                        Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri);
                        try {
                            startActivity(goToMarket);
                        } catch (ActivityNotFoundException e) {
                            startActivity(
                                    new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store"
                                            + "/apps/details?id=de.syss.Mifare" + "ClassicToolDonate")));
                        }
                        if (showDonateDialogCheckBox.isChecked()) {
                            // Do not show the donate dialog again.
                            sharedEditor.putBoolean("show_donate_dialog", false);
                            sharedEditor.apply();
                        }
                        mResume = true;
                        checkNfc();
                    }
                }).setNegativeButton(R.string.action_cancel, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.cancel();
                    }
                }).setOnCancelListener(new DialogInterface.OnCancelListener() {
                    @Override
                    public void onCancel(DialogInterface dialog) {
                        if (showDonateDialogCheckBox.isChecked()) {
                            // Do not show the donate dialog again.
                            sharedEditor.putBoolean("show_donate_dialog", false);
                            sharedEditor.apply();
                        }
                        mResume = true;
                        checkNfc();
                    }
                }).show();
        mResume = false;
    }

    // Check if there is MIFARE Classic support.
    if (!Common.useAsEditorOnly() && !Common.hasMifareClassicSupport()) {
        // Disable read/write tag options.
        mReadTag.setEnabled(false);
        mWriteTag.setEnabled(false);
        CharSequence styledText = Html.fromHtml(getString(R.string.dialog_no_mfc_support_device));
        AlertDialog ad = new AlertDialog.Builder(this).setTitle(R.string.dialog_no_mfc_support_device_title)
                .setMessage(styledText).setIcon(android.R.drawable.ic_dialog_alert)
                .setPositiveButton(R.string.action_exit_app, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        finish();
                    }
                }).setNegativeButton(R.string.action_continue, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                        mResume = true;
                        checkNfc();
                    }
                }).setOnCancelListener(new DialogInterface.OnCancelListener() {
                    @Override
                    public void onCancel(DialogInterface dialog) {
                        finish();
                    }
                }).show();
        // Make links clickable.
        ((TextView) ad.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance());
        mResume = false;
    }
}

From source file:org.rm3l.ddwrt.mgmt.AbstractRouterMgmtDialogFragment.java

/**
 * Receive the result from a previous call to
 * {@link #startActivityForResult(android.content.Intent, int)}.  This follows the
 * related Activity API as described there in
 * {@link android.app.Activity#onActivityResult(int, int, android.content.Intent)}.
 *
 * @param requestCode The integer request code originally supplied to
 *                    startActivityForResult(), allowing you to identify who this
 *                    result came from./*from w w  w . j  av a  2  s . c om*/
 * @param resultCode  The integer result code returned by the child activity
 *                    through its setResult().
 * @param resultData  An Intent, which can return result data to the caller
 */
@Override
public void onActivityResult(int requestCode, int resultCode, Intent resultData) {
    // The ACTION_OPEN_DOCUMENT intent was sent with the request code
    // READ_REQUEST_CODE. If the request code seen here doesn't match, it's the
    // response to some other intent, and the code below shouldn't run at all.

    if (requestCode == READ_REQUEST_CODE && resultCode == Activity.RESULT_OK) {
        // The document selected by the user won't be returned in the intent.
        // Instead, a URI to that document will be contained in the return intent
        // provided to this method as a parameter.
        // Pull that URI using resultData.getData().
        Uri uri;
        if (resultData != null) {
            uri = resultData.getData();
            Log.i(LOG_TAG, "Uri: " + uri.toString());
            final AlertDialog d = (AlertDialog) getDialog();
            if (d != null) {

                final ContentResolver contentResolver = this.getSherlockActivity().getContentResolver();

                final Cursor uriCursor = contentResolver.query(uri, null, null, null, null);

                /*
                 * Get the column indexes of the data in the Cursor,
                 * move to the first row in the Cursor, get the data,
                 * and display it.
                 */
                final int nameIndex = uriCursor.getColumnIndex(OpenableColumns.DISPLAY_NAME);
                final int sizeIndex = uriCursor.getColumnIndex(OpenableColumns.SIZE);

                uriCursor.moveToFirst();

                //File size in bytes
                final long fileSize = uriCursor.getLong(sizeIndex);
                final String filename = uriCursor.getString(nameIndex);

                //Check file size
                if (fileSize > MAX_PRIVKEY_SIZE_BYTES) {
                    displayMessage(String.format("File '%s' too big (%s). Limit is %s", filename,
                            toHumanReadableByteCount(fileSize),
                            toHumanReadableByteCount(MAX_PRIVKEY_SIZE_BYTES)), ALERT);
                    return;
                }

                //Replace button hint message with file name
                final Button fileSelectorButton = (Button) d.findViewById(R.id.router_add_privkey);
                final CharSequence fileSelectorOriginalHint = fileSelectorButton.getHint();
                if (!Strings.isNullOrEmpty(filename)) {
                    fileSelectorButton.setHint(filename);
                }

                //Set file actual content in hidden field
                final TextView privKeyPath = (TextView) d.findViewById(R.id.router_add_privkey_path);
                try {
                    privKeyPath.setText(IOUtils.toString(contentResolver.openInputStream(uri)));
                } catch (IOException e) {
                    displayMessage("Error: " + e.getMessage(), ALERT);
                    e.printStackTrace();
                    fileSelectorButton.setHint(fileSelectorOriginalHint);
                }
            }
        }
    }
}