List of usage examples for android.app AlertDialog getButton
public Button getButton(int whichButton)
From source file:org.catrobat.catroid.ui.dialogs.LoginRegisterDialog.java
@Override public Dialog onCreateDialog(Bundle bundle) { View rootView = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_login_register, null); usernameEditText = (EditText) rootView.findViewById(R.id.username); passwordEditText = (EditText) rootView.findViewById(R.id.password); termsOfUseLinkTextView = (TextView) rootView.findViewById(R.id.register_terms_link); String termsOfUseUrl = getString(R.string.about_link_template, Constants.CATROBAT_TERMS_OF_USE_URL, getString(R.string.register_pocketcode_terms_of_use_text)); termsOfUseLinkTextView.setMovementMethod(LinkMovementMethod.getInstance()); termsOfUseLinkTextView.setText(Html.fromHtml(termsOfUseUrl)); usernameEditText.setText(""); passwordEditText.setText(""); final AlertDialog loginRegisterDialog = new AlertDialog.Builder(getActivity()).setView(rootView) .setTitle(R.string.login_register_dialog_title).setPositiveButton(R.string.login_or_register, null) .setNeutralButton(R.string.password_forgotten, null).create(); loginRegisterDialog.setCanceledOnTouchOutside(true); loginRegisterDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); loginRegisterDialog.setOnShowListener(new OnShowListener() { @Override//from ww w .jav a2 s . co m public void onShow(DialogInterface dialog) { InputMethodManager inputManager = (InputMethodManager) getActivity() .getSystemService(Context.INPUT_METHOD_SERVICE); inputManager.showSoftInput(usernameEditText, InputMethodManager.SHOW_IMPLICIT); Button loginRegisterButton = loginRegisterDialog.getButton(AlertDialog.BUTTON_POSITIVE); loginRegisterButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { handleLoginRegisterButtonClick(); } }); Button passwordForgottenButton = loginRegisterDialog.getButton(AlertDialog.BUTTON_NEUTRAL); passwordForgottenButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { handlePasswordForgottenButtonClick(); } }); } }); return loginRegisterDialog; }
From source file:com.example.linhdq.test.documents.creation.NewDocumentActivity.java
@Override protected void onPrepareDialog(int id, Dialog dialog, Bundle args) { switch (id) { case EDIT_TITLE_DIALOG_ID: final Uri documentUri = Uri.parse(args.getString(DIALOG_ARG_DOCUMENT_URI)); final String oldTitle = args.getString(DIALOG_ARG_TITLE); final EditText edit = (EditText) dialog.findViewById(R.id.edit_title); edit.setText(oldTitle);/*from www . ja v a 2 s.co m*/ AlertDialog alertDialog = (AlertDialog) dialog; Button okButton = alertDialog.getButton(AlertDialog.BUTTON_NEUTRAL); okButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { final String title = edit.getText().toString(); saveTitle(title, documentUri); } }); break; case HINT_DIALOG_ID: break; default: if (args != null) { final int max = args.getInt(DIALOG_ARG_MAX); final int progress = args.getInt(DIALOG_ARG_PROGRESS); // final int secondaryProgress = // args.getInt(DIALOG_ARG_SECONDARY_PROGRESS); final String message = args.getString(DIALOG_ARG_MESSAGE); final String title = args.getString(DIALOG_ARG_TITLE); if (id == PDF_PROGRESS_DIALOG_ID) { runOnUiThread(new Runnable() { @Override public void run() { pdfProgressDialog.setProgress(progress); pdfProgressDialog.setMax(max); if (message != null) { pdfProgressDialog.setMessage(message); } if (title != null) { pdfProgressDialog.setTitle(title); } } }); } else if (id == DELETE_PROGRESS_DIALOG_ID) { runOnUiThread(new Runnable() { @Override public void run() { deleteProgressDialog.setProgress(progress); deleteProgressDialog.setMax(max); if (message != null) { deleteProgressDialog.setMessage(message); } } }); } } } super.onPrepareDialog(id, dialog, args); }
From source file:org.nypl.simplified.app.MainSettingsAccountActivity.java
private void showAgeGateOptionsDialog(CheckBox age13_box) { final AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(R.string.age_verification_title); builder.setMessage(R.string.age_verification_changed); // Under 13/*from ww w. ja v a2 s . com*/ builder.setNeutralButton(R.string.age_verification_13_younger, (dialog, which) -> { Simplified.getSharedPrefs().putBoolean("age13", false); age13_box.setChecked(false); setSimplyCollectionCatalog(true); }); // 13 and Over builder.setPositiveButton(R.string.age_verification_13_older, (dialog, which) -> { Simplified.getSharedPrefs().putBoolean("age13", true); age13_box.setChecked(true); setSimplyCollectionCatalog(false); }); AlertDialog alert = builder.show(); final int resID = ThemeMatcher.Companion.color(this.account.getMainColor()); final int mainTextColor = ContextCompat.getColor(this, resID); alert.getButton(AlertDialog.BUTTON_NEUTRAL).setTextColor(mainTextColor); alert.getButton(AlertDialog.BUTTON_POSITIVE).setTextColor(mainTextColor); }
From source file:com.dattasmoon.pebble.plugin.EditNotificationActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { if (Constants.IS_LOGGABLE) { Log.i(Constants.LOG_TAG, "Selected menu item id: " + String.valueOf(item.getItemId())); }/*from w w w . j a va 2s . c o m*/ final AlertDialog.Builder builder = new AlertDialog.Builder(this); View v; ListViewHolder viewHolder; AdapterView.AdapterContextMenuInfo contextInfo; String app_name; final String package_name; switch (item.getItemId()) { case R.id.btnUncheckAll: builder.setTitle(R.string.dialog_confirm_title); builder.setMessage(getString(R.string.dialog_uncheck_message)); builder.setCancelable(false); builder.setPositiveButton(R.string.confirm, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int buttonId) { if (lvPackages == null || lvPackages.getAdapter() == null || ((packageAdapter) lvPackages.getAdapter()).selected == null) { //something went wrong return; } ((packageAdapter) lvPackages.getAdapter()).selected.clear(); lvPackages.invalidateViews(); } }); builder.setNegativeButton(R.string.decline, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int buttonId) { //do nothing! } }); builder.setIcon(android.R.drawable.ic_dialog_alert); builder.show(); return true; case R.id.btnSave: finish(); return true; case R.id.btnDonate: Intent i = new Intent(Intent.ACTION_VIEW); i.setData(Uri.parse(Constants.DONATION_URL)); startActivity(i); return true; case R.id.btnSettings: Intent settings = new Intent(this, SettingsActivity.class); startActivity(settings); return true; case R.id.btnRename: contextInfo = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo(); int position = contextInfo.position; long id = contextInfo.id; // the child view who's info we're viewing (should be equal to v) v = contextInfo.targetView; app_name = ((TextView) v.findViewById(R.id.tvPackage)).getText().toString(); viewHolder = (ListViewHolder) v.getTag(); if (viewHolder == null || viewHolder.chkEnabled == null) { //failure return true; } package_name = (String) viewHolder.chkEnabled.getTag(); builder.setTitle(R.string.dialog_title_rename_notification); final EditText input = new EditText(this); input.setHint(app_name); builder.setView(input); builder.setPositiveButton(R.string.confirm, null); builder.setNegativeButton(R.string.decline, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { //do nothing } }); final AlertDialog d = builder.create(); d.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialog) { Button b = d.getButton(AlertDialog.BUTTON_POSITIVE); if (b != null) { b.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { //can't be nothing if (input.getText().length() > 0) { if (Constants.IS_LOGGABLE) { Log.i(Constants.LOG_TAG, "Adding rename for " + package_name + " to " + input.getText()); } JSONObject rename = new JSONObject(); try { rename.put("pkg", package_name); rename.put("to", input.getText()); arrayRenames.put(rename); } catch (JSONException e) { e.printStackTrace(); } ((packageAdapter) lvPackages.getAdapter()).notifyDataSetChanged(); d.dismiss(); } else { input.setText(R.string.error_cant_be_blank); } } }); } } }); d.show(); return true; case R.id.btnRemoveRename: contextInfo = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo(); // the child view who's info we're viewing (should be equal to v) v = contextInfo.targetView; app_name = ((TextView) v.findViewById(R.id.tvPackage)).getText().toString(); viewHolder = (ListViewHolder) v.getTag(); if (viewHolder == null || viewHolder.chkEnabled == null) { if (Constants.IS_LOGGABLE) { Log.i(Constants.LOG_TAG, "Viewholder is null or chkEnabled is null"); } //failure return true; } package_name = (String) viewHolder.chkEnabled.getTag(); builder.setTitle( getString(R.string.dialog_title_remove_rename) + app_name + " (" + package_name + ")?"); builder.setPositiveButton(R.string.confirm, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (Constants.IS_LOGGABLE) { Log.i(Constants.LOG_TAG, "Before remove is: " + String.valueOf(arrayRenames.length())); } JSONArray tmp = new JSONArray(); try { for (int i = 0; i < arrayRenames.length(); i++) { if (!arrayRenames.getJSONObject(i).getString("pkg").equalsIgnoreCase(package_name)) { tmp.put(arrayRenames.getJSONObject(i)); } } } catch (JSONException e) { e.printStackTrace(); } arrayRenames = tmp; if (Constants.IS_LOGGABLE) { Log.i(Constants.LOG_TAG, "After remove is: " + String.valueOf(arrayRenames.length())); } ((packageAdapter) lvPackages.getAdapter()).notifyDataSetChanged(); } }); builder.setNegativeButton(R.string.decline, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { //do nothing } }); builder.show(); return true; } return super.onOptionsItemSelected(item); }
From source file:org.nypl.simplified.app.MainSettingsAccountActivity.java
private void showAgeChangeConfirmation(CompoundButton button, boolean checked) { if (checked) { Simplified.getSharedPrefs().putBoolean("age13", true); setSimplyCollectionCatalog(false); } else {//w ww.ja v a 2s . c om final AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(R.string.age_verification_confirm_title); builder.setMessage(R.string.age_verification_confirm_under13_check); builder.setNegativeButton(R.string.catalog_cancel_downloading, (dialog, which) -> { Simplified.getSharedPrefs().putBoolean("age13", true); button.setChecked(true); }); //Confirm Under 13 builder.setPositiveButton(R.string.catalog_book_delete, (dialog, which) -> { Simplified.getSharedPrefs().putBoolean("age13", false); button.setChecked(false); setSimplyCollectionCatalog(true); }); AlertDialog alert = builder.show(); final int resID = ThemeMatcher.Companion.color(this.account.getMainColor()); final int mainTextColor = ContextCompat.getColor(this, resID); alert.getButton(AlertDialog.BUTTON_NEGATIVE).setTextColor(mainTextColor); alert.getButton(AlertDialog.BUTTON_POSITIVE).setTextColor(mainTextColor); } }
From source file:de.spiritcroc.ownlog.ui.fragment.MultiSelectTagDialog.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { final Activity activity = getActivity(); AlertDialog.Builder builder = new AlertDialog.Builder(activity); final View view = createView(); restoreValues(savedInstanceState);/*from w w w . j a va2 s.co m*/ loadContent(); final AlertDialog alertDialog = builder.setTitle(R.string.dialog_select_tags).setView(view) .setPositiveButton(R.string.dialog_save_changes, null) .setNegativeButton(R.string.dialog_cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { // Only dismiss } }).setNeutralButton(R.string.dialog_add, null).create(); alertDialog.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialogInterface) { alertDialog.getButton(DialogInterface.BUTTON_POSITIVE) .setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { saveChanges(); } }); alertDialog.getButton(DialogInterface.BUTTON_NEUTRAL) .setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { new TagItemEditFragment().setShouldHideKeyboardOnDismiss(true) .show(getFragmentManager(), "TagItemEditFragment"); } }); } }); return alertDialog; }
From source file:hku.fyp14017.blencode.ui.dialogs.LoginRegisterDialog.java
@Override public Dialog onCreateDialog(Bundle bundle) { View rootView = LayoutInflater.from(getActivity()) .inflate(hku.fyp14017.blencode.R.layout.dialog_login_register, null); usernameEditText = (EditText) rootView.findViewById(hku.fyp14017.blencode.R.id.username); passwordEditText = (EditText) rootView.findViewById(hku.fyp14017.blencode.R.id.password); termsOfUseLinkTextView = (TextView) rootView.findViewById(hku.fyp14017.blencode.R.id.register_terms_link); String termsOfUseUrl = getString(hku.fyp14017.blencode.R.string.about_link_template, Constants.CATROBAT_TERMS_OF_USE_URL, getString(hku.fyp14017.blencode.R.string.register_pocketcode_terms_of_use_text)); termsOfUseLinkTextView.setMovementMethod(LinkMovementMethod.getInstance()); termsOfUseLinkTextView.setText(Html.fromHtml(termsOfUseUrl)); usernameEditText.setText(""); passwordEditText.setText(""); final AlertDialog loginRegisterDialog = new AlertDialog.Builder(getActivity()).setView(rootView) .setTitle(hku.fyp14017.blencode.R.string.login_register_dialog_title) .setPositiveButton(hku.fyp14017.blencode.R.string.login_or_register, null) .setNeutralButton(hku.fyp14017.blencode.R.string.password_forgotten, null).create(); loginRegisterDialog.setCanceledOnTouchOutside(true); loginRegisterDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); loginRegisterDialog.setOnShowListener(new OnShowListener() { @Override/*from w w w . j a v a 2s .c o m*/ public void onShow(DialogInterface dialog) { InputMethodManager inputManager = (InputMethodManager) getActivity() .getSystemService(Context.INPUT_METHOD_SERVICE); inputManager.showSoftInput(usernameEditText, InputMethodManager.SHOW_IMPLICIT); Button loginRegisterButton = loginRegisterDialog.getButton(AlertDialog.BUTTON_POSITIVE); loginRegisterButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { handleLoginRegisterButtonClick(); } }); Button passwordFhkuottenButton = loginRegisterDialog.getButton(AlertDialog.BUTTON_NEUTRAL); passwordFhkuottenButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { handlePasswordForgottenButtonClick(); } }); } }); return loginRegisterDialog; }
From source file:org.cloudfoundry.android.cfdroid.services.ServiceEditDialogFragment.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { LayoutInflater inflater = LayoutInflater.from(getActivity()); final View v = inflater.inflate(R.layout.service_edit, null); choices = (Spinner) v.findViewById(R.id.type); name = (EditText) v.findViewById(R.id.name); getLoaderManager().initLoader(0, null, this); name.setOnEditorActionListener(new OnEditorActionListener() { public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == IME_ACTION_DONE && ready()) { createService();/*from www .j av a 2 s . co m*/ return true; } return false; } }); name.addTextChangedListener(new BaseTextWatcher() { @Override public void afterTextChanged(Editable s) { updateEnablement(); } }); final AlertDialog dialog = new AlertDialog.Builder(getActivity()) .setTitle(R.string.edit_service_dialog_title).setView(v).setCancelable(true) .setPositiveButton(R.string.create, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); createService(); } }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }).create(); // workaround for http://code.google.com/p/android/issues/detail?id=6360 // ... dialog.setOnShowListener(new OnShowListener() { @Override public void onShow(DialogInterface di) { okButton = dialog.getButton(AlertDialog.BUTTON_POSITIVE); updateEnablement(); } }); return dialog; }
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);// www .java 2s .c o 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); }
From source file:de.baumann.hhsmoodle.data_courses.Courses_Fragment.java
private void setCoursesList() { if (isFABOpen) { closeFABMenu();/*from w w w . ja v a2 s. com*/ } //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; } }); }