@Override public void propertyChanged(String key, Object oldValue, Object newValue, KrollProxy proxy) { if (Log.isDebugModeEnabled()) { Log.d(TAG, "Property: " + key + " old: " + oldValue + " new: " + newValue, Log.DEBUG_MODE); } if (key.equals(TiC.PROPERTY_ENABLED)) { tv.setEnabled(TiConvert.toBoolean(newValue)); } else if (key.equals(TiC.PROPERTY_VALUE)) { tv.setText(TiConvert.toString(newValue)); } else if (key.equals(TiC.PROPERTY_MAX_LENGTH)) { maxLength = TiConvert.toInt(newValue); // truncate if current text exceeds max length Editable currentText = tv.getText(); if (maxLength >= 0 && currentText.length() > maxLength) { CharSequence truncateText = currentText.subSequence(0, maxLength); int cursor = tv.getSelectionStart() - 1; if (cursor > maxLength) { cursor = maxLength; } tv.setText(truncateText); tv.setSelection(cursor); } } else if (key.equals(TiC.PROPERTY_COLOR)) { tv.setTextColor(TiConvert.toColor((String) newValue)); } else if (key.equals(TiC.PROPERTY_HINT_TEXT)) { tv.setHint((String) newValue); } else if (key.equals(TiC.PROPERTY_ELLIPSIZE)) { if (TiConvert.toBoolean(newValue)) { tv.setEllipsize(TruncateAt.END); } else { tv.setEllipsize(null); } } else if (key.equals(TiC.PROPERTY_TEXT_ALIGN) || key.equals(TiC.PROPERTY_VERTICAL_ALIGN)) { String textAlign = null; String verticalAlign = null; if (key.equals(TiC.PROPERTY_TEXT_ALIGN)) { textAlign = TiConvert.toString(newValue); } else if (proxy.hasProperty(TiC.PROPERTY_TEXT_ALIGN)) { textAlign = TiConvert.toString(proxy.getProperty(TiC.PROPERTY_TEXT_ALIGN)); } if (key.equals(TiC.PROPERTY_VERTICAL_ALIGN)) { verticalAlign = TiConvert.toString(newValue); } else if (proxy.hasProperty(TiC.PROPERTY_VERTICAL_ALIGN)) { verticalAlign = TiConvert.toString(proxy.getProperty(TiC.PROPERTY_VERTICAL_ALIGN)); } handleTextAlign(textAlign, verticalAlign); } else if (key.equals(TiC.PROPERTY_KEYBOARD_TYPE) || (key.equals(TiC.PROPERTY_AUTOCORRECT) || key.equals(TiC.PROPERTY_AUTOCAPITALIZATION) || key.equals(TiC.PROPERTY_PASSWORD_MASK) || key.equals(TiC.PROPERTY_EDITABLE))) { KrollDict d = proxy.getProperties(); handleKeyboard(d); } else if (key.equals(TiC.PROPERTY_RETURN_KEY_TYPE)) { handleReturnKeyType(TiConvert.toInt(newValue)); } else if (key.equals(TiC.PROPERTY_FONT)) { TiUIHelper.styleText(tv, (HashMap) newValue); } else if (key.equals(TiC.PROPERTY_AUTO_LINK)) { TiUIHelper.linkifyIfEnabled(tv, newValue); } else { super.propertyChanged(key, oldValue, newValue, proxy); } }
@Override public void processProperties(KrollDict d) { super.processProperties(d); if (d.containsKey(TiC.PROPERTY_ENABLED)) { tv.setEnabled(TiConvert.toBoolean(d, TiC.PROPERTY_ENABLED, true)); } if (d.containsKey(TiC.PROPERTY_MAX_LENGTH) && field) { maxLength = TiConvert.toInt(d.get(TiC.PROPERTY_MAX_LENGTH), -1); } // Disable change event temporarily as we are setting the default value disableChangeEvent = true; if (d.containsKey(TiC.PROPERTY_VALUE)) { tv.setText(d.getString(TiC.PROPERTY_VALUE)); } else { tv.setText(""); } disableChangeEvent = false; if (d.containsKey(TiC.PROPERTY_COLOR)) { tv.setTextColor(TiConvert.toColor(d, TiC.PROPERTY_COLOR)); } if (d.containsKey(TiC.PROPERTY_HINT_TEXT)) { tv.setHint(d.getString(TiC.PROPERTY_HINT_TEXT)); } if (d.containsKey(TiC.PROPERTY_ELLIPSIZE)) { if (TiConvert.toBoolean(d, TiC.PROPERTY_ELLIPSIZE)) { tv.setEllipsize(TruncateAt.END); } else { tv.setEllipsize(null); } } if (d.containsKey(TiC.PROPERTY_FONT)) { TiUIHelper.styleText(tv, d.getKrollDict(TiC.PROPERTY_FONT)); } if (d.containsKey(TiC.PROPERTY_TEXT_ALIGN) || d.containsKey(TiC.PROPERTY_VERTICAL_ALIGN)) { String textAlign = null; String verticalAlign = null; if (d.containsKey(TiC.PROPERTY_TEXT_ALIGN)) { textAlign = d.getString(TiC.PROPERTY_TEXT_ALIGN); } if (d.containsKey(TiC.PROPERTY_VERTICAL_ALIGN)) { verticalAlign = d.getString(TiC.PROPERTY_VERTICAL_ALIGN); } handleTextAlign(textAlign, verticalAlign); } if (d.containsKey(TiC.PROPERTY_RETURN_KEY_TYPE)) { handleReturnKeyType(TiConvert.toInt(d.get(TiC.PROPERTY_RETURN_KEY_TYPE), RETURNKEY_DEFAULT)); } if (d.containsKey(TiC.PROPERTY_KEYBOARD_TYPE) || d.containsKey(TiC.PROPERTY_AUTOCORRECT) || d.containsKey(TiC.PROPERTY_PASSWORD_MASK) || d.containsKey(TiC.PROPERTY_AUTOCAPITALIZATION) || d.containsKey(TiC.PROPERTY_EDITABLE)) { handleKeyboard(d); } if (d.containsKey(TiC.PROPERTY_AUTO_LINK)) { TiUIHelper.linkifyIfEnabled(tv, d.get(TiC.PROPERTY_AUTO_LINK)); } }