bug 951959 - GeckoScreenOrientationListener is invoked hundreds of times during page load r=rnewman

This commit is contained in:
Brad Lassey 2014-01-14 22:46:26 -08:00
Родитель 2fae329855
Коммит d853ca24d6
1 изменённых файлов: 26 добавлений и 21 удалений

Просмотреть файл

@ -1,4 +1,5 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; 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/. */
@ -25,7 +26,7 @@ public class GeckoScreenOrientationListener {
@Override
public void onOrientationChanged(int aOrientation) {
GeckoScreenOrientationListener.getInstance().updateScreenOrientation();
GeckoScreenOrientationListener.getInstance().updateScreenOrientation(aOrientation);
}
}
@ -149,23 +150,27 @@ public class GeckoScreenOrientationListener {
}
private void updateScreenOrientation() {
Context context = GeckoAppShell.getContext();
int rotation = mDefaultOrientation;
if (context instanceof Activity) {
rotation = ((Activity)context).getWindowManager().getDefaultDisplay().getRotation();
}
Context context = GeckoAppShell.getContext();
int rotation = mDefaultOrientation;
if (context instanceof Activity) {
rotation = ((Activity)context).getWindowManager().getDefaultDisplay().getRotation();
}
updateScreenOrientation(rotation * 90);
}
private void updateScreenOrientation(int aOrientation) {
short previousOrientation = mOrientation;
if (rotation == Surface.ROTATION_0) {
if (aOrientation >= 315 || aOrientation < 45) {
mOrientation = eScreenOrientation_PortraitPrimary;
} else if (rotation == Surface.ROTATION_180) {
mOrientation = eScreenOrientation_PortraitSecondary;
} else if (rotation == Surface.ROTATION_270) {
mOrientation = eScreenOrientation_LandscapeSecondary;
} else if (rotation == Surface.ROTATION_90) {
} else if (aOrientation >= 45 && aOrientation < 135) {
mOrientation = eScreenOrientation_LandscapePrimary;
} else if (aOrientation >= 135 && aOrientation < 225) {
mOrientation = eScreenOrientation_PortraitSecondary;
} else if (aOrientation >= 225 && aOrientation < 315) {
mOrientation = eScreenOrientation_LandscapeSecondary;
} else {
Log.e(LOGTAG, "Unexpected value received! (" + rotation + ")");
Log.e(LOGTAG, "Unexpected value received! (" + aOrientation + ")");
return;
}
@ -207,18 +212,18 @@ public class GeckoScreenOrientationListener {
Log.e(LOGTAG, "Unexpected value received! (" + aOrientation + ")");
return;
}
if (GeckoAppShell.getContext() instanceof Activity)
((Activity)GeckoAppShell.getContext()).setRequestedOrientation(orientation);
if (GeckoAppShell.getContext() instanceof Activity)
((Activity)GeckoAppShell.getContext()).setRequestedOrientation(orientation);
updateScreenOrientation();
}
public void unlockScreenOrientation() {
if (!(GeckoAppShell.getContext() instanceof Activity))
return;
if (((Activity)GeckoAppShell.getContext()).getRequestedOrientation() == mDefaultOrientation)
return;
if (!(GeckoAppShell.getContext() instanceof Activity))
return;
if (((Activity)GeckoAppShell.getContext()).getRequestedOrientation() == mDefaultOrientation)
return;
((Activity)GeckoAppShell.getContext()).setRequestedOrientation(mDefaultOrientation);
((Activity)GeckoAppShell.getContext()).setRequestedOrientation(mDefaultOrientation);
updateScreenOrientation();
}
}