package com.bhegarty.imagefixer;

import android.Manifest;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.SurfaceView;
import android.view.View;
import android.view.WindowManager;

import org.opencv.android.BaseLoaderCallback;
import org.opencv.android.CameraBridgeViewBase;
import org.opencv.android.LoaderCallbackInterface;
import org.opencv.android.OpenCVLoader;
import org.opencv.android.Utils;
import org.opencv.core.Mat;
import org.opencv.core.Point;
import org.opencv.imgproc.Imgproc;

public class MainActivity extends Activity /*implements CameraBridgeViewBase.CvCameraViewListener2*/ {

    static final int REQUEST_IMAGE_CAPTURE = 1;
    static Uri uri;

    private static final String LOG_TAG = MainActivity.class.getSimpleName();
//    private CameraBridgeViewBase mOpenCvCameraView;

    static {
        System.loadLibrary("opencv_java3");
    }

//    @Override
//    public void onResume()
//    {
//        super.onResume();
//        if (isCameraPermissionGranted()) {
////            mOpenCvCameraView.enableView();
//            Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
//            if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
//                startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
//            }
//        }
//    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
        setContentView(R.layout.activity_main);

        if (isCameraPermissionGranted()) {
//            mOpenCvCameraView.enableView();
            Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
                startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
            }
        }
//        mOpenCvCameraView = (CameraBridgeViewBase) findViewById(R.id.MainCameraView);
//        mOpenCvCameraView.setVisibility(SurfaceView.VISIBLE);
//        mOpenCvCameraView.setCvCameraViewListener(this);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        Log.v(LOG_TAG, "onActivityResult: " + resultCode);
        if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
            Log.v(LOG_TAG, "Result Okay");

//            Bundle extras = data.getExtras();
//            Bitmap imageBitmap = (Bitmap) extras.get("data");

            Intent intent = new Intent(MainActivity.this, ImageActivity.class);
//            intent.putExtra("image", imageBitmap);
            startActivity(intent);
        }
    }

//    @Override
//    public void onPause()
//    {
//        super.onPause();
////        if (mOpenCvCameraView != null)
////            mOpenCvCameraView.disableView();
//    }
//
//    public void onDestroy() {
//        super.onDestroy();
////        if (mOpenCvCameraView != null)
////            mOpenCvCameraView.disableView();
//    }
//
//    public void onCameraViewStarted(int width, int height) {
//    }
//
//    public void onCameraViewStopped() {
//    }

//    public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {
//        Mat inputImage = inputFrame.rgba();
////        Mat newImage = mOpenCvCameraView.getRotation()
//        int height = inputFrame.rgba().height();
//        int width = inputFrame.rgba().width();
//
//        Mat newImage = Imgproc.getRotationMatrix2D(new Point(width/2, height/2), 90, 1);
//
//        Log.i(LOG_TAG, "HEIGHT: " + inputFrame.rgba().height());
//        Log.i(LOG_TAG, "WIDTH: " + inputFrame.rgba().width());
////        return inputFrame.rgba();
//        return newImage;
//    }

    public boolean isCameraPermissionGranted() {
        if (Build.VERSION.SDK_INT >= 23) {
            if (checkSelfPermission(Manifest.permission.CAMERA)
                    == PackageManager.PERMISSION_GRANTED) {
                Log.v(LOG_TAG, "Permission is granted");
                return true;
            } else {

                Log.v(LOG_TAG, "Permission is revoked");
                ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.CAMERA}, 1);
                return false;
            }
        } else { //permission is automatically granted on sdk<23 upon installation
            Log.v(LOG_TAG, "Permission is granted");
            return true;
        }
    }
}

@@ -265,39 +265,8 @@
 le;%0A
-import android.os.Environment;%0A
 impo
@@ -362,574 +362,96 @@
 oid.
-support.v7.app.AppCompatActivity;%0Aimport android.util.Log;%0Aimport android.view.SurfaceView;%0Aimport android.view.View;%0Aimport android.view.WindowManager;%0A%0Aimport org.opencv.android.BaseLoaderCallback;%0Aimport org.opencv.android.CameraBridgeViewBase;%0Aimport org.opencv.android.LoaderCallbackInterface;%0Aimport org.opencv.android.OpenCVLoader;%0Aimport org.opencv.android.Utils;%0Aimport org.opencv.core.Mat;%0Aimport org.opencv.core.Point;%0Aimport org.opencv.imgproc.Imgproc;%0A%0Apublic class MainActivity extends Activity /*implements CameraBridgeViewBase.CvCameraViewListener2*/
+util.Log;%0Aimport android.view.WindowManager;%0A%0Apublic class MainActivity extends Activity
  %7B%0A%0A
@@ -600,62 +600,8 @@
 e();
-%0A//    private CameraBridgeViewBase mOpenCvCameraView;
 %0A%0A  
@@ -666,473 +666,8 @@
  %7D%0A%0A
-//    @Override%0A//    public void onResume()%0A//    %7B%0A//        super.onResume();%0A//        if (isCameraPermissionGranted()) %7B%0A////            mOpenCvCameraView.enableView();%0A//            Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);%0A//            if (takePictureIntent.resolveActivity(getPackageManager()) != null) %7B%0A//                startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);%0A//            %7D%0A//        %7D%0A//    %7D%0A%0A
     
@@ -951,54 +951,8 @@
 ) %7B%0A
-//            mOpenCvCameraView.enableView();%0A
     
@@ -1223,219 +1223,8 @@
   %7D%0A
-//        mOpenCvCameraView = (CameraBridgeViewBase) findViewById(R.id.MainCameraView);%0A//        mOpenCvCameraView.setVisibility(SurfaceView.VISIBLE);%0A//        mOpenCvCameraView.setCvCameraViewListener(this);%0A
     
@@ -1506,18 +1506,16 @@
 kay%22);%0A%0A
-//
         
@@ -1548,26 +1548,24 @@
 etExtras();%0A
-//
             
@@ -1695,18 +1695,16 @@
 class);%0A
-//
         
@@ -1802,1071 +1802,8 @@
  %7D%0A%0A
-//    @Override%0A//    public void onPause()%0A//    %7B%0A//        super.onPause();%0A////        if (mOpenCvCameraView != null)%0A////            mOpenCvCameraView.disableView();%0A//    %7D%0A//%0A//    public void onDestroy() %7B%0A//        super.onDestroy();%0A////        if (mOpenCvCameraView != null)%0A////            mOpenCvCameraView.disableView();%0A//    %7D%0A//%0A//    public void onCameraViewStarted(int width, int height) %7B%0A//    %7D%0A//%0A//    public void onCameraViewStopped() %7B%0A//    %7D%0A%0A//    public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) %7B%0A//        Mat inputImage = inputFrame.rgba();%0A////        Mat newImage = mOpenCvCameraView.getRotation()%0A//        int height = inputFrame.rgba().height();%0A//        int width = inputFrame.rgba().width();%0A//%0A//        Mat newImage = Imgproc.getRotationMatrix2D(new Point(width/2, height/2), 90, 1);%0A//%0A//        Log.i(LOG_TAG, %22HEIGHT: %22 + inputFrame.rgba().height());%0A//        Log.i(LOG_TAG, %22WIDTH: %22 + inputFrame.rgba().width());%0A////        return inputFrame.rgba();%0A//        return newImage;%0A//    %7D%0A%0A
     

Add image bitmap to intent extra & tided up class