Beispiel #1
0
  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);
  }
Beispiel #2
0
  private boolean commitValue() throws ElementFailureException {
    try {
      Utils.runCommand(command + " \"" + lastEdit.toString() + '"');
      String result = getLiveValue();

      if (!result.equals(getStoredValue())) Utils.db.setValue(command, result);

      try {
        stored = Integer.parseInt(result);
      } catch (NumberFormatException ignored) {
        stored = result;
      }

      lastLive = lastEdit = stored;
      textView.setText(lastLive.toString());
      if (editText != null && editText.getParent() != null)
        if (((LinearLayout) editText.getParent()).findViewById(tv_id) == textView)
          editText.setText(lastLive.toString());
      valueCheck();

      return true;
    } catch (Exception e) {
      throw new ElementFailureException(this, e);
    }
  }
Beispiel #3
0
 public static void loadSections() {
   if (Utils.configSections == null) {
     JSONObject resultsJSONObject = Utils.getJSON();
     if (resultsJSONObject == null) {
       Synapse.currentEnvironmentState = Synapse.environmentState.JSON_FAILURE;
       return;
     }
     Utils.configSections = (JSONArray) resultsJSONObject.get("sections");
   }
 }
Beispiel #4
0
  /** ActivityListener methods */
  @Override
  public void onMainStart() throws ElementFailureException {
    if (!Utils.mainActivity.isChangingConfigurations() && Utils.appStarted)
      Synapse.executor.execute(resumeTask);

    if (!Utils.mainActivity.isChangingConfigurations() && !Utils.appStarted)
      try {
        ActionValueNotifierHandler.addNotifiers(this);
      } catch (Exception e) {
        Utils.createElementErrorView(new ElementFailureException(this, e));
      }
  }
Beispiel #5
0
 /** ActionValueClient methods */
 @Override
 public String getLiveValue() throws ElementFailureException {
   try {
     String value = Utils.runCommand(command);
     try {
       lastLive = Integer.parseInt(value);
     } catch (NumberFormatException ignored) {
       lastLive = value;
     }
     return value;
   } catch (Exception e) {
     throw new ElementFailureException(this, e);
   }
 }
Beispiel #6
0
  @Override
  public View getView() throws ElementFailureException {
    if (elementView != null) return elementView;

    LinearLayout v =
        (LinearLayout)
            LayoutInflater.from(Utils.mainActivity)
                .inflate(R.layout.template_livelabel, this.layout, false);

    assert v != null;
    elementView = v;

    /** Nesting another element's view in our own for title and description. */
    LinearLayout descriptionFrame = (LinearLayout) v.findViewById(R.id.SLiveLabel_descriptionFrame);

    if (titleObj != null) {
      TextView titleView = (TextView) titleObj.getView();
      titleView.setBackground(null);
      descriptionFrame.addView(titleView);
    }

    if (descriptionObj != null) descriptionFrame.addView(descriptionObj.getView());

    liveLabel = (TextView) v.findViewById(R.id.SLiveLabel_textView);

    if (style != null) {
      if (style.contains("bold") && style.contains("italic")) {
        liveLabel.setTypeface(liveLabel.getTypeface(), Typeface.BOLD_ITALIC);
        return v;
      }

      if (style.contains("bold")) liveLabel.setTypeface(liveLabel.getTypeface(), Typeface.BOLD);

      if (style.contains("italic")) liveLabel.setTypeface(liveLabel.getTypeface(), Typeface.ITALIC);
    }

    try {
      liveLabel.setText(Utils.runCommand(command).replace("@n", "\n"));
    } catch (Exception e) {
      throw new ElementFailureException(this, e);
    }

    return v;
  }
Beispiel #7
0
  public static JSONObject getJSON() {
    JSONObject result;

    String res = null;
    try {
      res = Utils.runCommandWithException("uci config", true);
    } catch (Exception e) {
      L.e("Can't access live customconfig: " + e.getMessage());
      return null;
    }

    try {
      result = (JSONObject) JSONValue.parse(res);
    } catch (ClassCastException e) {
      L.e(e.getMessage());
      return null;
    }

    return result;
  }