Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2015-12-18 09:59:41 +01:00
commit faa83dac7a

View file

@ -1,6 +1,8 @@
package net.osmand.plus.mapcontextmenu.other; package net.osmand.plus.mapcontextmenu.other;
import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.PopupMenu; import android.support.v7.widget.PopupMenu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
@ -15,9 +17,11 @@ import android.widget.TextView;
import net.osmand.AndroidUtils; import net.osmand.AndroidUtils;
import net.osmand.CallbackWithObject; import net.osmand.CallbackWithObject;
import net.osmand.IndexConstants;
import net.osmand.Location; import net.osmand.Location;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.plus.ApplicationMode; import net.osmand.plus.ApplicationMode;
import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.GPXUtilities; import net.osmand.plus.GPXUtilities;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings;
@ -27,6 +31,8 @@ import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.SettingsBaseActivity; import net.osmand.plus.activities.SettingsBaseActivity;
import net.osmand.plus.activities.SettingsNavigationActivity; import net.osmand.plus.activities.SettingsNavigationActivity;
import net.osmand.plus.dashboard.DashboardOnMap; import net.osmand.plus.dashboard.DashboardOnMap;
import net.osmand.plus.download.DownloadActivity;
import net.osmand.plus.download.DownloadActivityType;
import net.osmand.plus.helpers.FileNameTranslationHelper; import net.osmand.plus.helpers.FileNameTranslationHelper;
import net.osmand.plus.helpers.GpxUiHelper; import net.osmand.plus.helpers.GpxUiHelper;
import net.osmand.plus.routing.RouteProvider; import net.osmand.plus.routing.RouteProvider;
@ -37,9 +43,12 @@ import net.osmand.util.MapUtils;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List; import java.util.List;
import java.util.Set;
public class RoutePreferencesMenu { public class RoutePreferencesMenu {
private OsmandSettings settings; private OsmandSettings settings;
private OsmandApplication app; private OsmandApplication app;
private MapActivity mapActivity; private MapActivity mapActivity;
@ -47,6 +56,8 @@ public class RoutePreferencesMenu {
private RoutingHelper routingHelper; private RoutingHelper routingHelper;
private ArrayAdapter<LocalRoutingParameter> listAdapter; private ArrayAdapter<LocalRoutingParameter> listAdapter;
public static final String MORE_VALUE = "MORE_VALUE";
public RoutePreferencesMenu(MapActivity mapActivity) { public RoutePreferencesMenu(MapActivity mapActivity) {
this.mapActivity = mapActivity; this.mapActivity = mapActivity;
app = mapActivity.getMyApplication(); app = mapActivity.getMyApplication();
@ -133,9 +144,65 @@ public class RoutePreferencesMenu {
} }
private void selectVoiceGuidance() { private void selectVoiceGuidance() {
mapActivity.getDashboard().setDashboardVisibility(false, DashboardOnMap.DashboardType.ROUTE_PREFERENCES); final ContextMenuAdapter adapter = new ContextMenuAdapter(mapActivity);
controlsLayer.getMapRouteInfoMenu().hide();
app.getAvoidSpecificRoads().showDialog(mapActivity); String[] entries;
final String[] entrieValues;
Set<String> voiceFiles = getVoiceFiles();
entries = new String[voiceFiles.size() + 2];
entrieValues = new String[voiceFiles.size() + 2];
int k = 0;
entrieValues[k] = OsmandSettings.VOICE_PROVIDER_NOT_USE;
entries[k] = getString(R.string.shared_string_do_not_use);
adapter.item(entries[k]).reg();
k++;
for (String s : voiceFiles) {
entries[k] = (s.contains("tts") ? getString(R.string.ttsvoice) + " " : "") +
FileNameTranslationHelper.getVoiceName(mapActivity, s);
entrieValues[k] = s;
adapter.item(entries[k]).reg();
k++;
}
entrieValues[k] = MORE_VALUE;
entries[k] = 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() {
@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();
}
}
});
builder.create().show();
}
private Set<String> getVoiceFiles() {
// read available voice data
File extStorage = app.getAppPath(IndexConstants.VOICE_INDEX_DIR);
Set<String> setFiles = new LinkedHashSet<>();
if (extStorage.exists()) {
for (File f : extStorage.listFiles()) {
if (f.isDirectory()) {
setFiles.add(f.getName());
}
}
}
return setFiles;
} }
public OnItemClickListener getItemClickListener(final ArrayAdapter<?> listAdapter) { public OnItemClickListener getItemClickListener(final ArrayAdapter<?> listAdapter) {
@ -179,7 +246,7 @@ public class RoutePreferencesMenu {
v.findViewById(R.id.description_text).setVisibility(View.GONE); v.findViewById(R.id.description_text).setVisibility(View.GONE);
v.findViewById(R.id.select_button).setVisibility(View.GONE); v.findViewById(R.id.select_button).setVisibility(View.GONE);
((ImageView) v.findViewById(R.id.icon)) ((ImageView) v.findViewById(R.id.icon))
.setImageDrawable(mapActivity.getMyApplication().getIconsCache().getContentIcon(R.drawable.ic_action_volume_up, !nightMode)); .setImageDrawable(app.getIconsCache().getContentIcon(R.drawable.ic_action_volume_up, !nightMode));
final CompoundButton btn = (CompoundButton) v.findViewById(R.id.check_item); final CompoundButton btn = (CompoundButton) v.findViewById(R.id.check_item);
btn.setVisibility(View.VISIBLE); btn.setVisibility(View.VISIBLE);
btn.setChecked(!routingHelper.getVoiceRouter().isMute()); btn.setChecked(!routingHelper.getVoiceRouter().isMute());
@ -198,7 +265,7 @@ public class RoutePreferencesMenu {
if (parameter instanceof AvoidRoadsRoutingParameter) { if (parameter instanceof AvoidRoadsRoutingParameter) {
View v = mapActivity.getLayoutInflater().inflate(R.layout.switch_select_list_item, null); View v = mapActivity.getLayoutInflater().inflate(R.layout.switch_select_list_item, null);
((ImageView) v.findViewById(R.id.icon)) ((ImageView) v.findViewById(R.id.icon))
.setImageDrawable(mapActivity.getMyApplication().getIconsCache().getContentIcon(R.drawable.ic_action_road_works_dark, !nightMode)); .setImageDrawable(app.getIconsCache().getContentIcon(R.drawable.ic_action_road_works_dark, !nightMode));
v.findViewById(R.id.check_item).setVisibility(View.GONE); v.findViewById(R.id.check_item).setVisibility(View.GONE);
final TextView btn = (TextView) v.findViewById(R.id.select_button); final TextView btn = (TextView) v.findViewById(R.id.select_button);
btn.setTextColor(btn.getLinkTextColors()); btn.setTextColor(btn.getLinkTextColors());
@ -227,7 +294,12 @@ public class RoutePreferencesMenu {
final TextView btn = (TextView) v.findViewById(R.id.select_button); final TextView btn = (TextView) v.findViewById(R.id.select_button);
btn.setTextColor(btn.getLinkTextColors()); btn.setTextColor(btn.getLinkTextColors());
String voiceProvider = settings.VOICE_PROVIDER.get(); String voiceProvider = settings.VOICE_PROVIDER.get();
String voiceProviderStr = FileNameTranslationHelper.getVoiceName(mapActivity, voiceProvider); String voiceProviderStr;
if (OsmandSettings.VOICE_PROVIDER_NOT_USE.equals(voiceProvider)) {
voiceProviderStr = getString(R.string.shared_string_do_not_use);
} else {
voiceProviderStr = FileNameTranslationHelper.getVoiceName(mapActivity, voiceProvider);
}
voiceProviderStr += voiceProvider.contains("tts") ? " TTS" : ""; voiceProviderStr += voiceProvider.contains("tts") ? " TTS" : "";
btn.setText(voiceProviderStr); btn.setText(voiceProviderStr);
btn.setOnClickListener(new View.OnClickListener() { btn.setOnClickListener(new View.OnClickListener() {
@ -254,7 +326,7 @@ public class RoutePreferencesMenu {
if (parameter instanceof OtherSettingsRoutingParameter) { if (parameter instanceof OtherSettingsRoutingParameter) {
View v = mapActivity.getLayoutInflater().inflate(R.layout.layers_list_activity_item, null); View v = mapActivity.getLayoutInflater().inflate(R.layout.layers_list_activity_item, null);
final ImageView icon = (ImageView) v.findViewById(R.id.icon); final ImageView icon = (ImageView) v.findViewById(R.id.icon);
icon.setImageDrawable(mapActivity.getMyApplication().getIconsCache().getContentIcon(R.drawable.map_action_settings, !nightMode)); icon.setImageDrawable(app.getIconsCache().getContentIcon(R.drawable.map_action_settings, !nightMode));
icon.setVisibility(View.VISIBLE); icon.setVisibility(View.VISIBLE);
TextView titleView = (TextView) v.findViewById(R.id.title); TextView titleView = (TextView) v.findViewById(R.id.title);
titleView.setText(R.string.routing_settings_2); titleView.setText(R.string.routing_settings_2);
@ -308,7 +380,7 @@ public class RoutePreferencesMenu {
if (rp != null) { if (rp != null) {
if (gpxParam.id == R.string.gpx_option_reverse_route) { if (gpxParam.id == R.string.gpx_option_reverse_route) {
rp.setReverse(selected); rp.setReverse(selected);
TargetPointsHelper tg = mapActivity.getMyApplication().getTargetPointsHelper(); TargetPointsHelper tg = app.getTargetPointsHelper();
List<Location> ps = rp.getPoints(); List<Location> ps = rp.getPoints();
if (ps.size() > 0) { if (ps.size() > 0) {
Location first = ps.get(0); Location first = ps.get(0);
@ -358,7 +430,7 @@ public class RoutePreferencesMenu {
private List<LocalRoutingParameter> getRoutingParameters(ApplicationMode am) { private List<LocalRoutingParameter> getRoutingParameters(ApplicationMode am) {
List<LocalRoutingParameter> list = getRoutingParametersInner(am); List<LocalRoutingParameter> list = getRoutingParametersInner(am);
list.add(0, new MuteSoundRoutingParameter()); list.add(0, new MuteSoundRoutingParameter());
//list.add(1, new VoiceGuidanceRoutingParameter()); list.add(1, new VoiceGuidanceRoutingParameter());
list.add(2, new AvoidRoadsRoutingParameter()); list.add(2, new AvoidRoadsRoutingParameter());
list.add(new GpxLocalRoutingParameter()); list.add(new GpxLocalRoutingParameter());
list.add(new OtherSettingsRoutingParameter()); list.add(new OtherSettingsRoutingParameter());
@ -424,7 +496,7 @@ public class RoutePreferencesMenu {
@Override @Override
public boolean processResult(GPXUtilities.GPXFile[] result) { public boolean processResult(GPXUtilities.GPXFile[] result) {
mapActivity.getMapActions().setGPXRouteParams(result[0]); mapActivity.getMapActions().setGPXRouteParams(result[0]);
mapActivity.getMyApplication().getTargetPointsHelper().updateRouteAndReferesh(true); app.getTargetPointsHelper().updateRouteAndReferesh(true);
updateSpinnerItems(gpxSpinner); updateSpinnerItems(gpxSpinner);
updateParameters(); updateParameters();
mapActivity.getRoutingHelper().recalculateRouteDueToSettingsChange(); mapActivity.getRoutingHelper().recalculateRouteDueToSettingsChange();