List of usage examples for org.json JSONException toString
public String toString()
From source file:com.aerhard.oxygen.plugin.dbtagger.util.JsonUtil.java
/** * Gets the table body in the JSON server response and calls * {@link #convertArray(int, int, JSONArray)}. * /* w w w . j a v a 2 s.co m*/ * @param responseJSON * the JSON response * @return the body content */ private String[][] getTableBody(JSONObject responseJSON, int columns) { try { JSONArray dataArray = responseJSON.getJSONArray("data"); if (dataArray != null) { int rows = dataArray.length(); if (rows > 0) { return convertArray(rows, columns, dataArray); } } } catch (JSONException e) { workspace.showErrorMessage(i18n.getString("jsonUtil.dataError") + "\n" + e.toString()); } catch (ArrayStoreException e) { workspace.showErrorMessage(e.toString()); } return null; }
From source file:org.godotengine.godot.MessagingService.java
private void handleData(Map<String, String> data) { // TODO: Perform some action now..! // .../*from www. j a v a 2 s .c o m*/ JSONObject jobject = new JSONObject(); try { for (Map.Entry<String, String> entry : data.entrySet()) { jobject.put(entry.getKey(), entry.getValue()); } } catch (JSONException e) { Utils.d("JSONException: parsing, " + e.toString()); } if (jobject.length() > 0) { KeyValueStorage.setValue("firebase_notification_data", jobject.toString()); } }
From source file:cn.code.notes.gtask.remote.GTaskManager.java
private void initGTaskList() throws NetworkFailureException { if (mCancelled) return;/*from www. ja v a2s . c om*/ GTaskClient client = GTaskClient.getInstance(); try { JSONArray jsTaskLists = client.getTaskLists(); // init meta list first mMetaList = null; for (int i = 0; i < jsTaskLists.length(); i++) { JSONObject object = jsTaskLists.getJSONObject(i); String gid = object.getString(GTaskStringUtils.GTASK_JSON_ID); String name = object.getString(GTaskStringUtils.GTASK_JSON_NAME); if (name.equals(GTaskStringUtils.MIUI_FOLDER_PREFFIX + GTaskStringUtils.FOLDER_META)) { mMetaList = new TaskList(); mMetaList.setContentByRemoteJSON(object); // load meta data JSONArray jsMetas = client.getTaskList(gid); for (int j = 0; j < jsMetas.length(); j++) { object = (JSONObject) jsMetas.getJSONObject(j); MetaData metaData = new MetaData(); metaData.setContentByRemoteJSON(object); if (metaData.isWorthSaving()) { mMetaList.addChildTask(metaData); if (metaData.getGid() != null) { mMetaHashMap.put(metaData.getRelatedGid(), metaData); } } } } } // create meta list if not existed if (mMetaList == null) { mMetaList = new TaskList(); mMetaList.setName(GTaskStringUtils.MIUI_FOLDER_PREFFIX + GTaskStringUtils.FOLDER_META); GTaskClient.getInstance().createTaskList(mMetaList); } // init task list for (int i = 0; i < jsTaskLists.length(); i++) { JSONObject object = jsTaskLists.getJSONObject(i); String gid = object.getString(GTaskStringUtils.GTASK_JSON_ID); String name = object.getString(GTaskStringUtils.GTASK_JSON_NAME); if (name.startsWith(GTaskStringUtils.MIUI_FOLDER_PREFFIX) && !name.equals(GTaskStringUtils.MIUI_FOLDER_PREFFIX + GTaskStringUtils.FOLDER_META)) { TaskList tasklist = new TaskList(); tasklist.setContentByRemoteJSON(object); mGTaskListHashMap.put(gid, tasklist); mGTaskHashMap.put(gid, tasklist); // load tasks JSONArray jsTasks = client.getTaskList(gid); for (int j = 0; j < jsTasks.length(); j++) { object = (JSONObject) jsTasks.getJSONObject(j); gid = object.getString(GTaskStringUtils.GTASK_JSON_ID); Task task = new Task(); task.setContentByRemoteJSON(object); if (task.isWorthSaving()) { task.setMetaInfo(mMetaHashMap.get(gid)); tasklist.addChildTask(task); mGTaskHashMap.put(gid, task); } } } } } catch (JSONException e) { Log.e(TAG, e.toString()); e.printStackTrace(); throw new ActionFailureException("initGTaskList: handing JSONObject failed"); } }
From source file:cn.code.notes.gtask.remote.GTaskManager.java
private void addLocalNode(Node node) throws NetworkFailureException { if (mCancelled) { return;//from ww w .j a v a 2 s . c o m } SqlNote sqlNote; if (node instanceof TaskList) { if (node.getName().equals(GTaskStringUtils.MIUI_FOLDER_PREFFIX + GTaskStringUtils.FOLDER_DEFAULT)) { sqlNote = new SqlNote(mContext, Notes.ID_ROOT_FOLDER); } else if (node.getName() .equals(GTaskStringUtils.MIUI_FOLDER_PREFFIX + GTaskStringUtils.FOLDER_CALL_NOTE)) { sqlNote = new SqlNote(mContext, Notes.ID_CALL_RECORD_FOLDER); } else { sqlNote = new SqlNote(mContext); sqlNote.setContent(node.getLocalJSONFromContent()); sqlNote.setParentId(Notes.ID_ROOT_FOLDER); } } else { sqlNote = new SqlNote(mContext); JSONObject js = node.getLocalJSONFromContent(); try { if (js.has(GTaskStringUtils.META_HEAD_NOTE)) { JSONObject note = js.getJSONObject(GTaskStringUtils.META_HEAD_NOTE); if (note.has(NoteColumns.ID)) { long id = note.getLong(NoteColumns.ID); if (DataUtils.existInNoteDatabase(mContentResolver, id)) { // the id is not available, have to create a new one note.remove(NoteColumns.ID); } } } if (js.has(GTaskStringUtils.META_HEAD_DATA)) { JSONArray dataArray = js.getJSONArray(GTaskStringUtils.META_HEAD_DATA); for (int i = 0; i < dataArray.length(); i++) { JSONObject data = dataArray.getJSONObject(i); if (data.has(DataColumns.ID)) { long dataId = data.getLong(DataColumns.ID); if (DataUtils.existInDataDatabase(mContentResolver, dataId)) { // the data id is not available, have to create // a new one data.remove(DataColumns.ID); } } } } } catch (JSONException e) { Log.w(TAG, e.toString()); e.printStackTrace(); } sqlNote.setContent(js); Long parentId = mGidToNid.get(((Task) node).getParent().getGid()); if (parentId == null) { Log.e(TAG, "cannot find task's parent id locally"); throw new ActionFailureException("cannot add local node"); } sqlNote.setParentId(parentId.longValue()); } // create the local node sqlNote.setGtaskId(node.getGid()); sqlNote.commit(false); // update gid-nid mapping mGidToNid.put(node.getGid(), sqlNote.getId()); mNidToGid.put(sqlNote.getId(), node.getGid()); // update meta updateRemoteMeta(node.getGid(), sqlNote); }
From source file:com.google.enterprise.connector.db.diffing.DBHandle.java
/** * Reconstructs a {@code DocumentHandle} from a serialized string * representation.//from w w w .jav a2 s. co m */ public DBHandle(String jsonString) { JSONObject jo; try { jo = new JSONObject(jsonString); } catch (JSONException e) { LOG.warning( "Exception thrown while creating JSONObject from string" + jsonString + "\n" + e.toString()); throw new IllegalArgumentException("Exception thrown for illegal JsonString" + jsonString + "\n", e); } document = new JsonDocument(jo); try { documentId = Value.getSingleValueString(document, SpiConstants.PROPNAME_DOCID); } catch (RepositoryException e) { LOG.warning("Exception thrown while extracting docId for Document" + document + "\n" + e.toString()); // Thrown to indicate an inappropriate argument has been passed to // Value.getSingleValueString() method. throw new IllegalArgumentException(); } }
From source file:edu.ucsd.ccdb.cil.xml2json.XML2JsonUtil.java
public String xml2Json(String xml) throws Exception { String jsonPrettyPrintString = ""; try {//from w w w . j a v a 2s . c om JSONObject xmlJSONObj = XML.toJSONObject(xml); jsonPrettyPrintString = xmlJSONObj.toString(); //System.out.println(jsonPrettyPrintString); } catch (JSONException je) { System.out.println(je.toString()); } return jsonPrettyPrintString; }
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 ww w . ja va 2s .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:net.freifunk.android.discover.model.Community.java
public void populate(final RequestQueue rq, final CommunityReady communityReady) { rq.add(new JsonObjectRequest(getDetailUrl(), null, new Response.Listener<JSONObject>() { @Override/*from w ww .ja v a 2 s . co m*/ public void onResponse(JSONObject jsonObject) { try { setApiName(jsonObject.getString("name")); setApi(jsonObject.getString("api")); if (jsonObject.has("metacommunity")) setMetacommunity(jsonObject.getString("metacommunity")); JSONObject location = jsonObject.getJSONObject("location"); setAddressCity(location.getString("city")); if (location.has("address")) { JSONObject address = jsonObject.getJSONObject("address"); if (address.has("Name")) setAddressName(address.getString("Name")); if (address.has("Street")) setAddressStreet(address.getString("Street")); if (address.has("Zipcode")) setAddressZipcode(address.getString("Zipcode")); } setLat(location.getDouble("lat")); setLon(location.getDouble("lon")); setUrl(jsonObject.getString("url")); Log.d(TAG, getCommunity().toString()); communityReady.ready(getCommunity()); } catch (JSONException e) { Log.e(TAG, e.toString()); } } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError volleyError) { Log.e(TAG, volleyError.toString()); } })); }
From source file:com.google.android.apps.body.LayersLoader.java
/** Synchronously loads a single layer. */ private Render.DrawGroup[] load(Context context, int layerResource) { // TODO(thakis): this method is kinda ugly. // TODO(thakis): if we can bundle the resource files, rewrite them so that no conversion // needs to happen at load time. The utf8 stuff is clever, but mostly overhead // for local files. // Timers for different loading phases. float jsonReadS = 0; float jsonParseS = 0; float textureS = 0; float fileReadS = 0; float fileDecodeS = 0; float colorBufferS = 0; Render.DrawGroup[] drawGroups = null; long jsonReadStartNS = System.nanoTime(); JSONObject object = loadJsonResource(context, layerResource); jsonReadS = (System.nanoTime() - jsonReadStartNS) / 1e9f; long jsonParseStartNS = System.nanoTime(); Map<Integer, List<Loader>> toBeLoaded = new HashMap<Integer, List<Loader>>(); try {/* w w w .j av a2 s. c o m*/ JSONArray dataDrawGroups = object.getJSONArray("draw_groups"); drawGroups = new Render.DrawGroup[dataDrawGroups.length()]; for (int i = 0; i < drawGroups.length; ++i) { if (mCancelled) return null; JSONObject drawGroup = dataDrawGroups.getJSONObject(i); drawGroups[i] = new Render.DrawGroup(); if (drawGroup.has("texture")) drawGroups[i].texture = drawGroup.getString("texture"); else if (drawGroup.has("diffuse_color")) { JSONArray color = drawGroup.getJSONArray("diffuse_color"); drawGroups[i].diffuseColor = new float[3]; for (int j = 0; j < 3; ++j) drawGroups[i].diffuseColor[j] = (float) color.getDouble(j); } JSONArray draws = drawGroup.getJSONArray("draws"); drawGroups[i].draws = new ArrayList<Render.Draw>(draws.length()); for (int j = 0; j < draws.length(); ++j) { JSONObject jsonDraw = draws.getJSONObject(j); Render.Draw draw = new Render.Draw(); draw.geometry = jsonDraw.getString("geometry"); draw.offset = jsonDraw.getJSONArray("range").getInt(0); draw.count = jsonDraw.getJSONArray("range").getInt(1); drawGroups[i].draws.add(draw); } long textureReadStartNS = System.nanoTime(); loadTexture(mContext, drawGroups[i]); textureS += (System.nanoTime() - textureReadStartNS) / 1e9f; String indices = drawGroup.getString("indices"); FP.FPEntry indicesFP = FP.get(indices); if (toBeLoaded.get(indicesFP.file) == null) toBeLoaded.put(indicesFP.file, new ArrayList<Loader>()); toBeLoaded.get(indicesFP.file).add(new IndexLoader(drawGroups[i], indicesFP)); String attribs = drawGroup.getString("attribs"); FP.FPEntry attribsFP = FP.get(attribs); if (toBeLoaded.get(attribsFP.file) == null) toBeLoaded.put(attribsFP.file, new ArrayList<Loader>()); toBeLoaded.get(attribsFP.file).add(new AttribLoader(drawGroups[i], attribsFP)); drawGroups[i].numIndices = drawGroup.getInt("numIndices"); } } catch (JSONException e) { Log.e("Body", e.toString()); } jsonParseS = (System.nanoTime() - jsonParseStartNS) / 1e9f - textureS; for (int resource : toBeLoaded.keySet()) { if (mCancelled) return null; long fileReadStartNS = System.nanoTime(); char[] data = new char[0]; InputStream is = mContext.getResources().openRawResource(resource); try { // Comment from the ApiDemo content/ReadAsset.java in the Android SDK: // "We guarantee that the available method returns the total // size of the asset... of course, this does mean that a single // asset can't be more than 2 gigs." data = new char[is.available()]; Reader in = new InputStreamReader(is, "UTF-8"); in.read(data, 0, data.length); } catch (UnsupportedEncodingException e) { Log.e("Body", e.toString()); } catch (IOException e) { Log.e("Body", e.toString()); } finally { try { is.close(); } catch (IOException e) { Log.e("Body", e.toString()); } } fileReadS += (System.nanoTime() - fileReadStartNS) / 1.0e9f; long fileDecodeStartNS = System.nanoTime(); for (Loader l : toBeLoaded.get(resource)) { if (mCancelled) return null; l.load(data); } fileDecodeS += (System.nanoTime() - fileDecodeStartNS) / 1.0e9f; } long colorBufferStartNS = System.nanoTime(); for (Render.DrawGroup drawGroup : drawGroups) { if (mCancelled) return null; createColorBuffer(drawGroup); } colorBufferS = (System.nanoTime() - colorBufferStartNS) / 1e9f; Log.i("Body", "JSON read: " + jsonReadS + ", JSON parse: " + jsonParseS + ", texture: " + textureS + ", res read: " + fileReadS + ", res decode: " + fileDecodeS + ", colorbuf: " + colorBufferS); return drawGroups; }
From source file:com.cssweb.android.view.FinanceMini.java
public void drawHKPrice(Canvas canvas) { Paint paint = this.mPaint; paint.setTypeface(Typeface.DEFAULT_BOLD); paint.setAntiAlias(true);// w ww. j a va 2 s. c o m if (quoteData != null) { try { JSONArray jArr = quoteData.getJSONArray("data"); JSONObject jo = jArr.getJSONObject(0); paint.setTextAlign(Paint.Align.LEFT); paint.setTextSize(mTextSize); paint.setColor(GlobalColor.colorLabelName); canvas.translate(0, DY); canvas.drawText("?", x, y, paint); canvas.translate(0, DY); canvas.drawText("?", x, y, paint); canvas.translate(0, DY); canvas.drawText("", x, y, paint); canvas.translate(0, DY); canvas.drawText("?", x, y, paint); canvas.translate(0, DY); canvas.drawText("?", x, y, paint); paint.setTextAlign(Paint.Align.RIGHT); paint.setColor(GlobalColor.colorStockName); canvas.translate(width / 2, -DY * 4); canvas.drawText(Utils.getAmountFormat(jo.getInt("cjsl"), false), x - tips, y, paint); canvas.translate(0, DY); // if(jo.getDouble("wb")<0) // paint.setColor(GlobalColor.colorPriceDown); // else if(jo.getDouble("wb")>0) // paint.setColor(GlobalColor.colorpriceUp); // else // paint.setColor(GlobalColor.colorPriceEqual); // canvas.drawText(Utils.dataFormation(jo.getDouble("wb")*100, 1)+"%", x-tips, y, paint); canvas.drawText(Utils.getAmountFormat(jo.getInt("cjje"), false), x - tips, y, paint); paint.setColor(GlobalColor.colorpriceUp); canvas.translate(0, DY); canvas.drawText(Utils.getAmountFormat(jo.getDouble("wp"), false), x - tips, y, paint); paint.setColor(GlobalColor.colorStockName); canvas.translate(0, DY); canvas.drawText(Utils.getAmountFormat(jo.getInt("msgs"), true), x - tips, y, paint); paint.setTextAlign(Paint.Align.LEFT); paint.setColor(GlobalColor.colorLabelName); canvas.translate(0, -DY * 3); canvas.drawText("?", x, y, paint); canvas.translate(0, DY); // canvas.drawText("", x, y, paint); canvas.drawText("", x, y, paint); canvas.translate(0, DY); canvas.drawText("", x, y, paint); // canvas.translate(0, DY); // canvas.drawText("?", x, y, paint); canvas.translate(0, DY); canvas.drawText("", x, y, paint); paint.setTextAlign(Paint.Align.RIGHT); canvas.translate(width / 2, -DY * 3); paint.setColor(GlobalColor.colorStockName); canvas.drawText(Utils.dataFormation(jo.getDouble("lb"), 1, jo.getInt("tp")), x - tips, y, paint); canvas.translate(0, DY); // if(jo.getDouble("wc")<0) { // paint.setColor(GlobalColor.colorPriceDown); // canvas.drawText("-" + Utils.getAmountFormat(Math.abs(jo.getDouble("wc")), true), x-tips, y, paint); // } // else if(jo.getDouble("wc")>0) { // paint.setColor(GlobalColor.colorpriceUp); // canvas.drawText(Utils.getAmountFormat(jo.getDouble("wc"), true), x-tips, y, paint); // } // else { // paint.setColor(GlobalColor.colorPriceEqual); // canvas.drawText(Utils.getAmountFormat(jo.getDouble("wc"), true), x-tips, y, paint); // } paint.setColor(GlobalColor.colorPriceDown); canvas.drawText("", x - tips, y, paint); canvas.translate(0, DY); canvas.drawText(Utils.getAmountFormat(jo.getDouble("np"), false), x - tips, y, paint); // paint.setColor(GlobalColor.colorStockName); // canvas.translate(0, DY); // canvas.drawText(Utils.getAmountFormat(jo.getDouble("cjje"), true), x-tips, y, paint); } catch (JSONException e) { Log.e(TAG, e.toString()); } } }