Merge branch 'master' into profile_select_color

# Conflicts:
#	OsmAnd/res/values/strings.xml
This commit is contained in:
madwasp79 2019-06-19 15:53:10 +03:00
commit 55d2b0d412
13 changed files with 255 additions and 65 deletions

View file

@ -866,6 +866,11 @@
</intent-filter>
</service>
<service
android:name="net.osmand.plus.download.DownloadService"
android:label="@string/process_downloading_service"
android:stopWithTask="false" />
<receiver android:name="net.osmand.plus.OnNavigationServiceAlarmReceiver" />
<receiver android:name="net.osmand.plus.notifications.NotificationDismissReceiver" />

View file

@ -3470,4 +3470,6 @@
<string name="poi_defibrillator_location">Местонахождение</string>
<string name="poi_charcoal_pile">Куча для выжига угля</string>
</resources>

View file

@ -3961,4 +3961,6 @@
<string name="poi_changing_table_fee_yes">Changing table fee: yes</string>
<string name="poi_changing_table_fee_no">Changing table fee: no</string>
<string name="poi_charcoal_pile">Charcoal pile</string>
</resources>

View file

@ -11,6 +11,7 @@
Thx - Hardy
-->
<string name="process_downloading_service">OsmAnd downloading service</string>
<string name="shared_string_color_magenta">Magenta</string>
<string name="shared_string_icon">Icon</string>
<string name="app_profile_custom_nav_subtitle"></string>

View file

@ -1,14 +1,5 @@
package net.osmand.plus;
import java.util.ArrayList;
import java.util.List;
import net.osmand.plus.notifications.ErrorNotification;
import net.osmand.plus.notifications.GpxNotification;
import net.osmand.plus.notifications.NavigationNotification;
import net.osmand.plus.notifications.OsmandNotification;
import net.osmand.plus.notifications.OsmandNotification.NotificationType;
import android.annotation.TargetApi;
import android.app.Notification;
import android.app.NotificationChannel;
@ -19,6 +10,16 @@ import android.support.annotation.Nullable;
import android.support.v4.app.NotificationCompat.Builder;
import android.support.v4.app.NotificationManagerCompat;
import net.osmand.plus.notifications.DownloadNotification;
import net.osmand.plus.notifications.ErrorNotification;
import net.osmand.plus.notifications.GpxNotification;
import net.osmand.plus.notifications.NavigationNotification;
import net.osmand.plus.notifications.OsmandNotification;
import net.osmand.plus.notifications.OsmandNotification.NotificationType;
import java.util.ArrayList;
import java.util.List;
public class NotificationHelper {
public static final String NOTIFICATION_CHANEL_ID = "osmand_background_service";
@ -26,6 +27,7 @@ public class NotificationHelper {
private NavigationNotification navigationNotification;
private GpxNotification gpxNotification;
private DownloadNotification downloadNotification;
private ErrorNotification errorNotification;
private List<OsmandNotification> all = new ArrayList<>();
@ -37,9 +39,11 @@ public class NotificationHelper {
private void init() {
navigationNotification = new NavigationNotification(app);
gpxNotification = new GpxNotification(app);
downloadNotification = new DownloadNotification(app);
errorNotification = new ErrorNotification(app);
all.add(navigationNotification);
all.add(gpxNotification);
all.add(downloadNotification);
}
@NonNull
@ -59,6 +63,13 @@ public class NotificationHelper {
}
}
@Nullable
public Notification buildDownloadNotification() {
Builder notificationBuilder = downloadNotification.buildNotification(false);
return notificationBuilder != null ? notificationBuilder.build() : null;
}
private Notification buildErrorNotification() {
removeNotification(errorNotification.getType());
setTopNotification(errorNotification);

View file

@ -50,6 +50,7 @@ import net.osmand.plus.base.MapViewTrackingUtilities;
import net.osmand.plus.dialogs.CrashBottomSheetDialogFragment;
import net.osmand.plus.dialogs.RateUsBottomSheetDialog;
import net.osmand.plus.download.DownloadIndexesThread;
import net.osmand.plus.download.DownloadService;
import net.osmand.plus.download.IndexItem;
import net.osmand.plus.helpers.AvoidSpecificRoads;
import net.osmand.plus.helpers.WaypointHelper;
@ -98,6 +99,7 @@ public class OsmandApplication extends MultiDexApplication {
Handler uiHandler;
NavigationService navigationService;
DownloadService downloadService;
OsmandAidlApi aidlApi;
@ -506,6 +508,14 @@ public class OsmandApplication extends MultiDexApplication {
this.navigationService = navigationService;
}
public DownloadService getDownloadService() {
return downloadService;
}
public void setDownloadService(DownloadService downloadService) {
this.downloadService = downloadService;
}
public OsmandAidlApi getAidlApi() {
return aidlApi;
}
@ -889,6 +899,15 @@ public class OsmandApplication extends MultiDexApplication {
//getNotificationHelper().showNotifications();
}
public void startDownloadService() {
final Intent serviceIntent = new Intent(this, DownloadService.class);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
startForegroundService(serviceIntent);
} else {
startService(serviceIntent);
}
}
public String getLangTranslation(String l) {
try {

View file

@ -2,11 +2,7 @@ package net.osmand.plus.download;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
@ -14,8 +10,6 @@ import android.os.AsyncTask;
import android.os.AsyncTask.Status;
import android.os.StatFs;
import android.support.annotation.UiThread;
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.NotificationCompat.Builder;
import android.support.v7.app.AlertDialog;
import android.view.View;
import android.widget.Toast;
@ -25,7 +19,6 @@ import net.osmand.IndexConstants;
import net.osmand.PlatformUtil;
import net.osmand.map.WorldRegion;
import net.osmand.map.WorldRegion.RegionParams;
import net.osmand.plus.NotificationHelper;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.OsmandSettings.OsmandPreference;
@ -34,6 +27,7 @@ import net.osmand.plus.Version;
import net.osmand.plus.base.BasicProgressAsyncTask;
import net.osmand.plus.download.DownloadFileHelper.DownloadFileShowWarning;
import net.osmand.plus.helpers.DatabaseHelper;
import net.osmand.plus.notifications.OsmandNotification;
import net.osmand.plus.resources.ResourceManager;
import net.osmand.util.Algorithms;
@ -53,7 +47,7 @@ import java.util.concurrent.ConcurrentLinkedQueue;
@SuppressLint({ "NewApi", "DefaultLocale" })
public class DownloadIndexesThread {
private final static Log LOG = PlatformUtil.getLog(DownloadIndexesThread.class);
private static final int NOTIFICATION_ID = 45;
private OsmandApplication app;
private DownloadEvents uiActivity = null;
@ -65,8 +59,7 @@ public class DownloadIndexesThread {
private int currentDownloadingItemProgress = 0;
private DownloadResources indexes;
private Notification notification;
public interface DownloadEvents {
void newDownloadIndexes();
@ -109,52 +102,8 @@ public class DownloadIndexesThread {
}
private void updateNotification() {
if(getCurrentDownloadingItem() != null) {
BasicProgressAsyncTask<?, ?, ?, ?> task = getCurrentRunningTask();
final boolean isFinished = task == null
|| task.getStatus() == AsyncTask.Status.FINISHED;
Intent contentIntent = new Intent(app, DownloadActivity.class);
PendingIntent contentPendingIntent = PendingIntent.getActivity(app, 0, contentIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
app.getNotificationHelper().createNotificationChannel();
}
Builder bld = new NotificationCompat.Builder(app, NotificationHelper.NOTIFICATION_CHANEL_ID);
String msg = Version.getAppName(app);
if(!isFinished) {
msg = task.getDescription();
}
StringBuilder contentText = new StringBuilder();
List<IndexItem> ii = getCurrentDownloadingItems();
for (IndexItem i : ii) {
if (!isFinished && task.getTag() == i) {
continue;
}
if (contentText.length() > 0) {
contentText.append(", ");
}
contentText.append(i.getVisibleName(app, app.getRegions()));
contentText.append(" ").append(i.getType().getString(app));
}
bld.setContentTitle(msg).setSmallIcon(android.R.drawable.stat_sys_download)
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
.setContentText(contentText.toString())
.setContentIntent(contentPendingIntent).setOngoing(true);
int progress = getCurrentDownloadingItemProgress();
bld.setProgress(100, Math.max(progress, 0), progress < 0);
notification = bld.build();
NotificationManager mNotificationManager = (NotificationManager) app.getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(NOTIFICATION_ID, notification);
} else {
if(notification != null) {
NotificationManager mNotificationManager = (NotificationManager) app.getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.cancel(NOTIFICATION_ID);
notification = null;
}
}
app.getNotificationHelper().refreshNotification(OsmandNotification.NotificationType.DOWNLOAD);
}
@UiThread
protected void downloadHasFinished() {
@ -162,6 +111,9 @@ public class DownloadIndexesThread {
uiActivity.downloadHasFinished();
}
updateNotification();
if (app.getDownloadService() != null) {
app.getDownloadService().stopService(app);
}
}
public void initSettingsFirstMap(WorldRegion reg) {
@ -216,6 +168,10 @@ public class DownloadIndexesThread {
return res;
}
public boolean isDownloading() {
return !indexItemDownloading.isEmpty() || currentDownloadingItem != null;
}
public boolean isDownloading(IndexItem item) {
if(item == currentDownloadingItem) {
return true;
@ -269,6 +225,9 @@ public class DownloadIndexesThread {
indexItemDownloading.add(item);
}
}
if (app.getDownloadService() == null) {
app.startDownloadService();
}
if (currentDownloadingItem == null) {
execute(new DownloadIndexesAsyncTask());
} else {

View file

@ -0,0 +1,61 @@
package net.osmand.plus.download;
import android.app.Notification;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.notifications.OsmandNotification;
public class DownloadService extends Service {
public static class DownloadServiceBinder extends Binder {
}
private DownloadServiceBinder binder = new DownloadServiceBinder();
@Override
public IBinder onBind(Intent intent) {
return binder;
}
public void stopService(Context ctx) {
final Intent serviceIntent = new Intent(ctx, DownloadService.class);
ctx.stopService(serviceIntent);
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
final OsmandApplication app = (OsmandApplication) getApplication();
app.setDownloadService(this);
Notification notification = app.getNotificationHelper().buildDownloadNotification();
if (notification != null) {
startForeground(OsmandNotification.DOWNLOAD_NOTIFICATION_SERVICE_ID, notification);
app.getNotificationHelper().refreshNotification(OsmandNotification.NotificationType.DOWNLOAD);
}
return START_NOT_STICKY;
}
@Override
public void onDestroy() {
super.onDestroy();
final OsmandApplication app = (OsmandApplication) getApplication();
app.setDownloadService(null);
// remove notification
stopForeground(Boolean.TRUE);
app.getNotificationHelper().refreshNotification(OsmandNotification.NotificationType.DOWNLOAD);
app.runInUIThread(new Runnable() {
@Override
public void run() {
app.getNotificationHelper().refreshNotification(OsmandNotification.NotificationType.DOWNLOAD);
}
}, 500);
}
}

View file

@ -0,0 +1,106 @@
package net.osmand.plus.notifications;
import android.content.Intent;
import android.os.AsyncTask;
import android.support.v4.app.NotificationCompat;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.Version;
import net.osmand.plus.base.BasicProgressAsyncTask;
import net.osmand.plus.download.DownloadActivity;
import net.osmand.plus.download.DownloadIndexesThread;
import net.osmand.plus.download.DownloadService;
import net.osmand.plus.download.IndexItem;
import java.util.List;
public class DownloadNotification extends OsmandNotification {
public final static String GROUP_NAME = "DOWNLOAD";
public DownloadNotification(OsmandApplication app) {
super(app, GROUP_NAME);
}
@Override
public void init() {
}
@Override
public NotificationType getType() {
return NotificationType.DOWNLOAD;
}
@Override
public int getPriority() {
return NotificationCompat.PRIORITY_DEFAULT;
}
@Override
public boolean isActive() {
DownloadService service = app.getDownloadService();
return isEnabled() && service != null;
}
@Override
public boolean isEnabled() {
DownloadIndexesThread downloadThread = app.getDownloadThread();
return downloadThread.isDownloading();
}
@Override
public Intent getContentIntent() {
return new Intent(app, DownloadActivity.class);
}
@Override
public NotificationCompat.Builder buildNotification(boolean wearable) {
if (!isEnabled()) {
return null;
}
icon = android.R.drawable.stat_sys_download;
ongoing = true;
DownloadIndexesThread downloadThread = app.getDownloadThread();
if (downloadThread.getCurrentDownloadingItem() == null) {
return null;
}
BasicProgressAsyncTask<?, ?, ?, ?> task = downloadThread.getCurrentRunningTask();
final boolean isFinished = task == null || task.getStatus() == AsyncTask.Status.FINISHED;
NotificationCompat.Builder notificationBuilder = createBuilder(wearable);
String msg = Version.getAppName(app);
if (!isFinished) {
msg = task.getDescription();
}
StringBuilder contentText = new StringBuilder();
List<IndexItem> ii = downloadThread.getCurrentDownloadingItems();
for (IndexItem i : ii) {
if (!isFinished && task.getTag() == i) {
continue;
}
if (contentText.length() > 0) {
contentText.append(", ");
}
contentText.append(i.getVisibleName(app, app.getRegions()));
contentText.append(" ").append(i.getType().getString(app));
}
notificationBuilder.setContentTitle(msg)
.setContentText(contentText.toString())
.setOngoing(true);
int progress = downloadThread.getCurrentDownloadingItemProgress();
notificationBuilder.setProgress(100, Math.max(progress, 0), progress < 0);
return notificationBuilder;
}
@Override
public int getOsmandNotificationId() {
return DOWNLOAD_NOTIFICATION_SERVICE_ID;
}
@Override
public int getOsmandWearableNotificationId() {
return WEAR_DOWNLOAD_NOTIFICATION_SERVICE_ID;
}
}

View file

@ -1,11 +1,13 @@
package net.osmand.plus.notifications;
import android.content.Intent;
import android.support.v4.app.NotificationCompat;
import net.osmand.plus.NavigationService;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.monitoring.OsmandMonitoringPlugin;
import net.osmand.plus.routing.RoutingHelper;
@ -41,6 +43,11 @@ public class ErrorNotification extends OsmandNotification {
return true;
}
@Override
public Intent getContentIntent() {
return new Intent(app, MapActivity.class);
}
@Override
public NotificationCompat.Builder buildNotification(boolean wearable) {
String notificationTitle;

View file

@ -14,6 +14,7 @@ import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.monitoring.OsmandMonitoringPlugin;
import net.osmand.util.Algorithms;
@ -97,6 +98,11 @@ public class GpxNotification extends OsmandNotification {
return OsmandPlugin.getEnabledPlugin(OsmandMonitoringPlugin.class) != null;
}
@Override
public Intent getContentIntent() {
return new Intent(app, MapActivity.class);
}
@Override
public void onNotificationDismissed() {
if (!wasNoDataDismissed) {

View file

@ -21,6 +21,7 @@ import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.TargetPointsHelper.TargetPoint;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.routing.RouteCalculationResult;
import net.osmand.plus.routing.RouteCalculationResult.NextDirectionInfo;
import net.osmand.plus.routing.RouteDirectionInfo;
@ -112,6 +113,11 @@ public class NavigationNotification extends OsmandNotification {
|| (routingHelper.isRoutePlanningMode() && routingHelper.isPauseNavigation());
}
@Override
public Intent getContentIntent() {
return new Intent(app, MapActivity.class);
}
@Override
public Builder buildNotification(boolean wearable) {
if (!isEnabled()) {

View file

@ -18,11 +18,13 @@ public abstract class OsmandNotification {
public final static int NAVIGATION_NOTIFICATION_SERVICE_ID = 5;
public final static int GPX_NOTIFICATION_SERVICE_ID = 6;
public final static int ERROR_NOTIFICATION_SERVICE_ID = 7;
public final static int DOWNLOAD_NOTIFICATION_SERVICE_ID = 8;
public final static int TOP_NOTIFICATION_SERVICE_ID = 100;
public final static int WEAR_NAVIGATION_NOTIFICATION_SERVICE_ID = 1005;
public final static int WEAR_GPX_NOTIFICATION_SERVICE_ID = 1006;
public final static int WEAR_ERROR_NOTIFICATION_SERVICE_ID = 1007;
public final static int WEAR_DOWNLOAD_NOTIFICATION_SERVICE_ID = 1008;
protected OsmandApplication app;
@ -38,6 +40,7 @@ public abstract class OsmandNotification {
GPX,
GPS,
ERROR,
DOWNLOAD,
}
public OsmandNotification(OsmandApplication app, String groupName) {
@ -65,7 +68,7 @@ public abstract class OsmandNotification {
@SuppressLint("InlinedApi")
protected Builder createBuilder(boolean wearable) {
Intent contentIntent = new Intent(app, MapActivity.class);
Intent contentIntent = getContentIntent();
PendingIntent contentPendingIntent = PendingIntent.getActivity(app, 0, contentIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
@ -101,6 +104,8 @@ public abstract class OsmandNotification {
public abstract boolean isEnabled();
public abstract Intent getContentIntent();
public void setupNotification(Notification notification) {
}