Port orientation correction also to DashFavoritesFragment

This commit is contained in:
sonora 2015-01-06 01:41:22 +01:00
parent 485e947f02
commit 8966b88a79

View file

@ -10,6 +10,7 @@ import android.util.TypedValue;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.Button; import android.widget.Button;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
@ -39,6 +40,11 @@ public class DashFavoritesFragment extends DashBaseFragment {
private net.osmand.Location location = null; private net.osmand.Location location = null;
private LatLon loc = null; private LatLon loc = null;
private Float heading = null; private Float heading = null;
private static final int ORIENTATION_0 = 0;
private static final int ORIENTATION_90 = 3;
private static final int ORIENTATION_270 = 1;
private List<ImageView> arrows = new ArrayList<ImageView>(); private List<ImageView> arrows = new ArrayList<ImageView>();
List<FavouritePoint> points = new ArrayList<FavouritePoint>(); List<FavouritePoint> points = new ArrayList<FavouritePoint>();
@ -176,10 +182,22 @@ public class DashFavoritesFragment extends DashBaseFragment {
Float h = heading; Float h = heading;
float a = h != null ? h : 0; float a = h != null ? h : 0;
//TODO: Hardy: The arrow direction below is correct only for the default display's standard orientation //Hardy: getRotation() is the correction if device's screen orientation != the default display's standard orientation
// i.e. still needs to be corrected for .ROTATION_90/180/170 //TODO: getOrientation() needs to be used for API<8, deprecated after that
// Keep in mind: getRotation was introduced from Android 2.2 int screenOrientation = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getRotation();
draw.setAngle(mes[1] - a + 180); switch (screenOrientation)
{
case ORIENTATION_0: // Portrait
screenOrientation = 0;
break;
case ORIENTATION_90: // Landscape right
screenOrientation = 90;
break;
case ORIENTATION_270: // Landscape left
screenOrientation = 270;
break;
}
draw.setAngle(mes[1] - a + 180 + screenOrientation);
direction.setImageDrawable(draw); direction.setImageDrawable(draw);
} }