mirror of
https://github.com/moonlight-stream/moonlight-android.git
synced 2025-07-27 06:52:44 +00:00
Improve resolution preference storage to remove 16:9 assumptions
This commit is contained in:
parent
76e4512a0c
commit
581327dc8e
@ -44,7 +44,7 @@ public class PreferenceConfiguration {
|
|||||||
private static final String FLIP_FACE_BUTTONS_PREF_STRING = "checkbox_flip_face_buttons";
|
private static final String FLIP_FACE_BUTTONS_PREF_STRING = "checkbox_flip_face_buttons";
|
||||||
private static final String TOUCHSCREEN_TRACKPAD_PREF_STRING = "checkbox_touchscreen_trackpad";
|
private static final String TOUCHSCREEN_TRACKPAD_PREF_STRING = "checkbox_touchscreen_trackpad";
|
||||||
|
|
||||||
static final String DEFAULT_RESOLUTION = "720p";
|
static final String DEFAULT_RESOLUTION = "1280x720";
|
||||||
static final String DEFAULT_FPS = "60";
|
static final String DEFAULT_FPS = "60";
|
||||||
private static final boolean DEFAULT_STRETCH = false;
|
private static final boolean DEFAULT_STRETCH = false;
|
||||||
private static final boolean DEFAULT_SOPS = true;
|
private static final boolean DEFAULT_SOPS = true;
|
||||||
@ -77,6 +77,13 @@ public class PreferenceConfiguration {
|
|||||||
public static final int AUTOSELECT_H265 = 0;
|
public static final int AUTOSELECT_H265 = 0;
|
||||||
public static final int FORCE_H265_OFF = 1;
|
public static final int FORCE_H265_OFF = 1;
|
||||||
|
|
||||||
|
public static final String RES_360P = "640x360";
|
||||||
|
public static final String RES_480P = "854x480";
|
||||||
|
public static final String RES_720P = "1280x720";
|
||||||
|
public static final String RES_1080P = "1920x1080";
|
||||||
|
public static final String RES_1440P = "2560x1440";
|
||||||
|
public static final String RES_4K = "3840x2160";
|
||||||
|
|
||||||
public int width, height, fps;
|
public int width, height, fps;
|
||||||
public int bitrate;
|
public int bitrate;
|
||||||
public int videoFormat;
|
public int videoFormat;
|
||||||
@ -100,58 +107,54 @@ public class PreferenceConfiguration {
|
|||||||
public boolean touchscreenTrackpad;
|
public boolean touchscreenTrackpad;
|
||||||
public MoonBridge.AudioConfiguration audioConfiguration;
|
public MoonBridge.AudioConfiguration audioConfiguration;
|
||||||
|
|
||||||
private static int getHeightFromResolutionString(String resString) {
|
private static String convertFromLegacyResolutionString(String resString) {
|
||||||
if (resString.equalsIgnoreCase("360p")) {
|
if (resString.equalsIgnoreCase("360p")) {
|
||||||
return 360;
|
return RES_360P;
|
||||||
}
|
}
|
||||||
else if (resString.equalsIgnoreCase("480p")) {
|
else if (resString.equalsIgnoreCase("480p")) {
|
||||||
return 480;
|
return RES_480P;
|
||||||
}
|
}
|
||||||
else if (resString.equalsIgnoreCase("720p")) {
|
else if (resString.equalsIgnoreCase("720p")) {
|
||||||
return 720;
|
return RES_720P;
|
||||||
}
|
}
|
||||||
else if (resString.equalsIgnoreCase("1080p")) {
|
else if (resString.equalsIgnoreCase("1080p")) {
|
||||||
return 1080;
|
return RES_1080P;
|
||||||
}
|
}
|
||||||
else if (resString.equalsIgnoreCase("1440p")) {
|
else if (resString.equalsIgnoreCase("1440p")) {
|
||||||
return 1440;
|
return RES_1440P;
|
||||||
}
|
}
|
||||||
else if (resString.equalsIgnoreCase("4K")) {
|
else if (resString.equalsIgnoreCase("4K")) {
|
||||||
return 2160;
|
return RES_4K;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Should be unreachable
|
// Should be unreachable
|
||||||
return 720;
|
return RES_720P;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int getWidthFromResolutionString(String resString) {
|
private static int getWidthFromResolutionString(String resString) {
|
||||||
int height = getHeightFromResolutionString(resString);
|
return Integer.parseInt(resString.split("x")[0]);
|
||||||
if (height == 480) {
|
|
||||||
// This isn't an exact 16:9 resolution
|
|
||||||
return 854;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return (height * 16) / 9;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static int getHeightFromResolutionString(String resString) {
|
||||||
|
return Integer.parseInt(resString.split("x")[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getResolutionString(int width, int height) {
|
private static String getResolutionString(int width, int height) {
|
||||||
switch (height) {
|
switch (height) {
|
||||||
case 360:
|
case 360:
|
||||||
return "360p";
|
return RES_360P;
|
||||||
case 480:
|
case 480:
|
||||||
return "480p";
|
return RES_480P;
|
||||||
default:
|
default:
|
||||||
case 720:
|
case 720:
|
||||||
return "720p";
|
return RES_720P;
|
||||||
case 1080:
|
case 1080:
|
||||||
return "1080p";
|
return RES_1080P;
|
||||||
case 1440:
|
case 1440:
|
||||||
return "1440p";
|
return RES_1440P;
|
||||||
case 2160:
|
case 2160:
|
||||||
return "4K";
|
return RES_4K;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -322,6 +325,13 @@ public class PreferenceConfiguration {
|
|||||||
else {
|
else {
|
||||||
// Use the new preference location
|
// Use the new preference location
|
||||||
String resStr = prefs.getString(RESOLUTION_PREF_STRING, PreferenceConfiguration.DEFAULT_RESOLUTION);
|
String resStr = prefs.getString(RESOLUTION_PREF_STRING, PreferenceConfiguration.DEFAULT_RESOLUTION);
|
||||||
|
|
||||||
|
// Convert legacy resolution strings to the new style
|
||||||
|
if (!resStr.contains("x")) {
|
||||||
|
resStr = PreferenceConfiguration.convertFromLegacyResolutionString(resStr);
|
||||||
|
prefs.edit().putString(RESOLUTION_PREF_STRING, resStr).apply();
|
||||||
|
}
|
||||||
|
|
||||||
config.width = PreferenceConfiguration.getWidthFromResolutionString(resStr);
|
config.width = PreferenceConfiguration.getWidthFromResolutionString(resStr);
|
||||||
config.height = PreferenceConfiguration.getHeightFromResolutionString(resStr);
|
config.height = PreferenceConfiguration.getHeightFromResolutionString(resStr);
|
||||||
config.fps = Integer.parseInt(prefs.getString(FPS_PREF_STRING, PreferenceConfiguration.DEFAULT_FPS));
|
config.fps = Integer.parseInt(prefs.getString(FPS_PREF_STRING, PreferenceConfiguration.DEFAULT_FPS));
|
||||||
|
@ -249,33 +249,33 @@ public class StreamSettings extends Activity {
|
|||||||
if (maxSupportedResW != 0) {
|
if (maxSupportedResW != 0) {
|
||||||
if (maxSupportedResW < 3840) {
|
if (maxSupportedResW < 3840) {
|
||||||
// 4K is unsupported
|
// 4K is unsupported
|
||||||
removeValue(PreferenceConfiguration.RESOLUTION_PREF_STRING, "4K", new Runnable() {
|
removeValue(PreferenceConfiguration.RESOLUTION_PREF_STRING, PreferenceConfiguration.RES_4K, new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(SettingsFragment.this.getActivity());
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(SettingsFragment.this.getActivity());
|
||||||
setValue(PreferenceConfiguration.RESOLUTION_PREF_STRING, "1440p");
|
setValue(PreferenceConfiguration.RESOLUTION_PREF_STRING, PreferenceConfiguration.RES_1440P);
|
||||||
resetBitrateToDefault(prefs, null, null);
|
resetBitrateToDefault(prefs, null, null);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (maxSupportedResW < 2560) {
|
if (maxSupportedResW < 2560) {
|
||||||
// 1440p is unsupported
|
// 1440p is unsupported
|
||||||
removeValue(PreferenceConfiguration.RESOLUTION_PREF_STRING, "1440p", new Runnable() {
|
removeValue(PreferenceConfiguration.RESOLUTION_PREF_STRING, PreferenceConfiguration.RES_1440P, new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(SettingsFragment.this.getActivity());
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(SettingsFragment.this.getActivity());
|
||||||
setValue(PreferenceConfiguration.RESOLUTION_PREF_STRING, "1080p");
|
setValue(PreferenceConfiguration.RESOLUTION_PREF_STRING, PreferenceConfiguration.RES_1080P);
|
||||||
resetBitrateToDefault(prefs, null, null);
|
resetBitrateToDefault(prefs, null, null);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (maxSupportedResW < 1920) {
|
if (maxSupportedResW < 1920) {
|
||||||
// 1080p is unsupported
|
// 1080p is unsupported
|
||||||
removeValue(PreferenceConfiguration.RESOLUTION_PREF_STRING, "1080p", new Runnable() {
|
removeValue(PreferenceConfiguration.RESOLUTION_PREF_STRING, PreferenceConfiguration.RES_1080P, new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(SettingsFragment.this.getActivity());
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(SettingsFragment.this.getActivity());
|
||||||
setValue(PreferenceConfiguration.RESOLUTION_PREF_STRING, "720p");
|
setValue(PreferenceConfiguration.RESOLUTION_PREF_STRING, PreferenceConfiguration.RES_720P);
|
||||||
resetBitrateToDefault(prefs, null, null);
|
resetBitrateToDefault(prefs, null, null);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -9,12 +9,12 @@
|
|||||||
<item>4K</item>
|
<item>4K</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
<string-array name="resolution_values" translatable="false">
|
<string-array name="resolution_values" translatable="false">
|
||||||
<item>360p</item>
|
<item>640x360</item>
|
||||||
<item>480p</item>
|
<item>854x480</item>
|
||||||
<item>720p</item>
|
<item>1280x720</item>
|
||||||
<item>1080p</item>
|
<item>1920x1080</item>
|
||||||
<item>1440p</item>
|
<item>2560x1440</item>
|
||||||
<item>4K</item>
|
<item>3840x2160</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
<string-array name="fps_names">
|
<string-array name="fps_names">
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
android:summary="@string/summary_resolution_list"
|
android:summary="@string/summary_resolution_list"
|
||||||
android:entries="@array/resolution_names"
|
android:entries="@array/resolution_names"
|
||||||
android:entryValues="@array/resolution_values"
|
android:entryValues="@array/resolution_values"
|
||||||
android:defaultValue="720p" />
|
android:defaultValue="1280x720" />
|
||||||
<ListPreference
|
<ListPreference
|
||||||
android:key="list_fps"
|
android:key="list_fps"
|
||||||
android:title="@string/title_fps_list"
|
android:title="@string/title_fps_list"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user