From 35fd321ad7aae6ce5a9c968400a74e64c73e42a3 Mon Sep 17 00:00:00 2001 From: jolojo500 <193266106+jolojo500@users.noreply.github.com> Date: Fri, 9 May 2025 22:42:09 -0400 Subject: [PATCH 1/4] added ZoomLayout class under widget folder, should allow pinching. Currently a WIP --- .idea/AndroidProjectSystem.xml | 6 ++ .idea/artifacts/library_jvm_1_0_0.xml | 8 +++ .idea/compiler.xml | 2 +- .idea/deploymentTargetSelector.xml | 10 +++ .idea/gradle.xml | 1 - .idea/kotlinc.xml | 6 ++ .idea/runConfigurations.xml | 17 +++++ ...otlin-compiler-11440818964675593749.salive | 0 .../cloudstream3/widget/ZoomLayout.kt | 64 +++++++++++++++++++ 9 files changed, 112 insertions(+), 2 deletions(-) create mode 100644 .idea/AndroidProjectSystem.xml create mode 100644 .idea/artifacts/library_jvm_1_0_0.xml create mode 100644 .idea/deploymentTargetSelector.xml create mode 100644 .idea/kotlinc.xml create mode 100644 .idea/runConfigurations.xml create mode 100644 .kotlin/sessions/kotlin-compiler-11440818964675593749.salive create mode 100644 app/src/main/java/com/lagradost/cloudstream3/widget/ZoomLayout.kt diff --git a/.idea/AndroidProjectSystem.xml b/.idea/AndroidProjectSystem.xml new file mode 100644 index 0000000000..4a53bee8cb --- /dev/null +++ b/.idea/AndroidProjectSystem.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/artifacts/library_jvm_1_0_0.xml b/.idea/artifacts/library_jvm_1_0_0.xml new file mode 100644 index 0000000000..aa29393f4b --- /dev/null +++ b/.idea/artifacts/library_jvm_1_0_0.xml @@ -0,0 +1,8 @@ + + + $PROJECT_DIR$/library/build/libs + + + + + \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml index b589d56e9f..b86273d942 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/.idea/deploymentTargetSelector.xml b/.idea/deploymentTargetSelector.xml new file mode 100644 index 0000000000..b268ef36cd --- /dev/null +++ b/.idea/deploymentTargetSelector.xml @@ -0,0 +1,10 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml index d06216153d..4a0157633d 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -15,7 +15,6 @@ - diff --git a/.idea/kotlinc.xml b/.idea/kotlinc.xml new file mode 100644 index 0000000000..c22b6fa9ee --- /dev/null +++ b/.idea/kotlinc.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml new file mode 100644 index 0000000000..16660f1d80 --- /dev/null +++ b/.idea/runConfigurations.xml @@ -0,0 +1,17 @@ + + + + + + \ No newline at end of file diff --git a/.kotlin/sessions/kotlin-compiler-11440818964675593749.salive b/.kotlin/sessions/kotlin-compiler-11440818964675593749.salive new file mode 100644 index 0000000000..e69de29bb2 diff --git a/app/src/main/java/com/lagradost/cloudstream3/widget/ZoomLayout.kt b/app/src/main/java/com/lagradost/cloudstream3/widget/ZoomLayout.kt new file mode 100644 index 0000000000..fc79c9f174 --- /dev/null +++ b/app/src/main/java/com/lagradost/cloudstream3/widget/ZoomLayout.kt @@ -0,0 +1,64 @@ +package com.lagradost.cloudstream3.widget + +import android.content.Context +import android.graphics.Canvas +import android.util.AttributeSet +import android.view.MotionEvent +import android.view.ScaleGestureDetector +import android.widget.FrameLayout + +/** + *This is a container that lets the user pinch to zoom its entire contents + */ +class ZoomLayout @JvmOverloads constructor( //Why not + context: Context, + attrs: AttributeSet? = null +) : FrameLayout(context, attrs), ScaleGestureDetector.OnScaleGestureListener { + + private var scaleFactor = 1f //current scale factor + + //pivot points + private var focusX = 0f + private var focusY = 0f + + //the gesture detector + private val detector = ScaleGestureDetector(context, this) + + override fun onInterceptTouchEvent(ev: MotionEvent): Boolean { + //lets the detector see all touches + detector.onTouchEvent(ev) + //if we're in a scaling gesture, intercept so children don't steal it + return detector.isInProgress || super.onInterceptTouchEvent(ev) + } + + override fun onTouchEvent(ev: MotionEvent): Boolean { + detector.onTouchEvent(ev) + //consume all touch events to keep the zooming based on the current view + return true + } + + override fun dispatchDraw(canvas: Canvas) { + //before drawing children, scale the canvas around the pivot point + canvas.save() + canvas.translate(focusX, focusY) + canvas.scale(scaleFactor, scaleFactor) + canvas.translate(-focusX, -focusY) + super.dispatchDraw(canvas) + canvas.restore() + } + + //scaleGestureDetector callbacks + override fun onScaleBegin(detector: ScaleGestureDetector) = true + + override fun onScale(detector: ScaleGestureDetector): Boolean { + // Update scale and pivot + scaleFactor = (scaleFactor * detector.scaleFactor).coerceIn(0.5f, 3.0f) + focusX = detector.focusX + focusY = detector.focusY + // Tell Android we need to redraw + invalidate() + return true + } + + override fun onScaleEnd(detector: ScaleGestureDetector) { /* no-op */ } +} From d04862007aec6c1b1bbdc0e5490552a079f46253 Mon Sep 17 00:00:00 2001 From: jolojo500 <193266106+jolojo500@users.noreply.github.com> Date: Fri, 9 May 2025 22:43:57 -0400 Subject: [PATCH 2/4] added the zoomlayout to activity_main.xml. Tis project is well made lol good thing the root is easilly accessible. Works but not the best. WIP2 --- app/src/main/res/layout/activity_main.xml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index a06e6a157c..3dd2e36686 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -1,4 +1,10 @@ + + - \ No newline at end of file + + \ No newline at end of file From c6d210824d39c99d9ed4f2e59996fbda16a0189e Mon Sep 17 00:00:00 2001 From: jolojo500 <193266106+jolojo500@users.noreply.github.com> Date: Fri, 9 May 2025 23:20:49 -0400 Subject: [PATCH 3/4] not wokring attemp at nice behavior from no more gesture. FCauses crasheds becasue of animation intialized wron --- .idea/deploymentTargetSelector.xml | 8 +++++ ...tlin-compiler-13831499684968255860.salive} | 0 .../cloudstream3/widget/ZoomLayout.kt | 35 ++++++++++++++++++- 3 files changed, 42 insertions(+), 1 deletion(-) rename .kotlin/sessions/{kotlin-compiler-11440818964675593749.salive => kotlin-compiler-13831499684968255860.salive} (100%) diff --git a/.idea/deploymentTargetSelector.xml b/.idea/deploymentTargetSelector.xml index b268ef36cd..fe3f085ffb 100644 --- a/.idea/deploymentTargetSelector.xml +++ b/.idea/deploymentTargetSelector.xml @@ -4,6 +4,14 @@ diff --git a/.kotlin/sessions/kotlin-compiler-11440818964675593749.salive b/.kotlin/sessions/kotlin-compiler-13831499684968255860.salive similarity index 100% rename from .kotlin/sessions/kotlin-compiler-11440818964675593749.salive rename to .kotlin/sessions/kotlin-compiler-13831499684968255860.salive diff --git a/app/src/main/java/com/lagradost/cloudstream3/widget/ZoomLayout.kt b/app/src/main/java/com/lagradost/cloudstream3/widget/ZoomLayout.kt index fc79c9f174..4c90b722f0 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/widget/ZoomLayout.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/widget/ZoomLayout.kt @@ -6,6 +6,8 @@ import android.util.AttributeSet import android.view.MotionEvent import android.view.ScaleGestureDetector import android.widget.FrameLayout +import android.animation.ValueAnimator +import androidx.interpolator.view.animation.FastOutSlowInInterpolator /** *This is a container that lets the user pinch to zoom its entire contents @@ -24,6 +26,27 @@ class ZoomLayout @JvmOverloads constructor( //Why not //the gesture detector private val detector = ScaleGestureDetector(context, this) + //animator that resets scaleFactor/focus back to defaults + private val resetAnimator = ValueAnimator().apply { + interpolator = FastOutSlowInInterpolator() + duration = 300L + addUpdateListener { anim -> + // anim.animatedValue will go from 1f → 0f + val fraction = anim.animatedFraction + // lerp scaleFactor from current → 1f + scaleFactor = lerp(scaleFactorStart, 1f, fraction) + // lerp focus back to center + focusX = lerp(focusXStart, width / 2f, fraction) + focusY = lerp(focusYStart, height / 2f, fraction) + invalidate() + } + } + + + private var scaleFactorStart = 1f + private var focusXStart = 0f + private var focusYStart = 0f + override fun onInterceptTouchEvent(ev: MotionEvent): Boolean { //lets the detector see all touches detector.onTouchEvent(ev) @@ -60,5 +83,15 @@ class ZoomLayout @JvmOverloads constructor( //Why not return true } - override fun onScaleEnd(detector: ScaleGestureDetector) { /* no-op */ } + + //we now use it for a cleaner approach since it already works + override fun onScaleEnd(detector: ScaleGestureDetector) { + scaleFactorStart = scaleFactor + focusXStart = focusX + focusYStart = focusY + resetAnimator.start() + } + + //simple helper + private fun lerp(a: Float, b: Float, t: Float): Float = a + (b - a) * t } From 962dcf1b646d696f613a76a1ed083aa154eb9157 Mon Sep 17 00:00:00 2001 From: jolojo500 <193266106+jolojo500@users.noreply.github.com> Date: Fri, 9 May 2025 23:26:23 -0400 Subject: [PATCH 4/4] changed ValueAnimator() to ValueAnimator.ofFloat(0f,1f) so internal PorpertyValuesHolder isnt null. ZoomLayout no sbehaves smoothly. Verified the pinch to zoom gesture on real device and works without crashes.This commit should close #1619 --- ...255860.salive => kotlin-compiler-2935608288755244211.salive} | 0 .../main/java/com/lagradost/cloudstream3/widget/ZoomLayout.kt | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename .kotlin/sessions/{kotlin-compiler-13831499684968255860.salive => kotlin-compiler-2935608288755244211.salive} (100%) diff --git a/.kotlin/sessions/kotlin-compiler-13831499684968255860.salive b/.kotlin/sessions/kotlin-compiler-2935608288755244211.salive similarity index 100% rename from .kotlin/sessions/kotlin-compiler-13831499684968255860.salive rename to .kotlin/sessions/kotlin-compiler-2935608288755244211.salive diff --git a/app/src/main/java/com/lagradost/cloudstream3/widget/ZoomLayout.kt b/app/src/main/java/com/lagradost/cloudstream3/widget/ZoomLayout.kt index 4c90b722f0..45e07cdbd6 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/widget/ZoomLayout.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/widget/ZoomLayout.kt @@ -27,7 +27,7 @@ class ZoomLayout @JvmOverloads constructor( //Why not private val detector = ScaleGestureDetector(context, this) //animator that resets scaleFactor/focus back to defaults - private val resetAnimator = ValueAnimator().apply { + private val resetAnimator = ValueAnimator.ofFloat(0f,1f).apply { interpolator = FastOutSlowInInterpolator() duration = 300L addUpdateListener { anim ->