Browse Source

删除无用代码

詹子聪 5 năm trước cách đây
mục cha
commit
14b102b7f3

+ 0 - 1
app/build.gradle

@@ -85,7 +85,6 @@ dependencies {
 
     // crash捕获
     implementation 'cn.yc:ToolLib:1.2.0'
-    implementation project(path: ':camera')
 
     //api 'com.otaliastudios:cameraview:2.6.4'
 }

+ 0 - 11
app/src/main/AndroidManifest.xml

@@ -46,13 +46,6 @@
             </intent-filter>
         </activity>
 
-        <activity
-            android:name=".ui.OperationActivity"
-            android:screenOrientation="portrait" />
-
-        <activity
-            android:name=".ui.camera.wechat.WechatOperationActivity"
-            android:screenOrientation="portrait" />
 
         <activity
             android:name=".ui.camera.otalia.OtaOperationActivity"
@@ -60,10 +53,6 @@
             android:configChanges="keyboardHidden|orientation|screenSize"
             android:launchMode="singleTask"/>
 
-        <activity
-            android:name=".ui.camera.google.GoogleCameraActivity"
-            android:screenOrientation="portrait"
-            android:theme="@style/MaterialTheme"/>
     </application>
 
 </manifest>

+ 0 - 571
app/src/main/java/com/miekir/ocr/ui/CameraActivity.java

@@ -1,571 +0,0 @@
-package com.miekir.ocr.ui;
-
-import android.Manifest;
-import android.annotation.SuppressLint;
-import android.content.Context;
-import android.content.pm.PackageManager;
-import android.content.res.Configuration;
-import android.graphics.ImageFormat;
-import android.graphics.Point;
-import android.graphics.SurfaceTexture;
-import android.hardware.camera2.CameraAccessException;
-import android.hardware.camera2.CameraCaptureSession;
-import android.hardware.camera2.CameraCharacteristics;
-import android.hardware.camera2.CameraDevice;
-import android.hardware.camera2.CameraManager;
-import android.hardware.camera2.CameraMetadata;
-import android.hardware.camera2.CaptureRequest;
-import android.hardware.camera2.TotalCaptureResult;
-import android.hardware.camera2.params.StreamConfigurationMap;
-import android.media.Image;
-import android.media.ImageReader;
-import android.os.Build;
-import android.os.Bundle;
-import android.os.Environment;
-import android.os.Handler;
-import android.os.HandlerThread;
-import android.util.Log;
-import android.util.Range;
-import android.util.Size;
-import android.util.SparseIntArray;
-import android.view.Surface;
-import android.view.TextureView;
-import android.widget.ImageView;
-
-import androidx.annotation.NonNull;
-
-import com.miekir.ocr.R;
-import com.miekir.ocr.base.BaseCameraActivity;
-import com.miekir.ocr.tool.CameraPreviewTool;
-import com.miekir.ocr.tool.ImageUtil;
-import com.miekir.ocr.widget.AutoFitTextureView;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-import java.util.concurrent.Semaphore;
-import java.util.concurrent.TimeUnit;
-
-public class CameraActivity extends BaseCameraActivity {
-    protected int mLeft;
-    protected int mTop;
-    protected int mRight;
-    protected int mBottom;
-
-    private CameraManager mCameraManager;
-
-    private static SparseIntArray ORIENTATIONS = new SparseIntArray();
-
-    static {
-        ORIENTATIONS.append(Surface.ROTATION_0, 90);
-        ORIENTATIONS.append(Surface.ROTATION_90, 0);
-        ORIENTATIONS.append(Surface.ROTATION_180, 270);
-        ORIENTATIONS.append(Surface.ROTATION_270, 180);
-    }
-
-    private String cameraId;
-    private CameraDevice cameraDevice;
-    private CameraCaptureSession cameraCaptureSessions;
-    private CaptureRequest.Builder captureRequestBuilder;
-    private Size imageDimension;
-    private ImageReader imageReader;
-
-    private File directoryFile = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) + "/");
-
-    private Handler mBackgroundHandler;
-    private HandlerThread mBackgroundThread;
-
-    private AutoFitTextureView textureView;
-    private boolean mIsFlashOpen = false;
-    private ImageView iv_flash;
-
-    private Semaphore mCameraOpenCloseLock = new Semaphore(1);
-
-    private static final int MAX_PREVIEW_WIDTH = 1920;
-    private static final int MAX_PREVIEW_HEIGHT = 1080;
-    private int mSensorOrientation;
-
-
-
-    private TextureView.SurfaceTextureListener textureListener = new TextureView.SurfaceTextureListener() {
-        @Override
-        public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
-            openCamera(width, height);
-        }
-
-        @Override
-        public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) {
-            if (null != textureView || null == imageDimension) {
-                textureView.setTransform(CameraPreviewTool.configureTransform(width, height, imageDimension, CameraActivity.this));
-            }
-        }
-
-        @Override
-        public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
-            return false;
-        }
-
-        @Override
-        public void onSurfaceTextureUpdated(SurfaceTexture surface) {
-
-        }
-    };
-
-    private CameraDevice.StateCallback stateCallback = new CameraDevice.StateCallback() {
-        @Override
-        public void onOpened(CameraDevice camera) {
-
-            Log.e("tag", "onOpened");
-            mCameraOpenCloseLock.release();
-            cameraDevice = camera;
-            createCameraPreview();
-        }
-
-        @Override
-        public void onDisconnected(CameraDevice camera) {
-            mCameraOpenCloseLock.release();
-            cameraDevice.close();
-        }
-
-        @Override
-        public void onError(CameraDevice camera, int error) {
-            mCameraOpenCloseLock.release();
-            cameraDevice.close();
-            cameraDevice = null;
-        }
-    };
-
-
-    @Override
-    public int getLayoutID() {
-        return R.layout.activity_camera;
-    }
-
-
-    @SuppressLint("CheckResult")
-    @Override
-    public void initViews(Bundle savedInstanceState) {
-        textureView = findViewById(R.id.texture);
-        textureView.setSurfaceTextureListener(textureListener);
-        iv_flash = findViewById(R.id.iv_flash);
-        iv_flash.setOnClickListener(v -> {
-           mIsFlashOpen = !mIsFlashOpen;
-           if (mIsFlashOpen) {
-               iv_flash.setImageResource(R.mipmap.flash_open);
-           } else {
-               iv_flash.setImageResource(R.mipmap.flash_close);
-           }
-        });
-
-        textureView.post(new Runnable() {
-            @Override
-            public void run() {
-                setWidthHeight(textureView.getWidth(), textureView.getHeight());
-            }
-        });
-    }
-
-    @Override
-    protected void setWidthHeight(int width, int height) {
-
-    }
-
-
-    private void openCamera(int width, int height) {
-        mCameraManager = (CameraManager) getSystemService(Context.CAMERA_SERVICE);
-        Log.e("tag", "is camera open");
-
-        try {
-            if (!mCameraOpenCloseLock.tryAcquire(2500, TimeUnit.MILLISECONDS)) {
-                throw new RuntimeException("Time out waiting to lock camera opening.");
-            }
-            cameraId = mCameraManager.getCameraIdList()[0];
-            CameraCharacteristics characteristics = mCameraManager.getCameraCharacteristics(cameraId);
-            StreamConfigurationMap map = characteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
-            assert map != null;
-
-            Size largest = Collections.max(
-                    Arrays.asList(map.getOutputSizes(ImageFormat.JPEG)),
-                    new CameraPreviewTool.CompareSizesByArea());
-
-
-            int displayRotation = getWindowManager().getDefaultDisplay().getRotation();
-            //noinspection ConstantConditions
-            mSensorOrientation = characteristics.get(CameraCharacteristics.SENSOR_ORIENTATION);
-            boolean swappedDimensions = false;
-            switch (displayRotation) {
-                case Surface.ROTATION_0:
-                case Surface.ROTATION_180:
-                    if (mSensorOrientation == 90 || mSensorOrientation == 270) {
-                        swappedDimensions = true;
-                    }
-                    break;
-                case Surface.ROTATION_90:
-                case Surface.ROTATION_270:
-                    if (mSensorOrientation == 0 || mSensorOrientation == 180) {
-                        swappedDimensions = true;
-                    }
-                    break;
-                default:
-                    Log.e("tag", "Display rotation is invalid: " + displayRotation);
-            }
-
-            Point displaySize = new Point();
-            getWindowManager().getDefaultDisplay().getSize(displaySize);
-            int rotatedPreviewWidth = width;
-            int rotatedPreviewHeight = height;
-            int maxPreviewWidth = displaySize.x;
-            int maxPreviewHeight = displaySize.y;
-
-            if (swappedDimensions) {
-                rotatedPreviewWidth = height;
-                rotatedPreviewHeight = width;
-                maxPreviewWidth = displaySize.y;
-                maxPreviewHeight = displaySize.x;
-            }
-
-            if (maxPreviewWidth > MAX_PREVIEW_WIDTH) {
-                maxPreviewWidth = MAX_PREVIEW_WIDTH;
-            }
-
-            if (maxPreviewHeight > MAX_PREVIEW_HEIGHT) {
-                maxPreviewHeight = MAX_PREVIEW_HEIGHT;
-            }
-
-            imageDimension = CameraPreviewTool.chooseOptimalSize(map.getOutputSizes(SurfaceTexture.class),
-                    rotatedPreviewWidth, rotatedPreviewHeight, maxPreviewWidth,
-                    maxPreviewHeight, largest);
-
-            int orientation = getResources().getConfiguration().orientation;
-            if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
-                textureView.setAspectRatio(
-                        imageDimension.getWidth(), imageDimension.getHeight());
-            } else {
-                textureView.setAspectRatio(
-                        imageDimension.getHeight(), imageDimension.getWidth());
-            }
-
-            if (null != textureView || null == imageDimension) {
-                textureView.setTransform(CameraPreviewTool.configureTransform(width, height, imageDimension, CameraActivity.this));
-            }
-
-            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M &&
-                    checkSelfPermission(Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
-                return;
-            }
-            mCameraManager.openCamera(cameraId, stateCallback, null);
-        } catch (CameraAccessException | InterruptedException e) {
-            e.printStackTrace();
-        }
-        Log.e("tag", "openCamera X");
-    }
-
-    private Range<Integer> getRange() {
-        CameraCharacteristics chars = null;
-        try {
-            chars = mCameraManager.getCameraCharacteristics(cameraId);
-            Range<Integer>[] ranges = chars.get(CameraCharacteristics.CONTROL_AE_AVAILABLE_TARGET_FPS_RANGES);
-            Range<Integer> result = null;
-            for (Range<Integer> range : ranges) {
-                int upper = range.getUpper();
-                // 10 - min range upper for my needs
-                if (upper >= 10) {
-                    if (result == null || upper < result.getUpper().intValue()) {
-                        result = range;
-                    }
-                }
-            }
-            if (result == null) {
-                result = ranges[0];
-            }
-            return result;
-        } catch (CameraAccessException e) {
-            e.printStackTrace();
-            return null;
-        }
-    }
-
-    protected void createCameraPreview() {
-        try {
-            SurfaceTexture texture = textureView.getSurfaceTexture();
-            assert texture != null;
-            texture.setDefaultBufferSize(imageDimension.getWidth(), imageDimension.getHeight());
-            Surface surface = new Surface(texture);
-            captureRequestBuilder = cameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
-            //captureRequestBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON_AUTO_FLASH);
-            // 解决预览太暗的问题
-            captureRequestBuilder.set(CaptureRequest.CONTROL_AE_TARGET_FPS_RANGE, getRange());
-            captureRequestBuilder.addTarget(surface);
-
-            cameraDevice.createCaptureSession(Arrays.asList(surface), new CameraCaptureSession.StateCallback() {
-                @Override
-                public void onConfigured(@NonNull CameraCaptureSession cameraCaptureSession) {
-                    //The camera is already closed
-                    if (null == cameraDevice) {
-                        return;
-                    }
-                    // When the session is ready, we start displaying the preview.
-                    cameraCaptureSessions = cameraCaptureSession;
-                    updatePreview();
-                }
-
-                @Override
-                public void onConfigureFailed(@NonNull CameraCaptureSession cameraCaptureSession) {
-                    //Toast.makeText(CameraActivity.this, "Configuration change", Toast.LENGTH_SHORT).show();
-                }
-            }, null);
-        } catch (CameraAccessException e) {
-            e.printStackTrace();
-        }
-    }
-
-    protected void updatePreview() {
-        if (null == cameraDevice) {
-            Log.e("tag", "updatePreview error, return");
-        }
-        captureRequestBuilder.set(CaptureRequest.CONTROL_MODE, CameraMetadata.CONTROL_MODE_AUTO);
-        //justFlashLight(captureRequestBuilder);
-        try {
-            cameraCaptureSessions.setRepeatingRequest(captureRequestBuilder.build(), null, mBackgroundHandler);
-        } catch (CameraAccessException e) {
-            e.printStackTrace();
-        }
-    }
-
-    protected void startBackgroundThread() {
-        mBackgroundThread = new HandlerThread("Camera Background");
-        mBackgroundThread.start();
-        mBackgroundHandler = new Handler(mBackgroundThread.getLooper());
-    }
-
-    protected void stopBackgroundThread() {
-        mBackgroundThread.quitSafely();
-        try {
-            mBackgroundThread.join();
-            mBackgroundThread = null;
-            mBackgroundHandler = null;
-        } catch (InterruptedException e) {
-            e.printStackTrace();
-        }
-    }
-
-    private void closeCamera() {
-        try {
-            mCameraOpenCloseLock.acquire();
-            if (null != cameraCaptureSessions) {
-                cameraCaptureSessions.close();
-                cameraCaptureSessions = null;
-            }
-            if (null != cameraDevice) {
-                cameraDevice.close();
-                cameraDevice = null;
-            }
-            if (null != imageReader) {
-                imageReader.close();
-                imageReader = null;
-            }
-        } catch (InterruptedException e) {
-            throw new RuntimeException("Interrupted while trying to lock camera closing.");
-        } finally {
-            mCameraOpenCloseLock.release();
-        }
-    }
-
-    @Override
-    protected void onResume() {
-        super.onResume();
-        Log.e("tag", "onResume");
-        startBackgroundThread();
-        if (textureView.isAvailable()) {
-            openCamera(textureView.getWidth(), textureView.getHeight());
-        } else {
-            textureView.setSurfaceTextureListener(textureListener);
-        }
-    }
-
-    @Override
-    protected void onPause() {
-        Log.e("tag", "onPause");
-        closeCamera();
-        stopBackgroundThread();
-        super.onPause();
-    }
-
-    protected void takePicture() {
-        if (null == cameraDevice) {
-            Log.e("tag", "cameraDevice is null");
-            return;
-        }
-        CameraManager manager = (CameraManager) getSystemService(Context.CAMERA_SERVICE);
-        try {
-            CameraCharacteristics characteristics = manager.getCameraCharacteristics(cameraDevice.getId());
-            Size[] jpegSizes = null;
-            if (characteristics != null) {
-                jpegSizes = characteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP).getOutputSizes(ImageFormat.JPEG);
-            }
-            int width = 640;
-            int height = 480;
-            if (jpegSizes != null && 0 < jpegSizes.length) {
-                width = jpegSizes[0].getWidth();
-                height = jpegSizes[0].getHeight();
-            }
-            //ImageReader reader = ImageReader.newInstance(width, height, ImageFormat.JPEG, 1);
-            // 解决拍照慢的问题
-            ImageReader reader = ImageReader.newInstance(width, height, ImageFormat.YUV_420_888, 1);
-            List<Surface> outputSurfaces = new ArrayList<Surface>(2);
-            outputSurfaces.add(reader.getSurface());
-            outputSurfaces.add(new Surface(textureView.getSurfaceTexture()));
-            final CaptureRequest.Builder captureBuilder = cameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE);
-            captureBuilder.addTarget(reader.getSurface());
-            captureBuilder.set(CaptureRequest.CONTROL_MODE, CameraMetadata.CONTROL_MODE_AUTO);
-            // Orientation
-            int rotation = getWindowManager().getDefaultDisplay().getRotation();
-            captureBuilder.set(CaptureRequest.JPEG_ORIENTATION, ORIENTATIONS.get(rotation));
-            reader.setOnImageAvailableListener(readerListener, mBackgroundHandler);
-
-            final CameraCaptureSession.CaptureCallback captureListener = new CameraCaptureSession.CaptureCallback() {
-                @Override
-                public void onCaptureCompleted(CameraCaptureSession session, CaptureRequest request, TotalCaptureResult result) {
-                    super.onCaptureCompleted(session, request, result);
-                    //Toast.makeText(CameraActivity.this, "Saved:" + directoryFile, Toast.LENGTH_SHORT).show();
-                    createCameraPreview();
-                }
-
-            };
-
-            justFlashLight(captureBuilder);
-            cameraDevice.createCaptureSession(outputSurfaces, new CameraCaptureSession.StateCallback() {
-                @Override
-                public void onConfigured(CameraCaptureSession session) {
-                    try {
-                        session.capture(captureBuilder.build(), captureListener, mBackgroundHandler);
-                    } catch (CameraAccessException e) {
-                        e.printStackTrace();
-                    }
-                }
-
-                @Override
-                public void onConfigureFailed(CameraCaptureSession session) {
-                }
-            }, mBackgroundHandler);
-        } catch (CameraAccessException e) {
-            e.printStackTrace();
-        }
-    }
-
-    private void justFlashLight(CaptureRequest.Builder captureBuilder) {
-        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
-            if (mIsFlashOpen) {
-                captureBuilder.set(CaptureRequest.FLASH_MODE, CaptureRequest.FLASH_MODE_TORCH);
-                // 解决在部分手机全黑的问题
-                captureBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON);
-            } else {
-                captureBuilder.set(CaptureRequest.FLASH_MODE, CaptureRequest.FLASH_MODE_OFF);
-                captureBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON);
-            }
-
-            // 只有摄像头关闭的时候,才能用以下的方法
-            /*try {
-                //获取CameraManager
-                CameraManager mCameraManager = (CameraManager) getSystemService(Context.CAMERA_SERVICE);
-                //获取当前手机所有摄像头设备ID
-                String[] ids  = mCameraManager.getCameraIdList();
-                for (String id : ids) {
-                    CameraCharacteristics c = mCameraManager.getCameraCharacteristics(id);
-                    //查询该摄像头组件是否包含闪光灯
-                    Boolean flashAvailable = c.get(CameraCharacteristics.FLASH_INFO_AVAILABLE);
-                    Integer lensFacing = c.get(CameraCharacteristics.LENS_FACING);
-                    if (flashAvailable != null && flashAvailable
-                            && lensFacing != null && lensFacing == CameraCharacteristics.LENS_FACING_BACK) {
-                        //打开或关闭手电筒
-                        mCameraManager.setTorchMode(id, true);
-                    }
-                }
-            } catch (CameraAccessException e) {
-                e.printStackTrace();
-            }*/
-        } else {
-            if (mIsFlashOpen) {
-                // 拍完关闭闪光灯
-                captureBuilder.set(CaptureRequest.FLASH_MODE, CaptureRequest.FLASH_MODE_SINGLE);
-                //captureRequestBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON_ALWAYS_FLASH);
-                captureBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON);
-            } else {
-                captureBuilder.set(CaptureRequest.FLASH_MODE, CaptureRequest.FLASH_MODE_OFF);
-                //captureRequestBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON_AUTO_FLASH);
-                captureBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON);
-            }
-        }
-
-
-    }
-
-    ImageReader.OnImageAvailableListener readerListener = new ImageReader.OnImageAvailableListener() {
-        @Override
-        public void onImageAvailable(ImageReader reader) {
-
-            // YUV_420_888转换成jpg
-            Image image = reader.acquireLatestImage();
-            if (image != null) {
-                //converting to JPEG
-                byte[] jpegData = ImageUtil.imageToByteArray(image);
-
-                // 写入到文件
-                //FileManager.writeFrame(directoryFile.getAbsolutePath(), jpegData);
-                image.close();
-
-                // 得到裁剪后的图片数据
-                int[] rectData = new int[]{mLeft, mTop, mRight, mBottom};
-
-                if (!directoryFile.exists()) {
-                    directoryFile.mkdirs();
-                }
-
-                File file = new File(directoryFile, System.currentTimeMillis() + ".jpg");
-                onCropFinish(jpegData, rectData, file);
-            }
-
-            /*Image image = null;
-            try {
-                image = reader.acquireLatestImage();
-                ByteBuffer buffer = image.getPlanes()[0].getBuffer();
-                byte[] bytes = new byte[buffer.capacity()];
-                buffer.get(bytes);
-                save(bytes);
-            } catch (FileNotFoundException e) {
-                e.printStackTrace();
-            } catch (IOException e) {
-                e.printStackTrace();
-            } finally {
-                if (image != null) {
-                    image.close();
-                }
-            }*/
-        }
-
-        private void save(byte[] bytes) throws IOException {
-            OutputStream output = null;
-            try {
-                output = new FileOutputStream(directoryFile);
-                output.write(bytes);
-            } finally {
-                if (null != output) {
-                    output.close();
-                }
-            }
-        }
-    };
-
-
-    /**
-     * 裁剪完成,上传识别
-     */
-    protected void onCropFinish(byte[] rawPhotoBytes, int[] rectData, File file) {
-
-    }
-}

+ 0 - 311
app/src/main/java/com/miekir/ocr/ui/OperationActivity.java

@@ -1,311 +0,0 @@
-package com.miekir.ocr.ui;
-
-import android.app.AlertDialog;
-import android.content.Intent;
-import android.content.pm.ActivityInfo;
-import android.net.Uri;
-import android.os.Bundle;
-import android.text.TextUtils;
-import android.view.View;
-import android.widget.LinearLayout;
-import android.widget.TextView;
-
-import androidx.annotation.Nullable;
-
-import com.miekir.common.utils.ToastTool;
-import com.miekir.common.utils.ViewTool;
-import com.miekir.mvp.presenter.InjectPresenter;
-import com.miekir.ocr.R;
-import com.miekir.ocr.bean.OcrResult;
-import com.miekir.ocr.tool.AnimateManager;
-import com.miekir.ocr.tool.SystemTool;
-import com.miekir.ocr.widget.CropView;
-import com.miekir.ocr.widget.GlideV4ImageEngine;
-import com.miekir.ocr.widget.IndicatorText;
-import com.zhihu.matisse.Matisse;
-import com.zhihu.matisse.MimeType;
-
-import java.io.File;
-import java.util.List;
-
-/**
- * Copyright (C), 2019-2020, Genlot
- *
- * @author 詹子聪
- * @date 2020/7/27 9:01
- * Description: 菜单操作
- */
-public class OperationActivity extends CameraActivity implements CropView.OnRectChangeListener, View.OnClickListener, IOperationView {
-    private static final int REQUEST_CODE_CHOOSE = 6;
-
-    @InjectPresenter
-    OperationPresenter mOperationPresenter;
-
-    private CropView pcv_scan;
-    private int mCurrentType = CropView.SCAN_TYPE_ALL;
-    private String mCurrentScene = CropView.SCAN_SCENES[mCurrentType];
-    private int[] MENU_ID_LIST = {R.id.it_postal, R.id.it_address, R.id.it_name, R.id.it_all};
-
-    private TextView tv_orientation;
-    private String mLandscapeString;
-    private String mPortraitString;
-
-
-    @Override
-    public void initViews(Bundle savedInstanceState) {
-        super.initViews(savedInstanceState);
-
-        int[] clickIds = new int[]{R.id.it_postal, R.id.it_address, R.id.it_name, R.id.it_all,
-                R.id.fl_take, R.id.fl_album};
-        ViewTool.setOnClickListener(this, clickIds, this);
-
-        // 裁剪View
-        pcv_scan = findViewById(R.id.pcv_scan);
-        pcv_scan.setLocationListener(this);
-        //showResultDialog(null);
-        //showLoading("Loading...");
-
-        mLandscapeString = getResources().getString(R.string.landscape);
-        mPortraitString = getResources().getString(R.string.portrait);
-        tv_orientation = findViewById(R.id.tv_orientation);
-        tv_orientation.setOnClickListener(this);
-    }
-
-    @Override
-    public void onClick(View v) {
-        switch (v.getId()) {
-            case R.id.fl_take:
-                takePicture();
-                break;
-            case R.id.fl_album:
-                Matisse.from(this)
-                        .choose(MimeType.ofImage())
-                        .countable(true)
-                        .maxSelectable(1)
-                        //.addFilter(new GifSizeFilter(320, 320, 5 * Filter.K * Filter.K))
-                        //.gridExpectedSize(getResources().getDimensionPixelSize(R.dimen.grid_expected_size))
-                        .restrictOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED)
-                        .thumbnailScale(0.85f)
-                        //.imageEngine(new GlideEngine())
-                        .imageEngine(new GlideV4ImageEngine())
-                        //.showPreview(false) // Default is `true`
-                        .forResult(REQUEST_CODE_CHOOSE);
-                break;
-
-            case R.id.it_postal:
-            case R.id.it_address:
-            case R.id.it_name:
-            case R.id.it_all:
-                setScanArea(v.getId());
-                if (v.getId() == R.id.it_all) {
-                    tv_orientation.setText(mLandscapeString);
-                    tv_orientation.setVisibility(View.VISIBLE);
-                } else {
-                    tv_orientation.setVisibility(View.INVISIBLE);
-                }
-
-                break;
-
-            case R.id.tv_orientation:
-                String textOld = tv_orientation.getText().toString();
-                if (TextUtils.equals(mLandscapeString, textOld)) {
-                    tv_orientation.setText(mPortraitString);
-                } else {
-                    tv_orientation.setText(mLandscapeString);
-                }
-
-                if (tv_orientation.getVisibility() == View.VISIBLE) {
-                    // 切换横竖屏
-                    AnimateManager.getInstance().stopAnimation();
-                    pcv_scan.switchOrientation();
-                }
-                break;
-            default:
-                break;
-        }
-    }
-
-    @Override
-    protected void onCropFinish(byte[] rawPhotoBytes, int[] rectData, File file) {
-        super.onCropFinish(rawPhotoBytes, rectData, file);
-
-        if (tv_orientation.getVisibility() == View.VISIBLE) {
-            mOperationPresenter.startOcrFromFile(this, rawPhotoBytes, rectData, file, mCurrentScene, pcv_scan.isLandscape());
-        } else {
-            mOperationPresenter.startOcrFromFile(this, rawPhotoBytes, rectData, file, mCurrentScene, false);
-        }
-    }
-
-    /**
-     * 设置裁剪区域
-     * @param viewId
-     */
-    private void setScanArea(int viewId) {
-        for (int index = 0, len = MENU_ID_LIST.length; index < len; index++) {
-            IndicatorText indicatorText = findViewById(MENU_ID_LIST[index]);
-            if (MENU_ID_LIST[index] == viewId) {
-                indicatorText.onIndicatorClicked();
-                mCurrentType = CropView.SCAN_TYPES[index];
-                mCurrentScene = CropView.SCAN_SCENES[index];
-            } else {
-                indicatorText.onIndicatorRelease();
-            }
-        }
-        pcv_scan.setScanArea(mCurrentType);
-    }
-
-
-    @Override
-    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
-        super.onActivityResult(requestCode, resultCode, data);
-        if (resultCode == RESULT_OK && requestCode == REQUEST_CODE_CHOOSE && data != null) {
-            List<Uri> selectedList = Matisse.obtainResult(data);
-            if (selectedList != null && selectedList.size() > 0) {
-                if (tv_orientation.getVisibility() == View.VISIBLE) {
-                    mOperationPresenter.startOcrFromUri(this, selectedList.get(0), mCurrentScene, pcv_scan.isLandscape());
-                } else {
-                    mOperationPresenter.startOcrFromUri(this, selectedList.get(0), mCurrentScene, false);
-                }
-            }
-        }
-    }
-
-    @Override
-    public void locationRect(int startX, int startY, int endX, int endY) {
-        // 截取的区域坐标信息
-        //System.out.println("x:"+startX + "   y:" + startY + "    endX:" + endX + "   endY" + endY);
-        /*mLeft = startY;
-        mTop = SizeTool.SCREEN_WIDTH - endX;
-        mRight = endY;
-        mBottom = SizeTool.SCREEN_WIDTH - startX;*/
-
-        mLeft = startX;
-        mTop = startY;
-        mRight = endX;
-        mBottom = endY;
-
-        /*mLeft = startY;
-        mTop = SizeTool.SCREEN_WIDTH - endX;
-        mRight = endY;
-        mBottom = SizeTool.SCREEN_WIDTH - startX;*/
-    }
-
-    @Override
-    public void onOcrResult(OcrResult result) {
-        // 识别结果
-        showResultDialog(result);
-    }
-
-    /**
-     * 弹出识别对话框
-     * @param result
-     */
-    private void showResultDialog(OcrResult result) {
-        AlertDialog dialog = new AlertDialog.Builder(this).setView(R.layout.dialog_result).create();
-        dialog.show();
-        dialog.setCancelable(false);
-        dialog.setCanceledOnTouchOutside(false);
-
-        dialog.findViewById(R.id.tv_copy).setOnClickListener(v -> {
-            dialog.cancel();
-            if (result == null) {
-                return;
-            }
-
-            SystemTool.copyText(OperationActivity.this, "");
-            // 复制全部识别信息
-            if (mCurrentType == CropView.SCAN_TYPE_ALL) {
-                StringBuilder builder = new StringBuilder();
-                if (result.postcode != null) {
-                    builder.append(result.postcode.getText()).append(",");
-                }
-                if (result.address != null) {
-                    builder.append(result.address.getText()).append(",");
-                }
-                if (result.name != null) {
-                    builder.append(result.name.getText()).append(",");
-                }
-                if (builder.length() > 0) {
-                    builder.deleteCharAt(builder.length()-1);
-                    SystemTool.copyText(OperationActivity.this, builder.toString());
-                } else {
-                    SystemTool.copyText(OperationActivity.this, " ");
-                }
-            } else if (mCurrentType == CropView.SCAN_TYPE_POSTAL) {
-                if (result.postcode != null) {
-                    SystemTool.copyText(OperationActivity.this, result.postcode.getText());
-                } else {
-                    SystemTool.copyText(OperationActivity.this, " ");
-                }
-            } else if (mCurrentType == CropView.SCAN_TYPE_ADDRESS) {
-                if (result.address != null) {
-                    SystemTool.copyText(OperationActivity.this, result.address.getText());
-                } else {
-                    SystemTool.copyText(OperationActivity.this, " ");
-                }
-            } else if (mCurrentType == CropView.SCAN_TYPE_NAME) {
-                if (result.name != null) {
-                    SystemTool.copyText(OperationActivity.this, result.name.getText());
-                } else {
-                    SystemTool.copyText(OperationActivity.this, " ");
-                }
-            }
-
-            ToastTool.showShort(getString(R.string.copy_success));
-        });
-        dialog.findViewById(R.id.tv_cancel).setOnClickListener(v -> {
-            dialog.cancel();
-        });
-
-        LinearLayout ll_postal = dialog.findViewById(R.id.ll_postal);
-        LinearLayout ll_address = dialog.findViewById(R.id.ll_address);
-        LinearLayout ll_name = dialog.findViewById(R.id.ll_name);
-        if (mCurrentType == CropView.SCAN_TYPE_ALL) {
-            ll_postal.setVisibility(View.VISIBLE);
-            ll_address.setVisibility(View.VISIBLE);
-            ll_name.setVisibility(View.VISIBLE);
-        } else if (mCurrentType == CropView.SCAN_TYPE_POSTAL) {
-            ll_postal.setVisibility(View.VISIBLE);
-            ll_address.setVisibility(View.GONE);
-            ll_name.setVisibility(View.GONE);
-        } else if (mCurrentType == CropView.SCAN_TYPE_ADDRESS) {
-            ll_address.setVisibility(View.VISIBLE);
-            ll_postal.setVisibility(View.GONE);
-            ll_name.setVisibility(View.GONE);
-
-        } else if (mCurrentType == CropView.SCAN_TYPE_NAME) {
-            ll_name.setVisibility(View.VISIBLE);
-            ll_postal.setVisibility(View.GONE);
-            ll_address.setVisibility(View.GONE);
-        }
-
-        TextView tv_postal = dialog.findViewById(R.id.tv_postal);
-        TextView tv_address = dialog.findViewById(R.id.tv_address);
-        TextView tv_name = dialog.findViewById(R.id.tv_name);
-        tv_postal.setText("");
-        tv_address.setText("");
-        tv_name.setText("");
-
-
-        if (result == null) {
-            return;
-        }
-
-        if (result.postcode != null) {
-            tv_postal.setText(result.postcode.getText());
-        }
-
-        if (result.address != null) {
-            tv_address.setText(result.address.getText());
-        }
-
-        if (result.name != null) {
-            tv_name.setText(result.name.getText());
-        }
-    }
-
-    @Override
-    protected void setWidthHeight(int width, int height) {
-        mOperationPresenter.setWidthHeight(width, height);
-    }
-}

Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 0 - 1031
app/src/main/java/com/miekir/ocr/ui/camera/google/Camera2BasicFragment.java


+ 0 - 38
app/src/main/java/com/miekir/ocr/ui/camera/google/GoogleCameraActivity.java

@@ -1,38 +0,0 @@
-/*
- * Copyright 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *       http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.miekir.ocr.ui.camera.google;
-
-import android.os.Bundle;
-
-import androidx.appcompat.app.AppCompatActivity;
-
-import com.miekir.ocr.R;
-
-public class GoogleCameraActivity extends AppCompatActivity {
-
-    @Override
-    protected void onCreate(Bundle savedInstanceState) {
-        super.onCreate(savedInstanceState);
-        setContentView(R.layout.activity_google_camera);
-        if (null == savedInstanceState) {
-            getSupportFragmentManager().beginTransaction()
-                    .replace(R.id.container, GoogleCameraFragment.newInstance())
-                    .commit();
-        }
-    }
-
-}

Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 0 - 1034
app/src/main/java/com/miekir/ocr/ui/camera/google/GoogleCameraFragment.java


+ 0 - 161
app/src/main/java/com/miekir/ocr/ui/camera/wechat/WechatCameraActivity.java

@@ -1,161 +0,0 @@
-package com.miekir.ocr.ui.camera.wechat;
-
-
-import android.content.Intent;
-import android.graphics.Bitmap;
-import android.os.Bundle;
-import android.os.Environment;
-import android.util.Log;
-import android.widget.ImageView;
-import android.widget.Toast;
-
-import com.cjt2325.cameralibrary.JCameraView;
-import com.cjt2325.cameralibrary.listener.ErrorListener;
-import com.cjt2325.cameralibrary.listener.JCameraListener;
-import com.cjt2325.cameralibrary.util.FileUtil;
-import com.miekir.ocr.R;
-import com.miekir.ocr.base.BaseCameraActivity;
-import com.miekir.ocr.widget.CropView;
-
-import java.io.File;
-
-/**
- * Copyright (C), 2019-2020, Miekir
- *
- * @author Miekir
- * @date 2020/10/27 15:35
- * Description:
- */
-public class WechatCameraActivity extends BaseCameraActivity {
-    protected int mLeft;
-    protected int mTop;
-    protected int mRight;
-    protected int mBottom;
-
-    protected JCameraView jCameraView;
-    protected CropView pcv_scan;
-    private boolean mIsFlashOpen = false;
-    private ImageView iv_flash;
-
-    @Override
-    protected void onCreate(Bundle savedInstanceState) {
-        //getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
-        //setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
-        super.onCreate(savedInstanceState);
-    }
-
-    @Override
-    public int getLayoutID() {
-        return R.layout.activity_wechat_camera;
-    }
-
-    @Override
-    public void initViews(Bundle savedInstanceState) {
-
-        iv_flash = findViewById(R.id.iv_flash);
-        iv_flash.setOnClickListener(v -> {
-            mIsFlashOpen = !mIsFlashOpen;
-            if (mIsFlashOpen) {
-                iv_flash.setImageResource(R.mipmap.flash_open);
-                jCameraView.setFlashType(JCameraView.TYPE_FLASH_ON);
-            } else {
-                iv_flash.setImageResource(R.mipmap.flash_close);
-                jCameraView.setFlashType(JCameraView.TYPE_FLASH_OFF);
-            }
-        });
-
-
-        jCameraView = (JCameraView) findViewById(R.id.jcameraview);
-        jCameraView.post(new Runnable() {
-            @Override
-            public void run() {
-                setWidthHeight(jCameraView.getWidth(), jCameraView.getHeight());
-            }
-        });
-        //设置视频保存路径
-        jCameraView.setSaveVideoPath(Environment.getExternalStorageDirectory().getPath() + File.separator + "JCamera");
-        jCameraView.setFeatures(JCameraView.BUTTON_STATE_BOTH);
-        jCameraView.setTip("");
-        jCameraView.setMediaQuality(JCameraView.MEDIA_QUALITY_MIDDLE);
-        jCameraView.setErrorLisenter(new ErrorListener() {
-            @Override
-            public void onError() {
-                //错误监听
-                Log.i("CJT", "camera error");
-                Intent intent = new Intent();
-                setResult(103, intent);
-                finish();
-            }
-
-            @Override
-            public void AudioPermissionError() {
-                Toast.makeText(WechatCameraActivity.this, getString(R.string.permission_msg), Toast.LENGTH_SHORT).show();
-            }
-        });
-        //JCameraView监听
-        jCameraView.setJCameraLisenter(new JCameraListener() {
-            @Override
-            public void captureSuccess(Bitmap bitmap) {
-                //获取图片bitmap
-                takePhotoResult(bitmap);
-//                Log.i("JCameraView", "bitmap = " + bitmap.getWidth());
-//                String path = FileUtil.saveBitmap("JCamera", bitmap);
-//                Intent intent = new Intent();
-//                intent.putExtra("path", path);
-//                setResult(101, intent);
-//                finish();
-            }
-
-            @Override
-            public void recordSuccess(String url, Bitmap firstFrame) {
-                //获取视频路径
-                String path = FileUtil.saveBitmap("JCamera", firstFrame);
-                Log.i("CJT", "url = " + url + ", Bitmap = " + path);
-                Intent intent = new Intent();
-                intent.putExtra("path", path);
-                setResult(101, intent);
-                finish();
-            }
-        });
-
-        pcv_scan = findViewById(R.id.pcv_scan);
-//        pcv_scan.setOnFingerUpListener(event -> {
-//            if (event.getPointerCount() == 1 && jCameraView != null) {
-//                // 手动对焦
-//                jCameraView.setFocusViewWidthAnimation(event.getX(), event.getY());
-//            }
-//        });
-    }
-
-    @Override
-    protected void onStart() {
-        super.onStart();
-        //全屏显示
-        /*if (Build.VERSION.SDK_INT >= 19) {
-            View decorView = getWindow().getDecorView();
-            decorView.setSystemUiVisibility(
-                    View.SYSTEM_UI_FLAG_LAYOUT_STABLE
-                            | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
-                            | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
-                            | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
-                            | View.SYSTEM_UI_FLAG_FULLSCREEN
-                            | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
-        } else {
-            View decorView = getWindow().getDecorView();
-            int option = View.SYSTEM_UI_FLAG_FULLSCREEN;
-            decorView.setSystemUiVisibility(option);
-        }*/
-    }
-
-    @Override
-    protected void onResume() {
-        super.onResume();
-        jCameraView.onResume();
-    }
-
-    @Override
-    protected void onPause() {
-        super.onPause();
-        jCameraView.onPause();
-    }
-}

+ 0 - 321
app/src/main/java/com/miekir/ocr/ui/camera/wechat/WechatOperationActivity.java

@@ -1,321 +0,0 @@
-package com.miekir.ocr.ui.camera.wechat;
-
-import android.app.AlertDialog;
-import android.content.Intent;
-import android.content.pm.ActivityInfo;
-import android.graphics.Bitmap;
-import android.net.Uri;
-import android.os.Bundle;
-import android.os.Environment;
-import android.text.TextUtils;
-import android.view.View;
-import android.widget.LinearLayout;
-import android.widget.TextView;
-
-import androidx.annotation.Nullable;
-
-import com.miekir.common.utils.ToastTool;
-import com.miekir.common.utils.ViewTool;
-import com.miekir.mvp.presenter.InjectPresenter;
-import com.miekir.ocr.R;
-import com.miekir.ocr.bean.OcrResult;
-import com.miekir.ocr.tool.AnimateManager;
-import com.miekir.ocr.tool.SystemTool;
-import com.miekir.ocr.ui.IOperationView;
-import com.miekir.ocr.ui.OperationPresenter;
-import com.miekir.ocr.widget.CropView;
-import com.miekir.ocr.widget.GlideV4ImageEngine;
-import com.miekir.ocr.widget.IndicatorText;
-import com.zhihu.matisse.Matisse;
-import com.zhihu.matisse.MimeType;
-
-import java.io.File;
-import java.util.List;
-
-import static android.os.Environment.DIRECTORY_PICTURES;
-
-/**
- * Copyright (C), 2019-2020, Genlot
- *
- * @author 詹子聪
- * @date 2020/7/27 9:01
- * Description: 菜单操作
- */
-public class WechatOperationActivity extends WechatCameraActivity implements CropView.OnRectChangeListener, View.OnClickListener, IOperationView {
-    private static final int REQUEST_CODE_CHOOSE = 6;
-
-    @InjectPresenter
-    OperationPresenter mOperationPresenter;
-
-    private int mCurrentType = CropView.SCAN_TYPE_ALL;
-    private String mCurrentScene = CropView.SCAN_SCENES[mCurrentType];
-    private int[] MENU_ID_LIST = {R.id.it_postal, R.id.it_address, R.id.it_name, R.id.it_all};
-
-    private TextView tv_orientation;
-    private String mLandscapeString;
-    private String mPortraitString;
-
-
-    @Override
-    public void initViews(Bundle savedInstanceState) {
-        super.initViews(savedInstanceState);
-
-        int[] clickIds = new int[]{R.id.it_postal, R.id.fl_take, R.id.it_address, R.id.it_name, R.id.it_all, R.id.fl_album};
-        ViewTool.setOnClickListener(this, clickIds, this);
-
-        // 裁剪View
-        pcv_scan.setLocationListener(this);
-        //showResultDialog(null);
-        //showLoading("Loading...");
-
-        mLandscapeString = getResources().getString(R.string.landscape);
-        mPortraitString = getResources().getString(R.string.portrait);
-        tv_orientation = findViewById(R.id.tv_orientation);
-        tv_orientation.setOnClickListener(this);
-    }
-
-    @Override
-    public void onClick(View v) {
-        switch (v.getId()) {
-            case R.id.fl_take:
-                if (jCameraView != null) {
-                    jCameraView.takePhoto();
-                }
-                break;
-            case R.id.fl_album:
-                Matisse.from(this)
-                        .choose(MimeType.ofImage())
-                        .countable(true)
-                        .maxSelectable(1)
-                        //.addFilter(new GifSizeFilter(320, 320, 5 * Filter.K * Filter.K))
-                        //.gridExpectedSize(getResources().getDimensionPixelSize(R.dimen.grid_expected_size))
-                        .restrictOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED)
-                        .thumbnailScale(0.85f)
-                        //.imageEngine(new GlideEngine())
-                        .imageEngine(new GlideV4ImageEngine())
-                        //.showPreview(false) // Default is `true`
-                        .forResult(REQUEST_CODE_CHOOSE);
-                break;
-
-            case R.id.it_postal:
-            case R.id.it_address:
-            case R.id.it_name:
-            case R.id.it_all:
-                setScanArea(v.getId());
-                if (v.getId() == R.id.it_all) {
-                    tv_orientation.setText(mLandscapeString);
-                    tv_orientation.setVisibility(View.VISIBLE);
-                } else {
-                    tv_orientation.setVisibility(View.INVISIBLE);
-                }
-
-                break;
-
-            case R.id.tv_orientation:
-                String textOld = tv_orientation.getText().toString();
-                if (TextUtils.equals(mLandscapeString, textOld)) {
-                    tv_orientation.setText(mPortraitString);
-                } else {
-                    tv_orientation.setText(mLandscapeString);
-                }
-
-                if (tv_orientation.getVisibility() == View.VISIBLE) {
-                    // 切换横竖屏
-                    AnimateManager.getInstance().stopAnimation();
-                    pcv_scan.switchOrientation();
-                }
-                break;
-            default:
-                break;
-        }
-    }
-
-    /**
-     * 设置裁剪区域
-     * @param viewId
-     */
-    private void setScanArea(int viewId) {
-        for (int index = 0, len = MENU_ID_LIST.length; index < len; index++) {
-            IndicatorText indicatorText = findViewById(MENU_ID_LIST[index]);
-            if (MENU_ID_LIST[index] == viewId) {
-                indicatorText.onIndicatorClicked();
-                mCurrentType = CropView.SCAN_TYPES[index];
-                mCurrentScene = CropView.SCAN_SCENES[index];
-            } else {
-                indicatorText.onIndicatorRelease();
-            }
-        }
-        pcv_scan.setScanArea(mCurrentType);
-    }
-
-
-    @Override
-    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
-        super.onActivityResult(requestCode, resultCode, data);
-        if (resultCode == RESULT_OK && requestCode == REQUEST_CODE_CHOOSE && data != null) {
-            List<Uri> selectedList = Matisse.obtainResult(data);
-            if (selectedList != null && selectedList.size() > 0) {
-                if (tv_orientation.getVisibility() == View.VISIBLE) {
-                    mOperationPresenter.startOcrFromUri(this, selectedList.get(0), mCurrentScene, pcv_scan.isLandscape());
-                } else {
-                    mOperationPresenter.startOcrFromUri(this, selectedList.get(0), mCurrentScene, false);
-                }
-            }
-        }
-    }
-
-    @Override
-    public void locationRect(int startX, int startY, int endX, int endY) {
-        // 截取的区域坐标信息
-        //System.out.println("x:"+startX + "   y:" + startY + "    endX:" + endX + "   endY" + endY);
-        /*mLeft = startY;
-        mTop = SizeTool.SCREEN_WIDTH - endX;
-        mRight = endY;
-        mBottom = SizeTool.SCREEN_WIDTH - startX;*/
-
-        mLeft = startX;
-        mTop = startY;
-        mRight = endX;
-        mBottom = endY;
-
-        /*mLeft = startY;
-        mTop = SizeTool.SCREEN_WIDTH - endX;
-        mRight = endY;
-        mBottom = SizeTool.SCREEN_WIDTH - startX;*/
-    }
-
-    @Override
-    public void onOcrResult(OcrResult result) {
-        // 识别结果
-        showResultDialog(result);
-    }
-
-    /**
-     * 弹出识别对话框
-     * @param result
-     */
-    private void showResultDialog(OcrResult result) {
-        AlertDialog dialog = new AlertDialog.Builder(this).setView(R.layout.dialog_result).create();
-        dialog.show();
-        dialog.setCancelable(false);
-        dialog.setCanceledOnTouchOutside(false);
-
-        dialog.findViewById(R.id.tv_copy).setOnClickListener(v -> {
-            dialog.cancel();
-            if (result == null) {
-                return;
-            }
-
-            SystemTool.copyText(WechatOperationActivity.this, "");
-            // 复制全部识别信息
-            if (mCurrentType == CropView.SCAN_TYPE_ALL) {
-                StringBuilder builder = new StringBuilder();
-                if (result.postcode != null) {
-                    builder.append(result.postcode.getText()).append(",");
-                }
-                if (result.address != null) {
-                    builder.append(result.address.getText()).append(",");
-                }
-                if (result.name != null) {
-                    builder.append(result.name.getText()).append(",");
-                }
-                if (builder.length() > 0) {
-                    builder.deleteCharAt(builder.length()-1);
-                    SystemTool.copyText(WechatOperationActivity.this, builder.toString());
-                } else {
-                    SystemTool.copyText(WechatOperationActivity.this, " ");
-                }
-            } else if (mCurrentType == CropView.SCAN_TYPE_POSTAL) {
-                if (result.postcode != null) {
-                    SystemTool.copyText(WechatOperationActivity.this, result.postcode.getText());
-                } else {
-                    SystemTool.copyText(WechatOperationActivity.this, " ");
-                }
-            } else if (mCurrentType == CropView.SCAN_TYPE_ADDRESS) {
-                if (result.address != null) {
-                    SystemTool.copyText(WechatOperationActivity.this, result.address.getText());
-                } else {
-                    SystemTool.copyText(WechatOperationActivity.this, " ");
-                }
-            } else if (mCurrentType == CropView.SCAN_TYPE_NAME) {
-                if (result.name != null) {
-                    SystemTool.copyText(WechatOperationActivity.this, result.name.getText());
-                } else {
-                    SystemTool.copyText(WechatOperationActivity.this, " ");
-                }
-            }
-
-            ToastTool.showShort(getString(R.string.copy_success));
-        });
-        dialog.findViewById(R.id.tv_cancel).setOnClickListener(v -> {
-            dialog.cancel();
-        });
-
-        LinearLayout ll_postal = dialog.findViewById(R.id.ll_postal);
-        LinearLayout ll_address = dialog.findViewById(R.id.ll_address);
-        LinearLayout ll_name = dialog.findViewById(R.id.ll_name);
-        if (mCurrentType == CropView.SCAN_TYPE_ALL) {
-            ll_postal.setVisibility(View.VISIBLE);
-            ll_address.setVisibility(View.VISIBLE);
-            ll_name.setVisibility(View.VISIBLE);
-        } else if (mCurrentType == CropView.SCAN_TYPE_POSTAL) {
-            ll_postal.setVisibility(View.VISIBLE);
-            ll_address.setVisibility(View.GONE);
-            ll_name.setVisibility(View.GONE);
-        } else if (mCurrentType == CropView.SCAN_TYPE_ADDRESS) {
-            ll_address.setVisibility(View.VISIBLE);
-            ll_postal.setVisibility(View.GONE);
-            ll_name.setVisibility(View.GONE);
-
-        } else if (mCurrentType == CropView.SCAN_TYPE_NAME) {
-            ll_name.setVisibility(View.VISIBLE);
-            ll_postal.setVisibility(View.GONE);
-            ll_address.setVisibility(View.GONE);
-        }
-
-        TextView tv_postal = dialog.findViewById(R.id.tv_postal);
-        TextView tv_address = dialog.findViewById(R.id.tv_address);
-        TextView tv_name = dialog.findViewById(R.id.tv_name);
-        tv_postal.setText("");
-        tv_address.setText("");
-        tv_name.setText("");
-
-
-        if (result == null) {
-            return;
-        }
-
-        if (result.postcode != null) {
-            tv_postal.setText(result.postcode.getText());
-        }
-
-        if (result.address != null) {
-            tv_address.setText(result.address.getText());
-        }
-
-        if (result.name != null) {
-            tv_name.setText(result.name.getText());
-        }
-    }
-
-    @Override
-    protected void takePhotoResult(Bitmap bitmap) {
-        super.takePhotoResult(bitmap);
-        if (bitmap == null) {
-            return;
-        }
-        // 得到裁剪后的图片数据
-        int[] rectData = new int[]{mLeft, mTop, mRight, mBottom};
-        File file = new File(Environment.getExternalStoragePublicDirectory(DIRECTORY_PICTURES) + "/" + System.currentTimeMillis() + ".jpg");
-        if (tv_orientation.getVisibility() == View.VISIBLE) {
-            mOperationPresenter.startOcrFromBitmap(this, bitmap, rectData, file, mCurrentScene, pcv_scan.isLandscape());
-        } else {
-            mOperationPresenter.startOcrFromBitmap(this, bitmap, rectData, file, mCurrentScene, false);
-        }
-    }
-
-    @Override
-    protected void setWidthHeight(int width, int height) {
-        mOperationPresenter.setWidthHeight(width, height);
-    }
-}

+ 0 - 209
app/src/main/res/layout/activity_camera.xml

@@ -1,209 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:app="http://schemas.android.com/apk/res-auto"
-    android:id="@+id/activity_main"
-    android:layout_width="match_parent"
-    android:layout_height="match_parent"
-    android:orientation="vertical"
-    android:keepScreenOn="true">
-    <!--屏幕常亮-->
-
-    <LinearLayout
-        android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        android:background="@color/colorPrimary"
-        android:gravity="center_vertical"
-        android:minHeight="64dp"
-        android:orientation="horizontal"
-        android:paddingStart="@dimen/margin_default"
-        android:paddingTop="@dimen/margin_ss"
-        android:paddingEnd="@dimen/margin_default"
-        android:paddingBottom="@dimen/margin_ss">
-
-        <ImageView
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:src="@mipmap/logo" />
-
-        <TextView
-            android:layout_width="0dp"
-            android:layout_weight="1"
-            android:layout_height="wrap_content"
-            android:gravity="center"
-            android:text="@string/app_name"
-            android:textColor="@color/white"
-            android:textSize="18sp"
-            android:visibility="invisible"/>
-
-        <ImageView
-            android:id="@+id/iv_flash"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:src="@mipmap/flash_close"/>
-    </LinearLayout>
-
-
-    <FrameLayout
-        android:layout_width="match_parent"
-        android:layout_height="match_parent">
-
-        <com.miekir.ocr.widget.AutoFitTextureView
-            android:id="@+id/texture"
-            android:layout_width="match_parent"
-            android:layout_height="match_parent" />
-
-        <LinearLayout
-            android:layout_width="match_parent"
-            android:layout_height="match_parent"
-            android:orientation="vertical">
-
-            <FrameLayout
-                android:layout_width="wrap_content"
-                android:layout_height="0dp"
-                android:layout_weight="370">
-                <!--灰色遮罩-->
-                <com.miekir.ocr.widget.CropView
-                    android:id="@+id/pcv_scan"
-                    android:layout_width="match_parent"
-                    android:layout_height="match_parent"/>
-
-                <com.miekir.ocr.widget.ScalableImageView
-                    android:id="@+id/iv_animation"
-                    android:layout_width="wrap_content"
-                    android:layout_height="wrap_content"
-                    android:visibility="invisible"
-                    android:scaleType="fitXY"/>
-            </FrameLayout>
-
-            <View
-                android:layout_width="match_parent"
-                android:layout_height="0.8dp"
-                android:background="@color/white"/>
-
-
-            <LinearLayout
-                android:layout_width="match_parent"
-                android:layout_height="0dp"
-                android:layout_weight="180"
-                android:orientation="vertical"
-                android:background="@color/black_transparent">
-                <LinearLayout
-                    android:layout_width="match_parent"
-                    android:layout_height="wrap_content"
-                    android:gravity="center_vertical"
-                    android:orientation="horizontal">
-
-                    <Space
-                        android:layout_width="0dp"
-                        android:layout_height="wrap_content"
-                        android:layout_weight="1" />
-
-                    <com.miekir.ocr.widget.IndicatorText
-                        android:id="@+id/it_postal"
-                        android:layout_width="wrap_content"
-                        android:layout_height="wrap_content"
-                        app:text="@string/postal_code" />
-
-                    <Space
-                        android:layout_width="0dp"
-                        android:layout_height="wrap_content"
-                        android:layout_weight="1" />
-
-                    <com.miekir.ocr.widget.IndicatorText
-                        android:id="@+id/it_address"
-                        android:layout_width="wrap_content"
-                        android:layout_height="wrap_content"
-                        app:text="@string/address"/>
-
-                    <Space
-                        android:layout_width="0dp"
-                        android:layout_height="wrap_content"
-                        android:layout_weight="1" />
-
-                    <com.miekir.ocr.widget.IndicatorText
-                        android:id="@+id/it_name"
-                        android:layout_width="wrap_content"
-                        android:layout_height="wrap_content"
-                        app:text="@string/name"/>
-
-                    <Space
-                        android:layout_width="0dp"
-                        android:layout_height="wrap_content"
-                        android:layout_weight="1" />
-
-                    <com.miekir.ocr.widget.IndicatorText
-                        android:id="@+id/it_all"
-                        android:layout_width="wrap_content"
-                        android:layout_height="wrap_content"
-                        app:text="@string/full"
-                        app:focused="true"/>
-
-                    <Space
-                        android:layout_width="0dp"
-                        android:layout_height="wrap_content"
-                        android:layout_weight="1" />
-                </LinearLayout>
-
-
-                <LinearLayout
-                    android:layout_width="match_parent"
-                    android:layout_height="match_parent"
-                    android:gravity="center_vertical"
-                    android:orientation="horizontal"
-                    android:paddingBottom="@dimen/margin_default">
-
-                    <RelativeLayout
-                        android:layout_width="0dp"
-                        android:layout_height="wrap_content"
-                        android:layout_weight="1">
-
-                        <FrameLayout
-                            android:id="@+id/fl_album"
-                            android:foreground="@drawable/ripple_effect"
-                            android:layout_width="wrap_content"
-                            android:layout_height="wrap_content"
-                            android:layout_centerInParent="true"
-                            android:padding="@dimen/margin_default">
-                            <ImageView
-                                android:layout_width="wrap_content"
-                                android:layout_height="wrap_content"
-                                android:src="@mipmap/button_album"/>
-                        </FrameLayout>
-
-                    </RelativeLayout>
-
-                    <FrameLayout
-                        android:id="@+id/fl_take"
-                        android:layout_width="wrap_content"
-                        android:layout_height="wrap_content"
-                        android:foreground="@drawable/ripple_effect">
-
-                        <ImageView
-                            android:layout_width="wrap_content"
-                            android:layout_height="wrap_content"
-                            android:layout_gravity="center"
-                            android:src="@mipmap/button_take" />
-
-                        <ImageView
-                            android:layout_width="wrap_content"
-                            android:layout_height="wrap_content"
-                            android:layout_gravity="center"
-                            android:src="@mipmap/button_take_out" />
-                    </FrameLayout>
-
-                    <TextView
-                        android:id="@+id/tv_orientation"
-                        android:layout_width="0dp"
-                        android:layout_height="wrap_content"
-                        android:layout_marginStart="@dimen/margin_default"
-                        android:layout_marginEnd="@dimen/margin_default"
-                        android:layout_weight="1"
-                        android:gravity="center"
-                        android:text="@string/landscape"
-                        android:textColor="@color/colorPrimary"
-                        android:textSize="@dimen/size_text_title_p"/>
-                </LinearLayout>
-            </LinearLayout>
-        </LinearLayout>
-    </FrameLayout>
-</LinearLayout>

+ 0 - 22
app/src/main/res/layout/activity_google_camera.xml

@@ -1,22 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?><!--
- Copyright 2014 The Android Open Source Project
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
-     http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
--->
-<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:tools="http://schemas.android.com/tools"
-    android:id="@+id/container"
-    android:layout_width="match_parent"
-    android:layout_height="match_parent"
-    android:background="#000"
-    tools:context=".ui.camera.google.GoogleCameraActivity"/>

+ 0 - 210
app/src/main/res/layout/activity_wechat_camera.xml

@@ -1,210 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:app="http://schemas.android.com/apk/res-auto"
-    android:id="@+id/activity_main"
-    android:layout_width="match_parent"
-    android:layout_height="match_parent"
-    android:orientation="vertical"
-    android:keepScreenOn="true">
-    <!--屏幕常亮-->
-
-    <LinearLayout
-        android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        android:background="@color/colorPrimary"
-        android:gravity="center_vertical"
-        android:minHeight="64dp"
-        android:orientation="horizontal"
-        android:paddingStart="@dimen/margin_default"
-        android:paddingTop="@dimen/margin_ss"
-        android:paddingEnd="@dimen/margin_default"
-        android:paddingBottom="@dimen/margin_ss">
-
-        <ImageView
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:src="@mipmap/logo" />
-
-        <TextView
-            android:layout_width="0dp"
-            android:layout_weight="1"
-            android:layout_height="wrap_content"
-            android:gravity="center"
-            android:text="@string/app_name"
-            android:textColor="@color/white"
-            android:textSize="18sp"
-            android:visibility="invisible"/>
-
-        <ImageView
-            android:id="@+id/iv_flash"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:src="@mipmap/flash_close"/>
-    </LinearLayout>
-
-
-    <FrameLayout
-        android:layout_width="match_parent"
-        android:layout_height="match_parent">
-
-        <com.cjt2325.cameralibrary.JCameraView
-            android:id="@+id/jcameraview"
-            android:layout_width="match_parent"
-            android:layout_height="match_parent"
-            app:duration_max="10000" />
-
-        <LinearLayout
-            android:layout_width="match_parent"
-            android:layout_height="match_parent"
-            android:orientation="vertical">
-
-            <FrameLayout
-                android:layout_width="wrap_content"
-                android:layout_height="0dp"
-                android:layout_weight="370">
-                <!--灰色遮罩-->
-                <com.miekir.ocr.widget.CropView
-                    android:id="@+id/pcv_scan"
-                    android:layout_width="match_parent"
-                    android:layout_height="match_parent"/>
-
-                <com.miekir.ocr.widget.ScalableImageView
-                    android:id="@+id/iv_animation"
-                    android:layout_width="wrap_content"
-                    android:layout_height="wrap_content"
-                    android:visibility="invisible"
-                    android:scaleType="fitXY"/>
-            </FrameLayout>
-
-            <View
-                android:layout_width="match_parent"
-                android:layout_height="0.8dp"
-                android:background="@color/white"/>
-
-
-            <LinearLayout
-                android:layout_width="match_parent"
-                android:layout_height="0dp"
-                android:layout_weight="180"
-                android:orientation="vertical"
-                android:background="@color/black_transparent">
-                <LinearLayout
-                    android:layout_width="match_parent"
-                    android:layout_height="wrap_content"
-                    android:gravity="center_vertical"
-                    android:orientation="horizontal">
-
-                    <Space
-                        android:layout_width="0dp"
-                        android:layout_height="wrap_content"
-                        android:layout_weight="1" />
-
-                    <com.miekir.ocr.widget.IndicatorText
-                        android:id="@+id/it_postal"
-                        android:layout_width="wrap_content"
-                        android:layout_height="wrap_content"
-                        app:text="@string/postal_code" />
-
-                    <Space
-                        android:layout_width="0dp"
-                        android:layout_height="wrap_content"
-                        android:layout_weight="1" />
-
-                    <com.miekir.ocr.widget.IndicatorText
-                        android:id="@+id/it_address"
-                        android:layout_width="wrap_content"
-                        android:layout_height="wrap_content"
-                        app:text="@string/address"/>
-
-                    <Space
-                        android:layout_width="0dp"
-                        android:layout_height="wrap_content"
-                        android:layout_weight="1" />
-
-                    <com.miekir.ocr.widget.IndicatorText
-                        android:id="@+id/it_name"
-                        android:layout_width="wrap_content"
-                        android:layout_height="wrap_content"
-                        app:text="@string/name"/>
-
-                    <Space
-                        android:layout_width="0dp"
-                        android:layout_height="wrap_content"
-                        android:layout_weight="1" />
-
-                    <com.miekir.ocr.widget.IndicatorText
-                        android:id="@+id/it_all"
-                        android:layout_width="wrap_content"
-                        android:layout_height="wrap_content"
-                        app:text="@string/full"
-                        app:focused="true"/>
-
-                    <Space
-                        android:layout_width="0dp"
-                        android:layout_height="wrap_content"
-                        android:layout_weight="1" />
-                </LinearLayout>
-
-
-                <LinearLayout
-                    android:layout_width="match_parent"
-                    android:layout_height="match_parent"
-                    android:gravity="center_vertical"
-                    android:orientation="horizontal"
-                    android:paddingBottom="@dimen/margin_default">
-
-                    <RelativeLayout
-                        android:layout_width="0dp"
-                        android:layout_height="wrap_content"
-                        android:layout_weight="1">
-
-                        <FrameLayout
-                            android:id="@+id/fl_album"
-                            android:foreground="@drawable/ripple_effect"
-                            android:layout_width="wrap_content"
-                            android:layout_height="wrap_content"
-                            android:layout_centerInParent="true"
-                            android:padding="@dimen/margin_default">
-                            <ImageView
-                                android:layout_width="wrap_content"
-                                android:layout_height="wrap_content"
-                                android:src="@mipmap/button_album"/>
-                        </FrameLayout>
-
-                    </RelativeLayout>
-
-                    <FrameLayout
-                        android:id="@+id/fl_take"
-                        android:layout_width="wrap_content"
-                        android:layout_height="wrap_content"
-                        android:foreground="@drawable/ripple_effect">
-
-                        <ImageView
-                            android:layout_width="wrap_content"
-                            android:layout_height="wrap_content"
-                            android:layout_gravity="center"
-                            android:src="@mipmap/button_take" />
-
-                        <ImageView
-                            android:layout_width="wrap_content"
-                            android:layout_height="wrap_content"
-                            android:layout_gravity="center"
-                            android:src="@mipmap/button_take_out" />
-                    </FrameLayout>
-
-                    <TextView
-                        android:id="@+id/tv_orientation"
-                        android:layout_width="0dp"
-                        android:layout_height="wrap_content"
-                        android:layout_marginStart="@dimen/margin_default"
-                        android:layout_marginEnd="@dimen/margin_default"
-                        android:layout_weight="1"
-                        android:gravity="center"
-                        android:text="@string/landscape"
-                        android:textColor="@color/colorPrimary"
-                        android:textSize="@dimen/size_text_title_p"/>
-                </LinearLayout>
-            </LinearLayout>
-        </LinearLayout>
-    </FrameLayout>
-</LinearLayout>

+ 0 - 44
app/src/main/res/layout/fragment_camera2_basic.xml

@@ -1,44 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?><!--
- Copyright 2014 The Android Open Source Project
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
-     http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
--->
-<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
-    android:layout_width="match_parent"
-    android:layout_height="match_parent">
-
-    <com.miekir.ocr.widget.AutoFitTextureView
-        android:id="@+id/texture"
-        android:layout_width="wrap_content"
-        android:layout_height="wrap_content"
-        android:layout_alignParentStart="true"
-        android:layout_alignParentTop="true" />
-
-    <FrameLayout
-        android:id="@+id/control"
-        android:layout_width="match_parent"
-        android:layout_height="112dp"
-        android:layout_alignParentBottom="true"
-        android:layout_alignParentStart="true">
-
-        <Button
-            android:id="@+id/picture"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:layout_gravity="center"
-            android:text="Capture" />
-
-
-    </FrameLayout>
-
-</RelativeLayout>

+ 1 - 1
settings.gradle

@@ -1,3 +1,3 @@
 include ':cameraview'
-include ':app', ':common', ':adapter', ':mvp', ':network', ':camera', ':camerax'
+include ':app', ':common', ':adapter', ':mvp', ':network'
 rootProject.name='OCR Demo'