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-18062] Android: Enable links to work in textfields and textarea #6641

Merged
merged 1 commit into from
Mar 10, 2015
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 @@ -18,6 +18,7 @@
import org.appcelerator.titanium.util.TiUIHelper;

import android.app.Activity;
import android.os.Bundle;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.TextUtils;
Expand Down Expand Up @@ -95,9 +96,19 @@ public static AttributeProxy attributeProxyFor(Object obj, KrollProxy proxy)
return attributeProxy;
}
}

public static Spannable toSpannable(AttributedStringProxy attrString, Activity activity)
{
Bundle results = toSpannableInBundle(attrString, activity);
if (results.containsKey(TiC.PROPERTY_ATTRIBUTED_STRING)) {
return (Spannable) results.getCharSequence(TiC.PROPERTY_ATTRIBUTED_STRING);
}
return null;
}

public static Bundle toSpannableInBundle(AttributedStringProxy attrString, Activity activity)
{
Bundle results = new Bundle();
if (attrString != null && attrString.hasProperty(TiC.PROPERTY_TEXT)) {
String textString = TiConvert.toString(attrString.getProperty(TiC.PROPERTY_TEXT));
if (!TextUtils.isEmpty(textString)) {
Expand Down Expand Up @@ -176,16 +187,18 @@ public static Spannable toSpannable(AttributedStringProxy attrString, Activity a
spannableText.setSpan(new URLSpan(TiConvert.toString(attrValue)), range[0], range[0]
+ range[1], Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
results.putBoolean(TiC.PROPERTY_HAS_LINK, true);
break;
}
}
}
}
}
return spannableText;
results.putCharSequence(TiC.PROPERTY_ATTRIBUTED_STRING, spannableText);
return results;
}
}
return null;
return results;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,18 @@
import org.appcelerator.titanium.view.TiUIView;

import ti.modules.titanium.ui.AttributedStringProxy;
import android.content.Context;
import android.graphics.Rect;
import android.graphics.Typeface;
import android.os.Build;
import android.os.Bundle;
import android.text.Editable;
import android.text.InputType;
import android.text.Spannable;
import android.text.TextUtils.TruncateAt;
import android.text.TextWatcher;
import android.text.method.DialerKeyListener;
import android.text.method.DigitsKeyListener;
import android.text.method.LinkMovementMethod;
import android.text.method.NumberKeyListener;
import android.text.method.PasswordTransformationMethod;
import android.view.Gravity;
Expand Down Expand Up @@ -630,9 +631,12 @@ public void handleReturnKeyType(int type)
}

public void setAttributedStringText(AttributedStringProxy attrString) {
Spannable spannableText = AttributedStringProxy.toSpannable(attrString, TiApplication.getAppCurrentActivity());
if (spannableText != null) {
tv.setText(spannableText);
Bundle bundleText = AttributedStringProxy.toSpannableInBundle(attrString, TiApplication.getAppCurrentActivity());
if (bundleText.containsKey(TiC.PROPERTY_ATTRIBUTED_STRING)) {
tv.setText((Spannable) bundleText.getCharSequence(TiC.PROPERTY_ATTRIBUTED_STRING));
if(bundleText.getBoolean(TiC.PROPERTY_HAS_LINK, false)){
tv.setMovementMethod(LinkMovementMethod.getInstance());
}
}
}

Expand Down
5 changes: 5 additions & 0 deletions android/titanium/src/java/org/appcelerator/titanium/TiC.java
Original file line number Diff line number Diff line change
Expand Up @@ -1340,6 +1340,11 @@ public class TiC
*/
public static final String PROPERTY_HAS_CHILD = "hasChild";

/**
* @module.api
*/
public static final String PROPERTY_HAS_LINK = "hasLink";

/**
* @module.api
*/
Expand Down