完成方法没有完成活动

时间:2016-02-11 18:18:52

标签: android

         public  boolean takeBarCode() {

                     System.out.println(Looper.myLooper() == Looper.getMainLooper()? "Main Thread: ": "Outside of main thread");
                     BarcodeGraphic graphic = mGraphicOverlay.getFirstGraphic();
                     Barcode barcode = null;
                     System.out.println(graphic);
                     if (graphic != null) {
                         System.out.println(graphic.getBarcode());
                         barcode = graphic.getBarcode();
                         if (barcode != null) {
                             System.out.println(barcode.toString());
                             Intent data = new Intent();
                             data.putExtra(BarcodeObject, barcode);
                             setResult(CommonStatusCodes.SUCCESS, data);
                             mCameraSource.cancelAutoFocus();
                             finish();
                         } else {
                             System.out.println("Barcode este null");
                         }
                     } else {
                         System.out.println("Graphic este null");
                     }
                return barcode != null;
            }




    @RequiresPermission(Manifest.permission.CAMERA)
        public CameraSource start(SurfaceHolder surfaceHolder) throws IOException {
            synchronized (mCameraLock) {
                if (mCamera != null) {
                    return this;
                }

                mCamera = createCamera();



                mCamera.setPreviewDisplay(surfaceHolder);
                mCamera.startPreview();
                mCamera.autoFocus(new Camera.AutoFocusCallback(){
                    @Override
                    public void onAutoFocus(boolean success, Camera camera) {

                        System.out.println("AutoFocus NOWW");
                        BarcodeCaptureActivity b = new BarcodeCaptureActivity();
                        b.takeBarCode();
                        Camera.Parameters parameters = mCamera.getParameters();
                        List<String> focusModes = parameters.getSupportedFocusModes();
                        if (focusModes.contains(Camera.Parameters.FOCUS_MODE_AUTO))
                        {
                            parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
                        }
                        mCamera.setParameters(parameters);
                    }
                });
                mProcessingThread = new Thread(mFrameProcessor);
                mFrameProcessor.setActive(true);
                mProcessingThread.start();
            }
            return this;
        }




 public void onClick(View v) {
        if (v.getId() == R.id.read_barcode) {
            // launch barcode activity.
            Intent intent = new Intent(this, BarcodeCaptureActivity.class);


            startActivityForResult(intent, RC_BARCODE_CAPTURE);
        }

    }

    /**
     * Called when an activity you launched exits, giving you the requestCode
     * you started it with, the resultCode it returned, and any additional
     * data from it.  The <var>resultCode</var> will be
     * {@link #RESULT_CANCELED} if the activity explicitly returned that,
     * didn't return any result, or crashed during its operation.
     * <p/>
     * <p>You will receive this call immediately before onResume() when your
     * activity is re-starting.
     * <p/>
     *
     * @param requestCode The integer request code originally supplied to
     *                    startActivityForResult(), allowing you to identify who this
     *                    result came from.
     * @param resultCode  The integer result code returned by the child activity
     *                    through its setResult().
     * @param data        An Intent, which can return result data to the caller
     *                    (various data can be attached to Intent "extras").
     * @see #startActivityForResult
     * @see #createPendingResult
     * @see #setResult(int)
     */
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == RC_BARCODE_CAPTURE) {
            if (resultCode == CommonStatusCodes.SUCCESS) {
                if (data != null) {
                    Barcode barcode = data.getParcelableExtra(BarcodeCaptureActivity.BarcodeObject);
                    statusMessage.setText(R.string.barcode_success);
                    barcodeValue.setText(barcode.displayValue);
                    Log.d(TAG, "Barcode read: " + barcode.displayValue);
                } else {
                    statusMessage.setText(R.string.barcode_failure);
                    Log.d(TAG, "No barcode captured, intent data is null");
                }
            } else {
                statusMessage.setText(String.format(getString(R.string.barcode_error),
                        CommonStatusCodes.getStatusCodeString(resultCode)));
            }
        }
        else {
            super.onActivityResult(requestCode, resultCode, data);
        }
    }
}

我的问题是childActivity没有完成。 takeBarCode()在start()方法中从其他Class调用。我创建了一个Activity的引用,其中我的takeBarcode()是我所谓的。它看起来像完成不起作用!这是autoFocus的问题?

0 个答案:

没有答案