Ejemplo n.º 1
0
  /** @see Widget.setProperty. */
  @Override
  public boolean setProperty(String property, String value)
      throws PropertyConversionException, InvalidPropertyValueException {
    if (super.setProperty(property, value)) {
      return true;
    }

    TextView textView = (TextView) getView();
    if (property.equals(IX_WIDGET.MAW_LABEL_TEXT)) {
      textView.setText(value);
    } else if (property.equals(IX_WIDGET.MAW_EDIT_BOX_PLACEHOLDER)) {
      textView.setHint(value);
    } else if (property.equals(IX_WIDGET.MAW_LABEL_FONT_COLOR)) {
      textView.setTextColor(ColorConverter.convert(value));
    } else if (property.equals(IX_WIDGET.MAW_LABEL_FONT_SIZE)) {
      textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, FloatConverter.convert(value));
    } else if (property.equals(Types.WIDGET_PROPERTY_TEXT_HORIZONTAL_ALIGNMENT)) {
      mHorizontalGravity = HorizontalAlignment.convert(value);
      textView.setGravity(mHorizontalGravity | mVerticalGravity);
    } else if (property.equals(Types.WIDGET_PROPERTY_TEXT_VERTICAL_ALIGNMENT)) {
      mVerticalGravity = VerticalAlignment.convert(value);
      textView.setGravity(mHorizontalGravity | mVerticalGravity);
    } else if (property.equals(IX_WIDGET.MAW_LABEL_MAX_NUMBER_OF_LINES)) {
      if (IntConverter.convert(value) < 0) {
        throw new InvalidPropertyValueException(property, value);
      }
      // This overrides any height setting.
      // Makes the TextView be at most this many lines tall.
      m_maxNrLines = IntConverter.convert(value);
      if (m_maxNrLines == 0) {
        textView.setMaxLines(Integer.MAX_VALUE);

      } else {
        textView.setMaxLines(m_maxNrLines);
      }
    } else if (property.equals(IX_WIDGET.MAW_LABEL_FONT_HANDLE)) {
      MoSyncFontHandle currentFont = null;

      // Search the handle in the list of fonts.
      currentFont = MoSyncThread.getMoSyncFont(IntConverter.convert(value));

      if (currentFont != null) {
        setFontTypeface(currentFont.getTypeface(), currentFont.getFontSize());
      } else throw new InvalidPropertyValueException(property, value);
    } else {
      return false;
    }

    return true;
  }