1b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk/* 2b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk * Copyright (C) 2013 The Android Open Source Project 3b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk * 4b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk * Licensed under the Apache License, Version 2.0 (the "License"); 5b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk * you may not use this file except in compliance with the License. 6b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk * You may obtain a copy of the License at 7b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk * 8b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk * http://www.apache.org/licenses/LICENSE-2.0 9b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk * 10b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk * Unless required by applicable law or agreed to in writing, software 11b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk * distributed under the License is distributed on an "AS IS" BASIS, 12b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk * See the License for the specific language governing permissions and 14b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk * limitations under the License. 15b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk */ 16b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk 17b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunkpackage com.android.gallery3d.filtershow.imageshow; 18b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk 19b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunkimport android.content.Context; 20b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunkimport android.graphics.Bitmap; 21b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunkimport android.graphics.Canvas; 22b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunkimport android.util.AttributeSet; 23b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunkimport android.view.MotionEvent; 24b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk 25b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunkimport com.android.gallery3d.filtershow.editors.EditorMirror; 26b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunkimport com.android.gallery3d.filtershow.filters.FilterMirrorRepresentation; 27b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunkimport com.android.gallery3d.filtershow.imageshow.GeometryMathUtils.GeometryHolder; 28b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk 29b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunkpublic class ImageMirror extends ImageShow { 30b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk private static final String TAG = ImageMirror.class.getSimpleName(); 31b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk private EditorMirror mEditorMirror; 32b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk private FilterMirrorRepresentation mLocalRep = new FilterMirrorRepresentation(); 33b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk private GeometryHolder mDrawHolder = new GeometryHolder(); 34b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk 35b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk public ImageMirror(Context context, AttributeSet attrs) { 36b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk super(context, attrs); 37b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk } 38b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk 39b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk public ImageMirror(Context context) { 40b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk super(context); 41b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk } 42b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk 43b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk public void setFilterMirrorRepresentation(FilterMirrorRepresentation rep) { 44b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk mLocalRep = (rep == null) ? new FilterMirrorRepresentation() : rep; 45b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk } 46b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk 47b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk public void flip() { 48b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk mLocalRep.cycle(); 49b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk invalidate(); 50b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk } 51b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk 52b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk public FilterMirrorRepresentation getFinalRepresentation() { 53b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk return mLocalRep; 54b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk } 55b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk 56b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk @Override 57b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk public boolean onTouchEvent(MotionEvent event) { 58b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk // Treat event as handled. 59b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk return true; 60b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk } 61b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk 62b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk @Override 63b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk public void onDraw(Canvas canvas) { 64b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk MasterImage master = MasterImage.getImage(); 65b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk Bitmap image = master.getFiltersOnlyImage(); 66b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk if (image == null) { 67b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk return; 68b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk } 69b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk GeometryMathUtils.initializeHolder(mDrawHolder, mLocalRep); 70b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk GeometryMathUtils.drawTransformedCropped(mDrawHolder, canvas, image, getWidth(), 71b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk getHeight()); 72b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk } 73b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk 74b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk public void setEditor(EditorMirror editorFlip) { 75b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk mEditorMirror = editorFlip; 76b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk } 77b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk 78b0f7a8f7f7d95ae12e92f529fd9a8a37f75b105cRuben Brunk} 79