diff --git a/app/src/main/java/com/ds/avare/PlatesActivity.java b/app/src/main/java/com/ds/avare/PlatesActivity.java index b342dbfa8..fad919d66 100644 --- a/app/src/main/java/com/ds/avare/PlatesActivity.java +++ b/app/src/main/java/com/ds/avare/PlatesActivity.java @@ -75,6 +75,9 @@ public class PlatesActivity extends Activity implements Observer { private Button mAirportButton; private Button mPlatesButton; private Button mApproachButton; + private Button mRotateButton; + private Button mRotate90Button; + private Button mRotate10Button; private Button mPlatesTagButton; private Button mPlatesTimerButton; private AlertDialog mPlatesPopup; @@ -296,6 +299,7 @@ public void onClick(View v) { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); + mPlatesView.clearRotation(); setPlateFromPos(which); } }; @@ -482,6 +486,40 @@ public boolean onLongClick(View v) { } }); + mRotateButton = (Button)view.findViewById(R.id.plates_button_rotate); + mRotate90Button = (Button)view.findViewById(R.id.plates_button_rotate_90); + mRotate10Button = (Button)view.findViewById(R.id.plates_button_rotate_10); + mRotateButton.getBackground().setAlpha(255); + mRotateButton.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + mPlatesView.clearRotation(); + if (mRotate90Button.getVisibility() == View.INVISIBLE) { + mRotate90Button.setVisibility(View.VISIBLE); + mRotate10Button.setVisibility(View.VISIBLE); + } else { + mRotate90Button.setVisibility(View.INVISIBLE); + mRotate10Button.setVisibility(View.INVISIBLE); + } + } + }); + mRotate10Button.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + mPlatesView.advancePlateRotationRDegrees(10.0); + } + }); + mRotate90Button.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + mPlatesView.advancePlateRotationRDegrees(90.0); + } + }); + 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 +956,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..695e686b0 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,25 @@ 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 advancePlateRotationRDegrees(double r) { + mCurrentRotation += 360.0 - r; + mCurrentRotation %= 360.0; + mCurrentRotation = round(mCurrentRotation); + } + + public void clearRotation() { + mCurrentRotation = 0.0; } // 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 +219,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 +262,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 +287,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 +427,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..8c10f2fae 100644 --- a/app/src/main/res/layout/plates.xml +++ b/app/src/main/res/layout/plates.xml @@ -32,10 +32,48 @@ 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" /> -