Back to project page Android-Apps.
The source code is released under:
Apache License
If you think the Android project Android-Apps listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.kniezrec.remoterecorder; //from w ww . j a v a2 s.c o m import org.json.JSONException; import org.json.JSONObject; public enum Communication { START_REC(100), STOP_REC(200), GET_FILENAME(400), GET_FILES(401), DOWNLOAD_FILE( 402), CANCEL(403), DELETE_FILE(405), CHANGE_TIME(406), NOTHING(0); private final int type; Communication(int i) { this.type = i; } private static Communication fromInteger(int x) { switch (x) { case 100: return START_REC; case 200: return STOP_REC; case 400: return GET_FILENAME; case 401: return GET_FILES; case 402: return DOWNLOAD_FILE; case 403: return CANCEL; case 405: return DELETE_FILE; default: return NOTHING; } } public static Communication getRequestCode(byte[] data) { String strToUpdateUI; if (data == null) { strToUpdateUI = "0"; } else { strToUpdateUI = new String(data); } Communication req = Communication.NOTHING; int code; try { code = Integer.parseInt(strToUpdateUI); req = Communication.fromInteger(code); } catch (NumberFormatException e) { code = -1; } if (code == -1) { try { JSONObject json = new JSONObject(strToUpdateUI); String reqType = json.optString("request"); if (reqType.equals("get")) { return Communication.DOWNLOAD_FILE; } else if (reqType.equals("delete")) { return Communication.DELETE_FILE; } else if (reqType.equals("newTime")) { return Communication.CHANGE_TIME; } } catch (JSONException e) { e.printStackTrace(); } } return req; } public int getNumericType() { return type; } }