OSDN Git Service

add flexable ui for parameters
authorJohn Hoford <hoford@google.com>
Tue, 12 Mar 2013 23:30:10 +0000 (16:30 -0700)
committerJohn Hoford <hoford@google.com>
Fri, 29 Mar 2013 19:11:16 +0000 (12:11 -0700)
Change-Id: Ifa9862ceb7f9a12b1b9b985fdc737dc1bb679921

21 files changed:
res/drawable/filtershow_addpoint.png [new file with mode: 0644]
res/drawable/filtershow_delpoint.png [new file with mode: 0644]
res/drawable/filtershow_vertical_bar.png [new file with mode: 0644]
res/layout/filtershow_control_action_slider.xml [new file with mode: 0644]
res/layout/filtershow_control_title_slider.xml [new file with mode: 0644]
res/layout/filtershow_editor_panel.xml
res/layout/filtershow_seekbar.xml [new file with mode: 0644]
res/values/filtershow_ids.xml
src/com/android/gallery3d/filtershow/PanelController.java
src/com/android/gallery3d/filtershow/controller/ActionSlider.java [new file with mode: 0644]
src/com/android/gallery3d/filtershow/controller/BasicSlider.java [new file with mode: 0644]
src/com/android/gallery3d/filtershow/controller/Control.java [new file with mode: 0644]
src/com/android/gallery3d/filtershow/controller/Parameter.java [new file with mode: 0644]
src/com/android/gallery3d/filtershow/controller/ParameterActionAndInt.java [new file with mode: 0644]
src/com/android/gallery3d/filtershow/controller/ParameterInteger.java [new file with mode: 0644]
src/com/android/gallery3d/filtershow/controller/TitledSlider.java [new file with mode: 0644]
src/com/android/gallery3d/filtershow/editors/Editor.java
src/com/android/gallery3d/filtershow/editors/EditorVignette.java
src/com/android/gallery3d/filtershow/editors/ParametricEditor.java [new file with mode: 0644]
src/com/android/gallery3d/filtershow/filters/FilterBasicRepresentation.java
src/com/android/gallery3d/filtershow/imageshow/ImageVignette.java

diff --git a/res/drawable/filtershow_addpoint.png b/res/drawable/filtershow_addpoint.png
new file mode 100644 (file)
index 0000000..483d8ee
Binary files /dev/null and b/res/drawable/filtershow_addpoint.png differ
diff --git a/res/drawable/filtershow_delpoint.png b/res/drawable/filtershow_delpoint.png
new file mode 100644 (file)
index 0000000..84f2e5b
Binary files /dev/null and b/res/drawable/filtershow_delpoint.png differ
diff --git a/res/drawable/filtershow_vertical_bar.png b/res/drawable/filtershow_vertical_bar.png
new file mode 100644 (file)
index 0000000..5ac0a9f
Binary files /dev/null and b/res/drawable/filtershow_vertical_bar.png differ
diff --git a/res/layout/filtershow_control_action_slider.xml b/res/layout/filtershow_control_action_slider.xml
new file mode 100644 (file)
index 0000000..7caf96d
--- /dev/null
@@ -0,0 +1,40 @@
+<?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"
+    xmlns:app="http://schemas.android.com/apk/res/com.example.imagefilterharness"
+    android:layout_width="match_parent"
+    android:layout_height="150dp"
+    android:orientation="horizontal" >
+
+    <ImageButton
+        android:id="@+id/actionButton"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:scaleType="centerInside"
+        android:background="@drawable/filtershow_button_background"
+        android:src="@drawable/filtershow_addpoint"
+        android:paddingBottom="8dp"  />
+
+    <SeekBar
+        android:id="@+id/controlValueSeekBar"
+        android:layout_width="match_parent"
+         android:layout_height="wrap_content"
+        android:layout_gravity="fill_horizontal"
+        style="@style/FilterShowSlider" />
+</LinearLayout>
+
diff --git a/res/layout/filtershow_control_title_slider.xml b/res/layout/filtershow_control_title_slider.xml
new file mode 100644 (file)
index 0000000..a2c65cf
--- /dev/null
@@ -0,0 +1,41 @@
+<?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.
+-->
+
+<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res/com.example.imagefilterharness"
+    android:layout_width="match_parent"
+    android:layout_height="150dp"
+    android:columnCount="2"
+    android:orientation="horizontal" >
+
+    <TextView
+        android:id="@+id/controlName"
+        android:layout_gravity="left" />
+
+    <TextView
+        android:id="@+id/controlValue"
+        android:layout_gravity="right" />
+
+    <SeekBar
+        android:id="@+id/controlValueSeekBar"
+        android:layout_width="match_parent"
+        android:layout_column="0"
+        android:layout_columnSpan="2"
+        android:layout_gravity="fill_horizontal"
+        style="@style/FilterShowSlider" />
+</GridLayout>
+
index ffe5d48..2d085a8 100644 (file)
             android:layout_height="94dip"
             android:layout_gravity="left|center_vertical"
             android:layout_weight=".1"
-            android:background="@android:color/transparent"
+            android:background="@drawable/filtershow_button_background"
             android:gravity="center"
             android:src="@drawable/ic_menu_cancel_holo_light"
-            android:textSize="18dip" />
+            android:textSize="18dip" 
+            style="@style/FilterShowBottomButton" />
 
         <ImageView
             android:layout_width="2dp"
             android:layout_height="fill_parent"
-            android:src="@drawable/filtershow_vertical_line" />
+            android:src="@drawable/filtershow_vertical_bar" />
 
         <LinearLayout
             android:id="@+id/panelAccessoryViewList"
@@ -77,7 +78,7 @@
                 android:layout_width="fill_parent"
                 android:layout_height="fill_parent"
                 android:layout_gravity="center"
-                android:background="@android:color/transparent"
+                android:background="@drawable/filtershow_button_background"
                 android:gravity="center"
                 android:text="@string/apply_effect"
                 android:textSize="18dip"
@@ -87,7 +88,7 @@
         <ImageView
             android:layout_width="2dp"
             android:layout_height="fill_parent"
-            android:src="@drawable/filtershow_vertical_line" />
+            android:src="@drawable/filtershow_vertical_bar" />
 
         <ImageButton
             android:id="@+id/applyFilter"
             android:layout_height="94dip"
             android:layout_gravity="right|center_vertical"
             android:layout_weight=".1"
-            android:background="@android:color/transparent"
+            android:background="@drawable/filtershow_button_background"
             android:gravity="center"
             android:src="@drawable/ic_menu_done_holo_light"
-            android:textSize="18dip" />
+            android:textSize="18dip" 
+            style="@style/FilterShowBottomButton" />
     </LinearLayout>
 
-</LinearLayout>
\ No newline at end of file
+</LinearLayout>
diff --git a/res/layout/filtershow_seekbar.xml b/res/layout/filtershow_seekbar.xml
new file mode 100644 (file)
index 0000000..53f5980
--- /dev/null
@@ -0,0 +1,33 @@
+<?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="wrap_content"
+    android:layout_weight="0"
+    android:orientation="vertical"
+    android:visibility="visible" >
+
+    <SeekBar
+        android:id="@+id/primarySeekBar"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:layout_weight="1"
+        style="@style/FilterShowSlider" />
+
+</LinearLayout>
index 9380740..8ac2941 100644 (file)
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="utf-8"?>
 <!--
 /*
-* Copyright (C) 2012 The Android Open Source Project
+* 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.
@@ -46,4 +46,5 @@
     <item type="id" name="editorFlip" />
     <item type="id" name="editorRotate" />
     <item type="id" name="editorStraighten" />
+    <item type="id" name="editorParametric" />
 </resources>
index 8352032..6b20fe1 100644 (file)
@@ -151,7 +151,7 @@ public class PanelController implements OnClickListener {
         private final View mView;
         private final LinearLayout mAccessoryViewList;
         private Vector<View> mAccessoryViews = new Vector<View>();
-        private final TextView mTextView;
+        private final Button mTextView;
         private boolean mSelected = false;
         private String mEffectName = null;
         private int mParameterValue = 0;
@@ -160,10 +160,9 @@ public class PanelController implements OnClickListener {
         public UtilityPanel(Context context, View utilityPanel) {
             mView = utilityPanel;
             View accessoryViewList = mView.findViewById(R.id.panelAccessoryViewList);
-            Button textView = (Button) mView.findViewById(R.id.applyEffect);
+            mTextView = (Button) mView.findViewById(R.id.applyEffect);
             mContext = context;
             mAccessoryViewList = (LinearLayout) accessoryViewList;
-            mTextView = (TextView) textView;
         }
 
         public boolean selected() {
@@ -212,6 +211,16 @@ public class PanelController implements OnClickListener {
         public View getEditControl() {
             return mView.findViewById(R.id.controlArea);
         }
+
+        public void removeControlChildren() {
+            LinearLayout controlArea = (LinearLayout) mView.findViewById(R.id.controlArea);
+            controlArea.removeAllViews();
+        }
+
+        public Button getEditTitle() {
+            return mTextView;
+        }
+
         public void updateText() {
             String s;
             if (mCurrentEditor == null) {
@@ -589,8 +598,10 @@ public class PanelController implements OnClickListener {
                     if (mEditorPlaceHolder.contains(representation.getEditorId())) {
                         mCurrentEditor = mEditorPlaceHolder.showEditor(
                                 representation.getEditorId());
-                        mCurrentEditor.setUtilityPanelUI(
-                                mUtilityPanel.getActionControl(), mUtilityPanel.getEditControl());
+                        mUtilityPanel.removeControlChildren();
+                        mCurrentEditor.setUpEditorUI(
+                                mUtilityPanel.getActionControl(), mUtilityPanel.getEditControl(),
+                                mUtilityPanel.getEditTitle());
                         mCurrentImage = mCurrentEditor.getImageShow();
                         mCurrentEditor.setPanelController(this);
 
diff --git a/src/com/android/gallery3d/filtershow/controller/ActionSlider.java b/src/com/android/gallery3d/filtershow/controller/ActionSlider.java
new file mode 100644 (file)
index 0000000..6ed2467
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * 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.util.Log;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.view.ViewGroup;
+import android.widget.ImageButton;
+
+import com.android.gallery3d.R;
+import com.android.gallery3d.filtershow.editors.Editor;
+
+public class ActionSlider extends TitledSlider {
+    private static final String LOGTAG = "ActionSlider";
+    ImageButton mActionButton;
+    public ActionSlider() {
+        mLayoutID = R.layout.filtershow_control_action_slider;
+    }
+
+    @Override
+    public void setUp(ViewGroup container, Parameter parameter, Editor editor) {
+        super.setUp(container, parameter, editor);
+        mActionButton = (ImageButton) mTopView.findViewById(R.id.actionButton);
+        mActionButton.setOnClickListener(new OnClickListener() {
+
+            @Override
+            public void onClick(View v) {
+                ((ParameterActionAndInt) mParameter).fireAction();
+            }
+        });
+    }
+
+    @Override
+    public void updateUI() {
+        super.updateUI();
+        if (mActionButton != null) {
+            int iconId = ((ParameterActionAndInt) mParameter).getActionIcon();
+            mActionButton.setImageResource(iconId);
+        }
+    }
+}
diff --git a/src/com/android/gallery3d/filtershow/controller/BasicSlider.java b/src/com/android/gallery3d/filtershow/controller/BasicSlider.java
new file mode 100644 (file)
index 0000000..c54fe77
--- /dev/null
@@ -0,0 +1,87 @@
+/*
+ * 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.editors.Editor;
+
+public class BasicSlider implements Control {
+    private SeekBar mSeekBar;
+    private ParameterInteger mParameter;
+    Editor mEditor;
+
+    @Override
+    public void setUp(ViewGroup container, Parameter parameter, Editor editor) {
+        mEditor = editor;
+        Context context = container.getContext();
+        mParameter = (ParameterInteger) parameter;
+        LayoutInflater inflater =
+                (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+        LinearLayout lp = (LinearLayout) inflater.inflate(
+                R.layout.filtershow_seekbar, container, true);
+        mSeekBar = (SeekBar) lp.findViewById(R.id.primarySeekBar);
+
+        updateUI();
+        mSeekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
+
+            @Override
+            public void onStopTrackingTouch(SeekBar seekBar) {
+            }
+
+            @Override
+            public void onStartTrackingTouch(SeekBar seekBar) {
+            }
+
+            @Override
+            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
+                if (mParameter != null) {
+                    mParameter.setValue(progress + mParameter.getMinimum());
+                    mEditor.commitLocalRepresentation();
+
+                }
+            }
+        });
+    }
+
+    @Override
+    public View getTopView() {
+        return mSeekBar;
+    }
+
+    @Override
+    public void setPrameter(Parameter parameter) {
+        mParameter = (ParameterInteger) parameter;
+        if (mSeekBar != null) {
+            updateUI();
+        }
+    }
+
+    @Override
+    public void updateUI() {
+        mSeekBar.setMax(mParameter.getMaximum() - mParameter.getMinimum());
+        mSeekBar.setProgress(mParameter.getValue() - mParameter.getMinimum());
+    }
+
+}
diff --git a/src/com/android/gallery3d/filtershow/controller/Control.java b/src/com/android/gallery3d/filtershow/controller/Control.java
new file mode 100644 (file)
index 0000000..4342290
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * 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.view.View;
+import android.view.ViewGroup;
+
+import com.android.gallery3d.filtershow.editors.Editor;
+
+public interface Control {
+    public void setUp(ViewGroup container, Parameter parameter, Editor editor);
+
+    public View getTopView();
+
+    public void setPrameter(Parameter parameter);
+
+    public void updateUI();
+}
diff --git a/src/com/android/gallery3d/filtershow/controller/Parameter.java b/src/com/android/gallery3d/filtershow/controller/Parameter.java
new file mode 100644 (file)
index 0000000..1e8694a
--- /dev/null
@@ -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.controller;
+
+public interface Parameter {
+    String getParameterName();
+
+    String getParameterType();
+
+    String getValueString();
+
+    public void setController(Control c);
+}
diff --git a/src/com/android/gallery3d/filtershow/controller/ParameterActionAndInt.java b/src/com/android/gallery3d/filtershow/controller/ParameterActionAndInt.java
new file mode 100644 (file)
index 0000000..04567e2
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+ * 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 interface ParameterActionAndInt extends ParameterInteger {
+    static String sParameterType = "ParameterActionAndInt";
+
+    public void fireAction();
+
+    public int getActionIcon();
+}
diff --git a/src/com/android/gallery3d/filtershow/controller/ParameterInteger.java b/src/com/android/gallery3d/filtershow/controller/ParameterInteger.java
new file mode 100644 (file)
index 0000000..0bfd201
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * 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 interface ParameterInteger extends Parameter {
+    static String sParameterType = "ParameterInteger";
+
+    int getMaximum();
+
+    int getMinimum();
+
+    int getDefaultValue();
+
+    int getValue();
+
+    void setValue(int value);
+}
diff --git a/src/com/android/gallery3d/filtershow/controller/TitledSlider.java b/src/com/android/gallery3d/filtershow/controller/TitledSlider.java
new file mode 100644 (file)
index 0000000..30b6fdb
--- /dev/null
@@ -0,0 +1,105 @@
+/*
+ * 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.util.Log;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.SeekBar;
+import android.widget.SeekBar.OnSeekBarChangeListener;
+import android.widget.TextView;
+
+import com.android.gallery3d.R;
+import com.android.gallery3d.filtershow.editors.Editor;
+
+public class TitledSlider implements Control {
+    private final String LOGTAG = "ParametricEditor";
+    private SeekBar mSeekBar;
+    private TextView mControlName;
+    private TextView mControlValue;
+    protected ParameterInteger mParameter;
+    Editor mEditor;
+    View mTopView;
+    protected int mLayoutID = R.layout.filtershow_control_title_slider;
+
+    @Override
+    public void setUp(ViewGroup container, Parameter parameter, Editor editor) {
+        mEditor = editor;
+        Context context = container.getContext();
+        mParameter = (ParameterInteger) parameter;
+        LayoutInflater inflater =
+                (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+        mTopView = inflater.inflate(mLayoutID, container, true);
+        mTopView.setVisibility(View.VISIBLE);
+        mSeekBar = (SeekBar) mTopView.findViewById(R.id.controlValueSeekBar);
+        mControlName = (TextView) mTopView.findViewById(R.id.controlName);
+        mControlValue = (TextView) mTopView.findViewById(R.id.controlValue);
+        updateUI();
+        mSeekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
+
+            @Override
+            public void onStopTrackingTouch(SeekBar seekBar) {
+            }
+
+            @Override
+            public void onStartTrackingTouch(SeekBar seekBar) {
+            }
+
+            @Override
+            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
+                if (mParameter != null) {
+                    mParameter.setValue(progress + mParameter.getMinimum());
+                    if (mControlName != null) {
+                        mControlName.setText(mParameter.getParameterName());
+                    }
+                    if (mControlValue != null) {
+                        mControlValue.setText(Integer.toString(mParameter.getValue()));
+                    }
+                    mEditor.commitLocalRepresentation();
+                }
+            }
+        });
+    }
+
+    @Override
+    public void setPrameter(Parameter parameter) {
+        mParameter = (ParameterInteger) parameter;
+        if (mSeekBar != null)
+            updateUI();
+    }
+
+    @Override
+    public void updateUI() {
+        if (mControlName != null) {
+            mControlName.setText(mParameter.getParameterName());
+        }
+        if (mControlValue != null) {
+            mControlValue.setText(
+                    Integer.toString(mParameter.getValue()));
+        }
+        mSeekBar.setMax(mParameter.getMaximum() - mParameter.getMinimum());
+        mSeekBar.setProgress(mParameter.getValue() - mParameter.getMinimum());
+        mEditor.commitLocalRepresentation();
+    }
+
+    @Override
+    public View getTopView() {
+        return mTopView;
+    }
+}
index 69266ff..013590c 100644 (file)
 package com.android.gallery3d.filtershow.editors;
 
 import android.content.Context;
-import android.graphics.drawable.Drawable;
-import android.text.Html;
+import android.util.AttributeSet;
 import android.view.LayoutInflater;
 import android.view.Menu;
 import android.view.View;
 import android.view.ViewGroup;
-import android.widget.*;
+import android.widget.Button;
+import android.widget.FrameLayout;
+import android.widget.LinearLayout;
+import android.widget.PopupMenu;
+import android.widget.SeekBar;
 import android.widget.SeekBar.OnSeekBarChangeListener;
 
 import com.android.gallery3d.R;
 import com.android.gallery3d.filtershow.PanelController;
 import com.android.gallery3d.filtershow.cache.ImageLoader;
+import com.android.gallery3d.filtershow.controller.Control;
 import com.android.gallery3d.filtershow.filters.FilterRepresentation;
 import com.android.gallery3d.filtershow.imageshow.ImageShow;
 import com.android.gallery3d.filtershow.imageshow.MasterImage;
@@ -43,6 +47,7 @@ public class Editor implements OnSeekBarChangeListener {
     protected ImageShow mImageShow;
     protected FrameLayout mFrameLayout;
     protected SeekBar mSeekBar;
+    Button mEditTitle;
     protected PanelController mPanelController;
     protected int mID;
     private final String LOGTAG = "Editor";
@@ -57,7 +62,7 @@ public class Editor implements OnSeekBarChangeListener {
     }
 
     public String calculateUserMessage(Context context, String effectName, Object parameterValue) {
-        String apply = context.getString(R.string.apply_effect);
+        String apply = "";
         if (mShowParameter == SHOW_VALUE_INT) {
             apply += " " + effectName + " " + parameterValue;
         } else {
@@ -83,6 +88,12 @@ public class Editor implements OnSeekBarChangeListener {
         return true;
     }
 
+    public void setUpEditorUI(View actionButton, View editControl, Button editTitle) {
+        this.mEditTitle = editTitle;
+        setMenuIcon(true);
+        setUtilityPanelUI(actionButton, editControl);
+    }
+
     public boolean showsPopupIndicator() {
         return true;
     }
@@ -92,17 +103,28 @@ public class Editor implements OnSeekBarChangeListener {
      * @param editControl this is the black area for sliders etc
      */
     public void setUtilityPanelUI(View actionButton, View editControl) {
-        mSeekBar = (SeekBar) editControl.findViewById(R.id.primarySeekBar);
+
+        AttributeSet aset;
+        Context context = editControl.getContext();
+        LayoutInflater inflater =
+                (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+        LinearLayout lp = (LinearLayout) inflater.inflate(
+                R.layout.filtershow_seekbar, (ViewGroup) editControl, true);
+        mSeekBar = (SeekBar) lp.findViewById(R.id.primarySeekBar);
+        mSeekBar.setOnSeekBarChangeListener(this);
+
         if (showsSeekBar()) {
             mSeekBar.setOnSeekBarChangeListener(this);
             mSeekBar.setVisibility(View.VISIBLE);
         } else {
             mSeekBar.setVisibility(View.INVISIBLE);
         }
+
         Button button = (Button) actionButton.findViewById(R.id.applyEffect);
         if (button != null) {
             if (showsPopupIndicator()) {
-                button.setCompoundDrawablesRelativeWithIntrinsicBounds(0, 0, R.drawable.filtershow_menu_marker, 0);
+                button.setCompoundDrawablesRelativeWithIntrinsicBounds(0, 0,
+                        R.drawable.filtershow_menu_marker, 0);
             } else {
                 button.setCompoundDrawablesRelativeWithIntrinsicBounds(0, 0, 0, 0);
             }
@@ -205,19 +227,29 @@ public class Editor implements OnSeekBarChangeListener {
     }
 
     public void openUtilityPanel(LinearLayout mAccessoryViewList) {
+        setMenuIcon(false);
         if (mImageShow != null) {
             mImageShow.openUtilityPanel(mAccessoryViewList);
         }
     }
 
+    protected void setMenuIcon(boolean on) {
+        mEditTitle.setCompoundDrawablesRelativeWithIntrinsicBounds(
+                0, 0, on ? R.drawable.filtershow_menu_marker : 0, 0);
+    }
     protected void createMenu(int[] strId, View button) {
         PopupMenu pmenu = new PopupMenu(mContext, button);
         Menu menu = pmenu.getMenu();
         for (int i = 0; i < strId.length; i++) {
             menu.add(Menu.NONE, Menu.FIRST + i, 0, mContext.getString(strId[i]));
         }
+        setMenuIcon(true);
+
     }
 
+    public Control[] getControls() {
+        return null;
+    }
     @Override
     public void onStartTrackingTouch(SeekBar arg0) {
 
index a7d99e4..7127b21 100644 (file)
@@ -24,7 +24,7 @@ import com.android.gallery3d.filtershow.filters.FilterRepresentation;
 import com.android.gallery3d.filtershow.filters.FilterVignetteRepresentation;
 import com.android.gallery3d.filtershow.imageshow.ImageVignette;
 
-public class EditorVignette extends BasicEditor {
+public class EditorVignette extends ParametricEditor {
     public static final int ID = R.id.vignetteEditor;
     private static final String LOGTAG = "EditorVignettePlanet";
     ImageVignette mImageVignette;
diff --git a/src/com/android/gallery3d/filtershow/editors/ParametricEditor.java b/src/com/android/gallery3d/filtershow/editors/ParametricEditor.java
new file mode 100644 (file)
index 0000000..cf00f4a
--- /dev/null
@@ -0,0 +1,197 @@
+/*
+ * 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.Point;
+import android.util.Log;
+import android.view.View;
+import android.view.ViewGroup;
+import android.view.ViewGroup.LayoutParams;
+import android.view.WindowManager;
+import android.widget.FrameLayout;
+import android.widget.LinearLayout;
+import android.widget.SeekBar;
+
+import com.android.gallery3d.R;
+import com.android.gallery3d.filtershow.controller.ActionSlider;
+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.ParameterInteger;
+import com.android.gallery3d.filtershow.controller.TitledSlider;
+import com.android.gallery3d.filtershow.filters.FilterBasicRepresentation;
+import com.android.gallery3d.filtershow.filters.FilterRepresentation;
+
+import java.lang.reflect.Constructor;
+import java.util.HashMap;
+
+public class ParametricEditor extends Editor {
+    private int mLayoutID;
+    private int mViewID;
+    public static int ID = R.id.editorParametric;
+    private final String LOGTAG = "ParametricEditor";
+    protected Control mControl;
+    public static final int MINIMUM_WIDTH = 600;
+    public static final int MINIMUM_HEIGHT = 800;
+
+    static HashMap<String, Class> portraitMap = new HashMap<String, Class>();
+    static HashMap<String, Class> landscapeMap = new HashMap<String, Class>();
+    static {
+        portraitMap.put(ParameterInteger.sParameterType, BasicSlider.class);
+        landscapeMap.put(ParameterInteger.sParameterType, TitledSlider.class);
+        portraitMap.put(ParameterActionAndInt.sParameterType, ActionSlider.class);
+        landscapeMap.put(ParameterActionAndInt.sParameterType, ActionSlider.class);
+    }
+
+    static Constructor getConstructor(Class cl) {
+        try {
+            return cl.getConstructor(Context.class, ViewGroup.class);
+        } catch (Exception e) {
+            return null;
+        }
+    }
+
+    public ParametricEditor() {
+        super(ID);
+    }
+
+    protected ParametricEditor(int id) {
+        super(id);
+    }
+
+    protected ParametricEditor(int id, int layoutID, int viewID) {
+        super(id);
+        mLayoutID = layoutID;
+        mViewID = viewID;
+    }
+
+    @Override
+    public String calculateUserMessage(Context context, String effectName, Object parameterValue) {
+        String apply = "";
+
+        if (mShowParameter == SHOW_VALUE_INT & useCompact(context)) {
+           if (getLocalRepresentation() instanceof FilterBasicRepresentation) {
+            FilterBasicRepresentation interval = (FilterBasicRepresentation) getLocalRepresentation();
+            apply += " " + effectName + " " + interval.getStateRepresentation();
+           } else {
+                apply += " " + effectName + " " + parameterValue;
+           }
+        } else {
+            apply += " " + effectName;
+        }
+        return apply;
+    }
+
+    @Override
+    public void createEditor(Context context, FrameLayout frameLayout) {
+        super.createEditor(context, frameLayout);
+        unpack(mViewID, mLayoutID);
+    }
+
+    @Override
+    public void reflectCurrentFilter() {
+        super.reflectCurrentFilter();
+        if (getLocalRepresentation() != null
+                && getLocalRepresentation() instanceof FilterBasicRepresentation) {
+            FilterBasicRepresentation interval = (FilterBasicRepresentation) getLocalRepresentation();
+            mControl.setPrameter(interval);
+        }
+    }
+
+    @Override
+    public Control[] getControls() {
+        BasicSlider slider = new BasicSlider();
+        return new Control[] {
+                slider
+        };
+    }
+
+    // TODO: need a better way to decide when which representation
+    static boolean useCompact(Context context) {
+        WindowManager w = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE));
+        Point size = new Point();
+        w.getDefaultDisplay().getSize(size);
+        if (size.x < size.y) { // if tall than wider
+            return true;
+        }
+        if (size.x < MINIMUM_WIDTH) {
+            return true;
+        }
+        if (size.y < MINIMUM_HEIGHT) {
+            return true;
+        }
+        return false;
+    }
+
+    @Override
+    public void setUtilityPanelUI(View actionButton, View editControl) {
+        FilterRepresentation rep = getLocalRepresentation();
+        if (this instanceof Parameter) {
+            control((Parameter) this, editControl);
+        } else if (rep instanceof Parameter) {
+            control((Parameter) rep, editControl);
+        } else {
+            mSeekBar = new SeekBar(editControl.getContext());
+            LayoutParams lp = new LinearLayout.LayoutParams(
+                    LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
+            mSeekBar.setLayoutParams(lp);
+            ((LinearLayout) editControl).addView(mSeekBar);
+            mSeekBar.setOnSeekBarChangeListener(this);
+        }
+    }
+
+    protected void control(Parameter p, View editControl) {
+        String pType = p.getParameterType();
+        Context context = editControl.getContext();
+        Class c = ((useCompact(context)) ? portraitMap : landscapeMap).get(pType);
+
+        if (c != null) {
+            try {
+                mControl = (Control) c.newInstance();
+                mControl.setUp((ViewGroup) editControl, p, this);
+
+            } catch (Exception e) {
+                Log.e(LOGTAG, "Error in loading Control ", e);
+            }
+        } else {
+            Log.e(LOGTAG, "Unable to find class for " + pType);
+            for (String string : portraitMap.keySet()) {
+                Log.e(LOGTAG, "for " + string + " use " + portraitMap.get(string));
+            }
+        }
+    }
+
+    @Override
+    public void commitLocalRepresentation() {
+        super.commitLocalRepresentation();
+        FilterRepresentation rep = getLocalRepresentation();
+    }
+
+    @Override
+    public void onProgressChanged(SeekBar sbar, int progress, boolean arg2) {
+    }
+
+    @Override
+    public void onStartTrackingTouch(SeekBar arg0) {
+    }
+
+    @Override
+    public void onStopTrackingTouch(SeekBar arg0) {
+    }
+}
index 2410ebe..34323c4 100644 (file)
 package com.android.gallery3d.filtershow.filters;
 
 import com.android.gallery3d.app.Log;
+import com.android.gallery3d.filtershow.controller.Control;
+import com.android.gallery3d.filtershow.controller.ParameterInteger;
 
-public class FilterBasicRepresentation extends FilterRepresentation {
+public class FilterBasicRepresentation extends FilterRepresentation implements ParameterInteger {
     private static final String LOGTAG = "FilterBasicRepresentation";
     private int mMinimum;
     private int mValue;
@@ -33,6 +35,7 @@ public class FilterBasicRepresentation extends FilterRepresentation {
         setValue(value);
     }
 
+    @Override
     public String toString() {
         return getName() + " : " + mMinimum + " < " + mValue + " < " + mMaximum;
     }
@@ -47,6 +50,7 @@ public class FilterBasicRepresentation extends FilterRepresentation {
         return representation;
     }
 
+    @Override
     public void useParametersFrom(FilterRepresentation a) {
         if (a instanceof FilterBasicRepresentation) {
             FilterBasicRepresentation representation = (FilterBasicRepresentation) a;
@@ -76,6 +80,7 @@ public class FilterBasicRepresentation extends FilterRepresentation {
         return false;
     }
 
+    @Override
     public int getMinimum() {
         return mMinimum;
     }
@@ -84,10 +89,12 @@ public class FilterBasicRepresentation extends FilterRepresentation {
         mMinimum = minimum;
     }
 
+    @Override
     public int getValue() {
         return mValue;
     }
 
+    @Override
     public void setValue(int value) {
         mValue = value;
         if (mValue < mMinimum) {
@@ -98,6 +105,7 @@ public class FilterBasicRepresentation extends FilterRepresentation {
         }
     }
 
+    @Override
     public int getMaximum() {
         return mMaximum;
     }
@@ -110,6 +118,7 @@ public class FilterBasicRepresentation extends FilterRepresentation {
         mDefaultValue = defaultValue;
     }
 
+    @Override
     public int getDefaultValue() {
         return mDefaultValue;
     }
@@ -122,7 +131,27 @@ public class FilterBasicRepresentation extends FilterRepresentation {
         mPreviewValue = previewValue;
     }
 
+    @Override
     public String getStateRepresentation() {
         return "" + getValue();
     }
+
+    @Override
+    public String getParameterType(){
+        return sParameterType;
+    }
+
+    @Override
+    public void setController(Control control) {
+    }
+
+    @Override
+    public String getValueString() {
+        return getStateRepresentation();
+    }
+
+    @Override
+    public String getParameterName() {
+        return getName();
+    }
 }
index 1149263..7ce9e51 100644 (file)
@@ -65,10 +65,6 @@ public class ImageVignette extends ImageShow {
                     mActiveHandle = -1;
                     break;
                 case MotionEvent.ACTION_DOWN:
-                    if (event.getPointerCount() == 1) {
-                        Log.v(LOGTAG, "################### ACTION_DOWN odd " + mActiveHandle
-                                + " touches=1");
-                    }
                     break;
             }
         }