allow snoozing or dismissing alarm by dragging the middle element

This commit is contained in:
tibbi 2018-07-08 15:40:15 +02:00
parent 9352fa0221
commit cde58b8c8c
3 changed files with 46 additions and 24 deletions

View File

@ -23,6 +23,7 @@ class ReminderActivity : SimpleActivity() {
private val increaseVolumeHandler = Handler()
private val maxReminderDurationHandler = Handler()
private var isAlarmReminder = false
private var didVibrate = false
private var alarm: Alarm? = null
private var mediaPlayer: MediaPlayer? = null
private var lastVolumeValue = 0.1f
@ -67,32 +68,50 @@ class ReminderActivity : SimpleActivity() {
reminder_draggable_background.applyColorFilter(getAdjustedPrimaryColor())
var minDragX = 0f
var maxDragX = 0f
var initialDraggableX = 0f
reminder_dismiss.onGlobalLayout {
minDragX = reminder_snooze.left.toFloat()
maxDragX = reminder_dismiss.left.toFloat()
initialDraggableX = reminder_draggable.left.toFloat()
}
reminder_draggable.setOnTouchListener { v, event ->
when (event.action) {
MotionEvent.ACTION_DOWN -> dragDownX = event.x
MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> dragDownX = 0f
MotionEvent.ACTION_DOWN -> {
dragDownX = event.x
reminder_draggable_background.animate().alpha(0f)
}
MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> {
dragDownX = 0f
if (!didVibrate) {
reminder_draggable.animate().x(initialDraggableX).withEndAction {
reminder_draggable_background.animate().alpha(0.2f)
}
}
}
MotionEvent.ACTION_MOVE -> {
reminder_draggable.x = Math.min(maxDragX, Math.max(minDragX, event.rawX - dragDownX))
if (reminder_draggable.x >= maxDragX - 50f) {
if (!didVibrate) {
reminder_draggable.performHapticFeedback()
}
didVibrate = true
finishActivity()
} else if (reminder_draggable.x <= minDragX + 50f) {
if (!didVibrate) {
reminder_draggable.performHapticFeedback()
}
didVibrate = true
snoozeAlarm()
}
}
}
true
}
reminder_dismiss.setOnClickListener {
finish()
}
reminder_snooze.beVisibleIf(isAlarmReminder)
reminder_snooze.applyColorFilter(config.textColor)
reminder_snooze.setOnClickListener {
snoozeClicked()
}
}
private fun setupAudio() {
@ -125,7 +144,7 @@ class ReminderActivity : SimpleActivity() {
override fun onNewIntent(intent: Intent?) {
super.onNewIntent(intent)
finish()
finishActivity()
}
override fun onDestroy() {
@ -141,12 +160,13 @@ class ReminderActivity : SimpleActivity() {
mediaPlayer = null
}
private fun snoozeClicked() {
private fun snoozeAlarm() {
destroyPlayer()
if (config.useSameSnooze) {
setupAlarmClock(alarm!!, config.snoozeTime * MINUTE_SECONDS)
finishActivity()
} else {
showPickSecondsDialog(config.snoozeTime * MINUTE_SECONDS, true) {
showPickSecondsDialog(config.snoozeTime * MINUTE_SECONDS, true, cancelCallback = { finishActivity() }) {
config.snoozeTime = it / MINUTE_SECONDS
setupAlarmClock(alarm!!, it)
finishActivity()

View File

@ -10,6 +10,6 @@
android:pivotY="50%"
android:repeatCount="infinite"
android:repeatMode="reverse"
android:toXScale="2.0"
android:toYScale="2.0"/>
android:toXScale="1.8"
android:toYScale="1.8"/>

View File

@ -32,9 +32,10 @@
<ImageView
android:id="@+id/reminder_snooze"
android:layout_width="@dimen/stopwatch_button_small_size"
android:layout_height="@dimen/stopwatch_button_small_size"
android:padding="@dimen/normal_margin"
android:layout_width="@dimen/reminder_background_min_size"
android:layout_height="@dimen/reminder_background_min_size"
android:clickable="false"
android:padding="@dimen/activity_margin"
android:src="@drawable/ic_snooze_big"
app:layout_constraintBottom_toBottomOf="@+id/reminder_draggable"
app:layout_constraintEnd_toStartOf="@+id/reminder_draggable"
@ -48,7 +49,7 @@
android:layout_height="@dimen/reminder_background_min_size"
android:layout_marginBottom="@dimen/activity_margin"
android:alpha="0.2"
android:padding="@dimen/normal_margin"
android:padding="@dimen/medium_margin"
android:src="@drawable/pulsing_background"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/reminder_dismiss"
@ -58,10 +59,10 @@
<ImageView
android:id="@+id/reminder_draggable"
android:layout_width="@dimen/stopwatch_button_small_size"
android:layout_height="@dimen/stopwatch_button_small_size"
android:layout_width="@dimen/reminder_background_min_size"
android:layout_height="@dimen/reminder_background_min_size"
android:layout_marginBottom="@dimen/activity_margin"
android:padding="@dimen/normal_margin"
android:padding="@dimen/activity_margin"
android:src="@drawable/ic_alarm_big"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/reminder_dismiss"
@ -71,9 +72,10 @@
<ImageView
android:id="@+id/reminder_dismiss"
android:layout_width="@dimen/stopwatch_button_small_size"
android:layout_height="@dimen/stopwatch_button_small_size"
android:padding="@dimen/normal_margin"
android:layout_width="@dimen/reminder_background_min_size"
android:layout_height="@dimen/reminder_background_min_size"
android:clickable="false"
android:padding="@dimen/activity_margin"
android:src="@drawable/ic_dismiss_alarm_big"
app:layout_constraintBottom_toBottomOf="@+id/reminder_draggable"
app:layout_constraintEnd_toEndOf="parent"