Mercurial > gmapzoominvert
comparison app/src/main/java/net/bgreco/gmapzoominvert/GMapZoomInvert.java @ 3:c1204965159f
Update for new Maps version
author | Brad Greco <brad@bgreco.net> |
---|---|
date | Wed, 05 Sep 2018 21:23:32 -0400 |
parents | fbccc77ea0e6 |
children |
comparison
equal
deleted
inserted
replaced
2:fbccc77ea0e6 | 3:c1204965159f |
---|---|
20 */ | 20 */ |
21 | 21 |
22 package net.bgreco.gmapzoominvert; | 22 package net.bgreco.gmapzoominvert; |
23 | 23 |
24 import static de.robv.android.xposed.XposedHelpers.findAndHookMethod; | 24 import static de.robv.android.xposed.XposedHelpers.findAndHookMethod; |
25 | |
26 import android.app.AndroidAppHelper; | |
25 import android.view.MotionEvent; | 27 import android.view.MotionEvent; |
28 import android.widget.Toast; | |
29 | |
26 import de.robv.android.xposed.IXposedHookLoadPackage; | 30 import de.robv.android.xposed.IXposedHookLoadPackage; |
27 import de.robv.android.xposed.XC_MethodHook; | 31 import de.robv.android.xposed.XC_MethodHook; |
32 import de.robv.android.xposed.XposedBridge; | |
28 import de.robv.android.xposed.callbacks.XC_LoadPackage.LoadPackageParam; | 33 import de.robv.android.xposed.callbacks.XC_LoadPackage.LoadPackageParam; |
29 | 34 |
30 public class GMapZoomInvert implements IXposedHookLoadPackage { | 35 public class GMapZoomInvert implements IXposedHookLoadPackage { |
31 | 36 |
32 @Override | 37 @Override |
33 public void handleLoadPackage(LoadPackageParam lpparam) throws Throwable { | 38 public void handleLoadPackage(LoadPackageParam lpparam) { |
34 if(!lpparam.packageName.equals("com.google.android.apps.maps")) | 39 if(!lpparam.packageName.equals("com.google.android.apps.maps")) |
35 return; | 40 return; |
36 | |
37 findAndHookMethod("com.google.android.apps.gmm.map.legacy.internal.vector.VectorMapViewImpl", lpparam.classLoader, "onTouchEvent", MotionEvent.class, new XC_MethodHook() { | |
38 | 41 |
39 private float lastTapX; | 42 try { |
40 private float lastTapY; | 43 findAndHookMethod("com.google.android.apps.gmm.base.views.map.MapViewContainer", lpparam.classLoader, "onInterceptTouchEvent", MotionEvent.class, motionEventHook); |
41 private long lastTapTime = 0; | 44 } catch (Throwable e) { |
42 private boolean doubleTap = false; | 45 XposedBridge.log(e); |
43 private boolean zooming = false; | 46 XposedBridge.log("Could not hook MapViewContainer. Trying VectorMapViewImpl."); |
44 | 47 try { |
45 @Override | 48 findAndHookMethod("com.google.android.apps.gmm.map.legacy.internal.vector.VectorMapViewImpl", lpparam.classLoader, "onTouchEvent", MotionEvent.class, motionEventHook); |
46 protected void beforeHookedMethod(MethodHookParam param) throws Throwable { | 49 } catch (Throwable e2) { |
47 MotionEvent e = (MotionEvent) param.args[0]; | 50 XposedBridge.log(e2); |
48 int action = e.getAction(); | 51 XposedBridge.log("Could not hook VectorMapViewImpl."); |
49 // Detect double taps | 52 } |
50 if(action == MotionEvent.ACTION_DOWN) { | 53 } |
51 // Do our best to mimic the Google Maps double tap detection logic | 54 } |
52 if(e.getEventTime() < lastTapTime + 250) { | |
53 if(e.getX() - lastTapX > -150 && e.getX() - lastTapX < 100 && e.getY() - lastTapY > -150 && e.getY() - lastTapY < 100) { | |
54 doubleTap = true; | |
55 } | |
56 } | |
57 lastTapTime = e.getEventTime(); | |
58 lastTapX = e.getX(); | |
59 lastTapY = e.getY(); | |
60 } else if(action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) { | |
61 // Also Invert the Y axis on release, otherwise the zoom will snap back | |
62 if(zooming) { | |
63 e.setLocation(e.getX(), lastTapY - (e.getY() - lastTapY)); | |
64 param.args[0] = e; | |
65 } | |
66 doubleTap = false; | |
67 zooming = false; | |
68 } else if(action == MotionEvent.ACTION_MOVE) { | |
69 // Invert the Y axis of the zoom gesture | |
70 if(e.getPointerCount() == 1) { | |
71 if(doubleTap) { | |
72 //Log.d("gmapzoominvert", "y offset: " + (lastTapY - e.getY())); | |
73 e.setLocation(e.getX(), lastTapY - (e.getY() - lastTapY)); | |
74 param.args[0] = e; | |
75 zooming = true; | |
76 } | |
77 } else { | |
78 // Another finger pressed cancels the zoom gesture | |
79 doubleTap = false; | |
80 zooming = false; | |
81 } | |
82 } | |
83 } | |
84 | |
85 }); | |
86 } | |
87 | 55 |
56 private XC_MethodHook motionEventHook = new XC_MethodHook() { | |
57 private float lastTapX; | |
58 private float lastTapY; | |
59 private long lastTapTime = 0; | |
60 private boolean doubleTap = false; | |
61 private boolean zooming = false; | |
62 | |
63 @Override | |
64 protected void beforeHookedMethod(MethodHookParam param) { | |
65 MotionEvent e = (MotionEvent) param.args[0]; | |
66 int action = e.getAction(); | |
67 // Detect double taps | |
68 if(action == MotionEvent.ACTION_DOWN) { | |
69 // Do our best to mimic the Google Maps double tap detection logic | |
70 if(e.getEventTime() < lastTapTime + 250) { | |
71 if(e.getX() - lastTapX > -150 && e.getX() - lastTapX < 100 && e.getY() - lastTapY > -150 && e.getY() - lastTapY < 100) { | |
72 doubleTap = true; | |
73 } | |
74 } | |
75 lastTapTime = e.getEventTime(); | |
76 lastTapX = e.getX(); | |
77 lastTapY = e.getY(); | |
78 } else if(action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) { | |
79 // Also Invert the Y axis on release, otherwise the zoom will snap back | |
80 if(zooming) { | |
81 e.setLocation(e.getX(), lastTapY - (e.getY() - lastTapY)); | |
82 param.args[0] = e; | |
83 } | |
84 doubleTap = false; | |
85 zooming = false; | |
86 } else if(action == MotionEvent.ACTION_MOVE) { | |
87 // Invert the Y axis of the zoom gesture | |
88 if(e.getPointerCount() == 1) { | |
89 if(doubleTap) { | |
90 //Log.d("gmapzoominvert", "y offset: " + (lastTapY - e.getY())); | |
91 e.setLocation(e.getX(), lastTapY - (e.getY() - lastTapY)); | |
92 param.args[0] = e; | |
93 zooming = true; | |
94 } | |
95 } else { | |
96 // Another finger pressed cancels the zoom gesture | |
97 doubleTap = false; | |
98 zooming = false; | |
99 } | |
100 } | |
101 } | |
102 }; | |
88 } | 103 } |