mirror of
https://github.com/moonlight-stream/moonlight-android.git
synced 2026-06-17 14:21:08 +00:00
Add cutout resolution options on Android 9
This commit is contained in:
@@ -23,6 +23,7 @@ import android.view.DisplayCutout;
|
|||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
import android.view.WindowInsets;
|
||||||
|
|
||||||
import com.limelight.LimeLog;
|
import com.limelight.LimeLog;
|
||||||
import com.limelight.PcView;
|
import com.limelight.PcView;
|
||||||
@@ -37,6 +38,9 @@ import java.util.Arrays;
|
|||||||
public class StreamSettings extends Activity {
|
public class StreamSettings extends Activity {
|
||||||
private PreferenceConfiguration previousPrefs;
|
private PreferenceConfiguration previousPrefs;
|
||||||
|
|
||||||
|
// HACK for Android 9
|
||||||
|
static DisplayCutout displayCutoutP;
|
||||||
|
|
||||||
void reloadSettings() {
|
void reloadSettings() {
|
||||||
getFragmentManager().beginTransaction().replace(
|
getFragmentManager().beginTransaction().replace(
|
||||||
R.id.stream_settings, new SettingsFragment()
|
R.id.stream_settings, new SettingsFragment()
|
||||||
@@ -52,11 +56,28 @@ public class StreamSettings extends Activity {
|
|||||||
UiHelper.setLocale(this);
|
UiHelper.setLocale(this);
|
||||||
|
|
||||||
setContentView(R.layout.activity_stream_settings);
|
setContentView(R.layout.activity_stream_settings);
|
||||||
reloadSettings();
|
|
||||||
|
|
||||||
UiHelper.notifyNewRootView(this);
|
UiHelper.notifyNewRootView(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAttachedToWindow() {
|
||||||
|
super.onAttachedToWindow();
|
||||||
|
|
||||||
|
// We have to use this hack on Android 9 because we don't have Display.getCutout()
|
||||||
|
// which was added in Android 10.
|
||||||
|
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.P) {
|
||||||
|
// Insets can be null when the activity is recreated on screen rotation
|
||||||
|
// https://stackoverflow.com/questions/61241255/windowinsets-getdisplaycutout-is-null-everywhere-except-within-onattachedtowindo
|
||||||
|
WindowInsets insets = getWindow().getDecorView().getRootWindowInsets();
|
||||||
|
if (insets != null) {
|
||||||
|
displayCutoutP = insets.getDisplayCutout();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
reloadSettings();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBackPressed() {
|
public void onBackPressed() {
|
||||||
finish();
|
finish();
|
||||||
@@ -235,9 +256,18 @@ public class StreamSettings extends Activity {
|
|||||||
// Add a native resolution with any insets included for users that don't want content
|
// Add a native resolution with any insets included for users that don't want content
|
||||||
// behind the notch of their display
|
// behind the notch of their display
|
||||||
boolean hasInsets = false;
|
boolean hasInsets = false;
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
||||||
|
DisplayCutout cutout;
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||||
// FIXME: Come up with a solution for Android 9 which doesn't support Display.getCutout()
|
// Use the much nicer Display.getCutout() API on Android 10+
|
||||||
DisplayCutout cutout = display.getCutout();
|
cutout = display.getCutout();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// Android 9 only
|
||||||
|
cutout = displayCutoutP;
|
||||||
|
}
|
||||||
|
|
||||||
if (cutout != null) {
|
if (cutout != null) {
|
||||||
int widthInsets = cutout.getSafeInsetLeft() + cutout.getSafeInsetRight();
|
int widthInsets = cutout.getSafeInsetLeft() + cutout.getSafeInsetRight();
|
||||||
int heightInsets = cutout.getSafeInsetBottom() + cutout.getSafeInsetTop();
|
int heightInsets = cutout.getSafeInsetBottom() + cutout.getSafeInsetTop();
|
||||||
|
|||||||
Reference in New Issue
Block a user