From c90a74956a514a6b8088a11f1fdd6b14c2eb7c4d Mon Sep 17 00:00:00 2001 From: Skalii Date: Wed, 17 Mar 2021 20:16:44 +0200 Subject: [PATCH] redesign trip recording start dialog --- ...tn_background_active_transparent_light.xml | 6 + ...btn_background_active_transparent_dark.xml | 6 + ...h_switch_divider_and_additional_button.xml | 124 ++++--- .../layout/preference_button_with_icon.xml | 47 +++ .../preference_button_with_icon_quadruple.xml | 57 ++++ .../preference_button_with_icon_triple.xml | 46 +++ ...l => trip_recording_starting_fragment.xml} | 91 +++-- OsmAnd/res/values/sizes.xml | 1 + OsmAnd/res/values/strings.xml | 1 + .../osmand/plus/activities/MapActivity.java | 7 +- .../plus/activities/MapActivityActions.java | 4 +- .../monitoring/OsmandMonitoringPlugin.java | 4 +- .../TripRecordingActiveBottomSheet.java | 113 ++++--- .../monitoring/TripRecordingBottomSheet.java | 306 ----------------- .../TripRecordingStartingBottomSheet.java | 314 ++++++++++++++++++ .../fragments/BaseSettingsFragment.java | 29 +- .../plus/track/TrackAppearanceFragment.java | 6 +- 17 files changed, 712 insertions(+), 450 deletions(-) create mode 100644 OsmAnd/res/drawable-hdpi/btn_background_active_transparent_light.xml create mode 100644 OsmAnd/res/drawable/btn_background_active_transparent_dark.xml create mode 100644 OsmAnd/res/layout/preference_button_with_icon.xml create mode 100644 OsmAnd/res/layout/preference_button_with_icon_quadruple.xml create mode 100644 OsmAnd/res/layout/preference_button_with_icon_triple.xml rename OsmAnd/res/layout/{trip_recording_fragment.xml => trip_recording_starting_fragment.xml} (57%) delete mode 100644 OsmAnd/src/net/osmand/plus/monitoring/TripRecordingBottomSheet.java create mode 100644 OsmAnd/src/net/osmand/plus/monitoring/TripRecordingStartingBottomSheet.java diff --git a/OsmAnd/res/drawable-hdpi/btn_background_active_transparent_light.xml b/OsmAnd/res/drawable-hdpi/btn_background_active_transparent_light.xml new file mode 100644 index 0000000000..add11f80f7 --- /dev/null +++ b/OsmAnd/res/drawable-hdpi/btn_background_active_transparent_light.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/OsmAnd/res/drawable/btn_background_active_transparent_dark.xml b/OsmAnd/res/drawable/btn_background_active_transparent_dark.xml new file mode 100644 index 0000000000..14ae96d07a --- /dev/null +++ b/OsmAnd/res/drawable/btn_background_active_transparent_dark.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/OsmAnd/res/layout/bottom_sheet_with_switch_divider_and_additional_button.xml b/OsmAnd/res/layout/bottom_sheet_with_switch_divider_and_additional_button.xml index 6953783885..a10a9eef42 100644 --- a/OsmAnd/res/layout/bottom_sheet_with_switch_divider_and_additional_button.xml +++ b/OsmAnd/res/layout/bottom_sheet_with_switch_divider_and_additional_button.xml @@ -4,80 +4,96 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="wrap_content" + android:layout_marginStart="@dimen/content_padding" + android:layout_marginLeft="@dimen/content_padding" + android:layout_marginEnd="@dimen/content_padding" + android:layout_marginRight="@dimen/content_padding" android:baselineAligned="false" android:gravity="center_vertical" - android:minHeight="@dimen/bottom_sheet_selected_item_title_height"> + android:minHeight="@dimen/bottom_sheet_list_item_height"> - + android:gravity="center_vertical" + app:cardBackgroundColor="?attr/switch_button_active" + app:cardCornerRadius="4dp" + app:cardElevation="0dp"> + android:layout_width="match_parent" + android:layout_height="match_parent" + android:background="?attr/selectableItemBackground" + android:orientation="horizontal"> - + + + 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/bottom_sheet_content_margin" + android:layout_marginRight="@dimen/bottom_sheet_content_margin" + android:clickable="false" + android:focusable="false" + android:focusableInTouchMode="false" + tools:checked="true" /> - + - - - + app:cardBackgroundColor="?attr/switch_button_active" + app:cardCornerRadius="4dp" + app:cardElevation="0dp"> - + android:background="?android:attr/selectableItemBackground" + android:clickable="true" + android:focusable="true" + android:gravity="center"> - + - + + + diff --git a/OsmAnd/res/layout/preference_button_with_icon.xml b/OsmAnd/res/layout/preference_button_with_icon.xml new file mode 100644 index 0000000000..1c6b6770fd --- /dev/null +++ b/OsmAnd/res/layout/preference_button_with_icon.xml @@ -0,0 +1,47 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/layout/preference_button_with_icon_quadruple.xml b/OsmAnd/res/layout/preference_button_with_icon_quadruple.xml new file mode 100644 index 0000000000..4105dbb2bc --- /dev/null +++ b/OsmAnd/res/layout/preference_button_with_icon_quadruple.xml @@ -0,0 +1,57 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/layout/preference_button_with_icon_triple.xml b/OsmAnd/res/layout/preference_button_with_icon_triple.xml new file mode 100644 index 0000000000..22d68ff090 --- /dev/null +++ b/OsmAnd/res/layout/preference_button_with_icon_triple.xml @@ -0,0 +1,46 @@ + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/layout/trip_recording_fragment.xml b/OsmAnd/res/layout/trip_recording_starting_fragment.xml similarity index 57% rename from OsmAnd/res/layout/trip_recording_fragment.xml rename to OsmAnd/res/layout/trip_recording_starting_fragment.xml index f69e4eb4c7..809cc015ac 100644 --- a/OsmAnd/res/layout/trip_recording_fragment.xml +++ b/OsmAnd/res/layout/trip_recording_starting_fragment.xml @@ -1,11 +1,11 @@ + android:orientation="vertical" + android:paddingBottom="@dimen/content_padding"> + app:typeface="@string/font_roboto_medium" /> + android:paddingRight="@dimen/content_padding" + android:paddingBottom="@dimen/bottom_sheet_content_margin"> + - + android:layout_height="wrap_content" + app:cardBackgroundColor="?attr/switch_button_active" + app:cardCornerRadius="4dp" + app:cardElevation="0dp"> + + + + + + + + + + + + + - + android:layout_height="@dimen/content_padding" /> + + - - - diff --git a/OsmAnd/res/values/sizes.xml b/OsmAnd/res/values/sizes.xml index dae06fed05..79fa32d1c3 100644 --- a/OsmAnd/res/values/sizes.xml +++ b/OsmAnd/res/values/sizes.xml @@ -418,4 +418,5 @@ 3sp 80dp + 160dp \ No newline at end of file diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 899beda35c..93cfd93231 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -11,6 +11,7 @@ Thx - Hardy --> + Logging interval set time period in which OsmAnd will ask for the current location position data. Please select another type of colorization. The track does not contain speed data. The track does not contain altitude data. diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index 7e0a07e40c..487f4d902f 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -93,7 +93,6 @@ import net.osmand.plus.importfiles.ImportHelper; import net.osmand.plus.mapcontextmenu.AdditionalActionsBottomSheetDialogFragment; import net.osmand.plus.mapcontextmenu.MapContextMenu; import net.osmand.plus.mapcontextmenu.builders.cards.dialogs.ContextMenuCardDialogFragment; -import net.osmand.plus.mapcontextmenu.editors.SelectFavoriteCategoryBottomSheet; import net.osmand.plus.mapcontextmenu.other.DestinationReachedMenu; import net.osmand.plus.mapcontextmenu.other.TrackDetailsMenu; import net.osmand.plus.mapmarkers.MapMarker; @@ -105,7 +104,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.monitoring.TripRecordingStartingBottomSheet; import net.osmand.plus.render.RendererRegistry; import net.osmand.plus.resources.ResourceManager; import net.osmand.plus.routepreparationmenu.ChooseRouteFragment; @@ -2242,8 +2241,8 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven return getFragment(MeasurementToolFragment.TAG); } - public TripRecordingBottomSheet getTripRecordingBottomSheet() { - return getFragment(TripRecordingBottomSheet.TAG); + public TripRecordingStartingBottomSheet getTripRecordingBottomSheet() { + return getFragment(TripRecordingStartingBottomSheet.TAG); } public ChooseRouteFragment getChooseRouteFragment() { diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java index c0fec48168..ff78335e74 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java @@ -63,7 +63,7 @@ import net.osmand.plus.measurementtool.MeasurementToolFragment; import net.osmand.plus.measurementtool.StartPlanRouteBottomSheet; import net.osmand.plus.monitoring.OsmandMonitoringPlugin; import net.osmand.plus.monitoring.TripRecordingActiveBottomSheet; -import net.osmand.plus.monitoring.TripRecordingBottomSheet; +import net.osmand.plus.monitoring.TripRecordingStartingBottomSheet; import net.osmand.plus.osmedit.dialogs.DismissRouteBottomSheetFragment; import net.osmand.plus.profiles.ProfileDataObject; import net.osmand.plus.profiles.ProfileDataUtils; @@ -856,7 +856,7 @@ public class MapActivityActions implements DialogProvider { if (monitoringPlugin.hasDataToSave() || monitoringPlugin.wasTrackMonitored()) { TripRecordingActiveBottomSheet.showInstance(mapActivity.getSupportFragmentManager(), monitoringPlugin.getCurrentTrack()); } else { - TripRecordingBottomSheet.showInstance(mapActivity.getSupportFragmentManager()); + TripRecordingStartingBottomSheet.showInstance(mapActivity.getSupportFragmentManager()); } return true; } diff --git a/OsmAnd/src/net/osmand/plus/monitoring/OsmandMonitoringPlugin.java b/OsmAnd/src/net/osmand/plus/monitoring/OsmandMonitoringPlugin.java index 2799ac8ded..4fa978a8d6 100644 --- a/OsmAnd/src/net/osmand/plus/monitoring/OsmandMonitoringPlugin.java +++ b/OsmAnd/src/net/osmand/plus/monitoring/OsmandMonitoringPlugin.java @@ -331,7 +331,7 @@ public class OsmandMonitoringPlugin extends OsmandPlugin { if (hasDataToSave() || wasTrackMonitored()) { TripRecordingActiveBottomSheet.showInstance(fragmentManager, getCurrentTrack()); } else { - TripRecordingBottomSheet.showInstance(fragmentManager); + TripRecordingStartingBottomSheet.showInstance(fragmentManager); } /*final boolean wasTrackMonitored = settings.SAVE_GLOBAL_TRACK_TO_GPX.get(); @@ -523,7 +523,7 @@ public class OsmandMonitoringPlugin extends OsmandPlugin { runnable.run(); } else if (map instanceof FragmentActivity) { FragmentActivity activity = (FragmentActivity) map; - TripRecordingBottomSheet.showInstance(activity.getSupportFragmentManager()); + TripRecordingStartingBottomSheet.showInstance(activity.getSupportFragmentManager()); } } diff --git a/OsmAnd/src/net/osmand/plus/monitoring/TripRecordingActiveBottomSheet.java b/OsmAnd/src/net/osmand/plus/monitoring/TripRecordingActiveBottomSheet.java index 00a9c0e8c0..27295899da 100644 --- a/OsmAnd/src/net/osmand/plus/monitoring/TripRecordingActiveBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/monitoring/TripRecordingActiveBottomSheet.java @@ -4,17 +4,16 @@ import android.app.Activity; import android.app.Dialog; import android.content.Context; import android.content.res.ColorStateList; -import android.graphics.Typeface; import android.graphics.drawable.Drawable; import android.os.AsyncTask; import android.os.Build; import android.os.Bundle; import android.os.Handler; -import android.util.TypedValue; import android.text.format.DateUtils; import android.view.Gravity; import android.view.LayoutInflater; import android.view.View; +import android.widget.CompoundButton; import android.widget.FrameLayout; import android.widget.LinearLayout; import android.widget.TextView; @@ -26,7 +25,7 @@ import androidx.annotation.Nullable; import androidx.annotation.StringRes; import androidx.appcompat.content.res.AppCompatResources; import androidx.appcompat.widget.AppCompatImageView; -import androidx.appcompat.widget.SwitchCompat; +import androidx.cardview.widget.CardView; import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.core.content.ContextCompat; import androidx.core.graphics.drawable.DrawableCompat; @@ -49,7 +48,6 @@ import net.osmand.plus.activities.SavingTrackHelper.SaveGpxResult; import net.osmand.plus.base.MenuBottomSheetDialogFragment; import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem; import net.osmand.plus.helpers.AndroidUiHelper; -import net.osmand.plus.helpers.FontCache; import net.osmand.plus.myplaces.SaveCurrentTrackTask; import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.track.GpxBlockStatisticsBuilder; @@ -66,7 +64,7 @@ import java.util.Arrays; import java.util.List; import static net.osmand.AndroidUtils.getSecondaryTextColorId; -import static net.osmand.plus.UiUtilities.CompoundButtonType.PROFILE_DEPENDENT; +import static net.osmand.plus.UiUtilities.CompoundButtonType.GLOBAL; public class TripRecordingActiveBottomSheet extends MenuBottomSheetDialogFragment { @@ -84,6 +82,7 @@ public class TripRecordingActiveBottomSheet extends MenuBottomSheetDialogFragmen private View statusContainer; private LinearLayout buttonAppearance; + private AppCompatImageView trackAppearanceIcon; private View buttonSave; private GpxBlockStatisticsBuilder blockStatisticsBuilder; @@ -141,7 +140,7 @@ public class TripRecordingActiveBottomSheet extends MenuBottomSheetDialogFragmen createItem(buttonClear, ItemType.CLEAR_DATA, hasDataToSave()); createItem(buttonOnline, ItemType.STOP_ONLINE, hasDataToSave()); - createItem(buttonSegment, ItemType.START_SEGMENT, wasTrackMonitored()); + createItem(buttonSegment, ItemType.START_NEW_SEGMENT, wasTrackMonitored()); createItem(buttonPause, wasTrackMonitored() ? ItemType.PAUSE : ItemType.RESUME, true); createItem(buttonStop, ItemType.STOP, true); @@ -163,37 +162,24 @@ public class TripRecordingActiveBottomSheet extends MenuBottomSheetDialogFragmen blockStatisticsBuilder.initStatBlocks(null, ContextCompat.getColor(app, getActiveTextColorId(nightMode)), nightMode); LinearLayout showTrackContainer = itemView.findViewById(R.id.show_track_on_map); - showTrackContainer.setMinimumHeight(app.getResources().getDimensionPixelSize(R.dimen.bottom_sheet_list_item_height)); - final LinearLayout buttonShow = showTrackContainer.findViewById(R.id.basic_item_body); + final CardView buttonShow = showTrackContainer.findViewById(R.id.compound_container); TextView showTrackTitle = buttonShow.findViewById(R.id.title); Integer showTitle = ItemType.SHOW_TRACK.getTitleId(); if (showTitle != null) { showTrackTitle.setText(showTitle); } - AndroidUtils.setPadding(buttonShow, AndroidUtils.dpToPx(app, 12f), 0, buttonShow.getPaddingRight(), 0); - showTrackTitle.setTextColor(ContextCompat.getColor(app, getActiveIconColorId(nightMode))); - showTrackTitle.setTextSize(TypedValue.COMPLEX_UNIT_PX, getResources().getDimensionPixelSize(R.dimen.default_desc_text_size)); - Typeface typeface = FontCache.getFont(app, app.getResources().getString(R.string.font_roboto_medium)); - showTrackTitle.setTypeface(typeface); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - float letterSpacing = AndroidUtils.getFloatValueFromRes(app, R.dimen.text_button_letter_spacing); - showTrackTitle.setLetterSpacing(letterSpacing); - } - final SwitchCompat showTrackOnMapButton = buttonShow.findViewById(R.id.switch_button); - showTrackOnMapButton.setChecked(app.getSelectedGpxHelper().getSelectedCurrentRecordingTrack() != null); - UiUtilities.setupCompoundButton(showTrackOnMapButton, nightMode, PROFILE_DEPENDENT); + final CompoundButton showTrackCompound = buttonShow.findViewById(R.id.compound_button); + showTrackCompound.setChecked(app.getSelectedGpxHelper().getSelectedCurrentRecordingTrack() != null); + UiUtilities.setupCompoundButton(showTrackCompound, nightMode, GLOBAL); buttonAppearance = showTrackContainer.findViewById(R.id.additional_button); - View divider = buttonAppearance.getChildAt(0); - AndroidUiHelper.setVisibility(View.GONE, divider); - int marginS = app.getResources().getDimensionPixelSize(R.dimen.context_menu_padding_margin_small); - UiUtilities.setMargins(buttonAppearance, marginS, 0, 0, 0); - updateTrackIcon(buttonAppearance); + trackAppearanceIcon = showTrackContainer.findViewById(R.id.additional_button_icon); + updateTrackIcon(app, trackAppearanceIcon); buttonAppearance.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - if (showTrackOnMapButton.isChecked()) { + if (showTrackCompound.isChecked()) { MapActivity mapActivity = getMapActivity(); if (mapActivity != null) { hide(); @@ -203,19 +189,19 @@ public class TripRecordingActiveBottomSheet extends MenuBottomSheetDialogFragmen } } }); - createItem(buttonAppearance, ItemType.APPEARANCE, showTrackOnMapButton.isChecked()); - setShowOnMapBackground(buttonShow, app, showTrackOnMapButton.isChecked(), nightMode); + createItem(buttonAppearance, ItemType.APPEARANCE, showTrackCompound.isChecked()); + setShowOnMapBackground(buttonShow, showTrackCompound.isChecked(), nightMode); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { buttonShow.setBackgroundTintList(null); } buttonShow.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - boolean checked = !showTrackOnMapButton.isChecked(); - showTrackOnMapButton.setChecked(checked); + boolean checked = !showTrackCompound.isChecked(); + showTrackCompound.setChecked(checked); app.getSelectedGpxHelper().selectGpxFile(app.getSavingTrackHelper().getCurrentGpx(), checked, false); createItem(buttonAppearance, ItemType.APPEARANCE, checked); - setShowOnMapBackground(buttonShow, app, checked, nightMode); + setShowOnMapBackground(buttonShow, checked, nightMode); } }); @@ -277,7 +263,7 @@ public class TripRecordingActiveBottomSheet extends MenuBottomSheetDialogFragmen settings.SAVE_GLOBAL_TRACK_TO_GPX.set(wasTrackMonitored); updateStatus(); createItem(buttonPause, wasTrackMonitored ? ItemType.PAUSE : ItemType.RESUME, true); - createItem(buttonSegment, ItemType.START_SEGMENT, wasTrackMonitored); + createItem(buttonSegment, ItemType.START_NEW_SEGMENT, wasTrackMonitored); } }); @@ -310,15 +296,17 @@ public class TripRecordingActiveBottomSheet extends MenuBottomSheetDialogFragmen } } - private void updateTrackIcon(View buttonAppearance) { - String width = settings.CURRENT_TRACK_WIDTH.get(); - boolean showArrows = settings.CURRENT_TRACK_SHOW_ARROWS.get(); - int color = settings.CURRENT_TRACK_COLOR.get(); - Drawable appearanceDrawable = TrackAppearanceFragment.getTrackIcon(app, width, showArrows, color); - AppCompatImageView appearanceIcon = buttonAppearance.findViewById(R.id.icon_after_divider); - int marginTrackIconH = app.getResources().getDimensionPixelSize(R.dimen.content_padding_small); - UiUtilities.setMargins(appearanceIcon, marginTrackIconH, 0, marginTrackIconH, 0); - appearanceIcon.setImageDrawable(appearanceDrawable); + public static void updateTrackIcon(OsmandApplication app, AppCompatImageView appearanceIcon) { + if (appearanceIcon != null) { + OsmandSettings settings = app.getSettings(); + String width = settings.CURRENT_TRACK_WIDTH.get(); + boolean showArrows = settings.CURRENT_TRACK_SHOW_ARROWS.get(); + int color = settings.CURRENT_TRACK_COLOR.get(); + Drawable appearanceDrawable = TrackAppearanceFragment.getTrackIcon(app, width, showArrows, color); + int marginTrackIconH = app.getResources().getDimensionPixelSize(R.dimen.content_padding_small); + UiUtilities.setMargins(appearanceIcon, marginTrackIconH, 0, marginTrackIconH, 0); + appearanceIcon.setImageDrawable(appearanceDrawable); + } } private void createItem(View view, ItemType type, boolean enabled) { @@ -370,7 +358,7 @@ public class TripRecordingActiveBottomSheet extends MenuBottomSheetDialogFragmen setTextColor(context, desc, false, nightMode, type); } - setItemBackground(context, nightMode, button != null ? button : (LinearLayout) view, enabled); + setItemBackground(context, nightMode, button != null ? button : view, enabled); } private String getTimeTrackSaved() { @@ -505,7 +493,7 @@ public class TripRecordingActiveBottomSheet extends MenuBottomSheetDialogFragmen show(); for (String key : keys) { if (key.equals(UPDATE_TRACK_ICON)) { - updateTrackIcon(buttonAppearance); + updateTrackIcon(app, trackAppearanceIcon); } } } @@ -524,7 +512,7 @@ public class TripRecordingActiveBottomSheet extends MenuBottomSheetDialogFragmen RECORDING(R.string.recording_default_name, R.drawable.ic_action_track_recordable), ON_PAUSE(R.string.on_pause, R.drawable.ic_pause), CLEAR_DATA(R.string.clear_recorded_data, R.drawable.ic_action_delete_dark), - START_SEGMENT(R.string.gpx_start_new_segment, R.drawable.ic_action_new_segment), + START_NEW_SEGMENT(R.string.gpx_start_new_segment, R.drawable.ic_action_new_segment), SAVE(R.string.shared_string_save, R.drawable.ic_action_save_to_file), PAUSE(R.string.shared_string_pause, R.drawable.ic_pause), RESUME(R.string.shared_string_resume, R.drawable.ic_play_dark), @@ -532,7 +520,9 @@ public class TripRecordingActiveBottomSheet extends MenuBottomSheetDialogFragmen STOP_AND_DISCARD(R.string.track_recording_stop_without_saving, R.drawable.ic_action_rec_stop), STOP_AND_SAVE(R.string.track_recording_save_and_stop, R.drawable.ic_action_save_to_file), STOP_ONLINE(R.string.live_monitoring_stop, R.drawable.ic_world_globe_dark), - CANCEL(R.string.shared_string_cancel, R.drawable.ic_action_close); + CANCEL(R.string.shared_string_cancel, R.drawable.ic_action_close), + START_RECORDING(R.string.shared_string_control_start, R.drawable.ic_action_direction_movement), + SETTINGS(R.string.shared_string_settings, R.drawable.ic_action_settings); @StringRes private final Integer titleId; @@ -560,24 +550,28 @@ public class TripRecordingActiveBottomSheet extends MenuBottomSheetDialogFragmen } } - public static void setItemBackground(Context context, boolean nightMode, LinearLayout view, boolean enabled) { + public static void setItemBackground(Context context, boolean nightMode, View view, boolean enabled) { Drawable background = AppCompatResources.getDrawable(context, R.drawable.btn_background_inactive_light); if (background != null && enabled) { + int normalColorId = view instanceof CardView + ? getActiveTransparentColorId(nightMode) : getInactiveButtonColorId(nightMode); ColorStateList iconColorStateList = AndroidUtils.createPressedColorStateList( - context, getInactiveButtonColorId(nightMode), getActiveButtonColorId(nightMode) + context, normalColorId, getActiveTextColorId(nightMode) ); DrawableCompat.setTintList(background, iconColorStateList); + if (view instanceof CardView) { + ((CardView) view).setCardBackgroundColor(iconColorStateList); + return; + } } else { UiUtilities.tintDrawable(background, ContextCompat.getColor(context, getInactiveButtonColorId(nightMode))); } view.setBackgroundDrawable(background); } - public static void setShowOnMapBackground(LinearLayout view, Context context, boolean checked, boolean nightMode) { - Drawable background = AppCompatResources.getDrawable(context, - nightMode ? checked ? R.drawable.btn_background_inactive_dark : R.drawable.btn_background_stroked_inactive_dark - : checked ? R.drawable.btn_background_inactive_light : R.drawable.btn_background_stroked_inactive_light); - view.setBackgroundDrawable(background); + public static void setShowOnMapBackground(View view, boolean checked, boolean nightMode) { + int background = checked ? getActiveTransparentBackgroundId(nightMode) : getInactiveStrokedBackgroundId(nightMode); + view.setBackgroundResource(background); } public static void setTextColor(Context context, TextView tv, boolean enabled, boolean nightMode, ItemType type) { @@ -638,11 +632,26 @@ public class TripRecordingActiveBottomSheet extends MenuBottomSheetDialogFragmen return nightMode ? R.color.icon_color_osmand_dark : R.color.icon_color_osmand_light; } + @DrawableRes + public static int getActiveTransparentColorId(boolean nightMode) { + return nightMode ? R.color.switch_button_active_dark : R.color.switch_button_active_light; + } + @ColorRes public static int getPressedColorId(boolean nightMode) { return nightMode ? R.color.active_buttons_and_links_text_dark : R.color.active_buttons_and_links_text_light; } + @DrawableRes + public static int getActiveTransparentBackgroundId(boolean nightMode) { + return nightMode ? R.drawable.btn_background_active_transparent_dark : R.drawable.btn_background_active_transparent_light; + } + + @DrawableRes + public static int getInactiveStrokedBackgroundId(boolean nightMode) { + return nightMode ? R.drawable.btn_background_stroked_inactive_dark : R.drawable.btn_background_stroked_inactive_light; + } + @Override protected int getDismissButtonHeight() { return getResources().getDimensionPixelSize(R.dimen.bottom_sheet_cancel_button_height); diff --git a/OsmAnd/src/net/osmand/plus/monitoring/TripRecordingBottomSheet.java b/OsmAnd/src/net/osmand/plus/monitoring/TripRecordingBottomSheet.java deleted file mode 100644 index bbaf9295f7..0000000000 --- a/OsmAnd/src/net/osmand/plus/monitoring/TripRecordingBottomSheet.java +++ /dev/null @@ -1,306 +0,0 @@ -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.view.ViewGroup; -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.core.content.ContextCompat; -import androidx.fragment.app.FragmentManager; - -import com.google.android.material.slider.RangeSlider; - -import net.osmand.AndroidUtils; -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.activities.SavingTrackHelper; -import net.osmand.plus.base.MenuBottomSheetDialogFragment; -import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithDescription; -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 LinearLayout container; - private View divider; - 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()); - - final int paddingSmall = getResources().getDimensionPixelSize(R.dimen.content_padding_small); - - 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, TripRecordingBottomSheet.this); - } - } - }); - - divider = itemView.findViewById(R.id.second_divider); - LinearLayout expandHideIntervalContainer = itemView.findViewById(R.id.interval_view_container); - upDownBtn = itemView.findViewById(R.id.up_down_button); - expandHideIntervalContainer.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(); - - container = itemView.findViewById(R.id.always_ask_and_range_slider_container); - RangeSlider intervalSlider = itemView.findViewById(R.id.interval_slider); - intervalSlider.setValueTo(secondsLength + minutesLength - 1); - int currentModeColor = app.getSettings().getApplicationMode().getProfileColor(nightMode); - UiUtilities.setupSlider(intervalSlider, nightMode, currentModeColor, true); - container.setVisibility(View.GONE); - 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); - } - }); - - final SwitchCompat showTrackOnMapButton = showTrackOnMapView.findViewById(R.id.switch_button); - showTrackOnMapButton.setChecked(app.getSelectedGpxHelper().getSelectedCurrentRecordingTrack() != null); - View basicItem = itemView.findViewById(R.id.basic_item_body); - basicItem.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - boolean checked = !showTrackOnMapButton.isChecked(); - showTrackOnMapButton.setChecked(checked); - app.getSelectedGpxHelper().selectGpxFile(app.getSavingTrackHelper().getCurrentGpx(), checked, 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; - ViewGroup.MarginLayoutParams marginParams = (ViewGroup.MarginLayoutParams) divider.getLayoutParams(); - final int dp8 = AndroidUtils.dpToPx(app, 8f); - final int dp16 = AndroidUtils.dpToPx(app, 16f); - if (infoExpanded) { - AndroidUtils.setMargins(marginParams, 0, dp16, 0, dp8); - } else { - AndroidUtils.setMargins(marginParams, 0, 0, 0, dp8); - } - AndroidUiHelper.updateVisibility(container, infoExpanded); - updateUpDownBtn(); - } - - @Override - protected boolean useVerticalButtons() { - return true; - } - - @Override - protected int getRightButtonHeight() { - return getResources().getDimensionPixelSize(R.dimen.bottom_sheet_cancel_button_height); - } - - @Override - protected int getDismissButtonHeight() { - return getResources().getDimensionPixelSize(R.dimen.bottom_sheet_cancel_button_height); - } - - @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() { - SavingTrackHelper helper = app.getSavingTrackHelper(); - helper.startNewSegment(); - settings.SAVE_GLOBAL_TRACK_TO_GPX.set(true); - app.startNavigationService(NavigationService.USED_BY_GPX); - MapActivity mapActivity = getMapActivity(); - if (mapActivity != null) { - TripRecordingActiveBottomSheet.showInstance(mapActivity.getSupportFragmentManager(), helper.getCurrentTrack()); - } - 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); - } - } -} \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/monitoring/TripRecordingStartingBottomSheet.java b/OsmAnd/src/net/osmand/plus/monitoring/TripRecordingStartingBottomSheet.java new file mode 100644 index 0000000000..7f19ea13fb --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/monitoring/TripRecordingStartingBottomSheet.java @@ -0,0 +1,314 @@ +package net.osmand.plus.monitoring; + +import android.app.Activity; +import android.app.Dialog; +import android.content.Context; +import android.graphics.Typeface; +import android.os.Build; +import android.os.Bundle; +import android.text.SpannableString; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.CompoundButton; +import android.widget.LinearLayout; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.appcompat.widget.AppCompatImageView; +import androidx.appcompat.widget.SwitchCompat; +import androidx.cardview.widget.CardView; +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.activities.MapActivity; +import net.osmand.plus.activities.SavingTrackHelper; +import net.osmand.plus.base.MenuBottomSheetDialogFragment; +import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem; +import net.osmand.plus.helpers.AndroidUiHelper; +import net.osmand.plus.helpers.FontCache; +import net.osmand.plus.monitoring.TripRecordingActiveBottomSheet.ItemType; +import net.osmand.plus.settings.backend.OsmandSettings; +import net.osmand.plus.settings.fragments.BaseSettingsFragment; +import net.osmand.plus.settings.fragments.BaseSettingsFragment.SettingsScreenType; +import net.osmand.plus.track.TrackAppearanceFragment; + +import static net.osmand.plus.UiUtilities.CompoundButtonType.GLOBAL; +import static net.osmand.plus.monitoring.OsmandMonitoringPlugin.MINUTES; +import static net.osmand.plus.monitoring.OsmandMonitoringPlugin.SECONDS; +import static net.osmand.plus.monitoring.TripRecordingActiveBottomSheet.UPDATE_TRACK_ICON; +import static net.osmand.plus.monitoring.TripRecordingActiveBottomSheet.createItem; +import static net.osmand.plus.monitoring.TripRecordingActiveBottomSheet.setShowOnMapBackground; +import static net.osmand.plus.monitoring.TripRecordingActiveBottomSheet.updateTrackIcon; + +public class TripRecordingStartingBottomSheet extends MenuBottomSheetDialogFragment { + + public static final String TAG = TripRecordingStartingBottomSheet.class.getSimpleName(); + public static final String UPDATE_LOGGING_INTERVAL = "update_logging_interval"; + + private OsmandApplication app; + private OsmandSettings settings; + + private AppCompatImageView upDownBtn; + private AppCompatImageView trackAppearanceIcon; + private CardView confirmContainer; + private SwitchCompat confirmCompound; + private TextView intervalValueView; + private LinearLayout intervalContainer; + private RangeSlider intervalSlider; + + private boolean infoExpanded; + + public static void showInstance(@NonNull FragmentManager fragmentManager) { + if (!fragmentManager.isStateSaved()) { + TripRecordingStartingBottomSheet fragment = new TripRecordingStartingBottomSheet(); + fragment.show(fragmentManager, TAG); + } + } + + @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_starting_fragment, null, false); + items.add(new BaseBottomSheetItem.Builder() + .setCustomView(itemView) + .create()); + + LinearLayout expandHideIntervalContainer = itemView.findViewById(R.id.interval_view_container); + upDownBtn = itemView.findViewById(R.id.up_down_button); + expandHideIntervalContainer.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + updateIntervalContainer(); + } + }); + + intervalValueView = itemView.findViewById(R.id.interval_value); + intervalContainer = itemView.findViewById(R.id.always_ask_and_range_slider_container); + intervalSlider = itemView.findViewById(R.id.interval_slider); + updateIntervalValue(); + + confirmContainer = itemView.findViewById(R.id.confirm_container); + confirmCompound = confirmContainer.findViewById(R.id.confirm_compound_button); + updateGlobalRemember(); + confirmContainer.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + boolean checked = !confirmCompound.isChecked(); + confirmCompound.setChecked(checked); + settings.SAVE_GLOBAL_TRACK_REMEMBER.set(checked); + setShowOnMapBackground(confirmContainer, checked, nightMode); + } + }); + + LinearLayout showTrackContainer = itemView.findViewById(R.id.show_track_on_map); + + final CardView buttonShow = itemView.findViewById(R.id.compound_container); + TextView showTrackTitle = buttonShow.findViewById(R.id.title); + showTrackTitle.setText(R.string.show_track_on_map); + final CompoundButton showTrackCompound = buttonShow.findViewById(R.id.compound_button); + showTrackCompound.setChecked(app.getSelectedGpxHelper().getSelectedCurrentRecordingTrack() != null); + UiUtilities.setupCompoundButton(showTrackCompound, nightMode, GLOBAL); + + LinearLayout buttonAppearance = showTrackContainer.findViewById(R.id.additional_button); + trackAppearanceIcon = showTrackContainer.findViewById(R.id.additional_button_icon); + updateTrackIcon(app, trackAppearanceIcon); + buttonAppearance.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, TripRecordingStartingBottomSheet.this); + } + } + }); + setShowOnMapBackground(buttonShow, showTrackCompound.isChecked(), nightMode); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + buttonShow.setBackgroundTintList(null); + } + buttonShow.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + boolean checked = !showTrackCompound.isChecked(); + showTrackCompound.setChecked(checked); + app.getSelectedGpxHelper().selectGpxFile(app.getSavingTrackHelper().getCurrentGpx(), checked, false); + setShowOnMapBackground(buttonShow, checked, nightMode); + } + }); + + updateUpDownBtn(); + + CardView cardLeft = itemView.findViewById(R.id.button_left); + createItem(app, nightMode, cardLeft, ItemType.CANCEL, true, null); + cardLeft.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + dismiss(); + } + }); + + CardView cardCenter = itemView.findViewById(R.id.button_center); + createItem(app, nightMode, cardCenter, ItemType.START_RECORDING, true, null); + cardCenter.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + startRecording(); + } + }); + + CardView cardRight = itemView.findViewById(R.id.button_right); + createItem(app, nightMode, cardRight, ItemType.SETTINGS, true, null); + cardRight.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + MapActivity mapActivity = getMapActivity(); + if (mapActivity != null) { + hide(); + BaseSettingsFragment.showInstance(mapActivity, SettingsScreenType.MONITORING_SETTINGS, TripRecordingStartingBottomSheet.this); + } + } + }); + } + + 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); + } + + private void updateIntervalValue() { + if (intervalSlider != null && intervalContainer != null) { + updateIntervalLegend(); + final int secondsLength = SECONDS.length; + final int minutesLength = MINUTES.length; + intervalSlider.setValueTo(secondsLength + minutesLength - 1); + int currentModeColor = app.getSettings().getApplicationMode().getProfileColor(nightMode); + UiUtilities.setupSlider(intervalSlider, nightMode, currentModeColor, true); + intervalContainer.setVisibility(View.GONE); + 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; + } + } + } + } + } + + private void updateIntervalContainer() { + infoExpanded = !infoExpanded; + AndroidUiHelper.updateVisibility(intervalContainer, infoExpanded); + updateUpDownBtn(); + } + + private void updateGlobalRemember() { + if (confirmContainer != null && confirmCompound != null) { + confirmCompound.setChecked(settings.SAVE_GLOBAL_TRACK_REMEMBER.get()); + setShowOnMapBackground(confirmContainer, confirmCompound.isChecked(), nightMode); + } + } + + private void updateUpDownBtn() { + int iconId = infoExpanded ? R.drawable.ic_action_arrow_down : R.drawable.ic_action_arrow_up; + upDownBtn.setImageDrawable(getContentIcon(iconId)); + } + + private void startRecording() { + SavingTrackHelper helper = app.getSavingTrackHelper(); + helper.startNewSegment(); + settings.SAVE_GLOBAL_TRACK_TO_GPX.set(true); + app.startNavigationService(NavigationService.USED_BY_GPX); + MapActivity mapActivity = getMapActivity(); + if (mapActivity != null) { + TripRecordingActiveBottomSheet.showInstance(mapActivity.getSupportFragmentManager(), helper.getCurrentTrack()); + } + dismiss(); + } + + public void show(String... keys) { + Dialog dialog = getDialog(); + if (dialog != null) { + dialog.show(); + for (String key : keys) { + if (key.equals(UPDATE_TRACK_ICON)) { + updateTrackIcon(app, trackAppearanceIcon); + } + if (key.equals(UPDATE_LOGGING_INTERVAL)) { + updateGlobalRemember(); + updateIntervalValue(); + AndroidUiHelper.updateVisibility(intervalContainer, infoExpanded); + } + } + } + } + + public void hide() { + Dialog dialog = getDialog(); + if (dialog != null) { + dialog.hide(); + } + } + + @Nullable + public MapActivity getMapActivity() { + Activity activity = getActivity(); + if (activity instanceof MapActivity) { + return (MapActivity) activity; + } + return null; + } + + @Override + protected boolean hideButtonsContainer() { + return true; + } + +} diff --git a/OsmAnd/src/net/osmand/plus/settings/fragments/BaseSettingsFragment.java b/OsmAnd/src/net/osmand/plus/settings/fragments/BaseSettingsFragment.java index e6d39cade8..d71387c0ce 100644 --- a/OsmAnd/src/net/osmand/plus/settings/fragments/BaseSettingsFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/fragments/BaseSettingsFragment.java @@ -61,6 +61,7 @@ import net.osmand.plus.activities.OsmandInAppPurchaseActivity; import net.osmand.plus.audionotes.MultimediaNotesFragment; import net.osmand.plus.development.DevelopmentSettingsFragment; import net.osmand.plus.monitoring.MonitoringSettingsFragment; +import net.osmand.plus.monitoring.TripRecordingStartingBottomSheet; import net.osmand.plus.openplacereviews.OprSettingsFragment; import net.osmand.plus.osmedit.OsmEditingFragment; import net.osmand.plus.profiles.SelectAppModesBottomSheetDialogFragment; @@ -85,6 +86,7 @@ import java.io.Serializable; import java.util.Set; import static net.osmand.aidlapi.OsmAndCustomizationConstants.DRAWER_SETTINGS_ID; +import static net.osmand.plus.monitoring.TripRecordingStartingBottomSheet.UPDATE_LOGGING_INTERVAL; public abstract class BaseSettingsFragment extends PreferenceFragmentCompat implements OnPreferenceChangeListener, OnPreferenceClickListener, AppModeChangedListener, OnConfirmPreferenceChange { @@ -291,6 +293,15 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl } } + @Override + public void onDestroyView() { + super.onDestroyView(); + Fragment target = getTargetFragment(); + if (target instanceof TripRecordingStartingBottomSheet) { + ((TripRecordingStartingBottomSheet) target).show(UPDATE_LOGGING_INTERVAL); + } + } + @Override public void onDetach() { super.onDetach(); @@ -884,21 +895,37 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl } public static boolean showInstance(FragmentActivity activity, SettingsScreenType screenType) { - return showInstance(activity, screenType, null); + return showInstance(activity, screenType, (ApplicationMode) null); + } + + public static boolean showInstance(FragmentActivity activity, SettingsScreenType screenType, Fragment target) { + return showInstance(activity, screenType, null, target); } public static boolean showInstance(FragmentActivity activity, SettingsScreenType screenType, @Nullable ApplicationMode appMode) { return showInstance(activity, screenType, appMode, new Bundle()); } + public static boolean showInstance(FragmentActivity activity, SettingsScreenType screenType, @Nullable ApplicationMode appMode, Fragment target) { + return showInstance(activity, screenType, appMode, new Bundle(), target); + } + public static boolean showInstance(FragmentActivity activity, SettingsScreenType screenType, @Nullable ApplicationMode appMode, @NonNull Bundle args) { + return showInstance(activity, screenType, appMode, args, null); + } + + public static boolean showInstance(FragmentActivity activity, SettingsScreenType screenType, + @Nullable ApplicationMode appMode, @NonNull Bundle args, @Nullable Fragment target) { try { Fragment fragment = Fragment.instantiate(activity, screenType.fragmentName); if (appMode != null) { args.putString(APP_MODE_KEY, appMode.getStringKey()); } fragment.setArguments(args); + if (target != null) { + fragment.setTargetFragment(target, 0); + } activity.getSupportFragmentManager().beginTransaction() .replace(R.id.fragmentContainer, fragment, screenType.fragmentName) .addToBackStack(DRAWER_SETTINGS_ID + ".new") diff --git a/OsmAnd/src/net/osmand/plus/track/TrackAppearanceFragment.java b/OsmAnd/src/net/osmand/plus/track/TrackAppearanceFragment.java index f33571bdd6..807becbb1c 100644 --- a/OsmAnd/src/net/osmand/plus/track/TrackAppearanceFragment.java +++ b/OsmAnd/src/net/osmand/plus/track/TrackAppearanceFragment.java @@ -37,7 +37,7 @@ 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.TripRecordingActiveBottomSheet; -import net.osmand.plus.monitoring.TripRecordingBottomSheet; +import net.osmand.plus.monitoring.TripRecordingStartingBottomSheet; import net.osmand.plus.routepreparationmenu.cards.BaseCard; import net.osmand.plus.routepreparationmenu.cards.BaseCard.CardListener; import net.osmand.plus.settings.backend.CommonPreference; @@ -398,8 +398,8 @@ public class TrackAppearanceFragment extends ContextMenuScrollFragment implement @Override public void onContextMenuDismiss(@NonNull ContextMenuFragment fragment) { Fragment target = getTargetFragment(); - if (target instanceof TripRecordingBottomSheet) { - ((TripRecordingBottomSheet) target).show(); + if (target instanceof TripRecordingStartingBottomSheet) { + ((TripRecordingStartingBottomSheet) target).show(UPDATE_TRACK_ICON); } else if (target instanceof TripRecordingActiveBottomSheet) { ((TripRecordingActiveBottomSheet) target).show(UPDATE_TRACK_ICON); }