List of usage examples for org.json JSONObject getString
public String getString(String key) throws JSONException
From source file:com.android.browser.GearsBaseDialog.java
/** * Utility method to set elements' text indicated in * the dialogs' arguments.//from w ww . j a v a 2 s .c o m */ void setLabel(JSONObject json, String name, int rsc) { try { if (json.has(name)) { String text = json.getString(name); View view = findViewById(rsc); if (view != null && text != null) { TextView textView = (TextView) view; textView.setText(text); textView.setVisibility(View.VISIBLE); } } } catch (JSONException e) { Log.e(TAG, "json exception", e); } }
From source file:uk.co.senab.photup.LoginActivity.java
private void saveFacebookSession() { AsyncFacebookRunner fbRunner = new AsyncFacebookRunner(mFacebook); fbRunner.request("me", new RequestListener() { public void onComplete(String response, Object state) { try { JSONObject object = new JSONObject(response); String id = object.getString("id"); String name = object.getString("name"); Session session = new Session(mFacebook, id, name); session.save(getApplicationContext()); setResult(RESULT_OK);//from www . j a v a 2 s .co m finish(); } catch (JSONException e) { e.printStackTrace(); } } public void onFacebookError(FacebookError e, Object state) { e.printStackTrace(); } public void onFileNotFoundException(FileNotFoundException e, Object state) { e.printStackTrace(); } public void onIOException(IOException e, Object state) { e.printStackTrace(); } public void onMalformedURLException(MalformedURLException e, Object state) { e.printStackTrace(); } }); }
From source file:com.altamiracorp.lumify.twitter.DefaultLumifyTwitterProcessor.java
@Override public void extractEntities(final String processId, final JSONObject jsonTweet, final Vertex tweetVertex, final TwitterEntityType entityType) { // TODO set visibility Visibility visibility = new Visibility(""); String tweetText = JSON_TEXT_PROPERTY.getFrom(jsonTweet); // only process if text is found in the tweet if (tweetText != null && !tweetText.trim().isEmpty()) { String tweetId = tweetVertex.getId().toString(); User user = getUser();/*from w ww .j av a 2 s. co m*/ Graph graph = getGraph(); OntologyRepository ontRepo = getOntologyRepository(); AuditRepository auditRepo = getAuditRepository(); Concept concept = ontRepo.getConceptByName(entityType.getConceptName()); Vertex conceptVertex = concept.getVertex(); String relDispName = conceptVertex.getPropertyValue(LumifyProperties.DISPLAY_NAME.getKey(), 0) .toString(); JSONArray entities = jsonTweet.getJSONObject("entities").getJSONArray(entityType.getJsonKey()); List<TermMentionModel> mentions = new ArrayList<TermMentionModel>(); for (int i = 0; i < entities.length(); i++) { JSONObject entity = entities.getJSONObject(i); String id; String sign = entity.getString(entityType.getSignKey()); if (entityType.getConceptName().equals(CONCEPT_TWITTER_MENTION)) { id = TWITTER_USER_PREFIX + entity.get("id"); } else if (entityType.getConceptName().equals(CONCEPT_TWITTER_HASHTAG)) { sign = sign.toLowerCase(); id = TWITTER_HASHTAG_PREFIX + sign; } else { try { id = URLEncoder.encode(TWITTER_URL_PREFIX + sign, "UTF-8"); } catch (UnsupportedEncodingException e) { throw new RuntimeException("URL id could not be UTF-8 encoded"); } } checkNotNull(sign, "Term sign cannot be null"); JSONArray indices = entity.getJSONArray("indices"); TermMentionRowKey termMentionRowKey = new TermMentionRowKey(tweetId, indices.getLong(0), indices.getLong(1)); TermMentionModel termMention = new TermMentionModel(termMentionRowKey); termMention.getMetadata().setSign(sign) .setOntologyClassUri( (String) conceptVertex.getPropertyValue(LumifyProperties.DISPLAY_NAME.getKey(), 0)) .setConceptGraphVertexId(concept.getId()).setVertexId(id); mentions.add(termMention); } for (TermMentionModel mention : mentions) { String sign = mention.getMetadata().getSign().toLowerCase(); String rowKey = mention.getRowKey().toString(); String id = mention.getMetadata().getGraphVertexId(); ElementMutation<Vertex> termVertexMutation; Vertex termVertex = graph.getVertex(id, user.getAuthorizations()); if (termVertex == null) { termVertexMutation = graph.prepareVertex(id, visibility, user.getAuthorizations()); } else { termVertexMutation = termVertex.prepareMutation(); } TITLE.setProperty(termVertexMutation, sign, visibility); ROW_KEY.setProperty(termVertexMutation, rowKey, visibility); CONCEPT_TYPE.setProperty(termVertexMutation, concept.getId(), visibility); if (!(termVertexMutation instanceof ExistingElementMutation)) { termVertex = termVertexMutation.save(); getAuditRepository().auditVertexElementMutation(termVertexMutation, termVertex, processId, user, visibility); } else { getAuditRepository().auditVertexElementMutation(termVertexMutation, termVertex, processId, user, visibility); termVertex = termVertexMutation.save(); } String termId = termVertex.getId().toString(); mention.getMetadata().setVertexId(termId); getTermMentionRepository().save(mention); graph.addEdge(tweetVertex, termVertex, entityType.getRelationshipLabel(), visibility, user.getAuthorizations()); auditRepo.auditRelationship(AuditAction.CREATE, tweetVertex, termVertex, relDispName, processId, "", user, visibility); graph.flush(); } } }
From source file:net.di2e.ddf.argo.probe.responselistener.ProbeResponseEndpoint.java
@POST @Consumes("application/json") public void getJSONServices(String jsonResponse) { LOGGER.debug("Got a probe response in JSON format:\n{}", jsonResponse); JSONArray services = new JSONArray(jsonResponse); Set<String> createdSources = new HashSet<String>(); for (int i = 0; i < services.length(); i++) { JSONObject jsonService = services.getJSONObject(i); // determine factory pid String sourceId = jsonService.getString(ArgoConstants.ID_KEY); if (!sourceIdExists(sourceId, createdSources)) { String serviceContractId = jsonService.getString(ArgoConstants.SERVICE_CONTRACTID_KEY); String serviceType = getServiceType(serviceContractId); if (serviceType != null) { String pid = serviceResolver.getFactoryPid(serviceType); LOGGER.debug(//from w w w . j a v a 2s . c o m "Got a factory pid of '{}' for service '{}' with service contract id '{}' so attempting to create new source '{}'", pid, serviceType, serviceContractId, sourceId); createSource(pid, sourceId, jsonService.getString(ArgoConstants.URL_KEY)); createdSources.add(sourceId); } else { LOGGER.debug("Could not find a Service Type for the Service Contract ID '{}'", serviceContractId); } } else { LOGGER.debug( "A Source with id '{}' already exists, so not creating a new one from probe, but checking if any values should be overridden", sourceId); // TODO override properties } } }
From source file:com.freecast.LudoCast.MainActivity.java
private void setupCastListener() { mCastConsumer = new VideoCastConsumerImpl() { @Override/* www . jav a 2 s. c o m*/ public void onApplicationConnected(ApplicationMetadata appMetadata, String sessionId, boolean wasLaunched) { System.out.println("onApplicationConnected message = " + sessionId); Toast.makeText(MainActivity.this, "Device is Ready to Start Game!!!", Toast.LENGTH_SHORT).show(); mAppConnected = true; try { Thread.currentThread().sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } if (mAppConnected) { Createbnt.setEnabled(true); Createbnt.setText("Start Game"); } else { Createbnt.setEnabled(false); Createbnt.setText("Disconnected"); } } @Override public void onConnected() { System.out.println("MainActivity onConnected "); Createbnt.setText("Connecting"); } @Override public void onDisconnected() { System.out.println("onDisconnected message "); mAppConnected = false; if (mAppConnected) { Createbnt.setEnabled(true); Createbnt.setText("Start Game"); } else { Createbnt.setEnabled(false); Createbnt.setText("Disconnected"); } } @Override public void onFailed(int resourceId, int statusCode) { System.out.println("onFailed message = " + statusCode); mAppConnected = false; if (mAppConnected) { Createbnt.setEnabled(true); Createbnt.setText("Start Game"); } else { Createbnt.setEnabled(false); Createbnt.setText("Disconnected"); } } @Override public void onApplicationDisconnected(int errorCode) { System.out.println("onApplicationDisconnected message = " + errorCode); mAppConnected = false; if (mAppConnected) { Createbnt.setEnabled(true); Createbnt.setText("Start Game"); } else { Createbnt.setEnabled(false); Createbnt.setText("Disconnected"); } } @Override public boolean onApplicationConnectionFailed(int errorCode) { System.out.println("onApplicationConnectionFailed message = " + errorCode); mAppConnected = false; if (mAppConnected) { Createbnt.setEnabled(true); Createbnt.setText("Start Game"); } else { Createbnt.setEnabled(false); Createbnt.setText("Disconnected"); } return true; } @Override public void onDataMessageReceived(String message) { JSONObject obj = null; try { obj = new JSONObject(message); } catch (JSONException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } String command = null; try { command = obj.getString("command"); } catch (JSONException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } if (command.equals("connect_reply")) { boolean ret = false; try { ret = obj.getBoolean("ret"); } catch (JSONException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } if (ret == false) { String reason = null; try { reason = obj.getString("error"); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } Log.d(TAG, "error info: " + reason); Toast.makeText(MainActivity.this, "Fail to connect Ludo Server !!!!", Toast.LENGTH_SHORT) .show(); } else { connectstatus = true; CreateConfigGame(message); } } try { protocol.parseMessage(message); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println("MainActivity receiver message = " + message); } @Override public void onConnectionSuspended(int cause) { Log.d(TAG, "onConnectionSuspended() was called with cause: " + cause); com.freecast.LudoCast.Utils.showToast(MainActivity.this, R.string.connection_temp_lost); } @Override public void onConnectivityRecovered() { com.freecast.LudoCast.Utils.showToast(MainActivity.this, R.string.connection_recovered); } @Override public void onCastDeviceDetected(final RouteInfo info) { if (!CastPreference.isFtuShown(MainActivity.this)) { CastPreference.setFtuShown(MainActivity.this); Log.d(TAG, "Route is visible: " + info); new Handler().postDelayed(new Runnable() { @Override public void run() { if (mediaRouteMenuItem.isVisible()) { Log.d(TAG, "Cast Icon is visible: " + info.getName()); } } }, 1000); } } }; }
From source file:de.blinkt.openvpn.fragments.AboutFragment.java
private void createPlayBuyOptions(ArrayList<String> ownedSkus, ArrayList<String> responseList) { try {/*from w ww.j a v a 2s .c om*/ Vector<Pair<String, String>> gdonation = new Vector<Pair<String, String>>(); gdonation.add(new Pair<String, String>(getString(R.string.donatePlayStore), null)); HashMap<String, SkuResponse> responseMap = new HashMap<String, SkuResponse>(); for (String thisResponse : responseList) { JSONObject object = new JSONObject(thisResponse); responseMap.put(object.getString("productId"), new SkuResponse(object.getString("price"), object.getString("title"))); } for (String sku : donationSkus) if (responseMap.containsKey(sku)) gdonation.add( getSkuTitle(sku, responseMap.get(sku).title, responseMap.get(sku).price, ownedSkus)); String gmsTextString = ""; for (int i = 0; i < gdonation.size(); i++) { if (i == 1) gmsTextString += " "; else if (i > 1) gmsTextString += ", "; gmsTextString += gdonation.elementAt(i).first; } SpannableString gmsText = new SpannableString(gmsTextString); int lStart = 0; int lEnd = 0; for (Pair<String, String> item : gdonation) { lEnd = lStart + item.first.length(); if (item.second != null) { final String mSku = item.second; ClickableSpan cspan = new ClickableSpan() { @Override public void onClick(View widget) { triggerBuy(mSku); } }; gmsText.setSpan(cspan, lStart, lEnd, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } lStart = lEnd + 2; // Account for ", " between items } if (gmsTextView != null) { gmsTextView.setText(gmsText); gmsTextView.setMovementMethod(LinkMovementMethod.getInstance()); gmsTextView.setVisibility(View.VISIBLE); } } catch (JSONException e) { VpnStatus.logException("Parsing Play Store IAP", e); } }
From source file:com.nextgis.firereporter.SettingsSupport.java
public SettingsSupport(Context context, PreferenceScreen screen) { this.screen = screen; this.context = context; // Load the preferences from an XML resource //addPreferencesFromResource(R.xml.preferences); mSendDataIntervalPref = (ListPreference) screen.findPreference(SettingsActivity.KEY_PREF_INTERVAL); if (mSendDataIntervalPref != null) { int index = mSendDataIntervalPref.findIndexOfValue(mSendDataIntervalPref.getValue()); if (index >= 0) { mSendDataIntervalPref.setSummary(mSendDataIntervalPref.getEntries()[index]); } else {/*from w ww .j ava 2 s .c om*/ mSendDataIntervalPref.setSummary((String) mSendDataIntervalPref.getValue()); } } mSaveBattPref = (CheckBoxPreference) screen.findPreference(SettingsActivity.KEY_PREF_SERVICE_BATT_SAVE); if (mSaveBattPref != null) mSaveBattPref.setSummary(mSaveBattPref.isChecked() ? R.string.stOn : R.string.stOff); mNotifyLEDPref = (CheckBoxPreference) screen.findPreference(SettingsActivity.KEY_PREF_NOTIFY_LED); if (mNotifyLEDPref != null) mNotifyLEDPref.setSummary(mNotifyLEDPref.isChecked() ? R.string.stOn : R.string.stOff); mPlaySoundPref = (CheckBoxPreference) screen.findPreference(SettingsActivity.KEY_PREF_NOTIFY_SOUND); if (mPlaySoundPref != null) mPlaySoundPref.setSummary(mPlaySoundPref.isChecked() ? R.string.stOn : R.string.stOff); mVibroPref = (CheckBoxPreference) screen.findPreference(SettingsActivity.KEY_PREF_NOTIFY_VIBRO); if (mVibroPref != null) mVibroPref.setSummary(mVibroPref.isChecked() ? R.string.stOn : R.string.stOff); mRowCountPref = (EditTextPreference) screen.findPreference(SettingsActivity.KEY_PREF_ROW_COUNT); if (mRowCountPref != null) mRowCountPref.setSummary((String) mRowCountPref.getText()); mFireSearchRadiusPref = (EditTextPreference) screen .findPreference(SettingsActivity.KEY_PREF_FIRE_SEARCH_RADIUS); if (mFireSearchRadiusPref != null) mFireSearchRadiusPref .setSummary((String) mFireSearchRadiusPref.getText() + " " + context.getString(R.string.km)); mDayIntervalPref = (ListPreference) screen.findPreference(SettingsActivity.KEY_PREF_SEARCH_DAY_INTERVAL); if (mDayIntervalPref != null) { int index = mDayIntervalPref.findIndexOfValue(mDayIntervalPref.getValue()); if (index >= 0) { mDayIntervalPref.setSummary(mDayIntervalPref.getEntries()[index]); } else { mDayIntervalPref.setSummary((String) mDayIntervalPref.getValue()); } } mSearchCurrentDatePref = (CheckBoxPreference) screen .findPreference(SettingsActivity.KEY_PREF_SEARCH_CURR_DAY); if (mSearchCurrentDatePref != null) mSearchCurrentDatePref.setSummary(mSearchCurrentDatePref.isChecked() ? R.string.stSearchCurrentDayOn : R.string.stSearchCurrentDayOff); mNasaServerPref = (EditTextPreference) screen.findPreference(SettingsActivity.KEY_PREF_SRV_NASA); if (mNasaServerPref != null) mNasaServerPref.setSummary((String) mNasaServerPref.getText()); mNasaServerUserPref = (EditTextPreference) screen.findPreference(SettingsActivity.KEY_PREF_SRV_NASA_USER); if (mNasaServerUserPref != null) mNasaServerUserPref.setSummary((String) mNasaServerUserPref.getText()); mUserServerPref = (EditTextPreference) screen.findPreference(SettingsActivity.KEY_PREF_SRV_USER); if (mUserServerPref != null) mUserServerPref.setSummary((String) mUserServerPref.getText()); mUserServerUserPref = (EditTextPreference) screen.findPreference(SettingsActivity.KEY_PREF_SRV_USER_USER); if (mUserServerUserPref != null) mUserServerUserPref.setSummary((String) mUserServerUserPref.getText()); mScanServerUserPref = (EditTextPreference) screen.findPreference(SettingsActivity.KEY_PREF_SRV_SCAN_USER); if (mScanServerUserPref != null) mScanServerUserPref.setSummary((String) mScanServerUserPref.getText()); mNasaServerPassPref = (EditTextPreference) screen.findPreference(SettingsActivity.KEY_PREF_SRV_NASA_PASS); mUserServerPassPref = (EditTextPreference) screen.findPreference(SettingsActivity.KEY_PREF_SRV_USER_PASS); mScanServerPassPref = (EditTextPreference) screen.findPreference(SettingsActivity.KEY_PREF_SRV_SCAN_PASS); final Preference checkNasaConnPref = (Preference) screen .findPreference(SettingsActivity.KEY_PREF_SRV_NASA_CHECK_CONN); final Preference checkUserConnPref = (Preference) screen .findPreference(SettingsActivity.KEY_PREF_SRV_USER_CHECK_CONN); final Preference checkScanConnPref = (Preference) screen .findPreference(SettingsActivity.KEY_PREF_SRV_SCAN_CHECK_CONN); mReturnHandler = new Handler() { @SuppressLint("NewApi") public void handleMessage(Message msg) { Bundle resultData = msg.getData(); boolean bHaveErr = resultData.getBoolean(GetFiresService.ERROR); int nType = resultData.getInt(GetFiresService.SOURCE); if (bHaveErr) { Toast.makeText(SettingsSupport.this.context, resultData.getString(GetFiresService.ERR_MSG), Toast.LENGTH_LONG).show(); if (nType == 1) {//user checkUserConnPref.setSummary(R.string.stConnectionFailed); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) checkUserConnPref.setIcon(R.drawable.ic_alerts_and_states_error); } else if (nType == 2) {//nasa checkNasaConnPref.setSummary(R.string.stConnectionFailed); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) checkNasaConnPref.setIcon(R.drawable.ic_alerts_and_states_error); } else if (nType == 3) {//scanex checkScanConnPref.setSummary(R.string.stConnectionFailed); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) checkScanConnPref.setIcon(R.drawable.ic_alerts_and_states_error); } } else { String sData = resultData.getString(GetFiresService.JSON); if (nType == 1) {//user JSONObject jsonMainObject; try { jsonMainObject = new JSONObject(sData); if (jsonMainObject.getBoolean("error")) { String sMsg = jsonMainObject.getString("msg"); Toast.makeText(SettingsSupport.this.context, sMsg, Toast.LENGTH_LONG).show(); checkUserConnPref.setSummary(R.string.stConnectionFailed); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) checkUserConnPref.setIcon(R.drawable.ic_alerts_and_states_error); } else { checkUserConnPref.setSummary(R.string.stConnectionSucceeded); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) checkUserConnPref.setIcon(R.drawable.ic_navigation_accept); } } catch (JSONException e) { Toast.makeText(SettingsSupport.this.context, e.toString(), Toast.LENGTH_LONG).show(); e.printStackTrace(); checkUserConnPref.setSummary(R.string.sCheckDBConnSummary); } } else if (nType == 2) {//nasa JSONObject jsonMainObject; try { jsonMainObject = new JSONObject(sData); if (jsonMainObject.getBoolean("error")) { String sMsg = jsonMainObject.getString("msg"); Toast.makeText(SettingsSupport.this.context, sMsg, Toast.LENGTH_LONG).show(); checkNasaConnPref.setSummary(R.string.stConnectionFailed); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) checkNasaConnPref.setIcon(R.drawable.ic_alerts_and_states_error); } else { checkNasaConnPref.setSummary(R.string.stConnectionSucceeded); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) checkNasaConnPref.setIcon(R.drawable.ic_navigation_accept); } } catch (JSONException e) { Toast.makeText(SettingsSupport.this.context, e.toString(), Toast.LENGTH_LONG).show(); e.printStackTrace(); checkNasaConnPref.setSummary(R.string.sCheckDBConnSummary); } } else if (nType == 3) {//scanex if (sData.length() == 0) { String sMsg = "Connect failed"; Toast.makeText(SettingsSupport.this.context, sMsg, Toast.LENGTH_LONG).show(); checkScanConnPref.setSummary(R.string.stConnectionFailed); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) checkScanConnPref.setIcon(R.drawable.ic_alerts_and_states_error); } else { checkScanConnPref.setSummary(R.string.stConnectionSucceeded); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) checkScanConnPref.setIcon(R.drawable.ic_navigation_accept); new HttpGetter(SettingsSupport.this.context, 4, SettingsSupport.this.context.getString(R.string.stChecking), mReturnHandler, true).execute( "http://fires.kosmosnimki.ru/SAPI/Account/Get/?CallBackName=" + GetFiresService.USER_ID, sData); } } else if (nType == 4) {//scanex detailes try { String sSubData = GetFiresService.removeJsonT(sData); JSONObject rootobj = new JSONObject(sSubData); String sStatus = rootobj.getString("Status"); if (sStatus.equals("OK")) { JSONObject resobj = rootobj.getJSONObject("Result"); String sName = ""; if (!resobj.isNull("FullName")) sName = resobj.getString("FullName"); String sPhone = ""; if (!resobj.isNull("Phone")) sPhone = resobj.getString("Phone"); //add properties if (sPhone.length() > 0) { Preference PhonePref = new Preference(SettingsSupport.this.context); PhonePref.setTitle(R.string.stScanexServerUserPhone); PhonePref.setSummary(sPhone); PhonePref.setOrder(2); SettingsSupport.this.screen.addPreference(PhonePref); } if (sName.length() > 0) { Preference NamePref = new Preference(SettingsSupport.this.context); NamePref.setTitle(R.string.stScanexServerUserFullName); NamePref.setSummary(sName); NamePref.setOrder(2); SettingsSupport.this.screen.addPreference(NamePref); } } else { Toast.makeText(SettingsSupport.this.context, rootobj.getString("ErrorInfo"), Toast.LENGTH_LONG).show(); } } catch (JSONException e) { Toast.makeText(SettingsSupport.this.context, e.toString(), Toast.LENGTH_LONG).show(); e.printStackTrace(); } } } }; }; if (checkNasaConnPref != null) checkNasaConnPref.setOnPreferenceClickListener(new OnPreferenceClickListener() { public boolean onPreferenceClick(Preference preference) { String sURL = mNasaServerPref.getText() + "?function=test_conn_nasa&user=" + mNasaServerUserPref.getText() + "&pass=" + mNasaServerPassPref.getText(); new HttpGetter(SettingsSupport.this.context, 2, SettingsSupport.this.context.getString(R.string.stChecking), mReturnHandler, true) .execute(sURL); return true; } }); if (checkUserConnPref != null) checkUserConnPref.setOnPreferenceClickListener(new OnPreferenceClickListener() { public boolean onPreferenceClick(Preference preference) { String sURL = mUserServerPref.getText() + "?function=test_conn_user&user=" + mUserServerUserPref.getText() + "&pass=" + mUserServerPassPref.getText(); new HttpGetter(SettingsSupport.this.context, 1, SettingsSupport.this.context.getString(R.string.stChecking), mReturnHandler, true) .execute(sURL); return true; } }); if (checkScanConnPref != null) checkScanConnPref.setOnPreferenceClickListener(new OnPreferenceClickListener() { public boolean onPreferenceClick(Preference preference) { //String sURL = mUserServerPref.getText() + "?function=test_conn_nasa&user=" + mUserServerUserPref.getText() + "&pass=" + mUserServerPassPref.getText(); new ScanexHttpLogin(SettingsSupport.this.context, 3, SettingsSupport.this.context.getString(R.string.stChecking), mReturnHandler, true) .execute(mScanServerUserPref.getText(), mScanServerPassPref.getText()); return true; } }); }
From source file:com.facebook.internal.LikeActionController.java
private static LikeActionController deserializeFromJson(String controllerJsonString) { LikeActionController controller;/*from ww w .j a v a 2s . co m*/ try { JSONObject controllerJson = new JSONObject(controllerJsonString); int version = controllerJson.optInt(JSON_INT_VERSION_KEY, -1); if (version != LIKE_ACTION_CONTROLLER_VERSION) { // Don't attempt to deserialize a controller that might be serialized differently than expected. return null; } controller = new LikeActionController(Session.getActiveSession(), controllerJson.getString(JSON_STRING_OBJECT_ID_KEY)); // Make sure to default to null and not empty string, to keep the logic elsewhere functioning properly. controller.likeCountStringWithLike = controllerJson.optString(JSON_STRING_LIKE_COUNT_WITH_LIKE_KEY, null); controller.likeCountStringWithoutLike = controllerJson .optString(JSON_STRING_LIKE_COUNT_WITHOUT_LIKE_KEY, null); controller.socialSentenceWithLike = controllerJson.optString(JSON_STRING_SOCIAL_SENTENCE_WITH_LIKE_KEY, null); controller.socialSentenceWithoutLike = controllerJson .optString(JSON_STRING_SOCIAL_SENTENCE_WITHOUT_LIKE_KEY, null); controller.isObjectLiked = controllerJson.optBoolean(JSON_BOOL_IS_OBJECT_LIKED_KEY); controller.unlikeToken = controllerJson.optString(JSON_STRING_UNLIKE_TOKEN_KEY, null); String pendingCallIdString = controllerJson.optString(JSON_STRING_PENDING_CALL_ID_KEY, null); if (!Utility.isNullOrEmpty(pendingCallIdString)) { controller.pendingCallId = UUID.fromString(pendingCallIdString); } JSONObject analyticsJSON = controllerJson.optJSONObject(JSON_BUNDLE_PENDING_CALL_ANALYTICS_BUNDLE); if (analyticsJSON != null) { controller.pendingCallAnalyticsBundle = BundleJSONConverter.convertToBundle(analyticsJSON); } } catch (JSONException e) { Log.e(TAG, "Unable to deserialize controller from JSON", e); controller = null; } return controller; }
From source file:com.ichi2.libanki.importer.Anki2Importer.java
/** Decks */ /* Given did in src col, return local id */ private long _did(long did) { try {/*from w ww . j av a 2s.co m*/ // already converted? if (mDecks.containsKey(did)) { return mDecks.get(did); } // get the name in src JSONObject g = mSrc.getDecks().get(did); String name = g.getString("name"); // if there's a prefix, replace the top level deck if (mDeckPrefix != null) { String[] tmpname = name.split("::", -1); name = mDeckPrefix; if (tmpname.length > 1) { for (int i = 0; i < tmpname.length - 2; i++) { name += "::" + tmpname[i + 1]; } } } // Manually create any parents so we can pull in descriptions String head = ""; String[] parents = name.split("::", -1); for (int i = 0; i < parents.length - 1; ++i) { if (head.length() > 0) { head = head.concat("::"); } head = head.concat(parents[i]); long idInSrc = mSrc.getDecks().id(head); _did(idInSrc); } // create in local long newid = mDst.getDecks().id(name); // pull conf over if (g.has("conf") && g.getLong("conf") != 1) { JSONObject conf = mSrc.getDecks().getConf(g.getLong("conf")); mDst.getDecks().save(conf); mDst.getDecks().updateConf(conf); JSONObject g2 = mDst.getDecks().get(newid); g2.put("conf", g.getLong("conf")); mDst.getDecks().save(g2); } // save desc JSONObject deck = mDst.getDecks().get(newid); deck.put("desc", g.getString("desc")); mDst.getDecks().save(deck); // add to deck map and return mDecks.put(did, newid); return newid; } catch (JSONException e) { throw new RuntimeException(e); } }
From source file:com.asd.littleprincesbeauty.data.TaskList.java
@Override public void setContentByRemoteJSON(JSONObject js) { if (js != null) { try {// w ww .ja va 2 s . c om // id if (js.has(GTaskStringUtils.GTASK_JSON_ID)) { setGid(js.getString(GTaskStringUtils.GTASK_JSON_ID)); } // last_modified if (js.has(GTaskStringUtils.GTASK_JSON_LAST_MODIFIED)) { setLastModified(js.getLong(GTaskStringUtils.GTASK_JSON_LAST_MODIFIED)); } // name if (js.has(GTaskStringUtils.GTASK_JSON_NAME)) { setName(js.getString(GTaskStringUtils.GTASK_JSON_NAME)); } } catch (JSONException e) { Log.e(TAG, e.toString()); e.printStackTrace(); throw new ActionFailureException("fail to get tasklist content from jsonobject"); } } }