Home | History | Annotate | Download | only in imageshow
      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 
     17 package com.android.gallery3d.filtershow.imageshow;
     18 
     19 import android.content.Context;
     20 import android.graphics.Canvas;
     21 import android.graphics.Color;
     22 import android.graphics.Matrix;
     23 import android.graphics.Paint;
     24 import android.graphics.Paint.Style;
     25 import android.util.AttributeSet;
     26 
     27 import com.android.gallery3d.filtershow.editors.EditorRedEye;
     28 import com.android.gallery3d.filtershow.filters.FilterPoint;
     29 import com.android.gallery3d.filtershow.filters.FilterRedEyeRepresentation;
     30 import com.android.gallery3d.filtershow.filters.ImageFilterRedEye;
     31 
     32 public abstract class ImagePoint extends ImageShow {
     33 
     34     private static final String LOGTAG = "ImageRedEyes";
     35     protected EditorRedEye mEditorRedEye;
     36     protected FilterRedEyeRepresentation mRedEyeRep;
     37     protected static float mTouchPadding = 80;
     38 
     39     public static void setTouchPadding(float padding) {
     40         mTouchPadding = padding;
     41     }
     42 
     43     public ImagePoint(Context context, AttributeSet attrs) {
     44         super(context, attrs);
     45     }
     46 
     47     public ImagePoint(Context context) {
     48         super(context);
     49     }
     50 
     51     @Override
     52     public void resetParameter() {
     53         ImageFilterRedEye filter = (ImageFilterRedEye) getCurrentFilter();
     54         if (filter != null) {
     55             filter.clear();
     56         }
     57         invalidate();
     58     }
     59 
     60     @Override
     61     public void onDraw(Canvas canvas) {
     62         super.onDraw(canvas);
     63         Paint paint = new Paint();
     64         paint.setStyle(Style.STROKE);
     65         paint.setColor(Color.RED);
     66         paint.setStrokeWidth(2);
     67 
     68         Matrix originalToScreen = getImageToScreenMatrix(false);
     69         Matrix originalRotateToScreen = getImageToScreenMatrix(true);
     70 
     71         if (mRedEyeRep != null) {
     72             for (FilterPoint candidate : mRedEyeRep.getCandidates()) {
     73                 drawPoint(candidate, canvas, originalToScreen, originalRotateToScreen, paint);
     74             }
     75         }
     76     }
     77 
     78     protected abstract void drawPoint(
     79             FilterPoint candidate, Canvas canvas, Matrix originalToScreen,
     80             Matrix originalRotateToScreen, Paint paint);
     81 
     82     public void setEditor(EditorRedEye editorRedEye) {
     83         mEditorRedEye = editorRedEye;
     84     }
     85 
     86     public void setRepresentation(FilterRedEyeRepresentation redEyeRep) {
     87         mRedEyeRep = redEyeRep;
     88     }
     89 }
     90