1/*
2 * Copyright (C) 2013 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
17package com.android.gallery3d.filtershow.imageshow;
18
19import android.content.Context;
20import android.graphics.Bitmap;
21import android.graphics.Canvas;
22import android.util.AttributeSet;
23import android.view.MotionEvent;
24
25import com.android.gallery3d.filtershow.editors.EditorMirror;
26import com.android.gallery3d.filtershow.filters.FilterMirrorRepresentation;
27import com.android.gallery3d.filtershow.imageshow.GeometryMathUtils.GeometryHolder;
28
29public class ImageMirror extends ImageShow {
30    private static final String TAG = ImageMirror.class.getSimpleName();
31    private EditorMirror mEditorMirror;
32    private FilterMirrorRepresentation mLocalRep = new FilterMirrorRepresentation();
33    private GeometryHolder mDrawHolder = new GeometryHolder();
34
35    public ImageMirror(Context context, AttributeSet attrs) {
36        super(context, attrs);
37    }
38
39    public ImageMirror(Context context) {
40        super(context);
41    }
42
43    public void setFilterMirrorRepresentation(FilterMirrorRepresentation rep) {
44        mLocalRep = (rep == null) ? new FilterMirrorRepresentation() : rep;
45    }
46
47    public void flip() {
48        mLocalRep.cycle();
49        invalidate();
50    }
51
52    public FilterMirrorRepresentation 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    @Override
63    public void onDraw(Canvas canvas) {
64        MasterImage master = MasterImage.getImage();
65        Bitmap image = master.getFiltersOnlyImage();
66        if (image == null) {
67            return;
68        }
69        GeometryMathUtils.initializeHolder(mDrawHolder, mLocalRep);
70        GeometryMathUtils.drawTransformedCropped(mDrawHolder, canvas, image, getWidth(),
71                getHeight());
72    }
73
74    public void setEditor(EditorMirror editorFlip) {
75        mEditorMirror = editorFlip;
76    }
77
78}
79