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.

While holding, the icon will also change to a finger (touch_app), to
provide a hint about what you need to do. This is an effective hint
because tapping makes it flicker, and if you hold for long enough to see
what the new icon is, you'll also hold for long enough that the
background will start fading, giving you the next hint.

Pressing the home or back button will still dismiss instantly, since
there's no way to track touches on those.
  • Loading branch information
smichel17 committed Feb 16, 2020
1 parent c47bb94 commit 0e40ffb
Showing 1 changed file with 56 additions and 3 deletions.
59 changes: 56 additions & 3 deletions src/main/java/trikita/talalarmo/alarm/AlarmActivity.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
package trikita.talalarmo.alarm;

import android.animation.AnimatorListenerAdapter;
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;
Expand All @@ -19,6 +24,10 @@

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

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

txt = "\ue857"; // alarm_off icon
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 AnimatorListenerAdapter() {
@Override
public void onAnimationStart(Animator animator) {
canceled = false;
txt = "\ue913"; // touch_app icon
}
@Override
public void onAnimationCancel(Animator animator) {
canceled = true;
txt = "\ue857"; // alarm_off icon
bgColor = colorFrom;
Anvil.render();
}
@Override
public void onAnimationEnd(Animator animator) {
if (!canceled) {
stopAlarm();
}
}
});

setContentView(new RenderableView(this) {
public void view() {
Theme.materialIcon(() -> {
size(FILL, FILL);
text("\ue857"); // "alarm off"
text(txt);
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

0 comments on commit 0e40ffb

Please sign in to comment.