Advertisement
Guest User

Untitled

a guest
Apr 19th, 2015
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.47 KB | None | 0 0
  1. protected void onCreate(Bundle savedInstanceState) {
  2. super.onCreate(savedInstanceState);
  3. BrushView view=new BrushView(this);
  4. setContentView(view);
  5. addContentView(view.btnEraseAll, view.params);
  6. }
  7.  
  8. <LinearLayout
  9. android:orientation="vertical"
  10. android:layout_width="fill_parent"
  11. android:layout_height="150dp" android:id="@+id/myLinearLayout"
  12. android:layout_marginTop="10dp">
  13.  
  14. <com.sample.app.Libraries.BrushViewClass
  15. android:layout_width="fill_parent"
  16. android:layout_height="fill_parent"/>
  17. </LinearLayout>
  18.  
  19. public class BrushViewClass extends View {
  20. private Paint brush = new Paint();
  21. private Path path = new Path();
  22. public Button btnEraseAll;
  23. public LayoutParams params;
  24.  
  25. public BrushViewClass(Context context) {
  26. super(context);
  27. brush.setAntiAlias(true);
  28. brush.setColor(Color.BLUE);
  29. brush.setStyle(Paint.Style.STROKE);
  30. brush.setStrokeJoin(Paint.Join.ROUND);
  31. brush.setStrokeWidth(10f);
  32.  
  33. btnEraseAll = new Button(context);
  34. btnEraseAll.setText(UC.getString(R.string.redraw_again));
  35. params = new LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT);
  36.  
  37. btnEraseAll.setBackgroundDrawable(getResources().getDrawable(R.drawable.selector_button_actions));
  38. btnEraseAll.setLayoutParams(params);
  39. btnEraseAll.setOnClickListener(new OnClickListener() {
  40.  
  41. @Override
  42. public void onClick(View view) {
  43. path.reset();
  44. postInvalidate();
  45.  
  46. }
  47. });
  48. }
  49.  
  50. @Override
  51. public boolean onTouchEvent(MotionEvent event) {
  52. float pointX = event.getX();
  53. float pointY = event.getY();
  54.  
  55. // Checks for the event that occurs
  56. switch (event.getAction()) {
  57. case MotionEvent.ACTION_DOWN:
  58. path.moveTo(pointX, pointY);
  59.  
  60. return true;
  61. case MotionEvent.ACTION_MOVE:
  62. path.lineTo(pointX, pointY);
  63. break;
  64. case MotionEvent.ACTION_UP:
  65. break;
  66. default:
  67. return false;
  68. }
  69. // Force a view to draw.
  70. postInvalidate();
  71. return false;
  72.  
  73. }
  74. @Override
  75. protected void onDraw(Canvas canvas) {
  76. canvas.drawPath(path, brush);
  77. }
  78. }
  79.  
  80. BrushViewClass view=new BrushViewClass(this);
  81. LinearLayout myLinearLayout = (LinearLayout) findViewById(R.id.myLinearLayout);
  82. myLinearLayout.addView(view.btnEraseAll, view.params);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement