Place your order today at a 20% discount

Android Studio (Java)
 
The SimplePaint app (full code given below) allows users to draw pictures by pressing the screen in the app.
 
The existing SimplePaint app allows users to draw using “circles” using the “SimpleDrawingView.java (using circles)” code given below. Add a button at the top of the app to allow users to toggle between drawing:
 
(a) using circle
 
(b) using path (path code is given below)
 
activity_main.xml
 
<?xml version=”1.0″ encoding=”utf-8″?>
 
<RelativeLayout
 
    xmlns:android=”http://schemas.android.com/apk/res/android”
 
    xmlns:tools=”http://schemas.android.com/tools”
 
    android:layout_width=”match_parent”
 
    android:layout_height=”match_parent”
 
    tools:context=”.MainActivity”>
 
    <com.example.simplepaint.SimpleDrawingView
 
        android:layout_width=”wrap_content”
 
        android:layout_height=”wrap_content”
 
        android:layout_alignParentBottom=”true”
 
        android:layout_alignParentLeft=”true”
 
        android:layout_alignParentRight=”true”
 
        android:layout_alignParentTop=”true”
 
        />
 
</RelativeLayout>
MainActivity.java
 
package com.example.simplepaint;
 
 
import androidx.appcompat.app.AppCompatActivity;
 
import android.os.Bundle;
 
 
 
public class MainActivity extends AppCompatActivity {
 
    @Override
 
    protected void onCreate(Bundle savedInstanceState) {
 
        super.onCreate(savedInstanceState);
 
        setContentView(R.layout.activity_main);
 
    }
 
}
SimpleDrawingView.java (using circles)
 
package com.example.simplepaint;
 
 
 
import android.content.Context;
 
import android.graphics.Canvas;
 
import android.graphics.Color;
 
import android.graphics.Paint;
 
import android.graphics.Path;
 
import android.graphics.Point;
 
import android.util.AttributeSet;
 
import android.view.MotionEvent;
 
import android.view.View;
 
import java.util.ArrayList;
 
import java.util.List;
 
 
public class SimpleDrawingView extends View {
 
    // setup initial color
 
    private final int paintColor = Color.BLACK;
 
    // defines paint and canvas
 
    private Paint drawPaint;
 
    // Store circles to draw each time the user touches down
 
    private List<Point> circlePoints;
 
 
 
    public SimpleDrawingView(Context context, AttributeSet attrs) {
 
        super(context, attrs);
 
        setupPaint(); // same as before
 
        circlePoints = new ArrayList<Point>();
 
    }
 
    // Draw each circle onto the view
 
    @Override
 
    protected void onDraw(Canvas canvas) {
 
        for (Point p : circlePoints) {
 
            canvas.drawCircle(p.x, p.y, 5, drawPaint);
 
        }
 
    }
 
 
 
    // Append new circle each time user presses on screen
 
    @Override
 
    public boolean onTouchEvent(MotionEvent event) {
 
        float touchX = event.getX();
 
        float touchY = event.getY();
 
        circlePoints.add(new Point(Math.round(touchX), Math.round(touchY)));
 
        // indicate view should be redrawn
 
        postInvalidate();
 
        return true;
 
    }
 
 
 
    private void setupPaint() {
 
        drawPaint = new Paint();
 
        drawPaint.setColor(paintColor);
 
        drawPaint.setAntiAlias(true);
 
        drawPaint.setStrokeWidth(5);
 
        drawPaint.setStyle(Paint.Style.FILL);
 
        drawPaint.setStrokeJoin(Paint.Join.ROUND);
 
        drawPaint.setStrokeCap(Paint.Cap.ROUND);
 
    }
 
}
 
SimpleDrawingView.java (using path)
 
package com.example.simplepaint;
 
 
 
import android.content.Context;
 
import android.graphics.Canvas;
 
import android.graphics.Color;
 
import android.graphics.Paint;
 
import android.graphics.Path;
 
import android.util.AttributeSet;
 
import android.view.MotionEvent;
 
import android.view.View;
 
 
 
public class SimpleDrawingView extends View {
 
    // setup initial color
 
    private final int paintColor = Color.BLACK;
 
    // defines paint and canvas
 
    private Paint drawPaint;
 
    // stores next circle
 
    private Path path = new Path();
 
 
 
    public SimpleDrawingView(Context context, AttributeSet attrs) {
 
        super(context, attrs);
 
        setFocusable(true);
 
        setFocusableInTouchMode(true);
 
        setupPaint();
 
    }
 
 
 
    private void setupPaint() {
 
        // Setup paint with color and stroke styles
 
        drawPaint = new Paint();
 
        drawPaint.setColor(paintColor);
 
        drawPaint.setAntiAlias(true);
 
        drawPaint.setStrokeWidth(5);
 
        drawPaint.setStyle(Paint.Style.STROKE);
 
        drawPaint.setStrokeJoin(Paint.Join.ROUND);
 
        drawPaint.setStrokeCap(Paint.Cap.ROUND);
 
    }
 
    @Override
 
    protected void onDraw(Canvas canvas) {
 
        canvas.drawPath(path, drawPaint);
 
    }
 
    @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;
 
            default:
 
                return false;
 
 
 
        }
 
 
 
        // Force a view to draw again
 
        postInvalidate();
 
        return true;
 
    }
 
}
The assignment Android Studio (Java) The SimplePaint app (full code given below) allows users to draw pictures by pressing the screen in the app. has been handled previously by writers from Wridemy.

Don't use plagiarized sources. Get Your Custom Essay on
Android Studio (Java) The SimplePaint app (full code given below) allows users to draw pictures by pressing the screen in the app.
From Just $13/Page
Order Essay

About ASAP Essays

We are a professional paper writing website. If you have searched a question and bumped into our website just know you are in the right place to get help in your coursework. We offer HIGH QUALITY & PLAGIARISM FREE Papers.

How It Works

To make an Order you only need to click on “Order Now” and we will direct you to our Order Page. Fill Our Order Form with all your assignment instructions. Select your deadline and pay for your paper. You will get it few hours before your set deadline.

Are there Discounts?

All new clients are eligible for 20% off in their first Order. Our payment method is safe and secure.

Hire a tutor today CLICK HERE to make your first order

  

Order your Assignment today and save 15% with the discount code ESSAYHELP

X