Mercurial > gmapzoominvert
comparison GMapZoomInvert/src/net/bgreco/gmapzoominvert/GMapZoomInvert.java @ 0:3da8a7a621cd
Initial commit
author | Brad Greco <brad@bgreco.net> |
---|---|
date | Mon, 20 Jan 2014 22:56:13 -0600 |
parents | |
children | 30f975176f8e |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:3da8a7a621cd |
---|---|
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 import android.view.MotionEvent; | |
26 import de.robv.android.xposed.IXposedHookLoadPackage; | |
27 import de.robv.android.xposed.XC_MethodHook; | |
28 import de.robv.android.xposed.callbacks.XC_LoadPackage.LoadPackageParam; | |
29 | |
30 public class GMapZoomInvert implements IXposedHookLoadPackage { | |
31 | |
32 private float lastTapX; | |
33 private float lastTapY; | |
34 private long lastTapTime = 0; | |
35 private boolean doubleTap = false; | |
36 private boolean zooming = false; | |
37 | |
38 @Override | |
39 public void handleLoadPackage(LoadPackageParam lpparam) throws Throwable { | |
40 if(!lpparam.packageName.equals("com.google.android.apps.maps")) | |
41 return; | |
42 | |
43 findAndHookMethod("com.google.android.apps.gmm.map.legacy.internal.vector.VectorMapViewImpl", lpparam.classLoader, "onTouchEvent", MotionEvent.class, new XC_MethodHook() { | |
44 | |
45 @Override | |
46 protected void beforeHookedMethod(MethodHookParam param) throws Throwable { | |
47 MotionEvent e = (MotionEvent) param.args[0]; | |
48 int action = e.getAction(); | |
49 // Detect double taps | |
50 if(action == MotionEvent.ACTION_DOWN) { | |
51 // Do our best to mimic the Google Maps double tap detection logic | |
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 | |
88 } |