Skip to content

Commit 23c786d

Browse files
committed
allow increasing text editor font size with gestures
1 parent b222a8c commit 23c786d

File tree

4 files changed

+78
-4
lines changed

4 files changed

+78
-4
lines changed

app/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,5 @@ android {
5353
dependencies {
5454
implementation 'com.simplemobiletools:commons:5.6.17'
5555
implementation 'com.github.Stericson:RootTools:df729dcb13'
56+
implementation 'com.alexvasilkov:gesture-views:2.5.2'
5657
}

app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/MainActivity.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ class MainActivity : SimpleActivity() {
248248
}
249249

250250
private fun launchAbout() {
251-
val licenses = LICENSE_GLIDE or LICENSE_PATTERN or LICENSE_REPRINT
251+
val licenses = LICENSE_GLIDE or LICENSE_PATTERN or LICENSE_REPRINT or LICENSE_GESTURE_VIEWS
252252

253253
val faqItems = arrayListOf(
254254
FAQItem(R.string.faq_3_title_commons, R.string.faq_3_text_commons),
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package com.simplemobiletools.filemanager.pro.views
2+
3+
import android.content.Context
4+
import android.util.AttributeSet
5+
import android.util.TypedValue
6+
import android.view.MotionEvent
7+
import androidx.appcompat.widget.AppCompatTextView
8+
import com.alexvasilkov.gestures.GestureController
9+
import com.alexvasilkov.gestures.State
10+
import com.alexvasilkov.gestures.views.interfaces.GestureView
11+
import com.simplemobiletools.commons.extensions.getAdjustedPrimaryColor
12+
import com.simplemobiletools.filemanager.pro.extensions.config
13+
14+
// taken from
15+
// https://github.com/alexvasilkov/GestureViews/blob/f0a4c266e31dcad23bd0d9013531bc1c501b9c9f/sample/src/main/java/com/alexvasilkov/gestures/sample/ex/custom/text/GestureTextView.java
16+
class GestureTextView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyle: Int = 0) : AppCompatTextView(context, attrs, defStyle), GestureView {
17+
private val controller: GestureController = GestureController(this)
18+
private var origSize = 0f
19+
private var size = 0f
20+
21+
init {
22+
controller.settings.setOverzoomFactor(1f).isPanEnabled = false
23+
controller.settings.initFromAttributes(context, attrs)
24+
controller.addOnStateChangeListener(object : GestureController.OnStateChangeListener {
25+
override fun onStateChanged(state: State) {
26+
applyState(state)
27+
}
28+
29+
override fun onStateReset(oldState: State, newState: State) {
30+
applyState(newState)
31+
}
32+
})
33+
34+
origSize = textSize
35+
setTextColor(context.config.textColor)
36+
setLinkTextColor(context.getAdjustedPrimaryColor())
37+
}
38+
39+
override fun getController() = controller
40+
41+
override fun onTouchEvent(event: MotionEvent) = controller.onTouch(this, event)
42+
43+
override fun setTextSize(size: Float) {
44+
super.setTextSize(size)
45+
origSize = textSize
46+
applyState(controller.state)
47+
}
48+
49+
override fun setTextSize(unit: Int, size: Float) {
50+
super.setTextSize(unit, size)
51+
origSize = textSize
52+
applyState(controller.state)
53+
}
54+
55+
override fun onSizeChanged(width: Int, height: Int, oldWidth: Int, oldHeight: Int) {
56+
super.onSizeChanged(width, height, oldWidth, oldHeight)
57+
controller.settings.setViewport(width, height).setImage(width, height)
58+
controller.updateState()
59+
}
60+
61+
private fun applyState(state: State) {
62+
var size = origSize * state.zoom
63+
val maxSize = origSize * controller.stateController.getMaxZoom(state)
64+
size = Math.max(origSize, Math.min(size, maxSize))
65+
66+
size = Math.round(size).toFloat()
67+
if (!State.equals(this.size, size)) {
68+
this.size = size
69+
super.setTextSize(TypedValue.COMPLEX_UNIT_PX, size)
70+
}
71+
}
72+
}

app/src/main/res/layout/activity_read_text.xml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@
33
xmlns:android="http://schemas.android.com/apk/res/android"
44
android:id="@+id/read_text_holder"
55
android:layout_width="match_parent"
6-
android:layout_height="wrap_content">
6+
android:layout_height="match_parent"
7+
android:fillViewport="true">
78

8-
<com.simplemobiletools.commons.views.MyEditText
9+
<com.simplemobiletools.filemanager.pro.views.GestureTextView
910
android:id="@+id/read_text_view"
1011
android:layout_width="match_parent"
1112
android:layout_height="wrap_content"
1213
android:background="@null"
13-
android:padding="@dimen/medium_margin"
1414
android:inputType="textMultiLine|textNoSuggestions"
15+
android:padding="@dimen/medium_margin"
1516
android:textCursorDrawable="@null"
1617
android:textSize="@dimen/smaller_text_size"/>
1718

0 commit comments

Comments
 (0)