List of usage examples for android.widget EditText EditText
public EditText(Context context)
From source file:im.vector.activity.CommonActivityUtils.java
public static AlertDialog createEditTextAlert(Activity context, String title, String hint, String initialText, final OnSubmitListener listener) { final AlertDialog.Builder alert = new AlertDialog.Builder(context); final EditText input = new EditText(context); if (hint != null) { input.setHint(hint);/*w w w . j a v a2 s .c o m*/ } if (initialText != null) { input.setText(initialText); } alert.setTitle(title); alert.setView(input); alert.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { String value = input.getText().toString().trim(); listener.onSubmit(value); } }); alert.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }); alert.setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { listener.onCancelled(); } }); AlertDialog dialog = alert.create(); // add the dialog to be rendered in the screenshot RageShake.getInstance().registerDialog(dialog); return dialog; }
From source file:musicplayer.MusicActivity.java
/** * Shows an alert dialog where the user can input a URL. After showing the dialog, if the user * confirms, sends the appropriate intent to the {@link MusicService} to cause that URL to be * played./* w w w .jav a2 s .com*/ */ void showUrlDialog() { AlertDialog.Builder alertBuilder = new AlertDialog.Builder(this); alertBuilder.setTitle("Manual Input"); alertBuilder.setMessage("Enter a URL (must be http://)"); final EditText input = new EditText(this); alertBuilder.setView(input); input.setText(SUGGESTED_URL); alertBuilder.setPositiveButton("Play!", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dlg, int whichButton) { // Send an intent with the URL of the song to play. This is expected by // MusicService. Intent i = new Intent(MusicService.ACTION_URL); Uri uri = Uri.parse(input.getText().toString()); i.setData(uri); startService(i); } }); alertBuilder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dlg, int whichButton) { } }); alertBuilder.show(); }
From source file:fr.alecanu.samplerssreader.RssReaderActivity.java
private void changeURL() { AlertDialog.Builder builder = new AlertDialog.Builder(this); final EditText input = new EditText(this); builder.setTitle(getString(R.string.title_change_url)).setMessage(getString(R.string.message_change_url)) .setView(input).setCancelable(false) .setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { if (Patterns.WEB_URL.matcher(input.getText().toString()).matches()) { if (URLUtil.isValidUrl(input.getText().toString())) { url = input.getText().toString(); } else { url = HTTP + input.getText().toString(); }// w w w . j a va2 s. c o m SharedPreferences.Editor edit = PreferenceManager .getDefaultSharedPreferences(getApplicationContext()).edit(); edit.putBoolean(PREFERENCE_SETUP, true); edit.putString(PREFERENCE_URL, url); edit.commit(); refreshList(); } else { new AlertDialog.Builder(RssReaderActivity.this).setCancelable(false) .setMessage(getString(R.string.fail_url)) .setNeutralButton(getString(R.string.ok), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface arg0, int arg1) { arg0.dismiss(); changeURL(); } }) .create().show(); } } }).setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { if (!PreferenceManager.getDefaultSharedPreferences(getApplicationContext()) .getBoolean(PREFERENCE_SETUP, false)) { finish(); } else { dialog.dismiss(); } } }); builder.create().show(); }
From source file:ca.zadrox.dota2esportticker.ui.MatchActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { Intent intentx;//from w ww .java 2 s.c o m switch (item.getItemId()) { case R.id.menu_refresh: setRefreshingState(true); onRefresh(); break; case R.id.menu_debug_notify: intentx = new Intent(ReminderAlarmService.ACTION_NOTIFY_DEBUG); intentx.setClass(this, ReminderAlarmService.class); this.startService(intentx); return true; case R.id.menu_debug_view_live_match: final Intent intent = new Intent(this, LiveGameStatsActivity.class); intent.putExtra(LiveGameStatsActivity.ARGS_GAME_TLL, (String) null); intent.putExtra(LiveGameStatsActivity.ARGS_GAME_TLR, (String) null); intent.putExtra(LiveGameStatsActivity.ARGS_GAME_BO, "best of 1"); intent.putExtra(LiveGameStatsActivity.ARGS_GAME_TNL, "Invasion"); intent.putExtra(LiveGameStatsActivity.ARGS_GAME_TNR, "Koopa"); intent.putExtra(LiveGameStatsActivity.ARGS_GAME_TN, "awesome"); final Context mContext = this; AlertDialog.Builder alert = new AlertDialog.Builder(this); alert.setTitle("Enter Match Id:"); // Set an EditText view to get user input final EditText input = new EditText(this); alert.setView(input); alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { intent.putExtra(LiveGameStatsActivity.ARGS_GAME_MID, Long.parseLong(input.getText().toString())); mContext.startActivity(intent); } }); alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { } }); alert.show(); return true; } return super.onOptionsItemSelected(item); }
From source file:com.willhauck.linconnectclient.SettingsActivity.java
@SuppressLint("SimpleDateFormat") private void setupSimplePreferencesScreen() { // Load preferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(SettingsActivity.this); // Add preferences from XML addPreferencesFromResource(R.xml.pref_general); bindPreferenceSummaryToValue(findPreference("pref_ip")); // Preference Categories serverCategory = ((PreferenceCategory) findPreference("cat_servers")); // Preferences refreshPreference = ((Preference) findPreference("pref_refresh")); serverCategory.removePreference(refreshPreference); loadingPreference = ((Preference) findPreference("pref_loading")); serverCategory.removePreference(loadingPreference); Preference prefEnable = findPreference("pref_enable"); prefEnable.setOnPreferenceClickListener(new OnPreferenceClickListener() { @Override//from ww w . ja v a2 s. c o m public boolean onPreferenceClick(Preference arg0) { // If Android 4.3+, open Notification Listener settings, // otherwise open accessibility settings if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN_MR2) { startActivityForResult(new Intent(android.provider.Settings.ACTION_ACCESSIBILITY_SETTINGS), 0); } else { Intent intent = new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS"); startActivity(intent); } return true; } }); ((Preference) findPreference("pref_ip")).setOnPreferenceChangeListener(new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference arg0, Object arg1) { // Update Custom IP address summary arg0.setSummary((String) arg1); refreshServerList(); // Create and send test notification SimpleDateFormat sf = new SimpleDateFormat("HH:mm:ss"); Object[] notif = new Object[3]; notif[0] = "Hello from Android!"; notif[1] = "Test succesful @ " + sf.format(new Date()); notif[2] = SettingsActivity.this.getResources().getDrawable(R.drawable.ic_launcher); new TestTask().execute(notif); return true; } }); Preference prefDownload = findPreference("pref_download"); prefDownload.setOnPreferenceClickListener(new OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference arg0) { // Create share dialog with server download URL Intent sendIntent = new Intent(); sendIntent.setAction(Intent.ACTION_SEND); sendIntent.putExtra(Intent.EXTRA_TEXT, "Download LinConnect server @ https://github.com/hauckwill/linconnect-server"); sendIntent.setType("text/plain"); startActivity(sendIntent); return true; } }); Preference prefApplication = findPreference("pref_application"); prefApplication.setOnPreferenceClickListener(new OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference arg0) { // Open application settings screen Intent intent = new Intent(getApplicationContext(), ApplicationSettingsActivity.class); startActivity(intent); return true; } }); Preference prefDonateBitcoin = findPreference("pref_donate_btc"); prefDonateBitcoin.setOnPreferenceClickListener(new OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference arg0) { try { // Open installed Bitcoin wallet if possible Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse( "bitcoin:1125MguyS1feaop99bCDPQG6ukUcMuvVBo?label=Will%20Hauck&message=Donation%20for%20LinConnect")); startActivity(intent); } catch (Exception e) { // Otherwise, show dialog with Bitcoin address EditText input = new EditText(SettingsActivity.this); input.setText("1125MguyS1feaop99bCDPQG6ukUcMuvVBo"); input.setEnabled(false); new AlertDialog.Builder(SettingsActivity.this).setTitle("Bitcoin Address") .setMessage( "Please donate to the following Bitcoin address. Thank you for the support.") .setView(input) .setPositiveButton("Copy Address", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { android.text.ClipboardManager clipboard = (android.text.ClipboardManager) getSystemService( Context.CLIPBOARD_SERVICE); clipboard.setText("1125MguyS1feaop99bCDPQG6ukUcMuvVBo"); } }).setNegativeButton("Okay", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { } }).show(); } return true; } }); Preference prefGooglePlus = findPreference("pref_google_plus"); prefGooglePlus.setOnPreferenceClickListener(new OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference arg0) { // Open Google Plus page Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse("https://plus.google.com/114633032648182423928/posts")); startActivity(intent); return true; } }); Preference prefDonatePlay = findPreference("pref_donate_play"); prefDonatePlay.setOnPreferenceClickListener(new OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference arg0) { // Open Donation Key app on Play Store Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse("market://details?id=com.willhauck.donation")); startActivity(intent); return true; } }); // Create handler to process a detected server serverFoundHandler = new Handler(new Handler.Callback() { @Override public boolean handleMessage(Message msg) { if (msg.obj != null) { javax.jmdns.ServiceInfo serviceInfo = mJmDNS.getServiceInfo(jmDnsServiceType, (String) msg.obj); // Get info about server String name = serviceInfo.getName(); String port = String.valueOf(serviceInfo.getPort()); String ip = serviceInfo.getHostAddresses()[0]; // Create a preference representing the server Preference p = new Preference(SettingsActivity.this); p.setTitle(name); p.setSummary(ip + ":" + port); p.setOnPreferenceClickListener(new OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference arg0) { refreshServerList(); // Save IP address in preferences Editor e = sharedPreferences.edit(); e.putString("pref_ip", arg0.getSummary().toString()); e.apply(); // Create and send test notification SimpleDateFormat sf = new SimpleDateFormat("HH:mm:ss"); Object[] notif = new Object[3]; notif[0] = "Hello from Android!"; notif[1] = "Test succesful @ " + sf.format(new Date()); notif[2] = SettingsActivity.this.getResources().getDrawable(R.drawable.ic_launcher); new TestTask().execute(notif); return true; } }); // Add preference to server list if it doesn't already exist boolean found = false; for (int i = 0; i < serverCategory.getPreferenceCount(); i++) { if (serverCategory.getPreference(i) != null && serverCategory.getPreference(i).getTitle() != null && serverCategory.getPreference(i).getTitle().equals(p.getTitle())) { found = true; } } if (!found) { serverCategory.addPreference(p); } refreshServerList(); // Remove loading indicator, add refresh indicator if it // isn't already there if (findPreference("pref_loading") != null) serverCategory.removePreference(findPreference("pref_loading")); if (findPreference("pref_refresh") == null) serverCategory.addPreference(refreshPreference); } return true; } }); // Create task to scan for servers class ServerScanTask extends AsyncTask<String, ServiceEvent, Boolean> { @Override protected void onPreExecute() { // Remove refresh preference, add loading preference if (findPreference("pref_refresh") != null) serverCategory.removePreference(refreshPreference); serverCategory.addPreference(loadingPreference); try { mJmDNS.removeServiceListener(jmDnsServiceType, ServerListener); } catch (Exception e) { } refreshServerList(); } @Override protected Boolean doInBackground(String... notif) { WifiInfo wifiinfo = mWifiManager.getConnectionInfo(); int intaddr = wifiinfo.getIpAddress(); // Ensure there is an active Wifi connection if (intaddr != 0) { byte[] byteaddr = new byte[] { (byte) (intaddr & 0xff), (byte) (intaddr >> 8 & 0xff), (byte) (intaddr >> 16 & 0xff), (byte) (intaddr >> 24 & 0xff) }; InetAddress addr = null; try { addr = InetAddress.getByAddress(byteaddr); } catch (UnknownHostException e1) { } // Create Multicast lock (required for JmDNS) mMulticastLock = mWifiManager.createMulticastLock("LinConnect"); mMulticastLock.setReferenceCounted(true); mMulticastLock.acquire(); try { mJmDNS = JmDNS.create(addr, "LinConnect"); } catch (IOException e) { } // Create listener for detected servers ServerListener = new ServiceListener() { @Override public void serviceAdded(ServiceEvent arg0) { final String name = arg0.getName(); // Send the server data to the handler, delayed by // 500ms to ensure all information is read serverFoundHandler.sendMessageDelayed(Message.obtain(serverFoundHandler, -1, name), 500); } @Override public void serviceRemoved(ServiceEvent arg0) { } @Override public void serviceResolved(ServiceEvent arg0) { mJmDNS.requestServiceInfo(arg0.getType(), arg0.getName(), 1); } }; mJmDNS.addServiceListener(jmDnsServiceType, ServerListener); return true; } return false; } @Override protected void onPostExecute(Boolean result) { if (!result) { // Notify user if there is no connection if (findPreference("pref_loading") != null) { serverCategory.removePreference(findPreference("pref_loading")); serverCategory.addPreference(refreshPreference); } Toast.makeText(getApplicationContext(), "Error: no connection.", Toast.LENGTH_LONG).show(); } } } refreshPreference.setOnPreferenceClickListener(new OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference arg0) { new ServerScanTask().execute(); return true; } }); // Start scanning for servers new ServerScanTask().execute(); }
From source file:org.bohrmeista.chan.ui.activity.BaseActivity.java
private void onPinLongPress(final Pin pin) { new AlertDialog.Builder(this) .setNegativeButton(R.string.drawer_pinned_delete, new DialogInterface.OnClickListener() { @Override//from w w w .j av a 2 s . c o m public void onClick(DialogInterface dialog, int which) { // Delete pin removePin(pin); } }).setPositiveButton(R.string.drawer_pinned_change_title, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // Change pin title final EditText text = new EditText(BaseActivity.this); text.setSingleLine(); text.setText(pin.loadable.title); text.setSelectAllOnFocus(true); AlertDialog titleDialog = new AlertDialog.Builder(BaseActivity.this) .setPositiveButton(R.string.change, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface d, int which) { String value = text.getText().toString(); if (!TextUtils.isEmpty(value)) { pin.loadable.title = value; updatePin(pin); } } }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface d, int which) { } }).setTitle(R.string.drawer_pinned_change_title).setView(text).create(); Utils.requestKeyboardFocus(titleDialog, text); titleDialog.show(); } }).show(); }
From source file:com.krayzk9s.imgurholo.ui.SingleImageFragment.java
@Override public boolean onOptionsItemSelected(MenuItem item) { // handle item selection final Activity activity = getActivity(); switch (item.getItemId()) { case R.id.action_sort: return true; case R.id.menuSortNewest: sort = "New"; refreshComments();/*from ww w . jav a 2 s . c om*/ activity.invalidateOptionsMenu(); return true; case R.id.menuSortTop: sort = "Top"; refreshComments(); activity.invalidateOptionsMenu(); return true; case R.id.menuSortBest: sort = "Best"; refreshComments(); activity.invalidateOptionsMenu(); return true; case R.id.action_refresh: refreshComments(); return true; case R.id.action_submit: final EditText newGalleryTitle = new EditText(activity); newGalleryTitle.setHint("Title"); newGalleryTitle.setSingleLine(); new AlertDialog.Builder(activity).setTitle("Set Gallery Title/Press OK to remove") .setView(newGalleryTitle) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { if (newGalleryTitle.getText() == null) return; HashMap<String, Object> galleryMap = new HashMap<String, Object>(); galleryMap.put("terms", "1"); galleryMap.put(ImgurHoloActivity.IMAGE_DATA_TITLE, newGalleryTitle.getText().toString()); newGalleryString = newGalleryTitle.getText().toString(); try { Fetcher fetcher = new Fetcher(singleImageFragment, "3/gallery/image/" + imageData.getJSONObject().getString("id"), ApiCall.GET, galleryMap, ((ImgurHoloActivity) getActivity()).getApiCall(), GALLERY); fetcher.execute(); } catch (Exception e) { Log.e("Error!", e.toString()); } } }).setNegativeButton(R.string.dialog_answer_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { // Do nothing. } }).show(); return true; case R.id.action_edit: try { final EditText newTitle = new EditText(activity); newTitle.setSingleLine(); if (!imageData.getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_TITLE).equals("null")) newTitle.setText(imageData.getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_TITLE)); final EditText newBody = new EditText(activity); newBody.setHint(R.string.body_hint_description); newTitle.setHint(R.string.body_hint_title); if (!imageData.getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_DESCRIPTION).equals("null")) newBody.setText(imageData.getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_DESCRIPTION)); LinearLayout linearLayout = new LinearLayout(activity); linearLayout.setOrientation(LinearLayout.VERTICAL); linearLayout.addView(newTitle); linearLayout.addView(newBody); new AlertDialog.Builder(activity).setTitle(R.string.dialog_edit_title).setView(linearLayout) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { TextView imageTitle = (TextView) imageLayoutView .findViewById(R.id.single_image_title); TextView imageDescription = (TextView) imageLayoutView .findViewById(R.id.single_image_description); if (newTitle.getText() != null && !newTitle.getText().toString().equals("")) { imageTitle.setText(newTitle.getText().toString()); imageTitle.setVisibility(View.VISIBLE); } else imageTitle.setVisibility(View.GONE); if (newBody.getText() != null && !newBody.getText().toString().equals("")) { imageDescription.setText(newBody.getText().toString()); imageDescription.setVisibility(View.VISIBLE); } else imageDescription.setVisibility(View.GONE); HashMap<String, Object> editImageMap = new HashMap<String, Object>(); editImageMap.put(ImgurHoloActivity.IMAGE_DATA_TITLE, newTitle.getText().toString()); editImageMap.put(ImgurHoloActivity.IMAGE_DATA_DESCRIPTION, newBody.getText().toString()); try { Fetcher fetcher = new Fetcher(singleImageFragment, "3/image/" + imageData.getJSONObject().getString("id"), ApiCall.POST, editImageMap, ((ImgurHoloActivity) getActivity()).getApiCall(), EDITIMAGE); fetcher.execute(); } catch (JSONException e) { Log.e("Error!", e.toString()); } } }).setNegativeButton(R.string.dialog_answer_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { // Do nothing. } }).show(); } catch (JSONException e) { Log.e("Error!", "oops, some image fields missing values" + e.toString()); } return true; case R.id.action_download: ImageUtils.downloadImage(this, imageData); return true; case R.id.action_delete: new AlertDialog.Builder(activity).setTitle(R.string.dialog_delete_confirmation_title) .setMessage(R.string.dialog_delete_confirmation_summary) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { try { Fetcher fetcher = new Fetcher(singleImageFragment, "3/image/" + imageData.getJSONObject().getString("id"), ApiCall.DELETE, null, ((ImgurHoloActivity) getActivity()).getApiCall(), DELETE); fetcher.execute(); } catch (JSONException e) { Log.e("Error!", e.toString()); } } }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { // Do nothing. } }).show(); return true; case R.id.action_copy: ImageUtils.copyImageURL(this, imageData); return true; case R.id.action_share: ImageUtils.shareImage(this, imageData); return true; default: return super.onOptionsItemSelected(item); } }
From source file:ca.ualberta.app.activity.FragmentProfile.java
/** * will be called when user want to re-set the username *//*from ww w. j a v a 2 s.c o m*/ private void showDialog() { AlertDialog.Builder alert = new AlertDialog.Builder(getActivity()); alert.setTitle("Change Author Name"); alert.setMessage("Enter Your Name Here"); final EditText input = new EditText(getActivity()); alert.setView(input); alert.setPositiveButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { newUsername = input.getEditableText().toString(); if (newUsername != null) { if (!authorMapController.hasAuthor(mcontext, newUsername)) { User.author.setUsername(newUsername); authorMapController.updateAuthor(mcontext, User.author); } else { Toast.makeText(getActivity(), "The username is aready exist, please choose another one.", Toast.LENGTH_SHORT).show(); showDialog(); } setAuthorName.setText(User.author.getUsername()); } else Toast.makeText(mcontext, "Please fill in name", Toast.LENGTH_SHORT).show(); } }); alert.setNegativeButton("CANCEL", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }); AlertDialog alertDialog = alert.create(); alertDialog.show(); }
From source file:com.xperia64.timidityae.PlaylistFragment.java
@Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); if (!gotPlaylists) { gotPlaylists = true;/*from w w w . j a v a2 s.com*/ getPlaylists(null); } getListView().setOnItemLongClickListener(new OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> arg0, View arg1, final int pos, long id) { if (!mode) { AlertDialog.Builder builderSingle = new AlertDialog.Builder(getActivity()); builderSingle.setIcon(R.drawable.ic_launcher); builderSingle.setTitle(getActivity().getResources() .getString((pos == 0) ? R.string.plist_save2 : R.string.plist_mod)); builderSingle.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); if (pos != 0) { builderSingle.setNeutralButton(getResources().getString(R.string.plist_del), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { AlertDialog.Builder builderDouble = new AlertDialog.Builder(getActivity()) .setIcon(R.drawable.ic_launcher) .setTitle(String.format( getActivity().getResources().getString(R.string.plist_del2), fname.get(pos))); builderDouble.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { File f = new File(path.get(pos)); if (f.exists()) { String[] x = null; try { new FileOutputStream(path.get(pos), true).close(); } catch (FileNotFoundException e) { x = Globals.getDocFilePaths(getActivity(), f.getAbsolutePath()); } catch (IOException e) { e.printStackTrace(); } if (x != null) { Globals.tryToDeleteFile(getActivity(), path.get(pos)); } else { f.delete(); } } getPlaylists(null); dialog.dismiss(); } }); builderDouble.setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); builderDouble.show(); } }); builderSingle.setPositiveButton(getResources().getString(R.string.plist_ren), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { AlertDialog.Builder alert = new AlertDialog.Builder(getActivity()); alert.setTitle(String.format(getResources().getString(R.string.plist_ren2), fname.get(pos))); final EditText input = new EditText(getActivity()); alert.setView(input); alert.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { String value = input.getText().toString(); File f = new File(path.get(pos)); File f2 = new File(path.get(pos).substring(0, path.get(pos).lastIndexOf('/') + 1) + value + ".tpl"); if (f.exists()) { if (f2.exists()) { Toast.makeText(getActivity(), getResources().getString(R.string.plist_ex), Toast.LENGTH_SHORT).show(); } else { String[] x = null; try { new FileOutputStream(f.getAbsolutePath(), true) .close(); } catch (FileNotFoundException e) { x = Globals.getDocFilePaths(getActivity(), f.getAbsolutePath()); } catch (IOException e) { e.printStackTrace(); } if (x != null) { Globals.renameDocumentFile(getActivity(), f.getAbsolutePath(), f2.getAbsolutePath() .substring(f2.getAbsolutePath() .indexOf(x[1]) + x[1].length())); } else { f.renameTo(f2); } } } else Toast.makeText(getActivity(), getResources().getString(R.string.plist_pnf), Toast.LENGTH_SHORT).show(); getPlaylists(null); dialog.dismiss(); } }); alert.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.dismiss(); } }); alert.show(); } }); } else { final EditText input2 = new EditText(getActivity()); builderSingle.setView(input2); builderSingle.setPositiveButton(getResources().getString(R.string.plist_save), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (input2.getText() != null) { if (!TextUtils.isEmpty(input2.getText().toString())) { tmpName = playlistDir + "/" + input2.getText().toString() + ".tpl"; vola = currPlist; write(); } } } }); } builderSingle.show(); return true; } else if (!plistName.equals("CURRENT")) { AlertDialog.Builder builderSingle = new AlertDialog.Builder(getActivity()); builderSingle.setIcon(R.drawable.ic_launcher); builderSingle.setTitle(getResources().getString(R.string.plist_modit)); final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(getActivity(), android.R.layout.select_dialog_item); arrayAdapter.add(getResources().getString(R.string.plist_ds)); arrayAdapter.add(getResources().getString(R.string.plist_addcsh)); arrayAdapter.add(getResources().getString(R.string.plist_addsh)); arrayAdapter.add(getResources().getString(R.string.plist_addfh)); arrayAdapter.add(getResources().getString(R.string.plist_addfth)); builderSingle.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); builderSingle.setAdapter(arrayAdapter, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { vola = parsePlist(tmpName = plistName); loki = pos; switch (which) { case 0: setItem(null, -1); write(); break; case 1: if (((TimidityActivity) getActivity()).currSongName != null) { setItem(((TimidityActivity) getActivity()).currSongName, 0); write(); } break; case 2: new FileBrowserDialog().create(0, (Globals.showVideos ? Globals.musicVideoFiles : Globals.musicFiles), PlaylistFragment.this, getActivity(), getActivity().getLayoutInflater(), false, Globals.defaultFolder, getActivity().getResources().getString(R.string.fb_add)); break; case 3: new FileBrowserDialog().create(1, null, PlaylistFragment.this, getActivity(), getActivity().getLayoutInflater(), false, Globals.defaultFolder, getActivity().getResources().getString(R.string.fb_add)); break; case 4: new FileBrowserDialog().create(2, null, PlaylistFragment.this, getActivity(), getActivity().getLayoutInflater(), false, Globals.defaultFolder, getActivity().getResources().getString(R.string.fb_add)); break; } } }); builderSingle.show(); return true; } return true; } }); }
From source file:br.com.GUI.perfil.HomePersonal.java
public boolean onOptionsItemSelected(MenuItem item) { // Take appropriate action for each action item click switch (item.getItemId()) { case R.id.actSolicitacoesDeAmizadePersonal: ArrayList<Aluno> solicitacoes = new Aluno().buscarAlunoNaoConfirmadoPorPersonalWeb("", pref.getString("usuario", null)); if (!solicitacoes.isEmpty()) { Intent i = new Intent(this, SolicitacoesDeAmizade.class); startActivity(i);//from w ww .jav a 2 s . c o m } else { AlertDialog.Builder alertDialog = new AlertDialog.Builder(this); alertDialog.setTitle("Ops..."); alertDialog.setMessage(R.string.label_voce_nao_possui_solicitacoes_de_amizade); alertDialog.setIcon(R.drawable.profile); alertDialog.setPositiveButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); // Showing Alert Message alertDialog.show(); } return true; case R.id.actLogoutPersonal: finish(); Intent login = new Intent(this, Login.class); login.putExtra("logout", true); editor.clear(); editor.commit(); startActivity(login); return true; case R.id.actAdicionarAlunos: Intent adicionarAlunos = new Intent(this, BuscarUsuario.class); startActivity(adicionarAlunos); return true; case R.id.actAlterarDadosPessoaisPersonal: if (pref.getBoolean("isFacebookUser", false)) { AlertDialog.Builder alertDialog = new AlertDialog.Builder(HomePersonal.this); alertDialog.setTitle("Erro"); alertDialog.setMessage( "Seu cadastro est vinculado ao Facebook, sendo assim, no possivel alterao de informaes pessoais"); alertDialog.setIcon(R.drawable.profile); alertDialog.setPositiveButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); // Showing Alert Message alertDialog.show(); } else { Intent alterarDados = new Intent(this, AlterarDadosPessoais.class); startActivity(alterarDados); } return true; case R.id.actPerfil: Intent perfilIntent = new Intent(this, PerfilPersonal.class); startActivity(perfilIntent); return true; case R.id.actNovaAvaliacao: Intent avaliacoesIntent = new Intent(this, AvaliarGorduraCorporal.class); startActivity(avaliacoesIntent); return true; case R.id.actNovoTreinamento: AlertDialog.Builder alertDialog = new AlertDialog.Builder(this); alertDialog.setTitle("Ops..."); alertDialog.setMessage("Digite um nome para o novo treinamento"); alertDialog.setIcon(R.drawable.critical); // Set an EditText view to get user input final EditText input = new EditText(this); alertDialog.setView(input); alertDialog.setPositiveButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { Treinamento t = new Treinamento(0, input.getText().toString(), null, null, pref.getString("usuario", null), null); //Log.i("interface: treinamento", t.toString()); try { int resultado = t.salvarTreinamentoWeb(b); if (resultado > 0) { Log.i("interface: salvei web", "salvei web"); t.setCodTreinamento(resultado); if (t.salvarTreinamento(b, pref.getString("usuario", null))) { Log.i("interface: salvei local", "salvei local"); Toast.makeText(HomePersonal.this, "Salvo com sucesso!", Toast.LENGTH_SHORT).show(); } } } catch (Exception ex) { ex.printStackTrace(); Toast.makeText(HomePersonal.this, "Erro ao salvar!", Toast.LENGTH_SHORT).show(); } } }); alertDialog.setNegativeButton("Cancelar", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); // Showing Alert Message alertDialog.show(); } return false; }