List of usage examples for android.app Dialog setTitle
public void setTitle(@StringRes int titleId)
From source file:no.ntnu.idi.socialhitchhiking.map.MapActivityJourney.java
/** * sends a message to the driver of a journey *///from www . j a va2 s . c o 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.orange.datavenue.StreamListFragment.java
/** * *//*from w w w . java2s .co m*/ private void deleteStream() { final android.app.Dialog dialog = new android.app.Dialog(getActivity()); dialog.setContentView(R.layout.delete_dialog); dialog.setTitle(R.string.delete); TextView info = (TextView) dialog.findViewById(R.id.info_label); info.setText(String.format(getString(R.string.delete_stream), Model.instance.currentStream.getId())); Button deleteButton = (Button) dialog.findViewById(R.id.delete_button); deleteButton.setOnClickListener(new Button.OnClickListener() { @Override public void onClick(View view) { Log.d(TAG_NAME, "datasource : " + Model.instance.currentDatasource.getId()); Log.d(TAG_NAME, "stream : " + Model.instance.currentStream.getId()); DeleteStreamOperation deleteStreamOperation = new DeleteStreamOperation(Model.instance.oapiKey, Model.instance.key, Model.instance.currentDatasource, Model.instance.currentStream, new OperationCallback() { @Override public void process(Object object, Exception exception) { if (exception == null) { getStreams(); // reload } else { Errors.displayError(getActivity(), exception); } } }); deleteStreamOperation.execute(""); dialog.dismiss(); } }); Button cancelDeleteButton = (Button) dialog.findViewById(R.id.cancel_button); cancelDeleteButton.setOnClickListener(new Button.OnClickListener() { @Override public void onClick(View arg0) { dialog.dismiss(); } }); dialog.setCancelable(false); dialog.show(); }
From source file:com.zapto.park.ParkActivity.java
public boolean onOptionsItemSelected(MenuItem item) { Intent i = null;// w w w. j a v a 2 s. co m switch (item.getItemId()) { // Add User case 1: Dialog d = new Dialog(cActivity); final Dialog dialog = d; d.setContentView(R.layout.dialog_add_employee); d.setTitle(R.string.create_user_title); final EditText first_name = (EditText) d.findViewById(R.id.employee_first); final EditText last_name = (EditText) d.findViewById(R.id.employee_last); Button button_getinfo = (Button) d.findViewById(R.id.button_getinfo); button_getinfo.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { EmployeeDB edb = new EmployeeDB(context); String first = first_name.getText().toString(); String last = last_name.getText().toString(); ContentValues cv = new ContentValues(); cv.put("totable_first", first); cv.put("totable_last", last); cv.put("totable_license", Globals.LICENSE_KEY); // Log request in database. ContentValues cv2 = new ContentValues(); cv2.put("first", first); cv2.put("last", last); // Query database. edb.insertEmployee(cv2); // Close our database. edb.close(); dialog.dismiss(); } }); d.show(); break; // Settings case 2: Log.i(LOG_TAG, "Settings menu clicked."); i = new Intent(this, SettingsActivity.class); startActivity(i); break; case 3: Log.i(LOG_TAG, "View Log Loading."); i = new Intent(this, ListViewActivity.class); startActivity(i); break; case 4: doInit(); Handler handler = new Handler(); handler.post(new Runnable() { @Override public void run() { updateEmployees(); doPendingRequests(); } }); break; case 5: Log.i(LOG_TAG, "SendEmailActivity Loading."); i = new Intent(this, SendEmailActivity.class); startActivity(i); break; case 6: Log.i(LOG_TAG, "View Log Loading."); i = new Intent(this, ListViewActivity.class); startActivity(i); break; } return true; }
From source file:com.digium.respoke.GroupListActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); if (id == R.id.action_join) { final Dialog dialog = new Dialog(this); dialog.setContentView(R.layout.dialog_join_group); dialog.setTitle("Join a group"); Button dialogButton = (Button) dialog.findViewById(R.id.button1); TextView errorText = (TextView) dialog.findViewById(R.id.errorText); errorText.setText(""); // if button is clicked, close the custom dialog dialogButton.setOnClickListener(new View.OnClickListener() { @Override//from w w w . jav a 2 s. c o m public void onClick(View v) { Button connectButton = (Button) dialog.findViewById(R.id.button1); ProgressBar progressCircle = (ProgressBar) dialog.findViewById(R.id.progress_circle); EditText userInput = (EditText) dialog.findViewById(R.id.editTextDialogUserInput); String groupID = userInput.getText().toString(); if (groupID.length() > 0) { TextView errorText = (TextView) dialog.findViewById(R.id.errorText); errorText.setText(""); connectButton.setText(""); progressCircle.setVisibility(View.VISIBLE); ContactManager.sharedInstance().joinGroup(groupID, new Respoke.TaskCompletionListener() { @Override public void onSuccess() { dialog.dismiss(); } @Override public void onError(final String errorMessage) { Button connectButton = (Button) dialog.findViewById(R.id.button1); ProgressBar progressCircle = (ProgressBar) dialog .findViewById(R.id.progress_circle); TextView errorText = (TextView) dialog.findViewById(R.id.errorText); errorText.setText(errorMessage); connectButton.setText("Connect"); progressCircle.setVisibility(View.INVISIBLE); } }); } else { TextView errorText = (TextView) dialog.findViewById(R.id.errorText); errorText.setText("Group name may not be blank"); } } }); dialog.show(); return true; } return super.onOptionsItemSelected(item); }
From source file:com.github.michalbednarski.intentslab.editor.FindComponentDialog.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { final Dialog dialog = super.onCreateDialog(savedInstanceState); dialog.setTitle(R.string.find); dialog.setOnKeyListener(this); return dialog; }
From source file:com.ibm.hellotodo.MainActivity.java
/** * Launches a dialog for adding a new TodoItem. Called when plus button is tapped. * * @param view The plus button that is tapped. *//* w w w. j a va 2 s . c om*/ public void addTodo(View view) { final Dialog addDialog = new Dialog(this); addDialog.setContentView(R.layout.add_edit_dialog); addDialog.setTitle("Add Todo"); TextView textView = (TextView) addDialog.findViewById(android.R.id.title); if (textView != null) { textView.setGravity(Gravity.CENTER); } addDialog.setCancelable(true); Button add = (Button) addDialog.findViewById(R.id.Add); addDialog.show(); // When done is pressed, send POST request to create TodoItem on Bluemix add.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { EditText itemToAdd = (EditText) addDialog.findViewById(R.id.todo); final String name = itemToAdd.getText().toString(); // If text was added, continue with normal operations if (!name.isEmpty()) { // Create JSON for new TodoItem, id should be 0 for new items String json = "{\"text\":\"" + name + "\",\"isDone\":false,\"id\":0}"; // Create POST request with IBM Mobile First SDK and set HTTP headers so Bluemix knows what to expect in the request Request request = new Request(client.getBluemixAppRoute() + "/api/Items", Request.POST); HashMap headers = new HashMap(); List<String> cType = new ArrayList<>(); cType.add("application/json"); List<String> accept = new ArrayList<>(); accept.add("Application/json"); headers.put("Content-Type", cType); headers.put("Accept", accept); request.setHeaders(headers); request.send(getApplicationContext(), json, new ResponseListener() { // On success, update local list with new TodoItem @Override public void onSuccess(Response response) { Log.i(TAG, "Item created successfully"); loadList(); } // On failure, log errors @Override public void onFailure(Response response, Throwable t, JSONObject extendedInfo) { String errorMessage = ""; if (response != null) { errorMessage += response.toString() + "\n"; } if (t != null) { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); t.printStackTrace(pw); errorMessage += "THROWN" + sw.toString() + "\n"; } if (extendedInfo != null) { errorMessage += "EXTENDED_INFO" + extendedInfo.toString() + "\n"; } if (errorMessage.isEmpty()) errorMessage = "Request Failed With Unknown Error."; Log.e(TAG, "addTodo failed with error: " + errorMessage); } }); } // Kill dialog when finished, or if no text was added addDialog.dismiss(); } }); }
From source file:com.ibm.hellotodo.MainActivity.java
/** * Launches a dialog for updating the TodoItem name. Called when the list item is tapped. * * @param view The TodoItem that is tapped. *//*from w w w . j ava 2 s. co m*/ public void editTodoName(View view) { // Gets position in list view of tapped item final Integer pos = mListView.getPositionForView(view); final Dialog addDialog = new Dialog(this); addDialog.setContentView(R.layout.add_edit_dialog); addDialog.setTitle("Edit Todo"); TextView textView = (TextView) addDialog.findViewById(android.R.id.title); if (textView != null) { textView.setGravity(Gravity.CENTER); } addDialog.setCancelable(true); EditText et = (EditText) addDialog.findViewById(R.id.todo); final String name = mTodoItemList.get(pos).text; final boolean isDone = mTodoItemList.get(pos).isDone; final int id = mTodoItemList.get(pos).idNumber; et.setText(name); Button addDone = (Button) addDialog.findViewById(R.id.Add); addDialog.show(); // When done is pressed, send PUT request to update TodoItem on Bluemix addDone.setOnClickListener(new View.OnClickListener() { // Save text inputted when done is tapped @Override public void onClick(View view) { EditText editedText = (EditText) addDialog.findViewById(R.id.todo); String newName = editedText.getText().toString(); // If new text is not empty, create JSON with updated info and send PUT request if (!newName.isEmpty()) { String json = "{\"text\":\"" + newName + "\",\"isDone\":" + isDone + ",\"id\":" + id + "}"; // Create PUT REST request using the IBM Mobile First SDK and set HTTP headers so Bluemix knows what to expect in the request Request request = new Request(client.getBluemixAppRoute() + "/api/Items", Request.PUT); HashMap headers = new HashMap(); List<String> cType = new ArrayList<>(); cType.add("application/json"); List<String> accept = new ArrayList<>(); accept.add("Application/json"); headers.put("Content-Type", cType); headers.put("Accept", accept); request.setHeaders(headers); request.send(getApplicationContext(), json, new ResponseListener() { // On success, update local list with updated TodoItem @Override public void onSuccess(Response response) { Log.i(TAG, "Item updated successfully"); loadList(); } // On failure, log errors @Override public void onFailure(Response response, Throwable t, JSONObject extendedInfo) { String errorMessage = ""; if (response != null) { errorMessage += response.toString() + "\n"; } if (t != null) { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); t.printStackTrace(pw); errorMessage += "THROWN" + sw.toString() + "\n"; } if (extendedInfo != null) { errorMessage += "EXTENDED_INFO" + extendedInfo.toString() + "\n"; } if (errorMessage.isEmpty()) errorMessage = "Request Failed With Unknown Error."; Log.e(TAG, "editTodoName failed with error: " + errorMessage); } }); } addDialog.dismiss(); } }); }
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 www . jav a 2 s. c om*/ 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.digitallizard.nicecompass.CompassActivity.java
protected Dialog onCreateDialog(int id) { Dialog dialog = null; // create a generic select bearing dialog dialog = createSelectBearingDialog(); Button setButton = (Button) dialog.findViewById(R.id.bearingSetButton); Button autoButton = (Button) dialog.findViewById(R.id.bearingAutoButton); switch (id) { case DIALOG_SELECT_LOCKED_BEARING: // set the title dialog.setTitle(this.getResources().getString(R.string.menu_title_manual_locked_brearing)); // get a reference to the textview for the callbacks //FIXME shouldn't store the reference like this lockedBearingEditText = (EditText) dialog.findViewById(R.id.bearingSelectionText); // add the appropriate listeners to the dialog buttons // add a listener to the set button setButton.setOnClickListener(new View.OnClickListener() { @Override// w w w.jav a 2s. co m public void onClick(View view) { // get the value and save it as required float value = 0; try { value = Float.parseFloat(lockedBearingEditText.getText().toString()); } catch (NumberFormatException e) { // probably a temporary error, just give up for now return; } // convert the value to a whole number value = (float) Math.floor(value); // make the value positive if (value < 0) { value *= -1f; } // if the value is out of range, move it to within range value = value % 360; lockedBearingEditText.setText(Integer.toString((int) value)); // lock the bearing to the value surface.lockBearingTo((int) value); // close the dialog closeBearingDialog(DIALOG_SELECT_LOCKED_BEARING); } }); // add a listener to the auto button autoButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { surface.unlockBearing(); // close the dialog closeBearingDialog(DIALOG_SELECT_LOCKED_BEARING); } }); break; case DIALOG_SELECT_VARIATION: // set the title dialog.setTitle(this.getResources().getString(R.string.menu_title_manual_variation)); // get a reference to the textview for the callbacks //FIXME shouldn't store the reference like this selectVariationEditText = (EditText) dialog.findViewById(R.id.bearingSelectionText); // add the appropriate listeners to the dialog buttons // add a listener to the set button setButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { // get the value and save it as required float value = 0; try { value = Float.parseFloat(selectVariationEditText.getText().toString()); } catch (NumberFormatException e) { // probably a temporary error, just give up for now return; } // set the manual declination surface.setManualDeclination(value); // close the dialog closeBearingDialog(DIALOG_SELECT_VARIATION); } }); // add a listener to the auto button autoButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { // disable manual declination surface.useAutoDeclination(); // close the dialog closeBearingDialog(DIALOG_SELECT_VARIATION); } }); break; default: dialog = null; } return dialog; }