public SGeneric( JSONObject element, LinearLayout layout, MainActivity.TabSectionFragment fragment) { super(element, layout, fragment); if (element.containsKey("action")) this.command = (String) element.get("action"); else throw new IllegalArgumentException("SCheckBox has no action defined"); if (this.element.containsKey("label")) this.label = Utils.localise(element.get("label")); if (element.containsKey("default")) this.original = element.get("default"); if (element.containsKey("inputType")) this.inputType = (String) element.get("inputType"); /** Add a description element inside our own with the same JSON object */ if (element.containsKey("description")) descriptionObj = new SDescription(element, layout, fragment); if (element.containsKey("title")) titleObj = new STitleBar(element, layout, fragment); resumeTask = new Runnable() { @Override public void run() { try { refreshValue(); } catch (ElementFailureException e) { Utils.createElementErrorView(e); } } }; ActionValueNotifierHandler.register(this); }
public SLiveLabel( JSONObject element, LinearLayout layout, MainActivity.TabSectionFragment fragment) { super(element, layout, fragment); if (element.containsKey("action")) this.command = (String) element.get("action"); else throw new IllegalArgumentException("SSeekBar has no action defined"); if (element.containsKey("refresh")) { refreshInterval = (Integer) element.get("refresh"); if (refreshInterval != 0 && refreshInterval < 50) refreshInterval = 50; } if (element.containsKey("style")) style = (String) element.get("style"); resumeTask = new Runnable() { @Override public void run() { try { liveLabel.setText(Utils.runCommand(command).replace("@n", "\n")); if (refreshInterval > 0) Synapse.handler.postDelayed(this, refreshInterval); } catch (Exception e) { liveLabel.setText(e.getMessage()); } } }; /** Add a description element inside our own with the same JSON object */ if (element.containsKey("description")) descriptionObj = new SDescription(element, layout, fragment); if (element.containsKey("title")) titleObj = new STitleBar(element, layout, fragment); }
public static String localise(Object textObject) { if (textObject instanceof String) { return (String) textObject; } else if (textObject instanceof JSONObject) { JSONObject object = (JSONObject) textObject; String localeKey; if (object.containsKey(Utils.locale)) localeKey = Utils.locale; else if (object.containsKey(Utils.locale.substring(0, 2))) localeKey = Utils.locale.substring(0, 2); else localeKey = "en"; return (String) object.get(localeKey); } return null; }