Skip to content

Commit 2127ee7

Browse files
cleanup
1 parent 2c20673 commit 2127ee7

File tree

20 files changed

+160
-269
lines changed

20 files changed

+160
-269
lines changed

.idea/caches/build_file_checksums.ser

0 Bytes
Binary file not shown.

.idea/caches/gradle_models.ser

2.15 KB
Binary file not shown.
+2-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3-
package="com.lb.autofittextviewtest" >
2+
<manifest package="com.lb.autofittextviewtest">
43

5-
<application />
4+
<application/>
65

76
</manifest>

AutoFitTextViewLibrary/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ android {
3737

3838
dependencies {
3939
implementation 'androidx.appcompat:appcompat:1.0.2'
40-
compile "androidx.core:core-ktx:+"
40+
compile "androidx.core:core-ktx:1.0.1"
4141
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
4242
}
4343
repositories {

AutoFitTextViewLibrary/project.properties

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#
1010
# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
1111
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
12-
1312
# Project target.
1413
target=android-21
1514
android.library=true

AutoFitTextViewLibrary/src/com/lb/auto_fit_textview/AutoResizeTextView.kt

+40-40
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,16 @@ import androidx.appcompat.widget.AppCompatTextView
2121
* 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
2222
*/
2323
class AutoResizeTextView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyle: Int = android.R.attr.textViewStyle) : AppCompatTextView(context, attrs, defStyle) {
24-
private val _availableSpaceRect = RectF()
25-
private val _sizeTester: SizeTester
26-
private var _maxTextSize: Float = 0.toFloat()
27-
private var _spacingMult = 1.0f
28-
private var _spacingAdd = 0.0f
29-
private var _minTextSize: Float = 0.toFloat()
30-
private var _widthLimit: Int = 0
31-
private var _maxLines: Int = 0
32-
private var _initialized = false
33-
private var _paint: TextPaint? = null
24+
private val availableSpaceRect = RectF()
25+
private val sizeTester: SizeTester
26+
private var maxTextSize: Float = 0.toFloat()
27+
private var spacingMult = 1.0f
28+
private var spacingAdd = 0.0f
29+
private var minTextSize: Float = 0.toFloat()
30+
private var widthLimit: Int = 0
31+
private var maxLines: Int = 0
32+
private var initialized = false
33+
private var textPaint: TextPaint? = null
3434

3535
private interface SizeTester {
3636
/**
@@ -45,19 +45,19 @@ class AutoResizeTextView @JvmOverloads constructor(context: Context, attrs: Attr
4545

4646
init {
4747
// using the minimal recommended font size
48-
_minTextSize = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 12f, resources.displayMetrics)
49-
_maxTextSize = textSize
50-
_paint = TextPaint(paint)
51-
if (_maxLines == 0)
48+
minTextSize = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 12f, resources.displayMetrics)
49+
maxTextSize = textSize
50+
textPaint = TextPaint(paint)
51+
if (maxLines == 0)
5252
// no value was assigned during construction
53-
_maxLines = NO_LINE_LIMIT
53+
maxLines = NO_LINE_LIMIT
5454
// prepare size tester:
55-
_sizeTester = object : SizeTester {
55+
sizeTester = object : SizeTester {
5656
internal val textRect = RectF()
5757

5858
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
5959
override fun onTestSize(suggestedSize: Int, availableSpace: RectF): Int {
60-
_paint!!.textSize = suggestedSize.toFloat()
60+
textPaint!!.textSize = suggestedSize.toFloat()
6161
val transformationMethod = transformationMethod
6262
val text: String
6363
if (transformationMethod != null)
@@ -66,10 +66,10 @@ class AutoResizeTextView @JvmOverloads constructor(context: Context, attrs: Attr
6666
text = getText().toString()
6767
val singleLine = maxLines == 1
6868
if (singleLine) {
69-
textRect.bottom = _paint!!.fontSpacing
70-
textRect.right = _paint!!.measureText(text)
69+
textRect.bottom = textPaint!!.fontSpacing
70+
textRect.right = textPaint!!.measureText(text)
7171
} else {
72-
val layout = StaticLayout(text, _paint, _widthLimit, Alignment.ALIGN_NORMAL, _spacingMult, _spacingAdd, true)
72+
val layout = StaticLayout(text, textPaint, widthLimit, Alignment.ALIGN_NORMAL, spacingMult, spacingAdd, true)
7373
// return early if we have more lines
7474
if (maxLines != NO_LINE_LIMIT && layout.lineCount > maxLines)
7575
return 1
@@ -93,7 +93,7 @@ class AutoResizeTextView @JvmOverloads constructor(context: Context, attrs: Attr
9393
// else, too big
9494
}
9595
}
96-
_initialized = true
96+
initialized = true
9797
}
9898

9999
fun isValidWordWrap(before: Char, after: Char): Boolean {
@@ -111,38 +111,38 @@ class AutoResizeTextView @JvmOverloads constructor(context: Context, attrs: Attr
111111
}
112112

113113
override fun setTextSize(size: Float) {
114-
_maxTextSize = size
114+
maxTextSize = size
115115
adjustTextSize()
116116
}
117117

118118
override fun setMaxLines(maxLines: Int) {
119119
super.setMaxLines(maxLines)
120-
_maxLines = maxLines
120+
this.maxLines = maxLines
121121
adjustTextSize()
122122
}
123123

124124
override fun getMaxLines(): Int {
125-
return _maxLines
125+
return maxLines
126126
}
127127

128128
override fun setSingleLine() {
129129
super.setSingleLine()
130-
_maxLines = 1
130+
maxLines = 1
131131
adjustTextSize()
132132
}
133133

134134
override fun setSingleLine(singleLine: Boolean) {
135135
super.setSingleLine(singleLine)
136136
if (singleLine)
137-
_maxLines = 1
137+
maxLines = 1
138138
else
139-
_maxLines = NO_LINE_LIMIT
139+
maxLines = NO_LINE_LIMIT
140140
adjustTextSize()
141141
}
142142

143143
override fun setLines(lines: Int) {
144144
super.setLines(lines)
145-
_maxLines = lines
145+
maxLines = lines
146146
adjustTextSize()
147147
}
148148

@@ -153,14 +153,14 @@ class AutoResizeTextView @JvmOverloads constructor(context: Context, attrs: Attr
153153
Resources.getSystem()
154154
else
155155
c.resources
156-
_maxTextSize = TypedValue.applyDimension(unit, size, r.displayMetrics)
156+
maxTextSize = TypedValue.applyDimension(unit, size, r.displayMetrics)
157157
adjustTextSize()
158158
}
159159

160160
override fun setLineSpacing(add: Float, mult: Float) {
161161
super.setLineSpacing(add, mult)
162-
_spacingMult = mult
163-
_spacingAdd = add
162+
spacingMult = mult
163+
spacingAdd = add
164164
}
165165

166166
/**
@@ -169,7 +169,7 @@ class AutoResizeTextView @JvmOverloads constructor(context: Context, attrs: Attr
169169
* @param minTextSize
170170
*/
171171
fun setMinTextSize(minTextSize: Float) {
172-
_minTextSize = minTextSize
172+
this.minTextSize = minTextSize
173173
adjustTextSize()
174174
}
175175

@@ -181,23 +181,23 @@ class AutoResizeTextView @JvmOverloads constructor(context: Context, attrs: Attr
181181
// @Override
182182
// public void run()
183183
// {
184-
if (!_initialized)
184+
if (!initialized)
185185
return
186-
val startSize = _minTextSize.toInt()
186+
val startSize = minTextSize.toInt()
187187
val heightLimit = measuredHeight - compoundPaddingBottom - compoundPaddingTop
188-
_widthLimit = measuredWidth - compoundPaddingLeft - compoundPaddingRight
189-
if (_widthLimit <= 0)
188+
widthLimit = measuredWidth - compoundPaddingLeft - compoundPaddingRight
189+
if (widthLimit <= 0)
190190
return
191-
_paint = TextPaint(paint)
192-
_availableSpaceRect.right = _widthLimit.toFloat()
193-
_availableSpaceRect.bottom = heightLimit.toFloat()
191+
textPaint = TextPaint(paint)
192+
availableSpaceRect.right = widthLimit.toFloat()
193+
availableSpaceRect.bottom = heightLimit.toFloat()
194194
superSetTextSize(startSize)
195195
// }
196196
// });
197197
}
198198

199199
private fun superSetTextSize(startSize: Int) {
200-
val textSize = binarySearch(startSize, _maxTextSize.toInt(), _sizeTester, _availableSpaceRect)
200+
val textSize = binarySearch(startSize, maxTextSize.toInt(), sizeTester, availableSpaceRect)
201201
super.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize.toFloat())
202202
}
203203

+12-19
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,17 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<manifest package="com.example.autofittextviewsample"
3-
xmlns:android="http://schemas.android.com/apk/res/android"
4-
android:installLocation="auto">
2+
<manifest package="com.example.autofittextviewsample" xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="auto">
53

6-
<application
7-
android:allowBackup="true"
8-
android:icon="@drawable/ic_launcher"
9-
android:label="@string/app_name"
10-
android:theme="@style/Theme.AppCompat.Light">
11-
<activity
12-
android:name=".MainActivity"
13-
android:label="@string/app_name">
14-
<intent-filter>
15-
<action android:name="android.intent.action.MAIN"/>
4+
<application
5+
android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/Theme.AppCompat.Light">
6+
<activity
7+
android:name=".MainActivity" android:label="@string/app_name">
8+
<intent-filter>
9+
<action android:name="android.intent.action.MAIN"/>
1610

17-
<category android:name="android.intent.category.LAUNCHER"/>
18-
</intent-filter>
19-
</activity>
20-
<activity android:name=".Main2Activity">
21-
</activity>
22-
</application>
11+
<category android:name="android.intent.category.LAUNCHER"/>
12+
</intent-filter>
13+
</activity>
14+
<activity android:name=".Main2Activity"></activity>
15+
</application>
2316

2417
</manifest>

AutoFitTextViewSample/build.gradle

+3-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ android {
77

88
defaultConfig {
99
applicationId "com.example.autofittextviewsample"
10-
minSdkVersion 14
10+
minSdkVersion 17
1111
targetSdkVersion 28
1212
versionCode 1
1313
versionName "1.0"
@@ -41,8 +41,9 @@ dependencies {
4141
implementation 'androidx.appcompat:appcompat:1.0.2'
4242
implementation 'androidx.recyclerview:recyclerview:1.0.0'
4343
implementation project(':AutoFitTextViewLibrary')
44-
compile "androidx.core:core-ktx:+"
44+
compile "androidx.core:core-ktx:1.0.1"
4545
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
46+
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
4647
}
4748
repositories {
4849
mavenCentral()

AutoFitTextViewSample/lint.xml

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<lint>
3-
</lint>
2+
<lint></lint>

AutoFitTextViewSample/project.properties

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#
1010
# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
1111
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
12-
1312
# Project target.
1413
target=android-21
1514
android.library.reference.1=..\\AutoFitTextViewLibrary

0 commit comments

Comments
 (0)