summaryrefslogtreecommitdiffstats
path: root/src/com/android
diff options
context:
space:
mode:
authorJohn Hoford <hoford@google.com>2013-08-22 14:38:19 -0700
committerJohn Hoford <hoford@google.com>2013-08-22 15:22:18 -0700
commit49798939f1bc58eaf5842bbc8bc5424284ab7930 (patch)
tree1c46853c45ce2ad7f5a930b29c779f4365ec4028 /src/com/android
parent73d0f42972c7c49a2589f2184f67e5a887007e7e (diff)
downloadandroid_packages_apps_Gallery2-49798939f1bc58eaf5842bbc8bc5424284ab7930.tar.gz
android_packages_apps_Gallery2-49798939f1bc58eaf5842bbc8bc5424284ab7930.tar.bz2
android_packages_apps_Gallery2-49798939f1bc58eaf5842bbc8bc5424284ab7930.zip
border UI editor
bug:9470514 Change-Id: I4d5cd91775c9b8742f847fd9a955f6f28e66cd38
Diffstat (limited to 'src/com/android')
-rw-r--r--src/com/android/gallery3d/filtershow/FilterShowActivity.java2
-rw-r--r--src/com/android/gallery3d/filtershow/controller/ParameterColor.java21
-rw-r--r--src/com/android/gallery3d/filtershow/editors/EditorColorBorder.java220
-rw-r--r--src/com/android/gallery3d/filtershow/editors/EditorColorBorderTabletUI.java253
-rw-r--r--src/com/android/gallery3d/filtershow/editors/EditorDraw.java10
-rw-r--r--src/com/android/gallery3d/filtershow/filters/BaseFiltersManager.java6
-rw-r--r--src/com/android/gallery3d/filtershow/filters/FilterColorBorderRepresentation.java79
-rw-r--r--src/com/android/gallery3d/filtershow/filters/FilterDrawRepresentation.java8
-rw-r--r--src/com/android/gallery3d/filtershow/filters/ImageFilterColorBorder.java (renamed from src/com/android/gallery3d/filtershow/filters/ImageFilterParametricBorder.java)51
-rw-r--r--src/com/android/gallery3d/filtershow/pipeline/FilterEnvironment.java4
10 files changed, 596 insertions, 58 deletions
diff --git a/src/com/android/gallery3d/filtershow/FilterShowActivity.java b/src/com/android/gallery3d/filtershow/FilterShowActivity.java
index b18eeb1bf..c3a5e15ff 100644
--- a/src/com/android/gallery3d/filtershow/FilterShowActivity.java
+++ b/src/com/android/gallery3d/filtershow/FilterShowActivity.java
@@ -73,6 +73,7 @@ import com.android.gallery3d.filtershow.data.UserPresetsManager;
import com.android.gallery3d.filtershow.editors.BasicEditor;
import com.android.gallery3d.filtershow.editors.Editor;
import com.android.gallery3d.filtershow.editors.EditorChanSat;
+import com.android.gallery3d.filtershow.editors.EditorColorBorder;
import com.android.gallery3d.filtershow.editors.EditorCrop;
import com.android.gallery3d.filtershow.editors.EditorDraw;
import com.android.gallery3d.filtershow.editors.EditorGrad;
@@ -496,6 +497,7 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
mEditorPlaceHolder.addEditor(new EditorChanSat());
mEditorPlaceHolder.addEditor(new EditorGrad());
mEditorPlaceHolder.addEditor(new EditorDraw());
+ mEditorPlaceHolder.addEditor(new EditorColorBorder());
mEditorPlaceHolder.addEditor(new BasicEditor());
mEditorPlaceHolder.addEditor(new ImageOnlyEditor());
mEditorPlaceHolder.addEditor(new EditorTinyPlanet());
diff --git a/src/com/android/gallery3d/filtershow/controller/ParameterColor.java b/src/com/android/gallery3d/filtershow/controller/ParameterColor.java
index 2608df6ce..4f8248fb0 100644
--- a/src/com/android/gallery3d/filtershow/controller/ParameterColor.java
+++ b/src/com/android/gallery3d/filtershow/controller/ParameterColor.java
@@ -16,6 +16,8 @@
package com.android.gallery3d.filtershow.controller;
+import android.graphics.Color;
+
public class ParameterColor implements Parameter {
public static String sParameterType = "ParameterColor";
protected Control mControl;
@@ -23,10 +25,12 @@ public class ParameterColor implements Parameter {
float[] mHSVO = new float[4];
String mParameterName;
int mValue;
- public final int ID;
+ public final int ID;
- public ParameterColor(int id) {
+ public ParameterColor(int id, int defaultColor) {
ID = id;
+ Color.colorToHSV(defaultColor, mHSVO);
+ mHSVO[3] = ((defaultColor >> 24) & 0xFF) / (float) 255;
}
@Override
@@ -36,24 +40,23 @@ public class ParameterColor implements Parameter {
public void setColor(float[] hsvo) {
mHSVO = hsvo;
+ mValue = Color.HSVToColor((int) (hsvo[3] * 255), mHSVO);
}
public float[] getColor() {
- mHSVO[3] = getValue() ;
return mHSVO;
}
-
public void copyFrom(Parameter src) {
- if (!(src instanceof BasicParameterInt)) {
+ if (!(src instanceof ParameterColor)) {
throw new IllegalArgumentException(src.getClass().getName());
}
- BasicParameterInt p = (BasicParameterInt) src;
+ ParameterColor p = (ParameterColor) src;
mValue = p.mValue;
+ System.arraycopy(p.mHSVO, 0, mHSVO, 0, 4);
}
-
@Override
public String getParameterName() {
return mParameterName;
@@ -61,7 +64,7 @@ public class ParameterColor implements Parameter {
@Override
public String getValueString() {
- return "("+Integer.toHexString(mValue)+")";
+ return "(" + Integer.toHexString(mValue) + ")";
}
@Override
@@ -75,6 +78,8 @@ public class ParameterColor implements Parameter {
public void setValue(int value) {
mValue = value;
+ Color.colorToHSV(mValue, mHSVO);
+ mHSVO[3] = ((mValue >> 24) & 0xFF) / (float) 255;
}
@Override
diff --git a/src/com/android/gallery3d/filtershow/editors/EditorColorBorder.java b/src/com/android/gallery3d/filtershow/editors/EditorColorBorder.java
new file mode 100644
index 000000000..2561dcd98
--- /dev/null
+++ b/src/com/android/gallery3d/filtershow/editors/EditorColorBorder.java
@@ -0,0 +1,220 @@
+/*
+ * 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.editors;
+
+import android.content.Context;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.graphics.Color;
+import android.view.LayoutInflater;
+import android.view.MenuItem;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.view.ViewGroup;
+import android.widget.Button;
+import android.widget.FrameLayout;
+import android.widget.LinearLayout;
+import android.widget.PopupMenu;
+import android.widget.SeekBar;
+
+import com.android.gallery3d.R;
+import com.android.gallery3d.filtershow.controller.BitmapCaller;
+import com.android.gallery3d.filtershow.controller.ColorChooser;
+import com.android.gallery3d.filtershow.controller.FilterView;
+import com.android.gallery3d.filtershow.filters.FilterColorBorderRepresentation;
+import com.android.gallery3d.filtershow.filters.FilterRepresentation;
+import com.android.gallery3d.filtershow.filters.ImageFilterColorBorder;
+import com.android.gallery3d.filtershow.imageshow.ImageShow;
+
+public class EditorColorBorder extends ParametricEditor implements FilterView {
+ private static final String LOGTAG = "EditorColorBorder";
+ public static final int ID = R.id.editorColorBorder;
+
+ int[] brushIcons = {
+ R.drawable.brush_flat,
+ R.drawable.brush_round,
+ R.drawable.brush_gauss,
+ R.drawable.brush_marker,
+ R.drawable.brush_spatter
+ };
+
+ int[] mBasColors = {
+ FilterColorBorderRepresentation.DEFAULT_MENU_COLOR1,
+ FilterColorBorderRepresentation.DEFAULT_MENU_COLOR2,
+ FilterColorBorderRepresentation.DEFAULT_MENU_COLOR3,
+ FilterColorBorderRepresentation.DEFAULT_MENU_COLOR4,
+ FilterColorBorderRepresentation.DEFAULT_MENU_COLOR5,
+ };
+ private EditorColorBorderTabletUI mTabletUI;
+ private String mParameterString;
+ private int mSelectedColorButton;
+
+ public EditorColorBorder() {
+ super(ID);
+ }
+
+ @Override
+ public String calculateUserMessage(Context context, String effectName, Object parameterValue) {
+ FilterColorBorderRepresentation rep = getColorBorderRep();
+ if (rep == null) {
+ return "";
+ }
+ if (mParameterString == null) {
+ mParameterString = "";
+ }
+ String paramString;
+ String val = rep.getValueString();
+ return mParameterString + val;
+ }
+
+ @Override
+ public void createEditor(Context context, FrameLayout frameLayout) {
+ mView = mImageShow = new ImageShow(context);
+ super.createEditor(context, frameLayout);
+ }
+
+ @Override
+ public void reflectCurrentFilter() {
+ super.reflectCurrentFilter();
+ FilterRepresentation rep = getLocalRepresentation();
+ if (rep != null && getLocalRepresentation() instanceof FilterColorBorderRepresentation) {
+ FilterColorBorderRepresentation cbRep =
+ (FilterColorBorderRepresentation) getLocalRepresentation();
+ if (!ParametricEditor.useCompact(mContext)) {
+ if (mTabletUI != null) {
+ mTabletUI.setColorBorderRepresentation(cbRep);
+ }
+ return;
+ }
+ cbRep.setPramMode(FilterColorBorderRepresentation.PARAM_COLOR);
+ mParameterString = mContext.getString(R.string.color_border_color);
+ control(cbRep.getCurrentParam(), mEditControl);
+ }
+ }
+
+ @Override
+ public void openUtilityPanel(final LinearLayout accessoryViewList) {
+ Button view = (Button) accessoryViewList.findViewById(R.id.applyEffect);
+ view.setText(mContext.getString(R.string.color_border_size));
+ view.setOnClickListener(new OnClickListener() {
+
+ @Override
+ public void onClick(View arg0) {
+ showPopupMenu(accessoryViewList);
+ }
+ });
+ }
+
+ @Override
+ public boolean showsSeekBar() {
+ return false;
+ }
+
+ private void showPopupMenu(LinearLayout accessoryViewList) {
+ final Button button = (Button) accessoryViewList.findViewById(
+ R.id.applyEffect);
+ if (button == null) {
+ return;
+ }
+ final PopupMenu popupMenu = new PopupMenu(mImageShow.getActivity(), button);
+ popupMenu.getMenuInflater().inflate(R.menu.filtershow_menu_color_border,
+ popupMenu.getMenu());
+ popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
+
+ @Override
+ public boolean onMenuItemClick(MenuItem item) {
+ selectMenuItem(item);
+ return true;
+ }
+ });
+ popupMenu.show();
+ }
+
+ protected void selectMenuItem(MenuItem item) {
+ ImageFilterColorBorder filter = (ImageFilterColorBorder) mImageShow.getCurrentFilter();
+ FilterColorBorderRepresentation rep = getColorBorderRep();
+ if (rep == null) {
+ return;
+ }
+ switch (item.getItemId()) {
+ case R.id.color_border_menu_clear:
+ clearFrame();
+ break;
+ case R.id.color_border_menu_size:
+ rep.setPramMode(FilterColorBorderRepresentation.PARAM_SIZE);
+ break;
+ case R.id.color_border_menu_corner_size:
+ rep.setPramMode(FilterColorBorderRepresentation.PARAM_RADIUS);
+ break;
+ case R.id.color_border_menu_color:
+ rep.setPramMode(FilterColorBorderRepresentation.PARAM_COLOR);
+ break;
+ }
+ if (item.getItemId() != R.id.color_border_menu_clear) {
+ mParameterString = item.getTitle().toString();
+ }
+ if (mControl instanceof ColorChooser) {
+ ColorChooser c = (ColorChooser) mControl;
+ mBasColors = c.getColorSet();
+ }
+ control(rep.getCurrentParam(), mEditControl);
+ if (mControl instanceof ColorChooser) {
+ ColorChooser c = (ColorChooser) mControl;
+ c.setColorSet(mBasColors);
+ }
+ mControl.updateUI();
+ mView.invalidate();
+ }
+
+ public void clearFrame() {
+ commitLocalRepresentation();
+ }
+
+ @Override
+ public void setUtilityPanelUI(View actionButton, View editControl) {
+ if (ParametricEditor.useCompact(mContext)) {
+ super.setUtilityPanelUI(actionButton, editControl);
+ return;
+ }
+ mSeekBar = (SeekBar) editControl.findViewById(R.id.primarySeekBar);
+ if (mSeekBar != null) {
+ mSeekBar.setVisibility(View.GONE);
+ }
+
+ mTabletUI = new EditorColorBorderTabletUI(this, mContext, editControl);
+
+ }
+
+ FilterColorBorderRepresentation getColorBorderRep() {
+ FilterRepresentation rep = getLocalRepresentation();
+ if (rep instanceof FilterColorBorderRepresentation) {
+ return (FilterColorBorderRepresentation) rep;
+ }
+ return null;
+ }
+
+ @Override
+ public void computeIcon(int index, BitmapCaller caller) {
+ Bitmap bitmap = BitmapFactory.decodeResource(mContext.getResources(), brushIcons[index]);
+ caller.available(bitmap);
+ }
+
+ public int getBrushIcon(int type) {
+ return brushIcons[type];
+ }
+
+}
diff --git a/src/com/android/gallery3d/filtershow/editors/EditorColorBorderTabletUI.java b/src/com/android/gallery3d/filtershow/editors/EditorColorBorderTabletUI.java
new file mode 100644
index 000000000..04aee2751
--- /dev/null
+++ b/src/com/android/gallery3d/filtershow/editors/EditorColorBorderTabletUI.java
@@ -0,0 +1,253 @@
+/*
+ * 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.editors;
+
+import android.app.ActionBar;
+import android.content.Context;
+import android.content.res.Resources;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.graphics.Color;
+import android.graphics.drawable.GradientDrawable;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.Button;
+import android.widget.ImageButton;
+import android.widget.ImageView;
+import android.widget.LinearLayout;
+import android.widget.SeekBar;
+import android.widget.TextView;
+
+import com.android.gallery3d.R;
+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.colorpicker.ColorSVRectView;
+import com.android.gallery3d.filtershow.controller.BasicParameterInt;
+import com.android.gallery3d.filtershow.controller.BasicParameterStyle;
+import com.android.gallery3d.filtershow.controller.ParameterColor;
+import com.android.gallery3d.filtershow.filters.FilterColorBorderRepresentation;
+
+import java.util.Arrays;
+
+public class EditorColorBorderTabletUI {
+ private EditorColorBorder mEditorDraw;
+ private int[] mBrushIcons;
+ private static int sIconDim = 120;
+ private int mSelectedColorButton;
+ private FilterColorBorderRepresentation mRep;
+ private Button[] mColorButton;
+ private ImageButton[] mStyleButton;
+ private ColorHueView mHueView;
+ private ColorSVRectView mSatValView;
+ private ColorOpacityView mOpacityView;
+
+ private int[] mBasColors;
+ private int mSelected;
+ private int mTransparent;
+ private SeekBar mCBSizeSeekBar;
+ private SeekBar mCBCornerSizeSeekBar;
+ TextView mCBCornerSizeValue;
+ TextView mCBSizeValue;
+
+ private int[] ids = {
+ R.id.draw_color_button01,
+ R.id.draw_color_button02,
+ R.id.draw_color_button03,
+ R.id.draw_color_button04,
+ R.id.draw_color_button05,
+ };
+
+ public void setColorBorderRepresentation(FilterColorBorderRepresentation rep) {
+ mRep = rep;
+ BasicParameterInt size;
+ size = (BasicParameterInt) mRep.getParam(FilterColorBorderRepresentation.PARAM_SIZE);
+ mCBSizeSeekBar.setMax(size.getMaximum() - size.getMinimum());
+ mCBSizeSeekBar.setProgress(size.getValue());
+
+ BasicParameterInt radius;
+ radius = (BasicParameterInt) mRep.getParam(FilterColorBorderRepresentation.PARAM_RADIUS);
+ mCBCornerSizeSeekBar.setMax(radius.getMaximum() - radius.getMinimum());
+ mCBCornerSizeSeekBar.setProgress(radius.getValue());
+
+ ParameterColor color;
+ color = (ParameterColor) mRep.getParam(FilterColorBorderRepresentation.PARAM_COLOR);
+ color.setValue(mBasColors[mSelectedColorButton]);
+ }
+
+ public EditorColorBorderTabletUI(EditorColorBorder editorDraw, Context context, View base) {
+ mEditorDraw = editorDraw;
+ mBasColors = editorDraw.mBasColors;
+ mBrushIcons = editorDraw.brushIcons;
+ LayoutInflater inflater =
+ (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+ LinearLayout lp = (LinearLayout) inflater.inflate(
+ R.layout.filtershow_color_border_ui, (ViewGroup) base, true);
+
+ Resources res = context.getResources();
+ sIconDim = res.getDimensionPixelSize(R.dimen.draw_style_icon_dim);
+ LinearLayout buttonContainer = (LinearLayout) lp.findViewById(R.id.listStyles);
+
+ mCBCornerSizeSeekBar = (SeekBar) lp.findViewById(R.id.colorBorderCornerSizeSeekBar);
+ mCBCornerSizeValue = (TextView) lp.findViewById(R.id.colorBorderCornerValue);
+ mCBSizeSeekBar = (SeekBar) lp.findViewById(R.id.colorBorderSizeSeekBar);
+ mCBSizeValue = (TextView) lp.findViewById(R.id.colorBorderSizeValue);
+ setupClearButton(lp);
+ setupCBSizeSeekBar(lp);
+ setupCBCornerSizeSeekBar(lp);
+ setupColor(lp, res);
+ }
+
+ private void setupClearButton(LinearLayout lp) {
+ Button clearButton = (Button) lp.findViewById(R.id.clearButton);
+ clearButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ mEditorDraw.clearFrame();
+ }
+ });
+ }
+
+ private void setupCBSizeSeekBar(LinearLayout lp) {
+ mCBSizeSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
+ @Override
+ public void onStopTrackingTouch(SeekBar seekBar) {
+ }
+ @Override
+ public void onStartTrackingTouch(SeekBar seekBar) {
+ }
+ @Override
+ public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
+ int type = FilterColorBorderRepresentation.PARAM_SIZE;
+ BasicParameterInt size = (BasicParameterInt) mRep.getParam(type);
+ size.setValue(progress + size.getMinimum());
+ mCBSizeValue.setText(Integer.toString(size.getValue()));
+ mEditorDraw.commitLocalRepresentation();
+ }
+ });
+
+ }
+
+ private void setupCBCornerSizeSeekBar(LinearLayout lp) {
+ mCBCornerSizeSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
+ @Override
+ public void onStopTrackingTouch(SeekBar seekBar) {
+ }
+ @Override
+ public void onStartTrackingTouch(SeekBar seekBar) {
+ }
+ @Override
+ public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
+ int type = FilterColorBorderRepresentation.PARAM_RADIUS;
+ BasicParameterInt size = (BasicParameterInt) mRep.getParam(type);
+ size.setValue(progress + size.getMinimum());
+ mCBCornerSizeValue.setText(size.getValue() + "");
+ mEditorDraw.commitLocalRepresentation();
+ }
+ });
+
+ }
+
+ private void setupColor(LinearLayout lp, Resources res) {
+ final LinearLayout ctls = (LinearLayout) lp.findViewById(R.id.controls);
+ final LinearLayout pick = (LinearLayout) lp.findViewById(R.id.colorPicker);
+ Button b = (Button) lp.findViewById(R.id.draw_color_popupbutton);
+ b.setOnClickListener(new View.OnClickListener() {
+
+ @Override
+ public void onClick(View view) {
+ boolean b = ctls.getVisibility() == View.VISIBLE;
+ ctls.setVisibility((b) ? View.GONE : View.VISIBLE);
+ pick.setVisibility((!b) ? View.GONE : View.VISIBLE);
+ }
+ }
+ );
+
+ mTransparent = res.getColor(R.color.color_chooser_unslected_border);
+ mSelected = res.getColor(R.color.color_chooser_slected_border);
+
+ mColorButton = new Button[ids.length];
+ for (int i = 0; i < ids.length; i++) {
+ mColorButton[i] = (Button) lp.findViewById(ids[i]);
+ float[] hsvo = new float[4];
+ Color.colorToHSV(mBasColors[i], hsvo);
+ hsvo[3] = (0xFF & (mBasColors[i] >> 24)) / (float) 255;
+ mColorButton[i].setTag(hsvo);
+ GradientDrawable sd = ((GradientDrawable) mColorButton[i].getBackground());
+ sd.setColor(mBasColors[i]);
+ sd.setStroke(3, (0 == i) ? mSelected : mTransparent);
+ final int buttonNo = i;
+ mColorButton[i].setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View arg0) {
+ mSelectedColorButton = buttonNo;
+ float[] hsvo = Arrays.copyOf((float[]) mColorButton[buttonNo].getTag(), 4);
+ resetBorders();
+ if (mRep == null) {
+ return;
+ }
+ int type = FilterColorBorderRepresentation.PARAM_COLOR;
+ ParameterColor pram = (ParameterColor) mRep.getParam(type);
+ pram.setValue(mBasColors[mSelectedColorButton]);
+ mEditorDraw.commitLocalRepresentation();
+ mHueView.setColor(hsvo);
+ mSatValView.setColor(hsvo);
+ mOpacityView.setColor(hsvo);
+ }
+ });
+ }
+ mHueView = (ColorHueView) lp.findViewById(R.id.ColorHueView);
+ mSatValView = (ColorSVRectView) lp.findViewById(R.id.colorRectView);
+ mOpacityView = (ColorOpacityView) lp.findViewById(R.id.colorOpacityView);
+ mHueView.addColorListener(mSatValView);
+ mSatValView.addColorListener(mHueView);
+ mHueView.addColorListener(mOpacityView);
+ mSatValView.addColorListener(mOpacityView);
+ mOpacityView.addColorListener(mSatValView);
+ mOpacityView.addColorListener(mHueView);
+ ColorListener colorListener = new ColorListener() {
+ @Override
+ public void setColor(float[] hsvo) {
+ int color = Color.HSVToColor((int) (hsvo[3] * 255), hsvo);
+ Button b = mColorButton[mSelectedColorButton];
+ float[] f = (float[]) b.getTag();
+ System.arraycopy(hsvo, 0, f, 0, 4);
+ mBasColors[mSelectedColorButton] = color;
+ GradientDrawable sd = ((GradientDrawable) b.getBackground());
+ sd.setColor(color);
+ resetBorders();
+ ParameterColor pram;
+ pram = (ParameterColor) mRep.getParam(FilterColorBorderRepresentation.PARAM_COLOR);
+ pram.setValue(color);
+ mEditorDraw.commitLocalRepresentation();
+ }
+ };
+ mHueView.addColorListener(colorListener);
+ mSatValView.addColorListener(colorListener);
+ mOpacityView.addColorListener(colorListener);
+ }
+
+ private void resetBorders() {
+ for (int i = 0; i < ids.length; i++) {
+ final Button button = mColorButton[i];
+ GradientDrawable sd = ((GradientDrawable) button.getBackground());
+ sd.setColor(mBasColors[i]);
+ sd.setStroke(3, (mSelectedColorButton == i) ? mSelected : mTransparent);
+ }
+ }
+}
diff --git a/src/com/android/gallery3d/filtershow/editors/EditorDraw.java b/src/com/android/gallery3d/filtershow/editors/EditorDraw.java
index 97c889cf0..48868215b 100644
--- a/src/com/android/gallery3d/filtershow/editors/EditorDraw.java
+++ b/src/com/android/gallery3d/filtershow/editors/EditorDraw.java
@@ -67,11 +67,11 @@ public class EditorDraw extends ParametricEditor implements FilterView {
};
int[] mBasColors = {
- Color.RED & 0x80FFFFFF,
- Color.GREEN & 0x80FFFFFF,
- Color.BLUE & 0x80FFFFFF,
- Color.BLACK & 0x80FFFFFF,
- Color.WHITE & 0x80FFFFFF
+ FilterDrawRepresentation.DEFAULT_MENU_COLOR1,
+ FilterDrawRepresentation.DEFAULT_MENU_COLOR2,
+ FilterDrawRepresentation.DEFAULT_MENU_COLOR3,
+ FilterDrawRepresentation.DEFAULT_MENU_COLOR4,
+ FilterDrawRepresentation.DEFAULT_MENU_COLOR5,
};
private EditorDrawTabletUI mTabletUI;
private String mParameterString;
diff --git a/src/com/android/gallery3d/filtershow/filters/BaseFiltersManager.java b/src/com/android/gallery3d/filtershow/filters/BaseFiltersManager.java
index 282254bba..7a5ec56f1 100644
--- a/src/com/android/gallery3d/filtershow/filters/BaseFiltersManager.java
+++ b/src/com/android/gallery3d/filtershow/filters/BaseFiltersManager.java
@@ -20,10 +20,6 @@ import android.content.res.Resources;
import android.util.Log;
import com.android.gallery3d.R;
-import com.android.gallery3d.filtershow.editors.EditorCrop;
-import com.android.gallery3d.filtershow.editors.EditorMirror;
-import com.android.gallery3d.filtershow.editors.EditorRotate;
-import com.android.gallery3d.filtershow.editors.EditorStraighten;
import com.android.gallery3d.filtershow.pipeline.ImagePreset;
import java.util.ArrayList;
@@ -141,7 +137,7 @@ public abstract class BaseFiltersManager implements FiltersManagerInterface {
filters.add(ImageFilterKMeans.class);
filters.add(ImageFilterFx.class);
filters.add(ImageFilterBorder.class);
- filters.add(ImageFilterParametricBorder.class);
+ filters.add(ImageFilterColorBorder.class);
}
public ArrayList<FilterRepresentation> getLooks() {
diff --git a/src/com/android/gallery3d/filtershow/filters/FilterColorBorderRepresentation.java b/src/com/android/gallery3d/filtershow/filters/FilterColorBorderRepresentation.java
index 94eb20631..929d7cc58 100644
--- a/src/com/android/gallery3d/filtershow/filters/FilterColorBorderRepresentation.java
+++ b/src/com/android/gallery3d/filtershow/filters/FilterColorBorderRepresentation.java
@@ -16,23 +16,50 @@
package com.android.gallery3d.filtershow.filters;
+import android.graphics.Color;
+
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.ParameterColor;
+import com.android.gallery3d.filtershow.editors.EditorColorBorder;
import com.android.gallery3d.filtershow.editors.ImageOnlyEditor;
public class FilterColorBorderRepresentation extends FilterRepresentation {
- private int mColor;
- private int mBorderSize;
- private int mBorderRadius;
+ private static final String LOGTAG = "FilterColorBorderRepresentation";
+ private static final String SERIALIZATION_NAME = "COLORBORDER";
+
+ public static final int PARAM_SIZE = 0;
+ public static final int PARAM_RADIUS = 1;
+ public static final int PARAM_COLOR = 2;
+ public static int DEFAULT_MENU_COLOR1 = Color.WHITE;
+ public static int DEFAULT_MENU_COLOR2 = Color.BLACK;
+ public static int DEFAULT_MENU_COLOR3 = Color.GRAY;
+ public static int DEFAULT_MENU_COLOR4 = 0xFFFFCCAA;
+ public static int DEFAULT_MENU_COLOR5 = 0xFFAAAAAA;
+ private BasicParameterInt mParamSize = new BasicParameterInt(PARAM_SIZE, 20, 2, 300);
+ private BasicParameterInt mParamRadius = new BasicParameterInt(PARAM_RADIUS, 4, 2, 300);
+ private ParameterColor mParamColor = new ParameterColor(PARAM_COLOR, DEFAULT_MENU_COLOR1);
+
+ private Parameter[] mAllParam = {
+ mParamSize,
+ mParamRadius,
+ mParamColor
+ };
+ private int mPramMode;
public FilterColorBorderRepresentation(int color, int size, int radius) {
super("ColorBorder");
- mColor = color;
- mBorderSize = size;
- mBorderRadius = radius;
+ setSerializationName(SERIALIZATION_NAME);
setFilterType(FilterRepresentation.TYPE_BORDER);
setTextId(R.string.borders);
- setEditorId(ImageOnlyEditor.ID);
+ setEditorId(EditorColorBorder.ID);
setShowParameterValue(false);
+ setFilterClass(ImageFilterColorBorder.class);
+ mParamColor.setValue(color);
+ mParamSize.setValue(size);
+ mParamColor.setValue(radius);
}
public String toString() {
@@ -41,7 +68,8 @@ public class FilterColorBorderRepresentation extends FilterRepresentation {
@Override
public FilterRepresentation copy() {
- FilterColorBorderRepresentation representation = new FilterColorBorderRepresentation(0,0,0);
+ FilterColorBorderRepresentation representation =
+ new FilterColorBorderRepresentation(0, 0, 0);
copyAllParameters(representation);
return representation;
}
@@ -69,9 +97,10 @@ public class FilterColorBorderRepresentation extends FilterRepresentation {
}
if (representation instanceof FilterColorBorderRepresentation) {
FilterColorBorderRepresentation border = (FilterColorBorderRepresentation) representation;
- if (border.mColor == mColor
- && border.mBorderSize == mBorderSize
- && border.mBorderRadius == mBorderRadius) {
+ if (border.mParamColor.getValue() == mParamColor.getValue()
+ && border.mParamRadius.getValue() == mParamRadius.getValue()
+ && border.mParamSize.getValue() == mParamSize.getValue()) {
+
return true;
}
}
@@ -82,32 +111,48 @@ public class FilterColorBorderRepresentation extends FilterRepresentation {
return true;
}
+ public Parameter getParam(int mode) {
+ return mAllParam[mode];
+ }
+
@Override
public int getTextId() {
return R.string.borders;
}
public int getColor() {
- return mColor;
+ return mParamColor.getValue();
}
public void setColor(int color) {
- mColor = color;
+ mParamColor.setValue(color);
}
public int getBorderSize() {
- return mBorderSize;
+ return mParamSize.getValue();
}
public void setBorderSize(int borderSize) {
- mBorderSize = borderSize;
+ mParamSize.setValue(borderSize);
}
public int getBorderRadius() {
- return mBorderRadius;
+ return mParamRadius.getValue();
}
public void setBorderRadius(int borderRadius) {
- mBorderRadius = borderRadius;
+ mParamRadius.setValue(borderRadius);
+ }
+
+ public void setPramMode(int pramMode) {
+ this.mPramMode = pramMode;
+ }
+
+ public Parameter getCurrentParam() {
+ return mAllParam[mPramMode];
+ }
+
+ public String getValueString() {
+ return "";
}
}
diff --git a/src/com/android/gallery3d/filtershow/filters/FilterDrawRepresentation.java b/src/com/android/gallery3d/filtershow/filters/FilterDrawRepresentation.java
index f05910b63..d4b4e87fa 100644
--- a/src/com/android/gallery3d/filtershow/filters/FilterDrawRepresentation.java
+++ b/src/com/android/gallery3d/filtershow/filters/FilterDrawRepresentation.java
@@ -43,12 +43,16 @@ public class FilterDrawRepresentation extends FilterRepresentation {
private static final String LOGTAG = "FilterDrawRepresentation";
public static final int PARAM_SIZE = 0;
-
public static final int PARAM_STYLE = 1;
public static final int PARAM_COLOR = 2;
private BasicParameterInt mParamSize = new BasicParameterInt(PARAM_SIZE, 20, 2, 300);
private BasicParameterStyle mParamStyle = new BasicParameterStyle(PARAM_STYLE, 5);
- ParameterColor mParamColor = new ParameterColor(PARAM_COLOR);
+ public static int DEFAULT_MENU_COLOR1 = Color.RED & 0x80FFFFFF;
+ public static int DEFAULT_MENU_COLOR2 = Color.GREEN & 0x80FFFFFF;
+ public static int DEFAULT_MENU_COLOR3 = Color.BLUE & 0x80FFFFFF;
+ public static int DEFAULT_MENU_COLOR4 = Color.BLACK & 0x80FFFFFF;
+ public static int DEFAULT_MENU_COLOR5 = Color.WHITE & 0x80FFFFFF;
+ ParameterColor mParamColor = new ParameterColor(PARAM_COLOR,DEFAULT_MENU_COLOR1);
int mParamMode;
Parameter mCurrentParam = mParamSize;
private static final String SERIAL_COLOR = "color";
diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterParametricBorder.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterColorBorder.java
index 25e5d1476..26f74a2a3 100644
--- a/src/com/android/gallery3d/filtershow/filters/ImageFilterParametricBorder.java
+++ b/src/com/android/gallery3d/filtershow/filters/ImageFilterColorBorder.java
@@ -18,19 +18,32 @@ package com.android.gallery3d.filtershow.filters;
import android.graphics.Bitmap;
import android.graphics.Canvas;
+import android.graphics.Color;
+import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.RectF;
-public class ImageFilterParametricBorder extends ImageFilter {
+import com.android.gallery3d.app.Log;
+
+public class ImageFilterColorBorder extends ImageFilter {
+ private static final String LOGTAG = "ImageFilterColorBorder";
private FilterColorBorderRepresentation mParameters = null;
+ Paint mPaint = new Paint();
+ RectF mRect = new RectF();
- public ImageFilterParametricBorder() {
+ public ImageFilterColorBorder() {
mName = "Border";
+ mPaint.setStyle(Paint.Style.STROKE);
+ }
+
+ public FilterRepresentation getDefaultRepresentation() {
+ return new FilterColorBorderRepresentation(Color.WHITE, 4, 4);
}
public void useRepresentation(FilterRepresentation representation) {
- FilterColorBorderRepresentation parameters = (FilterColorBorderRepresentation) representation;
+ FilterColorBorderRepresentation parameters =
+ (FilterColorBorderRepresentation) representation;
mParameters = parameters;
}
@@ -42,28 +55,24 @@ public class ImageFilterParametricBorder extends ImageFilter {
if (getParameters() == null) {
return;
}
- Path border = new Path();
- border.moveTo(0, 0);
- float bs = getParameters().getBorderSize() / 100.0f * w;
- float r = getParameters().getBorderRadius() / 100.0f * w;
- border.lineTo(0, h);
- border.lineTo(w, h);
- border.lineTo(w, 0);
- border.lineTo(0, 0);
- border.addRoundRect(new RectF(bs, bs, w - bs, h - bs),
- r, r, Path.Direction.CW);
-
- Paint paint = new Paint();
- paint.setAntiAlias(true);
- paint.setColor(getParameters().getColor());
- canvas.drawPath(border, paint);
+ mRect.set(0, 0, w, h);
+ mPaint.setColor(getParameters().getColor());
+ float size = getParameters().getBorderSize();
+ float radius = getParameters().getBorderRadius();
+ Matrix m = getOriginalToScreenMatrix(w, h);
+ radius = m.mapRadius(radius);
+ size = m.mapRadius(size);
+ mPaint.setStrokeWidth(size);
+ canvas.drawRoundRect(mRect, radius, radius, mPaint);
+ mRect.set(0 - radius, -radius, w + radius, h + radius);
+ canvas.drawRoundRect(mRect, 0, 0, mPaint);
}
@Override
public Bitmap apply(Bitmap bitmap, float scaleFactor, int quality) {
- Canvas canvas = new Canvas(bitmap);
- applyHelper(canvas, bitmap.getWidth(), bitmap.getHeight());
- return bitmap;
+ Canvas canvas = new Canvas(bitmap);
+ applyHelper(canvas, bitmap.getWidth(), bitmap.getHeight());
+ return bitmap;
}
}
diff --git a/src/com/android/gallery3d/filtershow/pipeline/FilterEnvironment.java b/src/com/android/gallery3d/filtershow/pipeline/FilterEnvironment.java
index 2757aff11..b34537668 100644
--- a/src/com/android/gallery3d/filtershow/pipeline/FilterEnvironment.java
+++ b/src/com/android/gallery3d/filtershow/pipeline/FilterEnvironment.java
@@ -20,6 +20,7 @@ import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.support.v8.renderscript.Allocation;
+import com.android.gallery3d.app.Log;
import com.android.gallery3d.filtershow.cache.BitmapCache;
import com.android.gallery3d.filtershow.filters.FilterRepresentation;
import com.android.gallery3d.filtershow.filters.FilterUserPresetRepresentation;
@@ -126,6 +127,9 @@ public class FilterEnvironment {
return bitmap;
}
ImageFilter filter = mFiltersManager.getFilterForRepresentation(representation);
+ if (filter == null){
+ Log.e(LOGTAG,"No ImageFilter for "+representation.getSerializationName());
+ }
filter.useRepresentation(representation);
filter.setEnvironment(this);
Bitmap ret = filter.apply(bitmap, mScaleFactor, mQuality);