Home | History | Annotate | Download | only in animation
      1 /*
      2  * Copyright (C) 2014 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 android.view.animation;
     18 
     19 import android.graphics.Rect;
     20 
     21 /**
     22  * An animation that controls the clip of an object. See the
     23  * {@link android.view.animation full package} description for details and
     24  * sample code.
     25  *
     26  * @hide
     27  */
     28 public class ClipRectAnimation extends Animation {
     29     private Rect mFromRect = new Rect();
     30     private Rect mToRect = new Rect();
     31 
     32     /**
     33      * Constructor to use when building a ClipRectAnimation from code
     34      *
     35      * @param fromClip the clip rect to animate from
     36      * @param toClip the clip rect to animate to
     37      */
     38     public ClipRectAnimation(Rect fromClip, Rect toClip) {
     39         if (fromClip == null || toClip == null) {
     40             throw new RuntimeException("Expected non-null animation clip rects");
     41         }
     42         mFromRect.set(fromClip);
     43         mToRect.set(toClip);
     44     }
     45 
     46     @Override
     47     protected void applyTransformation(float it, Transformation tr) {
     48         int l = mFromRect.left + (int) ((mToRect.left - mFromRect.left) * it);
     49         int t = mFromRect.top + (int) ((mToRect.top - mFromRect.top) * it);
     50         int r = mFromRect.right + (int) ((mToRect.right - mFromRect.right) * it);
     51         int b = mFromRect.bottom + (int) ((mToRect.bottom - mFromRect.bottom) * it);
     52         tr.setClipRect(l, t, r, b);
     53     }
     54 
     55     @Override
     56     public boolean willChangeTransformationMatrix() {
     57         return false;
     58     }
     59 }
     60