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:es.javocsoft.android.lib.toolbox.ToolBox.java

/**
 * "Coach mark" (help overlay image)/*from www.  j a v a  2s.  c  om*/
 * 
 * @param context
 * @param coachMarkLayoutId   Is "Help overlay" layout id in UX talk :-) 
 *             [coach_mark.xml is your coach mark layout]
 * @param coachMarkMasterViewId   is the id of the top most view in coach_mark.xml
 */
public static void dialog_onCoachMark(Context context, int coachMarkLayoutId, int coachMarkMasterViewId,
        int bgColor) {

    final Dialog dialog = new Dialog(context);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.getWindow().setBackgroundDrawable(new ColorDrawable(bgColor));
    dialog.setContentView(coachMarkLayoutId);
    dialog.setCanceledOnTouchOutside(true);

    //for dismissing anywhere you touch
    View masterView = dialog.findViewById(coachMarkMasterViewId);
    masterView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            dialog.dismiss();
        }
    });

    dialog.show();
}

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

public static void putOrder(final Context ctx, Quote quote) {

    final Instrument it = Common.selectedInstrument;// adapter.getItem(selectedRowId);

    final Dialog dialog = new Dialog(ctx);
    dialog.setContentView(R.layout.order_dialog);
    dialog.setTitle(R.string.OrderDialogTitle);

    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  av a  2 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(it.symbol);

    final Spinner aspinner = (Spinner) dialog.findViewById(R.id.acc_spinner);
    List<String> list = new ArrayList<String>(Common.getAccountList());
    ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(Common.app_ctx,
            android.R.layout.simple_spinner_item, list);
    dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_item);
    aspinner.setAdapter(dataAdapter);

    final EditText pricetxt = (EditText) dialog.findViewById(R.id.priceedit);
    final EditText quanttxt = (EditText) dialog.findViewById(R.id.quantedit);

    final Button buttonpm = (Button) dialog.findViewById(R.id.buttonPriceMinus);
    buttonpm.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {

            try {

                double price = Double.valueOf(pricetxt.getText().toString());
                price -= 0.01;
                if (price < 0)
                    price = 0;
                pricetxt.setText(twoDForm.format(price));

            } catch (Exception e) {

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

    final Button buttonpp = (Button) dialog.findViewById(R.id.buttonPricePlus);
    buttonpp.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {

            try {

                double price = Double.valueOf(pricetxt.getText().toString());
                price += 0.01;
                pricetxt.setText(twoDForm.format(price));

            } catch (Exception e) {

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

    final Button buttonqm = (Button) dialog.findViewById(R.id.buttonQtyMinus);
    buttonqm.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {

            try {

                long qty = Long.valueOf(quanttxt.getText().toString());
                qty -= 1;
                if (qty < 0)
                    qty = 0;
                quanttxt.setText(String.valueOf(qty));

            } catch (Exception e) {

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

    final Button buttonqp = (Button) dialog.findViewById(R.id.buttonQtyPlus);
    buttonqp.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {

            try {

                long qty = Long.valueOf(quanttxt.getText().toString());
                qty += 1;
                quanttxt.setText(String.valueOf(qty));

            } catch (Exception e) {

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

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

    if (quote != null) {

        // pricetxt.setText(quote.price.toString());
        pricetxt.setText(quote.getPriceS());
        if (quote.qtyBuy > 0) {

            quanttxt.setText(quote.qtyBuy.toString());
            bu1.setChecked(true);
            bu0.setChecked(false);

        } else {

            quanttxt.setText(quote.qtySell.toString());
            bu1.setChecked(false);
            bu0.setChecked(true);

        }
    }

    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);

            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;

            }

            JSONObject msg = new JSONObject();
            try {

                msg.put("objType", Common.CREATE_REMOVE_ORDER);
                msg.put("time", Calendar.getInstance().getTimeInMillis());
                msg.put("version", Common.PROTOCOL_VERSION);
                msg.put("device", "Android");
                msg.put("instrumId", Long.valueOf(it.id));
                msg.put("price", price);
                msg.put("qty", qval);
                msg.put("ordType", 1);
                msg.put("side", bu0.isChecked() ? 0 : 1);
                msg.put("code", String.valueOf(aspinner.getSelectedItem()));
                msg.put("orderNum", ++ordernum);
                msg.put("action", "CREATE");
                boolean b = (((mYear - 1900) == dat.getYear()) && (mMonth == dat.getMonth())
                        && (mDay == dat.getDate()));
                if (!b)
                    msg.put("expired", String.format("%02d.%02d.%04d", mDay, mMonth + 1, mYear));

                if (isSSL) {

                    //                ? ?:    newOrder-orderNum-instrumId-side-price-qty-code-ordType
                    //               :                  newOrder-16807-20594623-0-1150-13-1027700451-1
                    String forsign = "newOrder-" + ordernum + "-" + msg.getString("instrumId") + "-"
                            + msg.getString("side") + "-"
                            + JSONObject.numberToString(Double.valueOf(msg.getDouble("price"))) + "-"
                            + msg.getString("qty") + "-" + msg.getString("code") + "-"
                            + msg.getString("ordType");
                    byte[] signed = Common.signText(Common.signProfile, forsign.getBytes(), true);
                    String gsign = Base64.encodeToString(signed, Base64.DEFAULT);
                    msg.put("gostSign", gsign);
                }
                mainActivity.writeJSONMsg(msg);

            } catch (Exception e) {

                e.printStackTrace();
                Log.e(TAG, "Error! Cannot create JSON order object", e);
            }

            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.sentaroh.android.Utilities.Dialog.SafFileSelectDialogFragment.java

private void fileSelectEditDialogCreateBtn(final Activity activity, final Context context, final String c_dir,
        String n_dir, final TreeFilelistAdapter tfa, final NotifyEvent p_ntfy, final ListView lv) {
    // ??//from   w ww . j  av  a2 s.  c o  m
    mCreateDirDialog = new Dialog(activity);
    mCreateDirDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    mCreateDirDialog.setContentView(R.layout.single_item_input_dlg);
    final TextView dlg_title = (TextView) mCreateDirDialog.findViewById(R.id.single_item_input_title);
    dlg_title.setText(context.getString(R.string.msgs_file_select_edit_dlg_create));
    final TextView dlg_msg = (TextView) mCreateDirDialog.findViewById(R.id.single_item_input_msg);
    final TextView dlg_cmp = (TextView) mCreateDirDialog.findViewById(R.id.single_item_input_name);
    final CheckedTextView dlg_type = (CheckedTextView) mCreateDirDialog
            .findViewById(R.id.single_item_input_type);
    setCheckedTextView(dlg_type);
    dlg_type.setVisibility(CheckedTextView.VISIBLE);
    dlg_type.setText(context.getString(R.string.msgs_file_select_edit_dlg_dir_create_file));
    final Button btnOk = (Button) mCreateDirDialog.findViewById(R.id.single_item_input_ok_btn);
    final Button btnCancel = (Button) mCreateDirDialog.findViewById(R.id.single_item_input_cancel_btn);
    final EditText etDir = (EditText) mCreateDirDialog.findViewById(R.id.single_item_input_dir);

    dlg_cmp.setText(context.getString(R.string.msgs_file_select_edit_parent_directory) + ":" + c_dir);
    CommonDialog.setDlgBoxSizeCompact(mCreateDirDialog);
    etDir.setText(n_dir.replaceAll(c_dir, ""));
    btnOk.setEnabled(false);
    etDir.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }

        @Override
        public void afterTextChanged(Editable s) {
            if (s.length() > 0) {
                //               SafFile lf=mSafFileMgr.getSafFileBySdcardPath(mDialogSafRoot, c_dir+"/"+s.toString(), true);
                SafFile lf = mSafFileMgr.getSafFileBySdcardPath(mDialogSafRoot, c_dir, true);
                SafFile[] c_fl = lf.listFiles();
                boolean found = false;
                for (SafFile item : c_fl) {
                    if (item.getName().equals(s.toString())) {
                        found = true;
                        break;
                    }
                }
                //               Log.v("","fp="+lf.getPath());
                if (found) {
                    btnOk.setEnabled(false);
                    dlg_msg.setText(context.getString(R.string.msgs_single_item_input_dlg_duplicate_dir));
                } else {
                    btnOk.setEnabled(true);
                    dlg_msg.setText("");
                }
            }
        }

    });

    //OK button
    btnOk.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            //            NotifyEvent 
            final String creat_dir = etDir.getText().toString();
            final String n_path = c_dir + "/" + creat_dir;
            NotifyEvent ntfy = new NotifyEvent(context);
            ntfy.setListener(new NotifyEventListener() {
                @Override
                public void positiveResponse(Context c, Object[] o) {
                    boolean rc_create = false;
                    if (!dlg_type.isChecked()) {
                        Log.v("", "n_path=" + n_path);
                        SafFile sf = mSafFileMgr.getSafFileBySdcardPath(mSafFileMgr.getSdcardSafFile(), n_path,
                                true);
                        rc_create = sf.exists();
                    } else {
                        SafFile sf = mSafFileMgr.getSafFileBySdcardPath(mSafFileMgr.getSdcardSafFile(), n_path,
                                false);
                        rc_create = sf.exists();
                    }
                    if (!rc_create) {
                        dlg_msg.setText(String.format(
                                context.getString(R.string.msgs_file_select_edit_dlg_dir_not_created),
                                etDir.getText()));
                        return;
                    } else {
                        //                     String[] a_dir=creat_dir.startsWith("/")?creat_dir.substring(1).split("/"):creat_dir.split("/");
                        String[] a_dir = n_path.startsWith("/") ? n_path.substring(1).split("/")
                                : n_path.split("/");
                        String p_dir = "/", sep = "";
                        for (int i = 0; i < a_dir.length; i++) {
                            if (a_dir[i] != null && !a_dir[i].equals("")) {
                                //                           Log.v("","p_dir="+p_dir);
                                updateTreeFileList(p_dir, a_dir[i], c_dir, tfa, lv);
                                p_dir += sep + a_dir[i];
                                sep = "/";
                            }
                        }
                        mCreateDirDialog.dismiss();
                        mCreateDirDialog = null;
                        p_ntfy.notifyToListener(true, new Object[] { etDir.getText().toString() });
                    }
                }

                @Override
                public void negativeResponse(Context c, Object[] o) {
                }
            });
            CommonDialog cd = new CommonDialog(context, getFragmentManager());
            if (dlg_type.isChecked())
                cd.showCommonDialog(true, "W",
                        context.getString(R.string.msgs_file_select_edit_confirm_create_file), n_path, ntfy);
            else
                cd.showCommonDialog(true, "W",
                        context.getString(R.string.msgs_file_select_edit_confirm_create_directory), n_path,
                        ntfy);
        }
    });
    // CANCEL?
    btnCancel.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            mCreateDirDialog.dismiss();
            //            Log.v("","cancel create");
            mCreateDirDialog = null;
            p_ntfy.notifyToListener(false, null);
        }
    });
    mCreateDirDialog.show();
}

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

/**
 * Prompt the user to rate the app./*from   w ww .  j av a  2s.com*/
 * 
 * @param context
 */
public static void displayRating(final Launcher context) {
    SharedPreferences prefs = context.getSharedPreferences(Launcher.PREFERENCES_NAME, Activity.MODE_PRIVATE);

    if (prefs.getBoolean(DONT_SHOW_RATING_AGAIN, false)) {
        return;
    }

    final SharedPreferences.Editor editor = prefs.edit();

    // Get date of first launch
    Long date_firstLaunch = prefs.getLong(DATE_FIRST_LAUNCHED, 0);
    if (date_firstLaunch == 0) {
        date_firstLaunch = System.currentTimeMillis();
        editor.putLong(DATE_FIRST_LAUNCHED, date_firstLaunch);
    }

    // Wait at least n days before opening
    if (System.currentTimeMillis() >= date_firstLaunch + (DAYS_UNTIL_PROMPT * 24 * 60 * 60 * 1000)) {
        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.rating_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) {
                Intent intent = new Intent(Intent.ACTION_VIEW,
                        Uri.parse("market://details?id=com.entertailion.android.launcher"));
                context.startActivity(intent);
                if (editor != null) {
                    editor.putBoolean(DONT_SHOW_RATING_AGAIN, true);
                    editor.commit();
                }
                Analytics.logEvent(Analytics.RATING_YES);
                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) {
                if (editor != null) {
                    editor.putBoolean(DONT_SHOW_RATING_AGAIN, true);
                    editor.commit();
                }
                Analytics.logEvent(Analytics.RATING_NO);
                context.showCover(false);
                dialog.dismiss();
            }

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

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

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

    editor.commit();
}

From source file:co.taqat.call.CallActivity.java

private void showAcceptCallUpdateDialog() {
    final Dialog dialog = new Dialog(this);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    Drawable d = new ColorDrawable(ContextCompat.getColor(this, R.color.colorC));
    d.setAlpha(200);//from   ww  w  .  j a v  a  2s  .co m
    dialog.setContentView(R.layout.dialog);
    dialog.getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT,
            WindowManager.LayoutParams.MATCH_PARENT);
    dialog.getWindow().setBackgroundDrawable(d);

    TextView customText = (TextView) dialog.findViewById(R.id.customText);
    customText.setText(getResources().getString(R.string.add_video_dialog));
    Button delete = (Button) dialog.findViewById(R.id.delete_button);
    delete.setText(R.string.accept);
    Button cancel = (Button) dialog.findViewById(R.id.cancel);
    cancel.setText(R.string.decline);

    delete.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            int camera = getPackageManager().checkPermission(Manifest.permission.CAMERA, getPackageName());
            Log.i("[Permission] Camera permission is "
                    + (camera == PackageManager.PERMISSION_GRANTED ? "granted" : "denied"));

            if (camera == PackageManager.PERMISSION_GRANTED) {
                CallActivity.instance().acceptCallUpdate(true);
            } else {
                checkAndRequestPermission(Manifest.permission.CAMERA, PERMISSIONS_REQUEST_CAMERA);
            }

            dialog.dismiss();
        }
    });

    cancel.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            if (CallActivity.isInstanciated()) {
                CallActivity.instance().acceptCallUpdate(false);
            }
            dialog.dismiss();
        }
    });
    dialog.show();
}

From source file:es.javocsoft.android.lib.toolbox.ToolBox.java

public static void view_showAboutDialog(Context context, int titleResourceId, int aboutLayout, int okButtonId) {
    final Dialog dialog = new Dialog(context);
    dialog.setContentView(aboutLayout);/*from   w w  w .ja v  a  2s  . c o m*/
    dialog.setTitle(titleResourceId);

    Button dialogButton = (Button) dialog.findViewById(okButtonId);
    dialogButton.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            dialog.dismiss();
        }
    });

    dialog.show();
}

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

public void showOverRecoveryInstructions() {
    final AlertDialog.Builder Instructions = new AlertDialog.Builder(mContext);
    Instructions.setTitle(R.string.info).setMessage(R.string.flash_over_recovery)
            .setPositiveButton(R.string.positive, new DialogInterface.OnClickListener() {
                @Override//from  ww w .  j  a va 2s.c o m
                public void onClick(DialogInterface dialog, int which) {
                    try {
                        mToolbox.reboot(Toolbox.REBOOT_RECOVERY);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }).setNeutralButton(R.string.instructions, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    Dialog d = new Dialog(mContext);
                    d.setTitle(R.string.instructions);
                    TextView tv = new TextView(mContext);
                    tv.setTextSize(20);
                    tv.setText(R.string.instruction);
                    d.setContentView(tv);
                    d.setOnCancelListener(new DialogInterface.OnCancelListener() {
                        @Override
                        public void onCancel(DialogInterface dialog) {
                            Instructions.show();
                        }
                    });
                    d.show();
                }
            }).show();
}

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

/**
 * Display dialog to allow user to select which row to add the shortcut. For
 * TV channels let the user change the channel name.
 * /*from  www.j  ava 2 s. co  m*/
 * @see InstallShortcutReceiver
 * 
 * @param context
 * @param name
 * @param icon
 * @param uri
 */
public static void displayShortcutsRowSelection(final Launcher context, final String name, final String icon,
        final String uri) {
    if (uri == null) {
        return;
    }
    final Dialog dialog = new Dialog(context);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    final boolean isChannel = uri.startsWith("tv");
    dialog.setContentView(R.layout.select_row);

    final TextView channelTextView = (TextView) dialog.findViewById(R.id.channelText);
    final EditText channelNameEditText = (EditText) dialog.findViewById(R.id.channelName);
    if (isChannel) {
        channelTextView.setVisibility(View.VISIBLE);
        channelNameEditText.setVisibility(View.VISIBLE);
        channelNameEditText.setText(name);
    }

    final TextView selectTextView = (TextView) dialog.findViewById(R.id.selectText);
    selectTextView.setText(context.getString(R.string.dialog_select_row, name));

    final Spinner spinner = (Spinner) dialog.findViewById(R.id.spinner);

    final EditText nameEditText = (EditText) dialog.findViewById(R.id.rowName);
    final RadioButton currentRadioButton = (RadioButton) dialog.findViewById(R.id.currentRadio);
    currentRadioButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // hide the row name edit field if the current row radio button
            // is selected
            nameEditText.setVisibility(View.GONE);
            spinner.setVisibility(View.VISIBLE);
        }

    });
    final RadioButton newRadioButton = (RadioButton) dialog.findViewById(R.id.newRadio);
    newRadioButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // show the row name edit field if the new radio button is
            // selected
            nameEditText.setVisibility(View.VISIBLE);
            nameEditText.requestFocus();
            spinner.setVisibility(View.GONE);
        }

    });

    List<String> list = new ArrayList<String>();
    final ArrayList<RowInfo> rows = RowsTable.getRows(context);
    if (rows != null) {
        for (RowInfo row : rows) {
            list.add(row.getTitle());
        }
    }
    ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(context, R.layout.simple_spinner_item, list);
    dataAdapter.setDropDownViewResource(R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(dataAdapter);

    Button buttonYes = (Button) dialog.findViewById(R.id.buttonOk);
    buttonYes.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            String shortcutName = name;
            try {
                if (isChannel) {
                    String channelName = channelNameEditText.getText().toString().trim();
                    if (channelName.length() == 0) {
                        channelNameEditText.requestFocus();
                        displayAlert(context, context.getString(R.string.dialog_channel_name_alert));
                        return;
                    }
                    shortcutName = channelName;
                }
                // if the new row radio button is selected, the user must
                // enter a name for the new row
                String rowName = nameEditText.getText().toString().trim();
                if (newRadioButton.isChecked() && rowName.length() == 0) {
                    nameEditText.requestFocus();
                    displayAlert(context, context.getString(R.string.dialog_new_row_name_alert));
                    return;
                }
                boolean currentRow = !newRadioButton.isChecked();
                int rowId = 0;
                int rowPosition = 0;
                if (currentRow) {
                    if (rows != null) {
                        String selectedRow = (String) spinner.getSelectedItem();
                        for (RowInfo row : rows) {
                            if (row.getTitle().equals(selectedRow)) {
                                rowId = row.getId();
                                ArrayList<ItemInfo> items = ItemsTable.getItems(context, rowId);
                                rowPosition = items.size(); // in last
                                // position
                                // for selected
                                // row
                                break;
                            }
                        }
                    }
                } else {
                    rowId = (int) RowsTable.insertRow(context, rowName, 0, RowInfo.FAVORITE_TYPE);
                    rowPosition = 0;
                }

                Intent intent = new Intent(Intent.ACTION_VIEW);
                intent.setData(Uri.parse(uri));
                ItemsTable.insertItem(context, rowId, rowPosition, shortcutName, intent, icon,
                        DatabaseHelper.SHORTCUT_TYPE);
                Toast.makeText(context, context.getString(R.string.shortcut_installed, shortcutName),
                        Toast.LENGTH_SHORT).show();
                context.reloadAllGalleries();

                if (currentRow) {
                    Analytics.logEvent(Analytics.ADD_SHORTCUT);
                } else {
                    Analytics.logEvent(Analytics.ADD_SHORTCUT_WITH_ROW);
                }

            } catch (Exception e) {
                Log.d(LOG_TAG, "onClick", e);
            }

            context.showCover(false);
            dialog.dismiss();
        }

    });
    Button buttonNo = (Button) dialog.findViewById(R.id.buttonCancel);
    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_ADD_SHORTCUT);
}

From source file:de.bogutzky.psychophysiocollector.app.MainActivity.java

private void showGraph(String bluetoothDeviceAddress, int requestCode, int which) {
    int beginAtField = 0;
    GraphView graphView = null;//from   w ww.j  a v a  2 s.c o  m
    Dialog dialog = null;
    switch (requestCode) {
    case REQUEST_MAIN_COMMAND_SHIMMER:
        beginAtField = 1;
        switch (which) {
        case 1:
            beginAtField = 4;
            break;
        }

        graphView = new GraphView(this, beginAtField);
        if (this.shimmerImuService != null) {
            if (!isSessionStarted)
                this.startStreamingOfAllShimmerImus(false);
            this.shimmerImuService.startDataVisualization(bluetoothDeviceAddress, graphView);
        }
        dialog = new Dialog(this);
        dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
            @Override
            public void onDismiss(DialogInterface dialog) {
                if (shimmerImuService != null) {
                    shimmerImuService.stopDataVisualization();
                }
                if (!isSessionStarted) {
                    stopAllStreamingOfAllShimmerImus();
                }
            }
        });
        break;
    case REQUEST_MAIN_COMMAND_BIOHARNESS:
        graphView = new GraphView(this, beginAtField);
        if (this.bioHarnessService != null) {
            this.bioHarnessService.startDataVisualization(graphView);
        }
        dialog = new Dialog(this);
        dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
            @Override
            public void onDismiss(DialogInterface dialog) {
                if (bioHarnessService != null) {
                    bioHarnessService.stopDataVisualization();
                }
            }
        });
        break;
    }

    assert dialog != null;
    dialog.setContentView(graphView);
    dialog.setTitle(getString(R.string.graph));
    dialog.setCancelable(true);
    WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
    lp.copyFrom(dialog.getWindow().getAttributes());
    lp.width = WindowManager.LayoutParams.MATCH_PARENT;
    lp.height = WindowManager.LayoutParams.MATCH_PARENT;
    dialog.getWindow().setAttributes(lp);

    dialog.show();
}

From source file:com.sentaroh.android.SMBSync2.SyncTaskUtility.java

public void showSelectSdcardMsg(final NotifyEvent ntfy, String msg) {
    final Dialog dialog = new Dialog(mContext);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setContentView(R.layout.show_select_sdcard_dlg);

    final LinearLayout title_view = (LinearLayout) dialog.findViewById(R.id.show_select_sdcard_dlg_title_view);
    final TextView title = (TextView) dialog.findViewById(R.id.show_select_sdcard_dlg_title);
    title_view.setBackgroundColor(mGp.themeColorList.dialog_title_background_color);
    title.setTextColor(mGp.themeColorList.text_color_dialog_title);

    final TextView dlg_msg = (TextView) dialog.findViewById(R.id.show_select_sdcard_dlg_msg);
    dlg_msg.setText(msg);/*from  ww w .  ja  v a2  s .  co m*/
    ;

    final ImageView func_view = (ImageView) dialog.findViewById(R.id.show_select_sdcard_dlg_image);

    try {
        InputStream is = mContext.getResources().getAssets()
                .open(mContext.getString(R.string.msgs_main_external_sdcard_select_required_select_msg_file));
        Bitmap bm = BitmapFactory.decodeStream(is);
        func_view.setImageBitmap(bm);
    } catch (IOException e) {
        /* ? */
    }

    final Button btnOk = (Button) dialog.findViewById(R.id.show_select_sdcard_dlg_btn_ok);
    final Button btnCancel = (Button) dialog.findViewById(R.id.show_select_sdcard_dlg_btn_cancel);

    CommonDialog.setDlgBoxSizeLimit(dialog, true);

    // OK?
    btnOk.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            dialog.dismiss();
            ntfy.notifyToListener(true, null);
        }
    });
    // Cancel?
    btnCancel.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            dialog.dismiss();
            ntfy.notifyToListener(false, null);
        }
    });
    // Cancel?
    dialog.setOnCancelListener(new Dialog.OnCancelListener() {
        @Override
        public void onCancel(DialogInterface arg0) {
            btnCancel.performClick();
        }
    });

    dialog.show();

}