List of usage examples for android.app ProgressDialog setCancelable
public void setCancelable(boolean flag)
From source file:com.android.mms.ui.ComposeMessageActivity.java
private void processPickResult(final Intent data) { // The EXTRA_PHONE_URIS stores the phone's urls that were selected by user in the // multiple phone picker. final Parcelable[] uris = data.getParcelableArrayExtra(Intents.EXTRA_PHONE_URIS); final int recipientCount = uris != null ? uris.length : 0; final int recipientLimit = MmsConfig.getRecipientLimit(); if (recipientLimit != Integer.MAX_VALUE && recipientCount > recipientLimit) { new AlertDialog.Builder(this) .setMessage(getString(R.string.too_many_recipients, recipientCount, recipientLimit)) .setPositiveButton(android.R.string.ok, null).create().show(); return;//w w w . j a v a2 s . co m } final Handler handler = new Handler(); final ProgressDialog progressDialog = new ProgressDialog(this); progressDialog.setTitle(getText(R.string.pick_too_many_recipients)); progressDialog.setMessage(getText(R.string.adding_recipients)); progressDialog.setIndeterminate(true); progressDialog.setCancelable(false); final Runnable showProgress = new Runnable() { @Override public void run() { progressDialog.show(); } }; // Only show the progress dialog if we can not finish off parsing the return data in 1s, // otherwise the dialog could flicker. handler.postDelayed(showProgress, 1000); new Thread(new Runnable() { @Override public void run() { final ContactList list; try { list = ContactList.blockingGetByUris(uris); } finally { handler.removeCallbacks(showProgress); progressDialog.dismiss(); } // TODO: there is already code to update the contact header widget and recipients // editor if the contacts change. we can re-use that code. final Runnable populateWorker = new Runnable() { @Override public void run() { mRecipientsEditor.populate(list); updateTitle(list); } }; handler.post(populateWorker); } }, "ComoseMessageActivity.processPickResult").start(); }
From source file:org.telegram.messenger.MessagesController.java
public void startSecretChat(final Context context, final TLRPC.User user) { if (user == null) { return;/*from ww w . j av a2s . c o m*/ } final ProgressDialog progressDialog = new ProgressDialog(context); progressDialog.setMessage(context.getString(R.string.Loading)); progressDialog.setCanceledOnTouchOutside(false); progressDialog.setCancelable(false); progressDialog.show(); TLRPC.TL_messages_getDhConfig req = new TLRPC.TL_messages_getDhConfig(); req.random_length = 256; req.version = MessagesStorage.lastSecretVersion; ConnectionsManager.Instance.performRpc(req, new RPCRequest.RPCRequestDelegate() { @Override public void run(TLObject response, TLRPC.TL_error error) { if (error == null) { TLRPC.messages_DhConfig res = (TLRPC.messages_DhConfig) response; if (response instanceof TLRPC.TL_messages_dhConfig) { if (!Utilities.isGoodPrime(res.p, res.g)) { Utilities.RunOnUIThread(new Runnable() { @Override public void run() { try { if (!((ActionBarActivity) context).isFinishing()) { progressDialog.dismiss(); } } catch (Exception e) { FileLog.e("tmessages", e); } } }); return; } MessagesStorage.secretPBytes = res.p; MessagesStorage.secretG = res.g; MessagesStorage.lastSecretVersion = res.version; MessagesStorage.Instance.saveSecretParams(MessagesStorage.lastSecretVersion, MessagesStorage.secretG, MessagesStorage.secretPBytes); } final byte[] salt = new byte[256]; for (int a = 0; a < 256; a++) { salt[a] = (byte) ((byte) (random.nextDouble() * 256) ^ res.random[a]); } BigInteger i_g_a = BigInteger.valueOf(MessagesStorage.secretG); i_g_a = i_g_a.modPow(new BigInteger(1, salt), new BigInteger(1, MessagesStorage.secretPBytes)); byte[] g_a = i_g_a.toByteArray(); if (g_a.length > 256) { byte[] correctedAuth = new byte[256]; System.arraycopy(g_a, 1, correctedAuth, 0, 256); g_a = correctedAuth; } TLRPC.TL_messages_requestEncryption req2 = new TLRPC.TL_messages_requestEncryption(); req2.g_a = g_a; req2.user_id = getInputUser(user); req2.random_id = (int) (random.nextDouble() * Integer.MAX_VALUE); ConnectionsManager.Instance.performRpc(req2, new RPCRequest.RPCRequestDelegate() { @Override public void run(final TLObject response, TLRPC.TL_error error) { if (error == null) { Utilities.RunOnUIThread(new Runnable() { @Override public void run() { if (!((ActionBarActivity) context).isFinishing()) { try { progressDialog.dismiss(); } catch (Exception e) { FileLog.e("tmessages", e); } } TLRPC.EncryptedChat chat = (TLRPC.EncryptedChat) response; chat.user_id = chat.participant_id; encryptedChats.put(chat.id, chat); chat.a_or_b = salt; TLRPC.TL_dialog dialog = new TLRPC.TL_dialog(); dialog.id = ((long) chat.id) << 32; dialog.unread_count = 0; dialog.top_message = 0; dialog.last_message_date = ConnectionsManager.Instance.getCurrentTime(); dialogs_dict.put(dialog.id, dialog); dialogs.add(dialog); dialogsServerOnly.clear(); Collections.sort(dialogs, new Comparator<TLRPC.TL_dialog>() { @Override public int compare(TLRPC.TL_dialog tl_dialog, TLRPC.TL_dialog tl_dialog2) { if (tl_dialog.last_message_date == tl_dialog2.last_message_date) { return 0; } else if (tl_dialog.last_message_date < tl_dialog2.last_message_date) { return 1; } else { return -1; } } }); for (TLRPC.TL_dialog d : dialogs) { if ((int) d.id != 0) { dialogsServerOnly.add(d); } } NotificationCenter.Instance.postNotificationName(dialogsNeedReload); MessagesStorage.Instance.putEncryptedChat(chat, user, dialog); NotificationCenter.Instance.postNotificationName(encryptedChatCreated, chat); } }); } else { Utilities.RunOnUIThread(new Runnable() { @Override public void run() { if (!((ActionBarActivity) context).isFinishing()) { try { progressDialog.dismiss(); } catch (Exception e) { FileLog.e("tmessages", e); } AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setTitle(context.getString(R.string.AppName)); builder.setMessage(String.format( context.getString(R.string.CreateEncryptedChatOutdatedError), user.first_name, user.first_name)); builder.setPositiveButton( ApplicationLoader.applicationContext.getString(R.string.OK), null); builder.show().setCanceledOnTouchOutside(true); } } }); } } }, null, true, RPCRequest.RPCRequestClassGeneric | RPCRequest.RPCRequestClassFailOnServerErrors); } else { Utilities.RunOnUIThread(new Runnable() { @Override public void run() { if (!((ActionBarActivity) context).isFinishing()) { try { progressDialog.dismiss(); } catch (Exception e) { FileLog.e("tmessages", e); } } } }); } } }, null, true, RPCRequest.RPCRequestClassGeneric | RPCRequest.RPCRequestClassFailOnServerErrors); }
From source file:com.andrewshu.android.reddit.profile.ProfileActivity.java
@Override protected Dialog onCreateDialog(int id) { Dialog dialog;/*ww w . ja va 2 s . com*/ ProgressDialog pdialog; AlertDialog.Builder builder; LayoutInflater inflater; View layout; // used for inflated views for AlertDialog.Builder.setView() switch (id) { case Constants.DIALOG_LOGIN: dialog = new LoginDialog(this, mSettings, false) { @Override public void onLoginChosen(String user, String password) { dismissDialog(Constants.DIALOG_LOGIN); new MyLoginTask(user, password).execute(); } }; break; case Constants.DIALOG_COMPOSE: inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); builder = new AlertDialog.Builder(this); layout = inflater.inflate(R.layout.compose_dialog, null); final EditText composeDestination = (EditText) layout.findViewById(R.id.compose_destination_input); final EditText composeSubject = (EditText) layout.findViewById(R.id.compose_subject_input); final EditText composeText = (EditText) layout.findViewById(R.id.compose_text_input); final Button composeSendButton = (Button) layout.findViewById(R.id.compose_send_button); final Button composeCancelButton = (Button) layout.findViewById(R.id.compose_cancel_button); final EditText composeCaptcha = (EditText) layout.findViewById(R.id.compose_captcha_input); composeDestination.setText(mUsername); dialog = builder.setView(layout).create(); final Dialog composeDialog = dialog; composeSendButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { ThingInfo hi = new ThingInfo(); // reddit.com performs these sanity checks too. if ("".equals(composeDestination.getText().toString().trim())) { Toast.makeText(ProfileActivity.this, "please enter a username", Toast.LENGTH_LONG).show(); return; } if ("".equals(composeSubject.getText().toString().trim())) { Toast.makeText(ProfileActivity.this, "please enter a subject", Toast.LENGTH_LONG).show(); return; } if ("".equals(composeText.getText().toString().trim())) { Toast.makeText(ProfileActivity.this, "you need to enter a message", Toast.LENGTH_LONG) .show(); return; } if (composeCaptcha.getVisibility() == View.VISIBLE && "".equals(composeCaptcha.getText().toString().trim())) { Toast.makeText(ProfileActivity.this, "", Toast.LENGTH_LONG).show(); return; } hi.setDest(composeDestination.getText().toString().trim()); hi.setSubject(composeSubject.getText().toString().trim()); new MyMessageComposeTask(composeDialog, hi, composeCaptcha.getText().toString().trim()) .execute(composeText.getText().toString().trim()); dismissDialog(Constants.DIALOG_COMPOSE); } }); composeCancelButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { dismissDialog(Constants.DIALOG_COMPOSE); } }); break; case Constants.DIALOG_THREAD_CLICK: inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); builder = new AlertDialog.Builder(this); dialog = builder.setView(inflater.inflate(R.layout.thread_click_dialog, null)).create(); break; // "Please wait" case Constants.DIALOG_LOGGING_IN: pdialog = new ProgressDialog(this); pdialog.setMessage("Logging in..."); pdialog.setIndeterminate(true); pdialog.setCancelable(false); dialog = pdialog; break; case Constants.DIALOG_REPLYING: pdialog = new ProgressDialog(this); pdialog.setMessage("Sending reply..."); pdialog.setIndeterminate(true); pdialog.setCancelable(false); dialog = pdialog; break; case Constants.DIALOG_COMPOSING: pdialog = new ProgressDialog(this); pdialog.setMessage("Composing message..."); pdialog.setIndeterminate(true); pdialog.setCancelable(false); dialog = pdialog; break; default: throw new IllegalArgumentException("Unexpected dialog id " + id); } return dialog; }
From source file:com.piusvelte.sonet.core.SelectFriends.java
protected void loadFriends() { mFriends.clear();/*from ww w . j a v a2 s . c o m*/ // SimpleAdapter sa = new SimpleAdapter(SelectFriends.this, mFriends, R.layout.friend, new String[]{Entities.PROFILE, Entities.FRIEND, Entities.ESID}, new int[]{R.id.profile, R.id.name, R.id.selected}); SimpleAdapter sa = new SimpleAdapter(SelectFriends.this, mFriends, R.layout.friend, new String[] { Entities.FRIEND, Entities.ESID }, new int[] { R.id.name, R.id.selected }); setListAdapter(sa); final ProgressDialog loadingDialog = new ProgressDialog(this); final AsyncTask<Long, String, Boolean> asyncTask = new AsyncTask<Long, String, Boolean>() { @Override protected Boolean doInBackground(Long... params) { boolean loadList = false; SonetCrypto sonetCrypto = SonetCrypto.getInstance(getApplicationContext()); // load the session Cursor account = getContentResolver().query(Accounts.getContentUri(SelectFriends.this), new String[] { Accounts.TOKEN, Accounts.SECRET, Accounts.SERVICE }, Accounts._ID + "=?", new String[] { Long.toString(params[0]) }, null); if (account.moveToFirst()) { mToken = sonetCrypto.Decrypt(account.getString(0)); mSecret = sonetCrypto.Decrypt(account.getString(1)); mService = account.getInt(2); } account.close(); String response; switch (mService) { case TWITTER: break; case FACEBOOK: if ((response = SonetHttpClient.httpResponse(mHttpClient, new HttpGet( String.format(FACEBOOK_FRIENDS, FACEBOOK_BASE_URL, Saccess_token, mToken)))) != null) { try { JSONArray friends = new JSONObject(response).getJSONArray(Sdata); for (int i = 0, l = friends.length(); i < l; i++) { JSONObject f = friends.getJSONObject(i); HashMap<String, String> newFriend = new HashMap<String, String>(); newFriend.put(Entities.ESID, f.getString(Sid)); newFriend.put(Entities.PROFILE, String.format(FACEBOOK_PICTURE, f.getString(Sid))); newFriend.put(Entities.FRIEND, f.getString(Sname)); // need to alphabetize if (mFriends.isEmpty()) mFriends.add(newFriend); else { String fullName = f.getString(Sname); int spaceIdx = fullName.lastIndexOf(" "); String newFirstName = null; String newLastName = null; if (spaceIdx == -1) newFirstName = fullName; else { newFirstName = fullName.substring(0, spaceIdx++); newLastName = fullName.substring(spaceIdx); } List<HashMap<String, String>> newFriends = new ArrayList<HashMap<String, String>>(); for (int i2 = 0, l2 = mFriends.size(); i2 < l2; i2++) { HashMap<String, String> oldFriend = mFriends.get(i2); if (newFriend == null) { newFriends.add(oldFriend); } else { fullName = oldFriend.get(Entities.FRIEND); spaceIdx = fullName.lastIndexOf(" "); String oldFirstName = null; String oldLastName = null; if (spaceIdx == -1) oldFirstName = fullName; else { oldFirstName = fullName.substring(0, spaceIdx++); oldLastName = fullName.substring(spaceIdx); } if (newFirstName == null) { newFriends.add(newFriend); newFriend = null; } else { int comparison = oldFirstName.compareToIgnoreCase(newFirstName); if (comparison == 0) { // compare firstnames if (newLastName == null) { newFriends.add(newFriend); newFriend = null; } else if (oldLastName != null) { comparison = oldLastName.compareToIgnoreCase(newLastName); if (comparison == 0) { newFriends.add(newFriend); newFriend = null; } else if (comparison > 0) { newFriends.add(newFriend); newFriend = null; } } } else if (comparison > 0) { newFriends.add(newFriend); newFriend = null; } } newFriends.add(oldFriend); } } if (newFriend != null) newFriends.add(newFriend); mFriends = newFriends; } } loadList = true; } catch (JSONException e) { Log.e(TAG, e.toString()); } } break; case MYSPACE: break; case LINKEDIN: break; case FOURSQUARE: break; case IDENTICA: break; case GOOGLEPLUS: break; case CHATTER: break; } return loadList; } @Override protected void onPostExecute(Boolean loadList) { if (loadList) { // SimpleAdapter sa = new SimpleAdapter(SelectFriends.this, mFriends, R.layout.friend, new String[]{Entities.PROFILE, Entities.FRIEND}, new int[]{R.id.profile, R.id.name}); SimpleAdapter sa = new SimpleAdapter(SelectFriends.this, mFriends, R.layout.friend, new String[] { Entities.FRIEND, Entities.ESID }, new int[] { R.id.name, R.id.selected }); sa.setViewBinder(mViewBinder); setListAdapter(sa); } if (loadingDialog.isShowing()) loadingDialog.dismiss(); } }; loadingDialog.setMessage(getString(R.string.loading)); loadingDialog.setCancelable(true); loadingDialog.setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { if (!asyncTask.isCancelled()) asyncTask.cancel(true); } }); loadingDialog.setButton(ProgressDialog.BUTTON_NEGATIVE, getString(android.R.string.cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); loadingDialog.show(); asyncTask.execute(mAccountId); }
From source file:com.shafiq.myfeedle.core.SelectFriends.java
protected void loadFriends() { mFriends.clear();// www. j a v a 2s . c om // SimpleAdapter sa = new SimpleAdapter(SelectFriends.this, mFriends, R.layout.friend, new String[]{Entities.PROFILE, Entities.FRIEND, Entities.ESID}, new int[]{R.id.profile, R.id.name, R.id.selected}); SimpleAdapter sa = new SimpleAdapter(SelectFriends.this, mFriends, R.layout.friend, new String[] { Entities.FRIEND, Entities.ESID }, new int[] { R.id.name, R.id.selected }); setListAdapter(sa); final ProgressDialog loadingDialog = new ProgressDialog(this); final AsyncTask<Long, String, Boolean> asyncTask = new AsyncTask<Long, String, Boolean>() { @Override protected Boolean doInBackground(Long... params) { boolean loadList = false; MyfeedleCrypto myfeedleCrypto = MyfeedleCrypto.getInstance(getApplicationContext()); // load the session Cursor account = getContentResolver().query(Accounts.getContentUri(SelectFriends.this), new String[] { Accounts.TOKEN, Accounts.SECRET, Accounts.SERVICE }, Accounts._ID + "=?", new String[] { Long.toString(params[0]) }, null); if (account.moveToFirst()) { mToken = myfeedleCrypto.Decrypt(account.getString(0)); mSecret = myfeedleCrypto.Decrypt(account.getString(1)); mService = account.getInt(2); } account.close(); String response; switch (mService) { case TWITTER: break; case FACEBOOK: if ((response = MyfeedleHttpClient.httpResponse(mHttpClient, new HttpGet( String.format(FACEBOOK_FRIENDS, FACEBOOK_BASE_URL, Saccess_token, mToken)))) != null) { try { JSONArray friends = new JSONObject(response).getJSONArray(Sdata); for (int i = 0, l = friends.length(); i < l; i++) { JSONObject f = friends.getJSONObject(i); HashMap<String, String> newFriend = new HashMap<String, String>(); newFriend.put(Entities.ESID, f.getString(Sid)); newFriend.put(Entities.PROFILE, String.format(FACEBOOK_PICTURE, f.getString(Sid))); newFriend.put(Entities.FRIEND, f.getString(Sname)); // need to alphabetize if (mFriends.isEmpty()) mFriends.add(newFriend); else { String fullName = f.getString(Sname); int spaceIdx = fullName.lastIndexOf(" "); String newFirstName = null; String newLastName = null; if (spaceIdx == -1) newFirstName = fullName; else { newFirstName = fullName.substring(0, spaceIdx++); newLastName = fullName.substring(spaceIdx); } List<HashMap<String, String>> newFriends = new ArrayList<HashMap<String, String>>(); for (int i2 = 0, l2 = mFriends.size(); i2 < l2; i2++) { HashMap<String, String> oldFriend = mFriends.get(i2); if (newFriend == null) { newFriends.add(oldFriend); } else { fullName = oldFriend.get(Entities.FRIEND); spaceIdx = fullName.lastIndexOf(" "); String oldFirstName = null; String oldLastName = null; if (spaceIdx == -1) oldFirstName = fullName; else { oldFirstName = fullName.substring(0, spaceIdx++); oldLastName = fullName.substring(spaceIdx); } if (newFirstName == null) { newFriends.add(newFriend); newFriend = null; } else { int comparison = oldFirstName.compareToIgnoreCase(newFirstName); if (comparison == 0) { // compare firstnames if (newLastName == null) { newFriends.add(newFriend); newFriend = null; } else if (oldLastName != null) { comparison = oldLastName.compareToIgnoreCase(newLastName); if (comparison == 0) { newFriends.add(newFriend); newFriend = null; } else if (comparison > 0) { newFriends.add(newFriend); newFriend = null; } } } else if (comparison > 0) { newFriends.add(newFriend); newFriend = null; } } newFriends.add(oldFriend); } } if (newFriend != null) newFriends.add(newFriend); mFriends = newFriends; } } loadList = true; } catch (JSONException e) { Log.e(TAG, e.toString()); } } break; case MYSPACE: break; case LINKEDIN: break; case FOURSQUARE: break; case IDENTICA: break; case GOOGLEPLUS: break; case CHATTER: break; } return loadList; } @Override protected void onPostExecute(Boolean loadList) { if (loadList) { // SimpleAdapter sa = new SimpleAdapter(SelectFriends.this, mFriends, R.layout.friend, new String[]{Entities.PROFILE, Entities.FRIEND}, new int[]{R.id.profile, R.id.name}); SimpleAdapter sa = new SimpleAdapter(SelectFriends.this, mFriends, R.layout.friend, new String[] { Entities.FRIEND, Entities.ESID }, new int[] { R.id.name, R.id.selected }); sa.setViewBinder(mViewBinder); setListAdapter(sa); } if (loadingDialog.isShowing()) loadingDialog.dismiss(); } }; loadingDialog.setMessage(getString(R.string.loading)); loadingDialog.setCancelable(true); loadingDialog.setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { if (!asyncTask.isCancelled()) asyncTask.cancel(true); } }); loadingDialog.setButton(ProgressDialog.BUTTON_NEGATIVE, getString(android.R.string.cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); loadingDialog.show(); asyncTask.execute(mAccountId); }
From source file:com.andrewshu.android.reddit.comments.CommentsListActivity.java
@Override protected Dialog onCreateDialog(int id) { final Dialog dialog; ProgressDialog pdialog; AlertDialog.Builder builder;// w w w. j a v a 2 s.co m LayoutInflater inflater; switch (id) { case Constants.DIALOG_LOGIN: dialog = new LoginDialog(this, mSettings, false) { @Override public void onLoginChosen(String user, String password) { removeDialog(Constants.DIALOG_LOGIN); new MyLoginTask(user, password).execute(); } }; break; case Constants.DIALOG_COMMENT_CLICK: dialog = new CommentClickDialog(this, mSettings); break; case Constants.DIALOG_REPLY: { dialog = new Dialog(this, mSettings.getDialogTheme()); dialog.setContentView(R.layout.compose_reply_dialog); final EditText replyBody = (EditText) dialog.findViewById(R.id.body); final Button replySaveButton = (Button) dialog.findViewById(R.id.reply_save_button); final Button replyCancelButton = (Button) dialog.findViewById(R.id.reply_cancel_button); replySaveButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (mReplyTargetName != null) { new CommentReplyTask(mReplyTargetName).execute(replyBody.getText().toString()); dialog.dismiss(); } else { Common.showErrorToast("Error replying. Please try again.", Toast.LENGTH_SHORT, CommentsListActivity.this); } } }); replyCancelButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { mVoteTargetThing.setReplyDraft(replyBody.getText().toString()); dialog.cancel(); } }); dialog.setCancelable(false); // disallow the BACK key dialog.setOnCancelListener(new DialogInterface.OnCancelListener() { public void onCancel(DialogInterface dialog) { replyBody.setText(""); } }); break; } case Constants.DIALOG_EDIT: { dialog = new Dialog(this, mSettings.getDialogTheme()); dialog.setContentView(R.layout.compose_reply_dialog); final EditText replyBody = (EditText) dialog.findViewById(R.id.body); final Button replySaveButton = (Button) dialog.findViewById(R.id.reply_save_button); final Button replyCancelButton = (Button) dialog.findViewById(R.id.reply_cancel_button); replyBody.setText(mEditTargetBody); replySaveButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { if (mReplyTargetName != null) { new EditTask(mReplyTargetName).execute(replyBody.getText().toString()); dialog.dismiss(); } else { Common.showErrorToast("Error editing. Please try again.", Toast.LENGTH_SHORT, CommentsListActivity.this); } } }); replyCancelButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { dialog.cancel(); } }); dialog.setOnCancelListener(new DialogInterface.OnCancelListener() { public void onCancel(DialogInterface dialog) { replyBody.setText(""); } }); break; } case Constants.DIALOG_DELETE: builder = new AlertDialog.Builder(new ContextThemeWrapper(this, mSettings.getDialogTheme())); builder.setTitle("Really delete this?"); builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { removeDialog(Constants.DIALOG_DELETE); new DeleteTask(mDeleteTargetKind).execute(mReplyTargetName); } }).setNegativeButton("No", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); dialog = builder.create(); break; case Constants.DIALOG_SORT_BY: builder = new AlertDialog.Builder(new ContextThemeWrapper(this, mSettings.getDialogTheme())); builder.setTitle("Sort by:"); int selectedSortBy = -1; for (int i = 0; i < Constants.CommentsSort.SORT_BY_URL_CHOICES.length; i++) { if (Constants.CommentsSort.SORT_BY_URL_CHOICES[i].equals(mSettings.getCommentsSortByUrl())) { selectedSortBy = i; break; } } builder.setSingleChoiceItems(Constants.CommentsSort.SORT_BY_CHOICES, selectedSortBy, sortByOnClickListener); dialog = builder.create(); break; case Constants.DIALOG_REPORT: builder = new AlertDialog.Builder(new ContextThemeWrapper(this, mSettings.getDialogTheme())); builder.setTitle("Really report this?"); builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { removeDialog(Constants.DIALOG_REPORT); new ReportTask(mReportTargetName.toString()).execute(); } }).setNegativeButton("No", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); dialog = builder.create(); break; // "Please wait" case Constants.DIALOG_DELETING: pdialog = new ProgressDialog(new ContextThemeWrapper(this, mSettings.getDialogTheme())); pdialog.setMessage("Deleting..."); pdialog.setIndeterminate(true); pdialog.setCancelable(true); dialog = pdialog; break; case Constants.DIALOG_EDITING: pdialog = new ProgressDialog(new ContextThemeWrapper(this, mSettings.getDialogTheme())); pdialog.setMessage("Submitting edit..."); pdialog.setIndeterminate(true); pdialog.setCancelable(true); dialog = pdialog; break; case Constants.DIALOG_LOGGING_IN: pdialog = new ProgressDialog(new ContextThemeWrapper(this, mSettings.getDialogTheme())); pdialog.setMessage("Logging in..."); pdialog.setIndeterminate(true); pdialog.setCancelable(true); dialog = pdialog; break; case Constants.DIALOG_REPLYING: pdialog = new ProgressDialog(new ContextThemeWrapper(this, mSettings.getDialogTheme())); pdialog.setMessage("Sending reply..."); pdialog.setIndeterminate(true); pdialog.setCancelable(true); dialog = pdialog; break; case Constants.DIALOG_FIND: inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View content = inflater.inflate(R.layout.dialog_find, null); final EditText find_box = (EditText) content.findViewById(R.id.input_find_box); // final CheckBox wrap_box = (CheckBox) content.findViewById(R.id.find_wrap_checkbox); builder = new AlertDialog.Builder(new ContextThemeWrapper(this, mSettings.getDialogTheme())); builder.setView(content); builder.setTitle(R.string.find).setPositiveButton(R.string.find, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String search_text = find_box.getText().toString().toLowerCase(); // findCommentText(search_text, wrap_box.isChecked(), false); findCommentText(search_text, true, false); } }).setNegativeButton("Cancel", null); dialog = builder.create(); break; default: throw new IllegalArgumentException("Unexpected dialog id " + id); } return dialog; }
From source file:com.piusvelte.sonet.core.SonetCreatePost.java
private void setLocation(final long accountId) { final ProgressDialog loadingDialog = new ProgressDialog(this); final AsyncTask<Void, Void, String> asyncTask = new AsyncTask<Void, Void, String>() { int serviceId; @Override//from w w w. jav a 2 s .c o m protected String doInBackground(Void... none) { Cursor account = getContentResolver().query(Accounts.getContentUri(SonetCreatePost.this), new String[] { Accounts._ID, Accounts.TOKEN, Accounts.SERVICE, Accounts.SECRET }, Accounts._ID + "=?", new String[] { Long.toString(accountId) }, null); if (account.moveToFirst()) { SonetOAuth sonetOAuth; serviceId = account.getInt(account.getColumnIndex(Accounts.SERVICE)); switch (serviceId) { case TWITTER: // anonymous requests are rate limited to 150 per hour // authenticated requests are rate limited to 350 per hour, so authenticate this! sonetOAuth = new SonetOAuth(TWITTER_KEY, TWITTER_SECRET, mSonetCrypto.Decrypt(account.getString(account.getColumnIndex(Accounts.TOKEN))), mSonetCrypto.Decrypt(account.getString(account.getColumnIndex(Accounts.SECRET)))); return SonetHttpClient.httpResponse(mHttpClient, sonetOAuth.getSignedRequest( new HttpGet(String.format(TWITTER_SEARCH, TWITTER_BASE_URL, mLat, mLong)))); case FACEBOOK: return SonetHttpClient.httpResponse(mHttpClient, new HttpGet(String.format(FACEBOOK_SEARCH, FACEBOOK_BASE_URL, mLat, mLong, Saccess_token, mSonetCrypto.Decrypt(account.getString(account.getColumnIndex(Accounts.TOKEN)))))); case FOURSQUARE: return SonetHttpClient.httpResponse(mHttpClient, new HttpGet(String.format( FOURSQUARE_SEARCH, FOURSQUARE_BASE_URL, mLat, mLong, mSonetCrypto.Decrypt(account.getString(account.getColumnIndex(Accounts.TOKEN)))))); } } account.close(); return null; } @Override protected void onPostExecute(String response) { if (loadingDialog.isShowing()) loadingDialog.dismiss(); if (response != null) { switch (serviceId) { case TWITTER: try { JSONArray places = new JSONObject(response).getJSONObject(Sresult) .getJSONArray(Splaces); final String placesNames[] = new String[places.length()]; final String placesIds[] = new String[places.length()]; for (int i = 0, i2 = places.length(); i < i2; i++) { JSONObject place = places.getJSONObject(i); placesNames[i] = place.getString(Sfull_name); placesIds[i] = place.getString(Sid); } mDialog = (new AlertDialog.Builder(SonetCreatePost.this)) .setSingleChoiceItems(placesNames, -1, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { mAccountsLocation.put(accountId, placesIds[which]); dialog.dismiss(); } }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }) .create(); mDialog.show(); } catch (JSONException e) { Log.e(TAG, e.toString()); } break; case FACEBOOK: try { JSONArray places = new JSONObject(response).getJSONArray(Sdata); final String placesNames[] = new String[places.length()]; final String placesIds[] = new String[places.length()]; for (int i = 0, i2 = places.length(); i < i2; i++) { JSONObject place = places.getJSONObject(i); placesNames[i] = place.getString(Sname); placesIds[i] = place.getString(Sid); } mDialog = (new AlertDialog.Builder(SonetCreatePost.this)) .setSingleChoiceItems(placesNames, -1, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { mAccountsLocation.put(accountId, placesIds[which]); dialog.dismiss(); } }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }) .create(); mDialog.show(); } catch (JSONException e) { Log.e(TAG, e.toString()); } break; case FOURSQUARE: try { JSONArray groups = new JSONObject(response).getJSONObject(Sresponse) .getJSONArray(Sgroups); for (int g = 0, g2 = groups.length(); g < g2; g++) { JSONObject group = groups.getJSONObject(g); if (group.getString(Sname).equals(SNearby)) { JSONArray places = group.getJSONArray(Sitems); final String placesNames[] = new String[places.length()]; final String placesIds[] = new String[places.length()]; for (int i = 0, i2 = places.length(); i < i2; i++) { JSONObject place = places.getJSONObject(i); placesNames[i] = place.getString(Sname); placesIds[i] = place.getString(Sid); } mDialog = (new AlertDialog.Builder(SonetCreatePost.this)) .setSingleChoiceItems(placesNames, -1, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { mAccountsLocation.put(accountId, placesIds[which]); dialog.dismiss(); } }) .setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }) .create(); mDialog.show(); break; } } } catch (JSONException e) { Log.e(TAG, e.toString()); } break; } } else { (Toast.makeText(SonetCreatePost.this, getString(R.string.failure), Toast.LENGTH_LONG)).show(); } } }; loadingDialog.setMessage(getString(R.string.loading)); loadingDialog.setCancelable(true); loadingDialog.setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { if (!asyncTask.isCancelled()) asyncTask.cancel(true); } }); loadingDialog.setButton(ProgressDialog.BUTTON_NEGATIVE, getString(android.R.string.cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); loadingDialog.show(); asyncTask.execute(); }
From source file:com.piusvelte.sonet.SonetCreatePost.java
private void setLocation(final long accountId) { final ProgressDialog loadingDialog = new ProgressDialog(this); final AsyncTask<Void, Void, String> asyncTask = new AsyncTask<Void, Void, String>() { int serviceId; @Override// w w w .j av a2s . co m protected String doInBackground(Void... none) { Cursor account = getContentResolver().query(Accounts.getContentUri(SonetCreatePost.this), new String[] { Accounts._ID, Accounts.TOKEN, Accounts.SERVICE, Accounts.SECRET }, Accounts._ID + "=?", new String[] { Long.toString(accountId) }, null); if (account.moveToFirst()) { SonetOAuth sonetOAuth; serviceId = account.getInt(account.getColumnIndex(Accounts.SERVICE)); switch (serviceId) { case TWITTER: // anonymous requests are rate limited to 150 per hour // authenticated requests are rate limited to 350 per hour, so authenticate this! sonetOAuth = new SonetOAuth(BuildConfig.TWITTER_KEY, BuildConfig.TWITTER_SECRET, mSonetCrypto.Decrypt(account.getString(account.getColumnIndex(Accounts.TOKEN))), mSonetCrypto.Decrypt(account.getString(account.getColumnIndex(Accounts.SECRET)))); return SonetHttpClient.httpResponse(mHttpClient, sonetOAuth.getSignedRequest( new HttpGet(String.format(TWITTER_SEARCH, TWITTER_BASE_URL, mLat, mLong)))); case FACEBOOK: return SonetHttpClient.httpResponse(mHttpClient, new HttpGet(String.format(FACEBOOK_SEARCH, FACEBOOK_BASE_URL, mLat, mLong, Saccess_token, mSonetCrypto.Decrypt(account.getString(account.getColumnIndex(Accounts.TOKEN)))))); case FOURSQUARE: return SonetHttpClient.httpResponse(mHttpClient, new HttpGet(String.format( FOURSQUARE_SEARCH, FOURSQUARE_BASE_URL, mLat, mLong, mSonetCrypto.Decrypt(account.getString(account.getColumnIndex(Accounts.TOKEN)))))); } } account.close(); return null; } @Override protected void onPostExecute(String response) { if (loadingDialog.isShowing()) loadingDialog.dismiss(); if (response != null) { switch (serviceId) { case TWITTER: try { JSONArray places = new JSONObject(response).getJSONObject(Sresult) .getJSONArray(Splaces); final String placesNames[] = new String[places.length()]; final String placesIds[] = new String[places.length()]; for (int i = 0, i2 = places.length(); i < i2; i++) { JSONObject place = places.getJSONObject(i); placesNames[i] = place.getString(Sfull_name); placesIds[i] = place.getString(Sid); } mDialog = (new AlertDialog.Builder(SonetCreatePost.this)) .setSingleChoiceItems(placesNames, -1, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { mAccountsLocation.put(accountId, placesIds[which]); dialog.dismiss(); } }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }) .create(); mDialog.show(); } catch (JSONException e) { Log.e(TAG, e.toString()); } break; case FACEBOOK: try { JSONArray places = new JSONObject(response).getJSONArray(Sdata); final String placesNames[] = new String[places.length()]; final String placesIds[] = new String[places.length()]; for (int i = 0, i2 = places.length(); i < i2; i++) { JSONObject place = places.getJSONObject(i); placesNames[i] = place.getString(Sname); placesIds[i] = place.getString(Sid); } mDialog = (new AlertDialog.Builder(SonetCreatePost.this)) .setSingleChoiceItems(placesNames, -1, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { mAccountsLocation.put(accountId, placesIds[which]); dialog.dismiss(); } }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }) .create(); mDialog.show(); } catch (JSONException e) { Log.e(TAG, e.toString()); } break; case FOURSQUARE: try { JSONArray groups = new JSONObject(response).getJSONObject(Sresponse) .getJSONArray(Sgroups); for (int g = 0, g2 = groups.length(); g < g2; g++) { JSONObject group = groups.getJSONObject(g); if (group.getString(Sname).equals(SNearby)) { JSONArray places = group.getJSONArray(Sitems); final String placesNames[] = new String[places.length()]; final String placesIds[] = new String[places.length()]; for (int i = 0, i2 = places.length(); i < i2; i++) { JSONObject place = places.getJSONObject(i); placesNames[i] = place.getString(Sname); placesIds[i] = place.getString(Sid); } mDialog = (new AlertDialog.Builder(SonetCreatePost.this)) .setSingleChoiceItems(placesNames, -1, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { mAccountsLocation.put(accountId, placesIds[which]); dialog.dismiss(); } }) .setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }) .create(); mDialog.show(); break; } } } catch (JSONException e) { Log.e(TAG, e.toString()); } break; } } else { (Toast.makeText(SonetCreatePost.this, getString(R.string.failure), Toast.LENGTH_LONG)).show(); } } }; loadingDialog.setMessage(getString(R.string.loading)); loadingDialog.setCancelable(true); loadingDialog.setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { if (!asyncTask.isCancelled()) asyncTask.cancel(true); } }); loadingDialog.setButton(ProgressDialog.BUTTON_NEGATIVE, getString(android.R.string.cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); loadingDialog.show(); asyncTask.execute(); }
From source file:com.shafiq.myfeedle.core.MyfeedleCreatePost.java
private void setLocation(final long accountId) { final ProgressDialog loadingDialog = new ProgressDialog(this); final AsyncTask<Void, Void, String> asyncTask = new AsyncTask<Void, Void, String>() { int serviceId; @Override// www. j a v a 2 s. c om protected String doInBackground(Void... none) { Cursor account = getContentResolver().query(Accounts.getContentUri(MyfeedleCreatePost.this), new String[] { Accounts._ID, Accounts.TOKEN, Accounts.SERVICE, Accounts.SECRET }, Accounts._ID + "=?", new String[] { Long.toString(accountId) }, null); if (account.moveToFirst()) { MyfeedleOAuth myfeedleOAuth; serviceId = account.getInt(account.getColumnIndex(Accounts.SERVICE)); switch (serviceId) { case TWITTER: // anonymous requests are rate limited to 150 per hour // authenticated requests are rate limited to 350 per hour, so authenticate this! myfeedleOAuth = new MyfeedleOAuth(TWITTER_KEY, TWITTER_SECRET, mMyfeedleCrypto.Decrypt(account.getString(account.getColumnIndex(Accounts.TOKEN))), mMyfeedleCrypto .Decrypt(account.getString(account.getColumnIndex(Accounts.SECRET)))); return MyfeedleHttpClient.httpResponse(mHttpClient, myfeedleOAuth.getSignedRequest( new HttpGet(String.format(TWITTER_SEARCH, TWITTER_BASE_URL, mLat, mLong)))); case FACEBOOK: return MyfeedleHttpClient.httpResponse(mHttpClient, new HttpGet(String.format(FACEBOOK_SEARCH, FACEBOOK_BASE_URL, mLat, mLong, Saccess_token, mMyfeedleCrypto.Decrypt( account.getString(account.getColumnIndex(Accounts.TOKEN)))))); case FOURSQUARE: return MyfeedleHttpClient.httpResponse(mHttpClient, new HttpGet( String.format(FOURSQUARE_SEARCH, FOURSQUARE_BASE_URL, mLat, mLong, mMyfeedleCrypto .Decrypt(account.getString(account.getColumnIndex(Accounts.TOKEN)))))); } } account.close(); return null; } @Override protected void onPostExecute(String response) { if (loadingDialog.isShowing()) loadingDialog.dismiss(); if (response != null) { switch (serviceId) { case TWITTER: try { JSONArray places = new JSONObject(response).getJSONObject(Sresult) .getJSONArray(Splaces); final String placesNames[] = new String[places.length()]; final String placesIds[] = new String[places.length()]; for (int i = 0, i2 = places.length(); i < i2; i++) { JSONObject place = places.getJSONObject(i); placesNames[i] = place.getString(Sfull_name); placesIds[i] = place.getString(Sid); } mDialog = (new AlertDialog.Builder(MyfeedleCreatePost.this)) .setSingleChoiceItems(placesNames, -1, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { mAccountsLocation.put(accountId, placesIds[which]); dialog.dismiss(); } }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }) .create(); mDialog.show(); } catch (JSONException e) { Log.e(TAG, e.toString()); } break; case FACEBOOK: try { JSONArray places = new JSONObject(response).getJSONArray(Sdata); final String placesNames[] = new String[places.length()]; final String placesIds[] = new String[places.length()]; for (int i = 0, i2 = places.length(); i < i2; i++) { JSONObject place = places.getJSONObject(i); placesNames[i] = place.getString(Sname); placesIds[i] = place.getString(Sid); } mDialog = (new AlertDialog.Builder(MyfeedleCreatePost.this)) .setSingleChoiceItems(placesNames, -1, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { mAccountsLocation.put(accountId, placesIds[which]); dialog.dismiss(); } }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }) .create(); mDialog.show(); } catch (JSONException e) { Log.e(TAG, e.toString()); } break; case FOURSQUARE: try { JSONArray groups = new JSONObject(response).getJSONObject(Sresponse) .getJSONArray(Sgroups); for (int g = 0, g2 = groups.length(); g < g2; g++) { JSONObject group = groups.getJSONObject(g); if (group.getString(Sname).equals(SNearby)) { JSONArray places = group.getJSONArray(Sitems); final String placesNames[] = new String[places.length()]; final String placesIds[] = new String[places.length()]; for (int i = 0, i2 = places.length(); i < i2; i++) { JSONObject place = places.getJSONObject(i); placesNames[i] = place.getString(Sname); placesIds[i] = place.getString(Sid); } mDialog = (new AlertDialog.Builder(MyfeedleCreatePost.this)) .setSingleChoiceItems(placesNames, -1, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { mAccountsLocation.put(accountId, placesIds[which]); dialog.dismiss(); } }) .setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }) .create(); mDialog.show(); break; } } } catch (JSONException e) { Log.e(TAG, e.toString()); } break; } } else { (Toast.makeText(MyfeedleCreatePost.this, getString(R.string.failure), Toast.LENGTH_LONG)) .show(); } } }; loadingDialog.setMessage(getString(R.string.loading)); loadingDialog.setCancelable(true); loadingDialog.setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { if (!asyncTask.isCancelled()) asyncTask.cancel(true); } }); loadingDialog.setButton(ProgressDialog.BUTTON_NEGATIVE, getString(android.R.string.cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); loadingDialog.show(); asyncTask.execute(); }