Show auto silence view
This commit is contained in:
parent
d845f241e9
commit
29194f241f
@ -1,6 +1,9 @@
|
||||
package com.philliphsu.clock2.alarms;
|
||||
|
||||
import android.app.Notification;
|
||||
import android.app.NotificationManager;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.NotificationCompat;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.philliphsu.clock2.Alarm;
|
||||
@ -8,10 +11,13 @@ import com.philliphsu.clock2.R;
|
||||
import com.philliphsu.clock2.ringtone.RingtoneActivity;
|
||||
import com.philliphsu.clock2.ringtone.RingtoneService;
|
||||
import com.philliphsu.clock2.util.AlarmController;
|
||||
import com.philliphsu.clock2.util.DateFormatUtils;
|
||||
|
||||
public class AlarmActivity extends RingtoneActivity<Alarm> {
|
||||
private static final String TAG = "TimesUpActivity";
|
||||
|
||||
private AlarmController mAlarmController;
|
||||
private NotificationManager mNotificationManager;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@ -20,6 +26,13 @@ public class AlarmActivity extends RingtoneActivity<Alarm> {
|
||||
// TODO: If the upcoming alarm notification isn't present, verify other notifications aren't affected.
|
||||
// This could be the case if we're starting a new instance of this activity after leaving the first launch.
|
||||
mAlarmController.removeUpcomingAlarmNotification(getRingingObject());
|
||||
mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void finish() {
|
||||
super.finish();
|
||||
mNotificationManager.cancel(TAG, getRingingObject().getIntId());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -75,4 +88,20 @@ public class AlarmActivity extends RingtoneActivity<Alarm> {
|
||||
mAlarmController.cancelAlarm(getRingingObject(), false);
|
||||
stopAndFinish();
|
||||
}
|
||||
|
||||
// TODO: Consider changing the return type to Notification, and move the actual
|
||||
// task of notifying to the base class.
|
||||
@Override
|
||||
protected void showAutoSilenced() {
|
||||
super.showAutoSilenced();
|
||||
// Post notification that alarm was missed
|
||||
String alarmTime = DateFormatUtils.formatTime(this,
|
||||
getRingingObject().hour(), getRingingObject().minutes());
|
||||
Notification note = new NotificationCompat.Builder(this)
|
||||
.setContentTitle(getString(R.string.missed_alarm))
|
||||
.setContentText(alarmTime)
|
||||
.setSmallIcon(R.mipmap.ic_launcher)
|
||||
.build();
|
||||
mNotificationManager.notify(TAG, getRingingObject().getIntId(), note);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
package com.philliphsu.clock2.alarms;
|
||||
|
||||
import android.app.Notification;
|
||||
import android.app.NotificationManager;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.support.v4.app.NotificationCompat;
|
||||
@ -20,7 +19,6 @@ public class AlarmRingtoneService extends RingtoneService<Alarm> {
|
||||
private static final String ACTION_SNOOZE = "com.philliphsu.clock2.ringtone.action.SNOOZE";
|
||||
private static final String ACTION_DISMISS = "com.philliphsu.clock2.ringtone.action.DISMISS";
|
||||
|
||||
private String mNormalRingTime;
|
||||
private AlarmController mAlarmController;
|
||||
|
||||
@Override
|
||||
@ -52,14 +50,6 @@ public class AlarmRingtoneService extends RingtoneService<Alarm> {
|
||||
protected void onAutoSilenced() {
|
||||
// TODO do we really need to cancel the alarm and intent?
|
||||
mAlarmController.cancelAlarm(getRingingObject(), false);
|
||||
// Post notification that alarm was missed
|
||||
NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
|
||||
Notification note = new NotificationCompat.Builder(this)
|
||||
.setContentTitle(getString(R.string.missed_alarm))
|
||||
.setContentText(mNormalRingTime)
|
||||
.setSmallIcon(R.mipmap.ic_launcher)
|
||||
.build();
|
||||
nm.notify(TAG, getRingingObject().getIntId(), note);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -72,12 +62,11 @@ public class AlarmRingtoneService extends RingtoneService<Alarm> {
|
||||
String title = getRingingObject().label().isEmpty()
|
||||
? getString(R.string.alarm)
|
||||
: getRingingObject().label();
|
||||
mNormalRingTime = formatTime(this, System.currentTimeMillis()); // now
|
||||
return new NotificationCompat.Builder(this)
|
||||
// Required contents
|
||||
.setSmallIcon(R.mipmap.ic_launcher) // TODO: alarm icon
|
||||
.setContentTitle(title)
|
||||
.setContentText(mNormalRingTime)
|
||||
.setContentText(formatTime(this, System.currentTimeMillis()))
|
||||
.addAction(R.mipmap.ic_launcher, // TODO: correct icon
|
||||
getString(R.string.snooze),
|
||||
getPendingIntent(ACTION_SNOOZE, getRingingObject().getIntId()))
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package com.philliphsu.clock2.ringtone;
|
||||
|
||||
import android.app.NotificationManager;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
@ -9,6 +10,7 @@ import android.support.annotation.DrawableRes;
|
||||
import android.support.annotation.StringRes;
|
||||
import android.support.design.widget.FloatingActionButton;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.GridLayout;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.WindowManager;
|
||||
@ -33,13 +35,16 @@ public abstract class RingtoneActivity<T extends Parcelable> extends AppCompatAc
|
||||
// Shared with RingtoneService
|
||||
public static final String ACTION_FINISH = "com.philliphsu.clock2.ringtone.action.FINISH";
|
||||
public static final String EXTRA_RINGING_OBJECT = "com.philliphsu.clock2.ringtone.extra.RINGING_OBJECT";
|
||||
public static final String ACTION_SHOW_SILENCED = "com.philliphsu.clock2.ringtone.action.SHOW_SILENCED";
|
||||
|
||||
private static boolean sIsAlive = false;
|
||||
private T mRingingObject;
|
||||
|
||||
@Bind(R.id.title) TextView mHeaderTitle;
|
||||
@Bind(R.id.auto_silenced_container) LinearLayout mAutoSilencedContainer;
|
||||
@Bind(R.id.auto_silenced_text) TextView mAutoSilencedText;
|
||||
@Bind(R.id.ok) Button mOkButton;
|
||||
@Bind(R.id.buttons_container) GridLayout mButtonsContainer;
|
||||
@Bind(R.id.btn_left) FloatingActionButton mLeftButton;
|
||||
@Bind(R.id.btn_right) FloatingActionButton mRightButton;
|
||||
|
||||
@ -104,6 +109,7 @@ public abstract class RingtoneActivity<T extends Parcelable> extends AppCompatAc
|
||||
// TODO: Do we need this anymore? I think this broadcast was only sent from
|
||||
// EditAlarmActivity?
|
||||
LocalBroadcastHelper.registerReceiver(this, mFinishReceiver, ACTION_FINISH);
|
||||
LocalBroadcastHelper.registerReceiver(this, mOnAutoSilenceReceiver, ACTION_SHOW_SILENCED);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -112,11 +118,13 @@ public abstract class RingtoneActivity<T extends Parcelable> extends AppCompatAc
|
||||
// TODO: Do we need this anymore? I think this broadcast was only sent from
|
||||
// EditAlarmActivity?
|
||||
LocalBroadcastHelper.unregisterReceiver(this, mFinishReceiver);
|
||||
LocalBroadcastHelper.unregisterReceiver(this, mOnAutoSilenceReceiver);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onNewIntent(Intent intent) {
|
||||
//super.onNewIntent(intent); // Not needed since no fragments hosted?
|
||||
|
||||
// TODO: Do we need this anymore? I think the broadcast that calls through to
|
||||
// this was only sent from EditAlarmActivity?
|
||||
|
||||
@ -162,6 +170,13 @@ public abstract class RingtoneActivity<T extends Parcelable> extends AppCompatAc
|
||||
sIsAlive = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@OnClick(R.id.ok)
|
||||
public void finish() {
|
||||
super.finish();
|
||||
NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
|
||||
}
|
||||
|
||||
public static boolean isAlive() {
|
||||
return sIsAlive;
|
||||
}
|
||||
@ -179,6 +194,11 @@ public abstract class RingtoneActivity<T extends Parcelable> extends AppCompatAc
|
||||
return mRingingObject;
|
||||
}
|
||||
|
||||
protected void showAutoSilenced() {
|
||||
mAutoSilencedContainer.setVisibility(View.VISIBLE);
|
||||
mButtonsContainer.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
// TODO: Do we need this anymore? I think this broadcast was only sent from
|
||||
// EditAlarmActivity?
|
||||
private final BroadcastReceiver mFinishReceiver = new BroadcastReceiver() {
|
||||
@ -187,4 +207,11 @@ public abstract class RingtoneActivity<T extends Parcelable> extends AppCompatAc
|
||||
stopAndFinish();
|
||||
}
|
||||
};
|
||||
|
||||
private final BroadcastReceiver mOnAutoSilenceReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
showAutoSilenced();
|
||||
}
|
||||
};
|
||||
}
|
||||
@ -52,9 +52,7 @@ public abstract class RingtoneService<T extends Parcelable> extends Service {
|
||||
@Override
|
||||
public void run() {
|
||||
onAutoSilenced();
|
||||
// TODO: Consider not finishing the activity, but update
|
||||
// its view to display that this ringing was missed?
|
||||
finishActivity();
|
||||
LocalBroadcastHelper.sendBroadcast(RingtoneService.this, RingtoneActivity.ACTION_SHOW_SILENCED);
|
||||
stopSelf();
|
||||
}
|
||||
};
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
package com.philliphsu.clock2.timers;
|
||||
|
||||
import android.app.Notification;
|
||||
import android.app.NotificationManager;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.provider.Settings;
|
||||
@ -51,14 +50,6 @@ public class TimerRingtoneService extends RingtoneService<Timer> {
|
||||
@Override
|
||||
protected void onAutoSilenced() {
|
||||
mController.stop();
|
||||
// Post notification that alarm was missed
|
||||
NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
|
||||
Notification note = new NotificationCompat.Builder(this)
|
||||
.setContentTitle(getString(R.string.timer_expired))
|
||||
.setContentText(getRingingObject().label())
|
||||
.setSmallIcon(R.mipmap.ic_launcher) // TODO: correct icon
|
||||
.build();
|
||||
nm.notify(TAG, getRingingObject().getIntId(), note);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -1,8 +1,11 @@
|
||||
package com.philliphsu.clock2.timers;
|
||||
|
||||
import android.app.Notification;
|
||||
import android.app.NotificationManager;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.SystemClock;
|
||||
import android.support.v4.app.NotificationCompat;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.philliphsu.clock2.R;
|
||||
@ -11,12 +14,22 @@ import com.philliphsu.clock2.ringtone.RingtoneActivity;
|
||||
import com.philliphsu.clock2.ringtone.RingtoneService;
|
||||
|
||||
public class TimesUpActivity extends RingtoneActivity<Timer> {
|
||||
private static final String TAG = "TimesUpActivity";
|
||||
|
||||
private NotificationManager mNotificationManager;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
stopService(new Intent(this, TimerNotificationService.class));
|
||||
TimerNotificationService.cancelNotification(this, getRingingObject().getId());
|
||||
mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void finish() {
|
||||
super.finish();
|
||||
mNotificationManager.cancel(TAG, getRingingObject().getIntId());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -75,4 +88,17 @@ public class TimesUpActivity extends RingtoneActivity<Timer> {
|
||||
protected void onRightButtonClick() {
|
||||
|
||||
}
|
||||
|
||||
// TODO: Consider changing the return type to Notification, and move the actual
|
||||
// task of notifying to the base class.
|
||||
@Override
|
||||
protected void showAutoSilenced() {
|
||||
super.showAutoSilenced();
|
||||
Notification note = new NotificationCompat.Builder(this)
|
||||
.setContentTitle(getString(R.string.timer_expired))
|
||||
.setContentText(getRingingObject().label())
|
||||
.setSmallIcon(R.mipmap.ic_launcher) // TODO: correct icon
|
||||
.build();
|
||||
mNotificationManager.notify(TAG, getRingingObject().getIntId(), note);
|
||||
}
|
||||
}
|
||||
|
||||
@ -22,6 +22,7 @@
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/auto_silenced_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
@ -48,6 +49,7 @@
|
||||
</LinearLayout>
|
||||
|
||||
<android.support.v7.widget.GridLayout
|
||||
android:id="@+id/buttons_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom"
|
||||
|
||||
Loading…
Reference in New Issue
Block a user