1 /* 2 * Copyright (C) 2012 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.gallery3d.app; 18 19 import android.animation.Animator; 20 import android.animation.Animator.AnimatorListener; 21 import android.animation.ObjectAnimator; 22 import android.content.Context; 23 import android.view.MotionEvent; 24 import android.view.View; 25 26 import com.android.gallery3d.common.ApiHelper; 27 28 /** 29 * The controller for the Trimming Video. 30 */ 31 public class TrimControllerOverlay extends CommonControllerOverlay { 32 TrimControllerOverlay(Context context)33 public TrimControllerOverlay(Context context) { 34 super(context); 35 } 36 37 @Override createTimeBar(Context context)38 protected void createTimeBar(Context context) { 39 mTimeBar = new TrimTimeBar(context, this); 40 } 41 hidePlayButtonIfPlaying()42 private void hidePlayButtonIfPlaying() { 43 if (mState == State.PLAYING) { 44 mPlayPauseReplayView.setVisibility(View.INVISIBLE); 45 } 46 if (ApiHelper.HAS_OBJECT_ANIMATION) { 47 mPlayPauseReplayView.setAlpha(1f); 48 } 49 } 50 51 @Override showPlaying()52 public void showPlaying() { 53 super.showPlaying(); 54 if (ApiHelper.HAS_OBJECT_ANIMATION) { 55 // Add animation to hide the play button while playing. 56 ObjectAnimator anim = ObjectAnimator.ofFloat(mPlayPauseReplayView, "alpha", 1f, 0f); 57 anim.setDuration(200); 58 anim.start(); 59 anim.addListener(new AnimatorListener() { 60 @Override 61 public void onAnimationStart(Animator animation) { 62 } 63 64 @Override 65 public void onAnimationEnd(Animator animation) { 66 hidePlayButtonIfPlaying(); 67 } 68 69 @Override 70 public void onAnimationCancel(Animator animation) { 71 hidePlayButtonIfPlaying(); 72 } 73 74 @Override 75 public void onAnimationRepeat(Animator animation) { 76 } 77 }); 78 } else { 79 hidePlayButtonIfPlaying(); 80 } 81 } 82 83 @Override setTimes(int currentTime, int totalTime, int trimStartTime, int trimEndTime)84 public void setTimes(int currentTime, int totalTime, int trimStartTime, int trimEndTime) { 85 mTimeBar.setTime(currentTime, totalTime, trimStartTime, trimEndTime); 86 } 87 88 @Override onTouchEvent(MotionEvent event)89 public boolean onTouchEvent(MotionEvent event) { 90 if (super.onTouchEvent(event)) { 91 return true; 92 } 93 94 // The special thing here is that the State.ENDED include both cases of 95 // the video completed and current == trimEnd. Both request a replay. 96 switch (event.getAction()) { 97 case MotionEvent.ACTION_DOWN: 98 if (mState == State.PLAYING || mState == State.PAUSED) { 99 mListener.onPlayPause(); 100 } else if (mState == State.ENDED) { 101 if (mCanReplay) { 102 mListener.onReplay(); 103 } 104 } 105 break; 106 case MotionEvent.ACTION_UP: 107 break; 108 } 109 return true; 110 } 111 } 112