make basic editor based on ParametricEditor
Change-Id: Ie0a799d7e85f4e21fdd86ffbdca9814a3cc40c61
diff --git a/src/com/android/gallery3d/filtershow/controller/BasicSlider.java b/src/com/android/gallery3d/filtershow/controller/BasicSlider.java
index c54fe77..df5b6ae 100644
--- a/src/com/android/gallery3d/filtershow/controller/BasicSlider.java
+++ b/src/com/android/gallery3d/filtershow/controller/BasicSlider.java
@@ -34,6 +34,7 @@
@Override
public void setUp(ViewGroup container, Parameter parameter, Editor editor) {
+ container.removeAllViews();
mEditor = editor;
Context context = container.getContext();
mParameter = (ParameterInteger) parameter;
diff --git a/src/com/android/gallery3d/filtershow/controller/ParameterStyles.java b/src/com/android/gallery3d/filtershow/controller/ParameterStyles.java
new file mode 100644
index 0000000..c267d3d
--- /dev/null
+++ b/src/com/android/gallery3d/filtershow/controller/ParameterStyles.java
@@ -0,0 +1,37 @@
+/*
+ * 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 com.android.gallery3d.filtershow.cache.RenderingRequestCaller;
+
+public interface ParameterStyles extends Parameter {
+ public static String sParameterType = "ParameterStyles";
+
+ int getNumberOfStyles();
+
+ int getDefaultSelected();
+
+ int getSelected();
+
+ void setSelected(int value);
+
+ void getIcon(int index, RenderingRequestCaller caller);
+
+ String getStyleTitle(int index, Context context);
+}
diff --git a/src/com/android/gallery3d/filtershow/controller/StyleChooser.java b/src/com/android/gallery3d/filtershow/controller/StyleChooser.java
new file mode 100644
index 0000000..201f661
--- /dev/null
+++ b/src/com/android/gallery3d/filtershow/controller/StyleChooser.java
@@ -0,0 +1,102 @@
+package com.android.gallery3d.filtershow.controller;
+
+import android.content.Context;
+import android.content.res.Resources;
+import android.graphics.Bitmap;
+import android.graphics.drawable.BitmapDrawable;
+import android.graphics.drawable.ScaleDrawable;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.Button;
+import android.widget.LinearLayout;
+
+import com.android.gallery3d.R;
+import com.android.gallery3d.filtershow.cache.RenderingRequest;
+import com.android.gallery3d.filtershow.cache.RenderingRequestCaller;
+import com.android.gallery3d.filtershow.editors.Editor;
+
+import java.util.Vector;
+
+public class StyleChooser implements Control, RenderingRequestCaller {
+ private final String LOGTAG = "StyleChooser";
+ protected ParameterStyles mParameter;
+ protected LinearLayout mLinearLayout;
+ protected Editor mEditor;
+ private View mTopView;
+ private int mProcessingButton = 0;
+ private Vector<Button> mIconButton = new Vector<Button>();
+ protected int mLayoutID = R.layout.filtershow_control_style_chooser;
+
+ @Override
+ public void setUp(ViewGroup container, Parameter parameter, Editor editor) {
+ container.removeAllViews();
+ mEditor = editor;
+ Context context = container.getContext();
+ mParameter = (ParameterStyles) parameter;
+ LayoutInflater inflater =
+ (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+ mTopView = inflater.inflate(mLayoutID, container, true);
+ mLinearLayout = (LinearLayout) mTopView.findViewById(R.id.listStyles);
+ mTopView.setVisibility(View.VISIBLE);
+ int n = mParameter.getNumberOfStyles();
+ mIconButton.clear();
+ for (int i = 0; i < n; i++) {
+ Button button = new Button(context);
+ mIconButton.add(button);
+ final int buttonNo = i;
+ button.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View arg0) {
+ mParameter.setSelected(buttonNo);
+ }
+ });
+ mLinearLayout.addView(button);
+ }
+ mProcessingButton = 0;
+ mParameter.getIcon(mProcessingButton, this);
+ }
+
+ @Override
+ public View getTopView() {
+ return mTopView;
+ }
+
+ @Override
+ public void setPrameter(Parameter parameter) {
+ mParameter = (ParameterStyles) parameter;
+ updateUI();
+ }
+
+ @Override
+ public void updateUI() {
+ if (mParameter == null) {
+ return;
+ }
+ }
+
+ @Override
+ public void available(RenderingRequest request) {
+ Bitmap bmap = request.getBitmap();
+ if (bmap == null) {
+ return;
+ }
+
+ try {
+ Button button = mIconButton.get(mProcessingButton);
+ Resources res = mLinearLayout.getContext().getResources();
+ BitmapDrawable drawable = new BitmapDrawable(res, bmap);
+ float scale = 12000 / (float) button.getWidth();
+ ScaleDrawable sd = new ScaleDrawable(drawable, 0, scale, scale);
+
+ button.setCompoundDrawablesWithIntrinsicBounds(null, sd, null, null);
+ } catch (Exception e) {
+ return;
+ }
+
+ mProcessingButton++;
+ if (mProcessingButton < mParameter.getNumberOfStyles())
+ mParameter.getIcon(mProcessingButton, this);
+ }
+
+}
diff --git a/src/com/android/gallery3d/filtershow/controller/TitledSlider.java b/src/com/android/gallery3d/filtershow/controller/TitledSlider.java
index 30b6fdb..cbaa489 100644
--- a/src/com/android/gallery3d/filtershow/controller/TitledSlider.java
+++ b/src/com/android/gallery3d/filtershow/controller/TitledSlider.java
@@ -40,6 +40,7 @@
@Override
public void setUp(ViewGroup container, Parameter parameter, Editor editor) {
+ container.removeAllViews();
mEditor = editor;
Context context = container.getContext();
mParameter = (ParameterInteger) parameter;
diff --git a/src/com/android/gallery3d/filtershow/editors/BasicEditor.java b/src/com/android/gallery3d/filtershow/editors/BasicEditor.java
index 2ff9c04..d9e9724 100644
--- a/src/com/android/gallery3d/filtershow/editors/BasicEditor.java
+++ b/src/com/android/gallery3d/filtershow/editors/BasicEditor.java
@@ -1,5 +1,5 @@
/*
- * 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.
@@ -17,42 +17,31 @@
package com.android.gallery3d.filtershow.editors;
import android.content.Context;
-import android.view.View;
-import android.widget.FrameLayout;
-import android.widget.SeekBar;
-import android.widget.SeekBar.OnSeekBarChangeListener;
import com.android.gallery3d.R;
+import com.android.gallery3d.filtershow.controller.Control;
+import com.android.gallery3d.filtershow.controller.ParameterInteger;
import com.android.gallery3d.filtershow.filters.FilterBasicRepresentation;
+import com.android.gallery3d.filtershow.filters.FilterRepresentation;
+
/**
* The basic editor that all the one parameter filters
*/
-public class BasicEditor extends Editor {
+public class BasicEditor extends ParametricEditor implements ParameterInteger {
public static int ID = R.id.basicEditor;
-
- private final String LOGTAG = "Editor";
- private int mLayoutID = R.layout.filtershow_default_editor;
- private int mViewID = R.id.basicEditor;
+ private final String LOGTAG = "BasicEditor";
public BasicEditor() {
- super(ID);
+ super(ID, R.layout.filtershow_default_editor, R.id.basicEditor);
}
protected BasicEditor(int id) {
- super(id);
+ super(id, R.layout.filtershow_default_editor, R.id.basicEditor);
}
protected BasicEditor(int id, int layoutID, int viewID) {
- super(id);
- mLayoutID = layoutID;
- mViewID = viewID;
- }
-
- @Override
- public void createEditor(Context context, FrameLayout frameLayout) {
- super.createEditor(context, frameLayout);
- unpack(mViewID, mLayoutID);
+ super(id, layoutID, viewID);
}
@Override
@@ -60,36 +49,81 @@
super.reflectCurrentFilter();
if (getLocalRepresentation() != null && getLocalRepresentation() instanceof FilterBasicRepresentation) {
FilterBasicRepresentation interval = (FilterBasicRepresentation) getLocalRepresentation();
- boolean f = interval.showParameterValue();
- mSeekBar.setVisibility((f) ? View.VISIBLE : View.GONE);
- int value = interval.getValue();
- int min = interval.getMinimum();
- int max = interval.getMaximum();
- mSeekBar.setMax(max - min);
- mSeekBar.setProgress(value - min);
+ Context context = mContext;
+ interval.getTextId();
+
}
}
- @Override
- public void onProgressChanged(SeekBar sbar, int progress, boolean arg2) {
- if (getLocalRepresentation() != null && getLocalRepresentation() instanceof FilterBasicRepresentation) {
- FilterBasicRepresentation interval = (FilterBasicRepresentation) getLocalRepresentation();
- int value = progress + interval.getMinimum();
- interval.setValue(value);
- mImageShow.onNewValue(value);
- mView.invalidate();
- if (interval.showParameterValue()) {
- mPanelController.onNewValue(value);
- }
- commitLocalRepresentation();
+ private FilterBasicRepresentation getBasicRepresentation() {
+ FilterRepresentation tmpRep = getLocalRepresentation();
+ if (tmpRep != null && tmpRep instanceof FilterBasicRepresentation) {
+ return (FilterBasicRepresentation) tmpRep;
+
}
+ return null;
}
@Override
- public void onStartTrackingTouch(SeekBar arg0) {
+ public int getMaximum() {
+ FilterBasicRepresentation rep = getBasicRepresentation();
+ if (rep == null) {
+ return 0;
+ }
+ return rep.getMaximum();
}
@Override
- public void onStopTrackingTouch(SeekBar arg0) {
+ public int getMinimum() {
+ FilterBasicRepresentation rep = getBasicRepresentation();
+ if (rep == null) {
+ return 0;
+ }
+ return rep.getMinimum();
}
+
+ @Override
+ public int getDefaultValue() {
+ return 0;
+ }
+
+ @Override
+ public int getValue() {
+ FilterBasicRepresentation rep = getBasicRepresentation();
+ if (rep == null) {
+ return 0;
+ }
+ return rep.getValue();
+ }
+
+ @Override
+ public String getValueString() {
+ return null;
+ }
+
+ @Override
+ public void setValue(int value) {
+ FilterBasicRepresentation rep = getBasicRepresentation();
+ if (rep == null) {
+ return;
+ }
+ rep.setValue(value);
+ commitLocalRepresentation();
+ }
+
+ @Override
+ public String getParameterName() {
+ FilterBasicRepresentation rep = getBasicRepresentation();
+ return mContext.getString(rep.getTextId());
+ }
+
+ @Override
+ public String getParameterType() {
+ return sParameterType;
+ }
+
+ @Override
+ public void setController(Control c) {
+ }
+
}
diff --git a/src/com/android/gallery3d/filtershow/editors/ParametricEditor.java b/src/com/android/gallery3d/filtershow/editors/ParametricEditor.java
index cf00f4a..9c275d4 100644
--- a/src/com/android/gallery3d/filtershow/editors/ParametricEditor.java
+++ b/src/com/android/gallery3d/filtershow/editors/ParametricEditor.java
@@ -34,6 +34,8 @@
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.ParameterStyles;
+import com.android.gallery3d.filtershow.controller.StyleChooser;
import com.android.gallery3d.filtershow.controller.TitledSlider;
import com.android.gallery3d.filtershow.filters.FilterBasicRepresentation;
import com.android.gallery3d.filtershow.filters.FilterRepresentation;
@@ -49,7 +51,8 @@
protected Control mControl;
public static final int MINIMUM_WIDTH = 600;
public static final int MINIMUM_HEIGHT = 800;
-
+ View mActionButton;
+ View mEditControl;
static HashMap<String, Class> portraitMap = new HashMap<String, Class>();
static HashMap<String, Class> landscapeMap = new HashMap<String, Class>();
static {
@@ -57,6 +60,8 @@
landscapeMap.put(ParameterInteger.sParameterType, TitledSlider.class);
portraitMap.put(ParameterActionAndInt.sParameterType, ActionSlider.class);
landscapeMap.put(ParameterActionAndInt.sParameterType, ActionSlider.class);
+ portraitMap.put(ParameterStyles.sParameterType, StyleChooser.class);
+ landscapeMap.put(ParameterStyles.sParameterType, StyleChooser.class);
}
static Constructor getConstructor(Class cl) {
@@ -122,7 +127,7 @@
};
}
- // TODO: need a better way to decide when which representation
+ // TODO: need a better way to decide which representation
static boolean useCompact(Context context) {
WindowManager w = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE));
Point size = new Point();
@@ -139,13 +144,23 @@
return false;
}
+ protected Parameter getParameterToEdit(FilterRepresentation rep) {
+ if (this instanceof Parameter) {
+ return (Parameter) this;
+ } else if (rep instanceof Parameter) {
+ return ((Parameter) rep);
+ }
+ return null;
+ }
+
@Override
public void setUtilityPanelUI(View actionButton, View editControl) {
+ mActionButton = actionButton;
+ mEditControl = editControl;
FilterRepresentation rep = getLocalRepresentation();
- if (this instanceof Parameter) {
- control((Parameter) this, editControl);
- } else if (rep instanceof Parameter) {
- control((Parameter) rep, editControl);
+ Parameter param = getParameterToEdit(rep);
+ if (param != null) {
+ control(param, editControl);
} else {
mSeekBar = new SeekBar(editControl.getContext());
LayoutParams lp = new LinearLayout.LayoutParams(
@@ -164,8 +179,10 @@
if (c != null) {
try {
mControl = (Control) c.newInstance();
+ p.setController(mControl);
mControl.setUp((ViewGroup) editControl, p, this);
+
} catch (Exception e) {
Log.e(LOGTAG, "Error in loading Control ", e);
}