From 866a4151c59d11a16aa9a3ca5c95705bdbbf7e31 Mon Sep 17 00:00:00 2001 From: paradix Date: Fri, 16 Jan 2015 11:32:55 +0100 Subject: [PATCH 1/5] final proposal for Issue #153 --- app/res/values-pl/cues.xml | 19 +++++---- app/res/values/cues.xml | 24 +++++++---- .../workout/feedback/AudioFeedback.java | 40 +++++++++++++++++-- .../org/runnerup/common/util/Constants.java | 6 +++ 4 files changed, 69 insertions(+), 20 deletions(-) diff --git a/app/res/values-pl/cues.xml b/app/res/values-pl/cues.xml index 7a2ffe150..debf1d4a7 100644 --- a/app/res/values-pl/cues.xml +++ b/app/res/values-pl/cues.xml @@ -14,20 +14,23 @@ ~ ~ You should have received a copy of the GNU General Public License ~ along with this program. If not, see .--> - aktywność - interwał - okrążenie + {1} {0} {2} + {0} {1} + 10#Treningu|20#Trening + 10#Interwału|20#interwał + 10#Okrążenia|20#Okrążenie + 1#{3}|2#{3}|3#{3}|4#{3}|5#{3}|6#{3} rozgrzewka uspokojenie aktualny regeneracja na kilometr na milę - rozpoczęte - zatrzymana - wznowiona - zatrzymana - zakończony + 101#rozpoczęty|102#rozpoczęty|103#rozpoczęte|106#rozpoczęta|109#rozpoczęte + 201#wstrzymany|202#wstrzymany|203#wstrzymane + 301#wznowiony|302#wznowiony|303#wznowione + 401#zatrzymany|402#zatrzymany|403#zatrzymane + 501#zakończony|502#zakończony|503#zakończone przyśpiesz zwolnij diff --git a/app/res/values/cues.xml b/app/res/values/cues.xml index bae7cc9ae..de3252ec5 100644 --- a/app/res/values/cues.xml +++ b/app/res/values/cues.xml @@ -14,20 +14,28 @@ ~ ~ You should have received a copy of the GNU General Public License ~ along with this program. If not, see .--> - activity - interval - lap + {0} {1} {2} + {0} {1} + 10#activity|20#activity + 10#interval|20#interval + 10#lap|20#lap + + 1#|2#|3#|4#|5#|6#{3} warm up cool down current recovery per kilometer per mile - started - paused - resumed - stopped - completed + 101#started|102#started|103#started|106#started|109#started + 201#paused|202#paused|203#paused + 301#resumed|302#resumed|303#resumed + 401#stopped|402#stopped|403#stopped + 501#completed|502#completed|503#completed speed up slow down diff --git a/app/src/org/runnerup/workout/feedback/AudioFeedback.java b/app/src/org/runnerup/workout/feedback/AudioFeedback.java index b7df8daff..b4dc7b248 100644 --- a/app/src/org/runnerup/workout/feedback/AudioFeedback.java +++ b/app/src/org/runnerup/workout/feedback/AudioFeedback.java @@ -23,6 +23,8 @@ import android.os.Build; import android.speech.tts.TextToSpeech; +import org.runnerup.R; +import org.runnerup.common.util.Constants; import org.runnerup.util.Formatter; import org.runnerup.workout.Dimension; import org.runnerup.workout.Event; @@ -31,6 +33,8 @@ import org.runnerup.workout.Scope; import org.runnerup.workout.Workout; +import java.text.ChoiceFormat; +import java.text.MessageFormat; import java.util.HashMap; @TargetApi(Build.VERSION_CODES.FROYO) @@ -43,6 +47,8 @@ public class AudioFeedback extends Feedback { RUTextToSpeech textToSpeech; Formatter formatter; + + public AudioFeedback(Scope scope, Event event) { super(); this.scope = scope; @@ -95,14 +101,40 @@ public boolean equals(Feedback _other) { protected String getCue(Workout w, Context ctx) { String msg = null; Resources res = ctx.getResources(); + + int nounKey = 10; + int verbKey = 100; + if (event != null && scope != null) { - msg = res.getString(scope.getCueId()) + " " + res.getString(event.getCueId()); + MessageFormat sentence = new MessageFormat(res.getString(R.string.cue_event_pattern)); + + ChoiceFormat cueNounPattern = new ChoiceFormat(res.getString(scope.getCueId())); + sentence.setFormatByArgumentIndex(0, cueNounPattern); + + ChoiceFormat cueVerbPattern = new ChoiceFormat(res.getString(event.getCueId())); + sentence.setFormatByArgumentIndex(1, cueVerbPattern); + + msg = sentence.format(new Object[] {nounKey * Constants.CUE_CASE.EVENT, verbKey * event.getValue() + scope.getValue()}); + } else if (event != null && intensity != null) { - msg = res.getString(intensity.getCueId(), "") + " " + res.getString(event.getCueId()); + MessageFormat sentence = new MessageFormat(res.getString(R.string.cue_event_pattern)); + + ChoiceFormat cueVerbPattern = new ChoiceFormat(res.getString(event.getCueId())); + sentence.setFormatByArgumentIndex(1, cueVerbPattern); + + msg = sentence.format(new Object[] {res.getString(intensity.getCueId()), verbKey * event.getValue() + intensity.getValue() * Constants.CUE_CASE.INTENSITY}); + } else if (dimension != null && scope != null && w.isEnabled(dimension, scope)) { + MessageFormat sentence = new MessageFormat(res.getString(R.string.cue_interval_pattern)); + + ChoiceFormat cueDimensionPattern = new ChoiceFormat(res.getString(R.string.cue_dimension_pattern)); + sentence.setFormatByArgumentIndex(1, cueDimensionPattern); + + ChoiceFormat cueNounPattern = new ChoiceFormat(res.getString(scope.getCueId())); + sentence.setFormatByArgumentIndex(0, cueNounPattern); + double val = w.get(scope, dimension); // SI - msg = res.getString(scope.getCueId()) + " " - + formatter.format(Formatter.CUE_LONG, dimension, val); + msg = sentence.format(new Object[] {nounKey * Constants.CUE_CASE.DIMENSION, dimension.getValue(), formatter.format(Formatter.CUE_LONG, dimension, val), res.getString(dimension.getTextId())}); } return msg; } diff --git a/common/src/main/java/org/runnerup/common/util/Constants.java b/common/src/main/java/org/runnerup/common/util/Constants.java index 4fbe71ea4..cd9ff03a2 100644 --- a/common/src/main/java/org/runnerup/common/util/Constants.java +++ b/common/src/main/java/org/runnerup/common/util/Constants.java @@ -180,6 +180,12 @@ public interface TRACKER_STATE { public static final int STOPPED = 9; }; + public interface CUE_CASE { + public static final int DIMENSION = 1; + public static final int EVENT = 2; + public static final int INTENSITY = 3; + } + public interface Wear { public interface Path { From a9efa2a8085530b845cf32722e4bd9dc12811dcc Mon Sep 17 00:00:00 2001 From: paradix Date: Fri, 16 Jan 2015 13:36:07 +0100 Subject: [PATCH 2/5] code cleanup --- app/res/values-pl/cues.xml | 2 +- app/res/values/cues.xml | 2 +- .../workout/feedback/AudioFeedback.java | 47 +++++++++++++++---- .../workout/feedback/CoachFeedback.java | 4 +- 4 files changed, 40 insertions(+), 15 deletions(-) diff --git a/app/res/values-pl/cues.xml b/app/res/values-pl/cues.xml index debf1d4a7..4a0da1035 100644 --- a/app/res/values-pl/cues.xml +++ b/app/res/values-pl/cues.xml @@ -26,7 +26,7 @@ regeneracja na kilometr na milę - 101#rozpoczęty|102#rozpoczęty|103#rozpoczęte|106#rozpoczęta|109#rozpoczęte + 101#rozpoczęty|102#rozpoczęty|103#rozpoczęte|112#rozpoczęta|115#rozpoczęte 201#wstrzymany|202#wstrzymany|203#wstrzymane 301#wznowiony|302#wznowiony|303#wznowione 401#zatrzymany|402#zatrzymany|403#zatrzymane diff --git a/app/res/values/cues.xml b/app/res/values/cues.xml index de3252ec5..af658f7c3 100644 --- a/app/res/values/cues.xml +++ b/app/res/values/cues.xml @@ -31,7 +31,7 @@ recovery per kilometer per mile - 101#started|102#started|103#started|106#started|109#started + 101#started|102#started|103#started|112#started|115#started 201#paused|202#paused|203#paused 301#resumed|302#resumed|303#resumed 401#stopped|402#stopped|403#stopped diff --git a/app/src/org/runnerup/workout/feedback/AudioFeedback.java b/app/src/org/runnerup/workout/feedback/AudioFeedback.java index b4dc7b248..237839ac6 100644 --- a/app/src/org/runnerup/workout/feedback/AudioFeedback.java +++ b/app/src/org/runnerup/workout/feedback/AudioFeedback.java @@ -46,7 +46,9 @@ public class AudioFeedback extends Feedback { Intensity intensity = null; RUTextToSpeech textToSpeech; Formatter formatter; - + int cueCase = 0; + final int nounKeyBase = 10; + final int verbKeyBase = 100; public AudioFeedback(Scope scope, Event event) { @@ -54,6 +56,7 @@ public AudioFeedback(Scope scope, Event event) { this.scope = scope; this.event = event; this.dimension = null; + this.cueCase = Constants.CUE_CASE.EVENT; } public AudioFeedback(Scope scope, Dimension dimension) { @@ -61,6 +64,7 @@ public AudioFeedback(Scope scope, Dimension dimension) { this.scope = scope; this.event = null; this.dimension = dimension; + this.cueCase = Constants.CUE_CASE.DIMENSION; } public AudioFeedback(Intensity intensity, Event event) { @@ -69,6 +73,7 @@ public AudioFeedback(Intensity intensity, Event event) { this.dimension = null; this.intensity = intensity; this.event = event; + this.cueCase = Constants.CUE_CASE.INTENSITY; } @Override @@ -98,13 +103,10 @@ public boolean equals(Feedback _other) { return true; } - protected String getCue(Workout w, Context ctx) { + protected String getCue(Workout w, Context ctx, double val) { String msg = null; Resources res = ctx.getResources(); - int nounKey = 10; - int verbKey = 100; - if (event != null && scope != null) { MessageFormat sentence = new MessageFormat(res.getString(R.string.cue_event_pattern)); @@ -114,7 +116,7 @@ protected String getCue(Workout w, Context ctx) { ChoiceFormat cueVerbPattern = new ChoiceFormat(res.getString(event.getCueId())); sentence.setFormatByArgumentIndex(1, cueVerbPattern); - msg = sentence.format(new Object[] {nounKey * Constants.CUE_CASE.EVENT, verbKey * event.getValue() + scope.getValue()}); + msg = sentence.format(new Object[] {getCueNounKey(), getCueVerbKey()}); } else if (event != null && intensity != null) { MessageFormat sentence = new MessageFormat(res.getString(R.string.cue_event_pattern)); @@ -122,7 +124,7 @@ protected String getCue(Workout w, Context ctx) { ChoiceFormat cueVerbPattern = new ChoiceFormat(res.getString(event.getCueId())); sentence.setFormatByArgumentIndex(1, cueVerbPattern); - msg = sentence.format(new Object[] {res.getString(intensity.getCueId()), verbKey * event.getValue() + intensity.getValue() * Constants.CUE_CASE.INTENSITY}); + msg = sentence.format(new Object[] {res.getString(intensity.getCueId()), getCueVerbKey()}); } else if (dimension != null && scope != null && w.isEnabled(dimension, scope)) { MessageFormat sentence = new MessageFormat(res.getString(R.string.cue_interval_pattern)); @@ -133,15 +135,40 @@ protected String getCue(Workout w, Context ctx) { ChoiceFormat cueNounPattern = new ChoiceFormat(res.getString(scope.getCueId())); sentence.setFormatByArgumentIndex(0, cueNounPattern); - double val = w.get(scope, dimension); // SI - msg = sentence.format(new Object[] {nounKey * Constants.CUE_CASE.DIMENSION, dimension.getValue(), formatter.format(Formatter.CUE_LONG, dimension, val), res.getString(dimension.getTextId())}); + //double val = w.get(scope, dimension); // SI + msg = sentence.format(new Object[] {getCueNounKey(), dimension.getValue(), formatter.format(Formatter.CUE_LONG, dimension, val), res.getString(dimension.getTextId())}); } return msg; } + private int getCueNounKey() { + switch (cueCase) { + case Constants.CUE_CASE.EVENT: + case Constants.CUE_CASE.DIMENSION: + return nounKeyBase * cueCase;//10,20,30 + case Constants.CUE_CASE.INTENSITY: + return -1; + default: + return 0; + } + } + + private int getCueVerbKey() { + switch (cueCase) { + case Constants.CUE_CASE.EVENT: + return verbKeyBase * event.getValue() + scope.getValue();//101,102,103,104 + case Constants.CUE_CASE.DIMENSION: + return -1; + case Constants.CUE_CASE.INTENSITY: + return verbKeyBase * event.getValue() + (intensity.getValue()+2) * cueCase;//106,109,112,115,118,121 + default: + return 0; + } + } + @Override public void emit(Workout w, Context ctx) { - String msg = getCue(w, ctx); + String msg = getCue(w, ctx, w.get(scope, dimension)); if (msg != null) { textToSpeech.speak(msg, TextToSpeech.QUEUE_ADD, null); } diff --git a/app/src/org/runnerup/workout/feedback/CoachFeedback.java b/app/src/org/runnerup/workout/feedback/CoachFeedback.java index 8eefe0403..1007c5040 100644 --- a/app/src/org/runnerup/workout/feedback/CoachFeedback.java +++ b/app/src/org/runnerup/workout/feedback/CoachFeedback.java @@ -96,9 +96,7 @@ public void emit(Workout s, Context ctx) { msg = " " + ctx.getResources().getString(R.string.cue_slowdown); } if (!"".contentEquals(msg)) { - textToSpeech.speak(ctx.getResources().getString(scope.getCueId()) - + " " - + formatter.format(Formatter.CUE_LONG, dimension, val) + textToSpeech.speak(getCue(s, ctx, val) + msg, TextToSpeech.QUEUE_ADD, null); } From 1ec228ce85a677e40bc5f8e4b0e3a4d5d26ccf87 Mon Sep 17 00:00:00 2001 From: paradix Date: Mon, 19 Jan 2015 09:49:20 +0100 Subject: [PATCH 3/5] reformatted cues for MessageFormat support --- app/res/values-de/cues.xml | 16 ++++++++-------- app/res/values-en-rNL/cues.xml | 16 ++++++++-------- app/res/values-es/cues.xml | 16 ++++++++-------- app/res/values-fr/cues.xml | 16 ++++++++-------- app/res/values-nl-rNL/cues.xml | 16 ++++++++-------- app/res/values-nl/cues.xml | 16 ++++++++-------- app/res/values-tr/cues.xml | 16 ++++++++-------- app/res/values/cues.xml | 16 ++++++++-------- 8 files changed, 64 insertions(+), 64 deletions(-) diff --git a/app/res/values-de/cues.xml b/app/res/values-de/cues.xml index cb68fa3fb..2e8a6159d 100644 --- a/app/res/values-de/cues.xml +++ b/app/res/values-de/cues.xml @@ -14,20 +14,20 @@ ~ ~ You should have received a copy of the GNU General Public License ~ along with this program. If not, see .--> - Aktivität - Intervall - Runde + 0<Aktivität + 0<Intervall + 0<Runde Aufwärmphase Abkühlphase Aktuell Erholung pro Kilometer pro Meile - begonnen - pausiert - fortgeführt - gestoppt - abgeschlossen + 0<begonnen + 0<pausiert + 0<fortgeführt + 0<gestoppt + 0<abgeschlossen beschleunige werde langsamer diff --git a/app/res/values-en-rNL/cues.xml b/app/res/values-en-rNL/cues.xml index c541ebcb1..5fea66dc4 100644 --- a/app/res/values-en-rNL/cues.xml +++ b/app/res/values-en-rNL/cues.xml @@ -14,20 +14,20 @@ ~ ~ You should have received a copy of the GNU General Public License ~ along with this program. If not, see .--> - activiteit - interval - ronde + 0<activiteit + 0<interval + 0<ronde warming-up cooling-down huidige herstel per kilometer per mijl - gestart - gepauzeerd - hervatten - gestopt - afgerond + 0<gestart + 0<gepauzeerd + 0<hervatten + 0<gestopt + 0<afgerond versnellen vertragen diff --git a/app/res/values-es/cues.xml b/app/res/values-es/cues.xml index 76a5f939b..5dc65e32a 100644 --- a/app/res/values-es/cues.xml +++ b/app/res/values-es/cues.xml @@ -14,19 +14,19 @@ ~ ~ You should have received a copy of the GNU General Public License ~ along with this program. If not, see .--> - actividad - intervalo - vuelta + 0<actividad + 0<intervalo + 0<vuelta calentamiento enfriamiento actual por kilómetro por milla - empezado - en pausa - reanudado - parado - completado + 0<empezado + 0<en pausa + 0<reanudado + 0<parado + 0<completado acelerar decelerar diff --git a/app/res/values-fr/cues.xml b/app/res/values-fr/cues.xml index 41ef1e344..5831c276d 100644 --- a/app/res/values-fr/cues.xml +++ b/app/res/values-fr/cues.xml @@ -14,20 +14,20 @@ ~ ~ You should have received a copy of the GNU General Public License ~ along with this program. If not, see .--> - activité - intervalle - tour + 0<activité + 0<intervalle + 0<tour échauffement refroidissement courant récupération par kilomètre par mille - démarré - pausé - repris - stoppé - terminé + 0<démarré + 0<pausé + 0<repris + 0<stoppé + 0<terminé accéléré ralentir diff --git a/app/res/values-nl-rNL/cues.xml b/app/res/values-nl-rNL/cues.xml index c541ebcb1..5fea66dc4 100644 --- a/app/res/values-nl-rNL/cues.xml +++ b/app/res/values-nl-rNL/cues.xml @@ -14,20 +14,20 @@ ~ ~ You should have received a copy of the GNU General Public License ~ along with this program. If not, see .--> - activiteit - interval - ronde + 0<activiteit + 0<interval + 0<ronde warming-up cooling-down huidige herstel per kilometer per mijl - gestart - gepauzeerd - hervatten - gestopt - afgerond + 0<gestart + 0<gepauzeerd + 0<hervatten + 0<gestopt + 0<afgerond versnellen vertragen diff --git a/app/res/values-nl/cues.xml b/app/res/values-nl/cues.xml index c541ebcb1..5fea66dc4 100644 --- a/app/res/values-nl/cues.xml +++ b/app/res/values-nl/cues.xml @@ -14,20 +14,20 @@ ~ ~ You should have received a copy of the GNU General Public License ~ along with this program. If not, see .--> - activiteit - interval - ronde + 0<activiteit + 0<interval + 0<ronde warming-up cooling-down huidige herstel per kilometer per mijl - gestart - gepauzeerd - hervatten - gestopt - afgerond + 0<gestart + 0<gepauzeerd + 0<hervatten + 0<gestopt + 0<afgerond versnellen vertragen diff --git a/app/res/values-tr/cues.xml b/app/res/values-tr/cues.xml index b74484911..dd8f5e843 100644 --- a/app/res/values-tr/cues.xml +++ b/app/res/values-tr/cues.xml @@ -14,19 +14,19 @@ ~ ~ You should have received a copy of the GNU General Public License ~ along with this program. If not, see .--> - aktivite - aralık - tur + 0<aktivite + 0<aralık + 0<tur ısınma soğuma şimdiki kilometre başına mil başına - başlandı - duraklatıldı - devam edildi - durduruldu - tamamlandı + 0<başlandı + 0<duraklatıldı + 0<devam edildi + 0<durduruldu + 0<tamamlandı hızlan yavaşla diff --git a/app/res/values/cues.xml b/app/res/values/cues.xml index af658f7c3..e11be2233 100644 --- a/app/res/values/cues.xml +++ b/app/res/values/cues.xml @@ -16,9 +16,9 @@ ~ along with this program. If not, see .--> {0} {1} {2} {0} {1} - 10#activity|20#activity - 10#interval|20#interval - 10#lap|20#lap + 0<activity + 0<interval + 0<lap