summaryrefslogtreecommitdiffstats
path: root/src/com/android/gallery3d/filtershow/editors
diff options
context:
space:
mode:
authorRuben Brunk <rubenbrunk@google.com>2013-07-18 16:37:30 -0700
committerRuben Brunk <rubenbrunk@google.com>2013-08-01 09:46:44 -0700
commit203eb404a7cd6a80397535e63d22b3772939f03d (patch)
treec6cc970ad5bf9fc710cb3a8a2a667729b2439623 /src/com/android/gallery3d/filtershow/editors
parent3a5bc6b23096365e1a814f8999937028bc12b401 (diff)
downloadandroid_packages_apps_Snap-203eb404a7cd6a80397535e63d22b3772939f03d.tar.gz
android_packages_apps_Snap-203eb404a7cd6a80397535e63d22b3772939f03d.tar.bz2
android_packages_apps_Snap-203eb404a7cd6a80397535e63d22b3772939f03d.zip
Refactoring Geometry handling.
Bug: 9170644 Bug: 9366654 Bug: 9366263 - Consolidates all the geometry transforms in GeometryMathUtils and significantly reduces complexity. - Removes GeometryMetadata object and dependent code. - Removes ImageGeometry and geometry update callbacks. Change-Id: I59add51907459593244c9ebaadef585efc7486d5
Diffstat (limited to 'src/com/android/gallery3d/filtershow/editors')
-rw-r--r--src/com/android/gallery3d/filtershow/editors/Editor.java45
-rw-r--r--src/com/android/gallery3d/filtershow/editors/EditorCrop.java106
-rw-r--r--src/com/android/gallery3d/filtershow/editors/EditorMirror.java (renamed from src/com/android/gallery3d/filtershow/editors/EditorFlip.java)49
-rw-r--r--src/com/android/gallery3d/filtershow/editors/EditorPanel.java17
-rw-r--r--src/com/android/gallery3d/filtershow/editors/EditorRotate.java35
-rw-r--r--src/com/android/gallery3d/filtershow/editors/EditorStraighten.java34
6 files changed, 216 insertions, 70 deletions
diff --git a/src/com/android/gallery3d/filtershow/editors/Editor.java b/src/com/android/gallery3d/filtershow/editors/Editor.java
index 9539d651b..a9e56e0c1 100644
--- a/src/com/android/gallery3d/filtershow/editors/Editor.java
+++ b/src/com/android/gallery3d/filtershow/editors/Editor.java
@@ -31,13 +31,15 @@ import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import com.android.gallery3d.R;
-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;
import com.android.gallery3d.filtershow.pipeline.ImagePreset;
+import java.util.ArrayList;
+import java.util.Collection;
+
/**
* Base class for Editors Must contain a mImageShow and a top level view
*/
@@ -51,6 +53,7 @@ public class Editor implements OnSeekBarChangeListener, SwapButton.SwapButtonLis
protected Button mFilterTitle;
protected int mID;
private final String LOGTAG = "Editor";
+ protected boolean mChangesGeometry = false;
protected FilterRepresentation mLocalRepresentation = null;
protected byte mShowParameter = SHOW_VALUE_UNDEFINED;
private Button mButton;
@@ -206,12 +209,50 @@ public class Editor implements OnSeekBarChangeListener, SwapButton.SwapButtonLis
return mLocalRepresentation;
}
+ /**
+ * Call this to update the preset in MasterImage with the current representation
+ * returned by getLocalRepresentation. This causes the preview bitmap to be
+ * regenerated.
+ */
public void commitLocalRepresentation() {
+ commitLocalRepresentation(getLocalRepresentation());
+ }
+
+ /**
+ * Call this to update the preset in MasterImage with a given representation.
+ * This causes the preview bitmap to be regenerated.
+ */
+ public void commitLocalRepresentation(FilterRepresentation rep) {
+ ArrayList<FilterRepresentation> filter = new ArrayList<FilterRepresentation>(1);
+ filter.add(rep);
+ commitLocalRepresentation(filter);
+ }
+
+ /**
+ * Call this to update the preset in MasterImage with a collection of FilterRepresnations.
+ * This causes the preview bitmap to be regenerated.
+ */
+ public void commitLocalRepresentation(Collection<FilterRepresentation> reps) {
ImagePreset preset = MasterImage.getImage().getPreset();
- preset.updateFilterRepresentation(getLocalRepresentation());
+ preset.updateFilterRepresentations(reps);
if (mButton != null) {
updateText();
}
+ if (mChangesGeometry) {
+ // Regenerate both the filtered and the geometry-only bitmaps
+ MasterImage.getImage().updatePresets(true);
+ } else {
+ // Regenerate only the filtered bitmap.
+ MasterImage.getImage().invalidateFiltersOnly();
+ }
+ preset.fillImageStateAdapter(MasterImage.getImage().getState());
+ }
+
+ /**
+ * This is called in response to a click to apply and leave the editor.
+ */
+ public void finalApplyCalled() {
+ commitLocalRepresentation();
}
protected void updateText() {
diff --git a/src/com/android/gallery3d/filtershow/editors/EditorCrop.java b/src/com/android/gallery3d/filtershow/editors/EditorCrop.java
index ec6e30b7e..511d4ff87 100644
--- a/src/com/android/gallery3d/filtershow/editors/EditorCrop.java
+++ b/src/com/android/gallery3d/filtershow/editors/EditorCrop.java
@@ -17,6 +17,8 @@
package com.android.gallery3d.filtershow.editors;
import android.content.Context;
+import android.util.Log;
+import android.util.SparseArray;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
@@ -26,43 +28,77 @@ import android.widget.LinearLayout;
import android.widget.PopupMenu;
import com.android.gallery3d.R;
-import com.android.gallery3d.filtershow.crop.CropExtras;
+import com.android.gallery3d.filtershow.filters.FilterCropRepresentation;
+import com.android.gallery3d.filtershow.filters.FilterRepresentation;
import com.android.gallery3d.filtershow.imageshow.ImageCrop;
+import com.android.gallery3d.filtershow.imageshow.MasterImage;
public class EditorCrop extends Editor implements EditorInfo {
+ public static final String TAG = EditorCrop.class.getSimpleName();
public static final int ID = R.id.editorCrop;
- private static final String LOGTAG = "EditorCrop";
- ImageCrop mImageCrop;
+ // Holder for an aspect ratio it's string id
+ protected static final class AspectInfo {
+ int mAspectX;
+ int mAspectY;
+ int mStringId;
+ AspectInfo(int stringID, int x, int y) {
+ mStringId = stringID;
+ mAspectX = x;
+ mAspectY = y;
+ }
+ };
+
+ // Mapping from menu id to aspect ratio
+ protected static final SparseArray<AspectInfo> sAspects;
+ static {
+ sAspects = new SparseArray<AspectInfo>();
+ sAspects.put(R.id.crop_menu_1to1, new AspectInfo(R.string.aspect1to1_effect, 1, 1));
+ sAspects.put(R.id.crop_menu_4to3, new AspectInfo(R.string.aspect4to3_effect, 4, 3));
+ sAspects.put(R.id.crop_menu_3to4, new AspectInfo(R.string.aspect3to4_effect, 3, 4));
+ sAspects.put(R.id.crop_menu_5to7, new AspectInfo(R.string.aspect5to7_effect, 5, 7));
+ sAspects.put(R.id.crop_menu_7to5, new AspectInfo(R.string.aspect7to5_effect, 7, 5));
+ sAspects.put(R.id.crop_menu_none, new AspectInfo(R.string.aspectNone_effect, 0, 0));
+ sAspects.put(R.id.crop_menu_original, new AspectInfo(R.string.aspectOriginal_effect, 0, 0));
+ }
+
+ protected ImageCrop mImageCrop;
private String mAspectString = "";
- private boolean mCropActionFlag = false;
- private CropExtras mCropExtras = null;
public EditorCrop() {
super(ID);
+ mChangesGeometry = true;
}
@Override
public void createEditor(Context context, FrameLayout frameLayout) {
super.createEditor(context, frameLayout);
if (mImageCrop == null) {
- // TODO: need this for now because there's extra state in ImageCrop.
- // all the state instead should be in the representation.
- // Same thing for the other geometry editors.
mImageCrop = new ImageCrop(context);
}
mView = mImageShow = mImageCrop;
- mImageCrop.bindAsImageLoadListener();
mImageCrop.setEditor(this);
- mImageCrop.syncLocalToMasterGeometry();
- mImageCrop.setCropActionFlag(mCropActionFlag);
- if (mCropActionFlag) {
- mImageCrop.setExtras(mCropExtras);
- mImageCrop.setAspectString(mAspectString);
- mImageCrop.clear();
+ }
+
+ @Override
+ public void reflectCurrentFilter() {
+ MasterImage master = MasterImage.getImage();
+ master.setCurrentFilterRepresentation(master.getPreset()
+ .getFilterWithSerializationName(FilterCropRepresentation.SERIALIZATION_NAME));
+ super.reflectCurrentFilter();
+ FilterRepresentation rep = getLocalRepresentation();
+ if (rep == null || rep instanceof FilterCropRepresentation) {
+ mImageCrop.setFilterCropRepresentation((FilterCropRepresentation) rep);
} else {
- mImageCrop.setExtras(null);
+ Log.w(TAG, "Could not reflect current filter, not of type: "
+ + FilterCropRepresentation.class.getSimpleName());
}
+ mImageCrop.invalidate();
+ }
+
+ @Override
+ public void finalApplyCalled() {
+ commitLocalRepresentation(mImageCrop.getFinalRepresentation());
}
@Override
@@ -70,27 +106,36 @@ public class EditorCrop extends Editor implements EditorInfo {
Button view = (Button) accessoryViewList.findViewById(R.id.applyEffect);
view.setText(mContext.getString(R.string.crop));
view.setOnClickListener(new OnClickListener() {
-
- @Override
+ @Override
public void onClick(View arg0) {
showPopupMenu(accessoryViewList);
}
});
}
- private void showPopupMenu(LinearLayout accessoryViewList) {
- final Button button = (Button) accessoryViewList.findViewById(
- R.id.applyEffect);
- if (button == null) {
- return;
+ private void changeCropAspect(int itemId) {
+ AspectInfo info = sAspects.get(itemId);
+ if (info == null) {
+ throw new IllegalArgumentException("Invalid resource ID: " + itemId);
}
+ if (itemId == R.id.crop_menu_original) {
+ mImageCrop.applyOriginalAspect();
+ } else if (itemId == R.id.crop_menu_none) {
+ mImageCrop.applyFreeAspect();
+ } else {
+ mImageCrop.applyAspect(info.mAspectX, info.mAspectY);
+ }
+ setAspectString(mContext.getString(info.mStringId));
+ }
+
+ private void showPopupMenu(LinearLayout accessoryViewList) {
+ final Button button = (Button) accessoryViewList.findViewById(R.id.applyEffect);
final PopupMenu popupMenu = new PopupMenu(mImageShow.getActivity(), button);
popupMenu.getMenuInflater().inflate(R.menu.filtershow_menu_crop, popupMenu.getMenu());
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
-
@Override
public boolean onMenuItemClick(MenuItem item) {
- mImageCrop.setAspectButton(item.getItemId());
+ changeCropAspect(item.getItemId());
return true;
}
});
@@ -117,16 +162,7 @@ public class EditorCrop extends Editor implements EditorInfo {
return true;
}
- public void setExtras(CropExtras cropExtras) {
- mCropExtras = cropExtras;
- }
-
- public void setAspectString(String s) {
+ private void setAspectString(String s) {
mAspectString = s;
}
-
- public void setCropActionFlag(boolean b) {
- mCropActionFlag = b;
- }
-
}
diff --git a/src/com/android/gallery3d/filtershow/editors/EditorFlip.java b/src/com/android/gallery3d/filtershow/editors/EditorMirror.java
index 67070045b..d6d9ee75d 100644
--- a/src/com/android/gallery3d/filtershow/editors/EditorFlip.java
+++ b/src/com/android/gallery3d/filtershow/editors/EditorMirror.java
@@ -17,6 +17,7 @@
package com.android.gallery3d.filtershow.editors;
import android.content.Context;
+import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
@@ -24,27 +25,45 @@ import android.widget.FrameLayout;
import android.widget.LinearLayout;
import com.android.gallery3d.R;
-import com.android.gallery3d.filtershow.imageshow.ImageFlip;
+import com.android.gallery3d.filtershow.filters.FilterMirrorRepresentation;
+import com.android.gallery3d.filtershow.filters.FilterRepresentation;
+import com.android.gallery3d.filtershow.imageshow.ImageMirror;
+import com.android.gallery3d.filtershow.imageshow.MasterImage;
-public class EditorFlip extends Editor implements EditorInfo {
- public static final String LOGTAG = "EditorFlip";
+public class EditorMirror extends Editor implements EditorInfo {
+ public static final String TAG = EditorMirror.class.getSimpleName();
public static final int ID = R.id.editorFlip;
- ImageFlip mImageFlip;
+ ImageMirror mImageMirror;
- public EditorFlip() {
+ public EditorMirror() {
super(ID);
+ mChangesGeometry = true;
}
@Override
public void createEditor(Context context, FrameLayout frameLayout) {
super.createEditor(context, frameLayout);
- if (mImageFlip == null) {
- mImageFlip = new ImageFlip(context);
+ if (mImageMirror == null) {
+ mImageMirror = new ImageMirror(context);
}
- mView = mImageShow = mImageFlip;
- mImageFlip.bindAsImageLoadListener();
- mImageFlip.setEditor(this);
- mImageFlip.syncLocalToMasterGeometry();
+ mView = mImageShow = mImageMirror;
+ mImageMirror.setEditor(this);
+ }
+
+ @Override
+ public void reflectCurrentFilter() {
+ MasterImage master = MasterImage.getImage();
+ master.setCurrentFilterRepresentation(master.getPreset()
+ .getFilterWithSerializationName(FilterMirrorRepresentation.SERIALIZATION_NAME));
+ super.reflectCurrentFilter();
+ FilterRepresentation rep = getLocalRepresentation();
+ if (rep == null || rep instanceof FilterMirrorRepresentation) {
+ mImageMirror.setFilterMirrorRepresentation((FilterMirrorRepresentation) rep);
+ } else {
+ Log.w(TAG, "Could not reflect current filter, not of type: "
+ + FilterMirrorRepresentation.class.getSimpleName());
+ }
+ mImageMirror.invalidate();
}
@Override
@@ -53,13 +72,17 @@ public class EditorFlip extends Editor implements EditorInfo {
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
- mImageFlip.flip();
- mImageFlip.saveAndSetPreset();
+ mImageMirror.flip();
}
});
}
@Override
+ public void finalApplyCalled() {
+ commitLocalRepresentation(mImageMirror.getFinalRepresentation());
+ }
+
+ @Override
public int getTextId() {
return R.string.mirror;
}
diff --git a/src/com/android/gallery3d/filtershow/editors/EditorPanel.java b/src/com/android/gallery3d/filtershow/editors/EditorPanel.java
index 40dfccd02..bc4ca6ab6 100644
--- a/src/com/android/gallery3d/filtershow/editors/EditorPanel.java
+++ b/src/com/android/gallery3d/filtershow/editors/EditorPanel.java
@@ -88,17 +88,8 @@ public class EditorPanel extends Fragment {
activity.backToMain();
}
});
- applyButton.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- MasterImage.getImage().invalidateFiltersOnly();
- FilterShowActivity activity = (FilterShowActivity) getActivity();
- activity.backToMain();
- }
- });
Button toggleState = (Button) mMainView.findViewById(R.id.toggle_state);
-
mEditor = activity.getEditor(mEditorID);
if (mEditor != null) {
mEditor.setUpEditorUI(actionControl, editControl, editTitle, toggleState);
@@ -107,6 +98,14 @@ public class EditorPanel extends Fragment {
mEditor.openUtilityPanel((LinearLayout) actionControl);
}
}
+ applyButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ FilterShowActivity activity = (FilterShowActivity) getActivity();
+ mEditor.finalApplyCalled();
+ activity.backToMain();
+ }
+ });
showImageStatePanel(activity.isShowingImageStatePanel());
return mMainView;
diff --git a/src/com/android/gallery3d/filtershow/editors/EditorRotate.java b/src/com/android/gallery3d/filtershow/editors/EditorRotate.java
index e66be2cc1..9452bf0c0 100644
--- a/src/com/android/gallery3d/filtershow/editors/EditorRotate.java
+++ b/src/com/android/gallery3d/filtershow/editors/EditorRotate.java
@@ -17,6 +17,7 @@
package com.android.gallery3d.filtershow.editors;
import android.content.Context;
+import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
@@ -24,15 +25,19 @@ import android.widget.FrameLayout;
import android.widget.LinearLayout;
import com.android.gallery3d.R;
+import com.android.gallery3d.filtershow.filters.FilterRepresentation;
+import com.android.gallery3d.filtershow.filters.FilterRotateRepresentation;
import com.android.gallery3d.filtershow.imageshow.ImageRotate;
+import com.android.gallery3d.filtershow.imageshow.MasterImage;
public class EditorRotate extends Editor implements EditorInfo {
- public static final String LOGTAG = "EditorRotate";
+ public static final String TAG = EditorRotate.class.getSimpleName();
public static final int ID = R.id.editorRotate;
ImageRotate mImageRotate;
public EditorRotate() {
super(ID);
+ mChangesGeometry = true;
}
@Override
@@ -42,9 +47,23 @@ public class EditorRotate extends Editor implements EditorInfo {
mImageRotate = new ImageRotate(context);
}
mView = mImageShow = mImageRotate;
- mImageRotate.bindAsImageLoadListener();
mImageRotate.setEditor(this);
- mImageRotate.syncLocalToMasterGeometry();
+ }
+
+ @Override
+ public void reflectCurrentFilter() {
+ MasterImage master = MasterImage.getImage();
+ master.setCurrentFilterRepresentation(master.getPreset()
+ .getFilterWithSerializationName(FilterRotateRepresentation.SERIALIZATION_NAME));
+ super.reflectCurrentFilter();
+ FilterRepresentation rep = getLocalRepresentation();
+ if (rep == null || rep instanceof FilterRotateRepresentation) {
+ mImageRotate.setFilterRotateRepresentation((FilterRotateRepresentation) rep);
+ } else {
+ Log.w(TAG, "Could not reflect current filter, not of type: "
+ + FilterRotateRepresentation.class.getSimpleName());
+ }
+ mImageRotate.invalidate();
}
@Override
@@ -54,13 +73,19 @@ public class EditorRotate extends Editor implements EditorInfo {
@Override
public void onClick(View arg0) {
mImageRotate.rotate();
- button.setText(mContext.getString(getTextId()) + " " + mImageRotate.getLocalValue());
- mImageRotate.saveAndSetPreset();
+ String displayVal = mContext.getString(getTextId()) + " "
+ + mImageRotate.getLocalValue();
+ button.setText(displayVal);
}
});
}
@Override
+ public void finalApplyCalled() {
+ commitLocalRepresentation(mImageRotate.getFinalRepresentation());
+ }
+
+ @Override
public int getTextId() {
return R.string.rotate;
}
diff --git a/src/com/android/gallery3d/filtershow/editors/EditorStraighten.java b/src/com/android/gallery3d/filtershow/editors/EditorStraighten.java
index 40333aa00..ff84ba8f9 100644
--- a/src/com/android/gallery3d/filtershow/editors/EditorStraighten.java
+++ b/src/com/android/gallery3d/filtershow/editors/EditorStraighten.java
@@ -17,24 +17,26 @@
package com.android.gallery3d.filtershow.editors;
import android.content.Context;
-import android.view.View;
+import android.util.Log;
import android.widget.FrameLayout;
import com.android.gallery3d.R;
-import com.android.gallery3d.filtershow.imageshow.GeometryMetadata;
+import com.android.gallery3d.filtershow.filters.FilterRepresentation;
+import com.android.gallery3d.filtershow.filters.FilterStraightenRepresentation;
import com.android.gallery3d.filtershow.imageshow.ImageStraighten;
+import com.android.gallery3d.filtershow.imageshow.MasterImage;
public class EditorStraighten extends Editor implements EditorInfo {
+ public static final String TAG = EditorStraighten.class.getSimpleName();
public static final int ID = R.id.editorStraighten;
ImageStraighten mImageStraighten;
- GeometryMetadata mGeometryMetadata;
public EditorStraighten() {
super(ID);
mShowParameter = SHOW_VALUE_INT;
+ mChangesGeometry = true;
}
- // TODO use filter reflection like
@Override
public String calculateUserMessage(Context context, String effectName, Object parameterValue) {
String apply = context.getString(R.string.apply_effect);
@@ -49,9 +51,29 @@ public class EditorStraighten extends Editor implements EditorInfo {
mImageStraighten = new ImageStraighten(context);
}
mView = mImageShow = mImageStraighten;
- mImageStraighten.bindAsImageLoadListener();
mImageStraighten.setEditor(this);
- mImageStraighten.syncLocalToMasterGeometry();
+ }
+
+ @Override
+ public void reflectCurrentFilter() {
+ MasterImage master = MasterImage.getImage();
+ master.setCurrentFilterRepresentation(master.getPreset().getFilterWithSerializationName(
+ FilterStraightenRepresentation.SERIALIZATION_NAME));
+ super.reflectCurrentFilter();
+ FilterRepresentation rep = getLocalRepresentation();
+ if (rep == null || rep instanceof FilterStraightenRepresentation) {
+ mImageStraighten
+ .setFilterStraightenRepresentation((FilterStraightenRepresentation) rep);
+ } else {
+ Log.w(TAG, "Could not reflect current filter, not of type: "
+ + FilterStraightenRepresentation.class.getSimpleName());
+ }
+ mImageStraighten.invalidate();
+ }
+
+ @Override
+ public void finalApplyCalled() {
+ commitLocalRepresentation(mImageStraighten.getFinalRepresentation());
}
@Override