List of usage examples for android.widget EditText getText
@Override
public Editable getText()
From source file:com.andrewshu.android.reddit.submit.SubmitLinkActivity.java
/** * Enable the UI after user is logged in. *//*from w ww . j a va 2s .c o m*/ private void start() { // Intents can be external (browser share page) or from Reddit is fun. String intentAction = getIntent().getAction(); if (Intent.ACTION_SEND.equals(intentAction)) { // Share Bundle extras = getIntent().getExtras(); if (extras != null) { String url = extras.getString(Intent.EXTRA_TEXT); final EditText submitLinkUrl = (EditText) findViewById(R.id.submit_link_url); final EditText submitLinkReddit = (EditText) findViewById(R.id.submit_link_reddit); final EditText submitTextReddit = (EditText) findViewById(R.id.submit_text_reddit); submitLinkUrl.setText(url); submitLinkReddit.setText(""); submitTextReddit.setText(""); mSubmitUrl = Constants.REDDIT_BASE_URL + "/submit"; } } else { String submitPath = null; Uri data = getIntent().getData(); if (data != null && Util.isRedditUri(data)) submitPath = data.getPath(); if (submitPath == null) submitPath = "/submit"; // the URL to do HTTP POST to mSubmitUrl = Util.absolutePathToURL(submitPath); // Put the subreddit in the text field final EditText submitLinkReddit = (EditText) findViewById(R.id.submit_link_reddit); final EditText submitTextReddit = (EditText) findViewById(R.id.submit_text_reddit); Matcher m = SUBMIT_PATH_PATTERN.matcher(submitPath); if (m.matches()) { String subreddit = m.group(1); if (StringUtils.isEmpty(subreddit)) { submitLinkReddit.setText(""); submitTextReddit.setText(""); } else { submitLinkReddit.setText(subreddit); submitTextReddit.setText(subreddit); } } } final Button submitLinkButton = (Button) findViewById(R.id.submit_link_button); submitLinkButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { if (validateLinkForm()) { final EditText submitLinkTitle = (EditText) findViewById(R.id.submit_link_title); final EditText submitLinkUrl = (EditText) findViewById(R.id.submit_link_url); final EditText submitLinkReddit = (EditText) findViewById(R.id.submit_link_reddit); final EditText submitLinkCaptcha = (EditText) findViewById(R.id.submit_link_captcha); new SubmitLinkTask(submitLinkTitle.getText().toString(), submitLinkUrl.getText().toString(), submitLinkReddit.getText().toString(), Constants.SUBMIT_KIND_LINK, submitLinkCaptcha.getText().toString()).execute(); } } }); final Button submitTextButton = (Button) findViewById(R.id.submit_text_button); submitTextButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { if (validateTextForm()) { final EditText submitTextTitle = (EditText) findViewById(R.id.submit_text_title); final EditText submitTextText = (EditText) findViewById(R.id.submit_text_text); final EditText submitTextReddit = (EditText) findViewById(R.id.submit_text_reddit); final EditText submitTextCaptcha = (EditText) findViewById(R.id.submit_text_captcha); new SubmitLinkTask(submitTextTitle.getText().toString(), submitTextText.getText().toString(), submitTextReddit.getText().toString(), Constants.SUBMIT_KIND_SELF, submitTextCaptcha.getText().toString()).execute(); } } }); // Check the CAPTCHA new MyCaptchaCheckRequiredTask().execute(); }
From source file:com.brewcrewfoo.performance.activities.PCSettings.java
@Override public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) { String key = preference.getKey(); if (key.equals("use_light_theme")) { mPreferences.edit().putBoolean("theme_changed", true).commit(); finish();//from w w w .ja v a2 s . c om return true; } else if (key.equals("visible_tabs")) { startActivity(new Intent(this, HideTabs.class)); return true; } else if (key.equals("boot_mode")) { if (mInitd.isChecked()) { LayoutInflater factory = LayoutInflater.from(this); final View editDialog = factory.inflate(R.layout.prop_edit_dialog, null); final EditText tv = (EditText) editDialog.findViewById(R.id.vprop); final TextView tn = (TextView) editDialog.findViewById(R.id.nprop); tv.setText(mPreferences.getString("script_name", "99PC")); tn.setText(""); tn.setVisibility(TextView.GONE); new AlertDialog.Builder(this).setTitle(getString(R.string.pt_script_name)).setView(editDialog) .setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String s = tv.getText().toString(); if ((s != null) && (s.length() > 0)) { mPreferences.edit().putString("script_name", s).apply(); } mInitd.setSummary(INIT_D + mPreferences.getString("script_name", "99PC")); new BootClass(c, mPreferences).writeScript(); } }).create().show(); } else { final StringBuilder sb = new StringBuilder(); sb.append("mount -o rw,remount /system;\n"); sb.append("busybox rm ").append(INIT_D).append(mPreferences.getString("script_name", "99PC")) .append(";\n"); sb.append("mount -o ro,remount /system;\n"); Helpers.shExec(sb, c, true); } return true; } else if (key.equals("int_sd")) { LayoutInflater factory = LayoutInflater.from(this); final View editDialog = factory.inflate(R.layout.prop_edit_dialog, null); final EditText tv = (EditText) editDialog.findViewById(R.id.vprop); final TextView tn = (TextView) editDialog.findViewById(R.id.nprop); tv.setText(""); tn.setText(getString(R.string.info_auto_sd)); new AlertDialog.Builder(this).setTitle(getString(R.string.pt_int_sd)).setView(editDialog) .setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String s = tv.getText().toString(); if ((s != null) && (s.length() > 0)) { if (s.endsWith("/")) { s = s.substring(0, s.length() - 1); } if (!s.startsWith("/")) { s = "/" + s; } final File dir = new File(s); if (dir.exists() && dir.isDirectory() && dir.canRead() && dir.canWrite()) mPreferences.edit().putString("int_sd_path", s).apply(); } else { mPreferences.edit().remove("int_sd_path").apply(); } mIntSD.setSummary(mPreferences.getString("int_sd_path", Environment.getExternalStorageDirectory().getAbsolutePath())); } }).create().show(); } else if (key.equals("ext_sd")) { LayoutInflater factory = LayoutInflater.from(this); final View editDialog = factory.inflate(R.layout.prop_edit_dialog, null); final EditText tv = (EditText) editDialog.findViewById(R.id.vprop); final TextView tn = (TextView) editDialog.findViewById(R.id.nprop); tv.setText(""); tn.setText(getString(R.string.info_auto_sd)); new AlertDialog.Builder(this).setTitle(getString(R.string.pt_ext_sd)).setView(editDialog) .setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String s = tv.getText().toString(); if ((s != null) && (s.length() > 0)) { if (s.endsWith("/")) { s = s.substring(0, s.length() - 1); } if (!s.startsWith("/")) { s = "/" + s; } final File dir = new File(s); if (dir.exists() && dir.isDirectory() && dir.canRead() && dir.canWrite()) mPreferences.edit().putString("ext_sd_path", s).apply(); } else { mPreferences.edit().remove("ext_sd_path").apply(); } mExtSD.setSummary(mPreferences.getString("ext_sd_path", Helpers.extSD())); } }).create().show(); } else if (key.equals("br_op")) { startActivity(new Intent(this, BackupRestore.class)); } else if (key.equals("version_info")) { if (isupdate && !NO_UPDATE) { LayoutInflater factory = LayoutInflater.from(this); final View editDialog = factory.inflate(R.layout.ver_dialog, null); final TextView msg = (TextView) editDialog.findViewById(R.id.msg); msg.setText(det); new AlertDialog.Builder(c).setView(editDialog).setTitle(getString(R.string.pt_update)) .setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }) .setPositiveButton(getString(R.string.btn_download), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (isDownloadManagerAvailable(c)) { String url = URL + TAG + ".apk"; DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url)); //request.setDescription(""); request.setTitle(TAG + " " + ver); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { request.allowScanningByMediaScanner(); request.setNotificationVisibility( DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); } request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, TAG + "-" + ver + ".apk"); DownloadManager manager = (DownloadManager) getSystemService( Context.DOWNLOAD_SERVICE); manager.enqueue(request); } else { Toast.makeText(c, getString(R.string.no_download_manager), Toast.LENGTH_LONG) .show(); } } }).create().show(); } return true; } else if (key.equals("pref_donate")) { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(PAYPAL + PAYPAL_BTN))); } return false; }
From source file:edu.cmu.hcii.hangg.beeksbeacon.Fragments.ManageBeaconFragment.java
private View.OnClickListener makeInsertAttachmentOnClickListener(final Button insertButton, final TextView namespaceTextView, final EditText typeEditText, final EditText dataEditText) { return new View.OnClickListener() { @Override/*from w w w.j a va 2 s . co m*/ public void onClick(View v) { final String namespace = namespaceTextView.getText().toString(); if (namespace.length() == 0) { toast("namespace cannot be empty"); return; } String type = typeEditText.getText().toString(); if (type.length() == 0) { toast("type cannot be empty"); return; } final String data = dataEditText.getText().toString(); if (data.length() == 0) { toast("data cannot be empty"); return; } Utils.setEnabledViews(false, insertButton); JSONObject body = buildCreateAttachmentJsonBody(namespace, type, data); Callback createAttachmentCallback = new Callback() { @Override public void onFailure(Request request, IOException e) { logErrorAndToast("Failed request: " + request, e); Utils.setEnabledViews(false, insertButton); } @Override public void onResponse(Response response) throws IOException { String body = response.body().string(); if (response.isSuccessful()) { try { JSONObject json = new JSONObject(body); attachmentsTable.addView(makeAttachmentRow(json), 2); namespaceTextView.setText(namespace); typeEditText.setText(""); typeEditText.requestFocus(); dataEditText.setText(""); insertButton.setEnabled(true); } catch (JSONException e) { logErrorAndToast("JSONException in building attachment data", e); } } else { logErrorAndToast("Unsuccessful createAttachment request: " + body); } Utils.setEnabledViews(true, insertButton); } }; client.createAttachment(createAttachmentCallback, beaconInstance.getBeaconName(), body); } }; }
From source file:samsungsami.io.example.samiremotecontrol.DeviceActivity.java
public void addFallback() { final ObjectMapper mapper = new ObjectMapper(); TextView textView = new TextView(this); textView.setText("fallback"); LinearLayout gridLayout = (LinearLayout) findViewById(R.id.gridLayout); gridLayout.addView(textView);//www. j av a 2s.c o m final EditText editText; editText = new EditText(this); Button button = new Button(this); button.setText("send"); button.setTextAppearance(this, android.R.style.TextAppearance_Small); button.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { MessagesApi msgApi = new MessagesApi(); msgApi.setBasePath(SamiHelper.SAMIHUB_BASE_PATH); msgApi.getInvoker().addDefaultHeader("Authorization", "bearer " + SamiHelper.getAccessToken()); sendCommandMessage = new Message(); sendCommandMessage.setSdid(did); sendCommandMessage.setDdid(did); sendCommandMessage.setToken("fakeToken"); try { Map<String, Object> messageData = mapper.readValue(editText.getText().toString(), Map.class); sendCommandMessage.setData(messageData); new CallPostMessageApiInBackground().execute(msgApi); } catch (IOException e) { } } }); gridLayout.addView(editText); gridLayout.addView(button); }
From source file:com.mobile.godot.activity.LauncherActivity.java
private AlertDialog buildDialogUserRegistration() { AlertDialog dialogUserRegistration;// w w w .ja va2 s . co m AlertDialog.Builder builderDialogUserRegistration = new AlertDialog.Builder(this); builderDialogUserRegistration.setTitle(R.string.dilog_title_user_registration) .setIcon(R.drawable.ic_launcher); LayoutInflater inflaterDialogUserRegistration = (LayoutInflater) this .getSystemService(LAYOUT_INFLATER_SERVICE); View contentDialogUserRegistration = inflaterDialogUserRegistration.inflate( R.layout.dialog_user_registration, (ViewGroup) findViewById(R.id.dialog_user_registration_root)); builderDialogUserRegistration.setView(contentDialogUserRegistration); final EditText etFirstname = (EditText) contentDialogUserRegistration.findViewById(R.id.etFirstname); final EditText etLastname = (EditText) contentDialogUserRegistration.findViewById(R.id.etLastname); final EditText etMail = (EditText) contentDialogUserRegistration.findViewById(R.id.etMail); final EditText etUsername = (EditText) contentDialogUserRegistration.findViewById(R.id.etUsername); final EditText etPassword = (EditText) contentDialogUserRegistration.findViewById(R.id.etPassword); builderDialogUserRegistration.setPositiveButton(R.string.register, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { String firstname = etFirstname.getText().toString(); String lastname = etLastname.getText().toString(); String mail = etMail.getText().toString(); String username = etUsername.getText().toString(); String password = etPassword.getText().toString(); UserBean user = new UserBean().setFirstname(firstname).setLastname(lastname).setMail(mail) .setUsername(username).setPassword(password); registerNewUser(user); } }); builderDialogUserRegistration.setNegativeButton(R.string.dialog_button_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { Toast.makeText(getApplicationContext(), R.string.toast_we_would_be_glad, Toast.LENGTH_SHORT) .show(); } }); dialogUserRegistration = builderDialogUserRegistration.create(); return dialogUserRegistration; }
From source file:com.rsltc.profiledata.main.MainActivity.java
private void showSaveDialog(final List<JSONObject> jsonObjectList) { AlertDialog.Builder builder = new AlertDialog.Builder(thisActivity); builder.setTitle("Dataset title"); final EditText input = new EditText(thisActivity); input.setInputType(InputType.TYPE_CLASS_TEXT); builder.setView(input);// www.jav a 2s . c om builder.setPositiveButton("OK", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { final String m_Text = input.getText().toString(); Runnable r = new Runnable() { @Override public void run() { exportFile(jsonObjectList, m_Text); } }; Thread t = new Thread(r); t.start(); } }); builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); builder.show(); }
From source file:com.krayzk9s.imgurholo.ui.AlbumsFragment.java
@Override public boolean onOptionsItemSelected(MenuItem item) { // handle item selection Activity activity = getActivity();//from w w w . j av a 2s. c o m switch (item.getItemId()) { case R.id.action_refresh: urls = new ArrayList<String>(); imageAdapter.notifyDataSetChanged(); getImages(); return true; case R.id.action_new: final EditText newTitle = new EditText(activity); newTitle.setSingleLine(); newTitle.setHint(R.string.hint_album_title); final EditText newDescription = new EditText(activity); newDescription.setHint(R.string.body_hint_description); LinearLayout linearLayout = new LinearLayout(activity); linearLayout.setOrientation(LinearLayout.VERTICAL); linearLayout.addView(newTitle); linearLayout.addView(newDescription); new AlertDialog.Builder(activity).setTitle(R.string.dialog_new_album_title).setView(linearLayout) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { NewAlbumAsync messagingAsync = new NewAlbumAsync(newTitle.getText().toString(), newDescription.getText().toString(), ((ImgurHoloActivity) getActivity()).getApiCall(), null, null); messagingAsync.execute(); } }).setNegativeButton(R.string.dialog_answer_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { // Do nothing. } }).show(); return true; default: return super.onOptionsItemSelected(item); } }
From source file:com.duy.pascal.ui.file.fragment.FragmentFileManager.java
/** * show dialog create new file/*from ww w . j a v a2 s . com*/ */ @Override public void createNewFile() { AlertDialog.Builder builder = new AlertDialog.Builder(getContext()); builder.setTitle(R.string.new_file); builder.setView(R.layout.dialog_new_file); final AlertDialog alertDialog = builder.create(); alertDialog.show(); final EditText editText = alertDialog.findViewById(R.id.edit_input); Button btnOK = alertDialog.findViewById(R.id.btn_ok); Button btnCancel = alertDialog.findViewById(R.id.btn_cancel); btnCancel.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { alertDialog.cancel(); } }); btnOK.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //get string path of in edit text String fileName = editText.getText().toString(); if (fileName.isEmpty()) { editText.setError(getString(R.string.enter_new_file_name)); return; } RadioButton checkBoxPas = alertDialog.findViewById(R.id.rad_program); RadioButton checkBoxInp = alertDialog.findViewById(R.id.rad_inp); if (checkBoxInp != null && checkBoxInp.isChecked()) fileName += ".inp"; else if (checkBoxPas.isChecked()) fileName += ".pas"; //create new file File file = new File(mCurrentFolder, fileName); try { file.createNewFile(); new UpdateList(mCurrentFolder).execute(); } catch (IOException e) { Toast.makeText(getContext(), e.getMessage(), Toast.LENGTH_SHORT).show(); } alertDialog.cancel(); } }); }
From source file:de.baumann.hhsmoodle.data_random.Random_Fragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_screen_dice, container, false); ImageView imgHeader = (ImageView) rootView.findViewById(R.id.imageView_header); helper_main.setImageHeader(getActivity(), imgHeader); fab_dice = (FloatingActionButton) rootView.findViewById(R.id.fab_dice); lv = (ListView) rootView.findViewById(R.id.list); viewPager = (ViewPager) getActivity().findViewById(R.id.viewpager); lvItems = (ListView) rootView.findViewById(R.id.lvItems); fabLayout1 = (LinearLayout) rootView.findViewById(R.id.fabLayout1); fabLayout2 = (LinearLayout) rootView.findViewById(R.id.fabLayout2); fab = (FloatingActionButton) rootView.findViewById(R.id.fab); FloatingActionButton fab1 = (FloatingActionButton) rootView.findViewById(R.id.fab1); FloatingActionButton fab2 = (FloatingActionButton) rootView.findViewById(R.id.fab2); fab.setOnClickListener(new View.OnClickListener() { @Override// w w w . j ava 2 s . co m public void onClick(View view) { if (!isFABOpen) { showFABMenu(); } else { closeFABMenu(); } } }); fab1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { closeFABMenu(); 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); final EditText edit_cont = (EditText) dialogView.findViewById(R.id.note_text_input); edit_cont.setHint(R.string.text_hint); 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(); if (db.isExist(inputTitle)) { Snackbar.make(lv, getString(R.string.toast_newTitle), Snackbar.LENGTH_LONG).show(); } else { db.insert(inputTitle, inputCont, "", "", helper_main.createDate()); dialog.dismiss(); setRandomList(); 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); } }); fab2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { closeFABMenu(); Intent mainIntent = new Intent(getActivity(), Popup_courseList.class); mainIntent.setAction("courseList_random"); startActivity(mainIntent); } }); fab_dice.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { try { Random rand = new Random(); final int n = rand.nextInt(lvItems.getCount()); setAdapter(n); lvItems.setSelection(n - 1); } catch (NumberFormatException nfe) { nfe.printStackTrace(); } } }); //calling Notes_DbAdapter db = new Random_DbAdapter(getActivity()); db.open(); setRandomList(); setHasOptionsMenu(true); return rootView; }
From source file:com.google.sample.beaconservice.ManageBeaconFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_manage_beacon, container, false); advertisedId_Type = (TextView) rootView.findViewById(R.id.advertisedId_Type); advertisedId_Id = (TextView) rootView.findViewById(R.id.advertisedId_Id); status = (TextView) rootView.findViewById(R.id.status); placeId = (TextView) rootView.findViewById(R.id.placeId); placeId.setOnClickListener(new View.OnClickListener() { @Override//from w w w . j a v a2s . c o m public void onClick(View v) { editLatLngAction(); } }); latLng = (TextView) rootView.findViewById(R.id.latLng); latLng.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { editLatLngAction(); } }); mapView = (ImageView) rootView.findViewById(R.id.mapView); mapView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { editLatLngAction(); } }); expectedStability = (TextView) rootView.findViewById(R.id.expectedStability); expectedStability.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()).setTitle("Edit Stability"); final ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(getActivity(), R.array.stability_enums, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); final Spinner spinner = new Spinner(getActivity()); spinner.setAdapter(adapter); // Set the position of the spinner to the current value. if (beacon.expectedStability != null && !beacon.expectedStability.equals(Beacon.STABILITY_UNSPECIFIED)) { for (int i = 0; i < spinner.getCount(); i++) { if (beacon.expectedStability.equals(spinner.getItemAtPosition(i))) { spinner.setSelection(i); } } } builder.setView(spinner); builder.setPositiveButton("Save", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { beacon.expectedStability = (String) spinner.getSelectedItem(); updateBeacon(); dialog.dismiss(); } }); builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); builder.show(); } }); description = (TextView) rootView.findViewById(R.id.description); description.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()).setTitle("Edit description"); final EditText editText = new EditText(getActivity()); editText.setText(description.getText()); builder.setView(editText); builder.setPositiveButton("Save", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { beacon.description = editText.getText().toString(); updateBeacon(); dialog.dismiss(); } }); builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); builder.show(); } }); actionButton = (Button) rootView.findViewById(R.id.actionButton); decommissionButton = (Button) rootView.findViewById(R.id.decommissionButton); decommissionButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { new AlertDialog.Builder(getActivity()).setTitle("Decommission Beacon") .setMessage("Are you sure you want to decommission this beacon? This operation is " + "irreversible and the beacon cannot be registered again") .setPositiveButton("Decommission", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); Callback decommissionCallback = new Callback() { @Override public void onFailure(Request request, IOException e) { logErrorAndToast("Failed request: " + request, e); } @Override public void onResponse(Response response) throws IOException { if (response.isSuccessful()) { beacon.status = Beacon.STATUS_DECOMMISSIONED; updateBeacon(); } else { String body = response.body().string(); logErrorAndToast("Unsuccessful decommissionBeacon request: " + body); } } }; client.decommissionBeacon(decommissionCallback, beacon.getBeaconName()); } }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }).show(); } }); attachmentsDivider = rootView.findViewById(R.id.attachmentsDivider); attachmentsLabel = (TextView) rootView.findViewById(R.id.attachmentsLabel); attachmentsTable = (TableLayout) rootView.findViewById(R.id.attachmentsTableLayout); // Fetch the namespace for the developer console project ID. We redraw the UI once that // request completes. // TODO: cache this. Callback listNamespacesCallback = new Callback() { @Override public void onFailure(Request request, IOException e) { logErrorAndToast("Failed request: " + request, e); } @Override public void onResponse(Response response) throws IOException { String body = response.body().string(); if (response.isSuccessful()) { try { JSONObject json = new JSONObject(body); JSONArray namespaces = json.getJSONArray("namespaces"); // At present there can be only one namespace. String tmp = namespaces.getJSONObject(0).getString("namespaceName"); if (tmp.startsWith("namespaces/")) { namespace = tmp.substring("namespaces/".length()); } else { namespace = tmp; } redraw(); } catch (JSONException e) { Log.e(TAG, "JSONException", e); } } else { logErrorAndToast("Unsuccessful listNamespaces request: " + body); } } }; client.listNamespaces(listNamespacesCallback); return rootView; }