Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7654c44b authored by Justin Klaassen's avatar Justin Klaassen
Browse files

Support Timer reveal on < API 21

Switch to using CircleView for the fullscreen timer reveal animation.

Change-Id: If36634423b0f3b623ced82d5626a8cc9556bac82
parent 86b035cb
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -17,4 +17,5 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/fragment_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />
    android:layout_height="match_parent"
    android:fitsSystemWindows="true" />
+25 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2015 The Android Open Source Project

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->

<resources>

    <style name="AppCompatTranslucentDecorTheme" parent="Theme.AppCompat.NoActionBar">
        <item name="android:windowContentOverlay">@null</item>
        <item name="android:windowTranslucentStatus">true</item>
        <item name="android:windowTranslucentNavigation">true</item>
    </style>

</resources>
+5 −7
Original line number Diff line number Diff line
@@ -21,6 +21,9 @@
        <item name="android:layout_gravity">center_horizontal</item>
    </style>

    <!-- variants: v19 -->
    <style name="AppCompatTranslucentDecorTheme" parent="Theme.AppCompat.NoActionBar" />

    <style name="DeskClockParentTheme" parent="Theme.AppCompat">
        <item name="android:statusBarColor">@color/status_bar</item>
        <item name="android:imageButtonStyle">@style/ImageButtonStyle</item>
@@ -124,14 +127,9 @@
        <item name="android:textSize">32sp</item>
    </style>

    <!-- NOTE: This must be a fullscreen theme, or else the fullscreen alarm will
         be unable to turn the screen on. -->
    <style name="AlarmAlertFullScreenTheme" parent="Theme.AppCompat.NoActionBar">
        <item name="android:windowTranslucentStatus">true</item>
    </style>
    <style name="AlarmAlertFullScreenTheme" parent="AppCompatTranslucentDecorTheme" />

    <style name="TimerAlertFullScreenTheme" parent="Theme.AppCompat.NoActionBar">
        <item name="android:statusBarColor">@color/status_bar</item>
    <style name="TimerAlertFullScreenTheme" parent="AppCompatTranslucentDecorTheme">
        <item name="android:imageButtonStyle">@style/ImageButtonStyle</item>
    </style>

+36 −48
Original line number Diff line number Diff line
@@ -21,8 +21,6 @@ import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.annotation.TargetApi;
import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentTransaction;
import android.app.NotificationManager;
@@ -31,9 +29,9 @@ import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.content.res.Resources;
import android.os.Build;
import android.graphics.Color;
import android.graphics.Rect;
import android.os.Bundle;
import android.os.Handler;
import android.preference.PreferenceManager;
import android.text.format.DateUtils;
import android.util.Log;
@@ -41,13 +39,10 @@ import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewAnimationUtils;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.ViewGroupOverlay;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.PathInterpolator;
import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.TextView;
@@ -58,9 +53,11 @@ import com.android.deskclock.DeskClock.OnTapListener;
import com.android.deskclock.DeskClockFragment;
import com.android.deskclock.LabelDialogFragment;
import com.android.deskclock.LogUtils;
import com.android.deskclock.PathInterpolatorCompat;
import com.android.deskclock.R;
import com.android.deskclock.TimerSetupView;
import com.android.deskclock.Utils;
import com.android.deskclock.widget.CircleView;
import com.android.deskclock.widget.sgv.GridAdapter;
import com.android.deskclock.widget.sgv.SgvAnimationHelper.AnimationIn;
import com.android.deskclock.widget.sgv.SgvAnimationHelper.AnimationOut;
@@ -522,13 +519,14 @@ public class TimerFullScreenFragment extends DeskClockFragment
        mFab.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                revealAnimation(mFab, getActivity().getResources().getColor(R.color.clock_white));
                new Handler().postDelayed(new Runnable() {
                final Animator revealAnimator = getRevealAnimator(mFab, Color.WHITE);
                revealAnimator.addListener(new AnimatorListenerAdapter() {
                    @Override
                    public void run() {
                    public void onAnimationEnd(Animator animation) {
                        updateAllTimesUpTimers();
                    }
                }, TimerFragment.ANIMATION_TIME_MILLIS);
                });
                revealAnimator.start();
            }
        });
    }
@@ -553,55 +551,45 @@ public class TimerFullScreenFragment extends DeskClockFragment
        }
    }

    private void revealAnimation(final View centerView, int color) {
        final Activity activity = getActivity();
        final View decorView = activity.getWindow().getDecorView();
        final ViewGroupOverlay overlay = (ViewGroupOverlay) decorView.getOverlay();
    private Animator getRevealAnimator(View source, int revealColor) {
        final ViewGroup containerView = (ViewGroup) source.getRootView()
                .findViewById(android.R.id.content);

        // Create a transient view for performing the reveal animation.
        final View revealView = new View(activity);
        revealView.setRight(decorView.getWidth());
        revealView.setBottom(decorView.getHeight());
        revealView.setBackgroundColor(color);
        overlay.add(revealView);
        final Rect sourceBounds = new Rect(0, 0, source.getHeight(), source.getWidth());
        containerView.offsetDescendantRectToMyCoords(source, sourceBounds);

        final int[] clearLocation = new int[2];
        centerView.getLocationInWindow(clearLocation);
        clearLocation[0] += centerView.getWidth() / 2;
        clearLocation[1] += centerView.getHeight() / 2;
        final int revealCenterX = clearLocation[0] - revealView.getLeft();
        final int revealCenterY = clearLocation[1] - revealView.getTop();
        final int centerX = sourceBounds.centerX();
        final int centerY = sourceBounds.centerY();

        final int xMax = Math.max(revealCenterX, decorView.getWidth() - revealCenterX);
        final int yMax = Math.max(revealCenterY, decorView.getHeight() - revealCenterY);
        final float revealRadius = (float) Math.sqrt(Math.pow(xMax, 2.0) + Math.pow(yMax, 2.0));
        final int xMax = Math.max(centerX, containerView.getWidth() - centerX);
        final int yMax = Math.max(centerY, containerView.getHeight() - centerY);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            showCircularReveal(revealView, revealCenterX, revealCenterY, revealRadius, overlay);
        } else {
            // TODO: show circular reveal
        }
    }
        final float startRadius = Math.max(sourceBounds.width(), sourceBounds.height()) / 2.0f;
        final float endRadius = (float) Math.sqrt(xMax * xMax + yMax * yMax);

    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    private void showCircularReveal(final View revealView, int revealCenterX, int revealCenterY,
                                    float revealRadius, final ViewGroupOverlay overlay) {
        final Animator revealAnimator = ViewAnimationUtils.createCircularReveal(
                revealView, revealCenterX, revealCenterY, 0.0f, revealRadius);
        revealAnimator.setInterpolator(new PathInterpolator(0.0f, 0.0f, 0.2f, 1.0f));
        final CircleView revealView = new CircleView(source.getContext())
                .setCenterX(centerX)
                .setCenterY(centerY)
                .setFillColor(revealColor);
        containerView.addView(revealView);

        final ValueAnimator fadeAnimator = ObjectAnimator.ofFloat(revealView, View.ALPHA, 1.0f);
        final Animator revealAnimator = ObjectAnimator.ofFloat(
                revealView, CircleView.RADIUS, startRadius, endRadius);
        revealAnimator.setInterpolator(new PathInterpolatorCompat(0.0f, 0.0f, 0.2f, 1.0f));

        final ValueAnimator fadeAnimator = ObjectAnimator.ofFloat(revealView, View.ALPHA, 0.0f);
        fadeAnimator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                overlay.remove(revealView);
                containerView.removeView(revealView);
            }
        });

        final AnimatorSet alertAnimator = new AnimatorSet();
        alertAnimator.setDuration(TimerFragment.ANIMATION_TIME_MILLIS);
        alertAnimator.play(revealAnimator).before(fadeAnimator);
        alertAnimator.start();
        final AnimatorSet animatorSet = new AnimatorSet();
        animatorSet.setDuration(TimerFragment.ANIMATION_TIME_MILLIS);
        animatorSet.playSequentially(revealAnimator, fadeAnimator);

        return revealAnimator;
    }

    @Override