From 7839f0b933062061cbb205d42d47bb41dafdd655 Mon Sep 17 00:00:00 2001 From: Alexey Kulish Date: Fri, 18 Dec 2015 18:58:39 +0300 Subject: [PATCH] First time voice provider dialog changed. Added interrupt music setting --- OsmAnd/res/layout/select_voice_first.xml | 81 +++++++++++++++ OsmAnd/res/values/strings.xml | 2 + OsmAnd/src/net/osmand/AndroidUtils.java | 13 +++ .../net/osmand/plus/OsmandApplication.java | 79 +++++++-------- .../other/RoutePreferencesMenu.java | 99 +++++++++++++++---- 5 files changed, 217 insertions(+), 57 deletions(-) create mode 100644 OsmAnd/res/layout/select_voice_first.xml diff --git a/OsmAnd/res/layout/select_voice_first.xml b/OsmAnd/res/layout/select_voice_first.xml new file mode 100644 index 0000000000..3aec79af97 --- /dev/null +++ b/OsmAnd/res/layout/select_voice_first.xml @@ -0,0 +1,81 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index aec3d64e5a..431a8e3304 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -9,6 +9,8 @@ 3. All your modified/created strings are in the top of the file (to make easier find what\'s translated). PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy --> + Select voice guidance + Select or download voice guidance for your language Select roads you want to avoid during navigation Sound App have no permission to access location data. diff --git a/OsmAnd/src/net/osmand/AndroidUtils.java b/OsmAnd/src/net/osmand/AndroidUtils.java index 8daaa2658f..73fc807b50 100644 --- a/OsmAnd/src/net/osmand/AndroidUtils.java +++ b/OsmAnd/src/net/osmand/AndroidUtils.java @@ -4,8 +4,10 @@ package net.osmand; import android.annotation.SuppressLint; import android.content.Context; import android.content.res.Configuration; +import android.content.res.Resources; import android.os.Build; import android.text.format.DateFormat; +import android.util.TypedValue; import android.view.View; import android.view.ViewParent; import android.view.inputmethod.InputMethodManager; @@ -15,6 +17,8 @@ import net.osmand.plus.R; import java.util.Date; +import static android.util.TypedValue.COMPLEX_UNIT_DIP; + public class AndroidUtils { /** @@ -103,4 +107,13 @@ public class AndroidUtils { : ctx.getResources().getColor(R.color.secondary_text_light)); } + public static int dpToPx(Context ctx, float dp) { + Resources r = ctx.getResources(); + return (int) TypedValue.applyDimension( + COMPLEX_UNIT_DIP, + dp, + r.getDisplayMetrics() + ); + } + } diff --git a/OsmAnd/src/net/osmand/plus/OsmandApplication.java b/OsmAnd/src/net/osmand/plus/OsmandApplication.java index 4de2113293..b4e5b6dea0 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandApplication.java +++ b/OsmAnd/src/net/osmand/plus/OsmandApplication.java @@ -17,18 +17,15 @@ import android.support.multidex.MultiDex; import android.support.multidex.MultiDexApplication; import android.support.v7.app.AlertDialog; import android.text.format.DateFormat; -import android.util.TypedValue; import android.view.View; import android.view.accessibility.AccessibilityManager; -import android.widget.CheckBox; -import android.widget.LinearLayout; -import android.widget.LinearLayout.LayoutParams; +import android.widget.ImageView; import android.widget.TextView; import android.widget.Toast; +import net.osmand.CallbackWithObject; import net.osmand.PlatformUtil; import net.osmand.access.AccessibilityPlugin; -import net.osmand.access.AccessibleAlertBuilder; import net.osmand.access.AccessibleToast; import net.osmand.map.OsmandRegions; import net.osmand.osm.MapPoiTypes; @@ -36,14 +33,15 @@ import net.osmand.plus.AppInitializer.AppInitializeListener; import net.osmand.plus.access.AccessibilityMode; import net.osmand.plus.activities.DayNightHelper; import net.osmand.plus.activities.ExitActivity; +import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.SavingTrackHelper; -import net.osmand.plus.activities.SettingsActivity; import net.osmand.plus.api.SQLiteAPI; import net.osmand.plus.api.SQLiteAPIImpl; import net.osmand.plus.dialogs.RateUsBottomSheetDialog; import net.osmand.plus.download.DownloadIndexesThread; import net.osmand.plus.helpers.AvoidSpecificRoads; import net.osmand.plus.helpers.WaypointHelper; +import net.osmand.plus.mapcontextmenu.other.RoutePreferencesMenu; import net.osmand.plus.monitoring.LiveMonitoringHelper; import net.osmand.plus.poi.PoiFiltersHelper; import net.osmand.plus.render.RendererRegistry; @@ -104,7 +102,8 @@ public class OsmandApplication extends MultiDexApplication { private Locale preferredLocale = null; private Locale defaultLocale; private File externalStorageDirectory; - + + private String firstSelectedVoiceProvider; // Typeface @@ -346,44 +345,46 @@ public class OsmandApplication extends MultiDexApplication { String voiceProvider = osmandSettings.VOICE_PROVIDER.get(); if (voiceProvider == null || OsmandSettings.VOICE_PROVIDER_NOT_USE.equals(voiceProvider)) { if (warningNoneProvider && voiceProvider == null) { - AlertDialog.Builder builder = new AccessibleAlertBuilder(uiContext); - LinearLayout ll = new LinearLayout(uiContext); - ll.setOrientation(LinearLayout.VERTICAL); - final TextView tv = new TextView(uiContext); - tv.setPadding(7, 3, 7, 0); - tv.setText(R.string.voice_is_not_available_msg); - tv.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 19); - ll.addView(tv); - - final CheckBox cb = new CheckBox(uiContext); - cb.setText(R.string.shared_string_remember_my_choice); - LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); - lp.setMargins(7, 10, 7, 0); - cb.setLayoutParams(lp); - ll.addView(cb); - + final AlertDialog.Builder builder = new AlertDialog.Builder(uiContext); + + View view = uiContext.getLayoutInflater().inflate(R.layout.select_voice_first, null); + + ((ImageView) view.findViewById(R.id.icon)) + .setImageDrawable(getIconsCache().getContentIcon(R.drawable.ic_action_volume_up, getSettings().isLightContent())); + + view.findViewById(R.id.spinner).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(final View v) { + RoutePreferencesMenu.selectVoiceGuidance((MapActivity) uiContext, new CallbackWithObject() { + @Override + public boolean processResult(String result) { + boolean acceptableValue = !RoutePreferencesMenu.MORE_VALUE.equals(firstSelectedVoiceProvider); + if (acceptableValue) { + ((TextView) v.findViewById(R.id.selectText)) + .setText(RoutePreferencesMenu.getVoiceProviderName(uiContext, result)); + firstSelectedVoiceProvider = result; + } + return acceptableValue; + } + }); + } + }); + + ((ImageView) view.findViewById(R.id.dropDownIcon)) + .setImageDrawable(getIconsCache().getContentIcon(R.drawable.ic_action_arrow_drop_down, getSettings().isLightContent())); + builder.setCancelable(true); - builder.setNegativeButton(R.string.shared_string_cancel, new DialogInterface.OnClickListener() { + builder.setNegativeButton(R.string.shared_string_cancel, null); + builder.setPositiveButton(R.string.shared_string_apply, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { - if(cb.isChecked()) { - osmandSettings.VOICE_PROVIDER.set(OsmandSettings.VOICE_PROVIDER_NOT_USE); + if (!Algorithms.isEmpty(firstSelectedVoiceProvider)) { + RoutePreferencesMenu.applyVoiceProvider((MapActivity) uiContext, firstSelectedVoiceProvider); } } }); - builder.setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - Intent intent = new Intent(uiContext, SettingsActivity.class); - intent.putExtra(SettingsActivity.INTENT_KEY_SETTINGS_SCREEN, SettingsActivity.SCREEN_GENERAL_SETTINGS); - uiContext.startActivity(intent); - } - }); - - - builder.setTitle(R.string.voice_is_not_available_title); - builder.setView(ll); - //builder.setMessage(R.string.voice_is_not_available_msg); + + builder.setView(view); builder.show(); } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/RoutePreferencesMenu.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/RoutePreferencesMenu.java index 3518c09fe7..2cbef200cf 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/RoutePreferencesMenu.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/RoutePreferencesMenu.java @@ -1,5 +1,6 @@ package net.osmand.plus.mapcontextmenu.other; +import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.support.v7.app.AlertDialog; @@ -92,6 +93,9 @@ public class RoutePreferencesMenu { private static class MuteSoundRoutingParameter extends LocalRoutingParameter { } + private static class InterruptMusicRoutingParameter extends LocalRoutingParameter { + } + private static class VoiceGuidanceRoutingParameter extends LocalRoutingParameter { } @@ -137,63 +141,88 @@ public class RoutePreferencesMenu { routingHelper.getVoiceRouter().setMute(mt); } + private void switchMusic() { + boolean mt = !settings.INTERRUPT_MUSIC.get(); + settings.INTERRUPT_MUSIC.set(mt); + } + private void selectRestrictedRoads() { mapActivity.getDashboard().setDashboardVisibility(false, DashboardOnMap.DashboardType.ROUTE_PREFERENCES); controlsLayer.getMapRouteInfoMenu().hide(); app.getAvoidSpecificRoads().showDialog(mapActivity); } - private void selectVoiceGuidance() { + public static void selectVoiceGuidance(final MapActivity mapActivity, final CallbackWithObject callback) { final ContextMenuAdapter adapter = new ContextMenuAdapter(mapActivity); String[] entries; final String[] entrieValues; - Set voiceFiles = getVoiceFiles(); + Set voiceFiles = getVoiceFiles(mapActivity); entries = new String[voiceFiles.size() + 2]; entrieValues = new String[voiceFiles.size() + 2]; int k = 0; + int selected = -1; + String selectedValue = mapActivity.getMyApplication().getSettings().VOICE_PROVIDER.get(); entrieValues[k] = OsmandSettings.VOICE_PROVIDER_NOT_USE; - entries[k] = getString(R.string.shared_string_do_not_use); + entries[k] = mapActivity.getResources().getString(R.string.shared_string_do_not_use); adapter.item(entries[k]).reg(); + if (OsmandSettings.VOICE_PROVIDER_NOT_USE.equals(selectedValue)) { + selected = k; + } k++; for (String s : voiceFiles) { - entries[k] = (s.contains("tts") ? getString(R.string.ttsvoice) + " " : "") + + entries[k] = (s.contains("tts") ? mapActivity.getResources().getString(R.string.ttsvoice) + " " : "") + FileNameTranslationHelper.getVoiceName(mapActivity, s); entrieValues[k] = s; adapter.item(entries[k]).reg(); + if (s.equals(selectedValue)) { + selected = k; + } k++; } entrieValues[k] = MORE_VALUE; - entries[k] = getString(R.string.install_more); + entries[k] = mapActivity.getResources().getString(R.string.install_more); adapter.item(entries[k]).reg(); - final AlertDialog.Builder builder = new AlertDialog.Builder(mapActivity); - final ArrayAdapter listAdapter = - adapter.createListAdapter(mapActivity, settings.isLightContent()); - builder.setAdapter(listAdapter, new DialogInterface.OnClickListener() { + AlertDialog.Builder bld = new AlertDialog.Builder(mapActivity); + bld.setSingleChoiceItems(entries, selected, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String value = entrieValues[which]; if (MORE_VALUE.equals(value)) { - // listPref.set(oldValue); // revert the change.. final Intent intent = new Intent(mapActivity, DownloadActivity.class); intent.putExtra(DownloadActivity.TAB_TO_OPEN, DownloadActivity.DOWNLOAD_TAB); intent.putExtra(DownloadActivity.FILTER_CAT, DownloadActivityType.VOICE_FILE.getTag()); mapActivity.startActivity(intent); } else { - settings.VOICE_PROVIDER.set(value); - app.showDialogInitializingCommandPlayer(mapActivity, false); - updateParameters(); + if (callback != null) { + callback.processResult(value); + } } + dialog.dismiss(); } }); - builder.create().show(); + bld.show(); } - private Set getVoiceFiles() { + public static String getVoiceProviderName(Context ctx, String value) { + if (OsmandSettings.VOICE_PROVIDER_NOT_USE.equals(value)) { + return ctx.getResources().getString(R.string.shared_string_do_not_use); + } else { + return (value.contains("tts") ? ctx.getResources().getString(R.string.ttsvoice) + " " : "") + + FileNameTranslationHelper.getVoiceName(ctx, value); + } + } + + public static void applyVoiceProvider(MapActivity mapActivity, String provider) { + mapActivity.getMyApplication().getSettings().VOICE_PROVIDER.set(provider); + mapActivity.getMyApplication().showDialogInitializingCommandPlayer(mapActivity, false); + } + + private static Set getVoiceFiles(MapActivity mapActivity) { // read available voice data - File extStorage = app.getAppPath(IndexConstants.VOICE_INDEX_DIR); + File extStorage = mapActivity.getMyApplication().getAppPath(IndexConstants.VOICE_INDEX_DIR); Set setFiles = new LinkedHashSet<>(); if (extStorage.exists()) { for (File f : extStorage.listFiles()) { @@ -220,6 +249,9 @@ public class RoutePreferencesMenu { } else if (obj instanceof VoiceGuidanceRoutingParameter) { final TextView btn = (TextView) view.findViewById(R.id.select_button); btn.performClick(); + } else if (obj instanceof InterruptMusicRoutingParameter) { + final CompoundButton btn = (CompoundButton) view.findViewById(R.id.check_item); + btn.performClick(); } else if (obj instanceof AvoidRoadsRoutingParameter) { selectRestrictedRoads(); } else if (view.findViewById(R.id.GPXRouteSpinner) != null) { @@ -305,7 +337,14 @@ public class RoutePreferencesMenu { btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - selectVoiceGuidance(); + selectVoiceGuidance(mapActivity, new CallbackWithObject() { + @Override + public boolean processResult(String result) { + applyVoiceProvider(mapActivity, result); + updateParameters(); + return true; + } + }); } }); @@ -315,6 +354,29 @@ public class RoutePreferencesMenu { return v; } + if (parameter instanceof InterruptMusicRoutingParameter) { + View v = mapActivity.getLayoutInflater().inflate(R.layout.switch_select_list_item, null); + v.findViewById(R.id.select_button).setVisibility(View.GONE); + v.findViewById(R.id.icon).setVisibility(View.GONE); + final CompoundButton btn = (CompoundButton) v.findViewById(R.id.check_item); + btn.setVisibility(View.VISIBLE); + btn.setChecked(settings.INTERRUPT_MUSIC.get()); + btn.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + switchMusic(); + } + }); + + TextView tv = (TextView) v.findViewById(R.id.header_text); + AndroidUtils.setTextPrimaryColor(mapActivity, tv, nightMode); + tv.setText(getString(R.string.interrupt_music)); + TextView tvDesc = (TextView) v.findViewById(R.id.description_text); + AndroidUtils.setTextSecondaryColor(mapActivity, tvDesc, nightMode); + tvDesc.setText(getString(R.string.interrupt_music_descr)); + + return v; + } if (parameter instanceof GpxLocalRoutingParameter) { View v = mapActivity.getLayoutInflater().inflate(R.layout.plan_route_gpx, null); AndroidUtils.setTextPrimaryColor(mapActivity, (TextView) v.findViewById(R.id.GPXRouteTitle), nightMode); @@ -433,7 +495,8 @@ public class RoutePreferencesMenu { List list = getRoutingParametersInner(am); list.add(0, new MuteSoundRoutingParameter()); list.add(1, new VoiceGuidanceRoutingParameter()); - list.add(2, new AvoidRoadsRoutingParameter()); + list.add(2, new InterruptMusicRoutingParameter()); + list.add(3, new AvoidRoadsRoutingParameter()); list.add(new GpxLocalRoutingParameter()); list.add(new OtherSettingsRoutingParameter()); return list;