List of usage examples for android.app Dialog Dialog
public Dialog(@NonNull Context context)
From source file:com.gunz.carrental.Fragments.CarsFragment.java
private void addCar(final boolean isAddCar, final int position) { final Dialog dialog = new Dialog(getActivity()); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setContentView(R.layout.custom_dialog_car); dialog.setCanceledOnTouchOutside(false); dialog.setCancelable(false);/*from ww w .j ava 2s .c om*/ TextView lblTitle = (TextView) dialog.findViewById(R.id.lblTitle); final MaterialEditText txBrand = (MaterialEditText) dialog.findViewById(R.id.txBrand); final MaterialEditText txModel = (MaterialEditText) dialog.findViewById(R.id.txModel); final MaterialEditText txLicense = (MaterialEditText) dialog.findViewById(R.id.txLicense); final MaterialEditText txFare = (MaterialEditText) dialog.findViewById(R.id.txFare); Button btnSave = (Button) dialog.findViewById(R.id.btnSave); ImageView imgClose = (ImageView) dialog.findViewById(R.id.imgClose); dialog.show(); clearErrorMsg(dialog); if (!isAddCar) { lblTitle.setText(getActivity().getResources().getString(R.string.update_car_title)); txBrand.setText(cars.get(position).brand); txModel.setText(cars.get(position).type); txLicense.setText(cars.get(position).licensePlat); txFare.setText(String.valueOf((int) cars.get(position).farePerDay)); } else { lblTitle.setText(getActivity().getResources().getString(R.string.add_new_car_title)); } btnSave.setOnClickListener(new OnOneClickListener() { @Override public void onOneClick(View v) { if (TextUtils.isEmpty(txBrand.getText().toString().trim())) { txBrand.setText(""); txBrand.setError(getActivity().getResources().getString(R.string.validation_required)); txBrand.requestFocus(); } else if (TextUtils.isEmpty(txModel.getText().toString().trim())) { txModel.setText(""); txModel.setError(getActivity().getResources().getString(R.string.validation_required)); txModel.requestFocus(); } else if (TextUtils.isEmpty(txLicense.getText().toString().trim())) { txLicense.setText(""); txLicense.setError(getActivity().getResources().getString(R.string.validation_required)); txLicense.requestFocus(); } else if (TextUtils.isEmpty(txFare.getText().toString().trim())) { txFare.setText(""); txFare.setError(getActivity().getResources().getString(R.string.validation_required)); txFare.requestFocus(); } else { String confirmText; if (isAddCar) { confirmText = getActivity().getResources().getString(R.string.dialog_add_car_question); } else { confirmText = getActivity().getResources().getString(R.string.dialog_update_car_question); } new SweetAlertDialog(getActivity(), SweetAlertDialog.NORMAL_TYPE) .setTitleText(getActivity().getResources().getString(R.string.dialog_confirmation)) .setContentText(confirmText) .setCancelText(getActivity().getResources().getString(R.string.btn_cancel)) .setConfirmText(getActivity().getResources().getString(R.string.btn_save)) .showCancelButton(true) .setConfirmClickListener(new SweetAlertDialog.OnSweetClickListener() { @Override public void onClick(SweetAlertDialog sweetAlertDialog) { if (isAddCar) { saveNewCar(dialog, txBrand.getText().toString().trim(), txModel.getText().toString().trim(), Integer.parseInt(txFare.getText().toString().trim()), txLicense.getText().toString().trim()); } else { updateCar(dialog, cars.get(position).id, txBrand.getText().toString().trim(), txModel.getText().toString().trim(), Integer.parseInt(txFare.getText().toString().trim()), txLicense.getText().toString().trim()); } sweetAlertDialog.dismiss(); } }).show(); } } }); imgClose.setOnClickListener(new OnOneClickListener() { @Override public void onOneClick(View v) { Animation animation = AnimationUtils.loadAnimation(getActivity(), R.anim.bounce); animation.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { } @Override public void onAnimationEnd(Animation animation) { dialog.dismiss(); } @Override public void onAnimationRepeat(Animation animation) { } }); v.startAnimation(animation); } }); }
From source file:com.mEmoZz.qrgen.MainActivity.java
public void mCore() { Toast.makeText(getApplicationContext(), "Generating code...", Toast.LENGTH_SHORT).show(); new CountDownTimer(3000, 1000) { public void onTick(long millisUntilFinished) { }//from w w w .j av a 2s. co m public void onFinish() { Button yupBtn, delBtn, shareBtn; Toast.makeText(getApplicationContext(), "Success", Toast.LENGTH_SHORT).show(); final Dialog dialog = new Dialog(MainActivity.this); dialog.setContentView(R.layout.dialog); dialog.setTitle("Want to save?"); iv = (ImageView) dialog.findViewById(R.id.iv); iv.setImageBitmap(bm); shareBtn = (Button) dialog.findViewById(R.id.shareBtn); shareBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { shareIt(); } }); yupBtn = (Button) dialog.findViewById(R.id.btn1); yupBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mStream(); dialog.dismiss(); } }); delBtn = (Button) dialog.findViewById(R.id.btn2); delBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dialog.dismiss(); Toast.makeText(getApplicationContext(), "Deleted!", Toast.LENGTH_SHORT).show(); } }); dialog.show(); dialog.setCancelable(false); keepDialog(dialog); } }.start(); }
From source file:com.greatnowhere.radar.MainRadarActivity.java
private void showAboutDialog() { final Dialog d = new Dialog(this); d.setContentView(R.layout.about);//w w w.j av a 2s. co m d.setTitle(R.string.app_name); Button dialogOk = (Button) d.findViewById(R.id.aboutIdButtonOK); dialogOk.setOnClickListener(new OnClickListener() { public void onClick(View v) { d.dismiss(); } }); d.show(); }
From source file:com.citrus.sdk.fragments.SavedOptions.java
private void processCardFlow(final String txnId, final String signature, final String token) { final Dialog cvvDialog = new Dialog(getActivity()); LayoutInflater inflater = (LayoutInflater) getActivity().getApplicationContext() .getSystemService(Context.LAYOUT_INFLATER_SERVICE); cvvDialog.requestWindowFeature(Window.FEATURE_NO_TITLE); View view = inflater.inflate(R.layout.cvv, null); final EditText cvvEditText = (EditText) view.findViewById(R.id.cvvText); final TextView errorText = (TextView) view.findViewById(R.id.errorText); Button payButton = (Button) view.findViewById(R.id.payButton); payButton.setOnClickListener(new OnClickListener() { @Override/*from ww w.j a va 2s.co m*/ public void onClick(View v) { if (TextUtils.isEmpty(cvvEditText.getText().toString()) || cvvEditText.getText().toString().length() < 3) { errorText.setText("Invalid cvv"); } else { fillDetails(txnId, signature, token, cvvEditText.getText().toString()); cvvDialog.dismiss(); } } }); cvvDialog.setContentView(view); cvvDialog.show(); }
From source file:com.iskrembilen.quasseldroid.gui.LoginActivity.java
@Override protected Dialog onCreateDialog(int id) { final Dialog dialog; switch (id) { case R.id.DIALOG_EDIT_CORE: //fallthrough case R.id.DIALOG_ADD_CORE: dialog = new Dialog(this); dialog.setContentView(R.layout.dialog_add_core); dialog.setTitle("Add new core"); OnClickListener buttonListener = new OnClickListener() { @Override/*from w w w. ja v a 2 s .co m*/ public void onClick(View v) { EditText nameField = (EditText) dialog.findViewById(R.id.dialog_name_field); EditText addressField = (EditText) dialog.findViewById(R.id.dialog_address_field); EditText portField = (EditText) dialog.findViewById(R.id.dialog_port_field); CheckBox sslBox = (CheckBox) dialog.findViewById(R.id.dialog_usessl_checkbox); if (v.getId() == R.id.cancel_button) { nameField.setText(""); addressField.setText(""); portField.setText(""); sslBox.setChecked(false); dialog.dismiss(); } else if (v.getId() == R.id.save_button && !nameField.getText().toString().equals("") && !addressField.getText().toString().equals("") && !portField.getText().toString().equals("")) { String name = nameField.getText().toString().trim(); String address = addressField.getText().toString().trim(); int port = Integer.parseInt(portField.getText().toString().trim()); boolean useSSL = sslBox.isChecked(); //TODO: Ken: mabye add some better check on what state the dialog is used for, edit/add. Atleast use a string from the resources so its the same if you change it. if ((String) dialog.getWindow().getAttributes().getTitle() == "Add new core") { dbHelper.addCore(name, address, port, useSSL); } else if ((String) dialog.getWindow().getAttributes().getTitle() == "Edit core") { dbHelper.updateCore(core.getSelectedItemId(), name, address, port, useSSL); } LoginActivity.this.updateCoreSpinner(); nameField.setText(""); addressField.setText(""); portField.setText(""); sslBox.setChecked(false); dialog.dismiss(); if ((String) dialog.getWindow().getAttributes().getTitle() == "Add new core") { Toast.makeText(LoginActivity.this, "Added core", Toast.LENGTH_LONG).show(); } else if ((String) dialog.getWindow().getAttributes().getTitle() == "Edit core") { Toast.makeText(LoginActivity.this, "Edited core", Toast.LENGTH_LONG).show(); } } } }; dialog.findViewById(R.id.cancel_button).setOnClickListener(buttonListener); dialog.findViewById(R.id.save_button).setOnClickListener(buttonListener); break; case R.id.DIALOG_NEW_CERTIFICATE: AlertDialog.Builder builder = new AlertDialog.Builder(LoginActivity.this); final SharedPreferences certPrefs = getSharedPreferences("CertificateStorage", Context.MODE_PRIVATE); builder.setMessage("Received a new certificate, do you trust it?\n" + hashedCert).setCancelable(false) .setPositiveButton("Yes", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { certPrefs.edit().putString("certificate", hashedCert).commit(); onConnect.onClick(null); } }).setNegativeButton("No", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); dialog = builder.create(); break; default: dialog = null; break; } return dialog; }
From source file:com.google.ytd.SubmitActivity.java
@Override protected Dialog onCreateDialog(int id) { final Dialog dialog = new Dialog(SubmitActivity.this); dialog.setTitle("Terms of Service"); switch (id) { case DIALOG_LEGAL: dialog.setContentView(R.layout.legal); TextView legalText = (TextView) dialog.findViewById(R.id.legal); legalText.setText(Util.readFile(this, R.raw.legal).toString()); dialog.findViewById(R.id.agree).setOnClickListener(new OnClickListener() { @Override/*from w ww . j av a 2 s.c om*/ public void onClick(View v) { dialog.cancel(); getAuthTokenWithPermission(youTubeName); } }); dialog.findViewById(R.id.notagree).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { dialog.cancel(); } }); break; } return dialog; }
From source file:no.ntnu.idi.socialhitchhiking.map.MapActivityJourney.java
/** * sends a message to the driver of a journey *//*from ww w . ja va 2s . co m*/ private void sendMessageToDriver() { final Dialog customDialog = new Dialog(this); customDialog.setContentView(R.layout.custom_dialog_layout); customDialog.setTitle("Message"); final List<String> spinnerArray = new ArrayList<String>(); spinnerArray.add("Everyone"); if (!getApp().getSelectedJourney().getDriver().equals(getApp().getUser())) { spinnerArray.add(getApp().getSelectedJourney().getDriver().getFullName()); } for (int i = 0; i < getApp().getSelectedJourney().getHitchhikers().size(); i++) { if (!getApp().getSelectedJourney().getHitchhikers().get(i).equals(getApp().getUser())) { spinnerArray.add(getApp().getSelectedJourney().getHitchhikers().get(i).getFullName()); } } final Spinner spinner = (Spinner) customDialog.findViewById(R.id.spinner); ArrayAdapter<String> adapter = new ArrayAdapter<String>(MapActivityJourney.this, android.R.layout.simple_spinner_item, spinnerArray); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner.setAdapter(adapter); ImageView sendBtn = (ImageView) customDialog.findViewById(R.id.sendBtn); final EditText input = (EditText) customDialog.findViewById(R.id.input); sendBtn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { User mid = getApp().getUser(); if (spinner.getSelectedItem().toString().equals("Everyone")) { if (input.getText().toString().equals("")) { input.setHint("Please fill in your message"); Toast toast = Toast.makeText(MapActivityJourney.this, "Please fill in your message", Toast.LENGTH_SHORT); toast.setGravity(Gravity.BOTTOM, toast.getXOffset() / 2, toast.getYOffset() / 2); toast.show(); } else { List<User> userList = new ArrayList<User>(); userList.add(getApp().getSelectedJourney().getDriver()); for (int k = 0; k < getApp().getSelectedJourney().getHitchhikers().size(); k++) { userList.add(getApp().getSelectedJourney().getHitchhikers().get(k)); } userList.remove(getApp().getUser()); for (int k = 0; k < userList.size(); k++) { sendMessage(userList.get(k), input); } Toast toast = Toast.makeText(MapActivityJourney.this, "Message sent", Toast.LENGTH_SHORT); toast.setGravity(Gravity.BOTTOM, toast.getXOffset() / 2, toast.getYOffset() / 2); toast.show(); customDialog.dismiss(); } } else { for (int j = 0; j < getApp().getSelectedJourney().getHitchhikers().size(); j++) { if (spinner.getSelectedItem().toString() .equals(getApp().getSelectedJourney().getHitchhikers().get(j).getFullName())) { mid = getApp().getSelectedJourney().getHitchhikers().get(j); } } if (spinner.getSelectedItem().toString() .equals(getApp().getSelectedJourney().getDriver().getFullName())) { mid = getApp().getSelectedJourney().getDriver(); } if (input.getText().toString().equals("")) { input.setHint("Please fill in your message"); Toast toast = Toast.makeText(MapActivityJourney.this, "Please fill in your message", Toast.LENGTH_SHORT); toast.setGravity(Gravity.BOTTOM, toast.getXOffset() / 2, toast.getYOffset() / 2); toast.show(); } else { sendMessage(mid, input); Toast toast = Toast.makeText(MapActivityJourney.this, "Message sent", Toast.LENGTH_SHORT); toast.setGravity(Gravity.BOTTOM, toast.getXOffset() / 2, toast.getYOffset() / 2); toast.show(); customDialog.dismiss(); } } } }); customDialog.show(); }
From source file:com.wrmndfzzy.atomize.intro.IntroActivity.java
protected void permissionsDialog() { final Dialog pDialog = new Dialog(IntroActivity.this); pDialog.requestWindowFeature(Window.FEATURE_NO_TITLE); pDialog.setTitle("Missing Permissions"); pDialog.setContentView(R.layout.intro_permissions_dialog); pDialogConfirm = (Button) pDialog.findViewById(R.id.ipDialogConfirm); pDialogConfirm.setOnClickListener(new View.OnClickListener() { @Override// ww w .jav a 2 s. c o m public void onClick(View v) { pDialog.dismiss(); IntroActivity.this.finish(); } }); pDialog.show(); }
From source file:com.adithya321.sharesanalysis.fragments.SalesShareFragment.java
private void setRecyclerViewAdapter() { sharesList = databaseHandler.getShares(); final List<Purchase> salesList = databaseHandler.getSales(); PurchaseShareAdapter purchaseAdapter = new PurchaseShareAdapter(getContext(), salesList); purchaseAdapter.setOnItemClickListener(new PurchaseShareAdapter.OnItemClickListener() { @Override//from w ww. jav a 2 s. co m public void onItemClick(View itemView, int position) { final Purchase purchase = salesList.get(position); final Dialog dialog = new Dialog(getActivity()); dialog.setTitle("Edit Share Sale"); dialog.setContentView(R.layout.dialog_sell_share_holdings); dialog.getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT); dialog.show(); final Spinner spinner = (Spinner) dialog.findViewById(R.id.existing_spinner); ArrayList<String> shares = new ArrayList<>(); int pos = 0; for (int i = 0; i < sharesList.size(); i++) { shares.add(sharesList.get(i).getName()); if (sharesList.get(i).getName().equals(purchase.getName())) pos = i; } ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<>(getActivity(), android.R.layout.simple_spinner_item, shares); spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner.setAdapter(spinnerAdapter); spinner.setSelection(pos); spinner.setVisibility(View.VISIBLE); final EditText quantity = (EditText) dialog.findViewById(R.id.no_of_shares); final EditText price = (EditText) dialog.findViewById(R.id.selling_price); quantity.setText(String.valueOf(purchase.getQuantity())); price.setText(String.valueOf(purchase.getPrice())); Calendar calendar = Calendar.getInstance(); calendar.setTime(purchase.getDate()); year_start = calendar.get(Calendar.YEAR); month_start = calendar.get(Calendar.MONTH) + 1; day_start = calendar.get(Calendar.DAY_OF_MONTH); final Button selectDate = (Button) dialog.findViewById(R.id.select_date); selectDate.setText(new StringBuilder().append(day_start).append("/").append(month_start).append("/") .append(year_start)); selectDate.setOnClickListener(SalesShareFragment.this); Button sellShareBtn = (Button) dialog.findViewById(R.id.sell_share_btn); sellShareBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Purchase p = new Purchase(); p.setId(purchase.getId()); String stringStartDate = year_start + " " + month_start + " " + day_start; DateFormat format = new SimpleDateFormat("yyyy MM dd", Locale.ENGLISH); try { Date date = format.parse(stringStartDate); p.setDate(date); } catch (Exception e) { Toast.makeText(getActivity(), "Invalid Date", Toast.LENGTH_SHORT).show(); return; } try { p.setQuantity(Integer.parseInt(quantity.getText().toString())); } catch (Exception e) { Toast.makeText(getActivity(), "Invalid Number of Shares", Toast.LENGTH_SHORT).show(); return; } try { p.setPrice(Double.parseDouble(price.getText().toString())); } catch (Exception e) { Toast.makeText(getActivity(), "Invalid Buying Price", Toast.LENGTH_SHORT).show(); return; } p.setType("sell"); p.setName(spinner.getSelectedItem().toString()); databaseHandler.updatePurchase(p); setRecyclerViewAdapter(); dialog.dismiss(); } }); } }); salesRecyclerView.setHasFixedSize(true); salesRecyclerView.setAdapter(purchaseAdapter); salesRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity())); }