Add a grayscale image for the large notification icon.

This commit is contained in:
Timothy Allen 2014-03-26 14:01:58 +02:00
parent 08b09b110b
commit be115f4c7f
11 changed files with 43 additions and 28 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

View File

@ -14,9 +14,6 @@ import android.view.Window;
import android.view.WindowManager; import android.view.WindowManager;
import android.widget.Button; import android.widget.Button;
import java.util.Timer;
import java.util.TimerTask;
// TODO See GlowPad. // TODO See GlowPad.
// TODO sound audible alarm -- see AlarmKlaxon.java // TODO sound audible alarm -- see AlarmKlaxon.java
@ -25,13 +22,11 @@ import java.util.TimerTask;
public class AlarmAlertActivity extends Activity { public class AlarmAlertActivity extends Activity {
// TODO correct alert lifetime // 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 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 Boolean userCancelled;
private static Vibrator vibrator;
private static Intent notifyIntent;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -57,13 +52,12 @@ public class AlarmAlertActivity extends Activity {
// Turn off the alert activity, and switch to a notification // Turn off the alert activity, and switch to a notification
new Handler().postDelayed(new Runnable() { new Handler().postDelayed(new Runnable() {
public void run() { public void run() {
// Close the dialogue and switch to notification
// if the Activity has not been closed by the user
if (!userCancelled) { if (!userCancelled) {
// Close the dialogue and switch to notification
// if the Activity has not been closed by the user
finish();
startService(notifyIntent); startService(notifyIntent);
finish();
} }
Log.d("AlarmAlertActivity", "Started notification");
} }
}, ALERT_LIFE); }, ALERT_LIFE);
} }
@ -82,21 +76,42 @@ public class AlarmAlertActivity extends Activity {
cancelButton.setOnClickListener (new View.OnClickListener() { cancelButton.setOnClickListener (new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
graceManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); cancelGraceAlarm();
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();
} }
}); });
} }
/**
* 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() { public void onStop() {
vibrator.cancel(); vibrator.cancel();
super.onStop(); 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();
}
} }

View File

@ -9,13 +9,14 @@ import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.BitmapFactory; 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.os.IBinder;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.util.Log; import android.util.Log;
import java.util.Timer;
import java.util.TimerTask;
public class AlarmNotify extends Service { public class AlarmNotify extends Service {
public static final int notifyID = 1; public static final int notifyID = 1;
private volatile boolean threadRunning = false; private volatile boolean threadRunning = false;
@ -45,7 +46,7 @@ public class AlarmNotify extends Service {
final long endTime = System.currentTimeMillis() + (gracePeriod * 60 * 1000); final long endTime = System.currentTimeMillis() + (gracePeriod * 60 * 1000);
//Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.alarm_notification); //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 NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
final Notification.Builder notification = new Notification.Builder(this) final Notification.Builder notification = new Notification.Builder(this)
.setContentTitle(getString(R.string.app_name)) .setContentTitle(getString(R.string.app_name))
@ -93,7 +94,6 @@ public class AlarmNotify extends Service {
if (!threadRunning) { if (!threadRunning) {
return; return;
} }
//Log.d("AlarmNotify", "secondsLeft is "+secondsLeft+" and progress is "+progress+" (gracePeriodSeconds is "+gracePeriodSeconds+")");
int minutesLeft = secondsLeft / 60; int minutesLeft = secondsLeft / 60;
notification.setContentText(String.format(getString(R.string.notificationText), MainActivity.MinutesToGracePeriodStr(minutesLeft))); notification.setContentText(String.format(getString(R.string.notificationText), MainActivity.MinutesToGracePeriodStr(minutesLeft)));
notification.setProgress(max, progress, false); notification.setProgress(max, progress, false);
@ -103,6 +103,7 @@ public class AlarmNotify extends Service {
secondsLeft = secondsLeft - (UPDATE_INTERVAL / 1000); secondsLeft = secondsLeft - (UPDATE_INTERVAL / 1000);
// Multiply each int by 1000 for greater progress resolution // Multiply each int by 1000 for greater progress resolution
progress = (((gracePeriodSeconds * 1000) - (secondsLeft * 1000)) * max) / (gracePeriodSeconds * 1000); 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 // Sleeps the thread, simulating an operation
// that takes time // that takes time
try { try {
@ -117,5 +118,4 @@ public class AlarmNotify extends Service {
return super.onStartCommand(intent, flags, startId); return super.onStartCommand(intent, flags, startId);
} }
} }

View File

@ -302,7 +302,7 @@ public class MainActivity extends ActionBarActivity {
if (alarmActive) { if (alarmActive) {
// Initialise alarm, which displays a dialog and system alert, and // 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. // which in turn, sends SMS if dialog is not exited.
alarmManager = (AlarmManager) getActivity().getSystemService(Context.ALARM_SERVICE); alarmManager = (AlarmManager) getActivity().getSystemService(Context.ALARM_SERVICE);
Intent alarmIntent = new Intent(getActivity(), AlarmReceiver.class); Intent alarmIntent = new Intent(getActivity(), AlarmReceiver.class);

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB