Double Screen Display Scheme for RK Platform

There are two ways of dual screen displaying: Android Presentationand RK dualscreen. We will focus on Android Presentation.
Android Presentationis a dual-screen solution provided by Google, which implements the distribution of VOPat the View level. The logic is controlled on the same APP.

Introduction Android Presentation

Presentationis a class developed by Androidfor dual-screen display. It can be achieved in an APK, by giving Presentationa separate layout of viewto achieve the same APK in the main screen and sub-screen display different viewto achieve remarkable results. It works by calling the getDisplaysmethod of DisplayManagerServiceto get the second display device. Pass the second display device as a parameter to Presentation, then implement its UI content in Presentation, and finally call the showmethod of Presentationto display the UI content on the second display device.
The Imin models supporting dual screens are D1p-602, D1p-603, D1-502, D1-503, D1w-702, D1w-703 and D3-505.

1. Introduction API

Official API and sample documentation:
https://developer.android.com/reference/android/app/Presentation.html
Domestic documentation:
http://www.android-doc.com/reference/android/app/Presentation.html
Source code & demo:
CustomerDisplaydemo.zip
Presentationis a special dialogtype officially provided by Googlefor displaying specific content on other non-home screen displays. When it is created, it needs to bind the display screen and configure contextand resourceaccording to the target display screen and its size.

2.Binding Display

2.1 Obtain and bind through the MediaRouterinterface
                  MediaRouter mediaRouter =(MediaRouter) context.getSystemService(Context.MEDIA_ROUTER_SERVICE); MediaRouter.RouteInfo route = mediaRouter.getSelectedRoute(); if(route !=null){ Display presentationDisplay = route.getPresentationDisplay(); if(presentationDisplay !=null){ Presentation presentation =new MyPresentation(context, presentationDisplay); presentation.show();
2.2 Get and bind through the DisplayManagerinterface
                  DisplayManager displayManager =(DisplayManager) context.getSystemService(Context.DISPLAY_SERVICE); Display[] presentationDisplays = displayManager.getDisplays(DisplayManager.DISPLAY_CATEGORY_PRESENTATION ); if(presentationDisplays.length >0){ // If there is more than one suitable presentation display, then we could consider // giving the user a choice. For this example, we simply choose the first display // which is the one the system recommends as the preferred presentation display. Display display = presentationDisplays[0]; Presentation presentation =new MyPresentation(context, presentationDisplay); presentation.show(); }

3.Create Presentation

                  public class MyPresentation extends Presentation { /** * Rewrite constructor * * @param outerContext Context is not limited to Activity, it can also be Application Context or Service, etc. * @param display Dislay of the secondary screen */ public MyPresentation(Context outerContext, Display display) { super(outerContext, display); } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.xxx); TextView textView = findViewById(R.id.text); } }

4.Setting the secondary screen does not exit with the main screen

Usually Presentationis created to pass in the context of Activity, and the sub-screen will be displayed or hidden with the activity created to create a global sub-screen, which needs to add system pop-up window privileges to Presentation. As mentioned earlier, the context of the incoming Presentation can be Applicationor Service, provided that the system pop-up window permissions must be added, otherwise it will crash, so that Presentationcan be newly created anywhere.

4.1 Add permissions to AndroidManifest. XML
                  <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
4.2 Add code to Presentation
                  getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);

Note:
The system bullet window privileges of the Presentationwill cover the ordinary Presentation, causing it unable to display; please dismiss the global Presentationbefore displaying the ordinary secondary screen, in order to make the switching smooth, the following code is recommended:

                  normalPresentation.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialog) { globalPresentation.dismiss(); } });

2.Getting screen resolution and pixel density

                  DisplayManager displayManager = (DisplayManager) context.getSystemService(Context.***DISPLAY\_SERVICE***); Display[] presentationDisplays = displayManager.getDisplays(**null**); DisplayMetrics metrics = new DisplayMetrics(); Display display = displays[1]; //The main screen is display [0] display.getMetrics(metrics); int width = metrics.widthPixels; // Screen width (pixels) int height = metrics.heightPixels; // Screen height(pixels)) int dpi=metrics.densityDpi; // Pixel density

Subscreen Interface Description

1.Constructing interfaces
Method name Presentation(Context outerContext,Display display)
Interface description Example A Presentation object bound to the target display using the default theme.
Input outerContext:Context object of application, display:Target display
return dispaly object
2.Function
Method name Functions
Display getDisplay() Get the target screen where the current presentation is displayed
Resources getResources() Get the Resources object for the current presentation
void onDisplayChanged() When the display of the presentation binding changes (such as size, direction, etc.), the system calls back the interface, and the system automatically calls cancel () interface to close the presentation.
void onDisplayRemoved() When the display bound to presentation is removed, the system calls back the interface, and after that, the system automatically calls cancel () interface to close the presentation.
void onStart() When this presentation is started, this interface is called, similar to the onStart of activity.
void onStop() When this presentation is going through the stop process, it will be called to this interface, which is similar to the onStop of activity.
void show() To display this presentation, if the display device cannot be found, calling this interface throws a Windows Manager. InvalidDisplayException exception
void dismiss() Used to hide this presentation