mirror of
https://github.com/moonlight-stream/moonlight-android.git
synced 2026-06-16 22:01:14 +00:00
Allow streaming in any orientation when using a square display
This commit is contained in:
@@ -124,11 +124,9 @@
|
|||||||
android:name="android.support.PARENT_ACTIVITY"
|
android:name="android.support.PARENT_ACTIVITY"
|
||||||
android:value="com.limelight.PcView" />
|
android:value="com.limelight.PcView" />
|
||||||
</activity>
|
</activity>
|
||||||
<!-- This will fall back to sensorLandscape at runtime on Android 4.2 and below -->
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".Game"
|
android:name=".Game"
|
||||||
android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|screenLayout|fontScale|uiMode|orientation|screenSize|smallestScreenSize|layoutDirection"
|
android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|screenLayout|fontScale|uiMode|orientation|screenSize|smallestScreenSize|layoutDirection"
|
||||||
android:screenOrientation="userLandscape"
|
|
||||||
android:noHistory="true"
|
android:noHistory="true"
|
||||||
android:supportsPictureInPicture="true"
|
android:supportsPictureInPicture="true"
|
||||||
android:resizeableActivity="true"
|
android:resizeableActivity="true"
|
||||||
|
|||||||
@@ -199,11 +199,8 @@ public class Game extends Activity implements SurfaceHolder.Callback,
|
|||||||
getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
|
getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
// We specified userLandscape in the manifest which isn't supported until 4.3,
|
// Enter landscape unless we're on a square screen
|
||||||
// so we must fall back at runtime to sensorLandscape.
|
setPreferredOrientationForCurrentDisplay();
|
||||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) {
|
|
||||||
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Listen for UI visibility events
|
// Listen for UI visibility events
|
||||||
getWindow().getDecorView().setOnSystemUiVisibilityChangeListener(this);
|
getWindow().getDecorView().setOnSystemUiVisibilityChangeListener(this);
|
||||||
@@ -528,10 +525,34 @@ public class Game extends Activity implements SurfaceHolder.Callback,
|
|||||||
streamView.getHolder().addCallback(this);
|
streamView.getHolder().addCallback(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setPreferredOrientationForCurrentDisplay() {
|
||||||
|
// If the display is somewhat square, allow any orientation. Otherwise, request landscape.
|
||||||
|
Display display = getWindowManager().getDefaultDisplay();
|
||||||
|
if (PreferenceConfiguration.isSquarishScreen(display.getWidth(), display.getHeight())) {
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
|
||||||
|
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_FULL_USER);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
|
||||||
|
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onConfigurationChanged(Configuration newConfig) {
|
public void onConfigurationChanged(Configuration newConfig) {
|
||||||
super.onConfigurationChanged(newConfig);
|
super.onConfigurationChanged(newConfig);
|
||||||
|
|
||||||
|
// Set requested orientation for possible new screen size
|
||||||
|
setPreferredOrientationForCurrentDisplay();
|
||||||
|
|
||||||
if (virtualController != null) {
|
if (virtualController != null) {
|
||||||
// Refresh layout of OSC for possible new screen size
|
// Refresh layout of OSC for possible new screen size
|
||||||
virtualController.refreshLayout();
|
virtualController.refreshLayout();
|
||||||
|
|||||||
@@ -148,6 +148,16 @@ public class PreferenceConfiguration {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If we have a screen that has semi-square dimensions, we may want to change our behavior
|
||||||
|
// to allow any orientation and vertical+horizontal resolutions.
|
||||||
|
public static boolean isSquarishScreen(int width, int height) {
|
||||||
|
float longDim = Math.max(width, height);
|
||||||
|
float shortDim = Math.min(width, height);
|
||||||
|
|
||||||
|
// We just put the arbitrary cutoff for a square-ish screen at 1.3
|
||||||
|
return longDim / shortDim < 1.3f;
|
||||||
|
}
|
||||||
|
|
||||||
private static String convertFromLegacyResolutionString(String resString) {
|
private static String convertFromLegacyResolutionString(String resString) {
|
||||||
if (resString.equalsIgnoreCase("360p")) {
|
if (resString.equalsIgnoreCase("360p")) {
|
||||||
return RES_360P;
|
return RES_360P;
|
||||||
|
|||||||
Reference in New Issue
Block a user