add menu on save current track 1/2
This commit is contained in:
parent
727b6ba399
commit
14b8df51b5
6 changed files with 195 additions and 13 deletions
55
OsmAnd/res/layout/fragment_on_save_current_track.xml
Normal file
55
OsmAnd/res/layout/fragment_on_save_current_track.xml
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:osmand="http://schemas.android.com/apk/res-auto"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:background="?attr/bg_color"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/saved_track_name_string"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:padding="@dimen/content_padding"
|
||||||
|
tools:text="Track 2019-02-26 12-52 saved"
|
||||||
|
android:textColor="?android:textColorPrimary"
|
||||||
|
android:textSize="@dimen/default_list_text_size"/>
|
||||||
|
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:paddingBottom="12dp">
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/open_track_button"
|
||||||
|
android:background="?attr/dlg_btn_secondary"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="@dimen/bottom_sheet_cancel_button_height"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:text="Open track"
|
||||||
|
android:textColor="?attr/dlg_btn_secondary_text"
|
||||||
|
android:textSize="@dimen/default_desc_text_size"
|
||||||
|
android:layout_marginLeft="16dp"
|
||||||
|
android:layout_marginRight="8dp"
|
||||||
|
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/show_on_map_button"
|
||||||
|
android:background="?attr/dlg_btn_primary"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="@dimen/bottom_sheet_cancel_button_height"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:text="Show on the map"
|
||||||
|
android:textAllCaps="true"
|
||||||
|
android:textColor="?attr/dlg_btn_primary_text"
|
||||||
|
android:textSize="@dimen/default_desc_text_size"
|
||||||
|
android:layout_marginLeft="8dp"
|
||||||
|
android:layout_marginRight="16dp"
|
||||||
|
/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
</LinearLayout>
|
|
@ -11,6 +11,7 @@
|
||||||
Thx - Hardy
|
Thx - Hardy
|
||||||
|
|
||||||
-->
|
-->
|
||||||
|
<string name="shared_string_saved">saved</string>
|
||||||
<string name="turn_screen_on_router">Wake on turn</string>
|
<string name="turn_screen_on_router">Wake on turn</string>
|
||||||
<string name="turn_screen_on_time_descr">Set the time for which the screen will turn on.</string>
|
<string name="turn_screen_on_time_descr">Set the time for which the screen will turn on.</string>
|
||||||
<string name="turn_screen_on_sensor">Use proximity sensor</string>
|
<string name="turn_screen_on_sensor">Use proximity sensor</string>
|
||||||
|
|
|
@ -743,7 +743,7 @@ public class AppInitializer implements IProgress {
|
||||||
if (System.currentTimeMillis() - timeUpdated >= 1000 * 60 * 30) {
|
if (System.currentTimeMillis() - timeUpdated >= 1000 * 60 * 30) {
|
||||||
startTask(app.getString(R.string.saving_gpx_tracks), -1);
|
startTask(app.getString(R.string.saving_gpx_tracks), -1);
|
||||||
try {
|
try {
|
||||||
warnings.addAll(app.savingTrackHelper.saveDataToGpx(app.getAppCustomization().getTracksDir()));
|
warnings.addAll(app.savingTrackHelper.saveDataToGpx(app.getAppCustomization().getTracksDir()).getWarnings());
|
||||||
} catch (RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
warnings.add(e.getMessage());
|
warnings.add(e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
|
@ -188,10 +188,11 @@ public class SavingTrackHelper extends SQLiteOpenHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return warnings
|
* @return warnings, filenames
|
||||||
*/
|
*/
|
||||||
public synchronized List<String> saveDataToGpx(File dir ) {
|
public synchronized SaveGpxResult saveDataToGpx(File dir) {
|
||||||
List<String> warnings = new ArrayList<String>();
|
List<String> warnings = new ArrayList<>();
|
||||||
|
List<String> filenames = new ArrayList<>();
|
||||||
dir.mkdirs();
|
dir.mkdirs();
|
||||||
if (dir.getParentFile().canWrite()) {
|
if (dir.getParentFile().canWrite()) {
|
||||||
if (dir.exists()) {
|
if (dir.exists()) {
|
||||||
|
@ -199,6 +200,7 @@ public class SavingTrackHelper extends SQLiteOpenHelper {
|
||||||
|
|
||||||
// save file
|
// save file
|
||||||
for (final String f : data.keySet()) {
|
for (final String f : data.keySet()) {
|
||||||
|
log.debug("Filename: " + f);
|
||||||
File fout = new File(dir, f + ".gpx"); //$NON-NLS-1$
|
File fout = new File(dir, f + ".gpx"); //$NON-NLS-1$
|
||||||
if (!data.get(f).isEmpty()) {
|
if (!data.get(f).isEmpty()) {
|
||||||
WptPt pt = data.get(f).findPointToShow();
|
WptPt pt = data.get(f).findPointToShow();
|
||||||
|
@ -214,6 +216,7 @@ public class SavingTrackHelper extends SQLiteOpenHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
String fileName = f + "_" + new SimpleDateFormat("HH-mm_EEE", Locale.US).format(new Date(pt.time)); //$NON-NLS-1$
|
String fileName = f + "_" + new SimpleDateFormat("HH-mm_EEE", Locale.US).format(new Date(pt.time)); //$NON-NLS-1$
|
||||||
|
filenames.add(fileName);
|
||||||
fout = new File(targetDir, fileName + ".gpx"); //$NON-NLS-1$
|
fout = new File(targetDir, fileName + ".gpx"); //$NON-NLS-1$
|
||||||
int ind = 1;
|
int ind = 1;
|
||||||
while (fout.exists()) {
|
while (fout.exists()) {
|
||||||
|
@ -224,7 +227,7 @@ public class SavingTrackHelper extends SQLiteOpenHelper {
|
||||||
Exception warn = GPXUtilities.writeGpxFile(fout, data.get(f));
|
Exception warn = GPXUtilities.writeGpxFile(fout, data.get(f));
|
||||||
if (warn != null) {
|
if (warn != null) {
|
||||||
warnings.add(warn.getMessage());
|
warnings.add(warn.getMessage());
|
||||||
return warnings;
|
return new SaveGpxResult(warnings, new ArrayList<String>());
|
||||||
}
|
}
|
||||||
|
|
||||||
GPXFile gpx = data.get(f);
|
GPXFile gpx = data.get(f);
|
||||||
|
@ -257,7 +260,7 @@ public class SavingTrackHelper extends SQLiteOpenHelper {
|
||||||
currentTrack.getModifiablePointsToDisplay().clear();
|
currentTrack.getModifiablePointsToDisplay().clear();
|
||||||
currentTrack.getModifiableGpxFile().modifiedTime = System.currentTimeMillis();
|
currentTrack.getModifiableGpxFile().modifiedTime = System.currentTimeMillis();
|
||||||
prepareCurrentTrackForRecording();
|
prepareCurrentTrackForRecording();
|
||||||
return warnings;
|
return new SaveGpxResult(warnings, filenames);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, GPXFile> collectRecordedData() {
|
public Map<String, GPXFile> collectRecordedData() {
|
||||||
|
@ -685,5 +688,24 @@ public class SavingTrackHelper extends SQLiteOpenHelper {
|
||||||
public SelectedGpxFile getCurrentTrack() {
|
public SelectedGpxFile getCurrentTrack() {
|
||||||
return currentTrack;
|
return currentTrack;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class SaveGpxResult {
|
||||||
|
|
||||||
|
public SaveGpxResult(List<String> warnings, List<String> filenames) {
|
||||||
|
this.warnings = warnings;
|
||||||
|
this.filenames = filenames;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<String> warnings;
|
||||||
|
List<String> filenames;
|
||||||
|
|
||||||
|
public List<String> getWarnings() {
|
||||||
|
return warnings;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getFilenames() {
|
||||||
|
return filenames;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,88 @@
|
||||||
|
package net.osmand.plus.monitoring;
|
||||||
|
|
||||||
|
import android.graphics.Typeface;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
|
import android.support.v4.app.FragmentManager;
|
||||||
|
import android.text.SpannableStringBuilder;
|
||||||
|
import android.text.Spanned;
|
||||||
|
import android.text.style.StyleSpan;
|
||||||
|
import android.view.ContextThemeWrapper;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.View.OnClickListener;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.Button;
|
||||||
|
import android.widget.TextView;
|
||||||
|
import java.io.File;
|
||||||
|
import net.osmand.plus.OsmandApplication;
|
||||||
|
import net.osmand.plus.R;
|
||||||
|
import net.osmand.plus.base.BottomSheetDialogFragment;
|
||||||
|
import net.osmand.plus.myplaces.AvailableGPXFragment;
|
||||||
|
|
||||||
|
public class OnSaveCurrentTrackFragment extends BottomSheetDialogFragment {
|
||||||
|
|
||||||
|
public static final String TAG = "OnSaveCurrentTrackBottomSheetFragment";
|
||||||
|
public static final String SAVED_TRACK_KEY = "saved_track_filename";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
|
final OsmandApplication app = getMyApplication();
|
||||||
|
Bundle args = getArguments();
|
||||||
|
String savedGpxName = "";
|
||||||
|
if (args != null && args.containsKey(SAVED_TRACK_KEY)) {
|
||||||
|
savedGpxName = args.getString(SAVED_TRACK_KEY, "");
|
||||||
|
} else {
|
||||||
|
dismiss();
|
||||||
|
}
|
||||||
|
|
||||||
|
final File f = new File (app.getAppCustomization().getTracksDir() +"/"+ savedGpxName + ".gpx");
|
||||||
|
final boolean nightMode = !app.getSettings().isLightContent();
|
||||||
|
final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
|
||||||
|
View mainView = View
|
||||||
|
.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_on_save_current_track, container);
|
||||||
|
TextView tv = mainView.findViewById(R.id.saved_track_name_string);
|
||||||
|
Button openTrackBtn = mainView.findViewById(R.id.open_track_button);
|
||||||
|
Button showOnMapBtn = mainView.findViewById(R.id.show_on_map_button);
|
||||||
|
|
||||||
|
SpannableStringBuilder ssb = new SpannableStringBuilder();
|
||||||
|
ssb.append(app.getResources().getString(R.string.shared_string_gpx_track)).append(" ");
|
||||||
|
int startIndex = ssb.length();
|
||||||
|
ssb.append(savedGpxName).append(" ");
|
||||||
|
ssb.setSpan(new StyleSpan(Typeface.BOLD), startIndex, ssb.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||||
|
startIndex = ssb.length();
|
||||||
|
ssb.append(app.getResources().getString(R.string.shared_string_saved));
|
||||||
|
ssb.setSpan(new StyleSpan(Typeface.NORMAL), startIndex, ssb.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||||
|
tv.setText(ssb);
|
||||||
|
|
||||||
|
openTrackBtn.setOnClickListener(new OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
AvailableGPXFragment.openTrack(getActivity(), f);
|
||||||
|
dismiss();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
showOnMapBtn.setOnClickListener(new OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
//show track on MapActivity
|
||||||
|
dismiss();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return mainView;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void showInstance(FragmentManager fragmentManager, String filename) {
|
||||||
|
OnSaveCurrentTrackFragment f = new OnSaveCurrentTrackFragment();
|
||||||
|
Bundle b = new Bundle();
|
||||||
|
b.putString(SAVED_TRACK_KEY, filename);
|
||||||
|
f.setArguments(b);
|
||||||
|
f.show(fragmentManager, TAG);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -31,6 +31,7 @@ import net.osmand.plus.OsmandSettings;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.activities.MapActivity;
|
import net.osmand.plus.activities.MapActivity;
|
||||||
import net.osmand.plus.activities.SavingTrackHelper;
|
import net.osmand.plus.activities.SavingTrackHelper;
|
||||||
|
import net.osmand.plus.activities.SavingTrackHelper.SaveGpxResult;
|
||||||
import net.osmand.plus.dashboard.tools.DashFragmentData;
|
import net.osmand.plus.dashboard.tools.DashFragmentData;
|
||||||
import net.osmand.plus.views.MapInfoLayer;
|
import net.osmand.plus.views.MapInfoLayer;
|
||||||
import net.osmand.plus.views.OsmandMapLayer.DrawSettings;
|
import net.osmand.plus.views.OsmandMapLayer.DrawSettings;
|
||||||
|
@ -40,6 +41,7 @@ import net.osmand.plus.views.mapwidgets.TextInfoWidget;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import gnu.trove.list.array.TIntArrayList;
|
import gnu.trove.list.array.TIntArrayList;
|
||||||
|
import net.osmand.util.Algorithms;
|
||||||
|
|
||||||
public class OsmandMonitoringPlugin extends OsmandPlugin {
|
public class OsmandMonitoringPlugin extends OsmandPlugin {
|
||||||
public static final String ID = "osmand.monitoring";
|
public static final String ID = "osmand.monitoring";
|
||||||
|
@ -288,7 +290,7 @@ public class OsmandMonitoringPlugin extends OsmandPlugin {
|
||||||
int which = holder[0];
|
int which = holder[0];
|
||||||
int item = items.get(which);
|
int item = items.get(which);
|
||||||
if(item == R.string.save_current_track){
|
if(item == R.string.save_current_track){
|
||||||
saveCurrentTrack();
|
saveCurrentTrack(map);
|
||||||
} else if(item == R.string.gpx_monitoring_start) {
|
} else if(item == R.string.gpx_monitoring_start) {
|
||||||
if (app.getLocationProvider().checkGPSEnabled(map)) {
|
if (app.getLocationProvider().checkGPSEnabled(map)) {
|
||||||
startGPXMonitoring(map, showTrackSelection);
|
startGPXMonitoring(map, showTrackSelection);
|
||||||
|
@ -330,11 +332,20 @@ public class OsmandMonitoringPlugin extends OsmandPlugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void saveCurrentTrack() {
|
public void saveCurrentTrack() {
|
||||||
saveCurrentTrack(null);
|
saveCurrentTrack(null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void saveCurrentTrack(@Nullable final Runnable onComplete) {
|
||||||
|
saveCurrentTrack(onComplete, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void saveCurrentTrack(@Nullable final Runnable onComplete) {
|
public void saveCurrentTrack(@Nullable final Activity activity) {
|
||||||
app.getTaskManager().runInBackground(new OsmAndTaskRunnable<Void, Void, Void>() {
|
saveCurrentTrack(null, activity);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void saveCurrentTrack(@Nullable final Runnable onComplete, @Nullable final
|
||||||
|
Activity activity) {
|
||||||
|
app.getTaskManager().runInBackground(new OsmAndTaskRunnable<Void, Void, SaveGpxResult>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPreExecute() {
|
protected void onPreExecute() {
|
||||||
|
@ -343,11 +354,12 @@ public class OsmandMonitoringPlugin extends OsmandPlugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Void doInBackground(Void... params) {
|
protected SaveGpxResult doInBackground(Void... params) {
|
||||||
try {
|
try {
|
||||||
SavingTrackHelper helper = app.getSavingTrackHelper();
|
SavingTrackHelper helper = app.getSavingTrackHelper();
|
||||||
helper.saveDataToGpx(app.getAppCustomization().getTracksDir());
|
SaveGpxResult result = helper.saveDataToGpx(app.getAppCustomization().getTracksDir());
|
||||||
helper.close();
|
helper.close();
|
||||||
|
return result;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -355,10 +367,14 @@ public class OsmandMonitoringPlugin extends OsmandPlugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPostExecute(Void aVoid) {
|
protected void onPostExecute(SaveGpxResult result) {
|
||||||
isSaving = false;
|
isSaving = false;
|
||||||
app.getNotificationHelper().refreshNotifications();
|
app.getNotificationHelper().refreshNotifications();
|
||||||
updateControl();
|
updateControl();
|
||||||
|
if (activity instanceof MapActivity && !Algorithms.isEmpty(result.getFilenames())) {
|
||||||
|
OnSaveCurrentTrackFragment.showInstance(((MapActivity) activity)
|
||||||
|
.getSupportFragmentManager(), result.getFilenames().get(0));
|
||||||
|
}
|
||||||
if (onComplete != null) {
|
if (onComplete != null) {
|
||||||
onComplete.run();
|
onComplete.run();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue