package flickr.usth.edu.com;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class CameraActivity extends AppCompatActivity {

    // LogCat tag
    private static final String TAG = CameraActivity.class.getSimpleName();


    // Camera activity request codes
    private static final int CAMERA_CAPTURE_IMAGE_REQUEST_CODE = 100;
    private static final int CAMERA_CAPTURE_VIDEO_REQUEST_CODE = 200;

    public static final int MEDIA_TYPE_IMAGE = 1;
    public static final int MEDIA_TYPE_VIDEO = 2;

    private Uri fileUri; // file url to store image/video

    private Button btnCapturePicture, btnRecordVideo;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_camera);

        // Changing action bar background color
        // These two lines are not needed
        getActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor(getResources().getString(R.color.action_bar))));

        btnCapturePicture = (Button) findViewById(R.id.btnCapturePicture);
        btnRecordVideo = (Button) findViewById(R.id.btnRecordVideo);
    }
}

@@ -1632,16 +1632,2391 @@
 dVideo);
+%0A%0A//        Capture image onClick%0A        btnCapturePicture.setOnClickListener(new View.OnClickListener() %7B%0A%0A            @Override%0A            public void onClick(View v) %7B%0A                // capture picture%0A                captureImage();%0A            %7D%0A        %7D);%0A%0A//        Record video onClick%0A        btnRecordVideo.setOnClickListener(new View.OnClickListener() %7B%0A%0A            @Override%0A            public void onClick(View v) %7B%0A                // record video%0A                recordVideo();%0A            %7D%0A        %7D);%0A%0A        // Checking camera availability%0A        if (!isDeviceSupportCamera()) %7B%0A            Toast.makeText(getApplicationContext(),%0A                    %22Sorry! Your device doesn't support camera%22,%0A                    Toast.LENGTH_LONG).show();%0A            // will close the app if the device does't have camera%0A            finish();%0A        %7D%0A    %7D%0A%0A    // Launch camera%0A    private void captureImage() %7B%0A        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);%0A%0A        fileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE);%0A%0A        intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);%0A%0A        // start the image capture Intent%0A        startActivityForResult(intent, CAMERA_CAPTURE_IMAGE_REQUEST_CODE);%0A    %7D%0A%0A    /**%0A     * Launching camera app to record video%0A     */%0A    private void recordVideo() %7B%0A        Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);%0A%0A        fileUri = getOutputMediaFileUri(MEDIA_TYPE_VIDEO);%0A%0A        // set video quality%0A        intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);%0A%0A        intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri); // set the image file%0A        // name%0A%0A        // start the video capture Intent%0A        startActivityForResult(intent, CAMERA_CAPTURE_VIDEO_REQUEST_CODE);%0A    %7D%0A%0A    /**%0A     * Store the file url as it will be null after returning from camera%0A     */%0A    @Override%0A    protected void onSaveInstanceState(Bundle outState) %7B%0A        super.onSaveInstanceState(outState);%0A%0A        // save file url in bundle as it will be null on screen orientation%0A        // changes%0A        outState.putParcelable(%22file_uri%22, fileUri);%0A    %7D%0A%0A    @Override%0A    protected void onRestoreInstanceState(Bundle savedInstanceState) %7B%0A        super.onRestoreInstanceState(savedInstanceState);%0A%0A        // get the file url%0A        fileUri = savedInstanceState.getParcelable(%22file_uri%22);
 %0A    %7D%0A%7D

add event for camera button, check camera availability