Merge remote-tracking branch 'origin/master' into configure_menu_items

This commit is contained in:
veliymolfar 2020-04-10 13:52:04 +03:00
commit cab97f1d38
15 changed files with 94 additions and 60 deletions

View file

@ -4,7 +4,7 @@
<shape android:shape="rectangle">
<solid android:color="@android:color/transparent" />
<corners android:radius="4dp" />
<stroke android:width="1dp" android:color="?attr/secondary_icon_color" />
<stroke android:width="1dp" android:color="?attr/stroked_buttons_and_links_outline" />
</shape>
</item>
</selector>

View file

@ -29,7 +29,8 @@
<net.osmand.plus.widgets.OsmandTextFieldBoxes
android:id="@+id/master_profile_otfb"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_height="wrap_content"
android:minHeight="60dp"
app:labelText="@string/profile_type_base_string"
app:primaryColor="@color/active_color_primary_dark"
app:secondaryColor="?android:textColorSecondary">
@ -40,6 +41,7 @@
android:layout_height="wrap_content"
android:focusable="false"
android:maxLines="1"
android:scrollbars="none"
tools:text="Car" />
</net.osmand.plus.widgets.OsmandTextFieldBoxes>

View file

@ -34,6 +34,7 @@
<attr name="ctx_menu_divider" format="reference" />
<attr name="bottom_menu_view_bg" format="reference" />
<attr name="left_menu_view_bg" format="reference" />
<attr name="stroked_buttons_and_links_outline" format="color" />
<attr name="dashboard_divider" format="reference" />
<attr name="dashboard_button" format="reference" />

View file

@ -277,6 +277,7 @@
<item name="colorBackgroundFloating">@color/list_background_color_light</item>
<item name="android:colorBackgroundFloating">@color/list_background_color_light</item>
<item name="preferenceTheme">@style/OsmandPreferenceTheme</item>
<item name="stroked_buttons_and_links_outline">@color/stroked_buttons_and_links_outline_light</item>
</style>
<style name="OverflowMenuButton" parent="@style/Widget.AppCompat.ActionButton.Overflow">
@ -542,6 +543,7 @@
<item name="colorBackgroundFloating">@color/list_background_color_dark</item>
<item name="android:colorBackgroundFloating">@color/list_background_color_dark</item>
<item name="preferenceTheme">@style/OsmandPreferenceTheme</item>
<item name="stroked_buttons_and_links_outline">@color/stroked_buttons_and_links_outline_dark</item>
</style>
<style name="FreeVersionBanner" parent="OsmandDarkTheme">

View file

@ -2210,7 +2210,15 @@ public class OsmandSettings {
12/*AudioAttributes.USAGE_ASSISTANCE_NAVIGATION_GUIDANCE*/).makeProfile();
// For now this can be changed only in TestVoiceActivity
public final OsmandPreference<Integer> BT_SCO_DELAY = new IntPreference("bt_sco_delay", 1500).makeGlobal().cache();
public final OsmandPreference<Integer>[] VOICE_PROMPT_DELAY = new IntPreference[10];
{
// 1500 ms delay works for most configurations to establish a BT SCO link
VOICE_PROMPT_DELAY[0] = new IntPreference("voice_prompt_delay_0", 1500).makeGlobal().cache(); /*AudioManager.STREAM_VOICE_CALL*/
// On most devices sound output works pomptly so usually no voice prompt delay needed
VOICE_PROMPT_DELAY[3] = new IntPreference("voice_prompt_delay_3", 0).makeGlobal().cache(); /*AudioManager.STREAM_MUSIC*/
VOICE_PROMPT_DELAY[5] = new IntPreference("voice_prompt_delay_5", 0).makeGlobal().cache(); /*AudioManager.STREAM_NOTIFICATION*/
}
// this value string is synchronized with settings_pref.xml preference name
public final CommonPreference<Boolean> MAP_ONLINE_DATA = new BooleanPreference("map_online_data", false).makeProfile();

View file

@ -19,6 +19,7 @@ import android.widget.Toast;
import androidx.appcompat.app.AlertDialog;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.activities.OsmandActionBarActivity;
import net.osmand.plus.routing.data.StreetName;
@ -125,14 +126,15 @@ public class TestVoiceActivity extends OsmandActionBarActivity {
String v ="";
v += " \u25CF App profile: " + ((OsmandApplication) getApplication()).getSettings().APPLICATION_MODE.get().getStringKey();
if (((OsmandApplication) getApplication()).getSettings().AUDIO_MANAGER_STREAM.get() == 3) {
int stream = ((OsmandApplication) getApplication()).getSettings().AUDIO_MANAGER_STREAM.get();
if (stream == 3) {
v += "\n \u25CF Voice guidance output: Media/music audio";
} else if (((OsmandApplication) getApplication()).getSettings().AUDIO_MANAGER_STREAM.get() == 5) {
} else if (stream == 5) {
v += "\n \u25CF Voice guidance output: Notification audio";
} else if (((OsmandApplication) getApplication()).getSettings().AUDIO_MANAGER_STREAM.get() == 0) {
} else if (stream == 0) {
v += "\n \u25CF Voice guidance output: Phone call audio";
} else {
v += "\n \u25CF Voice guidance output: " + ((OsmandApplication) getApplication()).getSettings().AUDIO_MANAGER_STREAM.get();
v += "\n \u25CF Voice guidance output: " + stream;
}
v += "\n \u25CF OsmAnd voice: " + osmandVoice;
@ -141,13 +143,16 @@ public class TestVoiceActivity extends OsmandActionBarActivity {
v += "\n \u25CF TTS voice language availability: " + TTSCommandPlayerImpl.getTtsVoiceStatus();
v += "\n \u25CF TTS voice actually used: " + TTSCommandPlayerImpl.getTtsVoiceUsed();
if (((OsmandApplication) getApplication()).getSettings().AUDIO_MANAGER_STREAM.get() == 0) {
if (stream == 0) {
v += "\n \u25CF BT SCO: " + AbstractPrologCommandPlayer.btScoInit;
} else {
v += "\n \u25CF BT SCO: The current app profile is not set to use 'Phone call audio'.";
}
v += "\n \u25CF Phone call audio delay: " + ((OsmandApplication) getApplication()).getSettings().BT_SCO_DELAY.get() + "\u00A0ms";
OsmandSettings.OsmandPreference<Integer> pref = ((OsmandApplication) getApplication()).getSettings().VOICE_PROMPT_DELAY[stream];
if(pref != null) {
v += "\n \u25CF Voice prompt delay for selected output: " + pref.get() + "\u00A0ms";
}
return v;
}
@ -230,7 +235,7 @@ public class TestVoiceActivity extends OsmandActionBarActivity {
addButton(ll, "Voice system info:", builder(p));
addButton(ll, "\u25BA (11.1) (Tap to refresh)\n" + getVoiceSystemInfo(), builder(p).attention(""));
addButton(ll, "\u25BA (11.2) Tap to change Phone call audio delay (if car stereo cuts off prompts). Default is 1500\u00A0ms.", builder(p).attention(""));
addButton(ll, "\u25BA (11.2) Tap to change voice prompt delay (if car stereo cuts off prompts). Default is 1500\u00A0ms for Phone call audio, or else 0\u00A0ms.", builder(p).attention(""));
ll.forceLayout();
}
@ -282,23 +287,18 @@ public class TestVoiceActivity extends OsmandActionBarActivity {
Toast.makeText(TestVoiceActivity.this, "Info refreshed.", Toast.LENGTH_LONG).show();
}
if (description.startsWith("\u25BA (11.2)")) {
if (((OsmandApplication) getApplication()).getSettings().AUDIO_MANAGER_STREAM.get() == 0) {
if (((OsmandApplication) getApplication()).getSettings().BT_SCO_DELAY.get() == 1000) {
((OsmandApplication) getApplication()).getSettings().BT_SCO_DELAY.set(1500);
} else if (((OsmandApplication) getApplication()).getSettings().BT_SCO_DELAY.get() == 1500) {
((OsmandApplication) getApplication()).getSettings().BT_SCO_DELAY.set(2000);
} else if (((OsmandApplication) getApplication()).getSettings().BT_SCO_DELAY.get() == 2000) {
((OsmandApplication) getApplication()).getSettings().BT_SCO_DELAY.set(2500);
} else if (((OsmandApplication) getApplication()).getSettings().BT_SCO_DELAY.get() == 2500) {
((OsmandApplication) getApplication()).getSettings().BT_SCO_DELAY.set(3000);
int ams = ((OsmandApplication) getApplication()).getSettings().AUDIO_MANAGER_STREAM.get();
OsmandSettings.OsmandPreference<Integer> pref = ((OsmandApplication) getApplication()).getSettings().VOICE_PROMPT_DELAY[ams];
if (pref != null) {
if (pref.get() >= 3000) {
pref.set(0);
} else {
((OsmandApplication) getApplication()).getSettings().BT_SCO_DELAY.set(1000);
pref.set(pref.get() + 500);
}
Toast.makeText(TestVoiceActivity.this, "Voice prompt delay changed to " + pref.get() + "\u00A0ms.", Toast.LENGTH_LONG).show();
}
infoButton.setText("\u25BA (11.1) (Tap to refresh)\n" + getVoiceSystemInfo());
Toast.makeText(TestVoiceActivity.this, "BT SCO init delay changed to " + ((OsmandApplication) getApplication()).getSettings().BT_SCO_DELAY.get() + "\u00A0ms.", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(TestVoiceActivity.this, "Setting only available when using 'Phone call audio'.", Toast.LENGTH_LONG).show();
}
}
}
});

View file

@ -192,7 +192,7 @@ public class VoiceRouter {
}
}
private double btScoDelayDistance = 0;
private double voicePromptDelayDistance = 0;
public boolean isDistanceLess(float currentSpeed, double dist, double etalon, float defSpeed) {
if (defSpeed <= 0) {
@ -202,12 +202,15 @@ public class VoiceRouter {
currentSpeed = DEFAULT_SPEED;
}
// Trigger close prompts earlier if delayed for BT SCO connection establishment
if ((settings.AUDIO_MANAGER_STREAM.getModeValue(router.getAppMode()) == 0) && !AbstractPrologCommandPlayer.btScoStatus) {
btScoDelayDistance = currentSpeed * (double) settings.BT_SCO_DELAY.get() / 1000;
// Trigger close prompts earlier to allow BT SCO link being established, or when VOICE_PROMPT_DELAY is set >0 for the other stream types
int ams = settings.AUDIO_MANAGER_STREAM.getModeValue(router.getAppMode());
if ((ams == 0 && !AbstractPrologCommandPlayer.btScoStatus) || ams > 0) {
if (settings.VOICE_PROMPT_DELAY[ams] != null) {
voicePromptDelayDistance = currentSpeed * (double) settings.VOICE_PROMPT_DELAY[ams].get() / 1000;
}
}
if ((dist < etalon + btScoDelayDistance) || ((dist - btScoDelayDistance) / currentSpeed) < (etalon / defSpeed)) {
if ((dist < etalon + voicePromptDelayDistance) || ((dist - voicePromptDelayDistance) / currentSpeed) < (etalon / defSpeed)) {
return true;
}
return false;
@ -520,9 +523,9 @@ public class VoiceRouter {
if (repeat || dist >= TURN_IN_DISTANCE_END) {
if ((isDistanceLess(speed, nextNextInfo.distanceTo, TURN_DISTANCE, 0f) || nextNextInfo.distanceTo < TURN_IN_DISTANCE_END) &&
nextNextInfo != null) {
playMakeTurnIn(currentSegment, next, dist - (int) btScoDelayDistance, nextNextInfo.directionInfo);
playMakeTurnIn(currentSegment, next, dist - (int) voicePromptDelayDistance, nextNextInfo.directionInfo);
} else {
playMakeTurnIn(currentSegment, next, dist - (int) btScoDelayDistance, null);
playMakeTurnIn(currentSegment, next, dist - (int) voicePromptDelayDistance, null);
}
playGoAndArriveAtDestination(repeat, nextInfo, currentSegment);
}

View file

@ -55,6 +55,7 @@ class ExportImportSettingsAdapter extends OsmandBaseExpandableListAdapter {
private boolean nightMode;
private boolean importState;
private int activeColorRes;
private int secondaryColorRes;
ExportImportSettingsAdapter(OsmandApplication app, boolean nightMode, boolean importState) {
this.app = app;
@ -68,6 +69,9 @@ class ExportImportSettingsAdapter extends OsmandBaseExpandableListAdapter {
activeColorRes = nightMode
? R.color.icon_color_active_dark
: R.color.icon_color_active_light;
secondaryColorRes = nightMode
? R.color.icon_color_secondary_dark
: R.color.icon_color_secondary_light;
}
@Override
@ -94,7 +98,6 @@ class ExportImportSettingsAdapter extends OsmandBaseExpandableListAdapter {
lineDivider.setVisibility(importState || isExpanded || isLastGroup ? View.GONE : View.VISIBLE);
cardTopDivider.setVisibility(importState ? View.VISIBLE : View.GONE);
cardBottomDivider.setVisibility(importState && !isExpanded ? View.VISIBLE : View.GONE);
CompoundButtonCompat.setButtonTintList(checkBox, ColorStateList.valueOf(ContextCompat.getColor(app, activeColorRes)));
final List<?> listItems = itemsMap.get(type);
subTextTv.setText(getSelectedItemsAmount(listItems));
@ -111,6 +114,8 @@ class ExportImportSettingsAdapter extends OsmandBaseExpandableListAdapter {
}
checkBox.setState(contains ? MISC : UNCHECKED);
}
int checkBoxColor = checkBox.getState() == UNCHECKED ? secondaryColorRes : activeColorRes;
CompoundButtonCompat.setButtonTintList(checkBox, ColorStateList.valueOf(ContextCompat.getColor(app, checkBoxColor)));
checkBoxContainer.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
@ -153,7 +158,8 @@ class ExportImportSettingsAdapter extends OsmandBaseExpandableListAdapter {
lineDivider.setVisibility(!importState && isLastChild && !isLastGroup ? View.VISIBLE : View.GONE);
cardBottomDivider.setVisibility(importState && isLastChild ? View.VISIBLE : View.GONE);
CompoundButtonCompat.setButtonTintList(checkBox, ColorStateList.valueOf(ContextCompat.getColor(app, activeColorRes)));
int checkBoxColor = itemSelected ? activeColorRes : secondaryColorRes;
CompoundButtonCompat.setButtonTintList(checkBox, ColorStateList.valueOf(ContextCompat.getColor(app, checkBoxColor)));
checkBox.setChecked(itemSelected);
checkBox.setClickable(false);

View file

@ -60,7 +60,6 @@ public class ImportedSettingsItemsAdapter extends
? R.color.active_color_primary_dark
: R.color.active_color_primary_light;
holder.icon.setPadding(0, 0, AndroidUtils.dpToPx(app, 16), 0);
holder.title.setTextColor(app.getResources().getColor(activeColorRes));
Typeface typeface = FontCache.getFont(app, app.getString(R.string.font_roboto_medium));
if (typeface != null) {

View file

@ -352,9 +352,13 @@ public class SRTMPlugin extends OsmandPlugin {
.setListener(listener).createItem());
}
boolean terrainEnabled = settings.TERRAIN.get();
TerrainMode terrainMode = settings.TERRAIN_MODE.get();
adapter.addItem(new ContextMenuItem.ItemBuilder()
.setId(TERRAIN)
.setTitleId(R.string.shared_string_terrain, mapActivity)
.setDescription(app.getString(terrainMode == TerrainMode.HILLSHADE
? R.string.shared_string_hillshade
: R.string.shared_string_slope))
.setSelected(terrainEnabled)
.setColor(terrainEnabled ? R.color.osmand_orange : ContextMenuItem.INVALID_ID)
.setIcon(R.drawable.ic_action_hillshade_dark)

View file

@ -225,8 +225,8 @@ public class TerrainFragment extends BaseOsmAndFragment implements View.OnClickL
public void onStopTrackingTouch(@NonNull Slider slider) {
switch (slider.getId()) {
case R.id.transparency_slider:
double d = (100 - slider.getValue()) * 2.55;
srtmPlugin.setTerrainTransparency((int) d, srtmPlugin.getTerrainMode());
double d = slider.getValue() * 2.55;
srtmPlugin.setTerrainTransparency((int) Math.ceil(d), srtmPlugin.getTerrainMode());
break;
case R.id.zoom_slider:
List<Float> values = slider.getValues();
@ -260,7 +260,7 @@ public class TerrainFragment extends BaseOsmAndFragment implements View.OnClickL
private void updateUiMode() {
TerrainMode mode = srtmPlugin.getTerrainMode();
if (terrainEnabled) {
int transparencyValue = (int) (100 - srtmPlugin.getTerrainTransparency() / 2.55);
int transparencyValue = (int) (srtmPlugin.getTerrainTransparency() / 2.55);
String transparency = transparencyValue + "%";
int minZoom = Math.max(srtmPlugin.getTerrainMinZoom(), TERRAIN_MIN_ZOOM);
int maxZoom = Math.min(srtmPlugin.getTerrainMaxZoom(), TERRAIN_MAX_ZOOM);

View file

@ -322,9 +322,6 @@ public abstract class AbstractPrologCommandPlayer implements CommandPlayer, Stat
public static boolean btScoStatus = false;
// BT_SCO_DELAY now in Settings. 1500 ms works for most configurations.
//public static final int BT_SCO_DELAY = 1500;
// This only needed for init debugging in TestVoiceActivity:
public static String btScoInit = "-";

View file

@ -55,15 +55,17 @@ public class JSMediaCommandPlayerImpl extends MediaCommandPlayerImpl {
// If we have not already started to play audio, start.
if (mediaPlayer == null) {
requestAudioFocus();
// Delay first prompt of each batch to allow BT SCO connection being established
if (ctx != null && ctx.getSettings().AUDIO_MANAGER_STREAM.getModeValue(getApplicationMode()) == 0) {
// Delay first prompt of each batch to allow BT SCO link being established, or when VOICE_PROMPT_DELAY is set >0 for the other stream types
if (ctx != null) {
int vpd = ctx.getSettings().VOICE_PROMPT_DELAY[ctx.getSettings().AUDIO_MANAGER_STREAM.getModeValue(getApplicationMode())].get();
if (vpd > 0) {
try {
log.debug("Delaying MediaCommandPlayer for BT SCO");
Thread.sleep(ctx.getSettings().BT_SCO_DELAY.get());
Thread.sleep(vpd);
} catch (InterruptedException e) {
}
}
}
}
playQueue();
return lst;
}

View file

@ -8,6 +8,7 @@ import android.os.Build;
import net.osmand.PlatformUtil;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.routing.VoiceRouter;
import org.apache.commons.logging.Log;
@ -87,15 +88,18 @@ public class MediaCommandPlayerImpl extends AbstractPrologCommandPlayer implemen
// If we have not already started to play audio, start.
if (mediaPlayer == null) {
requestAudioFocus();
// Delay first prompt of each batch to allow BT SCO connection being established
if (ctx != null && ctx.getSettings().AUDIO_MANAGER_STREAM.getModeValue(getApplicationMode()) == 0) {
// Delay first prompt of each batch to allow BT SCO link being established, or when VOICE_PROMPT_DELAY is set >0 for the other stream types
if (ctx != null) {
Integer stream = ctx.getSettings().AUDIO_MANAGER_STREAM.getModeValue(getApplicationMode());
OsmandSettings.OsmandPreference<Integer> pref = ctx.getSettings().VOICE_PROMPT_DELAY[stream];
if (pref.getModeValue(getApplicationMode()) > 0) {
try {
log.debug("Delaying MediaCommandPlayer for BT SCO");
Thread.sleep(ctx.getSettings().BT_SCO_DELAY.get());
Thread.sleep(pref.getModeValue(getApplicationMode()));
} catch (InterruptedException e) {
}
}
}
}
playQueue();
return lst;
}

View file

@ -17,6 +17,7 @@ import androidx.appcompat.app.AlertDialog;
import net.osmand.PlatformUtil;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.activities.SettingsActivity;
import net.osmand.plus.routing.VoiceRouter;
@ -123,14 +124,19 @@ public class TTSCommandPlayerImpl extends AbstractPrologCommandPlayer {
.setContentType(AudioAttributes.CONTENT_TYPE_SPEECH)
.build());
}
// Delay first prompt of each batch to allow BT SCO connection being established
if (ctx.getSettings().AUDIO_MANAGER_STREAM.getModeValue(getApplicationMode()) == 0) {
// Delay first prompt of each batch to allow BT SCO link being established, or when VOICE_PROMPT_DELAY is set >0 for the other stream types
if (ctx != null) {
Integer streamModeValue = ctx.getSettings().AUDIO_MANAGER_STREAM.getModeValue(getApplicationMode());
OsmandSettings.OsmandPreference<Integer> pref = ctx.getSettings().VOICE_PROMPT_DELAY[streamModeValue];
int vpd = pref == null ? 0 : pref.getModeValue(getApplicationMode());
if (vpd > 0) {
ttsRequests++;
if (android.os.Build.VERSION.SDK_INT < 21) {
params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID,""+System.currentTimeMillis());
mTts.playSilence(ctx.getSettings().BT_SCO_DELAY.get(), TextToSpeech.QUEUE_ADD, params);
params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, "" + System.currentTimeMillis());
mTts.playSilence(vpd, TextToSpeech.QUEUE_ADD, params);
} else {
mTts.playSilentUtterance(ctx.getSettings().BT_SCO_DELAY.get(), TextToSpeech.QUEUE_ADD, ""+System.currentTimeMillis());
mTts.playSilentUtterance(vpd, TextToSpeech.QUEUE_ADD, "" + System.currentTimeMillis());
}
}
}
}