Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d66a3fe1 authored by Gil Dobjanschi's avatar Gil Dobjanschi Committed by Android (Google) Code Review
Browse files

Merge "Adjust the duration of transitions if needed."

parents 36b113cb 05152ffd
Loading
Loading
Loading
Loading
+20 −0
Original line number Diff line number Diff line
@@ -116,10 +116,30 @@ public class MediaImageItem extends MediaItem {
    }

    /**
     * This method will adjust the duration of bounding transitions if the
     * current duration of the transactions become greater than the maximum
     * allowable duration.
     *
     * @param durationMs The duration of the image in the storyboard timeline
     */
    public void setDuration(long durationMs) {
        mDurationMs = durationMs;

        // Check if the duration of transitions need to be adjusted
        if (mBeginTransition != null) {
            final long maxDurationMs = mBeginTransition.getMaximumDuration();
            if (mBeginTransition.getDuration() > maxDurationMs) {
                mBeginTransition.setDuration(maxDurationMs);
            }
        }

        if (mEndTransition != null) {
            final long maxDurationMs = mEndTransition.getMaximumDuration();
            if (mEndTransition.getDuration() > maxDurationMs) {
                mEndTransition.setDuration(maxDurationMs);
            }
        }

        // TODO: Validate/modify the start and the end time of effects and overlays
    }

+1 −1
Original line number Diff line number Diff line
@@ -90,7 +90,7 @@ public abstract class MediaItem {
    }

    /**
     * @return The of the media item
     * @return The id of the media item
     */
    public String getId() {
        return mUniqueId;
+24 −4
Original line number Diff line number Diff line
@@ -245,7 +245,10 @@ public class MediaVideoItem extends MediaItem {
    }

    /**
     * Sets the start and end marks for trimming a video media item
     * Sets the start and end marks for trimming a video media item.
     * This method will adjust the duration of bounding transitions if the
     * current duration of the transactions become greater than the maximum
     * allowable duration.
     *
     * @param beginMs Start time in milliseconds. Set to 0 to extract from the
     *           beginning
@@ -265,18 +268,35 @@ public class MediaVideoItem extends MediaItem {
        }

        if (beginMs != mBeginBoundaryTimeMs) {
            mBeginBoundaryTimeMs = beginMs;
            if (mBeginTransition != null) {
                mBeginTransition.invalidate();
            }
        }

        if (endMs == mEndBoundaryTimeMs) {
            mEndBoundaryTimeMs = endMs;
        if (endMs != mEndBoundaryTimeMs) {
            if (mEndTransition != null) {
                mEndTransition.invalidate();
            }
        }

        mBeginBoundaryTimeMs = beginMs;
        mEndBoundaryTimeMs = endMs;

        // Check if the duration of transitions need to be adjusted
        if (mBeginTransition != null) {
            final long maxDurationMs = mBeginTransition.getMaximumDuration();
            if (mBeginTransition.getDuration() > maxDurationMs) {
                mBeginTransition.setDuration(maxDurationMs);
            }
        }

        if (mEndTransition != null) {
            final long maxDurationMs = mEndTransition.getMaximumDuration();
            if (mEndTransition.getDuration() > maxDurationMs) {
                mEndTransition.setDuration(maxDurationMs);
            }
        }

        // TODO: Validate/modify the start and the end time of effects and overlays
    }

+21 −0
Original line number Diff line number Diff line
@@ -124,7 +124,12 @@ public abstract class Transition {
     * @param durationMs the duration of the transition in milliseconds
     */
    public void setDuration(long durationMs) {
        if (durationMs > getMaximumDuration()) {
            throw new IllegalArgumentException("The duration is too large");
        }

        mDurationMs = durationMs;
        invalidate();
    }

    /**
@@ -134,6 +139,22 @@ public abstract class Transition {
        return mDurationMs;
    }

    /**
     * The duration of a transition cannot be greater than half of the minimum
     * duration of the bounding media items.
     *
     * @return The maximum duration of this transition
     */
    public long getMaximumDuration() {
        if (mAfterMediaItem == null) {
            return mBeforeMediaItem.getDuration() / 2;
        } else if (mBeforeMediaItem == null) {
            return mAfterMediaItem.getDuration() / 2;
        } else {
            return (Math.min(mAfterMediaItem.getDuration(), mBeforeMediaItem.getDuration()) / 2);
        }
    }

    /**
     * @return The behavior
     */