public void initTab(String result) { tabHost.setup(this, getSupportFragmentManager(), R.id.realtabcontent); try { JSONObject jsonObj = new JSONObject(result); JSONArray jsonArraySuccess = jsonObj.getJSONArray("Success"); JSONArray jsonArrayFail = jsonObj.getJSONArray("Fail"); int totalBooksBorrow = jsonArraySuccess.length() + jsonArrayFail.length(); Bundle success = new Bundle(); success.putString("Json", jsonArraySuccess.toString()); success.putInt("totalBooksBorrow", totalBooksBorrow); Bundle fail = new Bundle(); fail.putString("Json", jsonArrayFail.toString()); fail.putInt("totalBooksBorrow", totalBooksBorrow); tabHost.addTab( tabHost.newTabSpec("Success").setIndicator("Success"), SuccessBorrowBookFragment.class, success); tabHost.addTab( tabHost.newTabSpec("Fail").setIndicator("Fail"), FailBorrowBookFragment.class, fail); tabHost.setOnTabChangedListener( new TabHost.OnTabChangeListener() { @Override public void onTabChanged(String tabId) { /*Toast.makeText(ShowBorrowBooksResultActivity.this, "Tab Changed", Toast.LENGTH_SHORT).show();*/ } }); } catch (JSONException e) { e.printStackTrace(); } }
private JSONArray getCategory() { JSONArray cate1 = new JSONArray(); JSONArray cate2 = new JSONArray(); JSONArray allcategory = MassVigData.getinstance(this).getAllCategory(); JSONObject item; for (int i = 0, len = allcategory.length(); i < len; i++) { try { item = allcategory.getJSONObject(i); if (item.getJSONArray("Children").length() > 0) { // if(item.getBoolean("IsParent")){ cate1.put(item); } else { cate2.put(item); } } catch (Exception e) { e.printStackTrace(); } } try { if (cate2.length() > 0) return new JSONArray((cate1.toString() + cate2.toString()).replace("][", ",")); else return cate1; } catch (JSONException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } return null; }
private String[] jsonArrayToStringArray(JSONArray jsonArray) { return jsonArray .toString() .substring(1, jsonArray.toString().length() - 1) .replaceAll("\"", "") .split(","); }
/** @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String result = HttpUtil.handleRequest(request); System.out.println("GetFriendsServlet:" + result); try { JSONObject jsonObject = new JSONObject(result); String phone = jsonObject.getString("phone"); List<User> friends = new Database().getFriends(phone); JSONArray jsonArray = new JSONArray(); for (User friend : friends) { String friendName = friend.getName(); String friendPhone = friend.getPhone(); JSONObject friendObj = new JSONObject(); friendObj.put("phone", friendPhone); friendObj.put("name", friendName); jsonArray.put(friendObj); } System.out.println("GetFriendsServlet:" + jsonArray.toString()); HttpUtil.handleResponse(response, jsonArray.toString()); } catch (JSONException e) { e.printStackTrace(); } }
public static void addtoSms(JSONObject data) { try { if (!com.example.muditi.deligoo.Omoyo.shared.contains("sms_log")) { JSONArray jsonArray = new JSONArray(); JSONObject jsonObject = new JSONObject(); jsonObject.put("data", data); jsonArray.put(0, jsonObject); com.example.muditi.deligoo.Omoyo.edit.putString("sms_log", jsonArray.toString()); com.example.muditi.deligoo.Omoyo.edit.commit(); } else { JSONArray jsonArray = new JSONArray(com.example.muditi.deligoo.Omoyo.shared.getString("sms_log", "")); JSONObject jsonObject = new JSONObject(); jsonObject.put("data", data); jsonArray.put(jsonArray.length(), jsonObject); com.example.muditi.deligoo.Omoyo.edit.putString("sms_log", jsonArray.toString()); com.example.muditi.deligoo.Omoyo.edit.commit(); } } catch (JSONException ej) { } }
/** * Persists {@code this} test report to the given {@link * com.google.appengine.api.datastore.DatastoreService} and invalidate the cache. * * @param reports the reports entry point */ public void save(Reports reports) { final Entity entity = new Entity(TEST_REPORT, buildTypeId + buildId); entity.setProperty("buildTypeId", buildTypeId); entity.setProperty("buildId", buildId); entity.setProperty("buildDate", buildDate); entity.setProperty("buildDuration", buildDuration); entity.setProperty("numberOfPassedTests", numberOfPassedTests); entity.setProperty("numberOfIgnoredTests", numberOfIgnoredTests); entity.setProperty("numberOfFailedTests", numberOfFailedTests); final JSONArray jsonArrayFailedTests = new JSONArray(); for (Test oneFailingTest : failedTests) { jsonArrayFailedTests.put(oneFailingTest.asJson()); } entity.setProperty("failedTests", new Text(jsonArrayFailedTests.toString())); final JSONArray jsonArrayIgnoredTests = new JSONArray(); for (Test oneIgnoredTest : ignoredTests) { jsonArrayIgnoredTests.put(oneIgnoredTest.asJson()); } entity.setProperty("ignoredTests", new Text(jsonArrayIgnoredTests.toString())); final DatastoreService datastoreService = reports.getDatastoreService(); datastoreService.put(entity); final MemcacheService memcacheService = reports.getMemcacheService(); memcacheService.delete(buildTypeId); // invalidate cache }
public byte[] getAppHistoryJSONData() { JSONArray jsonArray = new JSONArray(); while (mCursor.moveToNext()) { setSendState(mCursor, SENDING); JSONObject object = new JSONObject(); try { object.put("uuid", mConfig.getUUID()); object.put( DataBaseHelper.APP_NAME, mCursor.getString(mCursor.getColumnIndex(DataBaseHelper.APP_NAME))); object.put( DataBaseHelper.PACKAGE_NAME, mCursor.getString(mCursor.getColumnIndex(DataBaseHelper.PACKAGE_NAME))); object.put( DataBaseHelper.START_DATE, mCursor.getString(mCursor.getColumnIndex(DataBaseHelper.START_DATE))); object.put( DataBaseHelper.START_TIME, mCursor.getString(mCursor.getColumnIndex(DataBaseHelper.START_TIME))); object.put( DataBaseHelper.USE_TIME, mCursor.getString(mCursor.getColumnIndex(DataBaseHelper.USE_TIME))); } catch (JSONException e) { e.printStackTrace(); } jsonArray.put(object); } Log.d("trans", "json[" + mCursor.getCount() + "]" + jsonArray.toString()); return jsonArray.toString().getBytes(); }
@POST @Path("/getSavedSearches") @Consumes(MediaType.APPLICATION_FORM_URLENCODED) @Produces("application/json") public String getSavedSearches(@FormParam("user") String user) { JSONArray queryList = new JSONArray(); System.out.println(user); CouchConnection couch = new CouchConnection("http://localhost:5984/", "savedsearches/"); JSONObject viewDocument = new JSONObject(); JSONArray searches = new JSONArray(); JSONArray keys = new JSONArray(); boolean existingViews = true; try { viewDocument = new JSONObject(couch.queryDB(user)); keys = viewDocument.names(); System.out.println(keys.toString()); } catch (Exception e) { existingViews = false; } return keys.toString(); }
public static String serializeTree(Node root) { JSONArray tree = new JSONArray(); if (root == null) { return tree.toString(); } recursivelySerialize(root, tree); return tree.toString(); }
private void write(JSONArray jsonArray) { if (jsonArray == null || jsonArray.toString().isEmpty()) { sharedPreferences.edit().putString(ARRAY_KEY, "{}").commit(); Log.i(LOG_TAG, "write / Writing empty array."); } else { sharedPreferences.edit().putString(ARRAY_KEY, jsonArray.toString()).commit(); Log.i(LOG_TAG, "write / New array: " + jsonArray.toString()); } }
@Override public Map<String, String> getEditorParameters( final Path path, final String editorID, String hostInfo, PlaceRequest place) { List<String> activeNodesList = new ArrayList<String>(); String activeNodesParam = place.getParameter("activeNodes", null); String readOnly = place.getParameter("readOnly", "false"); String encodedProcessSource = place.getParameter("encodedProcessSource", ""); if (activeNodesParam != null) { activeNodesList = Arrays.asList(activeNodesParam.split(",")); } List<String> completedNodesList = new ArrayList<String>(); String completedNodesParam = place.getParameter("completedNodes", null); if (completedNodesParam != null) { completedNodesList = Arrays.asList(completedNodesParam.split(",")); } JSONArray activeNodesArray = new JSONArray(activeNodesList); String encodedActiveNodesParam; try { encodedActiveNodesParam = Base64.encodeBase64URLSafeString(activeNodesArray.toString().getBytes("UTF-8")); } catch (UnsupportedEncodingException e) { encodedActiveNodesParam = ""; } JSONArray completedNodesArray = new JSONArray(completedNodesList); String encodedCompletedNodesParam; try { encodedCompletedNodesParam = Base64.encodeBase64URLSafeString(completedNodesArray.toString().getBytes("UTF-8")); } catch (UnsupportedEncodingException e) { encodedCompletedNodesParam = ""; } Map<String, String> editorParamsMap = new HashMap<String, String>(); editorParamsMap.put("hostinfo", hostInfo); editorParamsMap.put("uuid", path.toURI()); editorParamsMap.put("profile", "jbpm"); editorParamsMap.put("pp", ""); editorParamsMap.put("editorid", editorID); editorParamsMap.put("readonly", readOnly); editorParamsMap.put("activenodes", encodedActiveNodesParam); editorParamsMap.put("completednodes", encodedCompletedNodesParam); editorParamsMap.put("processsource", encodedProcessSource); return editorParamsMap; // String editorURL = hostInfo + "/editor/?uuid=" + path.toURI() + // "&profile=jbpm&pp=&editorid=" + editorID + "&readonly=" + readOnly + // "&activenodes=" + encodedActiveNodesParam + "&completednodes=" + // encodedCompletedNodesParam; // return getEditorResponse( editorURL, encodedProcessSource ); }
@Override protected String doInBackground(String... params) { ServerCom bServerCom = new ServerCom(mContext); JSONObject jsonReturnObj = null; try { MySharedPreferences msp = MySharedPreferences.getInstance(); JSONArray dataList = readContacts(); dataList.length(); String s = dataList.toString(); Log.e("CONI", "array length: " + dataList.length() + ""); Log.e("CONI", "string length: " + s.length() + ""); byte[] dataCompressed = Utils.compress(s); Log.e("CONI", "compressed length: " + dataCompressed.length + ""); bServerCom.setContactsZip( msp.getUserId(mContext), msp.getUserSecret(mContext), dataCompressed); jsonReturnObj = bServerCom.getReturnObject(); } catch (Exception e1) { e1.printStackTrace(); } String serverMessage = ""; try { if (jsonReturnObj == null) serverMessage = "ConnectionError"; else { serverMessage = jsonReturnObj.getString("message"); if (serverMessage.equals("success")) { if (jsonReturnObj.has("contacts_that_are_users")) { JSONArray contacts = jsonReturnObj.getJSONArray("contacts_that_are_users"); Log.e("TAG", contacts.toString()); MySharedPreferences.getInstance().saveContactsWithInstalledApp(mContext, contacts); } if (jsonReturnObj.has("recommended_contacts_that_arent_users")) { JSONArray contacts = jsonReturnObj.getJSONArray("recommended_contacts_that_arent_users"); Log.e("TAG", contacts.toString()); MySharedPreferences.getInstance().saveContactsRecommended(mContext, contacts); } } } } catch (JSONException e) { e.printStackTrace(); serverMessage = "GeneralError"; } return serverMessage; }
public void postResult(JSONArray args) { try { JSONArray result = new JSONArray(); result.put(0, mCallbackId); for (int i = 0; i < args.length(); i++) { result.put(i + 1, args.get(i)); } Log.w(TAG, "postResult: " + result.toString()); mExtension.postMessage(mInstanceId, result.toString()); } catch (JSONException e) { Log.e(TAG, e.toString()); } }
/** * Tests the {@link ClientMethodInvocation} serialization when using {@link * JavaScriptCallbackHelper#invokeCallback(String, Object...)}. #12532 */ public void testClientMethodSerialization_WithJSONArray_ContentStaysSame() throws Exception { JSONArray originalArray = new JSONArray(Arrays.asList("callbackParameter1", "callBackParameter2", "12345")); ClientMethodInvocation original = new ClientMethodInvocation( null, "interfaceName", JAVASCRIPT_CALLBACK_METHOD, new Object[] {"callBackMethodName", originalArray}); ClientMethodInvocation copy = (ClientMethodInvocation) serializeAndDeserialize(original); JSONArray copyArray = (JSONArray) copy.getParameters()[1]; assertEquals(originalArray.toString(), copyArray.toString()); }
/** * Handles the HTTP <code>GET</code> method. * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String ccIDStr = (String) request.getParameter("ccID"); int ccID = Integer.parseInt(ccIDStr); MissionDAO msonDAO = new MissionDAO(); IntelligenceDAO intlDAO = new IntelligenceDAO(); ArrayList<Excerpt> returnList = new ArrayList<Excerpt>(); ArrayList<Integer> eentIDList = msonDAO.GetEEntityIDsOfCC(ccID); ArrayList<Excerpt> excrList; for (Integer id : eentIDList) { for (Excerpt excr : intlDAO.GetExcerptOfEEntity(id)) { if (!returnList.contains(excr)) { returnList.add(excr); } } } JSONArray excrJArr = new JSONArray(returnList.toArray()); String excrJSON = excrJArr.toString(); response.setContentType("application/json"); response.setCharacterEncoding("UTF-8"); response.getWriter().write(excrJSON); }
// Return feed message data as JSON for unity public static String getTiersJSON(List<JSONObject> tiersList) { JSONArray tiersArray = new JSONArray(); for (JSONObject tier : tiersList) { tiersArray.put(tier); } return tiersArray.toString(); }
/** * Serialize the List * * @return The list as a String */ String serialize() { JSONArray array = new JSONArray(); for (Tile t : this) { array.put(t.json()); } return array.toString(); }
@RequestMapping(value = "/postResponse", method = RequestMethod.POST) public void postResponseToGroup( @ModelAttribute ParameterVO parameterVO, HttpServletRequest request, HttpServletResponse response, Model model) { String responseStatus = ApplicationConstants.GROUP_MESSAGE_POST_FAILURE; String responseMessage = ApplicationConstants.RESPONSE_FAILURE; JSONArray responseArray = new JSONArray(); JSONObject responseJson = new JSONObject(); try { // complete fetch basic objects from session dataAccessServiceManager.postResponse(parameterVO); if (parameterVO.isReponseStatus()) { responseMessage = ApplicationConstants.RESPONSE_SUCCESS; } response.setCharacterEncoding("UTF-8"); response.setContentType("text/html"); responseJson.put("message", responseMessage); responseArray.put(responseJson); response.getWriter().write(responseArray.toString()); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }
/** * Gets a JSON (JavaScript Object Notation) representation of all the specified events. * * @param events the events. * @return a JSON array with the JSON representation of all the specified events. */ public static String toJSON(final List<EventOccurrenceDTO> events) { JSONArray jsonArray = new JSONArray(); for (EventOccurrenceDTO event : events) { jsonArray.put(event.toJSONObject()); } return jsonArray.toString(); }
// 获取树 private String getRoleDatarangeTree() { JSONArray jsonArray = new JSONArray(); JSONObject jsonObject = new JSONObject(); jsonObject.put("id", "root"); jsonObject.put("pId", ""); jsonObject.put("name", "范围"); jsonObject.put("open", true); jsonArray.put(jsonObject); // JSONArray dataArray = dataContainerService.getDataContainerTree(); JSONArray datarangeArray = datarangeService.getDatarangeRootTree(); JSONArray queueArray = QueueManager.getQueueTree(); // JSONArray customerPoolsArray = customerPoolService.getPoolsTree(); // for(int i = 0; i < dataArray.length(); i++) { // jsonArray.put(dataArray.get(i)); // } for (int i = 0; i < datarangeArray.length(); i++) { jsonArray.put(datarangeArray.get(i)); } for (int i = 0; i < queueArray.length(); i++) { jsonArray.put(queueArray.get(i)); } // for(int i = 0; i < customerPoolsArray.length(); i++) { // jsonArray.put(customerPoolsArray.get(i)); // } // return jsonArray.toString(); }
protected void onPostExecute(JSONArray result) { dialog.dismiss(); Util.log("GetFeedAsync", result.toString()); for (int i = 0; i < result.length(); i++) { HashMap<String, String> cdr; try { cdr = new HashMap<>(); JSONObject jsonItems = result.getJSONObject(i); cdr.put("id", jsonItems.get("id").toString()); cdr.put("user", jsonItems.get("user").toString()); cdr.put("topicid", jsonItems.get("topicid").toString()); cdr.put("caption", jsonItems.get("caption").toString()); cdr.put("image", jsonItems.get("image").toString()); cdr.put("thumbsup", jsonItems.get("thumbsup").toString()); cdr.put("datecreated", jsonItems.get("datecreated").toString()); cdr.put("isregistered", jsonItems.get("isregistered").toString()); list.add(cdr); } catch (JSONException e) { e.printStackTrace(); } } adapter.notifyDataSetChanged(); // parseResult(result); }
/** * Creates the root view of the fragement, set title, the version number and the listener for the * download button. * * @return The fragment's root view. */ @Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = getLayoutView(); versionHelper = new VersionHelper(versionInfo.toString(), this); TextView nameLabel = (TextView) view.findViewById(UpdateView.NAME_LABEL_ID); nameLabel.setText(getAppName()); TextView versionLabel = (TextView) view.findViewById(UpdateView.VERSION_LABEL_ID); versionLabel.setText( "Version " + versionHelper.getVersionString() + "\n" + versionHelper.getFileInfoString()); Button updateButton = (Button) view.findViewById(UpdateView.UPDATE_BUTTON_ID); updateButton.setOnClickListener(this); WebView webView = (WebView) view.findViewById(UpdateView.WEB_VIEW_ID); webView.clearCache(true); webView.destroyDrawingCache(); webView.loadDataWithBaseURL( Constants.BASE_URL, versionHelper.getReleaseNotes(), "text/html", "utf-8", null); return view; }
public String getPersonaggiStoriciJSON() { logger.info("ListaPersonaggi JSON"); String res = ""; Sparql sp = new Sparql(queryPersonaggiStorici, endpoint); JSONObject result = new JSONObject(sp.returnJSON()); JSONArray jarray = result.getJSONObject("results").getJSONArray("bindings"); JSONArray arrayRisultati = new JSONArray(); // riscrivamo i risultati in maniera piu bella for (int i = 0; i < jarray.length(); i++) { JSONObject row = new JSONObject(); String uri = jarray.getJSONObject(i).getJSONObject("person").getString("value"); String name = jarray.getJSONObject(i).getJSONObject("name").getString("value"); String job = ""; if (jarray.getJSONObject(i).has("job")) job = jarray.getJSONObject(i).getJSONObject("job").getString("value"); row.accumulate("URI", uri); row.accumulate("name", name); row.accumulate("icona", Place.returnJobIcona(job)); row.accumulate( "detailEndpoint", ServerTomcat + infoPersonaggio + uri.replace("http://www.trentinocultura.net/asp_cat/main.asp?", "")); arrayRisultati.put(row); } logger.info("Restituiti " + arrayRisultati.length() + " personaggi storici"); // return sp.returnJSON(); return arrayRisultati.toString(); }
@SuppressWarnings("rawtypes") @Test public void assertContent() { TreeView treeView = (TreeView) getPrimaryStage().getScene().getRoot().lookup(".tree-view"); int expandedItemCount = treeView.getExpandedItemCount(); TreeItem treeItem = treeView.getTreeItem(expandedItemCount - 1); treeItem.setExpanded(true); final Object[] content = new Object[] {null}; Platform.runLater( new Runnable() { @Override public void run() { RFXTreeView rTreeView = new RFXTreeView(treeView, null, null, null); content[0] = rTreeView.getContent(); } }); new Wait("Waiting for contents.") { @Override public boolean until() { return content[0] != null; } }; JSONArray a = new JSONArray(content[0]); Assert.assertEquals( "[[\"Root node\",\"Child Node 1\",\"Child Node 2\",\"Child Node 3\",\"Child Node 4\",\"Child Node 5\",\"Child Node 6\",\"Child Node 7\",\"Child Node 8\",\"Child Node 9\",\"Child Node 10\",\"Child Node 11\",\"Child Node 12\",\"Child Node 13\",\"Child Node 14\",\"Child Node 15\",\"Child Node 16\",\"Child Node 17\",\"Child Node 18\",\"Child Node 19\",\"Child Node 20\",\"Child Node 21\",\"Child Node 22\",\"Child Node 23\",\"Child Node 24\"]]", a.toString()); }
private String getNotes(String sortOrder) { Uri uri = NoteTable.CONTENT_URI; ContentResolver cr = getContentResolver(); String[] projection = new String[] { NoteTable._ID, NoteTable.TITLE, NoteTable.DESCRIPTION, NoteTable.MODIFIED_DATE, NoteTable.TYPE }; Cursor c = cr.query(uri, projection, null, null, sortOrder); int iId = c.getColumnIndex(NoteTable._ID); int iTitle = c.getColumnIndex(NoteTable.TITLE); int iDescription = c.getColumnIndex(NoteTable.DESCRIPTION); int iType = c.getColumnIndex(NoteTable.TYPE); JSONArray res = new JSONArray(); try { for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) { JSONObject jsonObject = new JSONObject(); jsonObject.put(NoteTable._ID, c.getString(iId)); jsonObject.put(NoteTable.TITLE, c.getString(iTitle)); jsonObject.put(NoteTable.DESCRIPTION, c.getString(iDescription)); jsonObject.put(NoteTable.TYPE, c.getInt(iType)); res.put(jsonObject); } } catch (JSONException e) { e.printStackTrace(); } return res.toString(); }
public void a(List<PackageInfo> paramList) { JSONArray localJSONArray1; try { localJSONArray1 = new JSONArray(); Iterator localIterator = paramList.iterator(); while (localIterator.hasNext()) { PackageInfo localPackageInfo = (PackageInfo) localIterator.next(); JSONObject localJSONObject = new JSONObject(); localJSONObject.put("name", localPackageInfo.packageName); JSONArray localJSONArray2 = new JSONArray(); PermissionInfo[] arrayOfPermissionInfo = localPackageInfo.permissions; int i = arrayOfPermissionInfo.length; for (int j = 0; j < i; j++) localJSONArray2.put(arrayOfPermissionInfo[j].name); localJSONObject.put("permissions", localJSONArray2); localJSONArray1.put(localJSONObject); } } catch (JSONException localJSONException) { BLog.e("MalwareDetector", localJSONException.getMessage()); } while (true) { return; HoneyClientEvent localHoneyClientEvent = new HoneyClientEvent("android_malware_detected_event"); localHoneyClientEvent.d("malware_detector"); localHoneyClientEvent.b("description", localJSONArray1.toString()); this.b.b(localHoneyClientEvent); } }
protected String i() { JSONArray localJSONArray = new JSONArray(); Iterator localIterator = this.a.iterator(); while (localIterator.hasNext()) { GraphApiMethod localGraphApiMethod = (GraphApiMethod) localIterator.next(); JSONObject localJSONObject = new JSONObject(); try { localJSONObject.put("method", localGraphApiMethod.k); if (localGraphApiMethod.k.equals("POST")) { localJSONObject.put("relative_url", localGraphApiMethod.a(false, false)); localJSONObject.put("body", localGraphApiMethod.e().toString()); String str1 = localGraphApiMethod.h(); if (!StringUtils.c(str1)) localJSONObject.put("depends_on", str1); String str2 = localGraphApiMethod.g(); if (!StringUtils.c(str2)) localJSONObject.put("name", str2); localJSONObject.put("omit_response_on_success", false); localJSONArray.put(localJSONObject); } } catch (JSONException localJSONException) { while (true) { Log.a(g, "error while constructing the batch param", localJSONException); break; localJSONObject.put("relative_url", localGraphApiMethod.a(false, true)); } } catch (UnsupportedEncodingException localUnsupportedEncodingException) { Log.a(g, "error encoding something for the batch param", localUnsupportedEncodingException); } } return localJSONArray.toString(); }
@Override public PluginResult execute(final String action, final JSONArray data, final String callbackId) { Log.v(TAG + ":execute", "action=" + action); PluginResult result = null; if (REGISTER.equals(action)) { Log.v(TAG + ":execute", "data=" + data.toString()); try { JSONObject json = data.getJSONObject(0); callbackFunction = (String) json.get("callback"); currentPluginInstance = this; result = new PluginResult(Status.OK); } catch (JSONException e) { Log.e(TAG, "Got JSON Exception " + e.getMessage()); result = new PluginResult(Status.JSON_EXCEPTION); } } else if (UNREGISTER.equals(action)) { currentPluginInstance = null; result = new PluginResult(Status.OK); } else { Log.e(TAG, "Invalid action : " + action); result = new PluginResult(Status.INVALID_ACTION); } return result; }
/** 插入影片下载数据 */ public synchronized long insertMovieStore(DownLoadInfo downLoadInfo) { if (isStoreByUrl(downLoadInfo.getDownUrl())) return PipiPlayerConstant.ISEXIT_NORMOL; long sec = -1; try { ContentValues values = new ContentValues(); values.put(TableName.MovieID, downLoadInfo.getDownID()); values.put(TableName.MovieName, downLoadInfo.getDownName()); values.put(TableName.MovieImgUrl, downLoadInfo.getDownImg()); values.put(TableName.MovieUrl, downLoadInfo.getDownUrl()); values.put(TableName.MoviePlaySourKey, downLoadInfo.getDownTag()); ArrayList<String> list = downLoadInfo.getPlayList(); JSONArray array = new JSONArray(); for (String string : list) array.put(string); values.put(TableName.MoviePlayList, array.toString()); values.put(TableName.MoviePlayPosition, downLoadInfo.getDownPosition()); Log.i("TAG999", "insertMovieStore MoviePlayPosition===" + downLoadInfo.getDownPosition()); database = pipiDBHelp.getWritableDatabase(); sec = database.insert(PipiDBHelp.STORE_TABLENAME, null, values); } catch (Exception e) { // TODO: handle exception } return sec; }
/** * Gets a JSON (JavaScript Object Notation) representation of all the specified events. * * @param events the events. * @return a JSON array with the JSON representation of all the specified events. */ public static String toJSON(final List<DisplayableEventOccurrence> events) { JSONArray jsonArray = new JSONArray(); for (DisplayableEventOccurrence event : events) { jsonArray.put(event.toJSONObject()); } return jsonArray.toString(); }