89

GitHub - qingmei2/RxImagePicker: :star2: 支持RxJava2、灵活可高度定制的Android图...

 5 years ago
source link: https://github.com/qingmei2/RxImagePicker
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

README.md

RxImagePicker

Download

RxImagePicker的设计起源,请参考我的这篇文章

简介

RxImagePicker存在的目的是:让开发者能够简单并且灵活的方式实现Android开发中图片选择的需求。

它与传统的其他三方的图片选择库不同的是,后者通过跳转到固定的Activity进行图片选择,并不能满足所有应用的需求;以QQ聊天会话界面的图片选择功能为例,这种特殊的UI需求很难依靠图片选择库实现,开发者只能去自己实现。

一旦和目前项目的需求有了冲突(修改或者添加),开发者考虑的不应该是【这个库实现不了,干脆换一个库吧】或者【不管这个库,我去再单独实现一个】,而是,基于同一个图片选择框架,修改或者添加对应配置的接口

screenshot_qq

RxImagePicker是一个用于Android的响应式图片选择器,它将您的图片选择需求转换为一个接口进行配置,并在任何一个Activity或者Fragment中展示任何样式的图片选择UI。

支持的功能

  • Android Camera拍照
  • Android 图片选择
  • 以响应式数据流的格式返回数据(支持Observable/Flowable/Single/Maybe)
  • 动态配置响应式数据流的数据类型(File,Bitmap,或是Uri)

UI的支持

除了Android系统默认的图片选择样式,你可以选择使用这些额外的UI支持:

  • 系统级别图片选择器
  • 知乎主题图片选择器
  • 微信主题图片选择器
  • 自定义UI图片选择器

示例截图

系统图片选择和结果展示

screenshot_sysytem.png screenshot_result.png

知乎主题

screenshot_zhihu_dracula.png screenshot_zhihu_normal.png

微信主题

screenshot_wechat.png screenshot_wechat_expand.png

想要 快速实现上图所示效果 请点击这里查看wiki中的详细文档。

基础使用

1. 添加依赖在Module的build.gradle文件中:

// 最基础的架构,仅提供了系统默认的图片选择器和拍照功能
compile 'com.github.qingmei2:rximagepicker:0.2.3'

// 提供了自定义UI图片选择器的基本组件,自定义UI的需求需要添加该依赖
compile 'com.github.qingmei2:rximagepicker_support:0.2.3'

// 如果需要额外的UI支持,请选择依赖对应的UI拓展库
compile 'com.github.qingmei2:rximagepicker_support_zhihu:0.2.3'     // 知乎图片选择器
compile 'com.github.qingmei2:rximagepicker_support_wechat:0.2.3'    // 微信图片选择器

2. 接口配置

声明一个接口,并进行基础的配置:

public interface MyImagePicker {

    @Gallery    //打开相册选择图片
    @AsFile     //返回值为File类型
    Observable<File> openGallery();

    @Camera    //打开相机拍照
    @AsBitmap  //返回值为Bitmap类型
    Observable<Bitmap> openCamera();
}

3. 实例化接口并使用它

在您的Activity或者Fragment中实例化该接口,以打开系统默认的相册/相机界面:

//打开系统默认的图片选择器
private void onButtonClick() {
    new RxImagePicker.Builder()
            .with(this)
            .build()
            .create(MyImagePicker.class)
            .openGallery()
            .subscribe(new Consumer<File>() {
                @Override
                public void accept(File file) throws Exception {
                    // 对图片进行处理,比如加载到ImageView中
                }
            });
}

详细文档(重要!!!)

关于RxImagePicker更详细的使用说明,进阶使用和拓展功能,请参考wiki!

参考

RxImagePicker 的设计过程中,我参考了很多的三方库,它们源码中优秀的 设计思想 或者 架构设计 ,都给与了我很大的启示,在此深表感谢,感谢诸多开源爱好者前辈们的无私精神:

Contributor

License

The RxImagePicker:MIT License

Copyright (c) 2018 qingmei2

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK