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 @@ + 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 @@ - - - - - - -