diff --git a/android/.idea/misc.xml b/android/.idea/misc.xml index 37a7509..9ed052d 100644 --- a/android/.idea/misc.xml +++ b/android/.idea/misc.xml @@ -1,9 +1,35 @@ - - + + + - - \ No newline at end of file diff --git a/android/.idea/modules.xml b/android/.idea/modules.xml index bcc6c01..abc31fc 100644 --- a/android/.idea/modules.xml +++ b/android/.idea/modules.xml @@ -2,7 +2,7 @@ - + diff --git a/android/.idea/vcs.xml b/android/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/android/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/android/app/build.gradle b/android/app/build.gradle index 0fa6e10..09b66e1 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -16,6 +16,10 @@ android { proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } + compileOptions { + sourceCompatibility = '1.8' + targetCompatibility = '1.8' + } } dependencies { @@ -25,4 +29,6 @@ dependencies { testImplementation 'junit:junit:4.12' androidTestImplementation 'com.android.support.test:runner:1.0.2' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' + implementation 'com.android.support:cardview-v7:26.1.0' + implementation 'com.android.support:recyclerview-v7:26.1.0' } diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index 23ab039..edc85c5 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -2,6 +2,8 @@ + + - + + + + + + + \ No newline at end of file diff --git a/android/app/src/main/java/com/krokogator/photoeat/ArchiveActivity.java b/android/app/src/main/java/com/krokogator/photoeat/ArchiveActivity.java new file mode 100644 index 0000000..4b2fd5a --- /dev/null +++ b/android/app/src/main/java/com/krokogator/photoeat/ArchiveActivity.java @@ -0,0 +1,13 @@ +package com.krokogator.photoeat; + +import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; + +public class ArchiveActivity extends AppCompatActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_archive); + } +} diff --git a/android/app/src/main/java/com/krokogator/photoeat/MainActivity.java b/android/app/src/main/java/com/krokogator/photoeat/MainActivity.java index 79926fc..321ccb2 100644 --- a/android/app/src/main/java/com/krokogator/photoeat/MainActivity.java +++ b/android/app/src/main/java/com/krokogator/photoeat/MainActivity.java @@ -1,13 +1,103 @@ package com.krokogator.photoeat; -import android.support.v7.app.AppCompatActivity; +import android.content.Intent; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.net.Uri; import android.os.Bundle; +import android.os.Environment; +import android.provider.MediaStore; +import android.support.v4.content.FileProvider; +import android.support.v7.app.AppCompatActivity; +import android.util.Log; +import android.view.View; +import android.widget.Button; +import android.widget.ImageView; + +import java.io.File; +import java.io.IOException; +import java.text.SimpleDateFormat; +import java.util.Date; public class MainActivity extends AppCompatActivity { + static final int REQUEST_TAKE_PHOTO = 1; + + ImageView photo_preview; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); + + Button btnCamera = (Button) findViewById(R.id.button_take_photo); + Button btnArchive = (Button) findViewById(R.id.button_archive); + + btnCamera.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + dispatchTakePictureIntent(); +// System.out.println(getPic().getHeight()); + + } + }); + + btnArchive.setOnClickListener((view) -> { + Intent intent = new Intent(this, ArchiveActivity.class); + startActivity(intent); + }); + + + } + + static final int REQUEST_IMAGE_CAPTURE = 1; + + String mCurrentPhotoPath; + + private File createImageFile() throws IOException { + // Create an image file name + String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); + String imageFileName = "JPEG_" + timeStamp + "_"; + File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES); + File image = File.createTempFile( + imageFileName, /* prefix */ + ".jpg", /* suffix */ + storageDir /* directory */ + ); + + // Save a file: path for use with ACTION_VIEW intents + mCurrentPhotoPath = image.getAbsolutePath(); + return image; + } + + private void dispatchTakePictureIntent() { + Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); + // Ensure that there's a camera activity to handle the intent + if (takePictureIntent.resolveActivity(getPackageManager()) != null) { + // Create the File where the photo should go + File photoFile = null; + try { + photoFile = createImageFile(); + } catch (IOException ex) { + // Error occurred while creating the File + } + // Continue only if the File was successfully created + if (photoFile != null) { + Uri photoURI = FileProvider.getUriForFile(this, + "com.krokogator.photoeat.android.fileprovider", + photoFile); + takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI); + startActivityForResult(takePictureIntent, REQUEST_TAKE_PHOTO); + } + } + } + + @Override + protected void onActivityResult(int requestCode, int resultCode, Intent data) { + if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) { + Intent previewPhotoIntent = new Intent(this, PhotoPreviewActivity.class); + previewPhotoIntent.putExtra("imagePath", mCurrentPhotoPath); + startActivity(previewPhotoIntent); + } } } diff --git a/android/app/src/main/java/com/krokogator/photoeat/PhotoPreviewActivity.java b/android/app/src/main/java/com/krokogator/photoeat/PhotoPreviewActivity.java new file mode 100644 index 0000000..e9b6d74 --- /dev/null +++ b/android/app/src/main/java/com/krokogator/photoeat/PhotoPreviewActivity.java @@ -0,0 +1,91 @@ +package com.krokogator.photoeat; + +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.graphics.Matrix; +import android.media.ExifInterface; +import android.media.Image; +import android.os.Bundle; +import android.support.annotation.Nullable; +import android.support.v7.app.AppCompatActivity; +import android.util.Log; +import android.widget.ImageView; + +import java.util.logging.Logger; + +public class PhotoPreviewActivity extends AppCompatActivity { + + @Override + protected void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.photo_previev); + + String imagePath = (String) getIntent().getExtras().get("imagePath"); + ImageView preview = findViewById(R.id.photo_preview); + preview.setImageBitmap(getPic(imagePath)); + } + + private Bitmap getPic(String picPath) { + // Get the dimensions of the View + int targetW = 800; + int targetH = 1200; + + // Get the dimensions of the bitmap + BitmapFactory.Options bmOptions = new BitmapFactory.Options(); + bmOptions.inJustDecodeBounds = true; + BitmapFactory.decodeFile(picPath, bmOptions); + int photoW = bmOptions.outWidth; + int photoH = bmOptions.outHeight; + + // Determine how much to scale down the image + int scaleFactor = Math.min(photoW/targetW, photoH/targetH); + + // Decode the image file into a Bitmap sized to fill the View + bmOptions.inJustDecodeBounds = false; + bmOptions.inSampleSize = scaleFactor; + bmOptions.inPurgeable = true; + + Bitmap bitmap = BitmapFactory.decodeFile(picPath, bmOptions); + bitmap = getCorrectlyRotated(picPath, bitmap); + + return bitmap; + } + + private Bitmap getCorrectlyRotated(String imagePath, Bitmap bitmap){ + // Rotate Image if Needed + try + { + // Determine Orientation + ExifInterface exif = new ExifInterface(imagePath); + int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 1); + + // Determine Rotation + int rotation = 0; + if (orientation == 6) rotation = 90; + else if (orientation == 3) rotation = 180; + else if (orientation == 8) rotation = 270; + + // Rotate Image if Necessary + if (rotation != 0) + { + // Create Matrix + Matrix matrix = new Matrix(); + matrix.postRotate(rotation); + + // Rotate Bitmap + Bitmap rotated = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); + + // Pretend none of this ever happened! + bitmap.recycle(); + bitmap = rotated; + rotated = null; + } + } + catch (Exception e) + { + // TODO: Log Error Messages Here + } + + return bitmap; + } +} diff --git a/android/app/src/main/res/layout/activity_archive.xml b/android/app/src/main/res/layout/activity_archive.xml new file mode 100644 index 0000000..cd10185 --- /dev/null +++ b/android/app/src/main/res/layout/activity_archive.xml @@ -0,0 +1,334 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/android/app/src/main/res/layout/activity_main.xml b/android/app/src/main/res/layout/activity_main.xml index 22ea485..bcb09db 100644 --- a/android/app/src/main/res/layout/activity_main.xml +++ b/android/app/src/main/res/layout/activity_main.xml @@ -6,13 +6,57 @@ android:layout_height="match_parent" tools:context="com.krokogator.photoeat.MainActivity"> - + +