2020
2121
2222GitHub地址: [ https://github.com/crazycodeboy/TakePhoto ] ( https://github.com/crazycodeboy/TakePhoto )
23+ ## 目录
2324
24- ## 预览图
25+ - [ 安装说明] ( #安装说明 )
26+ - [ 演示] ( #演示 )
27+ - [ 使用说明] ( #使用说明 )
28+ - [ API] ( #api )
29+ - [ 贡献] ( #贡献 )
30+
31+ ## 安装说明
32+ ** Gradle:**
33+
34+ ``` groovy
35+ compile 'com.jph.takephoto:takephoto_library:3.0.0'
36+ ```
37+
38+ ** Maven:**
39+
40+ ``` groovy
41+ <dependency>
42+ <groupId>com.jph.takephoto</groupId>
43+ <artifactId>takephoto_library</artifactId>
44+ <version>3.0.0</version>
45+ <type>pom</type>
46+ </dependency>
47+ ```
2548
26- 运行效果图:
2749
50+ ## 演示
51+
52+ 运行效果图:
53+ ![ 预览图] ( https://raw.githubusercontent.com/crazycodeboy/TakePhoto/master/Screenshots/takephoto_preview.png )
2854![ 运行效果图] ( https://raw.githubusercontent.com/crazycodeboy/TakePhoto/master/Screenshots/%E9%A2%84%E8%A7%88%E5%9B%BE.jpg )
2955
3056
31- ## 如何使用
57+ ## 使用说明
3258
3359### 使用TakePhoto有以下两种方式:
3460** 方式一:通过继承的方式**
@@ -37,17 +63,61 @@ GitHub地址: [https://github.com/crazycodeboy/TakePhoto](https://github.com/c
37633 . 重写以下方法获取结果
3864
3965``` java
40- void takeSuccess(String imagePath);
41- void takeFail(String msg);
42- void takeCancel();
66+ void takeSuccess(TResult result);
67+ void takeFail(TResult result, String msg);
68+ void takeCancel();
4369```
44- 此方式使用简单,满足的大部分的使用需求,具体使用详见simple 。如果通过继承的方式无法满足实际项目的使用,可以通过下面介绍的方式。
70+ 此方式使用简单,满足的大部分的使用需求,具体使用详见 [ simple ] ( https://github.com/crazycodeboy/TakePhoto/blob/master/simple/src/main/java/com/jph/simple/SimpleActivity.java ) 。如果通过继承的方式无法满足实际项目的使用,可以通过下面介绍的方式。
4571
4672** 方式二:通过组装的方式**
47- 1 . 获取TakePhoto实例` TakePhoto takePhoto=new TakePhotoImpl(getActivity(),this); `
48- 2 . 在 ` onCreate ` ,` onActivityResult ` ,` onSaveInstanceState ` 方法中调用TakePhoto对用的方法。
49- 3 . 调用TakePhoto实例进行相关操作。
50- 4 . 在` TakeResultListener ` 相关方法中获取结果。
73+
74+ 可参照:[ TakePhotoActivity] ( https://github.com/crazycodeboy/TakePhoto/blob/master/takephoto_library/src/main/java/com/jph/takephoto/app/TakePhotoActivity.java ) ,以下为主要步骤:
75+
76+ 1.实现` TakePhoto.TakeResultListener,InvokeListener ` 接口。
77+
78+ 2.在 ` onCreate ` ,` onActivityResult ` ,` onSaveInstanceState ` 方法中调用TakePhoto对用的方法。
79+
80+ 3.重写` onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) ` ,添加如下代码。
81+
82+ ``` java
83+ @Override
84+ public void onRequestPermissionsResult(int requestCode, String [] permissions, int [] grantResults) {
85+ super . onRequestPermissionsResult(requestCode, permissions, grantResults);
86+ // 以下代码为处理Android6.0、7.0动态权限所需
87+ TPermissionType type= PermissionManager . onRequestPermissionsResult(requestCode,permissions,grantResults);
88+ PermissionManager . handlePermissionsResult(this ,type,invokeParam,this );
89+ }
90+ ```
91+
92+ 4.重写` TPermissionType invoke(InvokeParam invokeParam) ` 方法,添加如下代码:
93+
94+ ``` java
95+ @Override
96+ public TPermissionType invoke(InvokeParam invokeParam) {
97+ TPermissionType type= PermissionManager . checkPermission(TContextWrap . of(this ),invokeParam. getMethod());
98+ if (TPermissionType . WAIT. equals(type)){
99+ this . invokeParam= invokeParam;
100+ }
101+ return type;
102+ }
103+ ```
104+
105+ 5.添加如下代码获取TakePhoto实例:
106+
107+ ``` java
108+ /**
109+ * 获取TakePhoto实例
110+ * @return
111+ */
112+ public TakePhoto getTakePhoto(){
113+ if (takePhoto== null ){
114+ takePhoto= (TakePhoto ) TakePhotoInvocationHandler . of(this ). bind(new TakePhotoImpl (this ,this ));
115+ }
116+ return takePhoto;
117+ }
118+ ```
119+
120+ ## API
51121
52122### 获取图片
53123TakePhoto提供拍照,从相册选择,从文件中选择三种方式获取图片。
@@ -68,6 +138,11 @@ void onPickFromGallery();
68138 * @param outPutUri 图片保存的路径
69139 */
70140void onPickFromCapture(Uri outPutUri);
141+ /**
142+ * 图片多选
143+ * @param limit 最多选择图片张数的限制
144+ * */
145+ void onPickMultiple(int limit);
71146```
72147以上三种方式均提供对应的裁剪API,详见:[ 裁剪图片] ( https://github.com/crazycodeboy/TakePhoto#裁剪图片 ) 。
73148** 注:**
@@ -97,6 +172,12 @@ void onPickFromGalleryWithCrop(Uri outPutUri, CropOptions options);
97172 * @param options 裁剪配置
98173 */
99174void onPickFromDocumentsWithCrop(Uri outPutUri, CropOptions options);
175+ /**
176+ * 图片多选,并裁切
177+ * @param limit 最多选择图片张数的限制
178+ * @param options 裁剪配置
179+ * /
180+ void onPickMultipleWithCrop(int limit, CropOptions options);
100181```
101182#### 对指定图片进行裁剪
102183另外,TakePhoto也支持你对指定图片进行裁剪:
@@ -109,6 +190,12 @@ void onPickFromDocumentsWithCrop(Uri outPutUri, CropOptions options);
109190 * @param options 裁剪配置
110191 */
111192void onCrop(Uri imageUri, Uri outPutUri, CropOptions options)throws TException ;
193+ /**
194+ * 裁剪多张图片
195+ * @param multipleCrop 要裁切的图片的路径以及输出路径
196+ * @param options 裁剪配置
197+ */
198+ void onCrop(MultipleCrop multipleCrop, CropOptions options)throws TException ;
112199```
113200
114201#### CropOptions
@@ -139,13 +226,15 @@ void onCrop(Uri imageUri, Uri outPutUri, CropOptions options)throws TException;
139226 * @param showCompressDialog 压缩时是否显示进度对话框
140227 * @return
141228 */
142- TakePhoto onEnableCompress(CompressConfig config,boolean showCompressDialog);
229+ void onEnableCompress(CompressConfig config,boolean showCompressDialog);
143230```
144231
145232** Usage:**
146233
147234``` java
148- getTakePhoto(). onEnableCompress(compressConfig,true ). onPickFromGalleryWithCrop(imageUri,cropOptions);
235+ TakePhoto takePhoto= getTakePhoto();
236+ takePhoto. onEnableCompress(compressConfig,true );
237+ takePhoto. onPickFromGallery();
149238```
150239如果你启用了图片压缩,` TakePhoto ` 会使用` CompressImage ` 对图片进行压缩处理,` CompressImage ` 目前支持对图片的尺寸以及图片的质量进行压缩。默认情况下,` CompressImage ` 开启了尺寸与质量双重压缩。
151240
@@ -154,16 +243,16 @@ getTakePhoto().onEnableCompress(compressConfig,true).onPickFromGalleryWithCrop(i
154243** Usage:**
155244
156245``` java
157- new CompressImageImpl (compressConfig) . compress(picturePath , new CompressImage .CompressListener () {
246+ new CompressImageImpl (compressConfig,result . getImages() , new CompressImage .CompressListener () {
158247 @Override
159- public void onCompressSuccess (String imgPath ) {// 图片压缩成功
160-
248+ public void onCompressSuccess (ArrayList< TImage > images ) {
249+ // 图片压缩成功
161250 }
162251 @Override
163- public void onCompressFailed (String imagePath , String msg ) {// 图片压缩失败
164-
252+ public void onCompressFailed (ArrayList< TImage > images , String msg ) {
253+ // 图片压缩失败
165254 }
166- });
255+ }). compress() ;
167256```
168257
169258#### CompressConfig
@@ -172,12 +261,18 @@ new CompressImageImpl(compressConfig).compress(picturePath, new CompressImage.Co
172261
173262``` java
174263CompressConfig compressConfig= new CompressConfig .Builder (). setMaxSize(50 * 1024 ). setMaxPixel(800 ). create();
175- getTakePhoto(). onEnableCompress(compressConfig,true ). onPickFromGallery();
176264```
177265
178266
179267## 兼容性
180268
269+ ### Android6.0
270+ 由于Android6.0新增了"运行时权限控制(Runtime Permissions)",为了应对这一改变,TakePhoto加入和自动权限管理,当TakePhoto检测到需要权限时,TakePhoto会自动申请权限,所以小伙伴们不用担心,权限的使用问题。
271+
272+ ### Android7.0
273+
274+ 在Android N中,Android 框架执行了 StrictMode,应用间共享文件和以前也有所区别。为了适配Android7.0的改变,同时也为了方便大家使用TakePhoto,TakePhoto会自动根据手机的Android版本自行适配,小伙伴们依旧可以向TakePhoto传递` Uri imageUri = Uri.fromFile(file); ` 类型的Uri而不用担心兼容性问题。
275+
181276### TakePhoto在深度兼容性方面的测试
182277![ 兼容性测试报告] ( https://raw.githubusercontent.com/crazycodeboy/TakePhoto/master/Screenshots/%E5%85%BC%E5%AE%B9%E6%80%A7%E6%B5%8B%E8%AF%95.jpg )
183278
200295</activity>
201296```
202297
203- ## 在项目中使用
204- 为方便大家使用,现已将TakePhoto V2.0.4发布到JCenter(如果你对如何将项目发布到JCenter感兴趣可以参考:《[ 教你轻松将Android library 发布到JCenter] ( http://blog.csdn.net/fengyuzhengfan/article/details/51407009 ) )》
205- Gradle:
206-
207- ``` groovy
208- compile 'com.jph.takephoto:takephoto_library:2.0.4'
209- ```
210-
211- Maven:
212-
213- ``` groovy
214- <dependency>
215- <groupId>com.jph.takephoto</groupId>
216- <artifactId>takephoto_library</artifactId>
217- <version>2.0.4</version>
218- <type>pom</type>
219- </dependency>
220- ```
221298
222- ## 最后
223- 如果你对 [ TakePhoto ] ( https://github.com/crazycodeboy/TakePhoto ) 有更好的建议或想改造它 ,欢迎大家[ Fork and Pull requests] ( https://github.com/crazycodeboy/TakePhoto ) 。
299+ ## 贡献
300+ 如果你在使用TakePhoto中遇到任何问题可以提 [ Issues ] ( https://github.com/crazycodeboy/TakePhoto/issues ) 出来。另外欢迎大家为TakePhoto贡献智慧 ,欢迎大家[ Fork and Pull requests] ( https://github.com/crazycodeboy/TakePhoto ) 。
0 commit comments