Skip to content

Commit

Permalink
Hold to dismiss, for trikita#20
Browse files Browse the repository at this point in the history
Instead of dismissing instantly on touch, instead the touch must be held
down for 2 seconds. During this time, the background will fade to be the
same color as the alarm icon, giving a progress indicator.

If you release before 2 seconds, the alarm icon will change into the
text "HOLD" to provide a hint about what needs to happen.

Pressing the home or back button will still dismiss instantly.
  • Loading branch information
smichel17 committed Feb 16, 2020
1 parent c47bb94 commit 13f3a66
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 3 deletions.
61 changes: 58 additions & 3 deletions src/main/java/trikita/talalarmo/alarm/AlarmActivity.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,34 @@
package trikita.talalarmo.alarm;

import android.animation.Animator;
import android.animation.ArgbEvaluator;
import android.animation.ValueAnimator;
import android.app.Activity;
import android.content.Context;
import android.os.Build;
import android.os.Bundle;
import android.os.PowerManager;
import android.view.MotionEvent;
import android.view.Window;
import android.view.WindowManager;

import trikita.anvil.RenderableView;
import trikita.anvil.Anvil;
import static trikita.anvil.DSL.*;

import trikita.jedux.Action;
import trikita.talalarmo.Actions;
import trikita.talalarmo.App;
import trikita.talalarmo.R;
import trikita.talalarmo.ui.Theme;


public class AlarmActivity extends Activity {
private PowerManager.WakeLock mWakeLock;
private ValueAnimator mAnimator;
private int bgColor;
private int txt;
private boolean canceled;

@Override
protected void onCreate(Bundle b) {
Expand All @@ -37,15 +47,60 @@ protected void onCreate(Bundle b) {
window.setStatusBarColor(Theme.get(App.getState().settings().theme()).primaryDarkColor);
}

txt = R.string.alarm_off;
int colorFrom = Theme.get(App.getState().settings().theme()).backgroundColor;
int colorTo = Theme.get(App.getState().settings().theme()).accentColor;
bgColor = colorFrom;
mAnimator = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo);
mAnimator.setDuration(2000); // millis
mAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animator) {
bgColor = (int) animator.getAnimatedValue();
Anvil.render();
}
});
mAnimator.addListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animator) {
canceled = false;
}
@Override
public void onAnimationCancel(Animator animator) {
canceled = true;
txt = R.string.hold_dismiss_prompt;
bgColor = colorFrom;
Anvil.render();
}
@Override
public void onAnimationEnd(Animator animator) {
if (!canceled) {
stopAlarm();
}
}
@Override
public void onAnimationRepeat(Animator animator) {}
});

setContentView(new RenderableView(this) {
public void view() {
Theme.materialIcon(() -> {
size(FILL, FILL);
text("\ue857"); // "alarm off"
text(txt); // "alarm off"
textColor(Theme.get(App.getState().settings().theme()).accentColor);
textSize(dip(128));
backgroundColor(Theme.get(App.getState().settings().theme()).backgroundColor);
onClick(v -> stopAlarm());
backgroundColor(bgColor);
onTouch((v, e) -> {
if(e.getAction() == MotionEvent.ACTION_DOWN){
mAnimator.start();
return true;
}
if(e.getAction() == MotionEvent.ACTION_UP){
mAnimator.cancel();
return true;
}
return false;
});
});
}
});
Expand Down
2 changes: 2 additions & 0 deletions src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
<string name="settings_vibration_option">Vibrate</string>
<string name="settings_volume_increase_option">Fade-in sound</string>
<string name="tv_start_alarm_text">Tap here\nto set alarm</string>
<string name="hold_dismiss_prompt">HOLD</string>
<string name="alarm_off" translatable="false">"\ue857"</string>

<string name="hour">1 hour</string>
<string name="hours">%s hours</string>
Expand Down

0 comments on commit 13f3a66

Please sign in to comment.