FreeRDP
Loading...
Searching...
No Matches
ExternalDisplayManager.java
1/*
2 External Display Manager
3
4 Copyright 2026 Ibrahim Sevinc <ibrahim.sevinc.mail@gmail.com>
5
6 This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
7 If a copy of the MPL was not distributed with this file, You can obtain one at
8 http://mozilla.org/MPL/2.0/.
9*/
10
11package com.freerdp.freerdpcore.presentation;
12
13import android.app.Activity;
14import android.app.ActivityOptions;
15import android.content.Intent;
16import android.hardware.display.DisplayManager;
17import android.view.Display;
18
19import androidx.appcompat.app.AlertDialog;
20
21import com.freerdp.freerdpcore.R;
22
23class ExternalDisplayManager
24{
25 private final Activity activity;
26 private final DisplayManager displayManager;
27
28 ExternalDisplayManager(Activity activity)
29 {
30 this.activity = activity;
31 this.displayManager = (DisplayManager)activity.getSystemService(Activity.DISPLAY_SERVICE);
32 }
33
34 void launchSessionWithDisplayPicker(String refStr)
35 {
36 Display[] secondary = getSecondaryDisplays();
37 if (secondary.length == 0)
38 {
39 launchSessionOnDisplay(refStr, Display.DEFAULT_DISPLAY);
40 return;
41 }
42
43 String[] labels = new String[1 + secondary.length];
44 labels[0] = activity.getString(R.string.display_main_screen);
45 for (int i = 0; i < secondary.length; i++)
46 labels[i + 1] = secondary[i].getName();
47
48 new AlertDialog.Builder(activity)
49 .setTitle(R.string.select_display_title)
50 .setItems(labels,
51 (d, which) -> {
52 int id = (which == 0) ? Display.DEFAULT_DISPLAY
53 : secondary[which - 1].getDisplayId();
54 launchSessionOnDisplay(refStr, id);
55 })
56 .show();
57 }
58
59 private void launchSessionOnDisplay(String refStr, int displayId)
60 {
61 Intent intent = new Intent(activity, SessionActivity.class);
62 intent.putExtra(SessionActivity.PARAM_CONNECTION_REFERENCE, refStr);
63 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
64 ActivityOptions opts = ActivityOptions.makeBasic();
65 opts.setLaunchDisplayId(displayId);
66 activity.startActivity(intent, opts.toBundle());
67 }
68
69 private Display[] getSecondaryDisplays()
70 {
71 return displayManager.getDisplays(DisplayManager.DISPLAY_CATEGORY_PRESENTATION);
72 }
73}