|
|
|
@ -1,7 +1,5 @@
|
|
|
|
|
package net.micode.notes.ui;
|
|
|
|
|
|
|
|
|
|
import static net.micode.notes.tool.DataUtils.TAG;
|
|
|
|
|
|
|
|
|
|
import android.app.Activity;
|
|
|
|
|
import android.graphics.Bitmap;
|
|
|
|
|
import android.graphics.Canvas;
|
|
|
|
@ -9,19 +7,20 @@ import android.graphics.Color;
|
|
|
|
|
import android.graphics.Matrix;
|
|
|
|
|
import android.graphics.Paint;
|
|
|
|
|
import android.os.Bundle;
|
|
|
|
|
import android.os.Environment;
|
|
|
|
|
import android.util.Log;
|
|
|
|
|
import android.view.MotionEvent;
|
|
|
|
|
import android.view.View;
|
|
|
|
|
import android.widget.Button;
|
|
|
|
|
import android.view.ViewTreeObserver;
|
|
|
|
|
import android.widget.ImageButton;
|
|
|
|
|
import android.widget.ImageView;
|
|
|
|
|
import android.widget.RelativeLayout;
|
|
|
|
|
|
|
|
|
|
import net.micode.notes.R;
|
|
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.io.FileNotFoundException;
|
|
|
|
|
import java.io.FileOutputStream;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.io.OutputStream;
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
|
|
|
|
@ -31,15 +30,16 @@ public class DrawActivity extends Activity {
|
|
|
|
|
private Canvas canvas;
|
|
|
|
|
private Paint paint;
|
|
|
|
|
// 重置按钮
|
|
|
|
|
private Button reset_btn;
|
|
|
|
|
private Button save_paint;
|
|
|
|
|
private ImageButton reset_btn;
|
|
|
|
|
private ImageButton save_paint;
|
|
|
|
|
private boolean if_draw = false;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
setContentView(R.layout.activity_second);
|
|
|
|
|
img = (ImageView) findViewById(R.id.draw);
|
|
|
|
|
reset_btn = (Button) findViewById(R.id.reset);
|
|
|
|
|
reset_btn = (ImageButton) findViewById(R.id.reset);
|
|
|
|
|
reset_btn.setOnClickListener(new View.OnClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onClick(View v) {
|
|
|
|
@ -47,14 +47,16 @@ public class DrawActivity extends Activity {
|
|
|
|
|
showImage();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
save_paint = (Button)findViewById(R.id.save);
|
|
|
|
|
save_paint = (ImageButton)findViewById(R.id.save);
|
|
|
|
|
save_paint.setOnClickListener(new View.OnClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onClick(View view) {
|
|
|
|
|
String path = saveBitmap();
|
|
|
|
|
getIntent().putExtra("path", path);
|
|
|
|
|
setResult(1, getIntent());
|
|
|
|
|
Log.i(null, path);
|
|
|
|
|
if (if_draw) {
|
|
|
|
|
String path = saveBitmap();
|
|
|
|
|
getIntent().putExtra("path", path);
|
|
|
|
|
setResult(1, getIntent());
|
|
|
|
|
Log.i(null, path);
|
|
|
|
|
}
|
|
|
|
|
finish();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
@ -63,46 +65,62 @@ public class DrawActivity extends Activity {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void showImage() {
|
|
|
|
|
// 创建一张空白图片
|
|
|
|
|
mBitmap = Bitmap.createBitmap(720, 1280, Bitmap.Config.ARGB_8888);
|
|
|
|
|
// 创建一张画布
|
|
|
|
|
canvas = new Canvas(mBitmap);
|
|
|
|
|
// 画布背景为白色
|
|
|
|
|
canvas.drawColor(Color.WHITE);
|
|
|
|
|
// 创建画笔
|
|
|
|
|
paint = new Paint();
|
|
|
|
|
// 画笔颜色为蓝色
|
|
|
|
|
paint.setColor(Color.BLUE);
|
|
|
|
|
// 宽度5个像素
|
|
|
|
|
paint.setStrokeWidth(5);
|
|
|
|
|
// 先将白色背景画上
|
|
|
|
|
canvas.drawBitmap(mBitmap, new Matrix(), paint);
|
|
|
|
|
img.setImageBitmap(mBitmap);
|
|
|
|
|
|
|
|
|
|
img.setOnTouchListener(new View.OnTouchListener() {
|
|
|
|
|
int startX;
|
|
|
|
|
int startY;
|
|
|
|
|
ImageView huabu = (ImageView) findViewById(R.id.draw);
|
|
|
|
|
ViewTreeObserver vto = huabu.getViewTreeObserver();
|
|
|
|
|
vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onTouch(View v, MotionEvent event) {
|
|
|
|
|
switch (event.getAction()) {
|
|
|
|
|
case MotionEvent.ACTION_DOWN:
|
|
|
|
|
// 获取手按下时的坐标
|
|
|
|
|
startX = (int) event.getX();
|
|
|
|
|
startY = (int) event.getY();
|
|
|
|
|
break;
|
|
|
|
|
case MotionEvent.ACTION_MOVE:
|
|
|
|
|
// 获取手移动后的坐标
|
|
|
|
|
int endX = (int) event.getX();
|
|
|
|
|
int endY = (int) event.getY();
|
|
|
|
|
// 在开始和结束坐标间画一条线
|
|
|
|
|
canvas.drawLine(startX, startY, endX, endY, paint);
|
|
|
|
|
// 刷新开始坐标
|
|
|
|
|
startX = (int) event.getX();
|
|
|
|
|
startY = (int) event.getY();
|
|
|
|
|
img.setImageBitmap(mBitmap);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
public void onGlobalLayout() {
|
|
|
|
|
huabu.getViewTreeObserver().removeGlobalOnLayoutListener(this);
|
|
|
|
|
// 获取线性布局控件的高
|
|
|
|
|
int height = huabu.getHeight();
|
|
|
|
|
// 获取线性布局控件的宽
|
|
|
|
|
int width = huabu.getWidth();
|
|
|
|
|
//按照画布控件大小创建画布
|
|
|
|
|
mBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
|
|
|
|
|
// 创建一张画布
|
|
|
|
|
canvas = new Canvas(mBitmap);
|
|
|
|
|
// 画布背景为白色
|
|
|
|
|
canvas.drawColor(Color.WHITE);
|
|
|
|
|
// 创建画笔
|
|
|
|
|
paint = new Paint();
|
|
|
|
|
// 画笔颜色为蓝色
|
|
|
|
|
paint.setColor(Color.BLUE);
|
|
|
|
|
// 宽度5个像素
|
|
|
|
|
paint.setStrokeWidth(5);
|
|
|
|
|
//接缝处圆滑
|
|
|
|
|
paint.setStrokeCap(Paint.Cap.ROUND);
|
|
|
|
|
paint.setStrokeJoin(Paint.Join.ROUND);
|
|
|
|
|
// 先将白色背景画上
|
|
|
|
|
canvas.drawBitmap(mBitmap, new Matrix(), paint);
|
|
|
|
|
img.setImageBitmap(mBitmap);
|
|
|
|
|
|
|
|
|
|
img.setOnTouchListener(new View.OnTouchListener() {
|
|
|
|
|
int startX;
|
|
|
|
|
int startY;
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onTouch(View v, MotionEvent event) {
|
|
|
|
|
if_draw = true;
|
|
|
|
|
switch (event.getAction()) {
|
|
|
|
|
case MotionEvent.ACTION_DOWN:
|
|
|
|
|
// 获取手按下时的坐标
|
|
|
|
|
startX = (int) event.getX();
|
|
|
|
|
startY = (int) event.getY();
|
|
|
|
|
break;
|
|
|
|
|
case MotionEvent.ACTION_MOVE:
|
|
|
|
|
// 获取手移动后的坐标
|
|
|
|
|
int endX = (int) event.getX();
|
|
|
|
|
int endY = (int) event.getY();
|
|
|
|
|
// 在开始和结束坐标间画一条线
|
|
|
|
|
canvas.drawLine(startX, startY, endX, endY, paint);
|
|
|
|
|
// 刷新开始坐标
|
|
|
|
|
startX = (int) event.getX();
|
|
|
|
|
startY = (int) event.getY();
|
|
|
|
|
img.setImageBitmap(mBitmap);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|