Effects and overlays are not modified when a video clip is trimmed.

Change-Id: Ib9a54ecab4ea253caa6c64204493fc3f40a6aa53
diff --git a/media/java/android/media/videoeditor/MediaImageItem.java b/media/java/android/media/videoeditor/MediaImageItem.java
index df3c5fb..d2f3694 100755
--- a/media/java/android/media/videoeditor/MediaImageItem.java
+++ b/media/java/android/media/videoeditor/MediaImageItem.java
@@ -163,7 +163,9 @@
     public void setDuration(long durationMs) {

         mDurationMs = durationMs;

 

-        adjustElementsDuration();

+        adjustTransitions();

+        adjustOverlays();

+        adjustEffects();

     }

 

     /*

diff --git a/media/java/android/media/videoeditor/MediaItem.java b/media/java/android/media/videoeditor/MediaItem.java
index d9c38af..40d3619 100755
--- a/media/java/android/media/videoeditor/MediaItem.java
+++ b/media/java/android/media/videoeditor/MediaItem.java
@@ -40,13 +40,21 @@
      * clip are rendered black.

      */

     public static final int RENDERING_MODE_BLACK_BORDER = 0;

+

     /**

      * When using the RENDERING_MODE_STRETCH rendering mode video frames are

      * stretched horizontally or vertically to match the current aspect ratio of

-     * the movie.

+     * the video editor.

      */

     public static final int RENDERING_MODE_STRETCH = 1;

 

+    /**

+     * When using the RENDERING_MODE_CROPPING rendering mode video frames are

+     * scaled horizontally or vertically by preserving the original aspect

+     * ratio of the media item.

+     */

+    public static final int RENDERING_MODE_CROPPING = 2;

+

 

     // The unique id of the MediaItem

     private final String mUniqueId;

@@ -476,10 +484,9 @@
     }

 

     /**

-     * Adjust the duration of effects, overlays and transitions.

-     * This method will be called after a media item duration is changed.

+     * Adjust the duration transitions.

      */

-    protected void adjustElementsDuration() {

+    protected void adjustTransitions() {

         // Check if the duration of transitions need to be adjusted

         if (mBeginTransition != null) {

             final long maxDurationMs = mBeginTransition.getMaximumDuration();

@@ -494,31 +501,12 @@
                 mEndTransition.setDuration(maxDurationMs);

             }

         }

+    }

 

-        final List<Overlay> overlays = getAllOverlays();

-        for (Overlay overlay : overlays) {

-            // Adjust the start time if necessary

-            final long overlayStartTimeMs;

-            if (overlay.getStartTime() > getTimelineDuration()) {

-                overlayStartTimeMs = 0;

-            } else {

-                overlayStartTimeMs = overlay.getStartTime();

-            }

-

-            // Adjust the duration if necessary

-            final long overlayDurationMs;

-            if (overlayStartTimeMs + overlay.getDuration() > getTimelineDuration()) {

-                overlayDurationMs = getTimelineDuration() - overlayStartTimeMs;

-            } else {

-                overlayDurationMs = overlay.getDuration();

-            }

-

-            if (overlayStartTimeMs != overlay.getStartTime() ||

-                    overlayDurationMs != overlay.getDuration()) {

-                overlay.setStartTimeAndDuration(overlayStartTimeMs, overlayDurationMs);

-            }

-        }

-

+    /**

+     * Adjust the start time and/or duration of effects.

+     */

+    protected void adjustEffects() {

         final List<Effect> effects = getAllEffects();

         for (Effect effect : effects) {

             // Adjust the start time if necessary

@@ -543,4 +531,33 @@
             }

         }

     }

+

+    /**

+     * Adjust the start time and/or duration of overlays.

+     */

+    protected void adjustOverlays() {

+        final List<Overlay> overlays = getAllOverlays();

+        for (Overlay overlay : overlays) {

+            // Adjust the start time if necessary

+            final long overlayStartTimeMs;

+            if (overlay.getStartTime() > getTimelineDuration()) {

+                overlayStartTimeMs = 0;

+            } else {

+                overlayStartTimeMs = overlay.getStartTime();

+            }

+

+            // Adjust the duration if necessary

+            final long overlayDurationMs;

+            if (overlayStartTimeMs + overlay.getDuration() > getTimelineDuration()) {

+                overlayDurationMs = getTimelineDuration() - overlayStartTimeMs;

+            } else {

+                overlayDurationMs = overlay.getDuration();

+            }

+

+            if (overlayStartTimeMs != overlay.getStartTime() ||

+                    overlayDurationMs != overlay.getDuration()) {

+                overlay.setStartTimeAndDuration(overlayStartTimeMs, overlayDurationMs);

+            }

+        }

+    }

 }

diff --git a/media/java/android/media/videoeditor/MediaVideoItem.java b/media/java/android/media/videoeditor/MediaVideoItem.java
index f71f4f4..341bf8e 100755
--- a/media/java/android/media/videoeditor/MediaVideoItem.java
+++ b/media/java/android/media/videoeditor/MediaVideoItem.java
@@ -155,7 +155,11 @@
         mBeginBoundaryTimeMs = beginMs;

         mEndBoundaryTimeMs = endMs;

 

-        adjustElementsDuration();

+        adjustTransitions();

+

+        // Note that the start and duration of any effects and overlays are

+        // not adjusted nor are they automatically removed if they fall

+        // outside the new boundaries.

     }

 

     /**