List of usage examples for android.content DialogInterface.OnClickListener DialogInterface.OnClickListener
DialogInterface.OnClickListener
From source file:com.vuze.android.remote.SessionInfo.java
public static void showUrlFailedDialog(final Activity activity, final String errMsg, final String url, final String sample) { if (activity == null) { Log.e(null, "No activity for error message " + errMsg); return;/*from w w w .j a v a2s . c o m*/ } activity.runOnUiThread(new Runnable() { public void run() { if (activity.isFinishing()) { return; } String s = activity.getResources().getString(R.string.torrent_url_add_failed, url, sample); Spanned msg = Html.fromHtml(s); Builder builder = new AlertDialog.Builder(activity).setMessage(msg).setCancelable(true) .setNegativeButton(android.R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { } }).setNeutralButton(R.string.torrent_url_add_failed_openurl, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); activity.startActivity(intent); } }); builder.show(); } }); }
From source file:com.klinker.android.twitter.activities.drawer_activities.DrawerActivity.java
public void showFollowDialog() { new AlertDialog.Builder(context) .setItems(new CharSequence[] { "@TalonAndroid", "@lukeklinker", "Luke's Google+" }, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { if (i == 0) { // talon Intent profile = new Intent(context, ProfilePager.class); profile.putExtra("screenname", "TalonAndroid"); profile.putExtra("proPic", ""); startActivity(profile); } else if (i == 1) { // luke (twitter) Intent profile = new Intent(context, ProfilePager.class); profile.putExtra("screenname", "lukeklinker"); profile.putExtra("proPic", ""); startActivity(profile); } else { // luke (google+) startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://google.com/+LukeKlinker"))); }//from w ww .j ava2 s . co m } }) .create().show(); }
From source file:com.free.searcher.MainFragment.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); Log.d("data", "" + data); Log.d("requestCode", "" + requestCode); Log.d("resultCode", "" + resultCode); locX = 0;/* w w w . j a va2 s.com*/ locY = 0; try { if (data != null) { String[] stringExtra = data.getStringArrayExtra(FolderChooserActivity.SELECTED_DIR); if (requestCode == SEARCH_REQUEST_CODE) { if (resultCode == Activity.RESULT_OK) { stopReadAndSearch(); Log.d("SEARCH_REQUEST_CODE.selectedFiles", Util.arrayToString(stringExtra, true, MainFragment.LINE_SEP)); currentZipFileName = ""; // lm du kh?i show web getSourceFile selectedFiles = stringExtra; getSourceFileTask = new GetSourceFileTask(MainFragment.this); getSourceFileTask.execute(); load = "Search"; } else { // RESULT_CANCEL if (selectedFiles.length == 0) { showToast("Nothing to search"); statusView.setText("Nothing to search"); } } } else if (requestCode == ZIP_REQUEST_CODE) { if (resultCode == Activity.RESULT_OK) { stopReadAndSearch(); currentZipFileName = stringExtra[0]; selectedFiles = stringExtra; load = "Zip Reader"; Log.d("ZIP_REQUEST_CODE.currentZFile", currentZipFileName); statusView.setText("reading " + currentZipFileName + "..."); try { zr = new ZipReadingTask(MainFragment.this); zr.execute(); } catch (Exception e) { statusView.setText(e.getMessage()); Log.d("zip result", e.getMessage(), e); showToast(e.getMessage()); } } else if (currentZipFileName.length() == 0) { showToast("Nothing to read"); statusView.setText("Nothing to read"); } // } else if (requestCode == COMPARE_REQUEST_CODE1) { // if (resultCode == Activity.RESULT_OK) { // oriDoc = stringExtra[0]; // Log.d("COMPARE_REQUEST_CODE1.oriDoc", oriDoc); // Intent intent = new Intent(activity, FolderChooserActivity.class); // intent.putExtra(MainFragment.SELECTED_DIR, // new String[] { oriDoc }); // intent.putExtra(MainFragment.SUFFIX, DOC_FILES_SUFFIX); // intent.putExtra(MainFragment.MODE, !MULTI_FILES); // intent.putExtra(MainFragment.CHOOSER_TITLE,MODI_SUFFIX_TITLE); // activity.startActivityForResult(intent, COMPARE_REQUEST_CODE2); // } else { // RESULT_CANCEL // if (selectedFiles.length == 0) { // showToast("Nothing to compare"); // statusView.setText("Nothing to compare"); // } // } // } else if (requestCode == COMPARE_REQUEST_CODE2) { // if (resultCode == Activity.RESULT_OK) { // stopReadAndSearch(); // modifiedDoc = stringExtra[0]; // Log.d("COMPARE_REQUEST_CODE2.modifiedDoc", modifiedDoc); // currentZipFileName = ""; // lm du kh?i show web getSourceFile // selectedFiles = new String[] {oriDoc, modifiedDoc}; // load = "Search"; // requestCompare = true; // requestSearching = false; // getSourceFileTask = new GetSourceFileTask(MainFragment.this); // getSourceFileTask.execute(); // } else { // RESULT_CANCEL // if (selectedFiles.length == 0) { // showToast("Nothing to compare"); // statusView.setText("Nothing to compare"); // } // } } else if (requestCode == GEN_REQUEST_CODE) { if (resultCode == Activity.RESULT_OK) { Log.d("GEN_REQUEST_CODE.selectedFiles", stringExtra[0]); genStardictTask = new GenStardictTask(MainFragment.this, stringExtra[0]); genStardictTask.execute(); } else { // RESULT_CANCEL if (selectedFiles.length == 0) { showToast("Nothing to generate"); statusView.setText("Nothing to generate"); } } } else if (requestCode == RESTORE_REQUEST_CODE) { if (resultCode == Activity.RESULT_OK) { Log.d("RESTORE_REQUEST_CODE.selectedFiles", stringExtra[0]); restoreStardictTask = new RestoreStardictTask(MainFragment.this, stringExtra[0]); restoreStardictTask.execute(); } else { // RESULT_CANCEL if (selectedFiles.length == 0) { showToast("Nothing to restore"); statusView.setText("Nothing to restore"); } } } else if (requestCode == DUP_REQUEST_CODE) { if (resultCode == Activity.RESULT_OK) { stopReadAndSearch(); Log.d("DUP_REQUEST_CODE.selectedFiles", Util.arrayToString(stringExtra, true, MainFragment.LINE_SEP)); if (FileUtils.treeUri == null) {// && !checkFolder(new File(st).getParentFile(), WRITE_REQUEST_CODE)) { FileUtils.applicationContext = activity; FileUtils.treeUri = FileUtils .getSharedPreferenceUri(R.string.key_internal_uri_extsdcard); if (FileUtils.treeUri == null) { AlertDialog.Builder alert = new AlertDialog.Builder(activity); alert.setTitle("Grant Permission in extSdCard"); alert.setMessage("In the following Android dialog, " + "please select the external SD card and confirm at the bottom."); alert.setCancelable(true); alert.setPositiveButton("Yes", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { triggerStorageAccessFramework(INTENT_WRITE_REQUEST_CODE); } }); alert.setNegativeButton("No", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); AlertDialog alertDialog = alert.create(); alertDialog.show(); } } dupTask = new DupFinderTask(MainFragment.this, stringExtra); dupTask.execute(); } else { // RESULT_CANCEL if (selectedFiles.length == 0) { showToast("Nothing to find"); statusView.setText("Nothing to find"); } } } else if (requestCode == INTENT_WRITE_REQUEST_CODE) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { onActivityResultLollipop(requestCode, resultCode, data); } } else if (requestCode == TRANSLATE_REQUEST_CODE) { if (resultCode == Activity.RESULT_OK) { Log.d("TRANSLATE_REQUEST_CODE.selectedFiles", stringExtra[0]); stopReadAndSearch(); currentZipFileName = ""; // lm du kh?i show web getSourceFile selectedFiles = stringExtra; load = "Search"; requestCompare = false; requestTranslate = true; requestSearching = false; getSourceFileTask = new GetSourceFileTask(MainFragment.this); getSourceFileTask.execute(); } else { // RESULT_CANCEL if (selectedFiles.length == 0) { showToast("Nothing to translate"); statusView.setText("Nothing to translate"); } } // } else if (requestCode == REPLACE_REQUEST_CODE) { // if (resultCode == Activity.RESULT_OK) { // Log.d("REPLACE_REQUEST_CODE.selectedFiles", stringExtra[0]); // stopReadAndSearch(); // currentZipFileName = ""; // lm du kh?i show web getSourceFile // selectedFiles = stringExtra; // load = "Search"; // requestCompare = false; // requestTranslate = false; // requestSearching = false; // List<File> lf = FileUtil.getFiles(selectedFiles); // if (includeEnter) { // multiline // new ReplaceAllTask(this, lf, isRegex, caseSensitive, new String[]{replace}, new String[]{by}).execute(); // } else { // String[] replaces = replace.split("\r?\n"); // String[] bys = by.split("\r?\n"); // Log.d("bys.length ", bys.length + "."); // if (replaces.length == bys.length) { // new ReplaceAllTask(this, lf, isRegex, caseSensitive, replaces, bys).execute(); // } else { // showToast("The number of lines of replace and by are not equal"); // } // } // getSourceFileTask = new GetSourceFileTask(MainFragment.this); // getSourceFileTask.execute(); // } else { // RESULT_CANCEL // if (selectedFiles.length == 0) { // showToast("Nothing to translate"); // statusView.setText("Nothing to translate"); // } // } // } else if (requestCode == BATCH_REQUEST_CODE_1) { // if (resultCode == Activity.RESULT_OK) { // selectedFiles = stringExtra; // Log.d("BATCH_REQUEST_CODE_1.selectedFiles", Util.arrayToString(selectedFiles, true, "\n")); // Intent intent = new Intent(activity, FolderChooserActivity.class); // intent.putExtra(SearchFragment.SELECTED_DIR, // selectedFiles); // intent.putExtra(SearchFragment.SUFFIX, ""); // intent.putExtra(SearchFragment.MODE, !MULTI_FILES); // intent.putExtra(SearchFragment.CHOOSER_TITLE, "Output Folder"); // activity.startActivityForResult(intent, BATCH_REQUEST_CODE_2); // } else { // RESULT_CANCEL // if (selectedFiles.length == 0) { // showToast("Nothing to convert"); // statusView.setText("Nothing to convert"); // } // } // } else if (requestCode == BATCH_REQUEST_CODE_2) { // if (resultCode == Activity.RESULT_OK) { // stopReadAndSearch(); // outputFolder = stringExtra[0]; // Log.d("BATCH_REQUEST_CODE_2.outputfolder", outputFolder); // currentZipFileName = ""; // lm du kh?i show web getSourceFile // load = "Convert"; // // Log.i(Prefs.TAG, "onCreate ffmpeg4android ProgressBarExample"); //// demoVideoFolder = Environment.getExternalStorageDirectory().getAbsolutePath() + "/videokit/"; // Log.i(Prefs.TAG, getString(R.string.app_name) + " version: " + GeneralUtils.getVersionName(activity.getApplicationContext()) ); // workFolder = SearchFragment.PRIVATE_PATH + "/"; //activity.getApplicationContext().getFilesDir() + "/"; // Log.i(Prefs.TAG, "workFolder (license and logs location) path: " + workFolder); // vkLogPath = SearchFragment.PRIVATE_PATH + "/vk.log"; // Log.i(Prefs.TAG, "vk log (native log) path: " + vkLogPath); // GeneralUtils.copyLicenseFromAssetsToSDIfNeeded(activity, workFolder); // //GeneralUtils.copyDemoVideoFromAssetsToSDIfNeeded(activity, demoVideoFolder); // int rc = GeneralUtils.isLicenseValid(activity.getApplicationContext(), workFolder); // Log.i(Prefs.TAG, "License check RC: " + rc); // new Thread (new Runnable() { // @Override // public void run() { // List<File> lf = FileUtil.getFiles(selectedFiles); // for (File f : lf) { // Log.i(Prefs.TAG, "f = " + f); // synchronized (command) { // convertingFile = f.getAbsolutePath(); // Log.i(Prefs.TAG, convertingFile + "2=" + convertingFile); // runTranscoding(); // while (!progresssBarFinished) { // try { // Thread.sleep(250); // } catch (InterruptedException e) {} // } // } // } // } // }).start(); // } else { // RESULT_CANCEL // if (selectedFiles.length == 0) { // showToast("Nothing to convert"); // statusView.setText("Nothing to convert"); // } // } } } } catch (Throwable t) { Log.e("onActivityResult", t.getMessage(), t); } Log.d("onActivityResult.load", load + " onActivityResult"); webView.requestFocus(); }
From source file:com.juick.android.MainActivity.java
@Override public boolean onOptionsItemSelected(com.actionbarsherlock.view.MenuItem item) { if (item == null) return true; switch (item.getItemId()) { case R.id.menuitem_preferences: Intent prefsIntent = new Intent(this, NewJuickPreferenceActivity.class); prefsIntent.putExtra("menu", NewJuickPreferenceActivity.Menu.TOP_LEVEL.name()); startActivityForResult(prefsIntent, ACTIVITY_PREFERENCES); return true; case R.id.menuitem_newmessage: if (mf != null) { Intent intent1 = new Intent(this, NewMessageActivity.class); if (mf.messagesSource.getKind().startsWith("combined")) { //Toast.makeText(this, getString(R.string.GoToParticularToPost), Toast.LENGTH_LONG).show(); } else { intent1.putExtra("microblog", mf.messagesSource.getMicroBlog().getCode()); }/*from ww w .j a v a 2s .c om*/ startActivity(intent1); return true; } case R.id.menuitem_search: if (mf != null) { if (mf.messagesSource.getKind().equals("combined")) { Toast.makeText(this, getString(R.string.GoToParticularToSearch), Toast.LENGTH_LONG).show(); } else { Intent intent = new Intent(this, ExploreActivity.class); intent.putExtra("messagesSource", mf.messagesSource); startActivity(intent); } } return true; case R.id.reload: doReload(); return true; case R.id.menuitem_new_saved_sharing_key: new AlertDialog.Builder(this).setTitle("New Access URL generation") .setMessage("Old URL will become onvalid. Continue?") .setPositiveButton("Continue", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { obtainSavedMessagesURL(true); } }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { //To change body of implemented methods use File | Settings | File Templates. } }).setCancelable(true).show(); return true; case R.id.menuitem_existing_saved_sharing_key: obtainSavedMessagesURL(false); return true; case R.id.menuitem_load_colors_theme: startColorsThemeStorageAction(COLORS_THEME_STORAGE_ACTION_LOAD); return true; case R.id.menuitem_save_colors_theme: startColorsThemeStorageAction(COLORS_THEME_STORAGE_ACTION_SAVE); return true; default: return super.onOptionsItemSelected(item); } }
From source file:com.juick.android.MainActivity.java
private void obtainSavedMessagesURL(final boolean reset) { final ProgressDialog pd = new ProgressDialog(MainActivity.this); pd.setIndeterminate(true);/*from w w w .j a va2 s. c o m*/ pd.setTitle("Saved Messages"); pd.setMessage("Waiting for server key"); pd.setCancelable(true); pd.show(); new Thread("obtainSavedMessagesURL") { @Override public void run() { final RESTResponse restResponse = DatabaseService.obtainSharingURL(MainActivity.this, reset); if (restResponse.getErrorText() == null) try { new JSONObject(restResponse.getResult()); } catch (JSONException e) { restResponse.errorText = e.toString(); } runOnUiThread(new Runnable() { @Override public void run() { pd.cancel(); if (restResponse.getErrorText() != null) { Toast.makeText(MainActivity.this, restResponse.getErrorText(), Toast.LENGTH_LONG) .show(); } else { try { final String url = (String) new JSONObject(restResponse.getResult()).get("url"); if (url.length() == 0) { Toast.makeText(MainActivity.this, "You don't have key yet. Choose another option.", Toast.LENGTH_LONG) .show(); } else { new AlertDialog.Builder(MainActivity.this).setTitle("You got key!") .setMessage(url) .setPositiveButton("Ok", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }).setNeutralButton("Share with..", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Intent share = new Intent( android.content.Intent.ACTION_SEND); share.setType("text/plain"); share.addFlags( Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); share.putExtra(Intent.EXTRA_SUBJECT, "My Saved messages on Juick Advanced"); share.putExtra(Intent.EXTRA_TEXT, url); startActivity( Intent.createChooser(share, "Share link")); } }) .setCancelable(true).show(); } } catch (JSONException e) { Toast.makeText(MainActivity.this, e.toString(), Toast.LENGTH_LONG).show(); } } } }); } }.start(); }
From source file:com.free.searcher.MainFragment.java
public boolean preview(MenuItem item) { // final Dialog dialog = new Dialog(CountingFragment.this); // dialog.setContentView(R.layout.preview); // dialog.setTitle("Preview"); ///*ww w .j a va 2 s.c o m*/ // Button okBtn = (Button) dialog.findViewById(R.id.okBtn); // okBtn.setOnClickListener(new OnClickListener() { // // @Override // public void onClick(View v) { // EditText preview = (EditText) dialog.findViewById(R.id.preview); // CountingFragment.this.charsPreview = // Integer.valueOf(preview.getText().toString()); // diaLog.dismiss(); // } // }); // // Button cancelBtn = (Button) dialog.findViewById(R.id.cancelBtn); // cancelBtn.setOnClickListener(new OnClickListener() { // // @Override // public void onClick(View v) { // diaLog.dismiss(); // } // }); // dialog.show(); LayoutInflater factory = LayoutInflater.from(activity); final View textEntryView = factory.inflate(R.layout.preview, null); final EditText preview = (EditText) textEntryView.findViewById(R.id.preview); preview.setText("" + MainActivity.charsPreview); AlertDialog dialog = new AlertDialog.Builder(activity).setIconAttribute(android.R.attr.alertDialogIcon) .setTitle(R.string.charsPreview).setView(textEntryView) .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { try { MainActivity.charsPreview = Integer.valueOf(preview.getText().toString()); } catch (NumberFormatException nfe) { showToast("Invalid number. Keep the old value " + MainActivity.charsPreview); } dialog.dismiss(); } }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.dismiss(); } }).create(); dialog.show(); return true; }
From source file:com.free.searcher.MainFragment.java
public boolean clearCache(MenuItem item) { AlertDialog.Builder alert = new AlertDialog.Builder(activity); alert.setTitle("Clear Caching Files"); long[] entry = new long[] { 0, 0, 0 }; FileUtil.getDirSize(MainFragment.PRIVATE_DIR, entry); alert.setMessage("Cache has " + MainFragment.nf.format(entry[2]) + " folders, " + MainFragment.nf.format(entry[0]) + " files, " + MainFragment.nf.format(entry[1]) + " bytes. " + "\r\nAre you sure you want to clear the cached files? " + "\r\nAfter cleaning searching will be slow for the first times " + "and the searching task maybe incorrect."); alert.setCancelable(true);// w ww.j a va 2 s .c om alert.setNegativeButton("Yes", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Log.d("Cleaning files", FileUtil.deleteFiles(MainFragment.PRIVATE_DIR, MainFragment.LINE_SEP, true, "")); } }); alert.setPositiveButton("No", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); AlertDialog alertDialog = alert.create(); alertDialog.show(); return true; }
From source file:com.free.searcher.MainFragment.java
@Override public boolean onQueryTextSubmit(String query) { currentSearching = query;//w ww . j a v a 2 s. c o m findBox.setText(currentSearching); statusView.setText("Query = '" + query + "' : submitted"); webView.requestFocus(); try { // cha load source files if (query.trim().length() == 0) { status = "Nothing to search. Please type something for searching"; showToast(status.toString()); statusView.setText(status); return true; } Log.d("selectedFiles", selectedFiles + ""); if (selectedFiles == null || selectedFiles.length == 0 || selectedFiles[0].length() == 0) { // (cache == // null && // (!new // File(folderStr).exists())) status = "No file to search. Please select files or folders for searching"; showToast(status.toString()); statusView.setText(status); Log.d("search", "No file to search"); return true; } if (getSourceFileTask == null) { // Zip Reader or Restart app if (currentZipFileName.length() > 0) { // Zip reader AlertDialog.Builder alert = new AlertDialog.Builder(activity); alert.setTitle("Searching files"); alert.setMessage("Do you want to search this file " + currentZipFileName + "?"); alert.setCancelable(true); alert.setNegativeButton("Yes", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { showToast("Start loading files, please wait..."); requestSearching = true; getSourceFileTask = new GetSourceFileTask(MainFragment.this); getSourceFileTask.execute(); } }); alert.setPositiveButton("No", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); AlertDialog alertDialog = alert.create(); alertDialog.show(); } else { // SEARCH Dup Comp showToast("Start loading files, please wait..."); requestSearching = true; getSourceFileTask = new GetSourceFileTask(MainFragment.this); getSourceFileTask.execute(); } } else if (getSourceFileTask.getStatus() == Status.RUNNING || getSourceFileTask.getStatus() == Status.PENDING) { showToast("Still loading files, please wait..."); requestSearching = true; } else if (searchTask == null || searchTask.getStatus() == Status.FINISHED) { // load ri nhng cha chy g searchView(query); } else if (searchTask.getStatus() == Status.RUNNING || searchTask.getStatus() == Status.PENDING) { // load source file nhng ang chy ci khc showToast("Stopping previous seaching, please wait..."); searchTask.cancel(true); searchTask = null; searchView(query); } } catch (Throwable e) { Log.d("onQueryTextSubmit()", e.getMessage(), e); statusView.setText(e.getMessage()); } return true; }
From source file:com.codename1.impl.android.AndroidImplementation.java
@Override public Object showNativePicker(final int type, final Component source, final Object currentValue, final Object data) { if (getActivity() == null) { return null; }//from w w w . ja v a 2s . c o m final boolean[] canceled = new boolean[1]; final boolean[] dismissed = new boolean[1]; if (editInProgress()) { stopEditing(true); } if (type == Display.PICKER_TYPE_TIME) { class TimePick implements TimePickerDialog.OnTimeSetListener, TimePickerDialog.OnCancelListener, Runnable { int result = ((Integer) currentValue).intValue(); public void onTimeSet(TimePicker tp, int hour, int minute) { result = hour * 60 + minute; dismissed[0] = true; synchronized (this) { notify(); } } public void run() { while (!dismissed[0]) { synchronized (this) { try { wait(50); } catch (InterruptedException er) { } } } } @Override public void onCancel(DialogInterface di) { dismissed[0] = true; canceled[0] = true; synchronized (this) { notify(); } } } final TimePick pickInstance = new TimePick(); getActivity().runOnUiThread(new Runnable() { public void run() { int hour = ((Integer) currentValue).intValue() / 60; int minute = ((Integer) currentValue).intValue() % 60; TimePickerDialog tp = new TimePickerDialog(getActivity(), pickInstance, hour, minute, true) { @Override public void cancel() { super.cancel(); dismissed[0] = true; canceled[0] = true; } @Override public void dismiss() { super.dismiss(); dismissed[0] = true; } }; tp.setOnCancelListener(pickInstance); //DateFormat.is24HourFormat(activity)); tp.show(); } }); Display.getInstance().invokeAndBlock(pickInstance); if (canceled[0]) { return null; } return new Integer(pickInstance.result); } if (type == Display.PICKER_TYPE_DATE) { final java.util.Calendar cl = java.util.Calendar.getInstance(); if (currentValue != null) { cl.setTime((Date) currentValue); } class DatePick implements DatePickerDialog.OnDateSetListener, DatePickerDialog.OnCancelListener, Runnable { Date result = (Date) currentValue; public void onDateSet(DatePicker dp, int year, int month, int day) { java.util.Calendar c = java.util.Calendar.getInstance(); c.set(java.util.Calendar.YEAR, year); c.set(java.util.Calendar.MONTH, month); c.set(java.util.Calendar.DAY_OF_MONTH, day); result = c.getTime(); dismissed[0] = true; synchronized (this) { notify(); } } public void run() { while (!dismissed[0]) { synchronized (this) { try { wait(50); } catch (InterruptedException er) { } } } } public void onCancel(DialogInterface di) { result = null; dismissed[0] = true; canceled[0] = true; synchronized (this) { notify(); } } } final DatePick pickInstance = new DatePick(); getActivity().runOnUiThread(new Runnable() { public void run() { DatePickerDialog tp = new DatePickerDialog(getActivity(), pickInstance, cl.get(java.util.Calendar.YEAR), cl.get(java.util.Calendar.MONTH), cl.get(java.util.Calendar.DAY_OF_MONTH)) { @Override public void cancel() { super.cancel(); dismissed[0] = true; canceled[0] = true; } @Override public void dismiss() { super.dismiss(); dismissed[0] = true; } }; tp.setOnCancelListener(pickInstance); tp.show(); } }); Display.getInstance().invokeAndBlock(pickInstance); return pickInstance.result; } if (type == Display.PICKER_TYPE_STRINGS) { final String[] values = (String[]) data; class StringPick implements Runnable, NumberPicker.OnValueChangeListener { int result = -1; StringPick() { } public void run() { while (!dismissed[0]) { synchronized (this) { try { wait(50); } catch (InterruptedException er) { } } } } public void cancel() { dismissed[0] = true; canceled[0] = true; synchronized (this) { notify(); } } public void ok() { canceled[0] = false; dismissed[0] = true; synchronized (this) { notify(); } } @Override public void onValueChange(NumberPicker np, int oldVal, int newVal) { result = newVal; } } final StringPick pickInstance = new StringPick(); for (int iter = 0; iter < values.length; iter++) { if (values[iter].equals(currentValue)) { pickInstance.result = iter; break; } } if (pickInstance.result == -1 && values.length > 0) { // The picker will default to showing the first element anyways // If we don't set the result to 0, then the user has to first // scroll to a different number, then back to the first option // to pick the first option. pickInstance.result = 0; } getActivity().runOnUiThread(new Runnable() { public void run() { NumberPicker picker = new NumberPicker(getActivity()); if (source.getClientProperty("showKeyboard") == null) { picker.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS); } picker.setMinValue(0); picker.setMaxValue(values.length - 1); picker.setDisplayedValues(values); picker.setOnValueChangedListener(pickInstance); if (pickInstance.result > -1) { picker.setValue(pickInstance.result); } RelativeLayout linearLayout = new RelativeLayout(getActivity()); RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(50, 50); RelativeLayout.LayoutParams numPicerParams = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); numPicerParams.addRule(RelativeLayout.CENTER_HORIZONTAL); linearLayout.setLayoutParams(params); linearLayout.addView(picker, numPicerParams); AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getActivity()); alertDialogBuilder.setView(linearLayout); alertDialogBuilder.setCancelable(false) .setPositiveButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { pickInstance.ok(); } }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); pickInstance.cancel(); } }); AlertDialog alertDialog = alertDialogBuilder.create(); alertDialog.show(); } }); Display.getInstance().invokeAndBlock(pickInstance); if (canceled[0]) { return null; } if (pickInstance.result < 0) { return null; } return values[pickInstance.result]; } return null; }