diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/GMapZoomInvert/src/net/bgreco/gmapzoominvert/GMapZoomInvert.java	Mon Jan 20 22:56:13 2014 -0600
@@ -0,0 +1,88 @@
+/* Copyright (c) 2014 Brad Greco <brad@bgreco.net>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+package net.bgreco.gmapzoominvert;
+
+import static de.robv.android.xposed.XposedHelpers.findAndHookMethod;
+import android.view.MotionEvent;
+import de.robv.android.xposed.IXposedHookLoadPackage;
+import de.robv.android.xposed.XC_MethodHook;
+import de.robv.android.xposed.callbacks.XC_LoadPackage.LoadPackageParam;
+
+public class GMapZoomInvert implements IXposedHookLoadPackage {
+
+	private float lastTapX;
+	private float lastTapY;
+	private long lastTapTime = 0;
+	private boolean doubleTap = false;
+	private boolean zooming = false;
+	
+	@Override
+	public void handleLoadPackage(LoadPackageParam lpparam) throws Throwable {
+		if(!lpparam.packageName.equals("com.google.android.apps.maps"))
+			return;
+		
+		findAndHookMethod("com.google.android.apps.gmm.map.legacy.internal.vector.VectorMapViewImpl", lpparam.classLoader, "onTouchEvent", MotionEvent.class, new XC_MethodHook() {
+
+			@Override
+			protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
+				MotionEvent e = (MotionEvent) param.args[0];
+				int action = e.getAction();
+				// Detect double taps
+				if(action == MotionEvent.ACTION_DOWN) {
+					// Do our best to mimic the Google Maps double tap detection logic
+					if(e.getEventTime() < lastTapTime + 250) {
+						if(e.getX() - lastTapX > -150 && e.getX() - lastTapX < 100 && e.getY() - lastTapY > -150 && e.getY() - lastTapY < 100) {
+							doubleTap = true;
+						}
+					}
+					lastTapTime = e.getEventTime();
+					lastTapX = e.getX();
+					lastTapY = e.getY();
+				} else if(action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) {
+					// Also Invert the Y axis on release, otherwise the zoom will snap back
+					if(zooming) {
+						e.setLocation(e.getX(), lastTapY - (e.getY() - lastTapY));
+						param.args[0] = e;
+					}
+					doubleTap = false;
+					zooming = false;
+				} else if(action == MotionEvent.ACTION_MOVE) {
+					// Invert the Y axis of the zoom gesture
+					if(e.getPointerCount() == 1) {
+						if(doubleTap) {
+							//Log.d("gmapzoominvert", "y offset: " + (lastTapY - e.getY()));
+							e.setLocation(e.getX(), lastTapY - (e.getY() - lastTapY));
+							param.args[0] = e;
+							zooming = true;
+						}
+					} else {
+						// Another finger pressed cancels the zoom gesture
+						doubleTap = false;
+						zooming = false;
+					}
+				}
+			}
+			
+		});
+	}
+
+}