Blame view

src/com/ectrip/cyt/center/PrintHandle.java 7.94 KB
3c2353cd   杜方   1、畅游通核销app源码提交;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
  package com.ectrip.cyt.center;
  
  import android.content.Context;
  import android.content.Intent;
  import android.content.res.Resources;
  import android.widget.Toast;
  
  import com.ectrip.cyt.bean.ConfigBean;
  import com.ectrip.cyt.db.DbManager;
  import com.ectrip.cyt.ui.BaseActivity;
  import com.ectrip.cyt.utils.SharedPreferences2Obj;
  import com.ectrip.trips.check.R;
  
  import java.util.ArrayList;
  
  import android_serialport_api.print_tool.BasewinRebPosPortTool;
  import android_serialport_api.print_tool.MobilePrintTool;
  import android_serialport_api.print_tool.SerialIDPortTool;
  import android_serialport_api.print_tool.SerialNewHandlePortTool;
  import android_serialport_api.print_tool.SerialNewPortTool;
  import android_serialport_api.print_tool.SerialPortTool;
  import android_serialport_api.print_tool.SerialSmallPortTool;
  
  /**
   * @author jigo 打印处理
   */
  public class PrintHandle {
  	// private String TAG = PrintHandle.class.getSimpleName();
  	private Context context;
  	private String printInfo;
  	private final int ID_POS = 5;// 身份证pos
  	private final int GENERAL_POS = 6;// 一般pos
  	private final int SMALL_POS = 7;// 小的pos
  	private final int HANDSET = 8; // 手持机
  	private final int MOBILE = 9;// 手机
  	private final int New_POS = 10; // 新版的pos机
  	private final int New_IDPOS = 11; // 新版的身份证
  	private final int New_HANDSET_POS = 12; // 新版的手持机pos机
  	private final int BASEWIN_REB_POS = 13; // 盛本的红色pos机
  
  	private int isPrint = -1;// 是否打印
  	private String isStatistic = "0";
  
  	private static PrintHandle printHandle = null;
  
  	private Integer type = null;// 设备类型
  	private Resources resources;
  
  	public static PrintHandle getInstance() {
  		if (printHandle == null) {
  			synchronized (PrintHandle.class) {
  
  				printHandle = new PrintHandle();
  			}
  		}
  		return printHandle;
  	}
  
  	private boolean isClick = true;
  
  	public void print(String printInfo, Context context) {
  		this.context = context;
  		resources = context.getResources();
  
  		if (printInfo == null) {
  			return;
  		}
  //		int index = printInfo.indexOf("证件号码");
  //		if (printInfo.length()>27){
  //			String noString = printInfo.substring(26, 27);
  //			if (noString.equals("\n")) {
  //				String buf = printInfo.substring(index + 13, index + 21);
  //				printInfo = printInfo.replace(buf, "****");
  //			}
  //
  //		}
  
  		type = SharedPreferences2Obj.getInstance(context)
  				.setName("MachineType").getObject("type", Integer.class);
  
  		if (isClick == false) {
  			return;
  		}
  
  		if (isClick == true) {
  
  			this.printInfo = printInfo;
  			try {
  				ArrayList<ConfigBean> beans = DbManager.GetConfigs();
  				if (beans != null && beans.get(0) != null) {
  					// 判断是否为打印
  					isPrint = beans.get(0).getEc_isPrint();
  				}
  			} catch (Exception e) {
  				e.printStackTrace();
  			}
  
  			isStatistic = SharedPreferences2Obj.getInstance(context)
  					.setName("SelectAction")
  					.getObject("isStatistic", String.class); // 非统计
  			if (isStatistic != null) {
  				if (isStatistic.equals("0")) { // 非统计
  					String titleName = SharedPreferences2Obj
  							.getInstance(context).setName("SelectAction")
  							.getObject("titleName", String.class);
  					if (titleName != null) {
  						if (titleName.equals(resources
  								.getString(R.string.check))) {
  							if (isPrint == 1) { // 1的时候打印小票
  								printInfo(type);
  							}
  						} else if (titleName.equals(resources
  								.getString(R.string.reprint))) {
  							printInfo(type);
  						}
  					} else {
  						printInfo(type);
  					}
  				} else if (isStatistic.equals("1")) {
  					printInfo(type);
  				}
  			}
  		}
  	}
  
  	private void printInfo(Integer type) {
  
  		if (type != null) {
  			switch (type) {
  				case ID_POS:
  					try {
  						idPosPrint();
  					} catch (Exception e) {
  						e.printStackTrace();
  					}
  					break;
  				case GENERAL_POS:
  					try {
  						generalPrint();
  					} catch (Exception e) {
  						e.printStackTrace();
  					}
  					break;
  				case SMALL_POS:
  					try {
  						smallPosprint();
  					} catch (Exception e) {
  						e.printStackTrace();
  					}
  					break;
  				case HANDSET:
  					((BaseActivity) context).MToast(context,
  							context.getString(R.string.not_support_print),
  							Toast.LENGTH_SHORT);
  					// try {
  					// handlePrint();
  					// } catch (Exception e) {
  					// e.printStackTrace();
  					// }
  					break;
  				case MOBILE:
  					try {
  						mobilePrint();
  					} catch (Exception e) {
  						e.printStackTrace();
  					}
  					break;
  				case New_POS:
  					try {
  						newPosPrint();
  					} catch (Exception e) {
  						e.printStackTrace();
  					}
  					break;
  				case New_IDPOS:
  					try {
  						handlePosPrint();
  					} catch (Exception e) {
  						e.printStackTrace();
  					}
  					break;
  				case New_HANDSET_POS:
  					try {
  						handlePosPrint();
  					} catch (Exception e) {
  						e.printStackTrace();
  					}
  					break;
  				case BASEWIN_REB_POS:
  					try {
  						basewinPosPrint();
  					} catch (Exception e) {
  						e.printStackTrace();
  					}
  
  					break;
  				default:
  					break;
  			}
  		}
  	}
  
  	/************************ 关闭打印 *******************************************/
  	public void printClose() {
  		if (type != null) {
  			switch (type) {
  				case ID_POS:
  					break;
  				case GENERAL_POS:
  					break;
  				case SMALL_POS:
  					break;
  				case HANDSET:
  					break;
  				case MOBILE:
  					break;
  				case New_POS:
  					try {
  						if(serialNewPortTool!=null){
  							serialNewPortTool.close();
  						}
  					} catch (Exception e1) {
  						e1.printStackTrace();
  					}
  					break;
  				case New_IDPOS:
  					break;
  				case New_HANDSET_POS:
  					try {
  						if(serialNewHandlePortTool!=null){
  							serialNewHandlePortTool.close();
  						}
  					} catch (Exception e) {
  						e.printStackTrace();
  					}
  					break;
  				case BASEWIN_REB_POS:
  					try {
  						if(basewinRebPosPortTool!=null){
  							basewinRebPosPortTool.close();
  						}
  					} catch (Exception e) {
  						e.printStackTrace();
  					}
  					break;
  
  				default:
  					break;
  			}
  		}
  	}
  
  	/***************************** 普通pos机 ***********************************/
  	SerialPortTool portTool;
  	private void generalPrint() {
  		portTool = new SerialPortTool();
  		portTool.init(context, printInfo);
  	}
  
  	/******************************** 带身份证打印 ****************************************************/
  	SerialIDPortTool idPortTool;
  
  	private void idPosPrint() {
  		idPortTool = new SerialIDPortTool();
  		idPortTool.init(context, printInfo);
  	}
  
  	/******************************* 小pos机(手持pos机) ****************************************/
  	SerialSmallPortTool smallPortTool;
  
  	private void smallPosprint() {
  		smallPortTool = new SerialSmallPortTool();
  		smallPortTool.init(context, printInfo);
  	}
  
  	/********************************* 手机 ***************************************************/
  	private void mobilePrint() {
  		Intent intent = new Intent(context, MobilePrintTool.class);
  		intent.putExtra("info", printInfo);
  		context.startActivity(intent);
  	}
  
  	/********************************* 手持机 ******************************************************/
  	private void handlePrint() {
  		Intent intent = new Intent(context, MobilePrintTool.class);
  		intent.putExtra("info", printInfo);
  		context.startActivity(intent);
  	}
  
  	/******************************** 新版pos机 ***************************************************/
  	SerialNewPortTool serialNewPortTool;
  	private void newPosPrint() {
  		serialNewPortTool = new SerialNewPortTool();
  		serialNewPortTool.init(context, printInfo);
  	}
  
  	/********************************* 新版手持pos机 ***********************************************/
  	SerialNewHandlePortTool serialNewHandlePortTool;
  	private void handlePosPrint() {
  		serialNewHandlePortTool = new SerialNewHandlePortTool();
  		serialNewHandlePortTool.init(context, printInfo);
  	}
  	/********************************* 盛本红色pos机 ***********************************************/
  	BasewinRebPosPortTool basewinRebPosPortTool;
  	private void basewinPosPrint(){
  		basewinRebPosPortTool = new BasewinRebPosPortTool();
  		basewinRebPosPortTool.init(context, printInfo);
  	}
  }