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.filtershow.imageshow; 18 19 import android.content.Context; 20 import android.graphics.Bitmap; 21 import android.graphics.Canvas; 22 import android.util.AttributeSet; 23 import android.view.MotionEvent; 24 25 import com.android.gallery3d.filtershow.editors.EditorRotate; 26 import com.android.gallery3d.filtershow.filters.FilterRotateRepresentation; 27 import com.android.gallery3d.filtershow.imageshow.GeometryMathUtils.GeometryHolder; 28 29 public class ImageRotate extends ImageShow { 30 private EditorRotate mEditorRotate; 31 private static final String TAG = ImageRotate.class.getSimpleName(); 32 private FilterRotateRepresentation mLocalRep = new FilterRotateRepresentation(); 33 private GeometryHolder mDrawHolder = new GeometryHolder(); 34 35 public ImageRotate(Context context, AttributeSet attrs) { 36 super(context, attrs); 37 } 38 39 public ImageRotate(Context context) { 40 super(context); 41 } 42 43 public void setFilterRotateRepresentation(FilterRotateRepresentation rep) { 44 mLocalRep = (rep == null) ? new FilterRotateRepresentation() : rep; 45 } 46 47 public void rotate() { 48 mLocalRep.rotateCW(); 49 invalidate(); 50 } 51 52 public FilterRotateRepresentation getFinalRepresentation() { 53 return mLocalRep; 54 } 55 56 @Override 57 public boolean onTouchEvent(MotionEvent event) { 58 // Treat event as handled. 59 return true; 60 } 61 62 public int getLocalValue() { 63 return mLocalRep.getRotation().value(); 64 } 65 66 @Override 67 public void onDraw(Canvas canvas) { 68 MasterImage master = MasterImage.getImage(); 69 Bitmap image = master.getFiltersOnlyImage(); 70 if (image == null) { 71 return; 72 } 73 GeometryMathUtils.initializeHolder(mDrawHolder, mLocalRep); 74 GeometryMathUtils.drawTransformedCropped(mDrawHolder, canvas, image, canvas.getWidth(), 75 canvas.getHeight()); 76 } 77 78 public void setEditor(EditorRotate editorRotate) { 79 mEditorRotate = editorRotate; 80 } 81 } 82