167
+            rel = mGpService.sendEscCommand(0, str);
125 168
             GpCom.ERROR_CODE r = GpCom.ERROR_CODE.values()[rel];
126 169
             if (r != GpCom.ERROR_CODE.SUCCESS) {
127 170
                 view.showToast( GpCom.getErrorText(r));
128 171
             }
129
-        } catch (Exception e1) {
130
-            e1.printStackTrace();
172
+        } catch (Exception e) {
173
+            view.showToast(App.getAppContext().getString(R.string.go_check_printer));
131 174
         }
132 175
     }
133 176
 

+ 8 - 2
app/src/main/java/ai/pai/lensman/session/SessionActivity.java

@@ -17,6 +17,7 @@ import ai.pai.lensman.bean.PhotoBean;
17 17
 import ai.pai.lensman.bean.SessionBean;
18 18
 import ai.pai.lensman.printer.PrinterSettingActivity;
19 19
 import ai.pai.lensman.qrcode.QRCaptureActivity;
20
+import ai.pai.lensman.utils.UrlContainer;
20 21
 import butterknife.BindView;
21 22
 import butterknife.ButterKnife;
22 23
 import butterknife.OnClick;
@@ -94,7 +95,10 @@ public class SessionActivity extends BaseActivity implements SessionContract.Vie
94 95
 
95 96
     @OnClick(R.id.iv_qrcode)
96 97
     void showQRCodeForSession(){
97
-        new SessionQRPopup(this, sessionBean.sessionId,this).showPopupWindow();
98
+//        new SessionQRPopup(this, sessionBean.sessionId,this).showPopupWindow();
99
+        Intent intent = new Intent(this,PrinterSettingActivity.class);
100
+        intent.putExtra("qrcode", UrlContainer.HOST_URL+sessionBean.sessionId);
101
+        startActivity(intent);
98 102
     }
99 103
 
100 104
     @OnClick(R.id.title_bar_back_layout)
@@ -143,7 +147,9 @@ public class SessionActivity extends BaseActivity implements SessionContract.Vie
143 147
     @Override
144 148
     public void onClick(View view) {
145 149
         if(view.getId()==R.id.btn_print_qr){
146
-            presenter.printQR();
150
+            Intent intent = new Intent(this,PrinterSettingActivity.class);
151
+            intent.putExtra("qrcode",sessionBean.sessionId);
152
+            startActivity(intent);
147 153
         }else if(view.getId()==R.id.tv_printer_set){
148 154
             startActivity(new Intent(this, PrinterSettingActivity.class));
149 155
         }

+ 0 - 1
app/src/main/java/ai/pai/lensman/session/SessionContract.java

@@ -18,6 +18,5 @@ public class SessionContract {
18 18
 
19 19
     interface Presenter extends BasePresenter{
20 20
         void swipeToDeletePhoto(int index);
21
-        void printQR();
22 21
     }
23 22
 }

+ 1 - 127
app/src/main/java/ai/pai/lensman/session/SessionPresenter.java

@@ -1,34 +1,13 @@
1 1
 package ai.pai.lensman.session;
2 2
 
3
-import android.content.ComponentName;
4
-import android.content.Context;
5 3
 import android.content.Intent;
6
-import android.content.ServiceConnection;
7
-import android.os.IBinder;
8
-import android.text.TextUtils;
9
-import android.util.Base64;
10
-import android.util.Log;
11
-
12
-import com.android.common.utils.LogHelper;
13
-import com.gprinter.aidl.GpService;
14
-import com.gprinter.command.EscCommand;
15
-import com.gprinter.command.GpCom;
16
-import com.gprinter.io.PortParameters;
17
-import com.gprinter.service.GpPrintService;
18
-
19
-import org.apache.commons.lang.ArrayUtils;
20
-
21
-import java.text.SimpleDateFormat;
4
+
22 5
 import java.util.ArrayList;
23
-import java.util.Date;
24
-import java.util.Vector;
25 6
 
26 7
 import ai.pai.lensman.App;
27
-import ai.pai.lensman.R;
28 8
 import ai.pai.lensman.bean.PhotoBean;
29 9
 import ai.pai.lensman.bean.SessionBean;
30 10
 import ai.pai.lensman.db.DBService;
31
-import ai.pai.lensman.db.Preferences;
32 11
 import ai.pai.lensman.service.UploadService;
33 12
 
34 13
 
@@ -40,9 +19,6 @@ public class SessionPresenter implements SessionContract.Presenter, SessionInter
40 19
     private SessionBean sessionBean;
41 20
     private boolean isWorking;
42 21
 
43
-    private GpService mGpService = null;
44
-    private PrinterServiceConnection conn = null;
45
-    private int mPrinterId = 0;
46 22
 
47 23
 
48 24
     public SessionPresenter(SessionBean sessionBean, SessionContract.View view) {
@@ -63,16 +39,12 @@ public class SessionPresenter implements SessionContract.Presenter, SessionInter
63 39
             }
64 40
         }
65 41
         interactor.startSession();
66
-        startAndBindPrintService();
67 42
     }
68 43
 
69 44
     @Override
70 45
     public void stop() {
71 46
         interactor.endSession();
72 47
         isWorking = false;
73
-        if (conn != null) {
74
-            App.getAppContext().unbindService(conn);
75
-        }
76 48
     }
77 49
 
78 50
     @Override
@@ -111,102 +83,4 @@ public class SessionPresenter implements SessionContract.Presenter, SessionInter
111 83
         interactor.deletePhoto(photoBean);
112 84
     }
113 85
 
114
-    @Override
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();
121
-        EscCommand esc = new EscCommand();
122
-        esc.addPrintAndFeedLines((byte) 3);
123
-        esc.addSelectJustification(EscCommand.JUSTIFICATION.CENTER);//设置打印居中
124
-        esc.addSelectPrintModes(EscCommand.FONT.FONTA, EscCommand.ENABLE.OFF, EscCommand.ENABLE.ON, EscCommand.ENABLE.ON, EscCommand.ENABLE.OFF);//设置为倍高倍宽
125
-        esc.addText("拍爱\n");   //  打印文字
126
-        esc.addPrintAndLineFeed();
127
-
128
-		/*打印文字*/
129
-        esc.addSelectPrintModes(EscCommand.FONT.FONTA, EscCommand.ENABLE.OFF, EscCommand.ENABLE.OFF, EscCommand.ENABLE.OFF, EscCommand.ENABLE.OFF);//取消倍高倍宽
130
-        esc.addSelectJustification(EscCommand.JUSTIFICATION.LEFT);//设置打印左对齐
131
-        esc.addText("欢迎使用拍爱!\n");   //  打印文字
132
-
133
-		/*QRCode命令打印
134
-			此命令只在支持QRCode命令打印的机型才能使用。
135
-			在不支持二维码指令打印的机型上,则需要发送二维条码图片
136
-		*/
137
-        esc.addText("Print QRCode\n");   //  打印文字
138
-        esc.addPrintAndFeedLines((byte) 3);
139
-        esc.addSelectErrorCorrectionLevelForQRCode((byte) 0x31); //设置纠错等级
140
-        esc.addSelectSizeOfModuleForQRCode((byte)10);//设置qrcode模块大小
141
-        esc.addStoreQRCodeData(sessionBean.sessionId);//设置qrcode内容
142
-        esc.addSelectJustification(EscCommand.JUSTIFICATION.CENTER);//设置打印中心对齐
143
-        esc.addPrintQRCode();//打印QRCode
144
-        esc.addSelectJustification(EscCommand.JUSTIFICATION.LEFT);//设置打印左对齐
145
-        esc.addText("拍摄日期 "+new SimpleDateFormat("yy/MM/dd HH:mm").format(new Date()));
146
-        esc.addPrintAndFeedLines((byte) 3);
147
-
148
-        Vector<Byte> datas = esc.getCommand(); //发送数据
149
-        Byte[] Bytes = datas.toArray(new Byte[datas.size()]);
150
-        byte[] bytes = ArrayUtils.toPrimitive(Bytes);
151
-        String str = Base64.encodeToString(bytes, Base64.DEFAULT);
152
-        int rel;
153
-        try {
154
-            rel = mGpService.sendEscCommand(mPrinterId, str);
155
-            GpCom.ERROR_CODE r = GpCom.ERROR_CODE.values()[rel];
156
-            if (r != GpCom.ERROR_CODE.SUCCESS) {
157
-                sessionView.showToast( GpCom.getErrorText(r));
158
-            }
159
-        } catch (Exception e) {
160
-            sessionView.showToast(App.getAppContext().getString(R.string.go_check_printer));
161
-        }
162
-    }
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
-
192
-    private void startAndBindPrintService() {
193
-        Intent intent = new Intent(App.getAppContext(), GpPrintService.class);
194
-        App.getAppContext().startService(intent);
195
-        conn = new PrinterServiceConnection();
196
-        App.getAppContext().bindService(intent, conn, Context.BIND_AUTO_CREATE);
197
-    }
198
-
199
-    class PrinterServiceConnection implements ServiceConnection {
200
-        @Override
201
-        public void onServiceDisconnected(ComponentName name) {
202
-            Log.i("ServiceConnection", "onServiceDisconnected() called");
203
-            mGpService = null;
204
-        }
205
-
206
-        @Override
207
-        public void onServiceConnected(ComponentName name, IBinder service) {
208
-            mGpService = GpService.Stub.asInterface(service);
209
-        }
210
-    }
211
-
212 86
 }

+ 8 - 1
app/src/main/res/layout/activity_printer_setting.xml

@@ -65,6 +65,13 @@
65 65
         android:layout_below="@id/title_bar_with_back_btn"
66 66
         android:orientation="vertical">
67 67
 
68
+        <ImageView
69
+            android:id="@+id/iv_qrcode"
70
+            android:layout_width="240dp"
71
+            android:layout_height="240dp"
72
+            android:layout_gravity="center_horizontal"
73
+            android:layout_margin="8dp"/>
74
+
68 75
         <LinearLayout
69 76
             android:layout_width="match_parent"
70 77
             android:layout_height="38dp"
@@ -111,7 +118,7 @@
111 118
                 android:id="@+id/tv_print_test"
112 119
                 android:layout_width="wrap_content"
113 120
                 android:layout_height="wrap_content"
114
-                android:text="@string/print_test"
121
+                android:text="@string/print_qr"
115 122
                 android:textColor="@color/dark_grey"
116 123
                 android:textSize="16sp" />
117 124
         </LinearLayout>

kodo - Gogs: Go Git Service

暂无描述

Brightcells: fabef63211 set line_length=200 for isort 10 年之前
..
migrations 4defb80fdc gogs first init 10 年之前
__init__.py 4defb80fdc gogs first init 10 年之前
admin.py fabef63211 set line_length=200 for isort 10 年之前
models.py fabef63211 set line_length=200 for isort 10 年之前
tests.py fabef63211 set line_length=200 for isort 10 年之前
urls.py fabef63211 set line_length=200 for isort 10 年之前
views.py fabef63211 set line_length=200 for isort 10 年之前