Notification with buttons

This commit is contained in:
GaidamakUA 2015-07-24 11:56:38 +03:00
parent ab2ba708c2
commit 0e9d1ca771
2 changed files with 157 additions and 136 deletions

View file

@ -1,10 +1,6 @@
package net.osmand.plus; package net.osmand.plus;
import net.osmand.PlatformUtil;
import net.osmand.access.AccessibleToast;
import net.osmand.plus.osmo.OsMoPlugin;
import android.app.AlarmManager; import android.app.AlarmManager;
import android.app.Notification;
import android.app.NotificationManager; import android.app.NotificationManager;
import android.app.PendingIntent; import android.app.PendingIntent;
import android.app.Service; import android.app.Service;
@ -27,33 +23,42 @@ import android.support.v7.app.NotificationCompat;
import android.util.Log; import android.util.Log;
import android.widget.Toast; import android.widget.Toast;
import net.osmand.PlatformUtil;
import net.osmand.access.AccessibleToast;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.monitoring.OsmandMonitoringPlugin;
import net.osmand.plus.osmo.OsMoPlugin;
public class NavigationService extends Service implements LocationListener { public class NavigationService extends Service implements LocationListener {
public static class NavigationServiceBinder extends Binder { public static class NavigationServiceBinder extends Binder {
} }
// global id don't conflict with others // global id don't conflict with others
private final static int NOTIFICATION_SERVICE_ID = 5; private final static int NOTIFICATION_SERVICE_ID = 5;
public final static String OSMAND_STOP_SERVICE_ACTION = "OSMAND_STOP_SERVICE_ACTION"; //$NON-NLS-1$ public final static String OSMAND_STOP_SERVICE_ACTION = "OSMAND_STOP_SERVICE_ACTION"; //$NON-NLS-1$
public final static String OSMAND_SAVE_SERVICE_ACTION = "OSMAND_SAVE_SERVICE_ACTION";
public static int USED_BY_NAVIGATION = 1; public static int USED_BY_NAVIGATION = 1;
public static int USED_BY_GPX = 2; public static int USED_BY_GPX = 2;
public static int USED_BY_LIVE = 4; public static int USED_BY_LIVE = 4;
public final static String USAGE_INTENT = "SERVICE_USED_BY"; public final static String USAGE_INTENT = "SERVICE_USED_BY";
private NavigationServiceBinder binder = new NavigationServiceBinder(); private NavigationServiceBinder binder = new NavigationServiceBinder();
private int serviceOffInterval; private int serviceOffInterval;
private String serviceOffProvider; private String serviceOffProvider;
private int serviceError; private int serviceError;
private OsmandSettings settings; private OsmandSettings settings;
private Handler handler; private Handler handler;
private static WakeLock lockStatic; private static WakeLock lockStatic;
private PendingIntent pendingIntent; private PendingIntent pendingIntent;
private BroadcastReceiver broadcastReceiver; private BroadcastReceiver broadcastReceiver;
private BroadcastReceiver saveBroadcastReceiver;
private int usedBy = 0; private int usedBy = 0;
private OsmAndLocationProvider locationProvider; private OsmAndLocationProvider locationProvider;
@ -61,7 +66,7 @@ public class NavigationService extends Service implements LocationListener {
public IBinder onBind(Intent intent) { public IBinder onBind(Intent intent) {
return binder; return binder;
} }
protected synchronized static PowerManager.WakeLock getLock(Context context) { protected synchronized static PowerManager.WakeLock getLock(Context context) {
if (lockStatic == null) { if (lockStatic == null) {
PowerManager mgr = (PowerManager) context.getSystemService(Context.POWER_SERVICE); PowerManager mgr = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
@ -73,29 +78,29 @@ public class NavigationService extends Service implements LocationListener {
protected Handler getHandler() { protected Handler getHandler() {
return handler; return handler;
} }
public int getServiceError() { public int getServiceError() {
return serviceError; return serviceError;
} }
public int getServiceOffInterval() { public int getServiceOffInterval() {
return serviceOffInterval; return serviceOffInterval;
} }
public String getServiceOffProvider() { public String getServiceOffProvider() {
return serviceOffProvider; return serviceOffProvider;
} }
public boolean isUsed() { public boolean isUsed() {
return usedBy != 0; return usedBy != 0;
} }
public void addUsageIntent(int usageIntent) { public void addUsageIntent(int usageIntent) {
usedBy |= usageIntent; usedBy |= usageIntent;
} }
public void stopIfNeeded(Context ctx, int usageIntent) { public void stopIfNeeded(Context ctx, int usageIntent) {
if((usedBy & usageIntent) > 0) { if ((usedBy & usageIntent) > 0) {
usedBy -= usageIntent; usedBy -= usageIntent;
} }
@ -114,7 +119,7 @@ public class NavigationService extends Service implements LocationListener {
ctx.stopService(serviceIntent); ctx.stopService(serviceIntent);
} }
} }
@Override @Override
public int onStartCommand(Intent intent, int flags, int startId) { public int onStartCommand(Intent intent, int flags, int startId) {
handler = new Handler(); handler = new Handler();
@ -135,13 +140,13 @@ public class NavigationService extends Service implements LocationListener {
serviceError = Math.max(serviceError, 30 * 1000); serviceError = Math.max(serviceError, 30 * 1000);
// 3. not more than serviceOffInterval // 3. not more than serviceOffInterval
serviceError = Math.min(serviceError, serviceOffInterval); serviceError = Math.min(serviceError, serviceOffInterval);
locationProvider = app.getLocationProvider(); locationProvider = app.getLocationProvider();
app.setNavigationService(this); app.setNavigationService(this);
// requesting // requesting
if(isContinuous()){ if (isContinuous()) {
// request location updates // request location updates
LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
try { try {
@ -155,11 +160,11 @@ public class NavigationService extends Service implements LocationListener {
pendingIntent = PendingIntent.getBroadcast(this, 0, new Intent(this, OnNavigationServiceAlarmReceiver.class), PendingIntent.FLAG_UPDATE_CURRENT); pendingIntent = PendingIntent.getBroadcast(this, 0, new Intent(this, OnNavigationServiceAlarmReceiver.class), PendingIntent.FLAG_UPDATE_CURRENT);
alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + 500, serviceOffInterval, pendingIntent); alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + 500, serviceOffInterval, pendingIntent);
} }
// registering icon at top level // registering icon at top level
// Leave icon visible even for navigation for proper display // Leave icon visible even for navigation for proper display
// if (!startedForNavigation) { // if (!startedForNavigation) {
showNotificationInStatusBar(app); showNotificationInStatusBar(app);
// } // }
return START_REDELIVER_INTENT; return START_REDELIVER_INTENT;
} }
@ -168,35 +173,40 @@ public class NavigationService extends Service implements LocationListener {
broadcastReceiver = new BroadcastReceiver() { broadcastReceiver = new BroadcastReceiver() {
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
if(settings.SAVE_GLOBAL_TRACK_TO_GPX.get()) { if (settings.SAVE_GLOBAL_TRACK_TO_GPX.get()) {
settings.SAVE_GLOBAL_TRACK_TO_GPX.set(false); settings.SAVE_GLOBAL_TRACK_TO_GPX.set(false);
} }
OsMoPlugin plugin = OsmandPlugin.getEnabledPlugin(OsMoPlugin.class); OsMoPlugin plugin = OsmandPlugin.getEnabledPlugin(OsMoPlugin.class);
if(plugin != null) { if (plugin != null) {
if(plugin.getTracker().isEnabledTracker()) { if (plugin.getTracker().isEnabledTracker()) {
plugin.getTracker().disableTracker(); plugin.getTracker().disableTracker();
} }
} }
NavigationService.this.stopSelf(); NavigationService.this.stopSelf();
} }
}; };
registerReceiver(broadcastReceiver, new IntentFilter(OSMAND_STOP_SERVICE_ACTION)); registerReceiver(broadcastReceiver, new IntentFilter(OSMAND_STOP_SERVICE_ACTION));
saveBroadcastReceiver = new BroadcastReceiver() {
@Override
Intent notificationIntent = new Intent(OSMAND_STOP_SERVICE_ACTION); public void onReceive(Context context, Intent intent) {
final OsmandMonitoringPlugin plugin = OsmandPlugin
.getEnabledPlugin(OsmandMonitoringPlugin.class);
plugin.saveCurrentTrack();
}
};
registerReceiver(saveBroadcastReceiver, new IntentFilter(OSMAND_SAVE_SERVICE_ACTION));
//Show currently active wake-up interval //Show currently active wake-up interval
int soi = settings.SERVICE_OFF_INTERVAL.get(); int soi = settings.SERVICE_OFF_INTERVAL.get();
String nt = getString(R.string.service_stop_background_service) + ". " + getString(R.string.gps_wake_up_timer) + ": "; String nt = getString(R.string.service_stop_background_service) + ". " + getString(R.string.gps_wake_up_timer) + ": ";
if (soi == 0) { if (soi == 0) {
nt = nt + getString(R.string.int_continuosly); nt = nt + getString(R.string.int_continuosly);
} else if (soi <= 90000) { } else if (soi <= 90000) {
nt = nt + Integer.toString(soi/1000) + " " + getString(R.string.int_seconds); nt = nt + Integer.toString(soi / 1000) + " " + getString(R.string.int_seconds);
} else { } else {
nt = nt + Integer.toString(soi/1000/60) + " " + getString(R.string.int_min); nt = nt + Integer.toString(soi / 1000 / 60) + " " + getString(R.string.int_min);
} }
PendingIntent broadcast = PendingIntent.getBroadcast(this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
// Notification notification = new Notification(R.drawable.bgs_icon, "", //$NON-NLS-1$ // Notification notification = new Notification(R.drawable.bgs_icon, "", //$NON-NLS-1$
// System.currentTimeMillis()); // System.currentTimeMillis());
// //
@ -204,35 +214,51 @@ public class NavigationService extends Service implements LocationListener {
// broadcast); // broadcast);
// notification.flags = Notification.FLAG_NO_CLEAR; // notification.flags = Notification.FLAG_NO_CLEAR;
// startForeground(NOTIFICATION_SERVICE_ID, notification); // startForeground(NOTIFICATION_SERVICE_ID, notification);
final Builder noti = new NotificationCompat.Builder( String stop = getResources().getString(R.string.shared_string_control_stop);
this).setContentTitle(Version.getAppName(cl)) Intent stopIntent = new Intent(OSMAND_STOP_SERVICE_ACTION);
.setContentText(getString(R.string.osmand_service)).setSmallIcon(R.drawable.bgs_icon) PendingIntent stopPendingIntent = PendingIntent.getBroadcast(this, 0, stopIntent,
// .setLargeIcon(Helpers.getBitmap(R.drawable.mirakel, getBaseContext())) PendingIntent.FLAG_UPDATE_CURRENT);
.setContentIntent(broadcast).setOngoing(true); String pause = getResources().getString(R.string.shared_string_save);
startForeground(NOTIFICATION_SERVICE_ID, noti.build()); Intent saveIntent = new Intent(OSMAND_SAVE_SERVICE_ACTION);
PendingIntent savePendingIntent = PendingIntent.getBroadcast(this, 0, saveIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
Intent contentIntent = new Intent(this, MapActivity.class);
PendingIntent contentPendingIntent = PendingIntent.getActivity(this, 0, contentIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
final Builder notificationBuilder = new NotificationCompat.Builder(
this).setContentTitle(Version.getAppName(cl))
.setContentText(getString(R.string.osmand_service))
.setSmallIcon(R.drawable.bgs_icon)
// .setLargeIcon(Helpers.getBitmap(R.drawable.mirakel, getBaseContext()))
.setContentIntent(contentPendingIntent)
.setOngoing(true)
.addAction(R.drawable.ic_action_rec_stop, stop, stopPendingIntent)
.addAction(R.drawable.ic_action_save, pause, savePendingIntent);
startForeground(NOTIFICATION_SERVICE_ID, notificationBuilder.build());
} }
@Override @Override
public void onCreate() { public void onCreate() {
super.onCreate(); super.onCreate();
// initializing variables // initializing variables
} }
private boolean isContinuous(){ private boolean isContinuous() {
return serviceOffInterval == 0; return serviceOffInterval == 0;
} }
@Override @Override
public void onDestroy() { public void onDestroy() {
super.onDestroy(); super.onDestroy();
((OsmandApplication)getApplication()).setNavigationService(null); ((OsmandApplication) getApplication()).setNavigationService(null);
usedBy = 0; usedBy = 0;
// remove updates // remove updates
LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
locationManager.removeUpdates(this); locationManager.removeUpdates(this);
if (!isContinuous()) { if (!isContinuous()) {
WakeLock lock = getLock(this); WakeLock lock = getLock(this);
if (lock.isHeld()) { if (lock.isHeld()) {
@ -253,15 +279,19 @@ public class NavigationService extends Service implements LocationListener {
unregisterReceiver(broadcastReceiver); unregisterReceiver(broadcastReceiver);
broadcastReceiver = null; broadcastReceiver = null;
} }
if (saveBroadcastReceiver != null) {
unregisterReceiver(saveBroadcastReceiver);
saveBroadcastReceiver = null;
}
stopForeground(Boolean.TRUE); stopForeground(Boolean.TRUE);
} }
@Override @Override
public void onLocationChanged(Location l) { public void onLocationChanged(Location l) {
if(l != null && !settings.MAP_ACTIVITY_ENABLED.get()){ if (l != null && !settings.MAP_ACTIVITY_ENABLED.get()) {
net.osmand.Location location = OsmAndLocationProvider.convertLocation(l,(OsmandApplication) getApplication()); net.osmand.Location location = OsmAndLocationProvider.convertLocation(l, (OsmandApplication) getApplication());
if(!isContinuous()){ if (!isContinuous()) {
// unregister listener and wait next time // unregister listener and wait next time
LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
locationManager.removeUpdates(this); locationManager.removeUpdates(this);
@ -272,7 +302,7 @@ public class NavigationService extends Service implements LocationListener {
} }
locationProvider.setLocationFromService(location, isContinuous()); locationProvider.setLocationFromService(location, isContinuous());
} }
} }
@Override @Override
@ -281,21 +311,19 @@ public class NavigationService extends Service implements LocationListener {
} }
@Override @Override
public void onProviderEnabled(String provider) { public void onProviderEnabled(String provider) {
} }
@Override @Override
public void onStatusChanged(String provider, int status, Bundle extras) { public void onStatusChanged(String provider, int status, Bundle extras) {
} }
@Override @Override
public void onTaskRemoved(Intent rootIntent) { public void onTaskRemoved(Intent rootIntent) {
if (((OsmandApplication) getApplication()).getNavigationService() != null && if (((OsmandApplication) getApplication()).getNavigationService() != null &&
((OsmandApplication) getApplication()).getSettings().DISABLE_RECORDING_ONCE_APP_KILLED.get()) { ((OsmandApplication) getApplication()).getSettings().DISABLE_RECORDING_ONCE_APP_KILLED.get()) {
OsMoPlugin plugin = OsmandPlugin.getEnabledPlugin(OsMoPlugin.class); OsMoPlugin plugin = OsmandPlugin.getEnabledPlugin(OsMoPlugin.class);
if (plugin != null) { if (plugin != null) {
if (plugin.getTracker().isEnabledTracker()) { if (plugin.getTracker().isEnabledTracker()) {
@ -305,6 +333,4 @@ public class NavigationService extends Service implements LocationListener {
NavigationService.this.stopSelf(); NavigationService.this.stopSelf();
} }
} }
} }

View file

@ -1,47 +1,5 @@
package net.osmand.plus.myplaces; package net.osmand.plus.myplaces;
import java.io.File;
import java.text.Collator;
import java.text.DateFormat;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import net.osmand.IndexConstants;
import net.osmand.access.AccessibleToast;
import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick;
import net.osmand.plus.GPXUtilities;
import net.osmand.plus.GPXUtilities.GPXFile;
import net.osmand.plus.GPXUtilities.GPXTrackAnalysis;
import net.osmand.plus.GPXUtilities.WptPt;
import net.osmand.plus.GpxSelectionHelper;
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
import net.osmand.plus.IconsCache;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.OsmandActionBarActivity;
import net.osmand.plus.activities.OsmandBaseExpandableListAdapter;
import net.osmand.plus.activities.OsmandExpandableListFragment;
import net.osmand.plus.activities.SavingTrackHelper;
import net.osmand.plus.activities.TrackActivity;
import net.osmand.plus.dialogs.DirectionsDialogs;
import net.osmand.plus.download.LocalIndexesFragment;
import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.monitoring.OsmandMonitoringPlugin;
import net.osmand.plus.osmedit.OsmEditingPlugin;
import net.osmand.util.Algorithms;
import android.app.Activity; import android.app.Activity;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.app.AlertDialog.Builder; import android.app.AlertDialog.Builder;
@ -75,6 +33,49 @@ import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import net.osmand.IndexConstants;
import net.osmand.access.AccessibleToast;
import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick;
import net.osmand.plus.GPXUtilities;
import net.osmand.plus.GPXUtilities.GPXFile;
import net.osmand.plus.GPXUtilities.GPXTrackAnalysis;
import net.osmand.plus.GPXUtilities.WptPt;
import net.osmand.plus.GpxSelectionHelper;
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
import net.osmand.plus.IconsCache;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.OsmandActionBarActivity;
import net.osmand.plus.activities.OsmandBaseExpandableListAdapter;
import net.osmand.plus.activities.OsmandExpandableListFragment;
import net.osmand.plus.activities.SavingTrackHelper;
import net.osmand.plus.activities.TrackActivity;
import net.osmand.plus.dialogs.DirectionsDialogs;
import net.osmand.plus.download.LocalIndexesFragment;
import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.monitoring.OsmandMonitoringPlugin;
import net.osmand.plus.osmedit.OsmEditingPlugin;
import net.osmand.util.Algorithms;
import java.io.File;
import java.text.Collator;
import java.text.DateFormat;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
public class AvailableGPXFragment extends OsmandExpandableListFragment { public class AvailableGPXFragment extends OsmandExpandableListFragment {
public static final int SEARCH_ID = -1; public static final int SEARCH_ID = -1;
@ -115,7 +116,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
public void run() { public void run() {
if (getView() != null && updateEnable) { if (getView() != null && updateEnable) {
updateCurrentTrack(getView(), getActivity(), app); updateCurrentTrack(getView(), getActivity(), app);
if(selectedGpxHelper.getSelectedCurrentRecordingTrack() != null) { if (selectedGpxHelper.getSelectedCurrentRecordingTrack() != null) {
allGpxAdapter.notifyDataSetChanged(); allGpxAdapter.notifyDataSetChanged();
} }
startHandler(); startHandler();
@ -139,7 +140,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
allGpxAdapter.notifyDataSetChanged(); allGpxAdapter.notifyDataSetChanged();
} }
updateCurrentTrack(); updateCurrentTrack();
updateEnable = true; updateEnable = true;
startHandler(); startHandler();
} }
@ -152,14 +153,14 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
operationTask.cancel(true); operationTask.cancel(true);
} }
} }
public void updateCurrentTrack() { public void updateCurrentTrack() {
if (OsmandPlugin.getEnabledPlugin(OsmandMonitoringPlugin.class) == null) { if (OsmandPlugin.getEnabledPlugin(OsmandMonitoringPlugin.class) == null) {
return; return;
} }
updateCurrentTrack(getView(), getActivity(), app); updateCurrentTrack(getView(), getActivity(), app);
final CheckBox checkbox = (CheckBox) getView().findViewById(R.id.check_local_index); final CheckBox checkbox = (CheckBox) getView().findViewById(R.id.check_local_index);
checkbox.setVisibility(selectionMode && showOnMapMode? View.VISIBLE : View.GONE); checkbox.setVisibility(selectionMode && showOnMapMode ? View.VISIBLE : View.GONE);
if (selectionMode && showOnMapMode) { if (selectionMode && showOnMapMode) {
checkbox.setChecked(selectedItems.contains(currentRecording)); checkbox.setChecked(selectedItems.contains(currentRecording));
checkbox.setOnClickListener(new View.OnClickListener() { checkbox.setOnClickListener(new View.OnClickListener() {
@ -187,7 +188,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
} }
final boolean isRecording = app.getSettings().SAVE_GLOBAL_TRACK_TO_GPX.get(); final boolean isRecording = app.getSettings().SAVE_GLOBAL_TRACK_TO_GPX.get();
ImageButton stop = ((ImageButton) v.findViewById(R.id.stop)); ImageButton stop = ((ImageButton) v.findViewById(R.id.stop));
if(isRecording) { if (isRecording) {
stop.setImageDrawable(app.getIconsCache().getContentIcon(R.drawable.ic_action_rec_stop)); stop.setImageDrawable(app.getIconsCache().getContentIcon(R.drawable.ic_action_rec_stop));
} else { } else {
stop.setImageDrawable(app.getIconsCache().getIcon(R.drawable.ic_action_rec_start, R.color.recording_color)); stop.setImageDrawable(app.getIconsCache().getIcon(R.drawable.ic_action_rec_start, R.color.recording_color));
@ -210,15 +211,9 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
save.setOnClickListener(new View.OnClickListener() { save.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
Runnable run = new Runnable() { final OsmandMonitoringPlugin plugin = OsmandPlugin
@Override .getEnabledPlugin(OsmandMonitoringPlugin.class);
public void run() { plugin.saveCurrentTrack();
final OsmandMonitoringPlugin plugin = OsmandPlugin
.getEnabledPlugin(OsmandMonitoringPlugin.class);
plugin.saveCurrentTrack();
}
};
run.run();
} }
}); });
if (sth.getPoints() > 0 || sth.getDistance() > 0) { if (sth.getPoints() > 0 || sth.getDistance() > 0) {
@ -265,11 +260,11 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
return v; return v;
} }
public static void openTrack(Activity a, final File f) { public static void openTrack(Activity a, final File f) {
Intent newIntent = new Intent(a, ((OsmandApplication) a.getApplication()).getAppCustomization().getTrackActivity()); Intent newIntent = new Intent(a, ((OsmandApplication) a.getApplication()).getAppCustomization().getTrackActivity());
// causes wrong position caching: newIntent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); // causes wrong position caching: newIntent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
if(f == null) { if (f == null) {
newIntent.putExtra(TrackActivity.CURRENT_RECORDING, true); newIntent.putExtra(TrackActivity.CURRENT_RECORDING, true);
} else { } else {
newIntent.putExtra(TrackActivity.TRACK_FILE_NAME, f.getAbsolutePath()); newIntent.putExtra(TrackActivity.TRACK_FILE_NAME, f.getAbsolutePath());
@ -435,7 +430,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
private void openShowOnMapMode() { private void openShowOnMapMode() {
enableSelectionMode(true); enableSelectionMode(true);
showOnMapMode = true; showOnMapMode = true;
selectedItems.clear(); selectedItems.clear();
final Set<GpxInfo> originalSelectedItems = allGpxAdapter.getSelectedGpx(); final Set<GpxInfo> originalSelectedItems = allGpxAdapter.getSelectedGpx();
selectedItems.addAll(originalSelectedItems); selectedItems.addAll(originalSelectedItems);
@ -487,7 +482,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
} }
public void openSelectionMode(final int actionResId, int darkIcon, int lightIcon, public void openSelectionMode(final int actionResId, int darkIcon, int lightIcon,
final DialogInterface.OnClickListener listener) { final DialogInterface.OnClickListener listener) {
final int actionIconId = !isLightActionBar() ? darkIcon : lightIcon; final int actionIconId = !isLightActionBar() ? darkIcon : lightIcon;
String value = app.getString(actionResId); String value = app.getString(actionResId);
if (value.endsWith("...")) { if (value.endsWith("...")) {
@ -617,7 +612,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
if (getActivity() != null) { if (getActivity() != null) {
((OsmandActionBarActivity) getActivity()).setSupportProgressBarIndeterminateVisibility(false); ((OsmandActionBarActivity) getActivity()).setSupportProgressBarIndeterminateVisibility(false);
} }
if (allGpxAdapter.getGroupCount() > 0 && if (allGpxAdapter.getGroupCount() > 0 &&
allGpxAdapter.isShowingSelection()) { allGpxAdapter.isShowingSelection()) {
getExpandableListView().expandGroup(0); getExpandableListView().expandGroup(0);
} }
@ -643,7 +638,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
} }
private void loadGPXFolder(File mapPath, List<GpxInfo> result, LoadGpxTask loadTask, List<GpxInfo> progress, private void loadGPXFolder(File mapPath, List<GpxInfo> result, LoadGpxTask loadTask, List<GpxInfo> progress,
String gpxSubfolder) { String gpxSubfolder) {
for (File gpxFile : listFilesSorted(mapPath)) { for (File gpxFile : listFilesSorted(mapPath)) {
if (gpxFile.isDirectory()) { if (gpxFile.isDirectory()) {
String sub = gpxSubfolder.length() == 0 ? gpxFile.getName() : gpxSubfolder + "/" String sub = gpxSubfolder.length() == 0 ? gpxFile.getName() : gpxSubfolder + "/"
@ -682,7 +677,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
public GpxIndexesAdapter(Context ctx) { public GpxIndexesAdapter(Context ctx) {
warningColor = ctx.getResources().getColor(R.color.color_warning); warningColor = ctx.getResources().getColor(R.color.color_warning);
TypedArray ta = ctx.getTheme().obtainStyledAttributes(new int[] { android.R.attr.textColorPrimary }); TypedArray ta = ctx.getTheme().obtainStyledAttributes(new int[]{android.R.attr.textColorPrimary});
defaultColor = ta.getColor(0, ctx.getResources().getColor(R.color.color_unknown)); defaultColor = ta.getColor(0, ctx.getResources().getColor(R.color.color_unknown));
ta.recycle(); ta.recycle();
} }
@ -766,7 +761,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
@Override @Override
public View getChildView(final int groupPosition, final int childPosition, boolean isLastChild, public View getChildView(final int groupPosition, final int childPosition, boolean isLastChild,
View convertView, ViewGroup parent) { View convertView, ViewGroup parent) {
View v = convertView; View v = convertView;
final GpxInfo child = getChild(groupPosition, childPosition); final GpxInfo child = getChild(groupPosition, childPosition);
if (v == null) { if (v == null) {
@ -816,9 +811,9 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
checkItem.setVisibility(View.GONE); checkItem.setVisibility(View.GONE);
} }
final boolean isChecked; final boolean isChecked;
if(child.currentlyRecordingTrack) { if (child.currentlyRecordingTrack) {
isChecked = selectedGpxHelper.getSelectedCurrentRecordingTrack() != null; isChecked = selectedGpxHelper.getSelectedCurrentRecordingTrack() != null;
} else { } else {
final SelectedGpxFile selectedGpxFile = selectedGpxHelper.getSelectedFileByName(child.getFileName()); final SelectedGpxFile selectedGpxFile = selectedGpxHelper.getSelectedFileByName(child.getFileName());
@ -896,7 +891,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
@Override @Override
public String getGroup(int groupPosition) { public String getGroup(int groupPosition) {
if(isSelectedGroup(groupPosition)) { if (isSelectedGroup(groupPosition)) {
return app.getString(R.string.shared_string_selected); return app.getString(R.string.shared_string_selected);
} }
return category.get(getGroupPosition(groupPosition)); return category.get(getGroupPosition(groupPosition));
@ -1085,7 +1080,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
protected String doInBackground(GpxInfo... params) { protected String doInBackground(GpxInfo... params) {
for (GpxInfo info : params) { for (GpxInfo info : params) {
if (!isCancelled()) { if (!isCancelled()) {
if(!info.currentlyRecordingTrack) { if (!info.currentlyRecordingTrack) {
info.setGpx(GPXUtilities.loadGPXFile(app, info.file)); info.setGpx(GPXUtilities.loadGPXFile(app, info.file));
} }
publishProgress(info); publishProgress(info);
@ -1183,7 +1178,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
if (!selectionMode) { if (!selectionMode) {
Intent newIntent = new Intent(getActivity(), getMyApplication().getAppCustomization().getTrackActivity()); Intent newIntent = new Intent(getActivity(), getMyApplication().getAppCustomization().getTrackActivity());
// causes wrong position caching: newIntent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); // causes wrong position caching: newIntent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
if(item.currentlyRecordingTrack) { if (item.currentlyRecordingTrack) {
newIntent.putExtra(TrackActivity.CURRENT_RECORDING, true); newIntent.putExtra(TrackActivity.CURRENT_RECORDING, true);
} else { } else {
newIntent.putExtra(TrackActivity.TRACK_FILE_NAME, item.file.getAbsolutePath()); newIntent.putExtra(TrackActivity.TRACK_FILE_NAME, item.file.getAbsolutePath());
@ -1298,7 +1293,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
} else { } else {
viewName.setTypeface(Typeface.DEFAULT, Typeface.NORMAL); viewName.setTypeface(Typeface.DEFAULT, Typeface.NORMAL);
} }
SelectedGpxFile sgpx = child.currentlyRecordingTrack ? selectedGpxHelper.getSelectedCurrentRecordingTrack() : SelectedGpxFile sgpx = child.currentlyRecordingTrack ? selectedGpxHelper.getSelectedCurrentRecordingTrack() :
selectedGpxHelper.getSelectedFileByName(child.getFileName()); selectedGpxHelper.getSelectedFileByName(child.getFileName());
GPXTrackAnalysis analysis = null; GPXTrackAnalysis analysis = null;
if (sgpx != null) { if (sgpx != null) {
@ -1314,7 +1309,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
String size = ""; String size = "";
if (child.getSize() >= 0) { if (child.getSize() >= 0) {
if (child.getSize() > 100) { if (child.getSize() > 100) {
size = formatMb.format(new Object[] { (float) child.getSize() / (1 << 10) }); size = formatMb.format(new Object[]{(float) child.getSize() / (1 << 10)});
} else { } else {
size = child.getSize() + " kB"; size = child.getSize() + " kB";
} }
@ -1346,14 +1341,14 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
// if (analysis.totalDistanceMoving != 0) { // if (analysis.totalDistanceMoving != 0) {
// distance.setText(OsmAndFormatter.getFormattedDistance(analysis.totalDistanceMoving, app)); // distance.setText(OsmAndFormatter.getFormattedDistance(analysis.totalDistanceMoving, app));
// } else { // } else {
distance.setText(OsmAndFormatter.getFormattedDistance(analysis.totalDistance, app)); distance.setText(OsmAndFormatter.getFormattedDistance(analysis.totalDistance, app));
// } // }
if (analysis.isTimeSpecified()) { if (analysis.isTimeSpecified()) {
// if (analysis.isTimeMoving()) { // if (analysis.isTimeMoving()) {
// time.setText(Algorithms.formatDuration((int) (analysis.timeMoving / 1000)) + ""); // time.setText(Algorithms.formatDuration((int) (analysis.timeMoving / 1000)) + "");
// } else { // } else {
time.setText(Algorithms.formatDuration((int) (analysis.timeSpan / 1000)) + ""); time.setText(Algorithms.formatDuration((int) (analysis.timeSpan / 1000)) + "");
// } // }
} else { } else {
time.setText(""); time.setText("");