Giter VIP home page Giter VIP logo

android-fileselector's Introduction

#FileSelector

##Android平台下的文件选择器

  • 使用Android Studio,所以要引用该库也需时使用Android Studio开发
  • 支持Activity、DialogFragment、AlertDialog三种模式进行文件选择
  • 若不需要自定义可直接依赖aar包,需自定义可导入Module:FileSelector自行修改源码
  • 无其他依赖

###DialogFragment模式使用方法

    FileSelectorDialog fileDialog = new FileSelectorDialog();
    //设置文件选择完成后的回调事件
    fileDialog.setOnSelectFinish(new FileSelectorDialog.OnSelectFinish() {
        @Override
        public void onSelectFinish(ArrayList<String> paths) {
           Toast.makeText(getApplicationContext(), paths.toString(), Toast.LENGTH_SHORT).show();
        }
    });
    //传递配置信息
    Bundle bundle = new Bundle();
    bundle.putSerializable(FileConfig.FILE_CONFIG, fileConfig);
    fileDialog.setArguments(bundle);
    FragmentTransaction ft = getFragmentManager().beginTransaction();
    ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
    //在需要打开对话框时调用show函数
    fileDialog.show(ft, "fileDialog");

###Activity模式使用方法

    //生成一个Intent指向FileSelectorActivity
    Intent intent = new Intent(getApplicationContext(), FileSelectorActivity.class);
    //传递配置文件
    intent.putExtra(FileConfig.FILE_CONFIG, fileConfig);
    //启动
    startActivityForResult(intent, 0);

接收返回的数据

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == 0) {
            if (resultCode == RESULT_OK) {
                //通过FileSelector.RESULT键去取值,是个ArrayList<String>类型的值
                ArrayList<String> list = data.getStringArrayListExtra(FileSelector.RESULT);
                Toast.makeText(getApplicationContext(), list.toString(), Toast.LENGTH_SHORT).show();
            }
        }
        super.onActivityResult(requestCode, resultCode, data);
    }

在使用FileSelectorActivity时还需要在你的项目的AndroidManifest文件中加入:

    <activity android:name="zhou.tools.fileselector.FileSelectorActivity"/>

###AlertDialog模式使用方法

    //通过参数实例化
    FileSelectorAlertDialog fileSelectorAlertDialog=new FileSelectorAlertDialog(this,fileConfig);
    //在需要显示的时候调用show方法
    fileSelectorAlertDialog.show();

效果图:

Dialog模式

Activity模式

##具体操作方式还请查看Demo

by zzhoujay

android-fileselector's People

Contributors

zzhoujay avatar

Stargazers

Forget avatar Jessy He avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.