Extract methods for work with system UI to AndroidUtils
This commit is contained in:
parent
793b8793f2
commit
d7a7b9aa29
3 changed files with 43 additions and 46 deletions
|
@ -243,6 +243,38 @@ public class AndroidUtils {
|
|||
return new PointF(centroidX, centroidY);
|
||||
}
|
||||
|
||||
public static void showSystemUI(Activity activity) {
|
||||
if (Build.VERSION.SDK_INT >= 19 && !isSystemUiVisible(activity)) {
|
||||
switchSystemUiVisibility(activity);
|
||||
}
|
||||
}
|
||||
|
||||
public static void hideSystemUI(Activity activity) {
|
||||
if (Build.VERSION.SDK_INT >= 19 && isSystemUiVisible(activity)) {
|
||||
switchSystemUiVisibility(activity);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isSystemUiVisible(Activity activity) {
|
||||
if (Build.VERSION.SDK_INT >= 19) {
|
||||
int uiOptions = activity.getWindow().getDecorView().getSystemUiVisibility();
|
||||
return !((uiOptions | View.SYSTEM_UI_FLAG_FULLSCREEN) == uiOptions);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void switchSystemUiVisibility(Activity activity) {
|
||||
if (Build.VERSION.SDK_INT < 19) {
|
||||
return;
|
||||
}
|
||||
View decorView = activity.getWindow().getDecorView();
|
||||
int uiOptions = decorView.getSystemUiVisibility();
|
||||
uiOptions ^= View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
|
||||
uiOptions ^= View.SYSTEM_UI_FLAG_FULLSCREEN;
|
||||
uiOptions ^= View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
|
||||
decorView.setSystemUiVisibility(uiOptions);
|
||||
}
|
||||
|
||||
public static <K, V extends Comparable<? super V>> Map<K, V> sortByValue(Map<K, V> map) {
|
||||
List<Map.Entry<K, V>> list = new LinkedList<>(map.entrySet());
|
||||
Collections.sort(list, new Comparator<Map.Entry<K, V>>() {
|
||||
|
|
|
@ -812,9 +812,7 @@ public class ContextMenuLayer extends OsmandMapLayer {
|
|||
boolean processed = hideVisibleMenues();
|
||||
processed |= menu.onSingleTapOnMap();
|
||||
if (!processed) {
|
||||
MapControlsLayer controlsLayer = activity.getMapLayers().getMapControlsLayer();
|
||||
controlsLayer.switchMapControlsVisibility();
|
||||
controlsLayer.switchSystemUiVisibility();
|
||||
activity.getMapLayers().getMapControlsLayer().switchMapControlsVisibility(true);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -656,16 +656,9 @@ public class MapControlsLayer extends OsmandMapLayer {
|
|||
zoomOutButton.setOnLongClickListener(listener);
|
||||
}
|
||||
|
||||
private boolean isFullscreenModeAllowed() {
|
||||
return !(app.getRoutingHelper().isFollowingMode() || app.getRoutingHelper().isPauseNavigation()
|
||||
|| mapActivity.getMeasurementToolFragment() != null
|
||||
|| mapActivity.getPlanRouteFragment() != null
|
||||
|| mapActivity.getMapLayers().getRulerControlLayer().rulerModeOn());
|
||||
}
|
||||
|
||||
public void showMapControls() {
|
||||
mapActivity.findViewById(R.id.MapHudButtonsOverlay).setVisibility(View.VISIBLE);
|
||||
showSystemUI();
|
||||
AndroidUtils.showSystemUI(mapActivity);
|
||||
}
|
||||
|
||||
public void hideMapControls() {
|
||||
|
@ -681,49 +674,23 @@ public class MapControlsLayer extends OsmandMapLayer {
|
|||
return mapActivity.findViewById(R.id.MapHudButtonsOverlay).getVisibility() == View.VISIBLE;
|
||||
}
|
||||
|
||||
public void switchMapControlsVisibility() {
|
||||
if (!isFullscreenModeAllowed()) {
|
||||
public void switchMapControlsVisibility(boolean switchSystemUiVisibility) {
|
||||
if (app.getRoutingHelper().isFollowingMode() || app.getRoutingHelper().isPauseNavigation()
|
||||
|| mapActivity.getMeasurementToolFragment() != null
|
||||
|| mapActivity.getPlanRouteFragment() != null
|
||||
|| mapActivity.getMapLayers().getRulerControlLayer().rulerModeOn()) {
|
||||
return;
|
||||
}
|
||||
if (isMapControlsVisible()) {
|
||||
hideMapControls();
|
||||
AndroidUtils.hideSystemUI(mapActivity);
|
||||
if (switchSystemUiVisibility) {
|
||||
hideMapControls();
|
||||
}
|
||||
} else {
|
||||
showMapControls();
|
||||
}
|
||||
}
|
||||
|
||||
public void showSystemUI() {
|
||||
if (Build.VERSION.SDK_INT >= 19 && !isSystemUiVisible()) {
|
||||
switchSystemUiVisibility();
|
||||
}
|
||||
}
|
||||
|
||||
public void hideSystemUI() {
|
||||
if (Build.VERSION.SDK_INT >= 19 && isSystemUiVisible()) {
|
||||
switchSystemUiVisibility();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isSystemUiVisible() {
|
||||
if (Build.VERSION.SDK_INT >= 19) {
|
||||
int uiOptions = mapActivity.getWindow().getDecorView().getSystemUiVisibility();
|
||||
return !((uiOptions | View.SYSTEM_UI_FLAG_FULLSCREEN) == uiOptions);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void switchSystemUiVisibility() {
|
||||
if (!isFullscreenModeAllowed() || Build.VERSION.SDK_INT < 19) {
|
||||
return;
|
||||
}
|
||||
View decorView = mapActivity.getWindow().getDecorView();
|
||||
int uiOptions = decorView.getSystemUiVisibility();
|
||||
uiOptions ^= View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
|
||||
uiOptions ^= View.SYSTEM_UI_FLAG_FULLSCREEN;
|
||||
uiOptions ^= View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
|
||||
decorView.setSystemUiVisibility(uiOptions);
|
||||
}
|
||||
|
||||
public void startNavigation() {
|
||||
OsmandApplication app = mapActivity.getMyApplication();
|
||||
RoutingHelper routingHelper = app.getRoutingHelper();
|
||||
|
|
Loading…
Reference in a new issue