@@ -131,6 +131,7 @@ dependencies { | |||
implementation 'com.github.bumptech.glide:glide:4.11.0' | |||
annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0' | |||
implementation 'com.yanzhenjie:permission:2.0.0-rc12' | |||
} |
@@ -28,6 +28,9 @@ | |||
android:theme="@style/AppTheme" | |||
tools:ignore="GoogleAppIndexingWarning" | |||
tools:node="merge"> | |||
<activity | |||
android:name=".modules.home.fragment.from.FileActivity" | |||
android:exported="false" /> | |||
<activity | |||
android:name=".modules.home.fragment.from.ImageChooseActivity" | |||
android:exported="false" /> | |||
@@ -8,6 +8,10 @@ import androidx.annotation.Nullable; | |||
import com.bonait.bnframework.MainApplication; | |||
import com.bonait.bnframework.common.constant.Constants; | |||
import com.bonait.bnframework.common.filepicker.PickerManager; | |||
import com.bonait.bnframework.common.filepicker.adapter.FilePickerShowAdapter; | |||
import com.bonait.bnframework.common.filepicker.adapter.OnFileItemClickListener; | |||
import com.bonait.bnframework.common.filepicker.util.OpenFile; | |||
import com.bonait.bnframework.common.utils.AlertDialogUtils; | |||
import com.bonait.bnframework.common.utils.ToastUtils; | |||
import com.qmuiteam.qmui.arch.QMUIFragment; | |||
@@ -21,6 +21,8 @@ public interface Constants { | |||
// 申请权限跳转到设置界面code | |||
int APP_SETTING_DIALOG_REQUEST_CODE = 1; | |||
//选择文件事件 | |||
int REQ_CODE = 0X08; | |||
// 申请权限code | |||
int ALL_PERMISSION = 100; | |||
@@ -0,0 +1,182 @@ | |||
package com.bonait.bnframework.common.filepicker; | |||
import android.os.Bundle; | |||
import android.os.Environment; | |||
import android.view.LayoutInflater; | |||
import android.view.View; | |||
import android.view.ViewGroup; | |||
import android.widget.TextView; | |||
import android.widget.Toast; | |||
import androidx.annotation.Nullable; | |||
import androidx.fragment.app.Fragment; | |||
import androidx.recyclerview.widget.LinearLayoutManager; | |||
import androidx.recyclerview.widget.RecyclerView; | |||
import com.bonait.bnframework.R; | |||
import com.bonait.bnframework.common.filepicker.adapter.AllFileAdapter; | |||
import com.bonait.bnframework.common.filepicker.adapter.OnFileItemClickListener; | |||
import com.bonait.bnframework.common.filepicker.model.FileEntity; | |||
import com.bonait.bnframework.common.filepicker.util.FileUtils; | |||
import com.yanzhenjie.permission.Action; | |||
import com.yanzhenjie.permission.AndPermission; | |||
import com.yanzhenjie.permission.Permission; | |||
import java.io.File; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
/** | |||
* 作者:chs on 2017-08-24 11:05 | |||
* 邮箱:657083984@qq.com | |||
* 全部文件 | |||
*/ | |||
public class FileAllFragment extends Fragment { | |||
private RecyclerView mRecyclerView; | |||
private TextView mEmptyView,tv_back; | |||
private String mPath; | |||
private String rootPath; | |||
private List<FileEntity> mListFiles; | |||
private FileSelectFilter mFilter; | |||
//筛选类型条件 | |||
private String[] mFileTypes = new String[]{}; | |||
private AllFileAdapter mAllFileAdapter; | |||
private OnUpdateDataListener mOnUpdateDataListener; | |||
public void setOnUpdateDataListener(OnUpdateDataListener onUpdateDataListener) { | |||
mOnUpdateDataListener = onUpdateDataListener; | |||
} | |||
public static FileAllFragment newInstance(){ | |||
return new FileAllFragment(); | |||
} | |||
@Nullable | |||
@Override | |||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { | |||
View view = inflater.inflate(R.layout.fragment_file_all,null); | |||
initView(view); | |||
initData(); | |||
initEvent(); | |||
if(mOnUpdateDataListener!=null){ | |||
mOnUpdateDataListener.replacement(); | |||
} | |||
return view; | |||
} | |||
private void initView(View view) { | |||
LinearLayoutManager layoutManager = new LinearLayoutManager(getContext()); | |||
layoutManager.setOrientation(LinearLayoutManager.VERTICAL); | |||
mRecyclerView = (RecyclerView) view.findViewById(R.id.rl_all_file); | |||
mRecyclerView.setLayoutManager(layoutManager); | |||
mEmptyView = (TextView) view.findViewById(R.id.empty_view); | |||
tv_back = (TextView) view.findViewById(R.id.tv_back); | |||
} | |||
private void initData() { | |||
AndPermission.with(this) | |||
.runtime() | |||
.permission(Permission.Group.STORAGE) | |||
.onGranted(new Action<List<String>>() { | |||
@Override | |||
public void onAction(List<String> data) { | |||
getData(); | |||
} | |||
}) | |||
.onDenied(new Action<List<String>>() { | |||
@Override | |||
public void onAction(List<String> data) { | |||
Toast.makeText(getContext(),"读写sdk权限被拒绝",Toast.LENGTH_LONG).show(); | |||
} | |||
}) | |||
.start(); | |||
} | |||
private void getData(){ | |||
if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { | |||
Toast.makeText(getContext(), R.string.not_available, Toast.LENGTH_SHORT).show(); | |||
return; | |||
} | |||
mPath = Environment.getExternalStorageDirectory().getAbsolutePath(); | |||
rootPath = Environment.getExternalStorageDirectory().getAbsolutePath(); | |||
mFilter = new FileSelectFilter(mFileTypes); | |||
mListFiles = getFileList(mPath); | |||
mAllFileAdapter = new AllFileAdapter(getContext(),mListFiles,mFilter); | |||
mRecyclerView.setAdapter(mAllFileAdapter); | |||
} | |||
private void initEvent() { | |||
tv_back.setOnClickListener(new View.OnClickListener() { | |||
@Override | |||
public void onClick(View v) { | |||
String tempPath = new File(mPath).getParent(); | |||
if (tempPath == null || mPath.equals(rootPath)) { | |||
Toast.makeText(getContext(),"最外层了",Toast.LENGTH_SHORT).show(); | |||
return; | |||
} | |||
mPath = tempPath; | |||
mListFiles = getFileList(mPath); | |||
mAllFileAdapter.updateListData(mListFiles); | |||
mAllFileAdapter.notifyDataSetChanged(); | |||
} | |||
}); | |||
mAllFileAdapter.setOnItemClickListener(new OnFileItemClickListener() { | |||
@Override | |||
public void click(int position) { | |||
FileEntity entity = mListFiles.get(position); | |||
//如果是文件夹点击进入文件夹 | |||
if (entity.getFile().isDirectory()) { | |||
getIntoChildFolder(position); | |||
}else { | |||
File file = entity.getFile(); | |||
ArrayList<FileEntity> files = PickerManager.getInstance().files; | |||
if(files.contains(entity)){ | |||
files.remove(entity); | |||
if(mOnUpdateDataListener!=null){ | |||
mOnUpdateDataListener.update(-file.length()); | |||
} | |||
entity.setSelected(!entity.isSelected()); | |||
mAllFileAdapter.notifyDataSetChanged(); | |||
}else { | |||
if(PickerManager.getInstance().files.size()<PickerManager.getInstance().maxCount){ | |||
files.add(entity); | |||
if(mOnUpdateDataListener!=null){ | |||
mOnUpdateDataListener.update(file.length()); | |||
} | |||
entity.setSelected(!entity.isSelected()); | |||
mAllFileAdapter.notifyDataSetChanged(); | |||
}else { | |||
Toast.makeText(getContext(),getString(R.string.file_select_max,PickerManager.getInstance().maxCount),Toast.LENGTH_SHORT).show(); | |||
} | |||
} | |||
} | |||
} | |||
}); | |||
} | |||
//进入子文件夹 | |||
private void getIntoChildFolder(int position) { | |||
mPath = mListFiles.get(position).getFile().getAbsolutePath(); | |||
//更新数据源 | |||
mListFiles = getFileList(mPath); | |||
mAllFileAdapter.updateListData(mListFiles); | |||
mAllFileAdapter.notifyDataSetChanged(); | |||
mRecyclerView.scrollToPosition(0); | |||
} | |||
/** | |||
* 根据地址获取当前地址下的所有目录和文件,并且排序 | |||
* | |||
* @param path | |||
* @return List<File> | |||
*/ | |||
private List<FileEntity> getFileList(String path) { | |||
List<FileEntity> fileListByDirPath = FileUtils.getFileListByDirPath(path, mFilter); | |||
if(fileListByDirPath.size()>0){ | |||
mEmptyView.setVisibility(View.GONE); | |||
}else { | |||
mEmptyView.setVisibility(View.VISIBLE); | |||
} | |||
return fileListByDirPath; | |||
} | |||
} |
@@ -0,0 +1,127 @@ | |||
package com.bonait.bnframework.common.filepicker; | |||
import android.os.Bundle; | |||
import android.view.LayoutInflater; | |||
import android.view.View; | |||
import android.view.ViewGroup; | |||
import android.widget.ProgressBar; | |||
import android.widget.TextView; | |||
import android.widget.Toast; | |||
import androidx.annotation.Nullable; | |||
import androidx.fragment.app.Fragment; | |||
import androidx.recyclerview.widget.LinearLayoutManager; | |||
import androidx.recyclerview.widget.RecyclerView; | |||
import com.bonait.bnframework.R; | |||
import com.bonait.bnframework.common.filepicker.adapter.CommonFileAdapter; | |||
import com.bonait.bnframework.common.filepicker.adapter.OnFileItemClickListener; | |||
import com.bonait.bnframework.common.filepicker.model.FileEntity; | |||
import com.yanzhenjie.permission.Action; | |||
import com.yanzhenjie.permission.AndPermission; | |||
import com.yanzhenjie.permission.Permission; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
/** | |||
* 作者:chs on 2017-08-24 11:04 | |||
* 邮箱:657083984@qq.com | |||
* 常用文件 | |||
*/ | |||
public class FileCommonFragment extends Fragment implements FileScannerTask.FileScannerListener { | |||
private RecyclerView mRecyclerView; | |||
private TextView mEmptyView; | |||
private ProgressBar mProgressBar; | |||
private CommonFileAdapter mCommonFileAdapter; | |||
private OnUpdateDataListener mOnUpdateDataListener; | |||
public void setOnUpdateDataListener(OnUpdateDataListener onUpdateDataListener) { | |||
mOnUpdateDataListener = onUpdateDataListener; | |||
} | |||
public static FileCommonFragment newInstance(){ | |||
return new FileCommonFragment(); | |||
} | |||
@Nullable | |||
@Override | |||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { | |||
View view = inflater.inflate(R.layout.fragment_file_normal,null); | |||
initView(view); | |||
initData(); | |||
return view; | |||
} | |||
private void initView(View view) { | |||
LinearLayoutManager layoutManager = new LinearLayoutManager(getContext()); | |||
layoutManager.setOrientation(LinearLayoutManager.VERTICAL); | |||
mRecyclerView = (RecyclerView) view.findViewById(R.id.rl_normal_file); | |||
mRecyclerView.setLayoutManager(layoutManager); | |||
mEmptyView = (TextView) view.findViewById(R.id.empty_view); | |||
mProgressBar = (ProgressBar) view.findViewById(R.id.progress); | |||
mProgressBar.setVisibility(View.VISIBLE); | |||
} | |||
private void initData() { | |||
AndPermission.with(this) | |||
.runtime() | |||
.permission(Permission.Group.STORAGE) | |||
.onGranted(new Action<List<String>>() { | |||
@Override | |||
public void onAction(List<String> data) { | |||
new FileScannerTask(getContext(), FileCommonFragment.this).execute(); | |||
} | |||
}) | |||
.onDenied(new Action<List<String>>() { | |||
@Override | |||
public void onAction(List<String> data) { | |||
Toast.makeText(getContext(),"读写sdk权限被拒绝",Toast.LENGTH_LONG).show(); | |||
} | |||
}) | |||
.start(); | |||
} | |||
private void iniEvent(final List<FileEntity> entities) { | |||
mCommonFileAdapter.setOnItemClickListener(new OnFileItemClickListener() { | |||
@Override | |||
public void click(int position) { | |||
FileEntity entity = entities.get(position); | |||
String absolutePath = entity.getPath(); | |||
ArrayList<FileEntity> files = PickerManager.getInstance().files; | |||
if(files.contains(entity)){ | |||
files.remove(entity); | |||
if(mOnUpdateDataListener!=null){ | |||
mOnUpdateDataListener.update(-Long.parseLong(entity.getSize())); | |||
} | |||
entity.setSelected(!entity.isSelected()); | |||
mCommonFileAdapter.notifyDataSetChanged(); | |||
}else { | |||
if(PickerManager.getInstance().files.size()<PickerManager.getInstance().maxCount){ | |||
files.add(entity); | |||
if(mOnUpdateDataListener!=null){ | |||
mOnUpdateDataListener.update(Long.parseLong(entity.getSize())); | |||
} | |||
entity.setSelected(!entity.isSelected()); | |||
mCommonFileAdapter.notifyDataSetChanged(); | |||
}else { | |||
Toast.makeText(getContext(),getString(R.string.file_select_max,PickerManager.getInstance().maxCount),Toast.LENGTH_SHORT).show(); | |||
} | |||
} | |||
} | |||
}); | |||
} | |||
@Override | |||
public void scannerResult(List<FileEntity> entities) { | |||
mProgressBar.setVisibility(View.GONE); | |||
if(entities.size()>0){ | |||
mEmptyView.setVisibility(View.GONE); | |||
}else { | |||
mEmptyView.setVisibility(View.VISIBLE); | |||
} | |||
mCommonFileAdapter = new CommonFileAdapter(getContext(),entities); | |||
mRecyclerView.setAdapter(mCommonFileAdapter); | |||
iniEvent(entities); | |||
} | |||
} |
@@ -0,0 +1,147 @@ | |||
package com.bonait.bnframework.common.filepicker; | |||
import android.content.Context; | |||
import android.database.Cursor; | |||
import android.os.AsyncTask; | |||
import android.provider.MediaStore; | |||
import android.text.TextUtils; | |||
import android.webkit.MimeTypeMap; | |||
import com.bonait.bnframework.common.filepicker.model.FileEntity; | |||
import com.bonait.bnframework.common.filepicker.model.FileType; | |||
import java.io.File; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
import static android.provider.BaseColumns._ID; | |||
import static android.provider.MediaStore.MediaColumns.DATA; | |||
import static com.bonait.bnframework.common.filepicker.util.FileUtils.getFileType; | |||
/** | |||
* 作者:chs on 2017-08-24 14:39 | |||
* 邮箱:657083984@qq.com | |||
* 扫描媒体库获取数据 | |||
*/ | |||
public class FileScannerTask extends AsyncTask<Void, Void, List<FileEntity>> { | |||
public interface FileScannerListener { | |||
void scannerResult(List<FileEntity> entities); | |||
} | |||
private final String[] DOC_PROJECTION = { | |||
MediaStore.Images.Media._ID, | |||
MediaStore.Images.Media.DATA, | |||
MediaStore.Files.FileColumns.MIME_TYPE, | |||
MediaStore.Files.FileColumns.SIZE, | |||
MediaStore.Images.Media.DATE_ADDED, | |||
MediaStore.Files.FileColumns.TITLE | |||
}; | |||
private Context context; | |||
private FileScannerListener mFileScannerListener; | |||
public FileScannerTask(Context context, FileScannerListener fileScannerListener) { | |||
this.context = context; | |||
mFileScannerListener = fileScannerListener; | |||
} | |||
//MediaStore.Files存储了所有应用中共享的文件,包括图片、文件、视频、音乐等多媒体文件,包括非多媒体文件。 | |||
@Override | |||
protected List<FileEntity> doInBackground(Void... params) { | |||
List<FileEntity> fileEntities = new ArrayList<>(); | |||
String selection = | |||
MediaStore.Files.FileColumns.MIME_TYPE + "= ? " | |||
// + " or " + MediaStore.Files.FileColumns.MIME_TYPE + " = ? " | |||
// + " or " + MediaStore.Files.FileColumns.MIME_TYPE + " = ? " | |||
// + " or " + MediaStore.Files.FileColumns.MIME_TYPE + " = ? " | |||
// + " or " + MediaStore.Files.FileColumns.MIME_TYPE + " = ? " | |||
// + " or " + MediaStore.Files.FileColumns.MIME_TYPE + " = ? " | |||
// + " or " + MediaStore.Files.FileColumns.MIME_TYPE + " = ? " | |||
// + " or " + MediaStore.Files.FileColumns.MIME_TYPE + " = ? " | |||
// + " or " + MediaStore.Files.FileColumns.MIME_TYPE + " = ? " | |||
// + " or " + MediaStore.Files.FileColumns.MIME_TYPE + " = ? " | |||
// + " or " + MediaStore.Files.FileColumns.MIME_TYPE + " = ? " | |||
// + " or " + MediaStore.Files.FileColumns.MIME_TYPE + " = ? " | |||
// + " or " + MediaStore.Files.FileColumns.MIME_TYPE + " = ? " | |||
// + " or " + MediaStore.Files.FileColumns.MIME_TYPE + " = ? " | |||
+ " or " + MediaStore.Files.FileColumns.MIME_TYPE + " = ? " | |||
+ " or " + MediaStore.Files.FileColumns.MIME_TYPE + " = ? " | |||
+ " or " + MediaStore.Files.FileColumns.MIME_TYPE + " = ? " | |||
+ " or " + MediaStore.Files.FileColumns.MIME_TYPE + " = ? "; | |||
String[] selectionArgs = new String[]{ | |||
// MimeTypeMap.getSingleton().getMimeTypeFromExtension("text"), | |||
// MimeTypeMap.getSingleton().getMimeTypeFromExtension("doc"), | |||
// MimeTypeMap.getSingleton().getMimeTypeFromExtension("docx"), | |||
// MimeTypeMap.getSingleton().getMimeTypeFromExtension("dotx"), | |||
// MimeTypeMap.getSingleton().getMimeTypeFromExtension("dotx"), | |||
// MimeTypeMap.getSingleton().getMimeTypeFromExtension("pdf"), | |||
// MimeTypeMap.getSingleton().getMimeTypeFromExtension("ppt"), | |||
// MimeTypeMap.getSingleton().getMimeTypeFromExtension("pptx"), | |||
// MimeTypeMap.getSingleton().getMimeTypeFromExtension("potx"), | |||
// MimeTypeMap.getSingleton().getMimeTypeFromExtension("ppsx"), | |||
// MimeTypeMap.getSingleton().getMimeTypeFromExtension("xls"), | |||
// MimeTypeMap.getSingleton().getMimeTypeFromExtension("xlsx"), | |||
// MimeTypeMap.getSingleton().getMimeTypeFromExtension("xltx"), | |||
MimeTypeMap.getSingleton().getMimeTypeFromExtension("jpg"), | |||
MimeTypeMap.getSingleton().getMimeTypeFromExtension("jpg"), | |||
MimeTypeMap.getSingleton().getMimeTypeFromExtension("png"), | |||
MimeTypeMap.getSingleton().getMimeTypeFromExtension("svg"), | |||
MimeTypeMap.getSingleton().getMimeTypeFromExtension("gif") | |||
}; | |||
// for (String str : selectionArgs) { | |||
// Log.i("selectionArgs" , str); | |||
// } | |||
final Cursor cursor = context.getContentResolver().query( | |||
MediaStore.Files.getContentUri("external"),//数据源 | |||
DOC_PROJECTION,//查询类型 | |||
selection,//查询条件 | |||
selectionArgs, | |||
MediaStore.Files.FileColumns.DATE_ADDED + " DESC"); | |||
if (cursor != null) { | |||
fileEntities = getFiles(cursor); | |||
cursor.close(); | |||
} | |||
return fileEntities; | |||
} | |||
@Override | |||
protected void onPostExecute(List<FileEntity> entities) { | |||
super.onPostExecute(entities); | |||
if (mFileScannerListener != null) { | |||
mFileScannerListener.scannerResult(entities); | |||
} | |||
} | |||
private List<FileEntity> getFiles(Cursor cursor) { | |||
List<FileEntity> fileEntities = new ArrayList<>(); | |||
while (cursor.moveToNext()) { | |||
int id = cursor.getInt(cursor.getColumnIndexOrThrow(_ID)); | |||
String path = cursor.getString(cursor.getColumnIndexOrThrow(DATA)); | |||
String title = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Files.FileColumns.TITLE)); | |||
if (path != null) { | |||
FileType fileType = getFileType(PickerManager.getInstance().getFileTypes(), path); | |||
if (fileType != null && !(new File(path).isDirectory())) { | |||
FileEntity entity = new FileEntity(id, title, path); | |||
entity.setFileType(fileType); | |||
String mimeType = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Files.FileColumns.MIME_TYPE)); | |||
if (mimeType != null && !TextUtils.isEmpty(mimeType)) | |||
entity.setMimeType(mimeType); | |||
else { | |||
entity.setMimeType(""); | |||
} | |||
entity.setSize(cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Files.FileColumns.SIZE))); | |||
if(PickerManager.getInstance().files.contains(entity)){ | |||
entity.setSelected(true); | |||
} | |||
if (!fileEntities.contains(entity)) | |||
fileEntities.add(entity); | |||
} | |||
} | |||
} | |||
return fileEntities; | |||
} | |||
} |
@@ -0,0 +1,33 @@ | |||
package com.bonait.bnframework.common.filepicker; | |||
import java.io.File; | |||
import java.io.FileFilter; | |||
/** | |||
* 作者:chs on 2017-08-08 14:30 | |||
* 邮箱:657083984@qq.com | |||
* File的筛选 | |||
*/ | |||
public class FileSelectFilter implements FileFilter { | |||
private String[] mTypes; | |||
public FileSelectFilter(String[] types) { | |||
this.mTypes = types; | |||
} | |||
@Override | |||
public boolean accept(File file) { | |||
if (file.isDirectory()) { | |||
return true; | |||
} | |||
if (mTypes != null && mTypes.length > 0) { | |||
for (int i = 0; i < mTypes.length; i++) { | |||
if (file.getName().endsWith(mTypes[i].toLowerCase()) || file.getName().endsWith(mTypes[i].toUpperCase())) { | |||
return true; | |||
} | |||
} | |||
}else { | |||
return true; | |||
} | |||
return false; | |||
} | |||
} |
@@ -0,0 +1,11 @@ | |||
package com.bonait.bnframework.common.filepicker; | |||
/** | |||
* 作者:chs on 2017-08-25 10:39 | |||
* 邮箱:657083984@qq.com | |||
*/ | |||
public interface OnUpdateDataListener { | |||
void update(long size); | |||
void replacement(); | |||
} |
@@ -0,0 +1,73 @@ | |||
package com.bonait.bnframework.common.filepicker; | |||
import com.bonait.bnframework.R; | |||
import com.bonait.bnframework.common.filepicker.model.FileEntity; | |||
import com.bonait.bnframework.common.filepicker.model.FileType; | |||
import java.util.ArrayList; | |||
/** | |||
* 作者:chs on 2017-08-24 14:34 | |||
* 邮箱:657083984@qq.com | |||
*/ | |||
public class PickerManager { | |||
public static PickerManager getInstance() { | |||
return SingletonHolder.INSTANCE; | |||
} | |||
private static class SingletonHolder{ | |||
private static final PickerManager INSTANCE = new PickerManager(); | |||
} | |||
/** | |||
* 最多能选的文件的个数 | |||
*/ | |||
public int maxCount = 50; | |||
/** | |||
* 保存结果 | |||
*/ | |||
public ArrayList<FileEntity> files; | |||
/** | |||
* 筛选条件 类型 | |||
*/ | |||
public ArrayList<FileType> mFileTypes; | |||
/** | |||
* 文件夹筛选 | |||
* 这里包括 微信和QQ中的下载的文件和图片 | |||
*/ | |||
public String[] mFilterFolder = new String[]{"MicroMsg/Download","WeiXin","QQfile_recv","MobileQQ/photo"}; | |||
private PickerManager() { | |||
files = new ArrayList<>(); | |||
mFileTypes = new ArrayList<>(); | |||
addDocTypes(); | |||
} | |||
public void addDocTypes() | |||
{ | |||
String[] pdfs = {"pdf"}; | |||
mFileTypes.add(new FileType("PDF",pdfs, R.mipmap.file_picker_pdf)); | |||
String[] docs = {"doc","docx", "dot","dotx"}; | |||
mFileTypes.add(new FileType("DOC",docs,R.mipmap.file_picker_word)); | |||
String[] ppts = {"ppt","pptx"}; | |||
mFileTypes.add(new FileType("PPT",ppts,R.mipmap.file_picker_ppt)); | |||
String[] xlss = {"xls","xlt","xlsx","xltx"}; | |||
mFileTypes.add(new FileType("XLS",xlss,R.mipmap.file_picker_excle)); | |||
String[] txts = {"txt"}; | |||
mFileTypes.add(new FileType("TXT",txts, R.mipmap.file_picker_txt)); | |||
String[] imgs = {"png","jpg","jpeg","gif"}; | |||
mFileTypes.add(new FileType("IMG",imgs,0)); | |||
} | |||
public ArrayList<FileType> getFileTypes() { | |||
return mFileTypes; | |||
} | |||
public PickerManager setMaxCount(int maxCount) { | |||
this.maxCount = maxCount; | |||
return this; | |||
} | |||
} |
@@ -0,0 +1,97 @@ | |||
package com.bonait.bnframework.common.filepicker.adapter; | |||
import android.content.Context; | |||
import android.view.LayoutInflater; | |||
import android.view.View; | |||
import android.view.ViewGroup; | |||
import androidx.recyclerview.widget.RecyclerView; | |||
import com.bonait.bnframework.R; | |||
import com.bonait.bnframework.common.filepicker.model.FileEntity; | |||
import com.bonait.bnframework.common.filepicker.util.FileUtils; | |||
import com.bumptech.glide.Glide; | |||
import java.io.File; | |||
import java.io.FileFilter; | |||
import java.util.List; | |||
/** | |||
* 作者:chs on 2017-08-08 14:40 | |||
* 邮箱:657083984@qq.com | |||
*/ | |||
public class AllFileAdapter extends RecyclerView.Adapter<FilePickerViewHolder> { | |||
private List<FileEntity> mListData; | |||
private Context mContext; | |||
private FileFilter mFileFilter; | |||
private OnFileItemClickListener onItemClickListener; | |||
public void setOnItemClickListener(OnFileItemClickListener onItemClickListener) { | |||
this.onItemClickListener = onItemClickListener; | |||
} | |||
public AllFileAdapter(Context context, List<FileEntity> listData, FileFilter fileFilter) { | |||
mListData = listData; | |||
mContext = context; | |||
mFileFilter = fileFilter; | |||
} | |||
@Override | |||
public FilePickerViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { | |||
View view = LayoutInflater.from(mContext).inflate(R.layout.item_file_picker, parent, false); | |||
return new FilePickerViewHolder(view); | |||
} | |||
@Override | |||
public void onBindViewHolder(final FilePickerViewHolder holder, int positon) { | |||
final FileEntity entity = mListData.get(positon); | |||
final File file = entity.getFile(); | |||
holder.tvName.setText(file.getName()); | |||
if (file.isDirectory()) { | |||
holder.ivType.setImageResource(R.mipmap.file_picker_folder); | |||
holder.ivChoose.setVisibility(View.GONE); | |||
} else { | |||
if(entity.getFileType()!=null){ | |||
String title = entity.getFileType().getTitle(); | |||
if (title.equals("IMG")) { | |||
Glide.with(mContext).load(new File(entity.getPath())).into(holder.ivType); | |||
} else { | |||
holder.ivType.setImageResource(entity.getFileType().getIconStyle()); | |||
} | |||
}else { | |||
holder.ivType.setImageResource(R.mipmap.file_picker_def); | |||
} | |||
holder.ivChoose.setVisibility(View.VISIBLE); | |||
holder.tvDetail.setText(FileUtils.getReadableFileSize(file.length())); | |||
if (entity.isSelected()) { | |||
holder.ivChoose.setImageResource(R.mipmap.file_choice); | |||
} else { | |||
holder.ivChoose.setImageResource(R.mipmap.file_no_selection); | |||
} | |||
} | |||
holder.layoutRoot.setOnClickListener(new View.OnClickListener() { | |||
@Override | |||
public void onClick(View v) { | |||
if (onItemClickListener != null) { | |||
onItemClickListener.click(holder.getAdapterPosition()); | |||
} | |||
} | |||
}); | |||
} | |||
@Override | |||
public int getItemCount() { | |||
return mListData.size(); | |||
} | |||
/** | |||
* 更新数据源 | |||
* | |||
* @param mListData | |||
*/ | |||
public void updateListData(List<FileEntity> mListData) { | |||
this.mListData = mListData; | |||
} | |||
} |
@@ -0,0 +1,72 @@ | |||
package com.bonait.bnframework.common.filepicker.adapter; | |||
import android.content.Context; | |||
import android.view.LayoutInflater; | |||
import android.view.View; | |||
import android.view.ViewGroup; | |||
import androidx.recyclerview.widget.RecyclerView; | |||
import com.bonait.bnframework.R; | |||
import com.bonait.bnframework.common.filepicker.model.FileEntity; | |||
import com.bumptech.glide.Glide; | |||
import java.io.File; | |||
import java.util.List; | |||
/** | |||
* 作者:chs on 2017-08-24 15:43 | |||
* 邮箱:657083984@qq.com | |||
*/ | |||
public class CommonFileAdapter extends RecyclerView.Adapter<FilePickerViewHolder> { | |||
private Context mContext; | |||
private List<FileEntity> mData; | |||
private OnFileItemClickListener onItemClickListener; | |||
public void setOnItemClickListener(OnFileItemClickListener onItemClickListener) { | |||
this.onItemClickListener = onItemClickListener; | |||
} | |||
public CommonFileAdapter(Context context, List<FileEntity> data) { | |||
this.mContext = context; | |||
mData = data; | |||
} | |||
@Override | |||
public FilePickerViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { | |||
View itemView = LayoutInflater.from(mContext).inflate(R.layout.item_file_picker, parent, false); | |||
return new FilePickerViewHolder(itemView); | |||
} | |||
@Override | |||
public void onBindViewHolder(final FilePickerViewHolder holder, int position) { | |||
final FileEntity entity = mData.get(position); | |||
holder.tvName.setText(entity.getName()); | |||
holder.tvDetail.setText(entity.getMimeType()); | |||
String title = entity.getFileType().getTitle(); | |||
if (entity.isSelected()) { | |||
holder.ivChoose.setImageResource(R.mipmap.file_choice); | |||
} else { | |||
holder.ivChoose.setImageResource(R.mipmap.file_no_selection); | |||
} | |||
if (title.equals("IMG")) { | |||
Glide.with(mContext).load(new File(entity.getPath())).into(holder.ivType); | |||
} else { | |||
holder.ivType.setImageResource(entity.getFileType().getIconStyle()); | |||
} | |||
holder.layoutRoot.setOnClickListener(new View.OnClickListener() { | |||
@Override | |||
public void onClick(View v) { | |||
if (onItemClickListener != null) { | |||
onItemClickListener.click(holder.getAdapterPosition()); | |||
} | |||
} | |||
}); | |||
} | |||
@Override | |||
public int getItemCount() { | |||
return mData.size(); | |||
} | |||
} |
@@ -0,0 +1,118 @@ | |||
package com.bonait.bnframework.common.filepicker.adapter; | |||
import android.content.Context; | |||
import android.view.LayoutInflater; | |||
import android.view.View; | |||
import android.view.ViewGroup; | |||
import android.widget.ImageView; | |||
import android.widget.TextView; | |||
import androidx.annotation.NonNull; | |||
import androidx.recyclerview.widget.RecyclerView; | |||
import com.bonait.bnframework.R; | |||
import com.bonait.bnframework.common.filepicker.model.FileEntity; | |||
import com.bonait.bnframework.common.filepicker.util.FileUtils; | |||
import com.bonait.bnframework.common.image.MyBitmapUtils; | |||
import com.bonait.bnframework.common.utils.AlertDialogUtils; | |||
import com.bonait.bnframework.modules.home.adapter.image_sp_adapter; | |||
import com.bumptech.glide.Glide; | |||
import com.qmuiteam.qmui.widget.dialog.QMUIDialog; | |||
import com.qmuiteam.qmui.widget.dialog.QMUIDialogAction; | |||
import java.io.File; | |||
import java.util.ArrayList; | |||
/** | |||
* 作者:chs on 2017-08-28 10:54 | |||
* 邮箱:657083984@qq.com | |||
* 选择附件后显示 | |||
*/ | |||
public class FilePickerShowAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { | |||
private final LayoutInflater mLayoutInflater; | |||
private Context mContext; | |||
private ArrayList<FileEntity> mDataList; | |||
private OnDeleteListener mOnDeleteListener; | |||
private OnFileItemClickListener mOnItemClickListener; | |||
public void setOnItemClickListener(OnFileItemClickListener mOnItemClickListener) { | |||
this.mOnItemClickListener = mOnItemClickListener; | |||
} | |||
public void setOnDeleteListener(OnDeleteListener onDeleteListener) { | |||
mOnDeleteListener = onDeleteListener; | |||
} | |||
public FilePickerShowAdapter(Context context, ArrayList<FileEntity> dataList) { | |||
mContext = context; | |||
mLayoutInflater = LayoutInflater.from(context); | |||
mDataList = dataList; | |||
} | |||
@Override | |||
public FileShowViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { | |||
View view =mLayoutInflater.inflate(R.layout.item_file_picker_show, parent, false); | |||
return new FileShowViewHolder(view); | |||
} | |||
@Override | |||
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder myViewHolder, int position) { | |||
try { | |||
FileShowViewHolder holder = (FileShowViewHolder) myViewHolder; | |||
final FileEntity fileEntity = mDataList.get(position); | |||
final File file = fileEntity.getFile(); | |||
holder.mTvName.setText(file.getName()); | |||
holder.mTvDetail.setText(FileUtils.getReadableFileSize(file.length())); | |||
if (fileEntity.getFileType() != null) { | |||
String title = fileEntity.getFileType().getTitle(); | |||
if (title.equals("IMG")) { | |||
Glide.with(mContext).load(new File(fileEntity.getPath())).into(holder.mIvType); | |||
} else { | |||
holder.mIvType.setImageResource(fileEntity.getFileType().getIconStyle()); | |||
} | |||
} else { | |||
holder.mIvType.setImageResource(R.mipmap.file_picker_def); | |||
} | |||
holder.itemView.setOnClickListener(new View.OnClickListener() { | |||
@Override | |||
public void onClick(View v) { | |||
if (mOnItemClickListener != null) { | |||
mOnItemClickListener.click(holder.getAdapterPosition()); | |||
} | |||
} | |||
}); | |||
holder.mIvDelete.setVisibility(View.VISIBLE); | |||
holder.mIvDelete.setOnClickListener(new View.OnClickListener() { | |||
@Override | |||
public void onClick(View v) { | |||
mDataList.remove(holder.getAdapterPosition()); | |||
if (mOnDeleteListener != null) | |||
mOnDeleteListener.delete(holder.getAdapterPosition()); | |||
notifyDataSetChanged(); | |||
} | |||
}); | |||
} catch (Exception e) { | |||
e.printStackTrace(); | |||
} | |||
} | |||
@Override | |||
public int getItemCount() { | |||
return mDataList.size(); | |||
} | |||
class FileShowViewHolder extends RecyclerView.ViewHolder { | |||
private ImageView mIvType, mIvDelete; | |||
private TextView mTvName, mTvDetail; | |||
public FileShowViewHolder(View itemView) { | |||
super(itemView); | |||
mIvType = (ImageView) itemView.findViewById(R.id.iv_type); | |||
mIvDelete = (ImageView) itemView.findViewById(R.id.iv_delete); | |||
mTvName = (TextView) itemView.findViewById(R.id.tv_name); | |||
mTvDetail = (TextView) itemView.findViewById(R.id.tv_detail); | |||
} | |||
} | |||
} |
@@ -0,0 +1,30 @@ | |||
package com.bonait.bnframework.common.filepicker.adapter; | |||
import android.view.View; | |||
import android.widget.CheckBox; | |||
import android.widget.ImageView; | |||
import android.widget.RelativeLayout; | |||
import android.widget.TextView; | |||
import androidx.recyclerview.widget.RecyclerView; | |||
import com.bonait.bnframework.R; | |||
/** | |||
* 作者:chs on 2017-08-24 17:13 | |||
* 邮箱:657083984@qq.com | |||
*/ | |||
public class FilePickerViewHolder extends RecyclerView.ViewHolder { | |||
protected RelativeLayout layoutRoot; | |||
protected ImageView ivType,ivChoose; | |||
protected TextView tvName; | |||
protected TextView tvDetail; | |||
public FilePickerViewHolder(View itemView) { | |||
super(itemView); | |||
ivType = (ImageView) itemView.findViewById(R.id.iv_type); | |||
layoutRoot = (RelativeLayout) itemView.findViewById(R.id.layout_item_root); | |||
tvName = (TextView) itemView.findViewById(R.id.tv_name); | |||
tvDetail = (TextView) itemView.findViewById(R.id.tv_detail); | |||
ivChoose = (ImageView) itemView.findViewById(R.id.iv_choose); | |||
} | |||
} |
@@ -0,0 +1,10 @@ | |||
package com.bonait.bnframework.common.filepicker.adapter; | |||
/** | |||
* 作者:chs on 2017-09-06 14:57 | |||
* 邮箱:657083984@qq.com | |||
*/ | |||
public interface OnDeleteListener { | |||
void delete(int position); | |||
} |
@@ -0,0 +1,11 @@ | |||
package com.bonait.bnframework.common.filepicker.adapter; | |||
/** | |||
* 作者:chs on 2017-08-25 10:15 | |||
* 邮箱:657083984@qq.com | |||
* 条目点击 | |||
*/ | |||
public interface OnFileItemClickListener { | |||
void click(int position); | |||
} |
@@ -0,0 +1,153 @@ | |||
package com.bonait.bnframework.common.filepicker.model; | |||
import android.os.Parcel; | |||
import android.os.Parcelable; | |||
import java.io.File; | |||
/** | |||
* 作者:chs on 2017-08-24 14:41 | |||
* 邮箱:657083984@qq.com | |||
*/ | |||
public class FileEntity implements Parcelable { | |||
private int id; | |||
private String name; | |||
private String path; | |||
private String mimeType; | |||
private String size; | |||
private String date; | |||
private FileType fileType; | |||
private boolean isSelected; | |||
/* File 用于全部文件*/ | |||
private File mFile; | |||
public FileEntity(int id, String name, String path) { | |||
this.id = id; | |||
this.name = name; | |||
this.path = path; | |||
} | |||
public FileEntity(String path,File file, boolean isSelected) { | |||
this.path = path; | |||
mFile = file; | |||
this.isSelected = isSelected; | |||
} | |||
@Override | |||
public boolean equals(Object o) { | |||
if (this == o) return true; | |||
if (!(o instanceof FileEntity)) return false; | |||
FileEntity entity = (FileEntity) o; | |||
return path .equals(entity.path); | |||
} | |||
protected FileEntity(Parcel in) { | |||
id = in.readInt(); | |||
name = in.readString(); | |||
path = in.readString(); | |||
mimeType = in.readString(); | |||
size = in.readString(); | |||
date = in.readString(); | |||
} | |||
public static final Creator<FileEntity> CREATOR = new Creator<FileEntity>() { | |||
@Override | |||
public FileEntity createFromParcel(Parcel in) { | |||
return new FileEntity(in); | |||
} | |||
@Override | |||
public FileEntity[] newArray(int size) { | |||
return new FileEntity[size]; | |||
} | |||
}; | |||
@Override | |||
public int describeContents() { | |||
return 0; | |||
} | |||
@Override | |||
public void writeToParcel(Parcel dest, int flags) { | |||
dest.writeInt(id); | |||
dest.writeString(name); | |||
dest.writeString(path); | |||
dest.writeString(mimeType); | |||
dest.writeString(size); | |||
dest.writeString(date); | |||
} | |||
public int getId() { | |||
return id; | |||
} | |||
public void setId(int id) { | |||
this.id = id; | |||
} | |||
public String getName() { | |||
return name; | |||
} | |||
public void setName(String name) { | |||
this.name = name; | |||
} | |||
public String getPath() { | |||
return path; | |||
} | |||
public void setPath(String path) { | |||
this.path = path; | |||
} | |||
public String getMimeType() { | |||
return mimeType; | |||
} | |||
public void setMimeType(String mimeType) { | |||
this.mimeType = mimeType; | |||
} | |||
public String getSize() { | |||
return size; | |||
} | |||
public void setSize(String size) { | |||
this.size = size; | |||
} | |||
public String getDate() { | |||
return date; | |||
} | |||
public void setDate(String date) { | |||
this.date = date; | |||
} | |||
public FileType getFileType() { | |||
return fileType; | |||
} | |||
public void setFileType(FileType fileType) { | |||
this.fileType = fileType; | |||
} | |||
public File getFile() { | |||
return mFile; | |||
} | |||
public void setFile(File file) { | |||
mFile = file; | |||
} | |||
public boolean isSelected() { | |||
return isSelected; | |||
} | |||
public void setSelected(boolean selected) { | |||
isSelected = selected; | |||
} | |||
} |
@@ -0,0 +1,63 @@ | |||
package com.bonait.bnframework.common.filepicker.model; | |||
import android.os.Parcel; | |||
import android.os.Parcelable; | |||
/** | |||
* 作者:chs on 2017-08-24 15:19 | |||
* 邮箱:657083984@qq.com | |||
*/ | |||
public class FileType implements Parcelable{ | |||
private String title; | |||
private int iconStyle; | |||
public String[] filterType; | |||
public FileType(String title,String[] filterType,int iconStyle) { | |||
this.title = title; | |||
this.iconStyle = iconStyle; | |||
this.filterType = filterType; | |||
} | |||
protected FileType(Parcel in) { | |||
title = in.readString(); | |||
iconStyle = in.readInt(); | |||
filterType = in.createStringArray(); | |||
} | |||
public static final Creator<FileType> CREATOR = new Creator<FileType>() { | |||
@Override | |||
public FileType createFromParcel(Parcel in) { | |||
return new FileType(in); | |||
} | |||
@Override | |||
public FileType[] newArray(int size) { | |||
return new FileType[size]; | |||
} | |||
}; | |||
public String getTitle() { | |||
return title; | |||
} | |||
public int getIconStyle() { | |||
return iconStyle; | |||
} | |||
public String[] getFilterType() { | |||
return filterType; | |||
} | |||
@Override | |||
public int describeContents() { | |||
return 0; | |||
} | |||
@Override | |||
public void writeToParcel(Parcel dest, int flags) { | |||
dest.writeString(title); | |||
dest.writeInt(iconStyle); | |||
dest.writeStringArray(filterType); | |||
} | |||
} |
@@ -0,0 +1,26 @@ | |||
package com.bonait.bnframework.common.filepicker.util; | |||
import java.io.File; | |||
import java.util.Comparator; | |||
/** | |||
* | |||
*/ | |||
public class FileComparator implements Comparator<File> { | |||
@Override | |||
public int compare(File f1, File f2) { | |||
if(f1 == f2) { | |||
return 0; | |||
} | |||
if(f1.isDirectory() && f2.isFile()) { | |||
// Show directories above files | |||
return -1; | |||
} | |||
if(f1.isFile() && f2.isDirectory()) { | |||
// Show files below directories | |||
return 1; | |||
} | |||
// Sort the directories alphabetically | |||
return f1.getName().compareToIgnoreCase(f2.getName()); | |||
} | |||
} |
@@ -0,0 +1,104 @@ | |||
package com.bonait.bnframework.common.filepicker.util; | |||
import com.bonait.bnframework.common.filepicker.PickerManager; | |||
import com.bonait.bnframework.common.filepicker.model.FileEntity; | |||
import com.bonait.bnframework.common.filepicker.model.FileType; | |||
import java.io.File; | |||
import java.io.FileFilter; | |||
import java.text.DecimalFormat; | |||
import java.util.ArrayList; | |||
import java.util.Arrays; | |||
import java.util.Collections; | |||
import java.util.List; | |||
public class FileUtils { | |||
/** | |||
* 根据路径获取file的集合 | |||
* | |||
* @param path | |||
* @param filter | |||
* @return | |||
*/ | |||
public static List<FileEntity> getFileListByDirPath(String path, FileFilter filter) { | |||
File directory = new File(path); | |||
File[] files = directory.listFiles(filter); | |||
if (files == null) { | |||
return new ArrayList<>(); | |||
} | |||
List<File> result = Arrays.asList(files); | |||
Collections.sort(result, new FileComparator()); | |||
List<FileEntity> entities = new ArrayList<>(); | |||
for (File f : result) { | |||
String absolutePath = f.getAbsolutePath(); | |||
FileEntity e; | |||
if (checkExits(absolutePath)) { | |||
e = new FileEntity(absolutePath, f, true); | |||
} else { | |||
e = new FileEntity(absolutePath, f, false); | |||
} | |||
if(f.isFile()) | |||
{ | |||
FileType fileType = getFileTypeNoFolder(PickerManager.getInstance().mFileTypes, absolutePath); | |||
if(fileType!=null) | |||
{ | |||
e.setFileType(fileType); | |||
if (PickerManager.getInstance().files.contains(e)) { | |||
e.setSelected(true); | |||
} | |||
entities.add(e); | |||
} | |||
}else | |||
{ | |||
entities.add(e); | |||
} | |||
} | |||
return entities; | |||
} | |||
private static boolean checkExits(String path) { | |||
for (FileEntity entity : PickerManager.getInstance().files) { | |||
if (entity.getPath().equals(path)) { | |||
return true; | |||
} | |||
} | |||
return false; | |||
} | |||
public static String getReadableFileSize(long size) { | |||
if (size <= 0) return "0"; | |||
final String[] units = new String[]{"B", "KB", "MB", "GB", "TB"}; | |||
int digitGroups = (int) (Math.log10(size) / Math.log10(1024)); | |||
return new DecimalFormat("#.##").format(size / Math.pow(1024, digitGroups)) + " " + units[digitGroups]; | |||
} | |||
public static FileType getFileType(ArrayList<FileType> fileTypes, String path) { | |||
for (String str : PickerManager.getInstance().mFilterFolder) {//按文件夹筛选 | |||
if (path.contains(str)) { | |||
for (int index = 0; index < fileTypes.size(); index++) {//按照文件类型筛选 | |||
for (String string : fileTypes.get(index).filterType) { | |||
if (path.endsWith(string)) | |||
return fileTypes.get(index); | |||
} | |||
} | |||
} | |||
} | |||
return null; | |||
} | |||
//不包含文件夹 | |||
public static FileType getFileTypeNoFolder(ArrayList<FileType> fileTypes, String path) { | |||
for (int index = 0; index < fileTypes.size(); index++) {//按照文件类型筛选 | |||
for (String string : fileTypes.get(index).filterType) { | |||
if (path.endsWith(string)) | |||
return fileTypes.get(index); | |||
} | |||
} | |||
return null; | |||
} | |||
} |
@@ -0,0 +1,199 @@ | |||
package com.bonait.bnframework.common.filepicker.util; | |||
import android.content.Context; | |||
import android.content.Intent; | |||
import android.net.Uri; | |||
import android.os.Build; | |||
import androidx.core.content.FileProvider; | |||
import java.io.File; | |||
/** | |||
* 打开文件 | |||
*/ | |||
public class OpenFile { | |||
private static Context mContext; | |||
public static Intent openFile(String filePath, Context context){ | |||
mContext = context; | |||
File file = new File(filePath); | |||
if(!file.exists()) return null; | |||
/* 取得扩展名 */ | |||
String end=file.getName().substring(file.getName().lastIndexOf(".") + 1,file.getName().length()).toLowerCase(); | |||
/* 依扩展名的类型决定MimeType */ | |||
if(end.equals("m4a")||end.equals("mp3")||end.equals("mid")|| | |||
end.equals("xmf")||end.equals("ogg")||end.equals("wav")){ | |||
return getAudioFileIntent(filePath); | |||
}else if(end.equals("3gp")||end.equals("mp4")){ | |||
return getAudioFileIntent(filePath); | |||
}else if(end.equals("jpg")||end.equals("gif")||end.equals("png")|| | |||
end.equals("jpeg")||end.equals("bmp")){ | |||
return getImageFileIntent(filePath); | |||
}else if(end.equals("apk")){ | |||
return getApkFileIntent(filePath); | |||
}else if(end.equals("ppt")){ | |||
return getPptFileIntent(filePath); | |||
}else if(end.equals("xls")){ | |||
return getExcelFileIntent(filePath); | |||
}else if(end.equals("doc")){ | |||
return getWordFileIntent(filePath); | |||
}else if(end.equals("pdf")){ | |||
return getPdfFileIntent(filePath); | |||
}else if(end.equals("chm")){ | |||
return getChmFileIntent(filePath); | |||
}else if(end.equals("txt")){ | |||
return getTextFileIntent(filePath,false); | |||
}else{ | |||
return getAllIntent(filePath); | |||
} | |||
} | |||
private static Uri getUri(String path){ | |||
Uri uri; | |||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { | |||
String authority = mContext.getPackageName() + ".provider"; | |||
uri = FileProvider.getUriForFile(mContext, authority, new File(path)); | |||
} else { | |||
uri = Uri.fromFile(new File(path)); | |||
} | |||
return uri; | |||
} | |||
//Android获取一个用于打开APK文件的intent | |||
public static Intent getAllIntent(String param ) { | |||
Intent intent = new Intent(); | |||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | |||
intent.setAction(Intent.ACTION_VIEW);//动作 | |||
Uri uri = getUri(param); | |||
intent.setDataAndType(uri,"*/*"); | |||
return intent; | |||
} | |||
//Android获取一个用于打开APK文件的intent | |||
public static Intent getApkFileIntent(String param ) { | |||
Intent intent = new Intent(); | |||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | |||
intent.setAction(Intent.ACTION_VIEW); | |||
Uri uri = getUri(param); | |||
intent.setDataAndType(uri,"application/vnd.android.package-archive"); | |||
return intent; | |||
} | |||
//Android获取一个用于打开VIDEO文件的intent | |||
public static Intent getVideoFileIntent(String param ) { | |||
Intent intent = new Intent("android.intent.action.VIEW"); | |||
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); | |||
intent.putExtra("oneshot", 0); | |||
intent.putExtra("configchange", 0); | |||
Uri uri = getUri(param); | |||
intent.setDataAndType(uri, "video/*"); | |||
return intent; | |||
} | |||
//Android获取一个用于打开AUDIO文件的intent | |||
public static Intent getAudioFileIntent(String param ){ | |||
Intent intent = new Intent("android.intent.action.VIEW"); | |||
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); | |||
intent.putExtra("oneshot", 0); | |||
intent.putExtra("configchange", 0); | |||
Uri uri = getUri(param); | |||
intent.setDataAndType(uri, "audio/*"); | |||
return intent; | |||
} | |||
//Android获取一个用于打开Html文件的intent | |||
public static Intent getHtmlFileIntent(String param ){ | |||
Uri uri = Uri.parse(param ).buildUpon().encodedAuthority("com.android.htmlfileprovider").scheme("content").encodedPath(param ).build(); | |||
Intent intent = new Intent("android.intent.action.VIEW"); | |||
intent.setDataAndType(uri, "text/html"); | |||
return intent; | |||
} | |||
//Android获取一个用于打开图片文件的intent | |||
public static Intent getImageFileIntent(String param ) { | |||
Intent intent = new Intent("android.intent.action.VIEW"); | |||
intent.addCategory("android.intent.category.DEFAULT"); | |||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | |||
Uri uri = getUri(param); | |||
intent.setDataAndType(uri, "image/*"); | |||
return intent; | |||
} | |||
//Android获取一个用于打开PPT文件的intent | |||
public static Intent getPptFileIntent(String param ){ | |||
Intent intent = new Intent("android.intent.action.VIEW"); | |||
intent.addCategory("android.intent.category.DEFAULT"); | |||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | |||
Uri uri = getUri(param); | |||
intent.setDataAndType(uri, "application/vnd.ms-powerpoint"); | |||
return intent; | |||
} | |||
//Android获取一个用于打开Excel文件的intent | |||
public static Intent getExcelFileIntent(String param ){ | |||
Intent intent = new Intent("android.intent.action.VIEW"); | |||
intent.addCategory("android.intent.category.DEFAULT"); | |||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | |||
Uri uri = getUri(param); | |||
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); | |||
intent.setDataAndType(uri, "application/vnd.ms-excel"); | |||
return intent; | |||
} | |||
//Android获取一个用于打开Word文件的intent | |||
public static Intent getWordFileIntent(String param ){ | |||
Intent intent = new Intent("android.intent.action.VIEW"); | |||
intent.addCategory("android.intent.category.DEFAULT"); | |||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | |||
Uri uri = getUri(param); | |||
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); | |||
intent.setDataAndType(uri, "application/msword"); | |||
return intent; | |||
} | |||
//Android获取一个用于打开CHM文件的intent | |||
public static Intent getChmFileIntent(String param ){ | |||
Intent intent = new Intent("android.intent.action.VIEW"); | |||
intent.addCategory("android.intent.category.DEFAULT"); | |||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | |||
Uri uri = getUri(param); | |||
intent.setDataAndType(uri, "application/x-chm"); | |||
return intent; | |||
} | |||
//Android获取一个用于打开文本文件的intent | |||
public static Intent getTextFileIntent(String param, boolean paramBoolean){ | |||
Intent intent = new Intent("android.intent.action.VIEW"); | |||
intent.addCategory("android.intent.category.DEFAULT"); | |||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | |||
if (paramBoolean){ | |||
Uri uri1 = getUri(param); | |||
intent.setDataAndType(uri1, "text/plain"); | |||
}else{ | |||
Uri uri2 = getUri(param); | |||
intent.setDataAndType(uri2, "text/plain"); | |||
} | |||
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); | |||
return intent; | |||
} | |||
//Android获取一个用于打开PDF文件的intent | |||
public static Intent getPdfFileIntent(String param ){ | |||
Intent intent = new Intent("android.intent.action.VIEW"); | |||
intent.addCategory("android.intent.category.DEFAULT"); | |||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | |||
Uri uri = getUri(param); | |||
intent.setDataAndType(uri, "application/pdf"); | |||
return intent; | |||
} | |||
} | |||
@@ -0,0 +1,149 @@ | |||
package com.bonait.bnframework.modules.home.fragment.from; | |||
import androidx.appcompat.app.AppCompatActivity; | |||
import androidx.core.content.ContextCompat; | |||
import androidx.fragment.app.Fragment; | |||
import androidx.fragment.app.FragmentManager; | |||
import androidx.fragment.app.FragmentTransaction; | |||
import android.os.Bundle; | |||
import android.view.View; | |||
import android.widget.Button; | |||
import android.widget.TextView; | |||
import com.bonait.bnframework.R; | |||
import com.bonait.bnframework.common.filepicker.FileAllFragment; | |||
import com.bonait.bnframework.common.filepicker.FileCommonFragment; | |||
import com.bonait.bnframework.common.filepicker.OnUpdateDataListener; | |||
import com.bonait.bnframework.common.filepicker.PickerManager; | |||
import com.bonait.bnframework.common.filepicker.model.FileEntity; | |||
import com.bonait.bnframework.common.filepicker.util.FileUtils; | |||
import com.qmuiteam.qmui.widget.QMUITopBar; | |||
import java.io.File; | |||
public class FileActivity extends AppCompatActivity implements View.OnClickListener, OnUpdateDataListener { | |||
private QMUITopBar mTopBar; | |||
private Button btn_common,btn_all; | |||
private TextView tv_size,tv_confirm; | |||
private Fragment commonFileFragment,allFileFragment; | |||
private boolean isConfirm = false; | |||
@Override | |||
protected void onCreate(Bundle savedInstanceState) { | |||
super.onCreate(savedInstanceState); | |||
setContentView(R.layout.activity_file); | |||
initView(); | |||
initEvent(); | |||
setFragment(1); | |||
} | |||
private void initEvent() { | |||
btn_common.setOnClickListener(this); | |||
btn_all.setOnClickListener(this); | |||
tv_confirm.setOnClickListener(this); | |||
} | |||
private void initView() { | |||
btn_common = (Button) findViewById(R.id.btn_common); | |||
btn_all = (Button) findViewById(R.id.btn_all); | |||
tv_size = (TextView) findViewById(R.id.tv_size); | |||
tv_confirm = (TextView) findViewById(R.id.tv_confirm); | |||
mTopBar=findViewById(R.id.topbar); | |||
mTopBar.setTitle("图片选择"); | |||
mTopBar.addLeftImageButton(R.mipmap.fanhui,R.id.topbar).setOnClickListener(new View.OnClickListener() { | |||
@Override | |||
public void onClick(View view) { | |||
finish(); | |||
} | |||
}); | |||
} | |||
private void setFragment(int type) { | |||
FragmentManager fragmentManager = getSupportFragmentManager(); | |||
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); | |||
hideFragment(fragmentTransaction); | |||
switch (type){ | |||
case 1: | |||
if(commonFileFragment==null){ | |||
commonFileFragment = FileCommonFragment.newInstance(); | |||
((FileCommonFragment)commonFileFragment).setOnUpdateDataListener(this); | |||
fragmentTransaction.add(R.id.fl_content,commonFileFragment); | |||
}else { | |||
fragmentTransaction.show(commonFileFragment); | |||
} | |||
break; | |||
case 2: | |||
if(allFileFragment==null){ | |||
allFileFragment = FileAllFragment.newInstance(); | |||
((FileAllFragment)allFileFragment).setOnUpdateDataListener(this); | |||
fragmentTransaction.add(R.id.fl_content,allFileFragment); | |||
}else { | |||
fragmentTransaction.show(allFileFragment); | |||
} | |||
break; | |||
} | |||
fragmentTransaction.commit(); | |||
} | |||
private void hideFragment(FragmentTransaction transaction) { | |||
if (commonFileFragment != null) { | |||
transaction.hide(commonFileFragment); | |||
} | |||
if (allFileFragment != null) { | |||
transaction.hide(allFileFragment); | |||
} | |||
} | |||
@Override | |||
public void onClick(View v) { | |||
switch (v.getId()){ | |||
case R.id.btn_common: | |||
setFragment(1); | |||
btn_common.setBackgroundResource(R.mipmap.no_read_pressed); | |||
btn_common.setTextColor(ContextCompat.getColor(this,R.color.white)); | |||
btn_all.setBackgroundResource(R.mipmap.already_read); | |||
btn_all.setTextColor(ContextCompat.getColor(this,R.color.blue)); | |||
break; | |||
case R.id.btn_all: | |||
setFragment(2); | |||
btn_common.setBackgroundResource(R.mipmap.no_read); | |||
btn_common.setTextColor(ContextCompat.getColor(this,R.color.blue)); | |||
btn_all.setBackgroundResource(R.mipmap.already_read_pressed); | |||
btn_all.setTextColor(ContextCompat.getColor(this,R.color.white)); | |||
break; | |||
case R.id.tv_confirm: | |||
isConfirm = true; | |||
setResult(RESULT_OK); | |||
finish(); | |||
break; | |||
} | |||
} | |||
private long currentSize; | |||
@Override | |||
public void update(long size) { | |||
currentSize+=size; | |||
tv_size.setText(getString(R.string.already_select, FileUtils.getReadableFileSize(currentSize))); | |||
String res = "("+ PickerManager.getInstance().files.size()+"/"+PickerManager.getInstance().maxCount+")"; | |||
tv_confirm.setText(getString(R.string.file_select_res,res)); | |||
} | |||
@Override | |||
public void replacement() { | |||
long length=0; | |||
for (FileEntity item:PickerManager.getInstance().files) | |||
{ | |||
File file=item.getFile(); | |||
length+= file.length(); | |||
} | |||
currentSize=length; | |||
tv_size.setText(getString(R.string.already_select, FileUtils.getReadableFileSize(currentSize))); | |||
String res = "("+ PickerManager.getInstance().files.size()+"/"+PickerManager.getInstance().maxCount+")"; | |||
tv_confirm.setText(getString(R.string.file_select_res,res)); | |||
} | |||
@Override | |||
public void onBackPressed() { | |||
super.onBackPressed(); | |||
if(!isConfirm){ | |||
PickerManager.getInstance().files.clear(); | |||
} | |||
} | |||
} |
@@ -4,18 +4,54 @@ import android.content.Context; | |||
import androidx.annotation.NonNull; | |||
import androidx.annotation.Nullable; | |||
import androidx.appcompat.app.AppCompatActivity; | |||
import androidx.recyclerview.widget.LinearLayoutManager; | |||
import androidx.recyclerview.widget.RecyclerView; | |||
import android.content.Intent; | |||
import android.graphics.Bitmap; | |||
import android.graphics.BitmapFactory; | |||
import android.os.Bundle; | |||
import android.view.LayoutInflater; | |||
import android.view.View; | |||
import android.widget.Button; | |||
import android.widget.EditText; | |||
import com.bonait.bnframework.R; | |||
import com.bonait.bnframework.common.base.BaseFragment; | |||
import com.bonait.bnframework.common.constant.ConfigName; | |||
import com.bonait.bnframework.common.constant.Constants; | |||
import com.bonait.bnframework.common.db.QueryDB; | |||
import com.bonait.bnframework.common.db.mode.BPA_SYSTEMSET; | |||
import com.bonait.bnframework.common.filepicker.PickerManager; | |||
import com.bonait.bnframework.common.filepicker.adapter.FilePickerShowAdapter; | |||
import com.bonait.bnframework.common.filepicker.adapter.OnFileItemClickListener; | |||
import com.bonait.bnframework.common.filepicker.model.FileEntity; | |||
import com.bonait.bnframework.common.filepicker.util.OpenFile; | |||
import com.bonait.bnframework.common.image.utils.LocalCacheUtils; | |||
import com.bonait.bnframework.common.image.utils.MD5Encoder; | |||
import com.bonait.bnframework.common.utils.ToastUtils; | |||
import com.bonait.bnframework.common.view.MyLayoutManager; | |||
import com.bonait.bnframework.modules.home.fragment.from.FileActivity; | |||
import com.orhanobut.logger.Logger; | |||
import com.qmuiteam.qmui.arch.QMUIFragment; | |||
import butterknife.ButterKnife; | |||
import java.io.File; | |||
import java.io.FileInputStream; | |||
import java.util.List; | |||
public class systeminternetfragment extends BaseFragment { | |||
import butterknife.BindView; | |||
import butterknife.ButterKnife; | |||
import butterknife.OnClick; | |||
import pub.devrel.easypermissions.EasyPermissions; | |||
/** | |||
* 资源管理 | |||
*/ | |||
public class systeminternetfragment extends BaseFragment{ | |||
@BindView(R.id.rl_file) | |||
RecyclerView mRecyclerView; | |||
@BindView(R.id.baocunbendi) | |||
Button baocunbendi; | |||
private Context context; | |||
@Override | |||
protected View onCreateView() { | |||
@@ -31,6 +67,49 @@ public class systeminternetfragment extends BaseFragment { | |||
context = getContext(); | |||
} | |||
@OnClick({R.id.xuanzhewenjian,R.id.baocunbendi}) | |||
public void onViewClicked(View view) { | |||
switch (view.getId()) { | |||
case R.id.xuanzhewenjian://保存按钮 | |||
Intent intent = new Intent(context, FileActivity.class); | |||
startActivityForResult(intent, Constants.REQ_CODE); | |||
break; | |||
case R.id.baocunbendi://保存按钮 | |||
BitmapFactory.Options options = new BitmapFactory.Options(); | |||
options.inSampleSize=2;//宽高压缩为原来的1/2 | |||
for (FileEntity item:PickerManager.getInstance().files) | |||
{ | |||
File file= item.getFile(); | |||
try { | |||
Bitmap bitmap1= BitmapFactory.decodeStream(new FileInputStream(file)); | |||
new LocalCacheUtils().setBitmapToLocal(file.getName(),bitmap1); | |||
} catch (Exception e) { | |||
} | |||
} | |||
ToastUtils.info("添加成功!"); | |||
break; | |||
} | |||
} | |||
@Override | |||
public void onActivityResult(int requestCode, int resultCode, Intent data) { | |||
super.onActivityResult(requestCode, resultCode, data); | |||
if(requestCode == Constants.REQ_CODE){ | |||
mRecyclerView.setLayoutManager(new LinearLayoutManager(context)); | |||
FilePickerShowAdapter adapter = new FilePickerShowAdapter(context,PickerManager.getInstance().files); | |||
mRecyclerView.setAdapter(adapter); | |||
String res = "("+ PickerManager.getInstance().files.size()+"/"+PickerManager.getInstance().maxCount+")"; | |||
baocunbendi.setText(getString(R.string.file_select_res1,res)); | |||
// adapter.setOnItemClickListener(new OnFileItemClickListener() { | |||
// @Override | |||
// public void click(int position) { | |||
// startActivity(Intent.createChooser(OpenFile.openFile(PickerManager.getInstance().files.get(position).getPath(),getBaseFragmentActivity()), "选择程序")); | |||
// } | |||
// }); | |||
} | |||
} | |||
@Override | |||
public void onDestroy() { | |||
super.onDestroy(); | |||
@@ -0,0 +1,5 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<shape xmlns:android="http://schemas.android.com/apk/res/android"> | |||
<solid android:color="@color/file_bottom_line"/> | |||
<size android:height="1dp"/> | |||
</shape> |
@@ -0,0 +1,69 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |||
xmlns:app="http://schemas.android.com/apk/res-auto" | |||
xmlns:tools="http://schemas.android.com/tools" | |||
android:layout_width="match_parent" | |||
android:layout_height="match_parent" | |||
android:orientation="vertical" | |||
tools:context=".modules.home.fragment.from.FileActivity"> | |||
<com.qmuiteam.qmui.widget.QMUITopBar | |||
android:id="@+id/topbar" | |||
android:layout_width="match_parent" | |||
android:layout_height="?attr/qmui_topbar_height"/> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:padding="10dp" | |||
android:background="@color/white" | |||
android:orientation="horizontal"> | |||
<Button | |||
android:id="@+id/btn_common" | |||
android:layout_width="wrap_content" | |||
android:layout_height="30dp" | |||
android:layout_weight="1" | |||
android:background="@mipmap/no_read_pressed" | |||
android:textColor="@color/white" | |||
android:text="@string/file_normal"/> | |||
<Button | |||
android:id="@+id/btn_all" | |||
android:layout_width="wrap_content" | |||
android:layout_height="30dp" | |||
android:layout_weight="1" | |||
android:background="@mipmap/already_read" | |||
android:textColor="@color/blue" | |||
android:text="@string/file_all"/> | |||
</LinearLayout> | |||
<FrameLayout | |||
android:id="@+id/fl_content" | |||
android:layout_width="match_parent" | |||
android:layout_height="0dp" | |||
android:layout_weight="1" | |||
/> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="40dp" | |||
android:orientation="horizontal" | |||
android:gravity="center_vertical" | |||
> | |||
<TextView | |||
android:id="@+id/tv_size" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:layout_weight="1" | |||
android:text="已选择:0KB" | |||
android:layout_marginLeft="10dp" | |||
android:textColor="@color/black" | |||
/> | |||
<TextView | |||
android:id="@+id/tv_confirm" | |||
android:layout_width="wrap_content" | |||
android:layout_height="match_parent" | |||
android:paddingLeft="10dp" | |||
android:paddingRight="10dp" | |||
android:gravity="center" | |||
android:background="@color/blue" | |||
android:textColor="@color/white" | |||
android:text="确定(0/3)" | |||
/> | |||
</LinearLayout> | |||
</LinearLayout> |
@@ -10,10 +10,41 @@ | |||
android:layout_height="match_parent" | |||
android:orientation="vertical" | |||
android:background="@color/main_background"> | |||
<TextView | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:text="这里是系统设置的网络配置"/> | |||
<androidx.recyclerview.widget.RecyclerView | |||
android:id="@+id/rl_file" | |||
android:layout_width="match_parent" | |||
android:layout_height="0dp" | |||
android:layout_weight="1" | |||
android:layout_marginRight="10dp" | |||
android:layout_marginTop="10dp" | |||
android:layout_marginLeft="10dp" | |||
android:scrollbars="none" | |||
/> | |||
<LinearLayout | |||
android:layout_margin="@dimen/dp_10" | |||
android:layout_width="match_parent" | |||
android:layout_height="34dp" | |||
android:gravity="center_vertical" | |||
android:orientation="horizontal"> | |||
<Button | |||
android:id="@+id/xuanzhewenjian" | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:background="@drawable/bg_btn_login_selected" | |||
android:text="选择文件" | |||
android:layout_weight="1" | |||
/> | |||
<Button | |||
android:id="@+id/baocunbendi" | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:background="@drawable/button1" | |||
android:text="保存本地" | |||
android:layout_weight="1" | |||
/> | |||
</LinearLayout> | |||
</LinearLayout> | |||
</com.qmuiteam.qmui.widget.QMUIWindowInsetLayout> |
@@ -0,0 +1,38 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | |||
android:orientation="vertical" | |||
android:layout_width="match_parent" | |||
android:layout_height="match_parent"> | |||
<TextView | |||
android:id="@+id/tv_back" | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:drawableLeft="@mipmap/back" | |||
android:gravity="center_vertical" | |||
android:padding="10dp" | |||
android:text="返回上一层" | |||
/> | |||
<View | |||
android:id="@+id/view" | |||
android:layout_width="match_parent" | |||
android:layout_height="1dp" | |||
android:background="@color/file_bottom_line" | |||
android:layout_below="@id/tv_back" | |||
/> | |||
<androidx.recyclerview.widget.RecyclerView | |||
android:id="@+id/rl_all_file" | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:layout_below="@id/view" | |||
/> | |||
<TextView | |||
android:id="@+id/empty_view" | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:layout_centerInParent="true" | |||
android:gravity="center_horizontal" | |||
android:text="@string/empty_data" | |||
android:textSize="16sp" | |||
android:visibility="gone" | |||
/> | |||
</RelativeLayout> |
@@ -0,0 +1,27 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | |||
android:orientation="vertical" | |||
android:layout_width="match_parent" | |||
android:layout_height="match_parent"> | |||
<androidx.recyclerview.widget.RecyclerView | |||
android:id="@+id/rl_normal_file" | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content"/> | |||
<TextView | |||
android:id="@+id/empty_view" | |||
android:layout_width="match_parent" | |||
android:layout_height="wrap_content" | |||
android:layout_centerInParent="true" | |||
android:gravity="center_horizontal" | |||
android:text="@string/empty_data" | |||
android:textSize="16sp" | |||
android:visibility="gone" | |||
/> | |||
<ProgressBar | |||
android:id="@+id/progress" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:layout_centerInParent="true" | |||
android:visibility="gone" | |||
/> | |||
</RelativeLayout> |
@@ -0,0 +1,66 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | |||
android:id="@+id/layout_item_root" | |||
android:layout_width="match_parent" | |||
android:layout_height="80dp" | |||
android:clickable="true" | |||
android:layout_marginTop="10dp" | |||
android:background="@color/white" | |||
android:paddingLeft="10dp" | |||
android:paddingRight="10dp"> | |||
<ImageView | |||
android:id="@+id/iv_choose" | |||
android:layout_width="wrap_content" | |||
android:layout_height="wrap_content" | |||
android:layout_centerVertical="true" | |||
android:src="@mipmap/file_no_selection" | |||
/> | |||
<LinearLayout | |||
android:layout_width="match_parent" | |||
android:layout_height="match_parent" | |||
android:orientation="horizontal" | |||
android:layout_marginLeft="10dp" | |||
android:layout_toRightOf="@id/iv_choose" | |||
android:gravity="center_vertical" | |||
android:divider="@drawable/bottom_line" | |||
android:showDividers="middle" | |||
> | |||
<ImageView | |||
android:id="@+id/iv_type" | |||
android:layout_width="40dp" | |||
android:layout_height="40dp" | |||
android:layout_centerVertical="true" | |||
/> | |||
<LinearLayout | |||
android:id="@+id/layout_info" | |||
android:layout_width="match_parent" | |||
android:layout_height="match_parent" | |||
android:layout_marginLeft="10dp" | |||
android:layout_toRightOf="@id/iv_type" | |||
android:orientation="vertical" | |||
android:padding="10dp"> | |||
<TextView | |||
android:id="@+id/tv_name" | |||
android:layout_width="match_parent" | |||
android:layout_height="0dp" | |||
android:layout_weight="1" | |||
android:maxLines="1" | |||
android:ellipsize="end" | |||
android:textSize="16sp" | |||
android:textColor="@color/file_picker_title" | |||
android:text="名字"/> | |||
<TextView | |||
android:id="@+id/tv_detail" | |||
android:layout_width="match_parent" | |||
android:layout_height="0dp" | |||
android:layout_weight="1" | |||
android:textSize="14sp" | |||
android:textColor="@color/file_picker_des" | |||
android:text="类型:txt 大小:1024KB"/> | |||
</LinearLayout> | |||
</LinearLayout> | |||
</RelativeLayout> |
@@ -0,0 +1,60 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |||
xmlns:tools="http://schemas.android.com/tools" | |||
android:layout_width="match_parent" | |||
android:layout_height="80dp" | |||
android:gravity="center_vertical" | |||
android:orientation="horizontal" | |||
android:background="@color/white" | |||
android:layout_marginTop="10dp" | |||
android:paddingLeft="10dp" | |||
android:paddingRight="10dp" | |||
> | |||
<ImageView | |||
android:id="@+id/iv_type" | |||
android:layout_width="40dp" | |||
android:layout_height="40dp" | |||
android:layout_marginLeft="10dp" | |||
/> | |||
<LinearLayout | |||
android:id="@+id/layout_info" | |||
android:layout_width="0dp" | |||
android:layout_height="wrap_content" | |||
android:layout_marginLeft="10dp" | |||
android:layout_toRightOf="@id/iv_type" | |||
android:layout_weight="1" | |||
android:orientation="vertical" | |||
android:padding="10dp"> | |||
<TextView | |||
android:id="@+id/tv_name" | |||
android:layout_width="match_parent" | |||
android:layout_height="0dp" | |||
android:layout_weight="1" | |||
android:ellipsize="end" | |||
android:maxLines="1" | |||
android:textColor="@color/file_picker_title" | |||
tools:text="文件名"/> | |||
<TextView | |||
android:id="@+id/tv_detail" | |||
android:layout_width="match_parent" | |||
android:layout_height="0dp" | |||
android:layout_weight="1" | |||
android:textColor="@color/file_picker_des" | |||
android:textSize="14sp" | |||
android:text="类型:txt 大小:1024KB"/> | |||
/> | |||
</LinearLayout> | |||
<ImageView | |||
android:id="@+id/iv_delete" | |||
android:layout_width="40dp" | |||
android:layout_height="40dp" | |||
android:src="@mipmap/file_picker_delete" | |||
android:layout_marginRight="10dp" | |||
android:visibility="gone" | |||
/> | |||
</LinearLayout> |
@@ -3,6 +3,13 @@ | |||
<!--<color name="colorPrimary">#008577</color> | |||
<color name="colorPrimaryDark">#00574B</color> | |||
<color name="colorAccent">#D81B60</color>--> | |||
<color name="colorPrimary">#3F51B5</color> | |||
<color name="colorPrimaryDark">#303F9F</color> | |||
<color name="colorAccent">#FF4081</color> | |||
<color name="blue">#44B2FE</color> | |||
<color name="file_picker_title">#4A4A4A</color> | |||
<color name="file_picker_des">#86848B</color> | |||
<color name="file_bottom_line">#ECECEC</color> | |||
<!-- common --> | |||
<color name="dataGridColumnHeaderColor">#00c2f4</color> | |||
@@ -1,5 +1,14 @@ | |||
<resources> | |||
<string name="app_name">菠萝小炒</string> | |||
<string name="file_normal">常用文件</string> | |||
<string name="file_all">全部文件</string> | |||
<string name="empty_data">没有数据</string> | |||
<string name="not_available">sd卡不可用</string> | |||
<string name="already_select">已选择:%s</string> | |||
<string name="file_select_res">确定%s</string> | |||
<string name="file_select_max">最多选择%d个文件</string> | |||
<string name="file_select_res1">保存本地%s</string> | |||
<!-- TODO: Remove or change this placeholder text --> | |||
<string name="hello_blank_fragment">Hello blank fragment</string> | |||
@@ -14,7 +23,7 @@ | |||
<string name="common_example">示例图片</string> | |||
<!-- TODO: 系统设置 --> | |||
<string name="NetworkManagement">网络管理</string> | |||
<string name="NetworkManagement">资源管理</string> | |||
<string name="DeviceInformation">设备信息</string> | |||
<string name="SystemSettings">系统设置</string> | |||
<string name="SeasoningSettings">调料设置</string> | |||