OSDN Git Service

am 89cea037: am 49798939: border UI editor
authorJohn Hoford <hoford@google.com>
Thu, 22 Aug 2013 23:09:45 +0000 (16:09 -0700)
committerAndroid Git Automerger <android-git-automerger@android.com>
Thu, 22 Aug 2013 23:09:45 +0000 (16:09 -0700)
* commit '89cea0376a0d012c6c7f5cf7a0cd6b0e739c9a2a':
  border UI editor

15 files changed:
res/layout-land/filtershow_color_border_ui.xml [new file with mode: 0644]
res/menu/filtershow_menu_color_border.xml [new file with mode: 0644]
res/values/filtershow_ids.xml
res/values/filtershow_strings.xml
src/com/android/gallery3d/filtershow/FilterShowActivity.java
src/com/android/gallery3d/filtershow/controller/ParameterColor.java
src/com/android/gallery3d/filtershow/editors/EditorColorBorder.java [new file with mode: 0644]
src/com/android/gallery3d/filtershow/editors/EditorColorBorderTabletUI.java [new file with mode: 0644]
src/com/android/gallery3d/filtershow/editors/EditorDraw.java
src/com/android/gallery3d/filtershow/filters/BaseFiltersManager.java
src/com/android/gallery3d/filtershow/filters/FilterColorBorderRepresentation.java
src/com/android/gallery3d/filtershow/filters/FilterDrawRepresentation.java
src/com/android/gallery3d/filtershow/filters/ImageFilterColorBorder.java [moved from src/com/android/gallery3d/filtershow/filters/ImageFilterParametricBorder.java with 51% similarity]
src/com/android/gallery3d/filtershow/pipeline/FilterEnvironment.java
src_pd/com/android/gallery3d/filtershow/editors/EditorManager.java

diff --git a/res/layout-land/filtershow_color_border_ui.xml b/res/layout-land/filtershow_color_border_ui.xml
new file mode 100644 (file)
index 0000000..f16ea2c
--- /dev/null
@@ -0,0 +1,230 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+     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.
+-->
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+              android:id="@+id/top"
+              android:layout_width="match_parent"
+              android:layout_height="match_parent"
+              android:orientation="vertical"
+              android:visibility="visible">
+
+    <FrameLayout
+            android:id="@+id/editorContainer"
+            android:layout_width="match_parent"
+            android:layout_height="0dp"
+            android:layout_weight="6"
+            android:layout_gravity="bottom">
+
+        <LinearLayout
+                android:id="@+id/controls"
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:layout_gravity="bottom"
+                android:orientation="vertical"
+                android:visibility="visible">
+
+            <Button
+                    android:id="@+id/clearButton"
+                    android:layout_width="match_parent"
+                    android:layout_height="0dp"
+                    android:layout_weight="1"
+                    android:text="@string/color_border_clear"/>
+
+            <GridLayout
+                    android:layout_width="match_parent"
+                    android:layout_height="0dp"
+                    android:layout_weight="1"
+                    android:columnCount="2"
+                    android:orientation="horizontal">
+
+                <TextView
+                        android:id="@+id/controlName1"
+                        android:layout_gravity="left"
+                        android:layout_marginLeft="8dip"
+                        android:text="@string/color_border_size"/>
+
+                <TextView
+                        android:id="@+id/colorBorderSizeValue"
+                        android:layout_gravity="right"
+                        android:layout_marginRight="8dip"
+                        android:textStyle="bold"/>
+
+                <SeekBar
+                        android:id="@+id/colorBorderSizeSeekBar"
+                        android:layout_width="match_parent"
+                        android:layout_column="0"
+                        android:layout_columnSpan="2"
+                        android:layout_gravity="fill_horizontal"
+                        style="@style/FilterShowSlider"/>
+            </GridLayout>
+
+            <GridLayout
+                    android:layout_width="match_parent"
+                    android:layout_height="0dp"
+                    android:layout_weight="1"
+                    android:columnCount="2"
+                    android:orientation="horizontal">
+
+                <TextView
+                        android:id="@+id/controlName2"
+                        android:layout_gravity="left"
+                        android:layout_marginLeft="8dip"
+                        android:text="@string/color_border_corner_size"/>
+
+                <TextView
+                        android:id="@+id/colorBorderCornerValue"
+                        android:layout_gravity="right"
+                        android:layout_marginRight="8dip"
+                        android:textStyle="bold"/>
+
+                <SeekBar
+                        android:id="@+id/colorBorderCornerSizeSeekBar"
+                        android:layout_width="match_parent"
+                        android:layout_column="0"
+                        android:layout_columnSpan="2"
+                        android:layout_gravity="fill_horizontal"
+                        style="@style/FilterShowSlider"/>
+            </GridLayout>
+
+            <HorizontalScrollView
+                    android:id="@+id/scrollList"
+                    android:layout_width="match_parent"
+                    android:layout_height="0dp"
+                    android:layout_weight="1"
+                    android:scrollbars="none">
+
+                <LinearLayout
+                        android:id="@+id/listStyles"
+                        android:layout_width="wrap_content"
+                        android:layout_height="wrap_content"
+                        android:orientation="horizontal">
+
+                </LinearLayout>
+            </HorizontalScrollView>
+
+        </LinearLayout>
+
+        <LinearLayout
+                android:id="@+id/colorPicker"
+                android:layout_width="match_parent"
+                android:layout_height="match_parent"
+                android:orientation="vertical"
+                android:visibility="gone">
+
+            <TextView
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:text="@string/draw_color"
+                    android:layout_marginLeft="8dip"
+                    android:id="@+id/textView"/>
+
+            <com.android.gallery3d.filtershow.colorpicker.ColorOpacityView
+                    android:id="@+id/colorOpacityView"
+                    android:layout_width="match_parent"
+                    android:layout_height="0dp"
+                    android:layout_weight="1"/>
+
+            <com.android.gallery3d.filtershow.colorpicker.ColorSVRectView
+                    android:id="@+id/colorRectView"
+                    android:layout_width="match_parent"
+                    android:layout_height="0dp"
+                    android:layout_weight="4"
+                    android:layout_marginRight="1dp"/>
+
+            <com.android.gallery3d.filtershow.colorpicker.ColorHueView
+                    android:id="@+id/ColorHueView"
+                    android:layout_width="match_parent"
+                    android:layout_height="0dp"
+                    android:layout_weight="1"/>
+
+        </LinearLayout>
+    </FrameLayout>
+
+    <LinearLayout
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:orientation="horizontal"
+            android:layout_marginBottom="10dp"
+            android:layout_marginTop="10dp"
+            android:layout_marginLeft="1dp"
+            android:layout_marginRight="1dp">
+
+        <HorizontalScrollView
+                android:id="@+id/scrollList"
+                android:layout_width="0dp"
+                android:layout_weight="5"
+                android:layout_height="match_parent"
+                android:scrollbars="none">
+
+            <LinearLayout
+                    android:id="@+id/listColors"
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:orientation="horizontal">
+
+                <Button
+                        android:id="@+id/draw_color_button01"
+                        android:layout_width="0dip"
+                        android:layout_height="wrap_content"
+                        android:layout_weight="1"
+                        android:background="@drawable/filtershow_color_picker_circle"
+                        android:layout_margin="2dp"/>
+
+                <Button
+                        android:id="@+id/draw_color_button02"
+                        android:layout_width="0dip"
+                        android:layout_height="wrap_content"
+                        android:layout_weight="1"
+                        android:background="@drawable/filtershow_color_picker_circle"
+                        android:layout_margin="2dp"/>
+
+                <Button
+                        android:id="@+id/draw_color_button03"
+                        android:layout_width="0dip"
+                        android:layout_height="wrap_content"
+                        android:layout_weight="1"
+                        android:background="@drawable/filtershow_color_picker_circle"
+                        android:layout_margin="2dp"/>
+
+                <Button
+                        android:id="@+id/draw_color_button04"
+                        android:layout_width="0dip"
+                        android:layout_height="wrap_content"
+                        android:layout_weight="1"
+                        android:background="@drawable/filtershow_color_picker_circle"
+                        android:layout_margin="2dp"/>
+
+                <Button
+                        android:id="@+id/draw_color_button05"
+                        android:layout_width="0dip"
+                        android:layout_height="wrap_content"
+                        android:layout_weight="1"
+                        android:background="@drawable/filtershow_color_picker_circle"
+                        android:layout_margin="2dp"/>
+
+            </LinearLayout>
+        </HorizontalScrollView>
+
+        <Button
+                android:id="@+id/draw_color_popupbutton"
+                android:layout_width="0dp"
+                android:layout_height="match_parent"
+                android:layout_weight="1"
+                android:background="@android:drawable/ic_menu_more"
+                android:layout_margin="1dp"/>
+    </LinearLayout>
+</LinearLayout>
diff --git a/res/menu/filtershow_menu_color_border.xml b/res/menu/filtershow_menu_color_border.xml
new file mode 100644 (file)
index 0000000..7d27504
--- /dev/null
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+     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.
+-->
+
+<menu xmlns:android="http://schemas.android.com/apk/res/android">
+
+    <group android:id="@+id/curves_popupmenu">
+        <item
+                android:id="@+id/color_border_menu_corner_size"
+                android:title="@string/color_border_corner_size"/>
+        <item
+                android:id="@+id/color_border_menu_size"
+                android:title="@string/color_border_size"/>
+        <item
+                android:id="@+id/color_border_menu_color"
+                android:title="@string/color_border_color"/>
+        <item
+                android:id="@+id/color_border_menu_clear"
+                android:title="@string/color_border_clear"/>
+    </group>
+
+</menu>
\ No newline at end of file
index b315d12..460da61 100644 (file)
@@ -39,6 +39,7 @@
     <item type="id" name="imageCurves" />
     <item type="id" name="imageZoom" />
     <item type="id" name="editorDraw" />
+    <item type="id" name="editorColorBorder" />
     <item type="id" name="editorRedEye" />
     <item type="id" name="imageOnlyEditor" />
     <item type="id" name="vignetteEditor" />
index 9a41f3c..4c8996a 100644 (file)
     <!--  Label for the removing drawing from screen [CHAR LIMIT=14] -->
     <string name="draw_clear">Clear</string>
 
+
+    <!--  Label for the with of the border[CHAR LIMIT=14] -->
+    <string name="color_border_size">thickness</string>
+    <!--  Label for the border corner size (or rounding) [CHAR LIMIT=14] -->
+    <string name="color_border_corner_size">Corner Size</string>
+    <!--  Label for selecting the border color [CHAR LIMIT=14] -->
+    <string name="color_border_color">Color</string>
+     <!--  Label for the removing borders [CHAR LIMIT=14] -->
+    <string name="color_border_clear">Clear</string>
+
     <!--  Label for the select the color [CHAR LIMIT=35] -->
     <string name="color_pick_select">Choose custom color</string>
     <!--  The title for the color pick dialog [CHAR LIMIT=20] -->
index b18eeb1..c3a5e15 100644 (file)
@@ -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());
index 2608df6..4f8248f 100644 (file)
@@ -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 (file)
index 0000000..2561dcd
--- /dev/null
@@ -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 (file)
index 0000000..04aee27
--- /dev/null
@@ -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);
+        }
+    }
+}
index 97c889c..4886821 100644 (file)
@@ -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;
index 282254b..7a5ec56 100644 (file)
@@ -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() {
index 94eb206..929d7cc 100644 (file)
 
 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 "";
     }
 }
index f05910b..d4b4e87 100644 (file)
@@ -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";
@@ -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;
     }
 
 }
index 2757aff..b345376 100644 (file)
@@ -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);
index 3266425..e82d561 100644 (file)
@@ -31,6 +31,7 @@ public class EditorManager {
         editorPlaceHolder.addEditor(new EditorTinyPlanet());
         editorPlaceHolder.addEditor(new EditorDraw());
         editorPlaceHolder.addEditor(new EditorVignette());
+        editorPlaceHolder.addEditor(new EditorColorBorder());
         editorPlaceHolder.addEditor(new EditorMirror());
         editorPlaceHolder.addEditor(new EditorRotate());
         editorPlaceHolder.addEditor(new EditorStraighten());