3
|
1 /* Copyright (c) 2014 Brad Greco <brad@bgreco.net>
|
|
2 *
|
|
3 * Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4 * of this software and associated documentation files (the "Software"), to
|
|
5 * deal in the Software without restriction, including without limitation the
|
|
6 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
7 * sell copies of the Software, and to permit persons to whom the Software is
|
|
8 * furnished to do so, subject to the following conditions:
|
|
9 *
|
|
10 * The above copyright notice and this permission notice shall be included in
|
|
11 * all copies or substantial portions of the Software.
|
|
12 *
|
|
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
18 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
19 * IN THE SOFTWARE.
|
|
20 */
|
|
21
|
|
22 package net.bgreco.gmapzoominvert;
|
|
23
|
|
24 import static de.robv.android.xposed.XposedHelpers.findAndHookMethod;
|
|
25
|
|
26 import android.app.AndroidAppHelper;
|
|
27 import android.view.MotionEvent;
|
|
28 import android.widget.Toast;
|
|
29
|
|
30 import de.robv.android.xposed.IXposedHookLoadPackage;
|
|
31 import de.robv.android.xposed.XC_MethodHook;
|
|
32 import de.robv.android.xposed.XposedBridge;
|
|
33 import de.robv.android.xposed.callbacks.XC_LoadPackage.LoadPackageParam;
|
|
34
|
|
35 public class GMapZoomInvert implements IXposedHookLoadPackage {
|
|
36
|
|
37 @Override
|
|
38 public void handleLoadPackage(LoadPackageParam lpparam) {
|
|
39 if(!lpparam.packageName.equals("com.google.android.apps.maps"))
|
|
40 return;
|
|
41
|
|
42 try {
|
|
43 findAndHookMethod("com.google.android.apps.gmm.base.views.map.MapViewContainer", lpparam.classLoader, "onInterceptTouchEvent", MotionEvent.class, motionEventHook);
|
|
44 } catch (Throwable e) {
|
|
45 XposedBridge.log(e);
|
|
46 XposedBridge.log("Could not hook MapViewContainer. Trying VectorMapViewImpl.");
|
|
47 try {
|
|
48 findAndHookMethod("com.google.android.apps.gmm.map.legacy.internal.vector.VectorMapViewImpl", lpparam.classLoader, "onTouchEvent", MotionEvent.class, motionEventHook);
|
|
49 } catch (Throwable e2) {
|
|
50 XposedBridge.log(e2);
|
|
51 XposedBridge.log("Could not hook VectorMapViewImpl.");
|
|
52 }
|
|
53 }
|
|
54 }
|
|
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 };
|
|
103 }
|