List of usage examples for android.app AlertDialog setTitle
@Override public void setTitle(CharSequence title)
From source file:fm.smart.r1.activity.CreateSoundActivity.java
public void onWindowFocusChanged(boolean bool) { super.onWindowFocusChanged(bool); Log.d("DEBUG", "onWindowFocusChanged"); if (CreateSoundActivity.create_sound_result != null) { synchronized (CreateSoundActivity.create_sound_result) { final AlertDialog dialog = new AlertDialog.Builder(this).create(); final boolean success = CreateSoundActivity.create_sound_result.success(); dialog.setTitle(CreateSoundActivity.create_sound_result.getTitle()); dialog.setMessage(CreateSoundActivity.create_sound_result.getMessage()); CreateSoundActivity.create_sound_result = null; dialog.setButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // TODO avoid moving to item list if previous thread was // interrupted? create_sound.isInterrupted() but need // user to be aware if we // have created sound already - progress dialog is set // cancelable, so back button will work? maybe should // avoid encouraging cancel // on POST operations ... not sure what to do if no // response from server - guess we will time out // eventually ... // if (success) { // want to go back to individual item screen now ... ItemListActivity.loadItem(CreateSoundActivity.this, item_id); // } // TODO might want to go to different screens depending // on type of error, e.g. permission issue versus // network // error }/*from ww w .java 2s. c om*/ }); dialog.show(); } } }
From source file:org.adaway.ui.RedirectionListFragment.java
/** * Edit entry based on selection in context menu * * @param info//from ww w. j a va 2 s . co m */ private void menuEditEntry(AdapterContextMenuInfo info) { mCurrentRowId = info.id; // set global RowId to row id from cursor to use inside save button int position = info.position; View v = info.targetView; TextView hostnameTextView = (TextView) v.findViewWithTag("hostname_" + position); TextView ipTextView = (TextView) v.findViewWithTag("ip_" + position); AlertDialog.Builder builder = new AlertDialog.Builder(mActivity); builder.setCancelable(true); builder.setTitle(getString(R.string.checkbox_list_edit_dialog_title)); // build view from layout LayoutInflater factory = LayoutInflater.from(mActivity); final View dialogView = factory.inflate(R.layout.lists_redirection_dialog, null); final EditText hostnameEditText = (EditText) dialogView.findViewById(R.id.list_dialog_hostname); final EditText ipEditText = (EditText) dialogView.findViewById(R.id.list_dialog_ip); // set text from list hostnameEditText.setText(hostnameTextView.getText()); ipEditText.setText(ipTextView.getText()); // move cursor to end of EditText Editable hostnameEditContent = hostnameEditText.getText(); hostnameEditText.setSelection(hostnameEditContent.length()); Editable ipEditContent = ipEditText.getText(); ipEditText.setSelection(ipEditContent.length()); builder.setView(dialogView); builder.setPositiveButton(getResources().getString(R.string.button_save), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); String hostname = hostnameEditText.getText().toString(); String ip = ipEditText.getText().toString(); if (RegexUtils.isValidHostname(hostname)) { if (RegexUtils.isValidIP(ip)) { ProviderHelper.updateRedirectionListItemHostnameAndIp(mActivity, mCurrentRowId, hostname, ip); } else { AlertDialog alertDialog = new AlertDialog.Builder(mActivity).create(); alertDialog.setIcon(android.R.drawable.ic_dialog_alert); alertDialog.setTitle(R.string.no_ip_title); alertDialog.setMessage(getString(org.adaway.R.string.no_ip)); alertDialog.setButton(getString(R.string.button_close), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dlg, int sum) { dlg.dismiss(); } }); alertDialog.show(); } } else { AlertDialog alertDialog = new AlertDialog.Builder(mActivity).create(); alertDialog.setIcon(android.R.drawable.ic_dialog_alert); alertDialog.setTitle(R.string.no_hostname_title); alertDialog.setMessage(getString(org.adaway.R.string.no_hostname)); alertDialog.setButton(getString(R.string.button_close), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dlg, int sum) { dlg.dismiss(); } }); alertDialog.show(); } } }); builder.setNegativeButton(getResources().getString(R.string.button_cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); AlertDialog alert = builder.create(); alert.show(); }
From source file:org.adawaycn.ui.RedirectionListFragment.java
/** * Edit entry based on selection in context menu * * @param info// w w w . ja v a2s. c o m */ private void menuEditEntry(AdapterContextMenuInfo info) { mCurrentRowId = info.id; // set global RowId to row id from cursor to use inside save button int position = info.position; View v = info.targetView; TextView hostnameTextView = (TextView) v.findViewWithTag("hostname_" + position); TextView ipTextView = (TextView) v.findViewWithTag("ip_" + position); AlertDialog.Builder builder = new AlertDialog.Builder(mActivity); builder.setCancelable(true); builder.setTitle(getString(R.string.checkbox_list_edit_dialog_title)); // build view from layout LayoutInflater factory = LayoutInflater.from(mActivity); final View dialogView = factory.inflate(R.layout.lists_redirection_dialog, null); final EditText hostnameEditText = (EditText) dialogView.findViewById(R.id.list_dialog_hostname); final EditText ipEditText = (EditText) dialogView.findViewById(R.id.list_dialog_ip); // set text from list hostnameEditText.setText(hostnameTextView.getText()); ipEditText.setText(ipTextView.getText()); // move cursor to end of EditText Editable hostnameEditContent = hostnameEditText.getText(); hostnameEditText.setSelection(hostnameEditContent.length()); Editable ipEditContent = ipEditText.getText(); ipEditText.setSelection(ipEditContent.length()); builder.setView(dialogView); builder.setPositiveButton(getResources().getString(R.string.button_save), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); String hostname = hostnameEditText.getText().toString(); String ip = ipEditText.getText().toString(); if (org.adawaycn.util.RegexUtils.isValidHostname(hostname)) { if (org.adawaycn.util.RegexUtils.isValidIP(ip)) { org.adawaycn.provider.ProviderHelper.updateRedirectionListItemHostnameAndIp( mActivity, mCurrentRowId, hostname, ip); } else { AlertDialog alertDialog = new AlertDialog.Builder(mActivity).create(); alertDialog.setIcon(android.R.drawable.ic_dialog_alert); alertDialog.setTitle(R.string.no_ip_title); alertDialog.setMessage(getString(R.string.no_ip)); alertDialog.setButton(getString(R.string.button_close), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dlg, int sum) { dlg.dismiss(); } }); alertDialog.show(); } } else { AlertDialog alertDialog = new AlertDialog.Builder(mActivity).create(); alertDialog.setIcon(android.R.drawable.ic_dialog_alert); alertDialog.setTitle(R.string.no_hostname_title); alertDialog.setMessage(getString(R.string.no_hostname)); alertDialog.setButton(getString(R.string.button_close), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dlg, int sum) { dlg.dismiss(); } }); alertDialog.show(); } } }); builder.setNegativeButton(getResources().getString(R.string.button_cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); AlertDialog alert = builder.create(); alert.show(); }
From source file:cm.aptoide.pt.Aptoide.java
private void downloadServ(String srv) { try {//from w ww . j av a2s. com keepScreenOn.acquire(); BufferedInputStream getit = new BufferedInputStream(new URL(srv).openStream()); File file_teste = new File(TMP_SRV_FILE); if (file_teste.exists()) file_teste.delete(); FileOutputStream saveit = new FileOutputStream(TMP_SRV_FILE); BufferedOutputStream bout = new BufferedOutputStream(saveit, 1024); byte data[] = new byte[1024]; int readed = getit.read(data, 0, 1024); while (readed != -1) { bout.write(data, 0, readed); readed = getit.read(data, 0, 1024); } keepScreenOn.release(); bout.close(); getit.close(); saveit.close(); } catch (Exception e) { AlertDialog p = new AlertDialog.Builder(this).create(); p.setTitle(getText(R.string.top_error)); p.setMessage(getText(R.string.aptoide_error)); p.setButton(getText(R.string.btn_ok), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { return; } }); p.show(); } }
From source file:org.umit.icm.mobile.gui.ControlActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.controlactivity); WebsiteSuggestButton = (Button) this.findViewById(R.id.suggestWebsite); ServiceSuggestButton = (Button) this.findViewById(R.id.suggestService); scanButton = (Button) this.findViewById(R.id.scanButton); // filterButton = (Button) this.findViewById(R.id.filterButton); // servicesFilterButton = (Button) this.findViewById(R.id.serviceFilterButton); mapSelectionButton = (Button) this.findViewById(R.id.mapSelectionButton); enableTwitterButton = (Button) this.findViewById(R.id.enableTwitterButton); bugReportButton = (Button) this.findViewById(R.id.bugReportButton); aboutButton = (Button) this.findViewById(R.id.aboutButton); scanButton.setText(getString(R.string.scan_text) + " " + getString(R.string.scan_off)); try {/*from w w w . j ava 2s.c om*/ if (Globals.runtimeParameters.getTwitter().equals("Off")) { enableTwitterButton.setText(getString(R.string.enable_twitter_button)); } else { enableTwitterButton.setText(getString(R.string.disable_twitter_button)); } } catch (RuntimeException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } BroadcastReceiver receiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { if (intent.getAction().equals("org.umit.icm.mobile.CONTROL_ACTIVITY")) { scanButton.setText(getString(R.string.scan_text) + " " + getString(R.string.scan_on)); } } }; registerReceiver(receiver, new IntentFilter("org.umit.icm.mobile.CONTROL_ACTIVITY")); WebsiteSuggestButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { WebsiteSuggestionDialog websiteSuggestionDialog = new WebsiteSuggestionDialog(ControlActivity.this, "", new OnReadyListener()); websiteSuggestionDialog.show(); } }); ServiceSuggestButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { ServiceSuggestionDialog suggestionDialog = new ServiceSuggestionDialog(ControlActivity.this, "", new OnReadyListener()); suggestionDialog.show(); } }); enableTwitterButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { try { if (Globals.runtimeParameters.getTwitter().equals("Off")) { progressDialog = ProgressDialog.show(ControlActivity.this, getString(R.string.loading), getString(R.string.retrieving_website), true, false); new LaunchBrowser().execute(); TwitterDialog twitterDialog = new TwitterDialog(ControlActivity.this, ""); twitterDialog.show(); enableTwitterButton.setText(getString(R.string.disable_twitter_button)); } else { Globals.runtimeParameters.setTwitter("Off"); enableTwitterButton.setText(getString(R.string.enable_twitter_button)); } } catch (RuntimeException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }); mapSelectionButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { MapSelectionDialog MapSelectionDialog = new MapSelectionDialog(ControlActivity.this, ""); MapSelectionDialog.show(); } }); /* filterButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { Intent intent = new Intent(ControlActivity.this, WebsiteFilterActivity.class); startActivity(intent); } } ); servicesFilterButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { Intent intent = new Intent(ControlActivity.this, ServiceFilterActivity.class); startActivity(intent); } } );*/ bugReportButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { Intent intent = new Intent(ControlActivity.this, BugReportActivity.class); startActivity(intent); } }); aboutButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { String msg = getString(R.string.about_text) + "\n" + getString(R.string.link_to_open_monitor) + "\n" + getString(R.string.link_to_umit) + "\n" + getString(R.string.icons_by); final SpannableString spannableString = new SpannableString(msg); Linkify.addLinks(spannableString, Linkify.ALL); AlertDialog alertDialog = new AlertDialog.Builder(ControlActivity.this).create(); alertDialog.setTitle(getString(R.string.about_button)); alertDialog.setMessage(spannableString); alertDialog.setIcon(R.drawable.umit_128); alertDialog.setButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); alertDialog.show(); } }); scanButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { if (Globals.scanStatus.equalsIgnoreCase(getString(R.string.scan_on))) { scanButton.setText(getString(R.string.scan_text) + " " + getString(R.string.scan_on)); Globals.scanStatus = getString(R.string.scan_off); stopService(new Intent(ControlActivity.this, ConnectivityService.class)); } else { scanButton.setText(getString(R.string.scan_text) + " " + getString(R.string.scan_off)); Globals.scanStatus = getString(R.string.scan_on); startService(new Intent(ControlActivity.this, ConnectivityService.class)); } try { Globals.runtimeParameters.setScanStatus(Globals.scanStatus); } catch (RuntimeException e) { e.printStackTrace(); } Context context = getApplicationContext(); CharSequence text = getString(R.string.toast_scan_change) + " " + Globals.scanStatus; int duration = Toast.LENGTH_SHORT; Toast toast = Toast.makeText(context, text, duration); toast.show(); } }); }
From source file:com.loadsensing.app.LoginActivity.java
public void onClick(View v) { // this gets the resources in the xml file // and assigns it to a local variable of type EditText EditText usernameEditText = (EditText) findViewById(R.id.txt_username); EditText passwordEditText = (EditText) findViewById(R.id.txt_password); // the getText() gets the current value of the text box // the toString() converts the value to String data type // then assigns it to a variable of type String String sUserName = usernameEditText.getText().toString(); String sPassword = passwordEditText.getText().toString(); // Definimos constructor de alerta para los avisos posteriores AlertDialog alertDialog = new AlertDialog.Builder(this).create(); alertDialog = new AlertDialog.Builder(this).create(); // call the backend using Get parameters String address = SERVER_HOST + "?user=" + sUserName + "&pass=" + sPassword + ""; if (sUserName.equals("") || sPassword.equals("")) { // error alert alertDialog.setTitle(getResources().getString(R.string.error)); alertDialog.setMessage(getResources().getString(R.string.empty_fields)); alertDialog.setButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { return; }//from w w w . j a v a2 s. c o m }); alertDialog.show(); } else if (!checkConnection(this.getApplicationContext())) { alertDialog.setTitle(getResources().getString(R.string.error)); alertDialog.setMessage(getResources().getString(R.string.error_no_internet)); alertDialog.setButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { return; } }); alertDialog.show(); } else { try { showBusyCursor(true); progress = ProgressDialog.show(this, getResources().getString(R.string.pantalla_espera_title), getResources().getString(R.string.iniciando_sesion), true); Log.d(DEB_TAG, "Requesting to " + address); JSONObject json = JsonClient.connectJSONObject(address); CheckBox rememberUserPassword = (CheckBox) findViewById(R.id.remember_user_password); if (rememberUserPassword.isChecked()) { setSharedPreference("login", sUserName); setSharedPreference("password", sPassword); } else { setSharedPreference("login", ""); setSharedPreference("password", ""); } if (json.getString("session") != "0") { progress.dismiss(); // Guardamos la session en SharedPreferences para utilizarla // posteriormente setSharedPreference("session", json.getString("session")); // Sessin correcta. StartActivity de la home Intent intent = new Intent(); intent.setClass(this.getApplicationContext(), HomeActivity.class); startActivity(intent); } else { progress.dismiss(); alertDialog.setTitle(getResources().getString(R.string.error)); alertDialog.setMessage(getResources().getString(R.string.error_login)); alertDialog.setButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { return; } }); alertDialog.show(); } } catch (JSONException e) { progress.dismiss(); Log.d(DEB_TAG, "Error parsing data " + e.toString()); } showBusyCursor(false); } }
From source file:produvia.com.lights.SmartLightsActivity.java
public void promptLogin(final JSONObject loginService, final JSONObject responseData) { runOnUiThread(new Runnable() { public void run() { try { String type = loginService.getString("type"); //there was a login error. login again if (type.equals(WeaverSdk.FIRST_LOGIN_TYPE_NORMAL)) { //prompt for username and password and retry: promptUsernamePassword(loginService, responseData, false, null); } else if (type.equals(WeaverSdk.FIRST_LOGIN_TYPE_KEY)) { promptUsernamePassword(loginService, responseData, true, loginService.getString("description")); } else if (type.equals(WeaverSdk.FIRST_LOGIN_TYPE_PRESS2LOGIN)) { //prompt for username and password and retry: int countdown = loginService.has("login_timeout") ? loginService.getInt("login_timeout") : 15;/*from w w w .j a va 2 s. co m*/ final AlertDialog alertDialog = new AlertDialog.Builder(SmartLightsActivity.this).create(); alertDialog.setTitle(loginService.getString("description")); alertDialog.setCancelable(false); alertDialog.setCanceledOnTouchOutside(false); alertDialog.setMessage(loginService.getString("description") + "\n" + "Attempting to login again in " + countdown + " seconds..."); alertDialog.show(); // new CountDownTimer(countdown * 1000, 1000) { @Override public void onTick(long millisUntilFinished) { try { alertDialog.setMessage(loginService.getString("description") + "\n" + "Attempting to login again in " + millisUntilFinished / 1000 + " seconds..."); } catch (JSONException e) { } } @Override public void onFinish() { alertDialog.dismiss(); new Thread(new Runnable() { public void run() { try { JSONArray services = new JSONArray(); services.put(loginService); responseData.put("services", services); WeaverSdkApi.servicesSet(SmartLightsActivity.this, responseData); } catch (JSONException e) { } } }).start(); } }.start(); } } catch (JSONException e) { e.printStackTrace(); } } }); }
From source file:com.example.SimpleTestClient.Activities.TestMainActivity.java
private void showInformationBox() { if (this.showingQuestion != null) { String msg = ""; String title = ""; if (this.showingQuestion.getQuestionModel().Type == QuestionBase.QuestionType.SingleChoice) { msg = getResources().getString(R.string.info_question_singleChoice); title = "? ? "; }//from w w w . jav a 2 s.c o m if (this.showingQuestion.getQuestionModel().Type == QuestionBase.QuestionType.MultiChoice) { msg = getResources().getString(R.string.info_question_multiChoice); title = "? ? ? "; } if (this.showingQuestion.getQuestionModel().Type == QuestionBase.QuestionType.TextQuestion) { msg = getResources().getString(R.string.info_question_textChoice); title = "? ? ?"; } AlertDialog ad = new AlertDialog.Builder(this).create(); ad.setIcon(R.drawable.ic_action_about); ad.setTitle(title); // ad.setCancelable(false); // This blocks the 'BACK' button ad.setMessage(msg); ad.setButton("OK", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); ad.show(); } }
From source file:produvia.com.scanner.DevicesActivity.java
public void promptLogin(final JSONObject loginService, final JSONObject responseData) { runOnUiThread(new Runnable() { public void run() { try { String type = loginService.getString("type"); //there was a login error. login again if (type.equals(WeaverSdk.FIRST_LOGIN_TYPE_NORMAL)) { //prompt for username and password and retry: promptUsernamePassword(loginService, responseData, false, null); } else if (type.equals(WeaverSdk.FIRST_LOGIN_TYPE_KEY)) { promptUsernamePassword(loginService, responseData, true, loginService.getString("description")); } else if (type.equals(WeaverSdk.FIRST_LOGIN_TYPE_PRESS2LOGIN)) { //prompt for username and password and retry: int countdown = loginService.has("login_timeout") ? loginService.getInt("login_timeout") : 15;//from ww w. j a v a 2s. co m final AlertDialog alertDialog = new AlertDialog.Builder(DevicesActivity.this).create(); alertDialog.setTitle(loginService.getString("description")); alertDialog.setCancelable(false); alertDialog.setCanceledOnTouchOutside(false); alertDialog.setMessage(loginService.getString("description") + "\n" + "Attempting to login again in " + countdown + " seconds..."); alertDialog.show(); // new CountDownTimer(countdown * 1000, 1000) { @Override public void onTick(long millisUntilFinished) { try { alertDialog.setMessage(loginService.getString("description") + "\n" + "Attempting to login again in " + millisUntilFinished / 1000 + " seconds..."); } catch (JSONException e) { } } @Override public void onFinish() { alertDialog.dismiss(); new Thread(new Runnable() { public void run() { try { JSONArray services = new JSONArray(); services.put(loginService); responseData.put("services", services); WeaverSdkApi.servicesSet(DevicesActivity.this, responseData); } catch (JSONException e) { } } }).start(); } }.start(); } } catch (JSONException e) { e.printStackTrace(); } } }); }
From source file:com.xperia64.timidityae.FileBrowserFragment.java
public void getDir(String dirPath) { currPath = dirPath;/*from w w w .j a v a 2s.com*/ fname = new ArrayList<String>(); path = new ArrayList<String>(); if (currPath != null) { File f = new File(currPath); if (f.exists()) { File[] files = f.listFiles(); if (files != null && files.length > 0) { Arrays.sort(files, new FileComparator()); // System.out.println(currPath); if (!currPath.matches("[/]+")) { fname.add("../"); path.add(f.getParent() + "/"); mCallback.needFileBackCallback(true); } else { mCallback.needFileBackCallback(false); } for (int i = 0; i < files.length; i++) { File file = files[i]; if ((!file.getName().startsWith(".") && !Globals.showHiddenFiles) || Globals.showHiddenFiles) { if (file.isFile()) { int dotPosition = file.getName().lastIndexOf("."); String extension = ""; if (dotPosition != -1) { extension = (file.getName().substring(dotPosition)).toLowerCase(Locale.US); if (extension != null) { if ((Globals.showVideos ? Globals.musicVideoFiles : Globals.musicFiles) .contains("*" + extension + "*")) { path.add(file.getAbsolutePath()); fname.add(file.getName()); } } else if (file.getName().endsWith("/")) { path.add(file.getAbsolutePath() + "/"); fname.add(file.getName() + "/"); } } } else { path.add(file.getAbsolutePath() + "/"); fname.add(file.getName() + "/"); } } } } else { if (!currPath.matches("[/]+")) { fname.add("../"); path.add(f.getParent() + "/"); } } ArrayAdapter<String> fileList = new ArrayAdapter<String>(getActivity(), R.layout.row, fname); getListView().setFastScrollEnabled(true); getListView().setOnItemLongClickListener(new OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> l, View v, final int position, long id) { localfinished = false; if (new File(path.get(position)).isFile() && Globals.isMidi(path.get(position))) { AlertDialog.Builder alert = new AlertDialog.Builder(getActivity()); alert.setTitle("Convert to WAV File"); alert.setMessage( "Exports the MIDI/MOD file to WAV.\nNative Midi must be disabled in settings.\nWarning: WAV files are large."); InputFilter filter = new InputFilter() { public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) { for (int i = start; i < end; i++) { String IC = "*/*\n*\r*\t*\0*\f*`*?***\\*<*>*|*\"*:*"; if (IC.contains("*" + source.charAt(i) + "*")) { return ""; } } return null; } }; // Set an EditText view to get user input final EditText input = new EditText(getActivity()); input.setFilters(new InputFilter[] { filter }); alert.setView(input); alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { String value = input.getText().toString(); if (!value.toLowerCase(Locale.US).endsWith(".wav")) value += ".wav"; String parent = path.get(position).substring(0, path.get(position).lastIndexOf('/') + 1); boolean aWrite = true; boolean alreadyExists = new File(parent + value).exists(); String needRename = null; String probablyTheRoot = ""; String probablyTheDirectory = ""; try { new FileOutputStream(parent + value, true).close(); } catch (FileNotFoundException e) { aWrite = false; } catch (IOException e) { e.printStackTrace(); } if (!alreadyExists && aWrite) new File(parent + value).delete(); if (aWrite && new File(parent).canWrite()) { value = parent + value; } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && Globals.theFold != null) { // Write the file to getExternalFilesDir, then move it with the Uri // We need to tell JNIHandler that movement is needed. String[] tmp = Globals.getDocFilePaths(getActivity(), parent); probablyTheDirectory = tmp[0]; probablyTheRoot = tmp[1]; if (probablyTheDirectory.length() > 1) { needRename = parent.substring( parent.indexOf(probablyTheRoot) + probablyTheRoot.length()) + value; value = probablyTheDirectory + '/' + value; } else { value = Environment.getExternalStorageDirectory().getAbsolutePath() + '/' + value; } } else { value = Environment.getExternalStorageDirectory().getAbsolutePath() + '/' + value; } final boolean canWrite = aWrite; final String finalval = value; final String needToRename = needRename; final String probRoot = probablyTheRoot; if (new File(finalval).exists() || (new File(probRoot + needRename).exists() && needToRename != null)) { AlertDialog dialog2 = new AlertDialog.Builder(getActivity()).create(); dialog2.setTitle("Warning"); dialog2.setMessage("Overwrite WAV file?"); dialog2.setCancelable(false); dialog2.setButton(DialogInterface.BUTTON_POSITIVE, getResources().getString(android.R.string.yes), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int buttonId) { if (!canWrite && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { if (needToRename != null) { Globals.tryToDeleteFile(getActivity(), probRoot + needToRename); Globals.tryToDeleteFile(getActivity(), finalval); } else { Globals.tryToDeleteFile(getActivity(), finalval); } } else { new File(finalval).delete(); } saveWavPart2(position, finalval, needToRename); } }); dialog2.setButton(DialogInterface.BUTTON_NEGATIVE, getResources().getString(android.R.string.no), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int buttonId) { } }); dialog2.show(); } else { saveWavPart2(position, finalval, needToRename); } } }); alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { // Canceled. } }); alert.show(); return true; } else { } return false; } }); setListAdapter(fileList); } } }