fix crash after screen rotation;
remove unnecessary layout for buttons; some other code fixes;
This commit is contained in:
parent
77c4b12259
commit
d379b6cf4a
4 changed files with 204 additions and 262 deletions
|
@ -1,69 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
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">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/button_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:duplicateParentState="true"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal"
|
||||
android:paddingStart="@dimen/content_padding_small"
|
||||
android:paddingLeft="@dimen/content_padding_small"
|
||||
android:paddingTop="@dimen/text_margin_small"
|
||||
android:paddingEnd="@dimen/content_padding_small"
|
||||
android:paddingRight="@dimen/content_padding_small"
|
||||
android:paddingBottom="@dimen/text_margin_small"
|
||||
tools:background="@drawable/dlg_btn_secondary_dark"
|
||||
tools:ignore="UselessParent">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:duplicateParentState="true"
|
||||
android:orientation="vertical">
|
||||
|
||||
<net.osmand.plus.widgets.TextViewEx
|
||||
android:id="@+id/button_text"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:duplicateParentState="true"
|
||||
android:letterSpacing="@dimen/description_letter_spacing"
|
||||
android:textSize="@dimen/default_desc_text_size"
|
||||
osmand:typeface="@string/font_roboto_medium"
|
||||
tools:text="Title"
|
||||
tools:textColor="@color/text_color_secondary_light" />
|
||||
|
||||
<net.osmand.plus.widgets.TextViewEx
|
||||
android:id="@+id/desc"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:duplicateParentState="true"
|
||||
android:letterSpacing="@dimen/description_letter_spacing"
|
||||
android:textColor="@color/text_color_secondary_light"
|
||||
android:textSize="@dimen/default_desc_text_size"
|
||||
android:visibility="gone"
|
||||
osmand:typeface="@string/font_roboto_medium"
|
||||
tools:text="Description"
|
||||
tools:visibility="visible" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<androidx.appcompat.widget.AppCompatImageView
|
||||
android:id="@+id/icon"
|
||||
android:layout_width="@dimen/map_widget_icon"
|
||||
android:layout_height="@dimen/map_widget_icon"
|
||||
android:layout_marginStart="@dimen/context_menu_padding_margin_large"
|
||||
android:layout_marginLeft="@dimen/context_menu_padding_margin_large"
|
||||
android:duplicateParentState="true"
|
||||
tools:srcCompat="@drawable/ic_action_appearance"
|
||||
tools:tint="@color/icon_color_secondary_light" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</FrameLayout>
|
|
@ -1,10 +1,10 @@
|
|||
package net.osmand.plus.monitoring;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
|
@ -13,17 +13,16 @@ import net.osmand.plus.UiUtilities;
|
|||
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
|
||||
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
|
||||
import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithDescription;
|
||||
import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerSpaceItem;
|
||||
import net.osmand.plus.monitoring.TripRecordingActiveBottomSheet.ItemType;
|
||||
import net.osmand.plus.widgets.TextViewEx;
|
||||
|
||||
import androidx.annotation.DimenRes;
|
||||
import androidx.annotation.DrawableRes;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.StringRes;
|
||||
import androidx.appcompat.widget.AppCompatImageView;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
|
||||
public class ClearRecordedDataBottomSheetFragment extends MenuBottomSheetDialogFragment implements View.OnClickListener {
|
||||
public class ClearRecordedDataBottomSheetFragment extends MenuBottomSheetDialogFragment {
|
||||
|
||||
public static final String TAG = ClearRecordedDataBottomSheetFragment.class.getSimpleName();
|
||||
|
||||
|
@ -32,6 +31,9 @@ public class ClearRecordedDataBottomSheetFragment extends MenuBottomSheetDialogF
|
|||
@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);
|
||||
|
||||
items.add(new BottomSheetItemWithDescription.Builder()
|
||||
.setDescription(app.getString(R.string.clear_recorded_data_warning))
|
||||
|
@ -41,64 +43,65 @@ public class ClearRecordedDataBottomSheetFragment extends MenuBottomSheetDialogF
|
|||
.setLayoutId(R.layout.bottom_sheet_item_title_with_description)
|
||||
.create());
|
||||
|
||||
LayoutInflater inflater = UiUtilities.getInflater(getContext(), nightMode);
|
||||
items.add(new DividerSpaceItem(app, verticalBig));
|
||||
|
||||
items.add(new BaseBottomSheetItem.Builder()
|
||||
.setCustomView(setupBtn(inflater, ButtonType.CLEAR))
|
||||
.setOnClickListener(this)
|
||||
.setCustomView(setupBtn(inflater, ItemType.CLEAR_DATA))
|
||||
.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
app.getSavingTrackHelper().clearRecordedData(true);
|
||||
dismiss();
|
||||
}
|
||||
})
|
||||
.create());
|
||||
|
||||
items.add(new DividerSpaceItem(app, verticalBig));
|
||||
|
||||
items.add(new BaseBottomSheetItem.Builder()
|
||||
.setCustomView(setupBtn(inflater, ButtonType.CANCEL))
|
||||
.setOnClickListener(this)
|
||||
.setCustomView(setupBtn(inflater, ItemType.CANCEL))
|
||||
.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
dismiss();
|
||||
}
|
||||
})
|
||||
.create());
|
||||
|
||||
items.add(new DividerSpaceItem(app, verticalSmall));
|
||||
}
|
||||
|
||||
private View setupBtn(LayoutInflater inflater, ButtonType type) {
|
||||
View button = inflater.inflate(R.layout.bottom_sheet_item_button_with_icon, null);
|
||||
private View setupBtn(LayoutInflater inflater, ItemType type) {
|
||||
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);
|
||||
|
||||
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
|
||||
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT);
|
||||
int horizontal = context.getResources().getDimensionPixelSize(R.dimen.content_padding);
|
||||
int top = context.getResources().getDimensionPixelSize(type.topMarginRes);
|
||||
int bottom = context.getResources().getDimensionPixelSize(R.dimen.content_padding_small);
|
||||
params.setMargins(horizontal, top, horizontal, bottom);
|
||||
params.setMargins(horizontal, 0, horizontal, 0);
|
||||
button.setLayoutParams(params);
|
||||
|
||||
UiUtilities.setupDialogButton(nightMode, button, type.effect, type.titleId);
|
||||
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.effect == UiUtilities.DialogButtonType.SECONDARY_HARMFUL) {
|
||||
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);
|
||||
icon.setImageDrawable(getIcon(type.iconRes, colorRes));
|
||||
icon.setImageDrawable(getIcon(type.getIconId(), colorRes));
|
||||
|
||||
return button;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Object o = v.getTag();
|
||||
if (!(o instanceof ButtonType)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ButtonType tag = (ButtonType) o;
|
||||
if (tag == ButtonType.CLEAR) {
|
||||
app.getSavingTrackHelper().clearRecordedData(true);
|
||||
}
|
||||
dismiss();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
|
@ -117,26 +120,6 @@ public class ClearRecordedDataBottomSheetFragment extends MenuBottomSheetDialogF
|
|||
}
|
||||
}
|
||||
|
||||
enum ButtonType {
|
||||
CLEAR(R.string.clear_recorded_data, R.drawable.ic_action_delete_dark, R.dimen.dialog_content_margin, UiUtilities.DialogButtonType.SECONDARY_HARMFUL),
|
||||
CANCEL(R.string.shared_string_cancel, R.drawable.ic_action_close, R.dimen.content_padding_small, UiUtilities.DialogButtonType.SECONDARY);
|
||||
|
||||
@StringRes
|
||||
private final int titleId;
|
||||
@DrawableRes
|
||||
private final int iconRes;
|
||||
@DimenRes
|
||||
private final int topMarginRes;
|
||||
private final UiUtilities.DialogButtonType effect;
|
||||
|
||||
ButtonType(int titleId, int iconRes, int topMarginRes, UiUtilities.DialogButtonType effect) {
|
||||
this.titleId = titleId;
|
||||
this.iconRes = iconRes;
|
||||
this.topMarginRes = topMarginRes;
|
||||
this.effect = effect;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean hideButtonsContainer() {
|
||||
return true;
|
||||
|
|
|
@ -4,6 +4,7 @@ import android.content.Context;
|
|||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
|
@ -15,18 +16,17 @@ import net.osmand.plus.activities.MapActivity;
|
|||
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
|
||||
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
|
||||
import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithDescription;
|
||||
import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerSpaceItem;
|
||||
import net.osmand.plus.monitoring.TripRecordingActiveBottomSheet.ItemType;
|
||||
import net.osmand.plus.settings.backend.OsmandSettings;
|
||||
import net.osmand.plus.widgets.TextViewEx;
|
||||
|
||||
import androidx.annotation.DimenRes;
|
||||
import androidx.annotation.DrawableRes;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.StringRes;
|
||||
import androidx.appcompat.widget.AppCompatImageView;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
|
||||
public class StopTrackRecordingBottomFragment extends MenuBottomSheetDialogFragment implements View.OnClickListener {
|
||||
public class StopTrackRecordingBottomFragment extends MenuBottomSheetDialogFragment {
|
||||
|
||||
public static final String TAG = StopTrackRecordingBottomFragment.class.getSimpleName();
|
||||
|
||||
|
@ -34,7 +34,7 @@ public class StopTrackRecordingBottomFragment extends MenuBottomSheetDialogFragm
|
|||
private MapActivity mapActivity;
|
||||
private OsmandSettings settings;
|
||||
private OsmandMonitoringPlugin plugin;
|
||||
private ButtonType tag = ButtonType.CANCEL;
|
||||
private ItemType tag = ItemType.CANCEL;
|
||||
|
||||
public void setMapActivity(MapActivity mapActivity) {
|
||||
this.mapActivity = mapActivity;
|
||||
|
@ -45,6 +45,9 @@ public class StopTrackRecordingBottomFragment extends MenuBottomSheetDialogFragm
|
|||
app = requiredMyApplication();
|
||||
settings = app.getSettings();
|
||||
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);
|
||||
|
||||
items.add(new BottomSheetItemWithDescription.Builder()
|
||||
.setDescription(app.getString(R.string.track_recording_description))
|
||||
|
@ -54,52 +57,86 @@ public class StopTrackRecordingBottomFragment extends MenuBottomSheetDialogFragm
|
|||
.setLayoutId(R.layout.bottom_sheet_item_title_with_description)
|
||||
.create());
|
||||
|
||||
LayoutInflater inflater = UiUtilities.getInflater(getContext(), nightMode);
|
||||
items.add(new DividerSpaceItem(app, verticalBig));
|
||||
|
||||
items.add(new BaseBottomSheetItem.Builder()
|
||||
.setCustomView(setupButton(inflater, ButtonType.STOP_AND_DISCARD))
|
||||
.setOnClickListener(this)
|
||||
.setCustomView(setupButton(inflater, ItemType.STOP_AND_DISCARD))
|
||||
.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
tag = ItemType.STOP_AND_DISCARD;
|
||||
if (plugin != null && settings.SAVE_GLOBAL_TRACK_TO_GPX.get()) {
|
||||
plugin.stopRecording();
|
||||
app.getNotificationHelper().refreshNotifications();
|
||||
}
|
||||
app.getSavingTrackHelper().clearRecordedData(true);
|
||||
dismiss();
|
||||
}
|
||||
})
|
||||
.create());
|
||||
|
||||
items.add(new BaseBottomSheetItem.Builder()
|
||||
.setCustomView(setupButton(inflater, ButtonType.SAVE_AND_STOP))
|
||||
.setOnClickListener(this)
|
||||
.create());
|
||||
items.add(new DividerSpaceItem(app, verticalBig));
|
||||
|
||||
items.add(new BaseBottomSheetItem.Builder()
|
||||
.setCustomView(setupButton(inflater, ButtonType.CANCEL))
|
||||
.setOnClickListener(this)
|
||||
.setCustomView(setupButton(inflater, ItemType.SAVE_AND_STOP))
|
||||
.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
tag = ItemType.SAVE_AND_STOP;
|
||||
if (plugin != null && settings.SAVE_GLOBAL_TRACK_TO_GPX.get()) {
|
||||
plugin.saveCurrentTrack(null, mapActivity);
|
||||
app.getNotificationHelper().refreshNotifications();
|
||||
}
|
||||
dismiss();
|
||||
}
|
||||
})
|
||||
.create());
|
||||
|
||||
items.add(new DividerSpaceItem(app, verticalSmall));
|
||||
|
||||
items.add(new BaseBottomSheetItem.Builder()
|
||||
.setCustomView(setupButton(inflater, ItemType.CANCEL))
|
||||
.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
tag = ItemType.CANCEL;
|
||||
dismiss();
|
||||
}
|
||||
})
|
||||
.create());
|
||||
|
||||
items.add(new DividerSpaceItem(app, verticalSmall));
|
||||
}
|
||||
|
||||
private View setupButton(LayoutInflater inflater, ButtonType type) {
|
||||
View button = inflater.inflate(R.layout.bottom_sheet_item_button_with_icon, null);
|
||||
private View setupButton(LayoutInflater inflater, ItemType type) {
|
||||
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);
|
||||
|
||||
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
|
||||
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT);
|
||||
int horizontal = context.getResources().getDimensionPixelSize(R.dimen.content_padding);
|
||||
int top = context.getResources().getDimensionPixelSize(type.topMarginRes);
|
||||
int bottom = context.getResources().getDimensionPixelSize(R.dimen.content_padding_small);
|
||||
params.setMargins(horizontal, top, horizontal, bottom);
|
||||
params.setMargins(horizontal, 0, horizontal, 0);
|
||||
button.setLayoutParams(params);
|
||||
|
||||
UiUtilities.setupDialogButton(nightMode, button, type.effect, type.titleId);
|
||||
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.effect == DialogButtonType.SECONDARY_HARMFUL) {
|
||||
if (type.getEffect() == 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);
|
||||
icon.setImageDrawable(getIcon(type.iconRes, colorRes));
|
||||
icon.setImageDrawable(getIcon(type.getIconId(), colorRes));
|
||||
|
||||
if (type == ButtonType.STOP_AND_DISCARD) {
|
||||
if (type == ItemType.STOP_AND_DISCARD) {
|
||||
int size = context.getResources().getDimensionPixelSize(R.dimen.map_widget_height);
|
||||
LinearLayout.LayoutParams iconParams = new LinearLayout.LayoutParams(size, size);
|
||||
icon.setLayoutParams(iconParams);
|
||||
|
@ -108,29 +145,6 @@ public class StopTrackRecordingBottomFragment extends MenuBottomSheetDialogFragm
|
|||
return button;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Object o = v.getTag();
|
||||
if (!(o instanceof ButtonType)) {
|
||||
return;
|
||||
}
|
||||
|
||||
tag = (ButtonType) o;
|
||||
if (tag == ButtonType.STOP_AND_DISCARD) {
|
||||
if (plugin != null && settings.SAVE_GLOBAL_TRACK_TO_GPX.get()) {
|
||||
plugin.stopRecording();
|
||||
app.getNotificationHelper().refreshNotifications();
|
||||
}
|
||||
app.getSavingTrackHelper().clearRecordedData(true);
|
||||
} else if (tag == ButtonType.SAVE_AND_STOP) {
|
||||
if (plugin != null && settings.SAVE_GLOBAL_TRACK_TO_GPX.get()) {
|
||||
plugin.saveCurrentTrack(null, mapActivity);
|
||||
app.getNotificationHelper().refreshNotifications();
|
||||
}
|
||||
}
|
||||
dismiss();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
|
@ -143,7 +157,7 @@ public class StopTrackRecordingBottomFragment extends MenuBottomSheetDialogFragm
|
|||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
if (tag == ButtonType.CANCEL) {
|
||||
if (tag == ItemType.CANCEL) {
|
||||
Fragment target = getTargetFragment();
|
||||
if (target instanceof TripRecordingActiveBottomSheet) {
|
||||
((TripRecordingActiveBottomSheet) target).show();
|
||||
|
@ -151,27 +165,6 @@ public class StopTrackRecordingBottomFragment extends MenuBottomSheetDialogFragm
|
|||
}
|
||||
}
|
||||
|
||||
enum ButtonType {
|
||||
STOP_AND_DISCARD(R.string.track_recording_stop_without_saving, R.drawable.ic_action_rec_stop, R.dimen.dialog_content_margin, DialogButtonType.SECONDARY_HARMFUL),
|
||||
SAVE_AND_STOP(R.string.track_recording_save_and_stop, R.drawable.ic_action_save_to_file, R.dimen.content_padding_small, DialogButtonType.SECONDARY),
|
||||
CANCEL(R.string.shared_string_cancel, R.drawable.ic_action_close, R.dimen.zero, DialogButtonType.SECONDARY);
|
||||
|
||||
@StringRes
|
||||
private final int titleId;
|
||||
@DrawableRes
|
||||
private final int iconRes;
|
||||
@DimenRes
|
||||
private final int topMarginRes;
|
||||
private final DialogButtonType effect;
|
||||
|
||||
ButtonType(int titleId, int iconRes, int topMarginRes, DialogButtonType type) {
|
||||
this.titleId = titleId;
|
||||
this.iconRes = iconRes;
|
||||
this.topMarginRes = topMarginRes;
|
||||
this.effect = type;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean hideButtonsContainer() {
|
||||
return true;
|
||||
|
|
|
@ -42,6 +42,7 @@ 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;
|
||||
|
@ -67,6 +68,7 @@ public class TripRecordingActiveBottomSheet extends MenuBottomSheetDialogFragmen
|
|||
|
||||
public static final String TAG = TripRecordingActiveBottomSheet.class.getSimpleName();
|
||||
private static final Log log = PlatformUtil.getLog(TripRecordingActiveBottomSheet.class);
|
||||
private static final String UPDATE_CURRENT_GPX_FILE = "update_current_gpx_file";
|
||||
|
||||
private OsmandApplication app;
|
||||
private OsmandSettings settings;
|
||||
|
@ -137,6 +139,11 @@ public class TripRecordingActiveBottomSheet extends MenuBottomSheetDialogFragmen
|
|||
updateStatus();
|
||||
|
||||
RecyclerView statBlocks = itemView.findViewById(R.id.block_statistics);
|
||||
if (savedInstanceState != null) {
|
||||
if (savedInstanceState.containsKey(UPDATE_CURRENT_GPX_FILE) && savedInstanceState.getBoolean(UPDATE_CURRENT_GPX_FILE)) {
|
||||
selectedGpxFile = app.getSavingTrackHelper().getCurrentTrack();
|
||||
}
|
||||
}
|
||||
blockStatisticsBuilder = new GpxBlockStatisticsBuilder(app, selectedGpxFile);
|
||||
blockStatisticsBuilder.setBlocksView(statBlocks);
|
||||
blockStatisticsBuilder.setBlocksClickable(false);
|
||||
|
@ -262,17 +269,29 @@ 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);
|
||||
ItemType status = searchingGPS() ? ItemType.SEARCHING_GPS : !wasTrackMonitored() ? ItemType.ON_PAUSE : ItemType.RECORDING;
|
||||
statusTitle.setText(status.getTitleId());
|
||||
Integer titleId = status.getTitleId();
|
||||
if (titleId != null) {
|
||||
statusTitle.setText(titleId);
|
||||
}
|
||||
int colorText = status.equals(ItemType.SEARCHING_GPS) ? getSecondaryTextColorId(nightMode) : getOsmandIconColorId(nightMode);
|
||||
statusTitle.setTextColor(ContextCompat.getColor(app, colorText));
|
||||
int colorDrawable = ContextCompat.getColor(app,
|
||||
status.equals(ItemType.SEARCHING_GPS) ? getSecondaryIconColorId(nightMode) : getOsmandIconColorId(nightMode));
|
||||
Drawable statusDrawable = UiUtilities.tintDrawable(AppCompatResources.getDrawable(app, status.getIconId()), colorDrawable);
|
||||
statusIcon.setImageDrawable(statusDrawable);
|
||||
Integer iconId = status.getIconId();
|
||||
if (iconId != null) {
|
||||
int colorDrawable = ContextCompat.getColor(app,
|
||||
status.equals(ItemType.SEARCHING_GPS) ? getSecondaryIconColorId(nightMode) : getOsmandIconColorId(nightMode));
|
||||
Drawable statusDrawable = UiUtilities.tintDrawable(AppCompatResources.getDrawable(app, iconId), colorDrawable);
|
||||
statusIcon.setImageDrawable(statusDrawable);
|
||||
}
|
||||
}
|
||||
|
||||
private void createItem(View view, ItemType type, boolean enabled, @Nullable String description) {
|
||||
|
@ -281,13 +300,14 @@ public class TripRecordingActiveBottomSheet extends MenuBottomSheetDialogFragmen
|
|||
|
||||
AppCompatImageView icon = view.findViewById(R.id.icon);
|
||||
if (icon != null) {
|
||||
type.setTintedIcon(icon, app, enabled, false, nightMode);
|
||||
setTintedIcon(icon, app, enabled, false, nightMode, type);
|
||||
}
|
||||
|
||||
TextView title = view.findViewById(R.id.button_text);
|
||||
if (title != null) {
|
||||
title.setText(type.getTitleId());
|
||||
type.setTextColor(title, app, enabled, false, nightMode);
|
||||
Integer titleId = type.getTitleId();
|
||||
if (title != null && titleId != null) {
|
||||
title.setText(titleId);
|
||||
setTextColor(title, app, enabled, false, nightMode, type);
|
||||
}
|
||||
|
||||
TextViewEx desc = view.findViewById(R.id.desc);
|
||||
|
@ -295,13 +315,15 @@ public class TripRecordingActiveBottomSheet extends MenuBottomSheetDialogFragmen
|
|||
boolean isShowDesc = !Algorithms.isBlank(description);
|
||||
int marginDesc = isShowDesc ? 0 : app.getResources().getDimensionPixelSize(R.dimen.context_menu_padding_margin_medium);
|
||||
AndroidUiHelper.updateVisibility(desc, isShowDesc);
|
||||
UiUtilities.setMargins(title, 0, marginDesc, 0, marginDesc);
|
||||
if (title != null) {
|
||||
UiUtilities.setMargins(title, 0, marginDesc, 0, marginDesc);
|
||||
}
|
||||
desc.setText(description);
|
||||
type.setTextColor(desc, app, false, false, nightMode);
|
||||
setTextColor(desc, app, false, false, nightMode, type);
|
||||
}
|
||||
|
||||
setItemBackgroundInactive(button != null ? button : (LinearLayout) view, app, nightMode);
|
||||
type.changeOnTouch(button != null ? button : (LinearLayout) view, icon, title, app, enabled, nightMode);
|
||||
changeOnTouch(button != null ? button : (LinearLayout) view, icon, title, app, enabled, nightMode, type);
|
||||
}
|
||||
|
||||
private String getTimeTrackSaved() {
|
||||
|
@ -457,89 +479,102 @@ public class TripRecordingActiveBottomSheet extends MenuBottomSheetDialogFragmen
|
|||
view.setBackgroundDrawable(background);
|
||||
}
|
||||
|
||||
enum ItemType {
|
||||
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);
|
||||
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);
|
||||
|
||||
@StringRes
|
||||
private final Integer titleId;
|
||||
@DrawableRes
|
||||
private final Integer iconId;
|
||||
private final DialogButtonType effect;
|
||||
|
||||
ItemType(@Nullable @StringRes Integer titleId, @Nullable @DrawableRes Integer iconId) {
|
||||
ItemType(@Nullable @StringRes Integer titleId, @Nullable @DrawableRes Integer iconId, @Nullable DialogButtonType effect) {
|
||||
this.titleId = titleId;
|
||||
this.iconId = iconId;
|
||||
this.effect = effect;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Integer getTitleId() {
|
||||
return titleId;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Integer getIconId() {
|
||||
return iconId;
|
||||
}
|
||||
|
||||
public void setTextColor(TextView tv, Context context, boolean enabled, boolean pressed, boolean nightMode) {
|
||||
if (tv != null) {
|
||||
tv.setTextColor(ContextCompat.getColor(context,
|
||||
enabled ? pressed ? getPressedColorId(nightMode)
|
||||
: this == ItemType.CLEAR_DATA ? R.color.color_osm_edit_delete
|
||||
: getActiveTextColorId(nightMode) : getSecondaryTextColorId(nightMode)));
|
||||
@Nullable
|
||||
public DialogButtonType getEffect() {
|
||||
return effect;
|
||||
}
|
||||
}
|
||||
|
||||
public void setTextColor(TextView tv, Context context, boolean enabled, boolean pressed, boolean nightMode, ItemType type) {
|
||||
if (tv != null) {
|
||||
tv.setTextColor(ContextCompat.getColor(context,
|
||||
enabled ? pressed ? getPressedColorId(nightMode)
|
||||
: type == ItemType.CLEAR_DATA ? R.color.color_osm_edit_delete
|
||||
: getActiveTextColorId(nightMode) : getSecondaryTextColorId(nightMode)));
|
||||
}
|
||||
}
|
||||
|
||||
public void setTintedIcon(AppCompatImageView iv, Context context, boolean enabled, boolean pressed, boolean nightMode, ItemType type) {
|
||||
Integer iconId = type.getIconId();
|
||||
if (iv != null && iconId != null) {
|
||||
Drawable icon = AppCompatResources.getDrawable(context, iconId);
|
||||
int iconColor = enabled ? pressed ? getPressedColorId(nightMode)
|
||||
: type == ItemType.CLEAR_DATA ? R.color.color_osm_edit_delete
|
||||
: getActiveIconColorId(nightMode) : getSecondaryIconColorId(nightMode);
|
||||
Drawable tintedIcon = UiUtilities.tintDrawable(icon, ContextCompat.getColor(context, iconColor));
|
||||
iv.setImageDrawable(tintedIcon);
|
||||
if (type == ItemType.STOP) {
|
||||
int stopSize = iv.getResources().getDimensionPixelSize(R.dimen.bottom_sheet_icon_margin_large);
|
||||
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(stopSize, stopSize);
|
||||
iv.setLayoutParams(params);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setTintedIcon(AppCompatImageView iv, Context context, boolean enabled, boolean pressed, boolean nightMode) {
|
||||
if (iv != null) {
|
||||
Drawable icon = AppCompatResources.getDrawable(context, iconId);
|
||||
int iconColor = enabled ? pressed ? getPressedColorId(nightMode)
|
||||
: this == ItemType.CLEAR_DATA ? R.color.color_osm_edit_delete
|
||||
: getActiveIconColorId(nightMode) : getSecondaryIconColorId(nightMode);
|
||||
Drawable tintedIcon = UiUtilities.tintDrawable(icon, ContextCompat.getColor(context, iconColor));
|
||||
iv.setImageDrawable(tintedIcon);
|
||||
if (this == ItemType.STOP) {
|
||||
int stopSize = iv.getResources().getDimensionPixelSize(R.dimen.bottom_sheet_icon_margin_large);
|
||||
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(stopSize, stopSize);
|
||||
iv.setLayoutParams(params);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("ClickableViewAccessibility")
|
||||
private void changeOnTouch(final LinearLayout button, @Nullable final AppCompatImageView iv, @Nullable final TextView tv,
|
||||
final Context context, final boolean enabled, final boolean nightMode) {
|
||||
button.setOnTouchListener(new View.OnTouchListener() {
|
||||
@Override
|
||||
public boolean onTouch(View v, MotionEvent event) {
|
||||
if (enabled) {
|
||||
switch (event.getAction()) {
|
||||
case MotionEvent.ACTION_DOWN: {
|
||||
setItemBackgroundActive(button, context, nightMode);
|
||||
setTintedIcon(iv, context, true, true, nightMode);
|
||||
setTextColor(tv, context, true, true, nightMode);
|
||||
break;
|
||||
}
|
||||
case MotionEvent.ACTION_UP:
|
||||
case MotionEvent.ACTION_CANCEL: {
|
||||
setItemBackgroundInactive(button, context, nightMode);
|
||||
setTintedIcon(iv, context, true, false, nightMode);
|
||||
setTextColor(tv, context, true, false, nightMode);
|
||||
break;
|
||||
}
|
||||
@SuppressLint("ClickableViewAccessibility")
|
||||
private void changeOnTouch(final LinearLayout button, @Nullable final AppCompatImageView iv, @Nullable final TextView tv,
|
||||
final Context context, final boolean enabled, final boolean nightMode, final ItemType type) {
|
||||
button.setOnTouchListener(new View.OnTouchListener() {
|
||||
@Override
|
||||
public boolean onTouch(View v, MotionEvent event) {
|
||||
if (enabled) {
|
||||
switch (event.getAction()) {
|
||||
case MotionEvent.ACTION_DOWN: {
|
||||
setItemBackgroundActive(button, context, nightMode);
|
||||
setTintedIcon(iv, context, true, true, nightMode, type);
|
||||
setTextColor(tv, context, true, true, nightMode, type);
|
||||
break;
|
||||
}
|
||||
case MotionEvent.ACTION_UP:
|
||||
case MotionEvent.ACTION_CANCEL: {
|
||||
setItemBackgroundInactive(button, context, nightMode);
|
||||
setTintedIcon(iv, context, true, false, nightMode, type);
|
||||
setTextColor(tv, context, true, false, nightMode, type);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ColorRes
|
||||
|
|
Loading…
Reference in a new issue