Android Open Source - FxCameraApp Camera Helper Froyo






From Project

Back to project page FxCameraApp.

License

The source code is released under:

MIT License

If you think the Android project FxCameraApp listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.af.experiments.FxCameraApp.camera;
/*from w  w  w  .  j a  va  2  s.c  o m*/
import android.content.Context;
import android.graphics.ImageFormat;
import android.hardware.Camera;
import android.view.Display;
import android.view.Surface;
import android.view.WindowManager;

import java.util.List;

public class CameraHelperFroyo extends CameraHelperEclair implements Camera.OnZoomChangeListener {
    private byte[] mBuffer;

    public CameraHelperFroyo(final Context context) {
        super(context);
    }

    @Override
    public void setDisplayOrientation(final int degrees) {
        getCamera().setDisplayOrientation(degrees);
    }

    @Override
    public int getOrientation() {
        final WindowManager windowManager = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
        final Display display = windowManager.getDefaultDisplay();

        final int degrees;
        switch (display.getRotation()) {
            case Surface.ROTATION_270:
                degrees = 270;
                break;
            case Surface.ROTATION_180:
                degrees = 180;
                break;
            case Surface.ROTATION_90:
                degrees = 90;
                break;
            case Surface.ROTATION_0:
            default:
                degrees = 0;
                break;
        }

        int result;
        final CameraHelper.CameraInfoCompat info = getCameraInfo();
        if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
            result = (info.orientation + degrees) % 360;
//      result = (360 - result) % 360;  // compensate the mirror
        } else {  // back-facing
            result = (info.orientation - degrees + 360) % 360;
        }
        return result;
    }

    @Override
    public int getOptimalOrientation() {
        final WindowManager windowManager = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
        final Display display = windowManager.getDefaultDisplay();

        final int degrees;
        switch (display.getRotation()) {
            case Surface.ROTATION_270:
                degrees = 270;
                break;
            case Surface.ROTATION_180:
                degrees = 180;
                break;
            case Surface.ROTATION_90:
                degrees = 90;
                break;
            case Surface.ROTATION_0:
            default:
                degrees = 0;
                break;
        }

        int result;
        final CameraHelper.CameraInfoCompat info = getCameraInfo();
        if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
            result = (info.orientation + degrees) % 360;
            result = (360 - result) % 360;  // compensate the mirror
        } else {  // back-facing
            result = (info.orientation - degrees + 360) % 360;
        }
        return result;
    }

   @Override
    public void setPreviewCallback(final Camera.PreviewCallback cb) {
        final Camera camera = getCamera();
        if (cb != null) {
            try {
                final Camera.Size previewSize = getPreviewSize();
                final Camera.Size pictureSize = getPictureSize();
                final Camera.Parameters parameters = camera.getParameters();
                mBuffer = new byte[Math.max(
                        previewSize.width * previewSize.height * ImageFormat.getBitsPerPixel(parameters.getPreviewFormat()) / 8,
                        pictureSize.width * pictureSize.height * ImageFormat.getBitsPerPixel(ImageFormat.RGB_565) / 8
                )];
                camera.setPreviewCallbackWithBuffer(cb);
                camera.addCallbackBuffer(mBuffer);
            } catch (final OutOfMemoryError e) {
                mBuffer = null;
                camera.setPreviewCallbackWithBuffer(null);
                super.setPreviewCallback(cb);
            }
        } else {
            mBuffer = null;
            camera.setPreviewCallbackWithBuffer(null);
            camera.setPreviewCallback(null);
        }
    }

    @Override
    public void onPreviewFrame(final Camera.PreviewCallback cb) {
        if (mBuffer != null) {
            getCamera().addCallbackBuffer(mBuffer);
        } else {
            super.onPreviewFrame(cb);
        }
    }

    @Override
    public int getMaxExposureCompensation() {
        return getCamera().getParameters().getMaxExposureCompensation();
    }

    @Override
    public int getMinExposureCompensation() {
        return getCamera().getParameters().getMinExposureCompensation();
    }

    @Override
    public float getExposureCompensationStep() {
        return getCamera().getParameters().getExposureCompensationStep();
    }

    @Override
    public int getExposureCompensation() {
        return getCamera().getParameters().getExposureCompensation();
    }

    @Override
    public void setExposureCompensation(final int value) {
        final Camera.Parameters params = getCamera().getParameters();
        params.setExposureCompensation(value);
        try {
            getCamera().setParameters(params);
        } catch (final RuntimeException  e) {}  // ??????
    }

    @Override
    public boolean isZoomSupported() {
        return getParameters().isZoomSupported();
    }

    @Override
    public int getMaxZoom() {
        return getParameters().getMaxZoom();
    }

    @Override
    public List<Integer> getZoomRatios() {
        return getParameters().getZoomRatios();
    }
    @Override
    public int getZoom() {
        return getParameters().getZoom();
    }

    @Override
    public void setZoom(final int value) {
        final Camera.Parameters params = getParameters();
        params.setZoom(value);
        getCamera().setParameters(params);
    }


    private Camera.OnZoomChangeListener mOnZoomChangeListener;

    public void setZoomChangeListener(final Camera.OnZoomChangeListener listener) {
        mOnZoomChangeListener = listener;
        getCamera().setZoomChangeListener(this);
    }

    @Override
    public void onZoomChange(final int zoomValue, final boolean stopped, final Camera camera) {
        if (mOnZoomChangeListener != null) {
            mOnZoomChangeListener.onZoomChange(zoomValue, stopped, getCamera());
        }
    }

    @Override
    public void startSmoothZoom(final int value) {
        getCamera().startSmoothZoom(value);
    }

    @Override
    public void stopSmoothZoom() {
        getCamera().stopSmoothZoom();
    }

}




Java Source Code List

com.af.experiments.FxCameraApp.FilterAdapter.java
com.af.experiments.FxCameraApp.MyActivity.java
com.af.experiments.FxCameraApp.Utils.BitmapFactoryUtils.java
com.af.experiments.FxCameraApp.Utils.ExifUtils.java
com.af.experiments.FxCameraApp.Utils.Fps.java
com.af.experiments.FxCameraApp.Utils.LogWriter.java
com.af.experiments.FxCameraApp.Utils.OpenGlUtils.java
com.af.experiments.FxCameraApp.View.CameraView.java
com.af.experiments.FxCameraApp.View.DefaultPreview.java
com.af.experiments.FxCameraApp.View.GlPreview.java
com.af.experiments.FxCameraApp.View.PreviewTexture.java
com.af.experiments.FxCameraApp.camera.CameraHelperBase.java
com.af.experiments.FxCameraApp.camera.CameraHelperCupcake.java
com.af.experiments.FxCameraApp.camera.CameraHelperDonut.java
com.af.experiments.FxCameraApp.camera.CameraHelperEclair.java
com.af.experiments.FxCameraApp.camera.CameraHelperFactory.java
com.af.experiments.FxCameraApp.camera.CameraHelperFroyo.java
com.af.experiments.FxCameraApp.camera.CameraHelperGingerbread.java
com.af.experiments.FxCameraApp.camera.CameraHelperHonycomb.java
com.af.experiments.FxCameraApp.camera.CameraHelperICS.java
com.af.experiments.FxCameraApp.camera.CameraHelper.java
com.af.experiments.FxCameraApp.display.DisplayHelperBase.java
com.af.experiments.FxCameraApp.display.DisplayHelperFactory.java
com.af.experiments.FxCameraApp.display.DisplayHelperFroyo.java
com.af.experiments.FxCameraApp.display.DisplayHelperHoneycombMR2.java
com.af.experiments.FxCameraApp.display.DisplayHelperHoneycomb.java
com.af.experiments.FxCameraApp.display.DisplayHelper.java
com.af.experiments.FxCameraApp.ogles.DefaultConfigChooser.java
com.af.experiments.FxCameraApp.ogles.DefaultContextFactory.java
com.af.experiments.FxCameraApp.ogles.DefaultWindowSurfaceFactory.java
com.af.experiments.FxCameraApp.ogles.EGLLogWrapper.java
com.af.experiments.FxCameraApp.ogles.GLES20ConfigChooser.java
com.af.experiments.FxCameraApp.ogles.GLES20ContextFactory.java
com.af.experiments.FxCameraApp.ogles.GlImageBitmapTexture.java
com.af.experiments.FxCameraApp.ogles.GlImageResourceTexture.java
com.af.experiments.FxCameraApp.ogles.GlImageTexture.java
com.af.experiments.FxCameraApp.ogles.GlPreviewTextureFactory.java
com.af.experiments.FxCameraApp.ogles.GlSurfaceTexture.java
com.af.experiments.FxCameraApp.ogles.GlTextureView.java
com.af.experiments.FxCameraApp.ogles.PixelBuffer.java
com.af.experiments.FxCameraApp.ogles.PreviewSurfaceHelperBase.java
com.af.experiments.FxCameraApp.ogles.PreviewSurfaceHelperFactory.java
com.af.experiments.FxCameraApp.ogles.PreviewSurfaceHelper.java
com.af.experiments.FxCameraApp.ogles.Texture.java
com.af.experiments.FxCameraApp.renderer.GLES20FramebufferObject.java
com.af.experiments.FxCameraApp.renderer.GlFrameBufferObjectRenderer.java
com.af.experiments.FxCameraApp.renderer.MainRenderer.java
com.af.experiments.FxCameraApp.shaders.GlBilateralShader.java
com.af.experiments.FxCameraApp.shaders.GlBoxBlurShader.java
com.af.experiments.FxCameraApp.shaders.GlBulgeDistortionShader.java
com.af.experiments.FxCameraApp.shaders.GlCGAColorspaceShader.java
com.af.experiments.FxCameraApp.shaders.GlColorInvertShader.java
com.af.experiments.FxCameraApp.shaders.GlColorMatrixShader.java
com.af.experiments.FxCameraApp.shaders.GlColorPackingShader.java
com.af.experiments.FxCameraApp.shaders.GlConvolutionShader.java
com.af.experiments.FxCameraApp.shaders.GlEmbossShader.java
com.af.experiments.FxCameraApp.shaders.GlFalseColorShader.java
com.af.experiments.FxCameraApp.shaders.GlFastBlurShader.java
com.af.experiments.FxCameraApp.shaders.GlGaussianBlurShader.java
com.af.experiments.FxCameraApp.shaders.GlGlassSphereShader.java
com.af.experiments.FxCameraApp.shaders.GlGrayScaleShader.java
com.af.experiments.FxCameraApp.shaders.GlHarrisCornerDetectionShader.java
com.af.experiments.FxCameraApp.shaders.GlHazeShader.java
com.af.experiments.FxCameraApp.shaders.GlMonochromeShader.java
com.af.experiments.FxCameraApp.shaders.GlNobleCornerDetectionShader.java
com.af.experiments.FxCameraApp.shaders.GlPerlinNoiseShader.java
com.af.experiments.FxCameraApp.shaders.GlPinchDistortionShader.java
com.af.experiments.FxCameraApp.shaders.GlPixellateShader.java
com.af.experiments.FxCameraApp.shaders.GlPolarPixellateShader.java
com.af.experiments.FxCameraApp.shaders.GlPolkaDotShader.java
com.af.experiments.FxCameraApp.shaders.GlPosterizeShader.java
com.af.experiments.FxCameraApp.shaders.GlPreviewShader.java
com.af.experiments.FxCameraApp.shaders.GlSepiaShader.java
com.af.experiments.FxCameraApp.shaders.GlShaderGroup.java
com.af.experiments.FxCameraApp.shaders.GlShader.java
com.af.experiments.FxCameraApp.shaders.GlSharpenShader.java
com.af.experiments.FxCameraApp.shaders.GlShiTomasiFeatureDetectionShader.java
com.af.experiments.FxCameraApp.shaders.GlSobelEdgeDetectionShader.java
com.af.experiments.FxCameraApp.shaders.GlSphereRefractionShader.java
com.af.experiments.FxCameraApp.shaders.GlStretchDistortionShader.java
com.af.experiments.FxCameraApp.shaders.GlThreex3ConvolutionShader.java
com.af.experiments.FxCameraApp.shaders.GlThreex3TextureSamplingShader.java
com.af.experiments.FxCameraApp.shaders.GlToneShader.java
com.af.experiments.FxCameraApp.shaders.GlTwoInputShader.java
com.af.experiments.FxCameraApp.shaders.GlVignetteShader.java
com.af.experiments.FxCameraApp.shaders.GlWeakPixelInclusionShader.java
com.af.experiments.FxCameraApp.shaders.GlWhiteBalanceShader.java
com.af.experiments.FxCameraApp.shaders.GlXRayShader.java
com.af.experiments.FxCameraApp.shaders.GlXYDerivativeShader.java
com.af.experiments.FxCameraApp.shaders.fx.GlLutShader.java