diff options
author | Leith Bade <leith@mapbox.com> | 2015-02-26 11:16:14 -0800 |
---|---|---|
committer | Leith Bade <leith@mapbox.com> | 2015-02-26 11:16:14 -0800 |
commit | a5430e8730897924ab484b406a70eaf7bc89bd2f (patch) | |
tree | 746b5b91323d1050c2705dd936edfd5291b7b96a /android/java | |
parent | d0109fb834f15127fc12c95c17e5dd089eb90d0c (diff) | |
download | qtlocation-mapboxgl-a5430e8730897924ab484b406a70eaf7bc89bd2f.tar.gz |
Replace setRotation with Matrix
Diffstat (limited to 'android/java')
-rw-r--r-- | android/java/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxgl/testapp/MainActivity.java | 17 | ||||
-rw-r--r-- | android/java/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_main.xml | 4 |
2 files changed, 16 insertions, 5 deletions
diff --git a/android/java/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxgl/testapp/MainActivity.java b/android/java/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxgl/testapp/MainActivity.java index 4970760414..bd7100d98d 100644 --- a/android/java/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxgl/testapp/MainActivity.java +++ b/android/java/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxgl/testapp/MainActivity.java @@ -1,6 +1,7 @@ package com.mapbox.mapboxgl.testapp; import android.content.Context; +import android.graphics.Matrix; import android.graphics.PointF; import android.hardware.GeomagneticField; import android.hardware.Sensor; @@ -462,8 +463,18 @@ public class MainActivity extends ActionBarActivity { } } + // Rotates an ImageView - does not work if the ImageView has padding, use margins + private void rotateImageView(ImageView imageView, float angle) { + Matrix matrix = new Matrix(); + matrix.setScale((float) imageView.getWidth() / (float) imageView.getDrawable().getIntrinsicWidth(), (float) imageView.getHeight() / (float) imageView.getDrawable().getIntrinsicHeight()); + matrix.postRotate(angle, (float) imageView.getWidth() / 2.0f, (float) imageView.getHeight() / 2.0f); + imageView.setImageMatrix(matrix); + imageView.setScaleType(ImageView.ScaleType.MATRIX); + } + + // Updates the UI to match the current map's position private void updateMap() { - mCompassView.setRotation((float) mMapFragment.getMap().getDirection()); + rotateImageView(mCompassView, (float) mMapFragment.getMap().getDirection()); if (mGpsLocation != null) { mGpsMarker.setVisibility(View.VISIBLE); @@ -477,7 +488,7 @@ public class MainActivity extends ActionBarActivity { lp.topMargin = mMapFrameLayout.getHeight() - (int) ((screenLocation.y + 54.0f / 2.0f) * mDensity); mGpsMarker.setLayoutParams(lp); float bearing = mGpsLocation.hasBearing() ? mGpsLocation.getBearing() : mCompassBearing; - mGpsMarker.setRotation(bearing); + rotateImageView(mGpsMarker, bearing); mGpsMarker.requestLayout(); } else { mGpsMarker.setImageResource(R.drawable.location_marker); @@ -485,7 +496,7 @@ public class MainActivity extends ActionBarActivity { lp.leftMargin = (int) ((screenLocation.x - 27.0f / 2.0f) * mDensity); lp.topMargin = mMapFrameLayout.getHeight() - (int) ((screenLocation.y + 27.0f / 2.0f) * mDensity); mGpsMarker.setLayoutParams(lp); - mGpsMarker.setRotation(0.0f); + rotateImageView(mGpsMarker, 0.0f); mGpsMarker.requestLayout(); } } else { diff --git a/android/java/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_main.xml b/android/java/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_main.xml index 7d646222b2..6a9bf8266a 100644 --- a/android/java/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_main.xml +++ b/android/java/MapboxGLAndroidSDKTestApp/src/main/res/layout/activity_main.xml @@ -42,7 +42,7 @@ android:layout_width="48dp" android:layout_height="48dp" android:layout_gravity="end|top" - android:padding="10dp" + android:layout_margin="10dp" android:contentDescription="@string/compass_desc" android:src="@drawable/compass"/> @@ -52,7 +52,7 @@ android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceLarge" android:text="@string/label_fps" - android:padding="10dp" /> + android:layout_margin="10dp" /> </FrameLayout> </LinearLayout> |