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
17package android.view.animation;
18
19import 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 */
28public class ClipRectAnimation extends Animation {
29    protected Rect mFromRect = new Rect();
30    protected 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    /**
47     * Constructor to use when building a ClipRectAnimation from code
48     */
49    public ClipRectAnimation(int fromL, int fromT, int fromR, int fromB,
50            int toL, int toT, int toR, int toB) {
51        mFromRect.set(fromL, fromT, fromR, fromB);
52        mToRect.set(toL, toT, toR, toB);
53    }
54
55    @Override
56    protected void applyTransformation(float it, Transformation tr) {
57        int l = mFromRect.left + (int) ((mToRect.left - mFromRect.left) * it);
58        int t = mFromRect.top + (int) ((mToRect.top - mFromRect.top) * it);
59        int r = mFromRect.right + (int) ((mToRect.right - mFromRect.right) * it);
60        int b = mFromRect.bottom + (int) ((mToRect.bottom - mFromRect.bottom) * it);
61        tr.setClipRect(l, t, r, b);
62    }
63
64    @Override
65    public boolean willChangeTransformationMatrix() {
66        return false;
67    }
68}
69