基于Android手机电子书阅读器的设计与实现毕业设计 联系客服

发布时间 : 星期四 文章基于Android手机电子书阅读器的设计与实现毕业设计更新完毕开始阅读e3cee3ca29ea81c758f5f61fb7360b4c2e3f2a38

}

}

handler.sendEmptyMessage(-1);

扫描文本文件部分代码: public void getAllFiles(File root) {

File files[] = root.listFiles(new MyFileFilter(false,\ if (files != null) { for (File f : files) { if (f.isDirectory()) { getAllFiles(f); } else if ( f.length() > 1024 * 100) { Map tem = new HashMap(); tem.put(\ tem.put(\ tem.put(\ num++; handler.sendEmptyMessage(num); listTem.add(tem); isSelect.add(false); } } } }

3.4文件浏览模块功能描述

下面是文件浏览模块主页面,使用ListView组件显示文件目录,不同的文件类型显示不同的图标如图13所示。最上面标题栏有导航按钮,当点击导航按钮时会从左侧弹出导航栏如图14所示,导航栏中有标记文件按钮、分类排序按钮和添加到书架按钮,点击标记文件按钮或长按某文件或目录时则切换到多选模式,其中有多选按钮、反选按钮和取消按钮;点击分类排序则弹出子菜单,其中有按名称排序、按大小排序、按时间排序和按类型排序;点击添加到书架时如果为选择文件则自动进入多选模式让用户进行文件选择,如果用户未选择则提示“请选择书籍”,进行选择是用户可选择文件或目录,系统会自动进行扫描,把符合要求的文件添加到“最近书架”中,并弹出提示信息,其中有失败个数、已存在个数和成功个数。在多选模式下点击返回按钮或点击标记文件会取消多选模式。非多选模式下,用户点击文件时本软件会根据文件扩展名来判断打开文件方式如图15所示,如果是文本文件则直接用本软件打开,并把其添加到“最近书架”中,其它格式则调用对应的软件打开,如果是未识别的类型则提示“没有打开此文件的应用”。

图13 文件浏览页面 图14 文件浏览导航栏 图15 打开视频文件

文件路径导航实现代码: public void navigationBar() { String[] strPath = null; try { strPath = currentParent.getCanonicalPath().split(\ } catch (IOException e1) { e1.printStackTrace(); }

tvpath.removeAllViews();

for (int i = 1; i < strPath.length; i++) { final FrameLayout frameLayout = new FrameLayout( FileExplorerActivity.this); final LinearLayout linyou = new LinearLayout( FileExplorerActivity.this); final TextView imageText = new TextView(FileExplorerActivity.this); imageText.setGravity(Gravity.CENTER); imageText.setTextColor(Color.BLUE); if (i > 1) { if (i == 2) { imageText.setPadding(10, 0, 20, 0); imageText.setText(\存储器\ } else { imageText.setPadding(10, 0, 20, 0); imageText.setText(strPath[i]); } if (i == strPath.length - 1) { linyou.setBackgroundResource(R.drawable.rights_);

}

}

} else { linyou.setBackgroundResource(R.drawable.middle); } linyou.setOnClickListener(new imageTextListener(i, strPath.length, strPath)); }

frameLayout.addView(linyou); frameLayout.addView(imageText); tvpath.addView(frameLayout);

不同类型文件打开方式的核心代码如下: private void OpenPhoto(String work_answer) { Intent intent = null;

final String res_path = work_answer;

String suffixName=res_path.substring(res_path.lastIndexOf(\ .toLowerCase(); if (!new File(res_path).exists()) { Toast.makeText(this, suffixName + \资源不存在\ Toast.LENGTH_SHORT).show(); } else { //选择打开方式 if (\ intent = Utils.getWordFileIntent(res_path); }else if (\ intent = Utils.getPptFileIntent(res_path); }else if (\ intent = Utils.getExcelFileIntent(res_path); } else if (\ ||\ intent = Utils.getImageFileIntent(res_path); } else if (\ intent = Utils.getPdfFileIntent(res_path); } else if (\ intent = Utils.getAudioFileIntent(res_path); } else if (\ intent = Utils.getHtmlFileIntent(res_path); } else if (\ intent = Utils.getChmFileIntent(res_path); } else if (\ ||\ ||\ intent = Utils.getVideoFileIntent(res_path); } else if (\//设置文本打开方式为当前应用

}

}

int p1 = res_path.lastIndexOf(\ int p2 = res_path.lastIndexOf(\ long mFileSize = new File(res_path).length(); BookDatabaseHelper helper = new BookDatabaseHelper( FileExplorerActivity.this); SQLiteDatabase db = helper.getWritableDatabase(); BooksTableOperate booksTableOperate = new BooksTableOperate(db); booksTableOperate.insert(res_path.substring(p1 + 1, p2), res_path, getFileSize(mFileSize)); ActivityMain.myTabHost.setCurrentTab(1); helper = new BookDatabaseHelper(FileExplorerActivity.this); db = helper.getWritableDatabase(); booksTableOperate = new BooksTableOperate(db); BookInfo book = booksTableOperate.getBook(res_path); Intent it = new Intent(FileExplorerActivity.this, ReaderActivity.class); Bundle bundle = new Bundle(); bundle.putInt(\ bundle.putString(\ bundle.putString(\ bundle.putInt(\ it.putExtras(bundle); startActivity(it); db.close(); return;

} else if (\ intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(Uri.fromFile(new File(suffixName)), \ startActivity(intent); } else { Toast.makeText(this, \不支持\文件格式\ Toast.LENGTH_SHORT).show(); } try { this.startActivity(intent); } catch (Exception e) { Toast.makeText(this, \没有打开此文件的应用\ Toast.LENGTH_SHORT).show(); e.printStackTrace(); }