Commit a94485b3d604ffe6230819ccb1dfcd3d92588b4d

Authored by 杜方
1 parent 7fa57dc5

畅游通核销app:1.适配商米v2打印

AndroidManifest.xml
... ... @@ -2,8 +2,8 @@
2 2 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
3 3 xmlns:tool="http://schemas.android.com/tools"
4 4 package="com.ectrip.trips.check"
5   - android:versionCode="27"
6   - android:versionName="4.24"
  5 + android:versionCode="28"
  6 + android:versionName="4.25"
7 7 tool:ignore="LockedOrientationActivity">
8 8  
9 9 <!-- 各个类型的大小布局声明 -->
... ...
build.gradle
... ... @@ -5,21 +5,30 @@ apply plugin: &#39;com.android.application&#39;
5 5 buildscript {
6 6 repositories {
7 7 mavenCentral()
8   - maven {
9   - url 'https://maven.aliyun.com/repository/google/'
  8 + jcenter()
  9 + google()
  10 + maven { url "https://jitpack.io"}
  11 + maven { url "https://maven.aliyun.com/repository/google"}
  12 + maven { url "https://maven.aliyun.com/repository/public"}
  13 +// maven { url "https://maven.aliyun.com/repository/releases"}
  14 +// maven { url "https://maven.aliyun.com/repository/central"}
  15 +// maven { url "https://maven.aliyun.com/repository/gradle-plugin"}
  16 +// maven { url 'https://maven.aliyun.com/nexus/content/groups/public/'}
  17 +// maven {
  18 +// url 'https://maven.aliyun.com/repository/google/'
10 19 // url 'https://maven.google.com/'
11 20 // name 'Google'
12   - }
13   - maven {
14   - url 'https://maven.aliyun.com/repository/jcenter/'
15   - }
  21 +// }
  22 +// maven {
  23 +// url 'https://maven.aliyun.com/repository/jcenter/'
  24 +// }
16 25 // maven {
17 26 // url 'https://maven.google.com/'
18 27 // name 'Google'
19 28 // }
20 29 }
21 30 dependencies {
22   - classpath 'com.android.tools.build:gradle:3.4.0'
  31 + classpath 'com.android.tools.build:gradle:4.1.3'
23 32 }
24 33 }
25 34  
... ... @@ -30,7 +39,7 @@ dependencies {
30 39 implementation files('libs/fastjson-1.2.3.jar')
31 40 implementation files('libs/sunjce_provider.jar')
32 41 implementation files('libs/zbar.jar')
33   - implementation files('libs/zxing.jar')
  42 +// implementation files('libs/zxing.jar')
34 43 implementation files('libs/gson-2.6.2.jar')
35 44 implementation files('libs\\rskapi.jar')
36 45 implementation files('libs\\zkandroidcore.jar')
... ... @@ -42,10 +51,12 @@ dependencies {
42 51 implementation files('libs\\zypos1.8.jar')
43 52 implementation files('libs\\jsch-0.1.54.jar')
44 53 implementation 'org.jetbrains:annotations-java5:15.0'
  54 + implementation files('libs\\zxingcore-2.3.0.jar')
45 55 compileOnly files('external_libs/classes_2.1.11_20160907.jar')
46 56 compileOnly files('external_libs/bw_odm_20160526.jar')
47 57 implementation files('libs/bw_pos_sdk2.0.18.jar')
48 58 implementation 'com.squareup.okhttp3:okhttp:3.6.0'
  59 + implementation 'com.sunmi:printerx:1.0.18'
49 60 // implementation('com.android.support:support-v4:21.0.0')
50 61 // implementation('com.android.support:appcompat-v7:21.0.0'){ // You should exclude one of them not both of them
51 62 // exclude module: "support-v4"
... ... @@ -117,12 +128,13 @@ android {
117 128 release.setRoot('build-types/release')
118 129 }
119 130 defaultConfig {
120   - minSdkVersion 14
  131 + minSdkVersion 19
121 132 targetSdkVersion 21
122 133 vectorDrawables.useSupportLibrary =true
123 134  
124 135 ndk {
125 136 abiFilters "armeabi", "armeabi-v7a"//可以适当补填其他
  137 + abiFilters "arm64-v8a"
126 138 // abiFilters "armeabi"//可以适当补填其他
127 139 }
128 140 }
... ... @@ -149,12 +161,10 @@ def releaseTime() {
149 161 }
150 162  
151 163 repositories {
152   - maven {
153   - url 'https://maven.aliyun.com/repository/google/'
154   -// url 'https://maven.google.com/'
155   -// name 'Google'
156   - }
157   - maven {
158   - url 'https://maven.aliyun.com/repository/jcenter/'
159   - }
  164 + mavenCentral()
  165 + jcenter()
  166 + google()
  167 + maven { url "https://jitpack.io"}
  168 + maven { url "https://maven.aliyun.com/repository/google"}
  169 + maven { url "https://maven.aliyun.com/repository/public"}
160 170 }
161 171 \ No newline at end of file
... ...
libs/zxingcore-2.3.0.jar 0 → 100644
No preview for this file type
src/com/ectrip/cyt/center/PrintHandle.java
... ... @@ -3,15 +3,31 @@ package com.ectrip.cyt.center;
3 3 import android.content.Context;
4 4 import android.content.Intent;
5 5 import android.content.res.Resources;
  6 +import android.text.TextUtils;
6 7 import android.widget.Toast;
7 8  
8 9 import com.ectrip.cyt.bean.ConfigBean;
  10 +import com.ectrip.cyt.config.MyApp;
  11 +import com.ectrip.cyt.constant.LogoType;
  12 +import com.ectrip.cyt.constant.SelectAction;
  13 +import com.ectrip.cyt.constant.constant;
9 14 import com.ectrip.cyt.db.DbManager;
10 15 import com.ectrip.cyt.ui.BaseActivity;
  16 +import com.ectrip.cyt.ui.MainActivity;
  17 +import com.ectrip.cyt.utils.LogUtil;
11 18 import com.ectrip.cyt.utils.SharedPreferences2Obj;
12 19 import com.ectrip.trips.check.R;
13   -
  20 +import com.sunmi.printerx.SdkException;
  21 +import com.sunmi.printerx.api.LineApi;
  22 +import com.sunmi.printerx.api.PrintResult;
  23 +import com.sunmi.printerx.enums.Align;
  24 +import com.sunmi.printerx.enums.DividingLine;
  25 +import com.sunmi.printerx.style.BaseStyle;
  26 +import com.sunmi.printerx.style.TextStyle;
  27 +
  28 +import java.text.SimpleDateFormat;
14 29 import java.util.ArrayList;
  30 +import java.util.Date;
15 31  
16 32 import android_serialport_api.print_tool.BasewinRebPosPortTool;
17 33 import android_serialport_api.print_tool.MobilePrintTool;
... ... @@ -25,46 +41,48 @@ import android_serialport_api.print_tool.SerialSmallPortTool;
25 41 * @author jigo 打印处理
26 42 */
27 43 public class PrintHandle {
28   - // private String TAG = PrintHandle.class.getSimpleName();
29   - private Context context;
30   - private String printInfo;
31   - private final int ID_POS = 5;// 身份证pos
32   - private final int GENERAL_POS = 6;// 一般pos
33   - private final int SMALL_POS = 7;// 小的pos
34   - private final int HANDSET = 8; // 手持机
35   - private final int MOBILE = 9;// 手机
36   - private final int New_POS = 10; // 新版的pos机
37   - private final int New_IDPOS = 11; // 新版的身份证
38   - private final int New_HANDSET_POS = 12; // 新版的手持机pos机
39   - private final int BASEWIN_REB_POS = 13; // 盛本的红色pos机
40   -
41   - private int isPrint = -1;// 是否打印
42   - private String isStatistic = "0";
43   -
44   - private static PrintHandle printHandle = null;
45   -
46   - private Integer type = null;// 设备类型
47   - private Resources resources;
48   -
49   - public static PrintHandle getInstance() {
50   - if (printHandle == null) {
51   - synchronized (PrintHandle.class) {
52   -
53   - printHandle = new PrintHandle();
54   - }
55   - }
56   - return printHandle;
57   - }
58   -
59   - private boolean isClick = true;
60   -
61   - public void print(String printInfo, Context context) {
62   - this.context = context;
63   - resources = context.getResources();
64   -
65   - if (printInfo == null) {
66   - return;
67   - }
  44 + private String TAG = PrintHandle.class.getSimpleName();
  45 + private Context context;
  46 + private String printInfo;
  47 + private final int ID_POS = 5;// 身份证pos
  48 + private final int GENERAL_POS = 6;// 一般pos
  49 + private final int SMALL_POS = 7;// 小的pos
  50 + private final int HANDSET = 8; // 手持机
  51 + private final int MOBILE = 9;// 手机
  52 + private final int New_POS = 10; // 新版的pos机
  53 + private final int New_IDPOS = 11; // 新版的身份证
  54 + private final int New_HANDSET_POS = 12; // 新版的手持机pos机
  55 + private final int BASEWIN_REB_POS = 13; // 盛本的红色pos机
  56 + private final int SHANGMI_POS = 16;
  57 +
  58 + private int isPrint = -1;// 是否打印
  59 + private String isStatistic = "0";
  60 + private int Select = 0;
  61 +
  62 + private static PrintHandle printHandle = null;
  63 +
  64 + private Integer type = null;// 设备类型
  65 + private Resources resources;
  66 +
  67 + public static PrintHandle getInstance() {
  68 + if (printHandle == null) {
  69 + synchronized (PrintHandle.class) {
  70 +
  71 + printHandle = new PrintHandle();
  72 + }
  73 + }
  74 + return printHandle;
  75 + }
  76 +
  77 + private boolean isClick = true;
  78 +
  79 + public void print(String printInfo, Context context) {
  80 + this.context = context;
  81 + resources = context.getResources();
  82 + LogUtil.d(TAG, "printInfo = " + printInfo);
  83 + if (TextUtils.isEmpty(printInfo)) {
  84 + return;
  85 + }
68 86 // int index = printInfo.indexOf("证件号码");
69 87 // if (printInfo.length()>27){
70 88 // String noString = printInfo.substring(26, 27);
... ... @@ -75,236 +93,322 @@ public class PrintHandle {
75 93 //
76 94 // }
77 95  
78   - type = SharedPreferences2Obj.getInstance(context)
79   - .setName("MachineType").getObject("type", Integer.class);
80   -
81   - if (isClick == false) {
82   - return;
83   - }
84   -
85   - if (isClick == true) {
86   -
87   - this.printInfo = printInfo;
88   - try {
89   - ArrayList<ConfigBean> beans = DbManager.GetConfigs();
90   - if (beans != null && beans.get(0) != null) {
91   - // 判断是否为打印
92   - isPrint = beans.get(0).getEc_isPrint();
93   - }
94   - } catch (Exception e) {
95   - e.printStackTrace();
96   - }
97   -
98   - isStatistic = SharedPreferences2Obj.getInstance(context)
99   - .setName("SelectAction")
100   - .getObject("isStatistic", String.class); // 非统计
101   - if (isStatistic != null) {
102   - if (isStatistic.equals("0")) { // 非统计
103   - String titleName = SharedPreferences2Obj
104   - .getInstance(context).setName("SelectAction")
105   - .getObject("titleName", String.class);
106   - if (titleName != null) {
107   - if (titleName.equals(resources
108   - .getString(R.string.check))) {
109   - if (isPrint == 1) { // 1的时候打印小票
110   - printInfo(type);
111   - }
112   - } else if (titleName.equals(resources
113   - .getString(R.string.reprint))) {
114   - printInfo(type);
115   - }
116   - } else {
117   - printInfo(type);
118   - }
119   - } else if (isStatistic.equals("1")) {
120   - printInfo(type);
121   - }
122   - }
123   - }
124   - }
125   -
126   - private void printInfo(Integer type) {
127   -
128   - if (type != null) {
129   - switch (type) {
130   - case ID_POS:
131   - try {
132   - idPosPrint();
133   - } catch (Exception e) {
134   - e.printStackTrace();
135   - }
136   - break;
137   - case GENERAL_POS:
138   - try {
139   - generalPrint();
140   - } catch (Exception e) {
141   - e.printStackTrace();
142   - }
143   - break;
144   - case SMALL_POS:
145   - try {
146   - smallPosprint();
147   - } catch (Exception e) {
148   - e.printStackTrace();
149   - }
150   - break;
151   - case HANDSET:
152   - ((BaseActivity) context).MToast(context,
153   - context.getString(R.string.not_support_print),
154   - Toast.LENGTH_SHORT);
155   - // try {
156   - // handlePrint();
157   - // } catch (Exception e) {
158   - // e.printStackTrace();
159   - // }
160   - break;
161   - case MOBILE:
162   - try {
163   - mobilePrint();
164   - } catch (Exception e) {
165   - e.printStackTrace();
166   - }
167   - break;
168   - case New_POS:
169   - try {
170   - newPosPrint();
171   - } catch (Exception e) {
172   - e.printStackTrace();
173   - }
  96 + type = SharedPreferences2Obj.getInstance(context)
  97 + .setName("MachineType").getObject("type", Integer.class);
  98 +
  99 + LogUtil.d(TAG, "type = " + type);
  100 +
  101 + if (isClick == false) {
  102 + return;
  103 + }
  104 +
  105 + if (isClick == true) {
  106 +
  107 + this.printInfo = printInfo;
  108 + try {
  109 + ArrayList<ConfigBean> beans = DbManager.GetConfigs();
  110 + if (beans != null && beans.get(0) != null) {
  111 + // 判断是否为打印
  112 + isPrint = beans.get(0).getEc_isPrint();
  113 + }
  114 + } catch (Exception e) {
  115 + e.printStackTrace();
  116 + }
  117 +
  118 + isStatistic = SharedPreferences2Obj.getInstance(context)
  119 + .setName("SelectAction")
  120 + .getObject("isStatistic", String.class); // 非统计
  121 + Select = SharedPreferences2Obj.getInstance(context).
  122 + setName("SelectAction").getObject("Select", Integer.class);
  123 + if (isStatistic != null) {
  124 + if (isStatistic.equals("0")) { // 非统计
  125 + String titleName = SharedPreferences2Obj
  126 + .getInstance(context).setName("SelectAction")
  127 + .getObject("titleName", String.class);
  128 + if (titleName != null) {
  129 + if (titleName.equals(resources
  130 + .getString(R.string.check))) {
  131 + if (isPrint == 1) { // 1的时候打印小票
  132 + printInfo(type);
  133 + }
  134 + } else if (titleName.equals(resources
  135 + .getString(R.string.reprint))) {
  136 + printInfo(type);
  137 + }
  138 + } else {
  139 + printInfo(type);
  140 + }
  141 + } else if (isStatistic.equals("1")) {
  142 + printInfo(type);
  143 + }
  144 + }
  145 + }
  146 + }
  147 +
  148 + private void printInfo(Integer type) {
  149 +
  150 + if (type != null) {
  151 + switch (type) {
  152 + case ID_POS:
  153 + try {
  154 + idPosPrint();
  155 + } catch (Exception e) {
  156 + e.printStackTrace();
  157 + }
  158 + break;
  159 + case GENERAL_POS:
  160 + try {
  161 + generalPrint();
  162 + } catch (Exception e) {
  163 + e.printStackTrace();
  164 + }
  165 + break;
  166 + case SMALL_POS:
  167 + try {
  168 + smallPosprint();
  169 + } catch (Exception e) {
  170 + e.printStackTrace();
  171 + }
  172 + break;
  173 + case HANDSET:
  174 + ((BaseActivity) context).MToast(context,
  175 + context.getString(R.string.not_support_print),
  176 + Toast.LENGTH_SHORT);
  177 + // try {
  178 + // handlePrint();
  179 + // } catch (Exception e) {
  180 + // e.printStackTrace();
  181 + // }
  182 + break;
  183 + case MOBILE:
  184 + try {
  185 + mobilePrint();
  186 + } catch (Exception e) {
  187 + e.printStackTrace();
  188 + }
  189 + break;
  190 + case New_POS:
  191 + try {
  192 + newPosPrint();
  193 + } catch (Exception e) {
  194 + e.printStackTrace();
  195 + }
174 196 // Toast.makeText(context, "不支持", Toast.LENGTH_SHORT).show();
175   - break;
176   - case New_IDPOS:
177   - try {
178   - handlePosPrint();
179   - } catch (Exception e) {
180   - e.printStackTrace();
181   - }
182   - break;
183   - case New_HANDSET_POS:
184   - try {
185   - handlePosPrint();
186   - } catch (Exception e) {
187   - e.printStackTrace();
188   - }
189   - break;
190   - case BASEWIN_REB_POS:
191   - try {
192   - basewinPosPrint();
193   - } catch (Exception e) {
194   - e.printStackTrace();
195   - }
196   -
197   - break;
198   - default:
199   - break;
200   - }
201   - }
202   - }
203   -
204   - /************************ 关闭打印 *******************************************/
205   - public void printClose() {
206   - if (type != null) {
207   - switch (type) {
208   - case ID_POS:
209   - break;
210   - case GENERAL_POS:
211   - break;
212   - case SMALL_POS:
213   - break;
214   - case HANDSET:
215   - break;
216   - case MOBILE:
217   - break;
218   - case New_POS:
219   - try {
220   - if(serialNewPortTool!=null){
221   - serialNewPortTool.close();
222   - }
223   - } catch (Exception e1) {
224   - e1.printStackTrace();
225   - }
226   - break;
227   - case New_IDPOS:
228   - break;
229   - case New_HANDSET_POS:
230   - try {
231   - if(serialNewHandlePortTool!=null){
232   - serialNewHandlePortTool.close();
233   - }
234   - } catch (Exception e) {
235   - e.printStackTrace();
236   - }
237   - break;
238   - case BASEWIN_REB_POS:
239   - try {
240   - if(basewinRebPosPortTool!=null){
241   - basewinRebPosPortTool.close();
242   - }
243   - } catch (Exception e) {
244   - e.printStackTrace();
245   - }
246   - break;
247   -
248   - default:
249   - break;
250   - }
251   - }
252   - }
253   -
254   - /***************************** 普通pos机 ***********************************/
255   - SerialPortTool portTool;
256   - private void generalPrint() {
257   - portTool = new SerialPortTool();
258   - portTool.init(context, printInfo);
259   - }
260   -
261   - /******************************** 带身份证打印 ****************************************************/
262   - SerialIDPortTool idPortTool;
263   -
264   - private void idPosPrint() {
265   - idPortTool = new SerialIDPortTool();
266   - idPortTool.init(context, printInfo);
267   - }
268   -
269   - /******************************* 小pos机(手持pos机) ****************************************/
270   - SerialSmallPortTool smallPortTool;
271   -
272   - private void smallPosprint() {
273   - smallPortTool = new SerialSmallPortTool();
274   - smallPortTool.init(context, printInfo);
275   - }
276   -
277   - /********************************* 手机 ***************************************************/
278   - private void mobilePrint() {
279   - Intent intent = new Intent(context, MobilePrintTool.class);
280   - intent.putExtra("info", printInfo);
281   - context.startActivity(intent);
282   - }
283   -
284   - /********************************* 手持机 ******************************************************/
285   - private void handlePrint() {
286   - Intent intent = new Intent(context, MobilePrintTool.class);
287   - intent.putExtra("info", printInfo);
288   - context.startActivity(intent);
289   - }
290   -
291   - /******************************** 新版pos机 ***************************************************/
292   - SerialNewPortTool serialNewPortTool;
293   - private void newPosPrint() {
294   - serialNewPortTool = new SerialNewPortTool();
295   - serialNewPortTool.init(context, printInfo);
296   - }
297   -
298   - /********************************* 新版手持pos机 ***********************************************/
299   - SerialNewHandlePortTool serialNewHandlePortTool;
300   - private void handlePosPrint() {
301   - serialNewHandlePortTool = new SerialNewHandlePortTool();
302   - serialNewHandlePortTool.init(context, printInfo);
303   - }
304   - /********************************* 盛本红色pos机 ***********************************************/
305   - BasewinRebPosPortTool basewinRebPosPortTool;
306   - private void basewinPosPrint(){
307   - basewinRebPosPortTool = new BasewinRebPosPortTool();
308   - basewinRebPosPortTool.init(context, printInfo);
309   - }
  197 + break;
  198 + case New_IDPOS:
  199 + try {
  200 + handlePosPrint();
  201 + } catch (Exception e) {
  202 + e.printStackTrace();
  203 + }
  204 + break;
  205 + case New_HANDSET_POS:
  206 + try {
  207 + handlePosPrint();
  208 + } catch (Exception e) {
  209 + e.printStackTrace();
  210 + }
  211 + break;
  212 + case BASEWIN_REB_POS:
  213 + try {
  214 + basewinPosPrint();
  215 + } catch (Exception e) {
  216 + e.printStackTrace();
  217 + }
  218 +
  219 + break;
  220 + case SHANGMI_POS:
  221 + printSm();
  222 + break;
  223 + default:
  224 + break;
  225 + }
  226 + }
  227 + }
  228 +
  229 + /************************ 关闭打印 *******************************************/
  230 + public void printClose() {
  231 + if (type != null) {
  232 + switch (type) {
  233 + case ID_POS:
  234 + break;
  235 + case GENERAL_POS:
  236 + break;
  237 + case SMALL_POS:
  238 + break;
  239 + case HANDSET:
  240 + break;
  241 + case MOBILE:
  242 + break;
  243 + case New_POS:
  244 + try {
  245 + if (serialNewPortTool != null) {
  246 + serialNewPortTool.close();
  247 + }
  248 + } catch (Exception e1) {
  249 + e1.printStackTrace();
  250 + }
  251 + break;
  252 + case New_IDPOS:
  253 + break;
  254 + case New_HANDSET_POS:
  255 + try {
  256 + if (serialNewHandlePortTool != null) {
  257 + serialNewHandlePortTool.close();
  258 + }
  259 + } catch (Exception e) {
  260 + e.printStackTrace();
  261 + }
  262 + break;
  263 + case BASEWIN_REB_POS:
  264 + try {
  265 + if (basewinRebPosPortTool != null) {
  266 + basewinRebPosPortTool.close();
  267 + }
  268 + } catch (Exception e) {
  269 + e.printStackTrace();
  270 + }
  271 + break;
  272 +
  273 + default:
  274 + break;
  275 + }
  276 + }
  277 + }
  278 +
  279 + /***************************** 普通pos机 ***********************************/
  280 + SerialPortTool portTool;
  281 +
  282 + private void generalPrint() {
  283 + portTool = new SerialPortTool();
  284 + portTool.init(context, printInfo);
  285 + }
  286 +
  287 + /******************************** 带身份证打印 ****************************************************/
  288 + SerialIDPortTool idPortTool;
  289 +
  290 + private void idPosPrint() {
  291 + idPortTool = new SerialIDPortTool();
  292 + idPortTool.init(context, printInfo);
  293 + }
  294 +
  295 + /******************************* 小pos机(手持pos机) ****************************************/
  296 + SerialSmallPortTool smallPortTool;
  297 +
  298 + private void smallPosprint() {
  299 + smallPortTool = new SerialSmallPortTool();
  300 + smallPortTool.init(context, printInfo);
  301 + }
  302 +
  303 + /********************************* 手机 ***************************************************/
  304 + private void mobilePrint() {
  305 + Intent intent = new Intent(context, MobilePrintTool.class);
  306 + intent.putExtra("info", printInfo);
  307 + context.startActivity(intent);
  308 + }
  309 +
  310 + /********************************* 手持机 ******************************************************/
  311 + private void handlePrint() {
  312 + Intent intent = new Intent(context, MobilePrintTool.class);
  313 + intent.putExtra("info", printInfo);
  314 + context.startActivity(intent);
  315 + }
  316 +
  317 + /******************************** 新版pos机 ***************************************************/
  318 + SerialNewPortTool serialNewPortTool;
  319 +
  320 + private void newPosPrint() {
  321 + serialNewPortTool = new SerialNewPortTool();
  322 + serialNewPortTool.init(context, printInfo);
  323 + }
  324 +
  325 + /********************************* 新版手持pos机 ***********************************************/
  326 + SerialNewHandlePortTool serialNewHandlePortTool;
  327 +
  328 + private void handlePosPrint() {
  329 + serialNewHandlePortTool = new SerialNewHandlePortTool();
  330 + serialNewHandlePortTool.init(context, printInfo);
  331 + }
  332 +
  333 + /********************************* 盛本红色pos机 ***********************************************/
  334 + BasewinRebPosPortTool basewinRebPosPortTool;
  335 +
  336 + private void basewinPosPrint() {
  337 + basewinRebPosPortTool = new BasewinRebPosPortTool();
  338 + basewinRebPosPortTool.init(context, printInfo);
  339 + }
  340 + /********************************* 商米pos机 ***********************************************/
  341 + private void printSm() {
  342 + try {
  343 + LineApi api = MainActivity.selectPrinter.lineApi();
  344 + //需要监听打印结果时可以开启事务模式,只需要调用一次
  345 + api.enableTransMode(true);
  346 + printSmallTicket();
  347 + api.enableTransMode(false);
  348 + } catch (SdkException e) {
  349 + e.printStackTrace();
  350 + }
  351 + }
  352 +
  353 + private void printSmallTicket() {
  354 + int printNum = MyApp.getInstance().getPrintNum();
  355 + try {
  356 + LogUtil.d(TAG, "商米打印 = " + printInfo);
  357 + LineApi api = null;
  358 + for (int k = 0; k < printNum; k++) {
  359 + api = MainActivity.selectPrinter.lineApi();
  360 + api.initLine(BaseStyle.getStyle().setAlign(Align.CENTER));
  361 + if (isStatistic != null && isStatistic.equals("1")) {
  362 + api.printText("统计信息", TextStyle.getStyle().enableBold(true));
  363 + } else {
  364 + if (Select == 2) {
  365 + api.printText("订单信息(重打小票)", TextStyle.getStyle().enableBold(true));
  366 + } else {
  367 + api.printText("订单信息", TextStyle.getStyle().enableBold(true));
  368 + }
  369 + }
  370 + api.initLine(BaseStyle.getStyle().setAlign(Align.LEFT));
  371 +
  372 + if (isStatistic != null && isStatistic.equals("1")) {
  373 +
  374 + } else {
  375 + if (Select == SelectAction.Query.getValue()) { //打印时间
  376 + SimpleDateFormat df = new SimpleDateFormat(
  377 + "yyyy-MM-dd HH:mm:ss");// 设置日期格式
  378 + api.printText("检票时间:" + df.format(new Date()), TextStyle.getStyle());
  379 + } else if (Select == SelectAction.Reprint.getValue()) {// 重打时间
  380 + SimpleDateFormat df = new SimpleDateFormat(
  381 + "yyyy-MM-dd HH:mm:ss");// 设置日期格式
  382 + api.printText("重打时间:" + df.format(new Date()), TextStyle.getStyle());
  383 + }
  384 + }
  385 + api.printText(printInfo, TextStyle.getStyle());
  386 + api.printDividingLine(DividingLine.EMPTY, 30);
  387 + api.printText("取票人签名:" , TextStyle.getStyle());
  388 + api.printDividingLine(DividingLine.EMPTY, 30);
  389 + if (constant.logoMark == LogoType.CYT.getValue()) {
  390 + api.printText("----畅游通—智慧旅游O2O平台----", TextStyle.getStyle());
  391 + api.printText("--------www.jingqu.cn---------", TextStyle.getStyle());
  392 + }else if (constant.logoMark == LogoType.QNE.getValue()) {
  393 + api.printText("----欢迎使用去哪儿网O2O系统----", TextStyle.getStyle());
  394 + api.printText("--------www.qunar.com---------", TextStyle.getStyle());
  395 + }
  396 + api.autoOut();
  397 + api.printTrans(new PrintResult() {
  398 + @Override
  399 + public void onResult(int resultCode, String message) {
  400 + if (resultCode == 0) {
  401 + //打印成功
  402 + LogUtil.d(TAG, "打印成功");
  403 + } else {
  404 + //打印失败
  405 + LogUtil.d(TAG, "打印失败");
  406 + }
  407 + }
  408 + });
  409 + }
  410 + } catch (SdkException e) {
  411 + e.printStackTrace();
  412 + }
  413 + }
310 414 }
... ...
src/com/ectrip/cyt/constant/CheckTicketConstant.java
... ... @@ -6,7 +6,7 @@ package com.ectrip.cyt.constant;
6 6 public class CheckTicketConstant {
7 7  
8 8 public static String IP;
9   - public static final String httphead = "http://";
  9 + public static final String httphead = "https://";
10 10 public static final String action = "/checkTicket/excuteCheckTicket.action";
11 11 public static final String MD5KEY = "029124EDC5E180631627E3AE44108724";
12 12 public static final String CHECKTICKET = "C001"; //检票
... ...
src/com/ectrip/cyt/constant/DeviceType.java
... ... @@ -17,7 +17,8 @@ public enum DeviceType {
17 17 //BLACK_ID_POS:5501H手持机
18 18 //ID_CARD_POS_RSK:RSK手持机
19 19 ID_POS(5),GENERAL_POS(6),SMALL_POS(7),HANDSET(8),MOBILE(9),New_POS(10),
20   - New_IDPOS(11),New_HANDSET_POS(12),BASEWIN_REB_POS(13),BLACK_ID_POS(14),ID_CARD_POS_RSK(15);
  20 + New_IDPOS(11),New_HANDSET_POS(12),BASEWIN_REB_POS(13),BLACK_ID_POS(14),ID_CARD_POS_RSK(15)
  21 + ,SHANGMI_POS(16);
21 22 private int value;
22 23  
23 24 private DeviceType(int value) {
... ...
src/com/ectrip/cyt/request/ConsumeCodeRequest.java 0 → 100644
  1 +package com.ectrip.cyt.request;
  2 +
  3 +import java.util.List;
  4 +
  5 +public class ConsumeCodeRequest {
  6 + public String ver;// 版本号
  7 + public String verType; //版本类型
  8 + public String devId;// 移动终端ID
  9 + public String devType;// 终端类型
  10 + public Long accountId;
  11 + public String orderId;
  12 + public String count;
  13 + public String password;
  14 + public String verifyPassword;
  15 + public String consumedSeq;
  16 + public List<ProductOfConsumeOrder> products;
  17 +
  18 + public ConsumeCodeRequest(String orderId, String count, String password, String verifyPassword, String consumedSeq, List<ProductOfConsumeOrder> products) {
  19 + super();
  20 + this.orderId = orderId;
  21 + this.count = count;
  22 + this.password = password;
  23 + this.verifyPassword = verifyPassword;
  24 + this.consumedSeq = consumedSeq;
  25 + this.products = products;
  26 + }
  27 +
  28 + public String getOrderId() {
  29 + return orderId;
  30 + }
  31 +
  32 + public void setOrderId(String orderId) {
  33 + this.orderId = orderId;
  34 + }
  35 +
  36 + public String getCount() {
  37 + return count;
  38 + }
  39 +
  40 + public void setCount(String count) {
  41 + this.count = count;
  42 + }
  43 +
  44 + public String getPassword() {
  45 + return password;
  46 + }
  47 +
  48 + public void setPassword(String password) {
  49 + this.password = password;
  50 + }
  51 +
  52 + public String getVerifyPassword() {
  53 + return verifyPassword;
  54 + }
  55 +
  56 + public void setVerifyPassword(String verifyPassword) {
  57 + this.verifyPassword = verifyPassword;
  58 + }
  59 +
  60 + public String getConsumedSeq() {
  61 + return consumedSeq;
  62 + }
  63 +
  64 + public void setConsumedSeq(String consumedSeq) {
  65 + this.consumedSeq = consumedSeq;
  66 + }
  67 +
  68 + public List<ProductOfConsumeOrder> getProducts() {
  69 + return products;
  70 + }
  71 +
  72 + public void setProducts(List<ProductOfConsumeOrder> products) {
  73 + this.products = products;
  74 + }
  75 +
  76 + public String getVer() {
  77 + return ver;
  78 + }
  79 +
  80 + public void setVer(String ver) {
  81 + this.ver = ver;
  82 + }
  83 +
  84 + public String getVerType() {
  85 + return verType;
  86 + }
  87 +
  88 + public void setVerType(String verType) {
  89 + this.verType = verType;
  90 + }
  91 +
  92 + public String getDevId() {
  93 + return devId;
  94 + }
  95 +
  96 + public void setDevId(String devId) {
  97 + this.devId = devId;
  98 + }
  99 +
  100 + public String getDevType() {
  101 + return devType;
  102 + }
  103 +
  104 + public void setDevType(String devType) {
  105 + this.devType = devType;
  106 + }
  107 +
  108 + public Long getAccountId() {
  109 + return accountId;
  110 + }
  111 +
  112 + public void setAccountId(Long accountId) {
  113 + this.accountId = accountId;
  114 + }
  115 +}
... ...
src/com/ectrip/cyt/ui/MainActivity.java
... ... @@ -65,11 +65,14 @@ import com.ectrip.cyt.utils.SharedPreferences2Obj;
65 65 import com.ectrip.trips.check.R;
66 66 import com.ectrip.trips.net.HttpHelper;
67 67 import com.fri.idcread.idcread;
  68 +import com.sunmi.printerx.PrinterSdk;
  69 +import com.sunmi.printerx.SdkException;
68 70  
69 71 import java.io.File;
70 72 import java.io.InputStream;
71 73 import java.lang.reflect.Method;
72 74 import java.util.ArrayList;
  75 +import java.util.List;
73 76  
74 77 import hdx.HdxUtil;
75 78  
... ... @@ -87,6 +90,8 @@ public class MainActivity extends BaseActivity implements OnItemClickListener, V
87 90 private TextView unlogin;
88 91 private TextView tv_username;
89 92 private final Handler mHandler = new Handler();
  93 + public static PrinterSdk.Printer selectPrinter;
  94 +
90 95 @Override
91 96 protected void onCreate(Bundle savedInstanceState) {
92 97 super.onCreate(savedInstanceState);
... ... @@ -97,6 +102,12 @@ public class MainActivity extends BaseActivity implements OnItemClickListener, V
97 102 initView();
98 103 regularDelecte();
99 104 typeJudgment();
  105 + if (TextUtils.equals("V1", android.os.Build.MODEL)
  106 + || TextUtils.equals("V2", android.os.Build.MODEL)
  107 + || TextUtils.equals("P1_4G", android.os.Build.MODEL)
  108 + || TextUtils.equals("V2s", android.os.Build.MODEL)) {
  109 + initPrinter();
  110 + }
100 111 LogUtil.e(TAG, "硬件序列号 : " + getSerialNumber() + ",型号 :" + Build.MODEL);
101 112 mHandler.postDelayed(new Runnable() {
102 113 @Override
... ... @@ -136,6 +147,26 @@ public class MainActivity extends BaseActivity implements OnItemClickListener, V
136 147 startService(upLoad);
137 148 }
138 149  
  150 + /**
  151 + * 初始化默认打印机作为待操作的打印设备
  152 + */
  153 + private void initPrinter() {
  154 + try {
  155 + PrinterSdk.getInstance().getPrinter(this, new PrinterSdk.PrinterListen() {
  156 + @Override
  157 + public void onDefPrinter(PrinterSdk.Printer printer) {
  158 + selectPrinter = printer;
  159 + }
  160 +
  161 + @Override
  162 + public void onPrinters(List<PrinterSdk.Printer> printers) {
  163 +
  164 + }
  165 + });
  166 + } catch (SdkException e) {
  167 + e.printStackTrace();
  168 + }
  169 + }
139 170  
140 171 /**
141 172 * 获取硬件的序列号
... ... @@ -162,7 +193,7 @@ public class MainActivity extends BaseActivity implements OnItemClickListener, V
162 193 // 得到存储的类型
163 194 Integer type = SharedPreferences2Obj.getInstance(MainActivity.this)
164 195 .setName("MachineType").getObject("type", Integer.class);
165   -
  196 + LogUtil.d(TAG, "type = " + type);
166 197 //如果未存储类型
167 198 if (type == null || type == 0) {
168 199 DisplayMetrics metrics = new DisplayMetrics();
... ... @@ -247,6 +278,14 @@ public class MainActivity extends BaseActivity implements OnItemClickListener, V
247 278 SharedPreferences2Obj.getInstance(MainActivity.this)
248 279 .setName("MachineType")
249 280 .setObject("type", DeviceType.BASEWIN_REB_POS.getValue());
  281 + } else if (TextUtils.equals("V1", android.os.Build.MODEL)
  282 + || TextUtils.equals("V2", android.os.Build.MODEL)
  283 + || TextUtils.equals("P1_4G", android.os.Build.MODEL)
  284 + || TextUtils.equals("V2s", android.os.Build.MODEL)) {
  285 + LogUtil.i(TAG, "商米:" + android.os.Build.MODEL);
  286 + SharedPreferences2Obj.getInstance(MainActivity.this)
  287 + .setName("MachineType")
  288 + .setObject("type", DeviceType.SHANGMI_POS.getValue());
250 289 }
251 290 //盛本pos机测试*******************************
252 291 else {
... ... @@ -916,4 +955,10 @@ public class MainActivity extends BaseActivity implements OnItemClickListener, V
916 955 });
917 956  
918 957 }
  958 +
  959 + @Override
  960 + protected void onDestroy() {
  961 + super.onDestroy();
  962 + PrinterSdk.getInstance().destroy();
  963 + }
919 964 }
... ...
src/com/ectrip/cyt/ui/PhomeScanerOrderActivity.java
... ... @@ -182,13 +182,13 @@ public class PhomeScanerOrderActivity extends BaseActivity implements Callback {
182 182 e.printStackTrace();
183 183 }
184 184 Intent intent;
185   - if (resultString.startsWith("OCP_")) {
186   - intent = new Intent(PhomeScanerOrderActivity.this,
187   - PhoneCodeListActivity.class);
188   - } else {
  185 +// if (resultString.startsWith("OCP_")) {
  186 +// intent = new Intent(PhomeScanerOrderActivity.this,
  187 +// PhoneCodeListActivity.class);
  188 +// } else {
189 189 intent = new Intent(PhomeScanerOrderActivity.this,
190 190 QRCodeOrderListActivity.class);
191   - }
  191 +// }
192 192 intent.putExtra("mode", 1);
193 193 intent.putExtra("input_orid", resultString);
194 194 LogUtil.i(TAG, getString(R.string.scan_result) + resultString);
... ...
src/com/ectrip/cyt/zxing/camera/CameraConfigurationManager.java
... ... @@ -30,288 +30,288 @@ import com.ectrip.cyt.constant.DeviceType;
30 30 import com.ectrip.cyt.utils.LogUtil;
31 31 import com.ectrip.cyt.utils.SharedPreferences2Obj;
32 32  
33   -@SuppressWarnings({"deprecation" })
  33 +@SuppressWarnings({"deprecation"})
34 34 final class CameraConfigurationManager {
35 35  
36   - private final String TAG = CameraConfigurationManager.class.getSimpleName();
37   -
38   - private final int TEN_DESIRED_ZOOM = 27;
39   - private final int DESIRED_SHARPNESS = 30;
40   -
41   - private final Pattern COMMA_PATTERN = Pattern.compile(",");
42   -
43   - private Point screenResolution;
44   - private Point cameraResolution;
45   - private int previewFormat;
46   - private String previewFormatString;
47   -
48   - /**
49   - * Reads, one time, values from the camera that are needed by the app.
50   - */
51   - void initFromCameraParameters(Camera camera, Context context) {
52   - Camera.Parameters parameters = camera.getParameters();
53   - previewFormat = parameters.getPreviewFormat();
54   - previewFormatString = parameters.get("preview-format");
55   - LogUtil.d(TAG, "Default preview format: " + previewFormat + '/'
56   - + previewFormatString);
57   - WindowManager manager = (WindowManager) context
58   - .getSystemService(Context.WINDOW_SERVICE);
59   - Display display = manager.getDefaultDisplay();
60   - screenResolution = new Point(display.getWidth(), display.getHeight());
61   - LogUtil.d(TAG, "Screen resolution: " + screenResolution);
62   - cameraResolution = getCameraResolution(parameters, screenResolution);
63   - LogUtil.d(TAG, "Camera resolution: " + screenResolution);
64   - }
65   -
66   - /**
67   - * Sets the camera up to take preview images which are used for both preview
68   - * and decoding. We detect the preview format here so that
69   - * buildLuminanceSource() can build an appropriate LuminanceSource subclass.
70   - * In the future we may want to force YUV420SP as it's the smallest, and the
71   - * planar Y can be used for barcode scanning without a copy in some cases.
72   - */
73   - void setDesiredCameraParameters(Camera camera, Context context) {
74   - Camera.Parameters parameters = camera.getParameters();
75   - LogUtil.d(TAG, "Setting preview size: " + cameraResolution);
76   - parameters.setPreviewSize(cameraResolution.x, cameraResolution.y);
77   - setFlash(parameters);
78   - setZoom(parameters);
79   - // setSharpness(parameters);
80   - // modify here
81   -
82   - // camera.setDisplayOrientation(90);
83   - // 兼容2.1
84   - Integer type = SharedPreferences2Obj.getInstance(context)
85   - .setName("MachineType").getObject("type", Integer.class);
86   - if (type == DeviceType.HANDSET.getValue()
87   - || type == DeviceType.MOBILE.getValue()||type == DeviceType.BASEWIN_REB_POS.getValue()||type == DeviceType.ID_CARD_POS_RSK.getValue()) {
88   - setDisplayOrientation(camera, 90);
89   - }
90   - camera.setParameters(parameters);
91   - }
92   -
93   - Point getCameraResolution() {
94   - return cameraResolution;
95   - }
96   -
97   - Point getScreenResolution() {
98   - return screenResolution;
99   - }
100   -
101   - int getPreviewFormat() {
102   - return previewFormat;
103   - }
104   -
105   - String getPreviewFormatString() {
106   - return previewFormatString;
107   - }
108   -
109   - private Point getCameraResolution(Camera.Parameters parameters,
110   - Point screenResolution) {
111   -
112   - String previewSizeValueString = parameters.get("preview-size-values");
113   - // saw this on Xperia
114   - if (previewSizeValueString == null) {
115   - previewSizeValueString = parameters.get("preview-size-value");
116   - }
117   -
118   - Point cameraResolution = null;
119   -
120   - if (previewSizeValueString != null) {
121   - LogUtil.d(TAG, "preview-size-values parameter: "
122   - + previewSizeValueString);
123   - cameraResolution = findBestPreviewSizeValue(previewSizeValueString,
124   - screenResolution);
125   - }
126   -
127   - if (cameraResolution == null) {
128   - // Ensure that the camera resolution is a multiple of 8, as the
129   - // screen may not be.
130   - cameraResolution = new Point((screenResolution.x >> 3) << 3,
131   - (screenResolution.y >> 3) << 3);
132   - }
133   - return cameraResolution;
134   - }
135   -
136   - private Point findBestPreviewSizeValue(CharSequence previewSizeValueString,
137   - Point screenResolution) {
138   - int bestX = 0;
139   - int bestY = 0;
140   - int diff = Integer.MAX_VALUE;
141   - for (String previewSize : COMMA_PATTERN.split(previewSizeValueString)) {
142   -
143   - previewSize = previewSize.trim();
144   - int dimPosition = previewSize.indexOf('x');
145   - if (dimPosition < 0) {
146   - LogUtil.w(TAG, "Bad preview-size: " + previewSize);
147   - continue;
148   - }
149   -
150   - int newX;
151   - int newY;
152   - try {
153   - newX = Integer.parseInt(previewSize.substring(0, dimPosition));
154   - newY = Integer.parseInt(previewSize.substring(dimPosition + 1));
155   - } catch (NumberFormatException nfe) {
156   - LogUtil.w(TAG, "Bad preview-size: " + previewSize);
157   - continue;
158   - }
159   -
160   - int newDiff = Math.abs(newX - screenResolution.x)
161   - + Math.abs(newY - screenResolution.y);
162   - if (newDiff == 0) {
163   - bestX = newX;
164   - bestY = newY;
165   - break;
166   - } else if (newDiff < diff) {
167   - bestX = newX;
168   - bestY = newY;
169   - diff = newDiff;
170   - }
171   -
172   - }
173   -
174   - if (bestX > 0 && bestY > 0) {
175   - return new Point(bestX, bestY);
176   - }
177   - return null;
178   - }
179   -
180   - private int findBestMotZoomValue(CharSequence stringValues,
181   - int tenDesiredZoom) {
182   - int tenBestValue = 0;
183   - for (String stringValue : COMMA_PATTERN.split(stringValues)) {
184   - stringValue = stringValue.trim();
185   - double value;
186   - try {
187   - value = Double.parseDouble(stringValue);
188   - } catch (NumberFormatException nfe) {
189   - return tenDesiredZoom;
190   - }
191   - int tenValue = (int) (10.0 * value);
192   - if (Math.abs(tenDesiredZoom - value) < Math.abs(tenDesiredZoom
193   - - tenBestValue)) {
194   - tenBestValue = tenValue;
195   - }
196   - }
197   - return tenBestValue;
198   - }
199   -
200   - /**
201   - * @param parameters
202   - * FIXME: This is a hack to turn the flash off on the Samsung
203   - * Galaxy. And this is a hack-hack to work around a different
204   - * value on the Behold II Restrict Behold II check to Cupcake,
205   - * per Samsung's advice if (Build.MODEL.contains("Behold II") &&
206   - * CameraManager.SDK_INT == Build.VERSION_CODES.CUPCAKE) {
207   - */
208   - private void setFlash(Camera.Parameters parameters) {
209   - int sdkInt;
210   - try {
211   - sdkInt = Integer.parseInt(Build.VERSION.SDK);
212   - } catch (NumberFormatException nfe) {
213   - // Just to be safe
214   - sdkInt = 10000;
215   - }
216   - if (Build.MODEL.contains("Behold II") && sdkInt== 3) { // 3
217   - parameters.set("flash-value", 1);
218   - } else {
219   - parameters.set("flash-value", 2);
220   - }
221   - // This is the standard setting to turn the flash off that all devices
222   - // should honor.
223   - parameters.set("flash-mode", "off");
224   - }
225   -
226   - private void setZoom(Camera.Parameters parameters) {
227   -
228   - String zoomSupportedString = parameters.get("zoom-supported");
229   - if (zoomSupportedString != null
230   - && !Boolean.parseBoolean(zoomSupportedString)) {
231   - return;
232   - }
233   -
234   - int tenDesiredZoom = TEN_DESIRED_ZOOM;
235   -
236   - String maxZoomString = parameters.get("max-zoom");
237   - if (maxZoomString != null) {
238   - try {
239   - int tenMaxZoom = (int) (10.0 * Double
240   - .parseDouble(maxZoomString));
241   - if (tenDesiredZoom > tenMaxZoom) {
242   - tenDesiredZoom = tenMaxZoom;
243   - }
244   - } catch (NumberFormatException nfe) {
245   - LogUtil.w(TAG, "Bad max-zoom: " + maxZoomString);
246   - }
247   - }
248   -
249   - String takingPictureZoomMaxString = parameters
250   - .get("taking-picture-zoom-max");
251   - if (takingPictureZoomMaxString != null) {
252   - try {
253   - int tenMaxZoom = Integer.parseInt(takingPictureZoomMaxString);
254   - if (tenDesiredZoom > tenMaxZoom) {
255   - tenDesiredZoom = tenMaxZoom;
256   - }
257   - } catch (NumberFormatException nfe) {
258   - LogUtil.w(TAG, "Bad taking-picture-zoom-max: "
259   - + takingPictureZoomMaxString);
260   - }
261   - }
262   -
263   - String motZoomValuesString = parameters.get("mot-zoom-values");
264   - if (motZoomValuesString != null) {
265   - tenDesiredZoom = findBestMotZoomValue(motZoomValuesString,
266   - tenDesiredZoom);
267   - }
268   -
269   - String motZoomStepString = parameters.get("mot-zoom-step");
270   - if (motZoomStepString != null) {
271   - try {
272   - double motZoomStep = Double.parseDouble(motZoomStepString
273   - .trim());
274   - int tenZoomStep = (int) (10.0 * motZoomStep);
275   - if (tenZoomStep > 1) {
276   - tenDesiredZoom -= tenDesiredZoom % tenZoomStep;
277   - }
278   - } catch (NumberFormatException nfe) {
279   - // continue
280   - }
281   - }
282   -
283   - // Set zoom. This helps encourage the user to pull back.
284   - // Some devices like the Behold have a zoom parameter
285   - if (maxZoomString != null || motZoomValuesString != null) {
286   - parameters.set("zoom", String.valueOf(tenDesiredZoom / 10.0));
287   - }
288   -
289   - // Most devices, like the Hero, appear to expose this zoom parameter.
290   - // It takes on values like "27" which appears to mean 2.7x zoom
291   - if (takingPictureZoomMaxString != null) {
292   - parameters.set("taking-picture-zoom", tenDesiredZoom);
293   - }
294   - }
295   -
296   - public int getDesiredSharpness() {
297   - return DESIRED_SHARPNESS;
298   - }
299   -
300   - /**
301   - * compatible 1.6
302   - *
303   - * @param camera
304   - * @param angle
305   - */
306   - protected void setDisplayOrientation(Camera camera, int angle) {
307   - Method downPolymorphic;
308   - try {
309   - downPolymorphic = camera.getClass().getMethod(
310   - "setDisplayOrientation", new Class[] { int.class });
311   - if (downPolymorphic != null)
312   - downPolymorphic.invoke(camera, new Object[] { angle });
313   - } catch (Exception e1) {
314   - }
315   - }
  36 + private final String TAG = CameraConfigurationManager.class.getSimpleName();
  37 +
  38 + private final int TEN_DESIRED_ZOOM = 27;
  39 + private final int DESIRED_SHARPNESS = 30;
  40 +
  41 + private final Pattern COMMA_PATTERN = Pattern.compile(",");
  42 +
  43 + private Point screenResolution;
  44 + private Point cameraResolution;
  45 + private int previewFormat;
  46 + private String previewFormatString;
  47 +
  48 + /**
  49 + * Reads, one time, values from the camera that are needed by the app.
  50 + */
  51 + void initFromCameraParameters(Camera camera, Context context) {
  52 + Camera.Parameters parameters = camera.getParameters();
  53 + previewFormat = parameters.getPreviewFormat();
  54 + previewFormatString = parameters.get("preview-format");
  55 + LogUtil.d(TAG, "Default preview format: " + previewFormat + '/'
  56 + + previewFormatString);
  57 + WindowManager manager = (WindowManager) context
  58 + .getSystemService(Context.WINDOW_SERVICE);
  59 + Display display = manager.getDefaultDisplay();
  60 + screenResolution = new Point(display.getWidth(), display.getHeight());
  61 + LogUtil.d(TAG, "Screen resolution: " + screenResolution);
  62 + cameraResolution = getCameraResolution(parameters, screenResolution);
  63 + LogUtil.d(TAG, "Camera resolution: " + screenResolution);
  64 + }
  65 +
  66 + /**
  67 + * Sets the camera up to take preview images which are used for both preview
  68 + * and decoding. We detect the preview format here so that
  69 + * buildLuminanceSource() can build an appropriate LuminanceSource subclass.
  70 + * In the future we may want to force YUV420SP as it's the smallest, and the
  71 + * planar Y can be used for barcode scanning without a copy in some cases.
  72 + */
  73 + void setDesiredCameraParameters(Camera camera, Context context) {
  74 + Camera.Parameters parameters = camera.getParameters();
  75 + LogUtil.d(TAG, "Setting preview size: " + cameraResolution);
  76 + parameters.setPreviewSize(cameraResolution.x, cameraResolution.y);
  77 + setFlash(parameters);
  78 + setZoom(parameters);
  79 + // setSharpness(parameters);
  80 + // modify here
  81 +
  82 + // camera.setDisplayOrientation(90);
  83 + // 兼容2.1
  84 + Integer type = SharedPreferences2Obj.getInstance(context)
  85 + .setName("MachineType").getObject("type", Integer.class);
  86 + if (type == DeviceType.HANDSET.getValue()
  87 + || type == DeviceType.MOBILE.getValue() || type == DeviceType.BASEWIN_REB_POS.getValue() || type == DeviceType.ID_CARD_POS_RSK.getValue()
  88 + || type == DeviceType.SHANGMI_POS.getValue()) {
  89 + setDisplayOrientation(camera, 90);
  90 + }
  91 + camera.setParameters(parameters);
  92 + }
  93 +
  94 + Point getCameraResolution() {
  95 + return cameraResolution;
  96 + }
  97 +
  98 + Point getScreenResolution() {
  99 + return screenResolution;
  100 + }
  101 +
  102 + int getPreviewFormat() {
  103 + return previewFormat;
  104 + }
  105 +
  106 + String getPreviewFormatString() {
  107 + return previewFormatString;
  108 + }
  109 +
  110 + private Point getCameraResolution(Camera.Parameters parameters,
  111 + Point screenResolution) {
  112 +
  113 + String previewSizeValueString = parameters.get("preview-size-values");
  114 + // saw this on Xperia
  115 + if (previewSizeValueString == null) {
  116 + previewSizeValueString = parameters.get("preview-size-value");
  117 + }
  118 +
  119 + Point cameraResolution = null;
  120 +
  121 + if (previewSizeValueString != null) {
  122 + LogUtil.d(TAG, "preview-size-values parameter: "
  123 + + previewSizeValueString);
  124 + cameraResolution = findBestPreviewSizeValue(previewSizeValueString,
  125 + screenResolution);
  126 + }
  127 +
  128 + if (cameraResolution == null) {
  129 + // Ensure that the camera resolution is a multiple of 8, as the
  130 + // screen may not be.
  131 + cameraResolution = new Point((screenResolution.x >> 3) << 3,
  132 + (screenResolution.y >> 3) << 3);
  133 + }
  134 + return cameraResolution;
  135 + }
  136 +
  137 + private Point findBestPreviewSizeValue(CharSequence previewSizeValueString,
  138 + Point screenResolution) {
  139 + int bestX = 0;
  140 + int bestY = 0;
  141 + int diff = Integer.MAX_VALUE;
  142 + for (String previewSize : COMMA_PATTERN.split(previewSizeValueString)) {
  143 +
  144 + previewSize = previewSize.trim();
  145 + int dimPosition = previewSize.indexOf('x');
  146 + if (dimPosition < 0) {
  147 + LogUtil.w(TAG, "Bad preview-size: " + previewSize);
  148 + continue;
  149 + }
  150 +
  151 + int newX;
  152 + int newY;
  153 + try {
  154 + newX = Integer.parseInt(previewSize.substring(0, dimPosition));
  155 + newY = Integer.parseInt(previewSize.substring(dimPosition + 1));
  156 + } catch (NumberFormatException nfe) {
  157 + LogUtil.w(TAG, "Bad preview-size: " + previewSize);
  158 + continue;
  159 + }
  160 +
  161 + int newDiff = Math.abs(newX - screenResolution.x)
  162 + + Math.abs(newY - screenResolution.y);
  163 + if (newDiff == 0) {
  164 + bestX = newX;
  165 + bestY = newY;
  166 + break;
  167 + } else if (newDiff < diff) {
  168 + bestX = newX;
  169 + bestY = newY;
  170 + diff = newDiff;
  171 + }
  172 +
  173 + }
  174 +
  175 + if (bestX > 0 && bestY > 0) {
  176 + return new Point(bestX, bestY);
  177 + }
  178 + return null;
  179 + }
  180 +
  181 + private int findBestMotZoomValue(CharSequence stringValues,
  182 + int tenDesiredZoom) {
  183 + int tenBestValue = 0;
  184 + for (String stringValue : COMMA_PATTERN.split(stringValues)) {
  185 + stringValue = stringValue.trim();
  186 + double value;
  187 + try {
  188 + value = Double.parseDouble(stringValue);
  189 + } catch (NumberFormatException nfe) {
  190 + return tenDesiredZoom;
  191 + }
  192 + int tenValue = (int) (10.0 * value);
  193 + if (Math.abs(tenDesiredZoom - value) < Math.abs(tenDesiredZoom
  194 + - tenBestValue)) {
  195 + tenBestValue = tenValue;
  196 + }
  197 + }
  198 + return tenBestValue;
  199 + }
  200 +
  201 + /**
  202 + * @param parameters FIXME: This is a hack to turn the flash off on the Samsung
  203 + * Galaxy. And this is a hack-hack to work around a different
  204 + * value on the Behold II Restrict Behold II check to Cupcake,
  205 + * per Samsung's advice if (Build.MODEL.contains("Behold II") &&
  206 + * CameraManager.SDK_INT == Build.VERSION_CODES.CUPCAKE) {
  207 + */
  208 + private void setFlash(Camera.Parameters parameters) {
  209 + int sdkInt;
  210 + try {
  211 + sdkInt = Integer.parseInt(Build.VERSION.SDK);
  212 + } catch (NumberFormatException nfe) {
  213 + // Just to be safe
  214 + sdkInt = 10000;
  215 + }
  216 + if (Build.MODEL.contains("Behold II") && sdkInt == 3) { // 3
  217 + parameters.set("flash-value", 1);
  218 + } else {
  219 + parameters.set("flash-value", 2);
  220 + }
  221 + // This is the standard setting to turn the flash off that all devices
  222 + // should honor.
  223 + parameters.set("flash-mode", "off");
  224 + }
  225 +
  226 + private void setZoom(Camera.Parameters parameters) {
  227 +
  228 + String zoomSupportedString = parameters.get("zoom-supported");
  229 + if (zoomSupportedString != null
  230 + && !Boolean.parseBoolean(zoomSupportedString)) {
  231 + return;
  232 + }
  233 +
  234 + int tenDesiredZoom = TEN_DESIRED_ZOOM;
  235 +
  236 + String maxZoomString = parameters.get("max-zoom");
  237 + if (maxZoomString != null) {
  238 + try {
  239 + int tenMaxZoom = (int) (10.0 * Double
  240 + .parseDouble(maxZoomString));
  241 + if (tenDesiredZoom > tenMaxZoom) {
  242 + tenDesiredZoom = tenMaxZoom;
  243 + }
  244 + } catch (NumberFormatException nfe) {
  245 + LogUtil.w(TAG, "Bad max-zoom: " + maxZoomString);
  246 + }
  247 + }
  248 +
  249 + String takingPictureZoomMaxString = parameters
  250 + .get("taking-picture-zoom-max");
  251 + if (takingPictureZoomMaxString != null) {
  252 + try {
  253 + int tenMaxZoom = Integer.parseInt(takingPictureZoomMaxString);
  254 + if (tenDesiredZoom > tenMaxZoom) {
  255 + tenDesiredZoom = tenMaxZoom;
  256 + }
  257 + } catch (NumberFormatException nfe) {
  258 + LogUtil.w(TAG, "Bad taking-picture-zoom-max: "
  259 + + takingPictureZoomMaxString);
  260 + }
  261 + }
  262 +
  263 + String motZoomValuesString = parameters.get("mot-zoom-values");
  264 + if (motZoomValuesString != null) {
  265 + tenDesiredZoom = findBestMotZoomValue(motZoomValuesString,
  266 + tenDesiredZoom);
  267 + }
  268 +
  269 + String motZoomStepString = parameters.get("mot-zoom-step");
  270 + if (motZoomStepString != null) {
  271 + try {
  272 + double motZoomStep = Double.parseDouble(motZoomStepString
  273 + .trim());
  274 + int tenZoomStep = (int) (10.0 * motZoomStep);
  275 + if (tenZoomStep > 1) {
  276 + tenDesiredZoom -= tenDesiredZoom % tenZoomStep;
  277 + }
  278 + } catch (NumberFormatException nfe) {
  279 + // continue
  280 + }
  281 + }
  282 +
  283 + // Set zoom. This helps encourage the user to pull back.
  284 + // Some devices like the Behold have a zoom parameter
  285 + if (maxZoomString != null || motZoomValuesString != null) {
  286 + parameters.set("zoom", String.valueOf(tenDesiredZoom / 10.0));
  287 + }
  288 +
  289 + // Most devices, like the Hero, appear to expose this zoom parameter.
  290 + // It takes on values like "27" which appears to mean 2.7x zoom
  291 + if (takingPictureZoomMaxString != null) {
  292 + parameters.set("taking-picture-zoom", tenDesiredZoom);
  293 + }
  294 + }
  295 +
  296 + public int getDesiredSharpness() {
  297 + return DESIRED_SHARPNESS;
  298 + }
  299 +
  300 + /**
  301 + * compatible 1.6
  302 + *
  303 + * @param camera
  304 + * @param angle
  305 + */
  306 + protected void setDisplayOrientation(Camera camera, int angle) {
  307 + Method downPolymorphic;
  308 + try {
  309 + downPolymorphic = camera.getClass().getMethod(
  310 + "setDisplayOrientation", new Class[]{int.class});
  311 + if (downPolymorphic != null)
  312 + downPolymorphic.invoke(camera, new Object[]{angle});
  313 + } catch (Exception e1) {
  314 + }
  315 + }
316 316  
317 317 }
... ...
src/com/ectrip/trips/net/HttpHelper.java
... ... @@ -13,6 +13,7 @@ import com.ectrip.cyt.bean.ConfigBean;
13 13 import com.ectrip.cyt.callback.HttpCallback;
14 14 import com.ectrip.cyt.config.DevicTool;
15 15 import com.ectrip.cyt.config.MyApp;
  16 +import com.ectrip.cyt.constant.CheckTicketConstant;
16 17 import com.ectrip.cyt.constant.LogoType;
17 18 import com.ectrip.cyt.constant.constant;
18 19 import com.ectrip.cyt.db.DbManager;
... ... @@ -92,9 +93,9 @@ public class HttpHelper extends HttpHelperCore {
92 93 map.put("requestParam", requestParam);
93 94 LogUtil.i(TAG, requestParam + "requestParam");
94 95 executeHttpPost(
95   - "https://" + MyApp.getInstance().getServiceIp() + action, "",
  96 + CheckTicketConstant.httphead + MyApp.getInstance().getServiceIp() + action, "",
96 97 map, httpCallback, "data", DataTrans.class);
97   - LogUtil.i(TAG, "url = " + "http://" + MyApp.getInstance().getServiceIp() + action);
  98 + LogUtil.i(TAG, "url = " + CheckTicketConstant.httphead + MyApp.getInstance().getServiceIp() + action);
98 99 if (testMOdel != null && testMOdel) { // 这个是调试弹框
99 100 if (type == null) {
100 101 return;
... ... @@ -133,9 +134,9 @@ public class HttpHelper extends HttpHelperCore {
133 134 .getInstance().getSignkey(), MyApp.getInstance().getIdentity());
134 135 map.put("requestParam", requestParam);
135 136 LogUtil.i(TAG, "requestParam" + requestParam);
136   - LogUtil.i(TAG, "url = " + "http://" + MyApp.getInstance().getServiceIp() + action);
  137 + LogUtil.i(TAG, "url = " + CheckTicketConstant.httphead + MyApp.getInstance().getServiceIp() + action);
137 138 executeHttpPost(
138   - "https://" + MyApp.getInstance().getServiceIp() + action, "",
  139 + CheckTicketConstant.httphead + MyApp.getInstance().getServiceIp() + action, "",
139 140 map, httpCallback, "data", DataTrans.class);
140 141  
141 142 if (testMOdel != null && testMOdel) { // 这个是调试弹框
... ... @@ -175,7 +176,7 @@ public class HttpHelper extends HttpHelperCore {
175 176 map.put("requestParam", requestParam);
176 177 LogUtil.i(TAG, "requestParam" + requestParam);
177 178 executeHttpPost(
178   - "https://" + MyApp.getInstance().getServiceIp() + action, "",
  179 + CheckTicketConstant.httphead + MyApp.getInstance().getServiceIp() + action, "",
179 180 map, httpCallback, "data", DataTrans.class);
180 181  
181 182 if (testMOdel != null && testMOdel) { // 这个是调试弹框
... ... @@ -211,7 +212,7 @@ public class HttpHelper extends HttpHelperCore {
211 212 LogUtil.i(TAG, "requestParam" + requestParam);
212 213 LogUtil.i(TAG, "服务器地址:" + MyApp.getInstance().getServiceIp());
213 214 executeHttpPost(
214   - "https://" + MyApp.getInstance().getServiceIp() + action, "",
  215 + CheckTicketConstant.httphead + MyApp.getInstance().getServiceIp() + action, "",
215 216 map, httpCallback, "data", DataTrans.class);
216 217  
217 218 if (testMOdel != null && testMOdel) { // 这个是调试弹框
... ... @@ -251,7 +252,7 @@ public class HttpHelper extends HttpHelperCore {
251 252 map.put("requestParam", requestParam);
252 253 LogUtil.i(TAG, "requestParam" + requestParam);
253 254 executeHttpPost(
254   - "https://" + MyApp.getInstance().getServiceIp() + action, "",
  255 + CheckTicketConstant.httphead + MyApp.getInstance().getServiceIp() + action, "",
255 256 map, httpCallback, "data", DataTrans.class);
256 257 if (testMOdel != null && testMOdel) { // 这个是调试弹框
257 258 if (type == null) {
... ... @@ -294,7 +295,7 @@ public class HttpHelper extends HttpHelperCore {
294 295 map.put("requestParam", requestParam);
295 296 LogUtil.i(TAG, "requestParam" + requestParam);
296 297 executeHttpPost(
297   - "https://" + MyApp.getInstance().getServiceIp() + action, "",
  298 + CheckTicketConstant.httphead + MyApp.getInstance().getServiceIp() + action, "",
298 299 map, httpCallback, "data", DataTrans.class);
299 300 if (testMOdel != null && testMOdel) { // 这个是调试弹框
300 301 if (type == null) {
... ... @@ -344,7 +345,7 @@ public class HttpHelper extends HttpHelperCore {
344 345 map.put("requestParam", requestParam);
345 346 LogUtil.i(TAG, "requestParam" + requestParam);
346 347 executeHttpPost(
347   - "https://" + MyApp.getInstance().getServiceIp() + action, "",
  348 + CheckTicketConstant.httphead + MyApp.getInstance().getServiceIp() + action, "",
348 349 map, httpCallback, "data", DataTrans.class);
349 350 if (testMOdel != null && testMOdel) { // 这个是调试弹框
350 351 if (type == null) {
... ... @@ -389,9 +390,9 @@ public class HttpHelper extends HttpHelperCore {
389 390 String requestParam = DataTool.envelopeData(detectVersionRequest,
390 391 signkey, identity);
391 392 map.put("requestParam", requestParam);
392   - LogUtil.i(TAG, "url = " + "https://" + url + action);
  393 + LogUtil.i(TAG, "url = " + CheckTicketConstant.httphead + url + action);
393 394 LogUtil.i(TAG, "requestParam" + requestParam);
394   - executeHttpPost("https://" + url + action, "", map, httpCallback,
  395 + executeHttpPost(CheckTicketConstant.httphead + url + action, "", map, httpCallback,
395 396 "data", DataTrans.class);
396 397 }
397 398  
... ... @@ -422,7 +423,7 @@ public class HttpHelper extends HttpHelperCore {
422 423 map.put("requestParam", requestParam);
423 424 LogUtil.i(TAG, "requestParam" + requestParam);
424 425 executeHttpPost(
425   - "https://" + MyApp.getInstance().getServiceIp() + action, "",
  426 + CheckTicketConstant.httphead + MyApp.getInstance().getServiceIp() + action, "",
426 427 map, httpCallback, "data", DataTrans.class);
427 428  
428 429  
... ...