trackbook now asks the user before clearing the map
This commit is contained in:
parent
a38270d2c4
commit
e1b01091cb
5 changed files with 149 additions and 6 deletions
|
@ -18,6 +18,7 @@ package org.y20k.trackbook;
|
|||
|
||||
import android.Manifest;
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.DialogFragment;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
@ -44,6 +45,7 @@ import android.view.View;
|
|||
import android.widget.Button;
|
||||
import android.widget.Toast;
|
||||
|
||||
import org.y20k.trackbook.helpers.DialogClearFragment;
|
||||
import org.y20k.trackbook.helpers.LogHelper;
|
||||
import org.y20k.trackbook.helpers.NotificationHelper;
|
||||
import org.y20k.trackbook.helpers.TrackbookKeys;
|
||||
|
@ -57,7 +59,7 @@ import java.util.Map;
|
|||
/**
|
||||
* MainActivity class
|
||||
*/
|
||||
public class MainActivity extends AppCompatActivity implements TrackbookKeys {
|
||||
public class MainActivity extends AppCompatActivity implements TrackbookKeys, DialogClearFragment.DialogClearListener {
|
||||
|
||||
/* Define log tag */
|
||||
private static final String LOG_TAG = MainActivity.class.getSimpleName();
|
||||
|
@ -203,6 +205,26 @@ public class MainActivity extends AppCompatActivity implements TrackbookKeys {
|
|||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onDialogClearPositiveClick(DialogFragment dialog) {
|
||||
// DialogClear: User chose CLEAR.
|
||||
LogHelper.v(LOG_TAG, "User chose CLEAR");
|
||||
|
||||
// clear the map
|
||||
mMainActivityMapFragment.clearMap();
|
||||
|
||||
// dismiss notification
|
||||
NotificationHelper.stop();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onDialogClearNegativeClick(DialogFragment dialog) {
|
||||
// DialogClear: User chose CANCEL.
|
||||
LogHelper.v(LOG_TAG, "User chose CANCEL.");
|
||||
}
|
||||
|
||||
|
||||
/* Set up main layout */
|
||||
private void setupLayout() {
|
||||
if (mPermissionsGranted) {
|
||||
|
@ -232,8 +254,9 @@ public class MainActivity extends AppCompatActivity implements TrackbookKeys {
|
|||
if (mTrackerServiceRunning || mMainActivityMapFragment == null) {
|
||||
return false;
|
||||
} else {
|
||||
mMainActivityMapFragment.clearMap();
|
||||
NotificationHelper.stop();
|
||||
// show clear dialog
|
||||
DialogFragment dialog = new DialogClearFragment();
|
||||
dialog.show(getFragmentManager(), "DialogClearFragment");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -304,8 +327,6 @@ public class MainActivity extends AppCompatActivity implements TrackbookKeys {
|
|||
if (mTrackerServiceRunning || mMainActivityMapFragment == null) {
|
||||
return false;
|
||||
} else {
|
||||
mMainActivityMapFragment.clearMap();
|
||||
NotificationHelper.stop();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -404,7 +425,9 @@ public class MainActivity extends AppCompatActivity implements TrackbookKeys {
|
|||
// prevent multiple reactions to intent
|
||||
intent.setAction(ACTION_DEFAULT);
|
||||
} else if (intent.hasExtra(EXTRA_CLEAR_MAP) && mMainActivityMapFragment != null) {
|
||||
mMainActivityMapFragment.clearMap();
|
||||
// show clear dialog
|
||||
DialogFragment dialog = new DialogClearFragment();
|
||||
dialog.show(getFragmentManager(), "DialogClearFragment");
|
||||
// prevent multiple reactions to intent
|
||||
intent.setAction(ACTION_DEFAULT);
|
||||
}
|
||||
|
|
|
@ -384,6 +384,7 @@ public class MainActivityMapFragment extends Fragment implements TrackbookKeys {
|
|||
|
||||
/* Removes track crumbs from map */
|
||||
public void clearMap() {
|
||||
|
||||
// clear map
|
||||
if (mTrackOverlay != null) {
|
||||
Toast.makeText(mActivity, mActivity.getString(R.string.toast_message_clear_map), Toast.LENGTH_LONG).show();
|
||||
|
@ -391,6 +392,30 @@ public class MainActivityMapFragment extends Fragment implements TrackbookKeys {
|
|||
}
|
||||
// clear track object
|
||||
mTrack = null;
|
||||
|
||||
// // Use the Builder class for convenient dialog construction
|
||||
// AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||
// builder.setTitle(R.string.dialog_clear_map_title)
|
||||
// .setMessage(R.string.dialog_clear_map_message)
|
||||
// .setPositiveButton(R.string.dialog_clear_map_okay, new DialogInterface.OnClickListener() {
|
||||
// public void onClick(DialogInterface dialog, int id) {
|
||||
// // clear map
|
||||
// if (mTrackOverlay != null) {
|
||||
// Toast.makeText(mActivity, mActivity.getString(R.string.toast_message_clear_map), Toast.LENGTH_LONG).show();
|
||||
// mMapView.getOverlays().remove(mTrackOverlay);
|
||||
// }
|
||||
// // clear track object
|
||||
// mTrack = null;
|
||||
// }
|
||||
// })
|
||||
// .setNegativeButton(R.string.dialog_clear_map_cancel, new DialogInterface.OnClickListener() {
|
||||
// public void onClick(DialogInterface dialog, int id) {
|
||||
// // user clicked cancel - do nothing
|
||||
// }
|
||||
// });
|
||||
// // Create the AlertDialog object and return it
|
||||
// builder.create().show();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,83 @@
|
|||
/**
|
||||
* DialogClearFragment.java
|
||||
* Implements the DialogClearFragment class
|
||||
* A DialogClearFragment appears when the user wants to clear the map
|
||||
*
|
||||
* This file is part of
|
||||
* TRACKBOOK - Movement Recorder for Android
|
||||
*
|
||||
* Copyright (c) 2016 - Y20K.org
|
||||
* Licensed under the MIT-License
|
||||
* http://opensource.org/licenses/MIT
|
||||
*
|
||||
* Trackbook uses osmdroid - OpenStreetMap-Tools for Android
|
||||
* https://github.com/osmdroid/osmdroid
|
||||
*/
|
||||
|
||||
package org.y20k.trackbook.helpers;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.app.DialogFragment;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
|
||||
import org.y20k.trackbook.R;
|
||||
|
||||
|
||||
/**
|
||||
* DialogClearFragment class
|
||||
*/
|
||||
public class DialogClearFragment extends DialogFragment {
|
||||
|
||||
/* Define log tag */
|
||||
private static final String LOG_TAG = DialogClearFragment.class.getSimpleName();
|
||||
|
||||
|
||||
/* Interface that the context that creates an instance of this fragment must implement */
|
||||
public interface DialogClearListener {
|
||||
public void onDialogClearPositiveClick(DialogFragment dialog);
|
||||
public void onDialogClearNegativeClick(DialogFragment dialog);
|
||||
}
|
||||
|
||||
|
||||
/* Main class variables */
|
||||
private DialogClearListener mListener;
|
||||
|
||||
|
||||
@Override
|
||||
public void onAttach(Context context) {
|
||||
super.onAttach(context);
|
||||
// verify that the host context implements the callback interface
|
||||
try {
|
||||
// instantiate the NoticeDialogListener so we can send events to the host
|
||||
mListener = (DialogClearListener) context;
|
||||
} catch (ClassCastException e) {
|
||||
LogHelper.e(LOG_TAG, "Context does not implement the DialogClearListener interface.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
// construct dialog
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||
builder.setTitle(R.string.dialog_clear_map_title)
|
||||
.setMessage(R.string.dialog_clear_map_message)
|
||||
.setPositiveButton(R.string.dialog_clear_map_okay, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
// user clicked CLEAR - inform initiating fragment / context
|
||||
mListener.onDialogClearPositiveClick(DialogClearFragment.this);
|
||||
}
|
||||
})
|
||||
.setNegativeButton(R.string.dialog_clear_map_cancel, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
// user clicked CANCEL - inform initiating fragment / context
|
||||
mListener.onDialogClearNegativeClick(DialogClearFragment.this);
|
||||
}
|
||||
});
|
||||
// create the AlertDialog object and return it
|
||||
return builder.create();
|
||||
}
|
||||
}
|
|
@ -28,6 +28,12 @@
|
|||
<string name="snackbar_message_tracking_started">Tracking aktiviert</string>
|
||||
<string name="snackbar_message_location_offline">Standortdienste sind deaktiviert. Trackbook kann nicht aufzeichnen.</string>
|
||||
|
||||
<!-- dialogs -->
|
||||
<string name="dialog_clear_map_title">Zurücksetzen</string>
|
||||
<string name="dialog_clear_map_message">Möchten Sie die Karte zurücksetzen?</string>
|
||||
<string name="dialog_clear_map_okay">Zurücksetzen</string>
|
||||
<string name="dialog_clear_map_cancel">Abbrechen</string>
|
||||
|
||||
<!-- toast messages -->
|
||||
<string name="toast_message_permissions_granted">Berechtigungen erteilt.</string>
|
||||
<string name="toast_message_unable_to_start_app">Trackbook kann nicht starten.</string>
|
||||
|
|
|
@ -28,6 +28,12 @@
|
|||
<string name="snackbar_message_tracking_started">Tracking started</string>
|
||||
<string name="snackbar_message_location_offline">Location is turned off. Trackbook will not work.</string>
|
||||
|
||||
<!-- dialogs -->
|
||||
<string name="dialog_clear_map_title">Clear</string>
|
||||
<string name="dialog_clear_map_message">Do you want to clear the map?</string>
|
||||
<string name="dialog_clear_map_okay">Clear</string>
|
||||
<string name="dialog_clear_map_cancel">Cancel</string>
|
||||
|
||||
<!-- toast messages -->
|
||||
<string name="toast_message_permissions_granted">Permissions granted.</string>
|
||||
<string name="toast_message_unable_to_start_app">Unable to start Trackbook.</string>
|
||||
|
|
Loading…
Reference in a new issue