allow increasing text editor font size with gestures

This commit is contained in:
tibbi 2019-01-26 16:58:02 +01:00
parent b222a8c97d
commit 23c786d3b9
4 changed files with 78 additions and 4 deletions

View File

@ -53,4 +53,5 @@ android {
dependencies {
implementation 'com.simplemobiletools:commons:5.6.17'
implementation 'com.github.Stericson:RootTools:df729dcb13'
implementation 'com.alexvasilkov:gesture-views:2.5.2'
}

View File

@ -248,7 +248,7 @@ class MainActivity : SimpleActivity() {
}
private fun launchAbout() {
val licenses = LICENSE_GLIDE or LICENSE_PATTERN or LICENSE_REPRINT
val licenses = LICENSE_GLIDE or LICENSE_PATTERN or LICENSE_REPRINT or LICENSE_GESTURE_VIEWS
val faqItems = arrayListOf(
FAQItem(R.string.faq_3_title_commons, R.string.faq_3_text_commons),

View File

@ -0,0 +1,72 @@
package com.simplemobiletools.filemanager.pro.views
import android.content.Context
import android.util.AttributeSet
import android.util.TypedValue
import android.view.MotionEvent
import androidx.appcompat.widget.AppCompatTextView
import com.alexvasilkov.gestures.GestureController
import com.alexvasilkov.gestures.State
import com.alexvasilkov.gestures.views.interfaces.GestureView
import com.simplemobiletools.commons.extensions.getAdjustedPrimaryColor
import com.simplemobiletools.filemanager.pro.extensions.config
// taken from
// https://github.com/alexvasilkov/GestureViews/blob/f0a4c266e31dcad23bd0d9013531bc1c501b9c9f/sample/src/main/java/com/alexvasilkov/gestures/sample/ex/custom/text/GestureTextView.java
class GestureTextView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyle: Int = 0) : AppCompatTextView(context, attrs, defStyle), GestureView {
private val controller: GestureController = GestureController(this)
private var origSize = 0f
private var size = 0f
init {
controller.settings.setOverzoomFactor(1f).isPanEnabled = false
controller.settings.initFromAttributes(context, attrs)
controller.addOnStateChangeListener(object : GestureController.OnStateChangeListener {
override fun onStateChanged(state: State) {
applyState(state)
}
override fun onStateReset(oldState: State, newState: State) {
applyState(newState)
}
})
origSize = textSize
setTextColor(context.config.textColor)
setLinkTextColor(context.getAdjustedPrimaryColor())
}
override fun getController() = controller
override fun onTouchEvent(event: MotionEvent) = controller.onTouch(this, event)
override fun setTextSize(size: Float) {
super.setTextSize(size)
origSize = textSize
applyState(controller.state)
}
override fun setTextSize(unit: Int, size: Float) {
super.setTextSize(unit, size)
origSize = textSize
applyState(controller.state)
}
override fun onSizeChanged(width: Int, height: Int, oldWidth: Int, oldHeight: Int) {
super.onSizeChanged(width, height, oldWidth, oldHeight)
controller.settings.setViewport(width, height).setImage(width, height)
controller.updateState()
}
private fun applyState(state: State) {
var size = origSize * state.zoom
val maxSize = origSize * controller.stateController.getMaxZoom(state)
size = Math.max(origSize, Math.min(size, maxSize))
size = Math.round(size).toFloat()
if (!State.equals(this.size, size)) {
this.size = size
super.setTextSize(TypedValue.COMPLEX_UNIT_PX, size)
}
}
}

View File

@ -3,15 +3,16 @@
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/read_text_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_height="match_parent"
android:fillViewport="true">
<com.simplemobiletools.commons.views.MyEditText
<com.simplemobiletools.filemanager.pro.views.GestureTextView
android:id="@+id/read_text_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@null"
android:padding="@dimen/medium_margin"
android:inputType="textMultiLine|textNoSuggestions"
android:padding="@dimen/medium_margin"
android:textCursorDrawable="@null"
android:textSize="@dimen/smaller_text_size"/>