diff --git a/src/main/java/trikita/talalarmo/alarm/AlarmActivity.java b/src/main/java/trikita/talalarmo/alarm/AlarmActivity.java index 820775a..aa069b5 100644 --- a/src/main/java/trikita/talalarmo/alarm/AlarmActivity.java +++ b/src/main/java/trikita/talalarmo/alarm/AlarmActivity.java @@ -1,14 +1,20 @@ package trikita.talalarmo.alarm; +import android.animation.Animator; +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; @@ -19,6 +25,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) { @@ -37,15 +47,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; + }); }); } });