- The main screen is 14 inches and the secondary screen is 7 inches.
- The main screen is 14 inches and the secondary screen is 14 inches.
The main and secondary screens are all running SUNMIUI system, and T1 dual-screen communication is completed through the interface packaged by Shangmi.
Usually the developer's business app runs on the main screen, and the secondary screen needs to display list information, promotional pictures, publicity slides, promotional videos and other content. Developers have two ways to display content using the T1 subscreen:
- Shangmi has a display program built in the T1 sub-screen system (hereinafter referred to as 'sub-display program'). The app of the main screen complies with the unified specifications of Shangmi, and sends data of a specific format to the sub-display program. The program displays the content. (development costs are low, recommended).
- Developers develop their own screen display app (high development cost, not recommended).
The quotient specifies the layout that the sub-display program can display. The developer modifies the code of the main screen app and transmits the data of the relevant format to the sub-display program.
The following three paragraphs will explain how to use the sub-display program: I. Initialize the configuration. Two. 7-inch screen layout and code passing data. Three. 14 layouts of the 14-inch screen and code to pass data.
To operate the 7-inch and 14-inch initialization process, please download the resource file, refer to the Demo project, and directly import the jar package into the main screen app project or declare it in the build.gradle file under the Android Studio app module.
dependencies {
compile 'com.sunmi:DS_Lib:1.0.2'
compile 'com.google.code.gson:gson:2.6.2'//gson任意版本
}
Configure the following statement under the node of the manifest file AndroidMainfest.xml:
<application>
....
<receiver
android:name="sunmi.ds.MsgReceiver">
<intent-filter >
<action android:name="com.sunmi.hcservice"></action>
<action android:name="com.sunmi.hcservice.status"></action>
</intent-filter>
</receiver>
</application>
Initialize the SDK code in the appropriate place as follows, you can refer to the code in the Demo.
DSKernel mDSKernel =DSKernel.newInstance();
mDSKernel.init(context, mConnCallback);
mDSKernel.addReceiveCallback(mReceiveCallback);
Note: For the interface related to the main and secondary screen communication, please refer to the T1 dual-screen communication interface document in the resource file. The sub-screen guest display operation instruction kit sees the code in Demo:sunmi.ds.data for the operation of the sub-screen display command. The encapsulation is also the APP protocol layer in the framework diagram.
After completing the above operations, you can send data to the secondary screen. The following explains the display layout of the 7-inch screen and the 14-inch screen and the data format to be transmitted under each layout.
- Full screen display of a single picture
- Full screen only shows simple text
- Display image + text in the partial area of the screen
The following explains the data content that the main screen app needs to pass to the sub-display program when the 7-inch screen sub-display program displays each layout:
The effect diagram is as follows:
To display the above layout, just call DSKernel's sendFile method to send a picture to the sub-display program. It is recommended that the picture resolution be 1024*600, or the corresponding aspect ratio picture, otherwise it will be zoomed, the picture is instantly displayed in real time, and will be cached and reused. That is to say, theoretically, it is not necessary to use it every time. The program passes the picture.
You can participate in the demo about the 7-inch sub-display related code:
The code when sending data is as follows:
String filePath = "xxx/img.png"; // This is the local path of the image to be displayed
// Send a file to the sub-display program by sending a file to the sendFile of DSKernel
mDSKernel.sendFile(DSKernel.getDSDPackageName(), filePath, new ISendCallback(){
public void onSendSuccess(long l) {
// A successful callback is sent. The parameter long l is the unique identifier of the file on the secondary screen. The developer can save the field locally. The next time, the field can be used to query whether the file exists in the secondary display program.
showImg(fileId);//发送命令,让副屏显示图片
}
public void onSendFail(int i, String s) {
//Send failed callback
}
public void onSendProcess(long l, long l1) {
//发送状态的回调
}
});
void showImg(long fileId){
String json = UPacketFactory.createJson(DataModel.SHOW_IMG_WELCOME, "def");
mDSKernel.sendCMD(DSKernel.getDSDPackageName(), json, fileId, null);//该命令会让副屏显示图片
}
Note: In all places where you want to send files (pictures, videos), it is recommended that the developer call DSKernel.checkFileExist(long fileId, final ICheckFileCallback callback) before sending the file to check whether the file has a cache on the secondary screen. If there is any file, then You don't have to repeat it. The code to check is as follows:
// Description: This method checks whether the file corresponding to the fileId exists on the secondary screen. The first parameter is the file id returned by the secondary screen when the file is sent before. The id is unique for all files, and the second parameter is the result callback.
mDSKernel.checkFileExist(fileId, new ICheckFileCallback(){
@Override
public void onCheckFail() {}
@Override
public void onResult(boolean arg0) {
//返回值为true是存在
//返回值false是不存在
}
});
Display the two lines of characters in the title and content. The layout format is stipulated by the quotient. The main screen app only needs to send the data in the json format to the sub-display program.
The effect chart is as follows:
发数据时代码如下:
JSONObject json = new JSONObject();
json.put("title", title);//title为上面一行的标题内容
json.put("content", content);//content为下面一行的内容
String jsonStr = json.toString();
//构建DataPacket类
DataPacket packet = UPacketFactory.buildShowText(
DSKernel.getDSDPackageName(), jsonStr, callback);//第一个参数是接收数据的副显应用的包名,这里参照Demo就可以,第二个参数是要显示的内容字符串,第三个参数为结果回调。
mDSKernel.sendData(packet);//调用sendData方法发送文本
The layout format is also stipulated by the quotient. Currently, this layout of the 7-inch screen is recommended to display the following information: the picture is a two-dimensional code, and the text on the right has only two lines of title and content.
The data code is as follows:
JSONObject json = new JSONObject();
json.put("title", title);//Title is the title content of the above line
json.put("content", content);//Content is the content of the following line
String titleContentJsonStr= json.toString();
mDSKernel.sendFile(DSKernel.getDSDPackageName(), titleContentJsonStr,filePath, new ISendCallback() {
@Override
public void onSendSuccess(long fileId) {
showQRCode(fileId);//QR code image transmission
}
public void onSendFail(int i, String s) {
//错误回调
}
public void onSendProcess(long l, long l1) {
//发送状态回调
}
});
private void showQRCode(long fileId) {
String json = UPacketFactory.createJson(sunmi.ds.data.DataModel.QRCODE,"");
mDSKernel.sendCMD(DSKernel.getDSDPackageName(), json, fileId, null);
- Full screen display only complex table character data
- The picture is displayed on the left side of the screen and the complex table data is displayed on the right side.
- The slide is displayed on the left side of the screen and the complex table data is displayed on the right side.
- The video is displayed on the left side of the screen and the complex table data is displayed on the right side.
- Display a single picture in full screen
- Full screen slideshow
- Full screen video
The following explains the data content that the main screen app needs to pass to the sub-display program when the 14-inch screen sub-display program displays each layout:
The table data is displayed in full screen, and the display layout is fixed with three display areas: a title area, a list area, and a settlement area. The title area can only display a string of characters; the list area will display a table, which can display 1 to 8 column fields, the number of lines is not limited, but the line that can be displayed beyond the screen will automatically scroll to the bottom line; the settlement area can be displayed. 1 to 8 fields. The format is fixed by the quotient, but the field title and data content are passed by the main screen app.
The effect chart is as follows:
代码如下:
/**
*receiverPackageName The secondary screen that receives the data shows the app's package name DataType.DATA
*DataType.DATA
*DataModel.TEXT
*jsonStr shows the data content, see the box below for the specific format.
*callback callback
*/
DataPacket pack = buildPack(receiverPackageName, DataType.DATA, DataModel.TEXT, jsonStr, callback);//
mDSKernel.sendData(pack);
The data format of jsonStr above is shown in the following box. Please ask the developer to generate data in JSON format by referring to the following format. The title defines the content displayed in the title area, and the head defines the field title in the list area. Please generate the corresponding data according to the reference demo. Please note that the corresponding number of fields conforms to the specification. The key values of the following characters: title, head, list, KVPlist, name, value are fixed words, param1, param2...param8 are sequentially incremented, if the format is incorrect, Unable to display the effect.
{
"title": "三米奶茶店欢迎您",
"head": {
"param1": "序列号",
"param2": "商品名",
"param3": "单价",
"param4": "数量",
"param5": "小结"
},
"list": [
{
"param1": "1",
"param2": "华夫饼",
"param3": "10.00",
"param4": "1",
"param5":"10.00"
},
{
"param1": "1",
"param2": "吞拿鱼华夫饼",
"param3": "12.00",
"param4": "1",
"param5":"12.00"
}
... ...//这里是相同格式的数据
],
"KVPList": [
{
"name": "收款",
"value": "¥40.00"
},
{
"name": "优惠",
"value": "¥3.00"
},
{
"name": "找零",
"value": "¥3.00"
},
{
"name": "实收",
"value": "¥37.00"
}
]
}
Data format description:
1: title field is the title
2: the head field is the header field
3: list is the list of products, the number of fields in the header and table should be the same
4: KVPList is a list of settlement key-value pairs
rule:
When only the shopping list is displayed: the number of params assigned to the head is a minimum of 1 and a maximum of 8; the number of params assigned to each element in the list is a minimum of 1 and a maximum of 8; the size of the KVPList is a minimum of 1 and a maximum of 8.
2. The picture on the left of the screen is displayed, and the complex table data is displayed on the right (14-inch screen)
The left area shows the picture, the recommended picture size is 1186*1080; the right area shows complex table data, which is also divided into three display areas: title area, list area, and settlement area. The title area can only display a string of characters; the list area will display a table with up to 4 columns of fields, and the line data beyond the screen range can be scrolled; the settlement area can display 1 to 4 fields.
Effect chart:
code show as below:
String filePath = "xxx/img.png";//Displayed image path
mDSKernel.sendFile(DSKernel.getDSDPackageName(), filePath, new ISendCallback() {
public void onSendSuccess(long fileId) {
show(fileId, jsonStr);//图片发送成功,显示文字内容
}
public void onSendFail(int errorId, String errorInfo) {}
public void onSendProcess(long total, long sended) {}
});
void show(long fileId, String jsonStr){
jsonStr = UPacketFactory.createJson(DataModel.SHOW_IMG_LIST, jsonStr);//第一个参数DataModel.SHOW_IMG_LIST为显示布局模式,jsonStr为要显示的内容字符
mDSKernel.sendCMD(DSKernel.getDSDPackageName(), jsonStr, fileId,null);
}
The data format of jsonStr above is shown in the following box. Please ask the developer to generate data in JSON format by referring to the following format. The title defines the content displayed in the title area, and the head defines the field title in the list area. Please generate the corresponding data according to the reference Demo. Please note that the corresponding number of fields conforms to the specification. The key values of the following characters: title, head, list, KVPlist, name, and value are fixed words, and param1, param2...param4 are sequentially incremented.
{
"title": "商米奶茶店欢迎你",
"head": {
"param1": "商品名",
"param2": "单价",
"param3": "数量",
"param4":"小结"
},
"list": [
{
"param1": "华夫饼",
"param2": "10.00",
"param3": "1",
"param4":"10.00"
},
{
"param1": "吞拿鱼华夫饼",
"param2": "12.00",
"param3": "1",
"param4":"12.00"
}
... ...
],
"KVPList": [
{
"name": "收款",
"value": "¥40.00"
},
{
"name": "优惠",
"value": "¥3.00"
},
{
"name": "找零",
"value": "¥3.00"
},
{
"name": "实收",
"value": "¥37.00"
}
]
}
JSON data format description:
1: title field is the title
2: the head field is the header field
3: list is the list of products, the number of fields in the header and table should be the same
4: KVPList is a list of settlement key-value pairs
rule:
When displaying the picture and text mixture: the number of params assigned to the head is at least 1 and the maximum is 4; the number of params assigned to each element in the list is at least 1 and the maximum is 4; the size of the KVPList is at least 1 and the maximum is 4.
3. The slide is displayed on the left side of the screen, and the complex table data is displayed on the right side (14-inch screen)
The left area shows the slideshow. The recommended image size is 1186*1080. The right area shows complex table data, which is also divided into three display areas: title area, list area, and settlement area. The title area can only display a string of characters; the list area will display a table with up to 4 columns of fields, and the line data beyond the screen range can be scrolled; the settlement area can display 1 to 4 fields.
Effect chart:
代码如下:
List<String> paths = new ArrayList<>();
paths.add(Environment.getExternalStorageDirectory().getPath() + "/sunmi1.png");
paths.add(Environment.getExternalStorageDirectory().getPath() + "/sunmi2.png");
paths.add(Environment.getExternalStorageDirectory().getPath() + "/sunmi3.png");
paths.add(Environment.getExternalStorageDirectory().getPath() + "/sunmi4.png");
mDSKernel.sendFiles(DSKernel.getDSDPackageName(), "", paths, new ISendFilesCallback() {
@Override
public void onAllSendSuccess(long fileId) {
sendImgsListCMD(fileId,json);
}
@Override
public void onSendSuccess(String path, long taskId) {}
@Override
public void onSendFaile(int errorId, String errorInfo) {}
@Override
public void onSendFileFaile(String path, int errorId, String errorInfo) {}
@Override
public void onSendProcess(String path, long totle, long sended) {}
});
void sendImgsListCMD(long fileId, String jsonStr){
jsonStr= UPacketFactory.createJson(DataModel.SHOW_IMGS_LIST, json);
mDSKernel.sendCMD(DSKernel.getDSDPackageName(), jsonStr, fileId,null);
}
The data format rules of jsonStr above are the same as those in layout 2, and will not be described here.
4. The video is displayed on the left side of the screen, and the complex table data is displayed on the right side.
The left area shows the video, the recommended resolution is 1186*1080; the right area shows complex table data, which is also divided into three display areas: title area, list area, and settlement area. The title area can only display a string of characters; the list area will display a table with up to 4 columns of fields, and the line data beyond the screen range can be scrolled; the settlement area can display 1 to 4 fields.
Effect chart:
String filePath = "xxx/video.mp4";//显示的视频路径
mDSKernel.sendFile(DSKernel.getDSDPackageName(), filePath, new ISendCallback() {
public void onSendSuccess(long fileId) {
show(fileId, jsonStr);//视频发送成功
}
public void onSendFail(int errorId, String errorInfo) {}
public void onSendProcess(long total, long sended) {}
});
void show(long fileId, String jsonStr){
jsonStr = UPacketFactory.createJson(DataModel.SHOW_VIDEO_LIST, jsonStr);
mDSKernel.sendCMD(DSKernel.getDSDPackageName(), jsonStr, fileId,null);
}
The data format rules of jsonStr above are the same as those in layout 2, and will not be described here.
Effect chart:
Similar to the 7-inch screen, the picture is sent first. After the transmission is successful, the control command is displayed in the callback to display the picture. The code is as follows:
String filePath = "/sdcard/img.png";
mDSKernel.sendFile(DSKernel.getDSDPackageName(), filePath, new ISendCallback(){
public void onSendSuccess(long l) {
showImg(fileId);//先发送图片
}
public void onSendFail(int i, String s) {}
public void onSendProcess(long l, long l1) {}
});
void showImg(long fileId){
String json = UPacketFactory.createJson(DataModel.SHOW_IMG_WELCOME, "def");
mDSKernel.sendCMD(DSKernel.getDSDPackageName(), json, fileId, null);
}
Effect chart:
When the video is displayed for the first time, the process of passing the video may be very long. The developer should first pass the video to the sub-display program at the appropriate time. The sub-display program will cache the video. The code is as follows:
String filePath = "/sdcard/onepiece.mp4";
mDSKernel.sendFile(DSKernel.getDSDPackageName(), filePath, new ISendCallback(){
public void onSendSuccess(long l) {
playVideo(fileId);
}
public void onSendFail(int errorId, String errorInfo) {}
public void onSendProcess(long total, long sended) {}
});
void playVideo(long fileId){
String json = UPacketFactory.createJson(DataModel.VIDEO, "");
mDSKernel.sendCMD(DSKernel.getDSDPackageName(), json, fileId, null);
}
The effect chart is as follows:
The developer needs to prepare multiple images, call the sendFiles method to pass the path of multiple images to the sub-display program. The default switching time of the slide is 10 seconds. The main screen app can change the time by passing parameters. For details, please refer to the following code.
JSONObject json = new JSONObject();
json.put("interval",5000); //幻灯片的切换时间,用毫秒计算,如果不传默认是10000毫秒
List<String> pathList = new ArrayList<>();
pathList.add("/sdcard/img1.png");
pathList.add("/sdcard/img2.png");
...
mDSKernel.sendFiles(DSKernel.getDSDPackageName(), json.toString(), pathList, new ISendFilesCallback() {
public void onAllSendSuccess(long fileId) {
show(fileId);
}
public void onSendSuccess(final String s,final long l) {}
public void onSendFaile(int errorId, String errorInfo) {}
public void onSendFileFaile(String path, int errorId, String errorInfo){}
public void onSendProcess(String path, long total, long sended) {}
});
private void show(long fileId) {
String json = UPacketFactory.createJson(DataModel.IMAGES,"");
mDSKernel.sendCMD(DSKernel.getDSDPackageName(),json,fileId,null);
}
Additional instructions: The above is the layout currently supported by the Shangmi T1 built-in display program. More layouts will be added later, and developers can also develop sub-display programs that adapt to the merchant T1.