From a3ae89313f1ecf3fc33af50d1ead6e3b5222c591 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Wed, 2 Jan 2013 19:01:55 +0100 Subject: [PATCH] Fix get rotation method for view --- OsmAnd/src/net/osmand/ReflectionUtils.java | 22 +++++++++++++++++++ .../osmand/plus/activities/MapActivity.java | 8 +++++++ 2 files changed, 30 insertions(+) create mode 100644 OsmAnd/src/net/osmand/ReflectionUtils.java diff --git a/OsmAnd/src/net/osmand/ReflectionUtils.java b/OsmAnd/src/net/osmand/ReflectionUtils.java new file mode 100644 index 0000000000..0c93c9f70e --- /dev/null +++ b/OsmAnd/src/net/osmand/ReflectionUtils.java @@ -0,0 +1,22 @@ +package net.osmand; + +import java.lang.reflect.Method; + +import org.apache.commons.logging.Log; + +public class ReflectionUtils { + private static final Log log = LogUtil.getLog(ReflectionUtils.class); + + public static int callIntMethod(Object o, Class cl, String methodName, int defValue, Class[] parameterTypes, + Object... args){ + try { + Method m = cl.getDeclaredMethod(methodName, parameterTypes); + Integer i = (Integer) m.invoke(o, args); + return i.intValue(); + } catch (Exception e) { + log.debug("Reflection fails " + e.getMessage(), e); + } + return defValue; + } + +} diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index 7cab0815ed..8a1d8a79bd 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -10,6 +10,7 @@ import net.osmand.Algoritms; import net.osmand.GPXUtilities; import net.osmand.GPXUtilities.GPXFile; import net.osmand.LogUtil; +import net.osmand.ReflectionUtils; import net.osmand.Version; import net.osmand.access.AccessibilityPlugin; import net.osmand.access.AccessibleActivity; @@ -69,11 +70,13 @@ import android.os.Handler; import android.os.Message; import android.util.DisplayMetrics; import android.util.Log; +import android.view.Display; import android.view.Gravity; import android.view.KeyEvent; import android.view.Menu; import android.view.MenuItem; import android.view.MotionEvent; +import android.view.Surface; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup.LayoutParams; @@ -1291,8 +1294,13 @@ public class MapActivity extends AccessibleActivity implements IMapLocationListe public void onSensorChanged(SensorEvent event) { // Attention : sensor produces a lot of events & can hang the system float val = event.values[0]; + if(currentScreenOrientation == 1){ val += 90; + } else if(currentScreenOrientation == 2){ + val += 180; + } else if(currentScreenOrientation == 3){ + val += 270; } Location l = getLastKnownLocation(); if(l != null && previousCorrectionValue == 360) {