diff options
author | Yuli Huang <yuli@google.com> | 2011-11-28 20:05:27 +0800 |
---|---|---|
committer | Yuli Huang <yuli@google.com> | 2011-12-02 00:57:02 +0800 |
commit | 11571bf7436900b513dd3696a90f546b25839591 (patch) | |
tree | 37320f29530b7e641f7243c64afd0e8504b0491f /src/com/android/gallery3d/photoeditor | |
parent | 5a7fe75b7c95c2612b4a27ebaaa8d324fac6a849 (diff) | |
download | android_packages_apps_Snap-11571bf7436900b513dd3696a90f546b25839591.tar.gz android_packages_apps_Snap-11571bf7436900b513dd3696a90f546b25839591.tar.bz2 android_packages_apps_Snap-11571bf7436900b513dd3696a90f546b25839591.zip |
Refactor to remove obsolete design and improve code consistency.
1. Remove isValid()/validate() in Filter; EffectAction would push
filters into the stack when being notified by notifyChanged().
2. Make RedEyeAction consistent with DoodleAction by ignoring
out-of-bounds operations.
3. Improve consistency by encapsulate effect-tool creation/removal in
one class (EffectToolFactory).
4. Minimize variable visibility in EffectAction subclasses.
5. Fix unfinished doodle lost when exiting Doodle effect by multi-touch.
Change-Id: I8d3b127c5fe8777eb45b7c5ae680f6a30a99635a
Diffstat (limited to 'src/com/android/gallery3d/photoeditor')
50 files changed, 241 insertions, 500 deletions
diff --git a/src/com/android/gallery3d/photoeditor/EffectsBar.java b/src/com/android/gallery3d/photoeditor/EffectsBar.java index 40754040c..1aafc4e5d 100644 --- a/src/com/android/gallery3d/photoeditor/EffectsBar.java +++ b/src/com/android/gallery3d/photoeditor/EffectsBar.java @@ -92,6 +92,7 @@ public class EffectsBar extends LinearLayout { activeEffect = effect; exitEffectsGallery(); // Create effect tool panel first before the factory could create tools within. + // TODO: Refactor to encapsulate effect-tool panel in effect-tool factory. createEffectToolPanel(); activeEffect.begin(filterStack, new EffectToolFactory(effectToolPanel, inflater)); @@ -134,11 +135,6 @@ public class EffectsBar extends LinearLayout { @Override public void run() { SpinnerProgressDialog.dismissDialog(); - View fullscreenTool = getRootView().findViewById(R.id.fullscreen_effect_tool); - if (fullscreenTool != null) { - ((ViewGroup) fullscreenTool.getParent()).removeView(fullscreenTool); - } - removeView(effectToolPanel); effectToolPanel = null; activeEffect = null; if (runnableOnDone != null) { diff --git a/src/com/android/gallery3d/photoeditor/actions/AutoFixAction.java b/src/com/android/gallery3d/photoeditor/actions/AutoFixAction.java index 26b5f51dc..6b3f184b4 100644 --- a/src/com/android/gallery3d/photoeditor/actions/AutoFixAction.java +++ b/src/com/android/gallery3d/photoeditor/actions/AutoFixAction.java @@ -33,14 +33,10 @@ public class AutoFixAction extends EffectAction { } @Override - public void doBegin() { + public void prepare() { AutoFixFilter filter = new AutoFixFilter(); filter.setScale(DEFAULT_SCALE); - notifyFilterChanged(filter, true); + notifyChanged(filter); notifyDone(); } - - @Override - public void doEnd() { - } } diff --git a/src/com/android/gallery3d/photoeditor/actions/ColorTemperatureAction.java b/src/com/android/gallery3d/photoeditor/actions/ColorTemperatureAction.java index 24978faf0..ac329a038 100644 --- a/src/com/android/gallery3d/photoeditor/actions/ColorTemperatureAction.java +++ b/src/com/android/gallery3d/photoeditor/actions/ColorTemperatureAction.java @@ -28,32 +28,25 @@ public class ColorTemperatureAction extends EffectAction { private static final float DEFAULT_SCALE = 0.5f; - private ScaleSeekBar scalePicker; - public ColorTemperatureAction(Context context, AttributeSet attrs) { super(context, attrs); } @Override - public void doBegin() { + public void prepare() { final ColorTemperatureFilter filter = new ColorTemperatureFilter(); - scalePicker = factory.createScalePicker(EffectToolFactory.ScalePickerType.COLOR); + ScaleSeekBar scalePicker = factory.createScalePicker(EffectToolFactory.ScaleType.COLOR); scalePicker.setOnScaleChangeListener(new ScaleSeekBar.OnScaleChangeListener() { @Override public void onProgressChanged(float progress, boolean fromUser) { if (fromUser) { filter.setScale(progress); - notifyFilterChanged(filter, true); + notifyChanged(filter); } } }); scalePicker.setProgress(DEFAULT_SCALE); } - - @Override - public void doEnd() { - scalePicker.setOnScaleChangeListener(null); - } } diff --git a/src/com/android/gallery3d/photoeditor/actions/CropAction.java b/src/com/android/gallery3d/photoeditor/actions/CropAction.java index 60a01793f..0a3d12f56 100644 --- a/src/com/android/gallery3d/photoeditor/actions/CropAction.java +++ b/src/com/android/gallery3d/photoeditor/actions/CropAction.java @@ -29,25 +29,24 @@ public class CropAction extends EffectAction { private static final float DEFAULT_CROP = 0.2f; - private CropFilter filter; - private CropView cropView; - public CropAction(Context context, AttributeSet attrs) { super(context, attrs); } @Override - public void doBegin() { - filter = new CropFilter(); + public void prepare() { + // Cropped results wouldn't be previewed for changed crop bounds. + final CropFilter filter = new CropFilter(); + disableFilterOutput(); - cropView = factory.createCropView(); + CropView cropView = factory.createCropView(); cropView.setOnCropChangeListener(new CropView.OnCropChangeListener() { @Override public void onCropChanged(RectF cropBounds, boolean fromUser) { if (fromUser) { filter.setCropBounds(cropBounds); - notifyFilterChanged(filter, false); + notifyChanged(filter); } } }); @@ -55,12 +54,6 @@ public class CropAction extends EffectAction { RectF bounds = new RectF(DEFAULT_CROP, DEFAULT_CROP, 1 - DEFAULT_CROP, 1 - DEFAULT_CROP); cropView.setCropBounds(bounds); filter.setCropBounds(bounds); - notifyFilterChanged(filter, false); - } - - @Override - public void doEnd() { - cropView.setOnCropChangeListener(null); - notifyFilterChanged(filter, true); + notifyChanged(filter); } } diff --git a/src/com/android/gallery3d/photoeditor/actions/CrossProcessAction.java b/src/com/android/gallery3d/photoeditor/actions/CrossProcessAction.java index 8be60d307..7369dc552 100644 --- a/src/com/android/gallery3d/photoeditor/actions/CrossProcessAction.java +++ b/src/com/android/gallery3d/photoeditor/actions/CrossProcessAction.java @@ -31,12 +31,8 @@ public class CrossProcessAction extends EffectAction { } @Override - public void doBegin() { - notifyFilterChanged(new CrossProcessFilter(), true); + public void prepare() { + notifyChanged(new CrossProcessFilter()); notifyDone(); } - - @Override - public void doEnd() { - } } diff --git a/src/com/android/gallery3d/photoeditor/actions/DocumentaryAction.java b/src/com/android/gallery3d/photoeditor/actions/DocumentaryAction.java index 0ec4a0205..d1fd61171 100644 --- a/src/com/android/gallery3d/photoeditor/actions/DocumentaryAction.java +++ b/src/com/android/gallery3d/photoeditor/actions/DocumentaryAction.java @@ -31,12 +31,8 @@ public class DocumentaryAction extends EffectAction { } @Override - public void doBegin() { - notifyFilterChanged(new DocumentaryFilter(), true); + public void prepare() { + notifyChanged(new DocumentaryFilter()); notifyDone(); } - - @Override - public void doEnd() { - } } diff --git a/src/com/android/gallery3d/photoeditor/actions/Doodle.java b/src/com/android/gallery3d/photoeditor/actions/Doodle.java index ea23e2380..bd08983ba 100644 --- a/src/com/android/gallery3d/photoeditor/actions/Doodle.java +++ b/src/com/android/gallery3d/photoeditor/actions/Doodle.java @@ -55,18 +55,21 @@ public class Doodle implements Parcelable { } /** + * Checks if the constructed doodle path is in (0, 0, 1, 1) bounds. + */ + public boolean inBounds() { + RectF r = new RectF(); + normalizedPath.computeBounds(r, false); + return r.intersects(0, 0, 1, 1); + } + + /** * Adds control points whose coordinates range from 0 to 1 to construct the doodle path. - * - * @return true if the constructed path is in (0, 0, 1, 1) bounds; otherwise, false. */ - public boolean addControlPoint(PointF point) { + public void addControlPoint(PointF point) { PointF last = points.lastElement(); normalizedPath.quadTo(last.x, last.y, (last.x + point.x) / 2, (last.y + point.y) / 2); points.add(point); - - RectF r = new RectF(); - normalizedPath.computeBounds(r, false); - return r.intersects(0, 0, 1, 1); } public int getColor() { diff --git a/src/com/android/gallery3d/photoeditor/actions/DoodleAction.java b/src/com/android/gallery3d/photoeditor/actions/DoodleAction.java index 4ad2cfb11..ca999c1f2 100644 --- a/src/com/android/gallery3d/photoeditor/actions/DoodleAction.java +++ b/src/com/android/gallery3d/photoeditor/actions/DoodleAction.java @@ -28,53 +28,47 @@ public class DoodleAction extends EffectAction { private static final int DEFAULT_COLOR_INDEX = 4; - private DoodleFilter filter; - private ColorSeekBar colorPicker; - private DoodleView doodleView; - public DoodleAction(Context context, AttributeSet attrs) { super(context, attrs); } @Override - public void doBegin() { - filter = new DoodleFilter(); + public void prepare() { + // Directly draw on doodle-view because running the doodle filter isn't fast enough. + final DoodleFilter filter = new DoodleFilter(); + disableFilterOutput(); - colorPicker = factory.createColorPicker(); - colorPicker.setOnColorChangeListener(new ColorSeekBar.OnColorChangeListener() { + final DoodleView doodleView = factory.createDoodleView(); + doodleView.setOnDoodleChangeListener(new DoodleView.OnDoodleChangeListener() { @Override - public void onColorChanged(int color, boolean fromUser) { - if (fromUser) { - doodleView.setColor(color); + public void onDoodleChanged(Doodle doodle) { + // Check if the user draws within photo bounds and makes visible changes on photo. + if (doodle.inBounds()) { + notifyChanged(filter); } } - }); - colorPicker.setColorIndex(DEFAULT_COLOR_INDEX); - - doodleView = factory.createDoodleView(); - doodleView.setOnDoodleChangeListener(new DoodleView.OnDoodleChangeListener() { @Override - public void onDoodleInPhotoBounds() { - // Notify the user has drawn within photo bounds and made visible changes on photo. - filter.setDoodledInPhotoBounds(); - notifyFilterChanged(filter, false); + public void onDoodleFinished(Doodle doodle) { + if (doodle.inBounds()) { + filter.addDoodle(doodle); + notifyChanged(filter); + } } + }); + + ColorSeekBar colorPicker = factory.createColorPicker(); + colorPicker.setOnColorChangeListener(new ColorSeekBar.OnColorChangeListener() { @Override - public void onDoodleFinished(Doodle doodle) { - filter.addDoodle(doodle); - notifyFilterChanged(filter, false); + public void onColorChanged(int color, boolean fromUser) { + if (fromUser) { + doodleView.setColor(color); + } } }); + colorPicker.setColorIndex(DEFAULT_COLOR_INDEX); doodleView.setColor(colorPicker.getColor()); } - - @Override - public void doEnd() { - colorPicker.setOnColorChangeListener(null); - doodleView.setOnDoodleChangeListener(null); - notifyFilterChanged(filter, true); - } } diff --git a/src/com/android/gallery3d/photoeditor/actions/DoodleView.java b/src/com/android/gallery3d/photoeditor/actions/DoodleView.java index b59686151..d39604939 100644 --- a/src/com/android/gallery3d/photoeditor/actions/DoodleView.java +++ b/src/com/android/gallery3d/photoeditor/actions/DoodleView.java @@ -37,7 +37,7 @@ class DoodleView extends FullscreenToolView { */ public interface OnDoodleChangeListener { - void onDoodleInPhotoBounds(); + void onDoodleChanged(Doodle doodle); void onDoodleFinished(Doodle doodle); } @@ -111,9 +111,10 @@ class DoodleView extends FullscreenToolView { } private void addLastPointIntoDoodle() { - if ((doodle != null) && doodle.addControlPoint(new PointF(lastPoint.x, lastPoint.y))) { + if (doodle != null) { + doodle.addControlPoint(new PointF(lastPoint.x, lastPoint.y)); if (listener != null) { - listener.onDoodleInPhotoBounds(); + listener.onDoodleChanged(doodle); } invalidate(); } diff --git a/src/com/android/gallery3d/photoeditor/actions/DuotoneAction.java b/src/com/android/gallery3d/photoeditor/actions/DuotoneAction.java index b8da71e25..57082c064 100644 --- a/src/com/android/gallery3d/photoeditor/actions/DuotoneAction.java +++ b/src/com/android/gallery3d/photoeditor/actions/DuotoneAction.java @@ -34,15 +34,11 @@ public class DuotoneAction extends EffectAction { } @Override - public void doBegin() { + public void prepare() { // TODO: Add several sets of duo-tone colors to select from. DuotoneFilter filter = new DuotoneFilter(); filter.setDuotone(DEFAULT_FIRST_COLOR, DEFAULT_SECOND_COLOR); - notifyFilterChanged(filter, true); + notifyChanged(filter); notifyDone(); } - - @Override - public void doEnd() { - } } diff --git a/src/com/android/gallery3d/photoeditor/actions/EffectAction.java b/src/com/android/gallery3d/photoeditor/actions/EffectAction.java index 6c6a893e3..c17ec232e 100644 --- a/src/com/android/gallery3d/photoeditor/actions/EffectAction.java +++ b/src/com/android/gallery3d/photoeditor/actions/EffectAction.java @@ -45,11 +45,11 @@ public abstract class EffectAction extends LinearLayout { } protected EffectToolFactory factory; - private Listener listener; private Toast tooltip; private FilterStack filterStack; private boolean pushedFilter; + private boolean disableFilterOutput; private FilterChangedCallback lastFilterChangedCallback; public EffectAction(Context context, AttributeSet attrs) { @@ -84,14 +84,24 @@ public abstract class EffectAction extends LinearLayout { tooltip.setGravity(Gravity.CENTER, 0, 0); tooltip.show(); } - doBegin(); + prepare(); } /** + * Subclasses should create a specific filter and bind the filter to necessary UI controls here + * when the action is about to begin. + */ + protected abstract void prepare(); + + /** * Ends the effect and then executes the runnable after the effect is finished. */ public void end(final Runnable runnableOnODone) { - doEnd(); + // Remove created tools before ending and output the pushed filter if it wasn't outputted. + factory.removeTools(); + if (pushedFilter && disableFilterOutput) { + outputFilter(); + } // Wait till last output callback is done before finishing. if ((lastFilterChangedCallback == null) || lastFilterChangedCallback.done) { @@ -114,39 +124,38 @@ public abstract class EffectAction extends LinearLayout { tooltip = null; } pushedFilter = false; + disableFilterOutput = false; lastFilterChangedCallback = null; runnableOnDone.run(); } - protected void notifyDone() { - if (listener != null) { - listener.onDone(); - } + protected void disableFilterOutput() { + // Filter output won't be outputted until this effect has done editing its filter. + disableFilterOutput = true; + } + + protected void outputFilter() { + // Notify the stack to execute the changed top filter and output the results. + lastFilterChangedCallback = new FilterChangedCallback(); + filterStack.topFilterChanged(lastFilterChangedCallback); } - protected void notifyFilterChanged(Filter filter, boolean output) { - if (!pushedFilter && filter.isValid()) { + protected void notifyChanged(Filter filter) { + if (!pushedFilter) { filterStack.pushFilter(filter); pushedFilter = true; } - if (pushedFilter && output) { - // Notify the stack to execute the changed top filter and output the results. - lastFilterChangedCallback = new FilterChangedCallback(); - filterStack.topFilterChanged(lastFilterChangedCallback); + if (pushedFilter && !disableFilterOutput) { + outputFilter(); } } - /** - * Subclasses should creates a specific filter and binds the filter to necessary UI controls - * here when the action is about to begin. - */ - protected abstract void doBegin(); - - /** - * Subclasses could do specific ending operations here when the action is about to end. - */ - protected abstract void doEnd(); + protected void notifyDone() { + if (listener != null) { + listener.onDone(); + } + } /** * Done callback for executing top filter changes. diff --git a/src/com/android/gallery3d/photoeditor/actions/EffectToolFactory.java b/src/com/android/gallery3d/photoeditor/actions/EffectToolFactory.java index 3641828a6..f68db8b6a 100644 --- a/src/com/android/gallery3d/photoeditor/actions/EffectToolFactory.java +++ b/src/com/android/gallery3d/photoeditor/actions/EffectToolFactory.java @@ -28,36 +28,54 @@ import com.android.gallery3d.photoeditor.PhotoView; */ public class EffectToolFactory { - public enum ScalePickerType { + public enum ScaleType { LIGHT, SHADOW, COLOR, GENERIC } private final ViewGroup effectToolPanel; private final LayoutInflater inflater; + private ViewGroup effectToolFullscreen; public EffectToolFactory(ViewGroup effectToolPanel, LayoutInflater inflater) { this.effectToolPanel = effectToolPanel; this.inflater = inflater; } + public PhotoView getPhotoView() { + return (PhotoView) effectToolPanel.getRootView().findViewById(R.id.photo_view); + } + + public void removeTools() { + // Remove all created tools. + if (effectToolFullscreen != null) { + ((ViewGroup) effectToolFullscreen.getParent()).removeView(effectToolFullscreen); + effectToolFullscreen = null; + } + ((ViewGroup) effectToolPanel.getParent()).removeView(effectToolPanel); + } + private View createFullscreenTool(int toolId) { // Create full screen effect tool on top of photo-view and place it within the same // view group that contains photo-view. - View photoView = effectToolPanel.getRootView().findViewById(R.id.photo_view); + PhotoView photoView = getPhotoView(); ViewGroup parent = (ViewGroup) photoView.getParent(); - FullscreenToolView view = (FullscreenToolView) inflater.inflate(toolId, parent, false); - view.setPhotoBounds(((PhotoView) photoView).getPhotoBounds()); - parent.addView(view, parent.indexOfChild(photoView) + 1); - return view; + effectToolFullscreen = (ViewGroup) inflater.inflate( + R.layout.photoeditor_effect_tool_fullscreen, parent, false); + parent.addView(effectToolFullscreen, parent.indexOfChild(photoView) + 1); + FullscreenToolView tool = (FullscreenToolView) inflater.inflate( + toolId, effectToolFullscreen, false); + tool.setPhotoBounds(photoView.getPhotoBounds()); + effectToolFullscreen.addView(tool); + return tool; } private View createPanelTool(int toolId) { - View view = inflater.inflate(toolId, effectToolPanel, false); - effectToolPanel.addView(view, 0); - return view; + View tool = inflater.inflate(toolId, effectToolPanel, false); + effectToolPanel.addView(tool); + return tool; } - private int getScalePickerBackground(ScalePickerType type) { + private int getScalePickerBackground(ScaleType type) { switch (type) { case LIGHT: return R.drawable.photoeditor_scale_seekbar_light; @@ -71,7 +89,7 @@ public class EffectToolFactory { return R.drawable.photoeditor_scale_seekbar_generic; } - public ScaleSeekBar createScalePicker(ScalePickerType type) { + public ScaleSeekBar createScalePicker(ScaleType type) { ScaleSeekBar scalePicker = (ScaleSeekBar) createPanelTool( R.layout.photoeditor_scale_seekbar); scalePicker.setBackgroundResource(getScalePickerBackground(type)); diff --git a/src/com/android/gallery3d/photoeditor/actions/FaceTanAction.java b/src/com/android/gallery3d/photoeditor/actions/FaceTanAction.java index a82f33079..6faa778a0 100644 --- a/src/com/android/gallery3d/photoeditor/actions/FaceTanAction.java +++ b/src/com/android/gallery3d/photoeditor/actions/FaceTanAction.java @@ -28,35 +28,28 @@ public class FaceTanAction extends EffectAction { private static final float DEFAULT_SCALE = 0.5f; - private ScaleSeekBar scalePicker; - public FaceTanAction(Context context, AttributeSet attrs) { super(context, attrs); } @Override - public void doBegin() { + public void prepare() { final FaceTanFilter filter = new FaceTanFilter(); - scalePicker = factory.createScalePicker(EffectToolFactory.ScalePickerType.GENERIC); + ScaleSeekBar scalePicker = factory.createScalePicker(EffectToolFactory.ScaleType.GENERIC); scalePicker.setOnScaleChangeListener(new ScaleSeekBar.OnScaleChangeListener() { @Override public void onProgressChanged(float progress, boolean fromUser) { if (fromUser) { filter.setScale(progress); - notifyFilterChanged(filter, true); + notifyChanged(filter); } } }); scalePicker.setProgress(DEFAULT_SCALE); filter.setScale(DEFAULT_SCALE); - notifyFilterChanged(filter, true); - } - - @Override - public void doEnd() { - scalePicker.setOnScaleChangeListener(null); + notifyChanged(filter); } } diff --git a/src/com/android/gallery3d/photoeditor/actions/FaceliftAction.java b/src/com/android/gallery3d/photoeditor/actions/FaceliftAction.java index 90d4e0c72..9afa7baab 100644 --- a/src/com/android/gallery3d/photoeditor/actions/FaceliftAction.java +++ b/src/com/android/gallery3d/photoeditor/actions/FaceliftAction.java @@ -28,35 +28,28 @@ public class FaceliftAction extends EffectAction { private static final float DEFAULT_SCALE = 0.5f; - private ScaleSeekBar scalePicker; - public FaceliftAction(Context context, AttributeSet attrs) { super(context, attrs); } @Override - public void doBegin() { + public void prepare() { final FaceliftFilter filter = new FaceliftFilter(); - scalePicker = factory.createScalePicker(EffectToolFactory.ScalePickerType.GENERIC); + ScaleSeekBar scalePicker = factory.createScalePicker(EffectToolFactory.ScaleType.GENERIC); scalePicker.setOnScaleChangeListener(new ScaleSeekBar.OnScaleChangeListener() { @Override public void onProgressChanged(float progress, boolean fromUser) { if (fromUser) { filter.setScale(progress); - notifyFilterChanged(filter, true); + notifyChanged(filter); } } }); scalePicker.setProgress(DEFAULT_SCALE); filter.setScale(DEFAULT_SCALE); - notifyFilterChanged(filter, true); - } - - @Override - public void doEnd() { - scalePicker.setOnScaleChangeListener(null); + notifyChanged(filter); } } diff --git a/src/com/android/gallery3d/photoeditor/actions/FillLightAction.java b/src/com/android/gallery3d/photoeditor/actions/FillLightAction.java index 73cf3d85d..dbb52b57e 100644 --- a/src/com/android/gallery3d/photoeditor/actions/FillLightAction.java +++ b/src/com/android/gallery3d/photoeditor/actions/FillLightAction.java @@ -28,32 +28,25 @@ public class FillLightAction extends EffectAction { private static final float DEFAULT_SCALE = 0f; - private ScaleSeekBar scalePicker; - public FillLightAction(Context context, AttributeSet attrs) { super(context, attrs); } @Override - public void doBegin() { + public void prepare() { final FillLightFilter filter = new FillLightFilter(); - scalePicker = factory.createScalePicker(EffectToolFactory.ScalePickerType.LIGHT); + ScaleSeekBar scalePicker = factory.createScalePicker(EffectToolFactory.ScaleType.LIGHT); scalePicker.setOnScaleChangeListener(new ScaleSeekBar.OnScaleChangeListener() { @Override public void onProgressChanged(float progress, boolean fromUser) { if (fromUser) { filter.setScale(progress); - notifyFilterChanged(filter, true); + notifyChanged(filter); } } }); scalePicker.setProgress(DEFAULT_SCALE); } - - @Override - public void doEnd() { - scalePicker.setOnScaleChangeListener(null); - } } diff --git a/src/com/android/gallery3d/photoeditor/actions/FisheyeAction.java b/src/com/android/gallery3d/photoeditor/actions/FisheyeAction.java index 348f0048d..fdff064ee 100644 --- a/src/com/android/gallery3d/photoeditor/actions/FisheyeAction.java +++ b/src/com/android/gallery3d/photoeditor/actions/FisheyeAction.java @@ -28,35 +28,28 @@ public class FisheyeAction extends EffectAction { private static final float DEFAULT_SCALE = 0.5f; - private ScaleSeekBar scalePicker; - public FisheyeAction(Context context, AttributeSet attrs) { super(context, attrs); } @Override - public void doBegin() { + public void prepare() { final FisheyeFilter filter = new FisheyeFilter(); - scalePicker = factory.createScalePicker(EffectToolFactory.ScalePickerType.GENERIC); + ScaleSeekBar scalePicker = factory.createScalePicker(EffectToolFactory.ScaleType.GENERIC); scalePicker.setOnScaleChangeListener(new ScaleSeekBar.OnScaleChangeListener() { @Override public void onProgressChanged(float progress, boolean fromUser) { if (fromUser) { filter.setScale(progress); - notifyFilterChanged(filter, true); + notifyChanged(filter); } } }); scalePicker.setProgress(DEFAULT_SCALE); filter.setScale(DEFAULT_SCALE); - notifyFilterChanged(filter, true); - } - - @Override - public void doEnd() { - scalePicker.setOnScaleChangeListener(null); + notifyChanged(filter); } } diff --git a/src/com/android/gallery3d/photoeditor/actions/FlipAction.java b/src/com/android/gallery3d/photoeditor/actions/FlipAction.java index da238ba98..6381d7fe1 100644 --- a/src/com/android/gallery3d/photoeditor/actions/FlipAction.java +++ b/src/com/android/gallery3d/photoeditor/actions/FlipAction.java @@ -19,7 +19,6 @@ package com.android.gallery3d.photoeditor.actions; import android.content.Context; import android.util.AttributeSet; -import com.android.gallery3d.R; import com.android.gallery3d.photoeditor.PhotoView; import com.android.gallery3d.photoeditor.filters.FlipFilter; @@ -31,35 +30,32 @@ public class FlipAction extends EffectAction { private static final float DEFAULT_ANGLE = 0.0f; private static final float DEFAULT_FLIP_SPAN = 180.0f; - private FlipFilter filter; - private float horizontalFlipDegrees; - private float verticalFlipDegrees; - private Runnable queuedFlipChange; - private FlipView flipView; - public FlipAction(Context context, AttributeSet attrs) { super(context, attrs); } @Override - public void doBegin() { - filter = new FlipFilter(); + public void prepare() { + // Disable outputting flipped results and directly flip photo-view for animations. + final FlipFilter filter = new FlipFilter(); + disableFilterOutput(); - flipView = factory.createFlipView(); + final FlipView flipView = factory.createFlipView(); flipView.setOnFlipChangeListener(new FlipView.OnFlipChangeListener() { - // Directly transform photo-view because running the flip filter isn't fast enough. - PhotoView photoView = (PhotoView) flipView.getRootView().findViewById( - R.id.photo_view); + float horizontalDegrees; + float verticalDegrees; + Runnable queuedTransform; + PhotoView photoView = factory.getPhotoView(); @Override public void onAngleChanged(float horizontalDegrees, float verticalDegrees, boolean fromUser) { if (fromUser) { - horizontalFlipDegrees = horizontalDegrees; - verticalFlipDegrees = verticalDegrees; - updateFlipFilter(false); + this.horizontalDegrees = horizontalDegrees; + this.verticalDegrees = verticalDegrees; transformPhotoView(horizontalDegrees, verticalDegrees); + notifyChanged(filter); } } @@ -70,59 +66,42 @@ public class FlipAction extends EffectAction { @Override public void onStopTrackingTouch() { - roundFlipDegrees(); - updateFlipFilter(false); - transformPhotoView(horizontalFlipDegrees, verticalFlipDegrees); - flipView.setFlippedAngles(horizontalFlipDegrees, verticalFlipDegrees); + // Round flip degrees to multiples of 180 degrees. + horizontalDegrees = roundTo180(horizontalDegrees); + verticalDegrees = roundTo180(verticalDegrees); + transformPhotoView(horizontalDegrees, verticalDegrees); + flipView.setFlippedAngles(horizontalDegrees, verticalDegrees); + + // Flip the filter according to the flipped directions of flip-view. + filter.setFlip(((int) horizontalDegrees / 180) % 2 != 0, + ((int) verticalDegrees / 180) % 2 != 0); + notifyChanged(filter); + } + + private float roundTo180(float degrees) { + if (degrees % 180 != 0) { + degrees = Math.round(degrees / 180) * 180; + } + return degrees; } private void transformPhotoView(final float horizontalDegrees, final float verticalDegrees) { // Remove the outdated flip change before queuing a new one. - if (queuedFlipChange != null) { - photoView.remove(queuedFlipChange); + if (queuedTransform != null) { + photoView.remove(queuedTransform); } - queuedFlipChange = new Runnable() { + queuedTransform = new Runnable() { @Override public void run() { photoView.flipPhoto(horizontalDegrees, verticalDegrees); } }; - photoView.queue(queuedFlipChange); + photoView.queue(queuedTransform); } }); flipView.setFlippedAngles(DEFAULT_ANGLE, DEFAULT_ANGLE); flipView.setFlipSpan(DEFAULT_FLIP_SPAN); - horizontalFlipDegrees = 0; - verticalFlipDegrees = 0; - queuedFlipChange = null; - } - - @Override - public void doEnd() { - flipView.setOnFlipChangeListener(null); - // Round the current flip degrees in case flip tracking has not stopped yet. - roundFlipDegrees(); - updateFlipFilter(true); - } - - /** - * Rounds flip degrees to multiples of 180 degrees. - */ - private void roundFlipDegrees() { - if (horizontalFlipDegrees % 180 != 0) { - horizontalFlipDegrees = Math.round(horizontalFlipDegrees / 180) * 180; - } - if (verticalFlipDegrees % 180 != 0) { - verticalFlipDegrees = Math.round(verticalFlipDegrees / 180) * 180; - } - } - - private void updateFlipFilter(boolean outputFilter) { - // Flip the filter if the flipped degrees are at the opposite directions. - filter.setFlip(((int) horizontalFlipDegrees / 180) % 2 != 0, - ((int) verticalFlipDegrees / 180) % 2 != 0); - notifyFilterChanged(filter, outputFilter); } } diff --git a/src/com/android/gallery3d/photoeditor/actions/GrainAction.java b/src/com/android/gallery3d/photoeditor/actions/GrainAction.java index 258eb8aa8..4f643211a 100644 --- a/src/com/android/gallery3d/photoeditor/actions/GrainAction.java +++ b/src/com/android/gallery3d/photoeditor/actions/GrainAction.java @@ -28,35 +28,28 @@ public class GrainAction extends EffectAction { private static final float DEFAULT_SCALE = 0.5f; - private ScaleSeekBar scalePicker; - public GrainAction(Context context, AttributeSet attrs) { super(context, attrs); } @Override - public void doBegin() { + public void prepare() { final GrainFilter filter = new GrainFilter(); - scalePicker = factory.createScalePicker(EffectToolFactory.ScalePickerType.GENERIC); + ScaleSeekBar scalePicker = factory.createScalePicker(EffectToolFactory.ScaleType.GENERIC); scalePicker.setOnScaleChangeListener(new ScaleSeekBar.OnScaleChangeListener() { @Override public void onProgressChanged(float progress, boolean fromUser) { if (fromUser) { filter.setScale(progress); - notifyFilterChanged(filter, true); + notifyChanged(filter); } } }); scalePicker.setProgress(DEFAULT_SCALE); filter.setScale(DEFAULT_SCALE); - notifyFilterChanged(filter, true); - } - - @Override - public void doEnd() { - scalePicker.setOnScaleChangeListener(null); + notifyChanged(filter); } } diff --git a/src/com/android/gallery3d/photoeditor/actions/GrayscaleAction.java b/src/com/android/gallery3d/photoeditor/actions/GrayscaleAction.java index ac89cd196..3ec468c52 100644 --- a/src/com/android/gallery3d/photoeditor/actions/GrayscaleAction.java +++ b/src/com/android/gallery3d/photoeditor/actions/GrayscaleAction.java @@ -31,12 +31,8 @@ public class GrayscaleAction extends EffectAction { } @Override - public void doBegin() { - notifyFilterChanged(new GrayscaleFilter(), true); + public void prepare() { + notifyChanged(new GrayscaleFilter()); notifyDone(); } - - @Override - public void doEnd() { - } } diff --git a/src/com/android/gallery3d/photoeditor/actions/HighlightAction.java b/src/com/android/gallery3d/photoeditor/actions/HighlightAction.java index a3d62d286..fc06b737a 100644 --- a/src/com/android/gallery3d/photoeditor/actions/HighlightAction.java +++ b/src/com/android/gallery3d/photoeditor/actions/HighlightAction.java @@ -28,32 +28,25 @@ public class HighlightAction extends EffectAction { private static final float DEFAULT_SCALE = 0f; - private ScaleSeekBar scalePicker; - public HighlightAction(Context context, AttributeSet attrs) { super(context, attrs); } @Override - public void doBegin() { + public void prepare() { final HighlightFilter filter = new HighlightFilter(); - scalePicker = factory.createScalePicker(EffectToolFactory.ScalePickerType.LIGHT); + ScaleSeekBar scalePicker = factory.createScalePicker(EffectToolFactory.ScaleType.LIGHT); scalePicker.setOnScaleChangeListener(new ScaleSeekBar.OnScaleChangeListener() { @Override public void onProgressChanged(float progress, boolean fromUser) { if (fromUser) { filter.setScale(progress); - notifyFilterChanged(filter, true); + notifyChanged(filter); } } }); scalePicker.setProgress(DEFAULT_SCALE); } - - @Override - public void doEnd() { - scalePicker.setOnScaleChangeListener(null); - } } diff --git a/src/com/android/gallery3d/photoeditor/actions/LomoishAction.java b/src/com/android/gallery3d/photoeditor/actions/LomoishAction.java index 44ffc52fe..2061f282d 100644 --- a/src/com/android/gallery3d/photoeditor/actions/LomoishAction.java +++ b/src/com/android/gallery3d/photoeditor/actions/LomoishAction.java @@ -31,12 +31,8 @@ public class LomoishAction extends EffectAction { } @Override - public void doBegin() { - notifyFilterChanged(new LomoishFilter(), true); + public void prepare() { + notifyChanged(new LomoishFilter()); notifyDone(); } - - @Override - public void doEnd() { - } } diff --git a/src/com/android/gallery3d/photoeditor/actions/NegativeAction.java b/src/com/android/gallery3d/photoeditor/actions/NegativeAction.java index 527642133..f7de8718b 100644 --- a/src/com/android/gallery3d/photoeditor/actions/NegativeAction.java +++ b/src/com/android/gallery3d/photoeditor/actions/NegativeAction.java @@ -31,12 +31,8 @@ public class NegativeAction extends EffectAction { } @Override - public void doBegin() { - notifyFilterChanged(new NegativeFilter(), true); + public void prepare() { + notifyChanged(new NegativeFilter()); notifyDone(); } - - @Override - public void doEnd() { - } } diff --git a/src/com/android/gallery3d/photoeditor/actions/PosterizeAction.java b/src/com/android/gallery3d/photoeditor/actions/PosterizeAction.java index 760539da5..5fde60203 100644 --- a/src/com/android/gallery3d/photoeditor/actions/PosterizeAction.java +++ b/src/com/android/gallery3d/photoeditor/actions/PosterizeAction.java @@ -31,12 +31,8 @@ public class PosterizeAction extends EffectAction { } @Override - public void doBegin() { - notifyFilterChanged(new PosterizeFilter(), true); + public void prepare() { + notifyChanged(new PosterizeFilter()); notifyDone(); } - - @Override - public void doEnd() { - } } diff --git a/src/com/android/gallery3d/photoeditor/actions/RedEyeAction.java b/src/com/android/gallery3d/photoeditor/actions/RedEyeAction.java index a472ad985..cea1aaecf 100644 --- a/src/com/android/gallery3d/photoeditor/actions/RedEyeAction.java +++ b/src/com/android/gallery3d/photoeditor/actions/RedEyeAction.java @@ -18,6 +18,7 @@ package com.android.gallery3d.photoeditor.actions; import android.content.Context; import android.graphics.PointF; +import android.graphics.RectF; import android.util.AttributeSet; import com.android.gallery3d.photoeditor.filters.RedEyeFilter; @@ -27,29 +28,27 @@ import com.android.gallery3d.photoeditor.filters.RedEyeFilter; */ public class RedEyeAction extends EffectAction { - private TouchView touchView; - public RedEyeAction(Context context, AttributeSet attrs) { super(context, attrs); } @Override - public void doBegin() { + public void prepare() { final RedEyeFilter filter = new RedEyeFilter(); - touchView = factory.createTouchView(); + TouchView touchView = factory.createTouchView(); touchView.setSingleTapListener(new TouchView.SingleTapListener() { + final RectF bounds = new RectF(0, 0, 1, 1); + @Override public void onSingleTap(PointF point) { - filter.addRedEyePosition(point); - notifyFilterChanged(filter, true); + // Check if the user taps within photo bounds to remove red eye on photo. + if (bounds.contains(point.x, point.y)) { + filter.addRedEyePosition(point); + notifyChanged(filter); + } } }); } - - @Override - public void doEnd() { - touchView.setSingleTapListener(null); - } } diff --git a/src/com/android/gallery3d/photoeditor/actions/RotateAction.java b/src/com/android/gallery3d/photoeditor/actions/RotateAction.java index 36a09d96f..8adf3e582 100644 --- a/src/com/android/gallery3d/photoeditor/actions/RotateAction.java +++ b/src/com/android/gallery3d/photoeditor/actions/RotateAction.java @@ -19,7 +19,6 @@ package com.android.gallery3d.photoeditor.actions; import android.content.Context; import android.util.AttributeSet; -import com.android.gallery3d.R; import com.android.gallery3d.photoeditor.PhotoView; import com.android.gallery3d.photoeditor.filters.RotateFilter; @@ -31,32 +30,29 @@ public class RotateAction extends EffectAction { private static final float DEFAULT_ANGLE = 0.0f; private static final float DEFAULT_ROTATE_SPAN = 360.0f; - private RotateFilter filter; - private float rotateDegrees; - private Runnable queuedRotationChange; - private RotateView rotateView; - public RotateAction(Context context, AttributeSet attrs) { super(context, attrs); } @Override - public void doBegin() { - filter = new RotateFilter(); + public void prepare() { + // Disable outputting rotated results and directly rotate photo-view for animations. + final RotateFilter filter = new RotateFilter(); + disableFilterOutput(); - rotateView = factory.createRotateView(); + final RotateView rotateView = factory.createRotateView(); rotateView.setOnRotateChangeListener(new RotateView.OnRotateChangeListener() { - // Directly transform photo-view because running the rotate filter isn't fast enough. - PhotoView photoView = (PhotoView) rotateView.getRootView().findViewById( - R.id.photo_view); + float rotateDegrees; + Runnable queuedTransform; + PhotoView photoView = factory.getPhotoView(); @Override - public void onAngleChanged(float degrees, boolean fromUser){ + public void onAngleChanged(float degrees, boolean fromUser) { if (fromUser) { rotateDegrees = degrees; - updateRotateFilter(false); - transformPhotoView(degrees); + transformPhotoView(rotateDegrees); + notifyChanged(filter); } } @@ -67,52 +63,32 @@ public class RotateAction extends EffectAction { @Override public void onStopTrackingTouch() { - roundRotateDegrees(); - updateRotateFilter(false); + // Round rotate degrees to multiples of 90 degrees. + if (rotateDegrees % 90 != 0) { + rotateDegrees = Math.round(rotateDegrees / 90) * 90; + } transformPhotoView(rotateDegrees); rotateView.setRotatedAngle(rotateDegrees); + filter.setAngle(rotateDegrees); + notifyChanged(filter); } private void transformPhotoView(final float degrees) { // Remove the outdated rotation change before queuing a new one. - if (queuedRotationChange != null) { - photoView.remove(queuedRotationChange); + if (queuedTransform != null) { + photoView.remove(queuedTransform); } - queuedRotationChange = new Runnable() { + queuedTransform = new Runnable() { @Override public void run() { photoView.rotatePhoto(degrees); } }; - photoView.queue(queuedRotationChange); + photoView.queue(queuedTransform); } }); rotateView.setRotatedAngle(DEFAULT_ANGLE); rotateView.setRotateSpan(DEFAULT_ROTATE_SPAN); - rotateDegrees = 0; - queuedRotationChange = null; - } - - @Override - public void doEnd() { - rotateView.setOnRotateChangeListener(null); - // Round the current rotation degrees in case rotation tracking has not stopped yet. - roundRotateDegrees(); - updateRotateFilter(true); - } - - /** - * Rounds rotate degrees to multiples of 90 degrees. - */ - private void roundRotateDegrees() { - if (rotateDegrees % 90 != 0) { - rotateDegrees = Math.round(rotateDegrees / 90) * 90; - } - } - - private void updateRotateFilter(boolean outputFilter) { - filter.setAngle(rotateDegrees); - notifyFilterChanged(filter, outputFilter); } } diff --git a/src/com/android/gallery3d/photoeditor/actions/SaturationAction.java b/src/com/android/gallery3d/photoeditor/actions/SaturationAction.java index 2f67e0a01..b3ffe6470 100644 --- a/src/com/android/gallery3d/photoeditor/actions/SaturationAction.java +++ b/src/com/android/gallery3d/photoeditor/actions/SaturationAction.java @@ -28,32 +28,25 @@ public class SaturationAction extends EffectAction { private static final float DEFAULT_SCALE = 0.5f; - private ScaleSeekBar scalePicker; - public SaturationAction(Context context, AttributeSet attrs) { super(context, attrs); } @Override - public void doBegin() { + public void prepare() { final SaturationFilter filter = new SaturationFilter(); - scalePicker = factory.createScalePicker(EffectToolFactory.ScalePickerType.COLOR); + ScaleSeekBar scalePicker = factory.createScalePicker(EffectToolFactory.ScaleType.COLOR); scalePicker.setOnScaleChangeListener(new ScaleSeekBar.OnScaleChangeListener() { @Override public void onProgressChanged(float progress, boolean fromUser) { if (fromUser) { filter.setScale(progress); - notifyFilterChanged(filter, true); + notifyChanged(filter); } } }); scalePicker.setProgress(DEFAULT_SCALE); } - - @Override - public void doEnd() { - scalePicker.setOnScaleChangeListener(null); - } } diff --git a/src/com/android/gallery3d/photoeditor/actions/SepiaAction.java b/src/com/android/gallery3d/photoeditor/actions/SepiaAction.java index c431115f9..96b33a080 100644 --- a/src/com/android/gallery3d/photoeditor/actions/SepiaAction.java +++ b/src/com/android/gallery3d/photoeditor/actions/SepiaAction.java @@ -31,12 +31,8 @@ public class SepiaAction extends EffectAction { } @Override - public void doBegin() { - notifyFilterChanged(new SepiaFilter(), true); + public void prepare() { + notifyChanged(new SepiaFilter()); notifyDone(); } - - @Override - public void doEnd() { - } } diff --git a/src/com/android/gallery3d/photoeditor/actions/ShadowAction.java b/src/com/android/gallery3d/photoeditor/actions/ShadowAction.java index 15ba8508f..87781af6e 100644 --- a/src/com/android/gallery3d/photoeditor/actions/ShadowAction.java +++ b/src/com/android/gallery3d/photoeditor/actions/ShadowAction.java @@ -28,32 +28,25 @@ public class ShadowAction extends EffectAction { private static final float DEFAULT_SCALE = 0f; - private ScaleSeekBar scalePicker; - public ShadowAction(Context context, AttributeSet attrs) { super(context, attrs); } @Override - public void doBegin() { + public void prepare() { final ShadowFilter filter = new ShadowFilter(); - scalePicker = factory.createScalePicker(EffectToolFactory.ScalePickerType.SHADOW); + ScaleSeekBar scalePicker = factory.createScalePicker(EffectToolFactory.ScaleType.SHADOW); scalePicker.setOnScaleChangeListener(new ScaleSeekBar.OnScaleChangeListener() { @Override public void onProgressChanged(float progress, boolean fromUser) { if (fromUser) { filter.setScale(progress); - notifyFilterChanged(filter, true); + notifyChanged(filter); } } }); scalePicker.setProgress(DEFAULT_SCALE); } - - @Override - public void doEnd() { - scalePicker.setOnScaleChangeListener(null); - } } diff --git a/src/com/android/gallery3d/photoeditor/actions/SharpenAction.java b/src/com/android/gallery3d/photoeditor/actions/SharpenAction.java index c6b240b40..760f3909c 100644 --- a/src/com/android/gallery3d/photoeditor/actions/SharpenAction.java +++ b/src/com/android/gallery3d/photoeditor/actions/SharpenAction.java @@ -28,35 +28,28 @@ public class SharpenAction extends EffectAction { private static final float DEFAULT_SCALE = 0.5f; - private ScaleSeekBar scalePicker; - public SharpenAction(Context context, AttributeSet attrs) { super(context, attrs); } @Override - public void doBegin() { + public void prepare() { final SharpenFilter filter = new SharpenFilter(); - scalePicker = factory.createScalePicker(EffectToolFactory.ScalePickerType.GENERIC); + ScaleSeekBar scalePicker = factory.createScalePicker(EffectToolFactory.ScaleType.GENERIC); scalePicker.setOnScaleChangeListener(new ScaleSeekBar.OnScaleChangeListener() { @Override public void onProgressChanged(float progress, boolean fromUser) { if (fromUser) { filter.setScale(progress); - notifyFilterChanged(filter, true); + notifyChanged(filter); } } }); scalePicker.setProgress(DEFAULT_SCALE); filter.setScale(DEFAULT_SCALE); - notifyFilterChanged(filter, true); - } - - @Override - public void doEnd() { - scalePicker.setOnScaleChangeListener(null); + notifyChanged(filter); } } diff --git a/src/com/android/gallery3d/photoeditor/actions/StraightenAction.java b/src/com/android/gallery3d/photoeditor/actions/StraightenAction.java index 42b384dc6..5fb5ecdb7 100644 --- a/src/com/android/gallery3d/photoeditor/actions/StraightenAction.java +++ b/src/com/android/gallery3d/photoeditor/actions/StraightenAction.java @@ -29,24 +29,22 @@ public class StraightenAction extends EffectAction { private static final float DEFAULT_ANGLE = 0.0f; private static final float DEFAULT_ROTATE_SPAN = StraightenFilter.MAX_DEGREES * 2; - private RotateView rotateView; - public StraightenAction(Context context, AttributeSet attrs) { super(context, attrs); } @Override - public void doBegin() { + public void prepare() { final StraightenFilter filter = new StraightenFilter(); - rotateView = factory.createRotateView(); + RotateView rotateView = factory.createRotateView(); rotateView.setOnRotateChangeListener(new RotateView.OnRotateChangeListener() { @Override public void onAngleChanged(float degrees, boolean fromUser){ if (fromUser) { filter.setAngle(degrees); - notifyFilterChanged(filter, true); + notifyChanged(filter); } } @@ -64,9 +62,4 @@ public class StraightenAction extends EffectAction { rotateView.setRotatedAngle(DEFAULT_ANGLE); rotateView.setRotateSpan(DEFAULT_ROTATE_SPAN); } - - @Override - public void doEnd() { - rotateView.setOnRotateChangeListener(null); - } } diff --git a/src/com/android/gallery3d/photoeditor/actions/TintAction.java b/src/com/android/gallery3d/photoeditor/actions/TintAction.java index defd2a331..886b172a0 100644 --- a/src/com/android/gallery3d/photoeditor/actions/TintAction.java +++ b/src/com/android/gallery3d/photoeditor/actions/TintAction.java @@ -28,35 +28,28 @@ public class TintAction extends EffectAction { private static final int DEFAULT_COLOR_INDEX = 13; - private ColorSeekBar colorPicker; - public TintAction(Context context, AttributeSet attrs) { super(context, attrs); } @Override - public void doBegin() { + public void prepare() { final TintFilter filter = new TintFilter(); - colorPicker = factory.createColorPicker(); + ColorSeekBar colorPicker = factory.createColorPicker(); colorPicker.setOnColorChangeListener(new ColorSeekBar.OnColorChangeListener() { @Override public void onColorChanged(int color, boolean fromUser) { if (fromUser) { filter.setTint(color); - notifyFilterChanged(filter, true); + notifyChanged(filter); } } }); // Tint photo with the default color. colorPicker.setColorIndex(DEFAULT_COLOR_INDEX); filter.setTint(colorPicker.getColor()); - notifyFilterChanged(filter, true); - } - - @Override - public void doEnd() { - colorPicker.setOnColorChangeListener(null); + notifyChanged(filter); } } diff --git a/src/com/android/gallery3d/photoeditor/actions/TouchView.java b/src/com/android/gallery3d/photoeditor/actions/TouchView.java index 0548cc4b2..d5f311cd7 100644 --- a/src/com/android/gallery3d/photoeditor/actions/TouchView.java +++ b/src/com/android/gallery3d/photoeditor/actions/TouchView.java @@ -28,20 +28,6 @@ import android.view.MotionEvent; class TouchView extends FullscreenToolView { /** - * Listener of swipes. - */ - public interface SwipeListener { - - void onSwipeLeft(); - - void onSwipeRight(); - - void onSwipeUp(); - - void onSwipeDown(); - } - - /** * Listener of single tap on a point (relative to photo coordinates). */ public interface SingleTapListener { @@ -50,21 +36,18 @@ class TouchView extends FullscreenToolView { } private final GestureDetector gestureDetector; - - private SwipeListener swipeListener; private SingleTapListener singleTapListener; public TouchView(Context context, AttributeSet attrs) { super(context, attrs); - final int swipeThreshold = (int) (500 * getResources().getDisplayMetrics().density); gestureDetector = new GestureDetector( context, new GestureDetector.SimpleOnGestureListener() { @Override public boolean onDown(MotionEvent e) { - // GestureDetector onTouchEvent returns true for fling events only when their - // preceding down events are consumed. + // GestureDetector onTouchEvent returns true only for events whose preceding + // down-events have been consumed. return true; } @@ -77,37 +60,10 @@ class TouchView extends FullscreenToolView { } return true; } - - @Override - public boolean onFling( - MotionEvent me1, MotionEvent me2, float velocityX, float velocityY) { - if (swipeListener != null) { - float absX = Math.abs(velocityX); - float absY = Math.abs(velocityY); - float deltaX = me2.getX() - me1.getX(); - float deltaY = me2.getY() - me1.getY(); - int travelX = getWidth() / 4; - int travelY = getHeight() / 4; - if (velocityX > swipeThreshold && absY < absX && deltaX > travelX) { - swipeListener.onSwipeRight(); - } else if (velocityX < -swipeThreshold && absY < absX && deltaX < -travelX) { - swipeListener.onSwipeLeft(); - } else if (velocityY < -swipeThreshold && absX < absY && deltaY < -travelY) { - swipeListener.onSwipeUp(); - } else if (velocityY > swipeThreshold && absX < absY / 2 && deltaY > travelY) { - swipeListener.onSwipeDown(); - } - } - return true; - } }); gestureDetector.setIsLongpressEnabled(false); } - public void setSwipeListener(SwipeListener listener) { - swipeListener = listener; - } - public void setSingleTapListener(SingleTapListener listener) { singleTapListener = listener; } diff --git a/src/com/android/gallery3d/photoeditor/actions/VignetteAction.java b/src/com/android/gallery3d/photoeditor/actions/VignetteAction.java index f59c636db..fd5121fce 100644 --- a/src/com/android/gallery3d/photoeditor/actions/VignetteAction.java +++ b/src/com/android/gallery3d/photoeditor/actions/VignetteAction.java @@ -28,35 +28,28 @@ public class VignetteAction extends EffectAction { private static final float DEFAULT_SCALE = 0.5f; - private ScaleSeekBar scalePicker; - public VignetteAction(Context context, AttributeSet attrs) { super(context, attrs); } @Override - public void doBegin() { + public void prepare() { final VignetteFilter filter = new VignetteFilter(); - scalePicker = factory.createScalePicker(EffectToolFactory.ScalePickerType.GENERIC); + ScaleSeekBar scalePicker = factory.createScalePicker(EffectToolFactory.ScaleType.GENERIC); scalePicker.setOnScaleChangeListener(new ScaleSeekBar.OnScaleChangeListener() { @Override public void onProgressChanged(float progress, boolean fromUser) { if (fromUser) { filter.setScale(progress); - notifyFilterChanged(filter, true); + notifyChanged(filter); } } }); scalePicker.setProgress(DEFAULT_SCALE); filter.setScale(DEFAULT_SCALE); - notifyFilterChanged(filter, true); - } - - @Override - public void doEnd() { - scalePicker.setOnScaleChangeListener(null); + notifyChanged(filter); } } diff --git a/src/com/android/gallery3d/photoeditor/filters/AbstractScaleFilter.java b/src/com/android/gallery3d/photoeditor/filters/AbstractScaleFilter.java index 727a98cab..6376d33ef 100644 --- a/src/com/android/gallery3d/photoeditor/filters/AbstractScaleFilter.java +++ b/src/com/android/gallery3d/photoeditor/filters/AbstractScaleFilter.java @@ -30,7 +30,6 @@ public abstract class AbstractScaleFilter extends Filter { */ public void setScale(float scale) { this.scale = scale; - validate(); } @Override diff --git a/src/com/android/gallery3d/photoeditor/filters/CropFilter.java b/src/com/android/gallery3d/photoeditor/filters/CropFilter.java index ccca81387..00a6c424a 100644 --- a/src/com/android/gallery3d/photoeditor/filters/CropFilter.java +++ b/src/com/android/gallery3d/photoeditor/filters/CropFilter.java @@ -37,7 +37,6 @@ public class CropFilter extends Filter { */ public void setCropBounds(RectF bounds) { this.bounds = bounds; - validate(); } @Override diff --git a/src/com/android/gallery3d/photoeditor/filters/CrossProcessFilter.java b/src/com/android/gallery3d/photoeditor/filters/CrossProcessFilter.java index e82a66736..bc233daa2 100644 --- a/src/com/android/gallery3d/photoeditor/filters/CrossProcessFilter.java +++ b/src/com/android/gallery3d/photoeditor/filters/CrossProcessFilter.java @@ -27,10 +27,6 @@ public class CrossProcessFilter extends Filter { public static final Creator<CrossProcessFilter> CREATOR = creatorOf(CrossProcessFilter.class); - public CrossProcessFilter() { - validate(); - } - @Override public void process(Photo src, Photo dst) { getEffect(EffectFactory.EFFECT_CROSSPROCESS).apply( diff --git a/src/com/android/gallery3d/photoeditor/filters/DocumentaryFilter.java b/src/com/android/gallery3d/photoeditor/filters/DocumentaryFilter.java index d6f347b1f..d2e4c7cd0 100644 --- a/src/com/android/gallery3d/photoeditor/filters/DocumentaryFilter.java +++ b/src/com/android/gallery3d/photoeditor/filters/DocumentaryFilter.java @@ -27,10 +27,6 @@ public class DocumentaryFilter extends Filter { public static final Creator<DocumentaryFilter> CREATOR = creatorOf(DocumentaryFilter.class); - public DocumentaryFilter() { - validate(); - } - @Override public void process(Photo src, Photo dst) { getEffect(EffectFactory.EFFECT_DOCUMENTARY).apply( diff --git a/src/com/android/gallery3d/photoeditor/filters/DoodleFilter.java b/src/com/android/gallery3d/photoeditor/filters/DoodleFilter.java index 277e06df7..61920d377 100644 --- a/src/com/android/gallery3d/photoeditor/filters/DoodleFilter.java +++ b/src/com/android/gallery3d/photoeditor/filters/DoodleFilter.java @@ -40,14 +40,6 @@ public class DoodleFilter extends Filter { private final Vector<Doodle> doodles = new Vector<Doodle>(); - /** - * Signals once at least a doodle drawn within photo bounds; this filter is regarded as invalid - * (no-op on the photo) until not all its doodling is out of bounds. - */ - public void setDoodledInPhotoBounds() { - validate(); - } - public void addDoodle(Doodle doodle) { doodles.add(doodle); } diff --git a/src/com/android/gallery3d/photoeditor/filters/DuotoneFilter.java b/src/com/android/gallery3d/photoeditor/filters/DuotoneFilter.java index b94f95e5a..b2c55252e 100644 --- a/src/com/android/gallery3d/photoeditor/filters/DuotoneFilter.java +++ b/src/com/android/gallery3d/photoeditor/filters/DuotoneFilter.java @@ -35,7 +35,6 @@ public class DuotoneFilter extends Filter { public void setDuotone(int firstColor, int secondColor) { this.firstColor = firstColor; this.secondColor = secondColor; - validate(); } @Override diff --git a/src/com/android/gallery3d/photoeditor/filters/Filter.java b/src/com/android/gallery3d/photoeditor/filters/Filter.java index baa37472c..5d1ac229b 100644 --- a/src/com/android/gallery3d/photoeditor/filters/Filter.java +++ b/src/com/android/gallery3d/photoeditor/filters/Filter.java @@ -26,8 +26,7 @@ import com.android.gallery3d.photoeditor.Photo; import java.util.HashMap; /** - * Image filter for photo editing; most of its methods must be called from a single GL thread except - * validate()/isValid() that are called from UI thread. + * Image filter for photo editing; all of its methods must be called from a single GL thread. */ public abstract class Filter implements Parcelable { @@ -37,8 +36,6 @@ public abstract class Filter implements Parcelable { private static final HashMap<Filter, Effect> effects = new HashMap<Filter, Effect>(); private static EffectContext context; - private boolean isValid; - /** * Filter context should be released before the current GL context is lost. */ @@ -74,18 +71,6 @@ public abstract class Filter implements Parcelable { return effect; } - protected void validate() { - isValid = true; - } - - /** - * Some filters, e.g. lighting filters, are initially invalid until set up with parameters while - * others, e.g. Sepia or Posterize filters, are initially valid without parameters. - */ - public boolean isValid() { - return isValid; - } - /** * Processes the source bitmap and matrix and output the destination bitmap and matrix. * diff --git a/src/com/android/gallery3d/photoeditor/filters/FlipFilter.java b/src/com/android/gallery3d/photoeditor/filters/FlipFilter.java index 816aad87d..9c325c1c9 100644 --- a/src/com/android/gallery3d/photoeditor/filters/FlipFilter.java +++ b/src/com/android/gallery3d/photoeditor/filters/FlipFilter.java @@ -34,7 +34,6 @@ public class FlipFilter extends Filter { public void setFlip(boolean flipHorizontal, boolean flipVertical) { flips[0] = flipHorizontal; flips[1] = flipVertical; - validate(); } @Override diff --git a/src/com/android/gallery3d/photoeditor/filters/GrayscaleFilter.java b/src/com/android/gallery3d/photoeditor/filters/GrayscaleFilter.java index 38dfb528a..b0e94ef7c 100644 --- a/src/com/android/gallery3d/photoeditor/filters/GrayscaleFilter.java +++ b/src/com/android/gallery3d/photoeditor/filters/GrayscaleFilter.java @@ -27,10 +27,6 @@ public class GrayscaleFilter extends Filter { public static final Creator<GrayscaleFilter> CREATOR = creatorOf(GrayscaleFilter.class); - public GrayscaleFilter() { - validate(); - } - @Override public void process(Photo src, Photo dst) { getEffect(EffectFactory.EFFECT_GRAYSCALE).apply( diff --git a/src/com/android/gallery3d/photoeditor/filters/LomoishFilter.java b/src/com/android/gallery3d/photoeditor/filters/LomoishFilter.java index f8c517314..16a1d61e9 100644 --- a/src/com/android/gallery3d/photoeditor/filters/LomoishFilter.java +++ b/src/com/android/gallery3d/photoeditor/filters/LomoishFilter.java @@ -27,10 +27,6 @@ public class LomoishFilter extends Filter { public static final Creator<LomoishFilter> CREATOR = creatorOf(LomoishFilter.class); - public LomoishFilter() { - validate(); - } - @Override public void process(Photo src, Photo dst) { getEffect(EffectFactory.EFFECT_LOMOISH).apply( diff --git a/src/com/android/gallery3d/photoeditor/filters/NegativeFilter.java b/src/com/android/gallery3d/photoeditor/filters/NegativeFilter.java index 88bbd58ac..db702d7e3 100644 --- a/src/com/android/gallery3d/photoeditor/filters/NegativeFilter.java +++ b/src/com/android/gallery3d/photoeditor/filters/NegativeFilter.java @@ -27,10 +27,6 @@ public class NegativeFilter extends Filter { public static final Creator<NegativeFilter> CREATOR = creatorOf(NegativeFilter.class); - public NegativeFilter() { - validate(); - } - @Override public void process(Photo src, Photo dst) { getEffect(EffectFactory.EFFECT_NEGATIVE).apply( diff --git a/src/com/android/gallery3d/photoeditor/filters/PosterizeFilter.java b/src/com/android/gallery3d/photoeditor/filters/PosterizeFilter.java index 186baa9cb..23e78bffb 100644 --- a/src/com/android/gallery3d/photoeditor/filters/PosterizeFilter.java +++ b/src/com/android/gallery3d/photoeditor/filters/PosterizeFilter.java @@ -27,10 +27,6 @@ public class PosterizeFilter extends Filter { public static final Creator<PosterizeFilter> CREATOR = creatorOf(PosterizeFilter.class); - public PosterizeFilter() { - validate(); - } - @Override public void process(Photo src, Photo dst) { getEffect(EffectFactory.EFFECT_POSTERIZE).apply( diff --git a/src/com/android/gallery3d/photoeditor/filters/RedEyeFilter.java b/src/com/android/gallery3d/photoeditor/filters/RedEyeFilter.java index 257d3229e..32e8f7c30 100644 --- a/src/com/android/gallery3d/photoeditor/filters/RedEyeFilter.java +++ b/src/com/android/gallery3d/photoeditor/filters/RedEyeFilter.java @@ -39,7 +39,6 @@ public class RedEyeFilter extends Filter { */ public void addRedEyePosition(PointF point) { redeyes.add(point); - validate(); } @Override diff --git a/src/com/android/gallery3d/photoeditor/filters/RotateFilter.java b/src/com/android/gallery3d/photoeditor/filters/RotateFilter.java index d377f96b4..d820bdac6 100644 --- a/src/com/android/gallery3d/photoeditor/filters/RotateFilter.java +++ b/src/com/android/gallery3d/photoeditor/filters/RotateFilter.java @@ -31,9 +31,11 @@ public class RotateFilter extends Filter { private float degrees; + /** + * Sets rotation angle which must be multiples of 90 degrees. + */ public void setAngle(float degrees) { this.degrees = degrees; - validate(); } @Override diff --git a/src/com/android/gallery3d/photoeditor/filters/SepiaFilter.java b/src/com/android/gallery3d/photoeditor/filters/SepiaFilter.java index 6c1a70ef1..d95c0d84c 100644 --- a/src/com/android/gallery3d/photoeditor/filters/SepiaFilter.java +++ b/src/com/android/gallery3d/photoeditor/filters/SepiaFilter.java @@ -27,10 +27,6 @@ public class SepiaFilter extends Filter { public static final Creator<SepiaFilter> CREATOR = creatorOf(SepiaFilter.class); - public SepiaFilter() { - validate(); - } - @Override public void process(Photo src, Photo dst) { getEffect(EffectFactory.EFFECT_SEPIA).apply( diff --git a/src/com/android/gallery3d/photoeditor/filters/StraightenFilter.java b/src/com/android/gallery3d/photoeditor/filters/StraightenFilter.java index 90738f0f3..dffdf507c 100644 --- a/src/com/android/gallery3d/photoeditor/filters/StraightenFilter.java +++ b/src/com/android/gallery3d/photoeditor/filters/StraightenFilter.java @@ -34,7 +34,6 @@ public class StraightenFilter extends Filter { public void setAngle(float degrees) { this.degrees = degrees; - validate(); } @Override diff --git a/src/com/android/gallery3d/photoeditor/filters/TintFilter.java b/src/com/android/gallery3d/photoeditor/filters/TintFilter.java index af3d77773..7a7463e4c 100644 --- a/src/com/android/gallery3d/photoeditor/filters/TintFilter.java +++ b/src/com/android/gallery3d/photoeditor/filters/TintFilter.java @@ -33,7 +33,6 @@ public class TintFilter extends Filter { public void setTint(int color) { this.color = color; - validate(); } @Override |