|
31
|
+import ai.pai.lensman.db.Preferences;
|
27
|
32
|
import ai.pai.lensman.service.UploadService;
|
28
|
33
|
|
29
|
34
|
|
|
|
@@ -108,28 +113,37 @@ public class SessionPresenter implements SessionContract.Presenter, SessionInter
|
108
|
113
|
|
109
|
114
|
@Override
|
110
|
115
|
public void printQR() {
|
|
116
|
+ if(TextUtils.isEmpty(Preferences.getInstance().getPrinterMac())){
|
|
117
|
+ sessionView.showToast(App.getAppContext().getString(R.string.not_set_printer_yet));
|
|
118
|
+ return;
|
|
119
|
+ }
|
|
120
|
+ checkPrinter();
|
111
|
121
|
EscCommand esc = new EscCommand();
|
112
|
122
|
esc.addPrintAndFeedLines((byte) 3);
|
113
|
123
|
esc.addSelectJustification(EscCommand.JUSTIFICATION.CENTER);//设置打印居中
|
114
|
124
|
esc.addSelectPrintModes(EscCommand.FONT.FONTA, EscCommand.ENABLE.OFF, EscCommand.ENABLE.ON, EscCommand.ENABLE.ON, EscCommand.ENABLE.OFF);//设置为倍高倍宽
|
115
|
|
- esc.addText("Sample\n"); // 打印文字
|
|
125
|
+ esc.addText("拍爱\n"); // 打印文字
|
116
|
126
|
esc.addPrintAndLineFeed();
|
117
|
127
|
|
118
|
128
|
/*打印文字*/
|
119
|
129
|
esc.addSelectPrintModes(EscCommand.FONT.FONTA, EscCommand.ENABLE.OFF, EscCommand.ENABLE.OFF, EscCommand.ENABLE.OFF, EscCommand.ENABLE.OFF);//取消倍高倍宽
|
120
|
130
|
esc.addSelectJustification(EscCommand.JUSTIFICATION.LEFT);//设置打印左对齐
|
121
|
|
- esc.addText("Welcome to use Paiai!\n"); // 打印文字
|
|
131
|
+ esc.addText("欢迎使用拍爱!\n"); // 打印文字
|
122
|
132
|
|
123
|
133
|
/*QRCode命令打印
|
124
|
134
|
此命令只在支持QRCode命令打印的机型才能使用。
|
125
|
135
|
在不支持二维码指令打印的机型上,则需要发送二维条码图片
|
126
|
136
|
*/
|
127
|
|
- esc.addText("Print QRcode\n"); // 打印文字
|
|
137
|
+ esc.addText("Print QRCode\n"); // 打印文字
|
|
138
|
+ esc.addPrintAndFeedLines((byte) 3);
|
128
|
139
|
esc.addSelectErrorCorrectionLevelForQRCode((byte) 0x31); //设置纠错等级
|
129
|
|
- esc.addSelectSizeOfModuleForQRCode((byte) 3);//设置qrcode模块大小
|
|
140
|
+ esc.addSelectSizeOfModuleForQRCode((byte)10);//设置qrcode模块大小
|
130
|
141
|
esc.addStoreQRCodeData(sessionBean.sessionId);//设置qrcode内容
|
|
142
|
+ esc.addSelectJustification(EscCommand.JUSTIFICATION.CENTER);//设置打印中心对齐
|
131
|
143
|
esc.addPrintQRCode();//打印QRCode
|
132
|
|
- esc.addPrintAndLineFeed();
|
|
144
|
+ esc.addSelectJustification(EscCommand.JUSTIFICATION.LEFT);//设置打印左对齐
|
|
145
|
+ esc.addText("拍摄日期 "+new SimpleDateFormat("yy/MM/dd HH:mm").format(new Date()));
|
|
146
|
+ esc.addPrintAndFeedLines((byte) 3);
|
133
|
147
|
|
134
|
148
|
Vector<Byte> datas = esc.getCommand(); //发送数据
|
135
|
149
|
Byte[] Bytes = datas.toArray(new Byte[datas.size()]);
|
|
|
@@ -147,6 +161,34 @@ public class SessionPresenter implements SessionContract.Presenter, SessionInter
|
147
|
161
|
}
|
148
|
162
|
}
|
149
|
163
|
|
|
164
|
+ private void checkPrinter(){
|
|
165
|
+ sessionView.showToast(App.getAppContext().getString(R.string.connecting));
|
|
166
|
+ try{
|
|
167
|
+ int status = mGpService.queryPrinterStatus(0, 10000);
|
|
168
|
+ if (status != GpCom.STATE_NO_ERR) {
|
|
169
|
+ connectPrinter();
|
|
170
|
+ }
|
|
171
|
+ }catch (Exception e){
|
|
172
|
+ sessionView.showToast(App.getAppContext().getString(R.string.go_check_printer));
|
|
173
|
+ return;
|
|
174
|
+ }
|
|
175
|
+ printQR();
|
|
176
|
+ }
|
|
177
|
+
|
|
178
|
+ public void connectPrinter() {
|
|
179
|
+ if(mGpService==null){
|
|
180
|
+ sessionView.showToast(App.getAppContext().getString(R.string.printer_service_boot_fail));
|
|
181
|
+ return;
|
|
182
|
+ }
|
|
183
|
+ try {
|
|
184
|
+ int code = mGpService.openPort(0, PortParameters.BLUETOOTH, Preferences.getInstance().getPrinterMac(), 0);
|
|
185
|
+ LogHelper.d("czy111","open port return code ="+code);
|
|
186
|
+ } catch (Exception e) {
|
|
187
|
+ sessionView.showToast(App.getAppContext().getString(R.string.printer_port_open_fail));
|
|
188
|
+ }
|
|
189
|
+
|
|
190
|
+ }
|
|
191
|
+
|
150
|
192
|
private void startAndBindPrintService() {
|
151
|
193
|
Intent intent = new Intent(App.getAppContext(), GpPrintService.class);
|
152
|
194
|
App.getAppContext().startService(intent);
|
|
|
@@ -110,4 +110,6 @@
|
110
|
110
|
<string name="printer_status_query_fail">打印机状态查询失败</string>
|
111
|
111
|
|
112
|
112
|
<string name="printer_service_boot_fail">打印机服务连接失败,请退出应用重试</string>
|
|
113
|
+
|
|
114
|
+ <string name="not_set_printer_yet">尚未设置打印机,去设置</string>
|
113
|
115
|
</resources>
|
|
|
@@ -5,7 +5,7 @@ buildscript {
|
5
|
5
|
jcenter()
|
6
|
6
|
}
|
7
|
7
|
dependencies {
|
8
|
|
- classpath 'com.android.tools.build:gradle:2.1.3'
|
|
8
|
+ classpath 'com.android.tools.build:gradle:2.2.0-rc1'
|
9
|
9
|
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
|
10
|
10
|
// NOTE: Do not place your application dependencies here; they belong
|
11
|
11
|
// in the individual module build.gradle files
|