Fix turn screen on and notifications flickering

This commit is contained in:
max-klaus 2019-08-14 13:36:52 +03:00
parent e04a63987c
commit ceff1bef41
6 changed files with 37 additions and 21 deletions

View file

@ -286,7 +286,7 @@ public class NavigationService extends Service implements LocationListener {
@Override
public void onTaskRemoved(Intent rootIntent) {
OsmandApplication app = ((OsmandApplication) getApplication());
app.getNotificationHelper().removeNotifications();
app.getNotificationHelper().removeNotifications(false);
if (app.getNavigationService() != null &&
app.getSettings().DISABLE_RECORDING_ONCE_APP_KILLED.get()) {
NavigationService.this.stopSelf();

View file

@ -155,11 +155,13 @@ public class NotificationHelper {
}
}
public void removeNotifications() {
public void removeNotifications(boolean inactiveOnly) {
for (OsmandNotification notification : all) {
if (!inactiveOnly || !notification.isActive()) {
notification.removeNotification();
}
}
}
@TargetApi(26)
public void createNotificationChannel() {

View file

@ -242,7 +242,7 @@ public class OsmandApplication extends MultiDexApplication {
if(RateUsBottomSheetDialog.shouldShow(this)) {
osmandSettings.RATE_US_STATE.set(RateUsBottomSheetDialog.RateUsState.IGNORED);
}
getNotificationHelper().removeNotifications();
getNotificationHelper().removeNotifications(false);
}
public RendererRegistry getRendererRegistry() {

View file

@ -1315,7 +1315,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
@Override
protected void onStop() {
getMyApplication().getNotificationHelper().removeNotifications();
getMyApplication().getNotificationHelper().removeNotifications(true);
if(pendingPause) {
onPauseActivity();
}
@ -1404,7 +1404,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
}
public void updateApplicationModeSettings() {
changeKeyguardFlags(true);
changeKeyguardFlags();
updateMapSettings();
mapViewTrackingUtilities.updateSettings();
//app.getRoutingHelper().setAppMode(settings.getApplicationMode());
@ -1902,25 +1902,29 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
return oldPoint.getLayerId().equals(layerId) && oldPoint.getId().equals(point.getId());
}
public void changeKeyguardFlags(final boolean enable) {
public void changeKeyguardFlags() {
changeKeyguardFlags(false, true);
}
private void changeKeyguardFlags(boolean enable, boolean forceKeepScreenOn) {
if (enable) {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED,
WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
setKeepScreenOn(true);
} else {
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
setKeepScreenOn(false);
setKeepScreenOn(forceKeepScreenOn);
}
}
@Override
public void lock() {
changeKeyguardFlags(false);
changeKeyguardFlags(false, false);
}
@Override
public void unlock() {
changeKeyguardFlags(true);
changeKeyguardFlags(true, false);
}
private class ScreenOffReceiver extends BroadcastReceiver {
@ -1986,14 +1990,14 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
@Override
public void routeWasCancelled() {
changeKeyguardFlags(true);
changeKeyguardFlags();
}
@Override
public void routeWasFinished() {
if (!mIsDestroyed) {
DestinationReachedMenu.show(this);
changeKeyguardFlags(true);
changeKeyguardFlags();
}
}

View file

@ -31,7 +31,6 @@ public class LockHelper implements SensorEventListener {
private OsmandApplication app;
private CommonPreference<Integer> turnScreenOnTime;
private CommonPreference<Boolean> turnScreenOnSensor;
private boolean active;
@Nullable
private LockUIAdapter lockUIAdapter;
@ -102,12 +101,14 @@ public class LockHelper implements SensorEventListener {
private void timedUnlock(final long millis) {
uiHandler.removeCallbacks(lockRunnable);
if (!active && wakeLock == null) {
if (wakeLock == null) {
uiHandler.post(new Runnable() {
@Override
public void run() {
if (wakeLock == null) {
unlock();
}
}
});
}
uiHandler.postDelayed(lockRunnable, millis);
@ -159,13 +160,11 @@ public class LockHelper implements SensorEventListener {
}
public void onStart(@NonNull Activity activity) {
active = true;
switchSensorOff();
}
public void onStop(@NonNull Activity activity) {
lock();
active = false;
if (!activity.isFinishing() && isSensorEnabled()) {
switchSensorOn();
}

View file

@ -26,7 +26,6 @@ public abstract class OsmandNotification {
public final static int WEAR_ERROR_NOTIFICATION_SERVICE_ID = 1007;
public final static int WEAR_DOWNLOAD_NOTIFICATION_SERVICE_ID = 1008;
protected OsmandApplication app;
protected boolean ongoing = true;
protected int color;
@ -35,6 +34,8 @@ public abstract class OsmandNotification {
private String groupName;
private Notification currentNotification;
public enum NotificationType {
NAVIGATION,
GPX,
@ -125,7 +126,7 @@ public abstract class OsmandNotification {
if (isEnabled()) {
Builder notificationBuilder = buildNotification(false);
if (notificationBuilder != null) {
Notification notification = notificationBuilder.build();
Notification notification = getNotification(notificationBuilder);
setupNotification(notification);
notificationManager.notify(top ? TOP_NOTIFICATION_SERVICE_ID : getOsmandNotificationId(), notification);
notifyWearable(notificationManager);
@ -140,10 +141,10 @@ public abstract class OsmandNotification {
if (isEnabled()) {
Builder notificationBuilder = buildNotification(false);
if (notificationBuilder != null) {
Notification notification = notificationBuilder.build();
Notification notification = getNotification(notificationBuilder);
setupNotification(notification);
if (top) {
notificationManager.cancel(getOsmandNotificationId());
//notificationManager.cancel(getOsmandNotificationId());
notificationManager.notify(TOP_NOTIFICATION_SERVICE_ID, notification);
} else {
notificationManager.notify(getOsmandNotificationId(), notification);
@ -159,7 +160,17 @@ public abstract class OsmandNotification {
return false;
}
private Notification getNotification(Builder notificationBuilder) {
Notification notification = currentNotification;
if (notification == null) {
notification = notificationBuilder.build();
currentNotification = notification;
}
return notification;
}
public void removeNotification() {
currentNotification = null;
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(app);
notificationManager.cancel(getOsmandNotificationId());
notificationManager.cancel(getOsmandWearableNotificationId());