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/gradle.xml b/.idea/gradle.xml index b17f342..d3fcd3d 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -1,8 +1,10 @@ + 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/misc.xml b/.idea/misc.xml index b8ca955..8a3577b 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,5 +1,9 @@ + + + + @@ -12,7 +16,7 @@ - + diff --git a/.idea/modules.xml b/.idea/modules.xml index d36b263..3b2e0a9 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -2,9 +2,15 @@ - - - + + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml deleted file mode 100644 index 7f68460..0000000 --- a/.idea/runConfigurations.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/AutoFitTextViewLibrary/build.gradle b/AutoFitTextViewLibrary/build.gradle index 413cb76..c3f1f43 100644 --- a/AutoFitTextViewLibrary/build.gradle +++ b/AutoFitTextViewLibrary/build.gradle @@ -1,15 +1,12 @@ apply plugin: 'com.android.library' -apply plugin: 'kotlin-android-extensions' apply plugin: 'kotlin-android' android { - compileSdkVersion 28 + compileSdkVersion 33 defaultConfig { minSdkVersion 14 - targetSdkVersion 28 - versionCode 1 - versionName "1.0" + targetSdkVersion 33 } sourceSets { @@ -30,15 +27,17 @@ android { } } compileOptions { - sourceCompatibility = '1.8' - targetCompatibility = '1.8' + sourceCompatibility JavaVersion.VERSION_11 + targetCompatibility JavaVersion.VERSION_11 + } + kotlinOptions { + jvmTarget = "11" } } 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" + implementation 'androidx.appcompat:appcompat:1.5.1' + implementation "androidx.core:core-ktx:1.9.0" } repositories { mavenCentral() diff --git a/AutoFitTextViewLibrary/project.properties b/AutoFitTextViewLibrary/project.properties index e195e98..c46ed69 100644 --- a/AutoFitTextViewLibrary/project.properties +++ b/AutoFitTextViewLibrary/project.properties @@ -10,5 +10,3 @@ # 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.kt b/AutoFitTextViewLibrary/src/com/lb/auto_fit_textview/AutoResizeTextView.kt index 1e72576..8a882c8 100644 --- a/AutoFitTextViewLibrary/src/com/lb/auto_fit_textview/AutoResizeTextView.kt +++ b/AutoFitTextViewLibrary/src/com/lb/auto_fit_textview/AutoResizeTextView.kt @@ -30,7 +30,7 @@ class AutoResizeTextView @JvmOverloads constructor(context: Context, attrs: Attr private var widthLimit: Int = 0 private var maxLines: Int = 0 private var initialized = false - private var textPaint: TextPaint? = null + private var textPaint: TextPaint private interface SizeTester { /** @@ -43,6 +43,8 @@ class AutoResizeTextView @JvmOverloads constructor(context: Context, attrs: Attr fun onTestSize(suggestedSize: Int, availableSpace: RectF): Int } + + init { // using the minimal recommended font size minTextSize = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 12f, resources.displayMetrics) @@ -53,24 +55,22 @@ class AutoResizeTextView @JvmOverloads constructor(context: Context, attrs: Attr maxLines = NO_LINE_LIMIT // 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 text: String = transformationMethod?.getTransformation(text, this@AutoResizeTextView) + ?.toString() + ?: text.toString() val singleLine = maxLines == 1 if (singleLine) { - textRect.bottom = textPaint!!.fontSpacing - textRect.right = textPaint!!.measureText(text) + textRect.bottom = textPaint.fontSpacing + textRect.right = textPaint.measureText(text) } 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() + 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) // return early if we have more lines if (maxLines != NO_LINE_LIMIT && layout.lineCount > maxLines) @@ -135,10 +135,10 @@ class AutoResizeTextView @JvmOverloads constructor(context: Context, attrs: Attr override fun setSingleLine(singleLine: Boolean) { super.setSingleLine(singleLine) - if (singleLine) - maxLines = 1 + maxLines = if (singleLine) + 1 else - maxLines = NO_LINE_LIMIT + NO_LINE_LIMIT adjustTextSize() } @@ -150,8 +150,7 @@ class AutoResizeTextView @JvmOverloads constructor(context: Context, attrs: Attr override fun setTextSize(unit: Int, size: Float) { val c = context - val r: Resources - r = if (c == null) + val r: Resources = if (c == null) Resources.getSystem() else c.resources @@ -167,9 +166,8 @@ class AutoResizeTextView @JvmOverloads constructor(context: Context, attrs: Attr /** * Set the lower text size limit and invalidate the view - * - * @param minTextSize */ + @Suppress("unused") fun setMinTextSize(minTextSize: Float) { this.minTextSize = minTextSize adjustTextSize() @@ -237,6 +235,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/AndroidManifest.xml b/AutoFitTextViewSample/AndroidManifest.xml index 335ebc0..6291dd4 100644 --- a/AutoFitTextViewSample/AndroidManifest.xml +++ b/AutoFitTextViewSample/AndroidManifest.xml @@ -4,14 +4,14 @@ + android:name=".MainActivity" android:label="@string/app_name" android:exported="true"> - + diff --git a/AutoFitTextViewSample/build.gradle b/AutoFitTextViewSample/build.gradle index 21850d3..ede2293 100644 --- a/AutoFitTextViewSample/build.gradle +++ b/AutoFitTextViewSample/build.gradle @@ -1,14 +1,13 @@ apply plugin: 'com.android.application' -apply plugin: 'kotlin-android-extensions' apply plugin: 'kotlin-android' android { - compileSdkVersion 28 + compileSdkVersion 33 defaultConfig { applicationId "com.example.autofittextviewsample" minSdkVersion 17 - targetSdkVersion 28 + targetSdkVersion 33 versionCode 1 versionName "1.0" } @@ -30,20 +29,24 @@ android { } } compileOptions { - sourceCompatibility = '1.8' - targetCompatibility = '1.8' + sourceCompatibility JavaVersion.VERSION_11 + targetCompatibility JavaVersion.VERSION_11 + } + kotlinOptions { + jvmTarget = "11" + } + buildFeatures { + viewBinding true } - } dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) - implementation 'androidx.appcompat:appcompat:1.0.2' - implementation 'androidx.recyclerview:recyclerview:1.0.0' + implementation 'androidx.appcompat:appcompat:1.5.1' + implementation 'androidx.recyclerview:recyclerview:1.2.1' 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' + implementation 'androidx.core:core-ktx:1.9.0' + implementation 'androidx.constraintlayout:constraintlayout:2.1.4' } repositories { mavenCentral() diff --git a/AutoFitTextViewSample/lint.xml b/AutoFitTextViewSample/lint.xml index 9c0ed5a..da256df 100644 --- a/AutoFitTextViewSample/lint.xml +++ b/AutoFitTextViewSample/lint.xml @@ -1,2 +1,2 @@ - + diff --git a/AutoFitTextViewSample/project.properties b/AutoFitTextViewSample/project.properties index fb9fae5..c46ed69 100644 --- a/AutoFitTextViewSample/project.properties +++ b/AutoFitTextViewSample/project.properties @@ -10,5 +10,3 @@ # 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 index 855d748..e57cd09 100644 --- a/AutoFitTextViewSample/res/layout/activity_main.xml +++ b/AutoFitTextViewSample/res/layout/activity_main.xml @@ -20,7 +20,6 @@ android:text="2" app:layout_constraintBottom_toBottomOf="@id/minusLineCountButton" app:layout_constraintStart_toEndOf="@id/minusLineCountButton" app:layout_constraintTop_toBottomOf="@id/contentEditText"/> -