pull/441/head
gedoor 4 years ago
parent 027fc778ac
commit 04a76a2849
  1. 45
      app/src/main/java/io/legado/app/ui/book/read/ReadMenu.kt
  2. 17
      app/src/main/java/io/legado/app/ui/widget/SearchView.kt
  3. 5
      app/src/main/java/io/legado/app/ui/widget/image/CircleImageView.kt
  4. 20
      app/src/main/java/io/legado/app/ui/widget/image/CoverImageView.kt
  5. 42
      app/src/main/java/io/legado/app/ui/widget/image/FilletImageView.kt
  6. 408
      app/src/main/java/io/legado/app/ui/widget/image/PhotoView.kt
  7. 2
      app/src/main/java/io/legado/app/ui/widget/text/AccentBgTextView.kt
  8. 13
      app/src/main/java/io/legado/app/ui/widget/text/AutoCompleteTextView.kt

@ -21,37 +21,30 @@ import kotlinx.android.synthetic.main.view_read_menu.view.*
import org.jetbrains.anko.sdk27.listeners.onClick import org.jetbrains.anko.sdk27.listeners.onClick
import org.jetbrains.anko.sdk27.listeners.onLongClick import org.jetbrains.anko.sdk27.listeners.onLongClick
class ReadMenu : FrameLayout { /**
* 阅读界面菜单
*/
class ReadMenu @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : FrameLayout(context, attrs, defStyleAttr) {
var cnaShowMenu: Boolean = false var cnaShowMenu: Boolean = false
private var callBack: CallBack? = null private val callBack: CallBack? get() = activity as? CallBack
private lateinit var menuTopIn: Animation private lateinit var menuTopIn: Animation
private lateinit var menuTopOut: Animation private lateinit var menuTopOut: Animation
private lateinit var menuBottomIn: Animation private lateinit var menuBottomIn: Animation
private lateinit var menuBottomOut: Animation private lateinit var menuBottomOut: Animation
private val bgColor: Int private val bgColor: Int = context.bottomBackground
private val textColor: Int private val textColor: Int = context.getPrimaryTextColor(ColorUtils.isColorLight(bgColor))
private var bottomBackgroundList: ColorStateList private val bottomBackgroundList: ColorStateList = Selector.colorBuild()
.setDefaultColor(bgColor)
.setPressedColor(ColorUtils.darkenColor(bgColor))
.create()
private var onMenuOutEnd: (() -> Unit)? = null private var onMenuOutEnd: (() -> Unit)? = null
val showBrightnessView get() = context.getPrefBoolean(PreferKey.showBrightnessView, true) val showBrightnessView get() = context.getPrefBoolean(PreferKey.showBrightnessView, true)
constructor(context: Context) : super(context)
constructor(context: Context, attrs: AttributeSet) : super(context, attrs)
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(
context,
attrs,
defStyleAttr
)
init { init {
callBack = activity as? CallBack
bgColor = context.bottomBackground
textColor = context.getPrimaryTextColor(ColorUtils.isColorLight(bgColor))
bottomBackgroundList = Selector.colorBuild()
.setDefaultColor(bgColor)
.setPressedColor(ColorUtils.darkenColor(bgColor))
.create()
inflate(context, R.layout.view_read_menu, this) inflate(context, R.layout.view_read_menu, this)
if (AppConfig.isNightTheme) { if (AppConfig.isNightTheme) {
fabNightTheme.setImageResource(R.drawable.ic_daytime) fabNightTheme.setImageResource(R.drawable.ic_daytime)
@ -254,9 +247,7 @@ class ReadMenu : FrameLayout {
} }
} }
override fun onAnimationRepeat(animation: Animation) { override fun onAnimationRepeat(animation: Animation) = Unit
}
}) })
//隐藏菜单 //隐藏菜单
@ -277,9 +268,7 @@ class ReadMenu : FrameLayout {
callBack?.upSystemUiVisibility() callBack?.upSystemUiVisibility()
} }
override fun onAnimationRepeat(animation: Animation) { override fun onAnimationRepeat(animation: Animation) = Unit
}
}) })
} }

@ -16,21 +16,14 @@ import android.widget.TextView
import androidx.appcompat.widget.SearchView import androidx.appcompat.widget.SearchView
import io.legado.app.R import io.legado.app.R
class SearchView : SearchView { class SearchView @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : SearchView(context, attrs, defStyleAttr) {
private var mSearchHintIcon: Drawable? = null private var mSearchHintIcon: Drawable? = null
private var textView: TextView? = null private var textView: TextView? = null
constructor(
context: Context,
attrs: AttributeSet? = null
) : super(context, attrs)
constructor(
context: Context,
attrs: AttributeSet?,
defStyleAttr: Int
) : super(context, attrs, defStyleAttr)
@SuppressLint("UseCompatLoadingForDrawables") @SuppressLint("UseCompatLoadingForDrawables")
override fun onLayout( override fun onLayout(
changed: Boolean, changed: Boolean,

@ -26,10 +26,7 @@ import kotlin.math.pow
@Suppress("unused", "MemberVisibilityCanBePrivate") @Suppress("unused", "MemberVisibilityCanBePrivate")
class CircleImageView(context: Context, attrs: AttributeSet) : class CircleImageView(context: Context, attrs: AttributeSet) :
AppCompatImageView( AppCompatImageView(context, attrs) {
context,
attrs
) {
private val mDrawableRect = RectF() private val mDrawableRect = RectF()
private val mBorderRect = RectF() private val mBorderRect = RectF()

@ -20,7 +20,15 @@ import io.legado.app.utils.getPrefString
* 封面 * 封面
*/ */
@Suppress("unused") @Suppress("unused")
class CoverImageView : androidx.appcompat.widget.AppCompatImageView { class CoverImageView @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : androidx.appcompat.widget.AppCompatImageView(
context,
attrs,
defStyleAttr
) {
internal var width: Float = 0.toFloat() internal var width: Float = 0.toFloat()
internal var height: Float = 0.toFloat() internal var height: Float = 0.toFloat()
private var nameHeight = 0f private var nameHeight = 0f
@ -45,16 +53,6 @@ class CoverImageView : androidx.appcompat.widget.AppCompatImageView {
private var author: String? = null private var author: String? = null
private var loadFailed = false private var loadFailed = false
constructor(context: Context) : super(context)
constructor(context: Context, attrs: AttributeSet) : super(context, attrs)
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(
context,
attrs,
defStyleAttr
)
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
val measuredWidth = MeasureSpec.getSize(widthMeasureSpec) val measuredWidth = MeasureSpec.getSize(widthMeasureSpec)
val measuredHeight = measuredWidth * 7 / 5 val measuredHeight = measuredWidth * 7 / 5

@ -10,7 +10,11 @@ import io.legado.app.R
import io.legado.app.utils.dp import io.legado.app.utils.dp
import kotlin.math.max import kotlin.math.max
class FilletImageView : AppCompatImageView { class FilletImageView @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : AppCompatImageView(context, attrs, defStyleAttr) {
internal var width: Float = 0.toFloat() internal var width: Float = 0.toFloat()
internal var height: Float = 0.toFloat() internal var height: Float = 0.toFloat()
private var leftTopRadius: Int = 0 private var leftTopRadius: Int = 0
@ -18,26 +22,29 @@ class FilletImageView : AppCompatImageView {
private var rightBottomRadius: Int = 0 private var rightBottomRadius: Int = 0
private var leftBottomRadius: Int = 0 private var leftBottomRadius: Int = 0
constructor(context: Context) : super(context) init {
constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {
init(context, attrs)
}
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {
init(context, attrs)
}
private fun init(context: Context, attrs: AttributeSet) {
// 读取配置 // 读取配置
val array = context.obtainStyledAttributes(attrs, R.styleable.FilletImageView) val array = context.obtainStyledAttributes(attrs, R.styleable.FilletImageView)
val defaultRadius = 5.dp val defaultRadius = 5.dp
val radius = array.getDimensionPixelOffset(R.styleable.FilletImageView_radius, defaultRadius) val radius =
leftTopRadius = array.getDimensionPixelOffset(R.styleable.FilletImageView_left_top_radius, defaultRadius) array.getDimensionPixelOffset(R.styleable.FilletImageView_radius, defaultRadius)
rightTopRadius = array.getDimensionPixelOffset(R.styleable.FilletImageView_right_top_radius, defaultRadius) leftTopRadius = array.getDimensionPixelOffset(
R.styleable.FilletImageView_left_top_radius,
defaultRadius
)
rightTopRadius = array.getDimensionPixelOffset(
R.styleable.FilletImageView_right_top_radius,
defaultRadius
)
rightBottomRadius = rightBottomRadius =
array.getDimensionPixelOffset(R.styleable.FilletImageView_right_bottom_radius, defaultRadius) array.getDimensionPixelOffset(
leftBottomRadius = array.getDimensionPixelOffset(R.styleable.FilletImageView_left_bottom_radius, defaultRadius) R.styleable.FilletImageView_right_bottom_radius,
defaultRadius
)
leftBottomRadius = array.getDimensionPixelOffset(
R.styleable.FilletImageView_left_bottom_radius,
defaultRadius
)
//如果四个角的值没有设置,那么就使用通用的radius的值。 //如果四个角的值没有设置,那么就使用通用的radius的值。
if (defaultRadius == leftTopRadius) { if (defaultRadius == leftTopRadius) {
@ -53,7 +60,6 @@ class FilletImageView : AppCompatImageView {
leftBottomRadius = radius leftBottomRadius = radius
} }
array.recycle() array.recycle()
} }
override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) { override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) {

@ -16,6 +16,7 @@ import android.view.animation.Interpolator
import android.widget.ImageView import android.widget.ImageView
import android.widget.OverScroller import android.widget.OverScroller
import android.widget.Scroller import android.widget.Scroller
import androidx.appcompat.widget.AppCompatImageView
import io.legado.app.R import io.legado.app.R
import io.legado.app.ui.widget.image.photo.Info import io.legado.app.ui.widget.image.photo.Info
import io.legado.app.ui.widget.image.photo.OnRotateListener import io.legado.app.ui.widget.image.photo.OnRotateListener
@ -23,10 +24,12 @@ import io.legado.app.ui.widget.image.photo.RotateGestureDetector
import kotlin.math.abs import kotlin.math.abs
import kotlin.math.roundToInt import kotlin.math.roundToInt
@Suppress("UNUSED_PARAMETER", "unused", "MemberVisibilityCanBePrivate", "PropertyName")
@Suppress("UNUSED_PARAMETER", "unused", "MemberVisibilityCanBePrivate") class PhotoView @JvmOverloads constructor(
@SuppressLint("AppCompatCustomView") context: Context,
class PhotoView : ImageView { attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : AppCompatImageView(context, attrs, defStyleAttr) {
val MIN_ROTATE = 35 val MIN_ROTATE = 35
val ANIMA_DURING = 340 val ANIMA_DURING = 340
val MAX_SCALE = 2.5f val MAX_SCALE = 2.5f
@ -45,9 +48,9 @@ class PhotoView : ImageView {
private val mSynthesisMatrix: Matrix = Matrix() private val mSynthesisMatrix: Matrix = Matrix()
private val mTmpMatrix: Matrix = Matrix() private val mTmpMatrix: Matrix = Matrix()
private var mRotateDetector: RotateGestureDetector? = null private val mRotateDetector: RotateGestureDetector
private var mDetector: GestureDetector? = null private val mDetector: GestureDetector
private var mScaleDetector: ScaleGestureDetector? = null private val mScaleDetector: ScaleGestureDetector
private var mClickListener: OnClickListener? = null private var mClickListener: OnClickListener? = null
private var mScaleType: ScaleType? = null private var mScaleType: ScaleType? = null
@ -100,23 +103,11 @@ class PhotoView : ImageView {
private var mLongClick: OnLongClickListener? = null private var mLongClick: OnLongClickListener? = null
constructor(context: Context) : super(context) { private val mRotateListener = RotateListener()
init() private val mGestureListener = GestureListener()
} private val mScaleListener = ScaleGestureListener()
constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {
init()
}
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(
context,
attrs,
defStyleAttr
) {
init()
}
private fun init() { init {
super.setScaleType(ScaleType.MATRIX) super.setScaleType(ScaleType.MATRIX)
if (mScaleType == null) mScaleType = ScaleType.CENTER_INSIDE if (mScaleType == null) mScaleType = ScaleType.CENTER_INSIDE
mRotateDetector = RotateGestureDetector(mRotateListener) mRotateDetector = RotateGestureDetector(mRotateListener)
@ -484,11 +475,11 @@ class PhotoView : ImageView {
return if (isEnable) { return if (isEnable) {
val action = event.actionMasked val action = event.actionMasked
if (event.pointerCount >= 2) hasMultiTouch = true if (event.pointerCount >= 2) hasMultiTouch = true
mDetector!!.onTouchEvent(event) mDetector.onTouchEvent(event)
if (isRotateEnable) { if (isRotateEnable) {
mRotateDetector!!.onTouchEvent(event) mRotateDetector.onTouchEvent(event)
} }
mScaleDetector!!.onTouchEvent(event) mScaleDetector.onTouchEvent(event)
if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) onUp() if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) onUp()
true true
} else { } else {
@ -566,49 +557,6 @@ class PhotoView : ImageView {
return abs(rect.left.roundToInt() - (mWidgetRect.width() - rect.width()) / 2) < 1 return abs(rect.left.roundToInt() - (mWidgetRect.width() - rect.width()) / 2) < 1
} }
private val mRotateListener: OnRotateListener = object :
OnRotateListener {
override fun onRotate(
degrees: Float,
focusX: Float,
focusY: Float
) {
mRotateFlag += degrees
if (canRotate) {
mDegrees += degrees
mAnimMatrix.postRotate(degrees, focusX, focusY)
} else {
if (abs(mRotateFlag) >= mMinRotate) {
canRotate = true
mRotateFlag = 0f
}
}
}
}
private val mScaleListener: OnScaleGestureListener = object : OnScaleGestureListener {
override fun onScale(detector: ScaleGestureDetector): Boolean {
val scaleFactor = detector.scaleFactor
if (java.lang.Float.isNaN(scaleFactor) || java.lang.Float.isInfinite(scaleFactor)) return false
mScale *= scaleFactor
//mScaleCenter.set(detector.getFocusX(), detector.getFocusY());
mAnimMatrix.postScale(
scaleFactor,
scaleFactor,
detector.focusX,
detector.focusY
)
executeTranslate()
return true
}
override fun onScaleBegin(detector: ScaleGestureDetector): Boolean {
return true
}
override fun onScaleEnd(detector: ScaleGestureDetector) {}
}
private fun resistanceScrollByX( private fun resistanceScrollByX(
overScroll: Float, overScroll: Float,
detalX: Float detalX: Float
@ -652,147 +600,6 @@ class PhotoView : ImageView {
mClickListener?.onClick(this) mClickListener?.onClick(this)
} }
private val mGestureListener: GestureDetector.OnGestureListener =
object : SimpleOnGestureListener() {
override fun onLongPress(e: MotionEvent) {
mLongClick?.onLongClick(this@PhotoView)
}
override fun onDown(e: MotionEvent): Boolean {
hasOverTranslate = false
hasMultiTouch = false
canRotate = false
removeCallbacks(mClickRunnable)
return false
}
override fun onFling(
e1: MotionEvent,
e2: MotionEvent,
velocityX: Float,
velocityY: Float
): Boolean {
if (hasMultiTouch) return false
if (!imgLargeWidth && !imgLargeHeight) return false
if (mTranslate.isRunning) return false
var vx = velocityX
var vy = velocityY
if (mImgRect.left.roundToInt() >= mWidgetRect.left
|| mImgRect.right.roundToInt() <= mWidgetRect.right
) {
vx = 0f
}
if (mImgRect.top.roundToInt() >= mWidgetRect.top
|| mImgRect.bottom.roundToInt() <= mWidgetRect.bottom
) {
vy = 0f
}
if (canRotate || mDegrees % 90 != 0f) {
var toDegrees = (mDegrees / 90).toInt() * 90.toFloat()
val remainder = mDegrees % 90
if (remainder > 45) toDegrees += 90f else if (remainder < -45) toDegrees -= 90f
mTranslate.withRotate(mDegrees.toInt(), toDegrees.toInt())
mDegrees = toDegrees
}
doTranslateReset(mImgRect)
mTranslate.withFling(vx, vy)
mTranslate.start()
// onUp(e2);
return super.onFling(e1, e2, velocityX, velocityY)
}
override fun onScroll(
e1: MotionEvent,
e2: MotionEvent,
distanceX: Float,
distanceY: Float
): Boolean {
var x = distanceX
var y = distanceY
if (mTranslate.isRunning) {
mTranslate.stop()
}
if (canScrollHorizontallySelf(x)) {
if (x < 0 && mImgRect.left - x > mWidgetRect.left)
x = mImgRect.left
if (x > 0 && mImgRect.right - x < mWidgetRect.right)
x = mImgRect.right - mWidgetRect.right
mAnimMatrix.postTranslate(-x, 0f)
mTranslateX -= x.toInt()
} else if (imgLargeWidth || hasMultiTouch || hasOverTranslate) {
checkRect()
if (!hasMultiTouch) {
if (x < 0 && mImgRect.left - x > mCommonRect.left) x =
resistanceScrollByX(mImgRect.left - mCommonRect.left, x)
if (x > 0 && mImgRect.right - x < mCommonRect.right) x =
resistanceScrollByX(mImgRect.right - mCommonRect.right, x)
}
mTranslateX -= x.toInt()
mAnimMatrix.postTranslate(-x, 0f)
hasOverTranslate = true
}
if (canScrollVerticallySelf(y)) {
if (y < 0 && mImgRect.top - y > mWidgetRect.top) y =
mImgRect.top
if (y > 0 && mImgRect.bottom - y < mWidgetRect.bottom) y =
mImgRect.bottom - mWidgetRect.bottom
mAnimMatrix.postTranslate(0f, -y)
mTranslateY -= y.toInt()
} else if (imgLargeHeight || hasOverTranslate || hasMultiTouch) {
checkRect()
if (!hasMultiTouch) {
if (y < 0 && mImgRect.top - y > mCommonRect.top) y =
resistanceScrollByY(mImgRect.top - mCommonRect.top, y)
if (y > 0 && mImgRect.bottom - y < mCommonRect.bottom) y =
resistanceScrollByY(mImgRect.bottom - mCommonRect.bottom, y)
}
mAnimMatrix.postTranslate(0f, -y)
mTranslateY -= y.toInt()
hasOverTranslate = true
}
executeTranslate()
return true
}
override fun onSingleTapUp(e: MotionEvent): Boolean {
postDelayed(mClickRunnable, 250)
return false
}
override fun onDoubleTap(e: MotionEvent): Boolean {
mTranslate.stop()
val from: Float
val to: Float
val imgCx = mImgRect.left + mImgRect.width() / 2
val imgCy = mImgRect.top + mImgRect.height() / 2
mScaleCenter[imgCx] = imgCy
mRotateCenter[imgCx] = imgCy
mTranslateX = 0
mTranslateY = 0
if (isZoonUp) {
from = mScale
to = 1f
} else {
from = mScale
to = mMaxScale
mScaleCenter[e.x] = e.y
}
mTmpMatrix.reset()
mTmpMatrix.postTranslate(-mBaseRect.left, -mBaseRect.top)
mTmpMatrix.postTranslate(mRotateCenter.x, mRotateCenter.y)
mTmpMatrix.postTranslate(-mHalfBaseRectWidth, -mHalfBaseRectHeight)
mTmpMatrix.postRotate(mDegrees, mRotateCenter.x, mRotateCenter.y)
mTmpMatrix.postScale(to, to, mScaleCenter.x, mScaleCenter.y)
mTmpMatrix.postTranslate(mTranslateX.toFloat(), mTranslateY.toFloat())
mTmpMatrix.mapRect(mTmpRect, mBaseRect)
doTranslateReset(mTmpRect)
isZoonUp = !isZoonUp
mTranslate.withScale(from, to)
mTranslate.start()
return false
}
}
fun canScrollHorizontallySelf(direction: Float): Boolean { fun canScrollHorizontallySelf(direction: Float): Boolean {
if (mImgRect.width() <= mWidgetRect.width()) if (mImgRect.width() <= mWidgetRect.width())
return false return false
@ -1268,4 +1075,185 @@ class PhotoView : ImageView {
executeTranslate() executeTranslate()
} }
inner class RotateListener : OnRotateListener {
override fun onRotate(
degrees: Float,
focusX: Float,
focusY: Float
) {
mRotateFlag += degrees
if (canRotate) {
mDegrees += degrees
mAnimMatrix.postRotate(degrees, focusX, focusY)
} else {
if (abs(mRotateFlag) >= mMinRotate) {
canRotate = true
mRotateFlag = 0f
}
}
}
}
inner class GestureListener : SimpleOnGestureListener() {
override fun onLongPress(e: MotionEvent) {
mLongClick?.onLongClick(this@PhotoView)
}
override fun onDown(e: MotionEvent): Boolean {
hasOverTranslate = false
hasMultiTouch = false
canRotate = false
removeCallbacks(mClickRunnable)
return false
}
override fun onFling(
e1: MotionEvent,
e2: MotionEvent,
velocityX: Float,
velocityY: Float
): Boolean {
if (hasMultiTouch) return false
if (!imgLargeWidth && !imgLargeHeight) return false
if (mTranslate.isRunning) return false
var vx = velocityX
var vy = velocityY
if (mImgRect.left.roundToInt() >= mWidgetRect.left
|| mImgRect.right.roundToInt() <= mWidgetRect.right
) {
vx = 0f
}
if (mImgRect.top.roundToInt() >= mWidgetRect.top
|| mImgRect.bottom.roundToInt() <= mWidgetRect.bottom
) {
vy = 0f
}
if (canRotate || mDegrees % 90 != 0f) {
var toDegrees = (mDegrees / 90).toInt() * 90.toFloat()
val remainder = mDegrees % 90
if (remainder > 45) toDegrees += 90f else if (remainder < -45) toDegrees -= 90f
mTranslate.withRotate(mDegrees.toInt(), toDegrees.toInt())
mDegrees = toDegrees
}
doTranslateReset(mImgRect)
mTranslate.withFling(vx, vy)
mTranslate.start()
// onUp(e2);
return super.onFling(e1, e2, velocityX, velocityY)
}
override fun onScroll(
e1: MotionEvent,
e2: MotionEvent,
distanceX: Float,
distanceY: Float
): Boolean {
var x = distanceX
var y = distanceY
if (mTranslate.isRunning) {
mTranslate.stop()
}
if (canScrollHorizontallySelf(x)) {
if (x < 0 && mImgRect.left - x > mWidgetRect.left)
x = mImgRect.left
if (x > 0 && mImgRect.right - x < mWidgetRect.right)
x = mImgRect.right - mWidgetRect.right
mAnimMatrix.postTranslate(-x, 0f)
mTranslateX -= x.toInt()
} else if (imgLargeWidth || hasMultiTouch || hasOverTranslate) {
checkRect()
if (!hasMultiTouch) {
if (x < 0 && mImgRect.left - x > mCommonRect.left) x =
resistanceScrollByX(mImgRect.left - mCommonRect.left, x)
if (x > 0 && mImgRect.right - x < mCommonRect.right) x =
resistanceScrollByX(mImgRect.right - mCommonRect.right, x)
}
mTranslateX -= x.toInt()
mAnimMatrix.postTranslate(-x, 0f)
hasOverTranslate = true
}
if (canScrollVerticallySelf(y)) {
if (y < 0 && mImgRect.top - y > mWidgetRect.top) y =
mImgRect.top
if (y > 0 && mImgRect.bottom - y < mWidgetRect.bottom) y =
mImgRect.bottom - mWidgetRect.bottom
mAnimMatrix.postTranslate(0f, -y)
mTranslateY -= y.toInt()
} else if (imgLargeHeight || hasOverTranslate || hasMultiTouch) {
checkRect()
if (!hasMultiTouch) {
if (y < 0 && mImgRect.top - y > mCommonRect.top) y =
resistanceScrollByY(mImgRect.top - mCommonRect.top, y)
if (y > 0 && mImgRect.bottom - y < mCommonRect.bottom) y =
resistanceScrollByY(mImgRect.bottom - mCommonRect.bottom, y)
}
mAnimMatrix.postTranslate(0f, -y)
mTranslateY -= y.toInt()
hasOverTranslate = true
}
executeTranslate()
return true
}
override fun onSingleTapUp(e: MotionEvent): Boolean {
postDelayed(mClickRunnable, 250)
return false
}
override fun onDoubleTap(e: MotionEvent): Boolean {
mTranslate.stop()
val from: Float
val to: Float
val imgCx = mImgRect.left + mImgRect.width() / 2
val imgCy = mImgRect.top + mImgRect.height() / 2
mScaleCenter[imgCx] = imgCy
mRotateCenter[imgCx] = imgCy
mTranslateX = 0
mTranslateY = 0
if (isZoonUp) {
from = mScale
to = 1f
} else {
from = mScale
to = mMaxScale
mScaleCenter[e.x] = e.y
}
mTmpMatrix.reset()
mTmpMatrix.postTranslate(-mBaseRect.left, -mBaseRect.top)
mTmpMatrix.postTranslate(mRotateCenter.x, mRotateCenter.y)
mTmpMatrix.postTranslate(-mHalfBaseRectWidth, -mHalfBaseRectHeight)
mTmpMatrix.postRotate(mDegrees, mRotateCenter.x, mRotateCenter.y)
mTmpMatrix.postScale(to, to, mScaleCenter.x, mScaleCenter.y)
mTmpMatrix.postTranslate(mTranslateX.toFloat(), mTranslateY.toFloat())
mTmpMatrix.mapRect(mTmpRect, mBaseRect)
doTranslateReset(mTmpRect)
isZoonUp = !isZoonUp
mTranslate.withScale(from, to)
mTranslate.start()
return false
}
}
inner class ScaleGestureListener : OnScaleGestureListener {
override fun onScale(detector: ScaleGestureDetector): Boolean {
val scaleFactor = detector.scaleFactor
if (java.lang.Float.isNaN(scaleFactor) || java.lang.Float.isInfinite(scaleFactor)) return false
mScale *= scaleFactor
//mScaleCenter.set(detector.getFocusX(), detector.getFocusY());
mAnimMatrix.postScale(
scaleFactor,
scaleFactor,
detector.focusX,
detector.focusY
)
executeTranslate()
return true
}
override fun onScaleBegin(detector: ScaleGestureDetector): Boolean {
return true
}
override fun onScaleEnd(detector: ScaleGestureDetector) {}
}
} }

@ -11,7 +11,7 @@ import io.legado.app.utils.ColorUtils
import io.legado.app.utils.dp import io.legado.app.utils.dp
import io.legado.app.utils.getCompatColor import io.legado.app.utils.getCompatColor
class AccentBgTextView(context: Context, attrs: AttributeSet?) : class AccentBgTextView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) :
AppCompatTextView(context, attrs) { AppCompatTextView(context, attrs) {
private var radius = 0 private var radius = 0

@ -16,12 +16,12 @@ import io.legado.app.utils.visible
import kotlinx.android.synthetic.main.item_1line_text_and_del.view.* import kotlinx.android.synthetic.main.item_1line_text_and_del.view.*
import org.jetbrains.anko.sdk27.listeners.onClick import org.jetbrains.anko.sdk27.listeners.onClick
@Suppress("unused")
class AutoCompleteTextView : AppCompatAutoCompleteTextView { class AutoCompleteTextView @JvmOverloads constructor(
context: Context,
constructor(context: Context) : super(context) attrs: AttributeSet? = null,
defStyleAttr: Int = 0
constructor(context: Context, attrs: AttributeSet) : super(context, attrs) ) : AppCompatAutoCompleteTextView(context, attrs, defStyleAttr) {
var delCallBack: ((value: String) -> Unit)? = null var delCallBack: ((value: String) -> Unit)? = null
@ -33,7 +33,6 @@ class AutoCompleteTextView : AppCompatAutoCompleteTextView {
return true return true
} }
@SuppressLint("ClickableViewAccessibility") @SuppressLint("ClickableViewAccessibility")
override fun onTouchEvent(event: MotionEvent?): Boolean { override fun onTouchEvent(event: MotionEvent?): Boolean {
if (event?.action == MotionEvent.ACTION_DOWN) { if (event?.action == MotionEvent.ACTION_DOWN) {

Loading…
Cancel
Save