package com.example.lenovo.mynotebook.function;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.os.Environment;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.style.ImageSpan;
import android.util.DisplayMetrics;
import android.util.Log;
import android.widget.EditText;
import android.widget.ScrollView;
import com.example.lenovo.mynotebook.MainActivity;
import com.example.lenovo.mynotebook.R;
import com.example.lenovo.mynotebook.db.DBdataSource;
import com.example.lenovo.mynotebook.model.NoteInfo;
import com.example.lenovo.mynotebook.ui.MessageBox;
import com.example.lenovo.mynotebook.ui.UiHelper;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.io.FileDescriptor;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
/*
封装一些操作编辑器的方法
*/
public class NoteWrapper {
/*
此接口的作用是想edit_activity传送一个新的NoteInfo
*/
public interface INoteInfo{
void getANewNote(NoteInfo noteInfo);
}
public NoteWrapper (INoteInfo iNoteInfo,Context contexts) {
this.iNoteInfo=iNoteInfo;
context=contexts;
}
private static Context context;
private static String TAG = "Listview and ScrollView item 截图:";
public static final String PARTENIMAGEPATH="/sdcard/myImage/[0-9]*.jpg";
private INoteInfo iNoteInfo=null;
private DBdataSource dBdataSource=null;
private NoteInfo noteInfo=null;
private MessageBox messageBox=null;
private Intent intent=null;
private String name;
private String type;
/*
将插入如的图片保存到文件并返回路径名
*/
public String SaveToFile(String FilePath,String name,Bitmap bitmap){
FileOutputStream FOut = null;
File file = new File(FilePath);
// File file=StorageUtils.getOwnCacheDirectory
file.mkdirs();// 创建文件夹
String fileName = FilePath+name;
File pfile = new File(FilePath,name);
try {
FOut = new FileOutputStream(pfile);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, FOut);// 把数据写入文件
} catch (FileNotFoundException e) {
e.printStackTrace();
}finally {
try {
FOut.flush();
FOut.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return fileName;
}
/*
内容中是否包含图片
*/
public boolean isHaveImage(String content){
Pattern p=Pattern.compile(PARTENIMAGEPATH);
Matcher m=p.matcher(content);
if(m.find())
return true;
else
return false;
}
/*
将截图保存到文件
*/
public File bitMap2File(Bitmap bitmap) {
String path = "";
if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
path = Environment.getExternalStorageDirectory() + File.separator;//保存到sd根目录下
}
// File f = new File(path, System.currentTimeMillis() + ".jpg");
File f = new File(path, "share" + ".jpg");
if (f.exists()) {
f.delete();
}
try {
FileOutputStream out = new FileOutputStream(f);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);
out.flush();
out.close();
bitmap.recycle();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
return f;
}
}
/*
截图压缩
*/
public Bitmap compressImage(Bitmap image) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
image.compress(Bitmap.CompressFormat.JPEG, 10, baos);//质量压缩方法,这里100表示不压缩,把压缩后的数据存放到baos中
int options = 100;
while (baos.toByteArray().length / 1024 > 400) { //循环判断如果压缩后图片是否大于400kb,大于继续压缩(这里可以设置大些)
baos.reset();//重置baos即清空baos
image.compress(Bitmap.CompressFormat.JPEG, options, baos);//这里压缩options%,把压缩后的数据存放到baos中
options -= 10;//每次都减少10
}
ByteArrayInputStream isBm = new ByteArrayInputStream(baos.toByteArray());//把压缩后的数据baos存放到ByteArrayInputStream中
Bitmap bitmap = BitmapFactory.decodeStream(isBm, null, null);//把ByteArrayInputStream数据生成图片
return bitmap;
}
/*
获取ScrollView的截屏长图
*/
public static Bitmap getScrollViewBitmap(ScrollView scrollView, String picpath) {
int h = 0;
Bitmap bitmap=null;
// 获取listView实际高度
for (int i = 0; i < scrollView.getChildCount(); i++) {
h += scrollView.getChildAt(i).getHeight();
}
//从drable文件中获取背景图片转换成Bitmap
Bitmap icon = BitmapFactory.decodeResource(context.getResources(), R.drawable.timg);
//然后根据ScrollView的实际高度拉伸背景图片
icon=Bitmap.createScaledBitmap(icon,scrollView.getWidth(),h,true);
Log.d(TAG, "实际高度:" + h);
Log.d(TAG, " 高度:" + scrollView.getHeight());
// 创建对应大小的bitmap,此时这个Bitmap还未画上任何团
bitmap = Bitmap.createBitmap(scrollView.getWidth(), h,
Bitmap.Config.ARGB_8888);
final Canvas canvas = new Canvas(bitmap);
//将拉伸好的背景图片覆盖上去,画布就创建好了
canvas.drawBitmap(icon,0,0,null);
//将ScrollView的内容画到画布上
scrollView.draw(canvas);
return bitmap;
}
//计算图片的缩放值
public int calculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight) {
final int height = options.outHeight;
final int width = options.outWidth;
int inSampleSize = 1;
if (height > reqHeight || width > reqWidth) {
final int heightRatio = Math.round((float) height / (float) reqHeight);
final int widthRatio = Math.round((float) width / (float) reqWidth);
inSampleSize = heightRatio < widthRatio ? heightRatio : widthRatio;
}
return inSampleSize;
}
/*
获取图片的比例
*/
public BitmapFactory.Options getBili(int reqWidth, int reqHeight){
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
// Calculate inSampleSize
options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);
// Decode bitmap with inSampleSize set
options.inJustDecodeBounds = false;
return options;
}
/*
进一步修饰图片大小
*/
public Bitmap jinyibu(Bitmap bitmap,Context context){
DisplayMetrics dm = context.getResources().getDisplayMetrics();
int w_screen = dm.widthPixels;
int w_width = w_screen;
int b_width = bitmap.getWidth();
int b_height = bitmap.getHeight();
int w_height = w_width * b_height / b_width;
bitmap = Bitmap.createScaledBitmap(bitmap, w_width, w_height, false);
return bitmap;
}
/*
解析内容:用到了正则表达式
获取EditView的
没有合适的资源?快使用搜索试试~ 我知道了~
Android实现可以图文混合和长截图的日记本App,优秀安卓课程设计!
共68个文件
xml:16个
java:16个
png:11个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
5星 · 超过95%的资源 1 下载量 13 浏览量
2023-03-16
16:47:20
上传
评论 4
收藏 2.26MB ZIP 举报
温馨提示
本程序的亮点: 1.更换了字体叹墨咏黑 2.这个记事本程序支持图文混排 3.可以从相机、图库调取图片 4.可以将笔记分享为长图 5.长按ListView多选删除 6.必要的提醒:例如按两次退出程序 本程序的技术关键点 1.采用了多线程技术以提升程序的性能:主要在MainActivity中的onResume()方法 中进行异步访问数据库来获取列表的信息,这里主要用了AsyncTask这个轻量级异步任务类 2.使用Sqlite来保存数据:表列项有时间(Text)、内容(Text)、类型(Text)、名字(Text)、ID号(Integer)。使用了SQLiteOpenHelper类 3.应用了MVC模式来设计整个程序的架构 4.使用了各种Bitmap类操作方法压缩、解析、优化、获取图片 5.ListView长按实现Actionbar多选删除 6.在编辑框贴上图片时将图片自动生成一个文件名存在/sdcard/myImage/文件夹 7.利用SpannableString、ImageSpan和editable三个类加上对光标的操作实现在EditText的插入图片
资源推荐
资源详情
资源评论
收起资源包目录
BoteBook.zip (68个子文件)
BoteBook
.gradle
buildOutputCleanup
cache.properties 53B
buildOutputCleanup.lock 17B
outputFiles.bin 21KB
5.6.4
fileChanges
last-build.bin 1B
vcsMetadata-1
fileHashes
fileHashes.lock 17B
fileHashes.bin 18KB
gc.properties 0B
vcs-1
gc.properties 0B
gradle.properties 726B
gradle
wrapper
gradle-wrapper.jar 53KB
gradle-wrapper.properties 232B
app
src
androidTest
java
com
example
lenovo
mynotebook
ExampleInstrumentedTest.java 742B
test
java
com
example
lenovo
mynotebook
ExampleUnitTest.java 390B
main
ic_launcher-web.png 12KB
assets
fonts
new.ttf 1.12MB
java
com
example
lenovo
mynotebook
adapter
DataAdapter.java 3KB
repository
Myrepository.java 803B
edit_activity.java 14KB
function
StringFunction.java 599B
NoteWrapper.java 14KB
SearchNoteAsyncTask.java 1KB
MyDate.java 1KB
model
NoteInfo.java 1KB
MainActivity.java 9KB
ui
UiHelper.java 285B
MessageBox.java 5KB
db
DBSchema.java 1020B
MyDBhelper.java 727B
DBdataSource.java 6KB
res
mipmap-xxhdpi
ic_launcher_round.png 10KB
ic_launcher.png 3KB
mipmap-hdpi
ic_launcher_round.png 5KB
ic_launcher.png 2KB
drawable-v24
ic_launcher_foreground.xml 2KB
timg.jpg 18KB
mipmap-anydpi-v26
ic_launcher.xml 272B
ic_launcher_round.xml 272B
menu
menu_main.xml 877B
my_listview_ctx_menu.xml 394B
mipmap-mdpi
ic_launcher_round.png 3KB
ic_launcher.png 1KB
mipmap-xxxhdpi
ic_launcher_round.png 15KB
ic_launcher.png 4KB
values-v21
styles.xml 248B
mipmap-xhdpi
ic_launcher_round.png 7KB
ic_launcher.png 2KB
xml
file_paths.xml 206B
values
colors.xml 208B
strings.xml 74B
styles.xml 454B
layout
edit_activity.xml 2KB
activity_main.xml 2KB
item_of_listview.xml 2KB
inputdialog.xml 708B
drawable
ic_launcher_background.xml 5KB
timg.jpg 18KB
AndroidManifest.xml 1KB
proguard-rules.pro 751B
build.gradle 932B
release
app-release.apk 1.43MB
output.json 234B
.gitignore 7B
gradlew.bat 2KB
build.gradle 396B
settings.gradle 15B
local.properties 330B
gradlew 5KB
.gitignore 137B
共 68 条
- 1
资源评论
- lz什么都不会啊2023-12-25支持这个资源,内容详细,主要是能解决当下的问题,感谢大佬分享~
振华OPPO
- 粉丝: 27w+
- 资源: 532
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功