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