public void setBackgroundFromProperties(TiDict props) {
   if (props.containsKey("backgroundImage")) {
     setBackgroundImageProperty(props, "backgroundImage");
   } else if (props.containsKey("backgroundColor")) {
     Integer bgColor = TiConvert.toColor(props, "backgroundColor", "opacity");
     setBackgroundColor(bgColor);
   }
 }
Esempio n. 2
0
  @Override
  public void processProperties(TiDict d) {
    super.processProperties(d);

    TextView tv = (TextView) getNativeView();
    // Only accept one, prefer text to title.
    if (d.containsKey("text")) {
      tv.setText(TiConvert.toString(d, "text"));
    } else if (d.containsKey("title")) { // TODO this may not need to be supported.
      tv.setText(TiConvert.toString(d, "title"));
    }

    if (d.containsKey("color")) {
      tv.setTextColor(TiConvert.toColor(d, "color"));
    }
    if (d.containsKey("highlightedColor")) {
      tv.setHighlightColor(TiConvert.toColor(d, "highlightedColor"));
    }
    if (d.containsKey("font")) {
      TiUIHelper.styleText(tv, d.getTiDict("font"));
    }
    if (d.containsKey("textAlign")) {
      String textAlign = d.getString("textAlign");
      setAlignment(tv, textAlign);
    }
    tv.invalidate();
  }
Esempio n. 3
0
  @Override
  public Object get(String name, Scriptable start) {
    if (this.has(name, start)) {
      return super.get(name, start);
    }
    if (target instanceof TiProxy) {
      TiDict constants = ((TiProxy) target).getConstants();
      if (constants != null) {
        if (constants.containsKey(name)) {
          Object value = constants.get(name);
          super.putConst(name, start, value);
          return value;
        }
      }
    }

    if (DBG) {
      Log.d(LCAT, "get name: " + name);
    }
    Object o = NOT_FOUND;

    // If starts with Capital letter see if there is a module for it.
    if (name.matches("^[A-Z].*") || name.matches("iPhone")) {
      Object p = loadModule(name);
      if (p != null) {
        o = new KrollObject(this, p);
        put(name, this, o);
        ((TiModule) p).postCreate();
      }
    } else {
      if (DBG) {
        Log.d(LCAT, "Start: " + start.getClassName() + " looking for method:" + name);
      }
      o = handleMethodOrProperty(name, start, true, null);
    }

    return o;
  }
Esempio n. 4
0
  @Override
  public void processProperties(TiDict d) {
    TiImageView view = getView();

    if (d.containsKey("images")) {
      Object o = d.get("images");
      if (o instanceof Object[]) {
        setImages((Object[]) o);
      }
    } else if (d.containsKey("url")) {
      Log.w(LCAT, "The url property of ImageView is deprecated, use image instead.");
      if (!d.containsKey("image")) {
        d.put("image", d.get("url"));
      }
    }
    if (d.containsKey("canScale")) {
      view.setCanScaleImage(TiConvert.toBoolean(d, "canScale"));
    }
    if (d.containsKey("enableZoomControls")) {
      view.setEnableZoomControls(TiConvert.toBoolean(d, "enableZoomControls"));
    }
    if (d.containsKey("image")) {
      Object image = d.get("image");
      if (image instanceof String) {
        String imageURL = TiConvert.toString(d, "image");
        if (URLUtil.isNetworkUrl(imageURL)) {
          synchronized (imageTokenGenerator) {
            token = imageTokenGenerator.incrementAndGet();
            getView().setImageDrawable(null);
            new BgImageLoader(getProxy().getTiContext(), null, null, token).load(imageURL);
          }
        } else {
          setImage(createBitmap(imageURL));
        }
      } else {
        setImage(createBitmap(image));
      }

    } else {
      getProxy().internalSetDynamicValue("image", null, false);
    }

    super.processProperties(d);
  }
Esempio n. 5
0
  @Override
  public void processProperties(TiDict d) {
    super.processProperties(d);

    if (d.containsKey("enabled")) {
      tv.setEnabled(d.getBoolean("enabled"));
    }
    if (d.containsKey("value")) {
      tv.setText(d.getString("value"));
    }
    if (d.containsKey("color")) {
      tv.setTextColor(TiConvert.toColor(d, "color"));
    }
    if (d.containsKey("hintText")) {
      tv.setHint(d.getString("hintText"));
    }
    if (d.containsKey("font")) {
      TiUIHelper.styleText(tv, d.getTiDict("font"));
    }
    if (d.containsKey("textAlign") || d.containsKey("verticalAlign")) {
      String textAlign = null;
      String verticalAlign = null;
      if (d.containsKey("textAlign")) {
        textAlign = d.getString("textAlign");
      }
      if (d.containsKey("verticalAlign")) {
        verticalAlign = d.getString("verticalAlign");
      }
      handleTextAlign(textAlign, verticalAlign);
    }
    if (d.containsKey("returnKeyType")) {
      handleReturnKeyType(d.getInt("returnKeyType"));
    }
    if (d.containsKey("keyboardType")) {
      boolean autocorrect = true;
      if (d.containsKey("autocorrect")) {
        autocorrect = d.getBoolean("autocorrect");
      }
      handleKeyboardType(d.getInt("keyboardType"), autocorrect);
    }

    if (d.containsKey("autocapitalization")) {

      Capitalize autoCapValue = null;

      switch (d.getInt("autocapitalization")) {
        case TEXT_AUTOCAPITALIZATION_NONE:
          autoCapValue = Capitalize.NONE;
          break;

        case TEXT_AUTOCAPITALIZATION_ALL:
          autoCapValue = Capitalize.CHARACTERS;
          break;

        case TEXT_AUTOCAPITALIZATION_SENTENCES:
          autoCapValue = Capitalize.SENTENCES;
          break;

        case TEXT_AUTOCAPITALIZATION_WORDS:
          autoCapValue = Capitalize.WORDS;
          break;

        default:
          Log.w(
              LCAT, "Unknown AutoCapitalization Value [" + d.getString("autocapitalization") + "]");
          break;
      }

      if (null != autoCapValue) {
        tv.setKeyListener(TextKeyListener.getInstance(false, autoCapValue));
      }
    }

    if (d.containsKey("passwordMask")) {
      if (TiConvert.toBoolean(d.get("passwordMask"))) {
        // This shouldn't be needed but it's belts & braces
        tv.setKeyListener(TextKeyListener.getInstance(false, Capitalize.NONE));
        // Both setTransform & keyboard type are required
        tv.setTransformationMethod(PasswordTransformationMethod.getInstance());
        // We also need to set the keyboard type - otherwise the password mask won't be applied
        handleKeyboardType(KEYBOARD_PASSWORD, false);
      }
    }
  }
Esempio n. 6
0
  @Override
  public void propertyChanged(String key, Object oldValue, Object newValue, TiProxy proxy) {
    if (DBG) {
      Log.d(LCAT, "Property: " + key + " old: " + oldValue + " new: " + newValue);
    }
    if (key.equals("enabled")) {
      tv.setEnabled(TiConvert.toBoolean(newValue));
    } else if (key.equals("value")) {
      tv.setText((String) newValue);
    } else if (key.equals("color")) {
      tv.setTextColor(TiConvert.toColor((String) newValue));
    } else if (key.equals("passwordMask")) {
      if (TiConvert.toBoolean(newValue) == true) {
        // This shouldn't be needed but it's belts & braces
        tv.setKeyListener(TextKeyListener.getInstance(false, Capitalize.NONE));
        // Both setTransform & keyboard type are required
        tv.setTransformationMethod(PasswordTransformationMethod.getInstance());
        // We also need to set the keyboard type - otherwise the password mask won't be applied
        handleKeyboardType(KEYBOARD_PASSWORD, false);
      } else {
        handleKeyboardType(KEYBOARD_DEFAULT, false);
      }
    } else if (key.equals("hintText")) {
      tv.setHint((String) newValue);
    } else if (key.equals("textAlign") || key.equals("verticalAlign")) {
      String textAlign = null;
      String verticalAlign = null;
      if (key.equals("textAlign")) {
        textAlign = TiConvert.toString(newValue);
      }
      if (key.equals("verticalAlign")) {
        verticalAlign = TiConvert.toString(newValue);
      }
      handleTextAlign(textAlign, verticalAlign);
    } else if (key.equals("autocapitalization")) {

      // TODO Missing
      Capitalize autoCapValue = null;

      switch (TiConvert.toInt(newValue)) {
        case TEXT_AUTOCAPITALIZATION_NONE:
          autoCapValue = Capitalize.NONE;
          break;

        case TEXT_AUTOCAPITALIZATION_ALL:
          autoCapValue = Capitalize.CHARACTERS;
          break;

        case TEXT_AUTOCAPITALIZATION_SENTENCES:
          autoCapValue = Capitalize.SENTENCES;
          break;

        case TEXT_AUTOCAPITALIZATION_WORDS:
          autoCapValue = Capitalize.WORDS;
          break;

        default:
          Log.w(LCAT, "Unknown AutoCapitalization Value [" + TiConvert.toString(newValue) + "]");
          break;
      }

      if (null != autoCapValue) {
        tv.setKeyListener(TextKeyListener.getInstance(false, autoCapValue));
      }

    } else if (key.equals("keyboardType") || (key.equals("autocorrect"))) {
      TiDict d = proxy.getDynamicProperties();
      boolean autocorrect = false;
      if (d.containsKey("autocorrect")) {
        autocorrect = d.getBoolean("autocorrect");
      }

      handleKeyboardType(TiConvert.toInt(d, "keyboardType"), autocorrect);
    } else if (key.equals("returnKeyType")) {
      handleReturnKeyType(TiConvert.toInt(newValue));
    } else if (key.equals("font")) {
      TiUIHelper.styleText(tv, (TiDict) newValue);
    } else {
      super.propertyChanged(key, oldValue, newValue, proxy);
    }
  }