Search in sources :

Example 16 with CameraInfo

use of android.hardware.Camera.CameraInfo in project android_packages_apps_Camera by CyanogenMod.

the class DisableCameraReceiver method hasBackCamera.

private boolean hasBackCamera() {
    int n = android.hardware.Camera.getNumberOfCameras();
    CameraInfo info = new CameraInfo();
    for (int i = 0; i < n; i++) {
        android.hardware.Camera.getCameraInfo(i, info);
        if (info.facing == CameraInfo.CAMERA_FACING_BACK) {
            Log.i(TAG, "back camera found: " + i);
            return true;
        }
    }
    Log.i(TAG, "no back camera");
    return false;
}
Also used : CameraInfo(android.hardware.Camera.CameraInfo)

Example 17 with CameraInfo

use of android.hardware.Camera.CameraInfo in project android_packages_apps_Camera by CyanogenMod.

the class PhotoModule method onConfigurationChanged.

@Override
public void onConfigurationChanged(Configuration newConfig) {
    Log.v(TAG, "onConfigurationChanged");
    // Wait for camera initialization
    try {
        if (mCameraStartUpThread != null) {
            mCameraStartUpThread.join();
        }
    } catch (InterruptedException iex) {
    // Ignore.
    }
    setDisplayOrientation();
    ((ViewGroup) mRootView).removeAllViews();
    LayoutInflater inflater = mActivity.getLayoutInflater();
    inflater.inflate(R.layout.photo_module, (ViewGroup) mRootView);
    // from onCreate()
    initializeControlByIntent();
    initializeFocusManager();
    initializeMiscControls();
    loadCameraPreferences();
    // from initializeFirstTime()
    mShutterButton = mActivity.getShutterButton();
    mShutterButton.setOnShutterButtonListener(this);
    initializeZoom();
    initOnScreenIndicator();
    updateOnScreenIndicators();
    if (mFaceView != null) {
        mFaceView.clear();
        mFaceView.setVisibility(View.VISIBLE);
        mFaceView.setDisplayOrientation(mDisplayOrientation);
        CameraInfo info = CameraHolder.instance().getCameraInfo()[mCameraId];
        mFaceView.setMirror(info.facing == CameraInfo.CAMERA_FACING_FRONT);
        mFaceView.resume();
        mFocusManager.setFaceView(mFaceView);
    }
    initializeRenderOverlay();
    onFullScreenChanged(mActivity.isInCameraApp());
    if (mJpegImageData != null) {
        // Jpeg data found, picture has been taken.
        showPostCaptureAlert();
    }
}
Also used : ViewGroup(android.view.ViewGroup) LayoutInflater(android.view.LayoutInflater) CameraInfo(android.hardware.Camera.CameraInfo)

Example 18 with CameraInfo

use of android.hardware.Camera.CameraInfo in project android_packages_apps_Camera by CyanogenMod.

the class PhotoModule method switchCamera.

private void switchCamera() {
    if (mPaused)
        return;
    Log.v(TAG, "Start to switch camera. id=" + mPendingSwitchCameraId);
    mCameraId = mPendingSwitchCameraId;
    mPendingSwitchCameraId = -1;
    mPhotoControl.setCameraId(mCameraId);
    // from onPause
    closeCamera();
    collapseCameraControls();
    if (mFaceView != null)
        mFaceView.clear();
    if (mFocusManager != null)
        mFocusManager.removeMessages();
    // Restart the camera and initialize the UI. From onCreate.
    mPreferences.setLocalId(mActivity, mCameraId);
    CameraSettings.upgradeLocalPreferences(mPreferences.getLocal());
    try {
        mCameraDevice = Util.openCamera(mActivity, mCameraId);
        mParameters = mCameraDevice.getParameters();
    } catch (CameraHardwareException e) {
        Util.showErrorAndFinish(mActivity, R.string.cannot_connect_camera);
        return;
    } catch (CameraDisabledException e) {
        Util.showErrorAndFinish(mActivity, R.string.camera_disabled);
        return;
    }
    initializeCapabilities();
    CameraInfo info = CameraHolder.instance().getCameraInfo()[mCameraId];
    boolean mirror = (info.facing == CameraInfo.CAMERA_FACING_FRONT);
    mFocusManager.setMirror(mirror);
    mFocusManager.setParameters(mInitialParams);
    setupPreview();
    loadCameraPreferences();
    initializePhotoControl();
    mResetExposure = mParameters.getExposureCompensation();
    // from initializeFirstTime
    initializeZoom();
    updateOnScreenIndicators();
    showTapToFocusToastIfNeeded();
    if (ApiHelper.HAS_SURFACE_TEXTURE) {
        // Start switch camera animation. Post a message because
        // onFrameAvailable from the old camera may already exist.
        mHandler.sendEmptyMessage(SWITCH_CAMERA_START_ANIMATION);
    }
}
Also used : CameraInfo(android.hardware.Camera.CameraInfo)

Example 19 with CameraInfo

use of android.hardware.Camera.CameraInfo in project android_packages_apps_Camera by CyanogenMod.

the class VideoModule method initializeRecorder.

// Prepares media recorder.
private void initializeRecorder() {
    Log.v(TAG, "initializeRecorder");
    // If the mCameraDevice is null, then this activity is going to finish
    if (mActivity.mCameraDevice == null)
        return;
    if (!ApiHelper.HAS_SURFACE_TEXTURE_RECORDING && ApiHelper.HAS_SURFACE_TEXTURE) {
        // Set the SurfaceView to visible so the surface gets created.
        // surfaceCreated() is called immediately when the visibility is
        // changed to visible. Thus, mSurfaceViewReady should become true
        // right after calling setVisibility().
        mPreviewSurfaceView.setVisibility(View.VISIBLE);
        if (!mSurfaceViewReady)
            return;
    }
    Intent intent = mActivity.getIntent();
    Bundle myExtras = intent.getExtras();
    mVideoWidth = mProfile.videoFrameWidth;
    mVideoHeight = mProfile.videoFrameHeight;
    long requestedSizeLimit = 0;
    closeVideoFileDescriptor();
    if (mIsVideoCaptureIntent && myExtras != null) {
        Uri saveUri = (Uri) myExtras.getParcelable(MediaStore.EXTRA_OUTPUT);
        if (saveUri != null) {
            try {
                mVideoFileDescriptor = mContentResolver.openFileDescriptor(saveUri, "rw");
                mCurrentVideoUri = saveUri;
            } catch (java.io.FileNotFoundException ex) {
                // invalid uri
                Log.e(TAG, ex.toString());
            }
        }
        requestedSizeLimit = myExtras.getLong(MediaStore.EXTRA_SIZE_LIMIT);
    }
    mMediaRecorder = new MediaRecorder();
    setupMediaRecorderPreviewDisplay();
    // Unlock the camera object before passing it to media recorder.
    mActivity.mCameraDevice.unlock();
    mMediaRecorder.setCamera(mActivity.mCameraDevice.getCamera());
    if (!mCaptureTimeLapse) {
        mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
    }
    mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
    mMediaRecorder.setProfile(mProfile);
    mMediaRecorder.setMaxDuration(mMaxVideoDurationInMs);
    if (mCaptureTimeLapse) {
        double fps = 1000 / (double) mTimeBetweenTimeLapseFrameCaptureMs;
        setCaptureRate(mMediaRecorder, fps);
    }
    setRecordLocation();
    // instead.
    if (mVideoFileDescriptor != null) {
        mMediaRecorder.setOutputFile(mVideoFileDescriptor.getFileDescriptor());
    } else {
        generateVideoFilename(mProfile.fileFormat);
        mMediaRecorder.setOutputFile(mVideoFilename);
    }
    // Set maximum file size.
    long maxFileSize = mActivity.getStorageSpace() - Storage.LOW_STORAGE_THRESHOLD;
    if (requestedSizeLimit > 0 && requestedSizeLimit < maxFileSize) {
        maxFileSize = requestedSizeLimit;
    }
    try {
        mMediaRecorder.setMaxFileSize(maxFileSize);
    } catch (RuntimeException exception) {
    // We are going to ignore failure of setMaxFileSize here, as
    // a) The composer selected may simply not support it, or
    // b) The underlying media framework may not handle 64-bit range
    // on the size restriction.
    }
    // See android.hardware.Camera.Parameters.setRotation for
    // documentation.
    // Note that mOrientation here is the device orientation, which is the opposite of
    // what activity.getWindowManager().getDefaultDisplay().getRotation() would return,
    // which is the orientation the graphics need to rotate in order to render correctly.
    int rotation = 0;
    if (mOrientation != OrientationEventListener.ORIENTATION_UNKNOWN) {
        CameraInfo info = CameraHolder.instance().getCameraInfo()[mCameraId];
        if (info.facing == CameraInfo.CAMERA_FACING_FRONT) {
            rotation = (info.orientation - mOrientation + 360) % 360;
        } else {
            // back-facing camera
            rotation = (info.orientation + mOrientation) % 360;
        }
    }
    mMediaRecorder.setOrientationHint(rotation);
    try {
        mMediaRecorder.prepare();
    } catch (IOException e) {
        Log.e(TAG, "prepare failed for " + mVideoFilename, e);
        releaseMediaRecorder();
        throw new RuntimeException(e);
    }
    mMediaRecorder.setOnErrorListener(this);
    mMediaRecorder.setOnInfoListener(this);
}
Also used : Bundle(android.os.Bundle) Intent(android.content.Intent) MediaRecorder(android.media.MediaRecorder) IOException(java.io.IOException) Uri(android.net.Uri) CameraInfo(android.hardware.Camera.CameraInfo)

Example 20 with CameraInfo

use of android.hardware.Camera.CameraInfo in project android_packages_apps_Camera by CyanogenMod.

the class VideoModule method initializeEffectsPreview.

private void initializeEffectsPreview() {
    Log.v(TAG, "initializeEffectsPreview");
    // If the mCameraDevice is null, then this activity is going to finish
    if (mActivity.mCameraDevice == null)
        return;
    boolean inLandscape = (mActivity.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE);
    CameraInfo info = CameraHolder.instance().getCameraInfo()[mCameraId];
    mEffectsDisplayResult = false;
    mEffectsRecorder = new EffectsRecorder(mActivity);
    // TODO: Confirm none of the following need to go to initializeEffectsRecording()
    // and none of these change even when the preview is not refreshed.
    mEffectsRecorder.setCameraDisplayOrientation(mCameraDisplayOrientation);
    mEffectsRecorder.setCamera(mActivity.mCameraDevice);
    mEffectsRecorder.setCameraFacing(info.facing);
    mEffectsRecorder.setProfile(mProfile);
    mEffectsRecorder.setEffectsListener(this);
    mEffectsRecorder.setOnInfoListener(this);
    mEffectsRecorder.setOnErrorListener(this);
    // The input of effects recorder is affected by
    // android.hardware.Camera.setDisplayOrientation. Its value only
    // compensates the camera orientation (no Display.getRotation). So the
    // orientation hint here should only consider sensor orientation.
    int orientation = 0;
    if (mOrientation != OrientationEventListener.ORIENTATION_UNKNOWN) {
        orientation = mOrientation;
    }
    mEffectsRecorder.setOrientationHint(orientation);
    CameraScreenNail screenNail = (CameraScreenNail) mActivity.mCameraScreenNail;
    mEffectsRecorder.setPreviewSurfaceTexture(screenNail.getSurfaceTexture(), screenNail.getWidth(), screenNail.getHeight());
    if (mEffectType == EffectsRecorder.EFFECT_BACKDROPPER && ((String) mEffectParameter).equals(EFFECT_BG_FROM_GALLERY)) {
        mEffectsRecorder.setEffect(mEffectType, mEffectUriFromGallery);
    } else {
        mEffectsRecorder.setEffect(mEffectType, mEffectParameter);
    }
}
Also used : CameraInfo(android.hardware.Camera.CameraInfo)

Aggregations

CameraInfo (android.hardware.Camera.CameraInfo)56 Camera (android.hardware.Camera)6 CameraCharacteristics (android.hardware.camera2.CameraCharacteristics)5 ServiceSpecificException (android.os.ServiceSpecificException)5 SuppressLint (android.annotation.SuppressLint)3 WindowManager (android.view.WindowManager)2 IOException (java.io.IOException)2 TargetApi (android.annotation.TargetApi)1 Intent (android.content.Intent)1 Bitmap (android.graphics.Bitmap)1 Face (android.hardware.Camera.Face)1 FaceDetectionListener (android.hardware.Camera.FaceDetectionListener)1 MediaRecorder (android.media.MediaRecorder)1 Uri (android.net.Uri)1 Bundle (android.os.Bundle)1 NonNull (android.support.annotation.NonNull)1 Pair (android.util.Pair)1 LayoutInflater (android.view.LayoutInflater)1 ViewGroup (android.view.ViewGroup)1 AppDataDirGuesser (com.google.testing.littlemock.AppDataDirGuesser)1