左晓为主开发手持机充值管理机
zuoxiao
2023-12-08 beaf2b5257a455644ea26ed1878d3b623102f1d8
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
package com.kernal.passportreader.sdk.utils;
 
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.widget.Toast;
 
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
 
import kernal.idcard.android.RecogService;
import kernal.idcard.android.ResultMessage;
 
/**
 * Created by huangzhen on 2017/2/6.
 */
 
public class ActivityRecogUtils {
    /**
     *Invoking Activity recognition with animation effect
     * @param context Context
     * @param selectPath The path to recognize images.
     * @param nMainID Document type to be recognized.
     * @param cutBoolean To see if cropping is needed.
     */
    public static void getRecogResult(Context context, String selectPath, int nMainID, boolean cutBoolean) {
        try {
            RecogService.isRecogByPath = true;
            String logopath = "";
            // String logopath = getSDPath() + "/photo_logo.png";
            Intent intent = new Intent("kernal.idcard");
            Bundle bundle = new Bundle();
            int nSubID[] = null;// {0x0001};
            bundle.putBoolean("isGetRecogFieldPos", false);// To see if we get the location of recognized fields. If the default one is untrue, it means not getting.
            // It must be cropped in the images which have been clipped by core recognition engine.
            bundle.putString("cls", "checkauto.com.IdcardRunner");
            bundle.putInt("nTypeInitIDCard", 0); // To save, press “0”.
            bundle.putString("lpFileName", selectPath);//  Designated image path.
            bundle.putString("cutSavePath", "");// Storage path of cropping images.
            bundle.putInt("nTypeLoadImageToMemory", 0);// ”0” stands for unceratian images, “1” for visual ight, “2” for IR, “4” for UV.
            // if (nMainID == 1000) {
            // nSubID[0] = 3;
            // }
            bundle.putInt("nMainID", nMainID); // Mian type of documents. “6” stands for driving license, “2” for 2nd generation Identity card of P.R. Here one main document type can be uploaded. Each type of documents has its only unique ID No.. The possible value can be seen on the notes of main document type.
            bundle.putIntArray("nSubID", nSubID); // Save the subtype ID of recognized documents. The subtype ones of each document can be shown in “ Subtype document instruction”. IfnSubID[0]=null, it means to set main type douments as “nMainID”.
            // bundle.putBoolean("GetSubID", true);
            // //Get the subtype ID of recognized images.
            // bundle.putString("lpHeadFileName",
            // "/mnt/sdcard/head.jpg");//In saving the path, the suffix can only be jpg, bmp, tif.
            bundle.putBoolean("GetVersionInfo", true); //Get teh version information of development kit.
            //bundle.putBoolean("isSetIDCardRejectType", true);
            bundle.putString("sn", "");
            // bundle.putString("datefile",
            // "assets");//Environment.getExternalStorageDirectory().toString()+"/wtdate.lsc"
            bundle.putString("devcode", Devcode.devcode);
            // bundle.putBoolean("isCheckDevType", true); // To test device type switch in a compulsive way.
            // bundle.putString("versionfile",
            // "assets");//Environment.getExternalStorageDirectory().toString()+"/wtversion.lsc"
            // bundle.putString("sn", "XS4XAYRWEFRY248YY4LHYY178");
            // //Serial No. activation method,  XS4XAYRWEFRY248YY4LHYY178 has been used.
            // bundle.putString("server",
            // "http://192.168.0.36:8080");//http://192.168.0.36:8888
            // bundle.putString("authfile", ""); // File activation method.  //
            // /mnt/sdcard/AndroidWT/357816040594713_zj.txt
            if(nMainID==2) {
                bundle.putBoolean("isAutoClassify", true);
                bundle.putBoolean("isOnlyClassIDCard", true);
            }
            bundle.putString("logo", logopath); // The path of logo. Logo is shown on the top right corner of awaiting pages.
            bundle.putInt("nProcessType", 7);//2- rotation  3- cropping and rotation 4- tilt correction 5- cropping+ tilt correction 6- rotation+tile correct 7- cropping+rotation+tilt correction.
            bundle.putInt("nSetType", 1);// nSetType:“0”-cancelling the operations, 1- setting operations.
            bundle.putBoolean("isCut", cutBoolean); // If not setting, this item will be defualt automatic cropping.
            bundle.putBoolean("isSaveCut", true);// To see if the cropping images should be saved.
            bundle.putString("returntype", "withvalue");// Withvalue is a returned value mode with paramaters( new value passed mode.
           //bundle.putIntegerArrayList("listLoadXMLIdCardType", null);//Whether to add the function of random handoff on the camera interface, when the size is greater than 1, all the document templates in this set are loaded.
            intent.putExtras(bundle);
            ((Activity) context).startActivityForResult(intent, 8);
        } catch (Exception e) {
            Toast.makeText(
                    context,
                    context.getString(context.getResources().getIdentifier("noFoundProgram","string",context.getPackageName()))
                            + "wintone.idcard", Toast.LENGTH_SHORT).show();
        }
    }
 
    /**
     * .Get corresponding recognition results and skip to the result displaying interface.
     * @param context Context
     * @param resultMessage Recognize the returned paramater.
     * @param VehicleLicenseflag The primary interface is the one of driving license or general primary interface.
     */
    public static void goShowResultActivity(Context context, ResultMessage resultMessage, int VehicleLicenseflag, String fullPicturePath, String cutPicturePath) {
        try {
            String recogResultString = "";
            if (resultMessage.ReturnAuthority == 0
                    && resultMessage.ReturnInitIDCard == 0
                    && resultMessage.ReturnLoadImageToMemory == 0
                    && resultMessage.ReturnRecogIDCard > 0) {
                String iDResultString = "";
                String[] GetFieldName = resultMessage.GetFieldName;
                String[] GetRecogResult = resultMessage.GetRecogResult;
 
                for (int i = 1; i < GetFieldName.length; i++) {
                    if (GetRecogResult[i] != null) {
                        if (!recogResultString.equals(""))
                            recogResultString = recogResultString
                                    + GetFieldName[i] + ":"
                                    + GetRecogResult[i] + ",";
                        else {
                            recogResultString = GetFieldName[i] + ":"
                                    + GetRecogResult[i] + ",";
                        }
                    }
                }
                Intent intent = new Intent("kernal.idcard.ShowResultActivity");
                intent.putExtra("recogResult", recogResultString);
                intent.putExtra("VehicleLicenseflag", VehicleLicenseflag);
                intent.putExtra("fullPagePath", fullPicturePath);
                intent.putExtra("cutPagePath", cutPicturePath);
                intent.putExtra("importRecog", true);
                ((Activity)context).finish();
                ((Activity)context).startActivity(intent);
            } else {
                String string = "";
                if (resultMessage.ReturnAuthority == -100000) {
                    string = context.getString(context.getResources().getIdentifier("exception", "string", context.getPackageName()))
                            + resultMessage.ReturnAuthority;
                } else if (resultMessage.ReturnAuthority != 0) {
                    string = context.getString(context.getResources().getIdentifier("exception1", "string", context.getPackageName()))
                            + resultMessage.ReturnAuthority;
                } else if (resultMessage.ReturnInitIDCard != 0) {
                    string = context.getString(context.getResources().getIdentifier("exception2", "string", context.getPackageName()))
                            + resultMessage.ReturnInitIDCard;
                } else if (resultMessage.ReturnLoadImageToMemory != 0) {
                    if (resultMessage.ReturnLoadImageToMemory == 3) {
                        string = context.getString(context.getResources().getIdentifier("exception3", "string", context.getPackageName()))
                                + resultMessage.ReturnLoadImageToMemory;
                    } else if (resultMessage.ReturnLoadImageToMemory == 1) {
                        string = context.getString(context.getResources().getIdentifier("exception4", "string", context.getPackageName()))
                                + resultMessage.ReturnLoadImageToMemory;
                    } else {
                        string = context.getString(context.getResources().getIdentifier("exception5", "string", context.getPackageName()))
                                + resultMessage.ReturnLoadImageToMemory;
                    }
                } else if (resultMessage.ReturnRecogIDCard <= 0) {
                    if (resultMessage.ReturnRecogIDCard == -6) {
                        string = context.getString(context.getResources().getIdentifier("exception9", "string", context.getPackageName()));
                    } else {
                        string = context.getString(context.getResources().getIdentifier("exception6", "string", context.getPackageName()))
                                + resultMessage.ReturnRecogIDCard;
                    }
                }
                Intent intent = new Intent("kernal.idcard.ShowResultActivity");
                intent.putExtra("exception", string);
                intent.putExtra("VehicleLicenseflag", VehicleLicenseflag);
                ((Activity)context).finish();
                ((Activity)context).startActivity(intent);
            }
        } catch (Exception e) {
            e.printStackTrace();
            Toast.makeText(context,
                    context.getString(context.getResources().getIdentifier("recognized_failed","string",context.getPackageName())),
                    Toast.LENGTH_SHORT).show();
 
        }
 
    }
 
    /**
     * Transform the mirror data into a normal image
     * or Transform a normal image into the mirror data
     * @param src
     * @param w
     * @param h
     * @return
     */
    public static void transformMirrorNV21Data(byte[] src, int w, int h) {
        int i;
        int index;
        byte temp;
        int a, b;
        //mirror y
        for (i = 0; i < h; i++) {
            a = i * w;
            b = (i + 1) * w - 1;
            while (a < b) {
                temp = src[a];
                src[a] = src[b];
                src[b] = temp;
                a++;
                b--;
            }
        }
        // mirror u and v
        index = w * h;
        for (i = 0; i < h / 2; i++) {
            a = i * w;
            b = (i + 1) * w - 2;
            while (a < b) {
                temp = src[a + index];
                src[a + index] = src[b + index];
                src[b + index] = temp;
 
                temp = src[a + index + 1];
                src[a + index + 1] = src[b + index + 1];
                src[b + index + 1] = temp;
                a += 2;
                b -= 2;
            }
        }
    }
 
    /**
     * Transform the mirror data into a normal image
     * or Transform a normal image into the mirror data(RGB)
     * @param picPath
     */
   public static int[] transformMirrorRGB(String picPath){
       Bitmap bitmap=BitmapFactory.decodeFile(picPath);
       int width=bitmap.getWidth();
       int height=bitmap.getHeight();
       int[] pixels=new int[width*height];
       int a, b;
       int temp;
       bitmap.getPixels(pixels, 0, width, 0, 0, width, height);
       for (int i = 0; i < height; i++) {
           a = i * width;
           b = (i + 1) * width - 1;
           while (a < b) {
               temp = pixels[a];
               pixels[a] = pixels[b ];
               pixels[b] = temp;
               a += 1;
               b -= 1;
           }
       }
       if(bitmap!=null){
           if(!bitmap.isRecycled()){
               bitmap.recycle();
               bitmap=null;
           }
       }
    return pixels;
   }
    public static void copyFile(Context context, Uri srcUri, File dstFile) {
        try {
            InputStream inputStream = context.getContentResolver().openInputStream(srcUri);
            if (inputStream == null) return;
            OutputStream outputStream = new FileOutputStream(dstFile);
            copyStream(inputStream, outputStream);
            inputStream.close();
            outputStream.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public static int copyStream(InputStream input, OutputStream output) throws Exception, IOException {
        final int BUFFER_SIZE = 1024 * 2;
        byte[] buffer = new byte[BUFFER_SIZE];
        BufferedInputStream in = new BufferedInputStream(input, BUFFER_SIZE);
        BufferedOutputStream out = new BufferedOutputStream(output, BUFFER_SIZE);
        int count = 0, n = 0;
        try {
            while ((n = in.read(buffer, 0, BUFFER_SIZE)) != -1) {
                out.write(buffer, 0, n);
                count += n;
            }
            out.flush();
        } finally {
            try {
                out.close();
            } catch (IOException e) {
            }
            try {
                in.close();
            } catch (IOException e) {
            }
        }
        return count;
    }
}