diff --git a/GlowPadBackport/src/main/res/drawable-hdpi/ic_launcher.png b/GlowPadBackport/src/main/res/drawable-hdpi/ic_launcher.png new file mode 100644 index 0000000..96a442e Binary files /dev/null and b/GlowPadBackport/src/main/res/drawable-hdpi/ic_launcher.png differ diff --git a/GlowPadBackport/src/main/res/drawable-mdpi/ic_launcher.png b/GlowPadBackport/src/main/res/drawable-mdpi/ic_launcher.png new file mode 100644 index 0000000..359047d Binary files /dev/null and b/GlowPadBackport/src/main/res/drawable-mdpi/ic_launcher.png differ diff --git a/GlowPadBackport/src/main/res/drawable-xhdpi/ic_launcher.png b/GlowPadBackport/src/main/res/drawable-xhdpi/ic_launcher.png new file mode 100644 index 0000000..71c6d76 Binary files /dev/null and b/GlowPadBackport/src/main/res/drawable-xhdpi/ic_launcher.png differ diff --git a/GlowPadBackport/src/main/res/drawable-xxhdpi/ic_launcher.png b/GlowPadBackport/src/main/res/drawable-xxhdpi/ic_launcher.png new file mode 100644 index 0000000..4df1894 Binary files /dev/null and b/GlowPadBackport/src/main/res/drawable-xxhdpi/ic_launcher.png differ diff --git a/HypoAlarm/src/main/java/za/org/treehouse/hypoalarm/AlarmAlertActivity.java b/HypoAlarm/src/main/java/za/org/treehouse/hypoalarm/AlarmAlertActivity.java index 7afaebe..dfb3e80 100644 --- a/HypoAlarm/src/main/java/za/org/treehouse/hypoalarm/AlarmAlertActivity.java +++ b/HypoAlarm/src/main/java/za/org/treehouse/hypoalarm/AlarmAlertActivity.java @@ -14,9 +14,6 @@ import android.view.Window; import android.view.WindowManager; import android.widget.Button; -import java.util.Timer; -import java.util.TimerTask; - // TODO See GlowPad. // TODO sound audible alarm -- see AlarmKlaxon.java @@ -25,13 +22,11 @@ import java.util.TimerTask; public class AlarmAlertActivity extends Activity { // TODO correct alert lifetime - private static final int ALERT_LIFE = 1000*10;//1000*60*2; // 2 minutes + private static final int ALERT_LIFE = 1000*10; //1000*60*2; // 2 minutes private static final long[] vPattern = {500, 500}; - private static AlarmManager graceManager; - private static PendingIntent gracePendingIntent; - private static Intent notifyIntent; - private static Vibrator vibrator; private static Boolean userCancelled; + private static Vibrator vibrator; + private static Intent notifyIntent; @Override protected void onCreate(Bundle savedInstanceState) { @@ -57,13 +52,12 @@ public class AlarmAlertActivity extends Activity { // Turn off the alert activity, and switch to a notification new Handler().postDelayed(new Runnable() { public void run() { + // Close the dialogue and switch to notification + // if the Activity has not been closed by the user if (!userCancelled) { - // Close the dialogue and switch to notification - // if the Activity has not been closed by the user - finish(); startService(notifyIntent); + finish(); } - Log.d("AlarmAlertActivity", "Started notification"); } }, ALERT_LIFE); } @@ -82,21 +76,42 @@ public class AlarmAlertActivity extends Activity { cancelButton.setOnClickListener (new View.OnClickListener() { @Override public void onClick(View view) { - graceManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); - Intent graceIntent = new Intent(getApplicationContext(), GraceReceiver.class); - gracePendingIntent = PendingIntent.getBroadcast(getApplicationContext(), MainActivity.GRACE_REQUEST, graceIntent, 0); - graceManager.cancel(gracePendingIntent); - Log.d("AlarmAlertActivity", "Cancelled grace alarm."); - // Ensure we don't load a notification now - userCancelled = true; - // Close the dialogue (stop vibration &c) - finish(); + cancelGraceAlarm(); } }); } + /** + * Handle the user pressing the back/return button + * TODO Do we want this to cancel the alarm and grace period? + * TODO Or do we trigger the notification and finish() right away? + * TODO probably most intuitive to cancel the alarms... + */ + @Override + public void onBackPressed() { + cancelGraceAlarm(); + /* OR: + // Ensure that the we don't trigger the notification a second time + userCancelled = true; + startService(notifyIntent); + finish(); + */ + } + public void onStop() { vibrator.cancel(); super.onStop(); } + + private void cancelGraceAlarm() { + AlarmManager graceManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); + Intent graceIntent = new Intent(getApplicationContext(), GraceReceiver.class); + PendingIntent gracePendingIntent = PendingIntent.getBroadcast(getApplicationContext(), MainActivity.GRACE_REQUEST, graceIntent, 0); + graceManager.cancel(gracePendingIntent); + Log.d("AlarmAlertActivity", "Cancelled grace alarm."); + // Ensure we don't load a notification now + userCancelled = true; + // Close the dialogue (stop vibration &c) + finish(); + } } \ No newline at end of file diff --git a/HypoAlarm/src/main/java/za/org/treehouse/hypoalarm/AlarmNotify.java b/HypoAlarm/src/main/java/za/org/treehouse/hypoalarm/AlarmNotify.java index fd4cc17..a58840c 100644 --- a/HypoAlarm/src/main/java/za/org/treehouse/hypoalarm/AlarmNotify.java +++ b/HypoAlarm/src/main/java/za/org/treehouse/hypoalarm/AlarmNotify.java @@ -9,13 +9,14 @@ import android.content.Intent; import android.content.SharedPreferences; import android.graphics.Bitmap; import android.graphics.BitmapFactory; +import android.graphics.Canvas; +import android.graphics.ColorMatrix; +import android.graphics.ColorMatrixColorFilter; +import android.graphics.Paint; import android.os.IBinder; import android.preference.PreferenceManager; import android.util.Log; -import java.util.Timer; -import java.util.TimerTask; - public class AlarmNotify extends Service { public static final int notifyID = 1; private volatile boolean threadRunning = false; @@ -45,7 +46,7 @@ public class AlarmNotify extends Service { final long endTime = System.currentTimeMillis() + (gracePeriod * 60 * 1000); //Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.alarm_notification); - Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher); + Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.ic_grayscale); final NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); final Notification.Builder notification = new Notification.Builder(this) .setContentTitle(getString(R.string.app_name)) @@ -93,7 +94,6 @@ public class AlarmNotify extends Service { if (!threadRunning) { return; } - //Log.d("AlarmNotify", "secondsLeft is "+secondsLeft+" and progress is "+progress+" (gracePeriodSeconds is "+gracePeriodSeconds+")"); int minutesLeft = secondsLeft / 60; notification.setContentText(String.format(getString(R.string.notificationText), MainActivity.MinutesToGracePeriodStr(minutesLeft))); notification.setProgress(max, progress, false); @@ -103,6 +103,7 @@ public class AlarmNotify extends Service { secondsLeft = secondsLeft - (UPDATE_INTERVAL / 1000); // Multiply each int by 1000 for greater progress resolution progress = (((gracePeriodSeconds * 1000) - (secondsLeft * 1000)) * max) / (gracePeriodSeconds * 1000); + Log.d("AlarmNotify", "secondsLeft is "+secondsLeft+" and progress is "+progress+" (gracePeriodSeconds is "+gracePeriodSeconds+")"); // Sleeps the thread, simulating an operation // that takes time try { @@ -117,5 +118,4 @@ public class AlarmNotify extends Service { return super.onStartCommand(intent, flags, startId); } - } diff --git a/HypoAlarm/src/main/java/za/org/treehouse/hypoalarm/MainActivity.java b/HypoAlarm/src/main/java/za/org/treehouse/hypoalarm/MainActivity.java index 68428b3..dd9ec28 100644 --- a/HypoAlarm/src/main/java/za/org/treehouse/hypoalarm/MainActivity.java +++ b/HypoAlarm/src/main/java/za/org/treehouse/hypoalarm/MainActivity.java @@ -302,7 +302,7 @@ public class MainActivity extends ActionBarActivity { if (alarmActive) { // Initialise alarm, which displays a dialog and system alert, and - // calls CountDownTimer (or AlarmManager?) with grace_period as the delay + // calls AlarmManager with grace_period as the delay // which in turn, sends SMS if dialog is not exited. alarmManager = (AlarmManager) getActivity().getSystemService(Context.ALARM_SERVICE); Intent alarmIntent = new Intent(getActivity(), AlarmReceiver.class); diff --git a/HypoAlarm/src/main/res/drawable-hdpi/ic_grayscale.png b/HypoAlarm/src/main/res/drawable-hdpi/ic_grayscale.png new file mode 100644 index 0000000..3770d92 Binary files /dev/null and b/HypoAlarm/src/main/res/drawable-hdpi/ic_grayscale.png differ diff --git a/HypoAlarm/src/main/res/drawable-mdpi/ic_grayscale.png b/HypoAlarm/src/main/res/drawable-mdpi/ic_grayscale.png new file mode 100644 index 0000000..36695f2 Binary files /dev/null and b/HypoAlarm/src/main/res/drawable-mdpi/ic_grayscale.png differ diff --git a/HypoAlarm/src/main/res/drawable-xhdpi/ic_grayscale.png b/HypoAlarm/src/main/res/drawable-xhdpi/ic_grayscale.png new file mode 100644 index 0000000..9f90a90 Binary files /dev/null and b/HypoAlarm/src/main/res/drawable-xhdpi/ic_grayscale.png differ diff --git a/HypoAlarm/src/main/res/drawable-xxhdpi/ic_grayscale.png b/HypoAlarm/src/main/res/drawable-xxhdpi/ic_grayscale.png new file mode 100644 index 0000000..507ba5c Binary files /dev/null and b/HypoAlarm/src/main/res/drawable-xxhdpi/ic_grayscale.png differ