diff --git a/PocketMaps/app/src/main/java/com/junjunguo/pocketmaps/activities/MainActivity.java b/PocketMaps/app/src/main/java/com/junjunguo/pocketmaps/activities/MainActivity.java index 4a36728..e0bf665 100644 --- a/PocketMaps/app/src/main/java/com/junjunguo/pocketmaps/activities/MainActivity.java +++ b/PocketMaps/app/src/main/java/com/junjunguo/pocketmaps/activities/MainActivity.java @@ -41,6 +41,8 @@ import com.junjunguo.pocketmaps.fragments.Dialog; import com.junjunguo.pocketmaps.fragments.MessageDialog; import com.junjunguo.pocketmaps.fragments.MyMapAdapter; +import com.junjunguo.pocketmaps.navigator.NaviText; +import com.junjunguo.pocketmaps.navigator.NaviVoice; import com.junjunguo.pocketmaps.util.IO; import com.junjunguo.pocketmaps.util.SetStatusBarColor; import com.junjunguo.pocketmaps.util.Variable; @@ -69,6 +71,7 @@ public class MainActivity extends AppCompatActivity implements OnClickMapListene @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); + NaviText.initTextList(this); continueActivity(); } diff --git a/PocketMaps/app/src/main/java/com/junjunguo/pocketmaps/map/Navigator.java b/PocketMaps/app/src/main/java/com/junjunguo/pocketmaps/map/Navigator.java index dbacdfc..9d9c914 100644 --- a/PocketMaps/app/src/main/java/com/junjunguo/pocketmaps/map/Navigator.java +++ b/PocketMaps/app/src/main/java/com/junjunguo/pocketmaps/map/Navigator.java @@ -6,6 +6,7 @@ import com.junjunguo.pocketmaps.R; import com.junjunguo.pocketmaps.model.listeners.NavigatorListener; import com.junjunguo.pocketmaps.navigator.NaviEngine; +import com.junjunguo.pocketmaps.navigator.NaviText; import com.junjunguo.pocketmaps.util.UnitCalculator; import com.junjunguo.pocketmaps.util.Variable; @@ -325,8 +326,63 @@ public int getDirectionSignHuge(Instruction itemData) { * @return direction */ public String getDirectionDescription(Instruction instruction, boolean longText) { - if (instruction.getSign() == 4) return "Navigation End";//4 - String str; // TODO: Translate all this instructions to Language? + if (instruction.getSign() == 4) return NaviText.sNavEnd; + String str; + String streetName = instruction.getName(); + int sign = instruction.getSign(); + String dir = ""; + String dirTo = NaviText.sOnto; + switch (sign) { + case Instruction.CONTINUE_ON_STREET: + dir = (NaviText.sContinue); + dirTo = NaviText.sOn; + break; + case Instruction.LEAVE_ROUNDABOUT: + dir = (NaviText.sLeaveRound); + break; + case Instruction.TURN_SHARP_LEFT: + dir = (NaviText.sTurnXXX.replace("xxx", NaviText.sSharpL)); + break; + case Instruction.TURN_LEFT: + dir = (NaviText.sTurnXXX.replace("xxx", NaviText.sLeft)); + break; + case Instruction.TURN_SLIGHT_LEFT: + dir = (NaviText.sTurnXXX.replace("xxx", NaviText.sSlightL)); + break; + case Instruction.TURN_SLIGHT_RIGHT: + dir = (NaviText.sTurnXXX.replace("xxx", NaviText.sSlightR)); + break; + case Instruction.TURN_RIGHT: + dir = (NaviText.sTurnXXX.replace("xxx", NaviText.sRight)); + break; + case Instruction.TURN_SHARP_RIGHT: + dir = (NaviText.sTurnXXX.replace("xxx", NaviText.sSharpR)); + break; + case Instruction.REACHED_VIA: + dir = ("Reached via"); + break; + case Instruction.USE_ROUNDABOUT: + dir = (NaviText.sUseRound); + break; + case Instruction.KEEP_LEFT: + dir = (NaviText.sKeepXXX.replace("xxx", NaviText.sLeft)); + break; + case Instruction.KEEP_RIGHT: + dir = (NaviText.sKeepXXX.replace("xxx", NaviText.sRight)); + break; + } + if (!longText) { return dir; } + str = Helper.isEmpty(streetName) ? dir : (dir + " " + dirTo + " " + streetName); + return str; + } + + /** + * @param instruction + * @return direction + */ + public String getDirectionDescriptionFallback(Instruction instruction, boolean longText) { + if (instruction.getSign() == 4) return "Navigation End"; + String str; String streetName = instruction.getName(); int sign = instruction.getSign(); String dir = ""; diff --git a/PocketMaps/app/src/main/java/com/junjunguo/pocketmaps/navigator/NaviEngine.java b/PocketMaps/app/src/main/java/com/junjunguo/pocketmaps/navigator/NaviEngine.java index efaa39a..6ea273d 100644 --- a/PocketMaps/app/src/main/java/com/junjunguo/pocketmaps/navigator/NaviEngine.java +++ b/PocketMaps/app/src/main/java/com/junjunguo/pocketmaps/navigator/NaviEngine.java @@ -456,7 +456,7 @@ private NaviInstruction getNewInstruction() NaviInstruction nIn = new NaviInstruction(in, nextIn, fullTime); if (speakDistanceCheck(in.getDistance()) && nearestP.isDirectionOk()) { - naviVoice.speak(nIn.getVoiceText()); + naviVoice.speak(nIn.getVoiceTextFallback(), nIn.getVoiceText()); naviVoiceSpoken = true; } else @@ -495,7 +495,7 @@ private NaviInstruction getUpdatedInstruction(GeoPoint curPos, PointPosData near newIn.updateDist(partDistance); if (!naviVoiceSpoken && nearestP.isDirectionOk() && speakDistanceCheck(partDistance)) { - naviVoice.speak(newIn.getVoiceText()); + naviVoice.speak(newIn.getVoiceTextFallback(), newIn.getVoiceText()); naviVoiceSpoken = true; } return newIn; @@ -606,7 +606,7 @@ public void checkDirectionOk(Location pos, Instruction in, NaviVoice v) { if (wrongDirHint) { return; } wrongDirHint = true; - v.speak("Wrong direction"); + v.speak("Wrong direction", NaviText.sWrongDir); } } diff --git a/PocketMaps/app/src/main/java/com/junjunguo/pocketmaps/navigator/NaviInstruction.java b/PocketMaps/app/src/main/java/com/junjunguo/pocketmaps/navigator/NaviInstruction.java index 5e886df..fa3736c 100644 --- a/PocketMaps/app/src/main/java/com/junjunguo/pocketmaps/navigator/NaviInstruction.java +++ b/PocketMaps/app/src/main/java/com/junjunguo/pocketmaps/navigator/NaviInstruction.java @@ -11,6 +11,7 @@ public class NaviInstruction String curStreet; String nextInstruction; String nextInstructionShort; + String nextInstructionShortFallback; long fullTime; String fullTimeString; double nextDistance; @@ -25,6 +26,7 @@ public NaviInstruction(Instruction in, Instruction nextIn, long fullTime) nextSignResource = Navigator.getNavigator().getDirectionSignHuge(nextIn); nextInstruction = Navigator.getNavigator().getDirectionDescription(nextIn, true); nextInstructionShort = Navigator.getNavigator().getDirectionDescription(nextIn, false); + nextInstructionShortFallback = Navigator.getNavigator().getDirectionDescriptionFallback(nextIn, false); } else { @@ -32,6 +34,7 @@ public NaviInstruction(Instruction in, Instruction nextIn, long fullTime) nextSignResource = Navigator.getNavigator().getDirectionSignHuge(in); nextInstruction = Navigator.getNavigator().getDirectionDescription(in, true); nextInstructionShort = Navigator.getNavigator().getDirectionDescription(in, false); + nextInstructionShortFallback = Navigator.getNavigator().getDirectionDescriptionFallback(in, false); } if (nextSignResource == 0) { nextSignResource = R.drawable.ic_2x_continue_on_street; } nextDistance = in.getDistance(); @@ -68,6 +71,20 @@ public void updateDist(double partDistance) public String getVoiceText() + { + String unit = " " + NaviText.sMeters + ". "; + int roundetDistance = (int)nextDistance; + if (Variable.getVariable().isImperalUnit()) + { + unit = " " + NaviText.sFeets + ". "; + roundetDistance = (int)(nextDistance / UnitCalculator.METERS_OF_FEET); + } + roundetDistance = roundetDistance/10; + roundetDistance = roundetDistance * 10; + return NaviText.sIn + " " + roundetDistance + unit + nextInstructionShort; + } + + public String getVoiceTextFallback() { String unit = " meters. "; int roundetDistance = (int)nextDistance; @@ -78,6 +95,6 @@ public String getVoiceText() } roundetDistance = roundetDistance/10; roundetDistance = roundetDistance * 10; - return "In " + roundetDistance + unit + nextInstructionShort; + return "In " + roundetDistance + unit + nextInstructionShortFallback; } } diff --git a/PocketMaps/app/src/main/java/com/junjunguo/pocketmaps/navigator/NaviText.java b/PocketMaps/app/src/main/java/com/junjunguo/pocketmaps/navigator/NaviText.java new file mode 100644 index 0000000..a91622b --- /dev/null +++ b/PocketMaps/app/src/main/java/com/junjunguo/pocketmaps/navigator/NaviText.java @@ -0,0 +1,58 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package com.junjunguo.pocketmaps.navigator; + +import android.app.Activity; +import com.junjunguo.pocketmaps.R; + +/** + * + * @author ppp + */ +public class NaviText +{ + public static String sIn; + public static String sMeters; + public static String sFeets; + public static String sUseRound; + public static String sLeaveRound; + public static String sTurnXXX; + public static String sKeepXXX; + public static String sLeft; + public static String sRight; + public static String sSlightL; + public static String sSlightR; + public static String sSharpL; + public static String sSharpR; + public static String sWrongDir; + public static String sOn; + public static String sOnto; + public static String sContinue; + public static String sNavEnd; + + public static void initTextList(Activity activity) + { + if (sIn != null) { return; } + sIn = activity.getResources().getString(R.string.navivoice_in); + sFeets = activity.getResources().getString(R.string.navivoice_feets); + sMeters = activity.getResources().getString(R.string.navivoice_meters); + sUseRound = activity.getResources().getString(R.string.navivoice_useround); + sLeaveRound = activity.getResources().getString(R.string.navivoice_leaveround); + sTurnXXX = activity.getResources().getString(R.string.navivoice_turnxxx); + sKeepXXX = activity.getResources().getString(R.string.navivoice_keepxxx); + sLeft = activity.getResources().getString(R.string.navivoice_left); + sRight = activity.getResources().getString(R.string.navivoice_right); + sSlightL = activity.getResources().getString(R.string.navivoice_slightl); + sSlightR = activity.getResources().getString(R.string.navivoice_slightr); + sSharpL = activity.getResources().getString(R.string.navivoice_sharpl); + sSharpR = activity.getResources().getString(R.string.navivoice_sharpr); + sWrongDir = activity.getResources().getString(R.string.navivoice_wrongdir); + sOn = activity.getResources().getString(R.string.navivoice_on); + sOnto = activity.getResources().getString(R.string.navivoice_onto); + sContinue = activity.getResources().getString(R.string.navivoice_continue); + sNavEnd = activity.getResources().getString(R.string.navivoice_navend); + } +} diff --git a/PocketMaps/app/src/main/java/com/junjunguo/pocketmaps/navigator/NaviVoice.java b/PocketMaps/app/src/main/java/com/junjunguo/pocketmaps/navigator/NaviVoice.java index dd2e7e4..540d94b 100644 --- a/PocketMaps/app/src/main/java/com/junjunguo/pocketmaps/navigator/NaviVoice.java +++ b/PocketMaps/app/src/main/java/com/junjunguo/pocketmaps/navigator/NaviVoice.java @@ -3,21 +3,27 @@ import java.util.HashMap; import java.util.Locale; import java.util.Set; +import java.util.HashSet; import com.junjunguo.pocketmaps.util.Variable; import android.annotation.TargetApi; +import android.app.Activity; import android.content.Context; +import android.content.Intent; import android.os.Build; import android.speech.tts.TextToSpeech; import android.speech.tts.Voice; import android.speech.tts.TextToSpeech.OnInitListener; +import java.util.ArrayList; public class NaviVoice { + public static final String DISPLAY_LANG = Locale.getDefault().getDisplayLanguage(); TextToSpeech tts; Voice curVoice; - Locale wantedLang = Locale.ENGLISH; + Locale wantedLang = new Locale(DISPLAY_LANG); + Locale fallbackLang = Locale.ENGLISH; String wantedName; boolean ttsReady; boolean ttsMute = false; @@ -25,6 +31,7 @@ public class NaviVoice public NaviVoice(Context context) { tts = new TextToSpeech(context, createInitListener()); + updateVoiceCompat(); } public boolean isTtsReady() @@ -34,13 +41,14 @@ public boolean isTtsReady() public void setTtsMute(boolean ttsMute) { this.ttsMute = ttsMute; } - public void speak(String txt) + public void speak(String fallbackTxt, String txt) { if (!ttsReady) { return; } if (!Variable.getVariable().isVoiceON()) { return; } if (ttsMute) { return; } updateVoiceCompat(); - speakCompat(txt); + if (wantedLang == fallbackLang) { speakCompat(fallbackTxt); } + else { speakCompat(txt); } } /** Hint from https://stackoverflow.com/questions/27968146/texttospeech-with-api-21#29777304 **/ @@ -87,8 +95,10 @@ private void updateVoiceCompat() private void updateVoiceUnder20() { Locale l = tts.getLanguage(); - if (l.equals(wantedLang)) { return; } - tts.setLanguage(l); + if (l.equals(wantedLang) || l.equals(fallbackLang)) { return; } + tts.setLanguage(wantedLang); + if (!tts.getLanguage().equals(wantedLang)) + tts.setLanguage(fallbackLang); } @TargetApi(Build.VERSION_CODES.LOLLIPOP) @@ -97,7 +107,12 @@ private void updateVoiceGreater21() if (!ttsReady) { return; } if (curVoice == null) { - curVoice = searchWantedVoiceGreater21(); + curVoice = searchWantedVoiceGreater21(wantedLang); + if (curVoice == null) + { + wantedLang = fallbackLang; + curVoice = searchWantedVoiceGreater21(fallbackLang); + } if (curVoice == null) { return; } } else @@ -108,9 +123,9 @@ private void updateVoiceGreater21() } @TargetApi(Build.VERSION_CODES.LOLLIPOP) - private Voice searchWantedVoiceGreater21() + private Voice searchWantedVoiceGreater21(Locale selLang) { - Set curVoices = getVoiceListGreater21(wantedLang); + Set curVoices = getVoiceListGreater21(selLang); if (curVoices.size() == 0) { return null; } if (wantedName != null) { @@ -126,7 +141,13 @@ private Voice searchWantedVoiceGreater21() public Set getVoiceListGreater21(Locale lang) { if (!ttsReady) { return null; } - return tts.getVoices(); + Set allV = tts.getVoices(); + Set selV = new HashSet<>(); + for (Voice curV : allV) + { + if (curV.getLocale().getLanguage().equals(lang.getLanguage())) { selV.add(curV); } + } + return selV; } /** Can be set before androids TTS is ready. **/ diff --git a/PocketMaps/app/src/main/res/values-de/strings.xml b/PocketMaps/app/src/main/res/values-de/strings.xml index 6b44cad..b02601b 100644 --- a/PocketMaps/app/src/main/res/values-de/strings.xml +++ b/PocketMaps/app/src/main/res/values-de/strings.xml @@ -77,4 +77,22 @@ Texteingabe Bearbeiten Hilfe + Falsche Richtung + Nach + meter + Fuß + benutzen sie den Kreisverkehr + biegen sie xxx ab + halten sie sich xxx + links + rechts + leicht links + leicht rechts + scharf links + scharf rechts + auf + auf + weiter fahren + verlassen sie den Kreisverkehr + Navigation beendet diff --git a/PocketMaps/app/src/main/res/values-it/strings.xml b/PocketMaps/app/src/main/res/values-it/strings.xml index 5b0ad9b..5d4c355 100644 --- a/PocketMaps/app/src/main/res/values-it/strings.xml +++ b/PocketMaps/app/src/main/res/values-it/strings.xml @@ -77,4 +77,22 @@ inserire il testo Modifica Aiuto + Direzione sbagliata + In + metri + piedi + lasciare la rotonda + gira a xxx + tieni la xxx + sinistra + destra + slight left + slight right + forte a sinistra + forte a destra + su + onto + continuare + lasciare la rotonda + fine della navigazione diff --git a/PocketMaps/app/src/main/res/values-nl/strings.xml b/PocketMaps/app/src/main/res/values-nl/strings.xml index 651afb6..aa57aec 100644 --- a/PocketMaps/app/src/main/res/values-nl/strings.xml +++ b/PocketMaps/app/src/main/res/values-nl/strings.xml @@ -77,4 +77,22 @@ Voer tekst in Bewerk Helpen + Verkeerde kant + In + meter + voet + gebruik rotonde + sla xxxaf + xxx aanhouden + links + rechts + iets links + iets rechts + scherp links + scherp rechts + op + naar + vervolgen + verlaat de rotonde + Navigatie voltooid diff --git a/PocketMaps/app/src/main/res/values-pt-rBR/strings.xml b/PocketMaps/app/src/main/res/values-pt-rBR/strings.xml index 50e02ef..6232444 100644 --- a/PocketMaps/app/src/main/res/values-pt-rBR/strings.xml +++ b/PocketMaps/app/src/main/res/values-pt-rBR/strings.xml @@ -77,4 +77,22 @@ inserir texto Editar Socorro + Direção errada + em + metros + pés + use a rotatória + vire à xxx + fique à xxx + esquerda + direita + ligeiramente à esquerda + ligeiramente à direita + afiada esquerda + afiada dereita + em + para + continuar + sair da rotatória + fim da navegação diff --git a/PocketMaps/app/src/main/res/values/strings.xml b/PocketMaps/app/src/main/res/values/strings.xml index 9a549a2..7e2ab2e 100644 --- a/PocketMaps/app/src/main/res/values/strings.xml +++ b/PocketMaps/app/src/main/res/values/strings.xml @@ -77,4 +77,22 @@ Enter text Edit Help + Wrong direction + In + meters + feets + use roundabout + turn xxx + keep xxx + left + right + slight left + slight right + sharp left + sharp right + on + onto + continue + leave roundabout + Navigation end diff --git a/mapGenerator/compile_copy_paul.sh b/mapGenerator/compile_copy_paul.sh index 631a3b3..012a304 100755 --- a/mapGenerator/compile_copy_paul.sh +++ b/mapGenerator/compile_copy_paul.sh @@ -11,8 +11,8 @@ ## ############################################################################## -PROJ_PATH="/home/ppp/Desktop/Programmieren/map/PocketMaps/PocketMaps/" -export ANDROID_HOME="/home/ppp/Desktop/Programmieren/Android-SDK-Tests/android-sdk-linux/" +PROJ_PATH="/home/ppp/workspace/NetBeansProjects/PocketMaps_git/PocketMaps/" +export ANDROID_HOME="/home/ppp/workspace/Android-SDK/android-sdk-linux/" PACK_NAME=$(cat "$PROJ_PATH/app/src/main/AndroidManifest.xml" | grep "package=" | cut -d'"' -s -f 2) CUR_ARGS="build" TMP_COPY="false"