正在查看: 爱心e站 v1.0.0 应用的 FilePickerActivity.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: 爱心e站 v1.0.0 应用的 FilePickerActivity.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package com.newheyd.JZKFcanjiren.Utils.FileSelect;
import android.app.Activity;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import com.newheyd.JZKFcanjiren.R;
import java.io.File;
import java.util.ArrayList;
public class FilePickerActivity extends Activity {
private FileChooserAdapter mAdatper;
private ArrayList<FileInfoBean> mFileLists;
private String mLastFilePath;
private String mSdcardRootPath;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_file_picker);
requestPermission();
initView();
}
private void initView() {
RecyclerView recycle = (RecyclerView) findViewById(R.id.rvContainer);
GridLayoutManager manager = new GridLayoutManager(this, 3);
recycle.setLayoutManager(manager);
this.mFileLists = new ArrayList<>();
this.mAdatper = new FileChooserAdapter(this, this.mFileLists);
recycle.setAdapter(this.mAdatper);
this.mSdcardRootPath = Environment.getExternalStorageDirectory().getAbsolutePath();
updateFileItems(this.mSdcardRootPath);
findViewById(R.id.tv_back).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
FilePickerActivity.this.backProcess();
}
});
}
public void updateFileItems(String filePath) {
this.mLastFilePath = filePath;
if (this.mFileLists == null) {
this.mFileLists = new ArrayList<>();
}
if (!this.mFileLists.isEmpty()) {
this.mFileLists.clear();
}
File[] files = folderScan(filePath);
if (files != null) {
for (int i = 0; i < files.length; i++) {
if (!files[i].isHidden()) {
String fileAbsolutePath = files[i].getAbsolutePath();
String fileName = files[i].getName();
boolean isDirectory = false;
if (files[i].isDirectory()) {
isDirectory = true;
}
FileInfoBean fileInfo = new FileInfoBean(fileAbsolutePath, fileName, isDirectory);
this.mFileLists.add(fileInfo);
}
}
if (this.mAdatper != null) {
this.mAdatper.notifyDataSetChanged();
}
}
}
private File[] folderScan(String path) {
File file = new File(path);
File[] files = file.listFiles();
return files;
}
public void backProcess() {
if (!this.mLastFilePath.equals(this.mSdcardRootPath)) {
File thisFile = new File(this.mLastFilePath);
String parentFilePath = thisFile.getParent();
updateFileItems(parentFilePath);
} else {
setResult(0);
finish();
}
}
public void requestPermission() {
if (Build.VERSION.SDK_INT >= 23 && ContextCompat.checkSelfPermission(this, "android.permission.WRITE_EXTERNAL_STORAGE") != 0) {
ActivityCompat.requestPermissions(this, new String[]{"android.permission.WRITE_EXTERNAL_STORAGE", "android.permission.READ_EXTERNAL_STORAGE"}, 129);
}
}
}