package com.example.wir.basetabproject.act;
import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Rect;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.text.Editable;
import android.text.Layout;
import android.text.StaticLayout;
import android.text.TextPaint;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import com.example.wir.basetabproject.R;
import com.example.wir.basetabproject.data.PaintData;
import com.example.wir.basetabproject.utils.AppUtils;
import java.util.ArrayList;
/**
* Created by jhs on 2018/1/10.
*/
public class SecondActivity extends Activity implements View.OnClickListener {
private ImageView iv;
private Bitmap bitmap, backgroud; //画纸和背景图
private Canvas canvas; //画布
private Paint paint; //画笔
private Path path;
//储存已经写的笔画
private ArrayList<PaintData> savePath = new ArrayList<PaintData>();
private View v_red;
private View v_blue;
private TextView tv_return;//撤回
private TextView tv_line;//线
private TextView tv_arrow;//箭头
private TextView tv_frame;//框
private TextView tv_save;//保存
private TextView tv_txt;//
int mColor = Color.RED;
private RelativeLayout rl_base;
TextPaint mTextPaint; //文字画笔
public final static int DRAW_TXT_SIZE = 15;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
iv = findViewById(R.id.iv);
rl_base = findViewById(R.id.rl_base);
v_red = findViewById(R.id.v_red);
v_blue = findViewById(R.id.v_blue);
tv_return = findViewById(R.id.tv_return);
tv_line = findViewById(R.id.tv_line);
tv_arrow = findViewById(R.id.tv_arrow);
tv_frame = findViewById(R.id.tv_frame);
tv_save = findViewById(R.id.tv_save);
tv_txt = findViewById(R.id.tv_txt);
v_red.setOnClickListener(this);
v_blue.setOnClickListener(this);
tv_return.setOnClickListener(this);
tv_line.setOnClickListener(this);
tv_arrow.setOnClickListener(this);
tv_frame.setOnClickListener(this);
tv_save.setOnClickListener(this);
tv_txt.setOnClickListener(this);
// bitmap = Bitmap.createBitmap(getWindowManager().getDefaultDisplay()
// .getWidth(), getWindowManager().getDefaultDisplay().getHeight(),
// Bitmap.Config.ARGB_8888);
// canvas = new Canvas(bitmap);// 画板 paint =
// iv.setImageBitmap(bitmap);
// iv.setImageResource(R.drawable.iv_bg);
//拿到背景图
// //拿到和背景图一样大小的画纸
// bitmap = Bitmap.createBitmap(getWindowManager().getDefaultDisplay()
// .getWidth(), getWindowManager().getDefaultDisplay().getHeight(),
// backgroud.getConfig());
// ChangeImageSize(this,iv,backgroud.getHeight(),backgroud.getWidth());
//拿到背景图
backgroud = BitmapFactory.decodeResource(getResources(), R.drawable.iv_bg);
backgroud = getbitmap(backgroud, iv);
ViewGroup.LayoutParams lp = rl_base.getLayoutParams();
lp.width = backgroud.getWidth();
lp.height = backgroud.getHeight();
rl_base.setLayoutParams(lp);
initCanvas();
iv.setOnTouchListener(lineListener);
}
private void initPaint() {
//拿到画笔
paint = new Paint();
paint.setColor(mColor);//设置画笔颜色为黑色
// 设置“空心”的外框的宽度
paint.setStrokeWidth(5);
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeCap(Paint.Cap.ROUND);
mTextPaint = new TextPaint();
mTextPaint.setColor(mColor);
mTextPaint.setTextSize(AppUtils.dip2px(DRAW_TXT_SIZE, getBaseContext()));
mTextPaint.setAntiAlias(true);
}
@Override
public void onClick(View view) {
showTxt();
switch (view.getId()) {
case R.id.v_blue:
mColor = Color.BLUE;
paint.setColor(mColor);
break;
case R.id.v_red:
mColor = Color.RED;
paint.setColor(mColor);
break;
case R.id.tv_line:
iv.setOnTouchListener(lineListener);
break;
case R.id.tv_arrow:
iv.setOnTouchListener(arrowListener);
break;
case R.id.tv_frame:
iv.setOnTouchListener(frameListener);
break;
case R.id.tv_txt:
iv.setOnTouchListener(textListener);
break;
case R.id.tv_return:
returnOne();
break;
case R.id.tv_save:
String path = AppUtils.saveMyBitmapForPath(this, bitmap);
Toast.makeText(this, "保存至" + path, Toast.LENGTH_SHORT).show();
break;
}
}
private void returnOne() {
if (savePath != null && savePath.size() > 0) {
initCanvas();
savePath.remove(savePath.size() - 1);
for (PaintData data : savePath) {
data.draw(canvas, getBaseContext());
}
}
}
private void clearNew() {
initCanvas();
if (savePath != null && savePath.size() > 0) {
for (PaintData data : savePath) {
data.draw(canvas, getBaseContext());
}
}
}
@Override
public void onBackPressed() {
showTxt();
super.onBackPressed();
}
//初始化画布
public void initCanvas() {
initPaint();
bitmap = Bitmap.createBitmap(backgroud.getWidth(), backgroud.getHeight(), backgroud.getConfig());
// //把画纸固定在画布上
canvas = new Canvas(bitmap);
// //添加处理规则
Matrix matrix = new Matrix();
// //照着背景图画
canvas.drawBitmap(backgroud, matrix, paint);
iv.setImageBitmap(bitmap);
}
private View.OnTouchListener lineListener = new View.OnTouchListener() {
private float mX, mY;
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
float x = motionEvent.getX();
float y = motionEvent.getY();
switch (motionEvent.getAction()) {
case MotionEvent.ACTION_DOWN:
paint.setColor(mColor);
path = new Path();
path.reset();//清空path
path.moveTo(x, y);
mX = x;
mY = y;
break;
case MotionEvent.ACTION_MOVE:
float dx = Math.abs(x - mX);
float dy = Math.abs(y - mY);
if (dx >= 4 || dy >= 4) {
没有合适的资源?快使用搜索试试~ 我知道了~
原生Android画板(非签名),自带曲线,带箭头直线,框,文字,以及撤销功能
共89个文件
xml:44个
png:12个
bin:10个
3星 · 超过75%的资源 需积分: 10 21 下载量 137 浏览量
2018-01-18
16:37:42
上传
评论 1
收藏 2.07MB ZIP 举报
温馨提示
自己写的Android画板,原生的,使用Canvas,输入文字功能特别难写~代码不多,主要是算~~
资源推荐
资源详情
资源评论
收起资源包目录
BaseTabProject.zip (89个子文件)
BaseTabProject
gradlew 5KB
settings.gradle 16B
BaseTabProject.iml 868B
.idea
libraries
com_android_support_support_fragment_26_1_0.xml 702B
org_hamcrest_hamcrest_integration_1_3_jar.xml 578B
android_arch_lifecycle_runtime_1_0_0.xml 658B
com_android_support_test_espresso_espresso_core_3_0_1.xml 710B
com_google_code_findbugs_jsr305_2_0_1_jar.xml 359B
com_android_support_support_compat_26_1_0.xml 692B
com_squareup_javawriter_2_1_1_jar.xml 538B
android_arch_core_common_1_0_0_jar.xml 533B
com_android_support_animated_vector_drawable_26_1_0.xml 742B
com_android_support_support_vector_drawable_26_1_0.xml 737B
javax_inject_javax_inject_1_jar.xml 528B
org_hamcrest_hamcrest_core_1_3_jar.xml 543B
android_arch_lifecycle_common_1_0_0_jar.xml 548B
com_android_support_constraint_constraint_layout_solver_1_0_2_jar.xml 380B
com_android_support_support_media_compat_26_1_0.xml 722B
com_android_support_support_annotations_26_1_0_jar.xml 608B
org_hamcrest_hamcrest_library_1_3_jar.xml 557B
com_android_support_test_espresso_espresso_idling_resource_3_0_1.xml 765B
com_android_support_support_core_utils_26_1_0.xml 712B
com_android_support_appcompat_v7_26_1_0.xml 682B
net_sf_kxml_kxml2_2_3_0_jar.xml 285B
com_android_support_test_rules_1_0_1.xml 652B
com_android_support_constraint_constraint_layout_1_0_2.xml 501B
com_android_support_support_core_ui_26_1_0.xml 697B
com_android_support_test_runner_1_0_1.xml 657B
junit_junit_4_12_jar.xml 487B
com_android_support_support_v4_26_1_0.xml 672B
runConfigurations.xml 564B
misc.xml 2KB
workspace.xml 177KB
gradle.xml 626B
modules.xml 365B
gradle
wrapper
gradle-wrapper.properties 236B
gradle-wrapper.jar 52KB
.gradle
buildOutputCleanup
cache.properties.lock 2B
cache.properties 51B
built.bin 0B
4.1
fileChanges
last-build.bin 1B
taskHistory
taskHistory.lock 17B
fileSnapshots.bin 2.31MB
taskHistory.bin 82KB
javaCompile
javaCompile.lock 17B
classAnalysis.bin 1.11MB
jarAnalysis.bin 314KB
taskJars.bin 20KB
taskHistory.bin 1.94MB
fileContent
fileContent.lock 17B
fileHashes
fileHashes.bin 499KB
resourceHashesCache.bin 19KB
fileHashes.lock 17B
local.properties 512B
gradlew.bat 2KB
gradle.properties 747B
.gitignore 127B
app
src
androidTest
java
test
java
main
AndroidManifest.xml 750B
res
mipmap-hdpi
ic_launcher.png 3KB
ic_launcher_round.png 5KB
mipmap-xxxhdpi
ic_launcher.png 9KB
ic_launcher_round.png 15KB
mipmap-xhdpi
ic_launcher.png 4KB
ic_launcher_round.png 7KB
mipmap-anydpi-v26
ic_launcher.xml 276B
ic_launcher_round.xml 276B
mipmap-mdpi
ic_launcher.png 2KB
ic_launcher_round.png 3KB
drawable
ic_launcher_background.xml 6KB
iv_bg2.png 64KB
iv_bg.png 447KB
layout
activity_main1.xml 3KB
activity_first.xml 702B
activity_second.xml 5KB
activity_main.xml 916B
drawable-v24
ic_launcher_foreground.xml 2KB
values
colors.xml 214B
strings.xml 80B
styles.xml 394B
mipmap-xxhdpi
ic_launcher.png 6KB
ic_launcher_round.png 10KB
java
com
example
wir
basetabproject
utils
AppUtils.java 3KB
data
PaintData.java 2KB
act
SecondActivity.java 20KB
libs
app.iml 12KB
.gitignore 8B
build.gradle 963B
proguard-rules.pro 772B
build.gradle 573B
共 89 条
- 1
资源评论
- 木头人CXG2018-09-08功能很强大,但是缺少一些功能哈1
丨SnowFly
- 粉丝: 3
- 资源: 10
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 基于python和opencv的样本交互标注工具+源码+文档说明(期末大作业&课程设计&项目开发)
- IMG_20240329_150532.jpg
- 《电路》大作业:基于matlab实现的节点电压法计算+源代码+文档说明
- 3401-VB一款P-Channel沟道SOT23的MOSFET晶体管参数介绍与应用说明
- Mysql 版中国省市区数据表SQL
- 数值分析,基于MATLAB GUI 的“数值分析方法”计算器+源代码+文档说明
- 基于matlab水果识别系统代码32gui界面设计
- 基于Python大规模文本分析系统的开题报告.docx
- 3401-CMN3401-VB一款P-Channel沟道SOT23的MOSFET晶体管参数介绍与应用说明
- python实现的四则运算计算器
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功