Advertisement
Guest User

Untitled

a guest
Jan 24th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. public class DrawingImageView extends View {
  2.  
  3. private PointF point;
  4. private Paint paint = new Paint();
  5. Initialization init; //<---------------------
  6.  
  7. public DrawingImageView(Context context) {
  8. super(context);
  9. init = new Initialization(); <-------------------
  10. }
  11.  
  12. public DrawingImageView(Context context, AttributeSet attrs) {
  13. super(context, attrs);
  14. }
  15.  
  16. public DrawingImageView(Context context, AttributeSet attrs, int defStyleAttr) {
  17. super(context, attrs, defStyleAttr);
  18. }
  19.  
  20. @Override
  21. public boolean onTouchEvent(@NonNull MotionEvent event) {
  22. float x = event.getX();
  23. float y = event.getY();
  24.  
  25. switch (event.getAction()) {
  26. case MotionEvent.ACTION_DOWN:
  27. point = new PointF(x, y);
  28. invalidate();
  29. break;
  30. case MotionEvent.ACTION_MOVE:
  31. point.set(x, y);
  32. invalidate();
  33. break;
  34. case MotionEvent.ACTION_UP:
  35. case MotionEvent.ACTION_CANCEL:
  36. point = null;
  37. invalidate();
  38. break;
  39. }
  40. return true;
  41. }
  42.  
  43. @Override
  44. protected void onDraw(@NonNull Canvas canvas) {
  45. super.onDraw(canvas);
  46. if (point != null) {
  47. canvas.drawCircle(point.x, point.y, 100, paint);
  48. canvas.drawBitmap(init.b01,10,10,paint);<------------
  49. }
  50. }
  51. }
  52.  
  53. public class Initialization extends Activity {
  54. Bitmap b01;
  55.  
  56.  
  57.  
  58. public Initialization() {
  59. Bitmap b05 = BitmapFactory.decodeResource(getResources(), R.raw.t02);
  60. }
  61. }
  62. `
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement