mirror of
https://github.com/revanced/revanced-integrations.git
synced 2025-01-15 06:17:31 +01:00
feat(GitHub): Add Pinch to zoom
patch
This commit is contained in:
parent
130f629f6b
commit
3f81d187b5
@ -0,0 +1,40 @@
|
||||
package app.revanced.github;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.ScaleGestureDetector;
|
||||
import android.view.View;
|
||||
|
||||
public class PinchToZoomGesture implements View.OnTouchListener, ScaleGestureDetector.OnScaleGestureListener {
|
||||
private View view;
|
||||
private final ScaleGestureDetector gestureScale;
|
||||
private float scaleFactor = 1;
|
||||
|
||||
public PinchToZoomGesture(Context c){ gestureScale = new ScaleGestureDetector(c, this); }
|
||||
|
||||
@Override
|
||||
public boolean onTouch(View view, MotionEvent event) {
|
||||
this.view = view;
|
||||
view.onTouchEvent(event);
|
||||
return gestureScale.onTouchEvent(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onScale(ScaleGestureDetector detector) {
|
||||
scaleFactor *= detector.getScaleFactor();
|
||||
scaleFactor = (scaleFactor < 1 ? 1 : scaleFactor); // prevent our view from becoming too small //
|
||||
scaleFactor = ((float)((int)(scaleFactor * 100))) / 100; // Change precision to help with jitter when user just rests their fingers //
|
||||
view.setScaleX(scaleFactor);
|
||||
view.setScaleY(scaleFactor);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onScaleBegin(ScaleGestureDetector detector) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onScaleEnd(ScaleGestureDetector detector) {
|
||||
}
|
||||
}
|
19
app/src/main/java/app/revanced/github/PinchToZoomPatch.java
Normal file
19
app/src/main/java/app/revanced/github/PinchToZoomPatch.java
Normal file
@ -0,0 +1,19 @@
|
||||
package app.revanced.github;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.util.Log;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
public final class PinchToZoomPatch {
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
private static ViewGroup recyclerView;
|
||||
|
||||
public static void addPinchToZoomGesture(final ViewGroup codeViewRecycleView) {
|
||||
if (recyclerView == codeViewRecycleView) return;
|
||||
recyclerView = codeViewRecycleView;
|
||||
|
||||
recyclerView.setOnTouchListener(new PinchToZoomGesture(recyclerView.getContext()));
|
||||
|
||||
Log.d("revanced", "Adding pinch to zoom event handler to " + codeViewRecycleView);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user