Skip to content

Commit

Permalink
Release 1.0.1, add gallery, camera config, fix #11, close #15, close #12
Browse files Browse the repository at this point in the history
, close #7, close #2.
  • Loading branch information
yanzhenjie committed Mar 30, 2017
1 parent db5d6aa commit aed5262
Show file tree
Hide file tree
Showing 122 changed files with 4,887 additions and 1,694 deletions.
5 changes: 5 additions & 0 deletions .gitignore
@@ -0,0 +1,5 @@
*.iml
/.idea/
build
.gradle
/local.properties
2 changes: 1 addition & 1 deletion LICENSE
Expand Up @@ -186,7 +186,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright 2016 Yan Zhenjie
Copyright 2017 Yan Zhenjie

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
163 changes: 163 additions & 0 deletions README-CN.md
@@ -0,0 +1,163 @@
# Album
`Album`是一个MD风格的开源相册,主要功能分为两部分:相册选图、画廊预览。

技术交流群:[46523908](http://jq.qq.com/?_wv=1027&k=410oIg0)
图片上传推荐使用NoHttp:[NoHttp开源地址](https://github.com/yanzhenjie/NoHttp)[NoHttp使用文档](http://doc.nohttp.net)

我的主页:[http://www.yanzhenjie.com](http://www.yanzhenjie.com)
我的博客:[http://blog.yanzhenjie.com](http://blog.yanzhenjie.com)

# 特性
1. 支持组件:`Activity``Fragment`
2. UI风格可以配置,比如:`Toolbar``StatusBar``NavigationBar`
3. 单选、多选、文件夹预览、画廊、画廊缩放。
4. 支持配置相册展示时的列数。
5. 支持配置是否使用相机。
6. 画廊预览选择的图片,预览时可以反选。

# 效果预览
体验请[下载demo的apk](https://github.com/yanzhenjie/Album/blob/master/sample-release.apk?raw=true)
<image src="./image/1.gif" width="170px"/> <image src="./image/2.gif" width="170px"/> <image src="./image/3.gif" width="170px"/> <image src="./image/4.gif" width="170px"/>

# 依赖
* Gradle:
```groovy
compile 'com.yanzhenjie:album:1.0.1'
```

* Maven:
```xml
<dependency>
<groupId>com.yanzhenjie</groupId>
<artifactId>album</artifactId>
<version>1.0.1</version>
<type>pom</type>
</dependency>
```
* Eclipse 请放弃治疗。

# mainifest.xml中需要注册
```xml
<activity
android:name="com.yanzhenjie.album.AlbumActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:theme="@style/Theme.AppCompat.Light.NoActionBar"
android:windowSoftInputMode="stateAlwaysHidden|stateHidden" />
```

* 注意:1.0.0以上版本给这个activity配置的`android:title=""`属性会被自动忽略。

# 权限
```xml
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
```

* 开发者不需要担心`Android6.0`运行时权限,`Album`已经非常完善的处理过了。
* 另外`Android6.0`运行时权限推荐使用:[AndPermission](https://github.com/yanzhenjie/AndPermission),如果不使用6.0特性,建议把`targetSdkVersion`值设置的小于23,这样就不会使用`Android6.0`运行时权限了。

# 使用教程
`Album`主要功能分为两部分:相册选图、画廊预览,下面分别说明。

## Album相册
使用`Album.album(this).start()`即可调起相册。
```java
Album.album(this)
.requestCode(999) // 请求码,返回时onActivityResult()的第一个参数。
.toolBarColor(toolbarColor) // Toolbar 颜色,默认蓝色。
.statusBarColor(statusBarColor) // StatusBar 颜色,默认蓝色。
.navigationBarColor(navigationBarColor) // NavigationBar 颜色,默认黑色,建议使用默认。

.selectCount(9) // 最多选择几张图片。
.columnCount(2) // 相册展示列数,默认是2列。
.camera(true) // 是否有拍照功能。
.checkedList(mImageList) // 已经选择过得图片,相册会自动选中选过的图片,并计数。
.start();
```

重写`onActivityResult()`方法,接受图片选择结果:
```java
ArrayList<String> mImageList;

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(requestCode == 999) {
if (resultCode == RESULT_OK) { // Successfully.
// 不要质疑你的眼睛,就是这么简单。
mImageList = Album.parseResult(data);
} else if (resultCode == RESULT_CANCELED) { // User canceled.
// 用户取消了操作。
}
}
}
```

## Galleryhuala
使用`Album.album(this).start()`即可调起画廊,画廊只支持预览本地图片,你只需要传入一个图片集合:
```java
Album.gallery(this)
.requestCode(666) // 请求码,返回时onActivityResult()的第一个参数。
.toolBarColor(toolbarColor) // Toolbar 颜色,默认蓝色。
.statusBarColor(statusBarColor) // StatusBar 颜色,默认蓝色。
.navigationBarColor(navigationBarColor) // NavigationBar 颜色,默认黑色,建议使用默认。

.checkedList(mImageList) // 要预览的图片list。
.currentPosition(position) // 预览的时候要显示list中的图片的index。
.checkFunction(true) // 预览时是否有反选功能。
.start();
```
**注意:**

* 一定要传入要预览的图片集合,否则启动会立即返回。
* 调用画廊预览时判断`if(currentPosition < mImageList.size())`,这样才能保证传入的`position``list`中,否则会立即返回。

如果你需要预览时的反选功能,那么重写`onActivityResult()`方法,接受反选后的图片`List`结果:
```java
ArrayList<String> mImageList;

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(requestCode == 666) {
if (resultCode == RESULT_OK) { // Successfully.
// 不要再次质疑你的眼睛,还是这么简单。
mImageList = Album.parseResult(data);
} else if (resultCode == RESULT_CANCELED) { // User canceled.
// 用户取消了操作。
}
}
}
```

# 混淆
`Album`是完全可以混淆的,如果混淆后相册出现了问题,请在混淆规则中添加:
```txt
-dontwarn com.yanzhenjie.album.**
-keep class com.yanzhenjie.album.**{*;}
```

# Thanks
1. [PhotoView](https://github.com/chrisbanes/PhotoView)
2. [LoadingDrawable](https://github.com/dinuscxj/LoadingDrawable)

在此特别感谢上述项目及作者。

**关注我的微信公众号**
![公众号](./image/wechat.jpg)

# License
```text
Copyright 2017 Yan Zhenjie
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.
```
147 changes: 90 additions & 57 deletions README.md
@@ -1,111 +1,144 @@
# Album
1. Album是一个Android开源相册,支持单/多选、缩放、预览、按文件夹查看图片,二期会考虑加入图片剪切等操作,这个功能将是非必选的。
`Album` is an MaterialDesign tyle open source album, the main function is: `Album and Gallery`.

2. 开发者不需要担心`Android6.0`的运行时权限,`Album`已经非常完善的处理过了。
Image upload recommended NoHttp:[NoHttp Open source address](https://github.com/yanzhenjie/NoHttp).

3. 支持自定义样式风格,比如Toolbar颜色、状态栏颜色等。
[中文文档](./README-CN.md)

4. 内置支持了相机,开发者不用担心相机的使用问题,Album自动搞定。
# Features
1. Support component:`Activity``Fragment`.
2. UI style can be configured, for example: `Toolbar``StatusBar``NavigationBar`.
3. Radio, multi-select, folder preview, gallery, gallery zoom.
4. Support setting album number.
5. Support for configuring whether to use the camera.
6. Gallery preview multiple pictures, preview can be anti-election.

5. 支持`Activity``Fragment`调用。
# Screenshot
Please experience [download apk](https://github.com/yanzhenjie/Album/blob/master/sample-release.apk?raw=true).
<image src="./image/1.gif" width="170px"/> <image src="./image/2.gif" width="170px"/> <image src="./image/3.gif" width="170px"/> <image src="./image/4.gif" width="170px"/>

技术交流群:[46523908](http://jq.qq.com/?_wv=1027&k=410oIg0)
图片上传推荐使用NoHttp:[NoHttp源码](https://github.com/yanzhenjie/NoHttp)[NoHttp详细使用文档](http://doc.nohttp.net)

# Demo效果预览
<image src="https://github.com/yanzhenjie/album/blob/master/image/1.gif?raw=true" width="250px"/> <image src="https://github.com/yanzhenjie/album/blob/master/image/2.gif?raw=true" width="250px"/>
<image src="https://github.com/yanzhenjie/album/blob/master/image/3.gif?raw=true" width="250px"/> <image src="https://github.com/yanzhenjie/album/blob/master/image/4.gif?raw=true" width="250px"/>

如果你想体验一把,你可以[下载demo的apk](https://github.com/yanzhenjie/album/blob/master/sample-release.apk?raw=true)来玩玩。

# 使用方法
Gradle:
# Dependencies
* Gradle:
```groovy
compile 'com.yanzhenjie:album:1.0.0'
compile 'com.yanzhenjie:album:1.0.1'
```
Or Maven:

* Maven:
```xml
<dependency>
<groupId>com.yanzhenjie</groupId>
<artifactId>album</artifactId>
<version>1.0.0</version>
<version>1.0.1</version>
<type>pom</type>
</dependency>
```
Eclipse请下载源码自行转换成Library project。

# mainifest.xml中需要注册
# Register in mainifest.xml
```xml
<activity
android:name="com.yanzhenjie.album.AlbumActivity"
android:label="图库"
android:configChanges="orientation|keyboardHidden|screenSize"
android:theme="@style/Theme.AppCompat.Light.NoActionBar"
android:windowSoftInputMode="stateAlwaysHidden|stateHidden" />
```
其中`android:label="xx"`中的xx是调起的`Activity`的标题,你可以自定义,其它请照抄即可。

# 需要的权限
# Permission
```xml
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
```
开发者不需要担心`Android6.0`的运行时权限,`Album`已经非常完善的处理过了。

# 如何调用
调起Album的界面:
* Developers do not need to worry about `Android6.0` runtime permissions,`Album` has been very well handled.
* In addition `Android6.0` runtime permissions recommended: [AndPermission](https://github.com/yanzhenjie/AndPermission).

# Usage
Album's main function is: `Album and Gallery`, the following are described separately.

## Album
Use `Album.album(this).start()` to call up the album.
```java
// 1. 使用默认风格,并指定选择数量:
// 第一个参数Activity/Fragment; 第二个request_code; 第三个允许选择照片的数量,不填可以无限选择。
// Album.startAlbum(this, ACTIVITY_REQUEST_SELECT_PHOTO, 9);

// 2. 使用默认风格,不指定选择数量:
// Album.startAlbum(this, ACTIVITY_REQUEST_SELECT_PHOTO); // 第三个参数不填的话,可以选择无数个。

// 3. 指定风格,并指定选择数量,如果不想限制数量传入Integer.MAX_VALUE;
Album.startAlbum(this, ACTIVITY_REQUEST_SELECT_PHOTO
, 9 // 指定选择数量。
, ContextCompat.getColor(this, R.color.colorPrimary) // 指定Toolbar的颜色。
, ContextCompat.getColor(this, R.color.colorPrimaryDark)); // 指定状态栏的颜色。
Album.album(this)
.requestCode(999) // Request code.
.toolBarColor(toolbarColor) // Toolbar color.
.statusBarColor(statusBarColor) // StatusBar color.
.navigationBarColor(navigationBarColor) // NavigationBar color.

.selectCount(9) // Choose up to a few pictures.
.columnCount(2) // Number of albums.
.camera(true) // Have a camera function.
.checkedList(mImageList) // Has selected the picture, automatically select.
.start();
```

重写`Activity/Fragment``onActivityResult()`方法:
Accept the result:
```java
ArrayList<String> mImageList;

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 100) {
if (resultCode == RESULT_OK) { // 判断是否成功。
// 拿到用户选择的图片路径List:
List<String> pathList = Album.parseResult(data);
} else if (resultCode == RESULT_CANCELED) { // 用户取消选择。
// 根据需要提示用户取消了选择。
if(requestCode == 999) {
if (resultCode == RESULT_OK) { // Successfully.
// Parse select result.
mImageList = Album.parseResult(data);
} else if (resultCode == RESULT_CANCELED) {
// User canceled.
}
}
}
```

# 注意点
由于支持了MaterialDesign,项目中已经引用了Google官方的的support库:
```groovy
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.android.support:recyclerview-v7:24.2.1'
compile 'com.android.support:design:24.2.1'
## Gallery
Use the `Album.album(this).start ()` to call up the gallery.
```java
Album.gallery(this)
.requestCode(999) // Request code.
.toolBarColor(toolbarColor) // Toolbar color.
.statusBarColor(statusBarColor) // StatusBar color.
.navigationBarColor(navigationBarColor) // NavigationBar color.

.checkedList(mImageList) // List of pictures to preview.
.currentPosition(position) // First display position image of the list.
.checkFunction(true) // Anti-election function.
.start();
```

# 混淆
都是可以混淆的,如果混淆遇到问题了,请添加如下规则。
**Note:**

* Be sure to pass in the collection of pictures you want to preview, otherwise it will return immediately after the start.
* It is recommended to call the gallery preview to judge `if(currentPosition < mImageList.size())`, to ensure that the entry of the `position` in the `list`.

If you need to have an anti-selection function at the time of preview,override the `onActivityResult ()` method, after receiving the anti-selected picture `List` result:
```java
ArrayList<String> mImageList;

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(requestCode == 666) {
if (resultCode == RESULT_OK) { // Successfully.
// Parse select result.
mImageList = Album.parseResult(data);
} else if (resultCode == RESULT_CANCELED) {
// User canceled.
}
}
}
```

# Proguard-rules
If there is a problem, add the rule to the proguard-rules:
```txt
-dontwarn com.yanzhenjie.album.**
-keep class com.yanzhenjie.album.**{*;}
```

# Thanks
项目中的缩放是用的[PhotoView](https://github.com/chrisbanes/PhotoView),特别感谢作者的付出。
1. [PhotoView](https://github.com/chrisbanes/PhotoView)
2. [LoadingDrawable](https://github.com/dinuscxj/LoadingDrawable)

# License
```text
Copyright 2016 Yan Zhenjie
Copyright 2017 Yan Zhenjie
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -118,4 +151,4 @@ 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.
```
```

0 comments on commit aed5262

Please sign in to comment.