112017c1b3bc314b5fee96c3b2a033d7877ea84e4John Hoford/*
212017c1b3bc314b5fee96c3b2a033d7877ea84e4John Hoford * Copyright (C) 2013 The Android Open Source Project
312017c1b3bc314b5fee96c3b2a033d7877ea84e4John Hoford *
412017c1b3bc314b5fee96c3b2a033d7877ea84e4John Hoford * Licensed under the Apache License, Version 2.0 (the "License");
512017c1b3bc314b5fee96c3b2a033d7877ea84e4John Hoford * you may not use this file except in compliance with the License.
612017c1b3bc314b5fee96c3b2a033d7877ea84e4John Hoford * You may obtain a copy of the License at
712017c1b3bc314b5fee96c3b2a033d7877ea84e4John Hoford *
812017c1b3bc314b5fee96c3b2a033d7877ea84e4John Hoford *      http://www.apache.org/licenses/LICENSE-2.0
912017c1b3bc314b5fee96c3b2a033d7877ea84e4John Hoford *
1012017c1b3bc314b5fee96c3b2a033d7877ea84e4John Hoford * Unless required by applicable law or agreed to in writing, software
1112017c1b3bc314b5fee96c3b2a033d7877ea84e4John Hoford * distributed under the License is distributed on an "AS IS" BASIS,
1212017c1b3bc314b5fee96c3b2a033d7877ea84e4John Hoford * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1312017c1b3bc314b5fee96c3b2a033d7877ea84e4John Hoford * See the License for the specific language governing permissions and
1412017c1b3bc314b5fee96c3b2a033d7877ea84e4John Hoford * limitations under the License.
1512017c1b3bc314b5fee96c3b2a033d7877ea84e4John Hoford */
1612017c1b3bc314b5fee96c3b2a033d7877ea84e4John Hoford
1712017c1b3bc314b5fee96c3b2a033d7877ea84e4John Hofordpackage com.android.gallery3d.filtershow.imageshow;
1812017c1b3bc314b5fee96c3b2a033d7877ea84e4John Hoford
1912017c1b3bc314b5fee96c3b2a033d7877ea84e4John Hofordimport android.content.Context;
2012017c1b3bc314b5fee96c3b2a033d7877ea84e4John Hofordimport android.graphics.Canvas;
2112017c1b3bc314b5fee96c3b2a033d7877ea84e4John Hofordimport android.graphics.Color;
2212017c1b3bc314b5fee96c3b2a033d7877ea84e4John Hofordimport android.graphics.Matrix;
2312017c1b3bc314b5fee96c3b2a033d7877ea84e4John Hofordimport android.graphics.Paint;
2412017c1b3bc314b5fee96c3b2a033d7877ea84e4John Hofordimport android.graphics.Paint.Style;
2512017c1b3bc314b5fee96c3b2a033d7877ea84e4John Hofordimport android.util.AttributeSet;
2612017c1b3bc314b5fee96c3b2a033d7877ea84e4John Hoford
2712017c1b3bc314b5fee96c3b2a033d7877ea84e4John Hofordimport com.android.gallery3d.filtershow.editors.EditorRedEye;
2812017c1b3bc314b5fee96c3b2a033d7877ea84e4John Hofordimport com.android.gallery3d.filtershow.filters.FilterPoint;
2912017c1b3bc314b5fee96c3b2a033d7877ea84e4John Hofordimport com.android.gallery3d.filtershow.filters.FilterRedEyeRepresentation;
3012017c1b3bc314b5fee96c3b2a033d7877ea84e4John Hofordimport com.android.gallery3d.filtershow.filters.ImageFilterRedEye;
3112017c1b3bc314b5fee96c3b2a033d7877ea84e4John Hoford
3212017c1b3bc314b5fee96c3b2a033d7877ea84e4John Hofordpublic abstract class ImagePoint extends ImageShow {
3312017c1b3bc314b5fee96c3b2a033d7877ea84e4John Hoford
3412017c1b3bc314b5fee96c3b2a033d7877ea84e4John Hoford    private static final String LOGTAG = "ImageRedEyes";
3512017c1b3bc314b5fee96c3b2a033d7877ea84e4John Hoford    protected EditorRedEye mEditorRedEye;
3612017c1b3bc314b5fee96c3b2a033d7877ea84e4John Hoford    protected FilterRedEyeRepresentation mRedEyeRep;
3712017c1b3bc314b5fee96c3b2a033d7877ea84e4John Hoford    protected static float mTouchPadding = 80;
3812017c1b3bc314b5fee96c3b2a033d7877ea84e4John Hoford
3912017c1b3bc314b5fee96c3b2a033d7877ea84e4John Hoford    public static void setTouchPadding(float padding) {
4012017c1b3bc314b5fee96c3b2a033d7877ea84e4John Hoford        mTouchPadding = padding;
4112017c1b3bc314b5fee96c3b2a033d7877ea84e4John Hoford    }
4212017c1b3bc314b5fee96c3b2a033d7877ea84e4John Hoford
4312017c1b3bc314b5fee96c3b2a033d7877ea84e4John Hoford    public ImagePoint(Context context, AttributeSet attrs) {
4412017c1b3bc314b5fee96c3b2a033d7877ea84e4John Hoford        super(context, attrs);
4512017c1b3bc314b5fee96c3b2a033d7877ea84e4John Hoford    }
4612017c1b3bc314b5fee96c3b2a033d7877ea84e4John Hoford
4712017c1b3bc314b5fee96c3b2a033d7877ea84e4John Hoford    public ImagePoint(Context context) {
4812017c1b3bc314b5fee96c3b2a033d7877ea84e4John Hoford        super(context);
4912017c1b3bc314b5fee96c3b2a033d7877ea84e4John Hoford    }
5012017c1b3bc314b5fee96c3b2a033d7877ea84e4John Hoford
5112017c1b3bc314b5fee96c3b2a033d7877ea84e4John Hoford    @Override
5212017c1b3bc314b5fee96c3b2a033d7877ea84e4John Hoford    public void resetParameter() {
5312017c1b3bc314b5fee96c3b2a033d7877ea84e4John Hoford        ImageFilterRedEye filter = (ImageFilterRedEye) getCurrentFilter();
5412017c1b3bc314b5fee96c3b2a033d7877ea84e4John Hoford        if (filter != null) {
5512017c1b3bc314b5fee96c3b2a033d7877ea84e4John Hoford            filter.clear();
5612017c1b3bc314b5fee96c3b2a033d7877ea84e4John Hoford        }
5712017c1b3bc314b5fee96c3b2a033d7877ea84e4John Hoford        invalidate();
5812017c1b3bc314b5fee96c3b2a033d7877ea84e4John Hoford    }
5912017c1b3bc314b5fee96c3b2a033d7877ea84e4John Hoford
6012017c1b3bc314b5fee96c3b2a033d7877ea84e4John Hoford    @Override
6112017c1b3bc314b5fee96c3b2a033d7877ea84e4John Hoford    public void onDraw(Canvas canvas) {
6212017c1b3bc314b5fee96c3b2a033d7877ea84e4John Hoford        super.onDraw(canvas);
6312017c1b3bc314b5fee96c3b2a033d7877ea84e4John Hoford        Paint paint = new Paint();
6412017c1b3bc314b5fee96c3b2a033d7877ea84e4John Hoford        paint.setStyle(Style.STROKE);
6512017c1b3bc314b5fee96c3b2a033d7877ea84e4John Hoford        paint.setColor(Color.RED);
6612017c1b3bc314b5fee96c3b2a033d7877ea84e4John Hoford        paint.setStrokeWidth(2);
6712017c1b3bc314b5fee96c3b2a033d7877ea84e4John Hoford
68a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford        Matrix originalToScreen = getImageToScreenMatrix(false);
69a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford        Matrix originalRotateToScreen = getImageToScreenMatrix(true);
70a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford
7112017c1b3bc314b5fee96c3b2a033d7877ea84e4John Hoford        if (mRedEyeRep != null) {
7212017c1b3bc314b5fee96c3b2a033d7877ea84e4John Hoford            for (FilterPoint candidate : mRedEyeRep.getCandidates()) {
7312017c1b3bc314b5fee96c3b2a033d7877ea84e4John Hoford                drawPoint(candidate, canvas, originalToScreen, originalRotateToScreen, paint);
7412017c1b3bc314b5fee96c3b2a033d7877ea84e4John Hoford            }
7512017c1b3bc314b5fee96c3b2a033d7877ea84e4John Hoford        }
7612017c1b3bc314b5fee96c3b2a033d7877ea84e4John Hoford    }
7712017c1b3bc314b5fee96c3b2a033d7877ea84e4John Hoford
7812017c1b3bc314b5fee96c3b2a033d7877ea84e4John Hoford    protected abstract void drawPoint(
7912017c1b3bc314b5fee96c3b2a033d7877ea84e4John Hoford            FilterPoint candidate, Canvas canvas, Matrix originalToScreen,
8012017c1b3bc314b5fee96c3b2a033d7877ea84e4John Hoford            Matrix originalRotateToScreen, Paint paint);
8112017c1b3bc314b5fee96c3b2a033d7877ea84e4John Hoford
8212017c1b3bc314b5fee96c3b2a033d7877ea84e4John Hoford    public void setEditor(EditorRedEye editorRedEye) {
8312017c1b3bc314b5fee96c3b2a033d7877ea84e4John Hoford        mEditorRedEye = editorRedEye;
8412017c1b3bc314b5fee96c3b2a033d7877ea84e4John Hoford    }
8512017c1b3bc314b5fee96c3b2a033d7877ea84e4John Hoford
8612017c1b3bc314b5fee96c3b2a033d7877ea84e4John Hoford    public void setRepresentation(FilterRedEyeRepresentation redEyeRep) {
8712017c1b3bc314b5fee96c3b2a033d7877ea84e4John Hoford        mRedEyeRep = redEyeRep;
8812017c1b3bc314b5fee96c3b2a033d7877ea84e4John Hoford    }
8912017c1b3bc314b5fee96c3b2a033d7877ea84e4John Hoford}
90