From d8789a55b987001597a59cb1cd615f0d01c2d47b Mon Sep 17 00:00:00 2001 From: Matt Boutell Date: Sat, 30 Jan 2016 16:06:43 -0500 Subject: [PATCH 1/6] Done camera launch --- .../edu/rosehulman/photomessage/MainActivity.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/PhotoMessage/app/src/main/java/edu/rosehulman/photomessage/MainActivity.java b/PhotoMessage/app/src/main/java/edu/rosehulman/photomessage/MainActivity.java index 513c1f3..2f82db1 100644 --- a/PhotoMessage/app/src/main/java/edu/rosehulman/photomessage/MainActivity.java +++ b/PhotoMessage/app/src/main/java/edu/rosehulman/photomessage/MainActivity.java @@ -124,6 +124,11 @@ public boolean onTouchEvent(MotionEvent event) { private void takePhoto() { Log.d(LOG, "takePhoto() started"); // TODO: Launch an activity using the camera intent + Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); + Uri uri = PhotoUtils.getOutputMediaUri(getString(R.string.app_name)); + cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, uri); + startActivityForResult(cameraIntent, RC_PHOTO_ACTIVITY); + mPhotoMessage.setPath(uri.getPath()); } private void loadFromGallery() { @@ -141,7 +146,12 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == RC_PHOTO_ACTIVITY) { Log.d(LOG, "back from taking a photo"); // TODO: Get and show the bitmap - + mBitmap = BitmapFactory.decodeFile(mPhotoMessage.getPath()); + //Use the next 2 lines if your camera res is so high, it crashes your app + int width = 512, height = 512; + mBitmap = Bitmap.createScaledBitmap(mBitmap, width, height, true); + mImageView.setImageBitmap(mBitmap); + mCanSavePhoto = true; } if (requestCode == MainActivity.PICK_FROM_GALLERY_REQUEST) { From 016c23003cd377e791615bc2d17bd060b750e821 Mon Sep 17 00:00:00 2001 From: Matt Boutell Date: Sat, 30 Jan 2016 16:13:34 -0500 Subject: [PATCH 2/6] Gallery done --- .../rosehulman/photomessage/MainActivity.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/PhotoMessage/app/src/main/java/edu/rosehulman/photomessage/MainActivity.java b/PhotoMessage/app/src/main/java/edu/rosehulman/photomessage/MainActivity.java index 2f82db1..9d50739 100644 --- a/PhotoMessage/app/src/main/java/edu/rosehulman/photomessage/MainActivity.java +++ b/PhotoMessage/app/src/main/java/edu/rosehulman/photomessage/MainActivity.java @@ -30,7 +30,7 @@ public class MainActivity extends AppCompatActivity { static final String KEY_SOON_NOTIFICATION_ID = "KEY_SOON_NOTIFICATION_ID"; static final String KEY_NOTIFICATION = "KEY_NOTIFICATION"; private static final int RC_PHOTO_ACTIVITY = 1; - private static final int PICK_FROM_GALLERY_REQUEST = 2; + private static final int RC_PICK_FROM_GALLERY = 2; private static PhotoMessage mPhotoMessage = null; private boolean mCanSavePhoto = false; private Bitmap mBitmap; @@ -134,7 +134,8 @@ private void takePhoto() { private void loadFromGallery() { Log.d(LOG, "loadFromGallery() started"); // TODO: Launch the gallery to pick a photo from it. - + Intent galleryIntent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI); + startActivityForResult(galleryIntent, RC_PICK_FROM_GALLERY); } @Override @@ -154,10 +155,17 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) { mCanSavePhoto = true; } - if (requestCode == MainActivity.PICK_FROM_GALLERY_REQUEST) { + if (requestCode == MainActivity.RC_PICK_FROM_GALLERY) { Log.d(LOG, "Back from the gallery"); // TODO: Get and show the bitmap - + Uri uri = data.getData(); + String realPath = getRealPathFromUri(uri); + mBitmap = BitmapFactory.decodeFile(realPath); + int width = 512, height = 512; + mBitmap = Bitmap.createScaledBitmap(mBitmap, width, height, true); + mImageView.setImageBitmap(mBitmap); + mPhotoMessage.setPath(realPath); + mCanSavePhoto = false; } } From 9410911ea8b05bb5b47fdcfd96faf2567d4359ea Mon Sep 17 00:00:00 2001 From: Matt Boutell Date: Sat, 30 Jan 2016 17:55:02 -0500 Subject: [PATCH 3/6] Fix scaling issues in display --- .../DisplayLabeledPhotoActivity.java | 21 +++++++++---------- .../rosehulman/photomessage/MainActivity.java | 4 ++-- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/PhotoMessage/app/src/main/java/edu/rosehulman/photomessage/DisplayLabeledPhotoActivity.java b/PhotoMessage/app/src/main/java/edu/rosehulman/photomessage/DisplayLabeledPhotoActivity.java index 08f44d4..bb5dc7b 100644 --- a/PhotoMessage/app/src/main/java/edu/rosehulman/photomessage/DisplayLabeledPhotoActivity.java +++ b/PhotoMessage/app/src/main/java/edu/rosehulman/photomessage/DisplayLabeledPhotoActivity.java @@ -4,14 +4,11 @@ import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Color; -import android.net.Uri; import android.os.Bundle; import android.util.Log; import android.widget.ImageView; import android.widget.TextView; -import java.io.FileNotFoundException; - public class DisplayLabeledPhotoActivity extends Activity { @Override @@ -24,14 +21,16 @@ protected void onCreate(Bundle savedInstanceState) { ImageView imageView = (ImageView) findViewById(R.id.labeled_image_view); - Bitmap bitmap = null; - try { - Uri uri = Uri.parse(photoMessage.getPath()); - bitmap = BitmapFactory.decodeStream(getContentResolver().openInputStream(uri)); - } catch (FileNotFoundException e) { - Log.e(Constants.TAG, "Error: " + e); - } - // Bitmap bitmap = BitmapFactory.decodeFile(photoMessage.getUri()); +// Bitmap bitmap = null; +// try { +// Uri uri = Uri.parse(photoMessage.getPath()); +// bitmap = BitmapFactory.decodeStream(getContentResolver().openInputStream(uri)); +// } catch (FileNotFoundException e) { +// Log.e(Constants.TAG, "Error: " + e); +// } + Bitmap bitmap = BitmapFactory.decodeFile(photoMessage.getPath()); + bitmap = Bitmap.createScaledBitmap(bitmap, 512, 512, true); + imageView.setImageBitmap(bitmap); TextView messageTextView = (TextView) findViewById(R.id.labeled_text_view); diff --git a/PhotoMessage/app/src/main/java/edu/rosehulman/photomessage/MainActivity.java b/PhotoMessage/app/src/main/java/edu/rosehulman/photomessage/MainActivity.java index c7bdb21..8f0a19d 100644 --- a/PhotoMessage/app/src/main/java/edu/rosehulman/photomessage/MainActivity.java +++ b/PhotoMessage/app/src/main/java/edu/rosehulman/photomessage/MainActivity.java @@ -54,8 +54,6 @@ protected void onCreate(Bundle savedInstanceState) { R.mipmap.ic_launcher); // For debugging mBitmap = BitmapFactory.decodeFile("/storage/emulated/0/Pictures/PhotoMessage/IMG_20150810_132053.jpg"); - - mBitmap = Bitmap.createScaledBitmap(mBitmap, 512, 512, true); mImageView.setImageBitmap(mBitmap); mCanSavePhoto = true; @@ -132,6 +130,7 @@ private void takePhoto() { Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); Uri uri = PhotoUtils.getOutputMediaUri(getString(R.string.app_name)); cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, uri); + Log.d(Constants.TAG, "Path " + uri.getPath()); startActivityForResult(cameraIntent, RC_PHOTO_ACTIVITY); mPhotoMessage.setPath(uri.getPath()); } @@ -151,6 +150,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == RC_PHOTO_ACTIVITY) { Log.d(Constants.TAG, "back from taking a photo"); + Log.d(Constants.TAG, "Path " + mPhotoMessage.getPath()); // TODO: Get and show the bitmap mBitmap = BitmapFactory.decodeFile(mPhotoMessage.getPath()); //Use the next 2 lines if your camera res is so high, it crashes your app From dd9dd9e02e3a8bacfaea33360c9a557b174a9192 Mon Sep 17 00:00:00 2001 From: Matt Boutell Date: Mon, 1 Feb 2016 12:03:16 -0500 Subject: [PATCH 4/6] Add notification --- .../edu/rosehulman/photomessage/MainActivity.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/PhotoMessage/app/src/main/java/edu/rosehulman/photomessage/MainActivity.java b/PhotoMessage/app/src/main/java/edu/rosehulman/photomessage/MainActivity.java index 8f0a19d..522dd9c 100644 --- a/PhotoMessage/app/src/main/java/edu/rosehulman/photomessage/MainActivity.java +++ b/PhotoMessage/app/src/main/java/edu/rosehulman/photomessage/MainActivity.java @@ -1,5 +1,6 @@ package edu.rosehulman.photomessage; +import android.app.Notification; import android.content.Intent; import android.database.Cursor; import android.graphics.Bitmap; @@ -209,6 +210,17 @@ private void notifyNow() { } } + private Notification getNotification() { + return new Notification.Builder(this) + .setContentTitle(getString(R.string.notification_title)) + .setContentText(mPhotoMessage.getMessage()) + .setSmallIcon(android.R.drawable.ic_menu_camera) + .setLargeIcon(Bitmap.createBitmap(mBitmap, THUMBNAIL_SIZE, THUMBNAIL_SIZE, true)) + .build(); + } + + + private void notifyLater() { Log.d(Constants.TAG, "showLater() started"); DialogFragment df = new SetAlarmDialogFragment(); From ff1ca3d61327d49997983a399aca137eee2a11cb Mon Sep 17 00:00:00 2001 From: Matt Boutell Date: Mon, 1 Feb 2016 16:34:34 -0500 Subject: [PATCH 5/6] Finish notifications --- PhotoMessage/app/build.gradle | 2 +- PhotoMessage/app/src/main/AndroidManifest.xml | 6 +++ .../rosehulman/photomessage/MainActivity.java | 41 ++++++++++++++----- .../NotificationBroadcastReceiver.java | 24 +++++++++++ 4 files changed, 62 insertions(+), 11 deletions(-) create mode 100644 PhotoMessage/app/src/main/java/edu/rosehulman/photomessage/NotificationBroadcastReceiver.java diff --git a/PhotoMessage/app/build.gradle b/PhotoMessage/app/build.gradle index b8ce0a1..5655fda 100644 --- a/PhotoMessage/app/build.gradle +++ b/PhotoMessage/app/build.gradle @@ -6,7 +6,7 @@ android { defaultConfig { applicationId "edu.rosehulman.photomessage" - minSdkVersion 15 + minSdkVersion 16 targetSdkVersion 23 versionCode 1 versionName "1.0" diff --git a/PhotoMessage/app/src/main/AndroidManifest.xml b/PhotoMessage/app/src/main/AndroidManifest.xml index f636a11..94ff367 100644 --- a/PhotoMessage/app/src/main/AndroidManifest.xml +++ b/PhotoMessage/app/src/main/AndroidManifest.xml @@ -24,6 +24,12 @@ android:name=".DisplayLabeledPhotoActivity" android:label="@string/display_labeled_photo_activity_text" > + + + + + + diff --git a/PhotoMessage/app/src/main/java/edu/rosehulman/photomessage/MainActivity.java b/PhotoMessage/app/src/main/java/edu/rosehulman/photomessage/MainActivity.java index 522dd9c..e92eefe 100644 --- a/PhotoMessage/app/src/main/java/edu/rosehulman/photomessage/MainActivity.java +++ b/PhotoMessage/app/src/main/java/edu/rosehulman/photomessage/MainActivity.java @@ -1,6 +1,10 @@ package edu.rosehulman.photomessage; +import android.app.AlarmManager; import android.app.Notification; +import android.app.NotificationManager; +import android.app.PendingIntent; +import android.content.Context; import android.content.Intent; import android.database.Cursor; import android.graphics.Bitmap; @@ -8,6 +12,7 @@ import android.graphics.Color; import android.net.Uri; import android.os.Bundle; +import android.os.SystemClock; import android.provider.MediaStore; import android.support.v4.app.DialogFragment; import android.support.v4.content.CursorLoader; @@ -25,13 +30,15 @@ public class MainActivity extends AppCompatActivity { - static final String KEY_MESSAGE = "KEY_MESSAGE"; - static final String KEY_IMAGE_FILENAME = "KEY_IMAGE_FILENAME"; static final String KEY_PHOTO_MESSAGE = "KEY_PHOTO_MESSAGE"; static final String KEY_SOON_NOTIFICATION_ID = "KEY_SOON_NOTIFICATION_ID"; static final String KEY_NOTIFICATION = "KEY_NOTIFICATION"; private static final int RC_PHOTO_ACTIVITY = 1; private static final int RC_PICK_FROM_GALLERY = 2; + private static final int THUMBNAIL_SIZE = 96; + private static final int NOTIFICATION_ID = 1; + private static final int SOON_NOTIFICATION_ID = 2; + private static final int SECONDS_UNTIL_ALARM = 15; private static PhotoMessage mPhotoMessage = null; private boolean mCanSavePhoto = false; private Bitmap mBitmap; @@ -127,7 +134,7 @@ public boolean onTouchEvent(MotionEvent event) { private void takePhoto() { Log.d(Constants.TAG, "takePhoto() started"); - // TODO: Launch an activity using the camera intent + // DONE: Launch an activity using the camera intent Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); Uri uri = PhotoUtils.getOutputMediaUri(getString(R.string.app_name)); cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, uri); @@ -206,21 +213,26 @@ private void notifyNow() { Log.d(Constants.TAG, "setMessage message to send: " + mPhotoMessage); // TODO: Replace this with a notification. - startActivity(displayIntent); + // startActivity(displayIntent); + Notification notification = getNotification(displayIntent); + NotificationManager manager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE); + manager.notify(NOTIFICATION_ID, notification); } } - private Notification getNotification() { + private Notification getNotification(final Intent intent) { + int unusedRequestCode = 0; + PendingIntent pendingIntent = PendingIntent.getActivity(this, unusedRequestCode, intent, PendingIntent.FLAG_UPDATE_CURRENT); + return new Notification.Builder(this) .setContentTitle(getString(R.string.notification_title)) .setContentText(mPhotoMessage.getMessage()) .setSmallIcon(android.R.drawable.ic_menu_camera) - .setLargeIcon(Bitmap.createBitmap(mBitmap, THUMBNAIL_SIZE, THUMBNAIL_SIZE, true)) + .setLargeIcon(Bitmap.createScaledBitmap(mBitmap, THUMBNAIL_SIZE, THUMBNAIL_SIZE, true)) + .setContentIntent(pendingIntent) .build(); } - - private void notifyLater() { Log.d(Constants.TAG, "showLater() started"); DialogFragment df = new SetAlarmDialogFragment(); @@ -234,8 +246,17 @@ public void setSoonAlarm() { Log.d(Constants.TAG, "setMessage message to send: " + mPhotoMessage); // TODO: Replace this with a notification that launches via a timer. - startActivity(displayIntent); - } + // startActivity(displayIntent); + Notification notification = getNotification(displayIntent); + Intent notifictionIntent = new Intent(this, NotificationBroadcastReceiver.class); + notifictionIntent.putExtra(KEY_NOTIFICATION, notification); + notifictionIntent.putExtra(KEY_SOON_NOTIFICATION_ID, SOON_NOTIFICATION_ID); + int unusedRequestCode = 0; + PendingIntent pendingIntent = PendingIntent.getBroadcast(this, unusedRequestCode, notifictionIntent, PendingIntent.FLAG_UPDATE_CURRENT); + long futureInMillis = SystemClock.elapsedRealtime() + SECONDS_UNTIL_ALARM * 1000; + AlarmManager alarmManger = (AlarmManager)getSystemService(Context.ALARM_SERVICE); + alarmManger.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, futureInMillis, pendingIntent); + } public void setFixedAlarm(int hour, int minute) { // Pleaceholder if you wanted to try this out (totally optional) diff --git a/PhotoMessage/app/src/main/java/edu/rosehulman/photomessage/NotificationBroadcastReceiver.java b/PhotoMessage/app/src/main/java/edu/rosehulman/photomessage/NotificationBroadcastReceiver.java new file mode 100644 index 0000000..b72e43d --- /dev/null +++ b/PhotoMessage/app/src/main/java/edu/rosehulman/photomessage/NotificationBroadcastReceiver.java @@ -0,0 +1,24 @@ +package edu.rosehulman.photomessage; + +import android.app.Notification; +import android.app.NotificationManager; +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; + +/** + * Created by Matt Boutell on 2/1/2016. + * Rose-Hulman Institute of Technology. + * Covered by MIT license. + */ +public class NotificationBroadcastReceiver extends BroadcastReceiver { + + @Override + public void onReceive(Context context, Intent intent) { + NotificationManager manager = (NotificationManager) + context.getSystemService(Context.NOTIFICATION_SERVICE); + Notification notification = intent.getParcelableExtra(MainActivity.KEY_NOTIFICATION); + int id = intent.getIntExtra(MainActivity.KEY_SOON_NOTIFICATION_ID, 0); + manager.notify(id, notification); + } +} From 951060b50fe26783a9ee6e3265fcbd24d80fd1ac Mon Sep 17 00:00:00 2001 From: Matt Boutell Date: Wed, 17 Feb 2016 22:33:01 -0500 Subject: [PATCH 6/6] Fix typo --- .../java/edu/rosehulman/photomessage/MainActivity.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/PhotoMessage/app/src/main/java/edu/rosehulman/photomessage/MainActivity.java b/PhotoMessage/app/src/main/java/edu/rosehulman/photomessage/MainActivity.java index e92eefe..662ec86 100644 --- a/PhotoMessage/app/src/main/java/edu/rosehulman/photomessage/MainActivity.java +++ b/PhotoMessage/app/src/main/java/edu/rosehulman/photomessage/MainActivity.java @@ -248,11 +248,11 @@ public void setSoonAlarm() { // TODO: Replace this with a notification that launches via a timer. // startActivity(displayIntent); Notification notification = getNotification(displayIntent); - Intent notifictionIntent = new Intent(this, NotificationBroadcastReceiver.class); - notifictionIntent.putExtra(KEY_NOTIFICATION, notification); - notifictionIntent.putExtra(KEY_SOON_NOTIFICATION_ID, SOON_NOTIFICATION_ID); + Intent notificationIntent = new Intent(this, NotificationBroadcastReceiver.class); + notificationIntent.putExtra(KEY_NOTIFICATION, notification); + notificationIntent.putExtra(KEY_SOON_NOTIFICATION_ID, SOON_NOTIFICATION_ID); int unusedRequestCode = 0; - PendingIntent pendingIntent = PendingIntent.getBroadcast(this, unusedRequestCode, notifictionIntent, PendingIntent.FLAG_UPDATE_CURRENT); + PendingIntent pendingIntent = PendingIntent.getBroadcast(this, unusedRequestCode, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); long futureInMillis = SystemClock.elapsedRealtime() + SECONDS_UNTIL_ALARM * 1000; AlarmManager alarmManger = (AlarmManager)getSystemService(Context.ALARM_SERVICE); alarmManger.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, futureInMillis, pendingIntent);