OSDN Git Service

layouts, image icons, and layer behavour
authorJohn Hoford <hoford@google.com>
Fri, 12 Oct 2012 04:04:41 +0000 (21:04 -0700)
committerJohn Hoford <hoford@google.com>
Fri, 12 Oct 2012 04:22:13 +0000 (21:22 -0700)
bug:7328726
Change-Id: I94300771dd7b6ff5b4196365f13320fbc4bdde92

res/layout/filtershow_activity.xml
res/values/attrs.xml
src/com/android/gallery3d/filtershow/CenteredLinearLayout.java [new file with mode: 0644]
src/com/android/gallery3d/filtershow/FilterShowActivity.java
src/com/android/gallery3d/filtershow/imageshow/ImageWithIcon.java [new file with mode: 0644]

index f9d04aa..0e15732 100644 (file)
@@ -17,7 +17,8 @@
 
 <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
-    android:layout_height="match_parent" >
+    android:layout_height="match_parent"
+    android:background="@color/background_main_toolbar" >
 
     <LinearLayout
         android:id="@+id/imageStatePanel"
                 android:visibility="gone" />
         </FrameLayout>
 
+        <com.android.gallery3d.filtershow.CenteredLinearLayout
+              xmlns:custom="http://schemas.android.com/apk/res/com.android.gallery3d"
+              android:id="@+id/mainPanel"
+              android:layout_width="match_parent"
+              android:layout_height="wrap_content"
+              android:layout_gravity="center"
+              custom:max_width="600dip"
+              android:orientation="vertical">
+
         <FrameLayout
             android:id="@+id/secondRowPanel"
             android:layout_width="fill_parent"
                     android:id="@+id/listGeometry"
                     android:layout_width="wrap_content"
                     android:layout_height="fill_parent"
-                    android:orientation="horizontal" >
+                    android:layout_gravity="center"
+                    android:orientation="horizontal">
 
                     <com.android.gallery3d.filtershow.ui.ImageButtonTitle
                         android:id="@+id/straightenButton"
             </HorizontalScrollView>
         </FrameLayout>
 
+        <com.android.gallery3d.filtershow.CenteredLinearLayout
+              xmlns:custom="http://schemas.android.com/apk/res/com.android.gallery3d"
+              android:id="@+id/mainPanel"
+              android:layout_width="match_parent"
+              android:layout_height="wrap_content"
+              android:layout_gravity="center"
+              custom:max_width="400dip"
+              android:orientation="vertical">
+
         <LinearLayout
             android:layout_width="match_parent"
             android:layout_height="48dip"
                 android:scaleType="centerInside"
                 android:src="@drawable/ic_photoeditor_color" />
         </LinearLayout>
+
+        </com.android.gallery3d.filtershow.CenteredLinearLayout>
+
+        </com.android.gallery3d.filtershow.CenteredLinearLayout>
     </LinearLayout>
 
 </FrameLayout>
index 94d5b72..f8ebd05 100644 (file)
@@ -18,4 +18,7 @@
         <attr name="listPreferredItemHeightSmall" format="dimension" />
         <attr name="switchStyle" format="reference" />
     </declare-styleable>
+    <declare-styleable name="CenteredLinearLayout">
+        <attr name="max_width" format="dimension" />
+    </declare-styleable>
 </resources>
diff --git a/src/com/android/gallery3d/filtershow/CenteredLinearLayout.java b/src/com/android/gallery3d/filtershow/CenteredLinearLayout.java
new file mode 100644 (file)
index 0000000..16b9695
--- /dev/null
@@ -0,0 +1,36 @@
+package com.android.gallery3d.filtershow;
+
+import android.content.Context;
+import android.content.res.Resources;
+import android.content.res.TypedArray;
+import android.util.AttributeSet;
+import android.util.TypedValue;
+import android.view.View.MeasureSpec;
+import android.widget.LinearLayout;
+
+import com.android.gallery3d.R;
+
+public class CenteredLinearLayout extends LinearLayout {
+    private final int mMaxWidth;
+
+    public CenteredLinearLayout(Context context, AttributeSet attrs) {
+        super(context, attrs);
+        TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.CenteredLinearLayout);
+        mMaxWidth = a.getDimensionPixelSize(R.styleable.CenteredLinearLayout_max_width, 0);
+    }
+
+    @Override
+    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
+        int parentWidth = MeasureSpec.getSize(widthMeasureSpec);
+        int parentHeight = MeasureSpec.getSize(heightMeasureSpec);
+        Resources r = getContext().getResources();
+        float value = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, parentWidth,
+                r.getDisplayMetrics());
+        if (mMaxWidth > 0 && parentWidth > mMaxWidth) {
+            int measureMode = MeasureSpec.getMode(widthMeasureSpec);
+            widthMeasureSpec = MeasureSpec.makeMeasureSpec(mMaxWidth, measureMode);
+        }
+        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
+    }
+
+}
index 5553a3c..f2b817c 100644 (file)
@@ -36,9 +36,17 @@ import com.android.gallery3d.R;
 import com.android.gallery3d.filtershow.cache.ImageLoader;
 import com.android.gallery3d.filtershow.filters.ImageFilter;
 import com.android.gallery3d.filtershow.filters.ImageFilterBorder;
+import com.android.gallery3d.filtershow.filters.ImageFilterContrast;
+import com.android.gallery3d.filtershow.filters.ImageFilterExposure;
 import com.android.gallery3d.filtershow.filters.ImageFilterFx;
+import com.android.gallery3d.filtershow.filters.ImageFilterHue;
 import com.android.gallery3d.filtershow.filters.ImageFilterParametricBorder;
 import com.android.gallery3d.filtershow.filters.ImageFilterRS;
+import com.android.gallery3d.filtershow.filters.ImageFilterSaturated;
+import com.android.gallery3d.filtershow.filters.ImageFilterShadows;
+import com.android.gallery3d.filtershow.filters.ImageFilterVibrance;
+import com.android.gallery3d.filtershow.filters.ImageFilterVignette;
+import com.android.gallery3d.filtershow.filters.ImageFilterWBalance;
 import com.android.gallery3d.filtershow.imageshow.ImageBorder;
 import com.android.gallery3d.filtershow.imageshow.ImageCrop;
 import com.android.gallery3d.filtershow.imageshow.ImageFlip;
@@ -47,6 +55,7 @@ import com.android.gallery3d.filtershow.imageshow.ImageShow;
 import com.android.gallery3d.filtershow.imageshow.ImageSmallBorder;
 import com.android.gallery3d.filtershow.imageshow.ImageSmallFilter;
 import com.android.gallery3d.filtershow.imageshow.ImageStraighten;
+import com.android.gallery3d.filtershow.imageshow.ImageWithIcon;
 import com.android.gallery3d.filtershow.imageshow.ImageZoom;
 import com.android.gallery3d.filtershow.presets.ImagePreset;
 import com.android.gallery3d.filtershow.provider.SharedImageProvider;
@@ -124,6 +133,7 @@ public class FilterShowActivity extends Activity implements OnItemClickListener,
 
         LinearLayout listFilters = (LinearLayout) findViewById(R.id.listFilters);
         LinearLayout listBorders = (LinearLayout) findViewById(R.id.listBorders);
+        LinearLayout listColors = (LinearLayout) findViewById(R.id.listColorsFx);
 
         mImageShow = (ImageShow) findViewById(R.id.imageShow);
         mImageCurves = (ImageCurves) findViewById(R.id.imageCurves);
@@ -199,7 +209,84 @@ public class FilterShowActivity extends Activity implements OnItemClickListener,
         mPanelController.addComponent(mGeometryButton, findViewById(R.id.flipButton));
 
         mPanelController.addPanel(mColorsButton, mListColors, 3);
-        mPanelController.addComponent(mColorsButton, findViewById(R.id.vignetteButton));
+
+        int []recastIDs = {
+                R.id.vignetteButton,
+                R.id.vibranceButton,
+                R.id.contrastButton,
+                R.id.saturationButton,
+                R.id.wbalanceButton,
+                R.id.hueButton,
+                R.id.exposureButton,
+                R.id.shadowRecoveryButton
+        };
+        ImageFilter []filters = {
+                new ImageFilterVignette(),
+                new ImageFilterVibrance(),
+                new ImageFilterContrast(),
+                new ImageFilterSaturated(),
+                new ImageFilterWBalance(),
+                new ImageFilterHue(),
+                new ImageFilterExposure(),
+                new ImageFilterShadows()
+        };
+
+
+        for (int i = 0; i < filters.length; i++) {
+
+            ImageSmallFilter fView = new ImageSmallFilter(this);
+            View v = listColors.findViewById(recastIDs[i]);
+            int pos = listColors.indexOfChild(v);
+            listColors.removeView(v);
+
+            filters[i].setParameter(100);
+            fView.setImageFilter(filters[i]);
+            fView.setController(this);
+            fView.setImageLoader(mImageLoader);
+            fView.setId(recastIDs[i]);
+
+            mPanelController.addComponent(mColorsButton, fView);
+            listColors.addView(fView,pos);
+        }
+
+        int []overlayIDs = {
+                R.id.sharpenButton,
+                R.id.curvesButtonRGB
+        };
+        int []overlayBitmaps = {
+                R.drawable.filtershow_button_colors_sharpen,
+                R.drawable.filtershow_button_colors_curve
+        };
+        int []overlayNames = {
+                R.string.sharpen,
+                R.string.curvesRGB
+        };
+
+        for (int i = 0; i < overlayIDs.length; i++)  {
+            ImageWithIcon fView = new ImageWithIcon(this);
+            View v = listColors.findViewById(overlayIDs[i]);
+            int pos = listColors.indexOfChild(v);
+            listColors.removeView(v);
+            final int sid =overlayNames[i];
+            ImageFilterExposure efilter = new ImageFilterExposure(){
+                {
+                    mName = getString(sid);
+                }
+            };
+            efilter.setParameter(-300);
+            Bitmap bitmap = BitmapFactory.decodeResource(getResources(),
+                    overlayBitmaps[i] );
+
+            fView.setIcon(bitmap);
+            fView.setImageFilter(efilter);
+            fView.setController(this);
+            fView.setImageLoader(mImageLoader);
+            fView.setId(overlayIDs[i]);
+
+            mPanelController.addComponent(mColorsButton, fView);
+            listColors.addView(fView,pos);
+        }
+
         mPanelController.addComponent(mColorsButton, findViewById(R.id.curvesButtonRGB));
         mPanelController.addComponent(mColorsButton, findViewById(R.id.sharpenButton));
         mPanelController.addComponent(mColorsButton, findViewById(R.id.vibranceButton));
diff --git a/src/com/android/gallery3d/filtershow/imageshow/ImageWithIcon.java b/src/com/android/gallery3d/filtershow/imageshow/ImageWithIcon.java
new file mode 100644 (file)
index 0000000..2666cb7
--- /dev/null
@@ -0,0 +1,34 @@
+package com.android.gallery3d.filtershow.imageshow;
+
+import android.content.Context;
+import android.graphics.Bitmap;
+import android.graphics.Canvas;
+import android.graphics.Rect;
+
+/**
+ * TODO: Insert description here. (generated by hoford)
+ */
+public class ImageWithIcon extends ImageSmallFilter {
+    /**
+     * @param context
+     */
+    public ImageWithIcon(Context context) {
+        super(context);
+        // TODO(hoford): Auto-generated constructor stub
+    }
+
+    private Bitmap bitmap;
+
+    public void setIcon(Bitmap bitmap){
+        this.bitmap = bitmap;
+    }
+
+    @Override
+    public void onDraw(Canvas canvas) {
+        super.onDraw(canvas);
+        if (bitmap != null) {
+            Rect d = new Rect(0, mMargin, getWidth() - mMargin, getWidth());
+            drawImage(canvas, bitmap, d);
+        }
+    }
+}