commit
2cd46aacdf
@ -1,45 +0,0 @@
|
||||
apply plugin: 'com.android.application'
|
||||
|
||||
android {
|
||||
compileSdk 30
|
||||
buildToolsVersion '30.0.3'
|
||||
useLibrary'org.apache.http.legacy'
|
||||
defaultConfig {
|
||||
applicationId "net.micode.notes"
|
||||
minSdkVersion 22
|
||||
//noinspection ExpiredTargetSdkVersion
|
||||
targetSdkVersion 30
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
|
||||
}
|
||||
}
|
||||
sourceSets{
|
||||
main(){
|
||||
jniLibs.srcDirs = ['libs']
|
||||
}
|
||||
}
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_1_8
|
||||
targetCompatibility JavaVersion.VERSION_1_8
|
||||
}
|
||||
}
|
||||
dependencies {
|
||||
implementation 'com.android.support:appcompat-v7:28.0.0'
|
||||
implementation 'com.android.support.constraint:constraint-layout:2.0.4'
|
||||
implementation files('libs\\Msc.jar')
|
||||
implementation "androidx.drawerlayout:drawerlayout:1.1.1"
|
||||
implementation 'com.android.support:design:29.1.1'
|
||||
implementation 'com.zhihu.android:matisse:0.5.2-beta4'
|
||||
implementation 'com.github.bumptech.glide:glide:4.8.0'
|
||||
annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0'
|
||||
implementation 'com.simple:spiderman:1.0.2'
|
||||
implementation 'com.android.support.constraint:constraint-layout:2.0.4'
|
||||
testImplementation 'junit:junit:4.12'
|
||||
androidTestImplementation 'com.android.support.test:runner:1.0.2'
|
||||
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
|
||||
}
|
||||
|
@ -0,0 +1,117 @@
|
||||
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;
|
||||
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.widget.ImageView;
|
||||
import net.micode.notes.R;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
public class DrawActivity extends Activity {
|
||||
private ImageView img;
|
||||
private Bitmap mBitmap;
|
||||
private Canvas canvas;
|
||||
private Paint paint;
|
||||
// 重置按钮
|
||||
private Button reset_btn;
|
||||
private Button save_paint;
|
||||
|
||||
@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.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
img.setImageBitmap(null);
|
||||
showImage();
|
||||
}
|
||||
});
|
||||
save_paint = (Button)findViewById(R.id.save);
|
||||
save_paint.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
//save();
|
||||
finish();
|
||||
}
|
||||
});
|
||||
// 绘图
|
||||
showImage();
|
||||
}
|
||||
|
||||
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;
|
||||
@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 save() {
|
||||
File file = new File(Environment.getExternalStorageDirectory(),
|
||||
System.currentTimeMillis() + ".jpg");
|
||||
OutputStream stream;
|
||||
Log.i(TAG, Environment.getExternalStorageDirectory().toString());
|
||||
try {
|
||||
stream = new FileOutputStream(file);
|
||||
mBitmap.compress(Bitmap.CompressFormat.JPEG, 200, stream);
|
||||
stream.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/img"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/draw"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="2"
|
||||
tools:src="@tools:sample/backgrounds/scenic" />
|
||||
<Button
|
||||
android:id="@+id/reset"
|
||||
android:layout_width="200dp"
|
||||
android:layout_height="129dp"
|
||||
android:layout_weight="1"
|
||||
android:text="Button"
|
||||
android:layout_gravity="center|center_vertical"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/save"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="2"
|
||||
android:text="Button" />
|
||||
|
||||
|
||||
</LinearLayout>
|
Loading…
Reference in new issue