android:id="@+id/filterButtonsList"
android:layout_width="fill_parent"
android:layout_height="96dip"
- android:background="@color/background_toolbar"
+ android:background="@color/background_main_toolbar"
android:orientation="horizontal"
android:visibility="gone" >
android:id="@+id/geometryList"
android:layout_width="fill_parent"
android:layout_height="96dip"
- android:background="@color/background_toolbar"
+ android:background="@color/background_main_toolbar"
android:visibility="gone" >
<LinearLayout
android:id="@+id/colorsFxList"
android:layout_width="fill_parent"
android:layout_height="96dip"
- android:background="@color/background_toolbar"
+ android:background="@color/background_main_toolbar"
android:visibility="gone" >
<LinearLayout
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.ContentValues;
-import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
-import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
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.ImageFilterFx;
import com.android.gallery3d.filtershow.filters.ImageFilterParametricBorder;
import com.android.gallery3d.filtershow.filters.ImageFilterRS;
import com.android.gallery3d.filtershow.imageshow.ImageBorder;
import com.android.gallery3d.filtershow.imageshow.ImageFlip;
import com.android.gallery3d.filtershow.imageshow.ImageRotate;
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.ImageZoom;
private ImageButton mGeometryButton = null;
private ImageButton mColorsButton = null;
+ private ImageSmallFilter mCurrentImageSmallFilter = null;
private static final int SELECT_PICTURE = 1;
private static final String LOGTAG = "FilterShowActivity";
protected static final boolean ANIMATE_PANELS = true;
mPanelController.addView(findViewById(R.id.resetEffect));
mPanelController.addView(findViewById(R.id.applyEffect));
- findViewById(R.id.compareWithOriginalImage).setOnTouchListener(createOnTouchShowOriginalButton());
+ findViewById(R.id.compareWithOriginalImage).setOnTouchListener(
+ createOnTouchShowOriginalButton());
findViewById(R.id.resetOperationsButton).setOnClickListener(
createOnClickResetOperationsButton());
private void hideSavingProgress() {
if (mSavingProgressDialog != null) {
ProgressDialog progress = mSavingProgressDialog.get();
- if (progress != null) progress.dismiss();
+ if (progress != null)
+ progress.dismiss();
}
}
ImagePreset[] preset = new ImagePreset[18];
int p = 0;
- int[]drawid = {
+ int[] drawid = {
R.drawable.filtershow_fx_0000_vintage,
R.drawable.filtershow_fx_0001_instant,
R.drawable.filtershow_fx_0002_bleach,
R.drawable.filtershow_fx_0008_washout_color
};
- int[]fxNameid = {
+ int[] fxNameid = {
R.string.ffx_vintage,
R.string.ffx_instant,
R.string.ffx_bleach,
R.string.ffx_washout_color,
};
+ preset[p++] = new ImagePreset();
+
for (int i = 0; i < drawid.length; i++) {
- Bitmap b = BitmapFactory.decodeResource(getResources(),drawid[i]);
+ Bitmap b = BitmapFactory.decodeResource(getResources(), drawid[i]);
preset[p++] = new ImagePresetFX(b, getString(fxNameid[i]));
}
- preset[p++] = new ImagePreset();
preset[p++] = new ImagePresetSaturated();
preset[p++] = new ImagePresetOld();
preset[p++] = new ImagePresetXProcessing();
preset[p++] = new ImagePresetBWGreen();
preset[p++] = new ImagePresetBWBlue();
+ ImageSmallFilter previousFilter = null;
for (int i = 0; i < p; i++) {
- ImageSmallFilter filter = new ImageSmallFilter(getBaseContext());
+ ImageSmallFilter filter = new ImageSmallFilter(this);
+ if (i == 0) {
+ filter.setSelected(true);
+ mCurrentImageSmallFilter = filter;
+ }
+ filter.setPreviousImageSmallFilter(previousFilter);
preset[i].setIsFx(true);
filter.setImagePreset(preset[i]);
filter.setController(this);
filter.setImageLoader(mImageLoader);
listFilters.addView(filter);
+ previousFilter = filter;
}
// Default preset (original)
ImageFilter[] borders = new ImageFilter[7];
borders[p++] = new ImageFilterBorder(null);
- borders[p++] = new ImageFilterParametricBorder(Color.WHITE, 100, 0);
- borders[p++] = new ImageFilterParametricBorder(Color.BLACK, 100, 0);
- borders[p++] = new ImageFilterParametricBorder(Color.WHITE, 100, 100);
- borders[p++] = new ImageFilterParametricBorder(Color.BLACK, 100, 100);
Drawable npd3 = getResources().getDrawable(R.drawable.filtershow_border_film3);
borders[p++] = new ImageFilterBorder(npd3);
Drawable npd = getResources().getDrawable(
R.drawable.filtershow_border_scratch3);
borders[p++] = new ImageFilterBorder(npd);
+ borders[p++] = new ImageFilterParametricBorder(Color.BLACK, 100, 0);
+ borders[p++] = new ImageFilterParametricBorder(Color.BLACK, 100, 100);
+ borders[p++] = new ImageFilterParametricBorder(Color.WHITE, 100, 0);
+ borders[p++] = new ImageFilterParametricBorder(Color.WHITE, 100, 100);
+ ImageSmallFilter previousFilter = null;
for (int i = 0; i < p; i++) {
- ImageSmallFilter filter = new ImageSmallFilter(getBaseContext());
+ ImageSmallBorder filter = new ImageSmallBorder(this);
+ filter.setPreviousImageSmallFilter(previousFilter);
filter.setImageFilter(borders[i]);
filter.setController(this);
filter.setBorder(true);
filter.setImageLoader(mImageLoader);
filter.setShowTitle(false);
listBorders.addView(filter);
+ previousFilter = filter;
}
}
r.getDisplayMetrics());
}
- public void useImagePreset(ImagePreset preset) {
+ public void useImagePreset(ImageSmallFilter imageSmallFilter, ImagePreset preset) {
if (preset == null) {
return;
}
+
+ if (mCurrentImageSmallFilter != null) {
+ mCurrentImageSmallFilter.setSelected(false);
+ }
+ mCurrentImageSmallFilter = imageSmallFilter;
+ mCurrentImageSmallFilter.setSelected(true);
+
ImagePreset copy = new ImagePreset(preset);
mImageShow.setImagePreset(copy);
if (preset.isFx()) {
invalidateViews();
}
- public void useImageFilter(ImageFilter imageFilter, boolean setBorder) {
+ public void useImageFilter(ImageSmallFilter imageSmallFilter, ImageFilter imageFilter,
+ boolean setBorder) {
if (imageFilter == null) {
return;
}
+
+ if (mCurrentImageSmallFilter != null) {
+ mCurrentImageSmallFilter.setSelected(false);
+ }
+ mCurrentImageSmallFilter = imageSmallFilter;
+ mCurrentImageSmallFilter.setSelected(true);
+
ImagePreset oldPreset = mImageShow.getImagePreset();
ImagePreset copy = new ImagePreset(oldPreset);
// TODO: use a numerical constant instead.
public class ImageFilterBWBlue extends ImageFilter {
public ImageFilterBWBlue() {
- mName = "Black & White (Blue)";
+ mName = "B&W - Blue";
}
native protected void nativeApplyFilter(Bitmap bitmap, int w, int h);
public class ImageFilterBWGreen extends ImageFilter {
public ImageFilterBWGreen() {
- mName = "Black & White (Green)";
+ mName = "B&W - Green";
}
native protected void nativeApplyFilter(Bitmap bitmap, int w, int h);
public class ImageFilterBWRed extends ImageFilter {
public ImageFilterBWRed() {
- mName = "Black & White (Red)";
+ mName = "B&W - Red";
}
native protected void nativeApplyFilter(Bitmap bitmap, int w, int h);
int w = bitmap.getWidth();
int h = bitmap.getHeight();
- Rect bounds = new Rect(0, 0, w, h);
+ float scale = scaleFactor * 2.0f;
+ Rect bounds = new Rect(0, 0, (int) (w / scale), (int) (h / scale));
Canvas canvas = new Canvas(bitmap);
+ canvas.scale(scale, scale);
mNinePatch.setBounds(bounds);
mNinePatch.draw(canvas);
return bitmap;
private static final String LOGTAG = "ImageShow";
protected Paint mPaint = new Paint();
- private static int mTextSize = 24;
- private static int mTextPadding = 20;
+ protected static int mTextSize = 24;
+ protected static int mTextPadding = 20;
protected ImagePreset mImagePreset = null;
protected ImageLoader mImageLoader = null;
--- /dev/null
+
+package com.android.gallery3d.filtershow.imageshow;
+
+import android.content.Context;
+import android.graphics.Bitmap;
+import android.graphics.Canvas;
+import android.graphics.Color;
+import android.graphics.Paint;
+import android.graphics.Path;
+import android.graphics.Rect;
+import android.graphics.RectF;
+import android.graphics.Region;
+import android.util.AttributeSet;
+
+public class ImageSmallBorder extends ImageSmallFilter {
+
+ // TODO: move this to xml.
+ protected final int mSelectedBackgroundColor = Color.WHITE;
+ protected final int mInnerBorderColor = Color.BLACK;
+ protected final int mInnerBorderWidth = 2;
+ protected final float mImageScaleFactor = 2.5f;
+
+ public ImageSmallBorder(Context context) {
+ super(context);
+ }
+
+ public ImageSmallBorder(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ }
+
+ @Override
+ public void onDraw(Canvas canvas) {
+ getFilteredImage();
+ if (mIsSelected) {
+ canvas.drawColor(mSelectedBackgroundColor);
+ } else {
+ canvas.drawColor(mBackgroundColor);
+ }
+ // TODO: simplify & make faster...
+ mPaint.setColor(mInnerBorderColor);
+ RectF border = new RectF(mMargin, mMargin, getWidth() - mMargin - 1, getHeight() - mMargin);
+ canvas.drawLine(0, 0, getWidth(), 0, mPaint);
+ mPaint.setStrokeWidth(mInnerBorderWidth);
+ Path path = new Path();
+ path.addRect(border, Path.Direction.CCW);
+ mPaint.setStyle(Paint.Style.STROKE);
+ canvas.drawPath(path, mPaint);
+ mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
+ canvas.save();
+ canvas.clipRect(mMargin + 1, mMargin, getWidth() - mMargin - 2, getHeight() - mMargin - 1,
+ Region.Op.INTERSECT);
+ canvas.translate(mMargin, mMargin + 1);
+ canvas.scale(mImageScaleFactor, mImageScaleFactor);
+ Rect d = new Rect(0, 0, getWidth(), getWidth());
+ drawImage(canvas, mFilteredImage, d);
+ canvas.restore();
+ }
+
+ @Override
+ public void drawImage(Canvas canvas, Bitmap image, Rect d) {
+ if (image != null) {
+ int iw = image.getWidth();
+ int ih = image.getHeight();
+ Rect s = new Rect(0, 0, iw, iw);
+ canvas.drawBitmap(image, s, d, mPaint);
+ }
+ }
+}
import android.content.Context;
import android.graphics.Bitmap;
+import android.graphics.Canvas;
+import android.graphics.Color;
+import android.graphics.Paint;
+import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.View;
private ImageFilter mImageFilter = null;
private boolean mShowTitle = true;
private boolean mSetBorder = false;
+ protected final Paint mPaint = new Paint();
+ protected boolean mIsSelected = false;
+ protected boolean mNextIsSelected = false;
+ private ImageSmallFilter mPreviousImageSmallFilter = null;
+
+ // TODO: move this to xml.
+ protected final int mMargin = 12;
+ protected final int mTextMargin = 8;
+ protected final int mBackgroundColor = Color.argb(255, 30, 32, 40);
+ protected final int mSelectedBackgroundColor = Color.WHITE;
+ protected final int mTextColor = Color.WHITE;
public ImageSmallFilter(Context context, AttributeSet attrs) {
super(context, attrs);
mImagePreset.add(mImageFilter);
}
+ public void setPreviousImageSmallFilter(ImageSmallFilter previous) {
+ mPreviousImageSmallFilter = previous;
+ }
+
+ @Override
+ public void setSelected(boolean value) {
+ if (mIsSelected != value) {
+ invalidate();
+ if (mPreviousImageSmallFilter != null) {
+ mPreviousImageSmallFilter.setNextSelected(value);
+ }
+ }
+ mIsSelected = value;
+ }
+
+ public void setNextSelected(boolean value) {
+ if (mNextIsSelected != value) {
+ invalidate();
+ }
+ mNextIsSelected = value;
+ }
+
public void setBorder(boolean value) {
mSetBorder = value;
}
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int parentWidth = MeasureSpec.getSize(widthMeasureSpec);
int parentHeight = MeasureSpec.getSize(heightMeasureSpec);
- setMeasuredDimension(parentHeight, parentHeight);
+ int h = mTextSize + mTextPadding;
+ setMeasuredDimension(parentHeight - h, parentHeight);
}
@Override
public void onClick(View v) {
if (mController != null) {
if (mImageFilter != null) {
- mController.useImageFilter(mImageFilter, mSetBorder);
+ mController.useImageFilter(this, mImageFilter, mSetBorder);
} else if (mImagePreset != null) {
- mController.useImagePreset(mImagePreset);
+ mController.useImagePreset(this, mImagePreset);
}
}
}
public boolean showHires() {
return false;
}
+
+ @Override
+ public void onDraw(Canvas canvas) {
+ getFilteredImage();
+ canvas.drawColor(mBackgroundColor);
+ Rect d = new Rect(0, mMargin, getWidth() - mMargin, getWidth());
+ float textWidth = mPaint.measureText(getImagePreset().name());
+ int h = mTextSize + 2 * mTextPadding;
+ int x = (int) ((getWidth() - textWidth) / 2);
+ int y = getHeight();
+ if (mIsSelected) {
+ mPaint.setColor(mSelectedBackgroundColor);
+ canvas.drawRect(0, 0, getWidth(), getWidth() + mMargin, mPaint);
+ }
+ if (mNextIsSelected) {
+ mPaint.setColor(mSelectedBackgroundColor);
+ canvas.drawRect(getWidth() - mMargin, 0, getWidth(), getWidth() + mMargin, mPaint);
+ }
+ drawImage(canvas, mFilteredImage, d);
+ mPaint.setTextSize(mTextSize);
+ mPaint.setColor(mTextColor);
+ canvas.drawText(getImagePreset().name(), x, y - mTextMargin, mPaint);
+ }
+
+ public void drawImage(Canvas canvas, Bitmap image, Rect d) {
+ if (image != null) {
+ int iw = image.getWidth();
+ int ih = image.getHeight();
+ int iy = (int) ((ih - iw) / 2.0f);
+ int ix = 0;
+ if (iw > ih) {
+ iy = 0;
+ ix = (int) ((iw - ih) / 2.0f);
+ }
+ Rect s = new Rect(ix, iy, ix + iw, iy + iw);
+ canvas.drawBitmap(image, s, d, mPaint);
+ }
+ }
+
}
// First we apply any transform -- 90 rotate, flip, straighten, crop
Bitmap bitmap = mGeoData.apply(original, mScaleFactor, mIsHighQuality);
- if (mImageBorder != null) {
- bitmap = mImageBorder.apply(bitmap, mScaleFactor, mIsHighQuality);
- }
-
for (int i = 0; i < mFilters.size(); i++) {
ImageFilter filter = mFilters.elementAt(i);
bitmap = filter.apply(bitmap, mScaleFactor, mIsHighQuality);
}
+ if (mImageBorder != null) {
+ bitmap = mImageBorder.apply(bitmap, mScaleFactor, mIsHighQuality);
+ }
+
if (mEndPoint != null) {
mEndPoint.updateFilteredImage(bitmap);
}
public class ImagePresetBW extends ImagePreset {
+ @Override
public String name() {
- return "Black & White";
+ return "B&W";
}
+ @Override
public void setup() {
mFilters.add(new ImageFilterBW());
}
public class ImagePresetBWBlue extends ImagePreset {
+ @Override
public String name() {
- return "Black & White (Blue)";
+ return "B&W - Blue";
}
+ @Override
public void setup() {
mFilters.add(new ImageFilterBWBlue());
}
public class ImagePresetBWGreen extends ImagePreset {
+ @Override
public String name() {
- return "Black & White (Green)";
+ return "B&W - Green";
}
+ @Override
public void setup() {
mFilters.add(new ImageFilterBWGreen());
}
public class ImagePresetBWRed extends ImagePreset {
+ @Override
public String name() {
- return "Black & White (Red)";
+ return "B&W - Red";
}
+ @Override
public void setup() {
mFilters.add(new ImageFilterBWRed());
}
public class ImagePresetSaturated extends ImagePreset {
+ @Override
public String name() {
return "Saturated";
}
+ @Override
public void setup() {
- mFilters.add(new ImageFilterSaturated());
+ ImageFilterSaturated filter = new ImageFilterSaturated();
+ filter.setParameter(50);
+ mFilters.add(filter);
}
}