diff options
7 files changed, 200 insertions, 15 deletions
diff --git a/res/values/filtershow_color.xml b/res/values/filtershow_color.xml index a8c44d8e2..c97088620 100644 --- a/res/values/filtershow_color.xml +++ b/res/values/filtershow_color.xml @@ -46,6 +46,6 @@ <color name="gradcontrol_point_shadow_end">#00000000</color> <color name="gradcontrol_line_color">#FFFFFF</color> <color name="gradcontrol_line_shadow">#000000</color> - + <color name="draw_rect_border">#888888</color> </resources>
\ No newline at end of file diff --git a/res/values/filtershow_values.xml b/res/values/filtershow_values.xml index 0bb59c06a..01e3bdd82 100644 --- a/res/values/filtershow_values.xml +++ b/res/values/filtershow_values.xml @@ -39,5 +39,16 @@ <!-- Grad filter minimum touch distance --> <dimen name="gradcontrol_min_touch_dist">80dip</dimen> + <!-- Grad filter minimum touch distance --> + <dimen name="draw_rect_border">20dip</dimen> + + <!-- Grad filter minimum touch distance --> + <dimen name="draw_rect_shadow">8dip</dimen> + + <!-- Grad filter minimum touch distance --> + <dimen name="draw_rect_border_edge">2dip</dimen> + + <!-- Grad filter minimum touch distance --> + <dimen name="draw_rect_round">10dip</dimen> </resources>
\ No newline at end of file diff --git a/src/com/android/gallery3d/filtershow/editors/EditorDraw.java b/src/com/android/gallery3d/filtershow/editors/EditorDraw.java index b05eb5cb7..b3fa3f7b8 100644 --- a/src/com/android/gallery3d/filtershow/editors/EditorDraw.java +++ b/src/com/android/gallery3d/filtershow/editors/EditorDraw.java @@ -16,24 +16,18 @@ package com.android.gallery3d.filtershow.editors; -import android.app.Dialog; import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.view.MenuItem; import android.view.View; import android.view.View.OnClickListener; -import android.view.WindowManager.LayoutParams; import android.widget.Button; import android.widget.FrameLayout; import android.widget.LinearLayout; import android.widget.PopupMenu; -import android.widget.SeekBar; import com.android.gallery3d.R; -import com.android.gallery3d.filtershow.FilterShowActivity; -import com.android.gallery3d.filtershow.colorpicker.ColorGridDialog; -import com.android.gallery3d.filtershow.colorpicker.RGBListener; import com.android.gallery3d.filtershow.controller.BitmapCaller; import com.android.gallery3d.filtershow.controller.FilterView; import com.android.gallery3d.filtershow.filters.FilterDrawRepresentation; @@ -73,6 +67,8 @@ public class EditorDraw extends ParametricEditor implements FilterView { } String paramString; String val = rep.getValueString(); + + mImageDraw.displayDrawLook(); return mParameterString + val; } @@ -189,4 +185,9 @@ public class EditorDraw extends ParametricEditor implements FilterView { Bitmap bitmap = BitmapFactory.decodeResource(mContext.getResources(), brushIcons[index]); caller.available(bitmap); } + + public int getBrushIcon(int type){ + return brushIcons[type]; + } + } diff --git a/src/com/android/gallery3d/filtershow/filters/FilterDrawRepresentation.java b/src/com/android/gallery3d/filtershow/filters/FilterDrawRepresentation.java index 05a8b11bf..d55fa6d14 100644 --- a/src/com/android/gallery3d/filtershow/filters/FilterDrawRepresentation.java +++ b/src/com/android/gallery3d/filtershow/filters/FilterDrawRepresentation.java @@ -76,6 +76,10 @@ public class FilterDrawRepresentation extends FilterRepresentation { mCurrentParam = mAllParam[mParamMode]; } + public int getParamMode() { + return mParamMode; + } + public Parameter getCurrentParam() { return mAllParam[mParamMode]; } @@ -223,14 +227,18 @@ public class FilterDrawRepresentation extends FilterRepresentation { return Color.HSVToColor(op, hsv); } - public void startNewSection(float x, float y) { + public void fillStrokeParameters(StrokeData sd){ byte type = (byte) mParamStyle.getSelected(); int color = computeCurrentColor(); float size = mParamSize.getValue(); + sd.mColor = color; + sd.mRadius = size; + sd.mType = type; + } + + public void startNewSection(float x, float y) { mCurrent = new StrokeData(); - mCurrent.mColor = color; - mCurrent.mRadius = size; - mCurrent.mType = type; + fillStrokeParameters(mCurrent); mCurrent.mPath = new Path(); mCurrent.mPath.moveTo(x, y); mCurrent.mPoints[0] = x; diff --git a/src/com/android/gallery3d/filtershow/filters/FilterGradRepresentation.java b/src/com/android/gallery3d/filtershow/filters/FilterGradRepresentation.java index 0c272d48a..354fa5925 100644 --- a/src/com/android/gallery3d/filtershow/filters/FilterGradRepresentation.java +++ b/src/com/android/gallery3d/filtershow/filters/FilterGradRepresentation.java @@ -68,7 +68,7 @@ public class FilterGradRepresentation extends FilterRepresentation private int yPos1 = 100; private int xPos2 = -1; private int yPos2 = 100; - private int brightness = 40; + private int brightness = -40; private int contrast = 0; private int saturation = 0; diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterDraw.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterDraw.java index 310808c21..e4a461573 100644 --- a/src/com/android/gallery3d/filtershow/filters/ImageFilterDraw.java +++ b/src/com/android/gallery3d/filtershow/filters/ImageFilterDraw.java @@ -110,6 +110,7 @@ public class ImageFilterDraw extends ImageFilter { Paint paint = new Paint(); paint.setStyle(Style.STROKE); + paint.setAntiAlias(true); paint.setColor(sd.mColor); paint.setStrokeWidth(toScrMatrix.mapRadius(sd.mRadius)); diff --git a/src/com/android/gallery3d/filtershow/imageshow/ImageDraw.java b/src/com/android/gallery3d/filtershow/imageshow/ImageDraw.java index 904973c7d..55057dc48 100644 --- a/src/com/android/gallery3d/filtershow/imageshow/ImageDraw.java +++ b/src/com/android/gallery3d/filtershow/imageshow/ImageDraw.java @@ -2,13 +2,25 @@ package com.android.gallery3d.filtershow.imageshow; import android.content.Context; +import android.content.res.Resources; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.graphics.BitmapShader; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Matrix; +import android.graphics.Paint; +import android.graphics.PorterDuff; +import android.graphics.PorterDuffColorFilter; +import android.graphics.RectF; +import android.graphics.Shader; import android.graphics.drawable.Drawable; +import android.graphics.drawable.NinePatchDrawable; +import android.os.Handler; import android.util.AttributeSet; import android.view.MotionEvent; +import com.android.gallery3d.R; import com.android.gallery3d.filtershow.editors.EditorDraw; import com.android.gallery3d.filtershow.filters.FilterDrawRepresentation; import com.android.gallery3d.filtershow.filters.ImageFilterDraw; @@ -22,20 +34,68 @@ public class ImageDraw extends ImageShow { private byte mType = 0; private FilterDrawRepresentation mFRep; private EditorDraw mEditorDraw; + private long mTimeout; + private Paint mCheckerdPaint = makeCheckedPaint(); + private Paint mShadowPaint = new Paint(); + private Paint mIconPaint = new Paint(); + private Paint mBorderPaint = new Paint(); + private Handler mHandler; + private FilterDrawRepresentation.StrokeData mTmpStrokData = + new FilterDrawRepresentation.StrokeData(); + private Bitmap mBitmap; + private float mDisplayRound; + private float mDisplayBorder; + private int DISPLAY_TIME = 500; + private Matrix mRotateToScreen = new Matrix(); + private Matrix mToOrig; + private int mBorderColor; + private int mBorderShadowSize; + private NinePatchDrawable mShadow; + + Runnable mUpdateRunnable = new Runnable() { + @Override + public void run() { + invalidate(); + } + }; + public ImageDraw(Context context, AttributeSet attrs) { super(context, attrs); resetParameter(); + setupConstants(context); + setupTimer(); } public ImageDraw(Context context) { super(context); resetParameter(); + setupConstants(context); + setupTimer(); + } + + private void setupConstants(Context context){ + Resources res = context.getResources(); + mDisplayRound = res.getDimensionPixelSize(R.dimen.draw_rect_round); + mDisplayBorder = res.getDimensionPixelSize(R.dimen.draw_rect_border); + mBorderShadowSize = res.getDimensionPixelSize(R.dimen.draw_rect_shadow); + float edge = res.getDimensionPixelSize(R.dimen.draw_rect_border_edge); + + mBorderColor = res.getColor(R.color.draw_rect_border); + mBorderPaint.setColor(mBorderColor); + mBorderPaint.setStyle(Paint.Style.STROKE); + mBorderPaint.setStrokeWidth(edge); + mShadowPaint.setStyle(Paint.Style.FILL); + mShadowPaint.setColor(Color.BLACK); + mShadowPaint.setShadowLayer(mBorderShadowSize,mBorderShadowSize, + mBorderShadowSize,Color.BLACK); + mShadow = (NinePatchDrawable) res.getDrawable(R.drawable.geometry_shadow); } public void setEditor(EditorDraw editorDraw) { mEditorDraw = editorDraw; } + public void setFilterDrawRepresentation(FilterDrawRepresentation fr) { mFRep = fr; } @@ -122,18 +182,122 @@ public class ImageDraw extends ImageShow { return true; } - Matrix mRotateToScreen = new Matrix(); - Matrix mToOrig; private void calcScreenMapping() { mToOrig = getScreenToImageMatrix(true); mToOrig.invert(mRotateToScreen); } + private static Paint makeCheckedPaint(){ + int[] colors = new int[16 * 16]; + for (int i = 0; i < colors.length; i++) { + int y = i / (16 * 8); + int x = (i / 8) % 2; + colors[i] = (x == y) ? 0xFF777777 : 0xFF222222; + } + Bitmap bitmap = Bitmap.createBitmap(colors, 16, 16, Bitmap.Config.ARGB_8888); + BitmapShader bs = new BitmapShader(bitmap, Shader.TileMode.REPEAT, Shader.TileMode.REPEAT); + Paint p = new Paint(); + p.setShader(bs); + return p; + } + + private void setupTimer() { + mHandler = new Handler(getActivity().getMainLooper()); + } + + private void scheduleWakeup(int delay) { + mHandler.removeCallbacks(mUpdateRunnable); + mHandler.postDelayed(mUpdateRunnable, delay); + } + + public Bitmap getBrush(int brushid) { + Bitmap bitmap; + BitmapFactory.Options opt = new BitmapFactory.Options(); + opt.inPreferredConfig = Bitmap.Config.ALPHA_8; + bitmap = BitmapFactory.decodeResource(getActivity().getResources(), brushid, opt); + bitmap = bitmap.extractAlpha(); + + return bitmap; + } + + public Bitmap createScaledBitmap(Bitmap src, int dstWidth, int dstHeight, boolean filter) { + Matrix m = new Matrix(); + m.setScale(dstWidth / (float) src.getWidth(), dstHeight / (float) src.getHeight()); + Bitmap result = Bitmap.createBitmap(dstWidth, dstHeight, src.getConfig()); + Canvas canvas = new Canvas(result); + + Paint paint = new Paint(); + paint.setFilterBitmap(filter); + canvas.drawBitmap(src, m, paint); + + return result; + + } + + public void displayDrawLook() { + if (mFRep == null) { + return; + } + int color = mTmpStrokData.mColor; + byte type = mTmpStrokData.mType; + float radius = mTmpStrokData.mRadius; + mFRep.fillStrokeParameters(mTmpStrokData); + if (type != mTmpStrokData.mType || radius != mTmpStrokData.mRadius) { + mBitmap = getBrush(mEditorDraw.getBrushIcon(mTmpStrokData.mType)); + float size = mRotateToScreen.mapRadius(mTmpStrokData.mRadius) * 2; + mBitmap = createScaledBitmap(mBitmap, (int) size, (int) size, true); + } + + if (color == mTmpStrokData.mColor + && type == mTmpStrokData.mType + && radius == mTmpStrokData.mRadius) { + return; + } + + mTimeout = DISPLAY_TIME + System.currentTimeMillis(); + scheduleWakeup(DISPLAY_TIME); + } + + public void drawLook(Canvas canvas) { + if (mFRep == null) { + return; + } + int cw = canvas.getWidth(); + int ch = canvas.getHeight(); + int centerx = cw / 2; + int centery = ch / 2; + + mFRep.fillStrokeParameters(mTmpStrokData); + mIconPaint.setAntiAlias(true); + mIconPaint.setColor(mTmpStrokData.mColor); + + mIconPaint.setColorFilter(new PorterDuffColorFilter(mTmpStrokData.mColor, + PorterDuff.Mode.MULTIPLY)); + float rad = mRotateToScreen.mapRadius(mTmpStrokData.mRadius); + RectF rec = new RectF(); + rec.set(centerx - mDisplayBorder - rad, + centery - mDisplayBorder - rad, + centerx + mDisplayBorder + rad, + centery + mDisplayBorder + rad); + mShadow.setBounds((int) (mBorderShadowSize + rec.left), + (int) (mBorderShadowSize + rec.top), + (int) (mBorderShadowSize + rec.right), + (int) (mBorderShadowSize + rec.bottom)); + mShadow.draw(canvas); + canvas.drawRoundRect(rec, mDisplayRound, mDisplayRound, mCheckerdPaint); + canvas.drawRoundRect(rec, mDisplayRound, mDisplayRound, mBorderPaint); + canvas.drawBitmap(mBitmap, + centerx - mBitmap.getWidth() / 2, + centery - mBitmap.getHeight() / 2, mIconPaint); + } + @Override public void onDraw(Canvas canvas) { super.onDraw(canvas); calcScreenMapping(); - + if (System.currentTimeMillis() < mTimeout) { + drawLook(canvas); + } } } |