aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/invalid/lena/scrcpy/SettingsActivity.java
blob: d95ecba3fb7b6563a39c135609575f80aaa3d420 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package invalid.lena.scrcpy;

import android.app.Activity;
import android.os.Bundle;
import android.widget.CheckBox;
import android.widget.RadioButton;
import android.widget.RadioGroup;

// Codec choice + streaming knobs. All persisted to SharedPreferences
// via Settings on click; the next session bringup reads them and
// applies to the scrcpy server cmdline.
public final class SettingsActivity extends Activity {

    @Override
    protected void onCreate(Bundle saved) {
        super.onCreate(saved);
        setContentView(R.layout.settings);
        setTitle(R.string.settings);

        RadioGroup videoGroup   = findViewById(R.id.video_codec);
        RadioGroup audioGroup   = findViewById(R.id.audio_codec);
        RadioGroup maxSizeGroup = findViewById(R.id.max_size);
        RadioGroup bitRateGroup = findViewById(R.id.video_bit_rate);
        RadioGroup maxFpsGroup  = findViewById(R.id.max_fps);
        CheckBox   statusBarBox = findViewById(R.id.show_status_bar);

        switch (Settings.videoCodec(this)) {
            case "h265": ((RadioButton) findViewById(R.id.video_h265)).setChecked(true); break;
            case "av1":  ((RadioButton) findViewById(R.id.video_av1)).setChecked(true);  break;
            default:     ((RadioButton) findViewById(R.id.video_h264)).setChecked(true);
        }
        switch (Settings.audioCodec(this)) {
            case "opus": ((RadioButton) findViewById(R.id.audio_opus)).setChecked(true); break;
            default:     ((RadioButton) findViewById(R.id.audio_raw)).setChecked(true);
        }
        switch (Settings.maxSize(this)) {
            case 480:  ((RadioButton) findViewById(R.id.max_size_480)).setChecked(true); break;
            case 720:  ((RadioButton) findViewById(R.id.max_size_720)).setChecked(true); break;
            case 1080: ((RadioButton) findViewById(R.id.max_size_1080)).setChecked(true); break;
            case 1440: ((RadioButton) findViewById(R.id.max_size_1440)).setChecked(true); break;
            case 2160: ((RadioButton) findViewById(R.id.max_size_2160)).setChecked(true); break;
            default:   ((RadioButton) findViewById(R.id.max_size_0)).setChecked(true);
        }
        switch (Settings.videoBitRate(this)) {
            case 1_000_000:  ((RadioButton) findViewById(R.id.bit_rate_1m)).setChecked(true);  break;
            case 2_000_000:  ((RadioButton) findViewById(R.id.bit_rate_2m)).setChecked(true);  break;
            case 4_000_000:  ((RadioButton) findViewById(R.id.bit_rate_4m)).setChecked(true);  break;
            case 16_000_000: ((RadioButton) findViewById(R.id.bit_rate_16m)).setChecked(true); break;
            default:         ((RadioButton) findViewById(R.id.bit_rate_8m)).setChecked(true);
        }
        switch (Settings.maxFps(this)) {
            case 30:  ((RadioButton) findViewById(R.id.max_fps_30)).setChecked(true);  break;
            case 60:  ((RadioButton) findViewById(R.id.max_fps_60)).setChecked(true);  break;
            case 90:  ((RadioButton) findViewById(R.id.max_fps_90)).setChecked(true);  break;
            case 120: ((RadioButton) findViewById(R.id.max_fps_120)).setChecked(true); break;
            default:  ((RadioButton) findViewById(R.id.max_fps_0)).setChecked(true);
        }

        videoGroup.setOnCheckedChangeListener((g, id) -> {
            String v = "h264";
            if (id == R.id.video_h265) v = "h265";
            else if (id == R.id.video_av1) v = "av1";
            Settings.setVideoCodec(this, v);
            Log.i("settings: video_codec=%s", v);
        });

        audioGroup.setOnCheckedChangeListener((g, id) -> {
            String a = id == R.id.audio_opus ? "opus" : "raw";
            Settings.setAudioCodec(this, a);
            Log.i("settings: audio_codec=%s", a);
        });

        maxSizeGroup.setOnCheckedChangeListener((g, id) -> {
            int v = 0;
            if      (id == R.id.max_size_480)  v = 480;
            else if (id == R.id.max_size_720)  v = 720;
            else if (id == R.id.max_size_1080) v = 1080;
            else if (id == R.id.max_size_1440) v = 1440;
            else if (id == R.id.max_size_2160) v = 2160;
            Settings.setMaxSize(this, v);
            Log.i("settings: max_size=%d", v);
        });

        bitRateGroup.setOnCheckedChangeListener((g, id) -> {
            int v = Settings.DEFAULT_VIDEO_BIT_RATE;
            if      (id == R.id.bit_rate_1m)  v = 1_000_000;
            else if (id == R.id.bit_rate_2m)  v = 2_000_000;
            else if (id == R.id.bit_rate_4m)  v = 4_000_000;
            else if (id == R.id.bit_rate_16m) v = 16_000_000;
            Settings.setVideoBitRate(this, v);
            Log.i("settings: video_bit_rate=%d", v);
        });

        maxFpsGroup.setOnCheckedChangeListener((g, id) -> {
            int v = 0;
            if      (id == R.id.max_fps_30)  v = 30;
            else if (id == R.id.max_fps_60)  v = 60;
            else if (id == R.id.max_fps_90)  v = 90;
            else if (id == R.id.max_fps_120) v = 120;
            Settings.setMaxFps(this, v);
            Log.i("settings: max_fps=%d", v);
        });

        statusBarBox.setChecked(Settings.showStatusBar(this));
        statusBarBox.setOnCheckedChangeListener((b, checked) -> {
            Settings.setShowStatusBar(this, checked);
            Log.i("settings: status_bar=%b", checked);
        });
    }
}