Home | History | Annotate | Download | only in anim
      1 /*
      2  * Copyright (C) 2017 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.android.launcher3.anim;
     18 
     19 import android.graphics.Rect;
     20 
     21 /**
     22  * A {@link RevealOutlineAnimation} that provides an outline that interpolates between two radii
     23  * and two {@link Rect}s.
     24  *
     25  * An example usage of this provider is an outline that starts out as a circle and ends
     26  * as a rounded rectangle.
     27  */
     28 public class RoundedRectRevealOutlineProvider extends RevealOutlineAnimation {
     29     private final float mStartRadius;
     30     private final float mEndRadius;
     31 
     32     private final Rect mStartRect;
     33     private final Rect mEndRect;
     34 
     35     public RoundedRectRevealOutlineProvider(float startRadius, float endRadius, Rect startRect,
     36             Rect endRect) {
     37         mStartRadius = startRadius;
     38         mEndRadius = endRadius;
     39         mStartRect = startRect;
     40         mEndRect = endRect;
     41     }
     42 
     43     @Override
     44     public boolean shouldRemoveElevationDuringAnimation() {
     45         return false;
     46     }
     47 
     48     @Override
     49     public void setProgress(float progress) {
     50         mOutlineRadius = (1 - progress) * mStartRadius + progress * mEndRadius;
     51 
     52         mOutline.left = (int) ((1 - progress) * mStartRect.left + progress * mEndRect.left);
     53         mOutline.top = (int) ((1 - progress) * mStartRect.top + progress * mEndRect.top);
     54         mOutline.right = (int) ((1 - progress) * mStartRect.right + progress * mEndRect.right);
     55         mOutline.bottom = (int) ((1 - progress) * mStartRect.bottom + progress * mEndRect.bottom);
     56     }
     57 }
     58