Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private boolean onTouchOrHoverEvent(MotionEvent event, boolean isTouch) {
- PaintMode mode = PaintMode.Draw;
- if ((buttonState & MotionEvent.BUTTON_TERTIARY) != 0) {
- // Splat paint when the middle mouse button or second stylus button is pressed.
- mode = PaintMode.Splat;
- } else if (isTouch || (buttonState & MotionEvent.BUTTON_PRIMARY) != 0) {
- // Draw paint when touching or if the primary button is pressed.
- mode = PaintMode.Draw;
- } else {
- // Otherwise, do not paint anything.
- return false;
- }
- final int action = event.getActionMasked();
- if (action == MotionEvent.ACTION_DOWN || action == MotionEvent.ACTION_MOVE) {
- final int N = event.getHistorySize();
- final int P = event.getPointerCount();
- for (int i = 0; i < N; i++) {
- for (int j = 0; j < P; j++) {
- paint(getPaintModeForTool(event.getToolType(j), mode),
- event.getHistoricalX(j, i),
- event.getHistoricalY(j, i),
- event.getHistoricalPressure(j, i),
- event.getHistoricalTouchMajor(j, i),
- event.getHistoricalTouchMinor(j, i),
- event.getHistoricalOrientation(j, i),
- event.getHistoricalAxisValue(MotionEvent.AXIS_DISTANCE, j, i),
- event.getHistoricalAxisValue(MotionEvent.AXIS_TILT, j, i));
- }
- }
- }
- return true;
- }
- private void paint(PaintMode mode, float x, float y, float pressure,
- float major, float minor, float orientation,
- float distance, float tilt) {
- if (mBitmap != null) {
- if (major <= 0 || minor <= 0) {
- // If size is not available, use a default value.
- major = minor = 16;
- }
- switch (mode) {
- case Draw:
- mPaint.setColor(COLORS[mColorIndex]);
- mPaint.setAlpha(Math.min((int)(pressure * 128), 255));
- drawOval(mCanvas, x, y, major, minor, orientation, mPaint);
- break;
- case Erase:
- mPaint.setColor(BACKGROUND_COLOR);
- mPaint.setAlpha(Math.min((int)(pressure * 128), 255));
- drawOval(mCanvas, x, y, major, minor, orientation, mPaint);
- break;
- case Splat:
- mPaint.setColor(COLORS[mColorIndex]);
- mPaint.setAlpha(64);
- drawSplat(mCanvas, x, y, orientation, distance, tilt, mPaint);
- break;
- }
- }
- mFadeSteps = 0;
- invalidate();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement