diff --git a/.idea/.name b/.idea/.name
deleted file mode 100644
index 088f47a..0000000
--- a/.idea/.name
+++ /dev/null
@@ -1 +0,0 @@
-AutoFitTextView
\ No newline at end of file
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/build_file_checksums.ser b/.idea/caches/build_file_checksums.ser
new file mode 100644
index 0000000..da027ce
Binary files /dev/null and b/.idea/caches/build_file_checksums.ser differ
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/codeStyles/Project.xml b/.idea/codeStyles/Project.xml
new file mode 100644
index 0000000..30aa626
--- /dev/null
+++ b/.idea/codeStyles/Project.xml
@@ -0,0 +1,29 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/compiler.xml b/.idea/compiler.xml
index 96cc43e..b589d56 100644
--- a/.idea/compiler.xml
+++ b/.idea/compiler.xml
@@ -1,22 +1,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
\ No newline at end of file
diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml
deleted file mode 100644
index e7bedf3..0000000
--- a/.idea/copyright/profiles_settings.xml
+++ /dev/null
@@ -1,3 +0,0 @@
-
-
-
\ 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 6b57537..aa64d09 100644
--- a/.idea/gradle.xml
+++ b/.idea/gradle.xml
@@ -1,11 +1,12 @@
+
-
+
-
+
@@ -13,13 +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 7158618..1a05895 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -1,62 +1,25 @@
-
-
-
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
-
+
-
-
-
-
- 1.8
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
deleted file mode 100644
index bbe1567..0000000
--- a/.idea/modules.xml
+++ /dev/null
@@ -1,13 +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 0bb8452..0000000
--- a/AutoFitTextViewLibrary/AndroidManifest.xml
+++ /dev/null
@@ -1,7 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/AutoFitTextViewLibrary/build.gradle b/AutoFitTextViewLibrary/build.gradle
deleted file mode 100644
index 75fb3fa..0000000
--- a/AutoFitTextViewLibrary/build.gradle
+++ /dev/null
@@ -1,34 +0,0 @@
-apply plugin: 'com.android.library'
-
-android {
- compileSdkVersion 23
- buildToolsVersion "23.0.1"
-
- defaultConfig {
- minSdkVersion 15
- targetSdkVersion 23
- 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
- }
- }
-}
-
-dependencies {
-}
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 93c8c3c..0000000
--- a/AutoFitTextViewLibrary/project.properties
+++ /dev/null
@@ -1,15 +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/com/lb/auto_fit_textview/AutoResizeTextView.java b/AutoFitTextViewLibrary/src/com/lb/auto_fit_textview/AutoResizeTextView.java
deleted file mode 100644
index 990f010..0000000
--- a/AutoFitTextViewLibrary/src/com/lb/auto_fit_textview/AutoResizeTextView.java
+++ /dev/null
@@ -1,242 +0,0 @@
-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;
-import android.text.Layout.Alignment;
-import android.text.StaticLayout;
-import android.text.TextPaint;
-import android.util.AttributeSet;
-import android.util.TypedValue;
-import android.widget.TextView;
-
-/**
- * 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
- */
-public class AutoResizeTextView extends TextView {
- private static final int NO_LINE_LIMIT = -1;
- private final RectF _availableSpaceRect = new RectF();
- private final SizeTester _sizeTester;
- private float _maxTextSize,_spacingMult = 1.0f, _spacingAdd = 0.0f, _minTextSize;
- private int _widthLimit, _maxLines;
- private boolean _initialized = false;
- private TextPaint _paint;
-
- private interface SizeTester {
- /**
- * @param suggestedSize Size of text to be tested
- * @param availableSpace available space in which text must fit
- * @return an integer < 0 if after applying {@code suggestedSize} to
- * text, it takes less space than {@code availableSpace}, > 0
- * otherwise
- */
- int onTestSize(int suggestedSize, RectF availableSpace);
- }
-
- public AutoResizeTextView(final Context context) {
- this(context, null, 0);
- }
-
- public AutoResizeTextView(final Context context, final AttributeSet attrs) {
- this(context, attrs, 0);
- }
-
- public AutoResizeTextView(final Context context, final AttributeSet attrs, final int defStyle) {
- super(context, attrs, defStyle);
-
- // using the minimal recommended font size
- _minTextSize = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 12, getResources().getDisplayMetrics());
- _maxTextSize = getTextSize();
- _paint = new TextPaint(getPaint());
- if (_maxLines == 0)
- // no value was assigned during construction
- _maxLines = NO_LINE_LIMIT;
- // prepare size tester:
- _sizeTester = new SizeTester() {
- final RectF textRect = new RectF();
-
- @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
- @Override
- public int onTestSize(final int suggestedSize, final RectF availableSPace) {
- _paint.setTextSize(suggestedSize);
- final TransformationMethod transformationMethod = getTransformationMethod();
- final String text;
- if (transformationMethod != null)
- text = transformationMethod.getTransformation(getText(), AutoResizeTextView.this).toString();
- else
- text = getText().toString();
-
- final boolean singleLine = getMaxLines() == 1;
- if (singleLine) {
- textRect.bottom = _paint.getFontSpacing();
- textRect.right = _paint.measureText(text);
- } else {
- final StaticLayout layout = new StaticLayout(text, _paint, _widthLimit, Alignment.ALIGN_NORMAL, _spacingMult, _spacingAdd, true);
- // return early if we have more lines
- if (getMaxLines() != NO_LINE_LIMIT && layout.getLineCount() > getMaxLines())
- return 1;
- textRect.bottom = layout.getHeight();
- int maxWidth = -1;
- 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;
- }
- textRect.offsetTo(0, 0);
- if (availableSPace.contains(textRect))
- // may be too small, don't worry we will find the best match
- return -1;
- // else, too big
- return 1;
- }
- };
- _initialized = true;
- }
-
- @Override
- public void setAllCaps(boolean allCaps) {
- super.setAllCaps(allCaps);
- adjustTextSize();
- }
-
- @Override
- public void setTypeface(final Typeface tf) {
- super.setTypeface(tf);
- adjustTextSize();
- }
-
- @Override
- public void setTextSize(final float size) {
- _maxTextSize = size;
- adjustTextSize();
- }
-
- @Override
- public void setMaxLines(final int maxlines) {
- super.setMaxLines(maxlines);
- _maxLines = maxlines;
- adjustTextSize();
- }
-
- @Override
- public int getMaxLines() {
- return _maxLines;
- }
-
- @Override
- public void setSingleLine() {
- super.setSingleLine();
- _maxLines = 1;
- adjustTextSize();
- }
-
- @Override
- public void setSingleLine(final boolean singleLine) {
- super.setSingleLine(singleLine);
- if (singleLine)
- _maxLines = 1;
- else _maxLines = NO_LINE_LIMIT;
- adjustTextSize();
- }
-
- @Override
- public void setLines(final int lines) {
- super.setLines(lines);
- _maxLines = lines;
- adjustTextSize();
- }
-
- @Override
- public void setTextSize(final int unit, final float size) {
- final Context c = getContext();
- Resources r;
- if (c == null)
- r = Resources.getSystem();
- else r = c.getResources();
- _maxTextSize = TypedValue.applyDimension(unit, size, r.getDisplayMetrics());
- adjustTextSize();
- }
-
- @Override
- public void setLineSpacing(final float add, final float mult) {
- super.setLineSpacing(add, mult);
- _spacingMult = mult;
- _spacingAdd = add;
- }
-
- /**
- * Set the lower text size limit and invalidate the view
- *
- * @param minTextSize
- */
- public void setMinTextSize(final float minTextSize) {
- _minTextSize = minTextSize;
- adjustTextSize();
- }
-
- private void 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;
- final int startSize = (int) _minTextSize;
- final int heightLimit = getMeasuredHeight() - getCompoundPaddingBottom() - getCompoundPaddingTop();
- _widthLimit = getMeasuredWidth() - getCompoundPaddingLeft() - getCompoundPaddingRight();
- if (_widthLimit <= 0)
- return;
- _paint = new TextPaint(getPaint());
- _availableSpaceRect.right = _widthLimit;
- _availableSpaceRect.bottom = heightLimit;
- superSetTextSize(startSize);
-// }
-// });
- }
-
- private void superSetTextSize(int startSize) {
- int textSize = binarySearch(startSize, (int) _maxTextSize, _sizeTester, _availableSpaceRect);
- super.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
- }
-
- private int binarySearch(final int start, final int end, final SizeTester sizeTester, final RectF availableSpace) {
- int lastBest = start, lo = start, hi = end - 1, mid;
- while (lo <= hi) {
- mid = lo + hi >>> 1;
- final int midValCmp = sizeTester.onTestSize(mid, availableSpace);
- if (midValCmp < 0) {
- lastBest = lo;
- lo = mid + 1;
- } else if (midValCmp > 0) {
- hi = mid - 1;
- lastBest = hi;
- } else return mid;
- }
- // make sure to return last best
- // this is what should always be returned
- return lastBest;
- }
-
- @Override
- protected void onTextChanged(final CharSequence text, final int start, final int before, final int after) {
- super.onTextChanged(text, start, before, after);
- adjustTextSize();
- }
-
- @Override
- protected void onSizeChanged(final int width, final int height, final int oldwidth, final int oldheight) {
- super.onSizeChanged(width, height, oldwidth, oldheight);
- if (width != oldwidth || height != oldheight)
- adjustTextSize();
- }
-}
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/main/kotlin/com/lb/auto_fit_textview/AutoResizeTextView.kt b/AutoFitTextViewLibrary/src/main/kotlin/com/lb/auto_fit_textview/AutoResizeTextView.kt
new file mode 100644
index 0000000..7dfd413
--- /dev/null
+++ b/AutoFitTextViewLibrary/src/main/kotlin/com/lb/auto_fit_textview/AutoResizeTextView.kt
@@ -0,0 +1,215 @@
+package com.lb.auto_fit_textview
+
+import android.content.Context
+import android.graphics.RectF
+import android.graphics.Typeface
+import android.os.Build
+import android.text.Layout.Alignment
+import android.text.StaticLayout
+import android.text.TextPaint
+import android.util.AttributeSet
+import android.util.TypedValue
+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
+ */
+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 = 0f
+ private var spacingMult = 1.0f
+ private var spacingAdd = 0.0f
+ private var minTextSize: Float = 0f
+ private var widthLimit: Int = 0
+ private var maxLinesValue: Int = -1
+ private var initialized = false
+ private var textPaint: TextPaint
+
+ private interface SizeTester {
+ /**
+ * @param suggestedSize Size of text to be tested
+ * @param availableSpace available space in which text must fit
+ * @return an integer < 0 if after applying `suggestedSize` to
+ * text, it takes less space than `availableSpace`, > 0
+ * otherwise
+ */
+ fun onTestSize(suggestedSize: Int, availableSpace: RectF): Int
+ }
+
+ init {
+ // using the minimal recommended font size
+ minTextSize = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 12f, resources.displayMetrics)
+ maxTextSize = textSize
+ textPaint = TextPaint(paint)
+ maxLinesValue = maxLines
+
+ // prepare size tester:
+ sizeTester = object : SizeTester {
+ val textRect = RectF()
+
+ override fun onTestSize(suggestedSize: Int, availableSpace: RectF): Int {
+ textPaint.textSize = suggestedSize.toFloat()
+ val transformationMethod = transformationMethod
+ 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(textToTest)
+ } else {
+ val layout: StaticLayout = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
+ 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 (maxLinesValue != NO_LINE_LIMIT && layout.lineCount > maxLinesValue)
+ return 1
+ textRect.bottom = layout.height.toFloat()
+ 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(textToTest[end - 1]))
+ return 1
+ val lineWidth = layout.getLineRight(i) - layout.getLineLeft(i)
+ if (maxWidth < lineWidth)
+ maxWidth = lineWidth
+ }
+ textRect.right = maxWidth
+ }
+ textRect.offsetTo(0f, 0f)
+ return if (availableSpace.contains(textRect)) -1 else 1
+ }
+ }
+ initialized = true
+ }
+
+ private fun isValidWordWrap(c: Char): Boolean = c == ' ' || c == '-'
+
+ override fun setAllCaps(allCaps: Boolean) {
+ super.setAllCaps(allCaps)
+ adjustTextSize()
+ }
+
+ override fun setTypeface(tf: Typeface?) {
+ super.setTypeface(tf)
+ adjustTextSize()
+ }
+
+ override fun setTextSize(size: Float) {
+ maxTextSize = size
+ adjustTextSize()
+ }
+
+ override fun setMaxLines(maxLines: Int) {
+ super.setMaxLines(maxLines)
+ this.maxLinesValue = maxLines
+ adjustTextSize()
+ }
+
+ override fun getMaxLines(): Int = maxLinesValue
+
+ @Deprecated("Deprecated in Java", ReplaceWith("maxLines = 1"))
+ override fun setSingleLine() {
+ @Suppress("DEPRECATION")
+ super.setSingleLine()
+ maxLinesValue = 1
+ adjustTextSize()
+ }
+
+ @Deprecated("Deprecated in Java", ReplaceWith("maxLines = if (singleLine) 1 else -1"))
+ override fun setSingleLine(singleLine: Boolean) {
+ @Suppress("DEPRECATION")
+ super.setSingleLine(singleLine)
+ maxLinesValue = if (singleLine) 1 else NO_LINE_LIMIT
+ adjustTextSize()
+ }
+
+ override fun setLines(lines: Int) {
+ super.setLines(lines)
+ maxLinesValue = lines
+ adjustTextSize()
+ }
+
+ override fun setTextSize(unit: Int, size: Float) {
+ maxTextSize = TypedValue.applyDimension(unit, size, context.resources.displayMetrics)
+ adjustTextSize()
+ }
+
+ override fun setLineSpacing(add: Float, mult: Float) {
+ super.setLineSpacing(add, mult)
+ spacingMult = mult
+ spacingAdd = add
+ }
+
+ /**
+ * Set the lower text size limit and invalidate the view
+ */
+ fun setMinTextSize(minTextSize: Float) {
+ this.minTextSize = minTextSize
+ adjustTextSize()
+ }
+
+ private fun adjustTextSize() {
+ if (!initialized) return
+ val startSize = minTextSize.toInt()
+ val heightLimit = measuredHeight - compoundPaddingBottom - compoundPaddingTop
+ widthLimit = measuredWidth - compoundPaddingLeft - compoundPaddingRight
+ if (widthLimit <= 0) return
+ textPaint = TextPaint(paint)
+ availableSpaceRect.right = widthLimit.toFloat()
+ availableSpaceRect.bottom = heightLimit.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 {
+ var lastBest = start
+ var lo = start
+ var hi = end - 1
+ var mid: Int
+ while (lo <= hi) {
+ mid = (lo + hi).ushr(1)
+ val midValCmp = sizeTester.onTestSize(mid, availableSpace)
+ if (midValCmp < 0) {
+ lastBest = mid
+ lo = mid + 1
+ } else if (midValCmp > 0) {
+ hi = mid - 1
+ } else {
+ return mid
+ }
+ }
+ return lastBest
+ }
+
+ override fun onTextChanged(text: CharSequence, start: Int, before: Int, after: Int) {
+ super.onTextChanged(text, start, before, after)
+ adjustTextSize()
+ }
+
+ override fun onSizeChanged(width: Int, height: Int, oldwidth: Int, oldheight: Int) {
+ super.onSizeChanged(width, height, oldwidth, oldheight)
+ if (width != oldwidth || height != oldheight)
+ adjustTextSize()
+ }
+
+ companion object {
+ 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 14fd1b8..0000000
--- a/AutoFitTextViewSample/AndroidManifest.xml
+++ /dev/null
@@ -1,23 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/AutoFitTextViewSample/build.gradle b/AutoFitTextViewSample/build.gradle
deleted file mode 100644
index a52b956..0000000
--- a/AutoFitTextViewSample/build.gradle
+++ /dev/null
@@ -1,38 +0,0 @@
-apply plugin: 'com.android.application'
-
-android {
- compileSdkVersion 22
- buildToolsVersion "23.0.1"
-
- defaultConfig {
- applicationId "com.example.autofittextviewsample"
- minSdkVersion 16
- targetSdkVersion 23
- 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']
- }
- }
-
-}
-
-dependencies {
- compile fileTree(dir: 'libs', include: ['*.jar'])
-
- compile project(':AutoFitTextViewLibrary')
-}
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/libs/android-support-v4.jar b/AutoFitTextViewSample/libs/android-support-v4.jar
deleted file mode 100644
index 187bdf4..0000000
Binary files a/AutoFitTextViewSample/libs/android-support-v4.jar and /dev/null differ
diff --git a/AutoFitTextViewSample/lint.xml b/AutoFitTextViewSample/lint.xml
deleted file mode 100644
index ee0eead..0000000
--- a/AutoFitTextViewSample/lint.xml
+++ /dev/null
@@ -1,3 +0,0 @@
-
-
-
\ No newline at end of file
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 f5fc260..0000000
--- a/AutoFitTextViewSample/project.properties
+++ /dev/null
@@ -1,15 +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 167857f..0000000
--- a/AutoFitTextViewSample/res/layout/activity_main.xml
+++ /dev/null
@@ -1,112 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/AutoFitTextViewSample/res/menu/main.xml b/AutoFitTextViewSample/res/menu/main.xml
deleted file mode 100644
index fee5ca0..0000000
--- a/AutoFitTextViewSample/res/menu/main.xml
+++ /dev/null
@@ -1,19 +0,0 @@
-
-
\ No newline at end of file
diff --git a/AutoFitTextViewSample/res/values/strings.xml b/AutoFitTextViewSample/res/values/strings.xml
deleted file mode 100644
index d66c73d..0000000
--- a/AutoFitTextViewSample/res/values/strings.xml
+++ /dev/null
@@ -1,12 +0,0 @@
-
-
-
- AutoFitTextViewSample
- Settings
- Repository website
- All my repositories
- All my apps
- More info
- Randomize
-
-
diff --git a/AutoFitTextViewSample/src/com/example/autofittextviewsample/MainActivity.java b/AutoFitTextViewSample/src/com/example/autofittextviewsample/MainActivity.java
deleted file mode 100644
index c7bfcea..0000000
--- a/AutoFitTextViewSample/src/com/example/autofittextviewsample/MainActivity.java
+++ /dev/null
@@ -1,185 +0,0 @@
-package com.example.autofittextviewsample;
-import android.app.Activity;
-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;
-import android.view.ViewGroup.LayoutParams;
-import android.view.ViewTreeObserver.OnPreDrawListener;
-import android.widget.EditText;
-import android.widget.SeekBar;
-import android.widget.SeekBar.OnSeekBarChangeListener;
-import android.widget.TextView;
-import com.lb.auto_fit_textview.AutoResizeTextView;
-
-public class MainActivity extends Activity
- {
- // private final Random _random =new Random();
- // private static final String ALLOWED_CHARACTERS ="qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890";
- private EditText _contentEditText;
- private ViewGroup _textViewcontainer;
- private SeekBar _widthSeekBar;
- private SeekBar _heightSeekBar;
- private TextView _linesCountTextView;
-
- @Override
- protected void onCreate(final Bundle savedInstanceState)
- {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- _textViewcontainer=(ViewGroup)findViewById(R.id.container);
- _contentEditText=(EditText)findViewById(R.id.contentEditText);
- _contentEditText.addTextChangedListener(new TextWatcher()
- {
- @Override
- public void onTextChanged(final CharSequence s,final int start,final int before,final int count)
- {}
-
- @Override
- public void beforeTextChanged(final CharSequence s,final int start,final int count,final int after)
- {}
-
- @Override
- public void afterTextChanged(final Editable s)
- {
- recreateTextView();
- }
- });
- _widthSeekBar=(SeekBar)findViewById(R.id.widthSeekBar);
- _heightSeekBar=(SeekBar)findViewById(R.id.heightSeekBar);
- final OnSeekBarChangeListener seekBarChangeListener=new OnSeekBarChangeListener()
- {
- @Override
- public void onStopTrackingTouch(final SeekBar seekBar)
- {}
-
- @Override
- public void onStartTrackingTouch(final SeekBar seekBar)
- {}
-
- @Override
- public void onProgressChanged(final SeekBar seekBar,final int progress,final boolean fromUser)
- {
- recreateTextView();
- }
- };
- _heightSeekBar.setOnSeekBarChangeListener(seekBarChangeListener);
- _widthSeekBar.setOnSeekBarChangeListener(seekBarChangeListener);
- _linesCountTextView=(TextView)findViewById(R.id.linesCountTextView);
- findViewById(R.id.plusLineCountButton).setOnClickListener(new OnClickListener()
- {
- @Override
- public void onClick(final View v)
- {
- int maxLinesCount=Integer.parseInt(_linesCountTextView.getText().toString());
- _linesCountTextView.setText(Integer.toString(++maxLinesCount));
- recreateTextView();
- }
- });
- findViewById(R.id.minusLineCountButton).setOnClickListener(new OnClickListener()
- {
- @Override
- public void onClick(final View v)
- {
- int maxLinesCount=Integer.parseInt(_linesCountTextView.getText().toString());
- if(maxLinesCount==1)
- return;
- _linesCountTextView.setText(Integer.toString(--maxLinesCount));
- recreateTextView();
- }
- });
- runJustBeforeBeingDrawn(_textViewcontainer,new Runnable()
- {
- @Override
- public void run()
- {
- recreateTextView();
- }
- });
- }
-
- protected void recreateTextView()
- {
- _textViewcontainer.removeAllViews();
- final int maxWidth=_textViewcontainer.getWidth();
- final int maxHeight=_textViewcontainer.getHeight();
- final AutoResizeTextView textView=new AutoResizeTextView(MainActivity.this);
- textView.setGravity(Gravity.CENTER);
- final int width=_widthSeekBar.getProgress()*maxWidth/_widthSeekBar.getMax();
- final int height=_heightSeekBar.getProgress()*maxHeight/_heightSeekBar.getMax();
- final int maxLinesCount=Integer.parseInt(_linesCountTextView.getText().toString());
- textView.setMaxLines(maxLinesCount);
- textView.setTextSize(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP,maxHeight,getResources().getDisplayMetrics()));
- textView.setEllipsize(TruncateAt.END);
- // since we use it only once per each click, we don't need to cache the results, ever
- textView.setLayoutParams(new LayoutParams(width,height));
- textView.setBackgroundColor(0xff00ff00);
- final String text=_contentEditText.getText().toString();
- textView.setText(text);
- _textViewcontainer.addView(textView);
- }
-
- // private String getRandomText()
- // {
- // final int textLength=_random.nextInt(20)+1;
- // final StringBuilder builder=new StringBuilder();
- // for(int i=0;i
+
+
+
+
+
+
+
+
+
+
+
+
+
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/src/main/res/layout/item.xml b/AutoFitTextViewSample/src/main/res/layout/item.xml
new file mode 100644
index 0000000..9464b5c
--- /dev/null
+++ b/AutoFitTextViewSample/src/main/res/layout/item.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
diff --git a/AutoFitTextViewSample/src/main/res/values-w820dp/dimens.xml b/AutoFitTextViewSample/src/main/res/values-w820dp/dimens.xml
new file mode 100644
index 0000000..1e656d6
--- /dev/null
+++ b/AutoFitTextViewSample/src/main/res/values-w820dp/dimens.xml
@@ -0,0 +1,6 @@
+
+
+ 64dp
+
diff --git a/AutoFitTextViewSample/src/main/res/values/dimens.xml b/AutoFitTextViewSample/src/main/res/values/dimens.xml
new file mode 100644
index 0000000..acf94cc
--- /dev/null
+++ b/AutoFitTextViewSample/src/main/res/values/dimens.xml
@@ -0,0 +1,5 @@
+
+
+ 16dp
+ 16dp
+
diff --git a/AutoFitTextViewSample/src/main/res/values/strings.xml b/AutoFitTextViewSample/src/main/res/values/strings.xml
new file mode 100644
index 0000000..5aa598d
--- /dev/null
+++ b/AutoFitTextViewSample/src/main/res/values/strings.xml
@@ -0,0 +1,5 @@
+
+
+ AutoFitTextViewSample
+ Randomize
+
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 f82c7ef..b090553 100644
--- a/README.md
+++ b/README.md
@@ -1,30 +1,46 @@
+[](https://jitpack.io/#AndroidDeveloperLB/AutoFitTextView)
+
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.
-
-Note that even though the sample is of API 16, it should work fine on most cases for much older versions.
+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.
-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]
-Known issues
-------------
+Import using Gradle (Kotlin DSL)
+--
+
+Add JitPack to your `settings.gradle.kts`:
+
+```kotlin
+dependencyResolutionManagement {
+ repositories {
+ ...
+ maven { url = uri("https://jitpack.io") }
+ }
+}
+```
+
+Add the dependency to your module `build.gradle.kts`:
- - API 12-15 (including) of Android might have issues as a cause of [**this known bug**][3], but in most cases it should work fine there too.
-
- - On very rare cases, the last character of a line goes to the next line. If you know how to fix it, please write down about it.
+```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
- [3]: https://code.google.com/p/android/issues/detail?id=22493
- [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 c6371d6..0000000
--- a/build.gradle
+++ /dev/null
@@ -1,19 +0,0 @@
-// Top-level build file where you can add configuration options common to all sub-projects/modules.
-
-buildscript {
- repositories {
- jcenter()
- }
- dependencies {
- classpath 'com.android.tools.build:gradle:1.3.1'
-
- // NOTE: Do not place your application dependencies here; they belong
- // in the individual module build.gradle files
- }
-}
-
-allprojects {
- repositories {
- jcenter()
- }
-}
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 34fb461..22941a3 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -1,18 +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
+# 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 e73669a..6fccdf5 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -1,6 +1,6 @@
-#Sun Dec 07 23:08:08 PST 2014
+#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-2.2.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")