- 支持自定义文件图标
- 以字符串集合返回
- 超级轻量,超级简单
- 基于kotlin
首先在你的项目配置kotlin环境, 在你的moudle里添加如下代码:
dependencies {
......
implementation 'com.william:JTFilePicker:1.3.2'
}
/**
* kotlin启动
* @param 参数1:可以是activity或者fragment
*/
JTFilePicker.from(activity||fragment, object :OnFileIconLoadListener{
override fun fileIconLoad(imageView: ImageView, fileBean: FileBean) {
when (fileBean.extension) {
"txt" ->
//可以用普通方式设置drawable
imageView.setImageDrawable(R.drawable.txt)
"jpg"->//图片类型可以直接在图标中预览
//推荐完全交给Glide或者其他图片加载框架
Glide.with(context).load(fileBean.path).into(imageView)
}
}
})
//可选,设置首页路径(即能打开的根目录)默认为内存卡根目录
//.setRoot(Environment.getExternalStorageDirectory().path)
.open(0)
/**
* kotlin接收
*/
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
if (resultCode == Activity.RESULT_OK){
Toast.makeText(this,"已成功:${data!!.getStringArrayListExtra("paths")}",Toast.LENGTH_SHORT).show()
} else {
Toast.makeText(this,"已取消",Toast.LENGTH_SHORT).show()
}
}
/**
* java 启动
* @param 参数1:可以是activity或者fragment
*/
JTFilePicker.Companion.from(this, new OnFileIconLoadListener() {
@Override
public void fileIconLoad(ImageView imageView, FileBean fileBean) {
switch (fileBean.getExtension()) {
case "txt":
//可以用普通方式设置drawable
imageView.setImageDrawable(R.drawable.txt);
break;
case "jpg"://图片类型可以直接在图标中预览
//推荐完全交给Glide或者其他图片加载框架
Glide.with(context).load(fileBean.getPath()).into(imageView);
break;
default:
}
}
})
//可选,设置首页路径(即能打开的根目录)默认为内存卡根目录
//.setRoot(Environment.getExternalStorageDirectory().path)
.open(0);
/**
* java java接收
*/
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == Activity.RESULT_CANCELED) {
return;
}
switch (requestCode) {
case REQUEST_PICK_FILE://从选择文件页面返回
List<String> paths = data.getStringArrayListExtra("paths");
break;
default:
}
}
Copyright 2018 william Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.