OSDN Git Service

Fix tiny planet to work with the new framework
authorJohn Hoford <hoford@google.com>
Fri, 8 Feb 2013 01:39:06 +0000 (17:39 -0800)
committerJohn Hoford <hoford@google.com>
Sat, 9 Feb 2013 00:08:07 +0000 (16:08 -0800)
Change-Id: I57e87ade6f2cfdfee1b237cdfdf5914244ee98aa

res/layout/filtershow_tiny_planet_editor.xml [new file with mode: 0644]
src/com/android/gallery3d/filtershow/FilterShowActivity.java
src/com/android/gallery3d/filtershow/editors/EditorTinyPlanet.java [new file with mode: 0644]
src/com/android/gallery3d/filtershow/filters/FilterTinyPlanetRepresentation.java [new file with mode: 0644]
src/com/android/gallery3d/filtershow/filters/ImageFilterDraw.java
src/com/android/gallery3d/filtershow/filters/ImageFilterTinyPlanet.java
src/com/android/gallery3d/filtershow/imageshow/ImageTinyPlanet.java
src_pd/com/android/gallery3d/filtershow/editors/EditorManager.java

diff --git a/res/layout/filtershow_tiny_planet_editor.xml b/res/layout/filtershow_tiny_planet_editor.xml
new file mode 100644 (file)
index 0000000..a99e406
--- /dev/null
@@ -0,0 +1,46 @@
+<?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.
+-->
+
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:iconbutton="http://schemas.android.com/apk/res/com.android.gallery3d"
+     android:id="@+id/tinyPlanetEditor"
+    android:layout_width="match_parent"
+    android:layout_height="wrap_content"
+    android:layout_weight="1" >
+
+    <com.android.gallery3d.filtershow.imageshow.ImageTinyPlanet
+        android:id="@+id/imageTinyPlanet"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content" />
+
+        <com.android.gallery3d.filtershow.CenteredLinearLayout
+            xmlns:custom="http://schemas.android.com/apk/res/com.android.gallery3d"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:layout_gravity="center_horizontal|bottom"
+            android:background="@android:color/transparent"
+            custom:max_width="600dip"
+            android:orientation="vertical">
+
+            <SeekBar
+                android:id="@+id/filterSeekBar"
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:layout_gravity="bottom"
+                android:padding="16dip"/>
+    </com.android.gallery3d.filtershow.CenteredLinearLayout>
+ </FrameLayout>
\ No newline at end of file
index 051ffaf..bf17a65 100644 (file)
@@ -65,6 +65,7 @@ import com.android.gallery3d.filtershow.editors.BasicEditor;
 import com.android.gallery3d.filtershow.editors.EditorDraw;
 import com.android.gallery3d.filtershow.editors.EditorManager;
 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.ImageCrop;
 import com.android.gallery3d.filtershow.imageshow.ImageDraw;
@@ -225,6 +226,7 @@ public class FilterShowActivity extends Activity implements OnItemClickListener,
         mEditorPlaceHolder.addEditor(new EditorDraw());
         mEditorPlaceHolder.addEditor(new BasicEditor());
         mEditorPlaceHolder.addEditor(new ImageOnlyEditor());
+        mEditorPlaceHolder.addEditor(new EditorTinyPlanet());
         EditorManager.addEditors(mEditorPlaceHolder);
         mEditorPlaceHolder.setOldViews(mImageViews);
         mEditorPlaceHolder.setImageLoader(mImageLoader);
diff --git a/src/com/android/gallery3d/filtershow/editors/EditorTinyPlanet.java b/src/com/android/gallery3d/filtershow/editors/EditorTinyPlanet.java
new file mode 100644 (file)
index 0000000..4f30dc1
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2012 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.util.Log;
+import android.widget.FrameLayout;
+
+import com.android.gallery3d.R;
+import com.android.gallery3d.filtershow.filters.FilterRepresentation;
+import com.android.gallery3d.filtershow.filters.FilterTinyPlanetRepresentation;
+import com.android.gallery3d.filtershow.imageshow.ImageTinyPlanet;
+
+public class EditorTinyPlanet extends BasicEditor {
+    public static final int ID = R.id.tinyPlanetEditor;
+    private static final String LOGTAG = "EditorTinyPlanet";
+    ImageTinyPlanet mImageTinyPlanet;
+
+    public EditorTinyPlanet() {
+        super(ID, R.layout.filtershow_tiny_planet_editor, R.id.imageTinyPlanet);
+    }
+
+    @Override
+    public void createEditor(Context context, FrameLayout frameLayout) {
+        super.createEditor(context, frameLayout);
+        mImageTinyPlanet = (ImageTinyPlanet) mImageShow;
+        mImageTinyPlanet.setEditor(this);
+    }
+
+    @Override
+    public void reflectCurrentFilter() {
+        super.reflectCurrentFilter();
+
+        FilterRepresentation rep = getLocalRepresentation();
+        if (rep != null && getLocalRepresentation() instanceof FilterTinyPlanetRepresentation) {
+            FilterTinyPlanetRepresentation drawRep = (FilterTinyPlanetRepresentation) rep;
+
+            mImageTinyPlanet.setRepresentation(drawRep);
+        }
+    }
+}
diff --git a/src/com/android/gallery3d/filtershow/filters/FilterTinyPlanetRepresentation.java b/src/com/android/gallery3d/filtershow/filters/FilterTinyPlanetRepresentation.java
new file mode 100644 (file)
index 0000000..640a57f
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2012 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.filters;
+
+import android.util.Log;
+
+public class FilterTinyPlanetRepresentation extends FilterBasicRepresentation {
+    private static final String LOGTAG = "FilterTinyPlanetRepresentation";
+    private float mAngle = 0;
+
+    public FilterTinyPlanetRepresentation() {
+        super("TinyPlanet", 0, 50, 100);
+        setShowParameterValue(true);
+    }
+
+    @Override
+    public FilterRepresentation clone() throws CloneNotSupportedException {
+        FilterTinyPlanetRepresentation representation = (FilterTinyPlanetRepresentation) super
+                .clone();
+        representation.mAngle = mAngle;
+        representation.setZoom(getZoom());
+        return representation;
+    }
+
+    public void setAngle(float angle) {
+        mAngle = angle;
+    }
+
+    public float getAngle() {
+        return mAngle;
+    }
+
+    public int getZoom() {
+        return getValue();
+    }
+
+    public void setZoom(int zoom) {
+        setValue(zoom);
+    }
+}
index 05efd4a..3613cb8 100644 (file)
@@ -66,6 +66,7 @@ public class ImageFilterDraw extends ImageFilter {
     public boolean hasDefaultRepresentation() {
         return true;
     }
+
     @Override
     public FilterRepresentation getDefaultRepresentation() {
         FilterDrawRepresentation representation = new FilterDrawRepresentation();
index a6075da..558af87 100644 (file)
@@ -18,22 +18,26 @@ package com.android.gallery3d.filtershow.filters;
 
 import android.graphics.Bitmap;
 import android.graphics.Canvas;
+import android.graphics.Paint;
+import android.graphics.Rect;
 import android.graphics.RectF;
 
 import com.adobe.xmp.XMPException;
 import com.adobe.xmp.XMPMeta;
 import com.android.gallery3d.R;
 import com.android.gallery3d.app.Log;
+import com.android.gallery3d.filtershow.editors.EditorTinyPlanet;
 import com.android.gallery3d.filtershow.presets.ImagePreset;
 
 /**
  * An image filter which creates a tiny planet projection.
  */
 public class ImageFilterTinyPlanet extends SimpleImageFilter {
-    private float mAngle = 0;
 
-    private static final String TAG = ImageFilterTinyPlanet.class.getSimpleName();
+
+    private static final String LOGTAG = ImageFilterTinyPlanet.class.getSimpleName();
     public static final String GOOGLE_PANO_NAMESPACE = "http://ns.google.com/photos/1.0/panorama/";
+    FilterTinyPlanetRepresentation mParameters = new FilterTinyPlanetRepresentation();
 
     public static final String CROPPED_AREA_IMAGE_WIDTH_PIXELS =
             "CroppedAreaImageWidthPixels";
@@ -51,25 +55,40 @@ public class ImageFilterTinyPlanet extends SimpleImageFilter {
     public ImageFilterTinyPlanet() {
         setFilterType(TYPE_TINYPLANET);
         mName = "TinyPlanet";
-        mAngle = 0;
     }
 
     @Override
-    public int getButtonId() {
-        return R.id.tinyplanetButton;
+    public int getEditingViewId() {
+        return EditorTinyPlanet.ID;
     }
 
     @Override
-    public int getTextId() {
-        return R.string.tinyplanet;
+    public boolean hasDefaultRepresentation() {
+        return true;
+    }
+
+    @Override
+    public void useRepresentation(FilterRepresentation representation) {
+        FilterTinyPlanetRepresentation parameters = (FilterTinyPlanetRepresentation) representation;
+        mParameters = parameters;
+    }
+
+    @Override
+    public FilterRepresentation getDefaultRepresentation() {
+        FilterTinyPlanetRepresentation representation = new FilterTinyPlanetRepresentation();
+        representation.setName("TinyPlanet");
+        representation.setFilterClass(ImageFilterTinyPlanet.class);
+        return representation;
     }
 
-    public void setAngle(float angle) {
-        mAngle = angle;
+    @Override
+    public int getButtonId() {
+        return R.id.tinyplanetButton;
     }
 
-    public float getAngle() {
-        return mAngle;
+    @Override
+    public int getTextId() {
+        return R.string.tinyplanet;
     }
 
     public boolean isNil() {
@@ -104,11 +123,38 @@ public class ImageFilterTinyPlanet extends SimpleImageFilter {
             } catch (java.lang.OutOfMemoryError e) {
                 System.gc();
                 outputSize /= 2;
-                Log.v(TAG, "No memory to create Full Tiny Planet create half");
+                Log.v(LOGTAG, "No memory to create Full Tiny Planet create half");
             }
         }
         nativeApplyFilter(bitmapIn, bitmapIn.getWidth(), bitmapIn.getHeight(), mBitmapOut,
-                outputSize, getParameters().getValue() / 100f, mAngle);
+                outputSize, mParameters.getZoom() / 100f, mParameters.getAngle());
+
+        if (true) {
+            // TODO(hoford): FIXME and remove this section
+            String text = "Tiny Planet Not Working";
+            int w2 = bitmapIn.getWidth() / 2;
+            int h2 = bitmapIn.getHeight() / 2;
+            Canvas c = new Canvas(bitmapIn);
+            Paint p = new Paint();
+            Rect src = new Rect(0, 0, mBitmapOut.getWidth(), mBitmapOut.getHeight());
+            Rect dst = new Rect(0, 0, bitmapIn.getWidth(), bitmapIn.getHeight());
+            c.drawBitmap(mBitmapOut, 0, 0, p);
+            float size = Math.min(w2, h2) / 4f;
+            p.setTextSize(size);
+            p.setColor(0xFF000000);
+            p.setStyle(Paint.Style.STROKE);
+            p.setStrokeWidth(20);
+            Rect bounds = new Rect();
+            p.getTextBounds(text, 0, text.length(), bounds);
+            int tw = bounds.width() / 2;
+            c.drawText(text, w2 - tw, h2, p);
+
+            p.setColor(0xFFFF0000);
+            p.setStyle(Paint.Style.FILL);
+            p.setStrokeWidth(0);
+
+            c.drawText(text, w2 - tw, h2, p);
+        }
         return mBitmapOut;
     }
 
@@ -137,7 +183,6 @@ public class ImageFilterTinyPlanet extends SimpleImageFilter {
                 } catch (java.lang.OutOfMemoryError e) {
                     System.gc();
                     scale /= 2;
-                    Log.v(TAG, "No memory to create Full Tiny Planet create half");
                 }
             }
             Canvas paddedCanvas = new Canvas(paddedBitmap);
index 82d8721..3e95d4e 100644 (file)
 package com.android.gallery3d.filtershow.imageshow;
 
 import android.content.Context;
+import android.graphics.Canvas;
+import android.graphics.Paint;
 import android.util.AttributeSet;
 import android.view.MotionEvent;
 
+import com.android.gallery3d.filtershow.editors.EditorTinyPlanet;
+import com.android.gallery3d.filtershow.filters.FilterCurvesRepresentation;
+import com.android.gallery3d.filtershow.filters.FilterTinyPlanetRepresentation;
 import com.android.gallery3d.filtershow.filters.ImageFilterTinyPlanet;
 
 public class ImageTinyPlanet extends ImageShow {
@@ -31,6 +36,8 @@ public class ImageTinyPlanet extends ImageShow {
     private float mCenterX = 0;
     private float mCenterY = 0;
     private float mStartAngle = 0;
+    private FilterTinyPlanetRepresentation mTinyPlanetRep;
+    private EditorTinyPlanet mEditorTinyPlanet;
 
     public ImageTinyPlanet(Context context) {
         super(context);
@@ -60,7 +67,6 @@ public class ImageTinyPlanet extends ImageShow {
 
     @Override
     public boolean onTouchEvent(MotionEvent event) {
-        ImageFilterTinyPlanet filter = (ImageFilterTinyPlanet) getCurrentFilter();
         float x = event.getX();
         float y = event.getY();
         mCurrentX = x;
@@ -71,15 +77,30 @@ public class ImageTinyPlanet extends ImageShow {
             case (MotionEvent.ACTION_DOWN):
                 mTouchCenterX = x;
                 mTouchCenterY = y;
-                mStartAngle = filter.getAngle();
+                mStartAngle = mTinyPlanetRep.getAngle();
                 break;
             case (MotionEvent.ACTION_UP):
             case (MotionEvent.ACTION_MOVE):
-                filter.setAngle(mStartAngle + getCurrentTouchAngle());
+                mTinyPlanetRep.setAngle(mStartAngle + getCurrentTouchAngle());
                 break;
         }
         resetImageCaches(this);
         invalidate();
+        mEditorTinyPlanet.commitLocalRepresentation();
         return true;
     }
+
+    public void setRepresentation(FilterTinyPlanetRepresentation tinyPlanetRep) {
+        mTinyPlanetRep = tinyPlanetRep;
+    }
+
+    public void setEditor(EditorTinyPlanet editorTinyPlanet) {
+        mEditorTinyPlanet = editorTinyPlanet;
+    }
+
+    @Override
+    public void onDraw(Canvas canvas) {
+        super.onDraw(canvas);
+    }
+
 }
index 5c1d004..67ccf9c 100644 (file)
@@ -26,6 +26,7 @@ public class EditorManager {
     public static void addEditors(EditorPlaceHolder editorPlaceHolder) {
         editorPlaceHolder.addEditor(new EditorZoom());
         editorPlaceHolder.addEditor(new EditorCurves());
+        editorPlaceHolder.addEditor(new EditorTinyPlanet());
         editorPlaceHolder.addEditor(new EditorDraw());
     }