Example usage for android.app AlertDialog dismiss

List of usage examples for android.app AlertDialog dismiss

Introduction

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

Prototype

@Override
public void dismiss() 

Source Link

Document

Dismiss this dialog, removing it from the screen.

Usage

From source file:com.fitme.MainActivity.java

public void onExerciseCreationRequested(final String trainName, final TrainingsListAdapter tla) {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(R.string.title_add_exercise_dialog);
    View view = getLayoutInflater().inflate(R.layout.dialog_add_exercise, null);
    builder.setView(view);/*from  w w  w .j  a v  a  2s.c  om*/
    builder.setPositiveButton(android.R.string.ok, null);
    builder.setNegativeButton(android.R.string.cancel, null);
    final AlertDialog dialogEx = builder.create();
    dialogEx.setOnShowListener(new DialogInterface.OnShowListener() {

        @Override
        public void onShow(DialogInterface dialog) {
            Button positive = dialogEx.getButton(AlertDialog.BUTTON_POSITIVE);
            positive.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    Spinner spinMuscleGroup = (Spinner) dialogEx.findViewById(R.id.spinner_select_mg_ex);
                    Spinner spinExName = (Spinner) dialogEx.findViewById(R.id.spinner_select_ex);
                    NumberPicker numpickRepeats = (NumberPicker) dialogEx
                            .findViewById(R.id.numberpicker_repeats_ex);
                    //Since we decide to have all spinners pre-populated no need to check data
                    Exercise e = new Exercise();
                    e.setName(spinExName.getSelectedItem().toString());
                    e.setMuscleGroup(spinMuscleGroup.getSelectedItem().toString());
                    e.setRepeats(numpickRepeats.getValue());
                    //Identifying program and training
                    long programId = MainActivity.this.getActiveProgramId();
                    TrainingDAO td = new TrainingDAO(MainActivity.this);
                    long trId = td.getTrainingByName(programId, trainName).getId();
                    e.setTrainId(trId);

                    //Insert new entry to db
                    ExerciseDAO ed = new ExerciseDAO(MainActivity.this);
                    long exId = ed.createExercise(e).getId();
                    e.setId(exId);
                    Toast.makeText(MainActivity.this, getText(R.string.toast_add_exercise_ok),
                            Toast.LENGTH_SHORT).show();
                    tla.addExercise(e, trainName);
                    dialogEx.dismiss();
                }
            });

        }
    });
    dialogEx.show();
    // Populate dialog fields
    NumberPicker np = (NumberPicker) dialogEx.findViewById(R.id.numberpicker_repeats_ex);
    final Spinner spinMuscleGroup = (Spinner) dialogEx.findViewById(R.id.spinner_select_mg_ex);
    final Spinner spinExName = (Spinner) dialogEx.findViewById(R.id.spinner_select_ex);
    np.setMaxValue(Exercise.MAX_REPEATS);
    np.setMinValue(Exercise.MIN_REPEATS);

    //Filling muscle groups spinner
    String[] muscleGroups = getResources().getStringArray(R.array.muscle_groups);

    ArrayAdapter<String> mgAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item,
            muscleGroups);
    spinMuscleGroup.setAdapter(mgAdapter);

    spinMuscleGroup.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
            String arrayName = ("exercises_" + spinMuscleGroup.getSelectedItem().toString()).toLowerCase();
            int id = getResources().getIdentifier(arrayName, "array", MainActivity.this.getPackageName());
            String[] exercises = getResources().getStringArray(id);
            ArrayAdapter<String> exAdapter = new ArrayAdapter<String>(MainActivity.this,
                    android.R.layout.simple_spinner_item, exercises);
            spinExName.setAdapter(exAdapter);
        }

        @Override
        public void onNothingSelected(AdapterView<?> adapterView) {

        }
    });
    spinMuscleGroup.setSelection(1);

}

From source file:org.telegram.ui.ThemeActivity.java

private void openThemeCreate() {
    final EditTextBoldCursor editText = new EditTextBoldCursor(getParentActivity());
    editText.setBackgroundDrawable(Theme.createEditTextDrawable(getParentActivity(), true));

    AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
    builder.setTitle(LocaleController.getString("NewTheme", R.string.NewTheme));
    builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
    builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), (dialog, which) -> {

    });//from w  w  w  . ja v  a 2s  . c o  m

    LinearLayout linearLayout = new LinearLayout(getParentActivity());
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    builder.setView(linearLayout);

    final TextView message = new TextView(getParentActivity());
    message.setText(LocaleController.formatString("EnterThemeName", R.string.EnterThemeName));
    message.setTextSize(16);
    message.setPadding(AndroidUtilities.dp(23), AndroidUtilities.dp(12), AndroidUtilities.dp(23),
            AndroidUtilities.dp(6));
    message.setTextColor(Theme.getColor(Theme.key_dialogTextBlack));
    linearLayout.addView(message,
            LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));

    editText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
    editText.setTextColor(Theme.getColor(Theme.key_dialogTextBlack));
    editText.setMaxLines(1);
    editText.setLines(1);
    editText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
    editText.setGravity(Gravity.LEFT | Gravity.TOP);
    editText.setSingleLine(true);
    editText.setImeOptions(EditorInfo.IME_ACTION_DONE);
    editText.setCursorColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
    editText.setCursorSize(AndroidUtilities.dp(20));
    editText.setCursorWidth(1.5f);
    editText.setPadding(0, AndroidUtilities.dp(4), 0, 0);
    linearLayout.addView(editText,
            LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 36, Gravity.TOP | Gravity.LEFT, 24, 6, 24, 0));
    editText.setOnEditorActionListener((textView, i, keyEvent) -> {
        AndroidUtilities.hideKeyboard(textView);
        return false;
    });
    final AlertDialog alertDialog = builder.create();
    alertDialog.setOnShowListener(dialog -> AndroidUtilities.runOnUIThread(() -> {
        editText.requestFocus();
        AndroidUtilities.showKeyboard(editText);
    }));
    showDialog(alertDialog);
    alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(v -> {
        if (editText.length() == 0) {
            Vibrator vibrator = (Vibrator) ApplicationLoader.applicationContext
                    .getSystemService(Context.VIBRATOR_SERVICE);
            if (vibrator != null) {
                vibrator.vibrate(200);
            }
            AndroidUtilities.shakeView(editText, 2, 0);
            return;
        }
        ThemeEditorView themeEditorView = new ThemeEditorView();
        String name = editText.getText().toString() + ".attheme";
        themeEditorView.show(getParentActivity(), name);
        Theme.saveCurrentTheme(name, true);
        updateRows();
        alertDialog.dismiss();

        SharedPreferences preferences = MessagesController.getGlobalMainSettings();
        if (preferences.getBoolean("themehint", false)) {
            return;
        }
        preferences.edit().putBoolean("themehint", true).commit();
        try {
            Toast.makeText(getParentActivity(),
                    LocaleController.getString("CreateNewThemeHelp", R.string.CreateNewThemeHelp),
                    Toast.LENGTH_LONG).show();
        } catch (Exception e) {
            FileLog.e(e);
        }
    });
}

From source file:de.baumann.hhsmoodle.data_courses.Courses_Fragment.java

private void setCoursesList() {

    if (isFABOpen) {
        closeFABMenu();/*from ww w  .j a va2  s  .c o m*/
    }

    //display data
    final int layoutstyle = R.layout.list_item_notes;
    int[] xml_id = new int[] { R.id.textView_title_notes, R.id.textView_des_notes, R.id.textView_create_notes };
    String[] column = new String[] { "courses_title", "courses_content", "courses_creation" };
    final Cursor row = db.fetchAllData();
    SimpleCursorAdapter adapter = new SimpleCursorAdapter(getActivity(), layoutstyle, row, column, xml_id, 0) {
        @Override
        public View getView(final int position, View convertView, ViewGroup parent) {

            View v = super.getView(position, convertView, parent);
            ImageView iv_icon = (ImageView) v.findViewById(R.id.icon_notes);
            iv_icon.setVisibility(View.GONE);

            return v;
        }
    };

    lv.setAdapter(adapter);
    //onClick function
    lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterview, View view, int position, long id) {

            if (isFABOpen) {
                closeFABMenu();
            }

            Cursor row2 = (Cursor) lv.getItemAtPosition(position);
            final String courses_title = row2.getString(row2.getColumnIndexOrThrow("courses_title"));
            final String courses_content = row2.getString(row2.getColumnIndexOrThrow("courses_content"));

            final CharSequence[] options = { getString(R.string.courseList_todo),
                    getString(R.string.courseList_note), getString(R.string.courseList_random),
                    getString(R.string.courseList_subject), getString(R.string.bookmark_createEvent) };

            new android.app.AlertDialog.Builder(getActivity())
                    .setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() {

                        public void onClick(DialogInterface dialog, int whichButton) {
                            dialog.cancel();
                        }
                    }).setItems(options, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int item) {
                            if (options[item].equals(getString(R.string.courseList_random))) {

                                android.app.AlertDialog.Builder builder = new android.app.AlertDialog.Builder(
                                        getActivity());
                                View dialogView = View.inflate(getActivity(), R.layout.dialog_edit_entry, null);

                                final EditText edit_title = (EditText) dialogView
                                        .findViewById(R.id.note_title_input);
                                edit_title.setHint(R.string.title_hint);
                                edit_title.setText(courses_title);

                                final EditText edit_cont = (EditText) dialogView
                                        .findViewById(R.id.note_text_input);
                                edit_cont.setHint(R.string.text_hint);
                                edit_cont.setText(courses_content);

                                builder.setView(dialogView);
                                builder.setTitle(R.string.number_edit_entry);
                                builder.setPositiveButton(R.string.toast_yes,
                                        new DialogInterface.OnClickListener() {

                                            public void onClick(DialogInterface dialog, int whichButton) {
                                            }
                                        });
                                builder.setNegativeButton(R.string.toast_cancel,
                                        new DialogInterface.OnClickListener() {

                                            public void onClick(DialogInterface dialog, int whichButton) {
                                                dialog.cancel();
                                            }
                                        });

                                final android.app.AlertDialog dialog2 = builder.create();
                                // Display the custom alert dialog on interface
                                dialog2.show();

                                dialog2.getButton(android.support.v7.app.AlertDialog.BUTTON_POSITIVE)
                                        .setOnClickListener(new View.OnClickListener() {
                                            @Override
                                            public void onClick(View v) {
                                                //Do stuff, possibly set wantToCloseDialog to true then...
                                                Random_DbAdapter db = new Random_DbAdapter(getActivity());
                                                db.open();

                                                String inputTitle = edit_title.getText().toString().trim();
                                                String inputCont = edit_cont.getText().toString().trim();

                                                if (db.isExist(inputTitle)) {
                                                    Snackbar.make(edit_title,
                                                            getString(R.string.toast_newTitle),
                                                            Snackbar.LENGTH_LONG).show();
                                                } else {
                                                    db.insert(inputTitle, inputCont, "", "",
                                                            helper_main.createDate());
                                                    dialog2.dismiss();
                                                }
                                            }
                                        });
                                helper_main.showKeyboard(getActivity(), edit_title);
                            }

                            if (options[item].equals(getString(R.string.courseList_note))) {
                                Notes_helper.newNote(getActivity(), courses_title, "", "", "", "", "");
                            }

                            if (options[item].equals(getString(R.string.courseList_todo))) {
                                Todo_helper.newTodo(getActivity(), courses_title, courses_content,
                                        getActivity().getString(R.string.note_content));
                            }

                            if (options[item].equals(getString(R.string.courseList_subject))) {

                                LayoutInflater inflater = getActivity().getLayoutInflater();

                                final ViewGroup nullParent = null;
                                View dialogView = inflater.inflate(R.layout.dialog_edit_subject, nullParent);

                                titleInput = (EditText) dialogView.findViewById(R.id.subject_title_);
                                titleInput.setSelection(titleInput.getText().length());
                                titleInput.setText("");
                                teacherInput = (EditText) dialogView.findViewById(R.id.subject_teacher);
                                teacherInput.setText(courses_title);
                                roomInput = (EditText) dialogView.findViewById(R.id.subject_room);
                                roomInput.setText("");
                                helper_main.showKeyboard(getActivity(), titleInput);

                                final ImageButton be = (ImageButton) dialogView
                                        .findViewById(R.id.imageButtonPri);
                                assert be != null;
                                be.setImageResource(R.drawable.circle_grey);
                                sharedPref.edit().putString("subject_color", "11").apply();

                                be.setOnClickListener(new View.OnClickListener() {

                                    @Override
                                    public void onClick(View arg0) {

                                        final helper_main.Item[] items = {
                                                new helper_main.Item(getString(R.string.subjects_color_red),
                                                        R.drawable.circle_red),
                                                new helper_main.Item(getString(R.string.subjects_color_pink),
                                                        R.drawable.circle_pink),
                                                new helper_main.Item(getString(R.string.subjects_color_purple),
                                                        R.drawable.circle_purple),
                                                new helper_main.Item(getString(R.string.subjects_color_blue),
                                                        R.drawable.circle_blue),
                                                new helper_main.Item(getString(R.string.subjects_color_teal),
                                                        R.drawable.circle_teal),
                                                new helper_main.Item(getString(R.string.subjects_color_green),
                                                        R.drawable.circle_green),
                                                new helper_main.Item(getString(R.string.subjects_color_lime),
                                                        R.drawable.circle_lime),
                                                new helper_main.Item(getString(R.string.subjects_color_yellow),
                                                        R.drawable.circle_yellow),
                                                new helper_main.Item(getString(R.string.subjects_color_orange),
                                                        R.drawable.circle_orange),
                                                new helper_main.Item(getString(R.string.subjects_color_brown),
                                                        R.drawable.circle_brown),
                                                new helper_main.Item(getString(R.string.subjects_color_grey),
                                                        R.drawable.circle_grey), };

                                        ListAdapter adapter = new ArrayAdapter<helper_main.Item>(getActivity(),
                                                android.R.layout.select_dialog_item, android.R.id.text1,
                                                items) {
                                            @NonNull
                                            public View getView(int position, View convertView,
                                                    @NonNull ViewGroup parent) {
                                                //Use super class to create the View
                                                View v = super.getView(position, convertView, parent);
                                                TextView tv = (TextView) v.findViewById(android.R.id.text1);
                                                tv.setTextSize(18);
                                                tv.setCompoundDrawablesWithIntrinsicBounds(items[position].icon,
                                                        0, 0, 0);
                                                //Add margin between image and text (support various screen densities)
                                                int dp5 = (int) (24 * getActivity().getResources()
                                                        .getDisplayMetrics().density + 0.5f);
                                                tv.setCompoundDrawablePadding(dp5);

                                                return v;
                                            }
                                        };

                                        new android.app.AlertDialog.Builder(getActivity())
                                                .setPositiveButton(R.string.toast_cancel,
                                                        new DialogInterface.OnClickListener() {

                                                            public void onClick(DialogInterface dialog,
                                                                    int whichButton) {
                                                                dialog.cancel();
                                                            }
                                                        })
                                                .setAdapter(adapter, new DialogInterface.OnClickListener() {
                                                    public void onClick(DialogInterface dialog, int item) {
                                                        if (item == 0) {
                                                            be.setImageResource(R.drawable.circle_red);
                                                            sharedPref.edit().putString("subject_color", "1")
                                                                    .apply();
                                                        } else if (item == 1) {
                                                            be.setImageResource(R.drawable.circle_pink);
                                                            sharedPref.edit().putString("subject_color", "2")
                                                                    .apply();
                                                        } else if (item == 2) {
                                                            be.setImageResource(R.drawable.circle_purple);
                                                            sharedPref.edit().putString("subject_color", "3")
                                                                    .apply();
                                                        } else if (item == 3) {
                                                            be.setImageResource(R.drawable.circle_blue);
                                                            sharedPref.edit().putString("subject_color", "4")
                                                                    .apply();
                                                        } else if (item == 4) {
                                                            be.setImageResource(R.drawable.circle_teal);
                                                            sharedPref.edit().putString("subject_color", "5")
                                                                    .apply();
                                                        } else if (item == 5) {
                                                            be.setImageResource(R.drawable.circle_green);
                                                            sharedPref.edit().putString("subject_color", "6")
                                                                    .apply();
                                                        } else if (item == 6) {
                                                            be.setImageResource(R.drawable.circle_lime);
                                                            sharedPref.edit().putString("subject_color", "7")
                                                                    .apply();
                                                        } else if (item == 7) {
                                                            be.setImageResource(R.drawable.circle_yellow);
                                                            sharedPref.edit().putString("subject_color", "8")
                                                                    .apply();
                                                        } else if (item == 8) {
                                                            be.setImageResource(R.drawable.circle_orange);
                                                            sharedPref.edit().putString("subject_color", "9")
                                                                    .apply();
                                                        } else if (item == 9) {
                                                            be.setImageResource(R.drawable.circle_brown);
                                                            sharedPref.edit().putString("subject_color", "10")
                                                                    .apply();
                                                        } else if (item == 10) {
                                                            be.setImageResource(R.drawable.circle_grey);
                                                            sharedPref.edit().putString("subject_color", "11")
                                                                    .apply();
                                                        }
                                                    }
                                                }).show();
                                    }
                                });

                                android.support.v7.app.AlertDialog.Builder builder = new android.support.v7.app.AlertDialog.Builder(
                                        getActivity());
                                builder.setTitle(R.string.subjects_edit);
                                builder.setView(dialogView);
                                builder.setPositiveButton(R.string.toast_yes,
                                        new DialogInterface.OnClickListener() {

                                            public void onClick(DialogInterface dialog, int whichButton) {
                                                Subject_DbAdapter db = new Subject_DbAdapter(getActivity());
                                                db.open();

                                                String inputTitle = titleInput.getText().toString().trim();
                                                String inputTeacher = teacherInput.getText().toString().trim();
                                                String inputRoom = roomInput.getText().toString().trim();

                                                Date date = new Date();
                                                DateFormat dateFormat = new SimpleDateFormat(
                                                        "yy-MM-dd_HH-mm-ss", Locale.getDefault());
                                                String creation = dateFormat.format(date);

                                                if (db.isExist(inputTitle)) {
                                                    Snackbar.make(titleInput,
                                                            getString(R.string.toast_newTitle),
                                                            Snackbar.LENGTH_LONG).show();
                                                } else {
                                                    db.insert(inputTitle, inputTeacher,
                                                            sharedPref.getString("subject_color", ""),
                                                            inputRoom, creation);
                                                    dialog.dismiss();
                                                }

                                            }
                                        });
                                builder.setNegativeButton(R.string.toast_cancel,
                                        new DialogInterface.OnClickListener() {

                                            public void onClick(DialogInterface dialog, int whichButton) {
                                                dialog.cancel();
                                            }
                                        });

                                final android.support.v7.app.AlertDialog dialog2 = builder.create();
                                dialog2.show();
                            }

                            if (options[item].equals(getString(R.string.bookmark_createEvent))) {
                                helper_main.createCalendarEvent(getActivity(), courses_title, courses_content);
                            }

                        }
                    }).show();
        }
    });

    lv.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {

            if (isFABOpen) {
                closeFABMenu();
            }

            Cursor row2 = (Cursor) lv.getItemAtPosition(position);
            final String _id = row2.getString(row2.getColumnIndexOrThrow("_id"));
            final String courses_title = row2.getString(row2.getColumnIndexOrThrow("courses_title"));
            final String courses_content = row2.getString(row2.getColumnIndexOrThrow("courses_content"));
            final String courses_icon = row2.getString(row2.getColumnIndexOrThrow("courses_icon"));
            final String courses_attachment = row2.getString(row2.getColumnIndexOrThrow("courses_attachment"));
            final String courses_creation = row2.getString(row2.getColumnIndexOrThrow("courses_creation"));

            final CharSequence[] options = { getString(R.string.number_edit_entry),
                    getString(R.string.bookmark_remove_bookmark) };
            new android.app.AlertDialog.Builder(getActivity())
                    .setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() {

                        public void onClick(DialogInterface dialog, int whichButton) {
                            dialog.cancel();
                        }
                    }).setItems(options, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int item) {

                            if (options[item].equals(getString(R.string.number_edit_entry))) {

                                android.app.AlertDialog.Builder builder = new android.app.AlertDialog.Builder(
                                        getActivity());
                                View dialogView = View.inflate(getActivity(), R.layout.dialog_edit_entry, null);

                                final EditText edit_title = (EditText) dialogView
                                        .findViewById(R.id.note_title_input);
                                edit_title.setHint(R.string.title_hint);
                                edit_title.setText(courses_title);

                                final EditText edit_cont = (EditText) dialogView
                                        .findViewById(R.id.note_text_input);
                                edit_cont.setHint(R.string.text_hint);
                                edit_cont.setText(courses_content);

                                builder.setView(dialogView);
                                builder.setTitle(R.string.number_edit_entry);
                                builder.setPositiveButton(R.string.toast_yes,
                                        new DialogInterface.OnClickListener() {

                                            public void onClick(DialogInterface dialog, int whichButton) {

                                                String inputTitle = edit_title.getText().toString().trim();
                                                String inputCont = edit_cont.getText().toString().trim();
                                                db.update(Integer.parseInt(_id), inputTitle, inputCont,
                                                        courses_icon, courses_attachment, courses_creation);
                                                setCoursesList();
                                                Snackbar.make(lv, R.string.bookmark_added,
                                                        Snackbar.LENGTH_SHORT).show();
                                            }
                                        });
                                builder.setNegativeButton(R.string.toast_cancel,
                                        new DialogInterface.OnClickListener() {

                                            public void onClick(DialogInterface dialog, int whichButton) {
                                                dialog.cancel();
                                            }
                                        });

                                final android.app.AlertDialog dialog2 = builder.create();
                                // Display the custom alert dialog on interface
                                dialog2.show();
                                helper_main.showKeyboard(getActivity(), edit_title);
                            }

                            if (options[item].equals(getString(R.string.bookmark_remove_bookmark))) {

                                Snackbar snackbar = Snackbar
                                        .make(lv, R.string.note_remove_confirmation, Snackbar.LENGTH_LONG)
                                        .setAction(R.string.toast_yes, new View.OnClickListener() {
                                            @Override
                                            public void onClick(View view) {
                                                db.delete(Integer.parseInt(_id));
                                                setCoursesList();
                                            }
                                        });
                                snackbar.show();
                            }

                        }
                    }).show();
            return true;
        }
    });
}

From source file:io.jari.geenstijl.Dialogs.ReplyDialog.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    LayoutInflater inflater = getActivity().getLayoutInflater();
    final View view = inflater.inflate(R.layout.dialog_reply, null);
    builder.setView(view).setPositiveButton(R.string.reply, null)
            .setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    ReplyDialog.this.getDialog().cancel();
                }//from  w  w w . j  a va  2s .c o m
            }).setTitle(R.string.reply);
    final AlertDialog alertDialog = builder.create();
    alertDialog.setOnShowListener(new DialogInterface.OnShowListener() {
        @Override
        public void onShow(DialogInterface dialog) {
            final View error = view.findViewById(R.id.error);
            final Button positive = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
            final Button negative = alertDialog.getButton(AlertDialog.BUTTON_NEGATIVE);
            positive.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    positive.setEnabled(false);
                    negative.setEnabled(false);
                    final TextView reply = (TextView) view.findViewById(R.id.reply);
                    final View loading = view.findViewById(R.id.loading);
                    reply.setVisibility(View.GONE);
                    loading.setVisibility(View.VISIBLE);
                    error.setVisibility(View.GONE);
                    alertDialog.setCancelable(false);
                    new Thread(new Runnable() {
                        @Override
                        public void run() {
                            boolean success;
                            try {
                                success = API.reply(artikel, reply.getText().toString(), activity);
                            } catch (Exception e) {
                                e.printStackTrace();
                                success = false;
                            }
                            alertDialog.setCancelable(true);
                            if (!success)
                                activity.runOnUiThread(new Runnable() {
                                    @Override
                                    public void run() {
                                        reply.setVisibility(View.VISIBLE);
                                        error.setVisibility(View.VISIBLE);
                                        positive.setEnabled(true);
                                        negative.setEnabled(true);
                                        loading.setVisibility(View.GONE);
                                    }
                                });
                            else
                                activity.runOnUiThread(new Runnable() {
                                    @Override
                                    public void run() {
                                        alertDialog.dismiss();
                                        Crouton.makeText(activity, getString(R.string.reply_success),
                                                Style.CONFIRM).show();
                                    }
                                });
                        }
                    }).start();
                }
            });
        }
    });

    return alertDialog;
}

From source file:com.fitme.MainActivity.java

/**
 * A fragment representing a exercises managment section of the app
 */// ww w . j ava 2  s  . c  o m

private void onAddProgramRequested(final ProgramListAdapter pda) {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(R.string.title_add_program_dialog);
    builder.setView(this.getLayoutInflater().inflate(R.layout.dialog_add_program, null));
    builder.setPositiveButton(android.R.string.ok, null);
    builder.setNegativeButton(android.R.string.cancel, null);
    final AlertDialog programDialog = builder.create();
    programDialog.setOnShowListener(new DialogInterface.OnShowListener() {

        @Override
        public void onShow(DialogInterface dialog) {
            Button positive = programDialog.getButton(AlertDialog.BUTTON_POSITIVE);
            positive.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    Program p = new Program();
                    EditText etName = (EditText) programDialog.findViewById(R.id.edittext_program_name);
                    EditText etDesc = (EditText) programDialog.findViewById(R.id.edittext_program_desc);
                    String programName = etName.getText().toString();
                    String programDesc = etDesc.getText().toString();
                    // Check if form filled correct
                    // Check if program name is empty
                    if (programName.isEmpty()) {
                        Toast.makeText(MainActivity.this, getString(R.string.toast_err_program_empty),
                                Toast.LENGTH_SHORT).show();
                        return;
                    }
                    // Check if program already exists
                    ProgramDAO pd = new ProgramDAO(MainActivity.this);
                    if (pd.getProgramByName(programName).getId() != ProgramDAO.ID_PROGRAM_NOT_FOUND) {
                        Toast.makeText(MainActivity.this, getString(R.string.toast_err_program_exists),
                                Toast.LENGTH_SHORT).show();
                        return;
                    }
                    // If everything is ok - then add new program
                    p.setName(programName);
                    p.setDescription(programDesc);
                    pd.createProgram(p);
                    Toast.makeText(MainActivity.this, getText(R.string.toast_add_program_ok),
                            Toast.LENGTH_SHORT).show();
                    pda.addProgram(p);
                    programDialog.dismiss();
                }
            });
        }
    });
    programDialog.show();

}

From source file:cm.aptoide.pt.ApkInfo.java

public void loadMalware(final MalwareStatus malwareStatus) {
    runOnUiThread(new Runnable() {

        @Override/*from ww  w  .j a v  a2s.  com*/
        public void run() {
            try {
                EnumApkMalware apkStatus = EnumApkMalware
                        .valueOf(malwareStatus.getStatus().toUpperCase(Locale.ENGLISH));
                Log.d("ApkInfoMalware-malwareStatus", malwareStatus.getStatus());
                Log.d("ApkInfoMalware-malwareReason", malwareStatus.getReason());

                switch (apkStatus) {
                case SCANNED:
                    ((TextView) findViewById(R.id.app_badge_text)).setText(getString(R.string.trusted));
                    ((ImageView) findViewById(R.id.app_badge)).setImageResource(R.drawable.badge_scanned);
                    ((LinearLayout) findViewById(R.id.badge_layout)).setOnClickListener(new OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            View trustedView = LayoutInflater.from(ApkInfo.this)
                                    .inflate(R.layout.dialog_anti_malware, null);
                            AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(ApkInfo.this)
                                    .setView(trustedView);
                            final AlertDialog trustedDialog = dialogBuilder.create();
                            trustedDialog.setIcon(R.drawable.badge_scanned);
                            trustedDialog.setTitle(getString(R.string.app_trusted, viewApk.getName()));
                            trustedDialog.setCancelable(true);

                            TextView tvSignatureValidation = (TextView) trustedView
                                    .findViewById(R.id.tv_signature_validation);
                            tvSignatureValidation.setText(getString(R.string.signature_verified));
                            ImageView check_signature = (ImageView) trustedView
                                    .findViewById(R.id.check_signature);
                            check_signature.setImageResource(R.drawable.ic_yes);

                            trustedDialog.setButton(Dialog.BUTTON_NEUTRAL, "Ok", new Dialog.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface arg0, int arg1) {
                                    trustedDialog.dismiss();
                                }
                            });
                            trustedDialog.show();
                        }
                    });
                    break;
                //             case UNKNOWN:
                //                ((TextView) findViewById(R.id.app_badge_text)).setText(getString(R.string.unknown));
                //                ((ImageView) findViewById(R.id.app_badge)).setImageResource(R.drawable.badge_unknown);
                //                break;
                case WARN:
                    ((TextView) findViewById(R.id.app_badge_text)).setText(getString(R.string.warning));
                    ((ImageView) findViewById(R.id.app_badge)).setImageResource(R.drawable.badge_warn);
                    ((LinearLayout) findViewById(R.id.badge_layout)).setOnClickListener(new OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            View warnView = LayoutInflater.from(ApkInfo.this)
                                    .inflate(R.layout.dialog_anti_malware, null);
                            AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(ApkInfo.this)
                                    .setView(warnView);
                            final AlertDialog warnDialog = dialogBuilder.create();
                            warnDialog.setIcon(R.drawable.badge_warn);
                            warnDialog.setTitle(getString(R.string.app_warning, viewApk.getName()));
                            warnDialog.setCancelable(true);

                            TextView tvSignatureValidation = (TextView) warnView
                                    .findViewById(R.id.tv_signature_validation);
                            tvSignatureValidation.setText(getString(R.string.signature_not_verified));
                            ImageView check_signature = (ImageView) warnView.findViewById(R.id.check_signature);
                            check_signature.setImageResource(R.drawable.ic_failed);

                            warnDialog.setButton(Dialog.BUTTON_NEUTRAL, "Ok", new Dialog.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface arg0, int arg1) {
                                    warnDialog.dismiss();
                                }
                            });
                            warnDialog.show();
                        }
                    });
                    break;
                //             case CRITICAL:
                //                ((TextView) findViewById(R.id.app_badge_text)).setText(getString(R.string.critical));
                //                ((ImageView) findViewById(R.id.app_badge)).setImageResource(R.drawable.badge_critical);
                //                break;
                default:
                    break;
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

    });

}

From source file:com.fitme.MainActivity.java

public void onProgramEditRequested(final ProgramRow oldProg, final ProgramListAdapter pda) {
    final Activity activity = MainActivity.this;
    AlertDialog.Builder builder = new AlertDialog.Builder(activity);
    builder.setTitle(getString(R.string.title_upd_program_dialog));
    builder.setView(getLayoutInflater().inflate(R.layout.dialog_add_program, null));
    builder.setPositiveButton(android.R.string.ok, null);
    builder.setNegativeButton(android.R.string.cancel, null);
    final AlertDialog programDialog = builder.create();
    programDialog.setOnShowListener(new DialogInterface.OnShowListener() {

        @Override/*  w w  w. j  a v  a2 s .  c o  m*/
        public void onShow(DialogInterface dialog) {
            Button positive = programDialog.getButton(AlertDialog.BUTTON_POSITIVE);
            positive.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    EditText etName = (EditText) programDialog.findViewById(R.id.edittext_program_name);
                    EditText etDesc = (EditText) programDialog.findViewById(R.id.edittext_program_desc);
                    String programName = etName.getText().toString();
                    String programDesc = etDesc.getText().toString();
                    // Validating form fields
                    // Check if program name changed
                    if (!programName.equals(oldProg.getName())) {
                        // If chanded - check it
                        // Check if empty
                        if (programName.isEmpty()) {
                            Toast.makeText(MainActivity.this, getString(R.string.toast_err_program_empty),
                                    Toast.LENGTH_SHORT).show();
                            return;
                        }
                        // Check if program already exists
                        ProgramDAO pd = new ProgramDAO(MainActivity.this);
                        if (pd.getProgramByName(programName).getId() != ProgramDAO.ID_PROGRAM_NOT_FOUND) {
                            Toast.makeText(MainActivity.this, getString(R.string.toast_err_program_exists),
                                    Toast.LENGTH_SHORT).show();
                            return;
                        }
                    } else {
                        // if program name stays the same - check description
                        // if description is the same - nothing happens
                        if (programDesc.equals(oldProg.getDescription())) {
                            programDialog.dismiss();
                            return;
                        }
                    }

                    // if everything is ok - update program record
                    Program p = new Program();
                    p.setName(programName);
                    p.setDescription(programDesc);
                    ProgramDAO pd = new ProgramDAO(activity);
                    pd.updateByName(oldProg.getName(), p);
                    Toast.makeText(activity, getText(R.string.toast_upd_program_ok), Toast.LENGTH_SHORT).show();
                    pda.updateProgram(oldProg.getName(), p);
                    programDialog.dismiss();
                }
            });

        }
    });
    programDialog.show();
    // Initiate data with old program entry
    EditText etName = (EditText) programDialog.findViewById(R.id.edittext_program_name);
    EditText etDesc = (EditText) programDialog.findViewById(R.id.edittext_program_desc);
    etName.setText(oldProg.getName());
    etDesc.setText(oldProg.getDescription());
}

From source file:com.free.searcher.MainFragment.java

public boolean preview(MenuItem item) {
    //         final Dialog dialog = new Dialog(CountingFragment.this);
    //         dialog.setContentView(R.layout.preview);
    //         dialog.setTitle("Preview");
    ///*from   w w  w  .  java2 s . c  o m*/
    //         Button okBtn = (Button) dialog.findViewById(R.id.okBtn);
    //         okBtn.setOnClickListener(new OnClickListener() {
    //
    //               @Override
    //               public void onClick(View v) {
    //                  EditText preview = (EditText) dialog.findViewById(R.id.preview);
    //                  CountingFragment.this.charsPreview =
    //                     Integer.valueOf(preview.getText().toString());
    //                  diaLog.dismiss();
    //               }
    //            });
    //
    //         Button cancelBtn = (Button) dialog.findViewById(R.id.cancelBtn);
    //         cancelBtn.setOnClickListener(new OnClickListener() {
    //
    //               @Override
    //               public void onClick(View v) {
    //                  diaLog.dismiss();
    //               }
    //            });
    //         dialog.show();

    LayoutInflater factory = LayoutInflater.from(activity);
    final View textEntryView = factory.inflate(R.layout.preview, null);
    final EditText preview = (EditText) textEntryView.findViewById(R.id.preview);
    preview.setText("" + MainActivity.charsPreview);
    AlertDialog dialog = new AlertDialog.Builder(activity).setIconAttribute(android.R.attr.alertDialogIcon)
            .setTitle(R.string.charsPreview).setView(textEntryView)
            .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    try {
                        MainActivity.charsPreview = Integer.valueOf(preview.getText().toString());
                    } catch (NumberFormatException nfe) {
                        showToast("Invalid number. Keep the old value " + MainActivity.charsPreview);
                    }
                    dialog.dismiss();
                }
            }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    dialog.dismiss();
                }
            }).create();
    dialog.show();
    return true;
}

From source file:com.fitme.MainActivity.java

public void onTrainingCreationRequested(final TrainingsListAdapter tla) {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(R.string.title_add_training_dialog);
    View addTrainDialogView = getLayoutInflater().inflate(R.layout.dialog_add_training, null);
    builder.setView(addTrainDialogView);

    builder.setPositiveButton(android.R.string.ok, null);
    builder.setNegativeButton(android.R.string.cancel, null);

    final AlertDialog trainingDialog = builder.create();

    trainingDialog.setOnShowListener(new DialogInterface.OnShowListener() {

        @Override/* www  . j av  a2  s.  c o m*/
        public void onShow(DialogInterface dialog) {
            Button positive = trainingDialog.getButton(AlertDialog.BUTTON_POSITIVE);
            positive.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    // handle OK

                    EditText etName = (EditText) trainingDialog.findViewById(R.id.edittext_training_name);
                    String trainingName = etName.getText().toString();

                    // Check if form filled correct
                    // Check if training name is empty
                    if (trainingName.isEmpty()) {
                        Toast.makeText(MainActivity.this, getString(R.string.toast_err_training_empty),
                                Toast.LENGTH_SHORT).show();
                        return;
                    }
                    // Check if training already exists
                    long programId = getActiveProgramId();
                    TrainingDAO td = new TrainingDAO(MainActivity.this);
                    if (td.getTrainingByName(programId, trainingName)
                            .getId() != TrainingDAO.ID_TRAINING_NOT_FOUND) {
                        Toast.makeText(MainActivity.this, getString(R.string.toast_err_training_exists),
                                Toast.LENGTH_SHORT).show();
                        return;
                    }
                    // If everything is ok - then add new program
                    Training t = new Training();
                    t.setName(trainingName);
                    t.setProgramId(programId);
                    //Insert entry to db
                    td.createTraining(t);
                    Toast.makeText(MainActivity.this, getText(R.string.toast_add_training_ok),
                            Toast.LENGTH_SHORT).show();
                    tla.addTraining(t);
                    trainingDialog.dismiss();
                }
            });

            Button negative = trainingDialog.getButton(AlertDialog.BUTTON_NEGATIVE);
            negative.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    trainingDialog.dismiss();

                }
            });

        }
    });
    trainingDialog.show();
}

From source file:org.akvo.caddisfly.ui.activity.MainActivity.java

public void onSaveCalibration() {
    final Context context = this;
    final MainApp mainApp = (MainApp) this.getApplicationContext();

    final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);
    final EditText input = new EditText(context);
    input.setInputType(InputType.TYPE_CLASS_TEXT);
    input.setFilters(new InputFilter[] { new InputFilter.LengthFilter(22) });

    alertDialogBuilder.setView(input);//from  w w w. ja v  a 2 s.co  m
    alertDialogBuilder.setCancelable(false);

    alertDialogBuilder.setTitle(R.string.saveCalibration);
    alertDialogBuilder.setMessage(R.string.giveNameForCalibration);

    alertDialogBuilder.setPositiveButton(R.string.ok, null);
    alertDialogBuilder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int i) {
            closeKeyboard(input);
            dialog.cancel();
        }
    });
    final AlertDialog alertDialog = alertDialogBuilder.create(); //create the box

    alertDialog.setOnShowListener(new DialogInterface.OnShowListener() {

        @Override
        public void onShow(DialogInterface dialog) {

            Button b = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
            b.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View view) {

                    if (!input.getText().toString().trim().isEmpty()) {
                        final ArrayList<String> exportList = new ArrayList<String>();

                        for (ColorInfo aColorList : mainApp.colorList) {
                            exportList.add(ColorUtils.getColorRgbString(aColorList.getColor()));
                        }

                        File external = Environment.getExternalStorageDirectory();
                        final String path = external.getPath() + Config.CALIBRATE_FOLDER_NAME;

                        File file = new File(path + input.getText());
                        if (file.exists()) {
                            AlertUtils.askQuestion(context, R.string.overwriteFile, R.string.nameAlreadyExists,
                                    new DialogInterface.OnClickListener() {
                                        @Override
                                        public void onClick(DialogInterface dialogInterface, int i) {
                                            FileUtils.saveToFile(path, input.getText().toString(),
                                                    exportList.toString());
                                        }
                                    });
                        } else {
                            FileUtils.saveToFile(path, input.getText().toString(), exportList.toString());
                        }

                        closeKeyboard(input);
                        alertDialog.dismiss();
                    } else {
                        input.setError(getString(R.string.invalidName));
                    }
                }
            });
        }
    });

    input.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if ((event != null && (event.getKeyCode() == KeyEvent.KEYCODE_ENTER))
                    || (actionId == EditorInfo.IME_ACTION_DONE)) {

            }
            return false;
        }
    });

    alertDialog.show();
    input.requestFocus();
    InputMethodManager imm = (InputMethodManager) this.getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);

}