Android Open Source - FxCameraApp My Activity






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;
// w  w w.ja va 2 s . c o m
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.View;
import android.widget.*;
import com.af.experiments.FxCameraApp.Utils.Fps;
import com.af.experiments.FxCameraApp.View.CameraView;
import com.af.experiments.FxCameraApp.View.GlPreview;
import com.af.experiments.FxCameraApp.camera.CameraHelper;
import com.af.experiments.FxCameraApp.shaders.*;
import com.af.experiments.FxCameraApp.shaders.fx.GlLutShader;

import java.io.*;
import java.util.ArrayList;

public class MyActivity extends Activity {

    private CameraView mCameraView;
    private GlPreview mPreview;
    private ImageView photoView;
    private ArrayList<GlShader> shaders;

    private ListView listView;
    private FilterAdapter filterAdapter;

    private GlShader mCurrentShader;
    private ProgressBar mProgress;

    private android.os.Handler mHandler;

    @Override
    protected void onCreate(final Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.main);

        mHandler = new android.os.Handler();
        mProgress = (ProgressBar) findViewById(R.id.progress);

        final TextView fpsTextView = (TextView) findViewById(R.id.fps_tv);

        mPreview = new GlPreview(this);
        mPreview.setFps( new Fps(new Fps.Callback() {
            @Override
            public void onFps(int fps) {
                fpsTextView.setText("fps: " + fps);
            }
        }));

        listView = (ListView) findViewById(R.id.shaders_list);
        shaders = new ArrayList<GlShader>();

        mCurrentShader = new GlShader();
        shaders.add(new GlShader());
        shaders.add(new GlColorInvertShader());
        shaders.add(new GlFalseColorShader());
        shaders.add(new GlXRayShader());

        shaders.add(new GlBilateralShader());
        shaders.add(new GlBoxBlurShader());
        shaders.add(new GlBulgeDistortionShader());
        shaders.add(new GlCGAColorspaceShader());
        //shaders.add(new GlColorPackingShader());
        //shaders.add(new GlConvolutionShader());
        shaders.add(new GlEmbossShader());
        shaders.add(new GlFastBlurShader());
        shaders.add(new GlGaussianBlurShader());
        //shaders.add(new GlHarrisCornerDetectionShader());
        shaders.add(new GlMonochromeShader());
        //shaders.add(new GlNobleCornerDetectionShader());
        //shaders.add(new GlPerlinNoiseShader());
        shaders.add(new GlPinchDistortionShader());
        shaders.add(new GlPixellateShader());
        shaders.add(new GlPolarPixellateShader());
        shaders.add(new GlPolkaDotShader());
        shaders.add(new GlPosterizeShader());

        shaders.add(new GlSharpenShader());
        //shaders.add(new GlShiTomasiFeatureDetectionShader());
        shaders.add(new GlSphereRefractionShader());
        shaders.add(new GlStretchDistortionShader());
        //shaders.add(new GlToneShader());
        shaders.add(new GlVignetteShader());
        //shaders.add(new GlWeakPixelInclusionShader());


        //shaders.add(new GlXYDerivativeShader());

        shaders.add(new GlGlassSphereShader());
        shaders.add(new GlGrayScaleShader());
        shaders.add(new GlSepiaShader());
        shaders.add(new GlSobelEdgeDetectionShader());

        shaders.add(new GlLutShader(getResources(), R.drawable.filtershow_fx_0000_vintage, "vintage"));
        shaders.add(new GlLutShader(getResources(), R.drawable.filtershow_fx_0001_instant, "instant"));
        shaders.add(new GlLutShader(getResources(), R.drawable.filtershow_fx_0002_bleach, "bleach"));
        shaders.add(new GlLutShader(getResources(), R.drawable.filtershow_fx_0003_blue_crush, "blue"));
        shaders.add(new GlLutShader(getResources(), R.drawable.filtershow_fx_0004_bw_contrast, "bw contrast"));
        shaders.add(new GlLutShader(getResources(), R.drawable.filtershow_fx_0005_punch, "punch"));
        shaders.add(new GlLutShader(getResources(), R.drawable.filtershow_fx_0006_x_process, "x process"));
        shaders.add(new GlLutShader(getResources(), R.drawable.filtershow_fx_0007_washout, "latte"));
        shaders.add(new GlLutShader(getResources(), R.drawable.filtershow_fx_0008_washout_color, "latte color"));

        filterAdapter = new FilterAdapter(this, R.layout.rowlayout, shaders);

        listView.setAdapter(filterAdapter);
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
                mCurrentShader = shaders.get(position);
                mPreview.setShader(mCurrentShader);
            }
        });

        photoView = (ImageView) findViewById(R.id.photo_view);
        photoView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
//                photoView.setVisibility(View.GONE);
//                mCameraView.setVisibility(View.VISIBLE);

            }
        });

        findViewById(R.id.resetButton).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mCameraView.startPreview();
            }
        });

        findViewById(R.id.catch_button).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mProgress.setVisibility(View.VISIBLE);
                mCameraView.capture(new CameraView.CaptureCallback() {
                    @Override
                    public boolean onImageCapture(Bitmap bitmap) {

                        mCameraView.stopPreview();
                        SaveImageTask task = new SaveImageTask();
                        task.execute(bitmap);
                        return true;
                    }
                });
            }
        });
    }

    class SaveImageTask extends AsyncTask<Bitmap, Void, Boolean> {

        @Override
        protected Boolean doInBackground(Bitmap... bitmaps) {
            Bitmap bitmap = bitmaps[0];
            saveBitmap(bitmap);
            return true;
        }

        private void saveBitmap( Bitmap bitmap) {
            File imagesFolder = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "/fxCameraApp");
            if (!imagesFolder.exists()) {
                imagesFolder.mkdirs();
            }
            String path = imagesFolder.getAbsolutePath() + "/fx_" + System.currentTimeMillis() + ".jpg";
            Log.d("face_rec", "saved face is " + path);

            File file = new File(path);
            ByteArrayOutputStream bytes = new ByteArrayOutputStream();
            bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
            FileOutputStream out = null;
            try {
                out = new FileOutputStream(file);
                out.write(bytes.toByteArray());
                out.flush();
                out.close();
                Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
                Uri contentUri = Uri.fromFile(file);
                mediaScanIntent.setData(contentUri);
                MyActivity.this.sendBroadcast(mediaScanIntent);
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        @Override
        protected void onPostExecute(Boolean result) {
            mProgress.setVisibility(View.GONE);
            mCameraView.startPreview();
            mPreview.setShader(mCurrentShader);
        }
    }

    @Override
    protected void onResume() {
        super.onResume();

        if (mCameraView != null ) {
            mCameraView.setPreview(mPreview);
            mHandler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    mCameraView.startPreview();
                }
            }, 1000);
        }
    }

    @Override
    protected void onPause() {
        if (mCameraView != null) {
            mCameraView.stopPreview();
        }
        super.onPause();
    }

    @Override
    public void onContentChanged() {
        super.onContentChanged();
        mCameraView = (CameraView) findViewById(R.id.camera);
        mCameraView.setPreview(mPreview);

        mCameraView.setPreviewSizePolicy(CameraView.PreviewSizePolicy.DISPLAY);

    }


    public CameraView getCameraView() {
        return mCameraView;
    }

    public CameraHelper getCameraHelper() {
        return mCameraView.getCameraHelper();
    }
}




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