EffectKenBurns.java revision 9bcedf7cf3e9c981837f2d8ec98cd118efad3f01
1/*
2 * Copyright (C) 2010 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
18package android.media.videoeditor;
19
20import android.graphics.Rect;
21
22/**
23 * This class represents a Ken Burns effect.
24 * {@hide}
25 */
26public class EffectKenBurns extends Effect {
27    /**
28     *  Instance variables
29     */
30    private Rect mStartRect;
31    private Rect mEndRect;
32
33    /**
34     * Objects of this type cannot be instantiated by using the default
35     * constructor
36     */
37    @SuppressWarnings("unused")
38    private EffectKenBurns() {
39        this(null, null, null, null, 0, 0);
40    }
41
42    /**
43     * Constructor
44     *
45     * @param mediaItem The media item owner
46     * @param effectId The effect id
47     * @param startRect The start rectangle
48     * @param endRect The end rectangle
49     * @param startTimeMs The start time
50     * @param durationMs The duration of the Ken Burns effect in milliseconds
51     */
52    public EffectKenBurns(MediaItem mediaItem, String effectId, Rect startRect,
53                         Rect endRect, long startTimeMs, long durationMs) {
54        super(mediaItem, effectId, startTimeMs, durationMs);
55
56        mStartRect = startRect;
57        mEndRect = endRect;
58    }
59
60    /**
61     * Set the start rectangle.
62     *
63     * @param startRect The start rectangle
64     *
65     * @throws IllegalArgumentException if start rectangle is incorrectly set.
66     */
67    public void setStartRect(Rect startRect) {
68        if ( (startRect.left == 0) && (startRect.right == 0)
69            && (startRect.bottom == 0) && (startRect.top == 0) ) {
70            throw new IllegalArgumentException("Invalid Rectangle");
71        }
72
73        mStartRect = startRect;
74    }
75
76    /**
77     * Get the start rectangle.
78     *
79     * @return The start rectangle
80     */
81    public Rect getStartRect() {
82        return mStartRect;
83    }
84
85    /**
86     * Set the end rectangle.
87     *
88     * @param endRect The end rectangle
89     *
90     * @throws IllegalArgumentException if end rectangle is incorrectly set.
91     */
92    public void setEndRect(Rect endRect) {
93        if ( (endRect.left == 0) && (endRect.right == 0)
94           && (endRect.bottom == 0) && (endRect.top == 0) ) {
95            throw new IllegalArgumentException("Invalid Rectangle");
96        }
97
98        mEndRect = endRect;
99    }
100
101    /**
102     * Get the end rectangle.
103     *
104     * @return The end rectangle
105     */
106    public Rect getEndRect() {
107        return mEndRect;
108    }
109
110    /**
111     * Get the KenBurn effect start and end rectangle coordinates
112     * @param start The rect object to be populated with start
113     * rectangle coordinates
114     *
115     * @param end The rect object to be populated with end
116     * rectangle coordinates
117     */
118    void getKenBurnsSettings(Rect start, Rect end) {
119        start.left = getStartRect().left;
120        start.top = getStartRect().top;
121        start.right = getStartRect().right;
122        start.bottom = getStartRect().bottom;
123        end.left = getEndRect().left;
124        end.top = getEndRect().top;
125        end.right = getEndRect().right;
126        end.bottom = getEndRect().bottom;
127    }
128}
129