Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- "An android app that allows you to simply draw onto a canvas."
- OBJECTIVES/HOW IT WORKS:
- - Once you start up the app, the canvas is right there with the buttons (save, gallery, about) right under it.
- - Have a palette to draw a picture using your finger on a canvas.
- - You'll be able to switch between the colors while drawing.
- - Have a 'save' button that enables you to save the picture and then it goes into a gallery.
- - Have a fully functioning gallery where all your saved pictures go, and you can share it to Facebook, Twitter, etc.
- - Have an about button that takes you to the about activity where it tells you the purpose of the program and the people that developed it.
- BUTTONS:
- BOTTOM:
- - Save: Saves whatever is on the canvas and puts it into the gallery or your photos.
- - Reset: Resets the canvas.
- - About: Tells you about the app.
- TOP:
- - Red: Changes the paint to red. (#FF0000)
- - Yellow: Changes the paint to yellow. (#FFFF00)
- - Green: Changes the paint to green. (#00CC00)
- - Blue: Changes the paint to blue. (#0000FF)
- - Black: Changes the paint to black. (#000000)
- - Purple: Changes the paint to purple. (#CC00CC)
- - Orange: Changes the paint to orange. (#FF8000)
- - Erase: Changes the paint to white. (#FFFFFF)
- - Thickness Plus Button: Increases the thickness of the paintbrush.
- - Thickness Minus Button: Decreases the thickness of the paintbrush.
- 3 Buttons
- 10 Image Buttons
- 13 Total Buttons
- LINKS:
- http://code.tutsplus.com/tutorials/android-sdk-create-a-drawing-app-touch-interaction--mobile-19202
- http://examples.javacodegeeks.com/android/core/graphics/canvas-graphics/android-canvas-example/
- http://www.rapidtables.com/web/color/RGB_Color.htm
- http://developer.android.com/reference/android/graphics/Paint.html
- https://www.airpair.com/android/photo-gallery-android-studio-list-fragments
- http://www.c-sharpcorner.com/UploadFile/e14021/capture-image-from-camera-and-selecting-image-from-gallery-o/
- https://stackoverflow.com/questions/2283444/android-image-button
- https://stackoverflow.com/questions/13946936/how-to-gap-between-two-buttons-in-linearlayout
- -----------------------------------------------------------------------------------------------------------------------------
- <?xml version="1.0" encoding="utf-8"?>
- <manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="com.samkough.painter" >
- <application
- android:allowBackup="true"
- android:icon="@mipmap/ic_launcher"
- android:label="@string/app_name"
- android:theme="@style/AppTheme" >
- <activity
- android:name=".MainActivity"
- android:label="@string/app_name" >
- <intent-filter>
- <action android:name="android.intent.action.MAIN" />
- <category android:name="android.intent.category.LAUNCHER" />
- </intent-filter>
- </activity>
- <activity
- android:name=".AboutActivity"
- android:label="@string/title_activity_about" >
- </activity>
- </application>
- <uses-permission android:name="android.permission.INTERNET" />
- <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
- <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
- </manifest>
- -----------------------------------------------------------------------------------------------------------------------------
- apply plugin: 'com.android.application'
- android {
- compileSdkVersion 22
- buildToolsVersion "22.0.1"
- defaultConfig {
- applicationId "com.samkough.painter"
- minSdkVersion 22
- targetSdkVersion 22
- versionCode 1
- versionName "1.0"
- }
- buildTypes {
- release {
- minifyEnabled false
- proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
- }
- }
- }
- dependencies {
- compile fileTree(dir: 'libs', include: ['*.jar'])
- compile 'com.squareup.picasso:picasso:2.5.2'
- }
- -----------------------------------------------------------------------------------------------------------------------------
- package samkough.com.painter;
- import android.content.Context;
- import android.graphics.Bitmap;
- import android.graphics.Canvas;
- import android.graphics.Color;
- import android.graphics.Paint;
- import android.graphics.Path;
- import android.util.AttributeSet;
- import android.util.TypedValue;
- import android.view.MotionEvent;
- import android.view.View;
- public class CanvasView extends View
- {
- /*
- * When the user touches the screen and moves their finger to draw,
- * we will use a Path to trace their drawing action on the canvas.
- * Both the canvas and the drawing on top of it are represented by Paint
- * objects. The initial paint color corresponds to the first color
- * in the palette we created last time, which will be initially selected
- * when the app launches. Finally we declare variables for the canvas
- * and bitmap - the user paths drawn with drawPaint will be drawn onto
- * the canvas, which is drawn with canvasPaint.
- * */
- //drawing paint
- private Paint paint = new Paint();
- // canvas paint
- private Paint canvasPaint = new Paint();
- //drawing path
- private Path path = new Path();
- // canvas
- private Canvas canvas = new Canvas();
- //canvas bitmap
- private Bitmap canvasBitmap;
- // brush size and pixel size
- private float brushSize, pixelAmount;
- public CanvasView(Context context, AttributeSet attrs)
- {
- // Setting the anti-alias, stroke join and cap styles will make the user's drawings appear smoother.
- super(context, attrs);
- paint.setAntiAlias(true);
- paint.setStrokeWidth(5);
- paint.setColor(Color.BLACK);
- paint.setStyle(Paint.Style.STROKE);
- paint.setStrokeJoin(Paint.Join.ROUND);
- paint.setStrokeCap(Paint.Cap.ROUND);
- }
- @Override
- protected void onSizeChanged(int w, int h, int oldw, int oldh)
- {
- super.onSizeChanged(w, h, oldw, oldh);
- canvasBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
- canvas = new Canvas(canvasBitmap);
- }
- @Override
- protected void onDraw(Canvas drawCanvas)
- {
- drawCanvas.drawBitmap(canvasBitmap, 0, 0, canvasPaint);
- drawCanvas.drawPath(path, paint);
- }
- @Override
- public boolean onTouchEvent(MotionEvent e)
- {
- // get the coords of the touch event
- float eventX = e.getX();
- float eventY = e.getY();
- switch (e.getAction()) {
- case MotionEvent.ACTION_DOWN:
- // set a new starting point
- path.moveTo(eventX, eventY);
- return true;
- case MotionEvent.ACTION_MOVE:
- // connect the points
- path.lineTo(eventX, eventY);
- break;
- default:
- return false;
- }
- // makes you view repaint and call ondraw
- invalidate();
- return true;
- }
- public void clearCanvas()
- {
- path.reset();
- invalidate();
- }
- public void setStrokeWidth(float f)
- {
- pixelAmount = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, f, getResources().getDisplayMetrics());
- brushSize = pixelAmount;
- paint.setAntiAlias(true);
- paint.setStyle(Paint.Style.STROKE);
- paint.setStrokeJoin(Paint.Join.ROUND);
- paint.setStrokeCap(Paint.Cap.ROUND);
- paint.setStrokeWidth(brushSize);
- invalidate();
- }
- public void setColor(int p)
- {
- paint.setAntiAlias(true);
- paint.setStyle(Paint.Style.STROKE);
- paint.setStrokeJoin(Paint.Join.ROUND);
- paint.setStrokeCap(Paint.Cap.ROUND);
- paint.setColor(p);
- invalidate();
- }
- }
- -----------------------------------------------------------------------------------------------------------------------------
- package com.samkough.painter;
- import android.app.Activity;
- import android.content.Intent;
- import android.graphics.Color;
- import android.os.Bundle;
- import android.view.Menu;
- import android.view.MenuItem;
- import android.view.View;
- import android.widget.Button;
- import android.widget.ImageButton;
- public class MainActivity extends Activity {
- private CanvasView canvasView;
- private int orange;
- private int purple;
- private float strokeWidth;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- canvasView = (CanvasView) findViewById(R.id.canvasView);
- orange = Color.rgb(250, 128, 0);
- purple = Color.rgb(128, 0, 128);
- strokeWidth = 0;
- // REGULAR BUTTONS: save, about, reset
- Button saveB = (Button) findViewById(R.id.saveButton);
- Button aboutB = (Button) findViewById(R.id.aboutButton);
- Button resetB = (Button) findViewById(R.id.resetButton);
- // IMAGE BUTTONS: red, blue, green, yellow, black, purple, orange, erase, brush thickness plus, brush thickness minus
- ImageButton redIb = (ImageButton) findViewById(R.id.redButton);
- ImageButton blueIb = (ImageButton) findViewById(R.id.blueButton);
- ImageButton greenIb = (ImageButton) findViewById(R.id.greenButton);
- ImageButton yellowIb = (ImageButton) findViewById(R.id.yellowButton);
- ImageButton blackIb = (ImageButton) findViewById(R.id.blackButton);
- ImageButton purpleIb = (ImageButton) findViewById(R.id.purpleButton);
- ImageButton orangeIb = (ImageButton) findViewById(R.id.orangeButton);
- ImageButton eraseIb = (ImageButton) findViewById(R.id.eraseButton);
- ImageButton plusIb = (ImageButton) findViewById(R.id.plusButton);
- ImageButton minusIb = (ImageButton) findViewById(R.id.minusButton);
- minusIb.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v)
- {
- strokeWidth -= 2;
- canvasView.setStrokeWidth(strokeWidth);
- }
- });
- plusIb.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- strokeWidth += 2;
- canvasView.setStrokeWidth(strokeWidth);
- }
- });
- eraseIb.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- canvasView.setColor(Color.TRANSPARENT);
- }
- });
- orangeIb.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- canvasView.setColor(orange);
- }
- });
- purpleIb.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- canvasView.setColor(purple);
- }
- });
- blackIb.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- canvasView.setColor(Color.BLACK);
- }
- });
- yellowIb.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- canvasView.setColor(Color.YELLOW);
- }
- });
- greenIb.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- canvasView.setColor(Color.GREEN);
- }
- });
- blueIb.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- canvasView.setColor(Color.BLUE);
- }
- });
- redIb.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- canvasView.setColor(Color.RED);
- }
- });
- saveB.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- }
- });
- aboutB.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- Intent intent = new Intent(getApplicationContext(), AboutActivity.class);
- startActivity(intent);
- }
- });
- resetB.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- canvasView.clearCanvas();
- }
- });
- }
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- // Inflate the menu; this adds items to the action bar if it is present.
- getMenuInflater().inflate(R.menu.menu_main, menu);
- return true;
- }
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- // Handle action bar item clicks here. The action bar will
- // automatically handle clicks on the Home/Up button, so long
- // as you specify a parent activity in AndroidManifest.xml.
- int id = item.getItemId();
- //noinspection SimplifiableIfStatement
- if (id == R.id.action_settings) {
- return true;
- }
- return super.onOptionsItemSelected(item);
- }
- }
- -----------------------------------------------------------------------------------------------------------------------------
- <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" android:paddingLeft="@dimen/activity_horizontal_margin"
- android:paddingRight="@dimen/activity_horizontal_margin"
- android:paddingTop="@dimen/activity_vertical_margin"
- android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"
- android:background="#B3B1B1">
- <LinearLayout
- android:orientation="vertical"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:layout_alignParentTop="true"
- android:layout_alignParentStart="true"
- android:id="@+id/linearLayout">
- <LinearLayout
- android:orientation="horizontal"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:gravity="center"
- android:layout_gravity="center_horizontal">
- <ImageButton
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:src="@drawable/red_button"
- android:background="@null"
- android:padding="5dp"
- android:id="@+id/redButton" />
- <ImageButton
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:src="@drawable/blue_button"
- android:background="@null"
- android:padding="5dp"
- android:id="@+id/blueButton"
- android:layout_gravity="center_horizontal" />
- <ImageButton
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:padding="5dp"
- android:src="@drawable/green_button"
- android:background="@null"
- android:id="@+id/greenButton" />
- <ImageButton
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:src="@drawable/yellow_button"
- android:background="@null"
- android:padding="5dp"
- android:id="@+id/yellowButton" />
- <ImageButton
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:src="@drawable/orange_button"
- android:background="@null"
- android:id="@+id/orangeButton"
- android:padding="5dp"
- android:layout_gravity="right" />
- <ImageButton
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:src="@drawable/purple_button"
- android:background="@null"
- android:padding="5dp"
- android:id="@+id/purpleButton"
- android:layout_gravity="right" />
- <ImageButton
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:src="@drawable/black_button"
- android:background="@null"
- android:padding="5dp"
- android:id="@+id/blackButton"
- android:layout_gravity="center_horizontal" />
- <ImageButton
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:background="@null"
- android:padding="5dp"
- android:src="@drawable/eraser_button"
- android:id="@+id/eraseButton"
- android:layout_gravity="center_horizontal" />
- <ImageButton
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:padding="5dp"
- android:src="@drawable/minus_sign"
- android:background="@null"
- android:id="@+id/minusButton" />
- <ImageButton
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:src="@drawable/plus_sign"
- android:padding="5dp"
- android:background="@null"
- android:id="@+id/plusButton" />
- </LinearLayout>
- <com.samkough.painter.CanvasView
- android:layout_width="match_parent"
- android:layout_height="400dp"
- android:id="@+id/canvasView"
- android:background="#ffffff"
- android:layout_alignParentEnd="true"
- android:clickable="true" />
- <LinearLayout
- android:orientation="horizontal"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:id="@+id/buttonLayout"
- android:gravity="center"
- android:layout_alignParentTop="true"
- android:layout_alignParentStart="true">
- <Button
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="Save"
- android:id="@+id/saveButton" />
- <Button
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="About"
- android:id="@+id/aboutButton"/>
- <Button
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="Reset"
- android:id="@+id/resetButton" />
- </LinearLayout>
- </LinearLayout>
- </RelativeLayout>
- -----------------------------------------------------------------------------------------------------------------------------
- package com.samkough.painter;
- import android.app.Activity;
- import android.os.Bundle;
- import android.view.Menu;
- import android.view.MenuItem;
- public class AboutActivity extends Activity {
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_about);
- }
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- // Inflate the menu; this adds items to the action bar if it is present.
- getMenuInflater().inflate(R.menu.menu_about, menu);
- return true;
- }
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- // Handle action bar item clicks here. The action bar will
- // automatically handle clicks on the Home/Up button, so long
- // as you specify a parent activity in AndroidManifest.xml.
- int id = item.getItemId();
- //noinspection SimplifiableIfStatement
- if (id == R.id.action_settings) {
- return true;
- }
- return super.onOptionsItemSelected(item);
- }
- }
- -----------------------------------------------------------------------------------------------------------------------------
- <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" android:paddingLeft="@dimen/activity_horizontal_margin"
- android:paddingRight="@dimen/activity_horizontal_margin"
- android:paddingTop="@dimen/activity_vertical_margin"
- android:paddingBottom="@dimen/activity_vertical_margin"
- android:background="#7A3737"
- tools:context="samkough.com.painter.AboutActivity">
- <ScrollView
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:id="@+id/scrollView">
- <LinearLayout
- android:orientation="vertical"
- android:layout_width="match_parent"
- android:layout_height="match_parent">
- <ImageView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:id="@+id/paintLogo"
- android:src="@drawable/paint_palette"
- android:layout_below="@+id/scrollView"
- android:layout_centerHorizontal="true"
- android:layout_gravity="center_horizontal" />
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="250dp"
- android:textAppearance="?android:attr/textAppearanceLarge"
- android:text="Painter is a drawing app which allows you to draw onto a canvas and then save it onto your gallery. It gives you a variety of tools to work with as well."
- android:id="@+id/aboutText"
- android:gravity="center"
- android:fontFamily=""
- android:textColor="#FFFFFF"
- android:textSize="30dp"
- android:layout_marginTop="37dp"
- android:layout_below="@+id/paintLogo"
- android:layout_toEndOf="@+id/scrollView"
- android:layout_column="8" />
- <ImageView
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:src="@drawable/profile_pic"
- android:id="@+id/profilePic" />
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="Sammy Samkough is a young ambitious programmer. With new ideas and new creations, he hopes to appease to the masses with his newfound apps."
- android:id="@+id/meText"
- android:gravity="center"
- android:fontFamily=""
- android:textColor="#FFFFFF"
- android:textSize="30dp"
- />
- </LinearLayout>
- </ScrollView>
- </RelativeLayout>
- -----------------------------------------------------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement