1db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford 2db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hofordpackage com.android.gallery3d.filtershow.imageshow; 3db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford 4db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hofordimport android.content.Context; 54e289659f746cf659e300c9fcd2048960e115f0cJohn Hofordimport android.content.res.Resources; 64e289659f746cf659e300c9fcd2048960e115f0cJohn Hofordimport android.graphics.Bitmap; 74e289659f746cf659e300c9fcd2048960e115f0cJohn Hofordimport android.graphics.BitmapFactory; 84e289659f746cf659e300c9fcd2048960e115f0cJohn Hofordimport android.graphics.BitmapShader; 9db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hofordimport android.graphics.Canvas; 10db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hofordimport android.graphics.Color; 11db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hofordimport android.graphics.Matrix; 124e289659f746cf659e300c9fcd2048960e115f0cJohn Hofordimport android.graphics.Paint; 134e289659f746cf659e300c9fcd2048960e115f0cJohn Hofordimport android.graphics.PorterDuff; 144e289659f746cf659e300c9fcd2048960e115f0cJohn Hofordimport android.graphics.PorterDuffColorFilter; 154e289659f746cf659e300c9fcd2048960e115f0cJohn Hofordimport android.graphics.RectF; 164e289659f746cf659e300c9fcd2048960e115f0cJohn Hofordimport android.graphics.Shader; 1719161944e0efb1ffe23274d7cf5315ce047e9dacJohn Hofordimport android.graphics.drawable.Drawable; 184e289659f746cf659e300c9fcd2048960e115f0cJohn Hofordimport android.graphics.drawable.NinePatchDrawable; 194e289659f746cf659e300c9fcd2048960e115f0cJohn Hofordimport android.os.Handler; 20db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hofordimport android.util.AttributeSet; 21db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hofordimport android.view.MotionEvent; 22db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford 234e289659f746cf659e300c9fcd2048960e115f0cJohn Hofordimport com.android.gallery3d.R; 2419161944e0efb1ffe23274d7cf5315ce047e9dacJohn Hofordimport com.android.gallery3d.filtershow.editors.EditorDraw; 2519161944e0efb1ffe23274d7cf5315ce047e9dacJohn Hofordimport com.android.gallery3d.filtershow.filters.FilterDrawRepresentation; 26db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hofordimport com.android.gallery3d.filtershow.filters.ImageFilterDraw; 27db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford 2863a7dac01d394523799939596b960cb03321798dJohn Hofordpublic class ImageDraw extends ImageShow { 29db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford 30db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford private static final String LOGTAG = "ImageDraw"; 31915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford private int mCurrentColor = Color.RED; 32915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford final static float INITAL_STROKE_RADIUS = 40; 33915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford private float mCurrentSize = INITAL_STROKE_RADIUS; 3419161944e0efb1ffe23274d7cf5315ce047e9dacJohn Hoford private byte mType = 0; 3519161944e0efb1ffe23274d7cf5315ce047e9dacJohn Hoford private FilterDrawRepresentation mFRep; 3619161944e0efb1ffe23274d7cf5315ce047e9dacJohn Hoford private EditorDraw mEditorDraw; 374e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford private long mTimeout; 384e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford private Paint mCheckerdPaint = makeCheckedPaint(); 394e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford private Paint mShadowPaint = new Paint(); 404e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford private Paint mIconPaint = new Paint(); 414e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford private Paint mBorderPaint = new Paint(); 424e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford private Handler mHandler; 434e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford private FilterDrawRepresentation.StrokeData mTmpStrokData = 444e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford new FilterDrawRepresentation.StrokeData(); 454e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford private Bitmap mBitmap; 464e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford private float mDisplayRound; 474e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford private float mDisplayBorder; 484e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford private int DISPLAY_TIME = 500; 494e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford private Matrix mRotateToScreen = new Matrix(); 504e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford private Matrix mToOrig; 514e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford private int mBorderColor; 524e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford private int mBorderShadowSize; 534e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford private NinePatchDrawable mShadow; 544e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford 554e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford Runnable mUpdateRunnable = new Runnable() { 564e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford @Override 574e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford public void run() { 584e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford invalidate(); 594e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford } 604e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford }; 614e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford 62db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford 63db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford public ImageDraw(Context context, AttributeSet attrs) { 64db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford super(context, attrs); 6519161944e0efb1ffe23274d7cf5315ce047e9dacJohn Hoford resetParameter(); 664e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford setupConstants(context); 674e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford setupTimer(); 68db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford } 69db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford 70db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford public ImageDraw(Context context) { 71db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford super(context); 7219161944e0efb1ffe23274d7cf5315ce047e9dacJohn Hoford resetParameter(); 734e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford setupConstants(context); 744e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford setupTimer(); 754e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford } 764e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford 774e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford private void setupConstants(Context context){ 784e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford Resources res = context.getResources(); 794e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford mDisplayRound = res.getDimensionPixelSize(R.dimen.draw_rect_round); 804e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford mDisplayBorder = res.getDimensionPixelSize(R.dimen.draw_rect_border); 814e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford mBorderShadowSize = res.getDimensionPixelSize(R.dimen.draw_rect_shadow); 824e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford float edge = res.getDimensionPixelSize(R.dimen.draw_rect_border_edge); 834e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford 844e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford mBorderColor = res.getColor(R.color.draw_rect_border); 854e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford mBorderPaint.setColor(mBorderColor); 864e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford mBorderPaint.setStyle(Paint.Style.STROKE); 874e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford mBorderPaint.setStrokeWidth(edge); 884e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford mShadowPaint.setStyle(Paint.Style.FILL); 894e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford mShadowPaint.setColor(Color.BLACK); 904e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford mShadowPaint.setShadowLayer(mBorderShadowSize,mBorderShadowSize, 914e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford mBorderShadowSize,Color.BLACK); 924e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford mShadow = (NinePatchDrawable) res.getDrawable(R.drawable.geometry_shadow); 9319161944e0efb1ffe23274d7cf5315ce047e9dacJohn Hoford } 9419161944e0efb1ffe23274d7cf5315ce047e9dacJohn Hoford 9519161944e0efb1ffe23274d7cf5315ce047e9dacJohn Hoford public void setEditor(EditorDraw editorDraw) { 9619161944e0efb1ffe23274d7cf5315ce047e9dacJohn Hoford mEditorDraw = editorDraw; 9719161944e0efb1ffe23274d7cf5315ce047e9dacJohn Hoford } 984e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford 9919161944e0efb1ffe23274d7cf5315ce047e9dacJohn Hoford public void setFilterDrawRepresentation(FilterDrawRepresentation fr) { 10019161944e0efb1ffe23274d7cf5315ce047e9dacJohn Hoford mFRep = fr; 101a4f38c0f8f70c998391780b672eea5d5e49277c7John Hoford mTmpStrokData = 102a4f38c0f8f70c998391780b672eea5d5e49277c7John Hoford new FilterDrawRepresentation.StrokeData(); 10319161944e0efb1ffe23274d7cf5315ce047e9dacJohn Hoford } 10419161944e0efb1ffe23274d7cf5315ce047e9dacJohn Hoford 10519161944e0efb1ffe23274d7cf5315ce047e9dacJohn Hoford public Drawable getIcon(Context context) { 10619161944e0efb1ffe23274d7cf5315ce047e9dacJohn Hoford 10719161944e0efb1ffe23274d7cf5315ce047e9dacJohn Hoford return null; 108db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford } 109db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford 110db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford @Override 111db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford public void resetParameter() { 11219161944e0efb1ffe23274d7cf5315ce047e9dacJohn Hoford if (mFRep != null) { 11319161944e0efb1ffe23274d7cf5315ce047e9dacJohn Hoford mFRep.clear(); 114db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford } 115915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford } 116db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford 117915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford public void setColor(int color) { 118915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford mCurrentColor = color; 119915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford } 120915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford 121915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford public void setSize(int size) { 122915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford mCurrentSize = size; 123915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford } 124915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford 12519161944e0efb1ffe23274d7cf5315ce047e9dacJohn Hoford public void setStyle(byte style) { 12619161944e0efb1ffe23274d7cf5315ce047e9dacJohn Hoford mType = (byte) (style % ImageFilterDraw.NUMBER_OF_STYLES); 12719161944e0efb1ffe23274d7cf5315ce047e9dacJohn Hoford } 12819161944e0efb1ffe23274d7cf5315ce047e9dacJohn Hoford 12919161944e0efb1ffe23274d7cf5315ce047e9dacJohn Hoford public int getStyle() { 13019161944e0efb1ffe23274d7cf5315ce047e9dacJohn Hoford return mType; 131915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford } 132915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford 133915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford public int getSize() { 134915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford return (int) mCurrentSize; 135db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford } 136db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford 137db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford float[] mTmpPoint = new float[2]; // so we do not malloc 138db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford @Override 139db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford public boolean onTouchEvent(MotionEvent event) { 1402fc7efdcd75279649091471dda3ee600db25a995John Hoford if (event.getPointerCount() > 1) { 1418ce4df0105e645aed8503c3f03c98c208621911dJohn Hoford boolean ret = super.onTouchEvent(event); 1422fc7efdcd75279649091471dda3ee600db25a995John Hoford if (mFRep.getCurrentDrawing() != null) { 1432fc7efdcd75279649091471dda3ee600db25a995John Hoford mFRep.clearCurrentSection(); 1442fc7efdcd75279649091471dda3ee600db25a995John Hoford mEditorDraw.commitLocalRepresentation(); 1452fc7efdcd75279649091471dda3ee600db25a995John Hoford } 1462fc7efdcd75279649091471dda3ee600db25a995John Hoford return ret; 147df0b0c4eaafcc9e4652fe6ec0791e4abe1c3b750nicolasroard } 1482fc7efdcd75279649091471dda3ee600db25a995John Hoford if (event.getAction() != MotionEvent.ACTION_DOWN) { 1492fc7efdcd75279649091471dda3ee600db25a995John Hoford if (mFRep.getCurrentDrawing() == null) { 1508ce4df0105e645aed8503c3f03c98c208621911dJohn Hoford return super.onTouchEvent(event); 1512fc7efdcd75279649091471dda3ee600db25a995John Hoford } 152db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford } 153db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford 154db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford if (event.getAction() == MotionEvent.ACTION_DOWN) { 1552fc7efdcd75279649091471dda3ee600db25a995John Hoford calcScreenMapping(); 156db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford mTmpPoint[0] = event.getX(); 157db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford mTmpPoint[1] = event.getY(); 158db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford mToOrig.mapPoints(mTmpPoint); 159f4b659334750a5aa75f929d18857a2ab93c9d939John Hoford mFRep.startNewSection( mTmpPoint[0], mTmpPoint[1]); 160db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford } 161df0b0c4eaafcc9e4652fe6ec0791e4abe1c3b750nicolasroard 162db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford if (event.getAction() == MotionEvent.ACTION_MOVE) { 1632fc7efdcd75279649091471dda3ee600db25a995John Hoford 164db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford int historySize = event.getHistorySize(); 165db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford for (int h = 0; h < historySize; h++) { 166db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford int p = 0; 167db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford { 168db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford mTmpPoint[0] = event.getHistoricalX(p, h); 169db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford mTmpPoint[1] = event.getHistoricalY(p, h); 170db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford mToOrig.mapPoints(mTmpPoint); 17119161944e0efb1ffe23274d7cf5315ce047e9dacJohn Hoford mFRep.addPoint(mTmpPoint[0], mTmpPoint[1]); 172db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford } 173db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford } 174db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford } 175df0b0c4eaafcc9e4652fe6ec0791e4abe1c3b750nicolasroard 176db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford if (event.getAction() == MotionEvent.ACTION_UP) { 177db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford mTmpPoint[0] = event.getX(); 178db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford mTmpPoint[1] = event.getY(); 179db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford mToOrig.mapPoints(mTmpPoint); 18019161944e0efb1ffe23274d7cf5315ce047e9dacJohn Hoford mFRep.endSection(mTmpPoint[0], mTmpPoint[1]); 181db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford } 18219161944e0efb1ffe23274d7cf5315ce047e9dacJohn Hoford mEditorDraw.commitLocalRepresentation(); 183db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford invalidate(); 184db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford return true; 185db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford } 186db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford 187db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford private void calcScreenMapping() { 1882fc7efdcd75279649091471dda3ee600db25a995John Hoford mToOrig = getScreenToImageMatrix(true); 189db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford mToOrig.invert(mRotateToScreen); 190db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford } 191db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford 1924e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford private static Paint makeCheckedPaint(){ 1934e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford int[] colors = new int[16 * 16]; 1944e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford for (int i = 0; i < colors.length; i++) { 1954e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford int y = i / (16 * 8); 1964e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford int x = (i / 8) % 2; 1974e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford colors[i] = (x == y) ? 0xFF777777 : 0xFF222222; 1984e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford } 1994e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford Bitmap bitmap = Bitmap.createBitmap(colors, 16, 16, Bitmap.Config.ARGB_8888); 2004e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford BitmapShader bs = new BitmapShader(bitmap, Shader.TileMode.REPEAT, Shader.TileMode.REPEAT); 2014e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford Paint p = new Paint(); 2024e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford p.setShader(bs); 2034e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford return p; 2044e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford } 2054e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford 2064e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford private void setupTimer() { 2074e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford mHandler = new Handler(getActivity().getMainLooper()); 2084e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford } 2094e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford 2104e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford private void scheduleWakeup(int delay) { 2114e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford mHandler.removeCallbacks(mUpdateRunnable); 2124e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford mHandler.postDelayed(mUpdateRunnable, delay); 2134e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford } 2144e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford 2154e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford public Bitmap getBrush(int brushid) { 2164e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford Bitmap bitmap; 2174e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford BitmapFactory.Options opt = new BitmapFactory.Options(); 2184e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford opt.inPreferredConfig = Bitmap.Config.ALPHA_8; 2194e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford bitmap = BitmapFactory.decodeResource(getActivity().getResources(), brushid, opt); 2204e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford bitmap = bitmap.extractAlpha(); 2214e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford 2224e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford return bitmap; 2234e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford } 2244e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford 2254e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford public Bitmap createScaledBitmap(Bitmap src, int dstWidth, int dstHeight, boolean filter) { 2264e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford Matrix m = new Matrix(); 2274e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford m.setScale(dstWidth / (float) src.getWidth(), dstHeight / (float) src.getHeight()); 2284e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford Bitmap result = Bitmap.createBitmap(dstWidth, dstHeight, src.getConfig()); 2294e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford Canvas canvas = new Canvas(result); 2304e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford 2314e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford Paint paint = new Paint(); 2324e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford paint.setFilterBitmap(filter); 2334e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford canvas.drawBitmap(src, m, paint); 2344e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford 2354e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford return result; 2364e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford 2374e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford } 2384e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford 2394e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford public void displayDrawLook() { 2404e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford if (mFRep == null) { 2414e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford return; 2424e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford } 2434e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford int color = mTmpStrokData.mColor; 2444e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford byte type = mTmpStrokData.mType; 2454e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford float radius = mTmpStrokData.mRadius; 2464e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford mFRep.fillStrokeParameters(mTmpStrokData); 2474e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford 2486125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford if (radius != mTmpStrokData.mRadius) { 2496125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford mTimeout = DISPLAY_TIME + System.currentTimeMillis(); 2506125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford scheduleWakeup(DISPLAY_TIME); 2514e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford } 2524e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford } 2534e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford 2544e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford public void drawLook(Canvas canvas) { 2554e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford if (mFRep == null) { 2564e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford return; 2574e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford } 2584e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford int cw = canvas.getWidth(); 2594e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford int ch = canvas.getHeight(); 2604e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford int centerx = cw / 2; 2614e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford int centery = ch / 2; 2624e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford 2636125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford// mFRep.fillStrokeParameters(mTmpStrokData); 2644e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford mIconPaint.setAntiAlias(true); 2656125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford mIconPaint.setStyle(Paint.Style.STROKE); 2664e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford float rad = mRotateToScreen.mapRadius(mTmpStrokData.mRadius); 2676125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford 2684e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford RectF rec = new RectF(); 2696125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford rec.set(centerx - rad, 2706125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford centery - rad, 2716125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford centerx + rad, 2726125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford centery + rad); 2736125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford mIconPaint.setColor(Color.BLACK); 2746125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford mIconPaint.setStrokeWidth(5); 2756125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford canvas.drawArc(rec, 0, 360, true, mIconPaint); 2766125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford mIconPaint.setColor(Color.WHITE); 2776125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford mIconPaint.setStrokeWidth(3); 2786125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford canvas.drawArc(rec, 0, 360, true, mIconPaint); 2794e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford } 2804e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford 281db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford @Override 282db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford public void onDraw(Canvas canvas) { 283db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford super.onDraw(canvas); 28419161944e0efb1ffe23274d7cf5315ce047e9dacJohn Hoford calcScreenMapping(); 2854e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford if (System.currentTimeMillis() < mTimeout) { 2864e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford drawLook(canvas); 2874e289659f746cf659e300c9fcd2048960e115f0cJohn Hoford } 288db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford } 289915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford 290db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford} 291