List of usage examples for android.app ProgressDialog setCancelable
public void setCancelable(boolean flag)
From source file:fm.smart.r1.activity.CreateSoundActivity.java
public void onClick(View v) { String threegpfile_name = "test.3gp_amr"; String amrfile_name = "test.amr"; File dir = this.getDir("sounds", MODE_WORLD_READABLE); final File threegpfile = new File(dir, threegpfile_name); File amrfile = new File(dir, amrfile_name); String path = threegpfile.getAbsolutePath(); Log.d("CreateSoundActivity", path); Log.d("CreateSoundActivity", (String) button.getText()); if (button.getText().equals("Start")) { try {/*from www . j ava 2 s . co m*/ recorder = new MediaRecorder(); // ContentValues values = new ContentValues(3); // // values.put(MediaStore.MediaColumns.TITLE, "test"); // values.put(MediaStore.MediaColumns.DATE_ADDED, // System.currentTimeMillis()); // values.put(MediaStore.MediaColumns.MIME_TYPE, // MediaRecorder.OutputFormat.THREE_GPP); // // ContentResolver contentResolver = new ContentResolver(this); // // Uri base = MediaStore.Audio.INTERNAL_CONTENT_URI; // Uri newUri = contentResolver.insert(base, values); recorder.setAudioSource(MediaRecorder.AudioSource.MIC); recorder.setOutputFormat(MediaRecorder.OutputFormat.RAW_AMR); recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); recorder.setOutputFile(path); recorder.prepare(); button.setText("Stop"); recorder.start(); } catch (Exception e) { Log.w(TAG, e); } } else { FileOutputStream os = null; FileInputStream is = null; try { recorder.stop(); recorder.release(); // Now the object cannot be reused button.setEnabled(false); // ThreegpReader tr = new ThreegpReader(threegpfile); // os = new FileOutputStream(amrfile); // tr.extractAmr(os); is = new FileInputStream(threegpfile); playSound(is.getFD()); final String media_entity = "http://test.com/test.mp3"; final String author = "tansaku"; final String author_url = "http://smart.fm/users/tansaku"; if (Main.isNotLoggedIn(this)) { Intent intent = new Intent(Intent.ACTION_VIEW); intent.setClassName(this, LoginActivity.class.getName()); intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); LoginActivity.return_to = CreateSoundActivity.class.getName(); LoginActivity.params = new HashMap<String, String>(); LoginActivity.params.put("item_id", item_id); LoginActivity.params.put("list_id", list_id); LoginActivity.params.put("id", id); LoginActivity.params.put("to_record", to_record); LoginActivity.params.put("sound_type", sound_type); startActivity(intent); } else { final ProgressDialog myOtherProgressDialog = new ProgressDialog(this); myOtherProgressDialog.setTitle("Please Wait ..."); myOtherProgressDialog.setMessage("Creating Sound ..."); myOtherProgressDialog.setIndeterminate(true); myOtherProgressDialog.setCancelable(true); final Thread create_sound = new Thread() { public void run() { // TODO make this interruptable .../*if // (!this.isInterrupted())*/ CreateSoundActivity.create_sound_result = createSound(threegpfile, media_entity, author, author_url, "1", id); myOtherProgressDialog.dismiss(); } }; myOtherProgressDialog.setButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { create_sound.interrupt(); } }); OnCancelListener ocl = new OnCancelListener() { public void onCancel(DialogInterface arg0) { create_sound.interrupt(); } }; myOtherProgressDialog.setOnCancelListener(ocl); myOtherProgressDialog.show(); create_sound.start(); } } catch (Exception e) { Log.w(TAG, e); } finally { if (os != null) { try { os.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } if (is != null) { try { is.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } } }
From source file:de.ub0r.android.callmeter.ui.prefs.Preferences.java
/** * Import data previously exported./*from w ww .ja v a 2 s .com*/ * * @param context * {@link Context} * @param uri * {@link Uri} */ private void importData(final Context context, final Uri uri) { Log.d(TAG, "importData(ctx, " + uri + ")"); final ProgressDialog d1 = new ProgressDialog(this); d1.setCancelable(true); d1.setMessage(this.getString(R.string.import_progr)); d1.setIndeterminate(true); d1.show(); new AsyncTask<Void, Void, String>() { @Override protected String doInBackground(final Void... params) { StringBuilder sb = new StringBuilder(); try { final BufferedReader bufferedReader = // . new BufferedReader(new InputStreamReader(// . Preferences.this.getStream(Preferences.this.getContentResolver(), uri)), BUFSIZE); String line = bufferedReader.readLine(); while (line != null) { sb.append(line); sb.append("\n"); line = bufferedReader.readLine(); } } catch (Exception e) { Log.e(TAG, "error in reading export: " + e.toString(), e); return null; } return sb.toString(); } @Override protected void onPostExecute(final String result) { Log.d(TAG, "import:\n" + result); d1.dismiss(); if (result == null || result.length() == 0) { Toast.makeText(Preferences.this, R.string.err_export_read, Toast.LENGTH_LONG).show(); return; } String[] lines = result.split("\n"); if (lines.length <= 2) { Toast.makeText(Preferences.this, R.string.err_export_read, Toast.LENGTH_LONG).show(); return; } Builder builder = new Builder(Preferences.this); builder.setCancelable(true); builder.setTitle(R.string.import_rules_); builder.setMessage(Preferences.this.getString(R.string.import_rules_hint) + "\n" + URLDecoder.decode(lines[1])); builder.setNegativeButton(android.R.string.cancel, null); builder.setPositiveButton(android.R.string.ok, new OnClickListener() { @Override public void onClick(final DialogInterface dialog, final int which) { d1.setCancelable(false); d1.setIndeterminate(true); d1.show(); new AsyncTask<Void, Void, Void>() { @Override protected Void doInBackground(final Void... params) { DataProvider.importData(Preferences.this, result); return null; } @Override protected void onPostExecute(final Void result) { de.ub0r.android.callmeter.ui.Plans.reloadList(); d1.dismiss(); } } // . .execute((Void) null); } }); builder.show(); } } // . .execute((Void) null); }
From source file:fm.smart.r1.CreateSoundActivity.java
public void onClick(View v) { String threegpfile_name = "test.3gp_amr"; String amrfile_name = "test.amr"; File dir = this.getDir("sounds", MODE_WORLD_READABLE); final File threegpfile = new File(dir, threegpfile_name); File amrfile = new File(dir, amrfile_name); String path = threegpfile.getAbsolutePath(); Log.d("CreateSoundActivity", path); Log.d("CreateSoundActivity", (String) button.getText()); if (button.getText().equals("Start")) { try {/*from w ww . j a v a2s .c o m*/ recorder = new MediaRecorder(); // ContentValues values = new ContentValues(3); // // values.put(MediaStore.MediaColumns.TITLE, "test"); // values.put(MediaStore.MediaColumns.DATE_ADDED, // System.currentTimeMillis()); // values.put(MediaStore.MediaColumns.MIME_TYPE, // MediaRecorder.OutputFormat.THREE_GPP); // // ContentResolver contentResolver = new ContentResolver(this); // // Uri base = MediaStore.Audio.INTERNAL_CONTENT_URI; // Uri newUri = contentResolver.insert(base, values); recorder.setAudioSource(MediaRecorder.AudioSource.MIC); recorder.setOutputFormat(MediaRecorder.OutputFormat.RAW_AMR); recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); recorder.setOutputFile(path); recorder.prepare(); button.setText("Stop"); recorder.start(); } catch (Exception e) { Log.w(TAG, e); } } else { FileOutputStream os = null; FileInputStream is = null; try { recorder.stop(); recorder.release(); // Now the object cannot be reused button.setEnabled(false); // ThreegpReader tr = new ThreegpReader(threegpfile); // os = new FileOutputStream(amrfile); // tr.extractAmr(os); is = new FileInputStream(threegpfile); playSound(is.getFD()); final String media_entity = "http://test.com/test.mp3"; final String author = "tansaku"; final String author_url = "http://smart.fm/users/tansaku"; if (LoginActivity.isNotLoggedIn(this)) { Intent intent = new Intent(Intent.ACTION_VIEW); intent.setClassName(this, LoginActivity.class.getName()); intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); LoginActivity.return_to = CreateSoundActivity.class.getName(); LoginActivity.params = new HashMap<String, String>(); LoginActivity.params.put("item_id", item_id); LoginActivity.params.put("goal_id", goal_id); LoginActivity.params.put("id", id); LoginActivity.params.put("to_record", to_record); LoginActivity.params.put("sound_type", sound_type); startActivity(intent); } else { final ProgressDialog myOtherProgressDialog = new ProgressDialog(this); myOtherProgressDialog.setTitle("Please Wait ..."); myOtherProgressDialog.setMessage("Creating Sound ..."); myOtherProgressDialog.setIndeterminate(true); myOtherProgressDialog.setCancelable(true); final Thread create_sound = new Thread() { public void run() { // TODO make this interruptable .../*if // (!this.isInterrupted())*/ CreateSoundActivity.create_sound_result = createSound(threegpfile, media_entity, author, author_url, "1", item_id, id, to_record); // this will also ensure item is in goal, but this // should be sentence // submission if we are handling sentence sound. if (sound_type.equals(Integer.toString(R.id.cue_sound))) { CreateSoundActivity.add_item_result = new AddItemResult( Main.lookup.addItemToGoal(Main.transport, Main.default_study_goal_id, item_id, CreateSoundActivity.create_sound_result.sound_id)); } else { // ensure item is in goal CreateSoundActivity.add_item_result = new AddItemResult(Main.lookup .addItemToGoal(Main.transport, Main.default_study_goal_id, item_id, null)); CreateSoundActivity.add_sentence_result = new AddSentenceResult( Main.lookup.addSentenceToGoal(Main.transport, Main.default_study_goal_id, item_id, id, CreateSoundActivity.create_sound_result.sound_id)); } myOtherProgressDialog.dismiss(); } }; myOtherProgressDialog.setButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { create_sound.interrupt(); } }); OnCancelListener ocl = new OnCancelListener() { public void onCancel(DialogInterface arg0) { create_sound.interrupt(); } }; myOtherProgressDialog.setOnCancelListener(ocl); myOtherProgressDialog.show(); create_sound.start(); } } catch (Exception e) { Log.w(TAG, e); } finally { if (os != null) { try { os.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } if (is != null) { try { is.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } } }
From source file:org.symptomcheck.capstone.ui.CheckInFlowActivityOld.java
private void executeCheckInSaving(final CheckIn checkIn) { final ProgressDialog ringProgressDialog = ProgressDialog.show(this, "Please wait ...", "Check-In submission in progress ...", true); ringProgressDialog.setCancelable(true); new Thread(new Runnable() { //TODO#BPR_8 Check-In saving performed in a background Thread @Override/*from w w w . j a va2 s . co m*/ public void run() { try { final boolean checkinRes = saveCheckIn(checkIn); Thread.sleep(3000); progressBarHandler.post(new Runnable() { @Override public void run() { if (checkinRes) { //re-schedule the next check-in SymptomAlarmRequest.get().setAlarm(getApplicationContext(), SymptomAlarmRequest.AlarmRequestedType.ALARM_CHECK_IN_REMINDER, false); SyncUtils.TriggerRefreshPartialCloud(ActiveContract.SYNC_CHECK_IN); finish(); Toast.makeText(getApplicationContext(), "Check-In Submitted Correctly", Toast.LENGTH_LONG).show(); } else { Toast.makeText(getApplicationContext(), "Check-In Submission ERROR!!!", Toast.LENGTH_LONG).show(); } } }); } catch (Exception ignored) { } ringProgressDialog.dismiss(); } }).start(); }
From source file:ca.rmen.android.scrumchatter.dialog.ProgressDialogFragment.java
/** * @return an indeterminate, non-cancelable, ProgressDialog with a message. *//*from w ww . j a v a2 s . c o m*/ @Override @NonNull public Dialog onCreateDialog(Bundle savedInstanceState) { Log.v(TAG, "onCreateDialog: savedInstanceState = " + savedInstanceState); ProgressDialog dialog = new ProgressDialog(getActivity()); Bundle arguments = getArguments(); dialog.setMessage(arguments.getString(DialogFragmentFactory.EXTRA_MESSAGE)); dialog.setIndeterminate(true); dialog.setOnShowListener(shownDialog -> { ProgressBar progressBar = (ProgressBar) ((ProgressDialog) shownDialog) .findViewById(android.R.id.progress); if (progressBar != null) { Drawable drawable = progressBar.getIndeterminateDrawable(); if (drawable != null) { drawable.setColorFilter( ContextCompat.getColor(getActivity(), R.color.scrum_chatter_accent_color), android.graphics.PorterDuff.Mode.SRC_IN); } } }); dialog.setCancelable(false); return dialog; }
From source file:com.xperia64.timidityae.FileBrowserFragment.java
public void saveWavPart2(final int position, final String finalval, final String needToRename) { ((TimidityActivity) getActivity()).writeFile(path.get(position), finalval); final ProgressDialog prog; prog = new ProgressDialog(getActivity()); prog.setButton(DialogInterface.BUTTON_NEGATIVE, "Cancel", new DialogInterface.OnClickListener() { @Override/* ww w .ja va 2 s . c om*/ public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); prog.setTitle("Converting to WAV"); prog.setMessage("Converting..."); prog.setIndeterminate(false); prog.setCancelable(false); prog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); prog.show(); new Thread(new Runnable() { @Override public void run() { while (!localfinished && prog.isShowing()) { prog.setMax(JNIHandler.maxTime); prog.setProgress(JNIHandler.currTime); try { Thread.sleep(25); } catch (InterruptedException e) { } } if (!localfinished) { JNIHandler.stop(); getActivity().runOnUiThread(new Runnable() { public void run() { Toast.makeText(getActivity(), "Conversion canceled", Toast.LENGTH_SHORT).show(); if (!Globals.keepWav) { if (new File(finalval).exists()) new File(finalval).delete(); } else { getDir(currPath); } } }); } else { getActivity().runOnUiThread(new Runnable() { public void run() { String trueName = finalval; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && Globals.theFold != null && needToRename != null) { if (Globals.renameDocumentFile(getActivity(), finalval, needToRename)) { trueName = needToRename; } else { trueName = "Error"; } } Toast.makeText(getActivity(), "Wrote " + trueName, Toast.LENGTH_SHORT).show(); prog.dismiss(); getDir(currPath); } }); } } }).start(); }
From source file:com.slownet5.pgprootexplorer.filemanager.ui.FileManagerActivity.java
private void setupRoot() { if (alreadySetup()) { afterInitSetup(true);//from w w w .ja va2 s . c o m return; } final ProgressDialog dialog = new ProgressDialog(this); dialog.setIndeterminate(true); dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); dialog.setTitle("Setting up root"); dialog.setCancelable(false); ; dialog.setMax(100); final String os = SystemUtils.getSystemArchitecture(); Log.d(TAG, "setupRoot: architecture is: " + os); class Setup extends AsyncTask<Void, Integer, Boolean> { @Override protected Boolean doInBackground(Void... params) { new File(SharedData.CRYPTO_FM_PATH).mkdirs(); String filename = SharedData.CRYPTO_FM_PATH + "/toybox"; AssetManager asset = getAssets(); try { InputStream stream = asset.open("toybox"); OutputStream out = new FileOutputStream(filename); byte[] buffer = new byte[4096]; int read; int total = 0; while ((read = stream.read(buffer)) != -1) { total += read; out.write(buffer, 0, read); } Log.d(TAG, "doInBackground: total written bytes: " + total); stream.close(); out.flush(); out.close(); } catch (IOException ex) { ex.printStackTrace(); return false; } RootUtils.initRoot(filename); return true; } @Override protected void onPreExecute() { dialog.setMessage("Please wait...."); dialog.show(); } @Override protected void onPostExecute(Boolean aBoolean) { dialog.dismiss(); if (aBoolean) { SharedPreferences.Editor prefs = getSharedPreferences(CommonConstants.COMMON_SHARED_PEREFS_NAME, Context.MODE_PRIVATE).edit(); prefs.putBoolean(CommonConstants.ROOT_TOYBOX, true); prefs.apply(); prefs.commit(); afterInitSetup(true); } else { afterInitSetup(aBoolean); } } } new Setup().execute(); }
From source file:com.kkbox.toolkit.dialog.KKDialog.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { DialogInterface.OnClickListener positiveListener = new DialogInterface.OnClickListener() { @Override/* w w w . j ava 2s.c o m*/ public void onClick(DialogInterface dialog, int id) { if (!isDismissed) { if (listener != null) { listener.onPositive(); } onDialogFinishedByUser(); isDismissed = true; } } }; DialogInterface.OnClickListener neutralListener = new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { if (!isDismissed) { if (listener != null) { listener.onNeutral(); } onDialogFinishedByUser(); isDismissed = true; } } }; DialogInterface.OnClickListener negativeListener = new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { if (!isDismissed) { if (listener != null) { listener.onNegative(); } onDialogFinishedByUser(); isDismissed = true; } } }; switch (dialogType) { case Type.PROGRESSING_DIALOG: ProgressDialog progressDialog; if (theme != -1) { progressDialog = new ProgressDialog(getActivity(), theme); } else { progressDialog = new ProgressDialog(getActivity()); } progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); progressDialog.setMessage(message); progressDialog.setIndeterminate(true); progressDialog.setCanceledOnTouchOutside(false); progressDialog.setCancelable(listener != null); return progressDialog; case Type.ALERT_DIALOG: AlertDialog.Builder builder; AlertDialog alertDialog; if (theme != -1) { builder = new AlertDialog.Builder(new ContextThemeWrapper(getActivity(), theme)); } else { builder = new AlertDialog.Builder(getActivity()); } builder.setMessage(message); builder.setTitle(title); builder.setPositiveButton(positiveButtonText, positiveListener); alertDialog = builder.create(); alertDialog.setCanceledOnTouchOutside(isAlertDialogCanceledOnTouchOutside); return alertDialog; case Type.THREE_CHOICE_DIALOG: if (theme != -1) { builder = new AlertDialog.Builder(new ContextThemeWrapper(getActivity(), theme)); } else { builder = new AlertDialog.Builder(getActivity()); } builder.setMessage(message); builder.setTitle(title); builder.setPositiveButton(positiveButtonText, positiveListener); builder.setNeutralButton(neutralButtonText, neutralListener); builder.setNegativeButton(negativeButtonText, negativeListener); alertDialog = builder.create(); alertDialog.setCanceledOnTouchOutside(isAlertDialogCanceledOnTouchOutside); return alertDialog; case Type.YES_OR_NO_DIALOG: if (theme != -1) { builder = new AlertDialog.Builder(new ContextThemeWrapper(getActivity(), theme)); } else { builder = new AlertDialog.Builder(getActivity()); } builder.setMessage(message); builder.setTitle(title); builder.setPositiveButton(positiveButtonText, positiveListener); builder.setNegativeButton(negativeButtonText, negativeListener); alertDialog = builder.create(); alertDialog.setCanceledOnTouchOutside(isAlertDialogCanceledOnTouchOutside); return alertDialog; case Type.SELECT_DIALOG: if (theme != -1) { builder = new AlertDialog.Builder(new ContextThemeWrapper(getActivity(), theme)); } else { builder = new AlertDialog.Builder(getActivity()); } builder.setMessage(message); builder.setTitle(title); builder.setSingleChoiceItems(entries, selectedIndex, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { if (!isDismissed) { if (listener != null) { listener.onEvent(id); } dismiss(); onDialogFinishedByUser(); isDismissed = true; } } }); builder.setNegativeButton(negativeButtonText, negativeListener); alertDialog = builder.create(); alertDialog.setCanceledOnTouchOutside(isAlertDialogCanceledOnTouchOutside); return alertDialog; case Type.CUSTOMIZE_DIALOG: if (theme != -1) { builder = new AlertDialog.Builder(new ContextThemeWrapper(getActivity(), theme)); } else { builder = new AlertDialog.Builder(getActivity()); } if (customizeView != null && customizeView.getParent() != null) { ((ViewGroup) customizeView.getParent()).removeView(customizeView); } builder.setView(customizeView); if (!TextUtils.isEmpty(title)) { builder.setTitle(title); } if (!TextUtils.isEmpty(positiveButtonText)) { builder.setPositiveButton(positiveButtonText, positiveListener); } if (!TextUtils.isEmpty(neutralButtonText)) { builder.setNeutralButton(neutralButtonText, neutralListener); } if (!TextUtils.isEmpty(negativeButtonText)) { builder.setNegativeButton(negativeButtonText, negativeListener); } alertDialog = builder.create(); alertDialog.setCanceledOnTouchOutside(isAlertDialogCanceledOnTouchOutside); return alertDialog; case Type.CUSTOMIZE_FULLSCREEN_DIALOG: Dialog dialog; if (theme != -1) { dialog = new Dialog(getActivity(), theme); } else { dialog = new Dialog(getActivity(), android.R.style.Theme_NoTitleBar); } if (customizeView != null && customizeView.getParent() != null) { ((ViewGroup) customizeView.getParent()).removeView(customizeView); } dialog.setContentView(customizeView); return dialog; } return null; }
From source file:com.owncloud.android.ui.activity.Uploader.java
@Override protected Dialog onCreateDialog(final int id) { final AlertDialog.Builder builder = new Builder(this); switch (id) { case DIALOG_WAITING: final ProgressDialog pDialog = new ProgressDialog(this, R.style.ProgressDialogTheme); pDialog.setIndeterminate(false); pDialog.setCancelable(false); pDialog.setMessage(getResources().getString(R.string.uploader_info_uploading)); pDialog.setOnShowListener(new DialogInterface.OnShowListener() { @Override//from w w w . ja v a 2 s. c om public void onShow(DialogInterface dialog) { ProgressBar v = (ProgressBar) pDialog.findViewById(android.R.id.progress); v.getIndeterminateDrawable().setColorFilter(getResources().getColor(R.color.color_accent), android.graphics.PorterDuff.Mode.MULTIPLY); } }); return pDialog; case DIALOG_NO_ACCOUNT: builder.setIcon(android.R.drawable.ic_dialog_alert); builder.setTitle(R.string.uploader_wrn_no_account_title); builder.setMessage( String.format(getString(R.string.uploader_wrn_no_account_text), getString(R.string.app_name))); builder.setCancelable(false); builder.setPositiveButton(R.string.uploader_wrn_no_account_setup_btn_text, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.ECLAIR_MR1) { // using string value since in API7 this // constatn is not defined // in API7 < this constatant is defined in // Settings.ADD_ACCOUNT_SETTINGS // and Settings.EXTRA_AUTHORITIES Intent intent = new Intent(android.provider.Settings.ACTION_ADD_ACCOUNT); intent.putExtra("authorities", new String[] { MainApp.getAuthTokenType() }); startActivityForResult(intent, REQUEST_CODE_SETUP_ACCOUNT); } else { // since in API7 there is no direct call for // account setup, so we need to // show our own AccountSetupAcricity, get // desired results and setup // everything for ourself Intent intent = new Intent(getBaseContext(), AccountAuthenticator.class); startActivityForResult(intent, REQUEST_CODE_SETUP_ACCOUNT); } } }); builder.setNegativeButton(R.string.uploader_wrn_no_account_quit_btn_text, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { finish(); } }); return builder.create(); case DIALOG_MULTIPLE_ACCOUNT: CharSequence ac[] = new CharSequence[mAccountManager .getAccountsByType(MainApp.getAccountType()).length]; for (int i = 0; i < ac.length; ++i) { ac[i] = DisplayUtils.convertIdn(mAccountManager.getAccountsByType(MainApp.getAccountType())[i].name, false); } builder.setTitle(R.string.common_choose_account); builder.setItems(ac, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { setAccount(mAccountManager.getAccountsByType(MainApp.getAccountType())[which]); onAccountSet(mAccountWasRestored); dialog.dismiss(); mAccountSelected = true; mAccountSelectionShowing = false; } }); builder.setCancelable(true); builder.setOnCancelListener(new OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { mAccountSelectionShowing = false; dialog.cancel(); finish(); } }); return builder.create(); case DIALOG_NO_STREAM: builder.setIcon(android.R.drawable.ic_dialog_alert); builder.setTitle(R.string.uploader_wrn_no_content_title); builder.setMessage(R.string.uploader_wrn_no_content_text); builder.setCancelable(false); builder.setNegativeButton(R.string.common_cancel, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { finish(); } }); return builder.create(); default: throw new IllegalArgumentException("Unknown dialog id: " + id); } }
From source file:com.carlrice.reader.activity.EditFeedActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: finish();//from w ww .j ava 2 s . c om return true; case R.id.menu_add_filter: { final View dialogView = getLayoutInflater().inflate(R.layout.dialog_filter_edit, null); new AlertDialog.Builder(this) // .setTitle(R.string.filter_add_title) // .setView(dialogView) // .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { String filterText = ((EditText) dialogView.findViewById(R.id.filterText)).getText() .toString(); if (filterText.length() != 0) { String feedId = getIntent().getData().getLastPathSegment(); ContentValues values = new ContentValues(); values.put(FilterColumns.FILTER_TEXT, filterText); values.put(FilterColumns.IS_REGEX, ((CheckBox) dialogView.findViewById(R.id.regexCheckBox)).isChecked()); values.put(FilterColumns.IS_APPLIED_TO_TITLE, ((RadioButton) dialogView.findViewById(R.id.applyTitleRadio)).isChecked()); values.put(FilterColumns.IS_ACCEPT_RULE, ((RadioButton) dialogView.findViewById(R.id.acceptRadio)).isChecked()); ContentResolver cr = getContentResolver(); cr.insert(FilterColumns.FILTERS_FOR_FEED_CONTENT_URI(feedId), values); } } }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { } }).show(); return true; } case R.id.menu_search_feed: { final View dialogView = getLayoutInflater().inflate(R.layout.dialog_search_feed, null); final EditText searchText = (EditText) dialogView.findViewById(R.id.searchText); if (!mUrlEditText.getText().toString().startsWith(Constants.HTTP_SCHEME) && !mUrlEditText.getText().toString().startsWith(Constants.HTTPS_SCHEME)) { searchText.setText(mUrlEditText.getText()); } final RadioGroup radioGroup = (RadioGroup) dialogView.findViewById(R.id.radioGroup); new AlertDialog.Builder(EditFeedActivity.this) // .setIcon(R.drawable.action_search) // .setTitle(R.string.feed_search) // .setView(dialogView) // .setPositiveButton(android.R.string.search_go, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (searchText.getText().length() > 0) { String tmp = searchText.getText().toString(); try { tmp = URLEncoder.encode(searchText.getText().toString(), Constants.UTF8); } catch (UnsupportedEncodingException ignored) { } final String text = tmp; switch (radioGroup.getCheckedRadioButtonId()) { case R.id.byWebSearch: final ProgressDialog pd = new ProgressDialog(EditFeedActivity.this); pd.setMessage(getString(R.string.loading)); pd.setCancelable(true); pd.setIndeterminate(true); pd.show(); getLoaderManager().restartLoader(1, null, new LoaderManager.LoaderCallbacks<ArrayList<HashMap<String, String>>>() { @Override public Loader<ArrayList<HashMap<String, String>>> onCreateLoader( int id, Bundle args) { return new GetFeedSearchResultsLoader(EditFeedActivity.this, text); } @Override public void onLoadFinished( Loader<ArrayList<HashMap<String, String>>> loader, final ArrayList<HashMap<String, String>> data) { pd.cancel(); if (data == null) { Toast.makeText(EditFeedActivity.this, R.string.error, Toast.LENGTH_SHORT).show(); } else if (data.isEmpty()) { Toast.makeText(EditFeedActivity.this, R.string.no_result, Toast.LENGTH_SHORT).show(); } else { AlertDialog.Builder builder = new AlertDialog.Builder( EditFeedActivity.this); builder.setTitle(R.string.feed_search); // create the grid item mapping String[] from = new String[] { FEED_SEARCH_TITLE, FEED_SEARCH_DESC }; int[] to = new int[] { android.R.id.text1, android.R.id.text2 }; // fill in the grid_item layout SimpleAdapter adapter = new SimpleAdapter( EditFeedActivity.this, data, R.layout.item_search_result, from, to); builder.setAdapter(adapter, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { mNameEditText.setText(data.get(which) .get(FEED_SEARCH_TITLE)); mUrlEditText.setText(data.get(which) .get(FEED_SEARCH_URL)); } }); builder.show(); } } @Override public void onLoaderReset( Loader<ArrayList<HashMap<String, String>>> loader) { } }); break; case R.id.byTopic: mUrlEditText.setText("http://www.faroo.com/api?q=" + text + "&start=1&length=10&l=en&src=news&f=rss"); break; case R.id.byYoutube: mUrlEditText.setText("http://www.youtube.com/rss/user/" + text.replaceAll("\\+", "") + "/videos.rss"); break; } } } }).setNegativeButton(android.R.string.cancel, null).show(); return true; } default: return super.onOptionsItemSelected(item); } }