T1 Custom Vice Screen Display App


                    

                                                           Development of T1 Customized Second Display Program

[Prompt: please read carefully the content in the document before the development. If you have any queries, please contact Sunmi Technology for consultation support.]

                                  【Note: plug in usb debugging line, which will lead to the disconnection of main & second screen.

About T1 Double Screen

As for Sunmi T1, there are two types of double screen configurations available:


1.  14 inch main screen, 7 inch second screen.

Note: 7 inch second screen only supports browsing, but does not support touch control and the installation of app. If the user needs to modify second screen interface, please refer to Docking Document for Built-in Second Display Program 

Ouk69hAZ0gIkhS99

2.  14 inch main screen, 14 inch second screen, touch control second screen.

VzaGKG2DvekBhhS3 (1)

Please check Introduction of Official Website for detailed hardware instructions. Both main and second screen of the device run SUNMI OS system, and they realize communication via the interface encapsulated by Sunmi.

Note: not to confuse the relevant codes of Sunmi, which may cause the component not to be able to work

#sunmi

-keep class com.luedongtech.kr3000.sunmi.** {*;}

-keep class sunmi.ds.**{*;}

-keep class com.sunmi.**{*;}

-keep class sunmi.sc.**{*;}

-keep class com.google.gson.**{*;}

Normally, the developer’s business app runs at the main screen while the second screen is required to display the content of list information, propaganda pictures, videos, etc., sometimes to realize simple interactive operation. As for the developers, two methods are available to display content with T1 second screen:


 1.  Use the built-in display program of T1 second screen system. The second display program will display the content only if the main screen app send data with specific format to the second display program according to Sunmi specifications (suggested for low development cost).


 2.  The developer writes second screen display app by himself/herself (with high development cost and degree of freedom).

 Although Sunmi’s encapsulated second display program can meet the demands of the vast majority of developers on second screen display content, yet the business is diverse. Sunmi always adheres to the openness principle to support the developers to write their own second display program. The following is the detailed description for writing the second display program by oneself.


  •  The distribution of second display app

We stipulate that business App will install on the second screen while installing on the main screen via App market only if one line configuration (to be described at the end of the document) is added to your main screen business App’s AndroidManifest.xml. That is to say, your main screen App is at the same time second screen App. Here, you are required to control the content displayed in the home page in the code.


Get Right to the Point


The core problem of the development of customized second display program is the communication of main & second screen. After realizing the communication of main & second screen, you may regard the second screen as ordinary second screen app relevant to the development of tablet computer. Here, it is necessary to first realize the communication method of double screen, and we’d like to provide you with visual presentation of the communication protocol of T1 double screen via a piece of picture.


T1’s communication protocol includes the following layers in turn from the bottom up:


1. Driver layer, which is the communication protocol at the lowest level. The developers do not need to care about it.


2. Service layer, which is a type of communication service encapsulated by Sunmi. The developers also do not need to care about it.


3. SDK layer, which is a communication interface used by T1’s self-contained second display program. The customized second display program also invokes the interface of this layer.


4.APP layer, which is the business app and built-in second display program owned by the developer himself/herself.

  • If T1 built-in second display program is used, the data communication method is as shown in the above figure. The developer’s main screen business App only needs to invoke Sunmi’s SDK and send data to the second display according to the data format specified by Sunmi, the rest will be done by the system.
  • If you are going to develop second display program by yourself, you need to process by yourself the actions of data receive & send, content display, etc. If you do not have a strong demand for customization, we suggest that you use T1’s self-contained second display program to display the content, which will save a lot of labor & material cost.

Start Developing


We have provided the developers with a Demo of double screen communication. You can download Develop Resources of Second Display Program, and refer to the code in Demo to realize your own second display app. Please deploy this Demo according to the following process:


    1.Install HCService.apk in the resource file onto two devices that simulate main & second screen Communication. The resource contains two apk of HCService. Please install release version first. If the installation fails, please try to install apk of unsigned version.

    2. This program is run respectively on main & second screen. Enter your own IP address on the first device, check “As Main Screen”, click Determine. 


    3.  Enter IP address of the main screen device on another device, click Determine (not to check “As MainScreen”), and you’ll see toast prompt “Connect with Main/Second Screen” popped up on the screen, which represents that it’s OK for main & second screen to communicate. If there is no popup prompt, please find HCService program in App Management in Setting (get into Setting -> App -> Click More at the Top Right Corner -> Click Display the System Progress, and then you will see HCService), to mandatorily stop HCService service on main & second screen, and then repeat the above-mentioned steps to have a try.


   4. Import MyDSD project into AndroidStudio. If an error is reported, please check whether your version in the compiling environment is compatible with demo. You can make the relevant adjustment by yourself. Note: we do not suggest that you use eclipse to develop second display program, currently there is no relevant eclipse resource package available.


    5.  Here, please modify the enabling page in AndroidManifest.xml to MainSceenActivity, and then deploy the project into the main screen device, and run.


    6.  Then modify the enabling page to ViceScreenActivity, and deploy the project into the second screen device, and run.


    7. Click the button for sending text on the main screen, check the change of the second screen’s displayed content, and then you may send the pictures to the second screen for checking the display situation


In this Demo, the methods of sending character data mutually between main & second screen are included. They are method of sending single file and that of sending several files. We are going to explain the development process of main & second screen communication based on Demo as follows:

1. To add the following content to build.gradle depends on:

dependencies {
    compile files('libs/commons-codec-1.9.jar')
    provided files('libs/framework.jar')
    compile 'com.android.support:appcompat-v7:22.2.1'
    compile 'com.sunmi:DS_Lib:latest.release'
    compile 'com.google.code.gson:gson:2.6.2'
}


The permission that is required to be added:


One more broadcast receiver. Please note: this is a fixed writing method, do not modify it.

<receiver android:name="sunmi.ds.MsgReceiver">
    <intent-filter>
        <action android:name="com.sunmi.hcservice" />
        <action android:name="com.sunmi.hcservice.status" />
    intent-filter>
receiver>


2.  Initialization. You may initialize SDK code in Application, and also initialize anywhere you want:

private void initSDK() {
    mDSKernel = DSKernel.newInstance();
    mDSKernel.init(this, mConnCallback);
}



The above DSKernel class is the core class in SDK, and almost all the methods relevant to double screen communication are among this class. Two monitor classes are required to be added after the initialization:

//Add the connect status listener
mDSKernel.addConnCallback(new IConnectionCallback(){
                        @Override
                        public void onConnected(ConnState arg0) {
                        //connect success
                        }

                        @Override
                        public void onDisConnect() {
                        //disconnect
                        }
                        
                });

//Add the data received listener               
mDSKernel.addReceiveCallback(new IReceiveCallback(){

                        @Override
                        public void onReceiveCMD(DSData arg0) {
                          //receive the CMD     
                        }

                        @Override
                        public void onReceiveData(DSData arg0) {
                           //receive some data
                        }

                        @Override
                        public void onReceiveFile(DSFile arg0) {
                           //receive one file
                        }

                        @Override
                        public void onReceiveFiles(DSFiles arg0) {
                           //receive multiple files
                        }
             
                        
                });   


Above we complete the initialization, and sure the communication will separate send and receive of the information. Main & second screen can send & receive data between each other. It can be seen that within MyDSD, many methods of sending data are included in MainScreenActivity, many methods of receiving data are included in ViewScreenActivity.

All the methods can be checked in DSKernel class, and you can also check Docking Document for T1 Double Screen Communication Interface for details. We are going to explain the usage of partial interfaces as follows:

1. Send character data, the second screen receives and display

DataPacket packet = UPacketFactory.buildShowText(DSKernel.getDSDPackageName(), 
"receive characters success!",null);
//The param DataPacket is the data package class of Dual Screen Communication
mDSKernel.sendData(packet);


The receiving method is in onReceiveData (DSData data) of IReceiveCallback interface:

@Override
public void onReceiveData(DSData data) {
    Log.d(TAG, "Data received:" + data.data);
}

2.  Method of sending command:

String json = UPacketFactory.createJson(DataModel.QRCODE, "");
//Three parameters: 1.package name of the app which receive the CMD,
 //2. the Command which you want send. 3. The result callback
mDSKernel.sendCMD(DSKernel.getDSDPackageName(), json.toString(), l,null);


Method of receiving command:

@Override
public void onReceiveCMD(DSData cmd) {
     Log.d(TAG, "Data received :" + cmd.data);
}

Example of usage scenarios of the command: as for the display of pictures, videos, etc., it is required to first send the file to the second screen, and the second screen will return an id of the file to the main screen. Then command is sent to the second screen to display pictures or videos of the specified id.

3.  Method of sending single file:

//Three parameters: 1. the package name of the receiver app in vice screen;
//2. The local path of the file. 3. result callback.
mDSKernel.sendFile(PACKAGE_OF_VICE, Environment.getExternalStorageDirectory().toString()
+"/"+videoInAsserts,
      new ISendCallback() {
         public void onSendSuccess(long l) {
               //
            showVideo(l);
         }

      
         public void onSendFail(int i, String s) {
            //tv_show_id.setText("fail:" + s);
            Log.i("sunmi", "---:" + s);
         }

         public void onSendProcess(long l, long l1) {
            //process
         }
      });



Method of receiving single file. Via invoking FilesManager.saveFile (DSFile file) in onReceiveFile (DSFile file) of IReceiveCallback interface, the file will be saved locally:

@Override
public void onReceiveFile(DSFile file) {
   Log.i(TAG,"path of the file received :"+file.path);
   Log.i(TAG,"taskId of the file received :"+file.taskId);
    mFilesManager.saveFile(file);
}

4. Method of sending several files

mDSKernel.sendFiles(PACKAGE_OF_VICE, json.toString(), paths, new ISendFilesCallback(){
   @Override
   public void onAllSendSuccess(long l) {
     //all those files send success
   }
   @Override
   public void onSendFaile(int arg0, String arg1) {}
   @Override
   public void onSendFileFaile(String arg0, int arg1, String arg2) {}
   @Override
   public void onSendProcess(String arg0, long arg1, long arg2) {}
   @Override
   public void onSendSuccess(String arg0, long arg1) {
   }
   
});


Method of receiving several files:

@Override
public void onReceiveFiles(DSFiles dsFiles) {
            mFilesManager.saveFiles(dsFiles);
        }


5. Method of enabling specified App


Refer to Demo’s generated data and send command to the second screen. This code needs the support of DSD program. You can find this apk in the downloaded resource file and install it on the second screen.

The above is the introduction of the usage of some basic interfaces. Please check the code comments in DSKernel for more interfaces.

DataPacket dsPacket   = UPacketFactory.buildOpenApp(PACKAGE_OF_VICE, null);
//PACKAGE_OF_VICE is the package name of app which you want start, such as :com.sunmi.mydsd
mDSKernel.sendCMD(dsPacket);


6.  Method of deleting the files that have been transferred to the second screen

The files that have been sent to the second screen via method 3, 4 (pictures & text, videos, APK) will be saved under the uniform folder. When there are too many data that will affect the normal storage, it is required to execute command to delete all these contents.

Release of App


All the Apps of main & second screen have been well developed, it’s sure to distribute this App in large scale via Sunmi App market. As we mentioned above, this App will install this App (it will only take effect via the installation of the App market) at the same time only if one line of configuration is added to AndroidManifest.xml of App and this App is installed on the main screen via App market with smooth communication of double screen. Main & second screen programs are written in one App, thus it is required that you add the relevant judgment logic in the inlet class. That’s the cause for your modifying the enabling page when running Demo. You may refer to Demo as for the concrete code to judge main & second screen.

Debugging second screen 


 


 "sunmi_dual" android:value="open"/>

 

Currently, the developers can debug the main screen via USB. Since normally the second screen only complete simple content display functions, considering a safe & stable second screen, Sunmi currently doesn’t open the second screen device to debug the operating environment directly via USB, and the second screen does not have its independent network connection. But don’t worry, we provide a type of alternative debugging solution (due to different environments, it may cause being unable to debug or debug exception).

Our engineers have simulated double screen communication channel base on the communication method of LAN. You may install double screen communication service prepared by us at any two Android tablet computers, set IP address, and then you can simulate the communication method of T1 main screen and second screen:

that is to say, we take two T1 devices, use the main screen of a T1 device to simulate the second screen and use that T1 device as main screen to communicate. Sure, you may use any Android mobile phone or tablet as the second screen, and then distribute the Apps to the devices via App market after completing the development debugging.

To supplement descriptions for one T1 wireless debugging:

1. The computer connects the device via USB, to ensure that the permission of the device debugging is open.

2. Enter “adb shell” in cmd command prompt to access T1 control console.

3. Enter “setprop service.adb.tcp.port 5555” in the control console.

4. Enter “ifconfig” in the control console to check ip address of T1 in the LAN, e.g.: 192.168.1.202

5. Access the options of the device: Setting -> Developer (If it has not been seen, you may access About the Device, click continuously several times the version number to open the developer mode) to find “Use DHCP Client End of the Old Version”, click it to open it.

6. Unplug USB.

7. Enter “adb connect ” in cmd, e.g.: adb connect 192.168.0.219. (Note: if prompt “Due to the active refusal of the target computer, it cannot be connected. (10061)” appears in this step, you can first close and then open the “USB debugging” option in the developer option, and then reenter the above command one time to have a try. )

8. The device pops up Toast prompt “You can begin to carry out the debugging”.

After completing the above steps, T1 wireless debugging can be realized.