Merge branch 'master' into OnlineRoutingBackend

# Conflicts:
#	OsmAnd/res/values/strings.xml
This commit is contained in:
nazar-kutz 2021-01-18 11:33:51 +02:00
commit 1e946c6d51
7 changed files with 465 additions and 21 deletions

View file

@ -0,0 +1,74 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:minHeight="@dimen/bottom_sheet_selected_item_title_height"
android:baselineAligned="false">
<LinearLayout
android:id="@+id/basic_item_body"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="?attr/selectableItemBackground">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
android:textAppearance="@style/TextAppearance.ListItemTitle"
tools:text="Some title" />
</LinearLayout>
<com.google.android.material.switchmaterial.SwitchMaterial
android:id="@+id/switch_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginStart="@dimen/bottom_sheet_content_margin"
android:layout_marginLeft="@dimen/bottom_sheet_content_margin"
android:layout_marginEnd="@dimen/content_padding_half"
android:layout_marginRight="@dimen/content_padding_half"
tools:checked="true" />
</LinearLayout>
<LinearLayout
android:id="@+id/additional_button"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal">
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:layout_marginTop="@dimen/content_padding_half"
android:layout_marginBottom="@dimen/content_padding_half"
android:background="?attr/divider_color_basic" />
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/icon_after_divider"
style="@style/Widget.AppCompat.Toolbar.Button.Navigation"
android:layout_width="@dimen/acceptable_touch_radius"
android:layout_height="@dimen/acceptable_touch_radius"
android:layout_gravity="center"
android:layout_marginLeft="@dimen/content_padding"
android:layout_marginRight="@dimen/content_padding"
app:srcCompat="@drawable/ic_action_track_line_bold_color" />
</LinearLayout>
</LinearLayout>

View file

@ -0,0 +1,91 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:osmand="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingStart="@dimen/content_padding"
android:paddingLeft="@dimen/content_padding"
android:paddingTop="@dimen/bottom_sheet_content_margin"
android:paddingEnd="@dimen/content_padding"
android:paddingRight="@dimen/content_padding">
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/content_padding"
android:letterSpacing="@dimen/text_button_letter_spacing"
android:text="@string/monitoring_settings"
android:textSize="@dimen/default_list_text_size"
osmand:typeface="@string/font_roboto_medium" />
<include
android:id="@+id/show_track_on_map"
layout="@layout/bottom_sheet_with_switch_divider_and_additional_button" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginBottom="@dimen/bottom_sheet_content_margin_small"
android:background="?attr/dashboard_divider" />
<View
android:layout_width="match_parent"
android:layout_height="@dimen/content_padding_small" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:orientation="horizontal">
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/interval_value"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ellipsize="end"
android:maxLines="1"
android:textSize="@dimen/default_list_text_size"
tools:text="Interval value" />
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/up_down_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@null"
app:srcCompat="@drawable/ic_action_arrow_down" />
</LinearLayout>
<com.google.android.material.slider.RangeSlider
android:id="@+id/interval_slider"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/save_track_interval_globally"
android:stepSize="1"
app:labelBehavior="gone" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/confirm_every_run"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="@dimen/content_padding"
android:letterSpacing="@dimen/text_button_letter_spacing"
android:minHeight="@dimen/context_menu_buttons_bottom_height"
android:paddingLeft="@dimen/content_padding_small"
android:paddingRight="@dimen/content_padding_small"
android:text="@string/confirm_every_run"
android:textColor="?android:textColorPrimary"
android:textSize="@dimen/default_list_text_size"
android:visibility="gone"
osmand:typeface="@string/font_roboto_regular"
tools:visibility="visible" />
</LinearLayout>

View file

@ -12,6 +12,8 @@
-->
<string name="show_track_on_map">Show track on map</string>
<string name="start_recording">Start recording</string>
<string name="message_name_is_already_exists">The name is already exists</string>
<string name="message_server_error">Server error: %1$s</string>
<string name="routing_engine_vehicle_type_mtb">MTB</string>

View file

@ -118,6 +118,7 @@ import net.osmand.plus.measurementtool.LoginBottomSheetFragment;
import net.osmand.plus.measurementtool.MeasurementEditingContext;
import net.osmand.plus.measurementtool.MeasurementToolFragment;
import net.osmand.plus.measurementtool.SnapTrackWarningFragment;
import net.osmand.plus.monitoring.TripRecordingBottomSheet;
import net.osmand.plus.render.RendererRegistry;
import net.osmand.plus.resources.ResourceManager;
import net.osmand.plus.routepreparationmenu.ChooseRouteFragment;
@ -2205,6 +2206,10 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
return getFragment(MeasurementToolFragment.TAG);
}
public TripRecordingBottomSheet getTripRecordingBottomSheet() {
return getFragment(TripRecordingBottomSheet.TAG);
}
public ChooseRouteFragment getChooseRouteFragment() {
return getFragment(ChooseRouteFragment.TAG);
}
@ -2221,7 +2226,6 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
return getFragment(SnapTrackWarningFragment.TAG);
}
@NonNull
public TrackMenuFragment getTrackMenuFragment() {
return getFragment(TrackMenuFragment.TAG);
}

View file

@ -505,15 +505,9 @@ public class OsmandMonitoringPlugin extends OsmandPlugin {
};
if (choice.value || map == null) {
runnable.run();
} else {
showIntervalChooseDialog(map, app.getString(R.string.save_track_interval_globally) + " : %s",
app.getString(R.string.save_track_to_gpx_globally), SECONDS, MINUTES, choice, vs, showTrackSelection,
new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
runnable.run();
}
});
} else if (map instanceof FragmentActivity) {
FragmentActivity activity = (FragmentActivity) map;
TripRecordingBottomSheet.showInstance(activity.getSupportFragmentManager());
}
}

View file

@ -0,0 +1,273 @@
package net.osmand.plus.monitoring;
import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.text.SpannableString;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.SwitchCompat;
import androidx.fragment.app.FragmentManager;
import com.google.android.material.slider.RangeSlider;
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
import net.osmand.plus.NavigationService;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.UiUtilities.DialogButtonType;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithDescription;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerSpaceItem;
import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.helpers.FontCache;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.track.TrackAppearanceFragment;
import static net.osmand.plus.UiUtilities.CompoundButtonType.PROFILE_DEPENDENT;
import static net.osmand.plus.monitoring.OsmandMonitoringPlugin.MINUTES;
import static net.osmand.plus.monitoring.OsmandMonitoringPlugin.SECONDS;
public class TripRecordingBottomSheet extends MenuBottomSheetDialogFragment {
public static final String TAG = TripRecordingBottomSheet.class.getSimpleName();
private OsmandApplication app;
private OsmandSettings settings;
private ImageView upDownBtn;
private SwitchCompat confirmEveryRun;
private TextView intervalValueView;
private boolean infoExpanded;
@Override
public void createMenuItems(Bundle savedInstanceState) {
app = requiredMyApplication();
settings = app.getSettings();
Context context = requireContext();
LayoutInflater inflater = UiUtilities.getInflater(context, nightMode);
View itemView = inflater.inflate(R.layout.trip_recording_fragment, null, false);
items.add(new BottomSheetItemWithDescription.Builder()
.setCustomView(itemView)
.create());
int padding = getResources().getDimensionPixelSize(R.dimen.content_padding_small);
final int paddingSmall = getResources().getDimensionPixelSize(R.dimen.content_padding_small);
items.add(new DividerSpaceItem(context, padding));
LinearLayout showTrackOnMapView = itemView.findViewById(R.id.show_track_on_map);
TextView showTrackOnMapTitle = showTrackOnMapView.findViewById(R.id.title);
showTrackOnMapTitle.setText(R.string.show_track_on_map);
ImageView trackAppearanceIcon = showTrackOnMapView.findViewById(R.id.icon_after_divider);
int color = settings.CURRENT_TRACK_COLOR.get();
String width = settings.CURRENT_TRACK_WIDTH.get();
boolean showArrows = settings.CURRENT_TRACK_SHOW_ARROWS.get();
Drawable drawable = TrackAppearanceFragment.getTrackIcon(app, width, showArrows, color);
trackAppearanceIcon.setImageDrawable(drawable);
trackAppearanceIcon.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
hide();
SelectedGpxFile selectedGpxFile = app.getSavingTrackHelper().getCurrentTrack();
TrackAppearanceFragment.showInstance(mapActivity, selectedGpxFile);
}
}
});
upDownBtn = itemView.findViewById(R.id.up_down_button);
upDownBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
toggleInfoView();
}
});
final int secondsLength = SECONDS.length;
final int minutesLength = MINUTES.length;
intervalValueView = itemView.findViewById(R.id.interval_value);
updateIntervalLegend();
RangeSlider intervalSlider = itemView.findViewById(R.id.interval_slider);
intervalSlider.setValueTo(secondsLength + minutesLength - 1);
intervalSlider.addOnChangeListener(new RangeSlider.OnChangeListener() {
@Override
public void onValueChange(@NonNull RangeSlider slider, float value, boolean fromUser) {
int progress = (int) value;
if (progress == 0) {
settings.SAVE_GLOBAL_TRACK_INTERVAL.set(0);
} else if (progress < secondsLength) {
settings.SAVE_GLOBAL_TRACK_INTERVAL.set(SECONDS[progress] * 1000);
} else {
settings.SAVE_GLOBAL_TRACK_INTERVAL.set(MINUTES[progress - secondsLength] * 60 * 1000);
}
updateIntervalLegend();
}
});
for (int i = 0; i < secondsLength + minutesLength; i++) {
if (i < secondsLength) {
if (settings.SAVE_GLOBAL_TRACK_INTERVAL.get() <= SECONDS[i] * 1000) {
intervalSlider.setValues((float) i);
break;
}
} else {
if (settings.SAVE_GLOBAL_TRACK_INTERVAL.get() <= MINUTES[i - secondsLength] * 1000 * 60) {
intervalSlider.setValues((float) i);
break;
}
}
}
boolean checked = !settings.SAVE_GLOBAL_TRACK_REMEMBER.get();
confirmEveryRun = itemView.findViewById(R.id.confirm_every_run);
confirmEveryRun.setChecked(checked);
setBackgroundAndPadding(checked, paddingSmall);
confirmEveryRun.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
setBackgroundAndPadding(isChecked, paddingSmall);
settings.SAVE_GLOBAL_TRACK_REMEMBER.set(!isChecked);
}
});
SwitchCompat showTrackOnMapButton = showTrackOnMapView.findViewById(R.id.switch_button);
showTrackOnMapButton.setChecked(app.getSelectedGpxHelper().getSelectedCurrentRecordingTrack() != null);
showTrackOnMapButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
app.getSelectedGpxHelper().selectGpxFile(app.getSavingTrackHelper().getCurrentGpx(), isChecked, false);
}
});
UiUtilities.setupCompoundButton(showTrackOnMapButton, nightMode, PROFILE_DEPENDENT);
updateUpDownBtn();
}
private void updateIntervalLegend() {
String text = getString(R.string.save_track_interval_globally);
String textValue;
int interval = settings.SAVE_GLOBAL_TRACK_INTERVAL.get();
if (interval == 0) {
textValue = getString(R.string.int_continuosly);
} else {
int seconds = interval / 1000;
if (seconds <= SECONDS[SECONDS.length - 1]) {
textValue = seconds + " " + getString(R.string.int_seconds);
} else {
textValue = (seconds / 60) + " " + getString(R.string.int_min);
}
}
String textAll = getString(R.string.ltr_or_rtl_combine_via_colon, text, textValue);
Typeface typeface = FontCache.getRobotoMedium(app);
SpannableString spannableString = UiUtilities.createCustomFontSpannable(typeface, textAll, textValue);
intervalValueView.setText(spannableString);
}
public void show() {
Dialog dialog = getDialog();
if (dialog != null) {
dialog.show();
}
}
public void hide() {
Dialog dialog = getDialog();
if (dialog != null) {
dialog.hide();
}
}
private void setBackgroundAndPadding(boolean isChecked, int paddingSmall) {
if (nightMode) {
confirmEveryRun.setBackgroundResource(
isChecked ? R.drawable.layout_bg_dark_solid : R.drawable.layout_bg_dark);
} else {
confirmEveryRun.setBackgroundResource(
isChecked ? R.drawable.layout_bg_solid : R.drawable.layout_bg);
}
confirmEveryRun.setPadding(paddingSmall, 0, paddingSmall, 0);
}
private void updateUpDownBtn() {
int iconId = infoExpanded ? R.drawable.ic_action_arrow_down : R.drawable.ic_action_arrow_up;
upDownBtn.setImageDrawable(getContentIcon(iconId));
}
private void toggleInfoView() {
infoExpanded = !infoExpanded;
AndroidUiHelper.updateVisibility(confirmEveryRun, infoExpanded);
updateUpDownBtn();
}
@Override
protected boolean useVerticalButtons() {
return true;
}
@Override
protected int getRightBottomButtonTextId() {
return R.string.start_recording;
}
@Override
protected int getDismissButtonTextId() {
return R.string.shared_string_cancel;
}
@Override
protected DialogButtonType getRightBottomButtonType() {
return DialogButtonType.PRIMARY;
}
@Override
public int getSecondDividerHeight() {
return getResources().getDimensionPixelSize(R.dimen.bottom_sheet_icon_margin);
}
@Override
protected void onRightBottomButtonClick() {
app.getSavingTrackHelper().startNewSegment();
settings.SAVE_GLOBAL_TRACK_TO_GPX.set(true);
app.startNavigationService(NavigationService.USED_BY_GPX);
dismiss();
}
@Nullable
public MapActivity getMapActivity() {
Activity activity = getActivity();
if (activity instanceof MapActivity) {
return (MapActivity) activity;
}
return null;
}
public static void showInstance(@NonNull FragmentManager fragmentManager) {
if (!fragmentManager.isStateSaved()) {
TripRecordingBottomSheet fragment = new TripRecordingBottomSheet();
fragment.show(fragmentManager, TAG);
}
}
}

View file

@ -42,6 +42,7 @@ import net.osmand.plus.dialogs.GpxAppearanceAdapter;
import net.osmand.plus.dialogs.GpxAppearanceAdapter.AppearanceListItem;
import net.osmand.plus.dialogs.GpxAppearanceAdapter.GpxAppearanceAdapterType;
import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.monitoring.TripRecordingBottomSheet;
import net.osmand.plus.routepreparationmenu.cards.BaseCard;
import net.osmand.plus.routepreparationmenu.cards.BaseCard.CardListener;
import net.osmand.plus.settings.backend.CommonPreference;
@ -160,9 +161,14 @@ public class TrackAppearanceFragment extends ContextMenuScrollFragment implement
public void handleOnBackPressed() {
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
dismissImmediate();
TripRecordingBottomSheet fragment = mapActivity.getTripRecordingBottomSheet();
if (fragment != null) {
fragment.show();
} else {
mapActivity.launchPrevActivityIntent();
}
dismissImmediate();
}
}
});
}
@ -405,7 +411,7 @@ public class TrackAppearanceFragment extends ContextMenuScrollFragment implement
}
}
public Drawable getTrackIcon(OsmandApplication app, String widthAttr, boolean showArrows, @ColorInt int color) {
public static Drawable getTrackIcon(OsmandApplication app, String widthAttr, boolean showArrows, @ColorInt int color) {
int widthIconId = getWidthIconId(widthAttr);
Drawable widthIcon = app.getUIUtilities().getPaintedIcon(widthIconId, color);
@ -423,7 +429,7 @@ public class TrackAppearanceFragment extends ContextMenuScrollFragment implement
return UiUtilities.getLayeredIcon(transparencyIcon, widthIcon, strokeIcon);
}
private Drawable getTransparencyIcon(OsmandApplication app, String widthAttr, @ColorInt int color) {
private static Drawable getTransparencyIcon(OsmandApplication app, String widthAttr, @ColorInt int color) {
int transparencyIconId = getTransparencyIconId(widthAttr);
int colorWithoutAlpha = UiUtilities.removeAlpha(color);
int transparencyColor = UiUtilities.getColorWithAlpha(colorWithoutAlpha, 0.8f);