NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

package com.example.paintapplication;

import android.Manifest;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;

import yuku.ambilwarna.AmbilWarnaDialog;

public class MainActivity extends AppCompatActivity {

private PaintView paintView;
private int defaultColor;
private int STORAGE_PERMISSION_CODE = 1;

@Override
protected void onCreate(Bundle savedInstanceState) {

Button button;

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

paintView = findViewById(R.id.paintView);
button = findViewById(R.id.change_color_button);
DisplayMetrics displayMetrics = new DisplayMetrics();
SeekBar seekBar = findViewById(R.id.seekBar);
final TextView textView = findViewById(R.id.current_pen_size);

getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);

paintView.initialise(displayMetrics);

textView.setText("Pen size: " + seekBar.getProgress());

button.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {

openColourPicker();

}

});

seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {

paintView.setStrokeWidth(seekBar.getProgress());
textView.setText("Pen size: " + seekBar.getProgress());

}

@Override
public void onStartTrackingTouch(SeekBar seekBar) {

}

@Override
public void onStopTrackingTouch(SeekBar seekBar) {

}
});

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {

MenuInflater menuInflater = getMenuInflater();
menuInflater.inflate(R.menu.main, menu);

return super.onCreateOptionsMenu(menu);

}

private void requestStoragePermission () {

if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)) {

new AlertDialog.Builder(this)
.setTitle("Permission needed")
.setMessage("Needed to save image")
.setPositiveButton("OK", new DialogInterface.OnClickListener() {

@Override
public void onClick(DialogInterface dialog, int which) {

ActivityCompat.requestPermissions(MainActivity.this, new String[] {Manifest.permission.WRITE_EXTERNAL_STORAGE}, STORAGE_PERMISSION_CODE);

}
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {

@Override
public void onClick(DialogInterface dialog, int which) {

dialog.dismiss();

}

})
.create().show();

} else {

ActivityCompat.requestPermissions(this, new String[] {Manifest.permission.WRITE_EXTERNAL_STORAGE}, STORAGE_PERMISSION_CODE);

}

}

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {

if (requestCode == STORAGE_PERMISSION_CODE) {

if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {

Toast.makeText(this, "Access granted", Toast.LENGTH_LONG).show();

} else {

Toast.makeText(this, "Access denied", Toast.LENGTH_LONG).show();

}

}

}

@Override
public boolean onOptionsItemSelected(MenuItem item) {

switch (item.getItemId()) {

case R.id.clear_button:
paintView.clear();
return true;
case R.id.undo_button:
paintView.undo();
return true;
case R.id.redo_button:
paintView.redo();
return true;
case R.id.save_button:

if (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {

requestStoragePermission();

}
paintView.saveImage();
return true;

}

return super.onOptionsItemSelected(item);

}

private void openColourPicker () {

AmbilWarnaDialog ambilWarnaDialog = new AmbilWarnaDialog(this, defaultColor, new AmbilWarnaDialog.OnAmbilWarnaListener() {

@Override
public void onCancel(AmbilWarnaDialog dialog) {

Toast.makeText(MainActivity.this, "Unavailable", Toast.LENGTH_LONG).show();

}

@Override
public void onOk(AmbilWarnaDialog dialog, int color) {

defaultColor = color;

paintView.setColor(color);

}

});

ambilWarnaDialog.show(); // add

}
}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.