Search in sources :

Example 1 with SurfaceHolder

use of android.view.SurfaceHolder in project zxingfragmentlib by mitoyarzun.

the class BarCodeScannerFragment method startScan.

public void startScan() {
    if (cameraManager != null) {
        Log.e(TAG, "startScan: scan already started.");
        return;
    }
    cameraManager = new CameraManager(getActivity());
    cameraManager.setManualCameraId(getRequestedCameraId());
    viewfinderView = (ViewfinderView) getView().findViewById(R.id.viewfinder_view);
    viewfinderView.setCameraManager(cameraManager);
    handler = null;
    lastResult = null;
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
    //
    //    if (prefs.getBoolean(PreferencesActivity.KEY_DISABLE_AUTO_ORIENTATION, true)) {
    //      //noinspection ResourceType
    //      getActivity().setRequestedOrientation(getCurrentOrientation());
    //    } else {
    //      getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
    //    }
    SurfaceView surfaceView = (SurfaceView) getView().findViewById(R.id.preview_view);
    SurfaceHolder surfaceHolder = surfaceView.getHolder();
    surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
    if (hasSurface) {
        // The activity was paused but not stopped, so the surface still exists. Therefore
        // surfaceCreated() won't be called, so init the camera here.
        initCamera(surfaceHolder);
    } else {
        // Install the callback and wait for surfaceCreated() to init the camera.
        surfaceHolder.addCallback(this);
    }
    beepManager.updatePrefs();
    ambientLightManager.start(cameraManager);
    inactivityTimer.onResume();
    decodeFormats = null;
    characterSet = null;
}
Also used : SurfaceHolder(android.view.SurfaceHolder) SharedPreferences(android.content.SharedPreferences) CameraManager(com.google.zxing.client.android.camera.CameraManager) SurfaceView(android.view.SurfaceView)

Example 2 with SurfaceHolder

use of android.view.SurfaceHolder in project zxingfragmentlib by mitoyarzun.

the class BarCodeScannerFragment method stopScan.

public void stopScan() {
    if (cameraManager == null) {
        Log.e(TAG, "stopScan: scan already stopped");
        return;
    }
    if (handler != null) {
        handler.quitSynchronously();
        handler = null;
    }
    inactivityTimer.onPause();
    ambientLightManager.stop();
    beepManager.close();
    cameraManager.closeDriver();
    cameraManager = null;
    if (!hasSurface) {
        SurfaceView surfaceView = (SurfaceView) getView().findViewById(R.id.preview_view);
        SurfaceHolder surfaceHolder = surfaceView.getHolder();
        surfaceHolder.removeCallback(this);
    }
}
Also used : SurfaceHolder(android.view.SurfaceHolder) SurfaceView(android.view.SurfaceView)

Example 3 with SurfaceHolder

use of android.view.SurfaceHolder in project zxing-lib by kennydude.

the class ZXingFragment method onResume.

@SuppressWarnings("deprecation")
@Override
public void onResume() {
    super.onResume();
    // Setup camera view
    cameraManager = new CameraManager(getActivity().getApplication());
    cameraManager.setManualFramingRect(getView().getWidth(), getView().getHeight());
    viewfinderView = (ViewfinderView) getView().findViewById(R.id.viewfinder_view);
    viewfinderView.setCameraManager(cameraManager);
    SurfaceView surfaceView = (SurfaceView) getView().findViewById(R.id.preview_view);
    SurfaceHolder surfaceHolder = surfaceView.getHolder();
    if (hasSurface) {
        // The activity was paused but not stopped, so the surface still
        // exists. Therefore
        // surfaceCreated() won't be called, so init the camera here.
        initCamera(surfaceHolder);
    } else {
        // Install the callback and wait for surfaceCreated() to init the
        // camera.
        surfaceHolder.addCallback(this);
        surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
    }
}
Also used : SurfaceHolder(android.view.SurfaceHolder) CameraManager(com.google.zxing.client.android.camera.CameraManager) SurfaceView(android.view.SurfaceView)

Example 4 with SurfaceHolder

use of android.view.SurfaceHolder in project android_frameworks_base by ParanoidAndroid.

the class CameraTest method checkTakePicture.

private void checkTakePicture() {
    SurfaceHolder mSurfaceHolder;
    try {
        mSurfaceHolder = MediaFrameworkTest.mSurfaceView.getHolder();
        mCamera.setPreviewDisplay(mSurfaceHolder);
        Log.v(TAG, "Start preview");
        mCamera.startPreview();
        waitForPreviewDone();
        mCamera.setPreviewCallback(null);
        mCamera.takePicture(mShutterCallback, mRawPictureCallback, mJpegPictureCallback);
        waitForSnapshotDone();
    } catch (Exception e) {
        Log.v(TAG, e.toString());
    }
}
Also used : SurfaceHolder(android.view.SurfaceHolder)

Example 5 with SurfaceHolder

use of android.view.SurfaceHolder in project android_frameworks_base by ParanoidAndroid.

the class CameraFunctionalTest method testFunctionalCameraFlashModes.

/**
     * Functional test iterating on the various flash modes (on, off, auto, torch)
     */
@LargeTest
public void testFunctionalCameraFlashModes() throws Exception {
    try {
        SurfaceHolder surfaceHolder = MediaFrameworkTest.mSurfaceView.getHolder();
        Parameters params = mCameraTestHelper.getCameraParameters();
        List<String> supportedFlashModes = params.getSupportedFlashModes();
        assertNotNull("No flash modes supported", supportedFlashModes);
        for (int i = 0; i < supportedFlashModes.size(); i++) {
            runOnLooper(new Runnable() {

                @Override
                public void run() {
                    mCameraTestHelper.setupCameraTest();
                }
            });
            Log.v(TAG, "Setting flash mode to " + supportedFlashModes.get(i));
            params.setFlashMode(supportedFlashModes.get(i));
            mCameraTestHelper.setParameters(params);
            mCameraTestHelper.startCameraPreview(surfaceHolder);
            mCameraTestHelper.capturePhoto();
        }
        mCameraTestHelper.cleanupTestImages();
    } catch (Exception e) {
        Log.e(TAG, e.toString());
        fail("Camera flash mode test Exception");
    }
}
Also used : SurfaceHolder(android.view.SurfaceHolder) Parameters(android.hardware.Camera.Parameters) IOException(java.io.IOException) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Aggregations

SurfaceHolder (android.view.SurfaceHolder)189 SurfaceView (android.view.SurfaceView)62 LargeTest (android.test.suitebuilder.annotation.LargeTest)50 Parameters (android.hardware.Camera.Parameters)37 IOException (java.io.IOException)29 MediaPlayer (android.media.MediaPlayer)17 Surface (android.view.Surface)16 SurfaceTexture (android.graphics.SurfaceTexture)14 CamcorderProfile (android.media.CamcorderProfile)13 MediaRecorder (android.media.MediaRecorder)13 Camera (android.hardware.Camera)9 OverlayData (android.media.videoeditor.VideoEditor.OverlayData)9 Paint (android.graphics.Paint)8 AudioManager (android.media.AudioManager)8 SharedPreferences (android.content.SharedPreferences)7 MediaVideoItem (android.media.videoeditor.MediaVideoItem)7 CameraManager (com.google.zxing.client.android.camera.CameraManager)7 Intent (android.content.Intent)6 VideoEditor (android.media.videoeditor.VideoEditor)6 MediaProcessingProgressListener (android.media.videoeditor.VideoEditor.MediaProcessingProgressListener)6