List of usage examples for android.app ProgressDialog setCancelable
public void setCancelable(boolean flag)
From source file:de.da_sense.moses.client.AvailableFragment.java
/** * FIXME: The ProgressDialog doesn't show up. Handles installing APK from * the Server.// ww w . j av a2 s . co m * * @param app * the App to download and install */ protected void handleInstallApp(ExternalApplication app) { final ProgressDialog progressDialog = new ProgressDialog(WelcomeActivity.getInstance()); Log.d(TAG, "progressDialog = " + progressDialog); final ApkDownloadManager downloader = new ApkDownloadManager(app, WelcomeActivity.getInstance().getApplicationContext(), // getActivity().getApplicationContext(), new ExecutableForObject() { @Override public void execute(final Object o) { if (o instanceof Integer) { WelcomeActivity.getInstance().runOnUiThread(new Runnable() { @Override public void run() { if (totalSize == -1) { totalSize = (Integer) o / 1024; progressDialog.setMax(totalSize); } else { progressDialog.incrementProgressBy( ((Integer) o / 1024) - progressDialog.getProgress()); } } }); /* * They were : Runnable runnable = new Runnable() { * Integer temporary = (Integer) o / 1024; * * @Override public void run() { if (totalSize == * -1) { totalSize = temporary; * progressDialog.setMax(totalSize); } else { * progressDialog .incrementProgressBy( temporary - * progressDialog.getProgress()); } } }; * getActivity().runOnUiThread(runnable); */ } } }); progressDialog.setTitle(getString(R.string.downloadingApp)); progressDialog.setMessage(getString(R.string.pleaseWait)); progressDialog.setMax(0); progressDialog.setProgress(0); progressDialog.setOnCancelListener(new OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { downloader.cancel(); } }); progressDialog.setCancelable(true); progressDialog.setButton(DialogInterface.BUTTON_POSITIVE, "Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (progressDialog.isShowing()) progressDialog.cancel(); } }); progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); Observer observer = new Observer() { @Override public void update(Observable observable, Object data) { if (downloader.getState() == ApkDownloadManager.State.ERROR) { // error downloading if (progressDialog.isShowing()) { progressDialog.dismiss(); } showMessageBoxErrorDownloading(downloader); } else if (downloader.getState() == ApkDownloadManager.State.ERROR_NO_CONNECTION) { // error with connection if (progressDialog.isShowing()) { progressDialog.dismiss(); } showMessageBoxErrorNoConnection(downloader); } else if (downloader.getState() == ApkDownloadManager.State.FINISHED) { // success if (progressDialog.isShowing()) { progressDialog.dismiss(); } installDownloadedApk(downloader.getDownloadedApk(), downloader.getExternalApplicationResult()); } } }; downloader.addObserver(observer); totalSize = -1; // progressDialog.show(); FIXME: commented out in case it throws an // error downloader.start(); }
From source file:com.piusvelte.sonet.core.StatusDialog.java
@Override public void onClick(final DialogInterface dialog, int which) { switch (which) { case COMMENT: if (mAppWidgetId != -1) { if (mService == GOOGLEPLUS) startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse("https://plus.google.com"))); else if (mService == PINTEREST) { if (mSid != null) startActivity(new Intent(Intent.ACTION_VIEW) .setData(Uri.parse(String.format(PINTEREST_PIN, mSid)))); else startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse("https://pinterest.com"))); } else startActivity(Sonet.getPackageIntent(this, SonetComments.class).setData(mData)); } else//from w ww .j a va 2s . c o m (Toast.makeText(this, getString(R.string.error_status), Toast.LENGTH_LONG)).show(); dialog.cancel(); finish(); break; case POST: if (mAppWidgetId != -1) { if (mService == GOOGLEPLUS) startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse("https://plus.google.com"))); else if (mService == PINTEREST) startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse("https://pinterest.com"))); else startActivity(Sonet.getPackageIntent(this, SonetCreatePost.class).setData(Uri .withAppendedPath(Accounts.getContentUri(StatusDialog.this), Long.toString(mAccount)))); dialog.cancel(); finish(); } else { // no widget sent in, dialog to select one String[] widgets = getAllWidgets(); if (widgets.length > 0) { mDialog = (new AlertDialog.Builder(this)).setItems(widgets, new OnClickListener() { @Override public void onClick(DialogInterface arg0, int arg1) { // no account, dialog to select one // don't limit accounts to the widget Cursor c = StatusDialog.this.getContentResolver().query( Accounts.getContentUri(StatusDialog.this), new String[] { Accounts._ID, ACCOUNTS_QUERY }, null, null, null); if (c.moveToFirst()) { int iid = c.getColumnIndex(Accounts._ID), iusername = c.getColumnIndex(Accounts.USERNAME), i = 0; final long[] accountIndexes = new long[c.getCount()]; final String[] accounts = new String[c.getCount()]; while (!c.isAfterLast()) { long id = c.getLong(iid); accountIndexes[i] = id; accounts[i++] = c.getString(iusername); c.moveToNext(); } arg0.cancel(); mDialog = (new AlertDialog.Builder(StatusDialog.this)).setTitle(R.string.accounts) .setSingleChoiceItems(accounts, -1, new OnClickListener() { @Override public void onClick(DialogInterface arg0, int which) { startActivity(Sonet .getPackageIntent(StatusDialog.this, SonetCreatePost.class) .setData(Uri.withAppendedPath( Accounts.getContentUri(StatusDialog.this), Long.toString(accountIndexes[which])))); arg0.cancel(); } }).setCancelable(true).setOnCancelListener(new OnCancelListener() { @Override public void onCancel(DialogInterface arg0) { dialog.cancel(); } }).create(); mDialog.show(); } else { (Toast.makeText(StatusDialog.this, getString(R.string.error_status), Toast.LENGTH_LONG)).show(); dialog.cancel(); } c.close(); finish(); } }).setCancelable(true).setOnCancelListener(new OnCancelListener() { @Override public void onCancel(DialogInterface arg0) { dialog.cancel(); finish(); } }).create(); mDialog.show(); } else { (Toast.makeText(this, getString(R.string.error_status), Toast.LENGTH_LONG)).show(); dialog.cancel(); finish(); } } break; case SETTINGS: if (mAppWidgetId != -1) { startActivity(Sonet.getPackageIntent(this, ManageAccounts.class) .putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId)); dialog.cancel(); finish(); } else { // no widget sent in, dialog to select one String[] widgets = getAllWidgets(); if (widgets.length > 0) { mDialog = (new AlertDialog.Builder(this)).setItems(widgets, new OnClickListener() { @Override public void onClick(DialogInterface arg0, int arg1) { startActivity(Sonet.getPackageIntent(StatusDialog.this, ManageAccounts.class) .putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetIds[arg1])); arg0.cancel(); finish(); } }).setCancelable(true).setOnCancelListener(new OnCancelListener() { @Override public void onCancel(DialogInterface arg0) { dialog.cancel(); finish(); } }).create(); mDialog.show(); } else { (Toast.makeText(this, getString(R.string.error_status), Toast.LENGTH_LONG)).show(); dialog.cancel(); finish(); } } break; case NOTIFICATIONS: startActivity(Sonet.getPackageIntent(this, SonetNotifications.class)); dialog.cancel(); finish(); break; case REFRESH: if (mAppWidgetId != -1) { (Toast.makeText(getApplicationContext(), getString(R.string.refreshing), Toast.LENGTH_LONG)).show(); startService(Sonet.getPackageIntent(this, SonetService.class).setAction(ACTION_REFRESH) .putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, new int[] { mAppWidgetId })); dialog.cancel(); } else { // no widget sent in, dialog to select one String[] widgets = getAllWidgets(); if (widgets.length > 0) { mDialog = (new AlertDialog.Builder(this)).setItems(widgets, new OnClickListener() { @Override public void onClick(DialogInterface arg0, int arg1) { (Toast.makeText(StatusDialog.this.getApplicationContext(), getString(R.string.refreshing), Toast.LENGTH_LONG)).show(); startService(Sonet.getPackageIntent(StatusDialog.this, SonetService.class) .setAction(ACTION_REFRESH).putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, new int[] { mAppWidgetIds[arg1] })); arg0.cancel(); finish(); } }).setPositiveButton(R.string.refreshallwidgets, new OnClickListener() { @Override public void onClick(DialogInterface arg0, int which) { // refresh all (Toast.makeText(StatusDialog.this.getApplicationContext(), getString(R.string.refreshing), Toast.LENGTH_LONG)).show(); startService(Sonet.getPackageIntent(StatusDialog.this, SonetService.class) .putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, mAppWidgetIds)); arg0.cancel(); finish(); } }).setCancelable(true).setOnCancelListener(new OnCancelListener() { @Override public void onCancel(DialogInterface arg0) { dialog.cancel(); finish(); } }).create(); mDialog.show(); } else { dialog.cancel(); finish(); } } break; case PROFILE: Cursor account; final AsyncTask<String, Void, String> asyncTask; // get the resources switch (mService) { case TWITTER: account = this.getContentResolver().query(Accounts.getContentUri(StatusDialog.this), new String[] { Accounts._ID, Accounts.TOKEN, Accounts.SECRET }, Accounts._ID + "=?", new String[] { Long.toString(mAccount) }, null); if (account.moveToFirst()) { final ProgressDialog loadingDialog = new ProgressDialog(this); asyncTask = new AsyncTask<String, Void, String>() { @Override protected String doInBackground(String... arg0) { SonetOAuth sonetOAuth = new SonetOAuth(TWITTER_KEY, TWITTER_SECRET, arg0[0], arg0[1]); return SonetHttpClient.httpResponse( SonetHttpClient.getThreadSafeClient(getApplicationContext()), sonetOAuth.getSignedRequest( new HttpGet(String.format(TWITTER_USER, TWITTER_BASE_URL, mEsid)))); } @Override protected void onPostExecute(String response) { if (loadingDialog.isShowing()) loadingDialog.dismiss(); if (response != null) { try { JSONObject user = new JSONObject(response); startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri .parse(String.format(TWITTER_PROFILE, user.getString("screen_name"))))); } catch (JSONException e) { Log.e(TAG, e.toString()); onErrorExit(mServiceName); } } else { onErrorExit(mServiceName); } finish(); } }; 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(); finish(); } }); loadingDialog.show(); asyncTask.execute( mSonetCrypto.Decrypt(account.getString(account.getColumnIndex(Accounts.TOKEN))), mSonetCrypto.Decrypt(account.getString(account.getColumnIndex(Accounts.SECRET)))); } account.close(); break; case FACEBOOK: account = this.getContentResolver().query(Accounts.getContentUri(StatusDialog.this), new String[] { Accounts._ID, Accounts.TOKEN }, Accounts._ID + "=?", new String[] { Long.toString(mAccount) }, null); if (account.moveToFirst()) { final ProgressDialog loadingDialog = new ProgressDialog(this); asyncTask = new AsyncTask<String, Void, String>() { @Override protected String doInBackground(String... arg0) { return SonetHttpClient.httpResponse( SonetHttpClient.getThreadSafeClient(getApplicationContext()), new HttpGet(String.format(FACEBOOK_USER, FACEBOOK_BASE_URL, mEsid, Saccess_token, arg0[0]))); } @Override protected void onPostExecute(String response) { if (loadingDialog.isShowing()) loadingDialog.dismiss(); if (response != null) { try { startActivity(new Intent(Intent.ACTION_VIEW) .setData(Uri.parse((new JSONObject(response)).getString("link")))); } catch (JSONException e) { Log.e(TAG, e.toString()); onErrorExit(mServiceName); } } else { onErrorExit(mServiceName); } finish(); } }; 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(); finish(); } }); loadingDialog.show(); asyncTask.execute( mSonetCrypto.Decrypt(account.getString(account.getColumnIndex(Accounts.TOKEN)))); } account.close(); break; case MYSPACE: account = this.getContentResolver().query(Accounts.getContentUri(StatusDialog.this), new String[] { Accounts._ID, Accounts.TOKEN, Accounts.SECRET }, Accounts._ID + "=?", new String[] { Long.toString(mAccount) }, null); if (account.moveToFirst()) { final ProgressDialog loadingDialog = new ProgressDialog(this); asyncTask = new AsyncTask<String, Void, String>() { @Override protected String doInBackground(String... arg0) { SonetOAuth sonetOAuth = new SonetOAuth(MYSPACE_KEY, MYSPACE_SECRET, arg0[0], arg0[1]); return SonetHttpClient.httpResponse( SonetHttpClient.getThreadSafeClient(getApplicationContext()), sonetOAuth.getSignedRequest( new HttpGet(String.format(MYSPACE_USER, MYSPACE_BASE_URL, mEsid)))); } @Override protected void onPostExecute(String response) { if (loadingDialog.isShowing()) loadingDialog.dismiss(); if (response != null) { try { startActivity(new Intent(Intent.ACTION_VIEW) .setData(Uri.parse((new JSONObject(response)).getJSONObject("person") .getString("profileUrl")))); } catch (JSONException e) { Log.e(TAG, e.toString()); onErrorExit(mServiceName); } } else { onErrorExit(mServiceName); } finish(); } }; 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(); finish(); } }); loadingDialog.show(); asyncTask.execute( mSonetCrypto.Decrypt(account.getString(account.getColumnIndex(Accounts.TOKEN))), mSonetCrypto.Decrypt(account.getString(account.getColumnIndex(Accounts.SECRET)))); } account.close(); break; case FOURSQUARE: startActivity(new Intent(Intent.ACTION_VIEW) .setData(Uri.parse(String.format(FOURSQUARE_URL_PROFILE, mEsid)))); finish(); break; case LINKEDIN: account = this.getContentResolver().query(Accounts.getContentUri(StatusDialog.this), new String[] { Accounts._ID, Accounts.TOKEN, Accounts.SECRET }, Accounts._ID + "=?", new String[] { Long.toString(mAccount) }, null); if (account.moveToFirst()) { final ProgressDialog loadingDialog = new ProgressDialog(this); asyncTask = new AsyncTask<String, Void, String>() { @Override protected String doInBackground(String... arg0) { SonetOAuth sonetOAuth = new SonetOAuth(LINKEDIN_KEY, LINKEDIN_SECRET, arg0[0], arg0[1]); HttpGet httpGet = new HttpGet(String.format(LINKEDIN_URL_USER, mEsid)); for (String[] header : LINKEDIN_HEADERS) httpGet.setHeader(header[0], header[1]); return SonetHttpClient.httpResponse( SonetHttpClient.getThreadSafeClient(getApplicationContext()), sonetOAuth.getSignedRequest(httpGet)); } @Override protected void onPostExecute(String response) { if (loadingDialog.isShowing()) loadingDialog.dismiss(); if (response != null) { try { startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse( (new JSONObject(response)).getJSONObject("siteStandardProfileRequest") .getString("url").replaceAll("\\\\", "")))); } catch (JSONException e) { Log.e(TAG, e.toString()); onErrorExit(mServiceName); } } else { onErrorExit(mServiceName); } finish(); } }; 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(); finish(); } }); loadingDialog.show(); asyncTask.execute( mSonetCrypto.Decrypt(account.getString(account.getColumnIndex(Accounts.TOKEN))), mSonetCrypto.Decrypt(account.getString(account.getColumnIndex(Accounts.SECRET)))); } account.close(); break; case IDENTICA: account = this.getContentResolver().query(Accounts.getContentUri(StatusDialog.this), new String[] { Accounts._ID, Accounts.TOKEN, Accounts.SECRET }, Accounts._ID + "=?", new String[] { Long.toString(mAccount) }, null); if (account.moveToFirst()) { final ProgressDialog loadingDialog = new ProgressDialog(this); asyncTask = new AsyncTask<String, Void, String>() { @Override protected String doInBackground(String... arg0) { SonetOAuth sonetOAuth = new SonetOAuth(IDENTICA_KEY, IDENTICA_SECRET, arg0[0], arg0[1]); return SonetHttpClient.httpResponse( SonetHttpClient.getThreadSafeClient(getApplicationContext()), sonetOAuth.getSignedRequest( new HttpGet(String.format(IDENTICA_USER, IDENTICA_BASE_URL, mEsid)))); } @Override protected void onPostExecute(String response) { if (loadingDialog.isShowing()) loadingDialog.dismiss(); if (response != null) { try { JSONObject user = new JSONObject(response); startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse( String.format(IDENTICA_PROFILE, user.getString("screen_name"))))); } catch (JSONException e) { Log.e(TAG, e.toString()); onErrorExit(mServiceName); } } else { onErrorExit(mServiceName); } finish(); } }; 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(); finish(); } }); loadingDialog.show(); asyncTask.execute( mSonetCrypto.Decrypt(account.getString(account.getColumnIndex(Accounts.TOKEN))), mSonetCrypto.Decrypt(account.getString(account.getColumnIndex(Accounts.SECRET)))); } account.close(); break; case GOOGLEPLUS: startActivity(new Intent(Intent.ACTION_VIEW) .setData(Uri.parse(String.format(GOOGLEPLUS_PROFILE, mEsid)))); finish(); break; case PINTEREST: if (mEsid != null) startActivity(new Intent(Intent.ACTION_VIEW) .setData(Uri.parse(String.format(PINTEREST_PROFILE, mEsid)))); else startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse("https://pinterest.com"))); finish(); break; case CHATTER: account = this.getContentResolver().query(Accounts.getContentUri(StatusDialog.this), new String[] { Accounts._ID, Accounts.TOKEN }, Accounts._ID + "=?", new String[] { Long.toString(mAccount) }, null); if (account.moveToFirst()) { final ProgressDialog loadingDialog = new ProgressDialog(this); asyncTask = new AsyncTask<String, Void, String>() { @Override protected String doInBackground(String... arg0) { // need to get an instance return SonetHttpClient.httpResponse( SonetHttpClient.getThreadSafeClient(getApplicationContext()), new HttpPost(String.format(CHATTER_URL_ACCESS, CHATTER_KEY, arg0[0]))); } @Override protected void onPostExecute(String response) { if (loadingDialog.isShowing()) loadingDialog.dismiss(); if (response != null) { try { JSONObject jobj = new JSONObject(response); if (jobj.has("instance_url")) { startActivity(new Intent(Intent.ACTION_VIEW) .setData(Uri.parse(jobj.getString("instance_url") + "/" + mEsid))); } } catch (JSONException e) { Log.e(TAG, e.toString()); onErrorExit(mServiceName); } } else { onErrorExit(mServiceName); } finish(); } }; 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(); finish(); } }); loadingDialog.show(); asyncTask.execute( mSonetCrypto.Decrypt(account.getString(account.getColumnIndex(Accounts.TOKEN)))); } account.close(); break; } break; default: if ((itemsData != null) && (which < itemsData.length) && (itemsData[which] != null)) // open link startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse(itemsData[which]))); else (Toast.makeText(this, getString(R.string.error_status), Toast.LENGTH_LONG)).show(); finish(); break; } }
From source file:net.nightwhistler.pageturner.activity.ReadingFragment.java
@Override public void performSearch(String query) { LOG.debug("Starting search for: " + query); final ProgressDialog searchProgress = new ProgressDialog(context); searchProgress.setOwnerActivity(getActivity()); searchProgress.setCancelable(true); searchProgress.setMax(100);/* w w w .j a v a2 s.c o m*/ searchProgress.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); final SearchTextTask task = new SearchTextTask(bookView.getBook()) { int i = 0; @Override protected void onPreExecute() { super.onPreExecute(); searchProgress.setMessage(getString(R.string.search_wait)); searchProgress.show(); // Hide on-screen keyboard if it is showing InputMethodManager imm = (InputMethodManager) context .getSystemService(Activity.INPUT_METHOD_SERVICE); imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0); } @Override protected void onProgressUpdate(SearchResult... values) { if (!isAdded()) { return; } super.onProgressUpdate(values); LOG.debug("Found match at index=" + values[0].getIndex() + ", offset=" + values[0].getStart() + " with context " + values[0].getDisplay()); SearchResult res = values[0]; if (res.getDisplay() != null) { i++; String update = String.format(getString(R.string.search_hits), i); searchProgress.setMessage(update); } searchProgress.setProgress(bookView.getPercentageFor(res.getIndex(), res.getStart())); } @Override protected void onCancelled() { if (isAdded()) { Toast.makeText(context, R.string.search_cancelled, Toast.LENGTH_LONG).show(); } } protected void onPostExecute(java.util.List<SearchResult> result) { searchProgress.dismiss(); if (!isCancelled() && isAdded()) { if (result.size() > 0) { searchResults = result; showSearchResultDialog(result); } else { Toast.makeText(context, R.string.search_no_matches, Toast.LENGTH_LONG).show(); } } }; }; searchProgress.setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { task.cancel(true); } }); task.execute(query); }
From source file:com.piusvelte.sonet.StatusDialog.java
@Override public void onClick(final DialogInterface dialog, int which) { switch (which) { case COMMENT: if (mAppWidgetId != -1) { if (mService == GOOGLEPLUS) startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse("https://plus.google.com"))); else if (mService == PINTEREST) { if (mSid != null) startActivity(new Intent(Intent.ACTION_VIEW) .setData(Uri.parse(String.format(PINTEREST_PIN, mSid)))); else startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse("https://pinterest.com"))); } else startActivity(Sonet.getPackageIntent(this, SonetComments.class).setData(mData)); } else/* www . j ava2s. com*/ (Toast.makeText(this, getString(R.string.error_status), Toast.LENGTH_LONG)).show(); dialog.cancel(); finish(); break; case POST: if (mAppWidgetId != -1) { if (mService == GOOGLEPLUS) startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse("https://plus.google.com"))); else if (mService == PINTEREST) startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse("https://pinterest.com"))); else startActivity(Sonet.getPackageIntent(this, SonetCreatePost.class).setData(Uri .withAppendedPath(Accounts.getContentUri(StatusDialog.this), Long.toString(mAccount)))); dialog.cancel(); finish(); } else { // no widget sent in, dialog to select one String[] widgets = getAllWidgets(); if (widgets.length > 0) { mDialog = (new AlertDialog.Builder(this)).setItems(widgets, new OnClickListener() { @Override public void onClick(DialogInterface arg0, int arg1) { // no account, dialog to select one // don't limit accounts to the widget Cursor c = StatusDialog.this.getContentResolver().query( Accounts.getContentUri(StatusDialog.this), new String[] { Accounts._ID, ACCOUNTS_QUERY }, null, null, null); if (c.moveToFirst()) { int iid = c.getColumnIndex(Accounts._ID), iusername = c.getColumnIndex(Accounts.USERNAME), i = 0; final long[] accountIndexes = new long[c.getCount()]; final String[] accounts = new String[c.getCount()]; while (!c.isAfterLast()) { long id = c.getLong(iid); accountIndexes[i] = id; accounts[i++] = c.getString(iusername); c.moveToNext(); } arg0.cancel(); mDialog = (new AlertDialog.Builder(StatusDialog.this)).setTitle(R.string.accounts) .setSingleChoiceItems(accounts, -1, new OnClickListener() { @Override public void onClick(DialogInterface arg0, int which) { startActivity(Sonet .getPackageIntent(StatusDialog.this, SonetCreatePost.class) .setData(Uri.withAppendedPath( Accounts.getContentUri(StatusDialog.this), Long.toString(accountIndexes[which])))); arg0.cancel(); } }).setCancelable(true).setOnCancelListener(new OnCancelListener() { @Override public void onCancel(DialogInterface arg0) { dialog.cancel(); } }).create(); mDialog.show(); } else { (Toast.makeText(StatusDialog.this, getString(R.string.error_status), Toast.LENGTH_LONG)).show(); dialog.cancel(); } c.close(); finish(); } }).setCancelable(true).setOnCancelListener(new OnCancelListener() { @Override public void onCancel(DialogInterface arg0) { dialog.cancel(); finish(); } }).create(); mDialog.show(); } else { (Toast.makeText(this, getString(R.string.error_status), Toast.LENGTH_LONG)).show(); dialog.cancel(); finish(); } } break; case SETTINGS: if (mAppWidgetId != -1) { startActivity(Sonet.getPackageIntent(this, ManageAccounts.class) .putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId)); dialog.cancel(); finish(); } else { // no widget sent in, dialog to select one String[] widgets = getAllWidgets(); if (widgets.length > 0) { mDialog = (new AlertDialog.Builder(this)).setItems(widgets, new OnClickListener() { @Override public void onClick(DialogInterface arg0, int arg1) { startActivity(Sonet.getPackageIntent(StatusDialog.this, ManageAccounts.class) .putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetIds[arg1])); arg0.cancel(); finish(); } }).setCancelable(true).setOnCancelListener(new OnCancelListener() { @Override public void onCancel(DialogInterface arg0) { dialog.cancel(); finish(); } }).create(); mDialog.show(); } else { (Toast.makeText(this, getString(R.string.error_status), Toast.LENGTH_LONG)).show(); dialog.cancel(); finish(); } } break; case NOTIFICATIONS: startActivity(Sonet.getPackageIntent(this, SonetNotifications.class)); dialog.cancel(); finish(); break; case REFRESH: if (mAppWidgetId != -1) { (Toast.makeText(getApplicationContext(), getString(R.string.refreshing), Toast.LENGTH_LONG)).show(); startService(Sonet.getPackageIntent(this, SonetService.class).setAction(ACTION_REFRESH) .putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, new int[] { mAppWidgetId })); dialog.cancel(); } else { // no widget sent in, dialog to select one String[] widgets = getAllWidgets(); if (widgets.length > 0) { mDialog = (new AlertDialog.Builder(this)).setItems(widgets, new OnClickListener() { @Override public void onClick(DialogInterface arg0, int arg1) { (Toast.makeText(StatusDialog.this.getApplicationContext(), getString(R.string.refreshing), Toast.LENGTH_LONG)).show(); startService(Sonet.getPackageIntent(StatusDialog.this, SonetService.class) .setAction(ACTION_REFRESH).putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, new int[] { mAppWidgetIds[arg1] })); arg0.cancel(); finish(); } }).setPositiveButton(R.string.refreshallwidgets, new OnClickListener() { @Override public void onClick(DialogInterface arg0, int which) { // refresh all (Toast.makeText(StatusDialog.this.getApplicationContext(), getString(R.string.refreshing), Toast.LENGTH_LONG)).show(); startService(Sonet.getPackageIntent(StatusDialog.this, SonetService.class) .putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, mAppWidgetIds)); arg0.cancel(); finish(); } }).setCancelable(true).setOnCancelListener(new OnCancelListener() { @Override public void onCancel(DialogInterface arg0) { dialog.cancel(); finish(); } }).create(); mDialog.show(); } else { dialog.cancel(); finish(); } } break; case PROFILE: Cursor account; final AsyncTask<String, Void, String> asyncTask; // get the resources switch (mService) { case TWITTER: account = this.getContentResolver().query(Accounts.getContentUri(StatusDialog.this), new String[] { Accounts._ID, Accounts.TOKEN, Accounts.SECRET }, Accounts._ID + "=?", new String[] { Long.toString(mAccount) }, null); if (account.moveToFirst()) { final ProgressDialog loadingDialog = new ProgressDialog(this); asyncTask = new AsyncTask<String, Void, String>() { @Override protected String doInBackground(String... arg0) { SonetOAuth sonetOAuth = new SonetOAuth(BuildConfig.TWITTER_KEY, BuildConfig.TWITTER_SECRET, arg0[0], arg0[1]); return SonetHttpClient.httpResponse( SonetHttpClient.getThreadSafeClient(getApplicationContext()), sonetOAuth.getSignedRequest( new HttpGet(String.format(TWITTER_USER, TWITTER_BASE_URL, mEsid)))); } @Override protected void onPostExecute(String response) { if (loadingDialog.isShowing()) loadingDialog.dismiss(); if (response != null) { try { JSONObject user = new JSONObject(response); startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri .parse(String.format(TWITTER_PROFILE, user.getString("screen_name"))))); } catch (JSONException e) { Log.e(TAG, e.toString()); onErrorExit(mServiceName); } } else { onErrorExit(mServiceName); } finish(); } }; 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(); finish(); } }); loadingDialog.show(); asyncTask.execute( mSonetCrypto.Decrypt(account.getString(account.getColumnIndex(Accounts.TOKEN))), mSonetCrypto.Decrypt(account.getString(account.getColumnIndex(Accounts.SECRET)))); } account.close(); break; case FACEBOOK: account = this.getContentResolver().query(Accounts.getContentUri(StatusDialog.this), new String[] { Accounts._ID, Accounts.TOKEN }, Accounts._ID + "=?", new String[] { Long.toString(mAccount) }, null); if (account.moveToFirst()) { final ProgressDialog loadingDialog = new ProgressDialog(this); asyncTask = new AsyncTask<String, Void, String>() { @Override protected String doInBackground(String... arg0) { return SonetHttpClient.httpResponse( SonetHttpClient.getThreadSafeClient(getApplicationContext()), new HttpGet(String.format(FACEBOOK_USER, FACEBOOK_BASE_URL, mEsid, Saccess_token, arg0[0]))); } @Override protected void onPostExecute(String response) { if (loadingDialog.isShowing()) loadingDialog.dismiss(); if (response != null) { try { startActivity(new Intent(Intent.ACTION_VIEW) .setData(Uri.parse((new JSONObject(response)).getString("link")))); } catch (JSONException e) { Log.e(TAG, e.toString()); onErrorExit(mServiceName); } } else { onErrorExit(mServiceName); } finish(); } }; 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(); finish(); } }); loadingDialog.show(); asyncTask.execute( mSonetCrypto.Decrypt(account.getString(account.getColumnIndex(Accounts.TOKEN)))); } account.close(); break; case MYSPACE: account = this.getContentResolver().query(Accounts.getContentUri(StatusDialog.this), new String[] { Accounts._ID, Accounts.TOKEN, Accounts.SECRET }, Accounts._ID + "=?", new String[] { Long.toString(mAccount) }, null); if (account.moveToFirst()) { final ProgressDialog loadingDialog = new ProgressDialog(this); asyncTask = new AsyncTask<String, Void, String>() { @Override protected String doInBackground(String... arg0) { SonetOAuth sonetOAuth = new SonetOAuth(BuildConfig.MYSPACE_KEY, BuildConfig.MYSPACE_SECRET, arg0[0], arg0[1]); return SonetHttpClient.httpResponse( SonetHttpClient.getThreadSafeClient(getApplicationContext()), sonetOAuth.getSignedRequest( new HttpGet(String.format(MYSPACE_USER, MYSPACE_BASE_URL, mEsid)))); } @Override protected void onPostExecute(String response) { if (loadingDialog.isShowing()) loadingDialog.dismiss(); if (response != null) { try { startActivity(new Intent(Intent.ACTION_VIEW) .setData(Uri.parse((new JSONObject(response)).getJSONObject("person") .getString("profileUrl")))); } catch (JSONException e) { Log.e(TAG, e.toString()); onErrorExit(mServiceName); } } else { onErrorExit(mServiceName); } finish(); } }; 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(); finish(); } }); loadingDialog.show(); asyncTask.execute( mSonetCrypto.Decrypt(account.getString(account.getColumnIndex(Accounts.TOKEN))), mSonetCrypto.Decrypt(account.getString(account.getColumnIndex(Accounts.SECRET)))); } account.close(); break; case FOURSQUARE: startActivity(new Intent(Intent.ACTION_VIEW) .setData(Uri.parse(String.format(FOURSQUARE_URL_PROFILE, mEsid)))); finish(); break; case LINKEDIN: account = this.getContentResolver().query(Accounts.getContentUri(StatusDialog.this), new String[] { Accounts._ID, Accounts.TOKEN, Accounts.SECRET }, Accounts._ID + "=?", new String[] { Long.toString(mAccount) }, null); if (account.moveToFirst()) { final ProgressDialog loadingDialog = new ProgressDialog(this); asyncTask = new AsyncTask<String, Void, String>() { @Override protected String doInBackground(String... arg0) { SonetOAuth sonetOAuth = new SonetOAuth(BuildConfig.LINKEDIN_KEY, BuildConfig.LINKEDIN_SECRET, arg0[0], arg0[1]); HttpGet httpGet = new HttpGet(String.format(LINKEDIN_URL_USER, mEsid)); for (String[] header : LINKEDIN_HEADERS) httpGet.setHeader(header[0], header[1]); return SonetHttpClient.httpResponse( SonetHttpClient.getThreadSafeClient(getApplicationContext()), sonetOAuth.getSignedRequest(httpGet)); } @Override protected void onPostExecute(String response) { if (loadingDialog.isShowing()) loadingDialog.dismiss(); if (response != null) { try { startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse( (new JSONObject(response)).getJSONObject("siteStandardProfileRequest") .getString("url").replaceAll("\\\\", "")))); } catch (JSONException e) { Log.e(TAG, e.toString()); onErrorExit(mServiceName); } } else { onErrorExit(mServiceName); } finish(); } }; 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(); finish(); } }); loadingDialog.show(); asyncTask.execute( mSonetCrypto.Decrypt(account.getString(account.getColumnIndex(Accounts.TOKEN))), mSonetCrypto.Decrypt(account.getString(account.getColumnIndex(Accounts.SECRET)))); } account.close(); break; case IDENTICA: account = this.getContentResolver().query(Accounts.getContentUri(StatusDialog.this), new String[] { Accounts._ID, Accounts.TOKEN, Accounts.SECRET }, Accounts._ID + "=?", new String[] { Long.toString(mAccount) }, null); if (account.moveToFirst()) { final ProgressDialog loadingDialog = new ProgressDialog(this); asyncTask = new AsyncTask<String, Void, String>() { @Override protected String doInBackground(String... arg0) { SonetOAuth sonetOAuth = new SonetOAuth(BuildConfig.IDENTICA_KEY, BuildConfig.IDENTICA_SECRET, arg0[0], arg0[1]); return SonetHttpClient.httpResponse( SonetHttpClient.getThreadSafeClient(getApplicationContext()), sonetOAuth.getSignedRequest( new HttpGet(String.format(IDENTICA_USER, IDENTICA_BASE_URL, mEsid)))); } @Override protected void onPostExecute(String response) { if (loadingDialog.isShowing()) loadingDialog.dismiss(); if (response != null) { try { JSONObject user = new JSONObject(response); startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse( String.format(IDENTICA_PROFILE, user.getString("screen_name"))))); } catch (JSONException e) { Log.e(TAG, e.toString()); onErrorExit(mServiceName); } } else { onErrorExit(mServiceName); } finish(); } }; 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(); finish(); } }); loadingDialog.show(); asyncTask.execute( mSonetCrypto.Decrypt(account.getString(account.getColumnIndex(Accounts.TOKEN))), mSonetCrypto.Decrypt(account.getString(account.getColumnIndex(Accounts.SECRET)))); } account.close(); break; case GOOGLEPLUS: startActivity(new Intent(Intent.ACTION_VIEW) .setData(Uri.parse(String.format(GOOGLEPLUS_PROFILE, mEsid)))); finish(); break; case PINTEREST: if (mEsid != null) startActivity(new Intent(Intent.ACTION_VIEW) .setData(Uri.parse(String.format(PINTEREST_PROFILE, mEsid)))); else startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse("https://pinterest.com"))); finish(); break; case CHATTER: account = this.getContentResolver().query(Accounts.getContentUri(StatusDialog.this), new String[] { Accounts._ID, Accounts.TOKEN }, Accounts._ID + "=?", new String[] { Long.toString(mAccount) }, null); if (account.moveToFirst()) { final ProgressDialog loadingDialog = new ProgressDialog(this); asyncTask = new AsyncTask<String, Void, String>() { @Override protected String doInBackground(String... arg0) { // need to get an instance return SonetHttpClient.httpResponse( SonetHttpClient.getThreadSafeClient(getApplicationContext()), new HttpPost( String.format(CHATTER_URL_ACCESS, BuildConfig.CHATTER_KEY, arg0[0]))); } @Override protected void onPostExecute(String response) { if (loadingDialog.isShowing()) loadingDialog.dismiss(); if (response != null) { try { JSONObject jobj = new JSONObject(response); if (jobj.has("instance_url")) { startActivity(new Intent(Intent.ACTION_VIEW) .setData(Uri.parse(jobj.getString("instance_url") + "/" + mEsid))); } } catch (JSONException e) { Log.e(TAG, e.toString()); onErrorExit(mServiceName); } } else { onErrorExit(mServiceName); } finish(); } }; 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(); finish(); } }); loadingDialog.show(); asyncTask.execute( mSonetCrypto.Decrypt(account.getString(account.getColumnIndex(Accounts.TOKEN)))); } account.close(); break; } break; default: if ((itemsData != null) && (which < itemsData.length) && (itemsData[which] != null)) // open link startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse(itemsData[which]))); else (Toast.makeText(this, getString(R.string.error_status), Toast.LENGTH_LONG)).show(); finish(); break; } }
From source file:cm.aptoide.pt.MainActivity.java
@Override public boolean onContextItemSelected(final MenuItem item) { final ProgressDialog pd; switch (item.getItemId()) { case 0://from ww w . j a v a 2 s .c om pd = new ProgressDialog(mContext); pd.setMessage(getString(R.string.please_wait)); pd.show(); pd.setCancelable(false); new Thread(new Runnable() { private boolean result = false; @Override public void run() { try { result = service.deleteStore(db, ((AdapterContextMenuInfo) item.getMenuInfo()).id); } catch (Exception e) { e.printStackTrace(); } finally { runOnUiThread(new Runnable() { @Override public void run() { pd.dismiss(); if (result) { refreshAvailableList(false); installedLoader.forceLoad(); updatesLoader.forceLoad(); } else { Toast toast = Toast.makeText(mContext, mContext.getString(R.string.error_delete_store), Toast.LENGTH_SHORT); toast.show(); } } }); } } }).start(); break; case 1: pd = new ProgressDialog(mContext); pd.setMessage(getString(R.string.please_wait)); pd.show(); pd.setCancelable(false); new Thread(new Runnable() { @Override public void run() { try { service.parseServer(db, db.getServer(((AdapterContextMenuInfo) item.getMenuInfo()).id, false)); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { runOnUiThread(new Runnable() { @Override public void run() { pd.dismiss(); refreshAvailableList(false); } }); } } }).start(); break; } return super.onContextItemSelected(item); }
From source file:com.shafiq.myfeedle.core.StatusDialog.java
@Override public void onClick(final DialogInterface dialog, int which) { switch (which) { case COMMENT: if (mAppWidgetId != -1) { if (mService == GOOGLEPLUS) startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse("https://plus.google.com"))); else if (mService == PINTEREST) { if (mSid != null) startActivity(new Intent(Intent.ACTION_VIEW) .setData(Uri.parse(String.format(PINTEREST_PIN, mSid)))); else startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse("https://pinterest.com"))); } else startActivity(Myfeedle.getPackageIntent(this, MyfeedleComments.class).setData(mData)); } else/*from w ww. java 2 s . c om*/ (Toast.makeText(this, getString(R.string.error_status), Toast.LENGTH_LONG)).show(); dialog.cancel(); finish(); break; case POST: if (mAppWidgetId != -1) { if (mService == GOOGLEPLUS) startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse("https://plus.google.com"))); else if (mService == PINTEREST) startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse("https://pinterest.com"))); else startActivity(Myfeedle.getPackageIntent(this, MyfeedleCreatePost.class).setData(Uri .withAppendedPath(Accounts.getContentUri(StatusDialog.this), Long.toString(mAccount)))); dialog.cancel(); finish(); } else { // no widget sent in, dialog to select one String[] widgets = getAllWidgets(); if (widgets.length > 0) { mDialog = (new AlertDialog.Builder(this)).setItems(widgets, new OnClickListener() { @Override public void onClick(DialogInterface arg0, int arg1) { // no account, dialog to select one // don't limit accounts to the widget Cursor c = StatusDialog.this.getContentResolver().query( Accounts.getContentUri(StatusDialog.this), new String[] { Accounts._ID, ACCOUNTS_QUERY }, null, null, null); if (c.moveToFirst()) { int iid = c.getColumnIndex(Accounts._ID), iusername = c.getColumnIndex(Accounts.USERNAME), i = 0; final long[] accountIndexes = new long[c.getCount()]; final String[] accounts = new String[c.getCount()]; while (!c.isAfterLast()) { long id = c.getLong(iid); accountIndexes[i] = id; accounts[i++] = c.getString(iusername); c.moveToNext(); } arg0.cancel(); mDialog = (new AlertDialog.Builder(StatusDialog.this)).setTitle(R.string.accounts) .setSingleChoiceItems(accounts, -1, new OnClickListener() { @Override public void onClick(DialogInterface arg0, int which) { startActivity(Myfeedle .getPackageIntent(StatusDialog.this, MyfeedleCreatePost.class) .setData(Uri.withAppendedPath( Accounts.getContentUri(StatusDialog.this), Long.toString(accountIndexes[which])))); arg0.cancel(); } }).setCancelable(true).setOnCancelListener(new OnCancelListener() { @Override public void onCancel(DialogInterface arg0) { dialog.cancel(); } }).create(); mDialog.show(); } else { (Toast.makeText(StatusDialog.this, getString(R.string.error_status), Toast.LENGTH_LONG)).show(); dialog.cancel(); } c.close(); finish(); } }).setCancelable(true).setOnCancelListener(new OnCancelListener() { @Override public void onCancel(DialogInterface arg0) { dialog.cancel(); finish(); } }).create(); mDialog.show(); } else { (Toast.makeText(this, getString(R.string.error_status), Toast.LENGTH_LONG)).show(); dialog.cancel(); finish(); } } break; case SETTINGS: if (mAppWidgetId != -1) { startActivity(Myfeedle.getPackageIntent(this, ManageAccounts.class) .putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId)); dialog.cancel(); finish(); } else { // no widget sent in, dialog to select one String[] widgets = getAllWidgets(); if (widgets.length > 0) { mDialog = (new AlertDialog.Builder(this)).setItems(widgets, new OnClickListener() { @Override public void onClick(DialogInterface arg0, int arg1) { startActivity(Myfeedle.getPackageIntent(StatusDialog.this, ManageAccounts.class) .putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetIds[arg1])); arg0.cancel(); finish(); } }).setCancelable(true).setOnCancelListener(new OnCancelListener() { @Override public void onCancel(DialogInterface arg0) { dialog.cancel(); finish(); } }).create(); mDialog.show(); } else { (Toast.makeText(this, getString(R.string.error_status), Toast.LENGTH_LONG)).show(); dialog.cancel(); finish(); } } break; case NOTIFICATIONS: startActivity(Myfeedle.getPackageIntent(this, MyfeedleNotifications.class)); dialog.cancel(); finish(); break; case REFRESH: if (mAppWidgetId != -1) { (Toast.makeText(getApplicationContext(), getString(R.string.refreshing), Toast.LENGTH_LONG)).show(); startService(Myfeedle.getPackageIntent(this, MyfeedleService.class).setAction(ACTION_REFRESH) .putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, new int[] { mAppWidgetId })); dialog.cancel(); } else { // no widget sent in, dialog to select one String[] widgets = getAllWidgets(); if (widgets.length > 0) { mDialog = (new AlertDialog.Builder(this)).setItems(widgets, new OnClickListener() { @Override public void onClick(DialogInterface arg0, int arg1) { (Toast.makeText(StatusDialog.this.getApplicationContext(), getString(R.string.refreshing), Toast.LENGTH_LONG)).show(); startService(Myfeedle.getPackageIntent(StatusDialog.this, MyfeedleService.class) .setAction(ACTION_REFRESH).putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, new int[] { mAppWidgetIds[arg1] })); arg0.cancel(); finish(); } }).setPositiveButton(R.string.refreshallwidgets, new OnClickListener() { @Override public void onClick(DialogInterface arg0, int which) { // refresh all (Toast.makeText(StatusDialog.this.getApplicationContext(), getString(R.string.refreshing), Toast.LENGTH_LONG)).show(); startService(Myfeedle.getPackageIntent(StatusDialog.this, MyfeedleService.class) .putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, mAppWidgetIds)); arg0.cancel(); finish(); } }).setCancelable(true).setOnCancelListener(new OnCancelListener() { @Override public void onCancel(DialogInterface arg0) { dialog.cancel(); finish(); } }).create(); mDialog.show(); } else { dialog.cancel(); finish(); } } break; case PROFILE: Cursor account; final AsyncTask<String, Void, String> asyncTask; // get the resources switch (mService) { case TWITTER: account = this.getContentResolver().query(Accounts.getContentUri(StatusDialog.this), new String[] { Accounts._ID, Accounts.TOKEN, Accounts.SECRET }, Accounts._ID + "=?", new String[] { Long.toString(mAccount) }, null); if (account.moveToFirst()) { final ProgressDialog loadingDialog = new ProgressDialog(this); asyncTask = new AsyncTask<String, Void, String>() { @Override protected String doInBackground(String... arg0) { MyfeedleOAuth myfeedleOAuth = new MyfeedleOAuth(TWITTER_KEY, TWITTER_SECRET, arg0[0], arg0[1]); return MyfeedleHttpClient.httpResponse( MyfeedleHttpClient.getThreadSafeClient(getApplicationContext()), myfeedleOAuth.getSignedRequest( new HttpGet(String.format(TWITTER_USER, TWITTER_BASE_URL, mEsid)))); } @Override protected void onPostExecute(String response) { if (loadingDialog.isShowing()) loadingDialog.dismiss(); if (response != null) { try { JSONObject user = new JSONObject(response); startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri .parse(String.format(TWITTER_PROFILE, user.getString("screen_name"))))); } catch (JSONException e) { Log.e(TAG, e.toString()); onErrorExit(mServiceName); } } else { onErrorExit(mServiceName); } finish(); } }; 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(); finish(); } }); loadingDialog.show(); asyncTask.execute( mMyfeedleCrypto.Decrypt(account.getString(account.getColumnIndex(Accounts.TOKEN))), mMyfeedleCrypto.Decrypt(account.getString(account.getColumnIndex(Accounts.SECRET)))); } account.close(); break; case FACEBOOK: account = this.getContentResolver().query(Accounts.getContentUri(StatusDialog.this), new String[] { Accounts._ID, Accounts.TOKEN }, Accounts._ID + "=?", new String[] { Long.toString(mAccount) }, null); if (account.moveToFirst()) { final ProgressDialog loadingDialog = new ProgressDialog(this); asyncTask = new AsyncTask<String, Void, String>() { @Override protected String doInBackground(String... arg0) { return MyfeedleHttpClient.httpResponse( MyfeedleHttpClient.getThreadSafeClient(getApplicationContext()), new HttpGet(String.format(FACEBOOK_USER, FACEBOOK_BASE_URL, mEsid, Saccess_token, arg0[0]))); } @Override protected void onPostExecute(String response) { if (loadingDialog.isShowing()) loadingDialog.dismiss(); if (response != null) { try { startActivity(new Intent(Intent.ACTION_VIEW) .setData(Uri.parse((new JSONObject(response)).getString("link")))); } catch (JSONException e) { Log.e(TAG, e.toString()); onErrorExit(mServiceName); } } else { onErrorExit(mServiceName); } finish(); } }; 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(); finish(); } }); loadingDialog.show(); asyncTask.execute( mMyfeedleCrypto.Decrypt(account.getString(account.getColumnIndex(Accounts.TOKEN)))); } account.close(); break; case MYSPACE: account = this.getContentResolver().query(Accounts.getContentUri(StatusDialog.this), new String[] { Accounts._ID, Accounts.TOKEN, Accounts.SECRET }, Accounts._ID + "=?", new String[] { Long.toString(mAccount) }, null); if (account.moveToFirst()) { final ProgressDialog loadingDialog = new ProgressDialog(this); asyncTask = new AsyncTask<String, Void, String>() { @Override protected String doInBackground(String... arg0) { MyfeedleOAuth myfeedleOAuth = new MyfeedleOAuth(MYSPACE_KEY, MYSPACE_SECRET, arg0[0], arg0[1]); return MyfeedleHttpClient.httpResponse( MyfeedleHttpClient.getThreadSafeClient(getApplicationContext()), myfeedleOAuth.getSignedRequest( new HttpGet(String.format(MYSPACE_USER, MYSPACE_BASE_URL, mEsid)))); } @Override protected void onPostExecute(String response) { if (loadingDialog.isShowing()) loadingDialog.dismiss(); if (response != null) { try { startActivity(new Intent(Intent.ACTION_VIEW) .setData(Uri.parse((new JSONObject(response)).getJSONObject("person") .getString("profileUrl")))); } catch (JSONException e) { Log.e(TAG, e.toString()); onErrorExit(mServiceName); } } else { onErrorExit(mServiceName); } finish(); } }; 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(); finish(); } }); loadingDialog.show(); asyncTask.execute( mMyfeedleCrypto.Decrypt(account.getString(account.getColumnIndex(Accounts.TOKEN))), mMyfeedleCrypto.Decrypt(account.getString(account.getColumnIndex(Accounts.SECRET)))); } account.close(); break; case FOURSQUARE: startActivity(new Intent(Intent.ACTION_VIEW) .setData(Uri.parse(String.format(FOURSQUARE_URL_PROFILE, mEsid)))); finish(); break; case LINKEDIN: account = this.getContentResolver().query(Accounts.getContentUri(StatusDialog.this), new String[] { Accounts._ID, Accounts.TOKEN, Accounts.SECRET }, Accounts._ID + "=?", new String[] { Long.toString(mAccount) }, null); if (account.moveToFirst()) { final ProgressDialog loadingDialog = new ProgressDialog(this); asyncTask = new AsyncTask<String, Void, String>() { @Override protected String doInBackground(String... arg0) { MyfeedleOAuth myfeedleOAuth = new MyfeedleOAuth(LINKEDIN_KEY, LINKEDIN_SECRET, arg0[0], arg0[1]); HttpGet httpGet = new HttpGet(String.format(LINKEDIN_URL_USER, mEsid)); for (String[] header : LINKEDIN_HEADERS) httpGet.setHeader(header[0], header[1]); return MyfeedleHttpClient.httpResponse( MyfeedleHttpClient.getThreadSafeClient(getApplicationContext()), myfeedleOAuth.getSignedRequest(httpGet)); } @Override protected void onPostExecute(String response) { if (loadingDialog.isShowing()) loadingDialog.dismiss(); if (response != null) { try { startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse( (new JSONObject(response)).getJSONObject("siteStandardProfileRequest") .getString("url").replaceAll("\\\\", "")))); } catch (JSONException e) { Log.e(TAG, e.toString()); onErrorExit(mServiceName); } } else { onErrorExit(mServiceName); } finish(); } }; 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(); finish(); } }); loadingDialog.show(); asyncTask.execute( mMyfeedleCrypto.Decrypt(account.getString(account.getColumnIndex(Accounts.TOKEN))), mMyfeedleCrypto.Decrypt(account.getString(account.getColumnIndex(Accounts.SECRET)))); } account.close(); break; case IDENTICA: account = this.getContentResolver().query(Accounts.getContentUri(StatusDialog.this), new String[] { Accounts._ID, Accounts.TOKEN, Accounts.SECRET }, Accounts._ID + "=?", new String[] { Long.toString(mAccount) }, null); if (account.moveToFirst()) { final ProgressDialog loadingDialog = new ProgressDialog(this); asyncTask = new AsyncTask<String, Void, String>() { @Override protected String doInBackground(String... arg0) { MyfeedleOAuth myfeedleOAuth = new MyfeedleOAuth(IDENTICA_KEY, IDENTICA_SECRET, arg0[0], arg0[1]); return MyfeedleHttpClient.httpResponse( MyfeedleHttpClient.getThreadSafeClient(getApplicationContext()), myfeedleOAuth.getSignedRequest( new HttpGet(String.format(IDENTICA_USER, IDENTICA_BASE_URL, mEsid)))); } @Override protected void onPostExecute(String response) { if (loadingDialog.isShowing()) loadingDialog.dismiss(); if (response != null) { try { JSONObject user = new JSONObject(response); startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse( String.format(IDENTICA_PROFILE, user.getString("screen_name"))))); } catch (JSONException e) { Log.e(TAG, e.toString()); onErrorExit(mServiceName); } } else { onErrorExit(mServiceName); } finish(); } }; 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(); finish(); } }); loadingDialog.show(); asyncTask.execute( mMyfeedleCrypto.Decrypt(account.getString(account.getColumnIndex(Accounts.TOKEN))), mMyfeedleCrypto.Decrypt(account.getString(account.getColumnIndex(Accounts.SECRET)))); } account.close(); break; case GOOGLEPLUS: startActivity(new Intent(Intent.ACTION_VIEW) .setData(Uri.parse(String.format(GOOGLEPLUS_PROFILE, mEsid)))); finish(); break; case PINTEREST: if (mEsid != null) startActivity(new Intent(Intent.ACTION_VIEW) .setData(Uri.parse(String.format(PINTEREST_PROFILE, mEsid)))); else startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse("https://pinterest.com"))); finish(); break; case CHATTER: account = this.getContentResolver().query(Accounts.getContentUri(StatusDialog.this), new String[] { Accounts._ID, Accounts.TOKEN }, Accounts._ID + "=?", new String[] { Long.toString(mAccount) }, null); if (account.moveToFirst()) { final ProgressDialog loadingDialog = new ProgressDialog(this); asyncTask = new AsyncTask<String, Void, String>() { @Override protected String doInBackground(String... arg0) { // need to get an instance return MyfeedleHttpClient.httpResponse( MyfeedleHttpClient.getThreadSafeClient(getApplicationContext()), new HttpPost(String.format(CHATTER_URL_ACCESS, CHATTER_KEY, arg0[0]))); } @Override protected void onPostExecute(String response) { if (loadingDialog.isShowing()) loadingDialog.dismiss(); if (response != null) { try { JSONObject jobj = new JSONObject(response); if (jobj.has("instance_url")) { startActivity(new Intent(Intent.ACTION_VIEW) .setData(Uri.parse(jobj.getString("instance_url") + "/" + mEsid))); } } catch (JSONException e) { Log.e(TAG, e.toString()); onErrorExit(mServiceName); } } else { onErrorExit(mServiceName); } finish(); } }; 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(); finish(); } }); loadingDialog.show(); asyncTask.execute( mMyfeedleCrypto.Decrypt(account.getString(account.getColumnIndex(Accounts.TOKEN)))); } account.close(); break; } break; default: if ((itemsData != null) && (which < itemsData.length) && (itemsData[which] != null)) // open link startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse(itemsData[which]))); else (Toast.makeText(this, getString(R.string.error_status), Toast.LENGTH_LONG)).show(); finish(); break; } }
From source file:com.andrewshu.android.reddit.mail.InboxActivity.java
@Override protected Dialog onCreateDialog(int id) { Dialog dialog;/* w ww. j ava 2 s . c o m*/ ProgressDialog pdialog; AlertDialog.Builder builder; LayoutInflater inflater; View layout; // used for inflated views for AlertDialog.Builder.setView() switch (id) { case Constants.DIALOG_COMPOSE: inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); builder = new AlertDialog.Builder(new ContextThemeWrapper(this, mSettings.getDialogTheme())); layout = inflater.inflate(R.layout.compose_dialog, null); dialog = builder.setView(layout).create(); final Dialog composeDialog = dialog; Common.setTextColorFromTheme(mSettings.getTheme(), getResources(), (TextView) layout.findViewById(R.id.compose_destination_textview), (TextView) layout.findViewById(R.id.compose_subject_textview), (TextView) layout.findViewById(R.id.compose_message_textview), (TextView) layout.findViewById(R.id.compose_captcha_textview), (TextView) layout.findViewById(R.id.compose_captcha_loading)); 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); composeSendButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { ThingInfo thingInfo = new ThingInfo(); if (!FormValidation.validateComposeMessageInputFields(InboxActivity.this, composeDestination, composeSubject, composeText, composeCaptcha)) return; thingInfo.setDest(composeDestination.getText().toString().trim()); thingInfo.setSubject(composeSubject.getText().toString().trim()); new MyMessageComposeTask(composeDialog, thingInfo, composeCaptcha.getText().toString().trim(), mCaptchaIden, mSettings, mClient, InboxActivity.this) .execute(composeText.getText().toString().trim()); removeDialog(Constants.DIALOG_COMPOSE); } }); composeCancelButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { removeDialog(Constants.DIALOG_COMPOSE); } }); break; case Constants.DIALOG_COMPOSING: pdialog = new ProgressDialog(new ContextThemeWrapper(this, mSettings.getDialogTheme())); pdialog.setMessage("Composing message..."); pdialog.setIndeterminate(true); pdialog.setCancelable(true); dialog = pdialog; break; default: throw new IllegalArgumentException("Unexpected dialog id " + id); } return dialog; }
From source file:com.aujur.ebookreader.activity.ReadingFragment.java
@Override public void performSearch(String query) { LOG.debug("Starting search for: " + query); final ProgressDialog searchProgress = new ProgressDialog(context); searchProgress.setOwnerActivity(getActivity()); searchProgress.setCancelable(true); searchProgress.setMax(100);// w ww .ja v a 2s.c om searchProgress.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); final SearchTextTask task = new SearchTextTask(bookView.getBook()) { int i = 0; @Override protected void onPreExecute() { super.onPreExecute(); searchProgress.setMessage(getString(R.string.search_wait)); searchProgress.show(); // Hide on-screen keyboard if it is showing InputMethodManager imm = (InputMethodManager) context .getSystemService(Activity.INPUT_METHOD_SERVICE); imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0); } @Override protected void onProgressUpdate(SearchResult... values) { if (!isAdded()) { return; } super.onProgressUpdate(values); LOG.debug("Found match at index=" + values[0].getIndex() + ", offset=" + values[0].getStart() + " with context " + values[0].getDisplay()); SearchResult res = values[0]; if (res.getDisplay() != null) { i++; String update = String.format(getString(R.string.search_hits), i); searchProgress.setMessage(update); } searchProgress.setProgress(bookView.getPercentageFor(res.getIndex(), res.getStart())); } @Override protected void onCancelled() { if (isAdded()) { Toast.makeText(context, R.string.search_cancelled, Toast.LENGTH_LONG).show(); } } protected void onPostExecute(java.util.List<SearchResult> result) { searchProgress.dismiss(); if (!isCancelled() && isAdded()) { if (result.size() > 0) { searchResults = result; searchResultWraper.setSearchResult(searchResults); // showSearchResultDialog(result); Intent intent = new Intent(getActivity(), ReadingOptionsActivity.class); Bundle bundle = new Bundle(); bundle.putInt("SELECTED_TAB", 4); intent.putExtras(bundle); startActivity(intent); } else { Toast.makeText(context, R.string.search_no_matches, Toast.LENGTH_LONG).show(); } } }; }; searchProgress.setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { task.cancel(true); } }); task.execute(query); }
From source file:com.andrewshu.android.reddit.threads.ThreadsListActivity.java
@Override protected Dialog onCreateDialog(int id) { Dialog dialog;/*from w ww . j a v a 2 s . c o m*/ ProgressDialog pdialog; AlertDialog.Builder builder; switch (id) { case Constants.DIALOG_LOGIN: dialog = new LoginDialog(this, mSettings, false) { public void onLoginChosen(String user, String password) { removeDialog(Constants.DIALOG_LOGIN); new MyLoginTask(user, password).execute(); } }; break; case Constants.DIALOG_THREAD_CLICK: dialog = new ThreadClickDialog(this, mSettings); break; case Constants.DIALOG_SORT_BY: builder = new AlertDialog.Builder(new ContextThemeWrapper(this, mSettings.getDialogTheme())); builder.setTitle("Sort by:"); builder.setSingleChoiceItems(Constants.ThreadsSort.SORT_BY_CHOICES, getSelectedSortBy(), sortByOnClickListener); dialog = builder.create(); break; case Constants.DIALOG_SORT_BY_NEW: builder = new AlertDialog.Builder(new ContextThemeWrapper(this, mSettings.getDialogTheme())); builder.setTitle("what's new"); builder.setSingleChoiceItems(Constants.ThreadsSort.SORT_BY_NEW_CHOICES, getSelectedSortByNew(), sortByNewOnClickListener); dialog = builder.create(); break; case Constants.DIALOG_SORT_BY_CONTROVERSIAL: builder = new AlertDialog.Builder(new ContextThemeWrapper(this, mSettings.getDialogTheme())); builder.setTitle("most controversial"); builder.setSingleChoiceItems(Constants.ThreadsSort.SORT_BY_CONTROVERSIAL_CHOICES, getSelectedSortByControversial(), sortByControversialOnClickListener); dialog = builder.create(); break; case Constants.DIALOG_SORT_BY_TOP: builder = new AlertDialog.Builder(new ContextThemeWrapper(this, mSettings.getDialogTheme())); builder.setTitle("top scoring"); builder.setSingleChoiceItems(Constants.ThreadsSort.SORT_BY_TOP_CHOICES, getSelectedSortByTop(), sortByTopOnClickListener); dialog = builder.create(); break; // "Please wait" 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; default: throw new IllegalArgumentException("Unexpected dialog id " + id); } return dialog; }
From source file:com.andrewshu.android.reddit.user.ProfileActivity.java
@Override protected Dialog onCreateDialog(int id) { Dialog dialog;//from ww w . ja va 2 s . co m 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) { removeDialog(Constants.DIALOG_LOGIN); new MyLoginTask(user, password).execute(); } }; break; case Constants.DIALOG_COMPOSE: inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); builder = new AlertDialog.Builder(new ContextThemeWrapper(this, mSettings.getDialogTheme())); layout = inflater.inflate(R.layout.compose_dialog, null); Common.setTextColorFromTheme(mSettings.getTheme(), getResources(), (TextView) layout.findViewById(R.id.compose_destination_textview), (TextView) layout.findViewById(R.id.compose_subject_textview), (TextView) layout.findViewById(R.id.compose_message_textview), (TextView) layout.findViewById(R.id.compose_captcha_textview), (TextView) layout.findViewById(R.id.compose_captcha_loading)); 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(); if (!FormValidation.validateComposeMessageInputFields(ProfileActivity.this, composeDestination, composeSubject, composeText, composeCaptcha)) 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()); removeDialog(Constants.DIALOG_COMPOSE); } }); composeCancelButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { removeDialog(Constants.DIALOG_COMPOSE); } }); break; case Constants.DIALOG_THREAD_CLICK: dialog = new ThreadClickDialog(this, mSettings); break; // "Please wait" 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_COMPOSING: pdialog = new ProgressDialog(new ContextThemeWrapper(this, mSettings.getDialogTheme())); pdialog.setMessage("Composing message..."); pdialog.setIndeterminate(true); pdialog.setCancelable(true); dialog = pdialog; break; default: throw new IllegalArgumentException("Unexpected dialog id " + id); } return dialog; }