More refactoring...
Simplify management of filters in PanelController
bug:7688780
Change-Id: I0d07711cb2be127f064d476c6e98f4363b69b06c
diff --git a/src/com/android/gallery3d/filtershow/PanelController.java b/src/com/android/gallery3d/filtershow/PanelController.java
index 5629e7d..1d9cc22 100644
--- a/src/com/android/gallery3d/filtershow/PanelController.java
+++ b/src/com/android/gallery3d/filtershow/PanelController.java
@@ -42,6 +42,7 @@
import com.android.gallery3d.filtershow.filters.ImageFilterWBalance;
import com.android.gallery3d.filtershow.imageshow.ImageCrop;
import com.android.gallery3d.filtershow.imageshow.ImageShow;
+import com.android.gallery3d.filtershow.imageshow.ImageSmallFilter;
import com.android.gallery3d.filtershow.presets.ImagePreset;
import com.android.gallery3d.filtershow.ui.FramedTextButton;
import com.android.gallery3d.filtershow.ui.ImageCurves;
@@ -58,7 +59,7 @@
private static final String LOGTAG = "PanelController";
private boolean mFixedAspect = false;
- public void setFixedAspect(boolean t){
+ public void setFixedAspect(boolean t) {
mFixedAspect = t;
}
@@ -592,6 +593,27 @@
}
mUtilityPanel.hideAspectButtons();
mUtilityPanel.hideCurvesButtons();
+
+ if (view instanceof ImageSmallFilter) {
+ ImageSmallFilter component = (ImageSmallFilter) view;
+ ImageFilter filter = component.getImageFilter();
+ if (filter.getEditingViewId() != 0) {
+ mCurrentImage = showImageView(filter.getEditingViewId());
+ mCurrentImage.setShowControls(filter.showEditingControls());
+ String ename = mCurrentImage.getContext().getString(filter.getTextId());
+ mUtilityPanel.setEffectName(ename);
+ if (view.getId() == R.id.curvesButtonRGB) {
+ // TODO: delegate to the filter / editing view the management of the
+ // panel accessory view
+ mUtilityPanel.setShowParameter(false);
+ mUtilityPanel.showCurvesButtons();
+ }
+ ensureFilter(ename);
+ mCurrentImage.select();
+ }
+ return;
+ }
+
switch (view.getId()) {
case R.id.tinyplanetButton: {
mCurrentImage = showImageView(R.id.imageTinyPlanet).setShowControls(true);
@@ -611,11 +633,11 @@
String ename = mCurrentImage.getContext().getString(R.string.crop);
mUtilityPanel.setEffectName(ename);
mUtilityPanel.setShowParameter(false);
- if (mCurrentImage instanceof ImageCrop && mUtilityPanel.firstTimeCropDisplayed){
+ if (mCurrentImage instanceof ImageCrop && mUtilityPanel.firstTimeCropDisplayed) {
((ImageCrop) mCurrentImage).clear();
mUtilityPanel.firstTimeCropDisplayed = false;
}
- if (!mFixedAspect){
+ if (!mFixedAspect) {
mUtilityPanel.showAspectButtons();
}
break;
@@ -633,87 +655,6 @@
mUtilityPanel.setShowParameter(false);
break;
}
- case R.id.vignetteButton: {
- mCurrentImage = showImageView(R.id.imageShow).setShowControls(true);
- String ename = mCurrentImage.getContext().getString(R.string.vignette);
- mUtilityPanel.setEffectName(ename);
- ensureFilter(ename);
- break;
- }
- case R.id.curvesButtonRGB: {
- ImageCurves curves = (ImageCurves) showImageView(R.id.imageCurves);
- String ename = curves.getContext().getString(R.string.curvesRGB);
- mUtilityPanel.setEffectName(ename);
- mUtilityPanel.setShowParameter(false);
- mUtilityPanel.showCurvesButtons();
- mCurrentImage = curves;
- ensureFilter(ename);
- break;
- }
- case R.id.sharpenButton: {
- mCurrentImage = showImageView(R.id.imageZoom).setShowControls(true);
- String ename = mCurrentImage.getContext().getString(R.string.sharpness);
- mUtilityPanel.setEffectName(ename);
- ensureFilter(ename);
- break;
- }
- case R.id.contrastButton: {
- mCurrentImage = showImageView(R.id.imageShow).setShowControls(true);
- String ename = mCurrentImage.getContext().getString(R.string.contrast);
- mUtilityPanel.setEffectName(ename);
- ensureFilter(ename);
- break;
- }
- case R.id.saturationButton: {
- mCurrentImage = showImageView(R.id.imageShow).setShowControls(true);
- String ename = mCurrentImage.getContext().getString(R.string.saturation);
- mUtilityPanel.setEffectName(ename);
- ensureFilter(ename);
- break;
- }
- case R.id.bwfilterButton: {
- mCurrentImage = showImageView(R.id.imageShow).setShowControls(true);
- String ename = mCurrentImage.getContext().getString(R.string.bwfilter);
- mUtilityPanel.setEffectName(ename);
- ensureFilter(ename);
- break;
- }
- case R.id.wbalanceButton: {
- mCurrentImage = showImageView(R.id.imageShow).setShowControls(false);
- String ename = mCurrentImage.getContext().getString(R.string.wbalance);
- mUtilityPanel.setEffectName(ename);
- mUtilityPanel.setShowParameter(false);
- ensureFilter(ename);
- break;
- }
- case R.id.hueButton: {
- mCurrentImage = showImageView(R.id.imageShow).setShowControls(true);
- String ename = mCurrentImage.getContext().getString(R.string.hue);
- mUtilityPanel.setEffectName(ename);
- ensureFilter(ename);
- break;
- }
- case R.id.exposureButton: {
- mCurrentImage = showImageView(R.id.imageShow).setShowControls(true);
- String ename = mCurrentImage.getContext().getString(R.string.exposure);
- mUtilityPanel.setEffectName(ename);
- ensureFilter(ename);
- break;
- }
- case R.id.vibranceButton: {
- mCurrentImage = showImageView(R.id.imageShow).setShowControls(true);
- String ename = mCurrentImage.getContext().getString(R.string.vibrance);
- mUtilityPanel.setEffectName(ename);
- ensureFilter(ename);
- break;
- }
- case R.id.shadowRecoveryButton: {
- mCurrentImage = showImageView(R.id.imageShow).setShowControls(true);
- String ename = mCurrentImage.getContext().getString(R.string.shadow_recovery);
- mUtilityPanel.setEffectName(ename);
- ensureFilter(ename);
- break;
- }
case R.id.redEyeButton: {
mCurrentImage = showImageView(R.id.imageRedEyes).setShowControls(true);
String ename = mCurrentImage.getContext().getString(R.string.redeye);
diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilter.java b/src/com/android/gallery3d/filtershow/filters/ImageFilter.java
index 2009449..5c24fbf 100644
--- a/src/com/android/gallery3d/filtershow/filters/ImageFilter.java
+++ b/src/com/android/gallery3d/filtershow/filters/ImageFilter.java
@@ -18,6 +18,7 @@
import android.graphics.Bitmap;
+import com.android.gallery3d.R;
import com.android.gallery3d.filtershow.presets.ImagePreset;
public class ImageFilter implements Cloneable {
@@ -31,19 +32,19 @@
protected String mName = "Original";
private final String LOGTAG = "ImageFilter";
- public static final byte TYPE_BORDER =1;
- public static final byte TYPE_FX = 2;
+ public static final byte TYPE_BORDER = 1;
+ public static final byte TYPE_FX = 2;
public static final byte TYPE_WBALANCE = 3;
public static final byte TYPE_VIGNETTE = 4;
public static final byte TYPE_NORMAL = 5;
public static final byte TYPE_TINYPLANET = 6;
private byte filterType = TYPE_NORMAL;
- public byte getFilterType(){
+ public byte getFilterType() {
return filterType;
}
- protected void setFilterType(byte type){
+ protected void setFilterType(byte type) {
filterType = type;
}
@@ -59,6 +60,14 @@
return 0;
}
+ public int getEditingViewId() {
+ return R.id.imageShow;
+ }
+
+ public boolean showEditingControls() {
+ return true;
+ }
+
@Override
public ImageFilter clone() throws CloneNotSupportedException {
ImageFilter filter = (ImageFilter) super.clone();
@@ -105,7 +114,7 @@
* The maximum allowed value (inclusive)
* @return maximum value allowed as input to this filter
*/
- public int getMaxParameter(){
+ public int getMaxParameter() {
return mMaxParameter;
}
@@ -113,7 +122,7 @@
* The parameter value to be used in previews.
* @return parameter value to be used to preview the filter
*/
- public int getPreviewParameter(){
+ public int getPreviewParameter() {
return mPreviewParameter;
}
@@ -121,7 +130,7 @@
* The minimum allowed value (inclusive)
* @return minimum value allowed as input to this filter
*/
- public int getMinParameter(){
+ public int getMinParameter() {
return mMinParameter;
}
@@ -129,7 +138,7 @@
* Returns the default value returned by this filter.
* @return default value
*/
- public int getDefaultParameter(){
+ public int getDefaultParameter() {
return mDefaultParameter;
}
diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterCurves.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterCurves.java
index dda9699..46a00f4 100644
--- a/src/com/android/gallery3d/filtershow/filters/ImageFilterCurves.java
+++ b/src/com/android/gallery3d/filtershow/filters/ImageFilterCurves.java
@@ -47,6 +47,11 @@
}
@Override
+ public int getEditingViewId() {
+ return R.id.imageCurves;
+ }
+
+ @Override
public ImageFilter clone() throws CloneNotSupportedException {
ImageFilterCurves filter = (ImageFilterCurves) super.clone();
for (int i = 0; i < 4; i++) {
diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterRedEye.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterRedEye.java
index ff7027c..9ae6f51 100644
--- a/src/com/android/gallery3d/filtershow/filters/ImageFilterRedEye.java
+++ b/src/com/android/gallery3d/filtershow/filters/ImageFilterRedEye.java
@@ -20,6 +20,7 @@
import android.graphics.Matrix;
import android.graphics.RectF;
+import com.android.gallery3d.R;
import com.android.gallery3d.filtershow.imageshow.GeometryMetadata;
import java.util.Vector;
@@ -33,6 +34,21 @@
}
@Override
+ public int getButtonId() {
+ return R.id.redEyeButton;
+ }
+
+ @Override
+ public int getTextId() {
+ return R.string.redeye;
+ }
+
+ @Override
+ public int getEditingViewId() {
+ return R.id.imageRedEyes;
+ }
+
+ @Override
public ImageFilter clone() throws CloneNotSupportedException {
ImageFilterRedEye filter = (ImageFilterRedEye) super.clone();
if (mCandidates != null) {
diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterSharpen.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterSharpen.java
index b551c51..1951b9b 100644
--- a/src/com/android/gallery3d/filtershow/filters/ImageFilterSharpen.java
+++ b/src/com/android/gallery3d/filtershow/filters/ImageFilterSharpen.java
@@ -43,6 +43,11 @@
}
@Override
+ public int getEditingViewId() {
+ return R.id.imageZoom;
+ }
+
+ @Override
public void createFilter(android.content.res.Resources res, float scaleFactor,
boolean highQuality) {
int w = mInPixelsAllocation.getType().getX();
diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterWBalance.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterWBalance.java
index b2842f2..8665dc5 100644
--- a/src/com/android/gallery3d/filtershow/filters/ImageFilterWBalance.java
+++ b/src/com/android/gallery3d/filtershow/filters/ImageFilterWBalance.java
@@ -38,13 +38,17 @@
return R.string.wbalance;
}
+ public boolean showEditingControls() {
+ return false;
+ }
+
native protected void nativeApplyFilter(Bitmap bitmap, int w, int h, int locX, int locY);
@Override
public Bitmap apply(Bitmap bitmap, float scaleFactor, boolean highQuality) {
int w = bitmap.getWidth();
int h = bitmap.getHeight();
- nativeApplyFilter(bitmap, w, h, -1,-1);
+ nativeApplyFilter(bitmap, w, h, -1, -1);
return bitmap;
}
diff --git a/src/com/android/gallery3d/filtershow/imageshow/ImageSmallFilter.java b/src/com/android/gallery3d/filtershow/imageshow/ImageSmallFilter.java
index 358f4fb..2a3ee28 100644
--- a/src/com/android/gallery3d/filtershow/imageshow/ImageSmallFilter.java
+++ b/src/com/android/gallery3d/filtershow/imageshow/ImageSmallFilter.java
@@ -84,6 +84,10 @@
mImagePreset.add(mImageFilter);
}
+ public ImageFilter getImageFilter() {
+ return mImageFilter;
+ }
+
@Override
public void setSelected(boolean value) {
if (mIsSelected != value) {