Home | History | Annotate | Download | only in actions
      1 /*
      2  * Copyright (C) 2010 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.photoeditor.actions;
     18 
     19 import android.graphics.Path;
     20 import android.view.View;
     21 import android.view.ViewGroup;
     22 
     23 import com.android.photoeditor.FilterStack;
     24 import com.android.photoeditor.R;
     25 import com.android.photoeditor.filters.DoodleFilter;
     26 
     27 /**
     28  * An action handling doodle effect.
     29  */
     30 public class DoodleAction extends FilterAction {
     31 
     32     private static final int DEFAULT_COLOR_INDEX = 4;
     33 
     34     private DoodleFilter filter;
     35 
     36     public DoodleAction(FilterStack filterStack, ViewGroup tools) {
     37         super(filterStack, tools, R.string.doodle_tooltip);
     38     }
     39 
     40     @Override
     41     public void onBegin() {
     42         filter = new DoodleFilter();
     43 
     44         colorWheel.setOnColorChangeListener(new ColorWheel.OnColorChangeListener() {
     45 
     46             @Override
     47             public void onColorChanged(int color, boolean fromUser){
     48                 if (fromUser) {
     49                     doodleView.startPath(color);
     50                     filter.addPath(color);
     51                 }
     52             }
     53         });
     54         colorWheel.setColorIndex(DEFAULT_COLOR_INDEX);
     55         colorWheel.setVisibility(View.VISIBLE);
     56 
     57         // Directly draw on doodle-view instead of waiting for top-filter output callback.
     58         doodleView.setOnDoodleChangeListener(new DoodleView.OnDoodleChangeListener() {
     59 
     60             private final Path transformPath = new Path();
     61 
     62             @Override
     63             public void onLastPathChanged(Path path) {
     64                 photoView.mapPhotoPath(path, transformPath);
     65                 filter.updateLastPath(transformPath);
     66                 notifyFilterChanged(filter, false);
     67             }
     68         });
     69         doodleView.clear();
     70         doodleView.clipBounds(photoView.getPhotoDisplayBounds());
     71         doodleView.setVisibility(View.VISIBLE);
     72 
     73         int color = colorWheel.getColor();
     74         doodleView.startPath(color);
     75 
     76         filter.addPath(color);
     77     }
     78 
     79     @Override
     80     public void onEnd() {
     81         notifyFilterChanged(filter, true);
     82     }
     83 }
     84