Home | History | Annotate | Download | only in anim
      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.gallery3d.anim;
     18 
     19 import com.android.gallery3d.ui.GLCanvas;
     20 
     21 import java.util.ArrayList;
     22 
     23 public class AnimationSet extends CanvasAnimation {
     24 
     25     private final ArrayList<CanvasAnimation> mAnimations =
     26             new ArrayList<CanvasAnimation>();
     27     private int mSaveFlags = 0;
     28 
     29 
     30     public void addAnimation(CanvasAnimation anim) {
     31         mAnimations.add(anim);
     32         mSaveFlags |= anim.getCanvasSaveFlags();
     33     }
     34 
     35     @Override
     36     public void apply(GLCanvas canvas) {
     37         for (int i = 0, n = mAnimations.size(); i < n; i++) {
     38             mAnimations.get(i).apply(canvas);
     39         }
     40     }
     41 
     42     @Override
     43     public int getCanvasSaveFlags() {
     44         return mSaveFlags;
     45     }
     46 
     47     @Override
     48     protected void onCalculate(float progress) {
     49         // DO NOTHING
     50     }
     51 
     52     @Override
     53     public boolean calculate(long currentTimeMillis) {
     54         boolean more = false;
     55         for (CanvasAnimation anim : mAnimations) {
     56             more |= anim.calculate(currentTimeMillis);
     57         }
     58         return more;
     59     }
     60 
     61     @Override
     62     public void start() {
     63         for (CanvasAnimation anim : mAnimations) {
     64             anim.start();
     65         }
     66     }
     67 
     68     @Override
     69     public boolean isActive() {
     70         for (CanvasAnimation anim : mAnimations) {
     71             if (anim.isActive()) return true;
     72         }
     73         return false;
     74     }
     75 
     76 }
     77