-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20919 from osmandapp/QuickActionsForTripRecording
Implement quick actions for Trip Recording (issue #20800)
- Loading branch information
Showing
11 changed files
with
373 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
OsmAnd/src/net/osmand/plus/plugins/monitoring/actions/BaseMonitoringAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package net.osmand.plus.plugins.monitoring.actions; | ||
|
||
import androidx.annotation.Nullable; | ||
|
||
import net.osmand.plus.plugins.PluginsHelper; | ||
import net.osmand.plus.plugins.monitoring.OsmandMonitoringPlugin; | ||
import net.osmand.plus.quickaction.QuickAction; | ||
import net.osmand.plus.quickaction.QuickActionType; | ||
|
||
abstract class BaseMonitoringAction extends QuickAction { | ||
|
||
public BaseMonitoringAction(QuickActionType actionType) { | ||
super(actionType); | ||
} | ||
|
||
public BaseMonitoringAction(QuickAction quickAction) { | ||
super(quickAction); | ||
} | ||
|
||
protected boolean isRecordingTrack() { | ||
OsmandMonitoringPlugin plugin = getPlugin(); | ||
return plugin != null && plugin.isRecordingTrack(); | ||
} | ||
|
||
protected boolean hasDataToSave() { | ||
OsmandMonitoringPlugin plugin = getPlugin(); | ||
return plugin != null && plugin.hasDataToSave(); | ||
} | ||
|
||
@Nullable | ||
protected OsmandMonitoringPlugin getPlugin() { | ||
return PluginsHelper.getPlugin(OsmandMonitoringPlugin.class); | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
OsmAnd/src/net/osmand/plus/plugins/monitoring/actions/FinishTripRecordingAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package net.osmand.plus.plugins.monitoring.actions; | ||
|
||
import static net.osmand.plus.quickaction.QuickActionIds.FINISH_TRIP_RECORDING_ACTION; | ||
|
||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.TextView; | ||
|
||
import androidx.annotation.NonNull; | ||
|
||
import net.osmand.plus.OsmandApplication; | ||
import net.osmand.plus.R; | ||
import net.osmand.plus.activities.MapActivity; | ||
import net.osmand.plus.plugins.monitoring.OsmandMonitoringPlugin; | ||
import net.osmand.plus.quickaction.QuickAction; | ||
import net.osmand.plus.quickaction.QuickActionType; | ||
|
||
public class FinishTripRecordingAction extends BaseMonitoringAction { | ||
|
||
public static final QuickActionType TYPE = new QuickActionType(FINISH_TRIP_RECORDING_ACTION, | ||
"finish.trip.recording", FinishTripRecordingAction.class) | ||
.nameRes(R.string.shared_string_trip_recording) | ||
.iconRes(R.drawable.ic_action_trip_rec_finish) | ||
.nonEditable() | ||
.category(QuickActionType.MY_PLACES) | ||
.nameActionRes(R.string.shared_string_finish); | ||
|
||
public FinishTripRecordingAction() { | ||
super(TYPE); | ||
} | ||
|
||
public FinishTripRecordingAction(QuickAction quickAction) { | ||
super(quickAction); | ||
} | ||
|
||
@Override | ||
public void execute(@NonNull MapActivity mapActivity) { | ||
OsmandMonitoringPlugin plugin = getPlugin(); | ||
if (plugin != null) { | ||
OsmandApplication app = mapActivity.getMyApplication(); | ||
if (!isRecordingTrack()) { | ||
app.showToastMessage(R.string.start_trip_recording_first_m); | ||
} else if (!hasDataToSave()) { | ||
app.showToastMessage(R.string.track_does_not_contain_data_to_save); | ||
} else { | ||
plugin.finishRecording(); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void drawUI(@NonNull ViewGroup parent, @NonNull MapActivity mapActivity) { | ||
View view = LayoutInflater.from(parent.getContext()) | ||
.inflate(R.layout.quick_action_with_text, parent, false); | ||
((TextView) view.findViewById(R.id.text)).setText(R.string.quick_action_finish_trip_recording_summary); | ||
parent.addView(view); | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
OsmAnd/src/net/osmand/plus/plugins/monitoring/actions/SaveRecordedTripAndContinueAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package net.osmand.plus.plugins.monitoring.actions; | ||
|
||
import static net.osmand.plus.quickaction.QuickActionIds.SAVE_RECORDED_TRIP_AND_CONTINUE_ACTION; | ||
|
||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.TextView; | ||
|
||
import androidx.annotation.NonNull; | ||
|
||
import net.osmand.plus.OsmandApplication; | ||
import net.osmand.plus.R; | ||
import net.osmand.plus.activities.MapActivity; | ||
import net.osmand.plus.plugins.monitoring.OsmandMonitoringPlugin; | ||
import net.osmand.plus.quickaction.QuickAction; | ||
import net.osmand.plus.quickaction.QuickActionType; | ||
import net.osmand.plus.track.helpers.save.SaveGpxHelper; | ||
import net.osmand.shared.gpx.GpxFile; | ||
|
||
public class SaveRecordedTripAndContinueAction extends BaseMonitoringAction { | ||
|
||
public static final QuickActionType TYPE = new QuickActionType(SAVE_RECORDED_TRIP_AND_CONTINUE_ACTION, | ||
"save.trip.and.continue", SaveRecordedTripAndContinueAction.class) | ||
.nameRes(R.string.quick_action_save_recorded_trip_and_continue) | ||
.iconRes(R.drawable.ic_action_trip_rec_save) | ||
.nonEditable() | ||
.category(QuickActionType.MY_PLACES) | ||
.nameActionRes(R.string.shared_string_save); | ||
|
||
public SaveRecordedTripAndContinueAction() { | ||
super(TYPE); | ||
} | ||
|
||
public SaveRecordedTripAndContinueAction(QuickAction quickAction) { | ||
super(quickAction); | ||
} | ||
|
||
@Override | ||
public void execute(@NonNull MapActivity mapActivity) { | ||
OsmandMonitoringPlugin plugin = getPlugin(); | ||
if (plugin != null) { | ||
OsmandApplication app = mapActivity.getMyApplication(); | ||
if (!isRecordingTrack()) { | ||
app.showToastMessage(R.string.start_trip_recording_first_m); | ||
} else if (!hasDataToSave()) { | ||
app.showToastMessage(R.string.track_does_not_contain_data_to_save); | ||
} else { | ||
GpxFile gpxFile = app.getSavingTrackHelper().getCurrentTrack().getGpxFile(); | ||
SaveGpxHelper.saveCurrentTrack(app, gpxFile, errorMessage -> { | ||
plugin.saveCurrentTrack(null, mapActivity, false, true); | ||
}); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void drawUI(@NonNull ViewGroup parent, @NonNull MapActivity mapActivity) { | ||
View view = LayoutInflater.from(parent.getContext()) | ||
.inflate(R.layout.quick_action_with_text, parent, false); | ||
((TextView) view.findViewById(R.id.text)).setText(R.string.quick_action_save_recorded_trip_and_continue_summary); | ||
parent.addView(view); | ||
} | ||
} |
Oops, something went wrong.