├── checkabletextview ├── .gitignore ├── src │ └── main │ │ ├── res │ │ ├── values │ │ │ ├── strings.xml │ │ │ ├── colors.xml │ │ │ └── attrs.xml │ │ ├── drawable │ │ │ ├── fill_circle.xml │ │ │ └── ic_check_circle_vector.xml │ │ └── layout │ │ │ └── layout_checkable_text.xml │ │ ├── AndroidManifest.xml │ │ └── java │ │ └── com │ │ └── devzone │ │ └── checkabletextview │ │ ├── CheckedListener.kt │ │ ├── utils │ │ ├── AnimatorFactory.kt │ │ └── ViewUtils.kt │ │ └── CheckableTextView.kt ├── proguard-rules.pro └── build.gradle ├── app ├── .gitignore ├── src │ └── main │ │ ├── res │ │ ├── values │ │ │ ├── strings.xml │ │ │ ├── colors.xml │ │ │ └── styles.xml │ │ ├── font │ │ │ └── poppins_light.ttf │ │ ├── mipmap-hdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ ├── mipmap-anydpi-v26 │ │ │ ├── ic_launcher.xml │ │ │ └── ic_launcher_round.xml │ │ ├── drawable │ │ │ ├── ic_cancel_custom_vector.xml │ │ │ └── ic_launcher_background.xml │ │ ├── drawable-v24 │ │ │ └── ic_launcher_foreground.xml │ │ └── layout │ │ │ └── activity_main.xml │ │ ├── AndroidManifest.xml │ │ └── java │ │ └── com │ │ └── devzone │ │ └── ctv_sample │ │ └── MainActivity.kt ├── proguard-rules.pro └── build.gradle ├── settings.gradle ├── logo.png ├── sample.gif ├── fall_down.gif ├── overshoot.gif ├── sample_01.gif ├── sample_slowmo.gif ├── new_ripple_effect.gif ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .gitignore ├── LICENSE ├── gradle.properties ├── CONTRIBUTING.md ├── gradlew.bat ├── gradlew └── README.md /checkabletextview/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | *.iml 3 | /release 4 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app', ':checkabletextview' 2 | -------------------------------------------------------------------------------- /logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JDevZone/CheckableTextView/HEAD/logo.png -------------------------------------------------------------------------------- /sample.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JDevZone/CheckableTextView/HEAD/sample.gif -------------------------------------------------------------------------------- /fall_down.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JDevZone/CheckableTextView/HEAD/fall_down.gif -------------------------------------------------------------------------------- /overshoot.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JDevZone/CheckableTextView/HEAD/overshoot.gif -------------------------------------------------------------------------------- /sample_01.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JDevZone/CheckableTextView/HEAD/sample_01.gif -------------------------------------------------------------------------------- /sample_slowmo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JDevZone/CheckableTextView/HEAD/sample_slowmo.gif -------------------------------------------------------------------------------- /new_ripple_effect.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JDevZone/CheckableTextView/HEAD/new_ripple_effect.gif -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | CheckableTextView 3 | 4 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JDevZone/CheckableTextView/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /app/src/main/res/font/poppins_light.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JDevZone/CheckableTextView/HEAD/app/src/main/res/font/poppins_light.ttf -------------------------------------------------------------------------------- /checkabletextview/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | CheckableTextView 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JDevZone/CheckableTextView/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JDevZone/CheckableTextView/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JDevZone/CheckableTextView/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JDevZone/CheckableTextView/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JDevZone/CheckableTextView/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JDevZone/CheckableTextView/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JDevZone/CheckableTextView/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JDevZone/CheckableTextView/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JDevZone/CheckableTextView/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JDevZone/CheckableTextView/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /checkabletextview/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | -------------------------------------------------------------------------------- /checkabletextview/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #464646 4 | 5 | -------------------------------------------------------------------------------- /checkabletextview/src/main/java/com/devzone/checkabletextview/CheckedListener.kt: -------------------------------------------------------------------------------- 1 | package com.devzone.checkabletextview 2 | 3 | import android.view.View 4 | 5 | interface CheckedListener { 6 | fun onCheckChange(view: View, isChecked: Boolean) 7 | } -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Sat May 15 11:56:00 IST 2021 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip 7 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | .idea 4 | /local.properties 5 | /.idea/caches 6 | /.idea/libraries 7 | /.idea/modules.xml 8 | /.idea/workspace.xml 9 | /.idea/navEditor.xml 10 | /.idea/assetWizardSettings.xml 11 | .DS_Store 12 | /build 13 | /captures 14 | /.idea 15 | .externalNativeBuild 16 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #008577 4 | #00574B 5 | #D81B60 6 | #FF5722 7 | 8 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /checkabletextview/src/main/res/drawable/fill_circle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /checkabletextview/src/main/res/drawable/ic_check_circle_vector.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_cancel_custom_vector.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /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. 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 22 | -------------------------------------------------------------------------------- /checkabletextview/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. 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 22 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | apply plugin: 'kotlin-android' 4 | 5 | apply plugin: 'kotlin-android-extensions' 6 | 7 | android { 8 | compileSdkVersion 30 9 | defaultConfig { 10 | applicationId "com.devzone.checkabletextview" 11 | minSdkVersion 17 12 | targetSdkVersion 30 13 | versionCode 1 14 | versionName "1.0" 15 | 16 | } 17 | buildTypes { 18 | release { 19 | minifyEnabled false 20 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 21 | } 22 | } 23 | } 24 | 25 | dependencies { 26 | implementation fileTree(dir: 'libs', include: ['*.jar']) 27 | implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" 28 | implementation 'com.google.android.material:material:1.3.0' 29 | implementation 'androidx.appcompat:appcompat:1.2.0' 30 | implementation 'androidx.core:core-ktx:1.3.2' 31 | implementation project(path: ':checkabletextview') 32 | 33 | } 34 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 JDevZone 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /checkabletextview/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | apply plugin: 'kotlin-android' 3 | apply plugin: 'kotlin-android-extensions' 4 | apply plugin: 'com.github.dcendents.android-maven' 5 | 6 | group='com.github.JDevZone' 7 | 8 | android { 9 | compileSdkVersion 30 10 | 11 | 12 | defaultConfig { 13 | minSdkVersion 17 14 | targetSdkVersion 30 15 | versionCode 1 16 | versionName "1.0" 17 | vectorDrawables.useSupportLibrary = true 18 | 19 | } 20 | 21 | buildTypes { 22 | release { 23 | minifyEnabled false 24 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 25 | } 26 | } 27 | 28 | } 29 | 30 | dependencies { 31 | implementation fileTree(dir: 'libs', include: ['*.jar']) 32 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" 33 | implementation 'androidx.appcompat:appcompat:1.2.0' 34 | implementation "androidx.core:core-ktx:1.3.2" 35 | implementation 'androidx.vectordrawable:vectordrawable:1.2.0-alpha02' 36 | 37 | } 38 | repositories { 39 | mavenCentral() 40 | } 41 | -------------------------------------------------------------------------------- /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=-Xmx1536m 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 | # Automatically convert third-party libraries to use AndroidX 19 | android.enableJetifier=true 20 | # Kotlin code style for this project: "official" or "obsolete": 21 | kotlin.code.style=official 22 | -------------------------------------------------------------------------------- /checkabletextview/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 | -------------------------------------------------------------------------------- /checkabletextview/src/main/res/layout/layout_checkable_text.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 21 | 22 | 37 | 38 | 39 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/java/com/devzone/ctv_sample/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package com.devzone.ctv_sample 2 | 3 | import android.graphics.Color 4 | import android.os.Bundle 5 | import android.view.View 6 | import android.view.animation.AnticipateOvershootInterpolator 7 | import android.view.animation.BounceInterpolator 8 | import android.view.animation.LinearInterpolator 9 | import androidx.appcompat.app.AppCompatActivity 10 | import com.devzone.checkabletextview.CheckableTextView.Companion.SCALE 11 | import com.devzone.checkabletextview.CheckableTextView.Companion.TRANSLATE 12 | import com.devzone.checkabletextview.CheckedListener 13 | import kotlinx.android.synthetic.main.activity_main.* 14 | 15 | 16 | class MainActivity : AppCompatActivity(), CheckedListener { 17 | override fun onCreate(savedInstanceState: Bundle?) { 18 | super.onCreate(savedInstanceState) 19 | setContentView(R.layout.activity_main) 20 | 21 | checkedTV.setOnCheckChangeListener { _, isChecked -> 22 | stateTV.text = if (isChecked) "Checked" else "Unchecked" 23 | } 24 | checkedSecondTV.setOnCheckChangeListener(::checkHandler) // function as parameter 25 | checkedThirdTV.setOnCheckChangeListener(this@MainActivity) 26 | 27 | 28 | checkedTV.animInterpolator = AnticipateOvershootInterpolator() // setting custom interpolator 29 | checkedSecondTV.animInterpolator = LinearInterpolator() 30 | checkedThirdTV.animInterpolator = BounceInterpolator() 31 | 32 | checkedThirdTV.setAnimDuration(1000) 33 | checkedThirdTV.setRippleTint(Color.parseColor("#ff9900")) 34 | checkedSecondTV.setAnimDuration(1000) 35 | } 36 | 37 | private fun checkHandler(view: View, isChecked: Boolean) { 38 | 39 | when (view.id) { 40 | R.id.checkedSecondTV -> stateSecondTV.text = if (isChecked) "Checked" else "Unchecked" 41 | } 42 | } 43 | 44 | override fun onCheckChange(view: View, isChecked: Boolean) { //lagacy type listener callback 45 | checkedSecondTV.setAnimStyle(if(isChecked)TRANSLATE else SCALE) 46 | when (view.id) { 47 | R.id.checkedThirdTV -> stateThirdTV.text = if (isChecked) "Checked" else "Unchecked" 48 | } 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to Checkable TextView 2 | We love your input! We want to make contributing to this project as easy and transparent as possible, whether it's: 3 | 4 | - Reporting a bug 5 | - Discussing the current state of the code 6 | - Submitting a fix 7 | - Proposing new features 8 | - Becoming a maintainer 9 | 10 | ## We Develop with Github 11 | We use github to host code, to track issues and feature requests, as well as accept pull requests. 12 | 13 | ## We Use [Github Flow](https://guides.github.com/introduction/flow/index.html), So All Code Changes Happen Through Pull Requests 14 | Pull requests are the best way to propose changes to the codebase (we use [Github Flow](https://guides.github.com/introduction/flow/index.html)). We actively welcome your pull requests: 15 | 16 | 1. Fork the repo and create your branch from `master`. 17 | 2. If you've added code that should be tested, add tests. 18 | 3. If you've changed APIs, update the documentation. 19 | 4. Ensure the test suite passes. 20 | 5. Make sure your code lints. 21 | 6. Issue that pull request! 22 | 23 | ## Any contributions you make will be under the MIT Software License 24 | In short, when you submit code changes, your submissions are understood to be under the same [MIT License](http://choosealicense.com/licenses/mit/) that covers the project. Feel free to contact the maintainers if that's a concern. 25 | 26 | ## Write bug reports with detail, background, and sample code 27 | 28 | **Great Bug Reports** tend to have: 29 | 30 | - A quick summary and/or background 31 | - Steps to reproduce 32 | - Be specific! 33 | - Give sample code if you can. 34 | - What you expected would happen 35 | - What actually happens 36 | - Notes (possibly including why you think this might be happening, or stuff you tried that didn't work) 37 | 38 | People *love* thorough bug reports. I'm not even kidding. 39 | 40 | ## Use a Consistent Coding Style 41 | 42 | - Use consistent coding style for uniform coding standard and readibility. 43 | 44 | ## License 45 | By contributing, you agree that your contributions will be licensed under its MIT License. 46 | 47 | ## References 48 | This document was adapted from the open-source contribution guidelines template [Good-CONTRIBUTING](https://gist.github.com/PurpleBooth/b24679402957c63ec426) 49 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /checkabletextview/src/main/java/com/devzone/checkabletextview/utils/AnimatorFactory.kt: -------------------------------------------------------------------------------- 1 | package com.devzone.checkabletextview.utils 2 | 3 | import android.view.View 4 | import android.view.ViewPropertyAnimator 5 | import com.devzone.checkabletextview.CheckableTextView 6 | 7 | class AnimatorFactory { 8 | companion object { 9 | 10 | fun getAnimator(animateStyle: Int, view: View, show: Boolean, duration: Long): ViewPropertyAnimator { 11 | return when (animateStyle) { 12 | CheckableTextView.SCALE -> getScaleAnimator(view, show, duration) 13 | CheckableTextView.TRANSLATE -> getTranslateAnimator(view, show, duration) 14 | CheckableTextView.FALL_DOWN -> getFallDownAnimator(view, show, duration) 15 | else -> getScaleAnimator(view, show, duration) 16 | } 17 | 18 | } 19 | 20 | private fun getScaleAnimator(view: View, show: Boolean, animDuration: Long): ViewPropertyAnimator { 21 | //resetting view to initial state for this animation (if In case user sets new animation on the fly) 22 | view.translationX = CheckableTextView.MIN_VALUE 23 | view.translationY = CheckableTextView.MIN_VALUE 24 | 25 | val scale = if (show) CheckableTextView.MAX_SCALE else CheckableTextView.MIN_VALUE 26 | val rotation = if (show) CheckableTextView.MIN_VALUE else -CheckableTextView.MAX_ROTATION 27 | return view.animate().setStartDelay(20).scaleX(scale).scaleY(scale).rotation(rotation) 28 | .setDuration(animDuration) 29 | } 30 | 31 | private fun getTranslateAnimator(view: View, show: Boolean, animDuration: Long): ViewPropertyAnimator { 32 | view.scaleX = CheckableTextView.MAX_SCALE 33 | view.scaleY = CheckableTextView.MAX_SCALE 34 | view.translationY = CheckableTextView.MIN_VALUE 35 | 36 | val translate = if (show) CheckableTextView.MIN_VALUE else (view.width.toFloat() + view.width / 2) 37 | val rotation = if (show) CheckableTextView.MIN_VALUE else CheckableTextView.MAX_ROTATION 38 | return view.animate().setStartDelay(20).translationX(translate).rotation(rotation) 39 | .setDuration(animDuration) 40 | 41 | } 42 | 43 | private fun getFallDownAnimator(view: View, show: Boolean, animDuration: Long): ViewPropertyAnimator { 44 | view.scaleX = CheckableTextView.MAX_SCALE 45 | view.scaleY = CheckableTextView.MAX_SCALE 46 | view.rotation = CheckableTextView.MIN_VALUE 47 | 48 | val trValue = (view.height.toFloat() + view.height / 2) 49 | if (show) view.translationY = -trValue 50 | val translate = if (show) CheckableTextView.MIN_VALUE else trValue 51 | return view.animate().setStartDelay(20).translationY(translate) 52 | .setDuration(animDuration) 53 | } 54 | 55 | } 56 | } -------------------------------------------------------------------------------- /checkabletextview/src/main/java/com/devzone/checkabletextview/utils/ViewUtils.kt: -------------------------------------------------------------------------------- 1 | package com.devzone.checkabletextview.utils 2 | 3 | import android.content.Context 4 | import android.os.Build 5 | import android.util.TypedValue 6 | import android.view.View 7 | import com.devzone.checkabletextview.CheckableTextView 8 | 9 | class ViewUtils { 10 | companion object{ 11 | fun getThemeAccentColor(context: Context): String { 12 | return try { 13 | val colorAttr: Int = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { 14 | android.R.attr.colorAccent 15 | } else { 16 | //Get colorAccent defined for AppCompat 17 | context.resources.getIdentifier("colorAccent", "attr", context.packageName) 18 | } 19 | val outValue = TypedValue() 20 | context.theme.resolveAttribute(colorAttr, outValue, true) 21 | String.format("#%06X", 0xFFFFFF and outValue.data) 22 | } catch (e: Exception) { 23 | "#00FFFFFF" 24 | } 25 | } 26 | 27 | fun getRippleDrawable(context: Context): Int { 28 | val outValue = TypedValue() 29 | context.theme.resolveAttribute(android.R.attr.selectableItemBackground, outValue, true) 30 | return outValue.resourceId 31 | } 32 | 33 | fun resetView(animateStyle:Int,view: View, show: Boolean) { 34 | view.clearAnimation() 35 | when (animateStyle) { 36 | CheckableTextView.SCALE -> { 37 | view.translationX = CheckableTextView.MIN_VALUE 38 | view.translationY = CheckableTextView.MIN_VALUE 39 | view.rotation = if (show) CheckableTextView.MIN_VALUE else -CheckableTextView.MAX_ROTATION 40 | view.scaleX = if (show) CheckableTextView.MAX_SCALE else CheckableTextView.MIN_VALUE 41 | view.scaleY = if (show) CheckableTextView.MAX_SCALE else CheckableTextView.MIN_VALUE 42 | } 43 | CheckableTextView.TRANSLATE -> { 44 | view.scaleX = CheckableTextView.MAX_SCALE 45 | view.scaleY = CheckableTextView.MAX_SCALE 46 | view.rotation = if (show) CheckableTextView.MIN_VALUE else CheckableTextView.MAX_ROTATION 47 | view.translationY = CheckableTextView.MIN_VALUE 48 | view.translationX = if (show) CheckableTextView.MIN_VALUE else view.width.toFloat() + view.width / 2 49 | 50 | } 51 | CheckableTextView.FALL_DOWN -> { 52 | view.scaleX = CheckableTextView.MAX_SCALE 53 | view.scaleY = CheckableTextView.MAX_SCALE 54 | view.rotation = CheckableTextView.MIN_VALUE 55 | view.translationX = CheckableTextView.MIN_VALUE 56 | view.translationY = if (show) CheckableTextView.MIN_VALUE else view.height.toFloat() + view.height / 2 57 | } 58 | } 59 | 60 | } 61 | 62 | } 63 | } 64 | 65 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 25 | 26 | 27 | 37 | 38 | 44 | 45 | 55 | 56 | 57 | 58 | 68 | 69 | 70 | 82 | 83 | 84 | 94 | 95 | 96 | 97 | 98 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 10 | 12 | 14 | 16 | 18 | 20 | 22 | 24 | 26 | 28 | 30 | 32 | 34 | 36 | 38 | 40 | 42 | 44 | 46 | 48 | 50 | 52 | 54 | 56 | 58 | 60 | 62 | 64 | 66 | 68 | 70 | 72 | 74 | 75 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |
2 | 3 |
4 | 5 |

CheckableTextView

6 | 7 | 8 | -------------- 9 | 10 | 11 | 12 |

Checkable TextView [KOTLIN]

13 | 14 |

:zap:A simple and flexible Checked TextView or Checkable TextView written in Kotlin:zap:

15 | 16 | ------------------ 17 | 18 | 19 | [![](https://jitpack.io/v/JDevZone/CheckableTextView.svg)](https://jitpack.io/#JDevZone/CheckableTextView) 20 | [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-Checkable%20TextView-orange.svg?style=flat&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAMAAACdt4HsAAABRFBMVEUAAAAA//8AqqoAv79q6tVi69ht7dtm3cwQv59w389L4cNV1cZr5Ndm5tlt585o6NFq6tVm4NYJwadh3NNm5tUIv6dd4NFs6NFq59Rr49Vq5tVC1sFC1cFT28lr5tMJwaZr5dRp5tNq5NJQ28lq5dNQ3Mtq5NJp5NMJwqhr5tNr5tRQ28tS28kKwaZq5tMKwqdr5dRR3MlS2spr5NRR28pp5dNR28lq5NMJwaZp5dMLwacKwKdq5tJp5NNq5tNq5dJR28pQ3Mpq5NNq5dNq5dMKwahq5dNp5dNq5dNZ3s0KwqcKwadq5NMKwqdr5dNq5dNq5tNq5dNq5dNe4c5q5tNR28pf4c5q5dNR28pq5dNr5dNg4tBf4c9n5dIKwacLwagQw6oRxKs30rw40rxQ28dR28pR3Mhg4dBq5dOk7%2bTG9e7///%2bbCjGeAAAAXnRSTlMAAQMEDA0ODxAQERITFBUWGBkdHR4gISE1Nzw%2bQkdRVlhcYGNjZmdobG5wf4CEhIWImJmZmpudo6SnqaurrLW3urvAw8vMz9DR1tzd3eDh4%2bbo6u/w8fHx8vL5/f7%2bnPjfBgAAAWNJREFUeNrt0kdXQjEQBeB5YsGu2FFArNgbNgQRFQtgQ1RECTZ01P%2b/N3IgyCF5yTu4zLfL4t7M4oKmaVUMj88OUnafxwC%2bJUJiDpBwxAhZAL4oISTukOTjhJCo%2bILKGzqdbq/X7eyo/F98Qd0Woc764Ff7dCiJRcngVNuf/I4NpA1DoQxWyAQH5XnWMBJGjt1hljdvyL1mkSv7kmN5IVvg%2bR2F3p4CLC/Sc40mbvtBojuBphJdYKrhBCWO6sHMJkptgwkvKhgFocZLVHDVDCLLqGQRBJpSqOROdMIsMp8Uoug9Iyg4RuabQhS9D4FrAFULsBd4JtQLxoBnHcu%2bKBS/14DnAJXtA88FKjsHnntUloIywzVZ9Pih7KGUcRngz9dkBdK1FdxApLaCPWidXy06taCUmWsB7R%2bMU2yRylwGy%2bYpoPxWF0jlKVaQtrjAqoKIxQWygg0KKLZIObbAQlbTtIIfYmMHMd8lK1oAAAAASUVORK5CYII=)](https://android-arsenal.com/details/1/7770) 21 | [![GitHub license](https://img.shields.io/github/license/JDevZone/CheckableTextView.svg?style=flat)](https://github.com/JDevZone/CheckableTextView/blob/master/LICENSE) 22 | ![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/JDevZone/CheckableTextView) 23 | ![Version](https://img.shields.io/github/v/tag/JDevZone/CheckableTextView.svg?sort=semver&label=Latest-Version) 24 | 25 | 26 | --------------------------- 27 | ### What's New 28 | 29 | | Animation | Demo | 30 | | --- | :---: | 31 | |

New Ripple Like Fill Effect

| | 32 | |

Normal
(duration = 250 ms)

| | 33 | |

Custom Duration
(duration = 2000 ms)

| | 34 | 35 | > Sorry for flicker in slow motion video demo . You know android studio screen recorder sucks sometimes :sweat_smile: 36 | 37 | ### Custom Interpolators 38 | > custom interpolator support added 39 | 40 | | Interpolator | Demo | 41 | | --- | :---: | 42 | |

BounceInterpolator
with fall down animation

| | 43 | |

AnticipateOvershootInterpolator
with translate animation

| | 44 | 45 |

46 | --------------------------- 47 | ### Installation 48 | 49 | 1. Add it in your root build.gradle at the end of repositories: 50 | ```groovy 51 | allprojects { 52 | repositories { 53 | ... 54 | maven { url 'https://jitpack.io' } 55 | } 56 | } 57 | ``` 58 | 59 | 60 | 2. Add the dependency in app gradle 61 | 62 | ```groovy 63 | dependencies { 64 | implementation 'com.github.JDevZone:CheckableTextView:{latest_version}' 65 | } 66 | ``` 67 | ### Basic usage 68 | 69 | ```xml 70 | 78 | ``` 79 | ### Change State Programatically 80 | 81 | You can change checked state as follows : 82 | ```kotlin 83 | checkedTV.setChecked(isChecked) 84 | ``` 85 | Default value `shouldNotifyListeners` is false 86 | 87 | ***or*** 88 | 89 | ```kotlin 90 | checkedTV.setChecked(isChecked,shouldNotifyListeners) 91 | ``` 92 | First Boolean parameter `isChecked` sets the current state 93 | Second Boolean parameter `shouldNotifyListeners` determines 94 | if `onCheckChange` method should be called or not. 95 | 96 | ### Get Current State 97 | ```kotlin 98 | checkedTV.isChecked() 99 | ``` 100 | No Fancy enums, Just true for checked state and false for unchecked is returned 101 | 102 | ### Listen State Changes 103 | 104 | You can listen to state changes by registering a listener like as follows : 105 | ```kotlin 106 | checkedTV.setOnCheckChangeListener() 107 | ``` 108 | and get callback in implemented method : 109 | ```kotlin 110 | override fun onCheckChange(view: View, isChecked: Boolean) { 111 | // checkedTV returned as view 112 | // isChecked current state of the view 113 | } 114 | ``` 115 | ### Set Custom Interpolator 116 | 117 | ```kotlin 118 | checkedTV.setAnimInterpolator(BounceInterpolator()) 119 | ``` 120 | ### Experimental 121 | 122 | ```kotlin 123 | checkedTV.setClickEnabled(isClickable: Boolean) 124 | ``` 125 | Pass `isClickable` true for enable and false for disable clicks 126 | 127 | > currently restricted to `RestrictTo.Scope.LIBRARY` 128 | > you can use it simply Suppressing Lint Warnings (if have any) as `@SuppressLint("RestrictedApi")` 129 | 130 | ### Customisation 131 | 132 | Here are the attributes you can specify through XML or related setters: 133 | * `ctv_Text` - Set text. 134 | * `ctv_TextSize` - Set text size. 135 | * `ctv_TextColor` - Set text color. 136 | * `ctv_TextStyle` - Set text style. 137 | * `ctv_Icon` - Set custom icon. 138 | * `ctv_IconTint` - Set icon tint. 139 | * `ctv_IconChecked` - Set TextView (`CheckableTextView`) state checked. 140 | * `ctv_TextGravity` - Set text gravity. 141 | * `ctv_AnimType` - Set check animation type currently three available (`scale`,`translate` and `fall_down`). 142 | * `ctv_AnimDuration` - Set duration for check animation. 143 | * `ctv_AnimFirstTime` - Animate `CheckableTextView` for very first time. 144 | * `ctv_RippleAlpha` - Set Alpha (Transparency) value for ripple like fill effect 145 | * `ctv_RippleTint` - Set color value for ripple like fill effect 146 | * `ctv_RippleFillEnabled` - Sets if ripple like fill effect is enabled or not 147 | 148 | 149 | ### 📄 License 150 | 151 | Checkable TextView is released under the MIT license. 152 | See [LICENSE](./LICENSE) for details. 153 | 154 | 155 | 156 | -------------------------------------------------------------------------------- /checkabletextview/src/main/java/com/devzone/checkabletextview/CheckableTextView.kt: -------------------------------------------------------------------------------- 1 | package com.devzone.checkabletextview 2 | 3 | import android.animation.TimeInterpolator 4 | import android.content.Context 5 | import android.content.res.ColorStateList 6 | import android.content.res.TypedArray 7 | import android.graphics.Color 8 | import android.graphics.drawable.ColorDrawable 9 | import android.os.Build 10 | import android.util.AttributeSet 11 | import android.util.TypedValue 12 | import android.view.Gravity 13 | import android.view.LayoutInflater 14 | import android.view.View 15 | import android.view.ViewTreeObserver.OnGlobalLayoutListener 16 | import android.view.animation.AccelerateInterpolator 17 | import android.view.animation.LinearInterpolator 18 | import android.widget.RelativeLayout 19 | import androidx.annotation.* 20 | import androidx.appcompat.app.AppCompatDelegate 21 | import androidx.core.content.ContextCompat 22 | import androidx.core.graphics.ColorUtils 23 | import androidx.core.view.ViewCompat 24 | import com.devzone.checkabletextview.utils.AnimatorFactory.Companion.getAnimator 25 | import com.devzone.checkabletextview.utils.ViewUtils.Companion.getRippleDrawable 26 | import com.devzone.checkabletextview.utils.ViewUtils.Companion.getThemeAccentColor 27 | import com.devzone.checkabletextview.utils.ViewUtils.Companion.resetView 28 | import kotlinx.android.synthetic.main.layout_checkable_text.view.* 29 | 30 | class CheckableTextView : RelativeLayout { 31 | 32 | companion object { 33 | const val SCALE = 0 34 | const val TRANSLATE = 1 35 | const val FALL_DOWN = 2 36 | 37 | //-------------------------------------------------------------------------------// 38 | const val MIN_VALUE = 0f //(initial values for scale, translate etc.) 39 | const val MAX_SCALE = 1f //(max values for scale) 40 | const val MAX_ROTATION = 360f //(max values for rotation) 41 | } 42 | 43 | 44 | private var rippleTint: Int = Color.LTGRAY 45 | private var rippleAlpha: Int = 33 46 | private val defaultAnimFirstTime = true 47 | private val defaultResValue: Int = 0 48 | private val defaultAnimDuration: Long = 300 49 | private val defaultAnimateStyle = SCALE 50 | private val defaultCheckState = true 51 | private val defaultTextColor = android.R.color.black 52 | private val defaultCheckIcon = R.drawable.ic_check_circle_vector 53 | 54 | //initialise with default values 55 | private var checkIcon = defaultCheckIcon 56 | var animInterpolator: TimeInterpolator = LinearInterpolator() 57 | var animateFirstTime = defaultAnimFirstTime 58 | 59 | var isRippleFillEnabled = false 60 | private set 61 | 62 | var isChecked = defaultCheckState 63 | private set 64 | var animDuration = defaultAnimDuration 65 | private set 66 | var animateStyle = defaultAnimateStyle 67 | private set 68 | 69 | // check change listeners 70 | private var listener: CheckedListener? = 71 | null //Legacy type callback listener using interface (Both java & kotlin) 72 | 73 | /** 74 | * [Function],[Function2] (for two variables) 75 | * kotlin.jvm.functions.Function2() can be used with java code but requires Kotlin setup in project 76 | */ 77 | private var listenerNew: ((v: View, isChecked: Boolean) -> Unit)? = 78 | null //New type introduced by kotlin (Function2 , function as parameter) 79 | 80 | constructor(context: Context) : super(context) { 81 | init(context, null) 82 | } 83 | 84 | constructor(context: Context, attributeSet: AttributeSet) : super(context, attributeSet) { 85 | init(context, attributeSet) 86 | } 87 | 88 | constructor(context: Context, attributeSet: AttributeSet, defStyleAttr: Int) : super( 89 | context, 90 | attributeSet, 91 | defStyleAttr 92 | ) { 93 | init(context, attributeSet) 94 | } 95 | 96 | 97 | private fun init(context: Context, attributeSet: AttributeSet?) { 98 | AppCompatDelegate.setCompatVectorFromResourcesEnabled(true) 99 | val root = LayoutInflater.from(context).inflate( 100 | R.layout.layout_checkable_text, 101 | this, true) 102 | 103 | initValuesFromAttrs(attributeSet, context) 104 | 105 | root.viewTreeObserver.addOnGlobalLayoutListener(object : OnGlobalLayoutListener { 106 | override fun onGlobalLayout() { 107 | root.viewTreeObserver.removeOnGlobalLayoutListener(this) 108 | if (animateFirstTime) { 109 | resetView(animateStyle, checkedIV, !isChecked) 110 | animateView(checkedIV, isChecked) 111 | } else 112 | resetView(animateStyle, checkedIV, isChecked) 113 | 114 | } 115 | }) 116 | rootRL.setOnClickListener(clickListener()) 117 | } 118 | 119 | private fun initValuesFromAttrs(attributeSet: AttributeSet?, context: Context) { 120 | attributeSet?.apply { 121 | val array: TypedArray = context.obtainStyledAttributes(this, R.styleable.CheckableTextView) 122 | if (array.length() > 0) { 123 | 124 | rippleTint = array.getColor( 125 | R.styleable.CheckableTextView_ctv_RippleTint, 126 | Color.parseColor(getThemeAccentColor(context)) 127 | ) 128 | 129 | val iconTint = array.getColor( 130 | R.styleable.CheckableTextView_ctv_IconTint, 131 | Color.parseColor(getThemeAccentColor(context)) 132 | ) 133 | val textColor = array.getColor( 134 | R.styleable.CheckableTextView_ctv_TextColor, 135 | ContextCompat.getColor(context, defaultTextColor) 136 | ) 137 | val text = array.getString(R.styleable.CheckableTextView_ctv_Text) 138 | animateFirstTime = 139 | array.getBoolean( 140 | R.styleable.CheckableTextView_ctv_AnimFirstTime, 141 | defaultAnimFirstTime 142 | ) 143 | isChecked = array.getBoolean( 144 | R.styleable.CheckableTextView_ctv_IconChecked, 145 | defaultCheckState 146 | ) 147 | isRippleFillEnabled = 148 | array.getBoolean(R.styleable.CheckableTextView_ctv_RippleFillEnabled, false) 149 | val textSize = array.getDimensionPixelSize( 150 | R.styleable.CheckableTextView_ctv_TextSize, 151 | defaultResValue 152 | ) 153 | val textStyle = array.getResourceId( 154 | R.styleable.CheckableTextView_ctv_TextStyle, 155 | defaultResValue 156 | ) 157 | checkIcon = 158 | array.getResourceId(R.styleable.CheckableTextView_ctv_Icon, defaultResValue) 159 | val gravity = 160 | array.getInt(R.styleable.CheckableTextView_ctv_TextGravity, Gravity.CENTER) 161 | animateStyle = array.getInt(R.styleable.CheckableTextView_ctv_AnimType, SCALE) 162 | rippleAlpha = array.getInt(R.styleable.CheckableTextView_ctv_RippleAlpha, 33) 163 | normalizeRippleAlpha() 164 | val animDuration = 165 | array.getInt( 166 | R.styleable.CheckableTextView_ctv_AnimDuration, 167 | defaultAnimDuration.toInt() 168 | ).toLong() 169 | setAnimDuration(animDuration) 170 | 171 | //giving applied style attrs least preference (colors n text size will be override by ctv_TextColor & ctv_TextSize as applied later) 172 | applyTextStyle(textStyle, context) 173 | validateCheckIcon(context) 174 | setText(text ?: "") 175 | setTextGravity(gravity) 176 | checkedTextTV.setTextColor(textColor) 177 | checkedIV.setImageResource(checkIcon) 178 | 179 | if (isValidRes(textSize)) 180 | checkedTextTV.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize.toFloat()) 181 | 182 | if (isValidRes(iconTint)) 183 | checkedIV.setColorFilter(iconTint) 184 | } 185 | array.recycle() 186 | } 187 | } 188 | 189 | private fun normalizeRippleAlpha() { 190 | if (rippleAlpha < 0) 191 | rippleAlpha = 0 192 | if (rippleAlpha > 255) 193 | rippleAlpha = 255 194 | } 195 | 196 | private fun clickListener(): (v: View) -> Unit { 197 | return { 198 | checkedTextTV.text = checkedTextTV.text 199 | checkedTextTV.isSelected = true 200 | isChecked = !isChecked 201 | animateView(checkedIV, isChecked) 202 | notifyListener(isChecked) 203 | } 204 | } 205 | private fun applyTextStyle(textStyle: Int, context: Context) { 206 | if (isValidRes(textStyle)) { 207 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { 208 | checkedTextTV.setTextAppearance(textStyle) 209 | } else { 210 | checkedTextTV.setTextAppearance(context, textStyle) 211 | } 212 | } 213 | } 214 | 215 | private fun animateView(view: View, show: Boolean) { 216 | view.clearAnimation() 217 | if (isRippleFillEnabled) 218 | triggerFillAnimation(show) 219 | val animator = getAnimator(animateStyle, view, show, animDuration) 220 | animator.setInterpolator(animInterpolator).start() 221 | } 222 | 223 | private fun triggerFillAnimation(show: Boolean) { 224 | if (rippleAlpha <= 0) return 225 | val scale = if (show) width * 2f / fillIV.width else 0f 226 | val delay = if (show) animDuration / 2 else 0 227 | ViewCompat.setBackgroundTintList( 228 | fillIV, 229 | ColorStateList.valueOf( 230 | ColorUtils.setAlphaComponent( 231 | rippleTint, rippleAlpha 232 | ) 233 | ) 234 | ) 235 | fillIV.animate().setStartDelay(delay).scaleX(scale).scaleY(scale) 236 | .setDuration((animDuration * 1f / 1.1).toLong()) 237 | .setInterpolator(AccelerateInterpolator()) 238 | .start() 239 | } 240 | 241 | private fun validateCheckIcon(context: Context) { 242 | if (isValidRes(checkIcon)) { 243 | val drawableIcon = ContextCompat.getDrawable(context, checkIcon) 244 | if (drawableIcon == null) checkIcon = defaultCheckIcon 245 | drawableIcon.let { 246 | if (it is ColorDrawable) { 247 | checkIcon = defaultCheckIcon 248 | } 249 | } 250 | } else checkIcon = defaultCheckIcon 251 | } 252 | 253 | private fun isValidRes(res: Int) = res != defaultResValue 254 | private fun emptyNullCheck(text: String?) = text != null && !text.isBlank() 255 | 256 | private fun notifyListener(isChecked: Boolean) { 257 | listener?.onCheckChange(this, isChecked) 258 | listenerNew?.invoke(this, isChecked) 259 | } 260 | 261 | /*-------------------------------------------------public functions------------------------------------------------------------------------------------------*/ 262 | 263 | /** 264 | * Change [CheckableTextView] click state 265 | * @param isClickable = pass true for enable clicks and false for disable clicks. 266 | */ 267 | @RestrictTo(RestrictTo.Scope.LIBRARY) 268 | fun setClickEnabled(isClickable: Boolean) { 269 | // 0.5 second delay added to ongoing ripple animation to complete (if any) 270 | rootRL.postDelayed( 271 | { rootRL.setBackgroundResource(if (isClickable) getRippleDrawable(context) else android.R.color.transparent) }, 272 | 500 273 | ) 274 | rootRL.setOnClickListener(if (isClickable) clickListener() else null) 275 | } 276 | 277 | fun setOnCheckChangeListener(listener: CheckedListener) { 278 | this.listener = listener //only one type listener will invoke 279 | this.listenerNew = null 280 | } 281 | 282 | fun setOnCheckChangeListener(listenerNew: (view: View, isChecked: Boolean) -> Unit) { 283 | this.listener = null 284 | this.listenerNew = listenerNew 285 | } 286 | 287 | fun setChecked(isChecked: Boolean, shouldNotifyListeners: Boolean = false) { 288 | this.isChecked = isChecked 289 | animateView(checkedIV, isChecked) 290 | if (shouldNotifyListeners) 291 | notifyListener(isChecked) 292 | } 293 | 294 | fun setRippleFillEnabled(isEnabled: Boolean) { 295 | this.isRippleFillEnabled = isEnabled 296 | } 297 | 298 | fun setRippleTint(color: Int) { 299 | val extractedColor = try { 300 | ContextCompat.getColor(context, color) 301 | } catch (e: Exception) { 302 | color 303 | } 304 | setRippleFillEnabled(true) 305 | rippleTint = extractedColor 306 | } 307 | 308 | fun setRippleAlpha(alpha: Int) { 309 | this.rippleAlpha = alpha 310 | normalizeRippleAlpha() 311 | } 312 | 313 | fun setIconTint(color: Int) { 314 | val extractedColor = try { 315 | ContextCompat.getColor(context, color) 316 | } catch (e: Exception) { 317 | color 318 | } 319 | checkedIV.setColorFilter(extractedColor) 320 | 321 | } 322 | 323 | fun setTextSize(@DimenRes resId: Int) { 324 | if (isValidRes(resId)) { 325 | val dimension = resources.getDimensionPixelSize(resId) 326 | checkedTextTV.setTextSize(TypedValue.COMPLEX_UNIT_PX, dimension.toFloat()) 327 | } 328 | } 329 | 330 | fun setTextColor(color: Int) { 331 | val extractedColor = try { 332 | ContextCompat.getColor(context, color) 333 | } catch (e: Exception) { 334 | color 335 | } 336 | checkedTextTV.setTextColor(extractedColor) 337 | 338 | } 339 | 340 | fun setText(@StringRes resId: Int) { 341 | if (isValidRes(resId)) { 342 | val string = context.getString(resId) 343 | setText(string) 344 | } 345 | } 346 | 347 | fun setText(text: String) { 348 | if (emptyNullCheck(text)) { 349 | checkedTextTV.text = text 350 | checkedTextTV.isSelected = true 351 | } 352 | } 353 | 354 | fun setTextGravity(gravity: Int) { 355 | checkedTextTV.gravity = gravity 356 | } 357 | 358 | fun setIcon(@DrawableRes resId: Int) { 359 | if (isValidRes(resId)) { 360 | checkIcon = resId 361 | validateCheckIcon(context) 362 | checkedIV.setImageResource(checkIcon) 363 | } 364 | } 365 | 366 | fun setTextStyle(@StyleRes resId: Int) { 367 | if (isValidRes(resId)) 368 | applyTextStyle(resId, context) 369 | } 370 | 371 | /** 372 | * @param animType should be [SCALE],[TRANSLATE],[FALL_DOWN] 373 | */ 374 | fun setAnimStyle(animType: Int) { 375 | animateStyle = if (animType in SCALE..FALL_DOWN) animType else animateStyle 376 | } 377 | 378 | fun setAnimDuration(duration: Long) { 379 | if (duration == 0L || duration < 0) return 380 | animDuration = duration 381 | } 382 | 383 | } --------------------------------------------------------------------------------