Demo下载地址:https://download.csdn.net/download/as425017946/10664926
1.基本思路:
打开网络pdf 思路整体还是来源与图片的加载。
android中加载网络图片的框架有很多个。如image-laoder, fresco、glide等,首先都是从内存中找图片,如果内存中没有,接着从本地找,本地没有在从网络下载。
android中加载pdf也是类似,首先从本地找pdf文件,如果本地存在该pdf文件,直接打开,如果本地不存在,将该pdf文件下载到本地在打开。
下载文件用到了retrofit2的库,已经封装到android_pdf中了。
2.依赖android_pdf库方法
2.1 在项目的gradle中增加如下代码:
compile 'com.lidong.pdf:android_pdf:1.0.1'
2.2 一句代码就可以加载网络pdf。
pdfView.fileFromLocalStorage(this,this,this,fileUrl,fileName); //设置pdf文件地址
2.3对fileFromLocalStorage(this,this,this,fileUrl,fileName)的解析
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
|
- OnPageChangeListener onPageChangeListener :翻页回调
- OnLoadCompleteListener onLoadCompleteListener:加载完成的回调
- OnDrawListener:页面绘制的回调
- String fileUrl : 文件的网络地址
- String fileName 文件名称
3.使用android_pdf库方法
3.1写一个布局文件
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
3.2在MainActivity中加载
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
|