|
|
@ -200,7 +200,7 @@ class PhotoView : ImageView { |
|
|
|
override fun setImageResource(resId: Int) { |
|
|
|
override fun setImageResource(resId: Int) { |
|
|
|
var drawable: Drawable? = null |
|
|
|
var drawable: Drawable? = null |
|
|
|
try { |
|
|
|
try { |
|
|
|
drawable = resources.getDrawable(resId) |
|
|
|
drawable = resources.getDrawable(resId, null) |
|
|
|
} catch (e: Exception) { |
|
|
|
} catch (e: Exception) { |
|
|
|
} |
|
|
|
} |
|
|
|
setImageDrawable(drawable) |
|
|
|
setImageDrawable(drawable) |
|
|
@ -402,8 +402,8 @@ class PhotoView : ImageView { |
|
|
|
val pHeight = MeasureSpec.getSize(heightMeasureSpec) |
|
|
|
val pHeight = MeasureSpec.getSize(heightMeasureSpec) |
|
|
|
val widthMode = MeasureSpec.getMode(widthMeasureSpec) |
|
|
|
val widthMode = MeasureSpec.getMode(widthMeasureSpec) |
|
|
|
val heightMode = MeasureSpec.getMode(heightMeasureSpec) |
|
|
|
val heightMode = MeasureSpec.getMode(heightMeasureSpec) |
|
|
|
var width = 0 |
|
|
|
var width: Int |
|
|
|
var height = 0 |
|
|
|
var height: Int |
|
|
|
var p = layoutParams |
|
|
|
var p = layoutParams |
|
|
|
if (p == null) { |
|
|
|
if (p == null) { |
|
|
|
p = ViewGroup.LayoutParams( |
|
|
|
p = ViewGroup.LayoutParams( |
|
|
@ -703,47 +703,47 @@ class PhotoView : ImageView { |
|
|
|
distanceX: Float, |
|
|
|
distanceX: Float, |
|
|
|
distanceY: Float |
|
|
|
distanceY: Float |
|
|
|
): Boolean { |
|
|
|
): Boolean { |
|
|
|
var distanceX = distanceX |
|
|
|
var x = distanceX |
|
|
|
var distanceY = distanceY |
|
|
|
var y = distanceY |
|
|
|
if (mTranslate.isRunning) { |
|
|
|
if (mTranslate.isRunning) { |
|
|
|
mTranslate.stop() |
|
|
|
mTranslate.stop() |
|
|
|
} |
|
|
|
} |
|
|
|
if (canScrollHorizontallySelf(distanceX)) { |
|
|
|
if (canScrollHorizontallySelf(x)) { |
|
|
|
if (distanceX < 0 && mImgRect.left - distanceX > mWidgetRect.left) distanceX = |
|
|
|
if (x < 0 && mImgRect.left - x > mWidgetRect.left) |
|
|
|
mImgRect.left |
|
|
|
x = mImgRect.left |
|
|
|
if (distanceX > 0 && mImgRect.right - distanceX < mWidgetRect.right) distanceX = |
|
|
|
if (x > 0 && mImgRect.right - x < mWidgetRect.right) |
|
|
|
mImgRect.right - mWidgetRect.right |
|
|
|
x = mImgRect.right - mWidgetRect.right |
|
|
|
mAnimMatrix.postTranslate(-distanceX, 0f) |
|
|
|
mAnimMatrix.postTranslate(-x, 0f) |
|
|
|
mTranslateX -= distanceX.toInt() |
|
|
|
mTranslateX -= x.toInt() |
|
|
|
} else if (imgLargeWidth || hasMultiTouch || hasOverTranslate) { |
|
|
|
} else if (imgLargeWidth || hasMultiTouch || hasOverTranslate) { |
|
|
|
checkRect() |
|
|
|
checkRect() |
|
|
|
if (!hasMultiTouch) { |
|
|
|
if (!hasMultiTouch) { |
|
|
|
if (distanceX < 0 && mImgRect.left - distanceX > mCommonRect.left) distanceX = |
|
|
|
if (x < 0 && mImgRect.left - x > mCommonRect.left) x = |
|
|
|
resistanceScrollByX(mImgRect.left - mCommonRect.left, distanceX) |
|
|
|
resistanceScrollByX(mImgRect.left - mCommonRect.left, x) |
|
|
|
if (distanceX > 0 && mImgRect.right - distanceX < mCommonRect.right) distanceX = |
|
|
|
if (x > 0 && mImgRect.right - x < mCommonRect.right) x = |
|
|
|
resistanceScrollByX(mImgRect.right - mCommonRect.right, distanceX) |
|
|
|
resistanceScrollByX(mImgRect.right - mCommonRect.right, x) |
|
|
|
} |
|
|
|
} |
|
|
|
mTranslateX -= distanceX.toInt() |
|
|
|
mTranslateX -= x.toInt() |
|
|
|
mAnimMatrix.postTranslate(-distanceX, 0f) |
|
|
|
mAnimMatrix.postTranslate(-x, 0f) |
|
|
|
hasOverTranslate = true |
|
|
|
hasOverTranslate = true |
|
|
|
} |
|
|
|
} |
|
|
|
if (canScrollVerticallySelf(distanceY)) { |
|
|
|
if (canScrollVerticallySelf(y)) { |
|
|
|
if (distanceY < 0 && mImgRect.top - distanceY > mWidgetRect.top) distanceY = |
|
|
|
if (y < 0 && mImgRect.top - y > mWidgetRect.top) y = |
|
|
|
mImgRect.top |
|
|
|
mImgRect.top |
|
|
|
if (distanceY > 0 && mImgRect.bottom - distanceY < mWidgetRect.bottom) distanceY = |
|
|
|
if (y > 0 && mImgRect.bottom - y < mWidgetRect.bottom) y = |
|
|
|
mImgRect.bottom - mWidgetRect.bottom |
|
|
|
mImgRect.bottom - mWidgetRect.bottom |
|
|
|
mAnimMatrix.postTranslate(0f, -distanceY) |
|
|
|
mAnimMatrix.postTranslate(0f, -y) |
|
|
|
mTranslateY -= distanceY.toInt() |
|
|
|
mTranslateY -= y.toInt() |
|
|
|
} else if (imgLargeHeight || hasOverTranslate || hasMultiTouch) { |
|
|
|
} else if (imgLargeHeight || hasOverTranslate || hasMultiTouch) { |
|
|
|
checkRect() |
|
|
|
checkRect() |
|
|
|
if (!hasMultiTouch) { |
|
|
|
if (!hasMultiTouch) { |
|
|
|
if (distanceY < 0 && mImgRect.top - distanceY > mCommonRect.top) distanceY = |
|
|
|
if (y < 0 && mImgRect.top - y > mCommonRect.top) y = |
|
|
|
resistanceScrollByY(mImgRect.top - mCommonRect.top, distanceY) |
|
|
|
resistanceScrollByY(mImgRect.top - mCommonRect.top, y) |
|
|
|
if (distanceY > 0 && mImgRect.bottom - distanceY < mCommonRect.bottom) distanceY = |
|
|
|
if (y > 0 && mImgRect.bottom - y < mCommonRect.bottom) y = |
|
|
|
resistanceScrollByY(mImgRect.bottom - mCommonRect.bottom, distanceY) |
|
|
|
resistanceScrollByY(mImgRect.bottom - mCommonRect.bottom, y) |
|
|
|
} |
|
|
|
} |
|
|
|
mAnimMatrix.postTranslate(0f, -distanceY) |
|
|
|
mAnimMatrix.postTranslate(0f, -y) |
|
|
|
mTranslateY -= distanceY.toInt() |
|
|
|
mTranslateY -= y.toInt() |
|
|
|
hasOverTranslate = true |
|
|
|
hasOverTranslate = true |
|
|
|
} |
|
|
|
} |
|
|
|
executeTranslate() |
|
|
|
executeTranslate() |
|
|
@ -757,8 +757,8 @@ class PhotoView : ImageView { |
|
|
|
|
|
|
|
|
|
|
|
override fun onDoubleTap(e: MotionEvent): Boolean { |
|
|
|
override fun onDoubleTap(e: MotionEvent): Boolean { |
|
|
|
mTranslate.stop() |
|
|
|
mTranslate.stop() |
|
|
|
var from = 1f |
|
|
|
val from: Float |
|
|
|
var to = 1f |
|
|
|
val to: Float |
|
|
|
val imgCx = mImgRect.left + mImgRect.width() / 2 |
|
|
|
val imgCx = mImgRect.left + mImgRect.width() / 2 |
|
|
|
val imgCy = mImgRect.top + mImgRect.height() / 2 |
|
|
|
val imgCy = mImgRect.top + mImgRect.height() / 2 |
|
|
|
mScaleCenter[imgCx] = imgCy |
|
|
|
mScaleCenter[imgCx] = imgCy |
|
|
|