Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions app/src/main/java/com/ds/avare/PlatesActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -296,6 +299,7 @@ public void onClick(View v) {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
mPlatesView.clearRotation();
setPlateFromPos(which);
}
};
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
}

/**
Expand Down
53 changes: 48 additions & 5 deletions app/src/main/java/com/ds/avare/views/PlatesView.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -81,6 +83,8 @@ public class PlatesView extends View implements MultiTouchObjectCanvas<Object>,
private static final int TEXT_COLOR_OPPOSITE = Color.BLACK;
private static final int SHADOW = 4;

private double mCurrentRotation;

/**
*
* @param context
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand Down Expand Up @@ -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
Expand Down
46 changes: 42 additions & 4 deletions app/src/main/res/layout/plates.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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" />


<Button
<Button
android:id="@+id/plates_button_rotate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@+id/plates_header"
android:background="@drawable/button_small"
android:text="@string/Rotate"
android:textStyle="bold"
android:visibility="visible" />

<Button
android:id="@+id/plates_button_rotate_90"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:layout_marginEnd="5dp"
android:layout_below="@+id/plates_header"
android:layout_toLeftOf="@+id/plates_button_rotate"
android:background="@drawable/button_small"
android:text="+90"
android:textStyle="bold"
android:visibility="invisible" />

<Button
android:id="@+id/plates_button_rotate_10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:layout_marginEnd="5dp"
android:layout_below="@+id/plates_header"
android:layout_toLeftOf="@+id/plates_button_rotate_90"
android:background="@drawable/button_small"
android:text="+10"
android:textStyle="bold"
android:visibility="invisible" />

<Button
android:id="@+id/plates_button_tag"
android:textStyle="bold"
android:layout_centerVertical="true"
Expand Down Expand Up @@ -84,8 +122,8 @@ Redistribution and use in source and binary forms, with or without modification,
android:layout_width="wrap_content"
android:textOn="@string/Draw"
android:textStyle="bold" />


<LinearLayout
android:baselineAligned="true"
android:id="@+id/plates_header"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,7 @@ Redistribution and use in source and binary forms, with or without modification,
<string name="WindsAloftCeilingSummary">&quot;Select Winds Aloft display ceiling in thousands of feet&quot;</string>

<string name="Tag">Tag</string>
<string name="Rotate">Rotate</string>
<string name="PointName">Name of point</string>
<string name="Geotag">Geotag</string>
<string name="Verify">Verify</string>
Expand Down