Skip to content

Commit 08487bd

Browse files
committed
Added enableUnderLine method 🐱
1 parent f0c8a8a commit 08487bd

File tree

8 files changed

+21
-13
lines changed

8 files changed

+21
-13
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,12 @@ And also autoLink text pressed state color
114114
autoLinkTextView.setSelectedStateColor(ContextCompat.getColor(this, R.color.yourColor));
115115
```
116116
-------------------------
117+
Enable under line
118+
```java
119+
autoLinkTextView.enableUnderLine();
120+
```
121+
#![](screens/screen8.png)
122+
-------------------------
117123
## Contact
118124

119125
Pull requests are more than welcome.

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ apply plugin: 'com.android.application'
22

33
android {
44
compileSdkVersion 24
5-
buildToolsVersion "24.0.1"
5+
buildToolsVersion "24.0.3"
66
defaultConfig {
77
applicationId "com.luseen.activetextview"
88
minSdkVersion 14

app/src/main/java/com/luseen/activetextview/MainActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ protected void onCreate(Bundle savedInstanceState) {
1818
setContentView(R.layout.activity_main);
1919
AutoLinkTextView autoLinkTextView = (AutoLinkTextView) findViewById(R.id.active);
2020

21-
autoLinkTextView.setUnderLineEnabled(true);
21+
autoLinkTextView.enableUnderLine();
2222

2323
autoLinkTextView.addAutoLinkMode(
2424
AutoLinkMode.MODE_HASHTAG,

app/src/main/res/values/colors.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
<color name="colorAccent">#FF4081</color>
66
<color name="color1">#9C27B0</color>
77
<color name="color2">#1DA1F2</color>
8-
<color name="color3">#FFC107</color>
8+
<color name="color3">#ffa000</color>
99
<color name="color5">#64dd17</color>
1010
</resources>

autolinklibrary/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ apply plugin: 'com.novoda.bintray-release'
44

55
android {
66
compileSdkVersion 24
7-
buildToolsVersion "24.0.1"
7+
buildToolsVersion "24.0.3"
88

99
defaultConfig {
1010
minSdkVersion 14
@@ -29,7 +29,7 @@ dependencies {
2929
publish {
3030
groupId = 'com.github.armcha'
3131
artifactId = 'AutoLinkTextView'
32-
publishVersion = '0.1.1'
32+
publishVersion = '0.1.2'
3333
desc = 'Auto Link Text View'
3434
licences = ['MIT']
3535
website = 'https://github.com/armcha/AutoLinkTextView'

autolinklibrary/src/main/java/com/luseen/autolinklibrary/AutoLinkTextView.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
import android.support.annotation.ColorInt;
66
import android.text.Spannable;
77
import android.text.SpannableString;
8+
import android.text.TextPaint;
89
import android.util.AttributeSet;
10+
import android.util.Log;
911
import android.view.View;
1012
import android.widget.TextView;
1113

@@ -126,7 +128,6 @@ private List<AutoLinkItem> matchedRanges(String text) {
126128
return autoLinkItems;
127129
}
128130

129-
130131
private int getColorByMode(AutoLinkMode autoLinkMode) {
131132
switch (autoLinkMode) {
132133
case MODE_HASHTAG:
@@ -186,7 +187,7 @@ public void setAutoLinkOnClickListener(AutoLinkOnClickListener autoLinkOnClickLi
186187
this.autoLinkOnClickListener = autoLinkOnClickListener;
187188
}
188189

189-
public void setUnderLineEnabled(boolean underLineEnabled) {
190-
isUnderLineEnabled = underLineEnabled;
190+
public void enableUnderLine() {
191+
isUnderLineEnabled = true;
191192
}
192193
}

autolinklibrary/src/main/java/com/luseen/autolinklibrary/LinkTouchMovementMethod.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@ class LinkTouchMovementMethod extends LinkMovementMethod {
1717

1818
@Override
1919
public boolean onTouchEvent(TextView textView, final Spannable spannable, MotionEvent event) {
20-
if (event.getAction() == MotionEvent.ACTION_DOWN) {
20+
int action = event.getAction();
21+
if (action == MotionEvent.ACTION_DOWN) {
2122
pressedSpan = getPressedSpan(textView, spannable, event);
2223
if (pressedSpan != null) {
2324
pressedSpan.setPressed(true);
2425
Selection.setSelection(spannable, spannable.getSpanStart(pressedSpan),
2526
spannable.getSpanEnd(pressedSpan));
2627
}
27-
} else if (event.getAction() == MotionEvent.ACTION_MOVE) {
28+
} else if (action == MotionEvent.ACTION_MOVE) {
2829
TouchableSpan touchedSpan = getPressedSpan(textView, spannable, event);
2930
if (pressedSpan != null && touchedSpan != pressedSpan) {
3031
pressedSpan.setPressed(false);
@@ -54,10 +55,10 @@ private TouchableSpan getPressedSpan(TextView textView, Spannable spannable, Mot
5455
y += textView.getScrollY();
5556

5657
Layout layout = textView.getLayout();
57-
int line = layout.getLineForVertical(y);
58-
int off = layout.getOffsetForHorizontal(line, x);
58+
int verticalLine = layout.getLineForVertical(y);
59+
int horizontalOffset = layout.getOffsetForHorizontal(verticalLine, x);
5960

60-
TouchableSpan[] link = spannable.getSpans(off, off, TouchableSpan.class);
61+
TouchableSpan[] link = spannable.getSpans(horizontalOffset, horizontalOffset, TouchableSpan.class);
6162
TouchableSpan touchedSpan = null;
6263
if (link.length > 0) {
6364
touchedSpan = link[0];

screens/screen8.png

49.5 KB
Loading

0 commit comments

Comments
 (0)