代码拉取完成,页面将自动刷新
首先在你的项目配置kotlin环境, 在你的moudle里添加如下代码:
dependencies {
......
implementation 'com.william:JTFilePicker:1.3.1'
}
/**
* 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.
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。