Skip to content

Commit

Permalink
[TIMOB-18062] Android: TextField AttributedHintText is now supported.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashraf A. S committed Dec 12, 2014
1 parent 15aee43 commit c739c3b
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 8 deletions.
Expand Up @@ -24,6 +24,7 @@

@Kroll.proxy(creatableInModule=UIModule.class, propertyAccessors = {
TiC.PROPERTY_ATTRIBUTED_STRING,
TiC.PROPERTY_ATTRIBUTED_HINT_TEXT,
TiC.PROPERTY_AUTOCAPITALIZATION,
TiC.PROPERTY_AUTOCORRECT,
TiC.PROPERTY_AUTO_LINK,
Expand Down
Expand Up @@ -212,10 +212,17 @@ public void processProperties(KrollDict d)
handleKeyboard(d);
}

if (d.containsKey(TiC.PROPERTY_ATTRIBUTED_HINT_TEXT)) {
Object attributedString = d.get(TiC.PROPERTY_ATTRIBUTED_HINT_TEXT);
if (attributedString instanceof AttributedStringProxy) {
setAttributedStringHint((AttributedStringProxy) attributedString);
}
}

if (d.containsKey(TiC.PROPERTY_ATTRIBUTED_STRING)) {
Object attributedString = d.get(TiC.PROPERTY_ATTRIBUTED_STRING);
if (attributedString instanceof AttributedStringProxy) {
setAttributedString((AttributedStringProxy) attributedString);
setAttributedStringText((AttributedStringProxy) attributedString);
}
}

Expand Down Expand Up @@ -283,8 +290,10 @@ public void propertyChanged(String key, Object oldValue, Object newValue, KrollP
TiUIHelper.styleText(tv, (HashMap) newValue);
} else if (key.equals(TiC.PROPERTY_AUTO_LINK)) {
TiUIHelper.linkifyIfEnabled(tv, newValue);
} else if (key.equals(TiC.PROPERTY_ATTRIBUTED_HINT_TEXT) && newValue instanceof AttributedStringProxy) {
setAttributedStringHint((AttributedStringProxy) newValue);
} else if (key.equals(TiC.PROPERTY_ATTRIBUTED_STRING) && newValue instanceof AttributedStringProxy) {
setAttributedString((AttributedStringProxy) newValue);
setAttributedStringText((AttributedStringProxy) newValue);
} else {
super.propertyChanged(key, oldValue, newValue, proxy);
}
Expand Down Expand Up @@ -636,7 +645,15 @@ public void handleReturnKeyType(int type)
tv.setInputType(tv.getInputType());
}

public void setAttributedString(AttributedStringProxy attrString)
public void setAttributedStringText(AttributedStringProxy attrString){
tv.setText(attributedStringToSpannable(attrString));
}

public void setAttributedStringHint(AttributedStringProxy attrString){
tv.setHint(attributedStringToSpannable(attrString));
}

public Spannable attributedStringToSpannable(AttributedStringProxy attrString)
{
if (attrString.hasProperty(TiC.PROPERTY_TEXT)) {
String textString = TiConvert.toString(attrString.getProperty(TiC.PROPERTY_TEXT));
Expand Down Expand Up @@ -714,10 +731,9 @@ fontProperties[TiUIHelper.FONT_SIZE_POSITION], getProxy().getActivity())),
}
}
}
tv.setText(spannableText);
return spannableText;
}
}

return null;
}

}
6 changes: 5 additions & 1 deletion android/titanium/src/java/org/appcelerator/titanium/TiC.java
Expand Up @@ -2581,13 +2581,17 @@ public class TiC
* @module.api
*/
public static final String PROPERTY_DEPARTMENT = "department";


/**
* @module.api
*/
public static final String PROPERTY_ATTRIBUTED_STRING = "attributedString";

/**
* @module.api
*/
public static final String PROPERTY_ATTRIBUTED_HINT_TEXT = "attributedHintText";

/**
* @module.api
*/
Expand Down
2 changes: 1 addition & 1 deletion apidoc/Titanium/UI/TextField.yml
Expand Up @@ -91,7 +91,7 @@ properties:
The attributed hint text by the textField, if set, the textField ignores
the `hintText` property
type: Titanium.UI.AttributedString
platforms: [iphone, ipad]
platforms: [android, iphone, ipad]
since: 3.6.0

- name: autocapitalization
Expand Down

0 comments on commit c739c3b

Please sign in to comment.