Fix turn screen on and notifications flickering
This commit is contained in:
parent
e04a63987c
commit
ceff1bef41
6 changed files with 37 additions and 21 deletions
|
@ -286,7 +286,7 @@ public class NavigationService extends Service implements LocationListener {
|
||||||
@Override
|
@Override
|
||||||
public void onTaskRemoved(Intent rootIntent) {
|
public void onTaskRemoved(Intent rootIntent) {
|
||||||
OsmandApplication app = ((OsmandApplication) getApplication());
|
OsmandApplication app = ((OsmandApplication) getApplication());
|
||||||
app.getNotificationHelper().removeNotifications();
|
app.getNotificationHelper().removeNotifications(false);
|
||||||
if (app.getNavigationService() != null &&
|
if (app.getNavigationService() != null &&
|
||||||
app.getSettings().DISABLE_RECORDING_ONCE_APP_KILLED.get()) {
|
app.getSettings().DISABLE_RECORDING_ONCE_APP_KILLED.get()) {
|
||||||
NavigationService.this.stopSelf();
|
NavigationService.this.stopSelf();
|
||||||
|
|
|
@ -155,9 +155,11 @@ public class NotificationHelper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeNotifications() {
|
public void removeNotifications(boolean inactiveOnly) {
|
||||||
for (OsmandNotification notification : all) {
|
for (OsmandNotification notification : all) {
|
||||||
notification.removeNotification();
|
if (!inactiveOnly || !notification.isActive()) {
|
||||||
|
notification.removeNotification();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -242,7 +242,7 @@ public class OsmandApplication extends MultiDexApplication {
|
||||||
if(RateUsBottomSheetDialog.shouldShow(this)) {
|
if(RateUsBottomSheetDialog.shouldShow(this)) {
|
||||||
osmandSettings.RATE_US_STATE.set(RateUsBottomSheetDialog.RateUsState.IGNORED);
|
osmandSettings.RATE_US_STATE.set(RateUsBottomSheetDialog.RateUsState.IGNORED);
|
||||||
}
|
}
|
||||||
getNotificationHelper().removeNotifications();
|
getNotificationHelper().removeNotifications(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public RendererRegistry getRendererRegistry() {
|
public RendererRegistry getRendererRegistry() {
|
||||||
|
|
|
@ -1315,7 +1315,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onStop() {
|
protected void onStop() {
|
||||||
getMyApplication().getNotificationHelper().removeNotifications();
|
getMyApplication().getNotificationHelper().removeNotifications(true);
|
||||||
if(pendingPause) {
|
if(pendingPause) {
|
||||||
onPauseActivity();
|
onPauseActivity();
|
||||||
}
|
}
|
||||||
|
@ -1404,7 +1404,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateApplicationModeSettings() {
|
public void updateApplicationModeSettings() {
|
||||||
changeKeyguardFlags(true);
|
changeKeyguardFlags();
|
||||||
updateMapSettings();
|
updateMapSettings();
|
||||||
mapViewTrackingUtilities.updateSettings();
|
mapViewTrackingUtilities.updateSettings();
|
||||||
//app.getRoutingHelper().setAppMode(settings.getApplicationMode());
|
//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());
|
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) {
|
if (enable) {
|
||||||
getWindow().setFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED,
|
getWindow().setFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED,
|
||||||
WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
|
WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
|
||||||
setKeepScreenOn(true);
|
setKeepScreenOn(true);
|
||||||
} else {
|
} else {
|
||||||
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
|
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
|
||||||
setKeepScreenOn(false);
|
setKeepScreenOn(forceKeepScreenOn);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void lock() {
|
public void lock() {
|
||||||
changeKeyguardFlags(false);
|
changeKeyguardFlags(false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void unlock() {
|
public void unlock() {
|
||||||
changeKeyguardFlags(true);
|
changeKeyguardFlags(true, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private class ScreenOffReceiver extends BroadcastReceiver {
|
private class ScreenOffReceiver extends BroadcastReceiver {
|
||||||
|
@ -1986,14 +1990,14 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void routeWasCancelled() {
|
public void routeWasCancelled() {
|
||||||
changeKeyguardFlags(true);
|
changeKeyguardFlags();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void routeWasFinished() {
|
public void routeWasFinished() {
|
||||||
if (!mIsDestroyed) {
|
if (!mIsDestroyed) {
|
||||||
DestinationReachedMenu.show(this);
|
DestinationReachedMenu.show(this);
|
||||||
changeKeyguardFlags(true);
|
changeKeyguardFlags();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,6 @@ public class LockHelper implements SensorEventListener {
|
||||||
private OsmandApplication app;
|
private OsmandApplication app;
|
||||||
private CommonPreference<Integer> turnScreenOnTime;
|
private CommonPreference<Integer> turnScreenOnTime;
|
||||||
private CommonPreference<Boolean> turnScreenOnSensor;
|
private CommonPreference<Boolean> turnScreenOnSensor;
|
||||||
private boolean active;
|
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private LockUIAdapter lockUIAdapter;
|
private LockUIAdapter lockUIAdapter;
|
||||||
|
@ -102,11 +101,13 @@ public class LockHelper implements SensorEventListener {
|
||||||
|
|
||||||
private void timedUnlock(final long millis) {
|
private void timedUnlock(final long millis) {
|
||||||
uiHandler.removeCallbacks(lockRunnable);
|
uiHandler.removeCallbacks(lockRunnable);
|
||||||
if (!active && wakeLock == null) {
|
if (wakeLock == null) {
|
||||||
uiHandler.post(new Runnable() {
|
uiHandler.post(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
unlock();
|
if (wakeLock == null) {
|
||||||
|
unlock();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -159,13 +160,11 @@ public class LockHelper implements SensorEventListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onStart(@NonNull Activity activity) {
|
public void onStart(@NonNull Activity activity) {
|
||||||
active = true;
|
|
||||||
switchSensorOff();
|
switchSensorOff();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onStop(@NonNull Activity activity) {
|
public void onStop(@NonNull Activity activity) {
|
||||||
lock();
|
lock();
|
||||||
active = false;
|
|
||||||
if (!activity.isFinishing() && isSensorEnabled()) {
|
if (!activity.isFinishing() && isSensorEnabled()) {
|
||||||
switchSensorOn();
|
switchSensorOn();
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,6 @@ public abstract class OsmandNotification {
|
||||||
public final static int WEAR_ERROR_NOTIFICATION_SERVICE_ID = 1007;
|
public final static int WEAR_ERROR_NOTIFICATION_SERVICE_ID = 1007;
|
||||||
public final static int WEAR_DOWNLOAD_NOTIFICATION_SERVICE_ID = 1008;
|
public final static int WEAR_DOWNLOAD_NOTIFICATION_SERVICE_ID = 1008;
|
||||||
|
|
||||||
|
|
||||||
protected OsmandApplication app;
|
protected OsmandApplication app;
|
||||||
protected boolean ongoing = true;
|
protected boolean ongoing = true;
|
||||||
protected int color;
|
protected int color;
|
||||||
|
@ -35,6 +34,8 @@ public abstract class OsmandNotification {
|
||||||
|
|
||||||
private String groupName;
|
private String groupName;
|
||||||
|
|
||||||
|
private Notification currentNotification;
|
||||||
|
|
||||||
public enum NotificationType {
|
public enum NotificationType {
|
||||||
NAVIGATION,
|
NAVIGATION,
|
||||||
GPX,
|
GPX,
|
||||||
|
@ -125,7 +126,7 @@ public abstract class OsmandNotification {
|
||||||
if (isEnabled()) {
|
if (isEnabled()) {
|
||||||
Builder notificationBuilder = buildNotification(false);
|
Builder notificationBuilder = buildNotification(false);
|
||||||
if (notificationBuilder != null) {
|
if (notificationBuilder != null) {
|
||||||
Notification notification = notificationBuilder.build();
|
Notification notification = getNotification(notificationBuilder);
|
||||||
setupNotification(notification);
|
setupNotification(notification);
|
||||||
notificationManager.notify(top ? TOP_NOTIFICATION_SERVICE_ID : getOsmandNotificationId(), notification);
|
notificationManager.notify(top ? TOP_NOTIFICATION_SERVICE_ID : getOsmandNotificationId(), notification);
|
||||||
notifyWearable(notificationManager);
|
notifyWearable(notificationManager);
|
||||||
|
@ -140,10 +141,10 @@ public abstract class OsmandNotification {
|
||||||
if (isEnabled()) {
|
if (isEnabled()) {
|
||||||
Builder notificationBuilder = buildNotification(false);
|
Builder notificationBuilder = buildNotification(false);
|
||||||
if (notificationBuilder != null) {
|
if (notificationBuilder != null) {
|
||||||
Notification notification = notificationBuilder.build();
|
Notification notification = getNotification(notificationBuilder);
|
||||||
setupNotification(notification);
|
setupNotification(notification);
|
||||||
if (top) {
|
if (top) {
|
||||||
notificationManager.cancel(getOsmandNotificationId());
|
//notificationManager.cancel(getOsmandNotificationId());
|
||||||
notificationManager.notify(TOP_NOTIFICATION_SERVICE_ID, notification);
|
notificationManager.notify(TOP_NOTIFICATION_SERVICE_ID, notification);
|
||||||
} else {
|
} else {
|
||||||
notificationManager.notify(getOsmandNotificationId(), notification);
|
notificationManager.notify(getOsmandNotificationId(), notification);
|
||||||
|
@ -159,7 +160,17 @@ public abstract class OsmandNotification {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Notification getNotification(Builder notificationBuilder) {
|
||||||
|
Notification notification = currentNotification;
|
||||||
|
if (notification == null) {
|
||||||
|
notification = notificationBuilder.build();
|
||||||
|
currentNotification = notification;
|
||||||
|
}
|
||||||
|
return notification;
|
||||||
|
}
|
||||||
|
|
||||||
public void removeNotification() {
|
public void removeNotification() {
|
||||||
|
currentNotification = null;
|
||||||
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(app);
|
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(app);
|
||||||
notificationManager.cancel(getOsmandNotificationId());
|
notificationManager.cancel(getOsmandNotificationId());
|
||||||
notificationManager.cancel(getOsmandWearableNotificationId());
|
notificationManager.cancel(getOsmandWearableNotificationId());
|
||||||
|
|
Loading…
Reference in a new issue