Merge pull request #10930 from osmandapp/fix_trip_recording_process_p1

Fix trip recording process p1
This commit is contained in:
Vitaliy 2021-02-18 18:42:31 +02:00 committed by GitHub
commit 1a230ab3d3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 195 additions and 146 deletions

View file

@ -12,6 +12,7 @@
android:clickable="true"
android:focusable="true"
android:gravity="center_vertical"
android:minHeight="@dimen/bottom_sheet_list_item_height"
android:orientation="horizontal"
android:paddingStart="@dimen/content_padding_small"
android:paddingLeft="@dimen/content_padding_small"
@ -34,7 +35,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:duplicateParentState="true"
android:letterSpacing="@dimen/description_letter_spacing"
android:letterSpacing="@dimen/text_button_letter_spacing"
android:textSize="@dimen/default_desc_text_size"
osmand:typeface="@string/font_roboto_medium"
tools:text="Title"
@ -45,7 +46,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:duplicateParentState="true"
android:letterSpacing="@dimen/description_letter_spacing"
android:letterSpacing="@dimen/text_button_letter_spacing"
android:textSize="@dimen/default_desc_text_size"
android:visibility="gone"
osmand:typeface="@string/font_roboto_medium"

View file

@ -102,6 +102,19 @@
android:layout_marginRight="@dimen/content_padding"
android:layout_marginBottom="@dimen/content_padding" />
<include
android:id="@+id/button_online"
layout="@layout/bottom_sheet_button_with_icon"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/content_padding"
android:layout_marginLeft="@dimen/content_padding"
android:layout_marginTop="@dimen/content_padding_half"
android:layout_marginEnd="@dimen/content_padding"
android:layout_marginRight="@dimen/content_padding"
android:layout_marginBottom="@dimen/content_padding"
android:visibility="gone" />
<include
android:id="@+id/button_segment"
layout="@layout/bottom_sheet_button_with_icon"

View file

@ -23,12 +23,23 @@ public class ClearRecordedDataBottomSheetFragment extends MenuBottomSheetDialogF
private OsmandApplication app;
public static void showInstance(@NonNull FragmentManager fragmentManager, @NonNull Fragment target) {
if (!fragmentManager.isStateSaved()) {
ClearRecordedDataBottomSheetFragment fragment = new ClearRecordedDataBottomSheetFragment();
fragment.setTargetFragment(target, 0);
fragment.show(fragmentManager, TAG);
}
}
@Override
public void createMenuItems(Bundle savedInstanceState) {
app = requiredMyApplication();
LayoutInflater inflater = UiUtilities.getInflater(app, nightMode);
int verticalBig = getResources().getDimensionPixelSize(R.dimen.dialog_content_margin);
int verticalSmall = getResources().getDimensionPixelSize(R.dimen.content_padding_small);
int verticalNormal = getResources().getDimensionPixelSize(R.dimen.content_padding);
final View buttonClear = createItem(inflater, ItemType.CLEAR_DATA);
final View buttonCancel = createItem(inflater, ItemType.CANCEL);
items.add(new BottomSheetItemWithDescription.Builder()
.setDescription(app.getString(R.string.clear_recorded_data_warning))
@ -41,7 +52,7 @@ public class ClearRecordedDataBottomSheetFragment extends MenuBottomSheetDialogF
items.add(new DividerSpaceItem(app, verticalBig));
items.add(new BaseBottomSheetItem.Builder()
.setCustomView(TripRecordingActiveBottomSheet.createButton(inflater, ItemType.CLEAR_DATA, nightMode))
.setCustomView(buttonClear)
.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@ -54,7 +65,7 @@ public class ClearRecordedDataBottomSheetFragment extends MenuBottomSheetDialogF
items.add(new DividerSpaceItem(app, verticalBig));
items.add(new BaseBottomSheetItem.Builder()
.setCustomView(TripRecordingActiveBottomSheet.createButton(inflater, ItemType.CANCEL, nightMode))
.setCustomView(buttonCancel)
.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@ -63,7 +74,11 @@ public class ClearRecordedDataBottomSheetFragment extends MenuBottomSheetDialogF
})
.create());
items.add(new DividerSpaceItem(app, verticalSmall));
items.add(new DividerSpaceItem(app, verticalNormal));
}
private View createItem(LayoutInflater inflater, ItemType type) {
return TripRecordingActiveBottomSheet.createItem(app, nightMode, inflater, type);
}
@Override
@ -88,12 +103,4 @@ public class ClearRecordedDataBottomSheetFragment extends MenuBottomSheetDialogF
protected boolean hideButtonsContainer() {
return true;
}
public static void showInstance(@NonNull FragmentManager fragmentManager, @NonNull Fragment target) {
if (!fragmentManager.isStateSaved()) {
ClearRecordedDataBottomSheetFragment fragment = new ClearRecordedDataBottomSheetFragment();
fragment.setTargetFragment(target, 0);
fragment.show(fragmentManager, TAG);
}
}
}

View file

@ -34,6 +34,15 @@ public class StopTrackRecordingBottomFragment extends MenuBottomSheetDialogFragm
this.mapActivity = mapActivity;
}
public static void showInstance(MapActivity mapActivity, @NonNull FragmentManager fragmentManager, @NonNull Fragment target) {
if (!fragmentManager.isStateSaved()) {
StopTrackRecordingBottomFragment fragment = new StopTrackRecordingBottomFragment();
fragment.setMapActivity(mapActivity);
fragment.setTargetFragment(target, 0);
fragment.show(fragmentManager, TAG);
}
}
@Override
public void createMenuItems(Bundle savedInstanceState) {
app = requiredMyApplication();
@ -41,7 +50,11 @@ public class StopTrackRecordingBottomFragment extends MenuBottomSheetDialogFragm
plugin = OsmandPlugin.getPlugin(OsmandMonitoringPlugin.class);
LayoutInflater inflater = UiUtilities.getInflater(app, nightMode);
int verticalBig = getResources().getDimensionPixelSize(R.dimen.dialog_content_margin);
int verticalSmall = getResources().getDimensionPixelSize(R.dimen.content_padding_small);
int verticalNormal = getResources().getDimensionPixelSize(R.dimen.content_padding);
final View buttonDiscard = createItem(inflater, ItemType.STOP_AND_DISCARD);
final View buttonSave = createItem(inflater, ItemType.STOP_AND_SAVE);
final View buttonCancel = createItem(inflater, ItemType.CANCEL);
items.add(new BottomSheetItemWithDescription.Builder()
.setDescription(app.getString(R.string.track_recording_description))
@ -54,11 +67,11 @@ public class StopTrackRecordingBottomFragment extends MenuBottomSheetDialogFragm
items.add(new DividerSpaceItem(app, verticalBig));
items.add(new BaseBottomSheetItem.Builder()
.setCustomView(TripRecordingActiveBottomSheet.createButton(inflater, ItemType.STOP_AND_DISCARD, nightMode))
.setCustomView(buttonDiscard)
.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
tag = ItemType.STOP_AND_DISCARD;
tag = (ItemType) buttonDiscard.getTag();
if (plugin != null && settings.SAVE_GLOBAL_TRACK_TO_GPX.get()) {
plugin.stopRecording();
app.getNotificationHelper().refreshNotifications();
@ -72,11 +85,11 @@ public class StopTrackRecordingBottomFragment extends MenuBottomSheetDialogFragm
items.add(new DividerSpaceItem(app, verticalBig));
items.add(new BaseBottomSheetItem.Builder()
.setCustomView(TripRecordingActiveBottomSheet.createButton(inflater, ItemType.SAVE_AND_STOP, nightMode))
.setCustomView(buttonSave)
.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
tag = ItemType.SAVE_AND_STOP;
tag = (ItemType) buttonSave.getTag();
if (plugin != null && settings.SAVE_GLOBAL_TRACK_TO_GPX.get()) {
plugin.saveCurrentTrack(null, mapActivity);
app.getNotificationHelper().refreshNotifications();
@ -86,20 +99,24 @@ public class StopTrackRecordingBottomFragment extends MenuBottomSheetDialogFragm
})
.create());
items.add(new DividerSpaceItem(app, verticalSmall));
items.add(new DividerSpaceItem(app, verticalNormal));
items.add(new BaseBottomSheetItem.Builder()
.setCustomView(TripRecordingActiveBottomSheet.createButton(inflater, ItemType.CANCEL, nightMode))
.setCustomView(buttonCancel)
.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
tag = ItemType.CANCEL;
tag = (ItemType) buttonCancel.getTag();
dismiss();
}
})
.create());
items.add(new DividerSpaceItem(app, verticalSmall));
items.add(new DividerSpaceItem(app, verticalNormal));
}
private View createItem(LayoutInflater inflater, ItemType type) {
return TripRecordingActiveBottomSheet.createItem(app, nightMode, inflater, type);
}
@Override
@ -114,10 +131,13 @@ public class StopTrackRecordingBottomFragment extends MenuBottomSheetDialogFragm
@Override
public void onPause() {
super.onPause();
if (tag == ItemType.CANCEL) {
Fragment target = getTargetFragment();
if (target instanceof TripRecordingActiveBottomSheet) {
((TripRecordingActiveBottomSheet) target).show();
TripRecordingActiveBottomSheet tripRec = (TripRecordingActiveBottomSheet) target;
if (tag == ItemType.CANCEL) {
tripRec.show();
} else {
tripRec.dismiss();
}
}
}
@ -126,13 +146,4 @@ public class StopTrackRecordingBottomFragment extends MenuBottomSheetDialogFragm
protected boolean hideButtonsContainer() {
return true;
}
public static void showInstance(MapActivity mapActivity, @NonNull FragmentManager fragmentManager, @NonNull Fragment target) {
if (!fragmentManager.isStateSaved()) {
StopTrackRecordingBottomFragment fragment = new StopTrackRecordingBottomFragment();
fragment.setMapActivity(mapActivity);
fragment.setTargetFragment(target, 0);
fragment.show(fragmentManager, TAG);
}
}
}

View file

@ -43,7 +43,6 @@ import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
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.activities.SavingTrackHelper.SaveGpxResult;
@ -62,6 +61,8 @@ import net.osmand.util.Algorithms;
import org.apache.commons.logging.Log;
import java.lang.ref.WeakReference;
import java.util.Arrays;
import java.util.List;
import static net.osmand.plus.UiUtilities.CompoundButtonType.PROFILE_DEPENDENT;
@ -79,6 +80,7 @@ public class TripRecordingActiveBottomSheet extends MenuBottomSheetDialogFragmen
private SelectedGpxFile selectedGpxFile;
private View statusContainer;
private LinearLayout buttonAppearance;
private View buttonSave;
private GpxBlockStatisticsBuilder blockStatisticsBuilder;
@ -128,15 +130,19 @@ public class TripRecordingActiveBottomSheet extends MenuBottomSheetDialogFragmen
.create());
View buttonClear = itemView.findViewById(R.id.button_clear);
final View buttonOnline = itemView.findViewById(R.id.button_online);
View buttonSegment = itemView.findViewById(R.id.button_segment);
buttonSave = itemView.findViewById(R.id.button_save);
final View buttonPause = itemView.findViewById(R.id.button_pause);
View buttonStop = itemView.findViewById(R.id.button_stop);
createItem(buttonClear, ItemType.CLEAR_DATA, hasDataToSave(), null);
createItem(buttonSegment, ItemType.START_SEGMENT, wasTrackMonitored(), null);
createItem(buttonPause, wasTrackMonitored() ? ItemType.PAUSE : ItemType.RESUME, true, null);
createItem(buttonStop, ItemType.STOP, true, null);
createItem(buttonClear, ItemType.CLEAR_DATA, hasDataToSave());
createItem(buttonOnline, ItemType.STOP_ONLINE, hasDataToSave());
createItem(buttonSegment, ItemType.START_SEGMENT, wasTrackMonitored());
createItem(buttonPause, wasTrackMonitored() ? ItemType.PAUSE : ItemType.RESUME, true);
createItem(buttonStop, ItemType.STOP, true);
AndroidUiHelper.updateVisibility(buttonOnline, app.getLiveMonitoringHelper().isLiveMonitoringEnabled());
statusContainer = itemView.findViewById(R.id.status_container);
updateStatus();
@ -162,31 +168,25 @@ public class TripRecordingActiveBottomSheet extends MenuBottomSheetDialogFragmen
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.description_letter_spacing);
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 LinearLayout buttonAppearance = showTrackContainer.findViewById(R.id.additional_button);
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);
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);
updateTrackIcon(buttonAppearance);
buttonAppearance.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@ -200,7 +200,7 @@ public class TripRecordingActiveBottomSheet extends MenuBottomSheetDialogFragmen
}
}
});
createItem(buttonAppearance, ItemType.APPEARANCE, showTrackOnMapButton.isChecked(), null);
createItem(buttonAppearance, ItemType.APPEARANCE, showTrackOnMapButton.isChecked());
setShowOnMapBackground(buttonShow, app, showTrackOnMapButton.isChecked(), nightMode);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
buttonShow.setBackgroundTintList(null);
@ -211,7 +211,7 @@ public class TripRecordingActiveBottomSheet extends MenuBottomSheetDialogFragmen
boolean checked = !showTrackOnMapButton.isChecked();
showTrackOnMapButton.setChecked(checked);
app.getSelectedGpxHelper().selectGpxFile(app.getSavingTrackHelper().getCurrentGpx(), checked, false);
createItem(buttonAppearance, ItemType.APPEARANCE, checked, null);
createItem(buttonAppearance, ItemType.APPEARANCE, checked);
setShowOnMapBackground(buttonShow, app, checked, nightMode);
}
});
@ -225,6 +225,14 @@ public class TripRecordingActiveBottomSheet extends MenuBottomSheetDialogFragmen
}
});
buttonOnline.findViewById(R.id.button_container).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
settings.LIVE_MONITORING.set(false);
AndroidUiHelper.updateVisibility(buttonOnline, false);
}
});
buttonSegment.findViewById(R.id.button_container).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@ -265,7 +273,7 @@ public class TripRecordingActiveBottomSheet extends MenuBottomSheetDialogFragmen
}
settings.SAVE_GLOBAL_TRACK_TO_GPX.set(wasTrackMonitored);
updateStatus();
createItem(buttonPause, wasTrackMonitored ? ItemType.PAUSE : ItemType.RESUME, true, null);
createItem(buttonPause, wasTrackMonitored ? ItemType.PAUSE : ItemType.RESUME, true);
}
});
@ -279,12 +287,6 @@ public class TripRecordingActiveBottomSheet extends MenuBottomSheetDialogFragmen
});
}
@Override
public void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState);
outState.putBoolean(UPDATE_CURRENT_GPX_FILE, true);
}
private void updateStatus() {
TextView statusTitle = statusContainer.findViewById(R.id.text_status);
AppCompatImageView statusIcon = statusContainer.findViewById(R.id.icon_status);
@ -304,72 +306,67 @@ 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);
}
private void createItem(View view, ItemType type, boolean enabled) {
createItem(app, nightMode, view, type, enabled, null);
}
private void createItem(View view, ItemType type, boolean enabled, @Nullable String description) {
createItem(app, nightMode, view, type, enabled, description);
}
public static View createItem(Context context, boolean nightMode, LayoutInflater inflater, ItemType type) {
View button = inflater.inflate(R.layout.bottom_sheet_button_with_icon, null);
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT);
int horizontal = context.getResources().getDimensionPixelSize(R.dimen.content_padding);
params.setMargins(horizontal, 0, horizontal, 0);
button.setLayoutParams(params);
LinearLayout container = button.findViewById(R.id.button_container);
container.setClickable(false);
container.setFocusable(false);
createItem(context, nightMode, button, type, true, null);
return button;
}
public static void createItem(Context context, boolean nightMode, View view, ItemType type, boolean enabled, @Nullable String description) {
view.setTag(type);
LinearLayout button = view.findViewById(R.id.button_container);
AppCompatImageView icon = view.findViewById(R.id.icon);
if (icon != null) {
setTintedIcon(icon, enabled, nightMode, type);
setTintedIcon(context, icon, enabled, nightMode, type);
}
TextView title = view.findViewById(R.id.button_text);
Integer titleId = type.getTitleId();
if (title != null && titleId != null) {
title.setText(titleId);
setTextColor(title, enabled, nightMode, type);
setTextColor(context, title, enabled, nightMode, type);
}
TextViewEx desc = view.findViewById(R.id.desc);
if (desc != null) {
boolean isShowDesc = !Algorithms.isBlank(description);
int marginDesc = isShowDesc ? 0 : app.getResources().getDimensionPixelSize(R.dimen.context_menu_padding_margin_medium);
int marginDesc = isShowDesc ? 0 : context.getResources().getDimensionPixelSize(R.dimen.context_menu_padding_margin_medium);
AndroidUiHelper.updateVisibility(desc, isShowDesc);
if (title != null) {
UiUtilities.setMargins(title, 0, marginDesc, 0, marginDesc);
}
desc.setText(description);
setTextColor(desc, false, nightMode, type);
setTextColor(context, desc, false, nightMode, type);
}
setItemBackground(button != null ? button : (LinearLayout) view, enabled);
}
protected static View createButton(LayoutInflater inflater, ItemType type, boolean nightMode) {
View button = inflater.inflate(R.layout.bottom_sheet_button_with_icon, null);
button.setTag(type);
Context context = button.getContext();
LinearLayout container = button.findViewById(R.id.button_container);
container.setClickable(false);
container.setFocusable(false);
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT);
int horizontal = context.getResources().getDimensionPixelSize(R.dimen.content_padding);
params.setMargins(horizontal, 0, horizontal, 0);
button.setLayoutParams(params);
if (type.getTitleId() != null) {
UiUtilities.setupDialogButton(nightMode, button, type.getEffect(), type.getTitleId());
}
TextViewEx title = button.findViewById(R.id.button_text);
int margin = context.getResources().getDimensionPixelSize(R.dimen.context_menu_padding_margin_medium);
UiUtilities.setMargins(title, 0, margin, 0, margin);
int colorRes;
if (type.getEffect() == UiUtilities.DialogButtonType.SECONDARY_HARMFUL) {
colorRes = R.color.color_osm_edit_delete;
} else {
colorRes = nightMode ? R.color.dlg_btn_secondary_text_dark : R.color.dlg_btn_secondary_text_light;
}
AppCompatImageView icon = button.findViewById(R.id.icon);
if (type.getIconId() != null) {
Drawable drawable = AppCompatResources.getDrawable(context, type.getIconId());
UiUtilities.tintDrawable(drawable, ContextCompat.getColor(context, colorRes));
icon.setImageDrawable(drawable);
}
return button;
setItemBackground(context, nightMode, button != null ? button : (LinearLayout) view, enabled);
}
private String getTimeTrackSaved() {
@ -383,6 +380,12 @@ public class TripRecordingActiveBottomSheet extends MenuBottomSheetDialogFragmen
}
}
@Override
public void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState);
outState.putBoolean(UPDATE_CURRENT_GPX_FILE, true);
}
@Override
public void onResume() {
super.onResume();
@ -489,6 +492,13 @@ public class TripRecordingActiveBottomSheet extends MenuBottomSheetDialogFragmen
}
}
public void show(boolean updateTrackIcon) {
show();
if (updateTrackIcon && buttonAppearance != null) {
updateTrackIcon(buttonAppearance);
}
}
public void hide() {
Dialog dialog = getDialog();
if (dialog != null) {
@ -497,31 +507,31 @@ public class TripRecordingActiveBottomSheet extends MenuBottomSheetDialogFragmen
}
public enum ItemType {
SHOW_TRACK(R.string.shared_string_show_on_map, null, null),
APPEARANCE(null, null, null),
SEARCHING_GPS(R.string.searching_gps, R.drawable.ic_action_gps_info, null),
RECORDING(R.string.recording_default_name, R.drawable.ic_action_track_recordable, null),
ON_PAUSE(R.string.on_pause, R.drawable.ic_pause, null),
CLEAR_DATA(R.string.clear_recorded_data, R.drawable.ic_action_delete_dark, UiUtilities.DialogButtonType.SECONDARY_HARMFUL),
START_SEGMENT(R.string.gpx_start_new_segment, R.drawable.ic_action_new_segment, null),
SAVE(R.string.shared_string_save, R.drawable.ic_action_save_to_file, null),
PAUSE(R.string.shared_string_pause, R.drawable.ic_pause, null),
RESUME(R.string.shared_string_resume, R.drawable.ic_play_dark, null),
STOP(R.string.shared_string_control_stop, R.drawable.ic_action_rec_stop, null),
STOP_AND_DISCARD(R.string.track_recording_stop_without_saving, R.drawable.ic_action_rec_stop, DialogButtonType.SECONDARY_HARMFUL),
SAVE_AND_STOP(R.string.track_recording_save_and_stop, R.drawable.ic_action_save_to_file, DialogButtonType.SECONDARY),
CANCEL(R.string.shared_string_cancel, R.drawable.ic_action_close, DialogButtonType.SECONDARY);
SHOW_TRACK(R.string.shared_string_show_on_map, null),
APPEARANCE(null, null),
SEARCHING_GPS(R.string.searching_gps, R.drawable.ic_action_gps_info),
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),
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),
STOP(R.string.shared_string_control_stop, R.drawable.ic_action_rec_stop),
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);
@StringRes
private final Integer titleId;
@DrawableRes
private final Integer iconId;
private final DialogButtonType effect;
private static final List<ItemType> negative = Arrays.asList(CLEAR_DATA, STOP_AND_DISCARD);
ItemType(@Nullable @StringRes Integer titleId, @Nullable @DrawableRes Integer iconId, @Nullable DialogButtonType effect) {
ItemType(@Nullable @StringRes Integer titleId, @Nullable @DrawableRes Integer iconId) {
this.titleId = titleId;
this.iconId = iconId;
this.effect = effect;
}
@Nullable
@ -534,53 +544,52 @@ public class TripRecordingActiveBottomSheet extends MenuBottomSheetDialogFragmen
return iconId;
}
@Nullable
public DialogButtonType getEffect() {
return effect;
public boolean isNegative() {
return negative.contains(this);
}
}
private void setItemBackground(LinearLayout view, boolean enabled) {
Drawable background = AppCompatResources.getDrawable(app, R.drawable.btn_background_inactive_light);
public static void setItemBackground(Context context, boolean nightMode, LinearLayout view, boolean enabled) {
Drawable background = AppCompatResources.getDrawable(context, R.drawable.btn_background_inactive_light);
if (background != null && enabled) {
ColorStateList iconColorStateList = AndroidUtils.createPressedColorStateList(
app, getInactiveButtonColorId(nightMode), getActiveButtonColorId(nightMode)
context, getInactiveButtonColorId(nightMode), getActiveButtonColorId(nightMode)
);
DrawableCompat.setTintList(background, iconColorStateList);
} else {
UiUtilities.tintDrawable(background, ContextCompat.getColor(app, getInactiveButtonColorId(nightMode)));
UiUtilities.tintDrawable(background, ContextCompat.getColor(context, getInactiveButtonColorId(nightMode)));
}
view.setBackgroundDrawable(background);
}
private static void setShowOnMapBackground(LinearLayout view, Context context, boolean checked, boolean nightMode) {
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 void setTextColor(TextView tv, boolean enabled, boolean nightMode, ItemType type) {
public static void setTextColor(Context context, TextView tv, boolean enabled, boolean nightMode, ItemType type) {
if (tv != null) {
int activeColorId = type == ItemType.CLEAR_DATA ? R.color.color_osm_edit_delete : getActiveTextColorId(nightMode);
int activeColorId = type.isNegative() ? R.color.color_osm_edit_delete : getActiveTextColorId(nightMode);
int normalColorId = enabled ? activeColorId : getSecondaryTextColorId(nightMode);
ColorStateList textColorStateList = AndroidUtils.createPressedColorStateList(app, normalColorId, getPressedColorId(nightMode));
ColorStateList textColorStateList = AndroidUtils.createPressedColorStateList(context, normalColorId, getPressedColorId(nightMode));
tv.setTextColor(textColorStateList);
}
}
public void setTintedIcon(AppCompatImageView iv, boolean enabled, boolean nightMode, ItemType type) {
public static void setTintedIcon(Context context, AppCompatImageView iv, boolean enabled, boolean nightMode, ItemType type) {
Integer iconId = type.getIconId();
if (iv != null && iconId != null) {
Drawable icon = AppCompatResources.getDrawable(app, iconId);
int activeColorId = type == ItemType.CLEAR_DATA ? R.color.color_osm_edit_delete : getActiveIconColorId(nightMode);
Drawable icon = AppCompatResources.getDrawable(context, iconId);
int activeColorId = type.isNegative() ? R.color.color_osm_edit_delete : getActiveIconColorId(nightMode);
int normalColorId = enabled ? activeColorId : getSecondaryIconColorId(nightMode);
ColorStateList iconColorStateList = AndroidUtils.createPressedColorStateList(app, normalColorId, getPressedColorId(nightMode));
ColorStateList iconColorStateList = AndroidUtils.createPressedColorStateList(context, normalColorId, getPressedColorId(nightMode));
if (icon != null) {
DrawableCompat.setTintList(icon, iconColorStateList);
}
iv.setImageDrawable(icon);
if (type == ItemType.STOP) {
if (type.iconId == R.drawable.ic_action_rec_stop) {
int stopSize = iv.getResources().getDimensionPixelSize(R.dimen.bottom_sheet_icon_margin_large);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(stopSize, stopSize);
iv.setLayoutParams(params);
@ -589,42 +598,42 @@ public class TripRecordingActiveBottomSheet extends MenuBottomSheetDialogFragmen
}
@ColorRes
private static int getActiveTextColorId(boolean nightMode) {
public static int getActiveTextColorId(boolean nightMode) {
return nightMode ? R.color.active_color_primary_dark : R.color.active_color_primary_light;
}
@ColorRes
private static int getSecondaryTextColorId(boolean nightMode) {
public static int getSecondaryTextColorId(boolean nightMode) {
return nightMode ? R.color.text_color_secondary_dark : R.color.text_color_secondary_light;
}
@ColorRes
private static int getActiveIconColorId(boolean nightMode) {
public static int getActiveIconColorId(boolean nightMode) {
return nightMode ? R.color.icon_color_active_dark : R.color.icon_color_active_light;
}
@ColorRes
private static int getSecondaryIconColorId(boolean nightMode) {
public static int getSecondaryIconColorId(boolean nightMode) {
return nightMode ? R.color.icon_color_secondary_dark : R.color.icon_color_secondary_light;
}
@ColorRes
private static int getActiveButtonColorId(boolean nightMode) {
public static int getActiveButtonColorId(boolean nightMode) {
return nightMode ? R.color.active_buttons_and_links_bg_pressed_dark : R.color.active_buttons_and_links_bg_pressed_light;
}
@ColorRes
private static int getInactiveButtonColorId(boolean nightMode) {
public static int getInactiveButtonColorId(boolean nightMode) {
return nightMode ? R.color.inactive_buttons_and_links_bg_dark : R.color.inactive_buttons_and_links_bg_light;
}
@ColorRes
private static int getOsmandIconColorId(boolean nightMode) {
public static int getOsmandIconColorId(boolean nightMode) {
return nightMode ? R.color.icon_color_osmand_dark : R.color.icon_color_osmand_light;
}
@ColorRes
private static int getPressedColorId(boolean nightMode) {
public static int getPressedColorId(boolean nightMode) {
return nightMode ? R.color.active_buttons_and_links_text_dark : R.color.active_buttons_and_links_text_light;
}

View file

@ -1,6 +1,7 @@
package net.osmand.plus.track;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Handler;
import android.view.LayoutInflater;
import android.view.View;
@ -250,7 +251,11 @@ public class GpxBlockStatisticsBuilder {
holder.valueText.setTextColor(activeColor);
holder.titleText.setText(item.title);
holder.titleText.setTextColor(app.getResources().getColor(R.color.text_color_secondary_light));
holder.titleText.setWidth(calculateWidthWithin(item.title, item.value));
float letterSpacing = 0.00f;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
letterSpacing = Math.max(holder.valueText.getLetterSpacing(), holder.titleText.getLetterSpacing());
}
holder.titleText.setMinWidth(calculateWidthWithin(letterSpacing, item.title, item.value));
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@ -283,8 +288,11 @@ public class GpxBlockStatisticsBuilder {
notifyDataSetChanged();
}
public int calculateWidthWithin(String... texts) {
public int calculateWidthWithin(float letterSpacing, String... texts) {
int textWidth = AndroidUtils.getTextMaxWidth(textSize, Arrays.asList(texts));
if (letterSpacing != 0.00f) {
textWidth += Math.ceil(textWidth * letterSpacing);
}
return Math.min(maxWidthPx, Math.max(minWidthPx, textWidth));
}
}

View file

@ -385,7 +385,7 @@ public class TrackAppearanceFragment extends ContextMenuScrollFragment implement
if (target instanceof TripRecordingBottomSheet) {
((TripRecordingBottomSheet) target).show();
} else if (target instanceof TripRecordingActiveBottomSheet) {
((TripRecordingActiveBottomSheet) target).show();
((TripRecordingActiveBottomSheet) target).show(true);
}
}