List of usage examples for org.json JSONArray getLong
public long getLong(int index) throws JSONException
From source file:com.googlecode.android_scripting.facade.ui.UiFacade.java
/** * This will override the default behaviour of keys while in the fullscreen mode. ie: * /*from ww w . j a va 2s.c o m*/ * <pre> * droid.fullKeyOverride([24,25],True) * </pre> * * This will override the default behaviour of the volume keys (codes 24 and 25) so that they do * not actually adjust the volume. <br> * Returns a list of currently overridden keycodes. */ @Rpc(description = "Override default key actions") public JSONArray fullKeyOverride( @RpcParameter(name = "keycodes", description = "List of keycodes to override") JSONArray keycodes, @RpcParameter(name = "enable", description = "Turn overriding or off") @RpcDefault(value = "true") Boolean enable) throws JSONException { for (int i = 0; i < keycodes.length(); i++) { int value = (int) keycodes.getLong(i); if (value > 0) { if (enable) { if (!mOverrideKeys.contains(value)) { mOverrideKeys.add(value); } } else { int index = mOverrideKeys.indexOf(value); if (index >= 0) { mOverrideKeys.remove(index); } } } } if (mFullScreenTask != null) { mFullScreenTask.setOverrideKeys(mOverrideKeys); } return new JSONArray(mOverrideKeys); }
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();/* ww w.j a v a2 s .c o 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:edu.stanford.mobisocial.dungbeetle.feed.objects.InviteToSharedAppFeedObj.java
public void handleDirectMessage(Context context, Contact from, JSONObject obj) { try {//from ww w .j a v a 2s . c o m String packageName = obj.getString(PACKAGE_NAME); String feedName = obj.getString("sharedFeedName"); JSONArray ids = obj.getJSONArray(PARTICIPANTS); Intent launch = new Intent(); launch.setAction(Intent.ACTION_MAIN); launch.addCategory(Intent.CATEGORY_LAUNCHER); launch.putExtra("type", "invite_app_feed"); launch.putExtra("creator", false); launch.putExtra("sender", from.id); launch.putExtra("sharedFeedName", feedName); launch.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); long[] idArray = new long[ids.length()]; for (int i = 0; i < ids.length(); i++) { idArray[i] = ids.getLong(i); } launch.putExtra("participants", idArray); launch.setPackage(packageName); final PackageManager mgr = context.getPackageManager(); List<ResolveInfo> resolved = mgr.queryIntentActivities(launch, 0); if (resolved.size() == 0) { Toast.makeText(context, "Could not find application to handle invite.", Toast.LENGTH_SHORT).show(); return; } ActivityInfo info = resolved.get(0).activityInfo; launch.setComponent(new ComponentName(info.packageName, info.name)); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, launch, PendingIntent.FLAG_CANCEL_CURRENT); (new PresenceAwareNotify(context)).notify("New Invitation from " + from.name, "Invitation received from " + from.name, "Click to launch application: " + packageName, contentIntent); } catch (JSONException e) { Log.e(TAG, e.getMessage()); } }
From source file:net.dv8tion.jda.core.handle.GuildMemberUpdateHandler.java
private List<Role> toRolesList(GuildImpl guild, JSONArray array) { LinkedList<Role> roles = new LinkedList<>(); for (int i = 0; i < array.length(); i++) { final long id = array.getLong(i); Role r = guild.getRolesMap().get(id); if (r != null) { roles.add(r);/* w w w . j a v a 2s .c o m*/ } else { api.getEventCache().cache(EventCache.Type.ROLE, id, () -> { handle(responseNumber, allContent); }); EventCache.LOG .debug("Got GuildMember update but one of the Roles for the Member is not yet cached."); return null; } } return roles; }
From source file:com.phonegap.Storage.java
/** * Executes the request and returns PluginResult. * //from ww w .ja v a 2 s .c o m * @param action The action to execute. * @param args JSONArry of arguments for the plugin. * @param callbackId The callback id used when calling back into JavaScript. * @return A PluginResult object with a status and message. */ public PluginResult execute(String action, JSONArray args, String callbackId) { PluginResult.Status status = PluginResult.Status.OK; String result = ""; try { // TODO: Do we want to allow a user to do this, since they could get to other app databases? if (action.equals("setStorage")) { this.setStorage(args.getString(0)); } else if (action.equals("openDatabase")) { this.openDatabase(args.getString(0), args.getString(1), args.getString(2), args.getLong(3)); } else if (action.equals("executeSql")) { JSONArray a = args.getJSONArray(1); int len = a.length(); String[] s = new String[len]; for (int i = 0; i < len; i++) { s[i] = a.getString(i); } this.executeSql(args.getString(0), s, args.getString(2)); } return new PluginResult(status, result); } catch (JSONException e) { return new PluginResult(PluginResult.Status.JSON_EXCEPTION); } }
From source file:com.tweetlanes.android.App.java
public void updateTwitterAccountCount() { mAccounts.clear();//from www. ja v a 2 s. co m long currentAccountId = mPreferences.getLong(SHARED_PREFERENCES_KEY_CURRENT_ACCOUNT_ID, -1); String accountIndices = mPreferences.getString(SHARED_PREFERENCES_KEY_ACCOUNT_INDICES, null); if (accountIndices != null) { try { JSONArray jsonArray = new JSONArray(accountIndices); for (int i = 0; i < jsonArray.length(); i++) { Long id = jsonArray.getLong(i); String key = getAccountDescriptorKey(id); String jsonAsString = mPreferences.getString(key, null); if (jsonAsString != null) { AccountDescriptor account = new AccountDescriptor(this, jsonAsString); mAccounts.add(account); if (currentAccountId != -1 && account.getId() == currentAccountId) { mCurrentAccountIndex = i; } } } } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } } if (mCurrentAccountIndex == null && mAccounts.size() > 0) { mCurrentAccountIndex = 0; } }
From source file:salvatejero.cordova.liferay.LiferayPlugin.java
private Object[] getListOfParam(Method m, JSONArray values) throws JSONException { List<Object> listOfParams = new ArrayList<Object>(); for (int i = 0; i < m.getParameterTypes().length; i++) { @SuppressWarnings("rawtypes") Class c = m.getParameterTypes()[i]; if (c.getName().equals("java.lang.String")) { listOfParams.add(values.getString(i)); } else if (c.getName().equals("java.lang.Long")) { listOfParams.add(values.getLong(i)); } else if (c.getName().equals("java.lang.Integer")) { listOfParams.add(values.getInt(i)); } else if (c.getName().equals("long")) { listOfParams.add(values.getLong(i)); } else if (c.getName().equals("int")) { listOfParams.add(values.getInt(i)); }// w w w . j av a2 s. c om } Object[] paramsA = new Object[listOfParams.size()]; return listOfParams.toArray(paramsA); }
From source file:org.apache.cordova.deviceorientation.CompassListener.java
/** * Executes the request and returns PluginResult. * * @param action The action to execute. * @param args JSONArry of arguments for the plugin. * @param callbackS=Context The callback id used when calling back into JavaScript. * @return True if the action was valid. * @throws JSONException //from ww w .j a v a 2s.co m */ public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { if (action.equals("start")) { this.start(); } else if (action.equals("stop")) { this.stop(); } else if (action.equals("getStatus")) { int i = this.getStatus(); callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, i)); } else if (action.equals("getHeading")) { // If not running, then this is an async call, so don't worry about waiting if (this.status != CompassListener.RUNNING) { int r = this.start(); if (r == CompassListener.ERROR_FAILED_TO_START) { callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.IO_EXCEPTION, CompassListener.ERROR_FAILED_TO_START)); return true; } // Set a timeout callback on the main thread. Handler handler = new Handler(Looper.getMainLooper()); handler.postDelayed(new Runnable() { public void run() { CompassListener.this.timeout(); } }, 2000); } callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, getCompassHeading())); } else if (action.equals("setTimeout")) { this.setTimeout(args.getLong(0)); } else if (action.equals("getTimeout")) { long l = this.getTimeout(); callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, l)); } else { // Unsupported action return false; } return true; }
From source file:com.ct.speech.TTS.java
@Override public PluginResult execute(String action, JSONArray args, String callbackId) { PluginResult.Status status = PluginResult.Status.OK; String result = ""; try {//from w w w. j a v a 2s . c om if (action.equals("speak")) { String text = args.getString(0); if (isReady()) { mTts.speak(text, TextToSpeech.QUEUE_ADD, null); return new PluginResult(status, result); } else { JSONObject error = new JSONObject(); error.put("message", "TTS service is still initialzing."); error.put("code", TTS.INITIALIZING); return new PluginResult(PluginResult.Status.ERROR, error); } } else if (action.equals("silence")) { if (isReady()) { mTts.playSilence(args.getLong(0), TextToSpeech.QUEUE_ADD, null); return new PluginResult(status, result); } else { JSONObject error = new JSONObject(); error.put("message", "TTS service is still initialzing."); error.put("code", TTS.INITIALIZING); return new PluginResult(PluginResult.Status.ERROR, error); } } else if (action.equals("startup")) { if (mTts == null) { this.startupCallbackId = callbackId; state = TTS.INITIALIZING; mTts = new TextToSpeech((Context) ctx, this); //mTts.setLanguage(Locale.US); } PluginResult pluginResult = new PluginResult(status, TTS.INITIALIZING); pluginResult.setKeepCallback(true); return pluginResult; } else if (action.equals("shutdown")) { if (mTts != null) { mTts.shutdown(); } return new PluginResult(status, result); } else if (action.equals("stop")) { if (mTts != null) { mTts.stop(); } return new PluginResult(status, result); } else if (action.equals("getLanguage")) { if (mTts != null) { result = mTts.getLanguage().toString(); return new PluginResult(status, result); } } else if (action.equals("isLanguageAvailable")) { if (mTts != null) { Locale loc = new Locale(args.getString(0)); int available = mTts.isLanguageAvailable(loc); result = (available < 0) ? "false" : "true"; return new PluginResult(status, result); } } else if (action.equals("setLanguage")) { if (mTts != null) { Locale loc = new Locale(args.getString(0)); int available = mTts.setLanguage(loc); result = (available < 0) ? "false" : "true"; return new PluginResult(status, result); } } return new PluginResult(status, result); } catch (JSONException e) { e.printStackTrace(); return new PluginResult(PluginResult.Status.JSON_EXCEPTION); } }
From source file:com.tweetlanes.android.core.App.java
public void removeAccount(String accountKey) { final Editor edit = mPreferences.edit(); String accountIndices = mPreferences.getString(SharedPreferencesConstants.ACCOUNT_INDICES, null); if (accountIndices != null) { try {/* www .j a v a 2 s . c o m*/ JSONArray jsonArray = new JSONArray(accountIndices); JSONArray newIndicies = new JSONArray(); for (int i = 0; i < jsonArray.length(); i++) { Long id = jsonArray.getLong(i); String key = getAccountDescriptorKey(id); String jsonAsString = mPreferences.getString(key, null); if (jsonAsString != null) { AccountDescriptor account = new AccountDescriptor(this, jsonAsString); if (!account.getAccountKey().equals(accountKey)) { newIndicies.put(Long.toString(id)); } else { ArrayList<LaneDescriptor> lanes = account.getAllLaneDefinitions(); for (LaneDescriptor lane : lanes) { String lanekey = lane.getCacheKey(account.getScreenName() + account.getId()); edit.remove(lanekey); } edit.remove(key); mAccounts.remove(account); } } } accountIndices = newIndicies.toString(); edit.putString(SharedPreferencesConstants.ACCOUNT_INDICES, accountIndices); edit.commit(); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } } updateTwitterAccountCount(); }