001/*
002 * ===========================================================================================
003 * = COPYRIGHT
004 *          PAX Computer Technology (Shenzhen) Co., Ltd. PROPRIETARY INFORMATION
005 *   This software is supplied under the terms of a license agreement or nondisclosure
006 *   agreement with PAX Computer Technology (Shenzhen) Co., Ltd. and may not be copied or
007 *   disclosed except in accordance with the terms in that agreement.
008 *     Copyright (C) 2017-2023 PAX Computer Technology (Shenzhen) Co., Ltd. All rights reserved.
009 * Description: // Detail description about the function of this module,
010 *             // interfaces with the other modules, and dependencies.
011 * Revision History:
012 * Date                         Author                        Action
013 * 2017/04/01                   PAX                     Create/Add/Modify/Delete
014 * ===========================================================================================
015 */
016package com.pax.dal;
017
018import android.os.Bundle;
019
020import com.pax.dal.entity.OCRResult;
021import com.pax.dal.exceptions.OCRException;
022
023/**
024 * <div class="zh">OCR模块。</div> <div class="en">OCR module.</div>
025 */
026public interface IOCR {
027    /**
028     * <div class="zh">机读码。</div> <div class="en">Machine Readable Zone.</div>
029     * @since V3.16.00
030     */
031    public static final int TYPE_MRZ = 1;
032    /**
033     * <div class="zh">护照(暂不支持)。</div> <div class="en">Passport (not currently supported).</div>
034     * @since V3.16.00
035     */
036    public static final int TYPE_PASSPORT = 2;
037    /**
038     * <div class="zh">中国身份证(暂不支持)。</div> <div class="en">Chinese identity card (not currently supported).</div>
039     * @since V3.16.00
040     */
041    public static final int TYPE_CHINA_IDCARD = 3;
042
043    /**
044     * <div class="zh">通用机读码。</div> <div class="en">Universal Machine Readable Zone</div>
045     * @since V3.30.00
046     */
047    public static final int TYPE_MRZ_EX = 4;
048    /**
049     * <div class="zh">设置授权认证ID。</div> <div class="en">Set the authorization ID.</div>
050     *
051     * @param authId <div class="zh">授权认证ID。</div> <div class="en">Authorization ID.</div>
052     * @throws OCRException
053     * @since V3.16.00
054     */
055    void setAuthId(String authId) throws OCRException;
056
057    /**
058     * <div class="zh">打开OCR。</div> <div class="en">Open the OCR.</div>
059     *
060     * @throws OCRException
061     * @since V3.16.00
062     */
063    void open() throws OCRException;
064
065    /**
066     * <div class="zh">设置摄像头ID。</div> <div class="en">Set the camera ID.</div>
067     *
068     * @param cameraId <div class="zh">摄像头ID。<ul><li>0:后置摄像头。</li><li>1:前置摄像头。</li></ul></div>
069     *                 <div class="en">Camera ID.<ul><li>0:Rear camera.</li><li>1:Front camera.</li></ul></div>
070     * @throws OCRException
071     */
072    // void setCameraId(int cameraId) throws OCRException;
073    
074    /**
075     * <div class="zh">设置预览配置。在{@link #open()}之后和{@link #startPreview(int, int, IOCRListener)}之前调用。</div>
076     * <div class="en">Set the preview configuration.Called after {@link #open()} and before {@link #startPreview(int, int, IOCRListener)}.</div>
077     *
078     * @param param <div class="zh">
079     *                  <table border="1">
080     *                      <tr>
081     *                          <th>KEY名称</th>
082     *                          <th>类型</th>
083     *                          <th>说明</th>
084     *                      </tr>
085     *                      <tr>
086     *                          <td>cameraId</td>
087     *                          <td>int</td>
088     *                          <td>摄像头ID(默认后置) 0:后置摄像头 1:前置摄像头</td>
089     *                      </tr>
090     *                      <tr>
091     *                          <td>isFlashOn</td>
092     *                          <td>boolean</td>
093     *                          <td>是否开启闪光灯(默认不开启) true:开启 false:不开启</td>
094     *                      </tr>
095     *                      <tr>
096     *                          <td>isAutoFocus</td>
097     *                          <td>boolean</td>
098     *                          <td>是否开启自动对焦(默认不开启) true:开启 false:不开启</td>
099     *                      </tr>
100     *                  </table>
101     *              </div>
102     *              <div class="en">
103     *                  <table border="1">
104     *                      <tr>
105     *                          <th>The KEY name</th>
106     *                          <th>Type</th>
107     *                          <th>Instructions</th>
108     *                      </tr>
109     *                      <tr>
110     *                          <td>cameraId</td>
111     *                          <td>int</td>
112     *                          <td>Camera ID(default rear). 0: rear camera 1: front camera</td>
113     *                      </tr>
114     *                      <tr>
115     *                          <td>isFlashOn</td>
116     *                          <td>boolean</td>
117     *                          <td>Whether to turn on the flash (not on by default).true:open, false:not open</td>
118     *                      </tr>
119     *                      <tr>
120     *                          <td>isAutoFocus</td>
121     *                          <td>boolean</td>
122     *                          <td>Whether to turn on autofocus (not on by default).true:open, false:not open</td>
123     *                      </tr>
124     *                  </table>
125     *              </div>
126     * @throws OCRException
127     * @since V3.16.00
128     */
129    void setPreviewParam(Bundle param) throws OCRException;
130
131    /**
132     * <div class="zh">打开预览界面进行扫描。</div> <div class="en">Open the preview screen for scanning.</div>
133     *
134     * @param timeout  <div class="zh">超时时间。单位:毫秒。</div> <div class="en">Timeout time. Unit: ms.</div>
135     * @param type     <div class="zh">证件类型。
136     *                  <ul>
137     *                      <li>{@link #TYPE_MRZ}</li>
138     *                      <li>{@link #TYPE_PASSPORT}</li>
139     *                      <li>{@link #TYPE_CHINA_IDCARD}</li>
140     *                      <li>{@link #TYPE_MRZ_EX}</li>
141     *                  </ul>
142     *                 </div>
143     *                 <div class="en">Type of certificate.
144     *                  <ul>
145     *                      <li>{@link #TYPE_MRZ}</li>
146     *                      <li>{@link #TYPE_PASSPORT}</li>
147     *                      <li>{@link #TYPE_CHINA_IDCARD}</li>
148     *                      <li>{@link #TYPE_MRZ_EX}</li>
149     *                  </ul>
150     *                 </div>
151     * @param listener <div class="zh">扫描结果回调。{@link IOCRListener}</div> <div class="en">Callback of scan results.{@link IOCRListener}</div>
152     * @throws OCRException
153     * @since V3.16.00
154     */
155    void startPreview(int type, int timeout, IOCRListener listener) throws OCRException;
156
157    /**
158     * <div class="zh">关闭扫描预览界面。</div> <div class="en">Close the scan preview screen.</div>
159     *
160     * @throws OCRException
161     * @since V3.16.00
162     */
163    void stopPreview() throws OCRException;
164
165    /**
166     * <div class="zh">关闭OCR。</div> <div class="en">Close the OCR.</div>
167     *
168     * @throws OCRException
169     * @since V3.16.00
170     */
171    void close() throws OCRException;
172
173    /**
174     * <div class="zh">扫描结果回调。</div> <div class="en">Callback of scan results.</div>
175     * @since V3.16.00
176     */
177    interface IOCRListener {
178        /**
179         * <div class="zh">成功回调。</div> <div class="en">Success callback.</div>
180         * @param result <div class="zh">根据{@link #startPreview(int, int, IOCRListener)}的type,强制转换成对应的OCRResult。
181         *               <br/>{@link #TYPE_MRZ}: {@link com.pax.dal.entity.OCRMRZResult}
182         *               <br/>{@link #TYPE_MRZ_EX}: {@link com.pax.dal.entity.OCRMRZExResult}</div>
183         *               <div class="en">Cast to the corresponding OCRResult according to the type of {@link #startPreview(int, int, IOCRListener)}.
184         *               <br/>{@link #TYPE_MRZ}: {@link com.pax.dal.entity.OCRMRZResult}
185         *               <br/>{@link #TYPE_MRZ_EX}: {@link com.pax.dal.entity.OCRMRZExResult}</div>
186         * @since V3.16.00
187         */
188        void onSuccess(OCRResult result);
189
190        /**
191         * <div class="zh">错误回调。</div> <div class="en">Error callback.</div>
192         * @param code <div class="zh">
193         *              <ul>
194         *                  <li>1:获取失败</li>
195         *                  <li>2:扫描超时</li>
196         *                  <li>3:取消扫描</li>
197         *                  <li>4:OCR服务初始化失败</li>
198         *              </ul>
199         *             </div>
200         *             <div class="en">
201         *              <ul>
202         *                  <li>1:Scan failure</li>
203         *                  <li>2:Scan timeout</li>
204         *                  <li>3:Cancel scan</li>
205         *                  <li>4:OCR service initialization failure</li>
206         *              </ul>
207         *             </div>
208         * @since V3.16.00
209         */
210        void onError(int code);
211    }
212}