Merge remote-tracking branch 'origin/trip_recording' into trip_recording_graphs
# Conflicts: # OsmAnd/src/net/osmand/plus/monitoring/MonitoringSettingsFragment.java # OsmAnd/src/net/osmand/plus/monitoring/TripRecordingBottomFragment.java
This commit is contained in:
commit
bb1aef0862
8 changed files with 105 additions and 124 deletions
|
@ -25,6 +25,7 @@ import com.google.android.material.slider.Slider;
|
||||||
|
|
||||||
import net.osmand.AndroidUtils;
|
import net.osmand.AndroidUtils;
|
||||||
import net.osmand.Location;
|
import net.osmand.Location;
|
||||||
|
import net.osmand.PlatformUtil;
|
||||||
import net.osmand.ValueHolder;
|
import net.osmand.ValueHolder;
|
||||||
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
|
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
|
||||||
import net.osmand.plus.NavigationService;
|
import net.osmand.plus.NavigationService;
|
||||||
|
@ -48,6 +49,8 @@ import net.osmand.plus.views.layers.MapInfoLayer;
|
||||||
import net.osmand.plus.views.mapwidgets.widgets.TextInfoWidget;
|
import net.osmand.plus.views.mapwidgets.widgets.TextInfoWidget;
|
||||||
import net.osmand.util.Algorithms;
|
import net.osmand.util.Algorithms;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.lang.ref.WeakReference;
|
import java.lang.ref.WeakReference;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
@ -57,6 +60,7 @@ import static net.osmand.plus.UiUtilities.CompoundButtonType.PROFILE_DEPENDENT;
|
||||||
|
|
||||||
public class OsmandMonitoringPlugin extends OsmandPlugin {
|
public class OsmandMonitoringPlugin extends OsmandPlugin {
|
||||||
|
|
||||||
|
private static final Log LOG = PlatformUtil.getLog(OsmandMonitoringPlugin.class);
|
||||||
public static final String ID = "osmand.monitoring";
|
public static final String ID = "osmand.monitoring";
|
||||||
public final static String OSMAND_SAVE_SERVICE_ACTION = "OSMAND_SAVE_SERVICE_ACTION";
|
public final static String OSMAND_SAVE_SERVICE_ACTION = "OSMAND_SAVE_SERVICE_ACTION";
|
||||||
public static final int REQUEST_LOCATION_PERMISSION_FOR_GPX_RECORDING = 208;
|
public static final int REQUEST_LOCATION_PERMISSION_FOR_GPX_RECORDING = 208;
|
||||||
|
@ -470,12 +474,10 @@ public class OsmandMonitoringPlugin extends OsmandPlugin {
|
||||||
try {
|
try {
|
||||||
SavingTrackHelper helper = app.getSavingTrackHelper();
|
SavingTrackHelper helper = app.getSavingTrackHelper();
|
||||||
SaveGpxResult result = helper.saveDataToGpx(app.getAppCustomization().getTracksDir());
|
SaveGpxResult result = helper.saveDataToGpx(app.getAppCustomization().getTracksDir());
|
||||||
if (stopRecording) {
|
helper.close();
|
||||||
helper.close();
|
|
||||||
}
|
|
||||||
return result;
|
return result;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
LOG.error(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,6 +42,7 @@ import net.osmand.plus.OsmandPlugin;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.UiUtilities;
|
import net.osmand.plus.UiUtilities;
|
||||||
import net.osmand.plus.activities.MapActivity;
|
import net.osmand.plus.activities.MapActivity;
|
||||||
|
import net.osmand.plus.activities.SavingTrackHelper;
|
||||||
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
|
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
|
||||||
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
|
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
|
||||||
import net.osmand.plus.helpers.AndroidUiHelper;
|
import net.osmand.plus.helpers.AndroidUiHelper;
|
||||||
|
@ -76,12 +77,12 @@ public class TripRecordingBottomFragment extends MenuBottomSheetDialogFragment i
|
||||||
|
|
||||||
public static final String TAG = TripRecordingBottomFragment.class.getSimpleName();
|
public static final String TAG = TripRecordingBottomFragment.class.getSimpleName();
|
||||||
private static final Log LOG = PlatformUtil.getLog(TripRecordingBottomFragment.class);
|
private static final Log LOG = PlatformUtil.getLog(TripRecordingBottomFragment.class);
|
||||||
private static final String SAVE_CURRENT_GPX_FILE = "save_current_gpx_file";
|
|
||||||
public static final String UPDATE_TRACK_ICON = "update_track_icon";
|
public static final String UPDATE_TRACK_ICON = "update_track_icon";
|
||||||
private static final int GPS_UPDATE_INTERVAL = 1000;
|
private static final int GPS_UPDATE_INTERVAL = 1000;
|
||||||
|
|
||||||
private OsmandApplication app;
|
private OsmandApplication app;
|
||||||
private OsmandSettings settings;
|
private OsmandSettings settings;
|
||||||
|
private SavingTrackHelper helper;
|
||||||
private OsmandMonitoringPlugin plugin;
|
private OsmandMonitoringPlugin plugin;
|
||||||
|
|
||||||
private View statusContainer;
|
private View statusContainer;
|
||||||
|
@ -106,7 +107,7 @@ public class TripRecordingBottomFragment extends MenuBottomSheetDialogFragment i
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean hasDataToSave() {
|
private boolean hasDataToSave() {
|
||||||
return app.getSavingTrackHelper().hasDataToSave();
|
return helper.hasDataToSave();
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean searchingGPS() {
|
private boolean searchingGPS() {
|
||||||
|
@ -129,17 +130,12 @@ public class TripRecordingBottomFragment extends MenuBottomSheetDialogFragment i
|
||||||
public void createMenuItems(Bundle savedInstanceState) {
|
public void createMenuItems(Bundle savedInstanceState) {
|
||||||
app = requiredMyApplication();
|
app = requiredMyApplication();
|
||||||
settings = app.getSettings();
|
settings = app.getSettings();
|
||||||
|
helper = app.getSavingTrackHelper();
|
||||||
plugin = OsmandPlugin.getPlugin(OsmandMonitoringPlugin.class);
|
plugin = OsmandPlugin.getPlugin(OsmandMonitoringPlugin.class);
|
||||||
|
selectedGpxFile = helper.getCurrentTrack();
|
||||||
LayoutInflater inflater = UiUtilities.getInflater(getContext(), nightMode);
|
LayoutInflater inflater = UiUtilities.getInflater(getContext(), nightMode);
|
||||||
final FragmentManager fragmentManager = getFragmentManager();
|
final FragmentManager fragmentManager = getFragmentManager();
|
||||||
|
|
||||||
if (savedInstanceState != null) {
|
|
||||||
if (savedInstanceState.containsKey(SAVE_CURRENT_GPX_FILE)
|
|
||||||
&& savedInstanceState.getBoolean(SAVE_CURRENT_GPX_FILE)) {
|
|
||||||
selectedGpxFile = app.getSavingTrackHelper().getCurrentTrack();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
View itemView = inflater.inflate(R.layout.trip_recording_fragment, null, false);
|
View itemView = inflater.inflate(R.layout.trip_recording_fragment, null, false);
|
||||||
items.add(new BaseBottomSheetItem.Builder()
|
items.add(new BaseBottomSheetItem.Builder()
|
||||||
.setCustomView(itemView)
|
.setCustomView(itemView)
|
||||||
|
@ -201,7 +197,7 @@ public class TripRecordingBottomFragment extends MenuBottomSheetDialogFragment i
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
MapActivity mapActivity = getMapActivity();
|
MapActivity mapActivity = getMapActivity();
|
||||||
if (mapActivity != null && plugin != null && app.getSavingTrackHelper().hasDataToSave()) {
|
if (mapActivity != null && plugin != null && hasDataToSave()) {
|
||||||
plugin.saveCurrentTrack(null, mapActivity);
|
plugin.saveCurrentTrack(null, mapActivity);
|
||||||
app.getNotificationHelper().refreshNotifications();
|
app.getNotificationHelper().refreshNotifications();
|
||||||
dismiss();
|
dismiss();
|
||||||
|
@ -215,16 +211,11 @@ public class TripRecordingBottomFragment extends MenuBottomSheetDialogFragment i
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
if (fragmentManager != null) {
|
if (fragmentManager != null) {
|
||||||
TripRecordingOptionsBottomFragment.showInstance(fragmentManager, TripRecordingBottomFragment.this, selectedGpxFile);
|
TripRecordingOptionsBottomFragment.showInstance(fragmentManager, TripRecordingBottomFragment.this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onSaveInstanceState(@NonNull Bundle outState) {
|
|
||||||
super.onSaveInstanceState(outState);
|
|
||||||
outState.putBoolean(SAVE_CURRENT_GPX_FILE, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -404,9 +395,10 @@ public class TripRecordingBottomFragment extends MenuBottomSheetDialogFragment i
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static void setShowTrackItemBackground(View view, boolean checked, boolean nightMode) {
|
public static void setShowTrackItemBackground(View view, boolean checked, boolean nightMode) {
|
||||||
int background = checked ? getActiveTransparentBackgroundId(nightMode) : getInactiveStrokedBackgroundId(nightMode);
|
Drawable background = AppCompatResources.getDrawable(view.getContext(),
|
||||||
view.setBackgroundResource(background);
|
checked ? getActiveTransparentBackgroundId(nightMode) : getInactiveStrokedBackgroundId(nightMode));
|
||||||
|
view.setBackgroundDrawable(background);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createItem(View view, ItemType type) {
|
private void createItem(View view, ItemType type) {
|
||||||
|
@ -458,18 +450,18 @@ public class TripRecordingBottomFragment extends MenuBottomSheetDialogFragment i
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setItemBackground(Context context, boolean nightMode, View 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 (view instanceof CardView) {
|
||||||
|
int colorId = enabled ? getActiveTransparentColorId(nightMode) : getInactiveButtonColorId(nightMode);
|
||||||
|
((CardView) view).setCardBackgroundColor(AndroidUtils.createPressedColorStateList(
|
||||||
|
context, colorId, getActiveTextColorId(nightMode)
|
||||||
|
));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Drawable background = AppCompatResources.getDrawable(context, getInactiveButtonBackgroundId(nightMode));
|
||||||
if (background != null && enabled) {
|
if (background != null && enabled) {
|
||||||
int normalColorId = view instanceof CardView
|
DrawableCompat.setTintList(background, AndroidUtils.createPressedColorStateList(
|
||||||
? getActiveTransparentColorId(nightMode) : getInactiveButtonColorId(nightMode);
|
context, getInactiveButtonColorId(nightMode), getActiveTextColorId(nightMode)
|
||||||
ColorStateList iconColorStateList = AndroidUtils.createPressedColorStateList(
|
));
|
||||||
context, normalColorId, getActiveTextColorId(nightMode)
|
|
||||||
);
|
|
||||||
if (view instanceof CardView) {
|
|
||||||
((CardView) view).setCardBackgroundColor(iconColorStateList);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
DrawableCompat.setTintList(background, iconColorStateList);
|
|
||||||
} else {
|
} else {
|
||||||
UiUtilities.tintDrawable(background, ContextCompat.getColor(context, getInactiveButtonColorId(nightMode)));
|
UiUtilities.tintDrawable(background, ContextCompat.getColor(context, getInactiveButtonColorId(nightMode)));
|
||||||
}
|
}
|
||||||
|
@ -594,6 +586,10 @@ public class TripRecordingBottomFragment extends MenuBottomSheetDialogFragment i
|
||||||
public void openAnalyzeOnMap(GpxDisplayItem gpxItem) {
|
public void openAnalyzeOnMap(GpxDisplayItem gpxItem) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public interface DismissTargetFragment {
|
||||||
|
void dismissTarget();
|
||||||
|
}
|
||||||
|
|
||||||
@ColorRes
|
@ColorRes
|
||||||
public 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;
|
return nightMode ? R.color.active_color_primary_dark : R.color.active_color_primary_light;
|
||||||
|
@ -624,7 +620,7 @@ public class TripRecordingBottomFragment extends MenuBottomSheetDialogFragment i
|
||||||
return nightMode ? R.color.icon_color_osmand_dark : R.color.icon_color_osmand_light;
|
return nightMode ? R.color.icon_color_osmand_dark : R.color.icon_color_osmand_light;
|
||||||
}
|
}
|
||||||
|
|
||||||
@DrawableRes
|
@ColorRes
|
||||||
public static int getActiveTransparentColorId(boolean nightMode) {
|
public static int getActiveTransparentColorId(boolean nightMode) {
|
||||||
return nightMode ? R.color.switch_button_active_dark : R.color.switch_button_active_light;
|
return nightMode ? R.color.switch_button_active_dark : R.color.switch_button_active_light;
|
||||||
}
|
}
|
||||||
|
@ -644,6 +640,11 @@ public class TripRecordingBottomFragment extends MenuBottomSheetDialogFragment i
|
||||||
return nightMode ? R.drawable.btn_background_stroked_inactive_dark : R.drawable.btn_background_stroked_inactive_light;
|
return nightMode ? R.drawable.btn_background_stroked_inactive_dark : R.drawable.btn_background_stroked_inactive_light;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@DrawableRes
|
||||||
|
public static int getInactiveButtonBackgroundId(boolean nightMode) {
|
||||||
|
return nightMode ? R.drawable.btn_background_inactive_dark : R.drawable.btn_background_inactive_light;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean hideButtonsContainer() {
|
protected boolean hideButtonsContainer() {
|
||||||
return true;
|
return true;
|
||||||
|
@ -657,5 +658,4 @@ public class TripRecordingBottomFragment extends MenuBottomSheetDialogFragment i
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,9 +18,8 @@ import androidx.fragment.app.Fragment;
|
||||||
import androidx.fragment.app.FragmentManager;
|
import androidx.fragment.app.FragmentManager;
|
||||||
|
|
||||||
import static net.osmand.AndroidUtils.getPrimaryTextColorId;
|
import static net.osmand.AndroidUtils.getPrimaryTextColorId;
|
||||||
import static net.osmand.plus.monitoring.TripRecordingOptionsBottomFragment.*;
|
|
||||||
|
|
||||||
public class TripRecordingClearDataBottomFragment extends MenuBottomSheetDialogFragment {
|
public class TripRecordingClearDataBottomFragment extends MenuBottomSheetDialogFragment implements TripRecordingBottomFragment.DismissTargetFragment {
|
||||||
|
|
||||||
public static final String TAG = TripRecordingClearDataBottomFragment.class.getSimpleName();
|
public static final String TAG = TripRecordingClearDataBottomFragment.class.getSimpleName();
|
||||||
|
|
||||||
|
@ -41,7 +40,7 @@ public class TripRecordingClearDataBottomFragment extends MenuBottomSheetDialogF
|
||||||
int verticalBig = getResources().getDimensionPixelSize(R.dimen.dialog_content_margin);
|
int verticalBig = getResources().getDimensionPixelSize(R.dimen.dialog_content_margin);
|
||||||
int verticalNormal = getResources().getDimensionPixelSize(R.dimen.content_padding);
|
int verticalNormal = getResources().getDimensionPixelSize(R.dimen.content_padding);
|
||||||
String description = getString(R.string.clear_recorded_data_warning)
|
String description = getString(R.string.clear_recorded_data_warning)
|
||||||
.concat(getString(R.string.lost_data_warning));
|
.concat("\n").concat(getString(R.string.lost_data_warning));
|
||||||
final View buttonClear = createItem(inflater, ItemType.CLEAR_DATA);
|
final View buttonClear = createItem(inflater, ItemType.CLEAR_DATA);
|
||||||
final View buttonCancel = createItem(inflater, ItemType.CANCEL);
|
final View buttonCancel = createItem(inflater, ItemType.CANCEL);
|
||||||
|
|
||||||
|
@ -61,7 +60,7 @@ public class TripRecordingClearDataBottomFragment extends MenuBottomSheetDialogF
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
app.getSavingTrackHelper().clearRecordedData(true);
|
app.getSavingTrackHelper().clearRecordedData(true);
|
||||||
dismiss();
|
dismiss();
|
||||||
dismissTargetDialog(TripRecordingClearDataBottomFragment.this, TripRecordingOptionsBottomFragment.class);
|
dismissTarget();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.create());
|
.create());
|
||||||
|
@ -108,4 +107,11 @@ public class TripRecordingClearDataBottomFragment extends MenuBottomSheetDialogF
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void dismissTarget() {
|
||||||
|
Fragment target = getTargetFragment();
|
||||||
|
if (target instanceof TripRecordingOptionsBottomFragment) {
|
||||||
|
((TripRecordingOptionsBottomFragment) target).dismiss();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,10 +19,9 @@ import androidx.fragment.app.Fragment;
|
||||||
import androidx.fragment.app.FragmentManager;
|
import androidx.fragment.app.FragmentManager;
|
||||||
|
|
||||||
import static net.osmand.AndroidUtils.getPrimaryTextColorId;
|
import static net.osmand.AndroidUtils.getPrimaryTextColorId;
|
||||||
import static net.osmand.plus.monitoring.TripRecordingOptionsBottomFragment.ACTION_STOP_AND_DISCARD;
|
import static net.osmand.plus.monitoring.TripRecordingOptionsBottomFragment.ACTION_STOP_AND_DISMISS;
|
||||||
import static net.osmand.plus.monitoring.TripRecordingOptionsBottomFragment.dismissTargetDialog;
|
|
||||||
|
|
||||||
public class TripRecordingDiscardBottomFragment extends MenuBottomSheetDialogFragment {
|
public class TripRecordingDiscardBottomFragment extends MenuBottomSheetDialogFragment implements TripRecordingBottomFragment.DismissTargetFragment {
|
||||||
|
|
||||||
public static final String TAG = TripRecordingDiscardBottomFragment.class.getSimpleName();
|
public static final String TAG = TripRecordingDiscardBottomFragment.class.getSimpleName();
|
||||||
|
|
||||||
|
@ -43,13 +42,11 @@ public class TripRecordingDiscardBottomFragment extends MenuBottomSheetDialogFra
|
||||||
LayoutInflater inflater = UiUtilities.getInflater(app, nightMode);
|
LayoutInflater inflater = UiUtilities.getInflater(app, nightMode);
|
||||||
int verticalBig = getResources().getDimensionPixelSize(R.dimen.dialog_content_margin);
|
int verticalBig = getResources().getDimensionPixelSize(R.dimen.dialog_content_margin);
|
||||||
int verticalNormal = getResources().getDimensionPixelSize(R.dimen.content_padding);
|
int verticalNormal = getResources().getDimensionPixelSize(R.dimen.content_padding);
|
||||||
String description = getString(R.string.track_recording_description)
|
|
||||||
.concat(getString(R.string.lost_data_warning));
|
|
||||||
final View buttonDiscard = createItem(inflater, ItemType.STOP_AND_DISCARD);
|
final View buttonDiscard = createItem(inflater, ItemType.STOP_AND_DISCARD);
|
||||||
final View buttonCancel = createItem(inflater, ItemType.CANCEL);
|
final View buttonCancel = createItem(inflater, ItemType.CANCEL);
|
||||||
|
|
||||||
items.add(new BottomSheetItemWithDescription.Builder()
|
items.add(new BottomSheetItemWithDescription.Builder()
|
||||||
.setDescription(description)
|
.setDescription(getString(R.string.track_recording_description))
|
||||||
.setDescriptionColorId(getPrimaryTextColorId(nightMode))
|
.setDescriptionColorId(getPrimaryTextColorId(nightMode))
|
||||||
.setTitle(app.getString(R.string.track_recording_title))
|
.setTitle(app.getString(R.string.track_recording_title))
|
||||||
.setLayoutId(R.layout.bottom_sheet_item_title_with_description)
|
.setLayoutId(R.layout.bottom_sheet_item_title_with_description)
|
||||||
|
@ -68,8 +65,14 @@ public class TripRecordingDiscardBottomFragment extends MenuBottomSheetDialogFra
|
||||||
}
|
}
|
||||||
app.getSavingTrackHelper().clearRecordedData(true);
|
app.getSavingTrackHelper().clearRecordedData(true);
|
||||||
dismiss();
|
dismiss();
|
||||||
dismissTargetDialog(TripRecordingDiscardBottomFragment.this,
|
|
||||||
TripRecordingOptionsBottomFragment.class, ACTION_STOP_AND_DISCARD, true);
|
Fragment target = getTargetFragment();
|
||||||
|
if (target != null) {
|
||||||
|
Bundle args = new Bundle();
|
||||||
|
args.putBoolean(ACTION_STOP_AND_DISMISS, true);
|
||||||
|
target.setArguments(args);
|
||||||
|
}
|
||||||
|
dismissTarget();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.create());
|
.create());
|
||||||
|
@ -111,6 +114,14 @@ public class TripRecordingDiscardBottomFragment extends MenuBottomSheetDialogFra
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void dismissTarget() {
|
||||||
|
Fragment target = getTargetFragment();
|
||||||
|
if (target instanceof TripRecordingOptionsBottomFragment) {
|
||||||
|
((TripRecordingOptionsBottomFragment) target).dismiss();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean hideButtonsContainer() {
|
protected boolean hideButtonsContainer() {
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -11,7 +11,6 @@ import android.view.View;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.fragment.app.DialogFragment;
|
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
import androidx.fragment.app.FragmentManager;
|
import androidx.fragment.app.FragmentManager;
|
||||||
|
|
||||||
|
@ -36,11 +35,10 @@ import net.osmand.util.Algorithms;
|
||||||
|
|
||||||
import static net.osmand.AndroidUtils.getPrimaryTextColorId;
|
import static net.osmand.AndroidUtils.getPrimaryTextColorId;
|
||||||
|
|
||||||
public class TripRecordingOptionsBottomFragment extends MenuBottomSheetDialogFragment {
|
public class TripRecordingOptionsBottomFragment extends MenuBottomSheetDialogFragment implements TripRecordingBottomFragment.DismissTargetFragment {
|
||||||
|
|
||||||
public static final String TAG = TripRecordingOptionsBottomFragment.class.getSimpleName();
|
public static final String TAG = TripRecordingOptionsBottomFragment.class.getSimpleName();
|
||||||
public static final String ACTION_STOP_AND_DISCARD = "action_stop_and_discard";
|
public static final String ACTION_STOP_AND_DISMISS = "action_stop_and_discard";
|
||||||
private static final String SAVE_CURRENT_GPX_FILE = "save_current_gpx_file";
|
|
||||||
private static final int SAVE_UPDATE_INTERVAL = 1000;
|
private static final int SAVE_UPDATE_INTERVAL = 1000;
|
||||||
|
|
||||||
private OsmandApplication app;
|
private OsmandApplication app;
|
||||||
|
@ -72,11 +70,10 @@ public class TripRecordingOptionsBottomFragment extends MenuBottomSheetDialogFra
|
||||||
return settings.SAVE_GLOBAL_TRACK_TO_GPX.get();
|
return settings.SAVE_GLOBAL_TRACK_TO_GPX.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void showInstance(@NonNull FragmentManager fragmentManager, @NonNull Fragment target, SelectedGpxFile selectedGpxFile) {
|
public static void showInstance(@NonNull FragmentManager fragmentManager, @NonNull Fragment target) {
|
||||||
if (!fragmentManager.isStateSaved()) {
|
if (!fragmentManager.isStateSaved()) {
|
||||||
TripRecordingOptionsBottomFragment fragment = new TripRecordingOptionsBottomFragment();
|
TripRecordingOptionsBottomFragment fragment = new TripRecordingOptionsBottomFragment();
|
||||||
fragment.setTargetFragment(target, 0);
|
fragment.setTargetFragment(target, 0);
|
||||||
fragment.setSelectedGpxFile(selectedGpxFile);
|
|
||||||
fragment.show(fragmentManager, TAG);
|
fragment.show(fragmentManager, TAG);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -86,18 +83,12 @@ public class TripRecordingOptionsBottomFragment extends MenuBottomSheetDialogFra
|
||||||
app = requiredMyApplication();
|
app = requiredMyApplication();
|
||||||
settings = app.getSettings();
|
settings = app.getSettings();
|
||||||
helper = app.getSavingTrackHelper();
|
helper = app.getSavingTrackHelper();
|
||||||
|
selectedGpxFile = helper.getCurrentTrack();
|
||||||
LayoutInflater inflater = UiUtilities.getInflater(app, nightMode);
|
LayoutInflater inflater = UiUtilities.getInflater(app, nightMode);
|
||||||
final FragmentManager fragmentManager = getFragmentManager();
|
final FragmentManager fragmentManager = getFragmentManager();
|
||||||
int dp16 = getResources().getDimensionPixelSize(R.dimen.content_padding);
|
int dp16 = getResources().getDimensionPixelSize(R.dimen.content_padding);
|
||||||
int dp36 = getResources().getDimensionPixelSize(R.dimen.context_menu_controller_height);
|
int dp36 = getResources().getDimensionPixelSize(R.dimen.context_menu_controller_height);
|
||||||
|
|
||||||
if (savedInstanceState != null) {
|
|
||||||
if (savedInstanceState.containsKey(SAVE_CURRENT_GPX_FILE)
|
|
||||||
&& savedInstanceState.getBoolean(SAVE_CURRENT_GPX_FILE)) {
|
|
||||||
selectedGpxFile = app.getSavingTrackHelper().getCurrentTrack();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
buttonClear = createItem(inflater, ItemType.CLEAR_DATA, hasDataToSave());
|
buttonClear = createItem(inflater, ItemType.CLEAR_DATA, hasDataToSave());
|
||||||
final View buttonDiscard = createItem(inflater, ItemType.STOP_AND_DISCARD);
|
final View buttonDiscard = createItem(inflater, ItemType.STOP_AND_DISCARD);
|
||||||
final View buttonOnline = createItem(inflater, ItemType.STOP_ONLINE, hasDataToSave());
|
final View buttonOnline = createItem(inflater, ItemType.STOP_ONLINE, hasDataToSave());
|
||||||
|
@ -193,12 +184,6 @@ public class TripRecordingOptionsBottomFragment extends MenuBottomSheetDialogFra
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onSaveInstanceState(@NonNull Bundle outState) {
|
|
||||||
super.onSaveInstanceState(outState);
|
|
||||||
outState.putBoolean(SAVE_CURRENT_GPX_FILE, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
|
@ -213,14 +198,7 @@ public class TripRecordingOptionsBottomFragment extends MenuBottomSheetDialogFra
|
||||||
public void onPause() {
|
public void onPause() {
|
||||||
super.onPause();
|
super.onPause();
|
||||||
stopUpdatingTimeTrackSaved();
|
stopUpdatingTimeTrackSaved();
|
||||||
Fragment target = getTargetFragment();
|
dismissTarget();
|
||||||
if (target instanceof TripRecordingBottomFragment) {
|
|
||||||
if (isDiscard()) {
|
|
||||||
((TripRecordingBottomFragment) target).dismiss();
|
|
||||||
} else {
|
|
||||||
((TripRecordingBottomFragment) target).show();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void show() {
|
public void show() {
|
||||||
|
@ -237,32 +215,6 @@ public class TripRecordingOptionsBottomFragment extends MenuBottomSheetDialogFra
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isDiscard() {
|
|
||||||
Bundle args = getArguments();
|
|
||||||
if (args != null) {
|
|
||||||
return args.getBoolean(ACTION_STOP_AND_DISCARD);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected static void dismissTargetDialog(Fragment current, Class<?> targetClass) {
|
|
||||||
dismissTargetDialog(current, targetClass, null, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected static void dismissTargetDialog(Fragment current, Class<?> targetClass, String booleanKey, Boolean value) {
|
|
||||||
if (targetClass.isInstance(current.getTargetFragment())) {
|
|
||||||
Fragment target = current.getTargetFragment();
|
|
||||||
if (booleanKey != null && value != null) {
|
|
||||||
Bundle args = new Bundle();
|
|
||||||
args.putBoolean(booleanKey, value);
|
|
||||||
target.setArguments(args);
|
|
||||||
}
|
|
||||||
if (target instanceof DialogFragment) {
|
|
||||||
((DialogFragment) target).dismiss();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void stopUpdatingTimeTrackSaved() {
|
public void stopUpdatingTimeTrackSaved() {
|
||||||
handler.removeCallbacks(updatingTimeTrackSaved);
|
handler.removeCallbacks(updatingTimeTrackSaved);
|
||||||
}
|
}
|
||||||
|
@ -312,17 +264,37 @@ public class TripRecordingOptionsBottomFragment extends MenuBottomSheetDialogFra
|
||||||
OsmandMonitoringPlugin plugin = OsmandPlugin.getPlugin(OsmandMonitoringPlugin.class);
|
OsmandMonitoringPlugin plugin = OsmandPlugin.getPlugin(OsmandMonitoringPlugin.class);
|
||||||
if (mapActivity != null && plugin != null) {
|
if (mapActivity != null && plugin != null) {
|
||||||
stopUpdatingTimeTrackSaved();
|
stopUpdatingTimeTrackSaved();
|
||||||
settings.SAVE_GLOBAL_TRACK_TO_GPX.set(false);
|
|
||||||
plugin.saveCurrentTrack(null, mapActivity, false, true);
|
plugin.saveCurrentTrack(null, mapActivity, false, true);
|
||||||
|
Bundle args = new Bundle();
|
||||||
|
args.putBoolean(ACTION_STOP_AND_DISMISS, true);
|
||||||
|
setArguments(args);
|
||||||
dismiss();
|
dismiss();
|
||||||
dismissTargetDialog(TripRecordingOptionsBottomFragment.this, TripRecordingBottomFragment.class);
|
dismissTarget();
|
||||||
settings.SAVE_GLOBAL_TRACK_TO_GPX.set(true);
|
|
||||||
runUpdatingTimeTrackSaved();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isDiscard() {
|
||||||
|
Bundle args = getArguments();
|
||||||
|
if (args != null) {
|
||||||
|
return args.getBoolean(ACTION_STOP_AND_DISMISS);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void dismissTarget() {
|
||||||
|
Fragment target = getTargetFragment();
|
||||||
|
if (target instanceof TripRecordingBottomFragment) {
|
||||||
|
if (isDiscard()) {
|
||||||
|
((TripRecordingBottomFragment) target).dismiss();
|
||||||
|
} else {
|
||||||
|
((TripRecordingBottomFragment) target).show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public MapActivity getMapActivity() {
|
public MapActivity getMapActivity() {
|
||||||
Activity activity = getActivity();
|
Activity activity = getActivity();
|
||||||
|
@ -346,5 +318,4 @@ public class TripRecordingOptionsBottomFragment extends MenuBottomSheetDialogFra
|
||||||
protected boolean useVerticalButtons() {
|
protected boolean useVerticalButtons() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -103,7 +103,6 @@ public class TripRecordingStartingBottomFragment extends MenuBottomSheetDialogFr
|
||||||
updateUpDownBtn();
|
updateUpDownBtn();
|
||||||
|
|
||||||
CardView cardLeft = itemView.findViewById(R.id.button_left);
|
CardView cardLeft = itemView.findViewById(R.id.button_left);
|
||||||
|
|
||||||
createItem(app, nightMode, cardLeft, ItemType.CANCEL, true, null);
|
createItem(app, nightMode, cardLeft, ItemType.CANCEL, true, null);
|
||||||
cardLeft.setOnClickListener(new View.OnClickListener() {
|
cardLeft.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -113,7 +112,6 @@ public class TripRecordingStartingBottomFragment extends MenuBottomSheetDialogFr
|
||||||
});
|
});
|
||||||
|
|
||||||
CardView cardCenter = itemView.findViewById(R.id.button_center);
|
CardView cardCenter = itemView.findViewById(R.id.button_center);
|
||||||
|
|
||||||
createItem(app, nightMode, cardCenter, ItemType.START_RECORDING, true, null);
|
createItem(app, nightMode, cardCenter, ItemType.START_RECORDING, true, null);
|
||||||
cardCenter.setOnClickListener(new View.OnClickListener() {
|
cardCenter.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -123,7 +121,6 @@ public class TripRecordingStartingBottomFragment extends MenuBottomSheetDialogFr
|
||||||
});
|
});
|
||||||
|
|
||||||
CardView cardRight = itemView.findViewById(R.id.button_right);
|
CardView cardRight = itemView.findViewById(R.id.button_right);
|
||||||
|
|
||||||
createItem(app, nightMode, cardRight, ItemType.SETTINGS, true, null);
|
createItem(app, nightMode, cardRight, ItemType.SETTINGS, true, null);
|
||||||
cardRight.setOnClickListener(new View.OnClickListener() {
|
cardRight.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -222,19 +219,13 @@ public class TripRecordingStartingBottomFragment extends MenuBottomSheetDialogFr
|
||||||
dismiss();
|
dismiss();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void show(String... keys) {
|
public void show() {
|
||||||
Dialog dialog = getDialog();
|
Dialog dialog = getDialog();
|
||||||
if (dialog != null) {
|
if (dialog != null) {
|
||||||
dialog.show();
|
dialog.show();
|
||||||
for (String key : keys) {
|
updateTrackIcon(app, trackAppearanceIcon);
|
||||||
if (key.equals(UPDATE_TRACK_ICON)) {
|
updateIntervalValue();
|
||||||
updateTrackIcon(app, trackAppearanceIcon);
|
AndroidUiHelper.updateVisibility(intervalContainer, infoExpanded);
|
||||||
}
|
|
||||||
if (key.equals(UPDATE_LOGGING_INTERVAL)) {
|
|
||||||
updateIntervalValue();
|
|
||||||
AndroidUiHelper.updateVisibility(intervalContainer, infoExpanded);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -105,7 +105,7 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment {
|
||||||
private final Class<? extends LocalRoutingParameter>[] excludeParameters;
|
private final Class<? extends LocalRoutingParameter>[] excludeParameters;
|
||||||
|
|
||||||
@SafeVarargs
|
@SafeVarargs
|
||||||
DialogMode(Class<? extends LocalRoutingParameter> ... excludeParameters) {
|
DialogMode(Class<? extends LocalRoutingParameter>... excludeParameters) {
|
||||||
this.excludeParameters = excludeParameters;
|
this.excludeParameters = excludeParameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -693,9 +693,9 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void showInstance(MapActivity mapActivity,
|
public static void showInstance(MapActivity mapActivity,
|
||||||
Fragment targetFragment,
|
Fragment targetFragment,
|
||||||
DialogMode dialogMode,
|
DialogMode dialogMode,
|
||||||
String appModeKey) {
|
String appModeKey) {
|
||||||
try {
|
try {
|
||||||
FragmentManager fm = mapActivity.getSupportFragmentManager();
|
FragmentManager fm = mapActivity.getSupportFragmentManager();
|
||||||
if (!fm.isStateSaved()) {
|
if (!fm.isStateSaved()) {
|
||||||
|
|
|
@ -399,7 +399,7 @@ public class TrackAppearanceFragment extends ContextMenuScrollFragment implement
|
||||||
public void onContextMenuDismiss(@NonNull ContextMenuFragment fragment) {
|
public void onContextMenuDismiss(@NonNull ContextMenuFragment fragment) {
|
||||||
Fragment target = getTargetFragment();
|
Fragment target = getTargetFragment();
|
||||||
if (target instanceof TripRecordingStartingBottomFragment) {
|
if (target instanceof TripRecordingStartingBottomFragment) {
|
||||||
((TripRecordingStartingBottomFragment) target).show(UPDATE_TRACK_ICON);
|
((TripRecordingStartingBottomFragment) target).show();
|
||||||
} else if (target instanceof TripRecordingBottomFragment) {
|
} else if (target instanceof TripRecordingBottomFragment) {
|
||||||
((TripRecordingBottomFragment) target).show(UPDATE_TRACK_ICON);
|
((TripRecordingBottomFragment) target).show(UPDATE_TRACK_ICON);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue