From d24296d1beef001454cb63228d622db95c1d5e9a Mon Sep 17 00:00:00 2001 From: jackwilliard Date: Mon, 30 Nov 2020 12:55:18 -0500 Subject: [PATCH 1/3] Closes #245. Adds a rotate button to the airport diagrams and approach plates. This button does not appear in Track Up mode. Each click of the button rotates the diagram 90 degrees clockwise. Four files are affected within the UI code. --- .../java/com/ds/avare/PlatesActivity.java | 20 ++++++++ .../java/com/ds/avare/views/PlatesView.java | 49 +++++++++++++++++-- app/src/main/res/layout/plates.xml | 16 +++++- app/src/main/res/values/strings.xml | 1 + 4 files changed, 79 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/ds/avare/PlatesActivity.java b/app/src/main/java/com/ds/avare/PlatesActivity.java index b342dbfa8..fba28d9a5 100644 --- a/app/src/main/java/com/ds/avare/PlatesActivity.java +++ b/app/src/main/java/com/ds/avare/PlatesActivity.java @@ -75,6 +75,7 @@ public class PlatesActivity extends Activity implements Observer { private Button mAirportButton; private Button mPlatesButton; private Button mApproachButton; + private Button mRotateButton; private Button mPlatesTagButton; private Button mPlatesTimerButton; private AlertDialog mPlatesPopup; @@ -482,6 +483,19 @@ public boolean onLongClick(View v) { } }); + mRotateButton = (Button)view.findViewById(R.id.plates_button_rotate); + mRotateButton.getBackground().setAlpha(255); + mRotateButton.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + mPlatesView.advancePlateRotationNinetyDegrees(); + } + }); + if(mPref.isTrackUpPlates()) { + mRotateButton.setVisibility(View.INVISIBLE); + } else { + mRotateButton.setVisibility(View.VISIBLE); + } mPlatesTagButton = (Button)view.findViewById(R.id.plates_button_tag); mPlatesTagButton.getBackground().setAlpha(255); @@ -918,6 +932,12 @@ public void onResume() { else { mCenterButton.getBackground().setColorFilter(0xFF444444, PorterDuff.Mode.MULTIPLY); } + + if(mPref.isTrackUpPlates()) { + mRotateButton.setVisibility(View.INVISIBLE); + } else { + mRotateButton.setVisibility(View.VISIBLE); + } } /** diff --git a/app/src/main/java/com/ds/avare/views/PlatesView.java b/app/src/main/java/com/ds/avare/views/PlatesView.java index 21bae9a95..ef8ec8820 100644 --- a/app/src/main/java/com/ds/avare/views/PlatesView.java +++ b/app/src/main/java/com/ds/avare/views/PlatesView.java @@ -37,6 +37,8 @@ import org.metalev.multitouch.controller.MultiTouchController.PointInfo; import org.metalev.multitouch.controller.MultiTouchController.PositionAndScale; +import static java.lang.Math.round; + /** * * @author zkhan @@ -81,6 +83,8 @@ public class PlatesView extends View implements MultiTouchObjectCanvas, private static final int TEXT_COLOR_OPPOSITE = Color.BLACK; private static final int SHADOW = 4; + private double mCurrentRotation; + /** * * @param context @@ -110,10 +114,21 @@ private void setup(Context context) { mLineHeadingBitmap = new BitmapHolder(context, R.drawable.line_heading); mDipToPix = Helper.getDpiToPix(context); + mCurrentRotation = 0.0; + } + + private boolean shouldShowRotateButton() { + return !mPref.isTrackUp() && (mShowingAD || null != mMatrix); + } + + public void advancePlateRotationNinetyDegrees() { + mCurrentRotation += 270.0; + mCurrentRotation %= 360.0; + mCurrentRotation = round(mCurrentRotation); } // Condition for rotation, only rotate when track up and either airport diagram or geo tagged plate is showing - private boolean shouldRotate() { + private boolean shouldTrackUpRotate() { // XXX: Fix rotation return mPref.isTrackUpPlates() && (mShowingAD || null != mMatrix); } @@ -200,13 +215,20 @@ public Object getDraggableObjectAtPoint(PointInfo pt) { public void getPositionAndScale(Object obj, PositionAndScale objPosAndScaleOut) { float x = mPan.getMoveX(); float y = mPan.getMoveY(); - if(shouldRotate()) { + if(shouldTrackUpRotate()) { double p[] = new double[2]; double thetab = mGpsParams.getBearing(); p = Helper.rotateCoord(0, 0, -thetab, x, y); objPosAndScaleOut.set((float)p[0],(float)p[1], true, mScale.getScaleFactorRaw(), false, 0, 0, false, 0); } + else if(shouldShowRotateButton()) { + double p[] = new double[2]; + double thetab = mCurrentRotation; + p = Helper.rotateCoord(0, 0, -thetab, x, y); + objPosAndScaleOut.set((float)p[0],(float)p[1], true, + mScale.getScaleFactorRaw(), false, 0, 0, false, 0); + } else { objPosAndScaleOut.set(x, y, true, mScale.getScaleFactorRaw(), false, 0, 0, false, 0); @@ -236,12 +258,18 @@ public boolean setPositionAndScale(Object obj,PositionAndScale newObjPosAndScale /* * Threshold the drawing so we do not generate too many points */ - if (shouldRotate()) { + if (shouldTrackUpRotate()) { double thetab = mGpsParams.getBearing(); double p[] = new double[2]; p = Helper.rotateCoord(getWidth() / 2,getHeight() / 2 , thetab, x, y); mService.getPixelDraw().addPoint((float)p[0],(float)p[1]); } + else if (shouldShowRotateButton()){ + double thetab = mCurrentRotation; + double p[] = new double[2]; + p = Helper.rotateCoord(getWidth() / 2,getHeight() / 2 , thetab, x, y); + mService.getPixelDraw().addPoint((float)p[0],(float)p[1]); + } else { mService.getPixelDraw().addPoint(x, y); } @@ -255,12 +283,18 @@ public boolean setPositionAndScale(Object obj,PositionAndScale newObjPosAndScale float x = newObjPosAndScale.getXOff(); float y = newObjPosAndScale.getYOff(); - if (shouldRotate()) { + if (shouldTrackUpRotate()) { double thetab = mGpsParams.getBearing(); double p[] = new double[2]; p = Helper.rotateCoord(0, 0, thetab, x, y); mPan.setMove((float) p[0], (float) p[1]); } + else if (shouldShowRotateButton()) { + double thetab = mCurrentRotation; + double p[] = new double[2]; + p = Helper.rotateCoord(0, 0, thetab, x, y); + mPan.setMove((float) p[0], (float) p[1]); + } else { mPan.setMove(x, y); } @@ -389,11 +423,16 @@ public void onDraw(Canvas canvas) { } // rotate only when showing AD, or showing geo tagged approach plate. - if(shouldRotate()) { + if(shouldTrackUpRotate()) { canvas.save(); bRotated = true; canvas.rotate(-(int) mGpsParams.getBearing(),getWidth() / 2,getHeight() / 2); } + else if (shouldShowRotateButton()) { + canvas.save(); + bRotated = true; + canvas.rotate(-(int) mCurrentRotation,getWidth() / 2,getHeight() / 2); + } /* * Plate diff --git a/app/src/main/res/layout/plates.xml b/app/src/main/res/layout/plates.xml index 5928988fb..2bd035fb3 100644 --- a/app/src/main/res/layout/plates.xml +++ b/app/src/main/res/layout/plates.xml @@ -32,10 +32,22 @@ Redistribution and use in source and binary forms, with or without modification, android:layout_centerInParent="true" android:background="@drawable/button_small" android:layout_margin="5dp" - android:layout_alignParentBottom="true"/> + android:layout_alignParentBottom="true" + android:visibility="invisible" /> -