├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── mipmap-xhdpi
│ │ │ │ ├── img2.webp
│ │ │ │ ├── img3.webp
│ │ │ │ ├── img4.webp
│ │ │ │ ├── img5.webp
│ │ │ │ ├── man1.webp
│ │ │ │ ├── man2.webp
│ │ │ │ ├── man3.webp
│ │ │ │ ├── women1.webp
│ │ │ │ ├── women2.webp
│ │ │ │ ├── women3.webp
│ │ │ │ ├── ic_launcher.webp
│ │ │ │ └── ic_launcher_round.webp
│ │ │ ├── mipmap-hdpi
│ │ │ │ ├── ic_launcher.webp
│ │ │ │ └── ic_launcher_round.webp
│ │ │ ├── mipmap-mdpi
│ │ │ │ ├── ic_launcher.webp
│ │ │ │ └── ic_launcher_round.webp
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ ├── ic_launcher.webp
│ │ │ │ └── ic_launcher_round.webp
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ ├── ic_launcher.webp
│ │ │ │ └── ic_launcher_round.webp
│ │ │ ├── values
│ │ │ │ ├── styles.xml
│ │ │ │ ├── colors.xml
│ │ │ │ ├── themes.xml
│ │ │ │ └── strings.xml
│ │ │ ├── mipmap-anydpi-v26
│ │ │ │ ├── ic_launcher.xml
│ │ │ │ └── ic_launcher_round.xml
│ │ │ ├── drawable
│ │ │ │ ├── ic_text_expand.xml
│ │ │ │ ├── ic_dots.xml
│ │ │ │ ├── ic_list.xml
│ │ │ │ ├── ic_entered_text.xml
│ │ │ │ └── ic_launcher_background.xml
│ │ │ ├── menu
│ │ │ │ └── main_menu.xml
│ │ │ ├── values-night
│ │ │ │ └── themes.xml
│ │ │ ├── layout
│ │ │ │ ├── activity_main.xml
│ │ │ │ ├── item_recycler_view.xml
│ │ │ │ └── act_detail.xml
│ │ │ └── drawable-v24
│ │ │ │ └── ic_launcher_foreground.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── com
│ │ │ └── erif
│ │ │ └── readmoretextviewdemo
│ │ │ ├── model
│ │ │ └── ModelItemRecyclerView.java
│ │ │ ├── ActDetail.java
│ │ │ ├── adapter
│ │ │ └── AdapterRecyclerView.java
│ │ │ └── MainActivity.java
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── erif
│ │ │ └── readmoretextviewdemo
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── erif
│ │ └── readmoretextviewdemo
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
└── build.gradle.kts
├── readMoreTextView
├── .gitignore
├── consumer-rules.pro
├── src
│ ├── main
│ │ ├── AndroidManifest.xml
│ │ ├── res
│ │ │ └── values
│ │ │ │ ├── colors.xml
│ │ │ │ └── attrs.xml
│ │ └── java
│ │ │ └── com
│ │ │ └── erif
│ │ │ └── readmoretextview
│ │ │ ├── ToggleListener.java
│ │ │ ├── Interpolator.java
│ │ │ ├── InterpolatorType.java
│ │ │ └── TextViewReadMore.java
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── erif
│ │ │ └── readmoretextview
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── erif
│ │ └── readmoretextview
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
└── build.gradle.kts
├── .idea
├── .gitignore
├── codeStyles
│ ├── codeStyleConfig.xml
│ └── Project.xml
├── compiler.xml
├── kotlinc.xml
├── vcs.xml
├── AndroidProjectSystem.xml
├── deploymentTargetDropDown.xml
├── migrations.xml
├── deploymentTargetSelector.xml
├── material_theme_project_new.xml
├── inspectionProfiles
│ └── Project_Default.xml
├── gradle.xml
├── misc.xml
├── runConfigurations.xml
├── appInsightsSettings.xml
└── intellij-javadocs-4.0.1.xml
├── gradle
├── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
└── libs.versions.toml
├── .gitignore
├── settings.gradle.kts
├── gradle.properties
├── gradlew.bat
├── README.md
├── gradlew
└── LICENSE
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
--------------------------------------------------------------------------------
/readMoreTextView/.gitignore:
--------------------------------------------------------------------------------
1 | /build
--------------------------------------------------------------------------------
/readMoreTextView/consumer-rules.pro:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/eriffanani/TextViewReadMore/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/img2.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/eriffanani/TextViewReadMore/HEAD/app/src/main/res/mipmap-xhdpi/img2.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/img3.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/eriffanani/TextViewReadMore/HEAD/app/src/main/res/mipmap-xhdpi/img3.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/img4.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/eriffanani/TextViewReadMore/HEAD/app/src/main/res/mipmap-xhdpi/img4.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/img5.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/eriffanani/TextViewReadMore/HEAD/app/src/main/res/mipmap-xhdpi/img5.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/man1.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/eriffanani/TextViewReadMore/HEAD/app/src/main/res/mipmap-xhdpi/man1.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/man2.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/eriffanani/TextViewReadMore/HEAD/app/src/main/res/mipmap-xhdpi/man2.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/man3.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/eriffanani/TextViewReadMore/HEAD/app/src/main/res/mipmap-xhdpi/man3.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/women1.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/eriffanani/TextViewReadMore/HEAD/app/src/main/res/mipmap-xhdpi/women1.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/women2.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/eriffanani/TextViewReadMore/HEAD/app/src/main/res/mipmap-xhdpi/women2.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/women3.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/eriffanani/TextViewReadMore/HEAD/app/src/main/res/mipmap-xhdpi/women3.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/eriffanani/TextViewReadMore/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/eriffanani/TextViewReadMore/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/eriffanani/TextViewReadMore/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/eriffanani/TextViewReadMore/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/eriffanani/TextViewReadMore/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/eriffanani/TextViewReadMore/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/eriffanani/TextViewReadMore/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/eriffanani/TextViewReadMore/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/eriffanani/TextViewReadMore/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/eriffanani/TextViewReadMore/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/readMoreTextView/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/readMoreTextView/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #53A9ED
4 |
--------------------------------------------------------------------------------
/.idea/codeStyles/codeStyleConfig.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/kotlinc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/readMoreTextView/src/main/java/com/erif/readmoretextview/ToggleListener.java:
--------------------------------------------------------------------------------
1 | package com.erif.readmoretextview;
2 |
3 | public interface ToggleListener {
4 | public void onToggle(boolean collapsed);
5 | }
6 |
--------------------------------------------------------------------------------
/.idea/AndroidProjectSystem.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 |
--------------------------------------------------------------------------------
/.idea/deploymentTargetDropDown.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Sep 25 14:41:56 WIB 2024
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-bin.zip
5 | zipStoreBase=GRADLE_USER_HOME
6 | zipStorePath=wrapper/dists
7 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/caches
5 | /.idea/libraries
6 | /.idea/modules.xml
7 | /.idea/workspace.xml
8 | /.idea/navEditor.xml
9 | /.idea/assetWizardSettings.xml
10 | .DS_Store
11 | /build
12 | /captures
13 | .externalNativeBuild
14 | .cxx
15 | local.properties
16 |
--------------------------------------------------------------------------------
/.idea/migrations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/.idea/deploymentTargetSelector.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_text_expand.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/main_menu.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #FFBB86FC
4 | #FF6200EE
5 | #FF3700B3
6 | #FF03DAC5
7 | #FF018786
8 | #FF000000
9 | #FFFFFFFF
10 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_dots.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/test/java/com/erif/readmoretextviewdemo/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.erif.readmoretextviewdemo;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/readMoreTextView/src/test/java/com/erif/readmoretextview/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.erif.readmoretextview;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/.idea/material_theme_project_new.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/settings.gradle.kts:
--------------------------------------------------------------------------------
1 | @file:Suppress("UnstableApiUsage")
2 |
3 | pluginManagement {
4 | repositories {
5 | gradlePluginPortal()
6 | google()
7 | mavenCentral()
8 | }
9 | }
10 | dependencyResolutionManagement {
11 | repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
12 | repositories {
13 | google()
14 | mavenCentral()
15 | maven { url = uri("https://jitpack.io") }
16 | }
17 | }
18 | rootProject.name = "ReadMoreTextView"
19 | include(":app")
20 | include(":readMoreTextView")
21 |
--------------------------------------------------------------------------------
/readMoreTextView/src/main/java/com/erif/readmoretextview/Interpolator.java:
--------------------------------------------------------------------------------
1 | package com.erif.readmoretextview;
2 |
3 | public class Interpolator {
4 | public static final int DECELERATE = 0;
5 | public static final int ACCELERATE = 1;
6 | public static final int ANTICIPATE_OVERSHOOT = 2;
7 | public static final int ANTICIPATE = 3;
8 | public static final int BOUNCE = 4;
9 | public static final int FAST_OUT_LINEAR_IN = 5;
10 | public static final int FAST_OUT_SLOW_IN = 6;
11 | public static final int LINEAR_OUT_SLOW_IN = 7;
12 | }
--------------------------------------------------------------------------------
/.idea/inspectionProfiles/Project_Default.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/readMoreTextView/src/main/java/com/erif/readmoretextview/InterpolatorType.java:
--------------------------------------------------------------------------------
1 | package com.erif.readmoretextview;
2 |
3 | import androidx.annotation.IntDef;
4 |
5 | import java.lang.annotation.Retention;
6 | import java.lang.annotation.RetentionPolicy;
7 | import static com.erif.readmoretextview.Interpolator.*;
8 |
9 | @IntDef({
10 | DECELERATE,
11 | ACCELERATE,
12 | ANTICIPATE_OVERSHOOT,
13 | ANTICIPATE,
14 | BOUNCE,
15 | FAST_OUT_LINEAR_IN,
16 | FAST_OUT_SLOW_IN,
17 | LINEAR_OUT_SLOW_IN,
18 | })
19 | @Retention(RetentionPolicy.SOURCE)
20 | public @interface InterpolatorType {
21 | }
22 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_list.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_entered_text.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.kts.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
--------------------------------------------------------------------------------
/readMoreTextView/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.kts.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/erif/readmoretextviewdemo/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.erif.readmoretextviewdemo;
2 |
3 | import android.content.Context;
4 |
5 | import androidx.test.platform.app.InstrumentationRegistry;
6 | import androidx.test.ext.junit.runners.AndroidJUnit4;
7 |
8 | import org.junit.Test;
9 | import org.junit.runner.RunWith;
10 |
11 | import static org.junit.Assert.*;
12 |
13 | /**
14 | * Instrumented test, which will execute on an Android device.
15 | *
16 | * @see Testing documentation
17 | */
18 | @RunWith(AndroidJUnit4.class)
19 | public class ExampleInstrumentedTest {
20 | @Test
21 | public void useAppContext() {
22 | // Context of the app under test.
23 | Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
24 | assertEquals("com.erif.readmoretextview", appContext.getPackageName());
25 | }
26 | }
--------------------------------------------------------------------------------
/app/src/main/res/values-night/themes.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
16 |
--------------------------------------------------------------------------------
/readMoreTextView/src/androidTest/java/com/erif/readmoretextview/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.erif.readmoretextview;
2 |
3 | import android.content.Context;
4 |
5 | import androidx.test.platform.app.InstrumentationRegistry;
6 | import androidx.test.ext.junit.runners.AndroidJUnit4;
7 |
8 | import org.junit.Test;
9 | import org.junit.runner.RunWith;
10 |
11 | import static org.junit.Assert.*;
12 |
13 | /**
14 | * Instrumented test, which will execute on an Android device.
15 | *
16 | * @see Testing documentation
17 | */
18 | @RunWith(AndroidJUnit4.class)
19 | public class ExampleInstrumentedTest {
20 | @Test
21 | public void useAppContext() {
22 | // Context of the app under test.
23 | Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
24 | assertEquals("com.erif.readmoretextview.test", appContext.getPackageName());
25 | }
26 | }
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/.idea/appInsightsSettings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
15 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/gradle/libs.versions.toml:
--------------------------------------------------------------------------------
1 | [versions]
2 | agp = "8.11.1"
3 | android-kotlin = "2.2.0"
4 | appcompat = "1.7.1"
5 | constraintlayout = "2.2.1"
6 | espresso-core = "3.6.1"
7 | junit = "4.13.2"
8 | junit-version = "1.2.1"
9 | material = "1.12.0"
10 |
11 | [libraries]
12 | androidx-appcompat = { module = "androidx.appcompat:appcompat", version.ref = "appcompat" }
13 | androidx-constraintlayout = { module = "androidx.constraintlayout:constraintlayout", version.ref = "constraintlayout" }
14 | androidx-espresso-core = { module = "androidx.test.espresso:espresso-core", version.ref = "espresso-core" }
15 | androidx-junit = { module = "androidx.test.ext:junit", version.ref = "junit-version" }
16 | junit = { module = "junit:junit", version.ref = "junit" }
17 | material = { module = "com.google.android.material:material", version.ref = "material" }
18 |
19 | [plugins]
20 | android-application = { id = "com.android.application", version.ref = "agp" }
21 | android-library = { id = "com.android.library", version.ref = "agp" }
22 | android-kotlin = { id = "org.jetbrains.kotlin.android", version.ref = "android-kotlin" }
23 | maven = { id = "maven-publish" }
--------------------------------------------------------------------------------
/app/build.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | alias(libs.plugins.android.application)
3 | alias(libs.plugins.android.kotlin)
4 | }
5 |
6 | android {
7 |
8 | namespace = "com.erif.readmoretextviewdemo"
9 | compileSdk = 36
10 |
11 | defaultConfig {
12 | applicationId = "com.erif.readmoretextviewdemo"
13 | minSdk = 21
14 | versionCode = 1
15 | versionName = "1.0"
16 |
17 | testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
18 | }
19 |
20 | buildTypes {
21 | release {
22 | isMinifyEnabled = false
23 | proguardFiles(
24 | getDefaultProguardFile("proguard-android-optimize.txt"),
25 | "proguard-rules.pro"
26 | )
27 | }
28 | }
29 |
30 | compileOptions {
31 | sourceCompatibility = JavaVersion.VERSION_17
32 | targetCompatibility = JavaVersion.VERSION_17
33 | }
34 | }
35 |
36 | dependencies {
37 |
38 | implementation(libs.androidx.appcompat)
39 | implementation(libs.material)
40 | implementation(libs.androidx.constraintlayout)
41 | implementation(project(":readMoreTextView"))
42 |
43 | testImplementation(libs.junit)
44 | androidTestImplementation(libs.androidx.junit)
45 | androidTestImplementation(libs.androidx.espresso.core)
46 | }
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 | # AndroidX package structure to make it clearer which packages are bundled with the
15 | # Android operating system, and which are packaged with your app"s APK
16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
17 | android.useAndroidX=true
18 | # Enables namespacing of each library's R class so that its R class includes only the
19 | # resources declared in the library itself and none from the library's dependencies,
20 | # thereby reducing the size of the R class for that library
21 | android.nonTransitiveRClass=true
22 | android.nonFinalResIds=true
23 | org.gradle.configuration-cache=true
--------------------------------------------------------------------------------
/readMoreTextView/build.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | alias(libs.plugins.android.library)
3 | alias(libs.plugins.maven)
4 | }
5 |
6 | afterEvaluate {
7 | configure {
8 | publications {
9 | create("release") {
10 | groupId = "com.github.eriffanani"
11 | artifactId = "TextViewReadMore"
12 | version = "4.1.0"
13 | afterEvaluate {
14 | artifact(tasks.getByName("bundleReleaseAar"))
15 | }
16 | }
17 | }
18 | }
19 | }
20 |
21 | android {
22 |
23 | namespace = "com.erif.readmoretextview"
24 | compileSdk = 36
25 |
26 | defaultConfig {
27 | minSdk = 21
28 |
29 | testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
30 | consumerProguardFiles("consumer-rules.pro")
31 | }
32 |
33 | buildTypes {
34 | release {
35 | isMinifyEnabled = false
36 | proguardFiles(
37 | getDefaultProguardFile("proguard-android-optimize.txt"),
38 | "proguard-rules.pro"
39 | )
40 | }
41 | }
42 |
43 | compileOptions {
44 | sourceCompatibility = JavaVersion.VERSION_17
45 | targetCompatibility = JavaVersion.VERSION_17
46 | }
47 | }
48 |
49 | dependencies {
50 | implementation(libs.androidx.appcompat)
51 | implementation(libs.material)
52 |
53 | testImplementation(libs.junit)
54 | androidTestImplementation(libs.androidx.junit)
55 | androidTestImplementation(libs.androidx.espresso.core)
56 | }
57 |
58 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
19 |
20 |
26 |
27 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/app/src/main/java/com/erif/readmoretextviewdemo/model/ModelItemRecyclerView.java:
--------------------------------------------------------------------------------
1 | package com.erif.readmoretextviewdemo.model;
2 |
3 | public class ModelItemRecyclerView {
4 |
5 | private int id;
6 |
7 | private String name;
8 |
9 | private int profile;
10 |
11 | private int img;
12 |
13 | private String text;
14 | private boolean collapsed = true;
15 | private boolean showImage = false;
16 |
17 | public ModelItemRecyclerView() {}
18 |
19 | public ModelItemRecyclerView(int id, String name, int profile, int img, String text) {
20 | this.id = id;
21 | this.name = name;
22 | this.profile = profile;
23 | this.img = img;
24 | this.text = text;
25 | }
26 |
27 | public int getId() {
28 | return id;
29 | }
30 |
31 | public void setId(int id) {
32 | this.id = id;
33 | }
34 |
35 | public String getName() {
36 | return name;
37 | }
38 |
39 | public int getProfile() {
40 | return profile;
41 | }
42 |
43 | public String getText() {
44 | return text;
45 | }
46 |
47 | public void setText(String text) {
48 | this.text = text;
49 | }
50 |
51 | public boolean isCollapsed() {
52 | return collapsed;
53 | }
54 |
55 | public int getImg() {
56 | return img;
57 | }
58 |
59 | public void setImg(int img) {
60 | this.img = img;
61 | }
62 |
63 | public void setCollapsed(boolean collapsed) {
64 | this.collapsed = collapsed;
65 | }
66 |
67 | public boolean isShowImage() {
68 | return showImage;
69 | }
70 |
71 | public void setShowImage(boolean showImage) {
72 | this.showImage = showImage;
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
15 |
18 |
21 |
22 |
23 |
24 |
30 |
--------------------------------------------------------------------------------
/app/src/main/java/com/erif/readmoretextviewdemo/ActDetail.java:
--------------------------------------------------------------------------------
1 | package com.erif.readmoretextviewdemo;
2 |
3 | import android.os.Bundle;
4 | import android.view.MenuItem;
5 |
6 | import androidx.annotation.NonNull;
7 | import androidx.appcompat.app.AppCompatActivity;
8 |
9 | import com.erif.readmoretextview.TextViewReadMore;
10 |
11 | public class ActDetail extends AppCompatActivity {
12 |
13 | @Override
14 | protected void onCreate(Bundle savedInstanceState) {
15 | super.onCreate(savedInstanceState);
16 | setContentView(R.layout.act_detail);
17 |
18 | if (getSupportActionBar() != null) {
19 | getSupportActionBar().setDisplayHomeAsUpEnabled(true);
20 | getSupportActionBar().setTitle("Another Detail Example");
21 | }
22 |
23 | TextViewReadMore txtEntered = findViewById(R.id.act_detail_txtEntered);
24 | txtEntered.onClickExpand(v -> txtEntered.toggle());
25 | txtEntered.onClickCollapse(v -> txtEntered.toggle());
26 |
27 | TextViewReadMore txtEntered2 = findViewById(R.id.act_detail_txtEntered2);
28 | txtEntered2.onClickExpand(v -> txtEntered2.toggle());
29 | txtEntered2.onClickCollapse(v -> txtEntered2.toggle());
30 |
31 | TextViewReadMore txtAnim = findViewById(R.id.act_detail_txtAnim);
32 | txtAnim.onClickExpand(v -> txtAnim.toggle());
33 | txtAnim.onClickCollapse(v -> txtAnim.toggle());
34 |
35 | TextViewReadMore txtJustify = findViewById(R.id.act_detail_txtJustify);
36 | txtJustify.onClickExpand(v -> txtJustify.toggle());
37 | txtJustify.onClickCollapse(v -> txtJustify.toggle());
38 |
39 | }
40 |
41 | @Override
42 | public boolean onOptionsItemSelected(@NonNull MenuItem item) {
43 | if (item.getItemId() == android.R.id.home) {
44 | finish();
45 | return true;
46 | }
47 | return super.onOptionsItemSelected(item);
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/app/src/main/res/values/themes.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
20 |
21 |
38 |
39 |
--------------------------------------------------------------------------------
/readMoreTextView/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @rem
2 | @rem Copyright 2015 the original author or authors.
3 | @rem
4 | @rem Licensed under the Apache License, Version 2.0 (the "License");
5 | @rem you may not use this file except in compliance with the License.
6 | @rem You may obtain a copy of the License at
7 | @rem
8 | @rem https://www.apache.org/licenses/LICENSE-2.0
9 | @rem
10 | @rem Unless required by applicable law or agreed to in writing, software
11 | @rem distributed under the License is distributed on an "AS IS" BASIS,
12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | @rem See the License for the specific language governing permissions and
14 | @rem limitations under the License.
15 | @rem
16 |
17 | @if "%DEBUG%" == "" @echo off
18 | @rem ##########################################################################
19 | @rem
20 | @rem Gradle startup script for Windows
21 | @rem
22 | @rem ##########################################################################
23 |
24 | @rem Set local scope for the variables with windows NT shell
25 | if "%OS%"=="Windows_NT" setlocal
26 |
27 | set DIRNAME=%~dp0
28 | if "%DIRNAME%" == "" set DIRNAME=.
29 | set APP_BASE_NAME=%~n0
30 | set APP_HOME=%DIRNAME%
31 |
32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter.
33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
34 |
35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
37 |
38 | @rem Find java.exe
39 | if defined JAVA_HOME goto findJavaFromJavaHome
40 |
41 | set JAVA_EXE=java.exe
42 | %JAVA_EXE% -version >NUL 2>&1
43 | if "%ERRORLEVEL%" == "0" goto execute
44 |
45 | echo.
46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
47 | echo.
48 | echo Please set the JAVA_HOME variable in your environment to match the
49 | echo location of your Java installation.
50 |
51 | goto fail
52 |
53 | :findJavaFromJavaHome
54 | set JAVA_HOME=%JAVA_HOME:"=%
55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
56 |
57 | if exist "%JAVA_EXE%" goto execute
58 |
59 | echo.
60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
61 | echo.
62 | echo Please set the JAVA_HOME variable in your environment to match the
63 | echo location of your Java installation.
64 |
65 | goto fail
66 |
67 | :execute
68 | @rem Setup the command line
69 |
70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
71 |
72 |
73 | @rem Execute Gradle
74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
75 |
76 | :end
77 | @rem End local scope for the variables with windows NT shell
78 | if "%ERRORLEVEL%"=="0" goto mainEnd
79 |
80 | :fail
81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
82 | rem the _cmd.exe /c_ return code!
83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
84 | exit /b 1
85 |
86 | :mainEnd
87 | if "%OS%"=="Windows_NT" endlocal
88 |
89 | :omega
90 |
--------------------------------------------------------------------------------
/app/src/main/java/com/erif/readmoretextviewdemo/adapter/AdapterRecyclerView.java:
--------------------------------------------------------------------------------
1 | package com.erif.readmoretextviewdemo.adapter;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.view.LayoutInflater;
5 | import android.view.View;
6 | import android.view.ViewGroup;
7 | import android.widget.ImageView;
8 | import android.widget.TextView;
9 |
10 | import androidx.annotation.NonNull;
11 | import androidx.recyclerview.widget.RecyclerView;
12 |
13 | import com.erif.readmoretextviewdemo.R;
14 | import com.erif.readmoretextview.TextViewReadMore;
15 | import com.erif.readmoretextviewdemo.model.ModelItemRecyclerView;
16 | import com.google.android.material.imageview.ShapeableImageView;
17 |
18 | import java.text.SimpleDateFormat;
19 | import java.util.ArrayList;
20 | import java.util.Date;
21 | import java.util.List;
22 | import java.util.Locale;
23 |
24 | public class AdapterRecyclerView extends RecyclerView.Adapter {
25 |
26 | private List list = new ArrayList<>();
27 |
28 | @NonNull
29 | @Override
30 | public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
31 | LayoutInflater inflater = LayoutInflater.from(parent.getContext());
32 | return new Holder(inflater.inflate(R.layout.item_recycler_view, parent, false));
33 | }
34 |
35 | @Override
36 | public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
37 | if (holder instanceof Holder mHolder) {
38 | ModelItemRecyclerView item = list.get(position);
39 | mHolder.imgProfile.setImageResource(item.getProfile());
40 | mHolder.text.setText(item.getText());
41 | mHolder.text.collapsed(item.isCollapsed());
42 | mHolder.txtName.setText(item.getName());
43 | mHolder.img.setImageResource(item.getImg());
44 | mHolder.img.setVisibility(item.isShowImage() ? View.VISIBLE : View.GONE);
45 |
46 | mHolder.text.onClickExpand(v -> mHolder.text.toggle());
47 | mHolder.text.onClickCollapse(v -> mHolder.text.toggle());
48 | mHolder.text.toggleListener(collapsed -> {
49 | item.setCollapsed(collapsed);
50 | update(position);
51 | });
52 |
53 | mHolder.img.setOnClickListener(v -> update(position));
54 |
55 | SimpleDateFormat format = new SimpleDateFormat("EEEE, dd MMMM yyyy", Locale.getDefault());
56 | String date = format.format(new Date());
57 | mHolder.txtSubtitle.setText(date);
58 |
59 | }
60 | }
61 |
62 | @Override
63 | public int getItemCount() {
64 | return list.size();
65 | }
66 |
67 | @SuppressLint("NotifyDataSetChanged")
68 | public void setList(List list) {
69 | this.list = list;
70 | notifyDataSetChanged();
71 | }
72 |
73 | private void update(int position) {
74 | notifyItemChanged(position);
75 | }
76 |
77 | private static class Holder extends RecyclerView.ViewHolder {
78 | private final TextViewReadMore text;
79 | private final ShapeableImageView imgProfile;
80 | private final TextView txtName;
81 | private final TextView txtSubtitle;
82 | private final ImageView img;
83 | public Holder(@NonNull View itemView) {
84 | super(itemView);
85 | text = itemView.findViewById(R.id.item_recyclerView_txt);
86 | imgProfile = itemView.findViewById(R.id.item_recyclerView_imgProfile);
87 | txtName = itemView.findViewById(R.id.item_recyclerView_txtName);
88 | txtSubtitle = itemView.findViewById(R.id.item_recyclerView_txtSubtitle);
89 | img = itemView.findViewById(R.id.item_recyclerView_img);
90 | }
91 | }
92 |
93 | }
94 |
--------------------------------------------------------------------------------
/.idea/codeStyles/Project.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 | xmlns:android
21 |
22 | ^$
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 | xmlns:.*
32 |
33 | ^$
34 |
35 |
36 | BY_NAME
37 |
38 |
39 |
40 |
41 |
42 |
43 | .*:id
44 |
45 | http://schemas.android.com/apk/res/android
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 | .*:name
55 |
56 | http://schemas.android.com/apk/res/android
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 | name
66 |
67 | ^$
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 | style
77 |
78 | ^$
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 | .*
88 |
89 | ^$
90 |
91 |
92 | BY_NAME
93 |
94 |
95 |
96 |
97 |
98 |
99 | .*
100 |
101 | http://schemas.android.com/apk/res/android
102 |
103 |
104 | ANDROID_ATTRIBUTE_ORDER
105 |
106 |
107 |
108 |
109 |
110 |
111 | .*
112 |
113 | .*
114 |
115 |
116 | BY_NAME
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_recycler_view.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
15 |
16 |
23 |
24 |
31 |
32 |
37 |
38 |
46 |
47 |
54 |
55 |
56 |
57 |
58 |
59 |
68 |
69 |
70 |
71 |
75 |
76 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
109 |
110 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # TextView Read More
2 | Make your long textview setup easily and quickly
3 |
4 | ## Installation
5 | #### settings.gradle
6 | ```kotlin
7 | dependencyResolutionManagement {
8 | repositories {
9 | maven { url 'https://jitpack.io' }
10 | }
11 | }
12 | ```
13 |
14 | #### build.gradle(app)
15 | ```kotlin
16 | dependencies {
17 | implementation 'com.github.eriffanani:TextViewReadMore:4.1.0'
18 | }
19 | ```
20 |
21 | ## How To Use
22 | * Basic
23 | ```xml
24 |
29 | ```
30 | 
31 |
32 | #### Styling
33 | * Expand
34 | ```xml
35 |
42 | ```
43 | 
44 |
45 | * Collapse
46 | ```xml
47 |
53 | ```
54 |
55 | ### Animation
56 | ```xml
57 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 | ```
75 |
76 | ### Ellipsis Type
77 | ```xml
78 |
80 | ```
81 | ### Action
82 | ```xml
83 |
85 | ```
86 | ```java
87 | TextViewReadMore txtReadMore = findViewById(R.id.txtReadMore);
88 | txtReadMore.onClickExpand(v -> txtReadMore.toggle());
89 | txtReadMore.onClickCollapse(v -> txtReadMore.toggle());
90 | ```
91 |
92 | ### Listener
93 | * Java
94 | ```Java
95 | txtReadMore.toggleListener(collapsed -> { // TODO ACTION });
96 | ```
97 | * Kotlin
98 | ```kotlin
99 | txtReadMore.toggleListener { collapsed -> // TODO ACTION }
100 | ```
101 |
102 | ## Result
103 |
104 |
105 | ### With recyclerview
106 | * Use collapse function to onBindViewHolder
107 | ```java
108 | /**
109 | item.isCollapsed() is variable from your item to store and save state of
110 | textview (collapsed/expanded) when item displayed again from RecyclerView scroll
111 | */
112 | holder.text.collapsed(item.isCollapsed());
113 | ```
114 | * Use Toggle
115 | ```java
116 | holder.text.onClickExpand(v -> holder.text.toggle());
117 | holder.text.onClickCollapse(v -> holder.text.toggle());
118 | holder.text.toggleListener(collapsed -> {
119 | item.setCollapsed(collapsed);
120 | notifyItemChanged(position);
121 | });
122 | ```
123 | * Use Collapse Properties
124 | ```java
125 | // onClickExpand or onClickCollapse
126 | holder.text.onClickExpand(v -> {
127 | boolean status = !item.isCollapsed();
128 | holder.text.collapsed(status);
129 | item.setCollapsed(status);
130 | notifyItemChanged(position);
131 | });
132 | ```
133 | ## Result
134 |
135 |
136 | #### Information
137 | This library is still being developed further, please provide feedback if you find a bug. Thank you
138 | ### Licence
139 | ```license
140 | Copyright 2022 Mukhammad Erif Fanani
141 |
142 | Licensed under the Apache License, Version 2.0 (the "License");
143 | you may not use this file except in compliance with the License.
144 | You may obtain a copy of the License at
145 |
146 | http://www.apache.org/licenses/LICENSE-2.0
147 |
148 | Unless required by applicable law or agreed to in writing, software
149 | distributed under the License is distributed on an "AS IS" BASIS,
150 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
151 | See the License for the specific language governing permissions and
152 | limitations under the License.
153 | ```
154 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/act_detail.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
15 |
16 |
24 |
25 |
43 |
44 |
62 |
63 |
72 |
73 |
95 |
96 |
105 |
106 |
122 |
123 |
124 |
125 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/app/src/main/java/com/erif/readmoretextviewdemo/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.erif.readmoretextviewdemo;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.view.Menu;
6 | import android.view.MenuItem;
7 | import android.view.ViewGroup;
8 |
9 | import androidx.annotation.NonNull;
10 | import androidx.appcompat.app.AppCompatActivity;
11 | import androidx.appcompat.widget.Toolbar;
12 | import androidx.coordinatorlayout.widget.CoordinatorLayout;
13 | import androidx.core.graphics.Insets;
14 | import androidx.core.view.ViewCompat;
15 | import androidx.core.view.WindowCompat;
16 | import androidx.core.view.WindowInsetsCompat;
17 | import androidx.recyclerview.widget.DividerItemDecoration;
18 | import androidx.recyclerview.widget.LinearLayoutManager;
19 | import androidx.recyclerview.widget.RecyclerView;
20 | import androidx.recyclerview.widget.SimpleItemAnimator;
21 |
22 | import com.erif.readmoretextviewdemo.adapter.AdapterRecyclerView;
23 | import com.erif.readmoretextviewdemo.model.ModelItemRecyclerView;
24 |
25 | import java.util.ArrayList;
26 | import java.util.List;
27 | import java.util.Random;
28 |
29 | public class MainActivity extends AppCompatActivity {
30 |
31 | private CoordinatorLayout parentView;
32 | private Toolbar toolbar;
33 | private RecyclerView recyclerView;
34 | private AdapterRecyclerView adapter;
35 | private final List list = new ArrayList<>();
36 |
37 | @Override
38 | protected void onCreate(Bundle savedInstanceState) {
39 | super.onCreate(savedInstanceState);
40 | WindowCompat.setDecorFitsSystemWindows(getWindow(), false);
41 | setContentView(R.layout.activity_main);
42 | parentView = findViewById(R.id.act_main_parentView);
43 | toolbar = findViewById(R.id.act_main_toolbar);
44 | setSupportActionBar(toolbar);
45 | adapter = new AdapterRecyclerView();
46 |
47 | recyclerView = findViewById(R.id.act_main_recyclerView);
48 |
49 | recyclerView.setAdapter(adapter);
50 | LinearLayoutManager manager = new LinearLayoutManager(this);
51 | recyclerView.setLayoutManager(manager);
52 | recyclerView.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL));
53 | SimpleItemAnimator animator = (SimpleItemAnimator) recyclerView.getItemAnimator();
54 | if (animator != null)
55 | animator.setSupportsChangeAnimations(false);
56 |
57 | String[] arr = new String[] {
58 | getString(R.string.lorem_ipsum1),
59 | getString(R.string.lorem_short),
60 | getString(R.string.lorem_ipsum2),
61 | getString(R.string.lorem_ipsum3),
62 | "Short text 1",
63 | getString(R.string.lorem_ipsum4),
64 | getString(R.string.lorem_ipsum1),
65 | getString(R.string.lorem_ipsum2),
66 | "Short text 2",
67 | getString(R.string.lorem_ipsum1),
68 | getString(R.string.lorem_ipsum2)
69 | };
70 |
71 | String[] arrName = new String[] {
72 | "John Doe", "Louise Bourgeois",
73 | "Rafael Nadal", "Maria Sharapova",
74 | "C. Ronaldo", "Serena Williams",
75 | "John Doe", "Louise Bourgeois",
76 | "Rafael Nadal", "Maria Sharapova",
77 | "C. Ronaldo", "Serena Williams"
78 | };
79 |
80 | int [] profile = new int[] {
81 | R.mipmap.man1,
82 | R.mipmap.women1,
83 | R.mipmap.man2,
84 | R.mipmap.women2,
85 | R.mipmap.man3,
86 | R.mipmap.women3,
87 | R.mipmap.man1,
88 | R.mipmap.women1,
89 | R.mipmap.man2,
90 | R.mipmap.women2,
91 | R.mipmap.man3,
92 | R.mipmap.women3
93 | };
94 |
95 | int [] img = new int[] {
96 | R.mipmap.img2,
97 | R.mipmap.img3,
98 | R.mipmap.img4,
99 | R.mipmap.img5,
100 | R.mipmap.img2,
101 | R.mipmap.img3,
102 | R.mipmap.img4,
103 | R.mipmap.img5,
104 | R.mipmap.img2,
105 | R.mipmap.img3,
106 | R.mipmap.img4
107 | };
108 |
109 | for (int i=0; i {
124 | Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
125 | int statusBarHeight = systemBars.top;
126 | int navigationBarHeight = systemBars.bottom;
127 | ViewGroup.MarginLayoutParams toolbarParam = (ViewGroup.MarginLayoutParams) toolbar.getLayoutParams();
128 | toolbarParam.topMargin = statusBarHeight;
129 | toolbar.post(() -> {
130 | int toolbarHeight = toolbar.getHeight();
131 | int recyclerViewPaddingTop = statusBarHeight + toolbarHeight;
132 | recyclerView.setPadding(
133 | recyclerView.getPaddingStart(), recyclerViewPaddingTop,
134 | recyclerView.getPaddingEnd(), navigationBarHeight
135 | );
136 | adapter.setList(list);
137 | });
138 | return WindowInsetsCompat.CONSUMED;
139 | });
140 | }
141 |
142 | @Override
143 | public boolean onCreateOptionsMenu(Menu menu) {
144 | getMenuInflater().inflate(R.menu.main_menu, menu);
145 | return super.onCreateOptionsMenu(menu);
146 | }
147 |
148 | @Override
149 | public boolean onOptionsItemSelected(@NonNull MenuItem item) {
150 | if (item.getItemId() == R.id.main_menu_short_entered) {
151 | Intent intent = new Intent(this, ActDetail.class);
152 | startActivity(intent);
153 | }
154 | return super.onOptionsItemSelected(item);
155 | }
156 | }
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | #
4 | # Copyright 2015 the original author or authors.
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # https://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | ##############################################################################
20 | ##
21 | ## Gradle start up script for UN*X
22 | ##
23 | ##############################################################################
24 |
25 | # Attempt to set APP_HOME
26 | # Resolve links: $0 may be a link
27 | PRG="$0"
28 | # Need this for relative symlinks.
29 | while [ -h "$PRG" ] ; do
30 | ls=`ls -ld "$PRG"`
31 | link=`expr "$ls" : '.*-> \(.*\)$'`
32 | if expr "$link" : '/.*' > /dev/null; then
33 | PRG="$link"
34 | else
35 | PRG=`dirname "$PRG"`"/$link"
36 | fi
37 | done
38 | SAVED="`pwd`"
39 | cd "`dirname \"$PRG\"`/" >/dev/null
40 | APP_HOME="`pwd -P`"
41 | cd "$SAVED" >/dev/null
42 |
43 | APP_NAME="Gradle"
44 | APP_BASE_NAME=`basename "$0"`
45 |
46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
48 |
49 | # Use the maximum available, or set MAX_FD != -1 to use that value.
50 | MAX_FD="maximum"
51 |
52 | warn () {
53 | echo "$*"
54 | }
55 |
56 | die () {
57 | echo
58 | echo "$*"
59 | echo
60 | exit 1
61 | }
62 |
63 | # OS specific support (must be 'true' or 'false').
64 | cygwin=false
65 | msys=false
66 | darwin=false
67 | nonstop=false
68 | case "`uname`" in
69 | CYGWIN* )
70 | cygwin=true
71 | ;;
72 | Darwin* )
73 | darwin=true
74 | ;;
75 | MINGW* )
76 | msys=true
77 | ;;
78 | NONSTOP* )
79 | nonstop=true
80 | ;;
81 | esac
82 |
83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
84 |
85 |
86 | # Determine the Java command to use to start the JVM.
87 | if [ -n "$JAVA_HOME" ] ; then
88 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
89 | # IBM's JDK on AIX uses strange locations for the executables
90 | JAVACMD="$JAVA_HOME/jre/sh/java"
91 | else
92 | JAVACMD="$JAVA_HOME/bin/java"
93 | fi
94 | if [ ! -x "$JAVACMD" ] ; then
95 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
96 |
97 | Please set the JAVA_HOME variable in your environment to match the
98 | location of your Java installation."
99 | fi
100 | else
101 | JAVACMD="java"
102 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
103 |
104 | Please set the JAVA_HOME variable in your environment to match the
105 | location of your Java installation."
106 | fi
107 |
108 | # Increase the maximum file descriptors if we can.
109 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
110 | MAX_FD_LIMIT=`ulimit -H -n`
111 | if [ $? -eq 0 ] ; then
112 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
113 | MAX_FD="$MAX_FD_LIMIT"
114 | fi
115 | ulimit -n $MAX_FD
116 | if [ $? -ne 0 ] ; then
117 | warn "Could not set maximum file descriptor limit: $MAX_FD"
118 | fi
119 | else
120 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
121 | fi
122 | fi
123 |
124 | # For Darwin, add options to specify how the application appears in the dock
125 | if $darwin; then
126 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
127 | fi
128 |
129 | # For Cygwin or MSYS, switch paths to Windows format before running java
130 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
131 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
132 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
133 |
134 | JAVACMD=`cygpath --unix "$JAVACMD"`
135 |
136 | # We build the pattern for arguments to be converted via cygpath
137 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
138 | SEP=""
139 | for dir in $ROOTDIRSRAW ; do
140 | ROOTDIRS="$ROOTDIRS$SEP$dir"
141 | SEP="|"
142 | done
143 | OURCYGPATTERN="(^($ROOTDIRS))"
144 | # Add a user-defined pattern to the cygpath arguments
145 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
146 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
147 | fi
148 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
149 | i=0
150 | for arg in "$@" ; do
151 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
152 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
153 |
154 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
155 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
156 | else
157 | eval `echo args$i`="\"$arg\""
158 | fi
159 | i=`expr $i + 1`
160 | done
161 | case $i in
162 | 0) set -- ;;
163 | 1) set -- "$args0" ;;
164 | 2) set -- "$args0" "$args1" ;;
165 | 3) set -- "$args0" "$args1" "$args2" ;;
166 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;;
167 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
168 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
169 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
170 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
171 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
172 | esac
173 | fi
174 |
175 | # Escape application args
176 | save () {
177 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
178 | echo " "
179 | }
180 | APP_ARGS=`save "$@"`
181 |
182 | # Collect all arguments for the java command, following the shell quoting and substitution rules
183 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
184 |
185 | exec "$JAVACMD" "$@"
186 |
--------------------------------------------------------------------------------
/.idea/intellij-javadocs-4.0.1.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | UPDATE
6 | false
7 | true
8 |
9 | FIELD
10 | TYPE
11 | METHOD
12 |
13 |
14 | PUBLIC
15 | PROTECTED
16 | DEFAULT
17 |
18 |
19 |
20 |
21 |
22 | ^.*(public|protected|private)*.+interface\s+\w+.*
23 | /**\n
24 | * The interface ${name}.\n
25 | <#if element.typeParameters?has_content> * \n
26 | </#if>
27 | <#list element.typeParameters as typeParameter>
28 | * @param <${typeParameter.name}> the type parameter\n
29 | </#list>
30 | */
31 |
32 |
33 | ^.*(public|protected|private)*.+enum\s+\w+.*
34 | /**\n
35 | * The enum ${name}.\n
36 | */
37 |
38 |
39 | ^.*(public|protected|private)*.+class\s+\w+.*
40 | /**\n
41 | * The type ${name}.\n
42 | <#if element.typeParameters?has_content> * \n
43 | </#if>
44 | <#list element.typeParameters as typeParameter>
45 | * @param <${typeParameter.name}> the type parameter\n
46 | </#list>
47 | */
48 |
49 |
50 | .+
51 | /**\n
52 | * The type ${name}.\n
53 | */
54 |
55 |
56 |
57 |
58 | .+
59 | /**\n
60 | * Instantiates a new ${name}.\n
61 | <#if element.parameterList.parameters?has_content>
62 | *\n
63 | </#if>
64 | <#list element.parameterList.parameters as parameter>
65 | * @param ${parameter.name} the ${paramNames[parameter.name]}\n
66 | </#list>
67 | <#if element.throwsList.referenceElements?has_content>
68 | *\n
69 | </#if>
70 | <#list element.throwsList.referenceElements as exception>
71 | * @throws ${exception.referenceName} the ${exceptionNames[exception.referenceName]}\n
72 | </#list>
73 | */
74 |
75 |
76 |
77 |
78 | ^.*(public|protected|private)*\s*.*(\w(\s*<.+>)*)+\s+get\w+\s*\(.*\).+
79 | /**\n
80 | * Gets ${partName}.\n
81 | <#if element.typeParameters?has_content> * \n
82 | </#if>
83 | <#list element.typeParameters as typeParameter>
84 | * @param <${typeParameter.name}> the type parameter\n
85 | </#list>
86 | <#if element.parameterList.parameters?has_content>
87 | *\n
88 | </#if>
89 | <#list element.parameterList.parameters as parameter>
90 | * @param ${parameter.name} the ${paramNames[parameter.name]}\n
91 | </#list>
92 | <#if isNotVoid>
93 | *\n
94 | * @return the ${partName}\n
95 | </#if>
96 | <#if element.throwsList.referenceElements?has_content>
97 | *\n
98 | </#if>
99 | <#list element.throwsList.referenceElements as exception>
100 | * @throws ${exception.referenceName} the ${exceptionNames[exception.referenceName]}\n
101 | </#list>
102 | */
103 |
104 |
105 | ^.*(public|protected|private)*\s*.*(void|\w(\s*<.+>)*)+\s+set\w+\s*\(.*\).+
106 | /**\n
107 | * Sets ${partName}.\n
108 | <#if element.typeParameters?has_content> * \n
109 | </#if>
110 | <#list element.typeParameters as typeParameter>
111 | * @param <${typeParameter.name}> the type parameter\n
112 | </#list>
113 | <#if element.parameterList.parameters?has_content>
114 | *\n
115 | </#if>
116 | <#list element.parameterList.parameters as parameter>
117 | * @param ${parameter.name} the ${paramNames[parameter.name]}\n
118 | </#list>
119 | <#if isNotVoid>
120 | *\n
121 | * @return the ${partName}\n
122 | </#if>
123 | <#if element.throwsList.referenceElements?has_content>
124 | *\n
125 | </#if>
126 | <#list element.throwsList.referenceElements as exception>
127 | * @throws ${exception.referenceName} the ${exceptionNames[exception.referenceName]}\n
128 | </#list>
129 | */
130 |
131 |
132 | ^.*((public\s+static)|(static\s+public))\s+void\s+main\s*\(\s*String\s*(\[\s*\]|\.\.\.)\s+\w+\s*\).+
133 | /**\n
134 | * The entry point of application.\n
135 |
136 | <#if element.parameterList.parameters?has_content>
137 | *\n
138 | </#if>
139 | * @param ${element.parameterList.parameters[0].name} the input arguments\n
140 | <#if element.throwsList.referenceElements?has_content>
141 | *\n
142 | </#if>
143 | <#list element.throwsList.referenceElements as exception>
144 | * @throws ${exception.referenceName} the ${exceptionNames[exception.referenceName]}\n
145 | </#list>
146 | */
147 |
148 |
149 | .+
150 | /**\n
151 | * ${name}<#if isNotVoid> ${return}</#if>.\n
152 | <#if element.typeParameters?has_content> * \n
153 | </#if>
154 | <#list element.typeParameters as typeParameter>
155 | * @param <${typeParameter.name}> the type parameter\n
156 | </#list>
157 | <#if element.parameterList.parameters?has_content>
158 | *\n
159 | </#if>
160 | <#list element.parameterList.parameters as parameter>
161 | * @param ${parameter.name} the ${paramNames[parameter.name]}\n
162 | </#list>
163 | <#if isNotVoid>
164 | *\n
165 | * @return the ${return}\n
166 | </#if>
167 | <#if element.throwsList.referenceElements?has_content>
168 | *\n
169 | </#if>
170 | <#list element.throwsList.referenceElements as exception>
171 | * @throws ${exception.referenceName} the ${exceptionNames[exception.referenceName]}\n
172 | </#list>
173 | */
174 |
175 |
176 |
177 |
178 | ^.*(public|protected|private)*.+static.*(\w\s\w)+.+
179 | /**\n
180 | * The constant ${element.getName()}.\n
181 | */
182 |
183 |
184 | ^.*(public|protected|private)*.*(\w\s\w)+.+
185 | /**\n
186 | <#if element.parent.isInterface()>
187 | * The constant ${element.getName()}.\n
188 | <#else>
189 | * The ${name}.\n
190 | </#if> */
191 |
192 |
193 | .+
194 | /**\n
195 | <#if element.parent.isEnum()>
196 | *${name} ${typeName}.\n
197 | <#else>
198 | * The ${name}.\n
199 | </#if>*/
200 |
201 |
202 |
203 |
204 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Read More TextView
3 |
4 | Long text 2 Lorem ipsum at placerat massa Maecenas sodales rutrum est sed efficitur Nunc at Nunc at placerat massa Maecenas sodales
5 | placerat massa. asdfasf Maecenas sodales rutrum est sed efficitur.
6 |
7 | Long text 1 Lorem ipsum dolor sit amet, consectetur adipiscing elit.
8 | Maecenas sodales rutrum est sed efficitur. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
9 | Fusce eget ligula sed dolor accumsan tristique id vel turpis. Nam congue nunc hendrerit eros fermentum eleifend.
10 | Sed tristique facilisis imperdiet. Donec eget interdum dui.
11 |
12 | Long text 3 Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris pretium mauris vel
13 | lacus vulputate, ac dictum velit tempus. Suspendisse potenti. Proin eget sem ullamcorper, faucibus orci vel,
14 | facilisis sem. Nullam in metus at eros mattis malesuada. Vestibulum id justo sed ex interdum ultrices. Vestibulum
15 | lobortis posuere felis, a dictum tortor. Etiam a gravida augue, at interdum lacus. Ut finibus metus orci, eget
16 | lacinia turpis imperdiet et. Donec in sagittis erat. Aenean egestas vulputate nunc vel pulvinar. Pellentesque
17 | habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Maecenas nec orci porta,
18 | finibus quam ut, fringilla sapien. Maecenas tristique justo turpis, non pretium ligula sagittis luctus.
19 | Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum
20 | scelerisque tristique hendrerit.
21 |
22 |
23 | Long text 4 Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris pretium mauris vel
24 | lacus vulputate, ac dictum velit tempus. Suspendisse potenti. Proin eget sem ullamcorper, faucibus orci vel,
25 | facilisis sem. Nullam in metus at eros mattis malesuada. Vestibulum id justo sed ex interdum ultrices. Vestibulum
26 | lobortis posuere felis, a dictum tortor. Etiam a gravida augue, at interdum lacus. Ut finibus metus orci, eget
27 | lacinia turpis imperdiet et. Donec in sagittis erat. Aenean egestas vulputate nunc vel pulvinar. Pellentesque
28 | habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Maecenas nec orci porta,
29 | finibus quam ut, fringilla sapien. Maecenas tristique justo turpis, non pretium ligula sagittis luctus.
30 | Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum
31 | scelerisque tristique hendrerit.
32 | Cras vitae sapien pulvinar, accumsan nulla non, accumsan est. Praesent interdum turpis ut sem condimentum lobortis.
33 | Vestibulum suscipit diam vel nisi convallis efficitur. Fusce dapibus hendrerit lobortis. Nulla sagittis nisl et
34 | faucibus convallis. Proin eget hendrerit lectus, sed suscipit nunc. Pellentesque aliquam justo ut hendrerit
35 | porttitor. Duis quis dignissim velit, non semper lorem. Phasellus pulvinar, mi vitae consectetur ullamcorper,
36 | odio nisi luctus dolor, et accumsan erat tellus quis enim. Etiam finibus tortor nec viverra mattis. Nullam
37 | vehicula, neque ac pretium gravida, magna libero placerat neque, et imperdiet velit turpis vestibulum sapien.
38 |
39 |
40 | Long text 5 Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris pretium mauris vel
41 | lacus vulputate, ac dictum velit tempus. Suspendisse potenti. Proin eget sem ullamcorper, faucibus orci vel,
42 | facilisis sem. Nullam in metus at eros mattis malesuada. Vestibulum id justo sed ex interdum ultrices. Vestibulum
43 | lobortis posuere felis, a dictum tortor. Etiam a gravida augue, at interdum lacus. Ut finibus metus orci, eget
44 | lacinia turpis imperdiet et. Donec in sagittis erat. Aenean egestas vulputate nunc vel pulvinar. Pellentesque
45 | habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Maecenas nec orci porta,
46 | finibus quam ut, fringilla sapien. Maecenas tristique justo turpis, non pretium ligula sagittis luctus.
47 | Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum
48 | scelerisque tristique hendrerit.
49 | Cras vitae sapien pulvinar, accumsan nulla non, accumsan est. Praesent interdum turpis ut sem condimentum lobortis.
50 | Vestibulum suscipit diam vel nisi convallis efficitur. Fusce dapibus hendrerit lobortis. Nulla sagittis nisl et
51 | faucibus convallis. Proin eget hendrerit lectus, sed suscipit nunc. Pellentesque aliquam justo ut hendrerit
52 | porttitor. Duis quis dignissim velit, non semper lorem. Phasellus pulvinar, mi vitae consectetur ullamcorper,
53 | odio nisi luctus dolor, et accumsan erat tellus quis enim. Etiam finibus tortor nec viverra mattis. Nullam
54 | vehicula, neque ac pretium gravida, magna libero placerat neque, et imperdiet velit turpis vestibulum sapien.
55 | Quisque nec arcu ac metus euismod ultricies eu sed tortor. Nunc tristique tellus tortor, at semper ipsum hendrerit ac.
56 | Sed aliquam imperdiet magna vitae vestibulum. Nullam aliquam, sapien vel semper dictum, felis velit interdum
57 | libero, non condimentum dolor nulla quis erat. Fusce fermentum, ex et pretium pharetra, erat libero ultrices
58 | erat, a luctus erat lacus vitae odio. Vestibulum vitae lectus eu dolor convallis pellentesque laoreet non tortor.
59 | Maecenas ultricies suscipit condimentum. Suspendisse potenti. Proin ut porta felis. Aliquam eu eros mollis, commodo
60 | dui vitae, iaculis purus. Phasellus fermentum malesuada justo vitae aliquam. Nam libero eros, vestibulum id volutpat
61 | vitae, fringilla sed turpis. Sed convallis volutpat pretium.
62 | Suspendisse potenti. Morbi ultricies rhoncus dui, ultricies condimentum tortor aliquam nec. Etiam in porttitor quam,
63 | a pellentesque ipsum. Sed viverra sem felis, vitae sollicitudin leo aliquet non. Pellentesque magna neque,
64 | sollicitudin ut dictum feugiat, molestie vitae lacus. Donec sit amet massa porta, tempor magna a, tristique
65 | odio. Vivamus vel magna elit. Cras non orci fermentum, feugiat purus sed, tempus sapien. Donec a purus id magna
66 | maximus porta. Ut feugiat, ex a efficitur rutrum, tortor leo rhoncus tortor, sed sollicitudin elit lacus non
67 | risus. Proin id metus fermentum, feugiat magna vel, cursus libero.
68 | Phasellus ultricies efficitur ipsum, eu tempor nisi auctor a. Aliquam neque lectus, rhoncus at arcu quis, vehicula
69 | auctor enim. Etiam lacinia elit non leo finibus, non porttitor lorem tincidunt. Suspendisse ac urna ut quam
70 | vehicula fringilla sed nunc. Nunc volutpat nisi vitae urna laoreet, eu facilisis ipsum facilisis. Aliquam
71 | maximus egestas risus. Aenean ut elit vel nulla gravida sagittis. Class aptent taciti sociosqu ad litora torquent
72 | per conubia nostra, per inceptos himenaeos.
73 |
74 | 1. Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n
75 | 2. Maecenas sodales rutrum est sed efficitur.\n
76 | 3. Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n
77 | 4. Nunc at placerat massa.\n
78 | 5. Maecenas sodales rutrum est sed efficitur.\n
79 | 6. Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n
80 | 7. Nunc at placerat massa.
81 |
82 |
83 | Short text Lorem ipsum dolor sit amet, consectetur adipiscing elit.
84 | Maecenas sodales rutrum est sed efficitur. Lorem ipsum dolor sit amet.
85 |
86 | This is\nentered\ntext example\nlorem ipsum\ndolor sit amet. \n\nNunc at placerat massa Maecenas\nsodales
87 | placerat massa. asdfasf Maecenas \nsodales rutrum \nest sed efficitur.
88 |
89 | ejej\ndee\nd\nd\nf\nf\nd\nd
90 |
91 | 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111S11111111111111111111111111111111111111111111111111111111111111E
92 | abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXBukaDong
93 |
94 | Read More
95 | Read Less
96 |
97 | This text is using bounce effect, and 800 millis duration on expanding, and anticipate overshoot effect, and 900 millis duration when collapsing.
98 | Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas sodales rutrum est sed efficitur. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
99 | Fusce eget ligula sed dolor accumsan tristique id vel turpis.
100 |
101 | This is justified text inter word text example. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris pretium mauris vel
102 | lacus vulputate, ac dictum velit tempus. Suspendisse potenti. Proin eget sem ullamcorper, faucibus orci vel,
103 | facilisis sem. Nullam in metus at eros mattis malesuada. Vestibulum id justo sed ex interdum ultrices. Vestibulum
104 | lobortis posuere felis, a dictum tortor. Etiam a gravida augue, at interdum lacus. Ut finibus metus orci, eget
105 | lacinia turpis imperdiet et. Donec in sagittis erat. Aenean egestas vulputate nunc vel pulvinar. Pellentesque
106 | habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Maecenas nec orci porta,
107 | finibus quam ut, fringilla sapien. Maecenas tristique justo turpis, non pretium ligula sagittis luctus.
108 | Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum
109 | scelerisque tristique hendrerit.
110 |
111 |
112 |
113 | 1\n2a\n3\n4
114 |
115 |
116 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright 2022 Mukhammad Erif Fanani
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/readMoreTextView/src/main/java/com/erif/readmoretextview/TextViewReadMore.java:
--------------------------------------------------------------------------------
1 | package com.erif.readmoretextview;
2 |
3 | import static java.lang.Math.max;
4 |
5 | import android.animation.Animator;
6 | import android.animation.AnimatorListenerAdapter;
7 | import android.animation.TimeInterpolator;
8 | import android.animation.ValueAnimator;
9 | import android.annotation.SuppressLint;
10 | import android.content.Context;
11 | import android.content.res.Resources;
12 | import android.content.res.TypedArray;
13 | import android.graphics.Canvas;
14 | import android.graphics.Color;
15 | import android.graphics.Typeface;
16 | import android.graphics.text.LineBreaker;
17 | import android.os.Build;
18 | import android.os.Handler;
19 | import android.os.Looper;
20 | import android.os.SystemClock;
21 | import android.text.Layout;
22 | import android.text.SpannableStringBuilder;
23 | import android.text.Spanned;
24 | import android.text.StaticLayout;
25 | import android.text.TextPaint;
26 | import android.text.TextUtils;
27 | import android.text.method.LinkMovementMethod;
28 | import android.text.style.ClickableSpan;
29 | import android.text.style.ForegroundColorSpan;
30 | import android.text.style.StyleSpan;
31 | import android.text.style.UnderlineSpan;
32 | import android.util.AttributeSet;
33 | import android.util.Log;
34 | import android.view.MotionEvent;
35 | import android.view.View;
36 | import android.view.ViewGroup;
37 | import android.view.animation.AccelerateInterpolator;
38 | import android.view.animation.AnticipateInterpolator;
39 | import android.view.animation.AnticipateOvershootInterpolator;
40 | import android.view.animation.BounceInterpolator;
41 | import android.view.animation.DecelerateInterpolator;
42 | import android.widget.TextView;
43 |
44 | import androidx.annotation.NonNull;
45 | import androidx.annotation.Nullable;
46 | import androidx.appcompat.widget.AppCompatTextView;
47 | import androidx.core.content.ContextCompat;
48 | import androidx.interpolator.view.animation.FastOutLinearInInterpolator;
49 | import androidx.interpolator.view.animation.FastOutSlowInInterpolator;
50 | import androidx.interpolator.view.animation.LinearOutSlowInInterpolator;
51 |
52 | public class TextViewReadMore extends AppCompatTextView {
53 |
54 | private static final String DEFAULT_EXPAND_TEXT = "Read More";
55 | private static final String DEFAULT_COLLAPSE_TEXT = "Close";
56 | private static final String DOTS_CODE = "…"; // u2026
57 | private static final String SPACE_CODE = "\u00A0";
58 |
59 | private static final int ELLIPSIS_TYPE_DOTS = 0;
60 | private static final int ELLIPSIS_TYPE_NONE = 1;
61 |
62 | private String text;
63 |
64 | private String expandText = DEFAULT_EXPAND_TEXT;
65 | private int expandTextColor;
66 | private int expandTextStyle = 0;
67 | private boolean expandTextUnderline = false;
68 |
69 | private String collapseText = DEFAULT_COLLAPSE_TEXT;
70 | private int collapseTextColor;
71 | private int collapseTextStyle = 0;
72 | private boolean collapseTextUnderline = false;
73 |
74 | private boolean collapsed;
75 | private boolean rebuild = true;
76 | private int lineWidth = 0;
77 | private int maxLines = 1;
78 |
79 | private int halfHeight = 0;
80 | private int fullHeight = 0;
81 | private boolean isAnimate = false;
82 | private boolean isEllipsized = false;
83 | private int durationExpand = 300;
84 | private int durationCollapse = 300;
85 | private ToggleListener toggleListener;
86 |
87 | private View.OnClickListener onClickExpand;
88 | private View.OnClickListener onClickCollapse;
89 | private int actionClickColor = 0;
90 | private int ellipsisType = ELLIPSIS_TYPE_DOTS;
91 |
92 | private SpannableStringBuilder spanCollapsed;
93 | private SpannableStringBuilder spanExpanded;
94 |
95 | private static long mLastClickTime = 0;
96 |
97 | private int interpolatorExpand = 0;
98 | private int interpolatorCollapse = 0;
99 |
100 | public TextViewReadMore(@NonNull Context context) {
101 | super(context);
102 | init(context, null, 0);
103 | }
104 |
105 | public TextViewReadMore(@NonNull Context context, @Nullable AttributeSet attrs) {
106 | super(context, attrs);
107 | init(context, attrs, 0);
108 | }
109 |
110 | public TextViewReadMore(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
111 | super(context, attrs, defStyleAttr);
112 | init(context, attrs, defStyleAttr);
113 | }
114 |
115 | private void init(Context context, AttributeSet attrs, int defStyleAttr) {
116 | Resources.Theme theme = context.getTheme();
117 | if (theme != null) {
118 | TypedArray typedArray = theme.obtainStyledAttributes(
119 | attrs, R.styleable.TextViewReadMore, defStyleAttr, 0
120 | );
121 | try {
122 | text = typedArray.getString(R.styleable.TextViewReadMore_android_text);
123 | int getMaxLines = typedArray.getInt(R.styleable.TextViewReadMore_readMoreMaxLines, maxLines);
124 | maxLines = max(getMaxLines, maxLines);
125 | collapsed = typedArray.getBoolean(R.styleable.TextViewReadMore_collapsed, true);
126 |
127 | String getExpandText = typedArray.getString(R.styleable.TextViewReadMore_expandText);
128 | expandText = TextUtils.isEmpty(getExpandText) ? DEFAULT_EXPAND_TEXT : getExpandText;
129 | expandTextColor = typedArray.getColor(R.styleable.TextViewReadMore_expandTextColor, Color.BLUE);
130 | expandTextStyle = typedArray.getInt(R.styleable.TextViewReadMore_expandTextStyle, 0);
131 | expandTextUnderline = typedArray.getBoolean(R.styleable.TextViewReadMore_expandTextUnderline, expandTextUnderline);
132 |
133 | String getCollapseText = typedArray.getString(R.styleable.TextViewReadMore_collapseText);
134 | collapseText = getCollapseText == null ? DEFAULT_COLLAPSE_TEXT : getCollapseText;
135 | collapseTextColor = typedArray.getColor(R.styleable.TextViewReadMore_collapseTextColor, Color.BLUE);
136 | collapseTextStyle = typedArray.getInt(R.styleable.TextViewReadMore_collapseTextStyle, 0);
137 | collapseTextUnderline = typedArray.getBoolean(R.styleable.TextViewReadMore_collapseTextUnderline, collapseTextUnderline);
138 |
139 | int defaultActionClickColor = ContextCompat.getColor(context, R.color.text_view_read_more_button_hover_color);
140 | actionClickColor = typedArray.getColor(R.styleable.TextViewReadMore_actionClickColor, defaultActionClickColor);
141 |
142 | int getDuration = typedArray.getInt(R.styleable.TextViewReadMore_duration, 300);
143 | durationExpand = typedArray.getInt(R.styleable.TextViewReadMore_durationExpand, getDuration);
144 | durationCollapse = typedArray.getInt(R.styleable.TextViewReadMore_durationCollapse, getDuration);
145 |
146 | ellipsisType = typedArray.getInt(R.styleable.TextViewReadMore_ellipsisType, ELLIPSIS_TYPE_DOTS);
147 |
148 | int interpolator = typedArray.getInt(R.styleable.TextViewReadMore_interpolator, 0);
149 | interpolatorExpand = typedArray.getInt(R.styleable.TextViewReadMore_interpolatorExpand, interpolator);
150 | interpolatorCollapse = typedArray.getInt(R.styleable.TextViewReadMore_interpolatorCollapse, interpolator);
151 |
152 | } finally {
153 | typedArray.recycle();
154 | }
155 | setHighlightColor(Color.TRANSPARENT);
156 | }
157 | }
158 |
159 | public void collapsed(boolean collapsed) {
160 | this.collapsed = collapsed;
161 | rebuild = true;
162 | }
163 |
164 | public boolean isCollapsed() {
165 | return this.collapsed;
166 | }
167 |
168 | @Override
169 | public void setText(CharSequence text, BufferType type) {
170 | if (isAnimate) {
171 | rebuild = false;
172 | } else {
173 | if (text instanceof Spanned) {
174 | rebuild = false;
175 | } else {
176 | if (text != null) {
177 | this.text = text.toString();
178 | } else {
179 | this.text = null;
180 | }
181 | rebuild = true;
182 | }
183 | }
184 | if (isEllipsized(text)) {
185 | if (spanExpanded != null && !collapsed) {
186 | super.setText(spanExpanded, type);
187 | } else if (spanCollapsed != null && collapsed) {
188 | super.setText(spanCollapsed, type);
189 | } else {
190 | super.setText(text, type);
191 | }
192 | } else {
193 | super.setText(text, type);
194 | }
195 | }
196 |
197 | @Override
198 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
199 | int givenWidth = MeasureSpec.getSize(widthMeasureSpec);
200 | int sidePadding = getCompoundPaddingStart() + getCompoundPaddingEnd();
201 | lineWidth = givenWidth - sidePadding;
202 | super.onMeasure(widthMeasureSpec, heightMeasureSpec);
203 | }
204 |
205 | @Override
206 | protected void onDraw(Canvas canvas) {
207 | super.onDraw(canvas);
208 | if (rebuild)
209 | buildSpan();
210 | }
211 |
212 | private void buildSpan() {
213 | if (!TextUtils.isEmpty(text)) {
214 | isEllipsized = isEllipsized(text);
215 | if (isEllipsized) {
216 | if (rebuild) {
217 | if (collapsed) {
218 | StaticLayout layoutDefault = getStaticLayoutCollapsed(text);
219 | int sumLineWidth = 0;
220 | /* Unused
221 | CharSequence lastLineLetter = null;
222 | int lastLineLetterCount = 0;
223 | */
224 | for (int i = 0; i < maxLines; i++) {
225 | int count = (int) layoutDefault.getLineWidth(i);
226 | /* Unused
227 | int start = layoutDefault.getLineStart(i);
228 | int end = layoutDefault.getLineEnd(i);
229 | lastLineLetter = text.subSequence(start, end);
230 | lastLineLetterCount = lastLineLetter.length();
231 | */
232 | sumLineWidth += count;
233 | }
234 |
235 | float expandActionWidth = getPaint().measureText(" " + expandText);
236 | float doubleExpandWith = expandActionWidth * 2;
237 | /* Unused
238 | if (lastLineLetterCount < 3) {
239 | if (lastLineLetter != null) {
240 | String lastChar = lastLineLetter.toString().replaceAll("\n", "");
241 | float lastLineLetterAdd = getPaint().measureText(lastChar);
242 | sumLineWidth += lastLineLetterAdd;
243 | }
244 | }
245 | */
246 |
247 | float truncatedTextWidth = sumLineWidth - expandActionWidth;
248 | if (sumLineWidth < doubleExpandWith) {
249 | truncatedTextWidth = sumLineWidth;
250 | }
251 |
252 | CharSequence truncatedText = TextUtils.ellipsize(text, getPaint(), truncatedTextWidth, TextUtils.TruncateAt.END);
253 | Log.d("Collapse", truncatedText.toString());
254 | String exp = expandText.replaceAll(" ", SPACE_CODE);
255 | String finalText = truncatedText.toString();
256 | if (ellipsisType == ELLIPSIS_TYPE_NONE)
257 | finalText = truncatedText.toString().replace(DOTS_CODE, "");
258 | String collapsedText = finalText + SPACE_CODE + exp;
259 | StaticLayout layout = getStaticLayoutCollapsed(collapsedText);
260 | spanCollapsed = spanCollapsed(collapsedText);
261 | if (spanCollapsed != null) {
262 | updateParam(layout.getHeight());
263 | setText(spanCollapsed);
264 | }
265 | spanExpanded = spanExpanded();
266 | } else {
267 | spanExpanded = spanExpanded();
268 | StaticLayout layout = getStaticLayout(spanExpanded.toString());
269 | updateParam(layout.getHeight());
270 | setText(spanExpanded);
271 | }
272 | if (isJustified()) {
273 | setOnTouchListener(onTouchEvent());
274 | } else {
275 | setMovementMethod(LinkMovementMethod.getInstance());
276 | }
277 | rebuild = false;
278 | }
279 | } else {
280 | rebuild = false;
281 | StaticLayout layout = getStaticLayout(text);
282 | post(() -> updateParam(layout.getHeight()));
283 | }
284 | }
285 | }
286 |
287 | private boolean isEllipsized(@Nullable CharSequence charSequence) {
288 | if (charSequence == null)
289 | return false;
290 | StaticLayout layout = getStaticLayout(charSequence.toString());
291 | return layout.getLineCount() > maxLines;
292 | }
293 |
294 | private boolean isEllipsized(@Nullable String text) {
295 | if (text == null)
296 | return false;
297 | StaticLayout layout = getStaticLayout(text);
298 | return layout.getLineCount() > maxLines;
299 | }
300 |
301 | private SpannableStringBuilder spanCollapsed(String text) {
302 | if (text == null)
303 | return null;
304 | SpannableStringBuilder span = new SpannableStringBuilder(text);
305 | int start = text.length() - expandText.length();
306 | int end = text.length();
307 | span.setSpan(
308 | new ForegroundColorSpan(expandTextColor), start,
309 | end, Spanned.SPAN_INCLUSIVE_EXCLUSIVE
310 | );
311 | if (expandTextStyle == 1) {
312 | boldText(span, start, end);
313 | } else if (expandTextStyle == 2) {
314 | italicText(span, start, end);
315 | } else if (expandTextStyle == 3) {
316 | boldText(span, start, end);
317 | italicText(span, start, end);
318 | }
319 | if (expandTextUnderline) {
320 | underlineText(span, start, end);
321 | }
322 | span.setSpan(new ClickableSpan() {
323 | @Override
324 | public void onClick(@NonNull View widget) {
325 | if (onClickExpand != null) {
326 | new Handler(Looper.getMainLooper()).postDelayed(
327 | () -> onClickExpand.onClick(widget), 100
328 | );
329 | }
330 | }
331 |
332 | @Override
333 | public void updateDrawState(@NonNull TextPaint ds) {
334 | super.updateDrawState(ds);
335 | if (!expandTextUnderline)
336 | ds.setUnderlineText(false);
337 | if (isPressed()) {
338 | ds.setColor(actionClickColor);
339 | } else {
340 | ds.setColor(expandTextColor);
341 | }
342 | invalidate();
343 | }
344 | }, start, end, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
345 | return span;
346 | }
347 |
348 | private SpannableStringBuilder spanExpanded() {
349 | String collapsedTextSpace = collapseText.replaceAll(" ", SPACE_CODE);
350 | String fullText = text + SPACE_CODE + collapsedTextSpace;
351 | spanExpanded = spanExpanded(fullText);
352 | return spanExpanded;
353 | }
354 |
355 | private SpannableStringBuilder spanExpanded(String text) {
356 | SpannableStringBuilder span = new SpannableStringBuilder(text);
357 | int start = text.length() - collapseText.length();
358 | int end = text.length();
359 | span.setSpan(
360 | new ForegroundColorSpan(collapseTextColor), start,
361 | end, Spanned.SPAN_INCLUSIVE_EXCLUSIVE
362 | );
363 | if (collapseTextStyle == 1) {
364 | boldText(span, start, end);
365 | } else if (collapseTextStyle == 2) {
366 | italicText(span, start, end);
367 | } else if (collapseTextStyle == 3) {
368 | boldText(span, start, end);
369 | italicText(span, start, end);
370 | }
371 | if (collapseTextUnderline) {
372 | underlineText(span, start, end);
373 | }
374 | span.setSpan(new ClickableSpan() {
375 | @Override
376 | public void onClick(@NonNull View widget) {
377 | if (!collapseText.isEmpty() && !collapseText.equals(" ")) {
378 | if (onClickCollapse != null) {
379 | new Handler(Looper.getMainLooper()).postDelayed(
380 | () -> onClickCollapse.onClick(widget), 100
381 | );
382 | }
383 | }
384 | }
385 |
386 | @Override
387 | public void updateDrawState(@NonNull TextPaint ds) {
388 | super.updateDrawState(ds);
389 | if (!collapseTextUnderline)
390 | ds.setUnderlineText(false);
391 | if (isPressed()) {
392 | ds.setColor(actionClickColor);
393 | } else {
394 | ds.setColor(collapseTextColor);
395 | }
396 | invalidate();
397 | }
398 | }, start, end, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
399 | return span;
400 | }
401 |
402 | @SuppressLint("RestrictedApi")
403 | public void toggle() {
404 | int limitDuration = collapsed ? durationExpand : durationCollapse;
405 | int limit = max(limitDuration, 1000);
406 | if (SystemClock.elapsedRealtime() - mLastClickTime <= limit) {
407 | return;
408 | }
409 | mLastClickTime = SystemClock.elapsedRealtime();
410 | setMovementMethod(null);
411 |
412 | if (collapsed) {
413 | String collapsedTextSpace = collapseText.replaceAll(" ", SPACE_CODE);
414 | String fullText = text+SPACE_CODE+collapsedTextSpace;
415 |
416 | StaticLayout layoutFull = getStaticLayout(fullText);
417 | fullHeight = layoutFull.getHeight() + getPaddingTop() + getPaddingBottom();
418 | } else {
419 | StaticLayout layoutCollapsed = getStaticLayoutCollapsed(text);
420 | halfHeight = layoutCollapsed.getHeight() + getPaddingTop() + getPaddingTop();
421 | }
422 | int end = collapsed ? fullHeight : halfHeight;
423 | ValueAnimator anim = ValueAnimator.ofInt(getHeight(), end);
424 | anim.setInterpolator(collapsed ? animationExpand() : animationCollapse());
425 | anim.setDuration(collapsed ? durationExpand : durationCollapse);
426 | ViewGroup.LayoutParams params = getLayoutParams();
427 | anim.addUpdateListener(animation -> {
428 | Object value = animation.getAnimatedValue();
429 | params.height = (int) value;
430 | setLayoutParams(params);
431 | });
432 | anim.addListener(new AnimatorListenerAdapter() {
433 | @Override
434 | public void onAnimationStart(Animator animation) {
435 | super.onAnimationStart(animation);
436 | isAnimate = true;
437 | if (collapsed) {
438 | collapsed = false;
439 | setText(spanExpanded);
440 | collapsed = true;
441 | }
442 | }
443 | @Override
444 | public void onAnimationEnd(Animator animation) {
445 | super.onAnimationEnd(animation);
446 | isAnimate = false;
447 | collapsed = !collapsed;
448 | rebuild = true;
449 | new Handler(Looper.getMainLooper()).postDelayed(() -> {
450 | if (toggleListener != null)
451 | toggleListener.onToggle(collapsed);
452 | }, 0);
453 | }
454 | });
455 | if (isEllipsized)
456 | anim.start();
457 | }
458 |
459 | public void setInterpolator(@InterpolatorType int interpolator) {
460 | this.interpolatorExpand = interpolator;
461 | this.interpolatorCollapse = interpolator;
462 | }
463 |
464 | public void setInterpolatorExpand(@InterpolatorType int interpolator) {
465 | this.interpolatorExpand = interpolator;
466 | }
467 |
468 | public void setInterpolatorCollapse(@InterpolatorType int interpolator) {
469 | this.interpolatorCollapse = interpolator;
470 | }
471 |
472 | private TimeInterpolator animationExpand() {
473 | return animation(interpolatorExpand);
474 | }
475 |
476 | private TimeInterpolator animationCollapse() {
477 | return animation(interpolatorCollapse);
478 | }
479 |
480 | private TimeInterpolator animation(int value) {
481 | return switch (value) {
482 | case 1 -> new AccelerateInterpolator();
483 | case 2 -> new AnticipateOvershootInterpolator();
484 | case 3 -> new AnticipateInterpolator();
485 | case 4 -> new BounceInterpolator();
486 | case 5 -> new FastOutLinearInInterpolator();
487 | case 6 -> new FastOutSlowInInterpolator();
488 | case 7 -> new LinearOutSlowInInterpolator();
489 | default -> new DecelerateInterpolator();
490 | };
491 | }
492 |
493 | private void italicText(SpannableStringBuilder builder, int start, int end) {
494 | builder.setSpan(new StyleSpan(Typeface.ITALIC),
495 | start, end, Spanned.SPAN_INCLUSIVE_EXCLUSIVE
496 | );
497 | }
498 |
499 | private void boldText(SpannableStringBuilder builder, int start, int end) {
500 | builder.setSpan(new StyleSpan(Typeface.BOLD),
501 | start, end, Spanned.SPAN_INCLUSIVE_EXCLUSIVE
502 | );
503 | }
504 |
505 | private void underlineText(SpannableStringBuilder builder, int start, int end) {
506 | builder.setSpan(new UnderlineSpan(),
507 | start, end, Spanned.SPAN_INCLUSIVE_EXCLUSIVE
508 | );
509 | }
510 |
511 | public void toggleListener(ToggleListener toggleListener) {
512 | this.toggleListener = toggleListener;
513 | }
514 | public void onClickExpand(View.OnClickListener onClickExpand) {
515 | this.onClickExpand = onClickExpand;
516 | }
517 | public void onClickCollapse(View.OnClickListener onClickCollapse) {
518 | this.onClickCollapse = onClickCollapse;
519 | }
520 |
521 | public void setDuration(long millis) {
522 | int value = (int) millis;
523 | this.durationExpand = value;
524 | this.durationCollapse = value;
525 | }
526 |
527 | public void setDuration(double seconds) {
528 | int value = (int) seconds * 1000;
529 | this.durationExpand = value;
530 | this.durationCollapse = value;
531 | }
532 |
533 | public void setDurationExpand(long millis) {
534 | this.durationExpand = (int) millis;
535 | }
536 |
537 | public void setDurationExpand(double seconds) {
538 | this.durationExpand = (int) seconds * 1000;
539 | }
540 |
541 | public void setDurationCollapse(long millis) {
542 | this.durationCollapse = (int) millis;
543 | }
544 |
545 | public void setDurationCollapse(double seconds) {
546 | this.durationCollapse = (int) seconds * 1000;
547 | }
548 |
549 | private String ellipsize(String text, int size) {
550 | if (text.isEmpty() || size <= 0) {
551 | return "";
552 | } else if (text.length() <= size) {
553 | return text;
554 | } else {
555 | return text.substring(0, max(size - 1, 0))+"...";
556 | }
557 | }
558 |
559 | /*
560 | Unused function
561 | private void debug(String message) {
562 | Log.d("TextViewReadMore", message);
563 | }
564 |
565 | private String textReplaceSpace() {
566 | return text.replaceAll(" ", SPACE_CODE);
567 | }
568 | */
569 |
570 | private void updateParam(int height) {
571 | ViewGroup.LayoutParams params = getLayoutParams();
572 | int paddings = getPaddingTop() + getPaddingBottom();
573 | params.height = height + paddings;
574 | setLayoutParams(params);
575 | }
576 |
577 | private StaticLayout getStaticLayout(@Nullable String source) {
578 | String mSource = source == null ? "" : source;
579 | StaticLayout layout;
580 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
581 | layout = StaticLayout.Builder
582 | .obtain(mSource, 0, mSource.length(), getPaint(), lineWidth)
583 | .setLineSpacing(getLineSpacingExtra(), getLineSpacingMultiplier())
584 | .setIncludePad(getIncludeFontPadding())
585 | .setAlignment(Layout.Alignment.ALIGN_NORMAL)
586 | .build();
587 | /* Unused
588 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
589 | builder.setJustificationMode(getJustificationMode());
590 | }
591 | layout = builder.build();*/
592 | } else {
593 | layout = new StaticLayout(mSource, getPaint(), lineWidth, Layout.Alignment.ALIGN_NORMAL,
594 | getLineSpacingMultiplier(), getLineSpacingExtra(), getIncludeFontPadding()
595 | );
596 | }
597 | return layout;
598 | }
599 |
600 | private StaticLayout getStaticLayoutCollapsed(@Nullable String source) {
601 | String mSource = source == null ? "" : source;
602 | StaticLayout layout;
603 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
604 | layout = StaticLayout.Builder
605 | .obtain(mSource, 0, mSource.length(), getPaint(), lineWidth)
606 | .setMaxLines(maxLines)
607 | .setEllipsize(TextUtils.TruncateAt.END)
608 | .setLineSpacing(getLineSpacingExtra(), getLineSpacingMultiplier())
609 | .setIncludePad(getIncludeFontPadding())
610 | .setAlignment(Layout.Alignment.ALIGN_NORMAL)
611 | .build();
612 | /* Unused
613 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
614 | builder.setJustificationMode(getJustificationMode());
615 | }
616 | layout = builder.build();*/
617 | } else {
618 | int maxLength = mSource.length();
619 | do {
620 | layout = new StaticLayout(
621 | ellipsize(mSource, maxLength), getPaint(), lineWidth, Layout.Alignment.ALIGN_NORMAL,
622 | getLineSpacingMultiplier(), getLineSpacingExtra(), getIncludeFontPadding()
623 | );
624 | maxLength -= 10;
625 | } while (layout.getLineCount() > 2);
626 | }
627 | return layout;
628 | }
629 |
630 | private boolean isJustified() {
631 | boolean isJustified = false;
632 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
633 | if (getJustificationMode() == LineBreaker.JUSTIFICATION_MODE_INTER_WORD) {
634 | isJustified = true;
635 | }
636 | }
637 | return isJustified;
638 | }
639 |
640 | @SuppressLint("ClickableViewAccessibility")
641 | private View.OnTouchListener onTouchEvent() {
642 | return (v, event) -> {
643 | if(v instanceof TextView tv){
644 | if(event.getAction() == MotionEvent.ACTION_UP){
645 | int x = (int) (event.getX() - tv.getTotalPaddingLeft() + tv.getScrollX());
646 | int y = (int) (event.getY() - tv.getTotalPaddingTop() + tv.getScrollY());
647 | int line = tv.getLayout().getLineForVertical(y);
648 | int offset = tv.getLayout().getOffsetForHorizontal(line, x);
649 | if(tv.getText() instanceof Spanned spannable) {
650 | ClickableSpan[] links = spannable.getSpans(offset, offset, ClickableSpan.class);
651 | if (links.length > 0) {
652 | links[0].onClick(tv);
653 | }
654 | }
655 | }
656 | }
657 | return true;
658 | };
659 | }
660 |
661 | }
662 |
--------------------------------------------------------------------------------