Example usage for android.app AlertDialog getContext

List of usage examples for android.app AlertDialog getContext

Introduction

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

Prototype

public final @NonNull Context getContext() 

Source Link

Document

Retrieve the Context this Dialog is running in.

Usage

From source file:com.github.andrewlord1990.materialandroidsample.color.ColorChooserDialog.java

private View setupCustomView(final AlertDialog dialog) {
    Context context = dialog.getContext();
    View customView = LayoutInflater.from(context).inflate(R.layout.color_chooser, null);
    GridView grid = (GridView) customView.findViewById(R.id.colorChooserGrid);
    ColorGridAdapter adapter = new ColorGridAdapter(context, colors);
    grid.setAdapter(adapter);/*from  w  w w  . j  a v a2s  .c  om*/
    grid.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            if (listener != null) {
                listener.onColorSelected(requestCode, colors.get(position));
            }
            dialog.dismiss();
        }
    });
    return customView;
}

From source file:org.openmidaas.app.activities.ScanFragment.java

private void showNoQRCodeScannersPresentDialog() {
    AlertDialog.Builder dlBuilder = new AlertDialog.Builder(getActivity());
    dlBuilder.setTitle(R.string.no_qrcode_dialog_title);
    dlBuilder.setMessage(R.string.no_qrcode_dialog_message);
    dlBuilder.setIcon(android.R.drawable.ic_dialog_alert);
    dlBuilder.setPositiveButton(R.string.install_button, new DialogInterface.OnClickListener() {
        @Override/*from w  w w .  j a v a2  s. c  o m*/
        public void onClick(DialogInterface dialog, int whichButton) {
            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(Constants.ZXING_MARKET));
            AlertDialog aDialog = (AlertDialog) dialog;
            try {

                aDialog.getContext().startActivity(intent);
            } catch (ActivityNotFoundException e) {
                intent = new Intent(Intent.ACTION_VIEW, Uri.parse(Constants.ZXING_DIRECT));
                aDialog.getContext().startActivity(intent);
            }
        }
    });
    dlBuilder.setNegativeButton(R.string.cancel, null);
    dlBuilder.show();
}

From source file:org.steveleach.scoresheet.ui.ScoresheetActivity.java

private View getDialogView(AlertDialog dialog, String resourceName) {
    int textViewId = dialog.getContext().getResources().getIdentifier(resourceName, null, null);
    return dialog.findViewById(textViewId);
}

From source file:se.lu.nateko.edca.BackboneSvc.java

/**
  * Method that displays an alert dialog to the user showing the string argument as the message text.
  * @param message Message to display in the alert dialog.
  * @param target The activity to display the AlertDialog in, pass null to default to the "active" Activity.
  *//*from   www  .  j  a v  a 2 s. c  o  m*/
public void showAlertDialog(String message, Activity target) {
    Log.d(TAG, "showAlertDialog(String) called.");
    final String msg = message;
    final Activity tg = target;
    /*
      * By sending the code in "action" to the runOnUiThread() method from a separate thread,
      * its code will be placed in the UI Thread Message queue and thus happen after other
      * queued messages (such as displaying the layout).
      */
    new Thread(new Runnable() {
        public void run() {
            Runnable action = new Runnable() {
                public void run() {
                    /* The following is put on the Message queue. */
                    AlertDialog alertDialog = new AlertDialog.Builder((tg == null) ? getActiveActivity() : tg)
                            .create();
                    alertDialog.setMessage(msg);

                    /* Add a button to the dialog and set its text and button listener. */
                    alertDialog.setButton(
                            alertDialog.getContext().getString(R.string.service_alert_buttontext_ok),
                            new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int which) {
                                    dialog.dismiss();
                                }
                            });
                    alertDialog.show(); // Display the dialog to the user.
                }
            };
            ((tg == null) ? getActiveActivity() : tg).runOnUiThread(action);
        }
    }).start();

}

From source file:info.zamojski.soft.towercollector.MainActivity.java

private void displayNewVersionDownloadOptions(Bundle extras) {
    UpdateInfo updateInfo = (UpdateInfo) extras.getSerializable(UpdateCheckAsyncTask.INTENT_KEY_UPDATE_INFO);
    // display dialog
    AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
    LayoutInflater inflater = LayoutInflater.from(this);
    View dialogLayout = inflater.inflate(R.layout.new_version, null);
    dialogBuilder.setView(dialogLayout);
    final AlertDialog alertDialog = dialogBuilder.create();
    alertDialog.setCanceledOnTouchOutside(true);
    alertDialog.setCancelable(true);//from   ww  w  . ja va2  s  .c o m
    alertDialog.setTitle(R.string.updater_dialog_new_version_available);
    // load data
    ArrayAdapter<UpdateInfo.DownloadLink> adapter = new UpdateDialogArrayAdapter(alertDialog.getContext(),
            inflater, updateInfo.getDownloadLinks());
    ListView listView = (ListView) dialogLayout.findViewById(R.id.download_options_list);
    listView.setAdapter(adapter);
    // bind events
    final CheckBox disableAutoUpdateCheckCheckbox = (CheckBox) dialogLayout
            .findViewById(R.id.download_options_disable_auto_update_check_checkbox);
    listView.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            DownloadLink downloadLink = (DownloadLink) parent.getItemAtPosition(position);
            Log.d("displayNewVersionDownloadOptions(): Selected position: %s", downloadLink.getLabel());
            boolean disableAutoUpdateCheckCheckboxChecked = disableAutoUpdateCheckCheckbox.isChecked();
            Log.d("displayNewVersionDownloadOptions(): Disable update check checkbox checked = %s",
                    disableAutoUpdateCheckCheckboxChecked);
            if (disableAutoUpdateCheckCheckboxChecked) {
                MyApplication.getPreferencesProvider().setUpdateCheckEnabled(false);
            }
            MyApplication.getAnalytics().sendUpdateAction(downloadLink.getLabel());
            String link = downloadLink.getLink();
            try {
                startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(link)));
            } catch (ActivityNotFoundException ex) {
                Toast.makeText(getApplication(), R.string.web_browser_missing, Toast.LENGTH_LONG).show();
            }
            alertDialog.dismiss();
        }
    });
    alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, getString(R.string.dialog_cancel),
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    boolean disableAutoUpdateCheckCheckboxChecked = disableAutoUpdateCheckCheckbox.isChecked();
                    Log.d("displayNewVersionDownloadOptions(): Disable update check checkbox checked = %s",
                            disableAutoUpdateCheckCheckboxChecked);
                    if (disableAutoUpdateCheckCheckboxChecked) {
                        MyApplication.getPreferencesProvider().setUpdateCheckEnabled(false);
                    }
                }
            });
    alertDialog.show();
}

From source file:com.juick.android.ThreadActivity.java

private void previewAndSendReply(final String msg) {
    final SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
    if (sp.getBoolean("previewReplies", false)) {
        final TextView tv = new TextView(this);
        JuickMessage jm = new JuickMessage();
        jm.User = new JuickUser();
        jm.User.UName = "You";
        jm.Text = msg;/*from w  w w. ja  va  2s .c o m*/
        jm.tags = new Vector<String>();
        if (rid != 0) {
            // insert destination user name
            JuickMessage reply = tf.findReply(tf.getListView(), rid);
            if (reply != null) {
                jm.Text = "@" + reply.User.UName + " " + jm.Text;
            }
        }
        JuickMessagesAdapter.ParsedMessage parsedMessage = JuickMessagesAdapter.formatMessageText(this, jm,
                true);
        tv.setText(parsedMessage.textContent);
        tv.setPadding(10, 10, 10, 10);
        MainActivity.restyleChildrenOrWidget(tv);
        final AlertDialog dialog = new AlertDialog.Builder(
                new ContextThemeWrapper(this, R.style.Theme_Sherlock_Light)).setTitle("Post reply - preview")
                        .setView(tv).setCancelable(true)
                        .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                dialog.cancel();
                            }
                        }).setPositiveButton("Post reply", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                dialog.cancel();
                                sendReplyMain(msg);
                            }
                        }).create();
        dialog.setOnShowListener(new DialogInterface.OnShowListener() {
            @Override
            public void onShow(DialogInterface i) {
                tv.setBackgroundColor(JuickMessagesAdapter.getColorTheme(dialog.getContext()).getBackground());
                MainActivity.restyleChildrenOrWidget(tv);
            }
        });
        dialog.show();
    } else {
        sendReplyMain(msg);
    }
}

From source file:com.wikonos.fingerprint.activities.MainActivity.java

/**
 * Create dialog list of logs//from  ww  w  .  ja  v a 2s  .co  m
 * 
 * @return
 */
public AlertDialog getDialogReviewLogs() {
    /**
     * List of logs
     */
    File folder = new File(LogWriter.APPEND_PATH);
    final String[] files = folder.list(new FilenameFilter() {
        public boolean accept(File dir, String filename) {
            if (filename.contains(".log") && !filename.equals(LogWriter.DEFAULT_NAME)
                    && !filename.equals(LogWriterSensors.DEFAULT_NAME)
                    && !filename.equals(ErrorLog.DEFAULT_NAME))
                return true;
            else
                return false;
        }
    });

    Arrays.sort(files);
    ArrayUtils.reverse(files);

    String[] files_with_status = new String[files.length];
    String[] sent_mode = { "", "(s) ", "(e) ", "(s+e) " };
    for (int i = 0; i < files.length; ++i) {
        //0 -- not sent
        //1 -- server
        //2 -- email
        files_with_status[i] = sent_mode[getSentFlags(files[i], this)] + files[i];
    }

    if (files != null && files.length > 0) {

        final boolean[] selected = new boolean[files.length];

        final AlertDialog ald = new AlertDialog.Builder(MainActivity.this)
                .setMultiChoiceItems(files_with_status, selected,
                        new DialogInterface.OnMultiChoiceClickListener() {
                            public void onClick(DialogInterface dialog, int which, boolean isChecked) {
                                selected[which] = isChecked;
                            }
                        })
                .setOnCancelListener(new OnCancelListener() {
                    @Override
                    public void onCancel(DialogInterface dialog) {
                        // removeDialog(DIALOG_ID_REVIEW);
                    }
                })
                /**
                * Delete log
                */
                .setNegativeButton("Delete", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {

                        //Show delete confirm
                        standardConfirmDialog("Delete Logs", "Are you sure you want to delete selected logs?",
                                new OnClickListener() {
                                    //Confrim Delete
                                    @Override
                                    public void onClick(DialogInterface dialog, int which) {

                                        int deleteCount = 0;
                                        boolean flagSelected = false;
                                        for (int i = 0; i < selected.length; i++) {
                                            if (selected[i]) {
                                                flagSelected = true;
                                                LogWriter.delete(files[i]);
                                                LogWriter.delete(files[i].replace(".log", ".dev"));
                                                deleteCount++;
                                            }
                                        }

                                        reviewLogsCheckItems(flagSelected);

                                        removeDialog(DIALOG_ID_REVIEW);

                                        Toast.makeText(getApplicationContext(), deleteCount + " logs deleted.",
                                                Toast.LENGTH_SHORT).show();
                                    }
                                }, new OnClickListener() {
                                    //Cancel Delete
                                    @Override
                                    public void onClick(DialogInterface dialog, int which) {
                                        //Do nothing
                                        dialog.dismiss();
                                        Toast.makeText(getApplicationContext(), "Delete cancelled.",
                                                Toast.LENGTH_SHORT).show();
                                    }
                                }, false);
                    }
                })
                /**
                * Send to server functional
                **/
                .setNeutralButton("Send to Server", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        if (isOnline()) {
                            ArrayList<String> filesList = new ArrayList<String>();

                            for (int i = 0; i < selected.length; i++)
                                if (selected[i]) {

                                    filesList.add(LogWriter.APPEND_PATH + files[i]);
                                    //Move to httplogsender
                                    //setSentFlags(files[i], 1, MainActivity.this);   //Mark file as sent
                                }

                            if (reviewLogsCheckItems(filesList.size() > 0 ? true : false)) {
                                DataPersistence d = new DataPersistence(getApplicationContext());
                                new HttpLogSender(MainActivity.this,
                                        d.getServerName() + getString(R.string.submit_log_url), filesList)
                                                .setToken(getToken()).execute();
                            }

                            // removeDialog(DIALOG_ID_REVIEW);
                        } else {
                            standardAlertDialog(getString(R.string.msg_alert),
                                    getString(R.string.msg_no_internet), null);
                        }
                    }
                })
                /**
                * Email
                **/
                .setPositiveButton("eMail", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        boolean flagSelected = false;
                        // convert from paths to Android friendly
                        // Parcelable Uri's
                        ArrayList<Uri> uris = new ArrayList<Uri>();
                        for (int i = 0; i < selected.length; i++)
                            if (selected[i]) {
                                flagSelected = true;
                                /** wifi **/
                                File fileIn = new File(LogWriter.APPEND_PATH + files[i]);
                                Uri u = Uri.fromFile(fileIn);
                                uris.add(u);

                                /** sensors **/
                                File fileInSensors = new File(
                                        LogWriter.APPEND_PATH + files[i].replace(".log", ".dev"));
                                Uri uSens = Uri.fromFile(fileInSensors);
                                uris.add(uSens);

                                setSentFlags(files[i], 2, MainActivity.this); //Mark file as emailed
                            }

                        if (reviewLogsCheckItems(flagSelected)) {
                            /**
                             * Run sending email activity
                             */
                            Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND_MULTIPLE);
                            emailIntent.setType("plain/text");
                            emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
                                    "Wifi Searcher Scan Log");
                            emailIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
                            startActivity(Intent.createChooser(emailIntent, "Send mail..."));
                        }

                        // removeDialog(DIALOG_ID_REVIEW);
                    }
                }).create();

        ald.getListView().setOnItemLongClickListener(new OnItemLongClickListener() {

            @Override
            public boolean onItemLongClick(AdapterView<?> parent, View view, final int position, long id) {

                AlertDialog segmentNameAlert = segmentNameDailog("Rename Segment", ald.getContext(),
                        files[position], null, view, files, position);
                segmentNameAlert.setCanceledOnTouchOutside(false);
                segmentNameAlert.show();
                return false;
            }
        });
        return ald;
    } else {
        return standardAlertDialog(getString(R.string.msg_alert), getString(R.string.msg_log_nocount),
                new OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        removeDialog(DIALOG_ID_REVIEW);
                    }
                });
    }
}