First time voice provider dialog changed. Added interrupt music setting
This commit is contained in:
parent
b4727dfafd
commit
7839f0b933
5 changed files with 217 additions and 57 deletions
81
OsmAnd/res/layout/select_voice_first.xml
Normal file
81
OsmAnd/res/layout/select_voice_first.xml
Normal file
|
@ -0,0 +1,81 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:padding="@dimen/list_content_padding">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/select_voice_provider"
|
||||
android:textColor="?android:textColorPrimary"
|
||||
android:textSize="@dimen/default_list_text_size_large"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/message"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingTop="@dimen/list_content_padding"
|
||||
android:textColor="?android:textColorSecondary"
|
||||
android:text="@string/select_voice_provider_descr"
|
||||
android:textSize="@dimen/default_list_text_size"/>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingTop="@dimen/list_content_padding"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/icon"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:paddingRight="@dimen/list_content_padding"
|
||||
android:src="@drawable/ic_action_volume_up"/>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/spinner"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingTop="@dimen/list_content_padding"
|
||||
android:paddingBottom="@dimen/list_content_padding"
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/selectText"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:gravity="left|center_vertical"
|
||||
android:textColor="?android:textColorSecondary"
|
||||
android:textSize="@dimen/default_list_text_size"
|
||||
android:text="@string/select_voice_provider"/>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/dropDownIcon"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:src="@drawable/ic_action_arrow_drop_down"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<View
|
||||
android:id="@+id/underline"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:layout_marginTop="4dp"
|
||||
android:background="?android:textColorSecondary"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
|
@ -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
|
||||
-->
|
||||
<string name="select_voice_provider">Select voice guidance</string>
|
||||
<string name="select_voice_provider_descr">Select or download voice guidance for your language</string>
|
||||
<string name="impassable_road_desc">Select roads you want to avoid during navigation</string>
|
||||
<string name="shared_string_sound">Sound</string>
|
||||
<string name="no_location_permission">App have no permission to access location data.</string>
|
||||
|
|
|
@ -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()
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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<String>() {
|
||||
@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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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<String> callback) {
|
||||
final ContextMenuAdapter adapter = new ContextMenuAdapter(mapActivity);
|
||||
|
||||
String[] entries;
|
||||
final String[] entrieValues;
|
||||
Set<String> voiceFiles = getVoiceFiles();
|
||||
Set<String> 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<String> 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<String> 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<String> 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<String>() {
|
||||
@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<LocalRoutingParameter> 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;
|
||||
|
|
Loading…
Reference in a new issue