Skip to content

Commit 32c4ade

Browse files
committed
draw Accelerometer view
1 parent 301b45a commit 32c4ade

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

app/src/main/java/com/duy/compass/compass/AccelerometerCompassHelper.java

+11-3
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,21 @@ public SensorValue getSensorValue() {
8181
}
8282

8383
private void drawPitchRoll(Canvas canvas) {
84+
int length = 450;
85+
float radius = realPx(length);
86+
87+
mPathPaint.setColor(mBackgroundColor);
88+
mPathPaint.setStyle(Paint.Style.FILL);
89+
canvas.drawCircle(mCenter.x, mCenter.y, radius, mPathPaint);
90+
8491
mPathPaint.setColor(mPrimaryTextColor);
8592
mPathPaint.setStyle(Paint.Style.FILL);
8693
float roll = mSensorValue.getRoll();
8794
float pitch = mSensorValue.getPitch();
8895

89-
float radius = realPx(20);
96+
radius = realPx(100);
9097

9198
float cosP = (float) Math.cos(Math.toRadians(pitch - 90));
92-
int length = 100;
9399
float x = (float) (realPx(length) * cosP);
94100
float cosR = (float) Math.cos(Math.toRadians(roll - 90));
95101
float y = (float) (realPx(length) * cosR);
@@ -101,11 +107,13 @@ private void drawPitchRoll(Canvas canvas) {
101107
mPath.lineTo(mCenter.x + radius, mCenter.y);
102108
mPath.moveTo(mCenter.x, mCenter.y - radius);
103109
mPath.lineTo(mCenter.x, mCenter.y + radius);
110+
mPath.addCircle(mCenter.x, mCenter.y, radius, Path.Direction.CCW);
104111

105112
mPathPaint.setColor(mSecondaryTextColor);
106-
mPathPaint.setStrokeWidth(realPx(3));
113+
mPathPaint.setStrokeWidth(realPx(5));
107114
mPathPaint.setStyle(Paint.Style.STROKE);
108115
canvas.drawPath(mPath, mPathPaint);
116+
109117
}
110118

111119
public void onSizeChanged(int w, int h, int oldw, int oldh) {

0 commit comments

Comments
 (0)