List of usage examples for android.app ProgressDialog setMessage
@Override public void setMessage(CharSequence message)
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 a va2 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:com.slp.rss_api.activity.EditFeedActivity.java
public void onClickOk(View view) { // only in insert mode final String name = mNameEditText.getText().toString().trim(); final String urlOrSearch = mUrlEditText.getText().toString().trim(); if (urlOrSearch.isEmpty()) { Toast.makeText(this, R.string.error_feed_error, Toast.LENGTH_SHORT).show(); }/*from ww w . j ava 2 s. c o m*/ if (!urlOrSearch.contains(".") || !urlOrSearch.contains("/") || urlOrSearch.contains(" ")) { 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) { String encodedSearchText = urlOrSearch; try { encodedSearchText = URLEncoder.encode(urlOrSearch, Constants.UTF8); } catch (UnsupportedEncodingException ignored) { } return new GetFeedSearchResultsLoader(EditFeedActivity.this, encodedSearchText); } @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) { FeedDataContentProvider.addFeed(EditFeedActivity.this, data.get(which).get(FEED_SEARCH_URL), name.isEmpty() ? data.get(which).get(FEED_SEARCH_TITLE) : name, mRetrieveFulltextCb.isChecked()); setResult(RESULT_OK); finish(); } }); builder.show(); } } @Override public void onLoaderReset(Loader<ArrayList<HashMap<String, String>>> loader) { } }); } else { FeedDataContentProvider.addFeed(EditFeedActivity.this, urlOrSearch, name, mRetrieveFulltextCb.isChecked()); setResult(RESULT_OK); finish(); } }
From source file:com.aibasis.parent.ui.entrance.LoginActivity.java
/** * //from w w w. ja v a 2 s .c om * * @param view */ public void login(View view) { if (!CommonUtils.isNetWorkConnected(this)) { Toast.makeText(this, R.string.network_isnot_available, Toast.LENGTH_SHORT).show(); return; } currentUsername = usernameEditText.getText().toString().trim(); currentPassword = passwordEditText.getText().toString().trim(); if (TextUtils.isEmpty(currentUsername)) { Toast.makeText(this, R.string.User_name_cannot_be_empty, Toast.LENGTH_SHORT).show(); return; } if (TextUtils.isEmpty(currentPassword)) { Toast.makeText(this, R.string.Password_cannot_be_empty, Toast.LENGTH_SHORT).show(); return; } progressShow = true; final ProgressDialog pd = new ProgressDialog(LoginActivity.this); pd.setCanceledOnTouchOutside(false); pd.setOnCancelListener(new OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { progressShow = false; } }); pd.setMessage(getString(R.string.Is_landing)); pd.show(); final long start = System.currentTimeMillis(); accountAPI.login(currentUsername, currentPassword, new RequestListener() { @Override public void onComplete(String result) { try { final LoginResult loginResult = LoginResult.parse(result); if (LoginResult.SUCCESS.equals(loginResult.getResult())) { // sdk?? EMChatManager.getInstance().login(loginResult.getEaseId(), loginResult.getEasePassword(), new EMCallBack() { @Override public void onSuccess() { if (!progressShow) { return; } // ????? DemoApplication.getInstance().setUserName(currentUsername); DemoApplication.getInstance().setPassword(currentPassword); DemoApplication.getInstance().setEaseId(loginResult.getEaseId()); DemoApplication.getInstance() .setEasePassword(loginResult.getEasePassword()); DemoApplication.getInstance().setParentId(loginResult.getParentId()); SharePreferenceUtil sharePreferenceUtil = new SharePreferenceUtil( LoginActivity.this); sharePreferenceUtil .setParentId(DemoApplication.getInstance().getParentId()); try { // ** ?logout??? // ** manually load all local groups and EMGroupManager.getInstance().loadAllGroups(); EMChatManager.getInstance().loadAllConversations(); // ?? initializeContacts(); } catch (Exception e) { e.printStackTrace(); // ????? runOnUiThread(new Runnable() { public void run() { pd.dismiss(); DemoHXSDKHelper.getInstance().logout(true, null); Toast.makeText(getApplicationContext(), R.string.login_failure_failed, Toast.LENGTH_SHORT) .show(); } }); return; } // ?nickname ios?nick boolean updatenick = EMChatManager.getInstance() .updateCurrentUserNick(DemoApplication.currentUserNick.trim()); if (!updatenick) { Log.e("LoginActivity", "update current user nick fail"); } if (!LoginActivity.this.isFinishing() && pd.isShowing()) { pd.dismiss(); } // ? Intent intent = new Intent(LoginActivity.this, MainActivity.class); startActivity(intent); finish(); } @Override public void onProgress(int progress, String status) { } @Override public void onError(final int code, final String message) { if (!progressShow) { return; } runOnUiThread(new Runnable() { public void run() { pd.dismiss(); Toast.makeText(getApplicationContext(), getString(R.string.Login_failed) + message, Toast.LENGTH_SHORT).show(); } }); } }); } else if (LoginResult.FAILED.equals(loginResult.getResult())) { { Toast.makeText(getApplicationContext(), getString(R.string.Login_failed), Toast.LENGTH_SHORT).show(); } } } catch (JSONException e) { e.printStackTrace(); } } @Override public void onAPIException(APIException exception) { } }); }
From source file:cn.ucai.superwechat.fragments.ContactlistFragment.java
/** * ?//w w w.j a va2 s .c o m * * @param tobeDeleteUser */ public void deleteContact(final Contact tobeDeleteUser) { String st1 = getResources().getString(cn.ucai.superwechat.R.string.deleting); final String st2 = getResources().getString(cn.ucai.superwechat.R.string.Delete_failed); final ProgressDialog pd = new ProgressDialog(getActivity()); pd.setMessage(st1); pd.setCanceledOnTouchOutside(false); pd.show(); try { String path = new ApiParams() .with(I.Contact.USER_NAME, SuperWeChatApplication.getInstance().getUserName()) .with(I.Contact.CU_NAME, tobeDeleteUser.getMContactCname()) .getRequestUrl(I.REQUEST_DELETE_CONTACT); ((MainActivity) getActivity()).executeRequest(new GsonRequest<Boolean>(path, Boolean.class, responseDeleteContactListener(tobeDeleteUser), ((MainActivity) getActivity()).errorListener())); } catch (Exception e) { e.printStackTrace(); } new Thread(new Runnable() { public void run() { try { EMContactManager.getInstance().deleteContact(tobeDeleteUser.getMContactCname()); // db? EMUserDao dao = new EMUserDao(getActivity()); dao.deleteContact(tobeDeleteUser.getMContactCname()); ((DemoHXSDKHelper) HXSDKHelper.getInstance()).getContactList() .remove(tobeDeleteUser.getMContactCname()); getActivity().runOnUiThread(new Runnable() { public void run() { pd.dismiss(); adapter.remove(tobeDeleteUser); adapter.notifyDataSetChanged(); } }); } catch (final Exception e) { getActivity().runOnUiThread(new Runnable() { public void run() { pd.dismiss(); Toast.makeText(getActivity(), st2 + e.getMessage(), Toast.LENGTH_LONG).show(); } }); } } }).start(); }
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 {//ww w.ja 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:com.mobicage.rogerthat.plugins.messaging.widgets.PhotoUploadWidget.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == Crop.REQUEST_CROP) { handleCrop(resultCode, data);//from ww w .j a va 2 s . c o m } else if (requestCode == PICK_IMAGE) { if (resultCode == Activity.RESULT_OK) { if (data != null && data.getData() != null) { if (mRatio == null) { final Uri selectedImage = data.getData(); final ProgressDialog progressDialog = new ProgressDialog(mActivity); progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); progressDialog.setMessage(mActivity.getString(R.string.processing)); progressDialog.setCancelable(false); progressDialog.show(); new SafeAsyncTask<Object, Object, Boolean>() { @Override protected Boolean safeDoInBackground(Object... params) { L.d("Processing picture: " + selectedImage.getPath()); try { File tmpUploadFile = getTmpUploadPhotoLocation(); if (tmpUploadFile.getAbsolutePath().equals(selectedImage.getPath())) { return true; } else { InputStream is = mActivity.getContentResolver() .openInputStream(selectedImage); if (is != null) { try { OutputStream out = new FileOutputStream(tmpUploadFile); try { IOUtils.copy(is, out, 1024); } finally { out.close(); } } finally { is.close(); } return true; } } } catch (FileNotFoundException e) { L.d(e); } catch (Exception e) { L.bug("Unknown exception occured while processing picture: " + selectedImage.toString(), e); } return false; }; @Override protected void safeOnPostExecute(Boolean result) { progressDialog.dismiss(); if (result) { handleSelection(); } else { UIUtils.showLongToast(getContext(), R.string.crop__pick_error); } } @Override protected void safeOnCancelled(Boolean result) { } @Override protected void safeOnProgressUpdate(Object... values) { } @Override protected void safeOnPreExecute() { }; }.execute(); } else { beginCrop(data.getData()); return; } } else { if (mRatio == null) { handleSelection(); } else { beginCrop(mUriSavedImage); } } } } else { L.bug("Unexpected request code in onActivityResult: " + requestCode); } }
From source file:com.kkbox.toolkit.dialog.KKDialog.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { DialogInterface.OnClickListener positiveListener = new DialogInterface.OnClickListener() { @Override/*from w ww . j av a 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:org.exobel.routerkeygen.ui.Preferences.java
protected Dialog onCreateDialog(int id) { AlertDialog.Builder builder = new Builder(this); switch (id) { case DIALOG_ABOUT: { LayoutInflater inflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE); View layout = inflater.inflate(R.layout.about_dialog, (ViewGroup) findViewById(R.id.tabhost)); TabHost tabs = (TabHost) layout.findViewById(R.id.tabhost); tabs.setup();/*from w w w . j a v a 2 s . c om*/ TabSpec tspec1 = tabs.newTabSpec("about"); tspec1.setIndicator(getString(R.string.pref_about)); tspec1.setContent(R.id.text_about_scroll); TextView text = ((TextView) layout.findViewById(R.id.text_about)); text.setMovementMethod(LinkMovementMethod.getInstance()); text.append(VERSION + "\n" + LAUNCH_DATE); tabs.addTab(tspec1); TabSpec tspec2 = tabs.newTabSpec("credits"); tspec2.setIndicator(getString(R.string.dialog_about_credits)); tspec2.setContent(R.id.about_credits_scroll); ((TextView) layout.findViewById(R.id.about_credits)) .setMovementMethod(LinkMovementMethod.getInstance()); tabs.addTab(tspec2); TabSpec tspec3 = tabs.newTabSpec("license"); tspec3.setIndicator(getString(R.string.dialog_about_license)); tspec3.setContent(R.id.about_license_scroll); ((TextView) layout.findViewById(R.id.about_license)) .setMovementMethod(LinkMovementMethod.getInstance()); tabs.addTab(tspec3); builder.setNeutralButton(R.string.bt_close, new OnClickListener() { public void onClick(DialogInterface dialog, int which) { removeDialog(DIALOG_ABOUT); } }); builder.setView(layout); break; } case DIALOG_ASK_DOWNLOAD: { DialogInterface.OnClickListener diOnClickListener = new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // Check if we have the latest dictionary version. try { checkCurrentDictionary(); } catch (Exception e) { e.printStackTrace(); } } }; builder.setTitle(R.string.pref_download); builder.setMessage(R.string.msg_dicislarge); builder.setCancelable(false); builder.setPositiveButton(android.R.string.yes, diOnClickListener); builder.setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { removeDialog(DIALOG_ASK_DOWNLOAD); } }); break; } case DIALOG_UPDATE_NEEDED: { builder.setTitle(R.string.update_title) .setMessage(getString(R.string.update_message, lastVersion.version)) .setNegativeButton(R.string.bt_close, new OnClickListener() { public void onClick(DialogInterface dialog, int which) { removeDialog(DIALOG_UPDATE_NEEDED); } }).setPositiveButton(R.string.bt_website, new OnClickListener() { public void onClick(DialogInterface dialog, int which) { startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse(lastVersion.url))); } }); break; } case DIALOG_WAIT: { ProgressDialog pbarDialog = new ProgressDialog(Preferences.this); pbarDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); pbarDialog.setMessage(getString(R.string.msg_wait)); return pbarDialog; } case DIALOG_ERROR_TOO_ADVANCED: { builder.setTitle(R.string.msg_error).setMessage(R.string.msg_err_online_too_adv); break; } case DIALOG_ERROR: { builder.setTitle(R.string.msg_error).setMessage(R.string.msg_err_unkown); break; } case DIALOG_CHANGELOG: { LayoutInflater layoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); ChangeLogListView chgList = (ChangeLogListView) layoutInflater.inflate(R.layout.dialog_changelog, (ViewGroup) this.getWindow().getDecorView().getRootView(), false); builder.setTitle(R.string.pref_changelog).setView(chgList).setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.dismiss(); } }); break; } } return builder.create(); }
From source file:nl.privacybarometer.privacyvandaag.activity.EditFeedActivity.java
public void onClickOk(View view) { // only in insert mode final String name = mNameEditText.getText().toString().trim(); final String urlOrSearch = mUrlEditText.getText().toString().trim(); final String cookieName = mCookieNameEditText.getText().toString(); final String cookieValue = mCookieValueEditText.getText().toString(); final TypedArray selectedValues = getResources().obtainTypedArray(R.array.settings_keep_time_values); final Integer keepTime = selectedValues.getInt(mKeepTime.getSelectedItemPosition(), 0); final String iconDrawable = ""; if (urlOrSearch.isEmpty()) { Toast.makeText(this, R.string.error_feed_error, Toast.LENGTH_SHORT).show(); }/*from w w w . j a va2 s .c o m*/ if (!urlOrSearch.contains(".") || !urlOrSearch.contains("/") || urlOrSearch.contains(" ")) { 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) { String encodedSearchText = urlOrSearch; try { encodedSearchText = URLEncoder.encode(urlOrSearch, Constants.UTF8); } catch (UnsupportedEncodingException ignored) { } return new GetFeedSearchResultsLoader(EditFeedActivity.this, encodedSearchText); } @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) { FeedDataContentProvider.addFeed(EditFeedActivity.this, data.get(which).get(FEED_SEARCH_URL), name.isEmpty() ? data.get(which).get(FEED_SEARCH_TITLE) : name, mRetrieveFulltextCb.isChecked(), cookieName, cookieValue, keepTime, iconDrawable); setResult(RESULT_OK); finish(); } }); builder.show(); } } @Override public void onLoaderReset(Loader<ArrayList<HashMap<String, String>>> loader) { } }); } else { FeedDataContentProvider.addFeed(EditFeedActivity.this, urlOrSearch, name, mRetrieveFulltextCb.isChecked(), cookieName, cookieValue, keepTime, iconDrawable); setResult(RESULT_OK); finish(); } }
From source file:net.fred.feedex.activity.EditFeedActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: finish();/*w w w . java 2 s . co m*/ return true; case R.id.menu_validate: // only in insert mode final String name = mNameEditText.getText().toString().trim(); final String urlOrSearch = mUrlEditText.getText().toString().trim(); if (urlOrSearch.isEmpty()) { UiUtils.showMessage(EditFeedActivity.this, R.string.error_feed_error); } if (!urlOrSearch.contains(".") || !urlOrSearch.contains("/") || urlOrSearch.contains(" ")) { 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) { String encodedSearchText = urlOrSearch; try { encodedSearchText = URLEncoder.encode(urlOrSearch, Constants.UTF8); } catch (UnsupportedEncodingException ignored) { } return new GetFeedSearchResultsLoader(EditFeedActivity.this, encodedSearchText); } @Override public void onLoadFinished(Loader<ArrayList<HashMap<String, String>>> loader, final ArrayList<HashMap<String, String>> data) { pd.cancel(); if (data == null) { UiUtils.showMessage(EditFeedActivity.this, R.string.error); } else if (data.isEmpty()) { UiUtils.showMessage(EditFeedActivity.this, R.string.no_result); } 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) { FeedDataContentProvider.addFeed(EditFeedActivity.this, data.get(which).get(FEED_SEARCH_URL), name.isEmpty() ? data.get(which).get(FEED_SEARCH_TITLE) : name, mRetrieveFulltextCb.isChecked()); setResult(RESULT_OK); finish(); } }); builder.show(); } } @Override public void onLoaderReset(Loader<ArrayList<HashMap<String, String>>> loader) { } }); } else { FeedDataContentProvider.addFeed(EditFeedActivity.this, urlOrSearch, name, mRetrieveFulltextCb.isChecked()); setResult(RESULT_OK); finish(); } 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; } default: return super.onOptionsItemSelected(item); } }