diff options
| author | Lena <lena@omega> | 2026-01-01 00:00:00 +0000 |
|---|---|---|
| committer | Lena <lena@omega> | 2026-06-24 22:14:50 +0300 |
| commit | eb0c8951196c637e44daf3c0617b131b997d5d2c (patch) | |
| tree | 2f83b6a41cee745467e53fc401942b82cea286ea /app/src/main/java/invalid/lena/scrcpy/Settings.java | |
| download | scrcpy-android-0.1.tar.gz | |
scrcpy-android: mirror an Android device over wireless ADB0.1
Native Java app for Android 12+ that mirrors another Android
device over wireless ADB, forwarding video, audio, touch input,
and clipboard. Bundles a pinned scrcpy-server.jar and the
vendored libadb-android stack. Supports h264/h265/av1 video and
raw/opus audio with in-app codec selection. No NDK, no Kotlin.
Includes JVM unit tests and a Docker-based emulator e2e rig.
Diffstat (limited to 'app/src/main/java/invalid/lena/scrcpy/Settings.java')
| -rw-r--r-- | app/src/main/java/invalid/lena/scrcpy/Settings.java | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/app/src/main/java/invalid/lena/scrcpy/Settings.java b/app/src/main/java/invalid/lena/scrcpy/Settings.java new file mode 100644 index 0000000..c4bb83b --- /dev/null +++ b/app/src/main/java/invalid/lena/scrcpy/Settings.java @@ -0,0 +1,93 @@ +package invalid.lena.scrcpy; + +import android.content.Context; +import android.content.SharedPreferences; + +// Thin wrapper around SharedPreferences for the small set of user +// choices the app exposes. No reactivity, no DataStore - the values +// are read once when a Session starts and applied to the scrcpy +// server command line. +public final class Settings { + + private static final String FILE = "scrcpy-android"; + + public static final String VIDEO_CODEC = "video_codec"; + public static final String AUDIO_CODEC = "audio_codec"; + public static final String MAX_SIZE = "max_size"; // px, long edge; 0 = no cap + public static final String VIDEO_BIT_RATE = "video_bit_rate"; // bits/sec + public static final String MAX_FPS = "max_fps"; // fps; 0 = unlimited + public static final String HINT_BACK_SHOWN = "hint_back_shown"; // first-run UI hint + public static final String STATUS_BAR = "status_bar"; // show status bar while mirroring + + public static final String DEFAULT_VIDEO_CODEC = "h264"; + public static final String DEFAULT_AUDIO_CODEC = "raw"; + public static final int DEFAULT_MAX_SIZE = 0; + public static final int DEFAULT_VIDEO_BIT_RATE = 8_000_000; + public static final int DEFAULT_MAX_FPS = 0; + // Hidden while mirroring by default: an always-on bar over the video + // is intrusive. It still auto-shows when not CONNECTED so Reconnect + // stays reachable. Record lives in the bar, so enable this to keep it. + public static final boolean DEFAULT_STATUS_BAR = false; + + private Settings() {} + + public static SharedPreferences prefs(Context ctx) { + return ctx.getApplicationContext().getSharedPreferences(FILE, Context.MODE_PRIVATE); + } + + public static String videoCodec(Context ctx) { + return prefs(ctx).getString(VIDEO_CODEC, DEFAULT_VIDEO_CODEC); + } + + public static String audioCodec(Context ctx) { + return prefs(ctx).getString(AUDIO_CODEC, DEFAULT_AUDIO_CODEC); + } + + public static int maxSize(Context ctx) { + return prefs(ctx).getInt(MAX_SIZE, DEFAULT_MAX_SIZE); + } + + public static int videoBitRate(Context ctx) { + return prefs(ctx).getInt(VIDEO_BIT_RATE, DEFAULT_VIDEO_BIT_RATE); + } + + public static int maxFps(Context ctx) { + return prefs(ctx).getInt(MAX_FPS, DEFAULT_MAX_FPS); + } + + public static void setVideoCodec(Context ctx, String v) { + prefs(ctx).edit().putString(VIDEO_CODEC, v).apply(); + } + + public static void setAudioCodec(Context ctx, String a) { + prefs(ctx).edit().putString(AUDIO_CODEC, a).apply(); + } + + public static void setMaxSize(Context ctx, int v) { + prefs(ctx).edit().putInt(MAX_SIZE, v).apply(); + } + + public static void setVideoBitRate(Context ctx, int v) { + prefs(ctx).edit().putInt(VIDEO_BIT_RATE, v).apply(); + } + + public static void setMaxFps(Context ctx, int v) { + prefs(ctx).edit().putInt(MAX_FPS, v).apply(); + } + + public static boolean hintBackShown(Context ctx) { + return prefs(ctx).getBoolean(HINT_BACK_SHOWN, false); + } + + public static void setHintBackShown(Context ctx, boolean v) { + prefs(ctx).edit().putBoolean(HINT_BACK_SHOWN, v).apply(); + } + + public static boolean showStatusBar(Context ctx) { + return prefs(ctx).getBoolean(STATUS_BAR, DEFAULT_STATUS_BAR); + } + + public static void setShowStatusBar(Context ctx, boolean v) { + prefs(ctx).edit().putBoolean(STATUS_BAR, v).apply(); + } +} |