Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 27
buildToolsVersion "27.0.0"
compileSdkVersion 28
buildToolsVersion "28.0.3"

defaultConfig {
applicationId "com.borjabravo.readmoretextview"
minSdkVersion 14
targetSdkVersion 27
targetSdkVersion 28
versionCode 1
versionName "1.0"
}
Expand All @@ -25,8 +25,8 @@ android {
}

dependencies {
implementation 'com.android.support:appcompat-v7:27.0.0'
implementation 'com.android.support:design:27.0.0'
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'com.google.android.material:material:1.0.0'
implementation project(':readmoretextview')
testImplementation 'junit:junit:4.12'
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.borjabravo.readmoretextviewsample;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import androidx.appcompat.app.AppCompatActivity;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {
Expand Down
11 changes: 7 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
buildscript {
repositories {
jcenter()
google()
maven {
url "https://maven.google.com"
}
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0'
classpath 'com.novoda:bintray-release:0.5.0'
classpath 'com.android.tools.build:gradle:3.4.2'
classpath 'com.novoda:bintray-release:0.8.0'
}
}

allprojects {
repositories {
jcenter()
google()
jcenter()
}
}

Expand Down
4 changes: 3 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
# org.gradle.parallel=true
android.enableJetifier=true
android.useAndroidX=true
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Sun Nov 12 12:19:18 CET 2017
#Sun Aug 04 11:57:53 EEST 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
8 changes: 4 additions & 4 deletions readmoretextview/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ publish {
}

android {
compileSdkVersion 27
buildToolsVersion '27.0.0'
compileSdkVersion 28
buildToolsVersion '28.0.3'

defaultConfig {
minSdkVersion 14
targetSdkVersion 27
targetSdkVersion 28
versionCode 1
versionName "1.0"
}
Expand All @@ -28,6 +28,6 @@ android {
}

dependencies {
implementation 'com.android.support:support-compat:27.0.0'
implementation 'androidx.core:core:1.0.2'
testImplementation 'junit:junit:4.12'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.borjabravo.readmoretextview;

/**
* Created by Mays Atari.
*/

public interface ReadMoreListener {
void onReadMoreClick(boolean readMore);
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
*/
package com.borjabravo.readmoretextview;


import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.os.Build;
import android.support.v4.content.ContextCompat;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.TextPaint;
Expand All @@ -30,6 +30,8 @@
import android.view.ViewTreeObserver;
import android.widget.TextView;

import androidx.core.content.ContextCompat;

public class ReadMoreTextView extends TextView {

private static final int TRIM_MODE_LINES = 0;
Expand All @@ -38,17 +40,19 @@ public class ReadMoreTextView extends TextView {
private static final int DEFAULT_TRIM_LINES = 2;
private static final int INVALID_END_INDEX = -1;
private static final boolean DEFAULT_SHOW_TRIM_EXPANDED_TEXT = true;
private static final boolean DEFAULT_READ_MORE = true;
private static final String ELLIPSIZE = "... ";

private CharSequence text;
private BufferType bufferType;
private boolean readMore = true;
private boolean readMore;
private int trimLength;
private CharSequence trimCollapsedText;
private CharSequence trimExpandedText;
private ReadMoreClickableSpan viewMoreSpan;
private int colorClickableText;
private boolean showTrimExpandedText;
private ReadMoreListener readMoreListener;

private int trimMode;
private int lineEndIndex;
Expand All @@ -73,6 +77,7 @@ public ReadMoreTextView(Context context, AttributeSet attrs) {
ContextCompat.getColor(context, R.color.accent));
this.showTrimExpandedText =
typedArray.getBoolean(R.styleable.ReadMoreTextView_showTrimExpandedText, DEFAULT_SHOW_TRIM_EXPANDED_TEXT);
this.readMore = typedArray.getBoolean(R.styleable.ReadMoreTextView_readMore, DEFAULT_READ_MORE);
this.trimMode = typedArray.getInt(R.styleable.ReadMoreTextView_trimMode, TRIM_MODE_LINES);
typedArray.recycle();
viewMoreSpan = new ReadMoreClickableSpan();
Expand Down Expand Up @@ -178,11 +183,23 @@ public void setTrimLines(int trimLines) {
this.trimLines = trimLines;
}

public void setReadMore(boolean readMore) {
this.readMore = readMore;
}

public void setReadMoreListener(ReadMoreListener readMoreListener) {
this.readMoreListener = readMoreListener;
}

private class ReadMoreClickableSpan extends ClickableSpan {
@Override
public void onClick(View widget) {
readMore = !readMore;
setText();

if(readMoreListener != null){
readMoreListener.onReadMoreClick(readMore);
}
}

@Override
Expand Down
1 change: 1 addition & 0 deletions readmoretextview/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<attr name="trimCollapsedText" format="string" />
<attr name="trimLength" format="integer" />
<attr name="showTrimExpandedText" format="boolean" />
<attr name="readMore" format="boolean" />
<attr name="colorClickableText" format="color" />
<attr name="trimLines" format="integer" />
<attr name="trimMode">
Expand Down