Skip to content

Commit

Permalink
Updated SDKs
Browse files Browse the repository at this point in the history
  • Loading branch information
AndroidDeveloperLB committed Dec 28, 2022
1 parent 00be48a commit fe3caf4
Show file tree
Hide file tree
Showing 20 changed files with 175 additions and 110 deletions.
6 changes: 6 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 45 additions & 0 deletions .idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 9 additions & 3 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 0 additions & 12 deletions .idea/runConfigurations.xml

This file was deleted.

19 changes: 9 additions & 10 deletions AutoFitTextViewLibrary/build.gradle
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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()
Expand Down
2 changes: 0 additions & 2 deletions AutoFitTextViewLibrary/project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
/**
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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()
}

Expand All @@ -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
Expand All @@ -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()
Expand Down Expand Up @@ -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
}
}
4 changes: 2 additions & 2 deletions AutoFitTextViewSample/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
<application
android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/Theme.AppCompat.Light">
<activity
android:name=".MainActivity" android:label="@string/app_name">
android:name=".MainActivity" android:label="@string/app_name" android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>

<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name=".Main2Activity"></activity>
<activity android:name=".Main2Activity" />
</application>

</manifest>
25 changes: 14 additions & 11 deletions AutoFitTextViewSample/build.gradle
Original file line number Diff line number Diff line change
@@ -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"
}
Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion AutoFitTextViewSample/lint.xml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<lint></lint>
<lint />
2 changes: 0 additions & 2 deletions AutoFitTextViewSample/project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 0 additions & 1 deletion AutoFitTextViewSample/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"/>


<Button
android:id="@+id/plusLineCountButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/contentEditText" android:text="+"
app:layout_constraintStart_toEndOf="@id/linesCountTextView" app:layout_constraintTop_toBottomOf="@id/contentEditText"/>
Expand Down
9 changes: 6 additions & 3 deletions AutoFitTextViewSample/res/menu/main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
<menu>
<group android:checkableBehavior="none" android:menuCategory="container">
<item android:id="@+id/menuItem_show_recyclerViewSample" android:title="show RecyclerView sample"/>
<item android:id="@+id/menuItem_current_repository_website" android:title="Repository website"></item>
<item android:id="@+id/menuItem_all_my_repositories" android:title="All my repositories"></item>
<item android:id="@+id/menuItem_all_my_apps" android:title="All my apps"></item>
<item
android:id="@+id/menuItem_current_repository_website" android:title="Repository website" />
<item
android:id="@+id/menuItem_all_my_repositories" android:title="All my repositories" />
<item
android:id="@+id/menuItem_all_my_apps" android:title="All my apps" />
</group>
</menu>
</item>
Expand Down
Loading

0 comments on commit fe3caf4

Please sign in to comment.