Example usage for android.app Dialog Dialog

List of usage examples for android.app Dialog Dialog

Introduction

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

Prototype

public Dialog(@NonNull Context context) 

Source Link

Document

Creates a dialog window that uses the default dialog theme.

Usage

From source file:com.mobicage.rogerthat.plugins.messaging.widgets.AdvancedOrderWidget.java

private void showAdvancedOrderBasket() {
    if (mBasketDialog != null && mBasketDialog.isShowing())
        return;/*from ww w . j  a va 2  s  .  c  om*/
    final View v = mLayoutInFlater.inflate(R.layout.widget_advanced_order_basket, this, false);
    mBasketDialog = new Dialog(mActivity);
    mBasketDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    mBasketDialog.setContentView(v);
    mBasketDialog.setCanceledOnTouchOutside(true);
    mBasketDialog.setCancelable(true);

    final ListView listView = (ListView) v.findViewById(R.id.list_view);
    final Button submitBtn = (Button) v.findViewById(R.id.submit);
    final Button dismissBtn = (Button) v.findViewById(R.id.dismiss);

    listView.setAdapter(mBasketListAdapter);
    listView.setScrollContainer(false);
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            mBasketListAdapter.onItemClick(parent, view, position, id);
        }
    });

    submitBtn.setText((String) mMessage.form.get("positive_button"));

    submitBtn.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            mBasketDialog.dismiss();
            mActivity.excecutePositiveButtonClick();
        }
    });

    dismissBtn.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            mBasketDialog.dismiss();
        }
    });

    mActivity.getMainService().postOnUIHandler(new SafeRunnable() {
        @Override
        protected void safeRun() throws Exception {
            setBasketListViewHeight();
        }
    });

    mBasketDialog.show();
}

From source file:com.vkassin.mtrade.Common.java

public static void putArcDeal(final Context ctx) {

    final Dialog dialog = new Dialog(ctx);
    dialog.setContentView(R.layout.arcdeal_dialog);
    dialog.setTitle(R.string.ArcDealDialogTitle);

    datetxt = (EditText) dialog.findViewById(R.id.expdateedit);
    SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy");
    Date dat1 = new Date();
    datetxt.setText(sdf.format(dat1));//from w  w w . j  a  v  a2 s  . c  o  m
    mYear = dat1.getYear() + 1900;
    mMonth = dat1.getMonth();
    mDay = dat1.getDate();
    final Date dat = new GregorianCalendar(mYear, mMonth, mDay).getTime();

    datetxt.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            Log.i(TAG, "Show DatePickerDialog");
            DatePickerDialog dpd = new DatePickerDialog(ctx, mDateSetListener, mYear, mMonth, mDay);
            dpd.show();
        }
    });

    TextView itext = (TextView) dialog.findViewById(R.id.instrtext);
    itext.setText(Common.arcfilter);

    Button customDialog_Cancel = (Button) dialog.findViewById(R.id.cancelbutt);
    customDialog_Cancel.setOnClickListener(new Button.OnClickListener() {
        public void onClick(View arg0) {

            dialog.dismiss();
        }

    });

    Button customDialog_Put = (Button) dialog.findViewById(R.id.putorder);
    customDialog_Put.setOnClickListener(new Button.OnClickListener() {
        public void onClick(View arg0) {

            Double price = new Double(0);
            Long qval = new Long(0);
            final EditText pricetxt = (EditText) dialog.findViewById(R.id.priceedit);
            final EditText quanttxt = (EditText) dialog.findViewById(R.id.quantedit);

            try {

                price = Double.valueOf(pricetxt.getText().toString());
            } catch (Exception e) {

                Toast.makeText(ctx, R.string.CorrectPrice, Toast.LENGTH_SHORT).show();
                return;
            }
            try {

                qval = Long.valueOf(quanttxt.getText().toString());
            } catch (Exception e) {

                Toast.makeText(ctx, R.string.CorrectQty, Toast.LENGTH_SHORT).show();
                return;
            }

            //            if (dat.compareTo(new GregorianCalendar(mYear, mMonth, mDay)
            //            .getTime()) > 0) {
            //
            //               Toast.makeText(ctx, R.string.CorrectDate,
            //               Toast.LENGTH_SHORT).show();
            //
            //            return;
            //            }

            long maxkey = 0;
            Iterator<String> itr2 = arcdealMap.keySet().iterator();
            while (itr2.hasNext()) {
                String key1 = itr2.next();
                long k = Long.parseLong(key1);
                if (k > maxkey)
                    maxkey = k;
            }

            Deal adeal = new Deal();
            Iterator<String> itr1 = instrMap.keySet().iterator();
            while (itr1.hasNext()) {
                String key1 = itr1.next();
                Instrument in = instrMap.get(key1);
                if (in.symbol.equals(Common.arcfilter)) {

                    adeal.instrId = Long.valueOf(in.id);
                    break;
                }
            }

            final RadioButton bu0 = (RadioButton) dialog.findViewById(R.id.radio0);

            adeal.price = price;
            adeal.qty = qval;
            adeal.dtime = new GregorianCalendar(mYear, mMonth, mDay).getTimeInMillis();
            adeal.direct = bu0.isChecked() ? Long.valueOf(0) : Long.valueOf(1);
            Collection<String> lacc = Common.getAccountList();
            adeal.account = (lacc == null) ? "" : lacc.iterator().next();
            arcdealMap.put(String.valueOf(maxkey + 1), adeal);
            Common.saveArcDeals();
            Common.arcActivity.refresh();
            dialog.dismiss();
        }
    });

    dialog.show();

    WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
    lp.copyFrom(dialog.getWindow().getAttributes());
    lp.width = WindowManager.LayoutParams.FILL_PARENT;
    lp.height = WindowManager.LayoutParams.FILL_PARENT;
    dialog.getWindow().setAttributes(lp);

}

From source file:com.aegiswallet.actions.MainActivity.java

private void doBackupReminder() {

    if (System.currentTimeMillis() - application.lastReminderTime < 60000)
        return;//w w w.  j  a  v a2 s  . c om

    String lastBackupString = prefs.getString(Constants.LAST_BACKUP_DATE, null);
    int lastBackupNumAddresses = prefs.getInt(Constants.LAST_BACKUP_NUM_ADDRESSES, 0);

    final Dialog dialog = new Dialog(context);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setContentView(R.layout.backup_reminder_prompt);

    TextView backupText = (TextView) dialog.findViewById(R.id.backup_reminder_prompt_text);

    Button cancelButton = (Button) dialog.findViewById(R.id.backup_reminder_prompt_cancel_button);
    cancelButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            dialog.dismiss();
        }
    });

    final Button okayButton = (Button) dialog.findViewById(R.id.backup_reminder_prompt_ok_button);

    okayButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            dialog.dismiss();

            if (nfcEnabled) {
                Intent intent = new Intent(context, NFCActivity.class);
                intent.putExtra("nfc_action", "backup");
                startActivity(intent);
            } else
                application.showPasswordPrompt(context, Constants.ACTION_BACKUP);
        }
    });

    try {

        if (dialog.isShowing())
            return;

        if (lastBackupString != null) {
            Date lastBackupDate = Constants.backupDateFormat.parse(lastBackupString);
            long currentDate = System.currentTimeMillis();
            long difference = currentDate - lastBackupDate.getTime();

            long days = TimeUnit.MILLISECONDS.toDays(difference);
            int keyChainSize = wallet.getKeychainSize();

            if (days > 6) {
                dialog.show();
                application.lastReminderTime = System.currentTimeMillis();
            } else if (!prefs.contains(Constants.LAST_BACKUP_NUM_ADDRESSES)) {
                dialog.show();
                application.lastReminderTime = System.currentTimeMillis();

            } else if (keyChainSize > lastBackupNumAddresses) {
                backupText.setText(getString(R.string.backup_reminder_new_address));
                dialog.show();
                application.lastReminderTime = System.currentTimeMillis();
            }

        } else {
            application.lastReminderTime = System.currentTimeMillis();
            dialog.show();
        }

    } catch (ParseException e) {
        Log.d(TAG, e.getMessage());
    }
}

From source file:com.entertailion.android.launcher.Dialogs.java

/**
 * Utility method to display an alert dialog. Use instead of AlertDialog to
 * get the right styling.//from w w  w.  j a  v  a2s .  c o m
 * 
 * @param context
 * @param message
 */
public static void displayAlert(final Launcher context, String message) {
    final Dialog dialog = new Dialog(context);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setContentView(R.layout.alert);

    final TextView alertTextView = (TextView) dialog.findViewById(R.id.alertText);
    alertTextView.setText(message);
    Button alertButton = (Button) dialog.findViewById(R.id.alertButton);
    alertButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            context.showCover(false);
            dialog.dismiss();
        }

    });
    dialog.setOnDismissListener(new OnDismissListener() {

        @Override
        public void onDismiss(DialogInterface dialog) {
            context.showCover(false);
        }

    });
    context.showCover(true);
    dialog.show();
}

From source file:github.popeen.dsub.activity.SubsonicFragmentActivity.java

private void showLoginDialog() {
    final Dialog login = new Dialog(this);
    login.setContentView(R.layout.dialog_signin);

    Button btnLogin = (Button) login.findViewById(R.id.btnLogin);
    Button btnCancel = (Button) login.findViewById(R.id.btnCancel);

    btnLogin.setOnClickListener(new View.OnClickListener() {
        @Override//ww  w . j a  v  a  2 s.c o  m
        public void onClick(View view) {
            //Test server connection.
            EditText username = (EditText) login.findViewById(R.id.username);
            EditText password = (EditText) login.findViewById(R.id.password);
            EditText server = (EditText) login.findViewById(R.id.server);

            String strUsername = username.getText().toString();
            String strPassword = password.getText().toString();
            String strServer = server.getText().toString();

            if (strUsername.length() > 0 && strPassword.length() > 0 && strServer.length() > 0) {
                Util.setRestCredentials(SubsonicFragmentActivity.this, null, strUsername, strPassword,
                        strServer);
                login.dismiss();
                //recreate();
                SubsonicFragmentActivity.super.restart();
            }
        }
    });

    btnCancel.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            login.dismiss();
        }
    });

    login.show();
}

From source file:de.mkrtchyan.recoverytools.RecoveryTools.java

public void showPopup(int Menu, final View v) {
    PopupMenu popup = new PopupMenu(mContext, v);
    popup.getMenuInflater().inflate(Menu, popup.getMenu());
    popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override//from  w w w.j  a va2s .c  o m
        public boolean onMenuItemClick(MenuItem menuItem) {
            try {
                final String text = ((TextView) v).getText().toString();

                final Dialog dialog = new Dialog(mContext);
                dialog.setTitle(R.string.setname);
                dialog.setContentView(R.layout.dialog_input);
                final Button bGo = (Button) dialog.findViewById(R.id.bGoBackup);
                final EditText etFileName = (EditText) dialog.findViewById(R.id.etFileName);
                final File Backup = new File(PathToRecoveryBackups, text);

                switch (menuItem.getItemId()) {
                case R.id.iReboot:
                    mToolbox.reboot(Toolbox.REBOOT_REBOOT);
                    return true;
                case R.id.iRebootRecovery:
                    mToolbox.reboot(Toolbox.REBOOT_RECOVERY);
                    return true;
                case R.id.iRebootBootloader:
                    mToolbox.reboot(Toolbox.REBOOT_BOOTLOADER);
                    return true;
                case R.id.iRestoreRecovery:
                    new FlashUtil(mShell, mContext, mDevice, new File(PathToRecoveryBackups, text),
                            FlashUtil.JOB_RESTORE_RECOVERY).execute();
                    return true;
                case R.id.iRenameRecovery:
                    etFileName.setHint(text);
                    bGo.setOnClickListener(new View.OnClickListener() {

                        @Override
                        public void onClick(View v) {

                            String Name;
                            if (etFileName.getText() != null && !etFileName.getText().toString().equals("")) {
                                Name = etFileName.getText().toString();
                            } else {
                                Name = String.valueOf(etFileName.getHint());
                            }

                            if (!Name.endsWith(mDevice.getRecoveryExt())) {
                                Name = Name + mDevice.getRecoveryExt();
                            }

                            final File renamedBackup = new File(PathToRecoveryBackups, Name);

                            if (renamedBackup.exists()) {
                                Toast.makeText(mContext, R.string.backupalready, Toast.LENGTH_SHORT).show();
                            } else {
                                if (Backup.renameTo(renamedBackup)) {
                                    loadBackupDrawer();
                                }
                            }
                            dialog.dismiss();
                        }
                    });
                    dialog.show();
                    return true;
                case R.id.iDeleteRecoveryBackup:
                    if (((TextView) v).getText() != null) {
                        if (new File(PathToRecoveryBackups, text).delete()) {
                            Toast.makeText(mContext, String.format(mContext.getString(R.string.bak_deleted),
                                    ((TextView) v).getText()), Toast.LENGTH_SHORT).show();
                            loadBackupDrawer();
                        }
                    }
                    return true;
                case R.id.iRestoreKernel:
                    new FlashUtil(mShell, mContext, mDevice, new File(PathToKernelBackups, text),
                            FlashUtil.JOB_RESTORE_KERNEL).execute();
                    return true;
                case R.id.iRenameKernel:
                    etFileName.setHint(text);
                    bGo.setOnClickListener(new View.OnClickListener() {

                        @Override
                        public void onClick(View v) {

                            String Name;
                            if (etFileName.getText() != null && !etFileName.getText().toString().equals("")) {
                                Name = etFileName.getText().toString();
                            } else {
                                Name = String.valueOf(etFileName.getHint());
                            }

                            if (!Name.endsWith(mDevice.getKernelExt())) {
                                Name = Name + mDevice.getKernelExt();
                            }

                            final File renamedBackup = new File(PathToKernelBackups, Name);

                            if (renamedBackup.exists()) {
                                Toast.makeText(mContext, R.string.backupalready, Toast.LENGTH_SHORT).show();
                            } else {
                                if (Backup.renameTo(renamedBackup)) {
                                    loadBackupDrawer();
                                }
                            }
                            dialog.dismiss();

                        }
                    });
                    dialog.show();
                    return true;
                case R.id.iDeleteKernelBackup:
                    if (((TextView) v).getText() != null) {
                        if (new File(PathToKernelBackups, text).delete()) {
                            Toast.makeText(mContext, String.format(mContext.getString(R.string.bak_deleted),
                                    ((TextView) v).getText()), Toast.LENGTH_SHORT).show();
                            loadBackupDrawer();
                        }
                    }
                    return true;
                default:
                    return false;
                }
            } catch (Exception e) {
                return false;
            }
        }
    });
    popup.show();
}

From source file:com.entertailion.android.launcher.Dialogs.java

/**
 * Display a dialog to confirm that the user wants to delete an item.
 * //w w w  . ja va  2  s. c  o m
 * @param context
 */
public static void displayDeleteItem(final Launcher context) {
    final Dialog dialog = new Dialog(context);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setContentView(R.layout.confirmation);

    TextView confirmationTextView = (TextView) dialog.findViewById(R.id.confirmationText);
    confirmationTextView.setText(context.getString(R.string.dialog_delete_item_message));
    Button buttonYes = (Button) dialog.findViewById(R.id.button1);
    buttonYes.setText(context.getString(R.string.dialog_yes));
    buttonYes.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            context.deleteCurrentItem();
            context.showCover(false);
            dialog.dismiss();
        }

    });
    Button buttonNo = (Button) dialog.findViewById(R.id.button2);
    buttonNo.setText(context.getString(R.string.dialog_no));
    buttonNo.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            context.showCover(false);
            dialog.dismiss();
        }

    });
    dialog.setOnDismissListener(new OnDismissListener() {

        @Override
        public void onDismiss(DialogInterface dialog) {
            context.showCover(false);
        }

    });
    context.showCover(true);
    dialog.show();
    Analytics.logEvent(Analytics.DIALOG_DELETE_ITEM);
}

From source file:androidVNC.VncCanvasActivity.java

private void selectColorModel() {
    // Stop repainting the desktop
    // because the display is composited!
    vncCanvas.disableRepaints();/* w w  w.ja v a2 s .c o  m*/

    String[] choices = new String[COLORMODEL.values().length];
    int currentSelection = -1;
    for (int i = 0; i < choices.length; i++) {
        COLORMODEL cm = COLORMODEL.values()[i];
        choices[i] = cm.toString();
        if (vncCanvas.isColorModel(cm))
            currentSelection = i;
    }

    final Dialog dialog = new Dialog(this);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    ListView list = new ListView(this);
    list.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_checked, choices));
    list.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
    list.setItemChecked(currentSelection, true);
    list.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            dialog.dismiss();
            COLORMODEL cm = COLORMODEL.values()[arg2];
            vncCanvas.setColorModel(cm);
            connection.setColorModel(cm.nameString());
            connection.save(database.getWritableDatabase());
            //Toast.makeText(VncCanvasActivity.this,"Updating Color Model to " + cm.toString(), Toast.LENGTH_SHORT).show();
        }
    });
    dialog.setOnDismissListener(new OnDismissListener() {
        @Override
        public void onDismiss(DialogInterface arg0) {
            Log.i(TAG, "Color Model Selector dismissed");
            // Restore desktop repaints
            vncCanvas.enableRepaints();
        }
    });
    dialog.setContentView(list);
    dialog.show();
}

From source file:com.entertailion.android.launcher.Dialogs.java

/**
 * Display a dialog to confirm that a user wants to delete a row.
 * /*from  w  w w. j  av a2  s .  com*/
 * @param context
 */
public static void displayDeleteRow(final Launcher context) {
    final Dialog dialog = new Dialog(context);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setContentView(R.layout.confirmation);

    TextView confirmationTextView = (TextView) dialog.findViewById(R.id.confirmationText);
    confirmationTextView.setText(context.getString(R.string.dialog_delete_row_message));
    Button buttonYes = (Button) dialog.findViewById(R.id.button1);
    buttonYes.setText(context.getString(R.string.dialog_yes));
    buttonYes.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            context.deleteCurrentRow();
            context.showCover(false);
            dialog.dismiss();
        }

    });
    Button buttonNo = (Button) dialog.findViewById(R.id.button2);
    buttonNo.setText(context.getString(R.string.dialog_no));
    buttonNo.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            context.showCover(false);
            dialog.dismiss();
        }

    });
    dialog.setOnDismissListener(new OnDismissListener() {

        @Override
        public void onDismiss(DialogInterface dialog) {
            context.showCover(false);
        }

    });
    context.showCover(true);
    dialog.show();
    Analytics.logEvent(Analytics.DIALOG_DELETE_ROW);
}

From source file:com.sentaroh.android.SMBSync.SMBSyncMain.java

private void aboutSMBSync() {

    // common ??//  w  w  w  . j av  a  2s .com
    final Dialog dialog = new Dialog(this);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setContentView(R.layout.about_dialog);
    ((TextView) dialog.findViewById(R.id.about_dialog_title))
            .setText(getString(R.string.msgs_dlg_title_about) + "(Ver " + packageVersionName + ")");
    final WebView func_view = (WebView) dialog.findViewById(R.id.about_dialog_function);
    //      func_view.loadDataWithBaseURL("file:///android_asset/",
    //            getString(R.string.msgs_dlg_title_about_func_desc),"text/html","UTF-8","");
    func_view.loadUrl("file:///android_asset/" + getString(R.string.msgs_dlg_title_about_func_desc));
    func_view.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
    func_view.getSettings().setBuiltInZoomControls(true);

    final WebView change_view = (WebView) dialog.findViewById(R.id.about_dialog_change_history);
    change_view.loadUrl("file:///android_asset/" + getString(R.string.msgs_dlg_title_about_change_desc));
    change_view.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
    change_view.getSettings().setBuiltInZoomControls(true);

    final Button btnFunc = (Button) dialog.findViewById(R.id.about_dialog_btn_show_func);
    final Button btnChange = (Button) dialog.findViewById(R.id.about_dialog_btn_show_change);
    final Button btnOk = (Button) dialog.findViewById(R.id.about_dialog_btn_ok);

    func_view.setVisibility(TextView.VISIBLE);
    change_view.setVisibility(TextView.GONE);
    btnChange.setBackgroundResource(R.drawable.button_bg_color_selector);
    btnFunc.setBackgroundResource(R.drawable.button_bg_color_selector);
    btnChange.setTextColor(Color.DKGRAY);
    btnFunc.setTextColor(Color.GREEN);
    btnFunc.setEnabled(false);

    //      btnOk.setTextColor(Color.DKGRAY);
    //      btnOk.setTextColor(Color.GREEN);
    //      btnOk.setBackgroundResource(R.drawable.button_back_ground_color_selector);

    CommonDialog.setDlgBoxSizeLimit(dialog, true);

    // func?
    btnFunc.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            change_view.setVisibility(TextView.GONE);
            func_view.setVisibility(TextView.VISIBLE);
            CommonDialog.setDlgBoxSizeLimit(dialog, true);
            //            func_view.setEnabled(true);
            //            change_view.setEnabled(false);
            btnFunc.setTextColor(Color.GREEN);
            btnChange.setTextColor(Color.DKGRAY);
            btnChange.setEnabled(true);
            btnFunc.setEnabled(false);
        }
    });

    // change?
    btnChange.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            change_view.setVisibility(TextView.VISIBLE);
            func_view.setVisibility(TextView.GONE);
            CommonDialog.setDlgBoxSizeLimit(dialog, true);
            //            func_view.setEnabled(true);
            //            change_view.setEnabled(false);
            btnChange.setTextColor(Color.GREEN);
            btnFunc.setTextColor(Color.DKGRAY);
            btnChange.setEnabled(false);
            btnFunc.setEnabled(true);
        }
    });

    // OK?
    btnOk.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            dialog.dismiss();
        }
    });
    // Cancel?
    dialog.setOnCancelListener(new Dialog.OnCancelListener() {
        @Override
        public void onCancel(DialogInterface arg0) {
            btnOk.performClick();
        }
    });
    //      dialog.setOnKeyListener(new DialogOnKeyListener(mContext));
    //      dialog.setCancelable(false);
    dialog.show();

}