List of usage examples for android.database Cursor isAfterLast
boolean isAfterLast();
From source file:edu.stanford.mobisocial.dungbeetle.DBHelper.java
public Map<Long, byte[]> getPublicKeyPrintSharedSecretMap() { HashMap<Long, byte[]> key_ss = new HashMap<Long, byte[]>(); Cursor c = getReadableDatabase().query(Contact.TABLE, new String[] { Contact._ID, Contact.PUBLIC_KEY_HASH_64, Contact.SHARED_SECRET }, null, null, null, null, null);/*from w ww . ja va 2 s. c o m*/ c.moveToFirst(); while (!c.isAfterLast()) { long pk = c.getLong(1); byte[] ss = c.getBlob(2); if (ss == null) { Contact contact; try { contact = contactForContactId(c.getLong(0)).get(); ss = SharedSecretObj.getOrPushSecret(mContext, contact); } catch (NoValError e) { e.printStackTrace(); } } key_ss.put(pk, ss); c.moveToNext(); } c.close(); return key_ss; }
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 www . j av a2 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(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.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/*w w w .j a va 2 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(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:edu.stanford.mobisocial.dungbeetle.DBHelper.java
private long getFeedLastVisibleId(String feedName) { String[] types = DbObjects.getRenderableTypes(); StringBuffer allowed = new StringBuffer(); for (String type : types) { allowed.append(",'").append(type).append("'"); }// ww w. jav a 2 s . c om String visibleTypes = DbObject.TYPE + " in (" + allowed.substring(1) + ")"; String selection = DbObject.FEED_NAME + " = ?"; selection = andClauses(selection, visibleTypes); Cursor c = getReadableDatabase().query(DbObject.TABLE, new String[] { DbObject._ID }, selection, new String[] { feedName }, null, null, DbObject.SEQUENCE_ID + " DESC LIMIT 1"); try { c.moveToFirst(); if (!c.isAfterLast()) { long max = c.getLong(0); return max; } return -1; } finally { c.close(); } }
From source file:org.globalquakemodel.org.idctdo.EQForm_MapView.java
private void loadPrevSurveyPoints() { if (DEBUG_LOG) Log.d(TAG, "loading PREVIOUS survey points"); mDbHelper = new GemDbAdapter(getBaseContext()); mDbHelper.createDatabase();/*from w ww . j a v a2s . c o m*/ mDbHelper.open(); Cursor mCursor = mDbHelper.getGemObjectsForMap(); mDbHelper.close(); //if (DEBUG_LOG) Log.d("IDCT","Gem Map Objects cursor " + DatabaseUtils.dumpCursorToString(mCursor)); //ArrayList<DBRecord> gemObjectsList = GemUtilities.cursorToArrayList(gemObjects); //Log.d("IDCT","Gem Map Objects List " + gemObjectsList.get(gemObjectsList.size()-1)); mCursor.moveToFirst(); mWebView.loadUrl("javascript:clearMySurveyPoints()");//Inefficient while (!mCursor.isAfterLast()) { //if (DEBUG_LOG) Log.d("IDCT","Gem Map Objects cursor " + mCursor.getDouble(1) + " , " + mCursor.getDouble(2) + " , " + mCursor.getString(0)); mWebView.loadUrl("javascript:loadSurveyPointsOnMap(" + mCursor.getDouble(1) + "," + mCursor.getDouble(2) + ", \"" + mCursor.getString(0) + "\")"); mCursor.moveToNext(); } mCursor.close(); }
From source file:com.jsonstore.api.JSONStoreCollection.java
/** * Change a list of documents in the collection. * @param data// ww w .j av a 2 s . c o m * A list of data to update documents in the collection or add (if addNew * option is enabled). * @param options * Optional change options that are used to manipulate the change operation. * @return The total number of documents that are changed or added. * @throws JSONStoreChangeException * An exception occurred when performing the change operation, and the * operation failed. * @throws JSONStoreDatabaseClosedException * The JSONStore database is closed and cannot be accessed to execute * the change operation. */ public int changeData(List<JSONObject> data, JSONStoreChangeOptions options) throws JSONStoreChangeException, JSONStoreDatabaseClosedException { JSONStoreAnalyticsLogInstance logInst = JSONStoreLogger.startAnalyticsInstance(getUsername(), getName(), JSONStoreLogger.OPERATION_CHANGE); try { getAccessor(); //This does some closed checks if (options == null) options = new JSONStoreChangeOptions(); if (data == null) { return 0; } try { int changeCount = 0; if (!initializedJSONStoreInstance.isTransactionInProgress()) { synchronized (getAccessor()) { getAccessor().getRawDatabase().beginTransaction(); } } List<String> replaceCriteria = options.getSearchFieldCriteria(); if (replaceCriteria == null || replaceCriteria.size() == 0) { replaceCriteria = new LinkedList<String>(); } //Check to make sure the replaceCriteria are search keys/additional search keys for (String replaceKey : replaceCriteria) { if (!getSearchFields().containsKey(replaceKey.toLowerCase(Locale.ENGLISH)) && !getAdditionalSearchFields().containsKey(replaceKey.toLowerCase(Locale.ENGLISH)) && !getSearchFields().containsKey(replaceKey) && !getAdditionalSearchFields().containsKey(replaceKey)) { String message = "Replace criteria '" + replaceKey + "' must be a search field or additional search field."; JSONStoreChangeException jsException = new JSONStoreChangeException(message); logger.logError(message, jsException); throw jsException; } } List<JSONObject> allReplaceObjects = new LinkedList<JSONObject>(); List<JSONObject> allAddObjects = new LinkedList<JSONObject>(); for (JSONObject currentData : data) { // Build a select against this document. JSONStoreQueryParts queryContent = new JSONStoreQueryParts(); JSONStoreQueryPart queryContentPart = new JSONStoreQueryPart(); for (String criteria : replaceCriteria) { if (currentData.has(criteria)) { Object val = currentData.get(criteria); if (val instanceof Boolean) val = (Boolean) val ? 1 : 0; queryContentPart.addEqual(criteria, val.toString()); } } queryContent.addQueryPart(queryContentPart); QueryBuilderSelect selectQuery = new QueryBuilderSelect(this, queryContent); selectQuery.addSelectStatement(DatabaseConstants.FIELD_ID, false); Cursor allDocIds = runQuery(selectQuery); if (allDocIds != null) { if (allDocIds.getCount() <= 0 || replaceCriteria.size() == 0) { allAddObjects.add(currentData); } else { allDocIds.moveToFirst(); for (int i = 0; i < allDocIds.getCount() && !allDocIds.isAfterLast(); ++i) { int idIndex = allDocIds.getColumnIndex(DatabaseConstants.FIELD_ID); int replaceId = allDocIds.getInt(idIndex); JSONObject fullUpdateDoc = new JSONObject(); fullUpdateDoc.put(DatabaseConstants.FIELD_JSON, currentData); fullUpdateDoc.put(DatabaseConstants.FIELD_ID, replaceId); allReplaceObjects.add(fullUpdateDoc); allDocIds.moveToNext(); } } allDocIds.close(); } } JSONStoreReplaceOptions replaceOptions = new JSONStoreReplaceOptions(); replaceOptions.setMarkDirty(options.isMarkDirty()); for (JSONObject doc : allReplaceObjects) { try { if (replaceCriteria.size() != 0) { this.replaceDocument(doc, replaceOptions); changeCount++; } } catch (JSONStoreReplaceException e) { String message = "Failed to replace an existing document."; JSONStoreChangeException jsException = new JSONStoreChangeException(message, e); logger.logError(message, jsException); throw jsException; } } JSONStoreAddOptions addOptions = new JSONStoreAddOptions(); addOptions.setMarkDirty(options.isMarkDirty()); if (options.isAddNew()) { for (JSONObject doc : allAddObjects) { try { this.addData(doc, addOptions); changeCount++; } catch (JSONStoreAddException e) { String message = "Failed to add a new document."; JSONStoreChangeException jsException = new JSONStoreChangeException(message, e); logger.logError(message, jsException); throw jsException; } } } if (!initializedJSONStoreInstance.isTransactionInProgress()) { synchronized (getAccessor()) { getAccessor().getRawDatabase().setTransactionSuccessful(); getAccessor().getRawDatabase().endTransaction(); } } return changeCount; } catch (Throwable e) { if (!initializedJSONStoreInstance.isTransactionInProgress()) { synchronized (getAccessor()) { getAccessor().getRawDatabase().endTransaction(); } } throw new JSONStoreChangeException(e); } } finally { logInst.end(); } }
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// ww w . jav a2 s .c om (Toast.makeText(this, getString(R.string.error_status), Toast.LENGTH_LONG)).show(); dialog.cancel(); finish(); break; case POST: if (mAppWidgetId != -1) { if (mService == GOOGLEPLUS) startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse("https://plus.google.com"))); else if (mService == PINTEREST) startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse("https://pinterest.com"))); else startActivity(Myfeedle.getPackageIntent(this, MyfeedleCreatePost.class).setData(Uri .withAppendedPath(Accounts.getContentUri(StatusDialog.this), Long.toString(mAccount)))); dialog.cancel(); finish(); } else { // no widget sent in, dialog to select one String[] widgets = getAllWidgets(); if (widgets.length > 0) { mDialog = (new AlertDialog.Builder(this)).setItems(widgets, new OnClickListener() { @Override public void onClick(DialogInterface arg0, int arg1) { // no account, dialog to select one // don't limit accounts to the widget Cursor c = StatusDialog.this.getContentResolver().query( Accounts.getContentUri(StatusDialog.this), new String[] { Accounts._ID, ACCOUNTS_QUERY }, null, null, null); if (c.moveToFirst()) { int iid = c.getColumnIndex(Accounts._ID), iusername = c.getColumnIndex(Accounts.USERNAME), i = 0; final long[] accountIndexes = new long[c.getCount()]; final String[] accounts = new String[c.getCount()]; while (!c.isAfterLast()) { long id = c.getLong(iid); accountIndexes[i] = id; accounts[i++] = c.getString(iusername); c.moveToNext(); } arg0.cancel(); mDialog = (new AlertDialog.Builder(StatusDialog.this)).setTitle(R.string.accounts) .setSingleChoiceItems(accounts, -1, new OnClickListener() { @Override public void onClick(DialogInterface arg0, int which) { startActivity(Myfeedle .getPackageIntent(StatusDialog.this, MyfeedleCreatePost.class) .setData(Uri.withAppendedPath( Accounts.getContentUri(StatusDialog.this), Long.toString(accountIndexes[which])))); arg0.cancel(); } }).setCancelable(true).setOnCancelListener(new OnCancelListener() { @Override public void onCancel(DialogInterface arg0) { dialog.cancel(); } }).create(); mDialog.show(); } else { (Toast.makeText(StatusDialog.this, getString(R.string.error_status), Toast.LENGTH_LONG)).show(); dialog.cancel(); } c.close(); finish(); } }).setCancelable(true).setOnCancelListener(new OnCancelListener() { @Override public void onCancel(DialogInterface arg0) { dialog.cancel(); finish(); } }).create(); mDialog.show(); } else { (Toast.makeText(this, getString(R.string.error_status), Toast.LENGTH_LONG)).show(); dialog.cancel(); finish(); } } break; case SETTINGS: if (mAppWidgetId != -1) { startActivity(Myfeedle.getPackageIntent(this, ManageAccounts.class) .putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId)); dialog.cancel(); finish(); } else { // no widget sent in, dialog to select one String[] widgets = getAllWidgets(); if (widgets.length > 0) { mDialog = (new AlertDialog.Builder(this)).setItems(widgets, new OnClickListener() { @Override public void onClick(DialogInterface arg0, int arg1) { startActivity(Myfeedle.getPackageIntent(StatusDialog.this, ManageAccounts.class) .putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetIds[arg1])); arg0.cancel(); finish(); } }).setCancelable(true).setOnCancelListener(new OnCancelListener() { @Override public void onCancel(DialogInterface arg0) { dialog.cancel(); finish(); } }).create(); mDialog.show(); } else { (Toast.makeText(this, getString(R.string.error_status), Toast.LENGTH_LONG)).show(); dialog.cancel(); finish(); } } break; case NOTIFICATIONS: startActivity(Myfeedle.getPackageIntent(this, MyfeedleNotifications.class)); dialog.cancel(); finish(); break; case REFRESH: if (mAppWidgetId != -1) { (Toast.makeText(getApplicationContext(), getString(R.string.refreshing), Toast.LENGTH_LONG)).show(); startService(Myfeedle.getPackageIntent(this, MyfeedleService.class).setAction(ACTION_REFRESH) .putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, new int[] { mAppWidgetId })); dialog.cancel(); } else { // no widget sent in, dialog to select one String[] widgets = getAllWidgets(); if (widgets.length > 0) { mDialog = (new AlertDialog.Builder(this)).setItems(widgets, new OnClickListener() { @Override public void onClick(DialogInterface arg0, int arg1) { (Toast.makeText(StatusDialog.this.getApplicationContext(), getString(R.string.refreshing), Toast.LENGTH_LONG)).show(); startService(Myfeedle.getPackageIntent(StatusDialog.this, MyfeedleService.class) .setAction(ACTION_REFRESH).putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, new int[] { mAppWidgetIds[arg1] })); arg0.cancel(); finish(); } }).setPositiveButton(R.string.refreshallwidgets, new OnClickListener() { @Override public void onClick(DialogInterface arg0, int which) { // refresh all (Toast.makeText(StatusDialog.this.getApplicationContext(), getString(R.string.refreshing), Toast.LENGTH_LONG)).show(); startService(Myfeedle.getPackageIntent(StatusDialog.this, MyfeedleService.class) .putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, mAppWidgetIds)); arg0.cancel(); finish(); } }).setCancelable(true).setOnCancelListener(new OnCancelListener() { @Override public void onCancel(DialogInterface arg0) { dialog.cancel(); finish(); } }).create(); mDialog.show(); } else { dialog.cancel(); finish(); } } break; case PROFILE: Cursor account; final AsyncTask<String, Void, String> asyncTask; // get the resources switch (mService) { case TWITTER: account = this.getContentResolver().query(Accounts.getContentUri(StatusDialog.this), new String[] { Accounts._ID, Accounts.TOKEN, Accounts.SECRET }, Accounts._ID + "=?", new String[] { Long.toString(mAccount) }, null); if (account.moveToFirst()) { final ProgressDialog loadingDialog = new ProgressDialog(this); asyncTask = new AsyncTask<String, Void, String>() { @Override protected String doInBackground(String... arg0) { MyfeedleOAuth myfeedleOAuth = new MyfeedleOAuth(TWITTER_KEY, TWITTER_SECRET, arg0[0], arg0[1]); return MyfeedleHttpClient.httpResponse( MyfeedleHttpClient.getThreadSafeClient(getApplicationContext()), myfeedleOAuth.getSignedRequest( new HttpGet(String.format(TWITTER_USER, TWITTER_BASE_URL, mEsid)))); } @Override protected void onPostExecute(String response) { if (loadingDialog.isShowing()) loadingDialog.dismiss(); if (response != null) { try { JSONObject user = new JSONObject(response); startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri .parse(String.format(TWITTER_PROFILE, user.getString("screen_name"))))); } catch (JSONException e) { Log.e(TAG, e.toString()); onErrorExit(mServiceName); } } else { onErrorExit(mServiceName); } finish(); } }; loadingDialog.setMessage(getString(R.string.loading)); loadingDialog.setCancelable(true); loadingDialog.setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { if (!asyncTask.isCancelled()) asyncTask.cancel(true); } }); loadingDialog.setButton(ProgressDialog.BUTTON_NEGATIVE, getString(android.R.string.cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); finish(); } }); loadingDialog.show(); asyncTask.execute( mMyfeedleCrypto.Decrypt(account.getString(account.getColumnIndex(Accounts.TOKEN))), mMyfeedleCrypto.Decrypt(account.getString(account.getColumnIndex(Accounts.SECRET)))); } account.close(); break; case FACEBOOK: account = this.getContentResolver().query(Accounts.getContentUri(StatusDialog.this), new String[] { Accounts._ID, Accounts.TOKEN }, Accounts._ID + "=?", new String[] { Long.toString(mAccount) }, null); if (account.moveToFirst()) { final ProgressDialog loadingDialog = new ProgressDialog(this); asyncTask = new AsyncTask<String, Void, String>() { @Override protected String doInBackground(String... arg0) { return MyfeedleHttpClient.httpResponse( MyfeedleHttpClient.getThreadSafeClient(getApplicationContext()), new HttpGet(String.format(FACEBOOK_USER, FACEBOOK_BASE_URL, mEsid, Saccess_token, arg0[0]))); } @Override protected void onPostExecute(String response) { if (loadingDialog.isShowing()) loadingDialog.dismiss(); if (response != null) { try { startActivity(new Intent(Intent.ACTION_VIEW) .setData(Uri.parse((new JSONObject(response)).getString("link")))); } catch (JSONException e) { Log.e(TAG, e.toString()); onErrorExit(mServiceName); } } else { onErrorExit(mServiceName); } finish(); } }; loadingDialog.setMessage(getString(R.string.loading)); loadingDialog.setCancelable(true); loadingDialog.setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { if (!asyncTask.isCancelled()) asyncTask.cancel(true); } }); loadingDialog.setButton(ProgressDialog.BUTTON_NEGATIVE, getString(android.R.string.cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); finish(); } }); loadingDialog.show(); asyncTask.execute( mMyfeedleCrypto.Decrypt(account.getString(account.getColumnIndex(Accounts.TOKEN)))); } account.close(); break; case MYSPACE: account = this.getContentResolver().query(Accounts.getContentUri(StatusDialog.this), new String[] { Accounts._ID, Accounts.TOKEN, Accounts.SECRET }, Accounts._ID + "=?", new String[] { Long.toString(mAccount) }, null); if (account.moveToFirst()) { final ProgressDialog loadingDialog = new ProgressDialog(this); asyncTask = new AsyncTask<String, Void, String>() { @Override protected String doInBackground(String... arg0) { MyfeedleOAuth myfeedleOAuth = new MyfeedleOAuth(MYSPACE_KEY, MYSPACE_SECRET, arg0[0], arg0[1]); return MyfeedleHttpClient.httpResponse( MyfeedleHttpClient.getThreadSafeClient(getApplicationContext()), myfeedleOAuth.getSignedRequest( new HttpGet(String.format(MYSPACE_USER, MYSPACE_BASE_URL, mEsid)))); } @Override protected void onPostExecute(String response) { if (loadingDialog.isShowing()) loadingDialog.dismiss(); if (response != null) { try { startActivity(new Intent(Intent.ACTION_VIEW) .setData(Uri.parse((new JSONObject(response)).getJSONObject("person") .getString("profileUrl")))); } catch (JSONException e) { Log.e(TAG, e.toString()); onErrorExit(mServiceName); } } else { onErrorExit(mServiceName); } finish(); } }; loadingDialog.setMessage(getString(R.string.loading)); loadingDialog.setCancelable(true); loadingDialog.setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { if (!asyncTask.isCancelled()) asyncTask.cancel(true); } }); loadingDialog.setButton(ProgressDialog.BUTTON_NEGATIVE, getString(android.R.string.cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); finish(); } }); loadingDialog.show(); asyncTask.execute( mMyfeedleCrypto.Decrypt(account.getString(account.getColumnIndex(Accounts.TOKEN))), mMyfeedleCrypto.Decrypt(account.getString(account.getColumnIndex(Accounts.SECRET)))); } account.close(); break; case FOURSQUARE: startActivity(new Intent(Intent.ACTION_VIEW) .setData(Uri.parse(String.format(FOURSQUARE_URL_PROFILE, mEsid)))); finish(); break; case LINKEDIN: account = this.getContentResolver().query(Accounts.getContentUri(StatusDialog.this), new String[] { Accounts._ID, Accounts.TOKEN, Accounts.SECRET }, Accounts._ID + "=?", new String[] { Long.toString(mAccount) }, null); if (account.moveToFirst()) { final ProgressDialog loadingDialog = new ProgressDialog(this); asyncTask = new AsyncTask<String, Void, String>() { @Override protected String doInBackground(String... arg0) { MyfeedleOAuth myfeedleOAuth = new MyfeedleOAuth(LINKEDIN_KEY, LINKEDIN_SECRET, arg0[0], arg0[1]); HttpGet httpGet = new HttpGet(String.format(LINKEDIN_URL_USER, mEsid)); for (String[] header : LINKEDIN_HEADERS) httpGet.setHeader(header[0], header[1]); return MyfeedleHttpClient.httpResponse( MyfeedleHttpClient.getThreadSafeClient(getApplicationContext()), myfeedleOAuth.getSignedRequest(httpGet)); } @Override protected void onPostExecute(String response) { if (loadingDialog.isShowing()) loadingDialog.dismiss(); if (response != null) { try { startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse( (new JSONObject(response)).getJSONObject("siteStandardProfileRequest") .getString("url").replaceAll("\\\\", "")))); } catch (JSONException e) { Log.e(TAG, e.toString()); onErrorExit(mServiceName); } } else { onErrorExit(mServiceName); } finish(); } }; loadingDialog.setMessage(getString(R.string.loading)); loadingDialog.setCancelable(true); loadingDialog.setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { if (!asyncTask.isCancelled()) asyncTask.cancel(true); } }); loadingDialog.setButton(ProgressDialog.BUTTON_NEGATIVE, getString(android.R.string.cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); finish(); } }); loadingDialog.show(); asyncTask.execute( mMyfeedleCrypto.Decrypt(account.getString(account.getColumnIndex(Accounts.TOKEN))), mMyfeedleCrypto.Decrypt(account.getString(account.getColumnIndex(Accounts.SECRET)))); } account.close(); break; case IDENTICA: account = this.getContentResolver().query(Accounts.getContentUri(StatusDialog.this), new String[] { Accounts._ID, Accounts.TOKEN, Accounts.SECRET }, Accounts._ID + "=?", new String[] { Long.toString(mAccount) }, null); if (account.moveToFirst()) { final ProgressDialog loadingDialog = new ProgressDialog(this); asyncTask = new AsyncTask<String, Void, String>() { @Override protected String doInBackground(String... arg0) { MyfeedleOAuth myfeedleOAuth = new MyfeedleOAuth(IDENTICA_KEY, IDENTICA_SECRET, arg0[0], arg0[1]); return MyfeedleHttpClient.httpResponse( MyfeedleHttpClient.getThreadSafeClient(getApplicationContext()), myfeedleOAuth.getSignedRequest( new HttpGet(String.format(IDENTICA_USER, IDENTICA_BASE_URL, mEsid)))); } @Override protected void onPostExecute(String response) { if (loadingDialog.isShowing()) loadingDialog.dismiss(); if (response != null) { try { JSONObject user = new JSONObject(response); startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse( String.format(IDENTICA_PROFILE, user.getString("screen_name"))))); } catch (JSONException e) { Log.e(TAG, e.toString()); onErrorExit(mServiceName); } } else { onErrorExit(mServiceName); } finish(); } }; loadingDialog.setMessage(getString(R.string.loading)); loadingDialog.setCancelable(true); loadingDialog.setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { if (!asyncTask.isCancelled()) asyncTask.cancel(true); } }); loadingDialog.setButton(ProgressDialog.BUTTON_NEGATIVE, getString(android.R.string.cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); finish(); } }); loadingDialog.show(); asyncTask.execute( mMyfeedleCrypto.Decrypt(account.getString(account.getColumnIndex(Accounts.TOKEN))), mMyfeedleCrypto.Decrypt(account.getString(account.getColumnIndex(Accounts.SECRET)))); } account.close(); break; case GOOGLEPLUS: startActivity(new Intent(Intent.ACTION_VIEW) .setData(Uri.parse(String.format(GOOGLEPLUS_PROFILE, mEsid)))); finish(); break; case PINTEREST: if (mEsid != null) startActivity(new Intent(Intent.ACTION_VIEW) .setData(Uri.parse(String.format(PINTEREST_PROFILE, mEsid)))); else startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse("https://pinterest.com"))); finish(); break; case CHATTER: account = this.getContentResolver().query(Accounts.getContentUri(StatusDialog.this), new String[] { Accounts._ID, Accounts.TOKEN }, Accounts._ID + "=?", new String[] { Long.toString(mAccount) }, null); if (account.moveToFirst()) { final ProgressDialog loadingDialog = new ProgressDialog(this); asyncTask = new AsyncTask<String, Void, String>() { @Override protected String doInBackground(String... arg0) { // need to get an instance return MyfeedleHttpClient.httpResponse( MyfeedleHttpClient.getThreadSafeClient(getApplicationContext()), new HttpPost(String.format(CHATTER_URL_ACCESS, CHATTER_KEY, arg0[0]))); } @Override protected void onPostExecute(String response) { if (loadingDialog.isShowing()) loadingDialog.dismiss(); if (response != null) { try { JSONObject jobj = new JSONObject(response); if (jobj.has("instance_url")) { startActivity(new Intent(Intent.ACTION_VIEW) .setData(Uri.parse(jobj.getString("instance_url") + "/" + mEsid))); } } catch (JSONException e) { Log.e(TAG, e.toString()); onErrorExit(mServiceName); } } else { onErrorExit(mServiceName); } finish(); } }; loadingDialog.setMessage(getString(R.string.loading)); loadingDialog.setCancelable(true); loadingDialog.setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { if (!asyncTask.isCancelled()) asyncTask.cancel(true); } }); loadingDialog.setButton(ProgressDialog.BUTTON_NEGATIVE, getString(android.R.string.cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); finish(); } }); loadingDialog.show(); asyncTask.execute( mMyfeedleCrypto.Decrypt(account.getString(account.getColumnIndex(Accounts.TOKEN)))); } account.close(); break; } break; default: if ((itemsData != null) && (which < itemsData.length) && (itemsData[which] != null)) // open link startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse(itemsData[which]))); else (Toast.makeText(this, getString(R.string.error_status), Toast.LENGTH_LONG)).show(); finish(); break; } }
From source file:com.money.manager.ex.reports.IncomeVsExpensesListFragment.java
@Override public void onLoadFinished(Loader<Cursor> loader, Cursor data) { switch (loader.getId()) { case ID_LOADER_REPORT: // ((IncomeVsExpensesAdapter) getListAdapter()).swapCursor(data); ((IncomeVsExpensesAdapter) getListAdapter()).changeCursor(data); if (isResumed()) { setListShown(true);// ww w . jav a 2 s.co m } else { setListShownNoAnimation(true); } // calculate income, expenses double income = 0, expenses = 0; if (data == null) return; while (data.moveToNext()) { if (data.getInt(data.getColumnIndex( IncomeVsExpenseReportEntity.Month)) != IncomeVsExpensesActivity.SUBTOTAL_MONTH) { income += data.getDouble(data.getColumnIndex(IncomeVsExpenseReportEntity.Income)); expenses += data.getDouble(data.getColumnIndex(IncomeVsExpenseReportEntity.Expenses)); } } updateListViewFooter(mFooterListView, income, expenses); if (data.getCount() > 0) { getListView().removeFooterView(mFooterListView); getListView().addFooterView(mFooterListView); } if (((IncomeVsExpensesActivity) getActivity()).mIsDualPanel) { Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Override public void run() { showChart(); } }, 1 * 1000); } break; case ID_LOADER_YEARS: if (data != null && data.moveToFirst()) { while (!data.isAfterLast()) { int year = data.getInt(data.getColumnIndex("Year")); if (mYearsSelected.get(year, false) == false) { mYearsSelected.put(year, false); } data.moveToNext(); } startLoader(); } } }
From source file:org.digitalcampus.oppia.application.DbHelper.java
public ArrayList<Activity> getCourseActivities(long courseId) { ArrayList<Activity> activities = new ArrayList<Activity>(); String s = ACTIVITY_C_COURSEID + "=?"; String[] args = new String[] { String.valueOf(courseId) }; Cursor c = db.query(ACTIVITY_TABLE, null, s, args, null, null, null); c.moveToFirst();// w w w. java2 s . com while (c.isAfterLast() == false) { Activity activity = new Activity(); activity.setDbId(c.getInt(c.getColumnIndex(ACTIVITY_C_ID))); activity.setDigest(c.getString(c.getColumnIndex(ACTIVITY_C_ACTIVITYDIGEST))); activity.setTitlesFromJSONString(c.getString(c.getColumnIndex(ACTIVITY_C_TITLE))); activities.add(activity); c.moveToNext(); } c.close(); return activities; }
From source file:org.digitalcampus.oppia.application.DbHelper.java
public ArrayList<Activity> getCourseQuizzes(long courseId) { ArrayList<Activity> quizzes = new ArrayList<Activity>(); String s = ACTIVITY_C_COURSEID + "=? AND " + ACTIVITY_C_ACTTYPE + "=? AND " + ACTIVITY_C_SECTIONID + ">0"; String[] args = new String[] { String.valueOf(courseId), "quiz" }; Cursor c = db.query(ACTIVITY_TABLE, null, s, args, null, null, null); c.moveToFirst();/*w ww.j a va 2 s. c o m*/ while (c.isAfterLast() == false) { Activity quiz = new Activity(); quiz.setDbId(c.getInt(c.getColumnIndex(ACTIVITY_C_ID))); quiz.setDigest(c.getString(c.getColumnIndex(ACTIVITY_C_ACTIVITYDIGEST))); quiz.setTitlesFromJSONString(c.getString(c.getColumnIndex(ACTIVITY_C_TITLE))); quizzes.add(quiz); c.moveToNext(); } c.close(); return quizzes; }