Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timob 9517: Added auto link support for TextField and TextArea. #2474

Merged
merged 2 commits into from
Jun 29, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
@Kroll.proxy(creatableInModule=UIModule.class, propertyAccessors = {
TiC.PROPERTY_AUTOCAPITALIZATION,
TiC.PROPERTY_AUTOCORRECT,
TiC.PROPERTY_AUTO_LINK,
TiC.PROPERTY_CLEAR_ON_EDIT,
TiC.PROPERTY_COLOR,
TiC.PROPERTY_EDITABLE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
@Kroll.proxy(creatableInModule=UIModule.class, propertyAccessors = {
TiC.PROPERTY_AUTOCAPITALIZATION,
TiC.PROPERTY_AUTOCORRECT,
TiC.PROPERTY_AUTO_LINK,
TiC.PROPERTY_CLEAR_ON_EDIT,
TiC.PROPERTY_COLOR,
TiC.PROPERTY_EDITABLE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,28 +88,21 @@ public void processProperties(KrollDict d)
tv.setSingleLine(!TiConvert.toBoolean(d, TiC.PROPERTY_WORD_WRAP));
}
// This needs to be the last operation.
linkifyIfEnabled(tv, d.get(TiC.PROPERTY_AUTO_LINK));
TiUIHelper.linkifyIfEnabled(tv, d.get(TiC.PROPERTY_AUTO_LINK));
tv.invalidate();
}

private void linkifyIfEnabled(TextView tv, Object autoLink)
{
if (autoLink != null) {
Linkify.addLinks(tv, TiConvert.toInt(autoLink));
}
}

@Override
public void propertyChanged(String key, Object oldValue, Object newValue, KrollProxy proxy)
{
TextView tv = (TextView) getNativeView();
if (key.equals(TiC.PROPERTY_HTML)) {
tv.setText(Html.fromHtml(TiConvert.toString(newValue)), TextView.BufferType.SPANNABLE);
linkifyIfEnabled(tv, proxy.getProperty(TiC.PROPERTY_AUTO_LINK));
TiUIHelper.linkifyIfEnabled(tv, proxy.getProperty(TiC.PROPERTY_AUTO_LINK));
tv.requestLayout();
} else if (key.equals(TiC.PROPERTY_TEXT) || key.equals(TiC.PROPERTY_TITLE)) {
tv.setText(TiConvert.toString(newValue));
linkifyIfEnabled(tv, proxy.getProperty(TiC.PROPERTY_AUTO_LINK));
TiUIHelper.linkifyIfEnabled(tv, proxy.getProperty(TiC.PROPERTY_AUTO_LINK));
tv.requestLayout();
} else if (key.equals(TiC.PROPERTY_COLOR)) {
tv.setTextColor(TiConvert.toColor((String) newValue));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,25 +134,31 @@ public void processProperties(KrollDict d)
if (d.containsKey(TiC.PROPERTY_ENABLED)) {
tv.setEnabled(d.getBoolean(TiC.PROPERTY_ENABLED));
}

if (d.containsKey(TiC.PROPERTY_VALUE)) {
tv.setText(d.getString(TiC.PROPERTY_VALUE));
}

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;
Expand All @@ -164,13 +170,18 @@ public void processProperties(KrollDict d)
}
handleTextAlign(textAlign, verticalAlign);
}

if (d.containsKey(TiC.PROPERTY_RETURN_KEY_TYPE)) {
handleReturnKeyType(d.getInt(TiC.PROPERTY_RETURN_KEY_TYPE));
}
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))
{

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));
}
}


Expand Down Expand Up @@ -215,7 +226,10 @@ public void propertyChanged(String key, Object oldValue, Object newValue, KrollP
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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
import android.os.Handler;
import android.os.Looper;
import android.os.Process;
import android.text.util.Linkify;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.View;
Expand Down Expand Up @@ -135,6 +136,13 @@ public static void doKillOrContinueDialog(Context context, String title, String
.setNegativeButton("Kill", negativeListener)
.setCancelable(false).create().show();
}

public static void linkifyIfEnabled(TextView tv, Object autoLink)
{
if (autoLink != null) {
Linkify.addLinks(tv, TiConvert.toInt(autoLink));
}
}

/**
* Waits for the current activity to be ready, then invokes
Expand Down
14 changes: 11 additions & 3 deletions apidoc/Titanium/UI/TextArea.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,24 @@ properties:
- name: autoLink
summary: Automatically convert text to clickable links.
description: |
Use one of the <Titanium.UI.iOS> auto-detect constants,
In iOS, use one of the <Titanium.UI.iOS> auto-detect constants:
[AUTODETECT_ADDRESS](Titanium.UI.iOS.AUTODETECT_ADDRESS),
[AUTODETECT_ALL](Titanium.UI.iOS.AUTODETECT_ALL),
[AUTODETECT_CALENDAR](Titanium.UI.iOS.AUTODETECT_CALENDAR),
[AUTODETECT_LINK](Titanium.UI.iOS.AUTODETECT_LINK),
[AUTODETECT_NONE](Titanium.UI.iOS.AUTODETECT_NONE),
or [AUTODETECT_PHONE](Titanium.UI.iOS.AUTODETECT_PHONE).

In Android, use one of the <Titanium.UI.Android> linkify constants:
[LINKIFY_ALL](Titanium.UI.Android.LINKIFY_ALL),
[LINKIFY_EMAIL_ADDRESSES](Titanium.UI.Android.LINKIFY_EMAIL_ADDRESSES),
[LINKIFY_MAP_ADDRESSES](Titanium.UI.Android.LINKIFY_MAP_ADDRESSES),
[LINKIFY_PHONE_NUMBERS](Titanium.UI.Android.LINKIFY_PHONE_NUMBERS),
or [LINKIFY_WEB_URLS](Titanium.UI.Android.LINKIFY_WEB_URLS).
type: Number
default: <Titanium.UI.iOS.AUTODETECT_NONE>
platforms: [iphone, ipad]
default: <Titanium.UI.iOS.AUTODETECT_NONE> in iOS, undefined in Android
since: {android: 2.2.0}
platforms: [android, iphone, ipad]

- name: clearOnEdit
summary: Determines whether the value of this text area should be cleared when it is focused.
Expand Down
14 changes: 14 additions & 0 deletions apidoc/Titanium/UI/TextField.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,20 @@ properties:
type: Boolean
default: false

- name: autoLink
summary: Automatically convert text to clickable links.
description: |
Use one of the <Titanium.UI.Android> linkify constants:
[LINKIFY_ALL](Titanium.UI.Android.LINKIFY_ALL),
[LINKIFY_EMAIL_ADDRESSES](Titanium.UI.Android.LINKIFY_EMAIL_ADDRESSES),
[LINKIFY_MAP_ADDRESSES](Titanium.UI.Android.LINKIFY_MAP_ADDRESSES),
[LINKIFY_PHONE_NUMBERS](Titanium.UI.Android.LINKIFY_PHONE_NUMBERS),
or [LINKIFY_WEB_URLS](Titanium.UI.Android.LINKIFY_WEB_URLS).
type: Number
default: undefined
since: 2.2.0
platforms: [android]

- name: borderStyle
summary: Border style for the field.
description: |
Expand Down