diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
commit | 6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoScreenChangeListener.java | |
parent | Initial commit. (diff) | |
download | thunderbird-upstream.tar.xz thunderbird-upstream.zip |
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoScreenChangeListener.java')
-rw-r--r-- | mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoScreenChangeListener.java | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoScreenChangeListener.java b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoScreenChangeListener.java new file mode 100644 index 0000000000..dc36c6b631 --- /dev/null +++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoScreenChangeListener.java @@ -0,0 +1,76 @@ +/* -*- Mode: Java; c-basic-offset: 2; tab-width: 20; indent-tabs-mode: nil; -*- + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +package org.mozilla.gecko; + +import android.annotation.TargetApi; +import android.content.Context; +import android.hardware.display.DisplayManager; +import android.os.Build; +import android.util.Log; +import android.view.Display; + +@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) +public class GeckoScreenChangeListener implements DisplayManager.DisplayListener { + private static final String LOGTAG = "ScreenChangeListener"; + private static final boolean DEBUG = false; + + public GeckoScreenChangeListener() {} + + @Override + public void onDisplayAdded(final int displayId) {} + + @Override + public void onDisplayRemoved(final int displayId) {} + + @Override + public void onDisplayChanged(final int displayId) { + if (DEBUG) { + Log.d(LOGTAG, "onDisplayChanged"); + } + + // Even if onDisplayChanged is called, Configuration may not updated yet. + // So we use Display's data instead. + if (displayId != Display.DEFAULT_DISPLAY) { + if (DEBUG) { + Log.d(LOGTAG, "Primary display is only supported"); + } + return; + } + + final DisplayManager displayManager = getDisplayManager(); + if (displayManager == null) { + return; + } + + if (GeckoScreenOrientation.getInstance().update(displayManager.getDisplay(displayId))) { + // refreshScreenInfo is already called. + return; + } + + ScreenManagerHelper.refreshScreenInfo(); + } + + private static DisplayManager getDisplayManager() { + return (DisplayManager) + GeckoAppShell.getApplicationContext().getSystemService(Context.DISPLAY_SERVICE); + } + + public void enable() { + final DisplayManager displayManager = getDisplayManager(); + if (displayManager == null) { + return; + } + displayManager.registerDisplayListener(this, null); + } + + public void disable() { + final DisplayManager displayManager = getDisplayManager(); + if (displayManager == null) { + return; + } + displayManager.unregisterDisplayListener(this); + } +} |