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.cettco.buycar.activity.OrderDetailActivity.java

private void initDialog() {
    final Dialog dialog = new Dialog(OrderDetailActivity.this);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setCanceledOnTouchOutside(false);
    dialog.setContentView(R.layout.popup_accept);
    dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
    dialog.show();//from   w ww  .j  av a 2  s  . com
    Button cancelBtn = (Button) dialog.findViewById(R.id.popup_accept_cancel_btn);
    cancelBtn.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub

        }
    });
    Button payBtn = (Button) dialog.findViewById(R.id.popup_accept_pay_btn);
    payBtn.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub

        }
    });
}

From source file:com.simadanesh.isatis.ScreenSlideActivity.java

private void showSearchDialog() {
    if (search_dialog == null) {
        search_dialog = new Dialog(this);
        search_dialog.setContentView(R.layout.search_view);
        search_dialog.setCancelable(true);
        Utility.applyFont(search_dialog.findViewById(R.id.panel));
        Button btnok = (Button) search_dialog.findViewById(R.id.btn_ok);
        btnok.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                executeSearch();//  ww w  .  j  a  va 2  s.  c  om
            }

        });
        Button btnCancel = (Button) search_dialog.findViewById(R.id.btn_cancel);
        btnCancel.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                search_dialog.dismiss();
            }
        });
        search_dialog.setTitle(R.string.search);
    }

    search_dialog.show();
}

From source file:reportsas.com.formulapp.Formulario.java

public void CapturaF() {
    if (parametroCam == null) {

        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        startActivityForResult(intent, 1);

    } else {/*w  w w .j  a v a2s . com*/

        final Dialog dialog = new Dialog(this);
        dialog.setContentView(R.layout.dialog_imagen);
        dialog.setTitle("Captura de Formulario");
        byte[] decodedByte = Base64.decode(parametroCam.getValor(), 0);

        ImageView imageview = (ImageView) dialog.findViewById(R.id.ImaVcaptura);
        Button Button1 = (Button) dialog.findViewById(R.id.NuevaToma);
        Button Button2 = (Button) dialog.findViewById(R.id.btn_cerrar);

        imageview.setImageBitmap(BitmapFactory.decodeByteArray(decodedByte, 0, decodedByte.length));
        Button1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                startActivityForResult(intent, 1);
                dialog.dismiss();
            }
        });

        Button2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                dialog.dismiss();
            }
        });

        dialog.show();

    }

}

From source file:com.nnm.smsviet.MessageListActivity.java

public void initDialog() {
    this.emo_dialog = new Dialog(MessageListActivity.this);
    // dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    this.emo_dialog.setTitle("Text Emoticons");
    this.emo_dialog.setCancelable(true);
    this.emo_dialog.setContentView(R.layout.emo_girdview);
    GridView gridview = (GridView) this.emo_dialog.findViewById(R.id.gridview);
    gridview.setAdapter(new EmoAdapter(this));
    this.emo_dialog.setCanceledOnTouchOutside(true);
    gridview.setOnItemClickListener(new OnItemClickListener() {

        @Override//from ww w  .  j  a  v  a 2 s. c  o m
        public void onItemClick(final AdapterView<?> arg0, final View arg1, final int arg2, final long arg3) {
            if (MessageListActivity.this.etText.getText().toString().endsWith(" ")) {
                MessageListActivity.this.etText.append(emo[arg2]);
            } else {
                MessageListActivity.this.etText.append(" " + emo[arg2]);
            }
            MessageListActivity.this.emo_dialog.cancel();
        }
    });
}

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

private void showSettings() {
    final SharedPreferences sharedPref = getPreferences(Context.MODE_PRIVATE);
    int selfReportIntervalSpinnerPosition = sharedPref.getInt("selfReportIntervalSpinnerPosition", 2);
    int selfReportVarianceSpinnerPosition = sharedPref.getInt("selfReportVarianceSpinnerPosition", 0);
    int questionnaireSpinnerPosition = sharedPref.getInt("questionnaireSpinnerPosition", 0);
    //int baselineQuestionnaireSpinnerPosition = sharedPref.getInt("baselineQuestionnaireSpinnerPosition", 0);
    String activityName = sharedPref.getString("activityName", "");
    String participantFirstName = sharedPref.getString("participantFirstName", "");
    String participantLastName = sharedPref.getString("participantLastName", "");
    boolean configureInterval = sharedPref.getBoolean("configureInterval", false);
    final Dialog dialog = new Dialog(this);
    dialog.setContentView(R.layout.settings);
    dialog.setTitle(getString(R.string.action_settings));
    dialog.setCancelable(true);//from ww  w.ja  va2s. c om
    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);
    selfReportIntervalSpinner = (Spinner) dialog.findViewById(R.id.self_report_interval_spinner);
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
            R.array.study_protocol_settings_self_report_interval_values, android.R.layout.simple_spinner_item);
    selfReportIntervalSpinner.setAdapter(adapter);
    selfReportIntervalSpinner.setSelection(selfReportIntervalSpinnerPosition);
    selfReportVarianceSpinner = (Spinner) dialog.findViewById(R.id.self_report_variance_spinner);
    ArrayAdapter<CharSequence> adapter2 = ArrayAdapter.createFromResource(this,
            R.array.study_protocol_settings_self_report_variance_values, android.R.layout.simple_spinner_item);
    selfReportVarianceSpinner.setAdapter(adapter2);
    selfReportVarianceSpinner.setSelection(selfReportVarianceSpinnerPosition);

    questionnaireSpinner = (Spinner) dialog.findViewById(R.id.questionnaireSpinner);
    //baselineQuestionnaireSpinner = (Spinner) dialog.findViewById(R.id.baseline_questionnaireSpinner);

    String[] questionnaireTitles = new String[0];
    try {
        questionnaireTitles = new String[questionnaireCount];
        for (int i = 0; i < questionnaireCount; i++) {
            String questionnaireFilename = questionnaireFilenames[i];
            String questionnairePath = "questionnaires/" + localeString + "/" + questionnaireFilename;
            try {
                JSONObject questionnaire = Utils
                        .getJSONObjectFromInputStream(getAssets().open(questionnairePath));
                String questionnaireTitle = questionnaire.getJSONObject("questionnaire").getString("title");
                questionnaireTitles[i] = questionnaireTitle;
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    ArrayAdapter<String> qSpinnerAdapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item,
            questionnaireTitles);
    questionnaireSpinner.setAdapter(qSpinnerAdapter);
    questionnaireSpinner.setSelection(questionnaireSpinnerPosition);
    //baselineQuestionnaireSpinner.setAdapter(qSpinnerAdapter);
    //baselineQuestionnaireSpinner.setSelection(baselineQuestionnaireSpinnerPosition);

    final EditText participantFirstNameEditText = (EditText) dialog
            .findViewById(R.id.participant_first_name_edit_text);
    final EditText participantLastNameEditText = (EditText) dialog
            .findViewById(R.id.participant_last_name_edit_text);
    final EditText activityNameEditText = (EditText) dialog.findViewById(R.id.activity_name_edit_text);
    participantFirstNameEditText.setText(participantFirstName);
    participantLastNameEditText.setText(participantLastName);
    activityNameEditText.setText(activityName);

    final Switch configureIntervalSwitch = (Switch) dialog.findViewById(R.id.configure_interval_switch);
    configureIntervalSwitch.setChecked(configureInterval);
    if (configureInterval) {
        dialog.findViewById(R.id.configure_interval_layout).setVisibility(View.VISIBLE);
        dialog.findViewById(R.id.configure_variance_layout).setVisibility(View.VISIBLE);
    } else {
        dialog.findViewById(R.id.configure_interval_layout).setVisibility(View.GONE);
        dialog.findViewById(R.id.configure_variance_layout).setVisibility(View.GONE);
    }

    Button saveButton = (Button) dialog.findViewById(R.id.saveButton);
    saveButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            selfReportInterval = Integer.valueOf(selfReportIntervalSpinner.getSelectedItem().toString());
            selfReportVariance = Integer.valueOf(selfReportVarianceSpinner.getSelectedItem().toString());

            MainActivity.this.participantFirstName = participantFirstNameEditText.getText().toString().trim();
            MainActivity.this.participantLastName = participantLastNameEditText.getText().toString().trim();
            MainActivity.this.activityName = activityNameEditText.getText().toString().trim();
            MainActivity.this.intervalConfigured = configureIntervalSwitch.isChecked();

            SharedPreferences.Editor editor = sharedPref.edit();
            editor.putInt("selfReportIntervalSpinnerPosition",
                    selfReportIntervalSpinner.getSelectedItemPosition());
            editor.putInt("selfReportVarianceSpinnerPosition",
                    selfReportVarianceSpinner.getSelectedItemPosition());
            editor.putInt("questionnaireSpinnerPosition", questionnaireSpinner.getSelectedItemPosition());
            //editor.putInt("baselineQuestionnaireSpinnerPosition", baselineQuestionnaireSpinner.getSelectedItemPosition());
            editor.putInt("selfReportInterval",
                    Integer.valueOf(selfReportIntervalSpinner.getSelectedItem().toString()));
            editor.putInt("selfReportVariance",
                    Integer.valueOf(selfReportVarianceSpinner.getSelectedItem().toString()));

            editor.putString("participantFirstName", participantFirstNameEditText.getText().toString().trim());
            editor.putString("participantLastName", participantLastNameEditText.getText().toString().trim());
            editor.putString("activityName", activityNameEditText.getText().toString().trim());
            editor.putBoolean("configureInterval", configureIntervalSwitch.isChecked());
            editor.apply();

            dialog.dismiss();
        }
    });

    configureIntervalSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                dialog.findViewById(R.id.configure_interval_layout).setVisibility(View.VISIBLE);
                dialog.findViewById(R.id.configure_variance_layout).setVisibility(View.VISIBLE);
            } else {
                dialog.findViewById(R.id.configure_interval_layout).setVisibility(View.GONE);
                dialog.findViewById(R.id.configure_variance_layout).setVisibility(View.GONE);
            }
        }
    });
    dialog.show();
}

From source file:cs.umass.edu.prepare.view.activities.CalendarActivity.java

/**
 * Allows the user to set time for adherence data where the time is unknown.
 * @param medication the medication for which the adherence is being modified.
 * @param index the index of the adherence being modified, i.e. AM or PM.
 *///from w w  w.  jav a 2s  .com
private void setTimeTaken(final Medication medication, final Calendar dateKey, final int index) {
    final Dialog dialog = new Dialog(this);
    dialog.setContentView(R.layout.dialog_set_time);

    final TimePicker timePicker = (TimePicker) dialog.findViewById(R.id.time_picker);

    Button cancelButton = (Button) dialog.findViewById(R.id.btn_time_cancel);
    cancelButton.setOnClickListener(v -> dialog.dismiss());

    Button saveButton = (Button) dialog.findViewById(R.id.btn_time_save);
    saveButton.setOnClickListener(v -> {
        Calendar time = Utils.getTimeNoInterval(timePicker); // TODO: Store times taken
        Map<Medication, Adherence[]> dailyAdherence = adherenceData.get(dateKey);
        Adherence[] adherence = dailyAdherence.get(medication);
        adherence[index].setTimeTaken(time);

        Calendar[] schedule = dailySchedule.get(medication);
        Calendar timeToTake = (Calendar) time.clone();
        timeToTake.set(Calendar.HOUR_OF_DAY, schedule[index].get(Calendar.HOUR_OF_DAY));
        timeToTake.set(Calendar.MINUTE, schedule[index].get(Calendar.MINUTE));
        Calendar upperBound = (Calendar) timeToTake.clone();
        upperBound.add(Calendar.HOUR_OF_DAY, 1);
        Calendar lowerBound = (Calendar) timeToTake.clone();
        lowerBound.add(Calendar.HOUR_OF_DAY, -1);

        if (time.after(upperBound) || time.before(lowerBound)) {
            adherence[index].setAdherenceType(Adherence.AdherenceType.TAKEN_EARLY_OR_LATE);
        } else {
            adherence[index].setAdherenceType(Adherence.AdherenceType.TAKEN);
        }

        dialog.dismiss();
        refresh();

        DataIO preferences = DataIO.getInstance(CalendarActivity.this);
        preferences.setAdherenceData(this, adherenceData);
    });

    dialog.show();
}

From source file:com.sentaroh.android.Utilities.LogUtil.CommonLogFileListDialogFragment.java

private void confirmSendLog() {
    CommonLogUtil.flushLog(mContext, mGp);
    mThemeColorList = ThemeUtil.getThemeColorList(getActivity());
    createTempLogFile();/*from  w w w  .  java  2 s.  c o  m*/

    final Dialog dialog = new Dialog(getActivity());
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setContentView(R.layout.confirm_send_log_dlg);
    dialog.setCanceledOnTouchOutside(false);

    LinearLayout title_view = (LinearLayout) dialog.findViewById(R.id.confirm_send_log_dlg_title_view);
    title_view.setBackgroundColor(mThemeColorList.dialog_title_background_color);
    TextView title = (TextView) dialog.findViewById(R.id.confirm_send_log_dlg_title);
    title.setTextColor(mThemeColorList.text_color_dialog_title);
    TextView msg = (TextView) dialog.findViewById(R.id.confirm_send_log_dlg_msg);
    msg.setTextColor(mThemeColorList.text_color_info);
    msg.setBackgroundColor(mThemeColorList.dialog_msg_background_color);

    final Button btn_ok = (Button) dialog.findViewById(R.id.confirm_send_log_dlg_ok_btn);
    final Button btn_cancel = (Button) dialog.findViewById(R.id.confirm_send_log_dlg_cancel_btn);
    final Button btn_preview = (Button) dialog.findViewById(R.id.confirm_send_log_dlg_preview);

    CommonDialog.setDlgBoxSizeLimit(dialog, false);

    btn_preview.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View arg0) {
            Intent intent = new Intent(android.content.Intent.ACTION_VIEW);
            intent.setDataAndType(Uri.parse("file://" + mGp.getLogDirName() + "temp_log.txt"), "text/plain");
            startActivity(intent);
        }
    });

    btn_ok.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View arg0) {
            sendLogFileToDeveloper(mGp.getLogDirName() + "temp_log.txt");
            dialog.dismiss();
        }
    });

    btn_cancel.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View arg0) {
            dialog.dismiss();
        }
    });

    dialog.setOnCancelListener(new OnCancelListener() {
        @Override
        public void onCancel(DialogInterface arg0) {
            btn_cancel.performClick();
        }
    });

    dialog.show();

}

From source file:com.ibm.hellotodoadvanced.MainActivity.java

/**
 * Launches a dialog for adding a new TodoItem. Called when plus button is tapped.
 *
 * @param view The plus button that is tapped.
 *///from w  w w.  j  a  v a2s .co  m
public void addTodo(View view) {

    final Dialog addDialog = new Dialog(this);

    // UI settings for dialog pop-up
    addDialog.setContentView(R.layout.add_edit_dialog);
    addDialog.setTitle("Add Todo");
    TextView textView = (TextView) addDialog.findViewById(android.R.id.title);
    if (textView != null) {
        textView.setGravity(Gravity.CENTER);
    }
    addDialog.setCancelable(true);
    Button add = (Button) addDialog.findViewById(R.id.Add);
    addDialog.show();

    // When done is pressed, send POST request to create TodoItem on Bluemix
    add.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            EditText itemToAdd = (EditText) addDialog.findViewById(R.id.todo);
            final String name = itemToAdd.getText().toString();
            // If text was added, continue with normal operations
            if (!name.isEmpty()) {

                // Create JSON for new TodoItem, id should be 0 for new items
                String json = "{\"text\":\"" + name + "\",\"isDone\":false,\"id\":0}";

                // Create POST request with the Bluemix Mobile Services SDK and set HTTP headers so Bluemix knows what to expect in the request
                Request request = new Request(bmsClient.getBluemixAppRoute() + "/api/Items", Request.POST);

                HashMap headers = new HashMap();
                List<String> contentType = new ArrayList<>();
                contentType.add("application/json");
                List<String> accept = new ArrayList<>();
                accept.add("Application/json");

                headers.put("Content-Type", contentType);
                headers.put("Accept", accept);

                request.setHeaders(headers);

                request.send(getApplicationContext(), json, new ResponseListener() {
                    // On success, update local list with new TodoItem
                    @Override
                    public void onSuccess(Response response) {
                        Log.i(TAG, "Item " + name + " created successfully");

                        loadList();
                    }

                    // On failure, log errors
                    @Override
                    public void onFailure(Response response, Throwable throwable, JSONObject extendedInfo) {
                        String errorMessage = "";

                        if (response != null) {
                            errorMessage += response.toString() + "\n";
                        }

                        if (throwable != null) {
                            StringWriter sw = new StringWriter();
                            PrintWriter pw = new PrintWriter(sw);
                            throwable.printStackTrace(pw);
                            errorMessage += "THROWN" + sw.toString() + "\n";
                        }

                        if (extendedInfo != null) {
                            errorMessage += "EXTENDED_INFO" + extendedInfo.toString() + "\n";
                        }

                        if (errorMessage.isEmpty())
                            errorMessage = "Request Failed With Unknown Error.";

                        Log.e(TAG, "addTodo failed with error: " + errorMessage);
                    }
                });
            }

            // Close dialog when finished, or if no text was added
            addDialog.dismiss();
        }
    });
}

From source file:com.jinrustar.sky.main.MainActivity.java

private void showDilogTips() {
    if (dialog == null)
        dialog = new Dialog(context);
    dialog.getContext().setTheme(R.style.custom);
    dialog.setContentView(R.layout.layout_dialog_base);
    dialog.setTitle(R.string.toast_scan_tips);
    dialog.getWindow().setGravity(Gravity.CENTER);
    dialog.getWindow().setLayout(dialog.getWindow().getWindowManager().getDefaultDisplay().getWidth() - 150,
            WindowUtils.getScreenWidthAndHeight()[1] / 2);
    dialog.findViewById(R.id.tv_title1).setOnClickListener(new View.OnClickListener() {
        @Override/*ww w .j  a  v a 2 s.  com*/
        public void onClick(View v) {
            Intent intent = new Intent(context, QRScanActivity.class);
            startActivityForResult(intent, 0x57);
            dialog.dismiss();
        }
    });
    dialog.findViewById(R.id.tv_title2).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            dialog.dismiss();
        }
    });
    dialog.show();
}