diff --git a/.idea/AndroidProjectSystem.xml b/.idea/AndroidProjectSystem.xml
new file mode 100644
index 0000000..4a53bee
--- /dev/null
+++ b/.idea/AndroidProjectSystem.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/caches/deviceStreaming.xml b/.idea/caches/deviceStreaming.xml
new file mode 100644
index 0000000..8d2a5ae
--- /dev/null
+++ b/.idea/caches/deviceStreaming.xml
@@ -0,0 +1,1454 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/compiler.xml b/.idea/compiler.xml
new file mode 100644
index 0000000..b589d56
--- /dev/null
+++ b/.idea/compiler.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/deploymentTargetSelector.xml b/.idea/deploymentTargetSelector.xml
new file mode 100644
index 0000000..5c18785
--- /dev/null
+++ b/.idea/deploymentTargetSelector.xml
@@ -0,0 +1,18 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/gradle.xml b/.idea/gradle.xml
index b17f342..aa64d09 100644
--- a/.idea/gradle.xml
+++ b/.idea/gradle.xml
@@ -1,10 +1,12 @@
+
-
+
+
@@ -12,7 +14,6 @@
-
diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml
new file mode 100644
index 0000000..3479cd1
--- /dev/null
+++ b/.idea/inspectionProfiles/Project_Default.xml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml
new file mode 100644
index 0000000..3870572
--- /dev/null
+++ b/.idea/jarRepositories.xml
@@ -0,0 +1,45 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/kotlinc.xml b/.idea/kotlinc.xml
new file mode 100644
index 0000000..b1077fb
--- /dev/null
+++ b/.idea/kotlinc.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/markdown.xml b/.idea/markdown.xml
new file mode 100644
index 0000000..c61ea33
--- /dev/null
+++ b/.idea/markdown.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/migrations.xml b/.idea/migrations.xml
new file mode 100644
index 0000000..f8051a6
--- /dev/null
+++ b/.idea/migrations.xml
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
index b8ca955..1a05895 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -1,10 +1,14 @@
-
+
+
+
+
+
@@ -12,7 +16,7 @@
-
+
diff --git a/.idea/modules.xml b/.idea/modules.xml
deleted file mode 100644
index d36b263..0000000
--- a/.idea/modules.xml
+++ /dev/null
@@ -1,10 +0,0 @@
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml
index 7f68460..16660f1 100644
--- a/.idea/runConfigurations.xml
+++ b/.idea/runConfigurations.xml
@@ -3,9 +3,14 @@
-
-
-
+
+
+
+
+
+
+
+
diff --git a/AutoFitTextViewLibrary/.classpath b/AutoFitTextViewLibrary/.classpath
deleted file mode 100644
index 298b912..0000000
--- a/AutoFitTextViewLibrary/.classpath
+++ /dev/null
@@ -1,9 +0,0 @@
-
-
-
-
-
-
-
-
-
diff --git a/AutoFitTextViewLibrary/.project b/AutoFitTextViewLibrary/.project
deleted file mode 100644
index 2423645..0000000
--- a/AutoFitTextViewLibrary/.project
+++ /dev/null
@@ -1,33 +0,0 @@
-
-
- AutoFitTextViewLibrary
-
-
-
-
-
- com.android.ide.eclipse.adt.ResourceManagerBuilder
-
-
-
-
- com.android.ide.eclipse.adt.PreCompilerBuilder
-
-
-
-
- org.eclipse.jdt.core.javabuilder
-
-
-
-
- com.android.ide.eclipse.adt.ApkBuilder
-
-
-
-
-
- com.android.ide.eclipse.adt.AndroidNature
- org.eclipse.jdt.core.javanature
-
-
diff --git a/AutoFitTextViewLibrary/AndroidManifest.xml b/AutoFitTextViewLibrary/AndroidManifest.xml
deleted file mode 100644
index 82e47a7..0000000
--- a/AutoFitTextViewLibrary/AndroidManifest.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
-
diff --git a/AutoFitTextViewLibrary/build.gradle b/AutoFitTextViewLibrary/build.gradle
deleted file mode 100644
index 413cb76..0000000
--- a/AutoFitTextViewLibrary/build.gradle
+++ /dev/null
@@ -1,45 +0,0 @@
-apply plugin: 'com.android.library'
-apply plugin: 'kotlin-android-extensions'
-apply plugin: 'kotlin-android'
-
-android {
- compileSdkVersion 28
-
- defaultConfig {
- minSdkVersion 14
- targetSdkVersion 28
- versionCode 1
- versionName "1.0"
- }
-
- sourceSets {
- main {
- manifest.srcFile 'AndroidManifest.xml'
- java.srcDirs = ['src']
- resources.srcDirs = ['src']
- aidl.srcDirs = ['src']
- renderscript.srcDirs = ['src']
- res.srcDirs = ['res']
- assets.srcDirs = ['assets']
- }
- }
-
- buildTypes {
- release {
- minifyEnabled false
- }
- }
- compileOptions {
- sourceCompatibility = '1.8'
- targetCompatibility = '1.8'
- }
-}
-
-dependencies {
- implementation 'androidx.appcompat:appcompat:1.0.2'
- implementation "androidx.core:core-ktx:1.0.1"
- implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
-}
-repositories {
- mavenCentral()
-}
diff --git a/AutoFitTextViewLibrary/build.gradle.kts b/AutoFitTextViewLibrary/build.gradle.kts
new file mode 100644
index 0000000..384295f
--- /dev/null
+++ b/AutoFitTextViewLibrary/build.gradle.kts
@@ -0,0 +1,50 @@
+import org.gradle.kotlin.dsl.withType
+import org.jetbrains.kotlin.gradle.dsl.JvmTarget
+import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile
+
+plugins {
+ id("com.android.library")
+ id("maven-publish")
+}
+
+android {
+ namespace = "com.lb.auto_fit_textview"
+ compileSdk = 36
+
+ defaultConfig {
+ minSdk = 23
+ }
+ lint {
+ targetSdk = 36
+ }
+ compileOptions {
+ sourceCompatibility = JavaVersion.VERSION_17
+ targetCompatibility = JavaVersion.VERSION_17
+ }
+ tasks.withType().configureEach {
+ compilerOptions {
+ jvmTarget.set(JvmTarget.JVM_17)
+ }
+ }
+ publishing {
+ singleVariant("release") {
+ withSourcesJar()
+ withJavadocJar()
+ }
+ }
+}
+
+dependencies {
+ implementation("com.google.android.material:material:1.13.0")
+ implementation("androidx.core:core-ktx:1.17.0")
+}
+
+afterEvaluate {
+ publishing {
+ publications {
+ register("release") {
+ from(components["release"])
+ }
+ }
+ }
+}
diff --git a/AutoFitTextViewLibrary/proguard-project.txt b/AutoFitTextViewLibrary/proguard-rules.pro
similarity index 100%
rename from AutoFitTextViewLibrary/proguard-project.txt
rename to AutoFitTextViewLibrary/proguard-rules.pro
diff --git a/AutoFitTextViewLibrary/project.properties b/AutoFitTextViewLibrary/project.properties
deleted file mode 100644
index e195e98..0000000
--- a/AutoFitTextViewLibrary/project.properties
+++ /dev/null
@@ -1,14 +0,0 @@
-# This file is automatically generated by Android Tools.
-# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
-#
-# This file must be checked in Version Control Systems.
-#
-# To customize properties used by the Ant build system edit
-# "ant.properties", and override values to adapt the script to your
-# project structure.
-#
-# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
-#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
-# Project target.
-target=android-21
-android.library=true
diff --git a/AutoFitTextViewLibrary/src/main/AndroidManifest.xml b/AutoFitTextViewLibrary/src/main/AndroidManifest.xml
new file mode 100644
index 0000000..9a40236
--- /dev/null
+++ b/AutoFitTextViewLibrary/src/main/AndroidManifest.xml
@@ -0,0 +1,3 @@
+
+
+
diff --git a/AutoFitTextViewLibrary/src/com/lb/auto_fit_textview/AutoResizeTextView.kt b/AutoFitTextViewLibrary/src/main/kotlin/com/lb/auto_fit_textview/AutoResizeTextView.kt
similarity index 55%
rename from AutoFitTextViewLibrary/src/com/lb/auto_fit_textview/AutoResizeTextView.kt
rename to AutoFitTextViewLibrary/src/main/kotlin/com/lb/auto_fit_textview/AutoResizeTextView.kt
index df5689f..7dfd413 100644
--- a/AutoFitTextViewLibrary/src/com/lb/auto_fit_textview/AutoResizeTextView.kt
+++ b/AutoFitTextViewLibrary/src/main/kotlin/com/lb/auto_fit_textview/AutoResizeTextView.kt
@@ -1,8 +1,6 @@
package com.lb.auto_fit_textview
-import android.annotation.TargetApi
import android.content.Context
-import android.content.res.Resources
import android.graphics.RectF
import android.graphics.Typeface
import android.os.Build
@@ -16,21 +14,23 @@ import androidx.appcompat.widget.AppCompatTextView
/**
* a textView that is able to self-adjust its font size depending on the min and max size of the font, and its own size.
* code is heavily based on this StackOverflow thread:
- * http://stackoverflow.com/questions/16017165/auto-fit-textview-for-android/21851239#21851239
- * It should work fine with most Android versions, but might have some issues on Android 3.1 - 4.04, as setTextSize will only work for the first time.
- * More info here: https://code.google.com/p/android/issues/detail?id=22493 and here in case you wish to fix it: http://stackoverflow.com/a/21851239/878126
+ * http://stackoverflow.com/questions/16017165/auto-fit-textview-for-android/21851239#21851239
*/
-class AutoResizeTextView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyle: Int = android.R.attr.textViewStyle) : AppCompatTextView(context, attrs, defStyle) {
+class AutoResizeTextView @JvmOverloads constructor(
+ context: Context,
+ attrs: AttributeSet? = null,
+ defStyle: Int = android.R.attr.textViewStyle
+) : AppCompatTextView(context, attrs, defStyle) {
private val availableSpaceRect = RectF()
private val sizeTester: SizeTester
- private var maxTextSize: Float = 0.toFloat()
+ private var maxTextSize: Float = 0f
private var spacingMult = 1.0f
private var spacingAdd = 0.0f
- private var minTextSize: Float = 0.toFloat()
+ private var minTextSize: Float = 0f
private var widthLimit: Int = 0
- private var maxLines: Int = 0
+ private var maxLinesValue: Int = -1
private var initialized = false
- private var textPaint: TextPaint? = null
+ private var textPaint: TextPaint
private interface SizeTester {
/**
@@ -48,59 +48,58 @@ class AutoResizeTextView @JvmOverloads constructor(context: Context, attrs: Attr
minTextSize = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 12f, resources.displayMetrics)
maxTextSize = textSize
textPaint = TextPaint(paint)
- if (maxLines == 0)
- // no value was assigned during construction
- maxLines = NO_LINE_LIMIT
+ maxLinesValue = maxLines
+
// prepare size tester:
sizeTester = object : SizeTester {
- internal val textRect = RectF()
+ val textRect = RectF()
- @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
override fun onTestSize(suggestedSize: Int, availableSpace: RectF): Int {
- textPaint!!.textSize = suggestedSize.toFloat()
+ textPaint.textSize = suggestedSize.toFloat()
val transformationMethod = transformationMethod
- val text: String
- if (transformationMethod != null)
- text = transformationMethod.getTransformation(getText(), this@AutoResizeTextView).toString()
- else
- text = getText().toString()
- val singleLine = maxLines == 1
+ val textToTest: String = transformationMethod?.getTransformation(text, this@AutoResizeTextView)
+ ?.toString()
+ ?: text.toString()
+
+ val singleLine = maxLinesValue == 1
if (singleLine) {
- textRect.bottom = textPaint!!.fontSpacing
- textRect.right = textPaint!!.measureText(text)
+ textRect.bottom = textPaint.fontSpacing
+ textRect.right = textPaint.measureText(textToTest)
} else {
val layout: StaticLayout = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
- StaticLayout.Builder.obtain(text, 0, text.length, textPaint!!, widthLimit).setLineSpacing(spacingAdd, spacingMult).setAlignment(Alignment.ALIGN_NORMAL).setIncludePad(true).build()
- } else StaticLayout(text, textPaint, widthLimit, Alignment.ALIGN_NORMAL, spacingMult, spacingAdd, true)
+ StaticLayout.Builder.obtain(textToTest, 0, textToTest.length, textPaint, widthLimit)
+ .setLineSpacing(spacingAdd, spacingMult)
+ .setAlignment(Alignment.ALIGN_NORMAL)
+ .setIncludePad(true)
+ .build()
+ } else {
+ @Suppress("DEPRECATION")
+ StaticLayout(textToTest, textPaint, widthLimit, Alignment.ALIGN_NORMAL, spacingMult, spacingAdd, true)
+ }
// return early if we have more lines
- if (maxLines != NO_LINE_LIMIT && layout.lineCount > maxLines)
+ if (maxLinesValue != NO_LINE_LIMIT && layout.lineCount > maxLinesValue)
return 1
textRect.bottom = layout.height.toFloat()
- var maxWidth = -1
+ var maxWidth = -1f
val lineCount = layout.lineCount
for (i in 0 until lineCount) {
val end = layout.getLineEnd(i)
- if (i < lineCount - 1 && end > 0 && !isValidWordWrap(text[end - 1], text[end]))
+ if (i < lineCount - 1 && end > 0 && !isValidWordWrap(textToTest[end - 1]))
return 1
- if (maxWidth < layout.getLineRight(i) - layout.getLineLeft(i))
- maxWidth = layout.getLineRight(i).toInt() - layout.getLineLeft(i).toInt()
+ val lineWidth = layout.getLineRight(i) - layout.getLineLeft(i)
+ if (maxWidth < lineWidth)
+ maxWidth = lineWidth
}
- //for (int i = 0; i < layout.getLineCount(); i++)
- // if (maxWidth < layout.getLineRight(i) - layout.getLineLeft(i))
- // maxWidth = (int) layout.getLineRight(i) - (int) layout.getLineLeft(i);
- textRect.right = maxWidth.toFloat()
+ textRect.right = maxWidth
}
textRect.offsetTo(0f, 0f)
return if (availableSpace.contains(textRect)) -1 else 1
- // else, too big
}
}
initialized = true
}
- fun isValidWordWrap(before: Char, after: Char): Boolean {
- return before == ' ' || before == '-'
- }
+ private fun isValidWordWrap(c: Char): Boolean = c == ' ' || c == '-'
override fun setAllCaps(allCaps: Boolean) {
super.setAllCaps(allCaps)
@@ -119,43 +118,36 @@ class AutoResizeTextView @JvmOverloads constructor(context: Context, attrs: Attr
override fun setMaxLines(maxLines: Int) {
super.setMaxLines(maxLines)
- this.maxLines = maxLines
+ this.maxLinesValue = maxLines
adjustTextSize()
}
- override fun getMaxLines(): Int {
- return maxLines
- }
+ override fun getMaxLines(): Int = maxLinesValue
+ @Deprecated("Deprecated in Java", ReplaceWith("maxLines = 1"))
override fun setSingleLine() {
+ @Suppress("DEPRECATION")
super.setSingleLine()
- maxLines = 1
+ maxLinesValue = 1
adjustTextSize()
}
+ @Deprecated("Deprecated in Java", ReplaceWith("maxLines = if (singleLine) 1 else -1"))
override fun setSingleLine(singleLine: Boolean) {
+ @Suppress("DEPRECATION")
super.setSingleLine(singleLine)
- if (singleLine)
- maxLines = 1
- else
- maxLines = NO_LINE_LIMIT
+ maxLinesValue = if (singleLine) 1 else NO_LINE_LIMIT
adjustTextSize()
}
override fun setLines(lines: Int) {
super.setLines(lines)
- maxLines = lines
+ maxLinesValue = lines
adjustTextSize()
}
override fun setTextSize(unit: Int, size: Float) {
- val c = context
- val r: Resources
- r = if (c == null)
- Resources.getSystem()
- else
- c.resources
- maxTextSize = TypedValue.applyDimension(unit, size, r.displayMetrics)
+ maxTextSize = TypedValue.applyDimension(unit, size, context.resources.displayMetrics)
adjustTextSize()
}
@@ -167,8 +159,6 @@ class AutoResizeTextView @JvmOverloads constructor(context: Context, attrs: Attr
/**
* Set the lower text size limit and invalidate the view
- *
- * @param minTextSize
*/
fun setMinTextSize(minTextSize: Float) {
this.minTextSize = minTextSize
@@ -176,31 +166,16 @@ class AutoResizeTextView @JvmOverloads constructor(context: Context, attrs: Attr
}
private fun adjustTextSize() {
- // This is a workaround for truncated text issue on ListView, as shown here: https://github.com/AndroidDeveloperLB/AutoFitTextView/pull/14
- // TODO think of a nicer, elegant solution.
- // post(new Runnable()
- // {
- // @Override
- // public void run()
- // {
- if (!initialized)
- return
+ if (!initialized) return
val startSize = minTextSize.toInt()
val heightLimit = measuredHeight - compoundPaddingBottom - compoundPaddingTop
widthLimit = measuredWidth - compoundPaddingLeft - compoundPaddingRight
- if (widthLimit <= 0)
- return
+ if (widthLimit <= 0) return
textPaint = TextPaint(paint)
availableSpaceRect.right = widthLimit.toFloat()
availableSpaceRect.bottom = heightLimit.toFloat()
- superSetTextSize(startSize)
- // }
- // });
- }
-
- private fun superSetTextSize(startSize: Int) {
- val textSize = binarySearch(startSize, maxTextSize.toInt(), sizeTester, availableSpaceRect)
- super.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize.toFloat())
+ val calculatedSize = binarySearch(startSize, maxTextSize.toInt(), sizeTester, availableSpaceRect)
+ super.setTextSize(TypedValue.COMPLEX_UNIT_PX, calculatedSize.toFloat())
}
private fun binarySearch(start: Int, end: Int, sizeTester: SizeTester, availableSpace: RectF): Int {
@@ -212,16 +187,14 @@ class AutoResizeTextView @JvmOverloads constructor(context: Context, attrs: Attr
mid = (lo + hi).ushr(1)
val midValCmp = sizeTester.onTestSize(mid, availableSpace)
if (midValCmp < 0) {
- lastBest = lo
+ lastBest = mid
lo = mid + 1
} else if (midValCmp > 0) {
hi = mid - 1
- lastBest = hi
- } else
+ } else {
return mid
+ }
}
- // make sure to return last best
- // this is what should always be returned
return lastBest
}
@@ -237,6 +210,6 @@ class AutoResizeTextView @JvmOverloads constructor(context: Context, attrs: Attr
}
companion object {
- private val NO_LINE_LIMIT = -1
+ private const val NO_LINE_LIMIT = -1
}
}
diff --git a/AutoFitTextViewSample/.classpath b/AutoFitTextViewSample/.classpath
deleted file mode 100644
index 298b912..0000000
--- a/AutoFitTextViewSample/.classpath
+++ /dev/null
@@ -1,9 +0,0 @@
-
-
-
-
-
-
-
-
-
diff --git a/AutoFitTextViewSample/.project b/AutoFitTextViewSample/.project
deleted file mode 100644
index 9dcca0e..0000000
--- a/AutoFitTextViewSample/.project
+++ /dev/null
@@ -1,33 +0,0 @@
-
-
- AutoFitTextViewSample
-
-
-
-
-
- com.android.ide.eclipse.adt.ResourceManagerBuilder
-
-
-
-
- com.android.ide.eclipse.adt.PreCompilerBuilder
-
-
-
-
- org.eclipse.jdt.core.javabuilder
-
-
-
-
- com.android.ide.eclipse.adt.ApkBuilder
-
-
-
-
-
- com.android.ide.eclipse.adt.AndroidNature
- org.eclipse.jdt.core.javanature
-
-
diff --git a/AutoFitTextViewSample/AndroidManifest.xml b/AutoFitTextViewSample/AndroidManifest.xml
deleted file mode 100644
index 335ebc0..0000000
--- a/AutoFitTextViewSample/AndroidManifest.xml
+++ /dev/null
@@ -1,17 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/AutoFitTextViewSample/build.gradle b/AutoFitTextViewSample/build.gradle
deleted file mode 100644
index 21850d3..0000000
--- a/AutoFitTextViewSample/build.gradle
+++ /dev/null
@@ -1,50 +0,0 @@
-apply plugin: 'com.android.application'
-apply plugin: 'kotlin-android-extensions'
-apply plugin: 'kotlin-android'
-
-android {
- compileSdkVersion 28
-
- defaultConfig {
- applicationId "com.example.autofittextviewsample"
- minSdkVersion 17
- targetSdkVersion 28
- versionCode 1
- versionName "1.0"
- }
-
- buildTypes {
- release {
- }
- }
-
- sourceSets {
- main {
- manifest.srcFile 'AndroidManifest.xml'
- java.srcDirs = ['src']
- resources.srcDirs = ['src']
- aidl.srcDirs = ['src']
- renderscript.srcDirs = ['src']
- res.srcDirs = ['res']
- assets.srcDirs = ['assets']
- }
- }
- compileOptions {
- sourceCompatibility = '1.8'
- targetCompatibility = '1.8'
- }
-
-}
-
-dependencies {
- implementation fileTree(dir: 'libs', include: ['*.jar'])
- implementation 'androidx.appcompat:appcompat:1.0.2'
- implementation 'androidx.recyclerview:recyclerview:1.0.0'
- implementation project(':AutoFitTextViewLibrary')
- implementation 'androidx.core:core-ktx:1.0.1'
- implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
- implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
-}
-repositories {
- mavenCentral()
-}
diff --git a/AutoFitTextViewSample/build.gradle.kts b/AutoFitTextViewSample/build.gradle.kts
new file mode 100644
index 0000000..7bee511
--- /dev/null
+++ b/AutoFitTextViewSample/build.gradle.kts
@@ -0,0 +1,50 @@
+import org.gradle.kotlin.dsl.withType
+import org.jetbrains.kotlin.gradle.dsl.JvmTarget
+import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile
+
+plugins {
+ id("com.android.application")
+}
+
+android {
+ namespace = "com.example.autofittextviewsample"
+ compileSdk = 36
+
+ defaultConfig {
+ applicationId = "com.example.autofittextviewsample"
+ minSdk = 23
+ targetSdk = 36
+ versionCode = 1
+ versionName = "1.0"
+ }
+
+ buildTypes {
+ getByName("release") {
+ isMinifyEnabled = false
+ proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
+ }
+ }
+
+ compileOptions {
+ sourceCompatibility = JavaVersion.VERSION_17
+ targetCompatibility = JavaVersion.VERSION_17
+ }
+ tasks.withType().configureEach {
+ compilerOptions {
+ jvmTarget.set(JvmTarget.JVM_17)
+ }
+ }
+ buildFeatures {
+ viewBinding = true
+ }
+}
+
+dependencies {
+ implementation("com.google.android.material:material:1.13.0")
+ implementation("androidx.recyclerview:recyclerview:1.4.0")
+ implementation(project(":AutoFitTextViewLibrary"))
+ implementation("androidx.core:core-ktx:1.17.0")
+ implementation("androidx.constraintlayout:constraintlayout:2.2.1")
+ implementation("com.github.AndroidDeveloperLB:CommonUtils:37")
+
+}
diff --git a/AutoFitTextViewSample/lint.xml b/AutoFitTextViewSample/lint.xml
deleted file mode 100644
index 9c0ed5a..0000000
--- a/AutoFitTextViewSample/lint.xml
+++ /dev/null
@@ -1,2 +0,0 @@
-
-
diff --git a/AutoFitTextViewSample/proguard-project.txt b/AutoFitTextViewSample/proguard-rules.pro
similarity index 100%
rename from AutoFitTextViewSample/proguard-project.txt
rename to AutoFitTextViewSample/proguard-rules.pro
diff --git a/AutoFitTextViewSample/project.properties b/AutoFitTextViewSample/project.properties
deleted file mode 100644
index fb9fae5..0000000
--- a/AutoFitTextViewSample/project.properties
+++ /dev/null
@@ -1,14 +0,0 @@
-# This file is automatically generated by Android Tools.
-# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
-#
-# This file must be checked in Version Control Systems.
-#
-# To customize properties used by the Ant build system edit
-# "ant.properties", and override values to adapt the script to your
-# project structure.
-#
-# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
-#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
-# Project target.
-target=android-21
-android.library.reference.1=..\\AutoFitTextViewLibrary
diff --git a/AutoFitTextViewSample/res/layout/activity_main.xml b/AutoFitTextViewSample/res/layout/activity_main.xml
deleted file mode 100644
index 855d748..0000000
--- a/AutoFitTextViewSample/res/layout/activity_main.xml
+++ /dev/null
@@ -1,52 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/AutoFitTextViewSample/res/layout/activity_main2.xml b/AutoFitTextViewSample/res/layout/activity_main2.xml
deleted file mode 100644
index 6794a85..0000000
--- a/AutoFitTextViewSample/res/layout/activity_main2.xml
+++ /dev/null
@@ -1,5 +0,0 @@
-
-
-
diff --git a/AutoFitTextViewSample/res/menu/main.xml b/AutoFitTextViewSample/res/menu/main.xml
deleted file mode 100644
index 2a8a832..0000000
--- a/AutoFitTextViewSample/res/menu/main.xml
+++ /dev/null
@@ -1,13 +0,0 @@
-
-
diff --git a/AutoFitTextViewSample/src/com/example/autofittextviewsample/Main2Activity.kt b/AutoFitTextViewSample/src/com/example/autofittextviewsample/Main2Activity.kt
deleted file mode 100644
index 4503944..0000000
--- a/AutoFitTextViewSample/src/com/example/autofittextviewsample/Main2Activity.kt
+++ /dev/null
@@ -1,47 +0,0 @@
-package com.example.autofittextviewsample
-
-import android.os.Bundle
-import android.view.LayoutInflater
-import android.view.View
-import android.view.ViewGroup
-import android.widget.TextView
-import androidx.appcompat.app.AppCompatActivity
-import androidx.recyclerview.widget.LinearLayoutManager
-import androidx.recyclerview.widget.RecyclerView
-import androidx.recyclerview.widget.RecyclerView.Adapter
-import kotlinx.android.synthetic.main.activity_main2.*
-
-class Main2Activity : AppCompatActivity() {
-
- override fun onCreate(savedInstanceState: Bundle?) {
- super.onCreate(savedInstanceState)
- setContentView(R.layout.activity_main2)
- recyclerView.layoutManager = LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false)
- recyclerView.adapter = object : Adapter() {
- override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
- return object : ViewHolder(LayoutInflater.from(this@Main2Activity).inflate(R.layout.item, parent, false)) {
-
- }
- }
-
- override fun onBindViewHolder(holder: ViewHolder, position: Int) {
- val sb = StringBuilder("item:")
- for (i in 0..position)
- sb.append(Integer.toString(position))
- holder.textView.text = sb
- }
-
- override fun getItemCount(): Int {
- return 50
- }
- }
- }
-
- private open class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
- internal val textView: TextView
-
- init {
- textView = itemView.findViewById(android.R.id.text1) as TextView
- }
- }
-}
diff --git a/AutoFitTextViewSample/src/com/example/autofittextviewsample/MainActivity.kt b/AutoFitTextViewSample/src/com/example/autofittextviewsample/MainActivity.kt
deleted file mode 100644
index 24b9184..0000000
--- a/AutoFitTextViewSample/src/com/example/autofittextviewsample/MainActivity.kt
+++ /dev/null
@@ -1,132 +0,0 @@
-package com.example.autofittextviewsample
-
-import android.content.Intent
-import android.net.Uri
-import android.os.Bundle
-import android.text.Editable
-import android.text.TextUtils.TruncateAt
-import android.text.TextWatcher
-import android.util.TypedValue
-import android.view.Gravity
-import android.view.Menu
-import android.view.MenuItem
-import android.view.View
-import android.view.View.OnClickListener
-import android.view.ViewGroup.LayoutParams
-import android.view.ViewTreeObserver.OnPreDrawListener
-import android.widget.SeekBar
-import android.widget.SeekBar.OnSeekBarChangeListener
-import androidx.appcompat.app.AppCompatActivity
-import com.lb.auto_fit_textview.AutoResizeTextView
-import kotlinx.android.synthetic.main.activity_main.*
-
-class MainActivity : AppCompatActivity() {
- // private final Random _random =new Random();
- // private static final String ALLOWED_CHARACTERS ="qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890";
- override fun onCreate(savedInstanceState: Bundle?) {
- super.onCreate(savedInstanceState)
- setContentView(R.layout.activity_main)
- contentEditText!!.addTextChangedListener(object : TextWatcher {
- override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {}
-
- override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {}
-
- override fun afterTextChanged(s: Editable) {
- recreateTextView()
- }
- })
- val seekBarChangeListener = object : OnSeekBarChangeListener {
- override fun onStopTrackingTouch(seekBar: SeekBar) {}
-
- override fun onStartTrackingTouch(seekBar: SeekBar) {}
-
- override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) {
- recreateTextView()
- }
- }
- heightSeekBar!!.setOnSeekBarChangeListener(seekBarChangeListener)
- widthSeekBar!!.setOnSeekBarChangeListener(seekBarChangeListener)
- findViewById(R.id.plusLineCountButton).setOnClickListener {
- var maxLinesCount = Integer.parseInt(linesCountTextView!!.text.toString())
- linesCountTextView!!.text = Integer.toString(++maxLinesCount)
- recreateTextView()
- }
- findViewById(R.id.minusLineCountButton).setOnClickListener(OnClickListener {
- var maxLinesCount = Integer.parseInt(linesCountTextView!!.text.toString())
- if (maxLinesCount == 1)
- return@OnClickListener
- linesCountTextView!!.text = Integer.toString(--maxLinesCount)
- recreateTextView()
- })
- runJustBeforeBeingDrawn(textViewContainer!!, Runnable { recreateTextView() })
-
-
- }
-
- protected fun recreateTextView() {
- textViewContainer!!.removeAllViews()
- val maxWidth = textViewContainer!!.width
- val maxHeight = textViewContainer!!.height
- val textView = AutoResizeTextView(this@MainActivity)
- textView.gravity = Gravity.CENTER
- val width = widthSeekBar!!.progress * maxWidth / widthSeekBar!!.max
- val height = heightSeekBar!!.progress * maxHeight / heightSeekBar!!.max
- val maxLinesCount = Integer.parseInt(linesCountTextView!!.text.toString())
- textView.maxLines = maxLinesCount
- textView.textSize = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, maxHeight.toFloat(), resources.displayMetrics)
- textView.ellipsize = TruncateAt.END
- // since we use it only once per each click, we don't need to cache the results, ever
- textView.layoutParams = LayoutParams(width, height)
- textView.setBackgroundColor(-0xff0100)
- val text = contentEditText!!.text.toString()
- textView.text = text
- textViewContainer!!.addView(textView)
- }
-
- // private String getRandomText()
- // {
- // final int textLength=_random.nextInt(20)+1;
- // final StringBuilder builder=new StringBuilder();
- // for(int i=0;i url = "https://play.google.com/store/apps/developer?id=AndroidDeveloperLB"
- R.id.menuItem_all_my_repositories -> url = "https://github.com/AndroidDeveloperLB"
- R.id.menuItem_current_repository_website -> url = "https://github.com/AndroidDeveloperLB/AutoFitTextView"
- R.id.menuItem_show_recyclerViewSample -> {
- startActivity(Intent(this, Main2Activity::class.java))
- return true
- }
- }
- if (url == null)
- return true
- val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
- intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY or Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET)
- intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_MULTIPLE_TASK)
- startActivity(intent)
- return true
- }
-
- companion object {
-
- fun runJustBeforeBeingDrawn(view: View, runnable: Runnable) {
- val preDrawListener = object : OnPreDrawListener {
- override fun onPreDraw(): Boolean {
- runnable.run()
- view.viewTreeObserver.removeOnPreDrawListener(this)
- return true
- }
- }
- view.viewTreeObserver.addOnPreDrawListener(preDrawListener)
- }
- }
-}
diff --git a/AutoFitTextViewSample/src/main/AndroidManifest.xml b/AutoFitTextViewSample/src/main/AndroidManifest.xml
new file mode 100644
index 0000000..411cb33
--- /dev/null
+++ b/AutoFitTextViewSample/src/main/AndroidManifest.xml
@@ -0,0 +1,20 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/AutoFitTextViewSample/src/main/kotlin/com/example/autofittextviewsample/Main2Activity.kt b/AutoFitTextViewSample/src/main/kotlin/com/example/autofittextviewsample/Main2Activity.kt
new file mode 100644
index 0000000..5350fbc
--- /dev/null
+++ b/AutoFitTextViewSample/src/main/kotlin/com/example/autofittextviewsample/Main2Activity.kt
@@ -0,0 +1,55 @@
+package com.example.autofittextviewsample
+
+import android.os.Bundle
+import android.view.LayoutInflater
+import android.view.View
+import android.view.ViewGroup
+import android.widget.TextView
+import androidx.activity.SystemBarStyle
+import androidx.activity.enableEdgeToEdge
+import androidx.appcompat.app.AppCompatActivity
+import androidx.core.view.ViewCompat
+import androidx.core.view.WindowInsetsCompat
+import androidx.recyclerview.widget.LinearLayoutManager
+import androidx.recyclerview.widget.RecyclerView
+import com.example.autofittextviewsample.databinding.ActivityMain2Binding
+import com.example.autofittextviewsample.databinding.ActivityMainBinding
+import com.lb.common_utils.BoundActivity
+
+class Main2Activity : BoundActivity(ActivityMain2Binding::inflate) {
+
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ enableEdgeToEdge(statusBarStyle = SystemBarStyle.dark(0))
+ ViewCompat.setOnApplyWindowInsetsListener(binding.appBarLayout) { v, insets ->
+ val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars() or WindowInsetsCompat.Type.displayCutout())
+ binding.appBarLayout.setPadding(systemBars.left, systemBars.top, systemBars.right, 0)
+ insets
+ }
+ setSupportActionBar(binding.toolbar)
+
+ binding.recyclerView.layoutManager = LinearLayoutManager(this)
+ binding.recyclerView.adapter = SampleAdapter()
+ }
+
+ private class SampleAdapter : RecyclerView.Adapter() {
+ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
+ val view = LayoutInflater.from(parent.context).inflate(R.layout.item, parent, false)
+ return ViewHolder(view)
+ }
+
+ override fun onBindViewHolder(holder: ViewHolder, position: Int) {
+ val sb = StringBuilder("item:")
+ for (i in 0..position) {
+ sb.append(position.toString())
+ }
+ holder.textView.text = sb.toString()
+ }
+
+ override fun getItemCount(): Int = 50
+ }
+
+ private class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
+ val textView: TextView = itemView.findViewById(android.R.id.text1)
+ }
+}
diff --git a/AutoFitTextViewSample/src/main/kotlin/com/example/autofittextviewsample/MainActivity.kt b/AutoFitTextViewSample/src/main/kotlin/com/example/autofittextviewsample/MainActivity.kt
new file mode 100644
index 0000000..3aab709
--- /dev/null
+++ b/AutoFitTextViewSample/src/main/kotlin/com/example/autofittextviewsample/MainActivity.kt
@@ -0,0 +1,146 @@
+package com.example.autofittextviewsample
+
+import android.content.Intent
+import android.os.Bundle
+import android.text.Editable
+import android.text.TextUtils.TruncateAt
+import android.text.TextWatcher
+import android.util.TypedValue
+import android.view.Gravity
+import android.view.Menu
+import android.view.MenuInflater
+import android.view.MenuItem
+import android.view.View
+import android.view.ViewGroup.LayoutParams
+import android.view.ViewTreeObserver.OnPreDrawListener
+import android.widget.SeekBar
+import android.widget.SeekBar.OnSeekBarChangeListener
+import androidx.activity.SystemBarStyle
+import androidx.activity.enableEdgeToEdge
+import androidx.appcompat.app.AppCompatActivity
+import androidx.core.content.ContextCompat.startActivity
+import androidx.core.net.toUri
+import androidx.core.view.MenuProvider
+import androidx.core.view.ViewCompat
+import androidx.core.view.WindowInsetsCompat
+import com.example.autofittextviewsample.databinding.ActivityMainBinding
+import com.lb.auto_fit_textview.AutoResizeTextView
+import com.lb.common_utils.BoundActivity
+
+class MainActivity : BoundActivity(ActivityMainBinding::inflate) {
+
+ override fun onCreate(savedInstanceState: Bundle?) {
+ super.onCreate(savedInstanceState)
+ enableEdgeToEdge(statusBarStyle = SystemBarStyle.dark(0))
+ ViewCompat.setOnApplyWindowInsetsListener(binding.appBarLayout) { v, insets ->
+ val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars() or WindowInsetsCompat.Type.displayCutout())
+ binding.appBarLayout.setPadding(systemBars.left, systemBars.top, systemBars.right, 0)
+ insets
+ }
+ setSupportActionBar(binding.toolbar)
+
+ binding.contentEditText.addTextChangedListener(object : TextWatcher {
+ override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {}
+ override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {}
+ override fun afterTextChanged(s: Editable) {
+ recreateTextView()
+ }
+ })
+
+ val seekBarChangeListener = object : OnSeekBarChangeListener {
+ override fun onStopTrackingTouch(seekBar: SeekBar) {}
+ override fun onStartTrackingTouch(seekBar: SeekBar) {}
+ override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) {
+ recreateTextView()
+ }
+ }
+ binding.heightSeekBar.setOnSeekBarChangeListener(seekBarChangeListener)
+ binding.widthSeekBar.setOnSeekBarChangeListener(seekBarChangeListener)
+
+ binding.plusLineCountButton.setOnClickListener {
+ var maxLinesCount = binding.linesCountTextView.text.toString().toInt()
+ binding.linesCountTextView.text = (++maxLinesCount).toString()
+ recreateTextView()
+ }
+
+ binding.minusLineCountButton.setOnClickListener {
+ var maxLinesCount = binding.linesCountTextView.text.toString().toInt()
+ if (maxLinesCount == 1) return@setOnClickListener
+ binding.linesCountTextView.text = (--maxLinesCount).toString()
+ recreateTextView()
+ }
+
+ runJustBeforeBeingDrawn(binding.textViewContainer) { recreateTextView() }
+
+ addMenuProvider(object : MenuProvider {
+ override fun onCreateMenu(menu: Menu, menuInflater: MenuInflater) {
+ menu.addSubMenu("More info").let { subMenu ->
+ subMenu.setIcon(android.R.drawable.ic_menu_info_details)
+ subMenu.item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS)
+ subMenu.add("show RecyclerView sample").setOnMenuItemClickListener {
+ startActivity(Intent(this@MainActivity, Main2Activity::class.java))
+ true
+ }
+ subMenu.add("Repository website").setOnMenuItemClickListener(
+ createUrlMenuItemClickListener("https://github.com/AndroidDeveloperLB/AutoFitTextView")
+ )
+ subMenu.add("All my repositories").setOnMenuItemClickListener(
+ createUrlMenuItemClickListener("https://github.com/AndroidDeveloperLB")
+ )
+ subMenu.add("All my apps").setOnMenuItemClickListener(
+ createUrlMenuItemClickListener("https://play.google.com/store/apps/developer?id=AndroidDeveloperLB")
+ )
+ }
+ }
+
+ private fun createUrlMenuItemClickListener(url: String): MenuItem.OnMenuItemClickListener {
+ return MenuItem.OnMenuItemClickListener {
+ val intent = Intent(Intent.ACTION_VIEW, url.toUri())
+ intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY or Intent.FLAG_ACTIVITY_NEW_DOCUMENT)
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_MULTIPLE_TASK)
+ startActivity(intent)
+ true
+ }
+ }
+
+ override fun onMenuItemSelected(item: MenuItem): Boolean = true
+ })
+ }
+
+ private fun recreateTextView() {
+ binding.textViewContainer.removeAllViews()
+ val maxWidth = binding.textViewContainer.width
+ val maxHeight = binding.textViewContainer.height
+ if (maxWidth <= 0 || maxHeight <= 0) return
+
+ val textView = AutoResizeTextView(this@MainActivity)
+ textView.gravity = Gravity.CENTER
+ val width = binding.widthSeekBar.progress * maxWidth / binding.widthSeekBar.max
+ val height = binding.heightSeekBar.progress * maxHeight / binding.heightSeekBar.max
+ val maxLinesCount = binding.linesCountTextView.text.toString().toInt()
+ textView.maxLines = maxLinesCount
+ textView.textSize = TypedValue.applyDimension(
+ TypedValue.COMPLEX_UNIT_SP,
+ maxHeight.toFloat(),
+ resources.displayMetrics
+ )
+ textView.ellipsize = TruncateAt.END
+ textView.layoutParams = LayoutParams(width, height)
+ textView.setBackgroundColor(-0xff0100)
+ textView.text = binding.contentEditText.text.toString()
+ binding.textViewContainer.addView(textView)
+ }
+
+ companion object {
+ fun runJustBeforeBeingDrawn(view: View, runnable: Runnable) {
+ val preDrawListener = object : OnPreDrawListener {
+ override fun onPreDraw(): Boolean {
+ runnable.run()
+ view.viewTreeObserver.removeOnPreDrawListener(this)
+ return true
+ }
+ }
+ view.viewTreeObserver.addOnPreDrawListener(preDrawListener)
+ }
+ }
+}
diff --git a/AutoFitTextViewSample/res/drawable-hdpi/ic_launcher.png b/AutoFitTextViewSample/src/main/res/drawable-hdpi/ic_launcher.png
similarity index 100%
rename from AutoFitTextViewSample/res/drawable-hdpi/ic_launcher.png
rename to AutoFitTextViewSample/src/main/res/drawable-hdpi/ic_launcher.png
diff --git a/AutoFitTextViewSample/res/drawable-mdpi/ic_launcher.png b/AutoFitTextViewSample/src/main/res/drawable-mdpi/ic_launcher.png
similarity index 100%
rename from AutoFitTextViewSample/res/drawable-mdpi/ic_launcher.png
rename to AutoFitTextViewSample/src/main/res/drawable-mdpi/ic_launcher.png
diff --git a/AutoFitTextViewSample/res/drawable-xhdpi/ic_launcher.png b/AutoFitTextViewSample/src/main/res/drawable-xhdpi/ic_launcher.png
similarity index 100%
rename from AutoFitTextViewSample/res/drawable-xhdpi/ic_launcher.png
rename to AutoFitTextViewSample/src/main/res/drawable-xhdpi/ic_launcher.png
diff --git a/AutoFitTextViewSample/res/drawable-xxhdpi/ic_launcher.png b/AutoFitTextViewSample/src/main/res/drawable-xxhdpi/ic_launcher.png
similarity index 100%
rename from AutoFitTextViewSample/res/drawable-xxhdpi/ic_launcher.png
rename to AutoFitTextViewSample/src/main/res/drawable-xxhdpi/ic_launcher.png
diff --git a/AutoFitTextViewSample/src/main/res/layout/activity_main.xml b/AutoFitTextViewSample/src/main/res/layout/activity_main.xml
new file mode 100644
index 0000000..968f139
--- /dev/null
+++ b/AutoFitTextViewSample/src/main/res/layout/activity_main.xml
@@ -0,0 +1,97 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/AutoFitTextViewSample/src/main/res/layout/activity_main2.xml b/AutoFitTextViewSample/src/main/res/layout/activity_main2.xml
new file mode 100644
index 0000000..6386c6c
--- /dev/null
+++ b/AutoFitTextViewSample/src/main/res/layout/activity_main2.xml
@@ -0,0 +1,26 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/AutoFitTextViewSample/res/layout/item.xml b/AutoFitTextViewSample/src/main/res/layout/item.xml
similarity index 100%
rename from AutoFitTextViewSample/res/layout/item.xml
rename to AutoFitTextViewSample/src/main/res/layout/item.xml
diff --git a/AutoFitTextViewSample/res/values-w820dp/dimens.xml b/AutoFitTextViewSample/src/main/res/values-w820dp/dimens.xml
similarity index 100%
rename from AutoFitTextViewSample/res/values-w820dp/dimens.xml
rename to AutoFitTextViewSample/src/main/res/values-w820dp/dimens.xml
diff --git a/AutoFitTextViewSample/res/values/dimens.xml b/AutoFitTextViewSample/src/main/res/values/dimens.xml
similarity index 100%
rename from AutoFitTextViewSample/res/values/dimens.xml
rename to AutoFitTextViewSample/src/main/res/values/dimens.xml
diff --git a/AutoFitTextViewSample/res/values/strings.xml b/AutoFitTextViewSample/src/main/res/values/strings.xml
similarity index 100%
rename from AutoFitTextViewSample/res/values/strings.xml
rename to AutoFitTextViewSample/src/main/res/values/strings.xml
diff --git a/AutoFitTextViewSample/src/main/res/values/themes.xml b/AutoFitTextViewSample/src/main/res/values/themes.xml
new file mode 100644
index 0000000..270bccc
--- /dev/null
+++ b/AutoFitTextViewSample/src/main/res/values/themes.xml
@@ -0,0 +1,3 @@
+
+
+
diff --git a/README.md b/README.md
index 0c028f2..b090553 100644
--- a/README.md
+++ b/README.md
@@ -3,39 +3,44 @@
AutoFitTextView
===============
-A TextView that automatically fit its font and line count based on its available size and content
+A TextView that automatically fits its font and line count based on its available size and content.
This code is heavily based on [**this StackOverflow thread**][1].
-The sample shows how the library can handle various parameters being changed on the TextView: width, height, number of lines allowed, and the content (text) itself. You can play with the various properties to see how the library handle them.
+The sample shows how the library handles various parameters being changed on the TextView: width, height, number of lines allowed, and the content (text) itself. You can play with the various properties to see how the library handles them.
-Note that even though the sample is of API 17, it should work fine on most cases for API 14 and above.
-
-A nice example of how to use an EditText that has this functionality can be found [here][4] (didn't test it, but it looks promising).
+Note: The library is updated to use Kotlin DSL, modern AndroidX libraries, and has a minimum SDK requirement of 21.
Preview
--
![preview animation][2]
-Import using Gradle
+Import using Gradle (Kotlin DSL)
--
- allprojects {
- repositories {
- ...
- maven { url "https://jitpack.io" }
- }
- }
-
- dependencies {
- compile 'com.github.AndroidDeveloperLB:AutoFitTextView:XXX'
- }
+Add JitPack to your `settings.gradle.kts`:
-You can find recent version here (replace XXX):
+```kotlin
+dependencyResolutionManagement {
+ repositories {
+ ...
+ maven { url = uri("https://jitpack.io") }
+ }
+}
+```
-https://jitpack.io/#AndroidDeveloperLB/AutoFitTextView
+Add the dependency to your module `build.gradle.kts`:
+
+```kotlin
+dependencies {
+ implementation("com.github.AndroidDeveloperLB:AutoFitTextView:XXX")
+}
+```
+You can find the recent version here (replace XXX):
+
+https://jitpack.io/#AndroidDeveloperLB/AutoFitTextView
- [1]: http://stackoverflow.com/questions/16017165/auto-fit-textview-for-android/21851239
- [2]: https://raw.githubusercontent.com/AndroidDeveloperLB/AutoFitTextView/master/animationPreview.gif
- [4]: https://viksaaskool.wordpress.com/2014/11/16/using-auto-resize-to-fit-edittext-in-android/
+[1]: http://stackoverflow.com/questions/16017165/auto-fit-textview-for-android/21851239
+[2]: https://raw.githubusercontent.com/AndroidDeveloperLB/AutoFitTextView/master/animationPreview.gif
+[4]: https://viksaaskool.wordpress.com/2014/11/16/using-auto-resize-to-fit-edittext-in-android/
diff --git a/build.gradle b/build.gradle
deleted file mode 100644
index 3ca9435..0000000
--- a/build.gradle
+++ /dev/null
@@ -1,23 +0,0 @@
-// Top-level build file where you can add configuration options common to all sub-projects/modules.
-
-buildscript {
- ext.kotlin_version = '1.3.21'
- repositories {
- jcenter()
- google()
- }
- dependencies {
- classpath 'com.android.tools.build:gradle:3.3.1'
- classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
-
- // NOTE: Do not place your application dependencies here; they belong
- // in the individual module build.gradle files
- }
-}
-
-allprojects {
- repositories {
- jcenter()
- google()
- }
-}
diff --git a/build.gradle.kts b/build.gradle.kts
new file mode 100644
index 0000000..7e9eafc
--- /dev/null
+++ b/build.gradle.kts
@@ -0,0 +1,11 @@
+// Top-level build file where you can add configuration options common to all sub-projects/modules.
+
+plugins {
+ id("com.android.application") version "9.0.1" apply false
+ id("com.android.library") version "9.0.1" apply false
+}
+
+//allprojects {
+// group = findProperty("group") ?: "com.github.AndroidDeveloperLB"
+// version = findProperty("version") ?: "1.0.0"
+//}
diff --git a/gradle.properties b/gradle.properties
index e956ceb..22941a3 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -1,20 +1,27 @@
# Project-wide Gradle settings.
-
# IDE (e.g. Android Studio) users:
-# Settings specified in this file will override any Gradle settings
-# configured through the IDE.
-
+# Gradle settings configured through the IDE *will override*
+# any settings specified in this file.
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
-
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
-# Default value: -Xmx10248m -XX:MaxPermSize=256m
-# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
-
+org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
# When configured, Gradle will run in incubating parallel mode.
-# This option should only be used with decoupled projects. More details, visit
-# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
+# This option should only be used with decoupled projects. For more details, visit
+# https://developer.android.com/r/tools/gradle-multi-project-decoupled-projects
# org.gradle.parallel=true
-android.enableJetifier=true
+# AndroidX package structure to make it clearer which packages are bundled with the
+# Android operating system, and which are packaged with your app's APK
+# https://developer.android.com/topic/libraries/support-library/androidx-rn
android.useAndroidX=true
+# Kotlin code style for this project: "official" or "obsolete":
+kotlin.code.style=obsolete
+# Enables namespacing of each library's R class so that its R class includes only the
+# resources declared in the library itself and none from the library's dependencies,
+# thereby reducing the size of the R class for that library
+android.nonTransitiveRClass=true
+org.gradle.configuration-cache=true
+
+#https://dev.to/cdsap/gradle-811-faster-configuration-cache-and-improved-configuration-time-ja1
+org.gradle.configuration-cache.parallel=true
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index 8fdd95f..6fccdf5 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -1,6 +1,6 @@
-#Wed Feb 06 23:21:12 IST 2019
+#Tue Nov 18 00:41:16 IST 2025
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
+distributionUrl=https\://services.gradle.org/distributions/gradle-9.3.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
diff --git a/settings.gradle b/settings.gradle
deleted file mode 100644
index 2e8e233..0000000
--- a/settings.gradle
+++ /dev/null
@@ -1,2 +0,0 @@
-include ':AutoFitTextViewLibrary'
-include ':AutoFitTextViewSample'
diff --git a/settings.gradle.kts b/settings.gradle.kts
new file mode 100644
index 0000000..b875f85
--- /dev/null
+++ b/settings.gradle.kts
@@ -0,0 +1,18 @@
+pluginManagement {
+ repositories {
+ google()
+ mavenCentral()
+ gradlePluginPortal()
+ }
+}
+dependencyResolutionManagement {
+ repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
+ repositories {
+ google()
+ mavenCentral()
+ maven { url = uri("https://jitpack.io") }
+ }
+}
+rootProject.name = "AutoFitTextView"
+include(":AutoFitTextViewLibrary")
+include(":AutoFitTextViewSample")