Android Open Source - FxCameraApp Camera Helper Eclair






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 ava 2  s.  c  o  m*/
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import android.content.Context;
import android.hardware.Camera;

public class CameraHelperEclair extends CameraHelperDonut implements Camera.AutoFocusCallback {

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

    @Override
    public void setDisplayOrientation(final int degrees) {
        final Camera.Parameters params = getCamera().getParameters();
        params.setRotation(degrees);
        try {
            getCamera().setParameters(params);
        } catch (final RuntimeException e) {
        }
    }

    @Override
    public void initializeFocusMode() {
        final List<String> supportedFocusModes = getSupportedFocusModes();
        if (supportedFocusModes != null) {
            final Camera.Parameters parameters = getCamera().getParameters();
            if (supportedFocusModes.contains(Camera.Parameters.FOCUS_MODE_AUTO)) {
                parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO);
                try {
                    getCamera().setParameters(parameters);
                } catch (final RuntimeException e) {}  // ??????
            } else if (supportedFocusModes.contains(Camera.Parameters.FOCUS_MODE_INFINITY)) {
                parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_INFINITY);
                try {
                    getCamera().setParameters(parameters);
                } catch (final RuntimeException e) {}  // ??????
            } else {
                super.initializeFocusMode();
            }
        }
    }

    @Override
    public void takePicture(final Camera.PictureCallback callback, final boolean autoFocus) {
        setPictureCallback(callback);

        if (autoFocus) {
            getCamera().autoFocus(this);
        } else {
            takePicture(getCamera());
        }
    }

    @Override
    public final void cancelAutoFocus() {
        getCamera().cancelAutoFocus();
    }

    protected void takePicture(final Camera camera) {
        camera.setPreviewCallback(null);
        System.gc();

        camera.takePicture(mEnableShutterSound ? mNoopShutterCallback : null, null, null, this);
    }

    @Override
    public final void onAutoFocus(final boolean success, final Camera camera) {
//    camera.cancelAutoFocus();
        takePicture(camera);
    }

    @Override
    public List<Camera.Size> getSupportedPreviewSizes() {
        final List<Camera.Size> results = getCamera().getParameters().getSupportedPreviewSizes();
        Collections.sort(results, new CameraSizeComparator());
        return results;
    }

    @Override
    public List<Camera.Size> getSupportedPictureSizes() {
        final List<Camera.Size> results = getCamera().getParameters().getSupportedPictureSizes();
        Collections.sort(results, new CameraSizeComparator());
        return results;
    }

    @Override
    public String getAntibanding() {
        return getCamera().getParameters().getAntibanding();
    }

    @Override
    public String getColorEffect() {
        return getCamera().getParameters().getColorEffect();
    }
    @Override
    public String getFlashMode() {
        return getCamera().getParameters().getFlashMode();
    }

    @Override
    public String getFocusMode() {
        return getCamera().getParameters().getFocusMode();
    }

    @Override
    public String getSceneMode() {
        return getCamera().getParameters().getSceneMode();
    }

    @Override
    public String getWhiteBalance() {
        return getCamera().getParameters().getWhiteBalance();
    }

    @Override
    public List<String> getSupportedAntibanding() {
        return getCamera().getParameters().getSupportedAntibanding();
    }

    @Override
    public List<String> getSupportedColorEffects() {
        return getCamera().getParameters().getSupportedColorEffects();
    }

    @Override
    public List<String> getSupportedFlashModes() {
        return getCamera().getParameters().getSupportedFlashModes();
    }

    @Override
    public List<String> getSupportedFocusModes() {
        return getCamera().getParameters().getSupportedFocusModes();
    }

    @Override
    public List<String> getSupportedSceneModes() {
        return getCamera().getParameters().getSupportedSceneModes();
    }

    @Override
    public List<String> getSupportedWhiteBalance() {
        return getCamera().getParameters().getSupportedWhiteBalance();
    }

    @Override
    public List<String> getSupportedAntibanding(final String... values) {
        return getContainsList(getCamera().getParameters().getSupportedAntibanding(), values);
    }

    @Override
    public List<String> getSupportedColorEffects(final String... values) {
        return getContainsList(getCamera().getParameters().getSupportedColorEffects(), values);
    }

    @Override
    public List<String> getSupportedFlashModes(final String... values) {
        return getContainsList(getCamera().getParameters().getSupportedFlashModes(), values);
    }

    @Override
    public List<String> getSupportedFocusModes(final String... values) {
        return getContainsList(getCamera().getParameters().getSupportedFocusModes(), values);
    }

    @Override
    public List<String> getSupportedSceneModes(final String... values) {
        return getContainsList(getCamera().getParameters().getSupportedSceneModes(), values);
    }

    @Override
    public List<String> getSupportedWhiteBalance(final String... values) {
        return getContainsList(getCamera().getParameters().getSupportedWhiteBalance(), values);
    }

    private static List<String> getContainsList(final List<String> list, final String... values) {
        if (list == null) {
            return null;
        }

        final ArrayList<String> results = new ArrayList<String>();
        for (final String value : values) {
            if (list.contains(value)) {
                results.add(value);
            }
        }
        if (results.isEmpty()) {
            return null;
        }
        return results;
    }

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

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

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

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

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

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

    @Override
    public String switchAntibanding() {
        return switchAntibanding(getSupportedAntibanding());
    }
    @Override
    public String switchAntibanding(final String... values) {
        return switchAntibanding(getSupportedAntibanding(values));
    }
    private String switchAntibanding(final List<String> list) {
        final String value = getNextValue(list, getAntibanding());
        if (value != null) {
            setAntibanding(value);
        }
        return value;
    }

    @Override
    public String switchColorEffect() {
        return switchColorEffect(getSupportedColorEffects());
    }
    @Override
    public String switchColorEffect(final String... values) {
        return switchColorEffect(getSupportedColorEffects(values));
    }
    private String switchColorEffect(final List<String> list) {
        final String value = getNextValue(list, getColorEffect());
        if (value != null) {
            setColorEffect(value);
        }
        return value;
    }

    @Override
    public String switchFlashMode() {
        return switchFlashMode(getSupportedFlashModes());
    }
    @Override
    public String switchFlashMode(final String... values) {
        return switchFlashMode(getSupportedFlashModes(values));
    }
    private String switchFlashMode(final List<String> list) {
        final String value = getNextValue(list, getFlashMode());
        if (value != null) {
            setFlashMode(value);
        }
        return value;
    }

    @Override
    public String switchFocusMode() {
        return switchFocusMode(getSupportedFocusModes());
    }
    @Override
    public String switchFocusMode(final String... values) {
        return switchFocusMode(getSupportedFocusModes(values));
    }
    private String switchFocusMode(final List<String> list) {
        final String value = getNextValue(list, getFocusMode());
        if (value != null) {
            setFocusMode(value);
        }
        return value;
    }

    @Override
    public String switchSceneMode() {
        return switchSceneMode(getSupportedSceneModes());
    }
    @Override
    public String switchSceneMode(final String... values) {
        return switchSceneMode(getSupportedSceneModes(values));
    }
    private String switchSceneMode(final List<String> list) {
        final String value = getNextValue(list, getSceneMode());
        if (value != null) {
            setSceneMode(value);
        }
        return value;
    }

    @Override
    public String switchWhiteBalance() {
        return switchWhiteBalance(getSupportedWhiteBalance());
    }
    @Override
    public String switchWhiteBalance(final String... values) {
        return switchWhiteBalance(getSupportedWhiteBalance(values));
    }
    private String switchWhiteBalance(final List<String> list) {
        final String value = getNextValue(list, getWhiteBalance());
        if (value != null) {
            setWhiteBalance(value);
        }
        return value;
    }

    private static String getNextValue(final List<String> list, final String value) {
        if (list != null && list.size() > 1) {
            final int index = list.indexOf(value);
            final String result;
            if (index != -1) {
                result = list.get((index + 1) % list.size());
            } else {
                result = list.get(0);
            }
            return result;
        }
        return null;
    }

}




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