commit 1ca3f1cddbefb637d9118688908779e42470d40d
parent 0892a32490b77d67cddbf1a7d482b92edecc4140
Author: gstraube <gstraube@mailbox.org>
Date: Sun, 6 Sep 2020 11:11:09 +0200
Enable display of exact deviation (issue #40)
Diffstat:
7 files changed, 44 insertions(+), 0 deletions(-)
diff --git a/app/src/main/java/com/github/cythara/CanvasPainter.java b/app/src/main/java/com/github/cythara/CanvasPainter.java
@@ -7,6 +7,7 @@ import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Path;
+import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.text.TextPaint;
@@ -41,6 +42,7 @@ class CanvasPainter {
private float x;
private float y;
private boolean useScientificNotation;
+ private boolean showExactDeviation;
private int referencePitch;
private CanvasPainter(Context context) {
@@ -64,6 +66,8 @@ class CanvasPainter {
useScientificNotation = preferences.getBoolean(
MainActivity.USE_SCIENTIFIC_NOTATION, true);
+ showExactDeviation = preferences.getBoolean(MainActivity.SHOW_EXACT_DEVIATION, false);
+
referencePitch = preferences.getInt(
MainActivity.REFERENCE_PITCH, 440);
@@ -98,6 +102,10 @@ class CanvasPainter {
drawIndicator();
+ if (showExactDeviation) {
+ drawDeviation();
+ }
+
float x = canvas.getWidth() / 2F;
float y = canvas.getHeight() * 0.75f;
@@ -107,6 +115,20 @@ class CanvasPainter {
}
}
+ private void drawDeviation() {
+ long rounded = Math.round(pitchDifference.deviation);
+ String text = String.valueOf(rounded);
+
+ Rect bounds = new Rect();
+ symbolPaint.getTextBounds(text, 0, text.length(), bounds);
+ int width = bounds.width();
+
+ float xPos = x - width / 2F;
+ float yPos = canvas.getHeight() / 3F;
+
+ canvas.drawText(text, xPos, yPos, symbolPaint);
+ }
+
private void drawGauge() {
gaugePaint.setColor(textColor);
diff --git a/app/src/main/java/com/github/cythara/MainActivity.java b/app/src/main/java/com/github/cythara/MainActivity.java
@@ -38,6 +38,7 @@ public class MainActivity extends AppCompatActivity implements TaskCallbacks,
public static final String PREFS_FILE = "prefs_file";
public static final String USE_SCIENTIFIC_NOTATION = "use_scientific_notation";
public static final String CURRENT_TUNING = "current_tuning";
+ public static final String SHOW_EXACT_DEVIATION = "show_exact_deviation";
protected static final String REFERENCE_PITCH = "reference_pitch";
private static final String TAG_LISTENER_FRAGMENT = "listener_fragment";
private static final String USE_DARK_MODE = "use_dark_mode";
@@ -157,6 +158,18 @@ public class MainActivity extends AppCompatActivity implements TaskCallbacks,
break;
}
+ case R.id.show_exact_deviation: {
+ final SharedPreferences preferences = getSharedPreferences(PREFS_FILE,
+ MODE_PRIVATE);
+ boolean currentlyShowingExactDeviation = preferences.getBoolean(
+ SHOW_EXACT_DEVIATION, false);
+
+ SharedPreferences.Editor editor = preferences.edit();
+ editor.putBoolean(SHOW_EXACT_DEVIATION, !currentlyShowingExactDeviation);
+ editor.apply();
+
+ recreate();
+ }
}
return false;
diff --git a/app/src/main/res/menu/toolbar_menu.xml b/app/src/main/res/menu/toolbar_menu.xml
@@ -21,4 +21,9 @@
android:id="@+id/toggle_dark_mode"
android:title="@string/toggle_dark_mode"
app:showAsAction="never" />
+
+ <item
+ android:id="@+id/show_exact_deviation"
+ android:title="@string/show_exact_deviation"
+ app:showAsAction="never" />
</menu>
\ No newline at end of file
diff --git a/app/src/main/res/values-de-rDE/strings.xml b/app/src/main/res/values-de-rDE/strings.xml
@@ -12,6 +12,7 @@
Eine Mikrofongenehmigung ist erforderlich. App wird geschlossen.
</string>
<string name="ok">OK</string>
+ <string name="show_exact_deviation">Genaue Abweichung ein-/ausblenden</string>
<string-array name="tunings">
<item>Chromatisch</item>
diff --git a/app/src/main/res/values-eu/strings.xml b/app/src/main/res/values-eu/strings.xml
@@ -9,4 +9,5 @@
<string name="choose_a_frequency">Maiztasun bat hautatu:</string>
<string name="microphone_permission_required">Mikrofonoaren baimena beharrezkoa da</string>
<string name="ok">Ados</string>
+ <string name="show_exact_deviation">Erakutsi/ezkutatu desbideratze zehatza</string>
</resources>
diff --git a/app/src/main/res/values-pt-rBR/strings.xml b/app/src/main/res/values-pt-rBR/strings.xml
@@ -12,6 +12,7 @@
A permissão do microfone é necessária. App será fechado.
</string>
<string name="ok">OK</string>
+ <string name="show_exact_deviation">Mostrar/esconder o desvio exato</string>
<string-array name="tunings">
<item>Cromático</item>
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
@@ -14,6 +14,7 @@
<string name="permission_required">Permission required</string>
<string name="microphone_permission_required">Microphone permission is required. App will close.</string>
<string name="ok">OK</string>
+ <string name="show_exact_deviation">Show/hide exact deviation</string>
<string-array name="tunings">
<item>Chromatic</item>