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);
|
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) {
|
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());
|
List<Map.Entry<K, V>> list = new LinkedList<>(map.entrySet());
|
||||||
Collections.sort(list, new Comparator<Map.Entry<K, V>>() {
|
Collections.sort(list, new Comparator<Map.Entry<K, V>>() {
|
||||||
|
|
|
@ -812,9 +812,7 @@ public class ContextMenuLayer extends OsmandMapLayer {
|
||||||
boolean processed = hideVisibleMenues();
|
boolean processed = hideVisibleMenues();
|
||||||
processed |= menu.onSingleTapOnMap();
|
processed |= menu.onSingleTapOnMap();
|
||||||
if (!processed) {
|
if (!processed) {
|
||||||
MapControlsLayer controlsLayer = activity.getMapLayers().getMapControlsLayer();
|
activity.getMapLayers().getMapControlsLayer().switchMapControlsVisibility(true);
|
||||||
controlsLayer.switchMapControlsVisibility();
|
|
||||||
controlsLayer.switchSystemUiVisibility();
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -656,16 +656,9 @@ public class MapControlsLayer extends OsmandMapLayer {
|
||||||
zoomOutButton.setOnLongClickListener(listener);
|
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() {
|
public void showMapControls() {
|
||||||
mapActivity.findViewById(R.id.MapHudButtonsOverlay).setVisibility(View.VISIBLE);
|
mapActivity.findViewById(R.id.MapHudButtonsOverlay).setVisibility(View.VISIBLE);
|
||||||
showSystemUI();
|
AndroidUtils.showSystemUI(mapActivity);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void hideMapControls() {
|
public void hideMapControls() {
|
||||||
|
@ -681,49 +674,23 @@ public class MapControlsLayer extends OsmandMapLayer {
|
||||||
return mapActivity.findViewById(R.id.MapHudButtonsOverlay).getVisibility() == View.VISIBLE;
|
return mapActivity.findViewById(R.id.MapHudButtonsOverlay).getVisibility() == View.VISIBLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void switchMapControlsVisibility() {
|
public void switchMapControlsVisibility(boolean switchSystemUiVisibility) {
|
||||||
if (!isFullscreenModeAllowed()) {
|
if (app.getRoutingHelper().isFollowingMode() || app.getRoutingHelper().isPauseNavigation()
|
||||||
|
|| mapActivity.getMeasurementToolFragment() != null
|
||||||
|
|| mapActivity.getPlanRouteFragment() != null
|
||||||
|
|| mapActivity.getMapLayers().getRulerControlLayer().rulerModeOn()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (isMapControlsVisible()) {
|
if (isMapControlsVisible()) {
|
||||||
hideMapControls();
|
AndroidUtils.hideSystemUI(mapActivity);
|
||||||
|
if (switchSystemUiVisibility) {
|
||||||
|
hideMapControls();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
showMapControls();
|
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() {
|
public void startNavigation() {
|
||||||
OsmandApplication app = mapActivity.getMyApplication();
|
OsmandApplication app = mapActivity.getMyApplication();
|
||||||
RoutingHelper routingHelper = app.getRoutingHelper();
|
RoutingHelper routingHelper = app.getRoutingHelper();
|
||||||
|
|
Loading…
Reference in a new issue