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.photoeditor.actions; 18 19 import android.view.View; 20 import android.view.ViewGroup; 21 22 import com.android.photoeditor.FilterStack; 23 import com.android.photoeditor.R; 24 import com.android.photoeditor.animation.Rotate3DAnimation; 25 import com.android.photoeditor.filters.FlipFilter; 26 27 /** 28 * An action handling flip effect. 29 */ 30 public class FlipAction extends FilterAction { 31 32 private static final int ANIMATION_DURATION = 500; 33 34 private boolean flipHorizontal; 35 private boolean flipVertical; 36 FlipAction(FilterStack filterStack, ViewGroup tools)37 public FlipAction(FilterStack filterStack, ViewGroup tools) { 38 super(filterStack, tools, R.string.flip_tooltip); 39 } 40 41 @Override onBegin()42 public void onBegin() { 43 final FlipFilter filter = new FlipFilter(); 44 45 touchView.setSwipeListener(new TouchView.SwipeListener() { 46 47 @Override 48 public void onSwipeDown() { 49 setFlipAnimations(Rotate3DAnimation.Rotate.DOWN); 50 flipFilterVertically(filter); 51 } 52 53 @Override 54 public void onSwipeLeft() { 55 setFlipAnimations(Rotate3DAnimation.Rotate.LEFT); 56 flipFilterHorizontally(filter); 57 } 58 59 @Override 60 public void onSwipeRight() { 61 setFlipAnimations(Rotate3DAnimation.Rotate.RIGHT); 62 flipFilterHorizontally(filter); 63 } 64 65 @Override 66 public void onSwipeUp() { 67 setFlipAnimations(Rotate3DAnimation.Rotate.UP); 68 flipFilterVertically(filter); 69 } 70 }); 71 touchView.setVisibility(View.VISIBLE); 72 73 flipHorizontal = false; 74 flipVertical = false; 75 setFlipAnimations(Rotate3DAnimation.Rotate.RIGHT); 76 flipFilterHorizontally(filter); 77 } 78 79 @Override onEnd()80 public void onEnd() { 81 } 82 setFlipAnimations(Rotate3DAnimation.Rotate rotate)83 private void setFlipAnimations(Rotate3DAnimation.Rotate rotate) { 84 photoView.setTransitionAnimations( 85 Rotate3DAnimation.getFlipAnimations(rotate, ANIMATION_DURATION)); 86 } 87 flipFilterHorizontally(final FlipFilter filter)88 private void flipFilterHorizontally(final FlipFilter filter) { 89 flipHorizontal = !flipHorizontal; 90 filter.setFlip(flipHorizontal, flipVertical); 91 notifyFilterChanged(filter, true); 92 } 93 flipFilterVertically(final FlipFilter filter)94 private void flipFilterVertically(final FlipFilter filter) { 95 flipVertical = !flipVertical; 96 filter.setFlip(flipHorizontal, flipVertical); 97 notifyFilterChanged(filter, true); 98 } 99 } 100