예제 #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);
  }
예제 #2
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));
      }
  }
예제 #3
0
 @Override
 public void setDefaults() {
   if (original != null) {
     lastEdit = lastLive = original;
     textView.setText(lastLive.toString());
     if (editText != null && editText.getParent() != null)
       if (((LinearLayout) editText.getParent()).findViewById(tv_id) == textView)
         editText.setText(lastLive.toString());
     valueCheck();
   }
   ActionValueNotifierHandler.propagate(this, ActionValueEvent.RESET);
 }
예제 #4
0
  /** OnKeyListener methods */
  @Override
  public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
    if (actionId == EditorInfo.IME_ACTION_DONE
        || event.getAction() == KeyEvent.ACTION_DOWN
            && event.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
      editText.clearFocus();
      Utils.imm.hideSoftInputFromWindow(elementView.getWindowToken(), 0);

      String text = v.getText().toString();
      try {
        lastEdit = Integer.parseInt(text);
      } catch (NumberFormatException ignored) {
        lastEdit = text;
      }

      textView.setText(text);
      textView.setVisibility(View.VISIBLE);
      elementFrame.removeView(editText);
      valueCheck();
      ActionValueNotifierHandler.propagate(this, ActionValueEvent.SET);
    }

    return false;
  }
예제 #5
0
 @Override
 public void cancelValue() throws ElementFailureException {
   lastEdit = lastLive = stored;
   commitValue();
   ActionValueNotifierHandler.propagate(this, ActionValueEvent.CANCEL);
 }
예제 #6
0
 @Override
 public void applyValue() throws ElementFailureException {
   commitValue();
   ActionValueNotifierHandler.propagate(this, ActionValueEvent.APPLY);
 }