From 6ea73abf2b068773c00cfebe286bac50c12f88f9 Mon Sep 17 00:00:00 2001 From: Tobias Zwick Date: Sat, 9 Jun 2018 01:28:38 +0200 Subject: [PATCH] fix #1057 --- .../quests/bikeway/AddCyclewayForm.java | 6 +- .../tangram/MapControlsFragment.java | 9 +- .../streetcomplete/view/CompassView.java | 102 ------------------ .../drawable/ic_compass_needle_black_24dp.xml | 5 + .../main/res/layout/fragment_map_controls.xml | 11 +- app/src/main/res/layout/quest_cycleway.xml | 11 +- 6 files changed, 26 insertions(+), 118 deletions(-) delete mode 100644 app/src/main/java/de/westnordost/streetcomplete/view/CompassView.java create mode 100644 app/src/main/res/drawable/ic_compass_needle_black_24dp.xml diff --git a/app/src/main/java/de/westnordost/streetcomplete/quests/bikeway/AddCyclewayForm.java b/app/src/main/java/de/westnordost/streetcomplete/quests/bikeway/AddCyclewayForm.java index 661929a3ec..5ba1cf3468 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/quests/bikeway/AddCyclewayForm.java +++ b/app/src/main/java/de/westnordost/streetcomplete/quests/bikeway/AddCyclewayForm.java @@ -25,7 +25,6 @@ import de.westnordost.streetcomplete.data.osm.tql.TagFilterExpression; import de.westnordost.streetcomplete.quests.AbstractQuestFormAnswerFragment; import de.westnordost.streetcomplete.util.SphericalEarthMath; -import de.westnordost.streetcomplete.view.CompassView; import de.westnordost.streetcomplete.view.ListAdapter; import de.westnordost.streetcomplete.view.StreetSideSelectPuzzle; import de.westnordost.streetcomplete.view.dialogs.AlertDialogBuilder; @@ -48,7 +47,7 @@ public class AddCyclewayForm extends AbstractQuestFormAnswerFragment private StreetSideSelectPuzzle puzzle; - private CompassView compassView; + private ImageView compassView; private float wayOrientationAtCenter; private boolean isDefiningBothSides; @@ -149,7 +148,8 @@ private void initPuzzleImages(Bundle inState) } if(compassView != null) { - compassView.setOrientation(rotation, tilt); + compassView.setRotation((float) (180*rotation/Math.PI)); + compassView.setRotationX((float) (180*tilt/Math.PI)); } }); } diff --git a/app/src/main/java/de/westnordost/streetcomplete/tangram/MapControlsFragment.java b/app/src/main/java/de/westnordost/streetcomplete/tangram/MapControlsFragment.java index 8d3d1d4edd..d28cf8a825 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/tangram/MapControlsFragment.java +++ b/app/src/main/java/de/westnordost/streetcomplete/tangram/MapControlsFragment.java @@ -17,6 +17,7 @@ import android.view.ViewGroup; import android.view.animation.AnimationUtils; import android.widget.ImageButton; +import android.widget.ImageView; import com.github.florent37.viewtooltip.ViewTooltip; import com.mapzen.android.lost.api.LocationRequest; @@ -30,13 +31,12 @@ import de.westnordost.streetcomplete.location.LocationStateButton; import de.westnordost.streetcomplete.location.LocationUtil; import de.westnordost.streetcomplete.location.SingleLocationRequest; -import de.westnordost.streetcomplete.view.CompassView; public class MapControlsFragment extends Fragment { private SingleLocationRequest singleLocationRequest; private MapFragment mapFragment; - private CompassView compassNeedle; + private ImageView compassNeedle; private LocationStateButton trackingButton; @Inject SharedPreferences prefs; @@ -175,7 +175,10 @@ public interface Listener @AnyThread public void onMapOrientation(float rotation, float tilt) { - compassNeedle.setOrientation(rotation, tilt); + getActivity().runOnUiThread(() -> { + compassNeedle.setRotation((float) (180*rotation/Math.PI)); + compassNeedle.setRotationX((float) (180*tilt/Math.PI)); + }); } public void onMapInitialized() diff --git a/app/src/main/java/de/westnordost/streetcomplete/view/CompassView.java b/app/src/main/java/de/westnordost/streetcomplete/view/CompassView.java deleted file mode 100644 index 4e64fb5555..0000000000 --- a/app/src/main/java/de/westnordost/streetcomplete/view/CompassView.java +++ /dev/null @@ -1,102 +0,0 @@ -package de.westnordost.streetcomplete.view; - -import android.annotation.SuppressLint; -import android.content.Context; -import android.graphics.PixelFormat; -import android.opengl.GLSurfaceView; -import android.opengl.GLU; -import android.support.annotation.AnyThread; -import android.util.AttributeSet; - -import java.nio.ByteBuffer; -import java.nio.ByteOrder; -import java.nio.FloatBuffer; - -import javax.microedition.khronos.egl.EGLConfig; -import javax.microedition.khronos.opengles.GL10; - -public class CompassView extends GLSurfaceView -{ - private float rotation, tilt; - - public CompassView(Context ctx){ - super(ctx); - init(); - } - - public CompassView(Context context, AttributeSet attrs) { - super(context, attrs); - init(); - } - - private void init() { - setEGLContextClientVersion(1); - getHolder().setFormat(PixelFormat.TRANSLUCENT); - setEGLConfigChooser(8, 8, 8, 8, 16, 0); - setZOrderMediaOverlay(true); - - setRenderer(new CompassRenderer()); - setRenderMode(RENDERMODE_WHEN_DIRTY); - } - - @SuppressLint("WrongThread") @AnyThread public void setOrientation(float rotation, float tilt) - { - this.rotation = rotation; - this.tilt = tilt; - requestRender(); - } - - private class CompassRenderer implements Renderer - { - private ByteBuffer indexBuffer; - private FloatBuffer vertexBuffer; - - private byte indices[] = { 0,1,2,3 }; - private float vertices[] = { 0,1, 0.7f,-1, 0,-0.7f, -0.7f,-1 }; - - public CompassRenderer() - { - ByteBuffer vbb = ByteBuffer.allocateDirect(vertices.length*4); - vbb.order(ByteOrder.nativeOrder()); - vertexBuffer = vbb.asFloatBuffer(); - vertexBuffer.put(vertices); - vertexBuffer.position(0); - - indexBuffer = ByteBuffer.allocateDirect(indices.length); - indexBuffer.put(indices); - indexBuffer.position(0); - } - - @Override public void onSurfaceCreated(GL10 gl, EGLConfig config) - { - gl.glClearColor(1, 1, 1, 0); - } - - @Override public void onSurfaceChanged(GL10 gl, int width, int height) - { - gl.glViewport(0, 0, width, height); - float ratio = (float) width / height; - gl.glMatrixMode(GL10.GL_PROJECTION); - gl.glLoadIdentity(); - gl.glFrustumf(-ratio, ratio, -1, 1, 3, 7); - } - - @Override public void onDrawFrame(GL10 gl) - { - gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT); - gl.glMatrixMode(GL10.GL_MODELVIEW); - gl.glLoadIdentity(); - GLU.gluLookAt(gl, 0,0,-5, 0,0,0, 0,1,0); - - gl.glScalef(1.25f, 1.25f,1.25f); - gl.glRotatef(tilt * 180 / (float) Math.PI, 1, 0, 0); - gl.glRotatef(rotation * 180 / (float) Math.PI, 0, 0, 1); - - gl.glEnableClientState(GL10.GL_VERTEX_ARRAY); - - gl.glColor4f(0.8f,0.2f,0.2f,1); - gl.glVertexPointer(2, GL10.GL_FLOAT, 0, vertexBuffer); - gl.glDrawElements(GL10.GL_TRIANGLE_FAN, indices.length, GL10.GL_UNSIGNED_BYTE, indexBuffer); - } - } -} diff --git a/app/src/main/res/drawable/ic_compass_needle_black_24dp.xml b/app/src/main/res/drawable/ic_compass_needle_black_24dp.xml new file mode 100644 index 0000000000..6f9697571b --- /dev/null +++ b/app/src/main/res/drawable/ic_compass_needle_black_24dp.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/layout/fragment_map_controls.xml b/app/src/main/res/layout/fragment_map_controls.xml index 0837c023e6..e964036048 100644 --- a/app/src/main/res/layout/fragment_map_controls.xml +++ b/app/src/main/res/layout/fragment_map_controls.xml @@ -25,12 +25,13 @@ android:layout_alignParentTop="true" android:text="@string/compass_north_one_letter"/> - @@ -91,4 +92,4 @@ - \ No newline at end of file + diff --git a/app/src/main/res/layout/quest_cycleway.xml b/app/src/main/res/layout/quest_cycleway.xml index 510b111fe1..ab3b0dc2c2 100644 --- a/app/src/main/res/layout/quest_cycleway.xml +++ b/app/src/main/res/layout/quest_cycleway.xml @@ -29,14 +29,15 @@ android:text="@string/compass_north_one_letter" android:textSize="10dp"/> - - \ No newline at end of file +