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"/>
-
diff --git a/AutoFitTextViewSample/res/menu/main.xml b/AutoFitTextViewSample/res/menu/main.xml
index 2a8a832..322d72a 100644
--- a/AutoFitTextViewSample/res/menu/main.xml
+++ b/AutoFitTextViewSample/res/menu/main.xml
@@ -4,9 +4,12 @@
diff --git a/AutoFitTextViewSample/src/com/example/autofittextviewsample/Main2Activity.kt b/AutoFitTextViewSample/src/com/example/autofittextviewsample/Main2Activity.kt
index 4503944..aa73af4 100644
--- a/AutoFitTextViewSample/src/com/example/autofittextviewsample/Main2Activity.kt
+++ b/AutoFitTextViewSample/src/com/example/autofittextviewsample/Main2Activity.kt
@@ -9,17 +9,22 @@ 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.*
+import com.example.autofittextviewsample.databinding.ActivityMain2Binding
class Main2Activity : AppCompatActivity() {
+ private lateinit var binding: ActivityMain2Binding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
- setContentView(R.layout.activity_main2)
- recyclerView.layoutManager = LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false)
- recyclerView.adapter = object : Adapter() {
+ binding = ActivityMain2Binding.inflate(layoutInflater)
+ setContentView(binding.root)
+ binding.recyclerView.layoutManager =
+ LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false)
+ binding.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)) {
+ return object : ViewHolder(
+ LayoutInflater.from(this@Main2Activity).inflate(R.layout.item, parent, false)
+ ) {
}
}
@@ -27,7 +32,7 @@ class Main2Activity : AppCompatActivity() {
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val sb = StringBuilder("item:")
for (i in 0..position)
- sb.append(Integer.toString(position))
+ sb.append(position.toString())
holder.textView.text = sb
}
@@ -38,7 +43,7 @@ class Main2Activity : AppCompatActivity() {
}
private open class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
- internal val textView: TextView
+ 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
index 24b9184..c214426 100644
--- a/AutoFitTextViewSample/src/com/example/autofittextviewsample/MainActivity.kt
+++ b/AutoFitTextViewSample/src/com/example/autofittextviewsample/MainActivity.kt
@@ -14,19 +14,19 @@ 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.*
import android.widget.SeekBar.OnSeekBarChangeListener
import androidx.appcompat.app.AppCompatActivity
+import com.example.autofittextviewsample.databinding.ActivityMainBinding
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";
+ private lateinit var binding: ActivityMainBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
- setContentView(R.layout.activity_main)
- contentEditText!!.addTextChangedListener(object : TextWatcher {
+ binding = ActivityMainBinding.inflate(layoutInflater)
+ setContentView(binding.root)
+ 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) {}
@@ -44,43 +44,47 @@ class MainActivity : AppCompatActivity() {
recreateTextView()
}
}
- heightSeekBar!!.setOnSeekBarChangeListener(seekBarChangeListener)
- widthSeekBar!!.setOnSeekBarChangeListener(seekBarChangeListener)
+ binding.heightSeekBar.setOnSeekBarChangeListener(seekBarChangeListener)
+ binding.widthSeekBar.setOnSeekBarChangeListener(seekBarChangeListener)
findViewById(R.id.plusLineCountButton).setOnClickListener {
- var maxLinesCount = Integer.parseInt(linesCountTextView!!.text.toString())
- linesCountTextView!!.text = Integer.toString(++maxLinesCount)
+ var maxLinesCount = Integer.parseInt(binding.linesCountTextView.text.toString())
+ binding.linesCountTextView.text = (++maxLinesCount).toString()
recreateTextView()
}
findViewById(R.id.minusLineCountButton).setOnClickListener(OnClickListener {
- var maxLinesCount = Integer.parseInt(linesCountTextView!!.text.toString())
+ var maxLinesCount = Integer.parseInt(binding.linesCountTextView.text.toString())
if (maxLinesCount == 1)
return@OnClickListener
- linesCountTextView!!.text = Integer.toString(--maxLinesCount)
+ binding.linesCountTextView.text = (--maxLinesCount).toString()
recreateTextView()
})
- runJustBeforeBeingDrawn(textViewContainer!!, Runnable { recreateTextView() })
+ runJustBeforeBeingDrawn(binding.textViewContainer) { recreateTextView() }
}
- protected fun recreateTextView() {
- textViewContainer!!.removeAllViews()
- val maxWidth = textViewContainer!!.width
- val maxHeight = textViewContainer!!.height
+ private fun recreateTextView() {
+ binding.textViewContainer.removeAllViews()
+ val maxWidth = binding.textViewContainer.width
+ val maxHeight = binding.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())
+ val width = binding.widthSeekBar.progress * maxWidth / binding.widthSeekBar.max
+ val height = binding.heightSeekBar.progress * maxHeight / binding.heightSeekBar.max
+ val maxLinesCount = Integer.parseInt(binding.linesCountTextView.text.toString())
textView.maxLines = maxLinesCount
- textView.textSize = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, maxHeight.toFloat(), resources.displayMetrics)
+ 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()
+ val text = binding.contentEditText.text.toString()
textView.text = text
- textViewContainer!!.addView(textView)
+ binding.textViewContainer.addView(textView)
}
// private String getRandomText()
@@ -99,9 +103,13 @@ class MainActivity : AppCompatActivity() {
override fun onOptionsItemSelected(item: MenuItem): Boolean {
var url: String? = null
when (item.itemId) {
- R.id.menuItem_all_my_apps -> url = "https://play.google.com/store/apps/developer?id=AndroidDeveloperLB"
+ R.id.menuItem_all_my_apps -> 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_current_repository_website -> url =
+ "https://github.com/AndroidDeveloperLB/AutoFitTextView"
+
R.id.menuItem_show_recyclerViewSample -> {
startActivity(Intent(this, Main2Activity::class.java))
return true
diff --git a/build.gradle b/build.gradle
index 3ca9435..29c92ad 100644
--- a/build.gradle
+++ b/build.gradle
@@ -1,23 +1,21 @@
// 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()
+ mavenCentral()
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
+// https://mvnrepository.com/artifact/com.android.tools.build/gradle?repo=google
+ classpath 'com.android.tools.build:gradle:7.4.0-rc01'
+ // https://kotlinlang.org/docs/reference/using-gradle.html https://plugins.gradle.org/plugin/org.jetbrains.kotlin.android
+ classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.10"
}
}
allprojects {
repositories {
- jcenter()
+ mavenCentral()
google()
}
}
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index 8fdd95f..a745f78 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
+#Mon Dec 26 20:06:41 IST 2022
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
+distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip