Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- BrushView view=new BrushView(this);
- setContentView(view);
- addContentView(view.btnEraseAll, view.params);
- }
- <LinearLayout
- android:orientation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="150dp" android:id="@+id/myLinearLayout"
- android:layout_marginTop="10dp">
- <com.sample.app.Libraries.BrushViewClass
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"/>
- </LinearLayout>
- public class BrushViewClass extends View {
- private Paint brush = new Paint();
- private Path path = new Path();
- public Button btnEraseAll;
- public LayoutParams params;
- public BrushViewClass(Context context) {
- super(context);
- brush.setAntiAlias(true);
- brush.setColor(Color.BLUE);
- brush.setStyle(Paint.Style.STROKE);
- brush.setStrokeJoin(Paint.Join.ROUND);
- brush.setStrokeWidth(10f);
- btnEraseAll = new Button(context);
- btnEraseAll.setText(UC.getString(R.string.redraw_again));
- params = new LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT);
- btnEraseAll.setBackgroundDrawable(getResources().getDrawable(R.drawable.selector_button_actions));
- btnEraseAll.setLayoutParams(params);
- btnEraseAll.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View view) {
- path.reset();
- postInvalidate();
- }
- });
- }
- @Override
- public boolean onTouchEvent(MotionEvent event) {
- float pointX = event.getX();
- float pointY = event.getY();
- // Checks for the event that occurs
- switch (event.getAction()) {
- case MotionEvent.ACTION_DOWN:
- path.moveTo(pointX, pointY);
- return true;
- case MotionEvent.ACTION_MOVE:
- path.lineTo(pointX, pointY);
- break;
- case MotionEvent.ACTION_UP:
- break;
- default:
- return false;
- }
- // Force a view to draw.
- postInvalidate();
- return false;
- }
- @Override
- protected void onDraw(Canvas canvas) {
- canvas.drawPath(path, brush);
- }
- }
- BrushViewClass view=new BrushViewClass(this);
- LinearLayout myLinearLayout = (LinearLayout) findViewById(R.id.myLinearLayout);
- myLinearLayout.addView(view.btnEraseAll, view.params);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement