summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Hoford <hoford@google.com>2013-08-05 15:07:14 -0700
committerJohn Hoford <hoford@google.com>2013-08-09 17:21:22 -0700
commitf4b659334750a5aa75f929d18857a2ab93c9d939 (patch)
treefe4a4e7827129a79e694282a1506b9979ef1c712
parent8c3d2b9ab605cb8e5e883932147b8a378748ef32 (diff)
downloadandroid_packages_apps_Gallery2-f4b659334750a5aa75f929d18857a2ab93c9d939.tar.gz
android_packages_apps_Gallery2-f4b659334750a5aa75f929d18857a2ab93c9d939.tar.bz2
android_packages_apps_Gallery2-f4b659334750a5aa75f929d18857a2ab93c9d939.zip
fix draw
Change-Id: I535221edd992c1a8c659c398dba61158e0c1d87d
-rw-r--r--res/drawable-nodpi/brush_flat.pngbin0 -> 768 bytes
-rw-r--r--res/menu/filtershow_menu_draw.xml37
-rw-r--r--res/values/filtershow_color.xml4
-rw-r--r--res/values/filtershow_strings.xml8
-rw-r--r--src/com/android/gallery3d/filtershow/colorpicker/ColorBrightnessView.java203
-rw-r--r--src/com/android/gallery3d/filtershow/colorpicker/ColorHueView.java208
-rw-r--r--src/com/android/gallery3d/filtershow/colorpicker/ColorSaturationView.java202
-rw-r--r--src/com/android/gallery3d/filtershow/colorpicker/ColorValueView.java4
-rw-r--r--src/com/android/gallery3d/filtershow/controller/BasicParameterStyle.java2
-rw-r--r--src/com/android/gallery3d/filtershow/controller/BitmapCaller.java23
-rw-r--r--src/com/android/gallery3d/filtershow/controller/FilterView.java2
-rw-r--r--src/com/android/gallery3d/filtershow/controller/ParameterBrightness.java40
-rw-r--r--src/com/android/gallery3d/filtershow/controller/ParameterHue.java40
-rw-r--r--src/com/android/gallery3d/filtershow/controller/ParameterIconStyle.java33
-rw-r--r--src/com/android/gallery3d/filtershow/controller/ParameterOpacity.java39
-rw-r--r--src/com/android/gallery3d/filtershow/controller/ParameterSaturation.java40
-rw-r--r--src/com/android/gallery3d/filtershow/controller/ParameterStyles.java2
-rw-r--r--src/com/android/gallery3d/filtershow/controller/SliderBrightness.java75
-rw-r--r--src/com/android/gallery3d/filtershow/controller/SliderHue.java86
-rw-r--r--src/com/android/gallery3d/filtershow/controller/SliderOpacity.java76
-rw-r--r--src/com/android/gallery3d/filtershow/controller/SliderSaturation.java77
-rw-r--r--src/com/android/gallery3d/filtershow/controller/StyleChooser.java6
-rw-r--r--src/com/android/gallery3d/filtershow/editors/Editor.java17
-rw-r--r--src/com/android/gallery3d/filtershow/editors/EditorChanSat.java6
-rw-r--r--src/com/android/gallery3d/filtershow/editors/EditorDraw.java138
-rw-r--r--src/com/android/gallery3d/filtershow/editors/ParametricEditor.java17
-rw-r--r--src/com/android/gallery3d/filtershow/filters/FilterDrawRepresentation.java84
-rw-r--r--src/com/android/gallery3d/filtershow/filters/ParametericFilterRepresentation.java27
-rw-r--r--src/com/android/gallery3d/filtershow/imageshow/ImageDraw.java2
29 files changed, 1401 insertions, 97 deletions
diff --git a/res/drawable-nodpi/brush_flat.png b/res/drawable-nodpi/brush_flat.png
new file mode 100644
index 000000000..ec2e44312
--- /dev/null
+++ b/res/drawable-nodpi/brush_flat.png
Binary files differ
diff --git a/res/menu/filtershow_menu_draw.xml b/res/menu/filtershow_menu_draw.xml
index 2960c1f05..55414ea14 100644
--- a/res/menu/filtershow_menu_draw.xml
+++ b/res/menu/filtershow_menu_draw.xml
@@ -15,27 +15,30 @@
limitations under the License.
-->
-<menu xmlns:android="http://schemas.android.com/apk/res/android" >
+<menu xmlns:android="http://schemas.android.com/apk/res/android">
- <group android:id="@+id/curves_popupmenu" >
+ <group android:id="@+id/curves_popupmenu">
<item
- android:id="@+id/draw_menu_style_line"
- android:title="@string/draw_style_line" />
- <item
- android:id="@+id/draw_menu_style_brush_marker"
- android:title="@string/draw_style_brush_marker"/>
- <item
- android:id="@+id/draw_menu_style_brush_spatter"
- android:title="@string/draw_style_brush_spatter"/>
- <item
- android:id="@+id/draw_menu_size"
- android:title="@string/draw_size" />
+ android:id="@+id/draw_menu_style"
+ android:title="@string/draw_style"/>
<item
- android:id="@+id/draw_menu_color"
- android:title="@string/draw_color"/>
+ android:id="@+id/draw_menu_opacity"
+ android:title="@string/draw_opacity"/>
<item
- android:id="@+id/draw_menu_clear"
- android:title="@string/draw_clear"/>
+ android:id="@+id/draw_menu_value"
+ android:title="@string/draw_value"/>
+ <item
+ android:id="@+id/draw_menu_saturation"
+ android:title="@string/draw_saturation"/>
+ <item
+ android:id="@+id/draw_menu_hue"
+ android:title="@string/draw_hue"/>
+ <item
+ android:id="@+id/draw_menu_size"
+ android:title="@string/draw_size"/>
+ <item
+ android:id="@+id/draw_menu_clear"
+ android:title="@string/draw_clear"/>
</group>
</menu> \ No newline at end of file
diff --git a/res/values/filtershow_color.xml b/res/values/filtershow_color.xml
index d7cf79d70..a8c44d8e2 100644
--- a/res/values/filtershow_color.xml
+++ b/res/values/filtershow_color.xml
@@ -24,8 +24,8 @@
<color name="background_toolbar">#363949</color>
<color name="background_main_toolbar">#232323</color>
<color name="toolbar_separation_line">#333333</color>
- <color name="slider_dot_color">#6464FF</color>
- <color name="slider_line_color">#33B5E5</color>
+ <color name="slider_dot_color">#646464</color>
+ <color name="slider_line_color">#888888</color>
<color name="state_panel_separation_line">#232323</color>
<color name="filtershow_background">#333333</color>
<color name="filtershow_graphic">#717171</color>
diff --git a/res/values/filtershow_strings.xml b/res/values/filtershow_strings.xml
index b28dd5fbe..f2c1bf161 100644
--- a/res/values/filtershow_strings.xml
+++ b/res/values/filtershow_strings.xml
@@ -207,8 +207,14 @@
<string name="draw_style">Style</string>
<!-- Label for the size to draw in in [CHAR LIMIT=14] -->
<string name="draw_size">Size</string>
+ <!-- Label for the Hue to draw in [CHAR LIMIT=14] -->
+ <string name="draw_hue">Hue</string>
<!-- Label for the color to draw in [CHAR LIMIT=14] -->
- <string name="draw_color">Color</string>
+ <string name="draw_saturation">Saturation</string>
+ <!-- Label for the Brightness to draw in [CHAR LIMIT=14] -->
+ <string name="draw_value">Brightness</string>
+ <!-- Label for the color to draw in [CHAR LIMIT=14] -->
+ <string name="draw_opacity">Opacity</string>
<!-- Label for the line style of drawing in [CHAR LIMIT=14] -->
<string name="draw_style_line">Lines</string>
<!-- Label for the Marker brush style of drawing in [CHAR LIMIT=14] -->
diff --git a/src/com/android/gallery3d/filtershow/colorpicker/ColorBrightnessView.java b/src/com/android/gallery3d/filtershow/colorpicker/ColorBrightnessView.java
new file mode 100644
index 000000000..9b955efc6
--- /dev/null
+++ b/src/com/android/gallery3d/filtershow/colorpicker/ColorBrightnessView.java
@@ -0,0 +1,203 @@
+/*
+ * Copyright (C) 2013 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.filtershow.colorpicker;
+
+import android.content.Context;
+import android.graphics.Bitmap;
+import android.graphics.BitmapShader;
+import android.graphics.Canvas;
+import android.graphics.Color;
+import android.graphics.LinearGradient;
+import android.graphics.Paint;
+import android.graphics.RadialGradient;
+import android.graphics.Shader;
+import android.util.AttributeSet;
+import android.util.DisplayMetrics;
+import android.view.MotionEvent;
+import android.view.View;
+
+import com.android.gallery3d.R;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+
+public class ColorBrightnessView extends View implements ColorListener {
+
+ private float mRadius;
+ private float mWidth;
+ private Paint mBarPaint1;
+ private Paint mLinePaint1;
+ private Paint mLinePaint2;
+ private Paint mCheckPaint;
+
+ private float mHeight;
+ private Paint mDotPaint;
+ private int mBgcolor = 0;
+
+ private float mDotRadius;
+ private float mBorder;
+
+ private float[] mHSVO = new float[4];
+ private int mSliderColor;
+ private float mDotX = mBorder;
+ private float mDotY = mBorder;
+ private final static float DOT_SIZE = ColorRectView.DOT_SIZE;
+ public final static float BORDER_SIZE = 20;;
+
+ private ArrayList<ColorListener> mColorListeners = new ArrayList<ColorListener>();
+
+ public ColorBrightnessView(Context ctx, AttributeSet attrs) {
+ super(ctx, attrs);
+ DisplayMetrics metrics = ctx.getResources().getDisplayMetrics();
+ float mDpToPix = metrics.density;
+ mDotRadius = DOT_SIZE * mDpToPix;
+ mBorder = BORDER_SIZE * mDpToPix;
+ mBarPaint1 = new Paint();
+
+ mDotPaint = new Paint();
+
+ mDotPaint.setStyle(Paint.Style.FILL);
+ mDotPaint.setColor(ctx.getResources().getColor(R.color.slider_dot_color));
+ mSliderColor = ctx.getResources().getColor(R.color.slider_line_color);
+
+ mBarPaint1.setStyle(Paint.Style.FILL);
+
+ mLinePaint1 = new Paint();
+ mLinePaint1.setColor(Color.GRAY);
+ mLinePaint2 = new Paint();
+ mLinePaint2.setColor(mSliderColor);
+ mLinePaint2.setStrokeWidth(4);
+
+ int[] colors = new int[16 * 16];
+ for (int i = 0; i < colors.length; i++) {
+ int y = i / (16 * 8);
+ int x = (i / 8) % 2;
+ colors[i] = (x == y) ? 0xFFAAAAAA : 0xFF444444;
+ }
+ Bitmap bitmap = Bitmap.createBitmap(colors, 16, 16, Bitmap.Config.ARGB_8888);
+ BitmapShader bs = new BitmapShader(bitmap, Shader.TileMode.REPEAT, Shader.TileMode.REPEAT);
+ mCheckPaint = new Paint();
+ mCheckPaint.setShader(bs);
+ }
+
+ public boolean onDown(MotionEvent e) {
+ return true;
+ }
+
+ @Override
+ public boolean onTouchEvent(MotionEvent event) {
+ float ox = mDotX;
+ float oy = mDotY;
+
+ float x = event.getX();
+ float y = event.getY();
+
+ mDotX = x;
+
+ if (mDotX < mBorder) {
+ mDotX = mBorder;
+ }
+
+ if (mDotX > mWidth - mBorder) {
+ mDotX = mWidth - mBorder;
+ }
+ mHSVO[3] = (mDotX - mBorder) / (mWidth - mBorder * 2);
+ notifyColorListeners(mHSVO);
+ setupButton();
+ invalidate((int) (ox - mDotRadius), (int) (oy - mDotRadius), (int) (ox + mDotRadius),
+ (int) (oy + mDotRadius));
+ invalidate(
+ (int) (mDotX - mDotRadius), (int) (mDotY - mDotRadius), (int) (mDotX + mDotRadius),
+ (int) (mDotY + mDotRadius));
+
+ return true;
+ }
+
+ private void setupButton() {
+ float pos = mHSVO[3] * (mWidth - mBorder * 2);
+ mDotX = pos + mBorder;
+
+ int[] colors3 = new int[] {
+ mSliderColor, mSliderColor, 0x66000000, 0 };
+ RadialGradient g = new RadialGradient(mDotX, mDotY, mDotRadius, colors3, new float[] {
+ 0, .3f, .31f, 1 }, Shader.TileMode.CLAMP);
+ mDotPaint.setShader(g);
+ }
+
+ @Override
+ protected void onSizeChanged(int w, int h, int oldw, int oldh) {
+ mWidth = w;
+ mHeight = h;
+ mDotY = mHeight / 2;
+ updatePaint();
+ setupButton();
+ }
+
+ private void updatePaint() {
+ float[] hsvo = Arrays.copyOf(mHSVO, 4);
+ hsvo[2] = 1;
+ hsvo[1] = 1;
+ hsvo[3] = 1;
+ int color2 = Color.HSVToColor(hsvo);
+ hsvo[2] = 0;
+ int color1 = Color.HSVToColor(hsvo);
+
+ Shader sg = new LinearGradient(
+ mBorder, mBorder, mWidth - mBorder, mBorder,
+ color1, color2, Shader.TileMode.CLAMP);
+ mBarPaint1.setShader(sg);
+
+ }
+
+ @Override
+ protected void onDraw(Canvas canvas) {
+ super.onDraw(canvas);
+ canvas.drawColor(mBgcolor);
+ canvas.drawRect(mBorder, mBorder, mWidth - mBorder, mHeight - mBorder, mCheckPaint);
+ canvas.drawRect(mBorder, mBorder, mWidth - mBorder, mHeight - mBorder, mBarPaint1);
+ canvas.drawLine(mDotX, mDotY, mWidth - mBorder, mDotY, mLinePaint1);
+ canvas.drawLine(mBorder, mDotY, mDotX, mDotY, mLinePaint2);
+ if (mDotX != Float.NaN) {
+ canvas.drawCircle(mDotX, mDotY, mDotRadius, mDotPaint);
+ }
+ }
+
+ @Override
+ public void setColor(float[] hsv) {
+ System.arraycopy(hsv, 0, mHSVO, 0, mHSVO.length);
+
+ float oy = mDotY;
+
+ updatePaint();
+ setupButton();
+ invalidate();
+ }
+
+ public void notifyColorListeners(float[] hsvo) {
+ for (ColorListener l : mColorListeners) {
+ l.setColor(hsvo);
+ }
+ }
+
+ public void addColorListener(ColorListener l) {
+ mColorListeners.add(l);
+ }
+
+ public void removeColorListener(ColorListener l) {
+ mColorListeners.remove(l);
+ }
+}
diff --git a/src/com/android/gallery3d/filtershow/colorpicker/ColorHueView.java b/src/com/android/gallery3d/filtershow/colorpicker/ColorHueView.java
new file mode 100644
index 000000000..efde6fdf2
--- /dev/null
+++ b/src/com/android/gallery3d/filtershow/colorpicker/ColorHueView.java
@@ -0,0 +1,208 @@
+/*
+ * Copyright (C) 2013 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.filtershow.colorpicker;
+
+import android.content.Context;
+import android.graphics.Bitmap;
+import android.graphics.BitmapShader;
+import android.graphics.Canvas;
+import android.graphics.Color;
+import android.graphics.LinearGradient;
+import android.graphics.Paint;
+import android.graphics.RadialGradient;
+import android.graphics.Shader;
+import android.util.AttributeSet;
+import android.util.DisplayMetrics;
+import android.view.MotionEvent;
+import android.view.View;
+
+import com.android.gallery3d.R;
+
+import java.util.ArrayList;
+
+public class ColorHueView extends View implements ColorListener {
+
+ private float mRadius;
+ private float mWidth;
+ private Paint mBarPaint1;
+ private Paint mLinePaint1;
+ private Paint mLinePaint2;
+ private Paint mCheckPaint;
+
+ private float mHeight;
+ private Paint mDotPaint;
+ private int mBgcolor = 0;
+
+ private float mDotRadius;
+ private float mBorder;
+
+ private float[] mHSVO = new float[4];
+ private int mSliderColor;
+ private float mDotX = mBorder;
+ private float mDotY = mBorder;
+ private final static float DOT_SIZE = ColorRectView.DOT_SIZE;
+ public final static float BORDER_SIZE = 20;;
+
+ private ArrayList<ColorListener> mColorListeners = new ArrayList<ColorListener>();
+
+ public ColorHueView(Context ctx, AttributeSet attrs) {
+ super(ctx, attrs);
+ DisplayMetrics metrics = ctx.getResources().getDisplayMetrics();
+ float mDpToPix = metrics.density;
+ mDotRadius = DOT_SIZE * mDpToPix;
+ mBorder = BORDER_SIZE * mDpToPix;
+ mBarPaint1 = new Paint();
+
+ mDotPaint = new Paint();
+
+ mDotPaint.setStyle(Paint.Style.FILL);
+ mDotPaint.setColor(ctx.getResources().getColor(R.color.slider_dot_color));
+ mSliderColor = ctx.getResources().getColor(R.color.slider_line_color);
+
+ mBarPaint1.setStyle(Paint.Style.FILL);
+
+ mLinePaint1 = new Paint();
+ mLinePaint1.setColor(Color.GRAY);
+ mLinePaint2 = new Paint();
+ mLinePaint2.setColor(mSliderColor);
+ mLinePaint2.setStrokeWidth(4);
+
+ int[] colors = new int[16 * 16];
+ for (int i = 0; i < colors.length; i++) {
+ int y = i / (16 * 8);
+ int x = (i / 8) % 2;
+ colors[i] = (x == y) ? 0xFFAAAAAA : 0xFF444444;
+ }
+ Bitmap bitmap = Bitmap.createBitmap(colors, 16, 16, Bitmap.Config.ARGB_8888);
+ BitmapShader bs = new BitmapShader(bitmap, Shader.TileMode.REPEAT, Shader.TileMode.REPEAT);
+ mCheckPaint = new Paint();
+ mCheckPaint.setShader(bs);
+ }
+
+ public boolean onDown(MotionEvent e) {
+ return true;
+ }
+
+ @Override
+ public boolean onTouchEvent(MotionEvent event) {
+ float ox = mDotX;
+ float oy = mDotY;
+
+ float x = event.getX();
+ float y = event.getY();
+
+ mDotX = x;
+
+ if (mDotX < mBorder) {
+ mDotX = mBorder;
+ }
+
+ if (mDotX > mWidth - mBorder) {
+ mDotX = mWidth - mBorder;
+ }
+ mHSVO[3] = (mDotX - mBorder) / (mWidth - mBorder * 2);
+ notifyColorListeners(mHSVO);
+ setupButton();
+ invalidate((int) (ox - mDotRadius), (int) (oy - mDotRadius), (int) (ox + mDotRadius),
+ (int) (oy + mDotRadius));
+ invalidate(
+ (int) (mDotX - mDotRadius), (int) (mDotY - mDotRadius), (int) (mDotX + mDotRadius),
+ (int) (mDotY + mDotRadius));
+
+ return true;
+ }
+
+ private void setupButton() {
+ float pos = mHSVO[3] * (mWidth - mBorder * 2);
+ mDotX = pos + mBorder;
+
+ int[] colors3 = new int[] {
+ mSliderColor, mSliderColor, 0x66000000, 0 };
+ RadialGradient g = new RadialGradient(mDotX, mDotY, mDotRadius, colors3, new float[] {
+ 0, .3f, .31f, 1 }, Shader.TileMode.CLAMP);
+ mDotPaint.setShader(g);
+ }
+
+ @Override
+ protected void onSizeChanged(int w, int h, int oldw, int oldh) {
+ mWidth = w;
+ mHeight = h;
+ mDotY = mHeight / 2;
+ updatePaint();
+ setupButton();
+ }
+
+ private int[] mColors = new int[] {
+ 0xFFFF0000,// red
+ 0xFFFFFF00,// yellow
+ 0xFF00FF00,// green
+ 0xFF00FFFF,// cyan
+ 0xFF0000FF,// blue
+ 0xFFFF00FF,// magenta
+ 0xFFFF0000,// red
+ };
+
+ private void updatePaint() {
+
+ int color2 = Color.HSVToColor(mHSVO);
+ int color1 = color2 & 0xFFFFFF;
+
+ Shader sg = new LinearGradient(
+ mBorder, mBorder, mWidth - mBorder, mBorder,
+ mColors, null, Shader.TileMode.CLAMP);
+ mBarPaint1.setShader(sg);
+
+ }
+
+ @Override
+ protected void onDraw(Canvas canvas) {
+ super.onDraw(canvas);
+ canvas.drawColor(mBgcolor);
+ canvas.drawRect(mBorder, mBorder, mWidth - mBorder, mHeight - mBorder, mCheckPaint);
+ canvas.drawRect(mBorder, mBorder, mWidth - mBorder, mHeight - mBorder, mBarPaint1);
+ canvas.drawLine(mDotX, mDotY, mWidth - mBorder, mDotY, mLinePaint1);
+ canvas.drawLine(mBorder, mDotY, mDotX, mDotY, mLinePaint2);
+ if (mDotX != Float.NaN) {
+ canvas.drawCircle(mDotX, mDotY, mDotRadius, mDotPaint);
+ }
+ }
+
+ @Override
+ public void setColor(float[] hsv) {
+ System.arraycopy(hsv, 0, mHSVO, 0, mHSVO.length);
+
+ float oy = mDotY;
+
+ updatePaint();
+ setupButton();
+ invalidate();
+ }
+
+ public void notifyColorListeners(float[] hsvo) {
+ for (ColorListener l : mColorListeners) {
+ l.setColor(hsvo);
+ }
+ }
+
+ public void addColorListener(ColorListener l) {
+ mColorListeners.add(l);
+ }
+
+ public void removeColorListener(ColorListener l) {
+ mColorListeners.remove(l);
+ }
+}
diff --git a/src/com/android/gallery3d/filtershow/colorpicker/ColorSaturationView.java b/src/com/android/gallery3d/filtershow/colorpicker/ColorSaturationView.java
new file mode 100644
index 000000000..af4dfdaa1
--- /dev/null
+++ b/src/com/android/gallery3d/filtershow/colorpicker/ColorSaturationView.java
@@ -0,0 +1,202 @@
+/*
+ * Copyright (C) 2013 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.filtershow.colorpicker;
+
+import android.content.Context;
+import android.graphics.Bitmap;
+import android.graphics.BitmapShader;
+import android.graphics.Canvas;
+import android.graphics.Color;
+import android.graphics.LinearGradient;
+import android.graphics.Paint;
+import android.graphics.RadialGradient;
+import android.graphics.Shader;
+import android.util.AttributeSet;
+import android.util.DisplayMetrics;
+import android.view.MotionEvent;
+import android.view.View;
+
+import com.android.gallery3d.R;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+
+public class ColorSaturationView extends View implements ColorListener {
+
+ private float mRadius;
+ private float mWidth;
+ private Paint mBarPaint1;
+ private Paint mLinePaint1;
+ private Paint mLinePaint2;
+ private Paint mCheckPaint;
+
+ private float mHeight;
+ private Paint mDotPaint;
+ private int mBgcolor = 0;
+
+ private float mDotRadius;
+ private float mBorder;
+
+ private float[] mHSVO = new float[4];
+ private int mSliderColor;
+ private float mDotX = mBorder;
+ private float mDotY = mBorder;
+ private final static float DOT_SIZE = ColorRectView.DOT_SIZE;
+ public final static float BORDER_SIZE = 20;;
+
+ private ArrayList<ColorListener> mColorListeners = new ArrayList<ColorListener>();
+
+ public ColorSaturationView(Context ctx, AttributeSet attrs) {
+ super(ctx, attrs);
+ DisplayMetrics metrics = ctx.getResources().getDisplayMetrics();
+ float mDpToPix = metrics.density;
+ mDotRadius = DOT_SIZE * mDpToPix;
+ mBorder = BORDER_SIZE * mDpToPix;
+ mBarPaint1 = new Paint();
+
+ mDotPaint = new Paint();
+
+ mDotPaint.setStyle(Paint.Style.FILL);
+ mDotPaint.setColor(ctx.getResources().getColor(R.color.slider_dot_color));
+ mSliderColor = ctx.getResources().getColor(R.color.slider_line_color);
+
+ mBarPaint1.setStyle(Paint.Style.FILL);
+
+ mLinePaint1 = new Paint();
+ mLinePaint1.setColor(Color.GRAY);
+ mLinePaint2 = new Paint();
+ mLinePaint2.setColor(mSliderColor);
+ mLinePaint2.setStrokeWidth(4);
+
+ int[] colors = new int[16 * 16];
+ for (int i = 0; i < colors.length; i++) {
+ int y = i / (16 * 8);
+ int x = (i / 8) % 2;
+ colors[i] = (x == y) ? 0xFFAAAAAA : 0xFF444444;
+ }
+ Bitmap bitmap = Bitmap.createBitmap(colors, 16, 16, Bitmap.Config.ARGB_8888);
+ BitmapShader bs = new BitmapShader(bitmap, Shader.TileMode.REPEAT, Shader.TileMode.REPEAT);
+ mCheckPaint = new Paint();
+ mCheckPaint.setShader(bs);
+ }
+
+ public boolean onDown(MotionEvent e) {
+ return true;
+ }
+
+ @Override
+ public boolean onTouchEvent(MotionEvent event) {
+ float ox = mDotX;
+ float oy = mDotY;
+
+ float x = event.getX();
+ float y = event.getY();
+
+ mDotX = x;
+
+ if (mDotX < mBorder) {
+ mDotX = mBorder;
+ }
+
+ if (mDotX > mWidth - mBorder) {
+ mDotX = mWidth - mBorder;
+ }
+ mHSVO[3] = (mDotX - mBorder) / (mWidth - mBorder * 2);
+ notifyColorListeners(mHSVO);
+ setupButton();
+ invalidate((int) (ox - mDotRadius), (int) (oy - mDotRadius), (int) (ox + mDotRadius),
+ (int) (oy + mDotRadius));
+ invalidate(
+ (int) (mDotX - mDotRadius), (int) (mDotY - mDotRadius), (int) (mDotX + mDotRadius),
+ (int) (mDotY + mDotRadius));
+
+ return true;
+ }
+
+ private void setupButton() {
+ float pos = mHSVO[3] * (mWidth - mBorder * 2);
+ mDotX = pos + mBorder;
+
+ int[] colors3 = new int[] {
+ mSliderColor, mSliderColor, 0x66000000, 0 };
+ RadialGradient g = new RadialGradient(mDotX, mDotY, mDotRadius, colors3, new float[] {
+ 0, .3f, .31f, 1 }, Shader.TileMode.CLAMP);
+ mDotPaint.setShader(g);
+ }
+
+ @Override
+ protected void onSizeChanged(int w, int h, int oldw, int oldh) {
+ mWidth = w;
+ mHeight = h;
+ mDotY = mHeight / 2;
+ updatePaint();
+ setupButton();
+ }
+
+ private void updatePaint() {
+ float[]hsvo = Arrays.copyOf(mHSVO, 4);
+ hsvo[3] = 1;
+ hsvo[2] = 1;
+ hsvo[1] = 1;
+ int color2 = Color.HSVToColor(hsvo);
+ hsvo[1] = 0;
+ int color1 = Color.HSVToColor(hsvo);
+ Shader sg = new LinearGradient(
+ mBorder, mBorder, mWidth - mBorder, mBorder,
+ color1, color2, Shader.TileMode.CLAMP);
+ mBarPaint1.setShader(sg);
+
+ }
+
+ @Override
+ protected void onDraw(Canvas canvas) {
+ super.onDraw(canvas);
+ canvas.drawColor(mBgcolor);
+ canvas.drawRect(mBorder, mBorder, mWidth - mBorder, mHeight - mBorder, mCheckPaint);
+ canvas.drawRect(mBorder, mBorder, mWidth - mBorder, mHeight - mBorder, mBarPaint1);
+ canvas.drawLine(mDotX, mDotY, mWidth - mBorder, mDotY, mLinePaint1);
+ canvas.drawLine(mBorder, mDotY, mDotX, mDotY, mLinePaint2);
+ if (mDotX != Float.NaN) {
+ canvas.drawCircle(mDotX, mDotY, mDotRadius, mDotPaint);
+ }
+ }
+
+ @Override
+ public void setColor(float[] hsv) {
+ System.arraycopy(hsv, 0, mHSVO, 0, mHSVO.length);
+
+ float oy = mDotY;
+
+ updatePaint();
+ setupButton();
+ invalidate();
+ }
+
+ public void notifyColorListeners(float[] hsvo) {
+ for (ColorListener l : mColorListeners) {
+ l.setColor(hsvo);
+ }
+ }
+
+ public void addColorListener(ColorListener l) {
+ mColorListeners.add(l);
+ }
+
+ public void removeColorListener(ColorListener l) {
+ mColorListeners.remove(l);
+ }
+}
diff --git a/src/com/android/gallery3d/filtershow/colorpicker/ColorValueView.java b/src/com/android/gallery3d/filtershow/colorpicker/ColorValueView.java
index 13cb44bad..bbfd829b3 100644
--- a/src/com/android/gallery3d/filtershow/colorpicker/ColorValueView.java
+++ b/src/com/android/gallery3d/filtershow/colorpicker/ColorValueView.java
@@ -52,6 +52,8 @@ public class ColorValueView extends View implements ColorListener {
private final static float DOT_SIZE = ColorRectView.DOT_SIZE;
private final static float BORDER_SIZE = ColorRectView.DOT_SIZE;
+ private ArrayList<ColorListener> mColorListeners = new ArrayList<ColorListener>();
+
public ColorValueView(Context ctx, AttributeSet attrs) {
super(ctx, attrs);
DisplayMetrics metrics = ctx.getResources().getDisplayMetrics();
@@ -162,8 +164,6 @@ public class ColorValueView extends View implements ColorListener {
}
- ArrayList<ColorListener> mColorListeners = new ArrayList<ColorListener>();
-
public void notifyColorListeners(float[] hsv) {
for (ColorListener l : mColorListeners) {
l.setColor(hsv);
diff --git a/src/com/android/gallery3d/filtershow/controller/BasicParameterStyle.java b/src/com/android/gallery3d/filtershow/controller/BasicParameterStyle.java
index fb9f95e97..498dcc698 100644
--- a/src/com/android/gallery3d/filtershow/controller/BasicParameterStyle.java
+++ b/src/com/android/gallery3d/filtershow/controller/BasicParameterStyle.java
@@ -90,7 +90,7 @@ public class BasicParameterStyle implements ParameterStyles {
}
@Override
- public void getIcon(int index, RenderingRequestCaller caller) {
+ public void getIcon(int index, BitmapCaller caller) {
mEditor.computeIcon(index, caller);
}
diff --git a/src/com/android/gallery3d/filtershow/controller/BitmapCaller.java b/src/com/android/gallery3d/filtershow/controller/BitmapCaller.java
new file mode 100644
index 000000000..e06c7e21a
--- /dev/null
+++ b/src/com/android/gallery3d/filtershow/controller/BitmapCaller.java
@@ -0,0 +1,23 @@
+/*
+ * Copyright (C) 2013 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.filtershow.controller;
+
+import android.graphics.Bitmap;
+
+public interface BitmapCaller {
+ public void available(Bitmap bmap);
+}
diff --git a/src/com/android/gallery3d/filtershow/controller/FilterView.java b/src/com/android/gallery3d/filtershow/controller/FilterView.java
index 9ca81dc35..9ca0e604c 100644
--- a/src/com/android/gallery3d/filtershow/controller/FilterView.java
+++ b/src/com/android/gallery3d/filtershow/controller/FilterView.java
@@ -19,7 +19,7 @@ package com.android.gallery3d.filtershow.controller;
import com.android.gallery3d.filtershow.pipeline.RenderingRequestCaller;
public interface FilterView {
- public void computeIcon(int index, RenderingRequestCaller caller);
+ public void computeIcon(int index, BitmapCaller caller);
public void commitLocalRepresentation();
}
diff --git a/src/com/android/gallery3d/filtershow/controller/ParameterBrightness.java b/src/com/android/gallery3d/filtershow/controller/ParameterBrightness.java
new file mode 100644
index 000000000..669df93c9
--- /dev/null
+++ b/src/com/android/gallery3d/filtershow/controller/ParameterBrightness.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2013 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.filtershow.controller;
+
+public class ParameterBrightness extends BasicParameterInt {
+ public static String sParameterType = "ParameterBrightness";
+ float[] mHSVO = new float[4];
+
+ public ParameterBrightness(int id, int value) {
+ super(id, value, 0, 255);
+ }
+
+ @Override
+ public String getParameterType() {
+ return sParameterType;
+ }
+
+ public void setColor(float[] hsvo) {
+ mHSVO = hsvo;
+ }
+
+ public float[] getColor() {
+ mHSVO[3] = getValue() / (float) getMaximum();
+ return mHSVO;
+ }
+}
diff --git a/src/com/android/gallery3d/filtershow/controller/ParameterHue.java b/src/com/android/gallery3d/filtershow/controller/ParameterHue.java
new file mode 100644
index 000000000..7682ec9d5
--- /dev/null
+++ b/src/com/android/gallery3d/filtershow/controller/ParameterHue.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2013 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.filtershow.controller;
+
+public class ParameterHue extends BasicParameterInt {
+ public static String sParameterType = "ParameterHue";
+ float[] mHSVO = new float[4];
+
+ public ParameterHue(int id, int value) {
+ super(id, value, 0, 360);
+ }
+
+ @Override
+ public String getParameterType() {
+ return sParameterType;
+ }
+
+ public void setColor(float[] hsvo) {
+ mHSVO = hsvo;
+ }
+
+ public float[] getColor() {
+ mHSVO[3] = getValue() / (float) getMaximum();
+ return mHSVO;
+ }
+}
diff --git a/src/com/android/gallery3d/filtershow/controller/ParameterIconStyle.java b/src/com/android/gallery3d/filtershow/controller/ParameterIconStyle.java
new file mode 100644
index 000000000..a26ee65b0
--- /dev/null
+++ b/src/com/android/gallery3d/filtershow/controller/ParameterIconStyle.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2013 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.filtershow.controller;
+
+import android.graphics.Bitmap;
+
+public class ParameterIconStyle extends BasicParameterStyle {
+ Bitmap[] mBitmaps;
+
+ public ParameterIconStyle(int id, Bitmap[] styles) {
+ super(id, styles.length);
+ mBitmaps = styles;
+ }
+
+ @Override
+ public void getIcon(int index, BitmapCaller caller) {
+ caller.available(mBitmaps[index]);
+ }
+}
diff --git a/src/com/android/gallery3d/filtershow/controller/ParameterOpacity.java b/src/com/android/gallery3d/filtershow/controller/ParameterOpacity.java
new file mode 100644
index 000000000..aecbf4aa4
--- /dev/null
+++ b/src/com/android/gallery3d/filtershow/controller/ParameterOpacity.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2013 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.filtershow.controller;
+
+public class ParameterOpacity extends BasicParameterInt {
+ public static String sParameterType = "ParameterOpacity";
+ float[] mHSVO = new float[4];
+
+ public ParameterOpacity(int id, int value) {
+ super(id, value, 0, 255);
+ }
+
+ @Override
+ public String getParameterType() {
+ return sParameterType;
+ }
+
+ public void setColor(float[] hsvo) {
+ mHSVO = hsvo;
+ }
+
+ public float[] getColor() {
+ mHSVO[3] = getValue() / (float) getMaximum();
+ return mHSVO;
+ }
+}
diff --git a/src/com/android/gallery3d/filtershow/controller/ParameterSaturation.java b/src/com/android/gallery3d/filtershow/controller/ParameterSaturation.java
new file mode 100644
index 000000000..a6a4cb148
--- /dev/null
+++ b/src/com/android/gallery3d/filtershow/controller/ParameterSaturation.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2013 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.filtershow.controller;
+
+public class ParameterSaturation extends BasicParameterInt {
+ public static String sParameterType = "ParameterSaturation";
+ float[] mHSVO = new float[4];
+
+ public ParameterSaturation(int id, int value) {
+ super(id, value, 0, 100);
+ }
+
+ @Override
+ public String getParameterType() {
+ return sParameterType;
+ }
+
+ public void setColor(float[] hsvo) {
+ mHSVO = hsvo;
+ }
+
+ public float[] getColor() {
+ mHSVO[3] = getValue() / (float) getMaximum();
+ return mHSVO;
+ }
+}
diff --git a/src/com/android/gallery3d/filtershow/controller/ParameterStyles.java b/src/com/android/gallery3d/filtershow/controller/ParameterStyles.java
index 7d250a0bf..91d5a0005 100644
--- a/src/com/android/gallery3d/filtershow/controller/ParameterStyles.java
+++ b/src/com/android/gallery3d/filtershow/controller/ParameterStyles.java
@@ -31,7 +31,7 @@ public interface ParameterStyles extends Parameter {
void setSelected(int value);
- void getIcon(int index, RenderingRequestCaller caller);
+ void getIcon(int index, BitmapCaller caller);
String getStyleTitle(int index, Context context);
}
diff --git a/src/com/android/gallery3d/filtershow/controller/SliderBrightness.java b/src/com/android/gallery3d/filtershow/controller/SliderBrightness.java
new file mode 100644
index 000000000..6dc86882d
--- /dev/null
+++ b/src/com/android/gallery3d/filtershow/controller/SliderBrightness.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2013 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.filtershow.controller;
+
+import android.content.Context;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.LinearLayout;
+
+import com.android.gallery3d.R;
+import com.android.gallery3d.filtershow.colorpicker.ColorBrightnessView;
+import com.android.gallery3d.filtershow.colorpicker.ColorListener;
+import com.android.gallery3d.filtershow.colorpicker.ColorOpacityView;
+import com.android.gallery3d.filtershow.editors.Editor;
+
+public class SliderBrightness implements Control {
+ private ColorBrightnessView mColorOpacityView;
+ private ParameterBrightness mParameter;
+ Editor mEditor;
+
+ @Override
+ public void setUp(ViewGroup container, Parameter parameter, Editor editor) {
+ container.removeAllViews();
+ mEditor = editor;
+ Context context = container.getContext();
+ mParameter = (ParameterBrightness) parameter;
+ LayoutInflater inflater =
+ (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+ LinearLayout lp = (LinearLayout) inflater.inflate(
+ R.layout.filtershow_brightness, container, true);
+
+ mColorOpacityView = (ColorBrightnessView) lp.findViewById(R.id.brightnessView);
+ updateUI();
+ mColorOpacityView.addColorListener(new ColorListener() {
+ @Override
+ public void setColor(float[] hsvo) {
+ mParameter.setValue((int)(255* hsvo[3]));
+ mEditor.commitLocalRepresentation();
+ }
+ });
+ }
+
+ @Override
+ public View getTopView() {
+ return mColorOpacityView;
+ }
+
+ @Override
+ public void setPrameter(Parameter parameter) {
+ mParameter = (ParameterBrightness) parameter;
+ if (mColorOpacityView != null) {
+ updateUI();
+ }
+ }
+
+ @Override
+ public void updateUI() {
+ mColorOpacityView.setColor(mParameter.getColor());
+ }
+}
diff --git a/src/com/android/gallery3d/filtershow/controller/SliderHue.java b/src/com/android/gallery3d/filtershow/controller/SliderHue.java
new file mode 100644
index 000000000..a550afd79
--- /dev/null
+++ b/src/com/android/gallery3d/filtershow/controller/SliderHue.java
@@ -0,0 +1,86 @@
+/*
+ * Copyright (C) 2013 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.filtershow.controller;
+
+import android.content.Context;
+import android.graphics.Canvas;
+import android.graphics.ColorFilter;
+import android.graphics.LinearGradient;
+import android.graphics.Paint;
+import android.graphics.RectF;
+import android.graphics.Shader;
+import android.graphics.drawable.Drawable;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.LinearLayout;
+import android.widget.SeekBar;
+import android.widget.SeekBar.OnSeekBarChangeListener;
+
+import com.android.gallery3d.R;
+import com.android.gallery3d.app.Log;
+import com.android.gallery3d.filtershow.colorpicker.ColorHueView;
+import com.android.gallery3d.filtershow.colorpicker.ColorListener;
+import com.android.gallery3d.filtershow.colorpicker.ColorOpacityView;
+import com.android.gallery3d.filtershow.editors.Editor;
+
+public class SliderHue implements Control {
+ public static String LOGTAG = "SliderHue";
+ private ColorHueView mColorOpacityView;
+ private ParameterHue mParameter;
+ Editor mEditor;
+
+ @Override
+ public void setUp(ViewGroup container, Parameter parameter, Editor editor) {
+ container.removeAllViews();
+ mEditor = editor;
+ Context context = container.getContext();
+ mParameter = (ParameterHue) parameter;
+ LayoutInflater inflater =
+ (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+ LinearLayout lp = (LinearLayout) inflater.inflate(
+ R.layout.filtershow_hue, container, true);
+
+ mColorOpacityView = (ColorHueView) lp.findViewById(R.id.hueView);
+ updateUI();
+ mColorOpacityView.addColorListener(new ColorListener() {
+ @Override
+ public void setColor(float[] hsvo) {
+ mParameter.setValue((int)(360* hsvo[3]));
+ mEditor.commitLocalRepresentation();
+ }
+ });
+ }
+
+ @Override
+ public View getTopView() {
+ return mColorOpacityView;
+ }
+
+ @Override
+ public void setPrameter(Parameter parameter) {
+ mParameter = (ParameterHue) parameter;
+ if (mColorOpacityView != null) {
+ updateUI();
+ }
+ }
+
+ @Override
+ public void updateUI() {
+ mColorOpacityView.setColor(mParameter.getColor());
+ }
+}
diff --git a/src/com/android/gallery3d/filtershow/controller/SliderOpacity.java b/src/com/android/gallery3d/filtershow/controller/SliderOpacity.java
new file mode 100644
index 000000000..cd21e9b76
--- /dev/null
+++ b/src/com/android/gallery3d/filtershow/controller/SliderOpacity.java
@@ -0,0 +1,76 @@
+/*
+ * Copyright (C) 2013 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.filtershow.controller;
+
+import android.content.Context;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.LinearLayout;
+import android.widget.SeekBar;
+import android.widget.SeekBar.OnSeekBarChangeListener;
+
+import com.android.gallery3d.R;
+import com.android.gallery3d.filtershow.colorpicker.ColorListener;
+import com.android.gallery3d.filtershow.colorpicker.ColorOpacityView;
+import com.android.gallery3d.filtershow.editors.Editor;
+
+public class SliderOpacity implements Control {
+ private ColorOpacityView mColorOpacityView;
+ private ParameterOpacity mParameter;
+ private Editor mEditor;
+
+ @Override
+ public void setUp(ViewGroup container, Parameter parameter, Editor editor) {
+ container.removeAllViews();
+ mEditor = editor;
+ Context context = container.getContext();
+ mParameter = (ParameterOpacity) parameter;
+ LayoutInflater inflater =
+ (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+ LinearLayout lp = (LinearLayout) inflater.inflate(
+ R.layout.filtershow_opacity, container, true);
+
+ mColorOpacityView = (ColorOpacityView) lp.findViewById(R.id.opacityView);
+ updateUI();
+ mColorOpacityView.addColorListener(new ColorListener() {
+ @Override
+ public void setColor(float[] hsvo) {
+ mParameter.setValue((int) (255 * hsvo[3]));
+ mEditor.commitLocalRepresentation();
+ }
+ });
+ }
+
+ @Override
+ public View getTopView() {
+ return mColorOpacityView;
+ }
+
+ @Override
+ public void setPrameter(Parameter parameter) {
+ mParameter = (ParameterOpacity) parameter;
+ if (mColorOpacityView != null) {
+ updateUI();
+ }
+ }
+
+ @Override
+ public void updateUI() {
+ mColorOpacityView.setColor(mParameter.getColor());
+ }
+}
diff --git a/src/com/android/gallery3d/filtershow/controller/SliderSaturation.java b/src/com/android/gallery3d/filtershow/controller/SliderSaturation.java
new file mode 100644
index 000000000..1f2b3fbd8
--- /dev/null
+++ b/src/com/android/gallery3d/filtershow/controller/SliderSaturation.java
@@ -0,0 +1,77 @@
+/*
+ * Copyright (C) 2013 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.filtershow.controller;
+
+import android.content.Context;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.LinearLayout;
+import android.widget.SeekBar;
+import android.widget.SeekBar.OnSeekBarChangeListener;
+
+import com.android.gallery3d.R;
+import com.android.gallery3d.filtershow.colorpicker.ColorListener;
+import com.android.gallery3d.filtershow.colorpicker.ColorOpacityView;
+import com.android.gallery3d.filtershow.colorpicker.ColorSaturationView;
+import com.android.gallery3d.filtershow.editors.Editor;
+
+public class SliderSaturation implements Control {
+ private ColorSaturationView mColorOpacityView;
+ private ParameterSaturation mParameter;
+ private Editor mEditor;
+
+ @Override
+ public void setUp(ViewGroup container, Parameter parameter, Editor editor) {
+ container.removeAllViews();
+ mEditor = editor;
+ Context context = container.getContext();
+ mParameter = (ParameterSaturation) parameter;
+ LayoutInflater inflater =
+ (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+ LinearLayout lp = (LinearLayout) inflater.inflate(
+ R.layout.filtershow_saturation, container, true);
+
+ mColorOpacityView = (ColorSaturationView) lp.findViewById(R.id.saturationView);
+ updateUI();
+ mColorOpacityView.addColorListener(new ColorListener() {
+ @Override
+ public void setColor(float[] hsvo) {
+ mParameter.setValue((int) (255 * hsvo[3]));
+ mEditor.commitLocalRepresentation();
+ }
+ });
+ }
+
+ @Override
+ public View getTopView() {
+ return mColorOpacityView;
+ }
+
+ @Override
+ public void setPrameter(Parameter parameter) {
+ mParameter = (ParameterSaturation) parameter;
+ if (mColorOpacityView != null) {
+ updateUI();
+ }
+ }
+
+ @Override
+ public void updateUI() {
+ mColorOpacityView.setColor(mParameter.getColor());
+ }
+}
diff --git a/src/com/android/gallery3d/filtershow/controller/StyleChooser.java b/src/com/android/gallery3d/filtershow/controller/StyleChooser.java
index fb613abc7..97a47dd98 100644
--- a/src/com/android/gallery3d/filtershow/controller/StyleChooser.java
+++ b/src/com/android/gallery3d/filtershow/controller/StyleChooser.java
@@ -54,10 +54,10 @@ public class StyleChooser implements Control {
}
});
mLinearLayout.addView(button);
- mParameter.getIcon(i, new RenderingRequestCaller() {
+ mParameter.getIcon(i, new BitmapCaller() {
@Override
- public void available(RenderingRequest request) {
- Bitmap bmap = request.getBitmap();
+ public void available(Bitmap bmap) {
+
if (bmap == null) {
return;
}
diff --git a/src/com/android/gallery3d/filtershow/editors/Editor.java b/src/com/android/gallery3d/filtershow/editors/Editor.java
index 51df5b520..9e7eb0c6b 100644
--- a/src/com/android/gallery3d/filtershow/editors/Editor.java
+++ b/src/com/android/gallery3d/filtershow/editors/Editor.java
@@ -144,7 +144,7 @@ public class Editor implements OnSeekBarChangeListener, SwapButton.SwapButtonLis
}
- public void createEditor(Context context,FrameLayout frameLayout) {
+ public void createEditor(Context context, FrameLayout frameLayout) {
mContext = context;
mFrameLayout = frameLayout;
mLocalRepresentation = null;
@@ -211,17 +211,17 @@ public class Editor implements OnSeekBarChangeListener, SwapButton.SwapButtonLis
}
/**
- * Call this to update the preset in MasterImage with the current representation
- * returned by getLocalRepresentation. This causes the preview bitmap to be
- * regenerated.
+ * Call this to update the preset in MasterImage with the current representation
+ * returned by getLocalRepresentation. This causes the preview bitmap to be
+ * regenerated.
*/
public void commitLocalRepresentation() {
commitLocalRepresentation(getLocalRepresentation());
}
/**
- * Call this to update the preset in MasterImage with a given representation.
- * This causes the preview bitmap to be regenerated.
+ * Call this to update the preset in MasterImage with a given representation.
+ * This causes the preview bitmap to be regenerated.
*/
public void commitLocalRepresentation(FilterRepresentation rep) {
ArrayList<FilterRepresentation> filter = new ArrayList<FilterRepresentation>(1);
@@ -230,8 +230,8 @@ public class Editor implements OnSeekBarChangeListener, SwapButton.SwapButtonLis
}
/**
- * Call this to update the preset in MasterImage with a collection of FilterRepresnations.
- * This causes the preview bitmap to be regenerated.
+ * Call this to update the preset in MasterImage with a collection of FilterRepresentations.
+ * This causes the preview bitmap to be regenerated.
*/
public void commitLocalRepresentation(Collection<FilterRepresentation> reps) {
ImagePreset preset = MasterImage.getImage().getPreset();
@@ -306,6 +306,7 @@ public class Editor implements OnSeekBarChangeListener, SwapButton.SwapButtonLis
public Control[] getControls() {
return null;
}
+
@Override
public void onStartTrackingTouch(SeekBar arg0) {
diff --git a/src/com/android/gallery3d/filtershow/editors/EditorChanSat.java b/src/com/android/gallery3d/filtershow/editors/EditorChanSat.java
index 7e31f09ae..95a30e7fa 100644
--- a/src/com/android/gallery3d/filtershow/editors/EditorChanSat.java
+++ b/src/com/android/gallery3d/filtershow/editors/EditorChanSat.java
@@ -27,6 +27,7 @@ import android.widget.SeekBar.OnSeekBarChangeListener;
import com.android.gallery3d.R;
import com.android.gallery3d.filtershow.controller.BasicParameterStyle;
+import com.android.gallery3d.filtershow.controller.BitmapCaller;
import com.android.gallery3d.filtershow.controller.FilterView;
import com.android.gallery3d.filtershow.controller.Parameter;
import com.android.gallery3d.filtershow.filters.FilterChanSatRepresentation;
@@ -158,15 +159,14 @@ public class EditorChanSat extends ParametricEditor implements OnSeekBarChangeLi
}
@Override
- public void computeIcon(int n, RenderingRequestCaller caller) {
+ public void computeIcon(int n, BitmapCaller caller) {
FilterChanSatRepresentation rep = getChanSatRep();
if (rep == null) return;
rep = (FilterChanSatRepresentation) rep.copy();
ImagePreset preset = new ImagePreset();
preset.addFilter(rep);
Bitmap src = MasterImage.getImage().getThumbnailBitmap();
- RenderingRequest.post(null, src, preset, RenderingRequest.STYLE_ICON_RENDERING,
- caller);
+ caller.available(src);
}
protected void selectMenuItem(MenuItem item) {
diff --git a/src/com/android/gallery3d/filtershow/editors/EditorDraw.java b/src/com/android/gallery3d/filtershow/editors/EditorDraw.java
index 4b09051e2..b42aef297 100644
--- a/src/com/android/gallery3d/filtershow/editors/EditorDraw.java
+++ b/src/com/android/gallery3d/filtershow/editors/EditorDraw.java
@@ -18,6 +18,8 @@ package com.android.gallery3d.filtershow.editors;
import android.app.Dialog;
import android.content.Context;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
@@ -32,24 +34,51 @@ import com.android.gallery3d.R;
import com.android.gallery3d.filtershow.FilterShowActivity;
import com.android.gallery3d.filtershow.colorpicker.ColorGridDialog;
import com.android.gallery3d.filtershow.colorpicker.RGBListener;
+import com.android.gallery3d.filtershow.controller.BitmapCaller;
+import com.android.gallery3d.filtershow.controller.FilterView;
import com.android.gallery3d.filtershow.filters.FilterDrawRepresentation;
import com.android.gallery3d.filtershow.filters.FilterRepresentation;
import com.android.gallery3d.filtershow.filters.ImageFilterDraw;
import com.android.gallery3d.filtershow.imageshow.ImageDraw;
-public class EditorDraw extends Editor {
+public class EditorDraw extends ParametricEditor implements FilterView {
private static final String LOGTAG = "EditorDraw";
public static final int ID = R.id.editorDraw;
public ImageDraw mImageDraw;
+ private static final int MODE_BRIGHTNESS = FilterDrawRepresentation.PARAM_BRIGHTNESS;
+ private static final int MODE_SATURATION = FilterDrawRepresentation.PARAM_SATURATION;
+ private static final int MODE_SIZE = FilterDrawRepresentation.PARAM_SIZE;
+ private static final int MODE_HUEE = FilterDrawRepresentation.PARAM_HUE;
+ private static final int MODE_SIZEE = FilterDrawRepresentation.PARAM_SIZE;
+ private static final int MODE_OPACITY = FilterDrawRepresentation.PARAM_OPACITY;
+ private static final int MODE_STYLE = FilterDrawRepresentation.PARAM_STYLE;
+ int[] brushIcons = {
+ R.drawable.brush_flat,
+ R.drawable.brush_marker,
+ R.drawable.brush_spatter
+ };
+
+ String mParameterString;
public EditorDraw() {
super(ID);
}
@Override
+ public String calculateUserMessage(Context context, String effectName, Object parameterValue) {
+ FilterDrawRepresentation rep = getDrawRep();
+ if (rep == null) {
+ return "";
+ }
+ String paramString;
+ String val = rep.getValueString();
+ return mParameterString + val;
+ }
+
+ @Override
public void createEditor(Context context, FrameLayout frameLayout) {
- super.createEditor(context, frameLayout);
mView = mImageShow = mImageDraw = new ImageDraw(context);
+ super.createEditor(context, frameLayout);
mImageDraw.setEditor(this);
}
@@ -58,10 +87,12 @@ public class EditorDraw extends Editor {
public void reflectCurrentFilter() {
super.reflectCurrentFilter();
FilterRepresentation rep = getLocalRepresentation();
-
if (rep != null && getLocalRepresentation() instanceof FilterDrawRepresentation) {
FilterDrawRepresentation drawRep = (FilterDrawRepresentation) getLocalRepresentation();
mImageDraw.setFilterDrawRepresentation(drawRep);
+ drawRep.getParam(FilterDrawRepresentation.PARAM_STYLE).setFilterView(this);
+ drawRep.setPramMode(FilterDrawRepresentation.PARAM_HUE);
+ control(drawRep.getCurrentParam(), mEditControl);
}
}
@@ -71,7 +102,7 @@ public class EditorDraw extends Editor {
view.setText(mContext.getString(R.string.draw_style));
view.setOnClickListener(new OnClickListener() {
- @Override
+ @Override
public void onClick(View arg0) {
showPopupMenu(accessoryViewList);
}
@@ -95,64 +126,65 @@ public class EditorDraw extends Editor {
@Override
public boolean onMenuItemClick(MenuItem item) {
- ImageFilterDraw filter = (ImageFilterDraw) mImageShow.getCurrentFilter();
- if (item.getItemId() == R.id.draw_menu_color) {
- showColorGrid(item);
- } else if (item.getItemId() == R.id.draw_menu_size) {
- showSizeDialog(item);
- } else if (item.getItemId() == R.id.draw_menu_style_brush_marker) {
- ImageDraw idraw = (ImageDraw) mImageShow;
- idraw.setStyle(ImageFilterDraw.BRUSH_STYLE_MARKER);
- } else if (item.getItemId() == R.id.draw_menu_style_brush_spatter) {
- ImageDraw idraw = (ImageDraw) mImageShow;
- idraw.setStyle(ImageFilterDraw.BRUSH_STYLE_SPATTER);
- } else if (item.getItemId() == R.id.draw_menu_style_line) {
- ImageDraw idraw = (ImageDraw) mImageShow;
- idraw.setStyle(ImageFilterDraw.SIMPLE_STYLE);
- } else if (item.getItemId() == R.id.draw_menu_clear) {
- ImageDraw idraw = (ImageDraw) mImageShow;
- idraw.resetParameter();
- commitLocalRepresentation();
- }
- mView.invalidate();
+ selectMenuItem(item);
return true;
}
});
popupMenu.show();
+
}
- public void showSizeDialog(final MenuItem item) {
- FilterShowActivity ctx = mImageShow.getActivity();
- final Dialog dialog = new Dialog(ctx);
- dialog.setTitle(R.string.draw_size_title);
- dialog.setContentView(R.layout.filtershow_draw_size);
- final SeekBar bar = (SeekBar) dialog.findViewById(R.id.sizeSeekBar);
- ImageDraw idraw = (ImageDraw) mImageShow;
- bar.setProgress(idraw.getSize());
- Button button = (Button) dialog.findViewById(R.id.sizeAcceptButton);
- button.setOnClickListener(new OnClickListener() {
+ protected void selectMenuItem(MenuItem item) {
+ ImageFilterDraw filter = (ImageFilterDraw) mImageShow.getCurrentFilter();
+ FilterDrawRepresentation rep = getDrawRep();
+ if (rep == null) {
+ return;
+ }
- @Override
- public void onClick(View arg0) {
- int p = bar.getProgress();
+ switch (item.getItemId()) {
+ case R.id.draw_menu_clear:
ImageDraw idraw = (ImageDraw) mImageShow;
- idraw.setSize(p + 1);
- dialog.dismiss();
- }
- });
- dialog.show();
+ idraw.resetParameter();
+ commitLocalRepresentation();
+ break;
+ case R.id.draw_menu_hue:
+ rep.setPramMode(FilterDrawRepresentation.PARAM_HUE);
+ break;
+ case R.id.draw_menu_opacity:
+ rep.setPramMode(FilterDrawRepresentation.PARAM_OPACITY);
+ break;
+ case R.id.draw_menu_saturation:
+ rep.setPramMode(FilterDrawRepresentation.PARAM_SATURATION);
+ break;
+ case R.id.draw_menu_size:
+ rep.setPramMode(FilterDrawRepresentation.PARAM_SIZE);
+ break;
+ case R.id.draw_menu_style:
+ rep.setPramMode(FilterDrawRepresentation.PARAM_STYLE);
+ break;
+ case R.id.draw_menu_value:
+ rep.setPramMode(FilterDrawRepresentation.PARAM_BRIGHTNESS);
+ break;
+ }
+ if (item.getItemId() != R.id.draw_menu_clear) {
+ mParameterString = item.getTitle().toString();
+ }
+ control(rep.getCurrentParam(), mEditControl);
+ mControl.updateUI();
+ mView.invalidate();
}
- public void showColorGrid(final MenuItem item) {
- RGBListener cl = new RGBListener() {
- @Override
- public void setColor(int rgb) {
- ImageDraw idraw = (ImageDraw) mImageShow;
- idraw.setColor(rgb);
- }
- };
- ColorGridDialog cpd = new ColorGridDialog(mImageShow.getActivity(), cl);
- cpd.show();
- LayoutParams params = cpd.getWindow().getAttributes();
+ FilterDrawRepresentation getDrawRep() {
+ FilterRepresentation rep = getLocalRepresentation();
+ if (rep instanceof FilterDrawRepresentation) {
+ return (FilterDrawRepresentation) rep;
+ }
+ return null;
+ }
+
+ @Override
+ public void computeIcon(int index, BitmapCaller caller) {
+ Bitmap bitmap = BitmapFactory.decodeResource(mContext.getResources(), brushIcons[index]);
+ caller.available(bitmap);
}
}
diff --git a/src/com/android/gallery3d/filtershow/editors/ParametricEditor.java b/src/com/android/gallery3d/filtershow/editors/ParametricEditor.java
index 9ec858ca5..6f0a79222 100644
--- a/src/com/android/gallery3d/filtershow/editors/ParametricEditor.java
+++ b/src/com/android/gallery3d/filtershow/editors/ParametricEditor.java
@@ -33,8 +33,16 @@ import com.android.gallery3d.filtershow.controller.BasicSlider;
import com.android.gallery3d.filtershow.controller.Control;
import com.android.gallery3d.filtershow.controller.Parameter;
import com.android.gallery3d.filtershow.controller.ParameterActionAndInt;
+import com.android.gallery3d.filtershow.controller.ParameterBrightness;
+import com.android.gallery3d.filtershow.controller.ParameterHue;
import com.android.gallery3d.filtershow.controller.ParameterInteger;
+import com.android.gallery3d.filtershow.controller.ParameterOpacity;
+import com.android.gallery3d.filtershow.controller.ParameterSaturation;
import com.android.gallery3d.filtershow.controller.ParameterStyles;
+import com.android.gallery3d.filtershow.controller.SliderBrightness;
+import com.android.gallery3d.filtershow.controller.SliderHue;
+import com.android.gallery3d.filtershow.controller.SliderOpacity;
+import com.android.gallery3d.filtershow.controller.SliderSaturation;
import com.android.gallery3d.filtershow.controller.StyleChooser;
import com.android.gallery3d.filtershow.controller.TitledSlider;
import com.android.gallery3d.filtershow.filters.FilterBasicRepresentation;
@@ -56,6 +64,15 @@ public class ParametricEditor extends Editor {
static HashMap<String, Class> portraitMap = new HashMap<String, Class>();
static HashMap<String, Class> landscapeMap = new HashMap<String, Class>();
static {
+ portraitMap.put(ParameterSaturation.sParameterType, SliderSaturation.class);
+ landscapeMap.put(ParameterSaturation.sParameterType, SliderSaturation.class);
+ portraitMap.put(ParameterHue.sParameterType, SliderHue.class);
+ landscapeMap.put(ParameterHue.sParameterType, SliderHue.class);
+ portraitMap.put(ParameterOpacity.sParameterType, SliderOpacity.class);
+ landscapeMap.put(ParameterOpacity.sParameterType, SliderOpacity.class);
+ portraitMap.put(ParameterBrightness.sParameterType, SliderBrightness.class);
+ landscapeMap.put(ParameterBrightness.sParameterType, SliderBrightness.class);
+
portraitMap.put(ParameterInteger.sParameterType, BasicSlider.class);
landscapeMap.put(ParameterInteger.sParameterType, TitledSlider.class);
portraitMap.put(ParameterActionAndInt.sParameterType, ActionSlider.class);
diff --git a/src/com/android/gallery3d/filtershow/filters/FilterDrawRepresentation.java b/src/com/android/gallery3d/filtershow/filters/FilterDrawRepresentation.java
index 977dbeac5..e2abb3c4d 100644
--- a/src/com/android/gallery3d/filtershow/filters/FilterDrawRepresentation.java
+++ b/src/com/android/gallery3d/filtershow/filters/FilterDrawRepresentation.java
@@ -16,10 +16,18 @@
package com.android.gallery3d.filtershow.filters;
+import android.graphics.Color;
import android.graphics.Path;
import android.util.Log;
import com.android.gallery3d.R;
+import com.android.gallery3d.filtershow.controller.BasicParameterInt;
+import com.android.gallery3d.filtershow.controller.BasicParameterStyle;
+import com.android.gallery3d.filtershow.controller.Parameter;
+import com.android.gallery3d.filtershow.controller.ParameterBrightness;
+import com.android.gallery3d.filtershow.controller.ParameterHue;
+import com.android.gallery3d.filtershow.controller.ParameterOpacity;
+import com.android.gallery3d.filtershow.controller.ParameterSaturation;
import com.android.gallery3d.filtershow.editors.EditorDraw;
import java.util.Vector;
@@ -27,23 +35,79 @@ import java.util.Vector;
public class FilterDrawRepresentation extends FilterRepresentation {
private static final String LOGTAG = "FilterDrawRepresentation";
+ public static final int PARAM_SIZE = 0;
+ public static final int PARAM_HUE = 1;
+ public static final int PARAM_BRIGHTNESS = 2;
+ public static final int PARAM_SATURATION = 3;
+ public static final int PARAM_OPACITY = 4;
+ public static final int PARAM_STYLE = 5;
+ private BasicParameterInt mParamSize = new BasicParameterInt(PARAM_SIZE, 20, 2, 300);
+ private BasicParameterInt mParamHue = new ParameterHue(PARAM_HUE, 0);
+ private BasicParameterInt mParamBrightness = new ParameterBrightness(PARAM_BRIGHTNESS, 120);
+ private BasicParameterInt mParamSaturation = new ParameterSaturation(PARAM_SATURATION, 200);
+ private ParameterOpacity mParamOpacity = new ParameterOpacity(PARAM_OPACITY, 120);
+ private BasicParameterStyle mParamStyle = new BasicParameterStyle(PARAM_STYLE, 3);
+ int mParamMode;
+ Parameter mCurrentParam = mParamSize;
+
+ private Parameter[] mAllParam = {
+ mParamSize,
+ mParamHue,
+ mParamBrightness,
+ mParamSaturation,
+ mParamOpacity,
+ mParamStyle
+ };
+
+ public void setPramMode(int mode) {
+ mParamMode = mode;
+ mCurrentParam = mAllParam[mParamMode];
+ }
+
+ public Parameter getCurrentParam() {
+ return mAllParam[mParamMode];
+ }
+
+ public Parameter getParam(int type) {
+ return mAllParam[type];
+ }
+
public static class StrokeData implements Cloneable {
public byte mType;
public Path mPath;
public float mRadius;
public int mColor;
public int noPoints = 0;
+
@Override
public String toString() {
return "stroke(" + mType + ", path(" + (mPath) + "), " + mRadius + " , "
+ Integer.toHexString(mColor) + ")";
}
+
@Override
public StrokeData clone() throws CloneNotSupportedException {
return (StrokeData) super.clone();
}
}
+ public String getValueString() {
+
+ switch (mParamMode) {
+ case PARAM_SIZE:
+ case PARAM_HUE:
+ case PARAM_BRIGHTNESS:
+ case PARAM_SATURATION:
+ case PARAM_OPACITY:
+ int val = ((BasicParameterInt) mAllParam[mParamMode]).getValue();
+ return ((val > 0) ? " +" : " ") + val;
+ case PARAM_STYLE:
+ return "";
+
+ }
+ return "";
+ }
+
private Vector<StrokeData> mDrawing = new Vector<StrokeData>();
private StrokeData mCurrent; // used in the currently drawing style
@@ -62,7 +126,7 @@ public class FilterDrawRepresentation extends FilterRepresentation {
public String toString() {
return getName() + " : strokes=" + mDrawing.size()
+ ((mCurrent == null) ? " no current "
- : ("draw=" + mCurrent.mType + " " + mCurrent.noPoints));
+ : ("draw=" + mCurrent.mType + " " + mCurrent.noPoints));
}
public Vector<StrokeData> getDrawing() {
@@ -124,10 +188,10 @@ public class FilterDrawRepresentation extends FilterRepresentation {
FilterDrawRepresentation fdRep = (FilterDrawRepresentation) representation;
if (fdRep.mDrawing.size() != mDrawing.size())
return false;
- if (fdRep.mCurrent == null && mCurrent.mPath == null) {
+ if (fdRep.mCurrent == null && (mCurrent == null || mCurrent.mPath == null)) {
return true;
}
- if (fdRep.mCurrent != null && mCurrent.mPath != null) {
+ if (fdRep.mCurrent != null && mCurrent != null && mCurrent.mPath != null) {
if (fdRep.mCurrent.noPoints == mCurrent.noPoints) {
return true;
}
@@ -137,7 +201,19 @@ public class FilterDrawRepresentation extends FilterRepresentation {
return false;
}
- public void startNewSection(byte type, int color, float size, float x, float y) {
+ private int computeCurrentColor(){
+ float hue = 360 * mParamHue.getValue() / (float) mParamHue.getMaximum();
+ float sat = mParamSaturation.getValue() / (float) mParamSaturation.getMaximum();
+ float val = mParamBrightness.getValue() / (float) mParamBrightness.getMaximum();
+ int op = mParamOpacity.getValue();
+ float[] hsv = new float[]{hue, sat, val};
+ return Color.HSVToColor(op, hsv);
+ }
+
+ public void startNewSection(float x, float y) {
+ byte type = (byte) mParamStyle.getSelected();
+ int color = computeCurrentColor();
+ float size = mParamSize.getValue();
mCurrent = new StrokeData();
mCurrent.mColor = color;
mCurrent.mRadius = size;
diff --git a/src/com/android/gallery3d/filtershow/filters/ParametericFilterRepresentation.java b/src/com/android/gallery3d/filtershow/filters/ParametericFilterRepresentation.java
new file mode 100644
index 000000000..9c50257f3
--- /dev/null
+++ b/src/com/android/gallery3d/filtershow/filters/ParametericFilterRepresentation.java
@@ -0,0 +1,27 @@
+/*
+ * Copyright (C) 2013 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.filtershow.filters;
+
+/**
+ * Class to simplify creating representations that use Parametric controllers
+ */
+public class ParametericFilterRepresentation extends FilterRepresentation {
+ public ParametericFilterRepresentation(String name) {
+ super(name);
+ }
+}
diff --git a/src/com/android/gallery3d/filtershow/imageshow/ImageDraw.java b/src/com/android/gallery3d/filtershow/imageshow/ImageDraw.java
index 9722034e0..904973c7d 100644
--- a/src/com/android/gallery3d/filtershow/imageshow/ImageDraw.java
+++ b/src/com/android/gallery3d/filtershow/imageshow/ImageDraw.java
@@ -94,7 +94,7 @@ public class ImageDraw extends ImageShow {
mTmpPoint[0] = event.getX();
mTmpPoint[1] = event.getY();
mToOrig.mapPoints(mTmpPoint);
- mFRep.startNewSection(mType, mCurrentColor, mCurrentSize, mTmpPoint[0], mTmpPoint[1]);
+ mFRep.startNewSection( mTmpPoint[0], mTmpPoint[1]);
}
if (event.getAction() == MotionEvent.ACTION_MOVE) {