# RxImagePicker **Repository Path**: chinasoft5_ohos/RxImagePicker ## Basic Information - **Project Name**: RxImagePicker - **Description**: 相册图片选择 - **Primary Language**: Java - **License**: MIT - **Default Branch**: 2.x - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 4 - **Forks**: 0 - **Created**: 2021-06-22 - **Last Updated**: 2022-09-06 ## Categories & Tags **Categories**: harmonyos-selector, harmonyos-image **Tags**: None ## README # RxImagePicker #### 项目介绍 - 项目名称:RxImagePicker - 所属系列:openharmony的第三方组件适配移植 - 功能:相册图片选择 - 项目移植状态:主功能完成 - 调用差异:无 - 开发版本:sdk6,DevEco Studio2.2 Beta1 - 基线版本:tag 2.5.6 #### 效果演示 ![输入图片说明](./image/RxImagePicker.gif "gif") #### 安装教程 1.在项目根目录下的build.gradle文件中, ``` allprojects { repositories { maven { url 'https://s01.oss.sonatype.org/content/repositories/snapshots/' } } } ``` 2.在entry模块的build.gradle文件中, ``` dependencies { implementation('com.gitee.chinasoft_ohos:rximagepicker:0.0.1-SNAPSHOT') implementation('com.gitee.chinasoft_ohos:rximagepicker_support:0.0.1-SNAPSHOT') implementation('com.gitee.chinasoft_ohos:rximagepicker_support_zhihu:0.0.1-SNAPSHOT') implementation('com.gitee.chinasoft_ohos:rximagepicker_support_wechat:0.0.1-SNAPSHOT') ...... } ``` 在sdk6,DevEco Studio2.2 Beta1下项目可直接运行 如无法运行,删除项目.gradle,.idea,build,gradle,build.gradle文件, 并依据自己的版本创建新项目,将新项目的对应文件复制到根目录下 #### 使用说明 声明一个接口,并进行基础的配置: ##### 系统风格的样式 ```java public interface MyImagePicker { @Gallery // 打开相册选择图片 Observable openGallery(Context context); @Camera // 打开相机拍照 Observable openCamera(Context context); } ``` ```java //在您的FractionAbility使用 //重写onRequestPermissionsFromUserResult @Override public void onRequestPermissionsFromUserResult(int requestCode, String[] permissions, int[] grantResults) { AbilityUtils.onRequestPermissionsFromUserResult(this, requestCode, permissions, grantResults); } //onAbilityResult @Override protected void onAbilityResult(int requestCode, int resultCode, Intent resultData) { super.onAbilityResult(requestCode, resultCode, resultData); AbilityUtils.onAbilityResult(this, requestCode, resultCode, resultData); } Consumer consumer = new Consumer() { @Override public void accept(Result result) throws Throwable { } } //打开系统默认的相册 RxImagePicker.create(MyImagePicker.class).openGallery(this) .subscribe(consumer); //打开相机 RxImagePicker.create(MyImagePicker.class).openCamera(this) .subscribe(consumer); ``` ##### 微信风格的样式 ```java public interface WechatImagePicker { @Gallery(componentClazz = WechatImagePickerAbility.class, openAsFragment = false) Observable openGallery(Context context, ICustomPickerConfiguration config); @Camera Observable openCamera(Context context); } ``` ```java //在您的FractionAbility使用 @Override protected void onAbilityResult(int requestCode, int resultCode, Intent resultData) { super.onAbilityResult(requestCode, resultCode, resultData); AbilityUtils.onAbilityResult(this, requestCode, resultCode, resultData); } RxImagePicker rxImagePicker = RxImagePicker .create(WechatImagePicker.class); //打开相机 rxImagePicker.openCamera(this) .subscribe(onNext(), onError()); //打开相册 rxImagePicker.openGallery(this, new WechatConfigrationBuilder(MimeType.ofAll(), false) .capture(true) .maxSelectable(9) .countable(true) .spanCount(4) .countable(false) .build()) .subscribe(onNext(), onError()); ``` ##### 知乎风格的样式 ```java public interface ZhihuImagePicker { @Gallery( componentClazz = ZhihuImagePickerAbility.class, openAsFragment = false ) Observable openGalleryAsNormal(Context context, ICustomPickerConfiguration iCustomPickerConfiguration); @Gallery( componentClazz = ZhihuImagePickerAbility.class, openAsFragment = false ) Observable openGalleryAsDracula(Context context, ICustomPickerConfiguration iCustomPickerConfiguration); @Camera Observable openCamera(Context context); } ``` ```java //在您的FractionAbility使用 @Override protected void onAbilityResult(int requestCode, int resultCode, Intent resultData) { super.onAbilityResult(requestCode, resultCode, resultData); AbilityUtils.onAbilityResult(this, requestCode, resultCode, resultData); } RxImagePicker rxImagePicker = RxImagePicker .create(ZhihuImagePicker.class); rxImagePicker.openCamera(this) .subscribe(fetchUriObserver()); //风格1 rxImagePicker.openGalleryAsNormal(this, new ZhihuConfigurationBuilder(MimeType.ofImage(), false) .capture(true) .maxSelectable(9) .countable(true) .spanCount(4) .theme(com.qingmei2.rximagepicker_extension_zhihu.ResourceTable.Pattern_Zhihu_Normal) .build()) .subscribe(fetchUriObserver()); //风格2 rxImagePicker.openGalleryAsDracula(this, new ZhihuConfigurationBuilder(MimeType.ofImage(), false) .capture(true) .spanCount(3) .maxSelectable(1) .theme(com.qingmei2.rximagepicker_extension_zhihu.ResourceTable.Pattern_Zhihu_Dracula) .build()) .subscribe(fetchUriObserver()); ``` ##### 自定义风格属性文件 [属性文件事例](./rximagepicker_support_wechat/src/main/resources/base/element/pattern.json) ------ | JSON Attribute| Description| |--------------|------------ | |colorPrimary| 相册主题色| |colorPrimaryDark| 相册副主题色| |album.dropdown.title.color| 相薄弹出框title字体色| |album.dropdown.count.color| 相薄弹出框tcount字体色| |album.dropdown.popup.bg.color| 相薄弹出框t背景色| |album.element.color| 箭头颜色| |album.thumbnail.placeholder| 占位图颜色| |album.emptyView| 空视图图片| |item.placeholder| 占位图颜色| |item.checkCircle.backgroundColor| 选择框背景| |item.checkCircle.borderColor| 选择框边框背景| |page.bg| 相薄背景| |bottomToolbar.bg| 底部框背景| |bottomToolbar.preview.textColor| 底部预览字体颜色(可选择)| |bottomToolbar.preview.textColor.disable| 底部预览字体颜色(默认)| |bottomToolbar.apply.textColor| 底部使用字体颜色(可选择)| |bottomToolbar.apply.textColor.disable| 底部使用字体颜色(默认)| |preview.bottomToolbar.back.textColor| 预览返回字体颜色| |preview.bottomToolbar.apply.textColor| 预览底部使用字体颜色(可选择)| |preview.bottomToolbar.apply.textColor.disable| 预览底部使用字体颜色(默认)| |capture.textColor| 相机按钮颜色| #### 测试信息 CodeCheck代码测试无异常 CloudTest代码测试无异常 病毒安全检测通过 当前版本demo功能与原组件基本无差异 #### 版本迭代 - 0.0.1-SNAPSHOT #### 版权和许可信息 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.