OSDN Git Service

refactor the geometry code
authorJohn Hoford <hoford@google.com>
Wed, 27 Feb 2013 16:41:19 +0000 (08:41 -0800)
committerJohn Hoford <hoford@google.com>
Thu, 28 Feb 2013 01:32:01 +0000 (17:32 -0800)
Change-Id: I5b0381ec5e127aabf37924af64fbeb490755bc9a

24 files changed:
res/layout/filtershow_activity.xml
res/values/filtershow_ids.xml
src/com/android/gallery3d/filtershow/EditorPlaceHolder.java
src/com/android/gallery3d/filtershow/FilterShowActivity.java
src/com/android/gallery3d/filtershow/PanelController.java
src/com/android/gallery3d/filtershow/cache/ImageLoader.java
src/com/android/gallery3d/filtershow/editors/EditorCrop.java [new file with mode: 0644]
src/com/android/gallery3d/filtershow/editors/EditorFlip.java [new file with mode: 0644]
src/com/android/gallery3d/filtershow/editors/EditorInfo.java [new file with mode: 0644]
src/com/android/gallery3d/filtershow/editors/EditorRotate.java [new file with mode: 0644]
src/com/android/gallery3d/filtershow/editors/EditorStraighten.java [new file with mode: 0644]
src/com/android/gallery3d/filtershow/filters/BaseFiltersManager.java
src/com/android/gallery3d/filtershow/filters/FilterRepresentation.java
src/com/android/gallery3d/filtershow/filters/ImageFilterGeometry.java
src/com/android/gallery3d/filtershow/imageshow/GeometryMetadata.java
src/com/android/gallery3d/filtershow/imageshow/ImageCrop.java
src/com/android/gallery3d/filtershow/imageshow/ImageFlip.java
src/com/android/gallery3d/filtershow/imageshow/ImageGeometry.java
src/com/android/gallery3d/filtershow/imageshow/ImageRotate.java
src/com/android/gallery3d/filtershow/imageshow/ImageStraighten.java
src/com/android/gallery3d/filtershow/imageshow/MasterImage.java
src/com/android/gallery3d/filtershow/presets/ImagePreset.java
src/com/android/gallery3d/filtershow/ui/FilterIconButton.java
src_pd/com/android/gallery3d/filtershow/editors/EditorManager.java

index e811ec7..0f94f92 100644 (file)
                 android:layout_width="match_parent"
                 android:layout_height="wrap_content" />
 
-            <com.android.gallery3d.filtershow.imageshow.ImageStraighten
-                android:id="@+id/imageStraighten"
-                android:layout_width="match_parent"
-                android:layout_height="wrap_content"
-                android:visibility="gone" />
-
-            <com.android.gallery3d.filtershow.imageshow.ImageCrop
-                android:id="@+id/imageCrop"
-                android:layout_width="match_parent"
-                android:layout_height="wrap_content"
-                android:visibility="gone" />
-
-            <com.android.gallery3d.filtershow.imageshow.ImageRotate
-                android:id="@+id/imageRotate"
-                android:layout_width="match_parent"
-                android:layout_height="wrap_content"
-                android:visibility="gone" />
-
-            <com.android.gallery3d.filtershow.imageshow.ImageFlip
-                android:id="@+id/imageFlip"
-                android:layout_width="match_parent"
-                android:layout_height="wrap_content"
-                android:visibility="gone" />
-
             <com.android.gallery3d.filtershow.imageshow.ImageTinyPlanet
                 android:id="@+id/imageTinyPlanet"
                 android:layout_width="match_parent"
                     android:layout_width="wrap_content"
                     android:layout_height="fill_parent"
                     android:layout_gravity="left"
-                    android:orientation="horizontal">
-
-                    <com.android.gallery3d.filtershow.ui.IconButton
-                        android:id="@+id/straightenButton"
-                        android:layout_height="match_parent"
-                        style="@style/IconButton"
-                        android:drawableTop="@drawable/filtershow_button_geometry_straighten"
-                        android:text="@string/straighten" />
-
-                    <com.android.gallery3d.filtershow.ui.IconButton
-                        android:id="@+id/cropButton"
-                        android:layout_height="match_parent"
-                        style="@style/IconButton"
-                        android:drawableTop="@drawable/filtershow_button_geometry_crop"
-                        android:text="@string/crop" />
-
-                    <com.android.gallery3d.filtershow.ui.IconButton
-                        android:id="@+id/rotateButton"
-                        android:layout_height="match_parent"
-                        style="@style/IconButton"
-                        android:drawableTop="@drawable/filtershow_button_geometry_rotate"
-                        android:text="@string/rotate" />
-
-                    <com.android.gallery3d.filtershow.ui.IconButton
-                        android:id="@+id/flipButton"
-                        android:layout_height="match_parent"
-                        style="@style/IconButton"
-                        android:drawableTop="@drawable/filtershow_button_geometry_flip"
-                        android:text="@string/mirror" />
+                    android:orientation="horizontal" />
 
-                </LinearLayout>
             </HorizontalScrollView>
 
             <HorizontalScrollView
index 28e7816..9380740 100644 (file)
@@ -42,4 +42,8 @@
     <item type="id" name="editorRedEye" />
     <item type="id" name="imageOnlyEditor" />
     <item type="id" name="vignetteEditor" />
+    <item type="id" name="editorCrop" />
+    <item type="id" name="editorFlip" />
+    <item type="id" name="editorRotate" />
+    <item type="id" name="editorStraighten" />
 </resources>
index dee9d2e..4cba0e3 100644 (file)
@@ -79,4 +79,8 @@ public class EditorPlaceHolder {
     public void setImageLoader(ImageLoader imageLoader) {
         mImageLoader = imageLoader;
     }
+
+    public Editor getEditor(int editorId) {
+        return mEditors.get(editorId);
+    }
 }
index 516a192..7401a1c 100644 (file)
@@ -53,12 +53,18 @@ import com.android.gallery3d.data.LocalAlbum;
 import com.android.gallery3d.filtershow.cache.FilteringPipeline;
 import com.android.gallery3d.filtershow.cache.ImageLoader;
 import com.android.gallery3d.filtershow.editors.BasicEditor;
+import com.android.gallery3d.filtershow.editors.EditorCrop;
 import com.android.gallery3d.filtershow.editors.EditorDraw;
+import com.android.gallery3d.filtershow.editors.EditorFlip;
+import com.android.gallery3d.filtershow.editors.EditorInfo;
 import com.android.gallery3d.filtershow.editors.EditorManager;
 import com.android.gallery3d.filtershow.editors.EditorRedEye;
+import com.android.gallery3d.filtershow.editors.EditorRotate;
+import com.android.gallery3d.filtershow.editors.EditorStraighten;
 import com.android.gallery3d.filtershow.editors.ImageOnlyEditor;
 import com.android.gallery3d.filtershow.editors.EditorTinyPlanet;
 import com.android.gallery3d.filtershow.filters.*;
+import com.android.gallery3d.filtershow.imageshow.GeometryMetadata;
 import com.android.gallery3d.filtershow.imageshow.ImageCrop;
 import com.android.gallery3d.filtershow.imageshow.ImageFlip;
 import com.android.gallery3d.filtershow.imageshow.ImageRotate;
@@ -96,10 +102,6 @@ public class FilterShowActivity extends Activity implements OnItemClickListener,
     private final PanelController mPanelController = new PanelController();
     private ImageLoader mImageLoader = null;
     private ImageShow mImageShow = null;
-    private ImageStraighten mImageStraighten = null;
-    private ImageCrop mImageCrop = null;
-    private ImageRotate mImageRotate = null;
-    private ImageFlip mImageFlip = null;
     private ImageTinyPlanet mImageTinyPlanet = null;
 
     private View mSaveButton = null;
@@ -175,22 +177,13 @@ public class FilterShowActivity extends Activity implements OnItemClickListener,
         });
 
         mImageLoader = new ImageLoader(this, getApplicationContext());
-
         mImageShow = (ImageShow) findViewById(R.id.imageShow);
-        mImageStraighten = (ImageStraighten) findViewById(R.id.imageStraighten);
-        mImageCrop = (ImageCrop) findViewById(R.id.imageCrop);
-        mImageRotate = (ImageRotate) findViewById(R.id.imageRotate);
-        mImageFlip = (ImageFlip) findViewById(R.id.imageFlip);
         mImageTinyPlanet = (ImageTinyPlanet) findViewById(R.id.imageTinyPlanet);
 
-        mImageCrop.setAspectTextSize((int) getPixelsFromDip(18));
+        ImageCrop.setAspectTextSize((int) getPixelsFromDip(18));
         ImageCrop.setTouchTolerance((int) getPixelsFromDip(25));
         ImageCrop.setMinCropSize((int) getPixelsFromDip(55));
         mImageViews.add(mImageShow);
-        mImageViews.add(mImageStraighten);
-        mImageViews.add(mImageCrop);
-        mImageViews.add(mImageRotate);
-        mImageViews.add(mImageFlip);
         mImageViews.add(mImageTinyPlanet);
 
         mEditorPlaceHolder.setContainer((FrameLayout) findViewById(R.id.editorContainer));
@@ -199,6 +192,10 @@ public class FilterShowActivity extends Activity implements OnItemClickListener,
         mEditorPlaceHolder.addEditor(new ImageOnlyEditor());
         mEditorPlaceHolder.addEditor(new EditorTinyPlanet());
         mEditorPlaceHolder.addEditor(new EditorRedEye());
+        mEditorPlaceHolder.addEditor(new EditorCrop());
+        mEditorPlaceHolder.addEditor(new EditorFlip());
+        mEditorPlaceHolder.addEditor(new EditorRotate());
+        mEditorPlaceHolder.addEditor(new EditorStraighten());
         EditorManager.addEditors(mEditorPlaceHolder);
         mEditorPlaceHolder.setOldViews(mImageViews);
         mEditorPlaceHolder.setImageLoader(mImageLoader);
@@ -211,30 +208,32 @@ public class FilterShowActivity extends Activity implements OnItemClickListener,
         mColorsButton = (ImageButton) findViewById(R.id.colorsButton);
 
         mImageShow.setImageLoader(mImageLoader);
-        mImageStraighten.setImageLoader(mImageLoader);
-        mImageCrop.setImageLoader(mImageLoader);
-        mImageRotate.setImageLoader(mImageLoader);
-        mImageFlip.setImageLoader(mImageLoader);
         mImageTinyPlanet.setImageLoader(mImageLoader);
 
         mPanelController.setActivity(this);
         mPanelController.setEditorPlaceHolder(mEditorPlaceHolder);
 
         mPanelController.addImageView(findViewById(R.id.imageShow));
-        mPanelController.addImageView(findViewById(R.id.imageStraighten));
-        mPanelController.addImageView(findViewById(R.id.imageCrop));
-        mPanelController.addImageView(findViewById(R.id.imageRotate));
-        mPanelController.addImageView(findViewById(R.id.imageFlip));
         mPanelController.addImageView(findViewById(R.id.imageTinyPlanet));
 
         mPanelController.addPanel(mFxButton, findViewById(R.id.fxList), 0);
         mPanelController.addPanel(mBorderButton, findViewById(R.id.bordersList), 1);
-
         mPanelController.addPanel(mGeometryButton, findViewById(R.id.geometryList), 2);
-        mPanelController.addComponent(mGeometryButton, findViewById(R.id.straightenButton));
-        mPanelController.addComponent(mGeometryButton, findViewById(R.id.cropButton));
-        mPanelController.addComponent(mGeometryButton, findViewById(R.id.rotateButton));
-        mPanelController.addComponent(mGeometryButton, findViewById(R.id.flipButton));
+
+        // TODO: move to a separate function.
+        GeometryMetadata geo = new GeometryMetadata();
+        int[] editorsId = geo.getEditorIds();
+        for (int i = 0; i < editorsId.length; i++) {
+            int editorId = editorsId[i];
+            GeometryMetadata geometry = new GeometryMetadata(geo);
+            geometry.setEditorId(editorId);
+            EditorInfo editorInfo = (EditorInfo) mEditorPlaceHolder.getEditor(editorId);
+            geometry.setTextId(editorInfo.getTextId());
+            geometry.setOverlayId(editorInfo.getOverlayId());
+            geometry.setOverlayOnly(editorInfo.getOverlayOnly());
+            setupFilterRepresentationButton(
+                    geometry, (LinearLayout) findViewById(R.id.listGeometry), mGeometryButton);
+        }
 
         mPanelController.addPanel(mColorsButton, findViewById(R.id.colorsFxList), 3);
 
@@ -305,10 +304,11 @@ public class FilterShowActivity extends Activity implements OnItemClickListener,
                 }
                 mImageShow.getImagePreset().mGeoData.setCropExtras(mCropExtras);
 
-                mImageCrop.setExtras(mCropExtras);
+                // FIXME: moving to editors breaks the crop action
+//                mImageCrop.setExtras(mCropExtras);
                 String s = getString(R.string.Fixed);
-                mImageCrop.setAspectString(s);
-                mImageCrop.setCropActionFlag(true);
+//                mImageCrop.setAspectString(s);
+//                mImageCrop.setCropActionFlag(true);
                 mPanelController.setFixedAspect(mCropExtras.getAspectX() > 0
                         && mCropExtras.getAspectY() > 0);
             }
@@ -470,7 +470,8 @@ public class FilterShowActivity extends Activity implements OnItemClickListener,
             mLoadBitmapTask = null;
 
             if (mAction == CROP_ACTION) {
-                mPanelController.showComponent(findViewById(R.id.cropButton));
+                // FIXME: broken by the move to editors
+                // mPanelController.showComponent(findViewById(R.id.cropButton));
             } else if (mAction == TINY_PLANET_ACTION) {
                 mPanelController.showComponent(findViewById(R.id.tinyplanetButton));
             }
index 3c3de89..519733e 100644 (file)
@@ -31,6 +31,7 @@ import com.android.gallery3d.filtershow.filters.FilterRepresentation;
 import com.android.gallery3d.filtershow.filters.ImageFilter;
 import com.android.gallery3d.filtershow.filters.ImageFilterTinyPlanet;
 import com.android.gallery3d.filtershow.imageshow.ImageCrop;
+import com.android.gallery3d.filtershow.imageshow.ImageGeometry;
 import com.android.gallery3d.filtershow.imageshow.ImageShow;
 import com.android.gallery3d.filtershow.imageshow.MasterImage;
 import com.android.gallery3d.filtershow.presets.ImagePreset;
@@ -155,7 +156,6 @@ public class PanelController implements OnClickListener {
         private String mEffectName = null;
         private int mParameterValue = 0;
         private boolean mShowParameterValue = false;
-        boolean firstTimeCropDisplayed = true;
 
         public UtilityPanel(Context context, View view, View accessoryViewList,
                 View textView) {
@@ -532,44 +532,10 @@ public class PanelController implements OnClickListener {
                 mUtilityPanel.setEffectName(ename);
                 break;
             }
-            case R.id.straightenButton: {
-                mCurrentImage = showImageView(R.id.imageStraighten);
-                String ename = mCurrentImage.getContext().getString(R.string.straighten);
-                mUtilityPanel.setEffectName(ename);
-                break;
-            }
-            case R.id.cropButton: {
-                mCurrentImage = showImageView(R.id.imageCrop);
-                String ename = mCurrentImage.getContext().getString(R.string.crop);
-                mUtilityPanel.setEffectName(ename);
-                mUtilityPanel.setShowParameter(false);
-                if (mCurrentImage instanceof ImageCrop && mUtilityPanel.firstTimeCropDisplayed) {
-                    ((ImageCrop) mCurrentImage).clear();
-                    mUtilityPanel.firstTimeCropDisplayed = false;
-                    ((ImageCrop) mCurrentImage).setFixedAspect(mFixedAspect);
-                }
-                break;
-            }
-            case R.id.rotateButton: {
-                mCurrentImage = showImageView(R.id.imageRotate);
-                String ename = mCurrentImage.getContext().getString(R.string.rotate);
-                mUtilityPanel.setEffectName(ename);
-                break;
-            }
-            case R.id.flipButton: {
-                mCurrentImage = showImageView(R.id.imageFlip);
-                String ename = mCurrentImage.getContext().getString(R.string.mirror);
-                mUtilityPanel.setEffectName(ename);
-                mUtilityPanel.setShowParameter(false);
-                break;
-            }
             case R.id.applyEffect: {
                 if (MasterImage.getImage().getCurrentFilter() instanceof ImageFilterTinyPlanet) {
                     mActivity.saveImage();
                 } else {
-                    if (mCurrentImage instanceof ImageCrop) {
-                        ((ImageCrop) mCurrentImage).saveAndSetPreset();
-                    }
                     showPanel(mCurrentPanel);
                 }
                 MasterImage.getImage().invalidateFiltersOnly();
index b5ed9ee..d284a03 100644 (file)
@@ -28,6 +28,7 @@ import android.graphics.BitmapRegionDecoder;
 import android.graphics.Matrix;
 import android.graphics.Rect;
 import android.graphics.Bitmap.CompressFormat;
+import android.graphics.RectF;
 import android.media.ExifInterface;
 import android.net.Uri;
 import android.provider.MediaStore;
@@ -44,8 +45,10 @@ import com.android.gallery3d.exif.ExifTag;
 import com.android.gallery3d.filtershow.CropExtras;
 import com.android.gallery3d.filtershow.FilterShowActivity;
 import com.android.gallery3d.filtershow.HistoryAdapter;
+import com.android.gallery3d.filtershow.imageshow.GeometryMetadata;
 import com.android.gallery3d.filtershow.imageshow.ImageCrop;
 import com.android.gallery3d.filtershow.imageshow.ImageShow;
+import com.android.gallery3d.filtershow.imageshow.MasterImage;
 import com.android.gallery3d.filtershow.presets.ImagePreset;
 import com.android.gallery3d.filtershow.tools.BitmapTask;
 import com.android.gallery3d.filtershow.tools.SaveCopyTask;
@@ -131,6 +134,15 @@ public class ImageLoader {
             return false;
         }
         updateBitmaps();
+        // TODO: cleanup
+        GeometryMetadata geo = MasterImage.getImage().getPreset().mGeoData;
+        float w = mOriginalBitmapLarge.getWidth();
+        float h = mOriginalBitmapLarge.getHeight();
+        RectF r = new RectF(0, 0, w, h);
+        geo.setPhotoBounds(r);
+        geo.setCropBounds(r);
+        MasterImage.getImage().getPreset().setGeometry(geo);
+        MasterImage.getImage().notifyGeometryChange();
         mLoadingLock.unlock();
         return true;
     }
diff --git a/src/com/android/gallery3d/filtershow/editors/EditorCrop.java b/src/com/android/gallery3d/filtershow/editors/EditorCrop.java
new file mode 100644 (file)
index 0000000..53e07ab
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * 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.widget.FrameLayout;
+
+import com.android.gallery3d.R;
+import com.android.gallery3d.filtershow.imageshow.ImageCrop;
+import com.android.gallery3d.filtershow.imageshow.MasterImage;
+
+public class EditorCrop extends Editor implements EditorInfo {
+    public static final int ID = R.id.editorCrop;
+    private static final String LOGTAG = "EditorCrop";
+
+    ImageCrop mImageCrop;
+
+    public EditorCrop() {
+        super(ID);
+    }
+
+    @Override
+    public void createEditor(Context context, FrameLayout frameLayout) {
+        super.createEditor(context, frameLayout);
+        mView = mImageShow = mImageCrop = new ImageCrop(context);
+        mImageCrop.setImageLoader(MasterImage.getImage().getImageLoader());
+        mImageCrop.setEditor(this);
+        mImageCrop.syncLocalToMasterGeometry();
+    }
+
+    @Override
+    public int getTextId() {
+        return R.string.crop;
+    }
+
+    @Override
+    public int getOverlayId() {
+        return R.drawable.filtershow_button_geometry_crop;
+    }
+
+    @Override
+    public boolean getOverlayOnly() {
+        return true;
+    }
+}
diff --git a/src/com/android/gallery3d/filtershow/editors/EditorFlip.java b/src/com/android/gallery3d/filtershow/editors/EditorFlip.java
new file mode 100644 (file)
index 0000000..bc04c11
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * 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.widget.FrameLayout;
+
+import com.android.gallery3d.R;
+import com.android.gallery3d.filtershow.imageshow.ImageFlip;
+import com.android.gallery3d.filtershow.imageshow.MasterImage;
+
+public class EditorFlip extends Editor implements EditorInfo {
+    public static final int ID = R.id.editorFlip;
+    ImageFlip mImageFlip;
+
+    public EditorFlip() {
+        super(ID);
+    }
+
+    @Override
+    public void createEditor(Context context, FrameLayout frameLayout) {
+        super.createEditor(context, frameLayout);
+        mView = mImageShow = mImageFlip = new ImageFlip(context);
+        mImageFlip.setImageLoader(MasterImage.getImage().getImageLoader());
+        mImageFlip.setEditor(this);
+        mImageFlip.syncLocalToMasterGeometry();
+    }
+
+    @Override
+    public int getTextId() {
+        return R.string.mirror;
+    }
+
+    @Override
+    public int getOverlayId() {
+        return R.drawable.filtershow_button_geometry_flip;
+    }
+
+    @Override
+    public boolean getOverlayOnly() {
+        return true;
+    }
+}
diff --git a/src/com/android/gallery3d/filtershow/editors/EditorInfo.java b/src/com/android/gallery3d/filtershow/editors/EditorInfo.java
new file mode 100644 (file)
index 0000000..75afe49
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+ * 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;
+
+public interface EditorInfo {
+    public int getTextId();
+    public int getOverlayId();
+    public boolean getOverlayOnly();
+}
diff --git a/src/com/android/gallery3d/filtershow/editors/EditorRotate.java b/src/com/android/gallery3d/filtershow/editors/EditorRotate.java
new file mode 100644 (file)
index 0000000..1385ec8
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * 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.widget.FrameLayout;
+
+import com.android.gallery3d.R;
+import com.android.gallery3d.filtershow.imageshow.ImageRotate;
+import com.android.gallery3d.filtershow.imageshow.MasterImage;
+
+public class EditorRotate extends Editor implements EditorInfo {
+    public static final int ID = R.id.editorRotate;
+    ImageRotate mImageRotate;
+
+    public EditorRotate() {
+        super(ID);
+    }
+
+    @Override
+    public void createEditor(Context context, FrameLayout frameLayout) {
+        super.createEditor(context, frameLayout);
+        mView = mImageShow = mImageRotate = new ImageRotate(context);
+        mImageRotate.setImageLoader(MasterImage.getImage().getImageLoader());
+        mImageRotate.setEditor(this);
+        mImageRotate.syncLocalToMasterGeometry();
+    }
+
+    @Override
+    public int getTextId() {
+        return R.string.rotate;
+    }
+
+    @Override
+    public int getOverlayId() {
+        return R.drawable.filtershow_button_geometry_rotate;
+    }
+
+    @Override
+    public boolean getOverlayOnly() {
+        return true;
+    }
+}
diff --git a/src/com/android/gallery3d/filtershow/editors/EditorStraighten.java b/src/com/android/gallery3d/filtershow/editors/EditorStraighten.java
new file mode 100644 (file)
index 0000000..0925589
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * 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.widget.FrameLayout;
+
+import com.android.gallery3d.R;
+import com.android.gallery3d.filtershow.imageshow.ImageStraighten;
+import com.android.gallery3d.filtershow.imageshow.MasterImage;
+
+public class EditorStraighten extends Editor implements EditorInfo {
+    public static final int ID = R.id.editorStraighten;
+    ImageStraighten mImageStraighten;
+
+    public EditorStraighten() {
+        super(ID);
+    }
+
+    @Override
+    public void createEditor(Context context, FrameLayout frameLayout) {
+        super.createEditor(context, frameLayout);
+        mView = mImageShow = mImageStraighten = new ImageStraighten(context);
+        mImageStraighten.setImageLoader(MasterImage.getImage().getImageLoader());
+        mImageStraighten.setEditor(this);
+        mImageStraighten.syncLocalToMasterGeometry();
+    }
+
+    @Override
+    public int getTextId() {
+        return R.string.straighten;
+    }
+
+    @Override
+    public int getOverlayId() {
+        return R.drawable.filtershow_button_geometry_straighten;
+    }
+
+    @Override
+    public boolean getOverlayOnly() {
+        return true;
+    }
+}
index 4dbf91a..820bdbf 100644 (file)
@@ -44,6 +44,8 @@ public abstract class BaseFiltersManager {
         filters.put(ImageFilterFx.class, new ImageFilterFx());
         filters.put(ImageFilterBorder.class, new ImageFilterBorder());
         filters.put(ImageFilterParametricBorder.class, new ImageFilterParametricBorder());
+        filters.put(ImageFilterGeometry.class, new ImageFilterGeometry());
+
     }
 
     public ImageFilter getFilter(Class c) {
index 83f2a1b..5dd72c9 100644 (file)
@@ -30,6 +30,7 @@ public class FilterRepresentation implements Cloneable {
     private int mEditorId = BasicEditor.ID;
     private int mButtonId = 0;
     private int mOverlayId = 0;
+    private boolean mOverlayOnly = false;
     private boolean mShowEditingControls = true;
     private boolean mShowParameterValue = true;
     private boolean mShowUtilityPanel = true;
@@ -58,6 +59,7 @@ public class FilterRepresentation implements Cloneable {
         representation.setEditorId(getEditorId());
         representation.setButtonId(getButtonId());
         representation.setOverlayId(getOverlayId());
+        representation.setOverlayOnly(getOverlayOnly());
         representation.setShowEditingControls(showEditingControls());
         representation.setShowParameterValue(showParameterValue());
         representation.setShowUtilityPanel(showUtilityPanel());
@@ -77,6 +79,7 @@ public class FilterRepresentation implements Cloneable {
                 && representation.mEditorId == mEditorId
                 && representation.mButtonId == mButtonId
                 && representation.mOverlayId == mOverlayId
+                && representation.mOverlayOnly == mOverlayOnly
                 && representation.mShowEditingControls == mShowEditingControls
                 && representation.mShowParameterValue == mShowParameterValue
                 && representation.mShowUtilityPanel == mShowUtilityPanel) {
@@ -181,10 +184,23 @@ public class FilterRepresentation implements Cloneable {
         mOverlayId = overlayId;
     }
 
-    public int getEditorId() {
+    public boolean getOverlayOnly() {
+        return mOverlayOnly;
+    }
+
+    public void setOverlayOnly(boolean value) {
+        mOverlayOnly = value;
+    }
+
+    final public int getEditorId() {
         return mEditorId;
     }
 
+    public int[] getEditorIds() {
+        return new int[] {
+        mEditorId };
+    }
+
     public void setEditorId(int editorId) {
         mEditorId = editorId;
     }
index 329ca81..cbb443f 100644 (file)
@@ -50,10 +50,6 @@ public class ImageFilterGeometry extends ImageFilter {
         return filter;
     }
 
-    public void setGeometryMetadata(GeometryMetadata m) {
-        mGeometry = m;
-    }
-
     native protected void nativeApplyFilterFlip(Bitmap src, int srcWidth, int srcHeight,
             Bitmap dst, int dstWidth, int dstHeight, int flip);
 
@@ -68,7 +64,7 @@ public class ImageFilterGeometry extends ImageFilter {
 
     @Override
     public void useRepresentation(FilterRepresentation representation) {
-
+        mGeometry = (GeometryMetadata) representation;
     }
 
     @Override
index a3645d6..647b101 100644 (file)
@@ -23,10 +23,14 @@ import android.graphics.RectF;
 
 import com.android.gallery3d.filtershow.CropExtras;
 import com.android.gallery3d.filtershow.cache.ImageLoader;
+import com.android.gallery3d.filtershow.editors.EditorCrop;
+import com.android.gallery3d.filtershow.editors.EditorFlip;
+import com.android.gallery3d.filtershow.editors.EditorRotate;
+import com.android.gallery3d.filtershow.editors.EditorStraighten;
+import com.android.gallery3d.filtershow.filters.FilterRepresentation;
 import com.android.gallery3d.filtershow.filters.ImageFilterGeometry;
 
-public class GeometryMetadata {
-    private static final ImageFilterGeometry mImageFilter = new ImageFilterGeometry();
+public class GeometryMetadata extends FilterRepresentation {
     private static final String LOGTAG = "GeometryMetadata";
     private float mScaleFactor = 1.0f;
     private float mRotation = 0;
@@ -59,9 +63,25 @@ public class GeometryMetadata {
     }
 
     public GeometryMetadata() {
+        super("GeometryMetadata");
+        setFilterClass(ImageFilterGeometry.class);
+        setEditorId(EditorCrop.ID);
+        setName("Crop");
+        setTextId(0);
+    }
+
+    @Override
+    public int[] getEditorIds() {
+        return new int[] {
+                EditorCrop.ID,
+                EditorStraighten.ID,
+                EditorRotate.ID,
+                EditorFlip.ID
+        };
     }
 
     public GeometryMetadata(GeometryMetadata g) {
+        super("GeometryMetadata");
         set(g);
     }
 
@@ -86,15 +106,6 @@ public class GeometryMetadata {
         return false;
     }
 
-    public Bitmap apply(Bitmap original, float scaleFactor, int quality) {
-        if (!hasModifications()) {
-            return original;
-        }
-        mImageFilter.setGeometryMetadata(this);
-        Bitmap m = mImageFilter.apply(original, scaleFactor, quality);
-        return m;
-    }
-
     public void set(GeometryMetadata g) {
         mScaleFactor = g.mScaleFactor;
         mRotation = g.mRotation;
@@ -436,4 +447,17 @@ public class GeometryMetadata {
         m.preRotate(-straighten, photo.centerX(), photo.centerY());
         return m;
     }
+
+    @Override
+    public void useParametersFrom(FilterRepresentation a) {
+        GeometryMetadata data = (GeometryMetadata) a;
+        set(data);
+    }
+
+    @Override
+    public FilterRepresentation clone() throws CloneNotSupportedException {
+        GeometryMetadata representation = (GeometryMetadata) super.clone();
+        representation.useParametersFrom(this);
+        return representation;
+    }
 }
index 284bfde..beaa93d 100644 (file)
@@ -37,6 +37,8 @@ import android.widget.PopupMenu;
 
 import com.android.gallery3d.R;
 import com.android.gallery3d.filtershow.CropExtras;
+import com.android.gallery3d.filtershow.editors.EditorCrop;
+import com.android.gallery3d.filtershow.filters.FilterCurvesRepresentation;
 import com.android.gallery3d.filtershow.ui.FramedTextButton;
 
 public class ImageCrop extends ImageGeometry {
@@ -81,11 +83,13 @@ public class ImageCrop extends ImageGeometry {
     private static final String LOGTAG = "ImageCrop";
 
     private String mAspect = "";
-    private int mAspectTextSize = 24;
+    private static int mAspectTextSize = 24;
 
     private boolean mFixedAspect = false;
 
-    public void setAspectTextSize(int textSize) {
+    private EditorCrop mEditorCrop;
+
+    public static void setAspectTextSize(int textSize) {
         mAspectTextSize = textSize;
     }
 
@@ -779,4 +783,8 @@ public class ImageCrop extends ImageGeometry {
         }
     }
 
+    public void setEditor(EditorCrop editorCrop) {
+        mEditorCrop = editorCrop;
+    }
+
 }
index 6bfba1b..70637a3 100644 (file)
@@ -24,6 +24,7 @@ import android.graphics.RectF;
 import android.util.AttributeSet;
 
 import com.android.gallery3d.R;
+import com.android.gallery3d.filtershow.editors.EditorFlip;
 import com.android.gallery3d.filtershow.imageshow.GeometryMetadata.FLIP;
 
 public class ImageFlip extends ImageGeometry {
@@ -32,6 +33,7 @@ public class ImageFlip extends ImageGeometry {
     private static final float MIN_FLICK_DIST_FOR_FLIP = 0.1f;
     private static final String LOGTAG = "ImageFlip";
     private FLIP mNextFlip = FLIP.NONE;
+    private EditorFlip mEditorFlip;
 
     public ImageFlip(Context context, AttributeSet attrs) {
         super(context, attrs);
@@ -140,4 +142,8 @@ public class ImageFlip extends ImageGeometry {
         drawTransformedCropped(canvas, image, gPaint);
     }
 
+    public void setEditor(EditorFlip editorFlip) {
+        mEditorFlip = editorFlip;
+    }
+
 }
index e18f0d0..352329e 100644 (file)
@@ -138,7 +138,7 @@ public abstract class ImageGeometry extends ImageShow {
     }
 
     // Overwrites local with master
-    protected void syncLocalToMasterGeometry() {
+    public void syncLocalToMasterGeometry() {
         mLocalGeometry = getGeometry();
         calculateLocalScalingFactorAndOffset();
     }
@@ -423,6 +423,7 @@ public abstract class ImageGeometry extends ImageShow {
             return;
         }
         mHasDrawn = true;
+
         drawShape(canvas, image);
     }
 
index 30cc9e2..c4b9aa2 100644 (file)
@@ -23,6 +23,7 @@ import android.graphics.Paint;
 import android.util.AttributeSet;
 
 import com.android.gallery3d.R;
+import com.android.gallery3d.filtershow.editors.EditorRotate;
 
 public class ImageRotate extends ImageGeometry {
 
@@ -30,6 +31,7 @@ public class ImageRotate extends ImageGeometry {
     private float mAngle = 0;
 
     private final boolean mSnapToNinety = true;
+    private EditorRotate mEditorRotate;
     private static final String LOGTAG = "ImageRotate";
 
     public ImageRotate(Context context, AttributeSet attrs) {
@@ -84,4 +86,8 @@ public class ImageRotate extends ImageGeometry {
         gPaint.setARGB(255, 255, 255, 255);
         drawTransformedCropped(canvas, image, gPaint);
     }
+
+    public void setEditor(EditorRotate editorRotate) {
+        mEditorRotate = editorRotate;
+    }
 }
index dfd9505..be116bd 100644 (file)
@@ -26,11 +26,13 @@ import android.graphics.RectF;
 import android.util.AttributeSet;
 
 import com.android.gallery3d.R;
+import com.android.gallery3d.filtershow.editors.EditorStraighten;
 
 public class ImageStraighten extends ImageGeometry {
 
     private float mBaseAngle = 0;
     private float mAngle = 0;
+    private EditorStraighten mEditorStraighten;
 
     private static final String LOGTAG = "ImageStraighten";
     private static final Paint gPaint = new Paint();
@@ -134,4 +136,8 @@ public class ImageStraighten extends ImageGeometry {
         }
     }
 
+    public void setEditor(EditorStraighten editorStraighten) {
+        mEditorStraighten = editorStraighten;
+    }
+
 }
index 9eafe22..4ca7430 100644 (file)
@@ -17,6 +17,7 @@
 package com.android.gallery3d.filtershow.imageshow;
 
 import android.graphics.*;
+import android.util.Log;
 
 import com.android.gallery3d.filtershow.FilterShowActivity;
 import com.android.gallery3d.filtershow.HistoryAdapter;
@@ -208,7 +209,8 @@ public class MasterImage implements RenderingRequestCaller {
         if (force || mGeometryOnlyPreset == null) {
             ImagePreset newPreset = new ImagePreset(mPreset);
             newPreset.setDoApplyFilters(false);
-            if (mGeometryOnlyPreset == null
+            newPreset.setDoApplyGeometry(true);
+            if (force || mGeometryOnlyPreset == null
                     || !newPreset.same(mGeometryOnlyPreset)) {
                 mGeometryOnlyPreset = newPreset;
                 RenderingRequest.post(mLoader.getOriginalBitmapLarge(),
@@ -217,8 +219,9 @@ public class MasterImage implements RenderingRequestCaller {
         }
         if (force || mFiltersOnlyPreset == null) {
             ImagePreset newPreset = new ImagePreset(mPreset);
+            newPreset.setDoApplyFilters(true);
             newPreset.setDoApplyGeometry(false);
-            if (mFiltersOnlyPreset == null
+            if (force || mFiltersOnlyPreset == null
                     || !newPreset.same(mFiltersOnlyPreset)) {
                 mFiltersOnlyPreset = newPreset;
                 RenderingRequest.post(mLoader.getOriginalBitmapLarge(),
@@ -330,6 +333,7 @@ public class MasterImage implements RenderingRequestCaller {
     }
 
     public void notifyGeometryChange() {
+        updatePresets(true);
         for (GeometryListener listener : mGeometryListeners) {
             listener.geometryChanged();
         }
index 1400fd4..7ceed73 100644 (file)
@@ -130,9 +130,13 @@ public class ImagePreset {
 
     public void updateFilterRepresentation(FilterRepresentation representation) {
         synchronized (mFilters) {
-            int position = getPositionForRepresentation(representation);
-            FilterRepresentation old = mFilters.elementAt(position);
-            old.updateTempParametersFrom(representation);
+            if (representation instanceof GeometryMetadata) {
+                setGeometry((GeometryMetadata) representation);
+            } else {
+                int position = getPositionForRepresentation(representation);
+                FilterRepresentation old = mFilters.elementAt(position);
+                old.updateTempParametersFrom(representation);
+            }
         }
         MasterImage.getImage().invalidatePreview();
     }
@@ -191,6 +195,7 @@ public class ImagePreset {
 
     public synchronized void setGeometry(GeometryMetadata m) {
         mGeoData.set(m);
+        MasterImage.getImage().notifyGeometryChange();
     }
 
     private void setBorder(FilterRepresentation filter) {
@@ -327,7 +332,10 @@ public class ImagePreset {
     }
 
     public void addFilter(FilterRepresentation representation) {
-        Log.v(LOGTAG, "*** Add Filter *** " + representation);
+        if (representation instanceof GeometryMetadata) {
+            setGeometry((GeometryMetadata) representation);
+            return;
+        }
         if (representation.getPriority() == FilterRepresentation.TYPE_BORDER) {
             setHistoryName(representation.getName());
             setBorder(representation);
@@ -359,6 +367,9 @@ public class ImagePreset {
     }
 
     public FilterRepresentation getRepresentation(FilterRepresentation filterRepresentation) {
+        if (filterRepresentation instanceof GeometryMetadata) {
+            return mGeoData;
+        }
         for (int i = 0; i < mFilters.size(); i++) {
             FilterRepresentation representation = mFilters.elementAt(i);
             if (representation.getFilterClass() == filterRepresentation.getFilterClass()) {
@@ -384,7 +395,14 @@ public class ImagePreset {
     public Bitmap applyGeometry(Bitmap bitmap) {
         // Apply any transform -- 90 rotate, flip, straighten, crop
         // Returns a new bitmap.
-        return mGeoData.apply(bitmap, mScaleFactor, mQuality);
+        if (mDoApplyGeometry) {
+            ImageFilter filter = FiltersManager.getManager().getFilterForRepresentation(mGeoData);
+            mGeoData.synchronizeRepresentation();
+            filter.useRepresentation(mGeoData);
+            filter.setImagePreset(this);
+            bitmap = filter.apply(bitmap, mScaleFactor, mQuality);
+        }
+        return bitmap;
     }
 
     public Bitmap applyBorder(Bitmap bitmap) {
index de2e1e5..746ad12 100644 (file)
@@ -21,6 +21,7 @@ import android.graphics.Bitmap;
 import android.graphics.BitmapFactory;
 import android.graphics.Rect;
 import android.util.AttributeSet;
+import android.util.Log;
 import android.view.View;
 import android.widget.LinearLayout;
 
@@ -30,6 +31,7 @@ import com.android.gallery3d.filtershow.cache.RenderingRequest;
 import com.android.gallery3d.filtershow.cache.RenderingRequestCaller;
 import com.android.gallery3d.filtershow.filters.FilterRepresentation;
 import com.android.gallery3d.filtershow.imageshow.GeometryListener;
+import com.android.gallery3d.filtershow.imageshow.GeometryMetadata;
 import com.android.gallery3d.filtershow.imageshow.MasterImage;
 import com.android.gallery3d.filtershow.presets.ImagePreset;
 
@@ -37,6 +39,7 @@ public class FilterIconButton extends IconButton implements View.OnClickListener
         RenderingRequestCaller, GeometryListener {
     private static final String LOGTAG = "FilterIconButton";
     private Bitmap mOverlayBitmap = null;
+    private boolean mOverlayOnly = false;
     private PanelController mController = null;
     private FilterRepresentation mFilterRepresentation = null;
     private LinearLayout mParentContainer = null;
@@ -68,6 +71,10 @@ public class FilterIconButton extends IconButton implements View.OnClickListener
 
     @Override
     protected Bitmap drawImage(Bitmap dst, Bitmap image, Rect destination) {
+        if (mOverlayOnly) {
+            // TODO: merge back IconButton and FilterIconButton
+            return super.drawImage(dst, image, destination);
+        }
         if (mIconBitmap == null && mPreset == null) {
             ImageLoader loader = MasterImage.getImage().getLoader();
             if (loader != null) {
@@ -76,6 +83,7 @@ public class FilterIconButton extends IconButton implements View.OnClickListener
                 dst = super.drawImage(dst, image, destination);
                 ImagePreset mPreset = new ImagePreset();
                 mPreset.addFilter(mFilterRepresentation);
+                mPreset.setDoApplyGeometry(false);
                 mDestination = destination;
                 RenderingRequest.post(dst.copy(Bitmap.Config.ARGB_8888, true), mPreset, RenderingRequest.ICON_RENDERING, this);
             }
@@ -112,6 +120,10 @@ public class FilterIconButton extends IconButton implements View.OnClickListener
             mOverlayBitmap = BitmapFactory.decodeResource(getResources(),
                     mFilterRepresentation.getOverlayId());
         }
+        mOverlayOnly = mFilterRepresentation.getOverlayOnly();
+        if (mOverlayOnly) {
+            setIcon(mOverlayBitmap);
+        }
         invalidate();
     }
 
@@ -131,6 +143,7 @@ public class FilterIconButton extends IconButton implements View.OnClickListener
     @Override
     public void geometryChanged() {
         stale_icon = true;
+
         mIconBitmap = null;
         mPreset = null;
         invalidate();
index 92962cb..2a39b68 100644 (file)
@@ -29,6 +29,10 @@ public class EditorManager {
         editorPlaceHolder.addEditor(new EditorTinyPlanet());
         editorPlaceHolder.addEditor(new EditorDraw());
         editorPlaceHolder.addEditor(new EditorVignette());
+        editorPlaceHolder.addEditor(new EditorFlip());
+        editorPlaceHolder.addEditor(new EditorRotate());
+        editorPlaceHolder.addEditor(new EditorStraighten());
+        editorPlaceHolder.addEditor(new EditorCrop());
     }
 
 }