【android开发】手写签名系统的设计与实现之实现文件夹以及文件列表显示(一)

来源:互联网 发布:linux jdk rpm 编辑:程序博客网 时间:2024/05/16 18:19

 随着移动设备的普及,人们越来越依赖移动设备,它带给人们许多的方便。其中手写签名,在一些金融行业使用较为普遍,目前手写签名系统有几款很不错,免费使用的不多。由于前一段时间项目需要,做了一个简单的手写签名系统,不是很完善,不过对于一般的需求是可以满足的,主要是针对pdf文件进行的操作,现在拿来给大家分享,希望有好的实现方式,能指点一下,大家共同进步。我们先看一下效果图:

           选择打开pdf文件                                 进入主界面                                选择要签名的位置

                    

         设置画笔的属性                                  在画板上签字                             预览签字效果

                  

一、模块划分:

1、文件查看模块

2、pdf解析模块

3、手写模块

4、生成新的pdf模块

  我们将针对每一个模块进行介绍,今天我们先介绍第一个模块---文件查看模块的实现原来及过程。

二、实现原理:

使用File类,读取当前文件夹中的所有文件及文件夹,并放在list集合中:

tems = new ArrayList<String>();paths = new ArrayList<String>();File presentFile = new  File(path);File[] files = presentFile.listFiles();// 显示当前路径,并返回根目录items.add("当前路径:"+path+" 文件个数:"+files.length);paths.add(rootPath);if (! path.equals(rootPath)) {// 返回上一级目录items.add("Back");paths.add(presentFile.getParent());}// 添加当前路径下的所有的文件名和路径for (File f : files) {items.add(f.getName());paths.add(f.getPath());}

最后将集合传给适配器,通过对文件名来判断文件类型:

// 设置列表适配器setListAdapter(new FileListAdapter(FileActivity.this, items, paths));
File f = new File(paths.get(position));//如果f表示的是一个目录则返回trueif(f.isDirectory()){if(fileName.contains("当前路径")){holder.imageIcon.setImageBitmap(rootIcon); }else if(fileName.equals("Back")){    holder.imageIcon.setImageBitmap(prevIcon);     }else if(f.canRead()){holder.imageIcon.setImageBitmap(folderIcon); }else{holder.imageIcon.setImageBitmap(NotReadfolderIcon); }}else{if(f.canRead()){//判断文件类型if(fileName.contains(".pdf")){holder.imageIcon.setImageBitmap(PdfFileIcon);}else if(fileName.contains(".apk")){holder.imageIcon.setImageBitmap(APKFileIcon);}else if(fileName.contains(".mp3") || fileName.contains(".ape") || fileName.contains(".flac")){holder.imageIcon.setImageBitmap(MP3FileIcon);}else if(fileName.contains(".png") || fileName.contains(".jpg") || fileName.contains(".bmp")){holder.imageIcon.setImageBitmap(PicFileIcon);}else{holder.imageIcon.setImageBitmap(docIcon); }}else{holder.imageIcon.setImageBitmap(NotReaddocIcon);}}
事前将不同文件及文件夹的图片保存到bitmap对象中:

// 初始化关联图标rootIcon = BitmapFactory.decodeResource(context.getResources(), R.drawable.sym_keyboard_shift);prevIcon = BitmapFactory.decodeResource(context.getResources(), R.drawable.sym_keyboard_return);//返回上一级菜单docIcon = BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_gesturebuilder);//显示文本文件NotReaddocIcon = BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_gesturebuilder_notread);//显示文本文件folderIcon = BitmapFactory.decodeResource(context.getResources(), R.drawable.live_folder_notes);//显示文件夹NotReadfolderIcon = BitmapFactory.decodeResource(context.getResources(), R.drawable.live_folder_cnntread);//显示不可读文件夹PdfFileIcon = BitmapFactory.decodeResource(context.getResources(), R.drawable.ico_pdf);APKFileIcon = BitmapFactory.decodeResource(context.getResources(), R.drawable.apk_icon);MP3FileIcon = BitmapFactory.decodeResource(context.getResources(), R.drawable.mp3);PicFileIcon = BitmapFactory.decodeResource(context.getResources(), R.drawable.picture);

通过上面我们看到,对文件的操作主要还是用到了file类,实现一个文件目录其实是很简单的。

到此,文件目录已经完成了,今天说的是比较简单的,详细代码就不全部贴出来了,在最后边将把代码下载链接留给大家,需要的朋友可以下载看看。明天我们将会介绍比较重要的模块-解析pdf。欢迎大家继续关注,对于不足之处敬请指正,大家一起进步,上传资源已经运行,没有问题,如果你不能运行,请在博客留言……

【android开发】手写签名系统的设计与实现之实现文件夹以及文件列表显示(一)


6 0
原创粉丝点击