Skip to content

Commit

Permalink
Modifications for displaying full-screen intent
Browse files Browse the repository at this point in the history
  • Loading branch information
WrichikBasu committed Jan 27, 2021
1 parent 848c0d1 commit 9fb80e3
Showing 1 changed file with 29 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ public void onReceive(Context context, Intent intent) {
@Override
public int onStartCommand(Intent intent, int flags, int startId) {

alarmDetails = Objects.requireNonNull(Objects.requireNonNull(intent.getExtras()).getBundle(ConstantsAndStatics.BUNDLE_KEY_ALARM_DETAILS));

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
startForeground(NOTIFICATION_ID, buildRingNotification(), ServiceInfo.FOREGROUND_SERVICE_TYPE_NONE);
} else {
Expand All @@ -149,9 +151,6 @@ public int onStartCommand(Intent intent, int flags, int startId) {
isShakeActive = sharedPreferences.getInt(ConstantsAndStatics.SHARED_PREF_KEY_DEFAULT_SHAKE_OPERATION,
ConstantsAndStatics.SNOOZE) != ConstantsAndStatics.DO_NOTHING;

alarmDetails = Objects.requireNonNull(intent.getExtras()).getBundle(ConstantsAndStatics.BUNDLE_KEY_ALARM_DETAILS);
assert alarmDetails != null;

alarmID = alarmDetails.getInt(ConstantsAndStatics.BUNDLE_KEY_ALARM_ID);

// Kill Service_SnoozeAlarm if it is running for a different alarm.
Expand Down Expand Up @@ -233,9 +232,10 @@ public void onDestroy() {
/**
* Reads the repeat days from alarm database.
* <p>
* I have received some crash reports from Google Play stating that {@code NullPointerException} is being thrown in {@code dismissAlarm()} at
* the statement {@code Collections.sort(repeatDays)}. It seems that even if repeat is ON, the repeat days list is null. That is why we are
* re-reading the repeat days from the database as a temporary fix.
* I have received some crash reports from Google Play stating that {@code NullPointerException} is being thrown in {@code dismissAlarm()} at the
* statement {@code Collections.sort(repeatDays)}. It seems that even if repeat is ON, the repeat days list is null. That is why we are
* re-reading
* the repeat days from the database as a temporary fix.
* </p>
*/
private void loadRepeatDays() {
Expand Down Expand Up @@ -292,37 +292,33 @@ private void createNotificationChannel() {
private Notification buildRingNotification() {
createNotificationChannel();

NotificationCompat.Builder builder = new NotificationCompat.Builder(this,
Integer.toString(NOTIFICATION_ID))
Intent fullScreenIntent = new Intent(this, Activity_RingAlarm.class)
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK)
.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY).putExtras(alarmDetails);

PendingIntent fullScreenPendingIntent = PendingIntent.getActivity(this, 3054, fullScreenIntent, PendingIntent.FLAG_UPDATE_CURRENT);

String alarmMessage = alarmDetails.getString(ConstantsAndStatics.BUNDLE_KEY_ALARM_MESSAGE, null);

NotificationCompat.Builder builder = new NotificationCompat.Builder(this, Integer.toString(NOTIFICATION_ID))
.setContentTitle(getResources().getString(R.string.app_name))
.setContentText("Initialising alarm...")
.setPriority(NotificationCompat.PRIORITY_MAX)
.setCategory(NotificationCompat.CATEGORY_ALARM)
.setSmallIcon(R.drawable.ic_notif);

// Launch the full-screen intent only when called by ringAlarm() method.
if (alarmDetails != null) {
Intent fullScreenIntent = new Intent(this, Activity_RingAlarm.class)
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK)
.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY).putExtras(alarmDetails);

PendingIntent fullScreenPendingIntent = PendingIntent.getActivity(this, 3054, fullScreenIntent, PendingIntent.FLAG_UPDATE_CURRENT);

String alarmMessage = alarmDetails.getString(ConstantsAndStatics.BUNDLE_KEY_ALARM_MESSAGE, null);

builder.setContentIntent(fullScreenPendingIntent)
.setFullScreenIntent(fullScreenPendingIntent, true);

if (alarmMessage != null) {
builder.setContentTitle(getString(R.string.app_name) + ": " + "Alarm ringing!")
.setContentText(alarmMessage.substring(10))
.setStyle(new NotificationCompat.BigTextStyle().bigText(alarmMessage));
} else {
builder.setContentText(getString(R.string.notifContent_ring));
}
.setSmallIcon(R.drawable.ic_notif)
.setContentIntent(fullScreenPendingIntent)
.setFullScreenIntent(fullScreenPendingIntent, true);

if (alarmMessage != null) {
builder.setContentTitle(getString(R.string.app_name))
.setContentText(alarmMessage)
.setStyle(new NotificationCompat.BigTextStyle().bigText(alarmMessage));
} else {
builder.setContentText(getString(R.string.notifContent_ring));
}


return builder.build();
}

Expand Down Expand Up @@ -535,8 +531,8 @@ private void setAlarm(@NonNull LocalDateTime alarmDateTime) {
//---------------------------------------------------------------------------------------------------

/**
* While testing, we found that sometimes, the alarm was being reset at a later date unintentionally. This function cancels such an
* unintentional alarm.
* While testing, we found that sometimes, the alarm was being reset at a later date unintentionally. This function cancels such an unintentional
* alarm.
*/
private void cancelPendingIntent() {

Expand Down

0 comments on commit 9fb80e3

Please sign in to comment.