FilePickerLibrary, 允许选取文件和/或者目录的简单库

分享于 

5分钟阅读

GitHub

  繁體 雙語
Simple library that allows for the picking of files and/or directories.
  • 源代码名称:FilePickerLibrary
  • 源代码网址:http://www.github.com/DeveloperPaul123/FilePickerLibrary
  • FilePickerLibrary源代码文档
  • FilePickerLibrary源代码下载
  • Git URL:
    git://www.github.com/DeveloperPaul123/FilePickerLibrary.git
    Git Clone代码到本地:
    git clone http://www.github.com/DeveloperPaul123/FilePickerLibrary
    Subversion代码到本地:
    $ svn co --depth empty http://www.github.com/DeveloperPaul123/FilePickerLibrary
    Checked out revision 1.
    $ cd repo
    $ svn up trunk
    
    FilePickerLibrary

    Android Arsenal

    Release

    允许选取文件和目录的简单库。 这是一种简洁且简单的方法,允许用户轻松地选择文件。 这个图书馆是由 Android L 和新的材料设计指南,添加到sleekness和美容的灵感。

    [image] ( 图像/main_framed。png )

    快速概述什么是

    • 兼容于API级别 16

    包括项目

    提供Gradle依赖项

    步骤 1

    在存储库的末尾添加 root build.gradle 中的JitPack:

    allprojects {
     repositories {
     ...
     maven { url "https://jitpack.io" }
     }
    }
    步骤 2

    添加依赖项

    dependencies {
     compile 'com.github.alirezaaa:FilePickerLibrary:3.5.1'}

    克隆或者下载 .zip 文件

    克隆这里存储库或者下载压缩文件,然后解压缩到你的计算机。 简单地将 library 模块导入你的项目。

    用法

    使用以下示例之一或者简单地编译并测试提供的示例 app:

    使用( 使用现代生成器)的材质主题

    newFilePickerBuilder(this)
    . withColor(android.R.color.holo_blue_bright)
    . withRequest(Request.FILE)
    . withScope(Scope.ALL)
    . withMimeType(MimeType.JPEG)
    . useMaterialActivity(true)
    . launch(REQUEST_FILE);

    image/png Mime类型

    Intent filePicker =newIntent(this, FilePickerActivity.class);
    filePicker.putExtra(FilePickerActivity.SCOPE, Scope.ALL);
    filePicker.putExtra(FilePickerActivity.REQUEST, Request.FILE);
    filePicker.putExtra(FilePickerActivity.INTENT_EXTRA_COLOR_ID, android.R.color.holo_green_dark);
    filePicker.putExtra(FilePickerActivity.MIME_TYPE, MimeType.PNG);
    startActivityForResult(filePicker, REQUEST_FILE);

    显示为对话框

    Intent filePickerDialogIntent =newIntent(this, FilePickerActivity.class);
    filePickerDialogIntent.putExtra(FilePickerActivity.THEME_TYPE, ThemeType.DIALOG);
    filePickerDialogIntent.putExtra(FilePickerActivity.REQUEST, Request.FILE);
    startActivityForResult(filePickerDialogIntent, REQUEST_FILE);

    选择目录

    Intent filePickerActivity =newIntent(this, FilePickerActivity.class);
    filePickerActivity.putExtra(FilePickerActivity.SCOPE, Scope.ALL);
    filePickerActivity.putExtra(FilePickerActivity.REQUEST, Request.DIRECTORY);
    filePickerActivity.putExtra(FilePickerActivity.INTENT_EXTRA_FAB_COLOR_ID, android.R.color.holo_green_dark);
    startActivityForResult(filePickerActivity, REQUEST_DIRECTORY);

    要得到结果,你必须重写 onActivityResult(int, int, Intent) 方法,如下所示:

    @Overridepublicvoid onActivityResult(int requestCode, int resultCode, Intent data) {
     super.onActivityResult(requestCode, resultCode, data);
     if ((requestCode ==REQUEST_DIRECTORY) && (resultCode ==RESULT_OK)) {
     Toast.makeText(this, "Directory Selected: "+ data.getStringExtra(FilePickerActivity.FILE_EXTRA_DATA_PATH), Toast.LENGTH_LONG).show();
     } elseif ((requestCode ==REQUEST_FILE) && (resultCode ==RESULT_OK)) {
     Toast.makeText(this, "File Selected: "+ data.getStringExtra(FilePickerActivity.FILE_EXTRA_DATA_PATH), Toast.LENGTH_LONG).show();
     }
    }

    贡献者

    许可证

    
    Copyright 2016 Paul T
    
    
    
    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.
    
    
    
    

    文件  files  DIR  pick  directories  Picking