android.graphics.EmbossMaskFilter;import android.graphics.Paint;import android.graphics.Path;import android.graphics.PorterDuff;import android.graphics.PorterDuffXfermode;import android.graphics.Rect;import android.os.Environment;import android.util.AttributeSet;import android.view.MotionEvent;import android.view.View;import br.com.infocusweb.flexpag.R;/** * View responsavel por desenhar na tela atravas do touch. * * @author Felipe Bonezi -> felipebonezi@gmail.com * @version 1.0.0 * @category View * */public class DrawingBoard extends View { private static final float TOUCH_TOLERANCE = 4; private static final String DIR_ROOT_NAME = "FlexPag"; private static final String DIR_SIGNATURE_NAME = "Signatures"; public static final String EXTRA_SIGNATURE = "SIGNATURE_EXTRA"; private int mWidth; private int mHeight; private int mPaintColor; private int mBoardColor; private float mStrokeSize; private float mX, mY; private boolean mIsEnable = true; private boolean mIsSigned = false; private Bitmap mBitmap; private Canvas mCanvas; private Path mPath; private Paint mPaint; private final Paint mBitmapPaint; private final EmbossMaskFilter mEmboss; private String mFullName = null; private Paint mPaint2; private Rect mBoundsName; private Paint mTextPaint; public DrawingBoard(final Context context) { super(context); mPath = new Path(); mBitmapPaint = new Paint(Paint.DITHER_FLAG); mEmboss = new EmbossMaskFilter(new float[] { 1, 1, 1 }, 0.4f, 6, 3.5f); mPaintColor = Color.BLACK; mBoardColor = Color.TRANSPARENT; } public DrawingBoard(final Context context, final AttributeSet attrs, final int defStyle) { super(context, attrs, defStyle); mPath = new Path(); mBitmapPaint = new Paint(Paint.DITHER_FLAG); mEmboss = new EmbossMaskFilter(new float[] { 1, 1, 1 }, 0.4f, 6, 3.5f); mPaintColor = Color.BLACK; mBoardColor = Color.TRANSPARENT; } public DrawingBoard(final Context context, final AttributeSet attrs) { super(context, attrs); mPath = new Path(); mBitmapPaint = new Paint(Paint.DITHER_FLAG); mEmboss = new EmbossMaskFilter(new float[] { 1, 1, 1 }, 0.4f, 6, 3.5f); mPaintColor = Color.BLACK; mBoardColor = Color.TRANSPARENT; } @Override protected void onSizeChanged(final int width, final int height, final int oldWidth, final int oldHeight) { super.onSizeChanged(width, height, oldWidth, oldHeight); mWidth = width; mHeight = height; mBitmap = Bitmap.createBitmap(mWidth, mHeight, Bitmap.Config.ARGB_8888); mCanvas = new Canvas(mBitmap); } @Override protected void onDraw(final Canvas canvas) { canvas.drawColor(mBoardColor); canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint); if (mPaint == null) { final float dimen = Float.parseFloat(getContext().getString(R.dimen.text_stroke_signature).substring(0, 1)); mStrokeSize = dimen; mPaint = createNewPaint(mPaintColor, mStrokeSize); } canvas.drawPath(mPath, mPaint); if(!mIsSigned && mIsEnable) { mPaint2 = new Paint(); mPaint2.setColor(Color.BLACK); mPaint2.setTextSize(30f); final Rect bounds = new Rect(); mPaint2.getTextBounds("Assine aqui...", 0, "Assine aqui...".length(), bounds); canvas.drawText("Assine aqui...", (mWidth / 2) - bounds.centerX(), (mHeight - 100), mPaint2); } canvas.drawLine(25, (mHeight - 50), (mWidth - 25), (mHeight - 50), mPaint2); if (mBoundsName == null) { mBoundsName = new Rect(); mTextPaint = new Paint(); final float dimen = Float.parseFloat(getContext().getString(R.dimen.text_signature).substring(0, 2)); if (isInEditMode()) { mTextPaint.setTextSize(18); } else { mTextPaint.setTextSize(dimen); } } if(mFullName != null) { mTextPaint.getTextBounds(mFullName, 0, mFullName.length(), mBoundsName); canvas.drawText(mFullName, (mWidth/2 - mBoundsName.centerX()), (mHeight - 25), mTextPaint); } } @Override public boolean onTouchEvent(final MotionEvent event) { if (mIsEnable) { draw(new Canvas()); final float x = event.getX(); final float y = event.getY(); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: touchStart(x, y); invalidate(); break; case MotionEvent.ACTION_MOVE: touchMove(x, y); invalidate(); break; case MotionEvent.ACTION_UP: touchUp(); invalidate(); mIsSigned = true; break; default: break; } return true; } else { return false; } } private Paint createNewPaint(final int color, final float strokeSize) { final Paint paint = new Paint(); paint.setAntiAlias(true); paint.setDither(true); paint.setColor(color); paint.setStyle(Paint.Style.STROKE); paint.setStrokeJoin(Paint.Join.ROUND); paint.setStrokeCap(Paint.Cap.ROUND); paint.setStrokeWidth(strokeSize); return paint; } private void touchStart(final float x, final float y) { mPath.reset(); mPath.moveTo(x, y); mX = x; mY = y; } private void touchMove(final float