继续分析源码
MainBrowserActivity,这个是主ui,由于代码较旧,所以没有处理sdcard的权限.
一般阅读器申请整个卡的读写.
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
- if (!Environment.isExternalStorageManager()) {
- Intent intent = new Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION)
- .setData(Uri.parse("package:" + getPackageName()));
- startActivity(intent);
- }
- } else {
- if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)
- != PackageManager.PERMISSION_GRANTED) {
- if (ActivityCompat.shouldShowRequestPermissionRationale(this,
- Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
- } else {
- ActivityCompat.requestPermissions(this,
- new String[]{Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE},
- 1);
- }
- }
- }
这样就可以管理卡了.
如果有外部传来uri,就先处理uri,这里的什么做法是由主页去接收uri,再分发到具体的页面.
而不把具体渲染页作为接收页,所以会处理onnewintent方法.
如果没有外部uri,则sdcard权限申请过了,就加载文件列表.且带过滤的.
父类BaseBrowserActivity,有两个tab,我把listview修改为recyclerview
为了更好的性能,与时俱进的.
UriBrowserAdapter是历史记录.在ui显示方面修改了样式
BrowserAdapter是文件浏览.
加载逻辑是在BrowserAdapter中的,
- public void setCurrentDirectory(File currentDirectory) {
- final File[] fileArray = currentDirectory.listFiles(filter);
- ArrayList<File> files = new ArrayList<>(fileArray != null ? Arrays.asList(fileArray) : Collections.<File>emptyList());
- this.currentDirectory = currentDirectory;
- Collections.sort(files, (o1, o2) -> {
- if (o1 == null && o2 == null) {
- return 0;
- }
- if (o1.isDirectory() && o2.isFile()) return -1;
- if (o1.isFile() && o2.isDirectory()) return 1;
- if (o1.lastModified() - o2.lastModified() > 0) {
- return -1;
- } else if (o1.lastModified() - o2.lastModified() < 0) { //jdk7以上需要对称,自反,传递性.
- return 1;
- } else {
- return 0;
- }
- });
- if (currentDirectory.getParentFile() != null) {
- files.add(0, currentDirectory.getParentFile());
- }
- setFiles(files);
- }
-
- public void setFiles(List<File> files) {
- submitList(files);
- }
这里我对排序作了修改,目录在前,修改日期倒序.
其它的内容看源码即可,文末有下载地址,或者看vudroid源码,可以去github搜索.因为它原来是在google code上的,已经没了.
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- //处理了全屏操作
- StatusBarHelper.hideSystemUI(this);
- StatusBarHelper.setImmerseBarAppearance(getWindow(), true);
- //初始化解码线程池
- initDecodeService();
- final ZoomModel zoomModel = new ZoomModel();
- final DecodingProgressModel progressModel =