Skip to content

Commit

Permalink
hold to dismiss, for trikita#20
Browse files Browse the repository at this point in the history
  • Loading branch information
smichel17 committed Dec 27, 2019
1 parent 8701347 commit 5860648
Showing 1 changed file with 53 additions and 2 deletions.
55 changes: 53 additions & 2 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.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;
Expand All @@ -19,6 +24,9 @@

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

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

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(3000); // 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;
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"
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 5860648

Please sign in to comment.