summaryrefslogtreecommitdiffstats
path: root/src/com/android/gallery3d/photoeditor/actions
diff options
context:
space:
mode:
authorYuli Huang <yuli@google.com>2011-11-04 16:39:50 +0800
committerYuli Huang <yuli@google.com>2011-11-09 01:08:44 +0800
commit16ac4446300bdc6b23a9436328a667996a70c278 (patch)
treed3984b476c56049afd695a25dae79397ad48ce00 /src/com/android/gallery3d/photoeditor/actions
parentb820346074c813500f2ea5b5ae1488fae2b29103 (diff)
downloadandroid_packages_apps_Snap-16ac4446300bdc6b23a9436328a667996a70c278.tar.gz
android_packages_apps_Snap-16ac4446300bdc6b23a9436328a667996a70c278.tar.bz2
android_packages_apps_Snap-16ac4446300bdc6b23a9436328a667996a70c278.zip
Fix b/5510870 by saving/restoring Activity states.
1. Filters implement Parcelable for saving/restoring states. 2. Extract Doodle for making doodling paths parcelable. Change-Id: Ice8e6e068891da8a8f9251e62d95ea755fa99933
Diffstat (limited to 'src/com/android/gallery3d/photoeditor/actions')
-rw-r--r--src/com/android/gallery3d/photoeditor/actions/ColorTemperatureAction.java2
-rw-r--r--src/com/android/gallery3d/photoeditor/actions/Doodle.java122
-rw-r--r--src/com/android/gallery3d/photoeditor/actions/DoodleAction.java5
-rw-r--r--src/com/android/gallery3d/photoeditor/actions/DoodlePaint.java34
-rw-r--r--src/com/android/gallery3d/photoeditor/actions/DoodleView.java67
-rw-r--r--src/com/android/gallery3d/photoeditor/actions/FillLightAction.java2
-rw-r--r--src/com/android/gallery3d/photoeditor/actions/HighlightAction.java2
-rw-r--r--src/com/android/gallery3d/photoeditor/actions/SaturationAction.java2
-rw-r--r--src/com/android/gallery3d/photoeditor/actions/ShadowAction.java2
-rw-r--r--src/com/android/gallery3d/photoeditor/actions/SharpenAction.java4
10 files changed, 162 insertions, 80 deletions
diff --git a/src/com/android/gallery3d/photoeditor/actions/ColorTemperatureAction.java b/src/com/android/gallery3d/photoeditor/actions/ColorTemperatureAction.java
index 41a89dbbe..24978faf0 100644
--- a/src/com/android/gallery3d/photoeditor/actions/ColorTemperatureAction.java
+++ b/src/com/android/gallery3d/photoeditor/actions/ColorTemperatureAction.java
@@ -44,7 +44,7 @@ public class ColorTemperatureAction extends EffectAction {
@Override
public void onProgressChanged(float progress, boolean fromUser) {
if (fromUser) {
- filter.setColorTemperature(progress);
+ filter.setScale(progress);
notifyFilterChanged(filter, true);
}
}
diff --git a/src/com/android/gallery3d/photoeditor/actions/Doodle.java b/src/com/android/gallery3d/photoeditor/actions/Doodle.java
new file mode 100644
index 000000000..ea23e2380
--- /dev/null
+++ b/src/com/android/gallery3d/photoeditor/actions/Doodle.java
@@ -0,0 +1,122 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.gallery3d.photoeditor.actions;
+
+import android.graphics.Color;
+import android.graphics.Matrix;
+import android.graphics.Paint;
+import android.graphics.Path;
+import android.graphics.PointF;
+import android.graphics.RectF;
+import android.os.Parcel;
+import android.os.Parcelable;
+
+import java.util.Vector;
+
+/**
+ * Doodle that consists of a color and doodling path for drawing.
+ */
+public class Doodle implements Parcelable {
+
+ private final int color;
+ private final Path normalizedPath = new Path();
+ private final Vector<PointF> points = new Vector<PointF>();
+
+ /**
+ * Creates paint for doodles.
+ */
+ public static Paint createPaint() {
+ Paint paint = new Paint(Paint.DITHER_FLAG | Paint.ANTI_ALIAS_FLAG);
+ paint.setStyle(Paint.Style.STROKE);
+ paint.setStrokeJoin(Paint.Join.ROUND);
+ paint.setStrokeCap(Paint.Cap.ROUND);
+ paint.setStrokeWidth(15);
+ return paint;
+ }
+
+ public Doodle(int color, PointF startPoint) {
+ this.color = Color.argb(192, Color.red(color), Color.green(color), Color.blue(color));
+ normalizedPath.moveTo(startPoint.x, startPoint.y);
+ points.add(startPoint);
+ }
+
+ /**
+ * 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) {
+ 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() {
+ return color;
+ }
+
+ public boolean isEmpty() {
+ return normalizedPath.isEmpty();
+ }
+
+ /**
+ * Gets the drawing path from the normalized doodle path.
+ */
+ public void getDrawingPath(Matrix matrix, Path path) {
+ path.set(normalizedPath);
+ path.transform(matrix);
+ }
+
+ @Override
+ public int describeContents() {
+ return 0;
+ }
+
+ @Override
+ public void writeToParcel(Parcel dest, int flags) {
+ dest.writeInt(color);
+ dest.writeInt(points.size());
+ for (PointF point : points) {
+ dest.writeParcelable(point, 0);
+ }
+ }
+
+ public static final Parcelable.Creator<Doodle> CREATOR = new Parcelable.Creator<Doodle>() {
+
+ @Override
+ public Doodle createFromParcel(Parcel source) {
+ int color = source.readInt();
+ int size = source.readInt();
+ if (size > 0) {
+ Doodle doodle = new Doodle(color, (PointF) source.readParcelable(null));
+ for (int i = 1; i < size; i++) {
+ doodle.addControlPoint((PointF) source.readParcelable(null));
+ }
+ return doodle;
+ }
+ return new Doodle(color, new PointF(0, 0));
+ }
+
+ @Override
+ public Doodle[] newArray(int size) {
+ return new Doodle[size];
+ }};
+}
diff --git a/src/com/android/gallery3d/photoeditor/actions/DoodleAction.java b/src/com/android/gallery3d/photoeditor/actions/DoodleAction.java
index b82414dc8..4ad2cfb11 100644
--- a/src/com/android/gallery3d/photoeditor/actions/DoodleAction.java
+++ b/src/com/android/gallery3d/photoeditor/actions/DoodleAction.java
@@ -17,7 +17,6 @@
package com.android.gallery3d.photoeditor.actions;
import android.content.Context;
-import android.graphics.Path;
import android.util.AttributeSet;
import com.android.gallery3d.photoeditor.filters.DoodleFilter;
@@ -64,8 +63,8 @@ public class DoodleAction extends EffectAction {
}
@Override
- public void onDoodleFinished(Path path, int color) {
- filter.addPath(path, color);
+ public void onDoodleFinished(Doodle doodle) {
+ filter.addDoodle(doodle);
notifyFilterChanged(filter, false);
}
});
diff --git a/src/com/android/gallery3d/photoeditor/actions/DoodlePaint.java b/src/com/android/gallery3d/photoeditor/actions/DoodlePaint.java
deleted file mode 100644
index bcde9f1b0..000000000
--- a/src/com/android/gallery3d/photoeditor/actions/DoodlePaint.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright (C) 2010 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.gallery3d.photoeditor.actions;
-
-import android.graphics.Paint;
-
-/**
- * A paint class for doodle effect.
- */
-public class DoodlePaint extends Paint {
-
- public DoodlePaint() {
- super(Paint.DITHER_FLAG | Paint.ANTI_ALIAS_FLAG);
-
- setStyle(Paint.Style.STROKE);
- setStrokeJoin(Paint.Join.ROUND);
- setStrokeCap(Paint.Cap.ROUND);
- setStrokeWidth(15);
- }
-}
diff --git a/src/com/android/gallery3d/photoeditor/actions/DoodleView.java b/src/com/android/gallery3d/photoeditor/actions/DoodleView.java
index cc5af84be..b59686151 100644
--- a/src/com/android/gallery3d/photoeditor/actions/DoodleView.java
+++ b/src/com/android/gallery3d/photoeditor/actions/DoodleView.java
@@ -19,7 +19,6 @@ package com.android.gallery3d.photoeditor.actions;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
-import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Path;
@@ -40,19 +39,20 @@ class DoodleView extends FullscreenToolView {
void onDoodleInPhotoBounds();
- void onDoodleFinished(Path path, int color);
+ void onDoodleFinished(Doodle doodle);
}
- private final Path normalizedPath = new Path();
- private final Path drawingPath = new Path();
- private final Paint doodlePaint = new DoodlePaint();
private final Paint bitmapPaint = new Paint(Paint.DITHER_FLAG);
+ private final Paint doodlePaint = Doodle.createPaint();
private final PointF lastPoint = new PointF();
- private final Matrix pathMatrix = new Matrix();
+ private final Path drawingPath = new Path();
+ private final Matrix drawingMatrix = new Matrix();
private final Matrix displayMatrix = new Matrix();
private Bitmap bitmap;
private Canvas bitmapCanvas;
+ private Doodle doodle;
+ private int color;
private OnDoodleChangeListener listener;
public DoodleView(Context context, AttributeSet attrs) {
@@ -71,50 +71,51 @@ class DoodleView extends FullscreenToolView {
if ((bitmap == null) && !r.isEmpty()) {
bitmap = Bitmap.createBitmap((int) r.width(), (int) r.height(),
Bitmap.Config.ARGB_8888);
- bitmap.eraseColor(0x00000000);
bitmapCanvas = new Canvas(bitmap);
// Set up a matrix that maps back normalized paths to be drawn on the bitmap or canvas.
- pathMatrix.setRectToRect(new RectF(0, 0, 1, 1), r, Matrix.ScaleToFit.FILL);
+ drawingMatrix.setRectToRect(new RectF(0, 0, 1, 1), r, Matrix.ScaleToFit.FILL);
}
displayMatrix.setRectToRect(r, displayBounds, Matrix.ScaleToFit.FILL);
}
private void drawDoodle(Canvas canvas) {
- if ((canvas != null) && !normalizedPath.isEmpty()) {
- drawingPath.set(normalizedPath);
- drawingPath.transform(pathMatrix);
+ if ((canvas != null) && (doodle != null)) {
+ doodlePaint.setColor(doodle.getColor());
+ doodle.getDrawingPath(drawingMatrix, drawingPath);
canvas.drawPath(drawingPath, doodlePaint);
}
}
public void setColor(int color) {
- // Reset path to draw in a new color.
- finishCurrentPath();
- normalizedPath.moveTo(lastPoint.x, lastPoint.y);
- doodlePaint.setColor(Color.argb(192, Color.red(color), Color.green(color),
- Color.blue(color)));
+ // Restart doodle to draw in a new color.
+ this.color = color;
+ finishDoodle();
+ startDoodle();
+ }
+
+ private void startDoodle() {
+ doodle = new Doodle(color, new PointF(lastPoint.x, lastPoint.y));
}
- private void finishCurrentPath() {
- if (!normalizedPath.isEmpty()) {
- // Update the finished path to the bitmap.
+ private void finishDoodle() {
+ if ((doodle != null) && !doodle.isEmpty()) {
+ // Update the finished non-empty doodle to the bitmap.
drawDoodle(bitmapCanvas);
if (listener != null) {
- listener.onDoodleFinished(new Path(normalizedPath), doodlePaint.getColor());
+ listener.onDoodleFinished(doodle);
}
- normalizedPath.rewind();
invalidate();
}
+ doodle = null;
}
- private void checkCurrentPathInBounds() {
- if ((listener != null) && !normalizedPath.isEmpty()) {
- RectF r = new RectF();
- normalizedPath.computeBounds(r, false);
- if (r.intersects(0, 0, 1, 1)) {
+ private void addLastPointIntoDoodle() {
+ if ((doodle != null) && doodle.addControlPoint(new PointF(lastPoint.x, lastPoint.y))) {
+ if (listener != null) {
listener.onDoodleInPhotoBounds();
}
+ invalidate();
}
}
@@ -129,26 +130,20 @@ class DoodleView extends FullscreenToolView {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
mapPhotoPoint(x, y, lastPoint);
- normalizedPath.moveTo(lastPoint.x, lastPoint.y);
+ startDoodle();
break;
case MotionEvent.ACTION_MOVE:
- float lastX = lastPoint.x;
- float lastY = lastPoint.y;
mapPhotoPoint(x, y, lastPoint);
- normalizedPath.quadTo(lastX, lastY, (lastX + lastPoint.x) / 2,
- (lastY + lastPoint.y) / 2);
- checkCurrentPathInBounds();
- invalidate();
+ addLastPointIntoDoodle();
break;
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_UP:
// Line to last position with offset to draw at least dots for single clicks.
mapPhotoPoint(x + 1, y + 1, lastPoint);
- normalizedPath.lineTo(lastPoint.x, lastPoint.y);
- checkCurrentPathInBounds();
- finishCurrentPath();
+ addLastPointIntoDoodle();
+ finishDoodle();
break;
}
}
diff --git a/src/com/android/gallery3d/photoeditor/actions/FillLightAction.java b/src/com/android/gallery3d/photoeditor/actions/FillLightAction.java
index 962486bbf..73cf3d85d 100644
--- a/src/com/android/gallery3d/photoeditor/actions/FillLightAction.java
+++ b/src/com/android/gallery3d/photoeditor/actions/FillLightAction.java
@@ -44,7 +44,7 @@ public class FillLightAction extends EffectAction {
@Override
public void onProgressChanged(float progress, boolean fromUser) {
if (fromUser) {
- filter.setBacklight(progress);
+ filter.setScale(progress);
notifyFilterChanged(filter, true);
}
}
diff --git a/src/com/android/gallery3d/photoeditor/actions/HighlightAction.java b/src/com/android/gallery3d/photoeditor/actions/HighlightAction.java
index cd8f4b278..a3d62d286 100644
--- a/src/com/android/gallery3d/photoeditor/actions/HighlightAction.java
+++ b/src/com/android/gallery3d/photoeditor/actions/HighlightAction.java
@@ -44,7 +44,7 @@ public class HighlightAction extends EffectAction {
@Override
public void onProgressChanged(float progress, boolean fromUser) {
if (fromUser) {
- filter.setHighlight(progress);
+ filter.setScale(progress);
notifyFilterChanged(filter, true);
}
}
diff --git a/src/com/android/gallery3d/photoeditor/actions/SaturationAction.java b/src/com/android/gallery3d/photoeditor/actions/SaturationAction.java
index 31bcfd664..2f67e0a01 100644
--- a/src/com/android/gallery3d/photoeditor/actions/SaturationAction.java
+++ b/src/com/android/gallery3d/photoeditor/actions/SaturationAction.java
@@ -44,7 +44,7 @@ public class SaturationAction extends EffectAction {
@Override
public void onProgressChanged(float progress, boolean fromUser) {
if (fromUser) {
- filter.setSaturation(progress);
+ filter.setScale(progress);
notifyFilterChanged(filter, true);
}
}
diff --git a/src/com/android/gallery3d/photoeditor/actions/ShadowAction.java b/src/com/android/gallery3d/photoeditor/actions/ShadowAction.java
index 185febc7c..15ba8508f 100644
--- a/src/com/android/gallery3d/photoeditor/actions/ShadowAction.java
+++ b/src/com/android/gallery3d/photoeditor/actions/ShadowAction.java
@@ -44,7 +44,7 @@ public class ShadowAction extends EffectAction {
@Override
public void onProgressChanged(float progress, boolean fromUser) {
if (fromUser) {
- filter.setShadow(progress);
+ filter.setScale(progress);
notifyFilterChanged(filter, true);
}
}
diff --git a/src/com/android/gallery3d/photoeditor/actions/SharpenAction.java b/src/com/android/gallery3d/photoeditor/actions/SharpenAction.java
index 7524c76ec..c6b240b40 100644
--- a/src/com/android/gallery3d/photoeditor/actions/SharpenAction.java
+++ b/src/com/android/gallery3d/photoeditor/actions/SharpenAction.java
@@ -44,14 +44,14 @@ public class SharpenAction extends EffectAction {
@Override
public void onProgressChanged(float progress, boolean fromUser) {
if (fromUser) {
- filter.setSharpen(progress);
+ filter.setScale(progress);
notifyFilterChanged(filter, true);
}
}
});
scalePicker.setProgress(DEFAULT_SCALE);
- filter.setSharpen(DEFAULT_SCALE);
+ filter.setScale(DEFAULT_SCALE);
notifyFilterChanged(filter, true);
}