Home | History | Annotate | Download | only in service
      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 package com.android.videoeditor.service;
     18 
     19 import java.util.Map;
     20 
     21 import android.media.videoeditor.Overlay;
     22 import android.os.Bundle;
     23 
     24 
     25 /**
     26  * The representation of an overlay in the user interface
     27  */
     28 public class MovieOverlay {
     29     // Overlay types
     30     public static final int OVERLAY_TYPE_CENTER_1 = 0;
     31     public static final int OVERLAY_TYPE_BOTTOM_1 = 1;
     32     public static final int OVERLAY_TYPE_CENTER_2 = 2;
     33     public static final int OVERLAY_TYPE_BOTTOM_2 = 3;
     34 
     35     // User attribute keys
     36     private static final String KEY_TYPE = "type";
     37     private static final String KEY_TITLE = "title";
     38     private static final String KEY_SUBTITLE = "subtitle";
     39 
     40     // Instance variables
     41     private final String mUniqueId;
     42     private long mStartTimeMs;
     43     private long mDurationMs;
     44     private String mTitle;
     45     private String mSubtitle;
     46     private int mType;
     47 
     48     private long mAppStartTimeMs;
     49     private long mAppDurationMs;
     50 
     51     /**
     52      * Default constructor
     53      */
     54     @SuppressWarnings("unused")
     55     private MovieOverlay() {
     56         this(null);
     57     }
     58 
     59     /**
     60      * Constructor
     61      *
     62      * @param overlay The overlay
     63      */
     64     MovieOverlay(Overlay overlay) {
     65         mUniqueId = overlay.getId();
     66         mAppStartTimeMs = mStartTimeMs = overlay.getStartTime();
     67         mAppDurationMs = mDurationMs = overlay.getDuration();
     68 
     69         final Map<String, String> userAttributes = overlay.getUserAttributes();
     70         mTitle = userAttributes.get(KEY_TITLE);
     71         mSubtitle = userAttributes.get(KEY_SUBTITLE);
     72         mType = Integer.parseInt(userAttributes.get(KEY_TYPE));
     73     }
     74 
     75     /**
     76      * Constructor
     77      *
     78      * @param id The overlay id
     79      * @param startTimeMs The start time
     80      * @param durationMs The duration
     81      * @param title The title
     82      * @param subTitle The sub title
     83      * @param type The title type
     84      */
     85     MovieOverlay(String id, long startTimeMs, long durationMs, String title,
     86             String subTitle, int type) {
     87         mUniqueId = id;
     88         mAppStartTimeMs = mStartTimeMs = startTimeMs;
     89         mAppDurationMs = mDurationMs = durationMs;
     90 
     91         mTitle = title;
     92         mSubtitle = subTitle;
     93         mType = type;
     94     }
     95 
     96     /**
     97      * @return The id of this overlay
     98      */
     99     public String getId() {
    100         return mUniqueId;
    101     }
    102 
    103     /**
    104      * If a preview or export is in progress, then this change is effective for
    105      * next preview or export session.
    106      *
    107      * @param durationMs The duration in milliseconds
    108      */
    109     void setDuration(long durationMs) {
    110         mDurationMs = durationMs;
    111     }
    112 
    113     /**
    114      * @return The duration of the overlay effect
    115      */
    116     long getDuration() {
    117         return mDurationMs;
    118     }
    119 
    120     /**
    121      * If a preview or export is in progress, then this change is effective for
    122      * next preview or export session.
    123      *
    124      * @param durationMs The duration in milliseconds
    125      */
    126     public void setAppDuration(long durationMs) {
    127         mAppDurationMs = durationMs;
    128     }
    129 
    130     /**
    131      * @return The duration of the overlay effect
    132      */
    133     public long getAppDuration() {
    134         return mAppDurationMs;
    135     }
    136 
    137     /**
    138      * Set the start time for the overlay. If a preview or export is in
    139      * progress, then this change is effective for next preview or export
    140      * session.
    141      *
    142      * @param startTimeMs start time in milliseconds
    143      */
    144     void setStartTime(long startTimeMs) {
    145         mStartTimeMs = startTimeMs;
    146     }
    147 
    148     /**
    149      * @return the start time of the overlay
    150      */
    151     long getStartTime() {
    152         return mStartTimeMs;
    153     }
    154 
    155     /**
    156      * Set the start time of this audio track relative to the storyboard
    157      * timeline. Default value is 0.
    158      *
    159      * @param startTimeMs the start time in milliseconds
    160      */
    161     public void setAppStartTime(long startTimeMs) {
    162         mAppStartTimeMs = startTimeMs;
    163     }
    164 
    165     /**
    166      * Get the start time of this audio track relative to the storyboard
    167      * timeline.
    168      *
    169      * @return The start time in milliseconds
    170      */
    171     public long getAppStartTime() {
    172         return mAppStartTimeMs;
    173     }
    174 
    175     /**
    176      * @return The title
    177      */
    178     public String getTitle() {
    179         return mTitle;
    180     }
    181 
    182     /**
    183      * @return The subtitle
    184      */
    185     public String getSubtitle() {
    186         return mSubtitle;
    187     }
    188 
    189     /**
    190      * @return The type
    191      */
    192     public int getType() {
    193         return mType;
    194     }
    195 
    196     /*
    197      * {@inheritDoc}
    198      */
    199     @Override
    200     public boolean equals(Object object) {
    201         if (!(object instanceof MovieOverlay)) {
    202             return false;
    203         }
    204         return mUniqueId.equals(((MovieOverlay)object).mUniqueId);
    205     }
    206 
    207     /*
    208      * {@inheritDoc}
    209      */
    210     @Override
    211     public int hashCode() {
    212         return mUniqueId.hashCode();
    213     }
    214 
    215     /**
    216      * Build the user attributes
    217      *
    218      * @return The user attributes
    219      */
    220     public Bundle buildUserAttributes() {
    221         final Bundle userAttributes = new Bundle(4);
    222         userAttributes.putInt(KEY_TYPE, mType);
    223         userAttributes.putString(KEY_TITLE, mTitle);
    224         userAttributes.putString(KEY_SUBTITLE, mSubtitle);
    225         return userAttributes;
    226     }
    227 
    228     /**
    229      * Build the user attributes
    230      *
    231      * @param type The overlay type
    232      * @param title The overlay title
    233      * @param subtitle The overlay subtitle
    234      *
    235      * @return The user attributes
    236      */
    237     public static Bundle buildUserAttributes(int type, String title, String subtitle) {
    238         final Bundle userAttributes = new Bundle(4);
    239         userAttributes.putInt(KEY_TYPE, type);
    240         userAttributes.putString(KEY_TITLE, title);
    241         userAttributes.putString(KEY_SUBTITLE, subtitle);
    242         return userAttributes;
    243     }
    244 
    245     /**
    246      * @param userAttributes The user attributes
    247      */
    248     void updateUserAttributes(Bundle userAttributes) {
    249         mType = userAttributes.getInt(KEY_TYPE);
    250         mTitle = userAttributes.getString(KEY_TITLE);
    251         mSubtitle = userAttributes.getString(KEY_SUBTITLE);
    252     }
    253 
    254     /**
    255      * Get the type of the value corresponding to the specified key
    256      *
    257      * @param name The key name
    258      *
    259      * @return The type
    260      */
    261     public static Class<?> getAttributeType(String name) {
    262         if (KEY_TYPE.equals(name)) {
    263             return Integer.class;
    264         } else {
    265             return String.class;
    266         }
    267     }
    268 
    269     /**
    270      * @param userAttributes The user attributes
    271      *
    272      * @return The type
    273      */
    274     public static int getType(Bundle userAttributes) {
    275         return userAttributes.getInt(KEY_TYPE);
    276     }
    277 
    278     /**
    279      * @param userAttributes The user attributes
    280      *
    281      * @return The title
    282      */
    283     public static String getTitle(Bundle userAttributes) {
    284         return userAttributes.getString(KEY_TITLE);
    285     }
    286 
    287     /**
    288      * @param userAttributes The user attributes
    289      *
    290      * @return The subtitle
    291      */
    292     public static String getSubtitle(Bundle userAttributes) {
    293         return userAttributes.getString(KEY_SUBTITLE);
    294     }
    295 }
    296