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