changeset 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 3ec20fbf7dc5
files .hgignore app/build.gradle app/src/main/java/net/bgreco/gmapzoominvert/GMapZoomInvert.java
diffstat 3 files changed, 106 insertions(+), 92 deletions(-) [+]
line wrap: on
line diff
--- a/.hgignore	Wed Sep 05 20:07:35 2018 -0400
+++ b/.hgignore	Wed Sep 05 21:23:32 2018 -0400
@@ -7,3 +7,6 @@
 app/build
 captures
 .externalNativeBuild
+build
+keystore.jks
+app\release\output.json
\ No newline at end of file
--- a/app/build.gradle	Wed Sep 05 20:07:35 2018 -0400
+++ b/app/build.gradle	Wed Sep 05 21:23:32 2018 -0400
@@ -24,9 +24,5 @@
 
 dependencies {
     implementation fileTree(dir: 'libs', include: ['*.jar'])
-    implementation 'com.android.support:appcompat-v7:27.1.1'
-    testImplementation 'junit:junit:4.12'
-    androidTestImplementation 'com.android.support.test:runner:1.0.2'
-    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
     compileOnly 'de.robv.android.xposed:api:82'
 }
--- a/app/src/main/java/net/bgreco/gmapzoominvert/GMapZoomInvert.java	Wed Sep 05 20:07:35 2018 -0400
+++ b/app/src/main/java/net/bgreco/gmapzoominvert/GMapZoomInvert.java	Wed Sep 05 21:23:32 2018 -0400
@@ -1,88 +1,103 @@
-/* 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 {
-
-	@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() {
-
-			private float lastTapX;
-			private float lastTapY;
-			private long lastTapTime = 0;
-			private boolean doubleTap = false;
-			private boolean zooming = false;
-			
-			@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;
-					}
-				}
-			}
-			
-		});
-	}
-
-}
+/* 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.app.AndroidAppHelper;
+import android.view.MotionEvent;
+import android.widget.Toast;
+
+import de.robv.android.xposed.IXposedHookLoadPackage;
+import de.robv.android.xposed.XC_MethodHook;
+import de.robv.android.xposed.XposedBridge;
+import de.robv.android.xposed.callbacks.XC_LoadPackage.LoadPackageParam;
+
+public class GMapZoomInvert implements IXposedHookLoadPackage {
+
+    @Override
+    public void handleLoadPackage(LoadPackageParam lpparam) {
+        if(!lpparam.packageName.equals("com.google.android.apps.maps"))
+            return;
+
+        try {
+            findAndHookMethod("com.google.android.apps.gmm.base.views.map.MapViewContainer", lpparam.classLoader, "onInterceptTouchEvent", MotionEvent.class, motionEventHook);
+        } catch (Throwable e) {
+            XposedBridge.log(e);
+            XposedBridge.log("Could not hook MapViewContainer. Trying VectorMapViewImpl.");
+            try {
+                findAndHookMethod("com.google.android.apps.gmm.map.legacy.internal.vector.VectorMapViewImpl", lpparam.classLoader, "onTouchEvent", MotionEvent.class, motionEventHook);
+            } catch (Throwable e2) {
+                XposedBridge.log(e2);
+                XposedBridge.log("Could not hook VectorMapViewImpl.");
+            }
+        }
+    }
+
+    private XC_MethodHook motionEventHook = new XC_MethodHook() {
+        private float lastTapX;
+        private float lastTapY;
+        private long lastTapTime = 0;
+        private boolean doubleTap = false;
+        private boolean zooming = false;
+
+        @Override
+        protected void beforeHookedMethod(MethodHookParam param) {
+            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;
+                }
+            }
+        }
+    };
+}