commit ca2d23d188f14cb33c8f55502cc0052392f2fd1a
parent a07af772f279f9fa0bb7cf530efc6d03a25942b7
Author: gstraube <gstraube@mailbox.org>
Date: Sun, 16 Jul 2017 17:18:38 +0200
Draw indicator in a separate method
Diffstat:
1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/app/src/main/java/com/github/cythara/TunerView.java b/app/src/main/java/com/github/cythara/TunerView.java
@@ -20,6 +20,10 @@ public class TunerView extends View {
private Paint background = new Paint();
private PitchDifference pitchDifference;
+ private float gaugeWidth;
+ private float x;
+ private float y;
+
public TunerView(Context context) {
super(context);
}
@@ -33,6 +37,9 @@ public class TunerView extends View {
super.onDraw(canvas);
this.canvas = canvas;
+ gaugeWidth = 0.45F * canvas.getWidth();
+ x = canvas.getWidth() / 2F;
+ y = canvas.getHeight() / 2F;
textPaint.setColor(Color.BLACK);
int textSize = getResources().getDimensionPixelSize(R.dimen.noteTextSize);
@@ -42,15 +49,13 @@ public class TunerView extends View {
setBackground();
drawGauge();
+ drawIndicator();
drawText();
}
}
private void drawGauge() {
- float x = canvas.getWidth() / 2F;
- float y = canvas.getHeight() / 2F;
-
gaugePaint.setColor(Color.BLACK);
int gaugeSize = getResources().getDimensionPixelSize(R.dimen.gaugeSize);
@@ -59,8 +64,6 @@ public class TunerView extends View {
int textSize = getResources().getDimensionPixelSize(R.dimen.numbersTextSize);
numbersPaint.setTextSize(textSize);
- float gaugeWidth = 0.45F * canvas.getWidth();
-
canvas.drawLine(x - gaugeWidth, y, x + gaugeWidth, y, gaugePaint);
float spaceWidth = gaugeWidth / 3F;
@@ -70,7 +73,9 @@ public class TunerView extends View {
drawMark(y, x + factor * spaceWidth, String.valueOf(i));
drawMark(y, x - factor * spaceWidth, String.valueOf(i));
}
+ }
+ private void drawIndicator() {
float deviation = (float) pitchDifference.deviation;
float xPos = x + (deviation * gaugeWidth / 30F);