diff --git a/FlowTextView.iml b/FlowTextView.iml index 5550340..5581c00 100644 --- a/FlowTextView.iml +++ b/FlowTextView.iml @@ -1,15 +1,14 @@ - + - - - + @@ -17,5 +16,4 @@ - - + \ No newline at end of file diff --git a/README.md b/README.md index 88f88e8..377ef1a 100644 --- a/README.md +++ b/README.md @@ -66,6 +66,11 @@ Add the dependency: compile 'com.github.deano2390:FlowTextView:2.0.5' ``` +Install to local maven, from `flowtextview/`: +``` +gradle clean build publishToMavenLocal +``` + License ------- diff --git a/build.gradle b/build.gradle index 1296bf3..4f43b7b 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,7 @@ buildscript { mavenCentral() } dependencies { - classpath 'com.android.tools.build:gradle:1.0.0' + classpath 'com.android.tools.build:gradle:2.3.0' } } diff --git a/flowtextview-sample/build.gradle b/flowtextview-sample/build.gradle index 7f4f76d..2437347 100644 --- a/flowtextview-sample/build.gradle +++ b/flowtextview-sample/build.gradle @@ -1,12 +1,12 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 21 - buildToolsVersion '21.1.2' + compileSdkVersion 25 + buildToolsVersion '25.0.2' defaultConfig { applicationId 'com.dean.flowtextviewsampleapp.sample' - minSdkVersion 8 - targetSdkVersion 19 + minSdkVersion 9 + targetSdkVersion 25 versionCode 1 versionName '1.0' } @@ -22,6 +22,6 @@ android { dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) - compile 'com.android.support:appcompat-v7:21.0.3' + compile 'com.android.support:appcompat-v7:25.3.1' compile project(':flowtextview') } diff --git a/flowtextview/build.gradle b/flowtextview/build.gradle index a2f72cd..bb0eb43 100644 --- a/flowtextview/build.gradle +++ b/flowtextview/build.gradle @@ -1,13 +1,31 @@ apply plugin: 'com.android.library' +apply plugin: 'maven-publish' +task sourceJar(type: Jar) { + from android.sourceSets.main.java.srcDirs + classifier "source" +} + +publishing { + publications { + maven(MavenPublication) { + groupId 'com.github.deano2390' + artifactId 'FlowTextView' + version '2.0.8' + + artifact(sourceJar) + artifact("$buildDir/outputs/aar/${project.getName()}-release.aar") + } + } +} android { - compileSdkVersion 21 - buildToolsVersion "21.1.2" + compileSdkVersion 25 + buildToolsVersion '25.0.2' defaultConfig { minSdkVersion 8 - targetSdkVersion 15 + targetSdkVersion 25 } buildTypes { @@ -16,6 +34,7 @@ android { proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt' } } + } diff --git a/flowtextview/src/main/AndroidManifest.xml b/flowtextview/src/main/AndroidManifest.xml index e0b26ea..8bd5bf8 100644 --- a/flowtextview/src/main/AndroidManifest.xml +++ b/flowtextview/src/main/AndroidManifest.xml @@ -2,9 +2,4 @@ package="uk.co.deanwild.flowtextview.flowtextview" android:versionCode="1" android:versionName="1.0" > - - - \ No newline at end of file diff --git a/flowtextview/src/main/java/uk/co/deanwild/flowtextview/FlowTextView.java b/flowtextview/src/main/java/uk/co/deanwild/flowtextview/FlowTextView.java index f3b8dce..cc26024 100644 --- a/flowtextview/src/main/java/uk/co/deanwild/flowtextview/FlowTextView.java +++ b/flowtextview/src/main/java/uk/co/deanwild/flowtextview/FlowTextView.java @@ -1,7 +1,6 @@ package uk.co.deanwild.flowtextview; import android.content.Context; -import android.content.res.ColorStateList; import android.content.res.Configuration; import android.content.res.TypedArray; import android.graphics.Canvas; @@ -92,6 +91,7 @@ private void init(Context context, AttributeSet attrs) { mLinkPaint.setColor(Color.BLUE); mLinkPaint.setUnderlineText(true); this.setBackgroundColor(Color.TRANSPARENT); + setOnTouchListener(mClickHandler); } private void readAttrs(Context context, AttributeSet attrs) { @@ -139,14 +139,22 @@ protected void onDraw(Canvas canvas) { mSpanParser.reset(); + boolean lastBlockWasCountedAsEmptyLine = false; + for (int block_no = 0; block_no <= blocks.length - 1; block_no++) // at the highest level we iterate through each 'block' of text { String thisBlock = blocks[block_no]; if (thisBlock.length() <= 0) { //is a line break - lineIndex++; // we need a new line - charOffsetEnd += 2; - charOffsetStart = charOffsetEnd; + if (lastBlockWasCountedAsEmptyLine) { + lastBlockWasCountedAsEmptyLine = false; + } else { + lineIndex++; // we need a new line + charOffsetEnd += 2; + charOffsetStart = charOffsetEnd; + lastBlockWasCountedAsEmptyLine = true; + } } else { // is some actual text + lastBlockWasCountedAsEmptyLine = false; while (thisBlock.length() > 0) { // churn through the block spitting it out onto seperate lines until there is nothing left to render lineIndex++; // we need a new line diff --git a/flowtextview/src/main/java/uk/co/deanwild/flowtextview/helpers/ClickHandler.java b/flowtextview/src/main/java/uk/co/deanwild/flowtextview/helpers/ClickHandler.java index 289067b..bccf587 100644 --- a/flowtextview/src/main/java/uk/co/deanwild/flowtextview/helpers/ClickHandler.java +++ b/flowtextview/src/main/java/uk/co/deanwild/flowtextview/helpers/ClickHandler.java @@ -3,7 +3,6 @@ import android.view.MotionEvent; import android.view.View; -import java.util.ArrayList; import java.util.List; import uk.co.deanwild.flowtextview.listeners.OnLinkClickListener; @@ -12,13 +11,13 @@ /** * Created by Dean on 24/06/2014. */ -public class ClickHandler implements View.OnTouchListener{ +public class ClickHandler implements View.OnTouchListener { private final SpanParser mSpanParser; - private OnLinkClickListener mOnLinkClickListener; + private OnLinkClickListener mOnLinkClickListener = OnLinkClickListener.DEFAULT; private double distance = 0; - private float x1,y1,x2,y2 = 0f; + private float x1, y1, x2, y2 = 0f; public ClickHandler(SpanParser spanParser) { this.mSpanParser = spanParser; @@ -29,22 +28,22 @@ public boolean onTouch(View view, MotionEvent event) { int event_code = event.getAction(); - if(event_code == MotionEvent.ACTION_DOWN){ + if (event_code == MotionEvent.ACTION_DOWN) { distance = 0; x1 = event.getX(); y1 = event.getY(); } - if(event_code == MotionEvent.ACTION_MOVE){ + if (event_code == MotionEvent.ACTION_MOVE) { x2 = event.getX(); y2 = event.getY(); distance = getPointDistance(x1, y1, x2, y2); } - if(distance < 10) { // my random guess at an acceptable drift distance to regard this as a click + if (distance < 10) { // my random guess at an acceptable drift distance to regard this as a click if (event_code == MotionEvent.ACTION_UP) { // if the event is an "up" and we havn't moved far since the "down", then it's a click - return onClick(event.getX(), event.getY()); // process the click and say whether we consumed it + return onClick(view, event.getX(), event.getY()); // process the click and say whether we consumed it } return true; } @@ -52,7 +51,7 @@ public boolean onTouch(View view, MotionEvent event) { return false; } - private boolean onClick(float x, float y){ + private boolean onClick(final View view, float x, float y) { List links = mSpanParser.getLinks(); @@ -62,10 +61,10 @@ private boolean onClick(float x, float y){ float brX = link.xOffset + link.width; float brY = link.yOffset + link.height; - if(x > tlX && x < brX){ - if(y > tlY && y < brY){ + if (x > tlX && x < brX) { + if (y > tlY && y < brY) { // collision - onLinkClick(link.url); + onLinkClick(view, link.url); return true; // the click was consumed } } @@ -74,12 +73,12 @@ private boolean onClick(float x, float y){ return false; } - private void onLinkClick(String url){ - if(mOnLinkClickListener!=null) mOnLinkClickListener.onLinkClick(url); + private void onLinkClick(final View view, String url) { + if (mOnLinkClickListener != null) mOnLinkClickListener.onLinkClick(view, url); } - private static double getPointDistance(float x1, float y1, float x2, float y2){ - return Math.sqrt(Math.pow(x1 - x2, 2) + Math.pow(y1- y2, 2)); + private static double getPointDistance(float x1, float y1, float x2, float y2) { + return Math.sqrt(Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2)); } public OnLinkClickListener getOnLinkClickListener() { diff --git a/flowtextview/src/main/java/uk/co/deanwild/flowtextview/helpers/SpanParser.java b/flowtextview/src/main/java/uk/co/deanwild/flowtextview/helpers/SpanParser.java index fe09861..d0857f5 100644 --- a/flowtextview/src/main/java/uk/co/deanwild/flowtextview/helpers/SpanParser.java +++ b/flowtextview/src/main/java/uk/co/deanwild/flowtextview/helpers/SpanParser.java @@ -4,6 +4,7 @@ import android.text.Spannable; import android.text.TextPaint; import android.text.style.StyleSpan; +import android.text.style.TypefaceSpan; import android.text.style.URLSpan; import java.util.ArrayList; @@ -112,11 +113,12 @@ public float parseSpans(List objects, Object[] spans, int lineStart, } private HtmlObject parseSpan(Object span, String content, int start, int end){ - if(span instanceof URLSpan){ return getHtmlLink((URLSpan) span, content, start, end, 0); - }else if(span instanceof StyleSpan){ + }else if(span instanceof StyleSpan) { return getStyledObject((StyleSpan) span, content, start, end, 0); + } else if (span instanceof TypefaceSpan) { + return getTypefaceObject((TypefaceSpan) span, content, start, end, 0); }else{ return getHtmlObject(content, start, end, 0); } @@ -135,6 +137,19 @@ private HtmlObject getStyledObject(StyleSpan span, String content, int start, in return obj; } + private HtmlObject getTypefaceObject(final TypefaceSpan span, final String content, final int start, final int end, final float thisXOffset) { + TextPaint paint = mPaintHelper.getPaintFromHeap(); + paint.setTextSize(mFlowTextView.getTextsize()); + paint.setColor(mFlowTextView.getColor()); + + span.updateDrawState(paint); + span.updateMeasureState(paint); + + HtmlObject obj = new HtmlObject(content, start, end, thisXOffset, paint); + obj.recycle = true; + return obj; + } + private HtmlObject getHtmlObject(String content, int start, int end, float thisXOffset){ return new HtmlObject(content, start, end, thisXOffset, mFlowTextView.getTextPaint()); } diff --git a/flowtextview/src/main/java/uk/co/deanwild/flowtextview/listeners/OnLinkClickListener.java b/flowtextview/src/main/java/uk/co/deanwild/flowtextview/listeners/OnLinkClickListener.java index 94290f3..85df710 100644 --- a/flowtextview/src/main/java/uk/co/deanwild/flowtextview/listeners/OnLinkClickListener.java +++ b/flowtextview/src/main/java/uk/co/deanwild/flowtextview/listeners/OnLinkClickListener.java @@ -1,8 +1,20 @@ package uk.co.deanwild.flowtextview.listeners; +import android.content.Intent; +import android.net.Uri; +import android.view.View; + /** -* Created by Dean on 24/06/2014. -*/ + * Created by Dean on 24/06/2014. + */ public interface OnLinkClickListener { - public void onLinkClick(String url); + + OnLinkClickListener DEFAULT = new OnLinkClickListener() { + @Override + public void onLinkClick(View view, String url) { + view.getContext().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url))); + } + }; + + void onLinkClick(View view, String url); } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index a704f1f..e695582 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Fri Jan 30 11:01:50 CET 2015 +#Wed Mar 08 10:15:45 EET 2017 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip