List of usage examples for android.app ProgressDialog isShowing
public boolean isShowing()
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 ww w.jav a 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:com.piusvelte.sonet.core.SonetNotifications.java
@Override public boolean onContextItemSelected(final MenuItem item) { if (item.getItemId() == CLEAR) { final ProgressDialog loadingDialog = new ProgressDialog(this); final AsyncTask<Void, Void, Void> asyncTask = new AsyncTask<Void, Void, Void>() { @Override/* w ww. j a v a2 s . co m*/ protected Void doInBackground(Void... arg0) { // clear all notifications ContentValues values = new ContentValues(); values.put(Notifications.CLEARED, 1); SonetNotifications.this.getContentResolver().update( Notifications.getContentUri(SonetNotifications.this), values, Notifications._ID + "=?", new String[] { Long.toString(((AdapterContextMenuInfo) item.getMenuInfo()).id) }); return null; } @Override protected void onPostExecute(Void result) { if (loadingDialog.isShowing()) { loadingDialog.dismiss(); } SonetNotifications.this.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(); } }); loadingDialog.show(); asyncTask.execute(); } return super.onContextItemSelected(item); // clear }
From source file:com.mobicage.rogerthat.registration.RegistrationActivity2.java
private void tryConnect(final ProgressDialog pd, final int attempt, final String statusMessage, final RegistrationInfo info) { T.UI();//from www.j a v a 2s. c o m final Pausable pausable = this; if (attempt > XMPP_MAX_NUM_ATTEMPTS) { pd.dismiss(); new AlertDialog.Builder(RegistrationActivity2.this).setMessage(getString(R.string.registration_error)) .setCancelable(true).setPositiveButton(R.string.try_again, null).create().show(); mWiz.reInit(); mWiz.goBackToPrevious(); return; } pd.setMessage(statusMessage + attempt); if (!pd.isShowing()) pd.show(); L.d("Registration attempt #" + attempt); final String xmppServiceName = info.mCredentials.getXmppServiceName(); final String xmppAccount = info.mCredentials.getXmppAccount(); final String xmppPassword = info.mCredentials.getPassword(); final ConfigurationProvider cp = mService.getConfigurationProvider(); Configuration cfg = cp.getConfiguration(RegistrationWizard2.CONFIGKEY); final String invitorCode = (cfg == null) ? null : cfg.get(INVITOR_CODE_CONFIGKEY, null); final String invitorSecret = (cfg == null) ? null : cfg.get(INVITOR_SECRET_CONFIGKEY, null); Runnable runnable = new SafeRunnable() { @Override public void safeRun() { T.REGISTRATION(); try { if (CloudConstants.USE_XMPP_KICK_CHANNEL) { final ConnectionConfiguration xmppConfig = new XMPPConfigurationFactory(cp, mService.getNetworkConnectivityManager(), null) .getSafeXmppConnectionConfiguration(xmppServiceName); final XMPPConnection xmppCon = new XMPPConnection(xmppConfig); xmppCon.setLogger(new Logger() { @Override public void log(String message) { L.d(message); } }); xmppCon.connect(); xmppCon.login(xmppAccount, xmppPassword); final Thread t2 = new Thread(new SafeRunnable() { @Override protected void safeRun() throws Exception { L.d("REG Before disconnect (on separate thread) - xmpp-" + xmppCon.hashCode()); xmppCon.disconnect(); L.d("REG After disconnect (on separate thread) - xmpp-" + xmppCon.hashCode()); } }); t2.setDaemon(true); t2.start(); } postFinishRegistration(info.mCredentials.getUsername(), info.mCredentials.getPassword(), invitorCode, invitorSecret); mUIHandler.post(new SafeRunnable(pausable) { @Override protected void safeRun() throws Exception { T.UI(); mWiz.setCredentials(info.mCredentials); if (CloudConstants.USE_GCM_KICK_CHANNEL && !"".equals(mGCMRegistrationId)) { GoogleServicesUtils.saveGCMRegistrationId(mService, mGCMRegistrationId); } mService.setCredentials(mWiz.getCredentials()); mService.setRegisteredInConfig(true); final Intent launchServiceIntent = new Intent(RegistrationActivity2.this, MainService.class); launchServiceIntent.putExtra(MainService.START_INTENT_JUST_REGISTERED, true); launchServiceIntent.putExtra(MainService.START_INTENT_MY_EMAIL, mWiz.getEmail()); RegistrationActivity2.this.startService(launchServiceIntent); stopRegistrationService(); pd.dismiss(); mWiz.finish(); // finish } }); } catch (Exception e) { L.d("Exception while trying to end the registration process", e); mUIHandler.post(new SafeRunnable(pausable) { @Override protected void safeRun() throws Exception { T.UI(); tryConnect(pd, attempt + 1, statusMessage, info); } }); } } }; if (attempt == 1) { mWorkerHandler.post(runnable); } else { mWorkerHandler.postDelayed(runnable, XMPP_CHECK_DELAY_MILLIS); } }
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/*from w w w . j a va 2 s . co 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(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:com.commonsware.android.EMusicDownloader.SingleBook.java
public void sampleButtonPressed(View button) { Log.d("EMD - ", "Attempting to play sample"); if (sampleURL.contains("sample")) { final ProgressDialog dialog = ProgressDialog.show(this, "", getString(R.string.getting_sample_loation), true, true);//from ww w . j av a 2 s .c o m Thread t5 = new Thread() { public void run() { String addresstemp = ""; try { URL u = new URL(sampleURL); HttpURLConnection c = (HttpURLConnection) u.openConnection(); c.setRequestMethod("GET"); //c.setDoOutput(true); c.setFollowRedirects(true); c.setInstanceFollowRedirects(true); c.connect(); InputStream in = c.getInputStream(); InputStreamReader inputreader = new InputStreamReader(in); BufferedReader buffreader = new BufferedReader(inputreader); String line; // read every line of the file into the line-variable, on line at the time while ((line = buffreader.readLine()).length() > 0) { //Log.d("EMD - ","Read line"+line); if (line.contains(".mp3") || line.contains("samples.emusic") || line.contains("samples.nl.emusic")) { addresstemp = line; //Log.d("EMD - ","Found MP3 Address "+addresstemp); mp3Address = addresstemp; if (!vKilled && dialog.isShowing()) { handlerPlay.sendEmptyMessage(0); } if (dialog.isShowing()) { dialog.dismiss(); } } } in.close(); c.disconnect(); if (dialog.isShowing()) { dialog.dismiss(); } } catch (Exception ef) { Log.d("EMD - ", "Getting mp3 address failed "); if (dialog.isShowing()) { dialog.dismiss(); } } } }; t5.start(); } else { Toast.makeText(thisActivity, R.string.no_sample_available, Toast.LENGTH_SHORT).show(); } }
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 w w . j a v a2 s . 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(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.shafiq.myfeedle.core.MyfeedleNotifications.java
@Override public boolean onContextItemSelected(final MenuItem item) { if (item.getItemId() == CLEAR) { final ProgressDialog loadingDialog = new ProgressDialog(this); final AsyncTask<Void, Void, Void> asyncTask = new AsyncTask<Void, Void, Void>() { @Override//from w w w. jav a 2s. com protected Void doInBackground(Void... arg0) { // clear all notifications ContentValues values = new ContentValues(); values.put(Notifications.CLEARED, 1); MyfeedleNotifications.this.getContentResolver().update( Notifications.getContentUri(MyfeedleNotifications.this), values, Notifications._ID + "=?", new String[] { Long.toString(((AdapterContextMenuInfo) item.getMenuInfo()).id) }); return null; } @Override protected void onPostExecute(Void result) { if (loadingDialog.isShowing()) { loadingDialog.dismiss(); } MyfeedleNotifications.this.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(); } }); loadingDialog.show(); asyncTask.execute(); } return super.onContextItemSelected(item); // clear }
From source file:com.piusvelte.sonet.core.OAuthLogin.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setResult(RESULT_CANCELED);/* ww w. ja v a2s . c o m*/ mHttpClient = SonetHttpClient.getThreadSafeClient(getApplicationContext()); mLoadingDialog = new ProgressDialog(this); mLoadingDialog.setMessage(getString(R.string.loading)); mLoadingDialog.setCancelable(true); mLoadingDialog.setOnCancelListener(this); mLoadingDialog.setButton(ProgressDialog.BUTTON_NEGATIVE, getString(android.R.string.cancel), this); Intent intent = getIntent(); if (intent != null) { Bundle extras = intent.getExtras(); if (extras != null) { int service = extras.getInt(Sonet.Accounts.SERVICE, Sonet.INVALID_SERVICE); mServiceName = Sonet.getServiceName(getResources(), service); mWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); mAccountId = extras.getLong(Sonet.EXTRA_ACCOUNT_ID, Sonet.INVALID_ACCOUNT_ID); mSonetWebView = new SonetWebView(); final ProgressDialog loadingDialog = new ProgressDialog(this); final AsyncTask<String, Void, String> asyncTask = new AsyncTask<String, Void, String>() { @Override protected String doInBackground(String... args) { try { return mSonetOAuth.getAuthUrl(args[0], args[1], args[2], args[3], Boolean.parseBoolean(args[4]), mHttpClient); } catch (OAuthMessageSignerException e) { e.printStackTrace(); } catch (OAuthNotAuthorizedException e) { e.printStackTrace(); } catch (OAuthExpectationFailedException e) { e.printStackTrace(); } catch (OAuthCommunicationException e) { e.printStackTrace(); } return null; } @Override protected void onPostExecute(String url) { if (loadingDialog.isShowing()) loadingDialog.dismiss(); // load the webview if (url != null) { mSonetWebView.open(url); } else { (Toast.makeText(OAuthLogin.this, String.format(getString(R.string.oauth_error), mServiceName), Toast.LENGTH_LONG)).show(); OAuthLogin.this.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); dialog.cancel(); OAuthLogin.this.finish(); } }); loadingDialog.setButton(ProgressDialog.BUTTON_NEGATIVE, getString(android.R.string.cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (!asyncTask.isCancelled()) asyncTask.cancel(true); dialog.cancel(); OAuthLogin.this.finish(); } }); switch (service) { case TWITTER: mSonetOAuth = new SonetOAuth(TWITTER_KEY, TWITTER_SECRET); asyncTask.execute(String.format(TWITTER_URL_REQUEST, TWITTER_BASE_URL), String.format(TWITTER_URL_ACCESS, TWITTER_BASE_URL), String.format(TWITTER_URL_AUTHORIZE, TWITTER_BASE_URL), TWITTER_CALLBACK.toString(), Boolean.toString(true)); loadingDialog.show(); break; case FACEBOOK: mSonetWebView.open(String.format(FACEBOOK_URL_AUTHORIZE, FACEBOOK_BASE_URL, FACEBOOK_ID, FACEBOOK_CALLBACK.toString())); break; case MYSPACE: mSonetOAuth = new SonetOAuth(MYSPACE_KEY, MYSPACE_SECRET); asyncTask.execute(MYSPACE_URL_REQUEST, MYSPACE_URL_ACCESS, MYSPACE_URL_AUTHORIZE, MYSPACE_CALLBACK.toString(), Boolean.toString(true)); loadingDialog.show(); break; case FOURSQUARE: mSonetWebView.open(String.format(FOURSQUARE_URL_AUTHORIZE, FOURSQUARE_KEY, FOURSQUARE_CALLBACK.toString())); break; case LINKEDIN: mSonetOAuth = new SonetOAuth(LINKEDIN_KEY, LINKEDIN_SECRET); asyncTask.execute(LINKEDIN_URL_REQUEST, LINKEDIN_URL_ACCESS, LINKEDIN_URL_AUTHORIZE, LINKEDIN_CALLBACK.toString(), Boolean.toString(true)); loadingDialog.show(); break; case SMS: Cursor c = getContentResolver().query(Accounts.getContentUri(this), new String[] { Accounts._ID }, Accounts.SERVICE + "=?", new String[] { Integer.toString(SMS) }, null); if (c.moveToFirst()) { (Toast.makeText(OAuthLogin.this, "SMS has already been added.", Toast.LENGTH_LONG)).show(); } else { addAccount(getResources().getStringArray(R.array.service_entries)[SMS], null, null, 0, SMS, null); } c.close(); finish(); break; case RSS: // prompt for RSS url final EditText rss_url = new EditText(this); rss_url.setSingleLine(); new AlertDialog.Builder(OAuthLogin.this).setTitle(R.string.rss_url).setView(rss_url) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(final DialogInterface dialog, int which) { // test the url and add if valid, else Toast error mLoadingDialog.show(); (new AsyncTask<String, Void, String>() { String url; @Override protected String doInBackground(String... params) { url = rss_url.getText().toString(); return SonetHttpClient.httpResponse(mHttpClient, new HttpGet(url)); } @Override protected void onPostExecute(String response) { mLoadingDialog.dismiss(); if (response != null) { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db; try { db = dbf.newDocumentBuilder(); InputSource is = new InputSource(); is.setCharacterStream(new StringReader(response)); Document doc = db.parse(is); // test parsing... NodeList nodes = doc.getElementsByTagName(Sitem); if (nodes.getLength() > 0) { // check for an image NodeList images = doc.getElementsByTagName(Simage); if (images.getLength() > 0) { NodeList imageChildren = images.item(0).getChildNodes(); Node n = imageChildren.item(0); if (n.getNodeName().toLowerCase().equals(Surl)) { if (n.hasChildNodes()) { n.getChildNodes().item(0).getNodeValue(); } } } NodeList children = nodes.item(0).getChildNodes(); String date = null; String title = null; String description = null; String link = null; int values_count = 0; for (int child = 0, c2 = children.getLength(); (child < c2) && (values_count < 4); child++) { Node n = children.item(child); if (n.getNodeName().toLowerCase().equals(Spubdate)) { values_count++; if (n.hasChildNodes()) { date = n.getChildNodes().item(0).getNodeValue(); } } else if (n.getNodeName().toLowerCase() .equals(Stitle)) { values_count++; if (n.hasChildNodes()) { title = n.getChildNodes().item(0) .getNodeValue(); } } else if (n.getNodeName().toLowerCase() .equals(Sdescription)) { values_count++; if (n.hasChildNodes()) { StringBuilder sb = new StringBuilder(); NodeList descNodes = n.getChildNodes(); for (int dn = 0, dn2 = descNodes .getLength(); dn < dn2; dn++) { Node descNode = descNodes.item(dn); if (descNode .getNodeType() == Node.TEXT_NODE) { sb.append(descNode.getNodeValue()); } } // strip out the html tags description = sb.toString() .replaceAll("\\<(.|\n)*?>", ""); } } else if (n.getNodeName().toLowerCase() .equals(Slink)) { values_count++; if (n.hasChildNodes()) { link = n.getChildNodes().item(0).getNodeValue(); } } } if (Sonet.HasValues( new String[] { title, description, link, date })) { final EditText url_name = new EditText(OAuthLogin.this); url_name.setSingleLine(); new AlertDialog.Builder(OAuthLogin.this) .setTitle(R.string.rss_channel) .setView(url_name) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick( DialogInterface dialog1, int which) { addAccount( url_name.getText() .toString(), null, null, 0, RSS, url); dialog1.dismiss(); dialog.dismiss(); finish(); } }) .setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick( DialogInterface dialog1, int which) { dialog1.dismiss(); dialog.dismiss(); finish(); } }) .show(); } else { (Toast.makeText(OAuthLogin.this, "Feed is missing standard fields", Toast.LENGTH_LONG)).show(); } } else { (Toast.makeText(OAuthLogin.this, "Invalid feed", Toast.LENGTH_LONG)).show(); dialog.dismiss(); finish(); } } catch (ParserConfigurationException e) { Log.e(TAG, e.toString()); (Toast.makeText(OAuthLogin.this, "Invalid feed", Toast.LENGTH_LONG)).show(); dialog.dismiss(); finish(); } catch (SAXException e) { Log.e(TAG, e.toString()); (Toast.makeText(OAuthLogin.this, "Invalid feed", Toast.LENGTH_LONG)).show(); dialog.dismiss(); finish(); } catch (IOException e) { Log.e(TAG, e.toString()); (Toast.makeText(OAuthLogin.this, "Invalid feed", Toast.LENGTH_LONG)).show(); dialog.dismiss(); finish(); } } else { (Toast.makeText(OAuthLogin.this, "Invalid URL", Toast.LENGTH_LONG)) .show(); dialog.dismiss(); finish(); } } }).execute(rss_url.getText().toString()); } }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); finish(); } }).show(); break; case IDENTICA: mSonetOAuth = new SonetOAuth(IDENTICA_KEY, IDENTICA_SECRET); asyncTask.execute(String.format(IDENTICA_URL_REQUEST, IDENTICA_BASE_URL), String.format(IDENTICA_URL_ACCESS, IDENTICA_BASE_URL), String.format(IDENTICA_URL_AUTHORIZE, IDENTICA_BASE_URL), IDENTICA_CALLBACK.toString(), Boolean.toString(true)); loadingDialog.show(); break; case GOOGLEPLUS: mSonetWebView.open( String.format(GOOGLEPLUS_AUTHORIZE, GOOGLE_CLIENTID, "urn:ietf:wg:oauth:2.0:oob")); break; case CHATTER: mSonetWebView .open(String.format(CHATTER_URL_AUTHORIZE, CHATTER_KEY, CHATTER_CALLBACK.toString())); break; case PINTEREST: Cursor pinterestAccount = getContentResolver().query(Accounts.getContentUri(this), new String[] { Accounts._ID }, Accounts.SERVICE + "=?", new String[] { Integer.toString(PINTEREST) }, null); if (pinterestAccount.moveToFirst()) { (Toast.makeText(OAuthLogin.this, "Pinterest has already been added.", Toast.LENGTH_LONG)) .show(); } else { (Toast.makeText(OAuthLogin.this, "Pinterest currently allows only public, non-authenticated viewing.", Toast.LENGTH_LONG)).show(); String[] values = getResources().getStringArray(R.array.service_values); String[] entries = getResources().getStringArray(R.array.service_entries); for (int i = 0, l = values.length; i < l; i++) { if (Integer.toString(PINTEREST).equals(values[i])) { addAccount(entries[i], null, null, 0, PINTEREST, null); break; } } } pinterestAccount.close(); finish(); break; default: this.finish(); } } } }
From source file:com.piusvelte.sonet.OAuthLogin.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setResult(RESULT_CANCELED);/*from w ww. j a v a 2 s. c om*/ mHttpClient = SonetHttpClient.getThreadSafeClient(getApplicationContext()); mLoadingDialog = new ProgressDialog(this); mLoadingDialog.setMessage(getString(R.string.loading)); mLoadingDialog.setCancelable(true); mLoadingDialog.setOnCancelListener(this); mLoadingDialog.setButton(ProgressDialog.BUTTON_NEGATIVE, getString(android.R.string.cancel), this); Intent intent = getIntent(); if (intent != null) { Bundle extras = intent.getExtras(); if (extras != null) { int service = extras.getInt(Sonet.Accounts.SERVICE, Sonet.INVALID_SERVICE); mServiceName = Sonet.getServiceName(getResources(), service); mWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); mAccountId = extras.getLong(Sonet.EXTRA_ACCOUNT_ID, Sonet.INVALID_ACCOUNT_ID); mSonetWebView = new SonetWebView(); final ProgressDialog loadingDialog = new ProgressDialog(this); final AsyncTask<String, Void, String> asyncTask = new AsyncTask<String, Void, String>() { @Override protected String doInBackground(String... args) { try { return mSonetOAuth.getAuthUrl(args[0], args[1], args[2], args[3], Boolean.parseBoolean(args[4]), mHttpClient); } catch (OAuthMessageSignerException e) { e.printStackTrace(); } catch (OAuthNotAuthorizedException e) { e.printStackTrace(); } catch (OAuthExpectationFailedException e) { e.printStackTrace(); } catch (OAuthCommunicationException e) { e.printStackTrace(); } return null; } @Override protected void onPostExecute(String url) { if (loadingDialog.isShowing()) loadingDialog.dismiss(); // load the webview if (url != null) { mSonetWebView.open(url); } else { (Toast.makeText(OAuthLogin.this, String.format(getString(R.string.oauth_error), mServiceName), Toast.LENGTH_LONG)).show(); OAuthLogin.this.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); dialog.cancel(); OAuthLogin.this.finish(); } }); loadingDialog.setButton(ProgressDialog.BUTTON_NEGATIVE, getString(android.R.string.cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (!asyncTask.isCancelled()) asyncTask.cancel(true); dialog.cancel(); OAuthLogin.this.finish(); } }); switch (service) { case TWITTER: mSonetOAuth = new SonetOAuth(BuildConfig.TWITTER_KEY, BuildConfig.TWITTER_SECRET); asyncTask.execute(String.format(TWITTER_URL_REQUEST, TWITTER_BASE_URL), String.format(TWITTER_URL_ACCESS, TWITTER_BASE_URL), String.format(TWITTER_URL_AUTHORIZE, TWITTER_BASE_URL), TWITTER_CALLBACK.toString(), Boolean.toString(true)); loadingDialog.show(); break; case FACEBOOK: mSonetWebView.open(String.format(FACEBOOK_URL_AUTHORIZE, FACEBOOK_BASE_URL, BuildConfig.FACEBOOK_ID, FACEBOOK_CALLBACK.toString())); break; case MYSPACE: mSonetOAuth = new SonetOAuth(BuildConfig.MYSPACE_KEY, BuildConfig.MYSPACE_SECRET); asyncTask.execute(MYSPACE_URL_REQUEST, MYSPACE_URL_ACCESS, MYSPACE_URL_AUTHORIZE, MYSPACE_CALLBACK.toString(), Boolean.toString(true)); loadingDialog.show(); break; case FOURSQUARE: mSonetWebView.open(String.format(FOURSQUARE_URL_AUTHORIZE, BuildConfig.FOURSQUARE_KEY, FOURSQUARE_CALLBACK.toString())); break; case LINKEDIN: mSonetOAuth = new SonetOAuth(BuildConfig.LINKEDIN_KEY, BuildConfig.LINKEDIN_SECRET); asyncTask.execute(LINKEDIN_URL_REQUEST, LINKEDIN_URL_ACCESS, LINKEDIN_URL_AUTHORIZE, LINKEDIN_CALLBACK.toString(), Boolean.toString(true)); loadingDialog.show(); break; case SMS: Cursor c = getContentResolver().query(Accounts.getContentUri(this), new String[] { Accounts._ID }, Accounts.SERVICE + "=?", new String[] { Integer.toString(SMS) }, null); if (c.moveToFirst()) { (Toast.makeText(OAuthLogin.this, "SMS has already been added.", Toast.LENGTH_LONG)).show(); } else { addAccount(getResources().getStringArray(R.array.service_entries)[SMS], null, null, 0, SMS, null); } c.close(); finish(); break; case RSS: // prompt for RSS url final EditText rss_url = new EditText(this); rss_url.setSingleLine(); new AlertDialog.Builder(OAuthLogin.this).setTitle(R.string.rss_url).setView(rss_url) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(final DialogInterface dialog, int which) { // test the url and add if valid, else Toast error mLoadingDialog.show(); (new AsyncTask<String, Void, String>() { String url; @Override protected String doInBackground(String... params) { url = rss_url.getText().toString(); return SonetHttpClient.httpResponse(mHttpClient, new HttpGet(url)); } @Override protected void onPostExecute(String response) { mLoadingDialog.dismiss(); if (response != null) { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db; try { db = dbf.newDocumentBuilder(); InputSource is = new InputSource(); is.setCharacterStream(new StringReader(response)); Document doc = db.parse(is); // test parsing... NodeList nodes = doc.getElementsByTagName(Sitem); if (nodes.getLength() > 0) { // check for an image NodeList images = doc.getElementsByTagName(Simage); if (images.getLength() > 0) { NodeList imageChildren = images.item(0).getChildNodes(); Node n = imageChildren.item(0); if (n.getNodeName().toLowerCase().equals(Surl)) { if (n.hasChildNodes()) { n.getChildNodes().item(0).getNodeValue(); } } } NodeList children = nodes.item(0).getChildNodes(); String date = null; String title = null; String description = null; String link = null; int values_count = 0; for (int child = 0, c2 = children.getLength(); (child < c2) && (values_count < 4); child++) { Node n = children.item(child); if (n.getNodeName().toLowerCase().equals(Spubdate)) { values_count++; if (n.hasChildNodes()) { date = n.getChildNodes().item(0).getNodeValue(); } } else if (n.getNodeName().toLowerCase() .equals(Stitle)) { values_count++; if (n.hasChildNodes()) { title = n.getChildNodes().item(0) .getNodeValue(); } } else if (n.getNodeName().toLowerCase() .equals(Sdescription)) { values_count++; if (n.hasChildNodes()) { StringBuilder sb = new StringBuilder(); NodeList descNodes = n.getChildNodes(); for (int dn = 0, dn2 = descNodes .getLength(); dn < dn2; dn++) { Node descNode = descNodes.item(dn); if (descNode .getNodeType() == Node.TEXT_NODE) { sb.append(descNode.getNodeValue()); } } // strip out the html tags description = sb.toString() .replaceAll("\\<(.|\n)*?>", ""); } } else if (n.getNodeName().toLowerCase() .equals(Slink)) { values_count++; if (n.hasChildNodes()) { link = n.getChildNodes().item(0).getNodeValue(); } } } if (Sonet.HasValues( new String[] { title, description, link, date })) { final EditText url_name = new EditText(OAuthLogin.this); url_name.setSingleLine(); new AlertDialog.Builder(OAuthLogin.this) .setTitle(R.string.rss_channel) .setView(url_name) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick( DialogInterface dialog1, int which) { addAccount( url_name.getText() .toString(), null, null, 0, RSS, url); dialog1.dismiss(); dialog.dismiss(); finish(); } }) .setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick( DialogInterface dialog1, int which) { dialog1.dismiss(); dialog.dismiss(); finish(); } }) .show(); } else { (Toast.makeText(OAuthLogin.this, "Feed is missing standard fields", Toast.LENGTH_LONG)).show(); } } else { (Toast.makeText(OAuthLogin.this, "Invalid feed", Toast.LENGTH_LONG)).show(); dialog.dismiss(); finish(); } } catch (ParserConfigurationException e) { Log.e(TAG, e.toString()); (Toast.makeText(OAuthLogin.this, "Invalid feed", Toast.LENGTH_LONG)).show(); dialog.dismiss(); finish(); } catch (SAXException e) { Log.e(TAG, e.toString()); (Toast.makeText(OAuthLogin.this, "Invalid feed", Toast.LENGTH_LONG)).show(); dialog.dismiss(); finish(); } catch (IOException e) { Log.e(TAG, e.toString()); (Toast.makeText(OAuthLogin.this, "Invalid feed", Toast.LENGTH_LONG)).show(); dialog.dismiss(); finish(); } } else { (Toast.makeText(OAuthLogin.this, "Invalid URL", Toast.LENGTH_LONG)) .show(); dialog.dismiss(); finish(); } } }).execute(rss_url.getText().toString()); } }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); finish(); } }).show(); break; case IDENTICA: mSonetOAuth = new SonetOAuth(BuildConfig.IDENTICA_KEY, BuildConfig.IDENTICA_SECRET); asyncTask.execute(String.format(IDENTICA_URL_REQUEST, IDENTICA_BASE_URL), String.format(IDENTICA_URL_ACCESS, IDENTICA_BASE_URL), String.format(IDENTICA_URL_AUTHORIZE, IDENTICA_BASE_URL), IDENTICA_CALLBACK.toString(), Boolean.toString(true)); loadingDialog.show(); break; case GOOGLEPLUS: mSonetWebView.open(String.format(GOOGLEPLUS_AUTHORIZE, BuildConfig.GOOGLECLIENT_ID, "urn:ietf:wg:oauth:2.0:oob")); break; case CHATTER: mSonetWebView.open(String.format(CHATTER_URL_AUTHORIZE, BuildConfig.CHATTER_KEY, CHATTER_CALLBACK.toString())); break; case PINTEREST: Cursor pinterestAccount = getContentResolver().query(Accounts.getContentUri(this), new String[] { Accounts._ID }, Accounts.SERVICE + "=?", new String[] { Integer.toString(PINTEREST) }, null); if (pinterestAccount.moveToFirst()) { (Toast.makeText(OAuthLogin.this, "Pinterest has already been added.", Toast.LENGTH_LONG)) .show(); } else { (Toast.makeText(OAuthLogin.this, "Pinterest currently allows only public, non-authenticated viewing.", Toast.LENGTH_LONG)).show(); String[] values = getResources().getStringArray(R.array.service_values); String[] entries = getResources().getStringArray(R.array.service_entries); for (int i = 0, l = values.length; i < l; i++) { if (Integer.toString(PINTEREST).equals(values[i])) { addAccount(entries[i], null, null, 0, PINTEREST, null); break; } } } pinterestAccount.close(); finish(); break; default: this.finish(); } } } }
From source file:com.shafiq.myfeedle.core.OAuthLogin.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setResult(RESULT_CANCELED);/* w ww . jav a2s .c om*/ mHttpClient = MyfeedleHttpClient.getThreadSafeClient(getApplicationContext()); mLoadingDialog = new ProgressDialog(this); mLoadingDialog.setMessage(getString(R.string.loading)); mLoadingDialog.setCancelable(true); mLoadingDialog.setOnCancelListener(this); mLoadingDialog.setButton(ProgressDialog.BUTTON_NEGATIVE, getString(android.R.string.cancel), this); Intent intent = getIntent(); if (intent != null) { Bundle extras = intent.getExtras(); if (extras != null) { int service = extras.getInt(Myfeedle.Accounts.SERVICE, Myfeedle.INVALID_SERVICE); mServiceName = Myfeedle.getServiceName(getResources(), service); mWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); mAccountId = extras.getLong(Myfeedle.EXTRA_ACCOUNT_ID, Myfeedle.INVALID_ACCOUNT_ID); mMyfeedleWebView = new MyfeedleWebView(); final ProgressDialog loadingDialog = new ProgressDialog(this); final AsyncTask<String, Void, String> asyncTask = new AsyncTask<String, Void, String>() { @Override protected String doInBackground(String... args) { try { return mMyfeedleOAuth.getAuthUrl(args[0], args[1], args[2], args[3], Boolean.parseBoolean(args[4]), mHttpClient); } catch (OAuthMessageSignerException e) { e.printStackTrace(); } catch (OAuthNotAuthorizedException e) { e.printStackTrace(); } catch (OAuthExpectationFailedException e) { e.printStackTrace(); } catch (OAuthCommunicationException e) { e.printStackTrace(); } return null; } @Override protected void onPostExecute(String url) { if (loadingDialog.isShowing()) loadingDialog.dismiss(); // load the webview if (url != null) { mMyfeedleWebView.open(url); } else { (Toast.makeText(OAuthLogin.this, String.format(getString(R.string.oauth_error), mServiceName), Toast.LENGTH_LONG)).show(); OAuthLogin.this.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); dialog.cancel(); OAuthLogin.this.finish(); } }); loadingDialog.setButton(ProgressDialog.BUTTON_NEGATIVE, getString(android.R.string.cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (!asyncTask.isCancelled()) asyncTask.cancel(true); dialog.cancel(); OAuthLogin.this.finish(); } }); switch (service) { case TWITTER: mMyfeedleOAuth = new MyfeedleOAuth(TWITTER_KEY, TWITTER_SECRET); asyncTask.execute(String.format(TWITTER_URL_REQUEST, TWITTER_BASE_URL), String.format(TWITTER_URL_ACCESS, TWITTER_BASE_URL), String.format(TWITTER_URL_AUTHORIZE, TWITTER_BASE_URL), TWITTER_CALLBACK.toString(), Boolean.toString(true)); loadingDialog.show(); break; case FACEBOOK: mMyfeedleWebView.open(String.format(FACEBOOK_URL_AUTHORIZE, FACEBOOK_BASE_URL, FACEBOOK_ID, FACEBOOK_CALLBACK.toString())); break; // case MYSPACE: // mMyfeedleOAuth = new MyfeedleOAuth(MYSPACE_KEY, MYSPACE_SECRET); // asyncTask.execute(MYSPACE_URL_REQUEST, MYSPACE_URL_ACCESS, MYSPACE_URL_AUTHORIZE, MYSPACE_CALLBACK.toString(), Boolean.toString(true)); // loadingDialog.show(); // break; case FOURSQUARE: mMyfeedleWebView.open(String.format(FOURSQUARE_URL_AUTHORIZE, FOURSQUARE_KEY, FOURSQUARE_CALLBACK.toString())); break; case LINKEDIN: mMyfeedleOAuth = new MyfeedleOAuth(LINKEDIN_KEY, LINKEDIN_SECRET); asyncTask.execute(LINKEDIN_URL_REQUEST, LINKEDIN_URL_ACCESS, LINKEDIN_URL_AUTHORIZE, LINKEDIN_CALLBACK.toString(), Boolean.toString(true)); loadingDialog.show(); break; case SMS: Cursor c = getContentResolver().query(Accounts.getContentUri(this), new String[] { Accounts._ID }, Accounts.SERVICE + "=?", new String[] { Integer.toString(SMS) }, null); if (c.moveToFirst()) { (Toast.makeText(OAuthLogin.this, "SMS has already been added.", Toast.LENGTH_LONG)).show(); } else { addAccount(getResources().getStringArray(R.array.service_entries)[SMS], null, null, 0, SMS, null); } c.close(); finish(); break; case RSS: // prompt for RSS url final EditText rss_url = new EditText(this); rss_url.setSingleLine(); new AlertDialog.Builder(OAuthLogin.this).setTitle(R.string.rss_url).setView(rss_url) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(final DialogInterface dialog, int which) { // test the url and add if valid, else Toast error mLoadingDialog.show(); (new AsyncTask<String, Void, String>() { String url; @Override protected String doInBackground(String... params) { url = rss_url.getText().toString(); return MyfeedleHttpClient.httpResponse(mHttpClient, new HttpGet(url)); } @Override protected void onPostExecute(String response) { mLoadingDialog.dismiss(); if (response != null) { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db; try { db = dbf.newDocumentBuilder(); InputSource is = new InputSource(); is.setCharacterStream(new StringReader(response)); Document doc = db.parse(is); // test parsing... NodeList nodes = doc.getElementsByTagName(Sitem); if (nodes.getLength() > 0) { // check for an image NodeList images = doc.getElementsByTagName(Simage); if (images.getLength() > 0) { NodeList imageChildren = images.item(0).getChildNodes(); Node n = imageChildren.item(0); if (n.getNodeName().toLowerCase().equals(Surl)) { if (n.hasChildNodes()) { n.getChildNodes().item(0).getNodeValue(); } } } NodeList children = nodes.item(0).getChildNodes(); String date = null; String title = null; String description = null; String link = null; int values_count = 0; for (int child = 0, c2 = children.getLength(); (child < c2) && (values_count < 4); child++) { Node n = children.item(child); if (n.getNodeName().toLowerCase().equals(Spubdate)) { values_count++; if (n.hasChildNodes()) { date = n.getChildNodes().item(0).getNodeValue(); } } else if (n.getNodeName().toLowerCase() .equals(Stitle)) { values_count++; if (n.hasChildNodes()) { title = n.getChildNodes().item(0) .getNodeValue(); } } else if (n.getNodeName().toLowerCase() .equals(Sdescription)) { values_count++; if (n.hasChildNodes()) { StringBuilder sb = new StringBuilder(); NodeList descNodes = n.getChildNodes(); for (int dn = 0, dn2 = descNodes .getLength(); dn < dn2; dn++) { Node descNode = descNodes.item(dn); if (descNode .getNodeType() == Node.TEXT_NODE) { sb.append(descNode.getNodeValue()); } } // strip out the html tags description = sb.toString() .replaceAll("\\<(.|\n)*?>", ""); } } else if (n.getNodeName().toLowerCase() .equals(Slink)) { values_count++; if (n.hasChildNodes()) { link = n.getChildNodes().item(0).getNodeValue(); } } } if (Myfeedle.HasValues( new String[] { title, description, link, date })) { final EditText url_name = new EditText(OAuthLogin.this); url_name.setSingleLine(); new AlertDialog.Builder(OAuthLogin.this) .setTitle(R.string.rss_channel) .setView(url_name) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick( DialogInterface dialog1, int which) { addAccount( url_name.getText() .toString(), null, null, 0, RSS, url); dialog1.dismiss(); dialog.dismiss(); finish(); } }) .setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick( DialogInterface dialog1, int which) { dialog1.dismiss(); dialog.dismiss(); finish(); } }) .show(); } else { (Toast.makeText(OAuthLogin.this, "Feed is missing standard fields", Toast.LENGTH_LONG)).show(); } } else { (Toast.makeText(OAuthLogin.this, "Invalid feed", Toast.LENGTH_LONG)).show(); dialog.dismiss(); finish(); } } catch (ParserConfigurationException e) { Log.e(TAG, e.toString()); (Toast.makeText(OAuthLogin.this, "Invalid feed", Toast.LENGTH_LONG)).show(); dialog.dismiss(); finish(); } catch (SAXException e) { Log.e(TAG, e.toString()); (Toast.makeText(OAuthLogin.this, "Invalid feed", Toast.LENGTH_LONG)).show(); dialog.dismiss(); finish(); } catch (IOException e) { Log.e(TAG, e.toString()); (Toast.makeText(OAuthLogin.this, "Invalid feed", Toast.LENGTH_LONG)).show(); dialog.dismiss(); finish(); } } else { (Toast.makeText(OAuthLogin.this, "Invalid URL", Toast.LENGTH_LONG)) .show(); dialog.dismiss(); finish(); } } }).execute(rss_url.getText().toString()); } }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); finish(); } }).show(); break; // case IDENTICA: // mMyfeedleOAuth = new MyfeedleOAuth(IDENTICA_KEY, IDENTICA_SECRET); // asyncTask.execute(String.format(IDENTICA_URL_REQUEST, IDENTICA_BASE_URL), String.format(IDENTICA_URL_ACCESS, IDENTICA_BASE_URL), String.format(IDENTICA_URL_AUTHORIZE, IDENTICA_BASE_URL), IDENTICA_CALLBACK.toString(), Boolean.toString(true)); // loadingDialog.show(); // break; case GOOGLEPLUS: mMyfeedleWebView.open( String.format(GOOGLEPLUS_AUTHORIZE, GOOGLE_CLIENTID, "urn:ietf:wg:oauth:2.0:oob")); break; // case CHATTER: // mMyfeedleWebView.open(String.format(CHATTER_URL_AUTHORIZE, CHATTER_KEY, CHATTER_CALLBACK.toString())); // break; case PINTEREST: Cursor pinterestAccount = getContentResolver().query(Accounts.getContentUri(this), new String[] { Accounts._ID }, Accounts.SERVICE + "=?", new String[] { Integer.toString(PINTEREST) }, null); if (pinterestAccount.moveToFirst()) { (Toast.makeText(OAuthLogin.this, "Pinterest has already been added.", Toast.LENGTH_LONG)) .show(); } else { (Toast.makeText(OAuthLogin.this, "Pinterest currently allows only public, non-authenticated viewing.", Toast.LENGTH_LONG)).show(); String[] values = getResources().getStringArray(R.array.service_values); String[] entries = getResources().getStringArray(R.array.service_entries); for (int i = 0, l = values.length; i < l; i++) { if (Integer.toString(PINTEREST).equals(values[i])) { addAccount(entries[i], null, null, 0, PINTEREST, null); break; } } } pinterestAccount.close(); finish(); break; default: this.finish(); } } } }