plectrum

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit e4601e8261cabb822a1355398b56331c9e7a6650
parent 10a4018486a17050a6212ad2ad96c8388eef3d18
Author: gstraube <gstraube@mailbox.org>
Date:   Thu,  6 Jul 2017 19:03:43 +0200

Set background color depending on pitch deviation

Diffstat:
Mapp/src/main/java/com/github/cythara/TunerView.java | 18++++++++++++++++++
1 file changed, 18 insertions(+), 0 deletions(-)

diff --git a/app/src/main/java/com/github/cythara/TunerView.java b/app/src/main/java/com/github/cythara/TunerView.java @@ -10,7 +10,10 @@ import android.view.View; public class TunerView extends View { + private static final double MAX_ALLOWED_DEVIATION = 3D; + private Paint paint = new Paint(); + private Paint background = new Paint(); private PitchDifference pitchDifference; public TunerView(Context context) { @@ -32,10 +35,25 @@ public class TunerView extends View { float y = canvas.getHeight() / 2F; if (pitchDifference != null) { + int color = Color.RED; + if (pitchDifference.deviation <= MAX_ALLOWED_DEVIATION) { + color = Color.GREEN; + } + background.setColor(color); + + setBackground(canvas); + canvas.drawText(pitchDifference.closest.name(), x, y, paint); } } + private void setBackground(Canvas canvas) { + background.setStyle(Paint.Style.FILL); + background.setAlpha(70); + + canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), background); + } + public void setPitchDifference(PitchDifference pitchDifference) { this.pitchDifference = pitchDifference; }