package com.mm214.tonyapplication;

import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import java.io.File;
import android.content.Intent;
import android.net.Uri;
import android.os.Environment;
import android.provider.MediaStore;
import android.view.View;
import android.content.ContentValues;
import android.widget.Toast;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.app.Dialog;

import android.content.Intent;
import android.database.Cursor;
import android.os.AsyncTask;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.LoaderManager.LoaderCallbacks;
import android.support.v4.content.CursorLoader;
import android.support.v4.content.Loader;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends ActionBarActivity {
    static int TAKE_PICTURE = 1;
    Uri outputFileUri;
    final Context context = this;
    SQLiteDatabase mydb;
    public String lastId;
    public String picName;
    /** Database name */
    final myDBClass myDb = new myDBClass(this);




    /** A constant, stores the the table name */
    private static final String DATABASE_TABLE = "locations";



    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }













    public void btnTakePhoto(View view) {
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        long seconds = System.currentTimeMillis() / 1000;
        String pic = Long.toString(seconds);
        picName = pic + ".jpg";
        File file = new File(Environment.getExternalStorageDirectory()  , picName);
        outputFileUri = Uri.fromFile(file);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
        startActivityForResult(intent, TAKE_PICTURE);
    }






    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == TAKE_PICTURE && resultCode == RESULT_OK) {
            Toast.makeText(this, outputFileUri.toString(), Toast.LENGTH_LONG).show();
            myDb.InsertData(picName,  outputFileUri.toString());

        }

    }
}
