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
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ android:
- tools
- tools
- platform-tools
- build-tools-27.0.0
- build-tools-27.0.1
- android-27
- extra-android-m2repository

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ You can customize ReadMoreTextView with:
- app:showTrimExpandedText: Show the trim text if it's true.
- app:colorClickableText: Text color of trim clickable text.
- app:trimMode: Choose trim mode with two options: trimModeLength or trimModeLines.
- app:expandedTextAppearance: Style for text that appears when the view is expanded.
- app:collapsedTextAppearance: Style for text that appears when the view is collapsed.

## Screenshots

Expand Down
6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apply plugin: 'com.android.application'

android {
compileSdkVersion 27
buildToolsVersion "27.0.0"
buildToolsVersion "27.0.1"

defaultConfig {
applicationId "com.borjabravo.readmoretextview"
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 'com.android.support:appcompat-v7:27.0.1'
implementation 'com.android.support:design:27.0.1'
implementation project(':readmoretextview')
testImplementation 'junit:junit:4.12'
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ protected void onCreate(Bundle savedInstanceState) {
TextView text3 = findViewById(R.id.text3);
text3.setText(getString(R.string.lorem_ipsum3));
TextView text4 = findViewById(R.id.text4);
text4.setText(getString(R.string.one_line_text));
text4.setText(getString(R.string.lorem_ipsum));
TextView text5 = findViewById(R.id.text5);
text5.setText(getString(R.string.one_line_text));
}
}
18 changes: 13 additions & 5 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,36 @@
android:id="@+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:trimCollapsedText="@string/show_all_content"/>
app:trimCollapsedText="@string/show_all_content" />

<com.borjabravo.readmoretextview.ReadMoreTextView
android:id="@+id/text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/activity_vertical_margin"
app:colorClickableText="@color/colorPrimary"/>
app:colorClickableText="@color/colorPrimary" />

<com.borjabravo.readmoretextview.ReadMoreTextView
android:id="@+id/text3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/activity_vertical_margin"
app:showTrimExpandedText="false"
app:trimLength="100"
/>
app:trimLength="100" />

<com.borjabravo.readmoretextview.ReadMoreTextView
android:id="@+id/text4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
android:layout_marginTop="@dimen/activity_vertical_margin"
app:collapsedTextAppearance="@style/AppTheme.TextAppearance.Collapsed"
app:expandedTextAppearance="@style/AppTheme.TextAppearance.Expanded"
app:trimCollapsedText="@string/show_all_content" />

<com.borjabravo.readmoretextview.ReadMoreTextView
android:id="@+id/text5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/activity_vertical_margin" />

</LinearLayout>
13 changes: 13 additions & 0 deletions app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,17 @@

<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

<style name="AppTheme.TextAppearance.Collapsed" parent="android:TextAppearance">
<item name="android:textColor">@android:color/holo_blue_dark</item>
<item name="android:textColorLink">@android:color/holo_blue_dark</item>
<item name="android:textSize">12sp</item>
<item name="android:textStyle">bold</item>
</style>

<style name="AppTheme.TextAppearance.Expanded" parent="android:TextAppearance">
<item name="android:textColor">@android:color/holo_green_dark</item>
<item name="android:textColorLink">@android:color/holo_green_dark</item>
<item name="android:textSize">16sp</item>
<item name="android:textStyle">italic</item>
</style>
</resources>
4 changes: 2 additions & 2 deletions readmoretextview/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ publish {

android {
compileSdkVersion 27
buildToolsVersion '27.0.0'
buildToolsVersion '27.0.1'

defaultConfig {
minSdkVersion 14
Expand All @@ -28,6 +28,6 @@ android {
}

dependencies {
implementation 'com.android.support:support-compat:27.0.0'
implementation 'com.android.support:support-compat:27.0.1'
testImplementation 'junit:junit:4.12'
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@
import android.content.res.TypedArray;
import android.graphics.Color;
import android.os.Build;
import android.support.annotation.StyleRes;
import android.support.v4.content.ContextCompat;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.TextPaint;
import android.text.method.LinkMovementMethod;
import android.text.style.ClickableSpan;
import android.text.style.TextAppearanceSpan;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewTreeObserver;
Expand All @@ -40,6 +42,11 @@ public class ReadMoreTextView extends TextView {
private static final boolean DEFAULT_SHOW_TRIM_EXPANDED_TEXT = true;
private static final String ELLIPSIZE = "... ";

@StyleRes
private final int expandedTextAppearance;
@StyleRes
private final int collapsedTextAppearance;

private CharSequence text;
private BufferType bufferType;
private boolean readMore = true;
Expand Down Expand Up @@ -74,6 +81,8 @@ public ReadMoreTextView(Context context, AttributeSet attrs) {
this.showTrimExpandedText =
typedArray.getBoolean(R.styleable.ReadMoreTextView_showTrimExpandedText, DEFAULT_SHOW_TRIM_EXPANDED_TEXT);
this.trimMode = typedArray.getInt(R.styleable.ReadMoreTextView_trimMode, TRIM_MODE_LINES);
this.expandedTextAppearance = typedArray.getResourceId(R.styleable.ReadMoreTextView_expandedTextAppearance, -1);
this.collapsedTextAppearance = typedArray.getResourceId(R.styleable.ReadMoreTextView_collapsedTextAppearance, -1);
typedArray.recycle();
viewMoreSpan = new ReadMoreClickableSpan();
onGlobalLayoutLineEndIndex();
Expand Down Expand Up @@ -137,12 +146,14 @@ private CharSequence updateCollapsedText() {
SpannableStringBuilder s = new SpannableStringBuilder(text, 0, trimEndIndex)
.append(ELLIPSIZE)
.append(trimCollapsedText);
addTextStyleSpan(collapsedTextAppearance, s, trimCollapsedText);
return addClickableSpan(s, trimCollapsedText);
}

private CharSequence updateExpandedText() {
if (showTrimExpandedText) {
SpannableStringBuilder s = new SpannableStringBuilder(text, 0, text.length()).append(trimExpandedText);
addTextStyleSpan(expandedTextAppearance, s, trimExpandedText);
return addClickableSpan(s, trimExpandedText);
}
return text;
Expand All @@ -153,6 +164,12 @@ private CharSequence addClickableSpan(SpannableStringBuilder s, CharSequence tri
return s;
}

private CharSequence addTextStyleSpan( int textAppearance, SpannableStringBuilder s, CharSequence text) {
s.setSpan(new TextAppearanceSpan(getContext(), textAppearance), s.length() - text.length(),
s.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
return s;
}

public void setTrimLength(int trimLength) {
this.trimLength = trimLength;
setText();
Expand Down
6 changes: 4 additions & 2 deletions readmoretextview/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="ReadMoreTextView">
<attr name="expandedTextAppearance" format="reference" />
<attr name="collapsedTextAppearance" format="reference" />
<attr name="trimExpandedText" format="string" />
<attr name="trimCollapsedText" format="string" />
<attr name="trimLength" format="integer" />
<attr name="showTrimExpandedText" format="boolean" />
<attr name="colorClickableText" format="color" />
<attr name="trimLines" format="integer" />
<attr name="trimMode">
<enum name="trimModeLine" value="0"/>
<enum name="trimModeLength" value="1"/>
<enum name="trimModeLine" value="0" />
<enum name="trimModeLength" value="1" />
</attr>
</declare-styleable>
</resources>