public static JSONObject toJSON() throws JSONException { final JSONObject object = new JSONObject(); final JSONArray array = new JSONArray(); for (final TouchProfile p : profiles.values()) { array.put(p.toJSON()); } object.put("profiles", array); return object; }
public static void loadFromSettings(final AppSettings newSettings) { profiles.clear(); stack.clear(); boolean fromJSON = false; final String str = newSettings.tapProfiles; if (LengthUtils.isNotEmpty(str)) { try { final List<TouchProfile> list = fromJSON(str); for (final TouchProfile p : list) { profiles.put(p.name, p); } } catch (final Throwable ex) { LCTX.e("Error on tap configuration load: ", ex); } fromJSON = profiles.containsKey(DEFAULT_PROFILE); } if (!fromJSON) { if (LCTX.isDebugEnabled()) { LCTX.d("Creating default tap configuration..."); } final TouchProfile def = addProfile(DEFAULT_PROFILE); { final Region r = def.addRegion(0, 0, 100, 100); r.setAction(Touch.DoubleTap, R.id.actions_openOptionsMenu, true); } { final Region r = def.addRegion(0, 0, 100, 10); r.setAction(Touch.SingleTap, R.id.actions_verticalConfigScrollUp, true); } { final Region r = def.addRegion(0, 90, 100, 100); r.setAction(Touch.SingleTap, R.id.actions_verticalConfigScrollDown, true); } persist(); } stack.addFirst(profiles.get(DEFAULT_PROFILE)); }
private static List<TouchProfile> fromJSON(final String str) throws JSONException { final List<TouchProfile> list = new ArrayList<TouchProfile>(); final JSONObject root = new JSONObject(str); final JSONArray profiles = root.getJSONArray("profiles"); for (int pIndex = 0; pIndex < profiles.length(); pIndex++) { final JSONObject p = profiles.getJSONObject(pIndex); final TouchProfile profile = TouchProfile.fromJSON(p); list.add(profile); } return list; }