From 1684f14224b7590a4e78b79a367ab2b481152baa Mon Sep 17 00:00:00 2001 From: John Hoford Date: Thu, 11 Oct 2012 21:04:41 -0700 Subject: layouts, image icons, and layer behavour bug:7328726 Change-Id: I94300771dd7b6ff5b4196365f13320fbc4bdde92 --- .../gallery3d/filtershow/CenteredLinearLayout.java | 36 +++++++++ .../gallery3d/filtershow/FilterShowActivity.java | 89 +++++++++++++++++++++- .../filtershow/imageshow/ImageWithIcon.java | 34 +++++++++ 3 files changed, 158 insertions(+), 1 deletion(-) create mode 100644 src/com/android/gallery3d/filtershow/CenteredLinearLayout.java create mode 100644 src/com/android/gallery3d/filtershow/imageshow/ImageWithIcon.java diff --git a/src/com/android/gallery3d/filtershow/CenteredLinearLayout.java b/src/com/android/gallery3d/filtershow/CenteredLinearLayout.java new file mode 100644 index 000000000..16b969535 --- /dev/null +++ b/src/com/android/gallery3d/filtershow/CenteredLinearLayout.java @@ -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); + } + +} diff --git a/src/com/android/gallery3d/filtershow/FilterShowActivity.java b/src/com/android/gallery3d/filtershow/FilterShowActivity.java index 5553a3c20..f2b817c17 100644 --- a/src/com/android/gallery3d/filtershow/FilterShowActivity.java +++ b/src/com/android/gallery3d/filtershow/FilterShowActivity.java @@ -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 index 000000000..2666cb73d --- /dev/null +++ b/src/com/android/gallery3d/filtershow/imageshow/ImageWithIcon.java @@ -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); + } + } +} -- cgit v1.2.3