Skip to content

Commit

Permalink
Merge branch 'osmandapp:master' into hardy_Afa
Browse files Browse the repository at this point in the history
  • Loading branch information
sonora authored Dec 9, 2024
2 parents f091e16 + bf6727b commit d078b4d
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 23 deletions.
5 changes: 2 additions & 3 deletions OsmAnd/res/layout/navigation_widget_small.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
android:layout_height="@dimen/simple_widget_small_height"
android:orientation="vertical"
android:paddingStart="9dp"
android:paddingTop="6dp"
android:paddingEnd="16dp"
android:paddingBottom="3dp">
android:paddingVertical="6dp"
android:paddingEnd="16dp">

<LinearLayout
android:id="@+id/container"
Expand Down
2 changes: 2 additions & 0 deletions OsmAnd/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
- For wording and consistency, please note https://docs.osmand.net/docs/technical/contributions/translating-osmand
Thx - Hardy
-->

<string name="selected_delayed_profile">Selected profile \"%s\"</string>
<string name="shared_string_interpolation">Interpolation</string>
<string name="location_interpolation_percent">Location interpolation percentage</string>
<string name="location_interpolation_percent_desc">Set the percentage of location interpolation during route navigation. This parameter reduces the lag of your location position on the map during animation.</string>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package net.osmand.plus.quickaction.actions;

import static net.osmand.plus.OsmAndConstants.UI_HANDLER_MAP_CONTROLS;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.StringRes;
Expand All @@ -12,9 +15,11 @@
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.quickaction.QuickAction;
import net.osmand.plus.quickaction.QuickActionType;
import net.osmand.plus.settings.backend.ApplicationMode;
import net.osmand.plus.settings.backend.OsmandSettings;

public abstract class BaseSwitchAppModeAction extends QuickAction {
private static final long CHANGE_PROFILE_DELAY = 3500;

public BaseSwitchAppModeAction(QuickActionType type) {
super(type);
Expand All @@ -29,16 +34,48 @@ public BaseSwitchAppModeAction(QuickAction quickAction) {
@StringRes
public abstract int getQuickActionDescription();

@Override
public void execute(@NonNull MapActivity mapActivity) {
private static ApplicationMode delayedSwitchProfile;
private static Toast delayedSwitchProfileToast;

public void delayedSwitchAppMode(@NonNull MapActivity mapActivity) {
OsmandSettings settings = mapActivity.getMyApplication().getSettings();
if (shouldChangeForward()) {
settings.switchAppModeToNext();
} else {
settings.switchAppModeToPrevious();
ApplicationMode appMode = settings.getApplicationMode();
boolean next = shouldChangeForward();

if (delayedSwitchProfile == null) {
delayedSwitchProfile = appMode;
}
delayedSwitchProfile = settings.getSwitchedAppMode(delayedSwitchProfile, next);
cancelDelayedToast();

String patternDelayedSwitch = mapActivity.getString(R.string.selected_delayed_profile);
String messageDelayedSwitch = String.format(patternDelayedSwitch, delayedSwitchProfile.toHumanString());
delayedSwitchProfileToast = Toast.makeText(mapActivity, messageDelayedSwitch, Toast.LENGTH_SHORT);
delayedSwitchProfileToast.show();

mapActivity.getMyApplication().runMessageInUIThreadAndCancelPrevious(UI_HANDLER_MAP_CONTROLS + 1, () -> {
if (delayedSwitchProfile != null && appMode != delayedSwitchProfile && settings.setApplicationMode(delayedSwitchProfile)) {
cancelDelayedToast();
String pattern = mapActivity.getString(R.string.application_profile_changed);
String message = String.format(pattern, delayedSwitchProfile.toHumanString());
mapActivity.getMyApplication().showShortToastMessage(message);
}
delayedSwitchProfileToast = null;
delayedSwitchProfile = null;
}, CHANGE_PROFILE_DELAY);
}

private void cancelDelayedToast(){
if (delayedSwitchProfileToast != null) {
delayedSwitchProfileToast.cancel();
}
}

@Override
public void execute(@NonNull MapActivity mapActivity) {
delayedSwitchAppMode(mapActivity);
}

@Override
public void drawUI(@NonNull ViewGroup parent, @NonNull MapActivity mapActivity) {
View view = LayoutInflater.from(parent.getContext())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import net.osmand.plus.routing.RoutingHelper;
import net.osmand.plus.settings.backend.ApplicationMode;
import net.osmand.plus.track.fragments.TrackSelectSegmentBottomSheet.OnSegmentSelectedListener;
import net.osmand.plus.track.helpers.GpxNavigationHelper;
import net.osmand.plus.utils.AndroidUtils;
import net.osmand.plus.utils.ColorUtilities;
import net.osmand.plus.widgets.TextViewExProgress;
Expand Down
22 changes: 13 additions & 9 deletions OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -446,15 +446,7 @@ public boolean switchAppModeToPrevious() {

public boolean switchAppMode(boolean next) {
ApplicationMode appMode = getApplicationMode();
List<ApplicationMode> enabledModes = ApplicationMode.values(ctx);
int indexOfCurrent = enabledModes.indexOf(appMode);
int indexOfNext;
if (next) {
indexOfNext = indexOfCurrent < enabledModes.size() - 1 ? indexOfCurrent + 1 : 0;
} else {
indexOfNext = indexOfCurrent > 0 ? indexOfCurrent - 1 : enabledModes.size() - 1;
}
ApplicationMode nextAppMode = enabledModes.get(indexOfNext);
ApplicationMode nextAppMode = getSwitchedAppMode(appMode, next);
if (appMode != nextAppMode && setApplicationMode(nextAppMode)) {
String pattern = ctx.getString(R.string.application_profile_changed);
String message = String.format(pattern, nextAppMode.toHumanString());
Expand All @@ -464,6 +456,18 @@ public boolean switchAppMode(boolean next) {
return false;
}

public ApplicationMode getSwitchedAppMode(ApplicationMode selectedMode, boolean next) {
List<ApplicationMode> enabledModes = ApplicationMode.values(ctx);
int indexOfCurrent = enabledModes.indexOf(selectedMode);
int indexOfNext;
if (next) {
indexOfNext = indexOfCurrent < enabledModes.size() - 1 ? indexOfCurrent + 1 : 0;
} else {
indexOfNext = indexOfCurrent > 0 ? indexOfCurrent - 1 : enabledModes.size() - 1;
}
return enabledModes.get(indexOfNext);
}

public boolean setApplicationMode(ApplicationMode appMode) {
return setApplicationMode(appMode, true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@
import net.osmand.plus.track.helpers.GpxDisplayGroup;
import net.osmand.plus.track.helpers.GpxDisplayItem;
import net.osmand.plus.track.helpers.GpxFileLoaderTask;
import net.osmand.plus.track.helpers.GpxNavigationHelper;
import net.osmand.plus.track.helpers.GpxSelectionHelper;
import net.osmand.plus.track.helpers.GpxSelectionHelper.GpxDisplayItemType;
import net.osmand.plus.track.helpers.GpxUiHelper;
Expand Down
13 changes: 10 additions & 3 deletions OsmAnd/src/net/osmand/plus/views/mapwidgets/TurnDrawable.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public class TurnDrawable extends Drawable {
protected Paint paintRouteDirection;
protected Path pathForTurn = new Path();
protected Path pathForTurnOutlay = new Path();
private final Path originalPathForTurn = new Path();
private final Path originalPathForTurnOutlay = new Path();
protected TurnType turnType;
protected int turnImminent;
protected boolean deviatedFromRoute;
Expand Down Expand Up @@ -63,10 +65,15 @@ protected void onBoundsChange(Rect bounds) {
float scaleX = bounds.width() / 72f;
float scaleY = bounds.height() / 72f;
m.setScale(scaleX, scaleY);
pathForTurn.transform(m, pathForTurn);

pathForTurn.set(originalPathForTurn);
pathForTurn.transform(m);

pathForTurnOutlay.set(originalPathForTurnOutlay);
pathForTurnOutlay.transform(m);

centerText.x = scaleX * centerText.x;
centerText.y = scaleY * centerText.y;
pathForTurnOutlay.transform(m, pathForTurnOutlay);
}

public int getTurnImminent() {
Expand Down Expand Up @@ -136,7 +143,7 @@ public TurnType getTurnType() {
public boolean setTurnType(@Nullable TurnType turnType) {
if (turnType != this.turnType && !getBounds().isEmpty()) {
this.turnType = turnType;
TurnPathHelper.calcTurnPath(pathForTurn, pathForTurnOutlay, turnType, null,
TurnPathHelper.calcTurnPath(originalPathForTurn, originalPathForTurnOutlay, turnType, null,
centerText, mini, false, true, false);
onBoundsChange(getBounds());
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static net.osmand.plus.views.mapwidgets.widgets.StreetNameWidget.setShieldImage;
import static java.lang.Math.min;

import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.text.TextPaint;
import android.view.Gravity;
Expand Down Expand Up @@ -354,6 +355,8 @@ public void updateColors(@NonNull TextState textState) {
}

protected void updateVerticalWidgetColors(@NonNull TextState textState) {
int typefaceStyle = textState.textBold ? Typeface.BOLD : Typeface.NORMAL;

nightMode = textState.night;
int exitRefTextColorId = isNightMode()
? R.color.text_color_primary_dark
Expand All @@ -363,6 +366,9 @@ protected void updateVerticalWidgetColors(@NonNull TextState textState) {
distanceView.setTextColor(ContextCompat.getColor(app, exitRefTextColorId));
distanceSubView.setTextColor(ColorUtilities.getSecondaryTextColor(mapActivity, nightMode));
streetView.setTextColor(ColorUtilities.getSecondaryTextColor(mapActivity, nightMode));
distanceView.setTypeface(Typeface.DEFAULT, typefaceStyle);
distanceSubView.setTypeface(Typeface.DEFAULT, typefaceStyle);
streetView.setTypeface(Typeface.DEFAULT, typefaceStyle);

bg.setBackgroundResource(textState.widgetBackgroundId);
}
Expand Down

0 comments on commit d078b4d

Please sign in to comment.