mirror of
https://github.com/moonlight-stream/moonlight-android.git
synced 2026-04-23 16:56:41 +00:00
Reload the settings page when switching between screens on a foldable device
This commit is contained in:
@@ -4,6 +4,7 @@ import android.content.Context;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
|
import android.content.res.Configuration;
|
||||||
import android.media.MediaCodecInfo;
|
import android.media.MediaCodecInfo;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
@@ -38,11 +39,16 @@ import java.util.Arrays;
|
|||||||
|
|
||||||
public class StreamSettings extends Activity {
|
public class StreamSettings extends Activity {
|
||||||
private PreferenceConfiguration previousPrefs;
|
private PreferenceConfiguration previousPrefs;
|
||||||
|
private int previousDisplayPixelCount;
|
||||||
|
|
||||||
// HACK for Android 9
|
// HACK for Android 9
|
||||||
static DisplayCutout displayCutoutP;
|
static DisplayCutout displayCutoutP;
|
||||||
|
|
||||||
void reloadSettings() {
|
void reloadSettings() {
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||||
|
Display.Mode mode = getWindowManager().getDefaultDisplay().getMode();
|
||||||
|
previousDisplayPixelCount = mode.getPhysicalWidth() * mode.getPhysicalHeight();
|
||||||
|
}
|
||||||
getFragmentManager().beginTransaction().replace(
|
getFragmentManager().beginTransaction().replace(
|
||||||
R.id.stream_settings, new SettingsFragment()
|
R.id.stream_settings, new SettingsFragment()
|
||||||
).commitAllowingStateLoss();
|
).commitAllowingStateLoss();
|
||||||
@@ -79,6 +85,24 @@ public class StreamSettings extends Activity {
|
|||||||
reloadSettings();
|
reloadSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onConfigurationChanged(Configuration newConfig) {
|
||||||
|
super.onConfigurationChanged(newConfig);
|
||||||
|
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||||
|
Display.Mode mode = getWindowManager().getDefaultDisplay().getMode();
|
||||||
|
|
||||||
|
// If the display's physical pixel count has changed, we consider that it's a new display
|
||||||
|
// and we should reload our settings (which include display-dependent values).
|
||||||
|
//
|
||||||
|
// NB: We aren't using displayId here because that stays the same (DEFAULT_DISPLAY) when
|
||||||
|
// switching between screens on a foldable device.
|
||||||
|
if (mode.getPhysicalWidth() * mode.getPhysicalHeight() != previousDisplayPixelCount) {
|
||||||
|
reloadSettings();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
// NOTE: This will NOT be called on Android 13+ with android:enableOnBackInvokedCallback="true"
|
// NOTE: This will NOT be called on Android 13+ with android:enableOnBackInvokedCallback="true"
|
||||||
public void onBackPressed() {
|
public void onBackPressed() {
|
||||||
|
|||||||
Reference in New Issue
Block a user