From 6d09cccaebc9d072080abd3b759eaa8f7f938f14 Mon Sep 17 00:00:00 2001
From: James Fenn <18jafenn90@gmail.com>
Date: Sun, 14 May 2017 19:19:15 -0400
Subject: [PATCH] moved hardcoded strings to resources
---
.../james/metronome/activities/MainActivity.java | 15 ++++++---------
.../main/java/james/metronome/data/TickData.java | 9 +++++----
app/src/main/res/values/strings.xml | 5 +++++
3 files changed, 16 insertions(+), 13 deletions(-)
diff --git a/app/src/main/java/james/metronome/activities/MainActivity.java b/app/src/main/java/james/metronome/activities/MainActivity.java
index ecd3bbb..6715ac7 100644
--- a/app/src/main/java/james/metronome/activities/MainActivity.java
+++ b/app/src/main/java/james/metronome/activities/MainActivity.java
@@ -3,20 +3,17 @@
import android.animation.ArgbEvaluator;
import android.animation.ValueAnimator;
import android.content.SharedPreferences;
-import android.content.res.ColorStateList;
import android.graphics.Color;
import android.media.AudioAttributes;
import android.media.AudioManager;
import android.media.SoundPool;
import android.os.Build;
+import android.os.Bundle;
import android.os.Handler;
import android.preference.PreferenceManager;
-import android.support.v4.animation.ValueAnimatorCompat;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
-import android.os.Bundle;
import android.view.LayoutInflater;
-import android.view.MotionEvent;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
@@ -36,10 +33,10 @@ public class MainActivity extends AppCompatActivity implements Runnable {
public static final String PREF_INTERVAL = "interval";
public static final TickData[] ticks = new TickData[]{
- new TickData("Beep", R.raw.beep),
- new TickData("Click", R.raw.click),
- new TickData("Ding", R.raw.ding),
- new TickData("Wood", R.raw.wood)
+ new TickData(R.string.title_beep, R.raw.beep),
+ new TickData(R.string.title_click, R.raw.click),
+ new TickData(R.string.title_ding, R.raw.ding),
+ new TickData(R.string.title_wood, R.raw.wood)
};
private SoundPool soundPool;
@@ -209,7 +206,7 @@ public void onAnimationUpdate(ValueAnimator animation) {
}
});
- ((TextView) v.findViewById(R.id.name)).setText(ticks[i].getName());
+ ((TextView) v.findViewById(R.id.name)).setText(ticks[i].getName(this));
if (i != tick)
v.setVisibility(View.GONE);
diff --git a/app/src/main/java/james/metronome/data/TickData.java b/app/src/main/java/james/metronome/data/TickData.java
index 70b5d4d..7d46db6 100644
--- a/app/src/main/java/james/metronome/data/TickData.java
+++ b/app/src/main/java/james/metronome/data/TickData.java
@@ -3,19 +3,20 @@
import android.content.Context;
import android.media.SoundPool;
import android.support.annotation.RawRes;
+import android.support.annotation.StringRes;
public class TickData {
- private String name;
+ private int name;
private int soundRes;
- public TickData(String name, @RawRes int soundRes) {
+ public TickData(@StringRes int name, @RawRes int soundRes) {
this.name = name;
this.soundRes = soundRes;
}
- public String getName() {
- return name;
+ public String getName(Context context) {
+ return context.getString(name);
}
@RawRes
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 9f15e2f..e5497a2 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -2,4 +2,9 @@
Metronome
%1$s BPM
+
+ Beep
+ Click
+ Ding
+ Wood