├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── dimens.xml
│ │ │ │ ├── colors.xml
│ │ │ │ └── styles.xml
│ │ │ ├── mipmap-hdpi
│ │ │ │ ├── find_add_img.png
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── values-w820dp
│ │ │ │ └── dimens.xml
│ │ │ ├── drawable
│ │ │ │ └── border_red_roval_sign.xml
│ │ │ └── layout
│ │ │ │ ├── item.xml
│ │ │ │ └── activity_main.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── com
│ │ │ └── zq
│ │ │ └── weixinselectpicture
│ │ │ └── MainActivity.java
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── zq
│ │ │ └── weixinselectpicture
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── zq
│ │ └── weixinselectpicture
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
└── build.gradle
├── pictureselector
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ ├── asv.png
│ │ │ │ ├── asy.png
│ │ │ │ ├── btn_selected.png
│ │ │ │ ├── default_check.png
│ │ │ │ ├── default_error.png
│ │ │ │ ├── btn_unselected.png
│ │ │ │ └── ic_action_discard.png
│ │ │ ├── mipmap-hdpi
│ │ │ │ └── ic_action_discard.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ └── ic_action_discard.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ ├── ic_action_discard.png
│ │ │ │ ├── text_indicator_normal.png
│ │ │ │ └── text_indicator_pressed.png
│ │ │ ├── values
│ │ │ │ ├── colors.xml
│ │ │ │ ├── dimens.xml
│ │ │ │ └── strings.xml
│ │ │ ├── drawable
│ │ │ │ └── text_indicator.xml
│ │ │ ├── menu
│ │ │ │ ├── menu_picker.xml
│ │ │ │ └── menu_preview.xml
│ │ │ ├── layout
│ │ │ │ ├── item_preview.xml
│ │ │ │ ├── activity_image_preview.xml
│ │ │ │ ├── photopicker_toolbar.xml
│ │ │ │ ├── item_camera.xml
│ │ │ │ ├── item_select_image.xml
│ │ │ │ ├── activity_photopicker.xml
│ │ │ │ └── item_folder.xml
│ │ │ └── color
│ │ │ │ └── action_text_color.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── com
│ │ │ └── lidong
│ │ │ └── photopicker
│ │ │ ├── SelectModel.java
│ │ │ ├── Folder.java
│ │ │ ├── Image.java
│ │ │ ├── intent
│ │ │ ├── PhotoPreviewIntent.java
│ │ │ └── PhotoPickerIntent.java
│ │ │ ├── widget
│ │ │ └── ViewPagerFixed.java
│ │ │ ├── ImageConfig.java
│ │ │ ├── PhotoPagerAdapter.java
│ │ │ ├── ImageCaptureManager.java
│ │ │ ├── FolderAdapter.java
│ │ │ ├── PhotoPreviewActivity.java
│ │ │ ├── ImageGridAdapter.java
│ │ │ └── PhotoPickerActivity.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── lidong
│ │ └── photopicker
│ │ └── ApplicationTest.java
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── .idea
├── copyright
│ └── profiles_settings.xml
├── encodings.xml
├── vcs.xml
├── modules.xml
├── runConfigurations.xml
├── compiler.xml
├── gradle.xml
└── misc.xml
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitignore
├── README.md
├── gradle.properties
├── gradlew.bat
└── gradlew
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/pictureselector/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':pictureselector'
2 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | 仿微信选择图片
3 |
4 |
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DickyQie/android-advanced-effect/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/find_add_img.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DickyQie/android-advanced-effect/HEAD/app/src/main/res/mipmap-hdpi/find_add_img.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DickyQie/android-advanced-effect/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DickyQie/android-advanced-effect/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DickyQie/android-advanced-effect/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DickyQie/android-advanced-effect/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DickyQie/android-advanced-effect/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/pictureselector/src/main/res/mipmap-xxhdpi/asv.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DickyQie/android-advanced-effect/HEAD/pictureselector/src/main/res/mipmap-xxhdpi/asv.png
--------------------------------------------------------------------------------
/pictureselector/src/main/res/mipmap-xxhdpi/asy.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DickyQie/android-advanced-effect/HEAD/pictureselector/src/main/res/mipmap-xxhdpi/asy.png
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 | .externalNativeBuild
10 |
--------------------------------------------------------------------------------
/pictureselector/src/main/res/mipmap-xxhdpi/btn_selected.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DickyQie/android-advanced-effect/HEAD/pictureselector/src/main/res/mipmap-xxhdpi/btn_selected.png
--------------------------------------------------------------------------------
/pictureselector/src/main/res/mipmap-xxhdpi/default_check.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DickyQie/android-advanced-effect/HEAD/pictureselector/src/main/res/mipmap-xxhdpi/default_check.png
--------------------------------------------------------------------------------
/pictureselector/src/main/res/mipmap-xxhdpi/default_error.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DickyQie/android-advanced-effect/HEAD/pictureselector/src/main/res/mipmap-xxhdpi/default_error.png
--------------------------------------------------------------------------------
/pictureselector/src/main/res/mipmap-hdpi/ic_action_discard.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DickyQie/android-advanced-effect/HEAD/pictureselector/src/main/res/mipmap-hdpi/ic_action_discard.png
--------------------------------------------------------------------------------
/pictureselector/src/main/res/mipmap-mdpi/ic_action_discard.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DickyQie/android-advanced-effect/HEAD/pictureselector/src/main/res/mipmap-mdpi/ic_action_discard.png
--------------------------------------------------------------------------------
/pictureselector/src/main/res/mipmap-xxhdpi/btn_unselected.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DickyQie/android-advanced-effect/HEAD/pictureselector/src/main/res/mipmap-xxhdpi/btn_unselected.png
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/pictureselector/src/main/res/mipmap-xhdpi/ic_action_discard.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DickyQie/android-advanced-effect/HEAD/pictureselector/src/main/res/mipmap-xhdpi/ic_action_discard.png
--------------------------------------------------------------------------------
/pictureselector/src/main/res/mipmap-xxhdpi/ic_action_discard.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DickyQie/android-advanced-effect/HEAD/pictureselector/src/main/res/mipmap-xxhdpi/ic_action_discard.png
--------------------------------------------------------------------------------
/pictureselector/src/main/res/mipmap-xhdpi/text_indicator_normal.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DickyQie/android-advanced-effect/HEAD/pictureselector/src/main/res/mipmap-xhdpi/text_indicator_normal.png
--------------------------------------------------------------------------------
/pictureselector/src/main/res/mipmap-xhdpi/text_indicator_pressed.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DickyQie/android-advanced-effect/HEAD/pictureselector/src/main/res/mipmap-xhdpi/text_indicator_pressed.png
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/pictureselector/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Dec 28 10:00:20 PST 2015
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
7 |
--------------------------------------------------------------------------------
/pictureselector/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #cfcfcf
4 | #353535
5 | #818585
6 |
--------------------------------------------------------------------------------
/pictureselector/src/main/res/drawable/text_indicator.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ## Android之仿微信发朋友圈图片选择功能
2 |
最近项目中需要用到发表评论选择多张图片和拍照的功能,于是就仿照微信发表朋友圈的选择图片和拍照做了一个这样的案例,经过查找资料终于完成了此功能,
3 | 最近有时间就写出来和大家分享一下,希望对大家有所帮助。
4 | 效果如下图:
5 | 
6 |
7 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/pictureselector/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 10dp
4 | 72dp
5 | 120dp
6 | 5dp
7 | 16sp
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/border_red_roval_sign.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
8 | #181819
9 |
10 | #2988CC
11 | #6c6c6c
12 |
13 |
--------------------------------------------------------------------------------
/pictureselector/src/androidTest/java/com/lidong/photopicker/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.lidong.photopicker;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/pictureselector/src/main/res/menu/menu_picker.xml:
--------------------------------------------------------------------------------
1 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/com/zq/weixinselectpicture/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.zq.weixinselectpicture;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/pictureselector/src/main/java/com/lidong/photopicker/SelectModel.java:
--------------------------------------------------------------------------------
1 | package com.lidong.photopicker;
2 |
3 | /**
4 | * 照片选择类型
5 | * Created by foamtrace on 2015/8/25.
6 | */
7 | public enum SelectModel {
8 | SINGLE(PhotoPickerActivity.MODE_SINGLE),
9 | MULTI(PhotoPickerActivity.MODE_MULTI);
10 |
11 | private int model;
12 |
13 | SelectModel(int model) {
14 | this.model = model;
15 | }
16 |
17 | @Override
18 | public String toString() {
19 | return String.valueOf(this.model);
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/pictureselector/src/main/res/menu/menu_preview.xml:
--------------------------------------------------------------------------------
1 |
14 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
--------------------------------------------------------------------------------
/pictureselector/src/main/res/layout/item_preview.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
14 |
15 |
--------------------------------------------------------------------------------
/pictureselector/src/main/java/com/lidong/photopicker/Folder.java:
--------------------------------------------------------------------------------
1 | package com.lidong.photopicker;
2 |
3 | import java.util.List;
4 |
5 | /**
6 | * 文件夹
7 | */
8 | public class Folder {
9 | public String name;
10 | public String path;
11 | public Image cover;
12 | public List images;
13 |
14 | @Override
15 | public boolean equals(Object o) {
16 | try {
17 | Folder other = (Folder) o;
18 | return this.path.equalsIgnoreCase(other.path);
19 | }catch (ClassCastException e){
20 | e.printStackTrace();
21 | }
22 | return super.equals(o);
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/pictureselector/src/main/res/color/action_text_color.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/pictureselector/src/main/res/layout/activity_image_preview.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
10 |
11 |
15 |
16 |
--------------------------------------------------------------------------------
/pictureselector/src/main/res/layout/photopicker_toolbar.xml:
--------------------------------------------------------------------------------
1 |
2 |
13 |
14 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in D:\Android\SDK/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/pictureselector/src/main/java/com/lidong/photopicker/Image.java:
--------------------------------------------------------------------------------
1 | package com.lidong.photopicker;
2 |
3 | /**
4 | * 图片实体
5 | */
6 | public class Image {
7 | public String path;
8 | public String name;
9 | public long time;
10 |
11 | public Image(String path, String name, long time){
12 | this.path = path;
13 | this.name = name;
14 | this.time = time;
15 | }
16 |
17 | @Override
18 | public boolean equals(Object o) {
19 | try {
20 | Image other = (Image) o;
21 | return this.path.equalsIgnoreCase(other.path);
22 | }catch (ClassCastException e){
23 | e.printStackTrace();
24 | }
25 | return super.equals(o);
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/pictureselector/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in D:\DevSofrware\Android\sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/pictureselector/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | 图片
3 | 所有图片
4 | 预览
5 | 无法启用系统相机
6 | 已经达到最高选择数量
7 | 完成
8 | 完成(%1$d/%2$d)
9 | %1$d/%2$d
10 | 删除
11 | 删除了一张图片
12 | 确认删除?
13 | 确定
14 | 取消
15 | 撤消
16 |
17 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/pictureselector/src/main/res/layout/item_camera.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
18 |
19 |
--------------------------------------------------------------------------------
/pictureselector/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 |
4 |
5 | android {
6 | compileSdkVersion 22
7 | buildToolsVersion "22.0.1"
8 |
9 | defaultConfig {
10 | minSdkVersion 15
11 | targetSdkVersion 22
12 | versionCode 1
13 | versionName "1.0"
14 | }
15 | buildTypes {
16 | release {
17 | minifyEnabled false
18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
19 | }
20 | }
21 | }
22 |
23 | dependencies {
24 | compile fileTree(dir: 'libs', include: ['*.jar'])
25 | compile 'com.android.support:appcompat-v7:22.+'
26 | compile 'com.android.support:design:22.+'
27 | compile 'com.github.bumptech.glide:glide:3.7.0'
28 | compile 'com.github.chrisbanes.photoview:library:+'
29 | }
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/zq/weixinselectpicture/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.zq.weixinselectpicture;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.zq.weixinselectpicture", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/pictureselector/src/main/java/com/lidong/photopicker/intent/PhotoPreviewIntent.java:
--------------------------------------------------------------------------------
1 | package com.lidong.photopicker.intent;
2 |
3 | import android.content.Context;
4 | import android.content.Intent;
5 |
6 | import com.lidong.photopicker.PhotoPreviewActivity;
7 |
8 | import java.util.ArrayList;
9 |
10 | /**
11 | * 预览照片
12 | */
13 | public class PhotoPreviewIntent extends Intent{
14 |
15 | public PhotoPreviewIntent(Context packageContext) {
16 | super(packageContext, PhotoPreviewActivity.class);
17 | }
18 |
19 | /**
20 | * 照片地址
21 | * @param paths
22 | */
23 | public void setPhotoPaths(ArrayList paths){
24 | this.putStringArrayListExtra(PhotoPreviewActivity.EXTRA_PHOTOS, paths);
25 | }
26 |
27 | /**
28 | * 当前照片的下标
29 | * @param currentItem
30 | */
31 | public void setCurrentItem(int currentItem){
32 | this.putExtra(PhotoPreviewActivity.EXTRA_CURRENT_ITEM, currentItem);
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 22
5 | buildToolsVersion '22.0.1'
6 | defaultConfig {
7 | applicationId "com.zq.weixinselectpicture"
8 | minSdkVersion 15
9 | targetSdkVersion 22
10 | versionCode 1
11 | versionName "1.0"
12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(include: ['*.jar'], dir: 'libs')
24 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
25 | exclude group: 'com.android.support', module: 'support-annotations'
26 | })
27 | compile 'com.android.support:appcompat-v7:22.2.1'
28 | testCompile 'junit:junit:4.12'
29 | compile project(':pictureselector')
30 | }
31 |
--------------------------------------------------------------------------------
/pictureselector/src/main/java/com/lidong/photopicker/widget/ViewPagerFixed.java:
--------------------------------------------------------------------------------
1 | package com.lidong.photopicker.widget;
2 |
3 | import android.content.Context;
4 | import android.support.v4.view.ViewPager;
5 | import android.util.AttributeSet;
6 | import android.view.MotionEvent;
7 |
8 | /**
9 | * 修复图片在ViewPager控件中缩放报错的BUG
10 | */
11 | public class ViewPagerFixed extends ViewPager {
12 |
13 | public ViewPagerFixed(Context context) {
14 | super(context);
15 | }
16 |
17 | public ViewPagerFixed(Context context, AttributeSet attrs) {
18 | super(context, attrs);
19 | }
20 |
21 | @Override
22 | public boolean onTouchEvent(MotionEvent ev) {
23 | try {
24 | return super.onTouchEvent(ev);
25 | } catch (IllegalArgumentException ex) {
26 | ex.printStackTrace();
27 | }
28 | return false;
29 | }
30 |
31 | @Override
32 | public boolean onInterceptTouchEvent(MotionEvent ev) {
33 | try {
34 | return super.onInterceptTouchEvent(ev);
35 | } catch (IllegalArgumentException ex) {
36 | ex.printStackTrace();
37 | }
38 | return false;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/pictureselector/src/main/res/layout/item_select_image.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
13 |
14 |
20 |
21 |
29 |
30 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
23 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
16 |
17 |
19 |
20 |
22 |
23 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/pictureselector/src/main/java/com/lidong/photopicker/ImageConfig.java:
--------------------------------------------------------------------------------
1 | package com.lidong.photopicker;
2 |
3 | import android.os.Parcel;
4 | import android.os.Parcelable;
5 |
6 | /**
7 | * 读取手机照片的限制参数
8 | */
9 | public class ImageConfig implements Parcelable {
10 |
11 | // 图片最小宽度
12 | public int minWidth;
13 | // 图片最小高度
14 | public int minHeight;
15 | // 图片大小,单位字节
16 | public long minSize;
17 | // 照片类型: 例如 { image/jpeg, image/png, ... }
18 | public String[] mimeType;
19 |
20 | @Override
21 | public int describeContents() {
22 | return 0;
23 | }
24 |
25 | @Override
26 | public void writeToParcel(Parcel dest, int flags) {
27 | dest.writeInt(this.minWidth);
28 | dest.writeInt(this.minHeight);
29 | dest.writeLong(this.minSize);
30 | dest.writeStringArray(this.mimeType);
31 | }
32 |
33 | public ImageConfig() {
34 | }
35 |
36 | protected ImageConfig(Parcel in) {
37 | this.minWidth = in.readInt();
38 | this.minHeight = in.readInt();
39 | this.minSize = in.readLong();
40 | this.mimeType = in.createStringArray();
41 | }
42 |
43 | public static final Creator CREATOR = new Creator() {
44 | public ImageConfig createFromParcel(Parcel source) {
45 | return new ImageConfig(source);
46 | }
47 |
48 | public ImageConfig[] newArray(int size) {
49 | return new ImageConfig[size];
50 | }
51 | };
52 | }
53 |
--------------------------------------------------------------------------------
/pictureselector/src/main/java/com/lidong/photopicker/intent/PhotoPickerIntent.java:
--------------------------------------------------------------------------------
1 | package com.lidong.photopicker.intent;
2 |
3 | import android.content.Context;
4 | import android.content.Intent;
5 |
6 | import com.lidong.photopicker.ImageConfig;
7 | import com.lidong.photopicker.PhotoPickerActivity;
8 | import com.lidong.photopicker.SelectModel;
9 |
10 | import java.util.ArrayList;
11 |
12 | /**
13 | * 选择照片
14 | */
15 | public class PhotoPickerIntent extends Intent{
16 |
17 | public PhotoPickerIntent(Context packageContext) {
18 | super(packageContext, PhotoPickerActivity.class);
19 | }
20 |
21 | public void setShowCarema(boolean bool){
22 | this.putExtra(PhotoPickerActivity.EXTRA_SHOW_CAMERA, bool);
23 | }
24 |
25 | public void setMaxTotal(int total){
26 | this.putExtra(PhotoPickerActivity.EXTRA_SELECT_COUNT, total);
27 | }
28 |
29 | /**
30 | * 选择
31 | * @param model
32 | */
33 | public void setSelectModel(SelectModel model){
34 | this.putExtra(PhotoPickerActivity.EXTRA_SELECT_MODE, Integer.parseInt(model.toString()));
35 | }
36 |
37 | /**
38 | * 已选择的照片地址
39 | * @param imagePathis
40 | */
41 | public void setSelectedPaths(ArrayList imagePathis){
42 | this.putStringArrayListExtra(PhotoPickerActivity.EXTRA_DEFAULT_SELECTED_LIST, imagePathis);
43 | }
44 |
45 | /**
46 | * 显示相册图片的属性
47 | * @param config
48 | */
49 | public void setImageConfig(ImageConfig config){
50 | this.putExtra(PhotoPickerActivity.EXTRA_IMAGE_CONFIG, config);
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
20 |
27 |
28 |
34 |
46 |
47 |
--------------------------------------------------------------------------------
/pictureselector/src/main/res/layout/activity_photopicker.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
10 |
20 |
21 |
28 |
29 |
41 |
42 |
55 |
56 |
57 |
--------------------------------------------------------------------------------
/pictureselector/src/main/res/layout/item_folder.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
21 |
22 |
31 |
32 |
39 |
40 |
49 |
50 |
51 |
52 |
62 |
63 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/pictureselector/src/main/java/com/lidong/photopicker/PhotoPagerAdapter.java:
--------------------------------------------------------------------------------
1 | package com.lidong.photopicker;
2 |
3 | import android.content.Context;
4 | import android.net.Uri;
5 | import android.support.v4.view.PagerAdapter;
6 | import android.view.LayoutInflater;
7 | import android.view.View;
8 | import android.view.ViewGroup;
9 |
10 | import com.bumptech.glide.Glide;
11 |
12 | import java.io.File;
13 | import java.util.ArrayList;
14 | import java.util.List;
15 |
16 | import uk.co.senab.photoview.PhotoView;
17 | import uk.co.senab.photoview.PhotoViewAttacher;
18 |
19 | public class PhotoPagerAdapter extends PagerAdapter {
20 |
21 | public interface PhotoViewClickListener{
22 | void OnPhotoTapListener(View view, float v, float v1);
23 | }
24 |
25 | public PhotoViewClickListener listener;
26 |
27 | private List paths = new ArrayList<>();
28 | private Context mContext;
29 | private LayoutInflater mLayoutInflater;
30 |
31 |
32 | public PhotoPagerAdapter(Context mContext, List paths) {
33 | this.mContext = mContext;
34 | this.paths = paths;
35 | mLayoutInflater = LayoutInflater.from(mContext);
36 | }
37 |
38 | public void setPhotoViewClickListener(PhotoViewClickListener listener){
39 | this.listener = listener;
40 | }
41 |
42 | @Override public Object instantiateItem(ViewGroup container, int position) {
43 |
44 | View itemView = mLayoutInflater.inflate(R.layout.item_preview, container, false);
45 |
46 | PhotoView imageView = (PhotoView) itemView.findViewById(R.id.iv_pager);
47 |
48 | final String path = paths.get(position);
49 | final Uri uri;
50 | if (path.startsWith("http")) {
51 | uri = Uri.parse(path);
52 | } else {
53 | uri = Uri.fromFile(new File(path));
54 | }
55 | Glide.with(mContext)
56 | .load(uri)
57 | // .placeholder(R.mipmap.default_error)
58 | .error(R.mipmap.default_error)
59 | .crossFade()
60 | .into(imageView);
61 |
62 | imageView.setOnPhotoTapListener(new PhotoViewAttacher.OnPhotoTapListener() {
63 | @Override
64 | public void onPhotoTap(View view, float v, float v1) {
65 | if(listener != null){
66 | listener.OnPhotoTapListener(view, v, v1);
67 | }
68 | }
69 | });
70 |
71 | container.addView(itemView);
72 |
73 | return itemView;
74 | }
75 |
76 |
77 | @Override public int getCount() {
78 | return paths.size();
79 | }
80 |
81 |
82 | @Override public boolean isViewFromObject(View view, Object object) {
83 | return view == object;
84 | }
85 |
86 |
87 | @Override
88 | public void destroyItem(ViewGroup container, int position, Object object) {
89 | container.removeView((View) object);
90 | }
91 |
92 | @Override
93 | public int getItemPosition (Object object) { return POSITION_NONE; }
94 |
95 | }
96 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 | 1.8
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
--------------------------------------------------------------------------------
/pictureselector/src/main/java/com/lidong/photopicker/ImageCaptureManager.java:
--------------------------------------------------------------------------------
1 | package com.lidong.photopicker;
2 |
3 | import android.content.Context;
4 | import android.content.Intent;
5 | import android.net.Uri;
6 | import android.os.Bundle;
7 | import android.os.Environment;
8 | import android.provider.MediaStore;
9 |
10 | import java.io.File;
11 | import java.io.IOException;
12 | import java.text.SimpleDateFormat;
13 | import java.util.Date;
14 |
15 | /**
16 | * Created by donglua on 15/6/23.
17 | */
18 | public class ImageCaptureManager {
19 |
20 | private final static String CAPTURED_PHOTO_PATH_KEY = "mCurrentPhotoPath";
21 | public static final int REQUEST_TAKE_PHOTO = 1;
22 |
23 | private String mCurrentPhotoPath;
24 | private Context mContext;
25 |
26 | public ImageCaptureManager(Context mContext) {
27 | this.mContext = mContext;
28 | }
29 |
30 | private File createImageFile() throws IOException {
31 |
32 | // Create an image file name
33 | String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
34 | String imageFileName = "JPEG_" + timeStamp + "_";
35 | File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
36 | if (!storageDir.exists()) {
37 | if (!storageDir.mkdir()) {
38 | throw new IOException();
39 | }
40 | }
41 | File image = new File(storageDir, imageFileName + ".jpg");
42 | // Save a file: path for use with ACTION_VIEW intents
43 | mCurrentPhotoPath = image.getAbsolutePath();
44 | return image;
45 | }
46 |
47 |
48 | public Intent dispatchTakePictureIntent() throws IOException {
49 | Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
50 | // Ensure that there's a camera activity to handle the intent
51 | if (takePictureIntent.resolveActivity(mContext.getPackageManager()) != null) {
52 | // Create the File where the photo should go
53 | File photoFile = createImageFile();
54 | // Continue only if the File was successfully created
55 | if (photoFile != null) {
56 | takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,
57 | Uri.fromFile(photoFile));
58 | }
59 | }
60 | return takePictureIntent;
61 | }
62 |
63 |
64 | public void galleryAddPic() {
65 | Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
66 | File f = new File(mCurrentPhotoPath);
67 | Uri contentUri = Uri.fromFile(f);
68 | mediaScanIntent.setData(contentUri);
69 | mContext.sendBroadcast(mediaScanIntent);
70 | }
71 |
72 |
73 | public String getCurrentPhotoPath() {
74 | return mCurrentPhotoPath;
75 | }
76 |
77 | public void onSaveInstanceState(Bundle savedInstanceState) {
78 | if (savedInstanceState != null && mCurrentPhotoPath != null) {
79 | savedInstanceState.putString(CAPTURED_PHOTO_PATH_KEY, mCurrentPhotoPath);
80 | }
81 | }
82 |
83 | public void onRestoreInstanceState(Bundle savedInstanceState) {
84 | if (savedInstanceState != null && savedInstanceState.containsKey(CAPTURED_PHOTO_PATH_KEY)) {
85 | mCurrentPhotoPath = savedInstanceState.getString(CAPTURED_PHOTO_PATH_KEY);
86 | }
87 | }
88 |
89 | }
90 |
--------------------------------------------------------------------------------
/pictureselector/src/main/java/com/lidong/photopicker/FolderAdapter.java:
--------------------------------------------------------------------------------
1 | package com.lidong.photopicker;
2 |
3 | import android.content.Context;
4 | import android.view.LayoutInflater;
5 | import android.view.View;
6 | import android.view.ViewGroup;
7 | import android.widget.BaseAdapter;
8 | import android.widget.ImageView;
9 | import android.widget.TextView;
10 |
11 | import com.bumptech.glide.Glide;
12 |
13 | import java.io.File;
14 | import java.util.ArrayList;
15 | import java.util.List;
16 |
17 | /**
18 | * 文件夹Adapter
19 | */
20 | public class FolderAdapter extends BaseAdapter {
21 |
22 | private Context mContext;
23 | private LayoutInflater mInflater;
24 |
25 | private List mFolders = new ArrayList<>();
26 |
27 | int mImageSize;
28 |
29 | int lastSelected = 0;
30 |
31 | public FolderAdapter(Context context){
32 | mContext = context;
33 | mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
34 | mImageSize = mContext.getResources().getDimensionPixelOffset(R.dimen.folder_cover_size);
35 | }
36 |
37 | /**
38 | * 设置数据集
39 | * @param folders
40 | */
41 | public void setData(List folders) {
42 | if(folders != null && folders.size()>0){
43 | mFolders = folders;
44 | }else{
45 | mFolders.clear();
46 | }
47 | notifyDataSetChanged();
48 | }
49 |
50 | @Override
51 | public int getCount() {
52 | return mFolders.size()+1;
53 | }
54 |
55 | @Override
56 | public Folder getItem(int i) {
57 | if(i == 0) return null;
58 | return mFolders.get(i-1);
59 | }
60 |
61 | @Override
62 | public long getItemId(int i) {
63 | return i;
64 | }
65 |
66 | @Override
67 | public View getView(int i, View view, ViewGroup viewGroup) {
68 | ViewHolder holder;
69 | if(view == null){
70 | view = mInflater.inflate(R.layout.item_folder, viewGroup, false);
71 | holder = new ViewHolder(view);
72 | }else{
73 | holder = (ViewHolder) view.getTag();
74 | }
75 | if (holder != null) {
76 | if(i == 0){
77 | holder.name.setText(mContext.getResources().getString(R.string.all_image));
78 | holder.size.setText(getTotalImageSize() + "张");
79 | if(mFolders.size()>0){
80 | Folder f = mFolders.get(0);
81 |
82 | Glide.with(mContext)
83 | .load(new File(f.cover.path))
84 | .error(R.mipmap.default_error)
85 | .override(mImageSize, mImageSize)
86 | .centerCrop()
87 | .into(holder.cover);
88 | }
89 | }else {
90 | holder.bindData(getItem(i));
91 | }
92 | if(lastSelected == i){
93 | holder.indicator.setVisibility(View.VISIBLE);
94 | }else{
95 | holder.indicator.setVisibility(View.INVISIBLE);
96 | }
97 | }
98 | return view;
99 | }
100 |
101 | private int getTotalImageSize(){
102 | int result = 0;
103 | if(mFolders != null && mFolders.size()>0){
104 | for (Folder f: mFolders){
105 | result += f.images.size();
106 | }
107 | }
108 | return result;
109 | }
110 |
111 | public void setSelectIndex(int i) {
112 | if(lastSelected == i) return;
113 |
114 | lastSelected = i;
115 | notifyDataSetChanged();
116 | }
117 |
118 | public int getSelectIndex(){
119 | return lastSelected;
120 | }
121 |
122 | class ViewHolder{
123 | ImageView cover;
124 | TextView name;
125 | TextView size;
126 | ImageView indicator;
127 | ViewHolder(View view){
128 | cover = (ImageView)view.findViewById(R.id.cover);
129 | name = (TextView) view.findViewById(R.id.name);
130 | size = (TextView) view.findViewById(R.id.size);
131 | indicator = (ImageView) view.findViewById(R.id.indicator);
132 | view.setTag(this);
133 | }
134 |
135 | void bindData(Folder data) {
136 | name.setText(data.name);
137 | size.setText(data.images.size() + "张");
138 | // 显示图片
139 | Glide.with(mContext)
140 | .load(new File(data.cover.path))
141 | .placeholder(R.mipmap.default_error)
142 | .error(R.mipmap.default_error)
143 | .override(mImageSize, mImageSize)
144 | .centerCrop()
145 | .into(cover);
146 | }
147 | }
148 |
149 | }
150 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/pictureselector/src/main/java/com/lidong/photopicker/PhotoPreviewActivity.java:
--------------------------------------------------------------------------------
1 | package com.lidong.photopicker;
2 |
3 | import android.content.DialogInterface;
4 | import android.content.Intent;
5 | import android.os.Bundle;
6 | import android.support.design.widget.Snackbar;
7 | import android.support.v4.view.ViewPager;
8 | import android.support.v7.app.AlertDialog;
9 | import android.support.v7.app.AppCompatActivity;
10 | import android.support.v7.widget.Toolbar;
11 | import android.view.Menu;
12 | import android.view.MenuItem;
13 | import android.view.View;
14 |
15 | import com.lidong.photopicker.widget.ViewPagerFixed;
16 |
17 | import java.util.ArrayList;
18 |
19 | public class PhotoPreviewActivity extends AppCompatActivity implements PhotoPagerAdapter.PhotoViewClickListener{
20 |
21 | public static final String EXTRA_PHOTOS = "extra_photos";
22 | public static final String EXTRA_CURRENT_ITEM = "extra_current_item";
23 |
24 | /** 选择结果,返回为 ArrayList<String> 图片路径集合 */
25 | public static final String EXTRA_RESULT = "preview_result";
26 |
27 | /** 预览请求状态码 */
28 | public static final int REQUEST_PREVIEW = 99;
29 |
30 | private ArrayList paths;
31 | private ViewPagerFixed mViewPager;
32 | private PhotoPagerAdapter mPagerAdapter;
33 | private int currentItem = 0;
34 |
35 | @Override
36 | protected void onCreate(Bundle savedInstanceState) {
37 | super.onCreate(savedInstanceState);
38 |
39 | setContentView(R.layout.activity_image_preview);
40 |
41 | initViews();
42 |
43 | paths = new ArrayList<>();
44 | ArrayList pathArr = getIntent().getStringArrayListExtra(EXTRA_PHOTOS);
45 | if(pathArr != null){
46 | paths.addAll(pathArr);
47 | }
48 | paths.remove(pathArr.size()-1);
49 | currentItem = getIntent().getIntExtra(EXTRA_CURRENT_ITEM, 0);
50 |
51 | mPagerAdapter = new PhotoPagerAdapter(this, paths);
52 | mPagerAdapter.setPhotoViewClickListener(this);
53 | mViewPager.setAdapter(mPagerAdapter);
54 | mViewPager.setCurrentItem(currentItem);
55 | mViewPager.setOffscreenPageLimit(5);
56 |
57 | mViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
58 | @Override
59 | public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
60 | updateActionBarTitle();
61 | }
62 |
63 | @Override
64 | public void onPageSelected(int position) {
65 |
66 | }
67 |
68 | @Override
69 | public void onPageScrollStateChanged(int state) {
70 |
71 | }
72 | });
73 | updateActionBarTitle();
74 | }
75 |
76 | private void initViews(){
77 | mViewPager = (ViewPagerFixed) findViewById(R.id.vp_photos);
78 | Toolbar mToolbar = (Toolbar) findViewById(R.id.pickerToolbar);
79 | setSupportActionBar(mToolbar);
80 | getSupportActionBar().setDisplayHomeAsUpEnabled(true);
81 | }
82 |
83 | @Override
84 | public void OnPhotoTapListener(View view, float v, float v1) {
85 | onBackPressed();
86 | }
87 |
88 | public void updateActionBarTitle() {
89 | getSupportActionBar().setTitle(
90 | getString(R.string.image_index, mViewPager.getCurrentItem() + 1, paths.size()));
91 | }
92 |
93 | @Override
94 | public void onBackPressed() {
95 | Intent intent = new Intent();
96 | intent.putExtra(EXTRA_RESULT, paths);
97 | setResult(RESULT_OK, intent);
98 | finish();
99 | super.onBackPressed();
100 | }
101 |
102 | @Override
103 | public boolean onCreateOptionsMenu(Menu menu) {
104 | getMenuInflater().inflate(R.menu.menu_preview, menu);
105 | return true;
106 | }
107 |
108 | @Override
109 | public boolean onOptionsItemSelected(MenuItem item) {
110 |
111 | if(item.getItemId() == android.R.id.home){
112 | onBackPressed();
113 | return true;
114 | }
115 |
116 | // 删除当前照片
117 | if(item.getItemId() == R.id.action_discard){
118 | final int index = mViewPager.getCurrentItem();
119 | final String deletedPath = paths.get(index);
120 | Snackbar snackbar = Snackbar.make(getWindow().getDecorView().findViewById(android.R.id.content), R.string.deleted_a_photo,
121 | Snackbar.LENGTH_LONG);
122 | if(paths.size() <= 1){
123 | // 最后一张照片弹出删除提示
124 | // show confirm dialog
125 | new AlertDialog.Builder(this)
126 | .setTitle(R.string.confirm_to_delete)
127 | .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
128 | @Override public void onClick(DialogInterface dialogInterface, int i) {
129 | dialogInterface.dismiss();
130 | paths.remove(index);
131 | onBackPressed();
132 | }
133 | })
134 | .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
135 | @Override public void onClick(DialogInterface dialogInterface, int i) {
136 | dialogInterface.dismiss();
137 | }
138 | })
139 | .show();
140 | }else{
141 | snackbar.show();
142 | paths.remove(index);
143 | mPagerAdapter.notifyDataSetChanged();
144 | }
145 |
146 | snackbar.setAction(R.string.undo, new View.OnClickListener() {
147 | @Override
148 | public void onClick(View view) {
149 | if (paths.size() > 0) {
150 | paths.add(index, deletedPath);
151 | } else {
152 | paths.add(deletedPath);
153 | }
154 | mPagerAdapter.notifyDataSetChanged();
155 | mViewPager.setCurrentItem(index, true);
156 | }
157 | });
158 | }
159 | return super.onOptionsItemSelected(item);
160 | }
161 | }
162 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zq/weixinselectpicture/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.zq.weixinselectpicture;
2 |
3 | import android.content.Intent;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.os.Bundle;
6 | import android.util.Log;
7 | import android.view.LayoutInflater;
8 | import android.view.View;
9 | import android.view.ViewGroup;
10 | import android.widget.AdapterView;
11 | import android.widget.BaseAdapter;
12 | import android.widget.EditText;
13 | import android.widget.GridView;
14 | import android.widget.ImageView;
15 | import android.widget.TextView;
16 | import android.widget.Toast;
17 |
18 | import com.bumptech.glide.Glide;
19 | import com.lidong.photopicker.PhotoPickerActivity;
20 | import com.lidong.photopicker.PhotoPreviewActivity;
21 | import com.lidong.photopicker.SelectModel;
22 | import com.lidong.photopicker.intent.PhotoPickerIntent;
23 | import com.lidong.photopicker.intent.PhotoPreviewIntent;
24 |
25 | import org.json.JSONArray;
26 |
27 | import java.util.ArrayList;
28 |
29 | /**
30 | * Android之仿微信发朋友圈图片选择功能
31 | *
32 | */
33 |
34 | public class MainActivity extends AppCompatActivity {
35 |
36 | private static final int REQUEST_CAMERA_CODE = 10;
37 | private static final int REQUEST_PREVIEW_CODE = 20;
38 | private ArrayList imagePaths = new ArrayList<>();
39 |
40 | private GridView gridView;
41 | private GridAdapter gridAdapter;
42 | private TextView tv_click;
43 | private EditText textView;
44 | private String TAG =MainActivity.class.getSimpleName();
45 |
46 | @Override
47 | protected void onCreate(Bundle savedInstanceState) {
48 | super.onCreate(savedInstanceState);
49 | setContentView(R.layout.activity_main);
50 | gridView = (GridView) findViewById(R.id.gridView);
51 | tv_click = (TextView) findViewById(R.id.find_comment_submit);
52 | textView= (EditText)findViewById(R.id.et_context);
53 |
54 | int cols = getResources().getDisplayMetrics().widthPixels / getResources().getDisplayMetrics().densityDpi;
55 | cols = cols < 3 ? 3 : cols;
56 | gridView.setNumColumns(cols);
57 | gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
58 | @Override
59 | public void onItemClick(AdapterView> parent, View view, int position, long id) {
60 |
61 |
62 | String imgs = (String) parent.getItemAtPosition(position);
63 | if ("paizhao".equals(imgs) ){
64 | PhotoPickerIntent intent = new PhotoPickerIntent(MainActivity.this);
65 | intent.setSelectModel(SelectModel.MULTI);
66 | intent.setShowCarema(true); // 是否显示拍照
67 | intent.setMaxTotal(6); // 最多选择照片数量,默认为6
68 | intent.setSelectedPaths(imagePaths); // 已选中的照片地址, 用于回显选中状态
69 | startActivityForResult(intent, REQUEST_CAMERA_CODE);
70 | }else{
71 | Toast.makeText(MainActivity.this,"1"+position,Toast.LENGTH_SHORT).show();
72 | PhotoPreviewIntent intent = new PhotoPreviewIntent(MainActivity.this);
73 | intent.setCurrentItem(position);
74 | intent.setPhotoPaths(imagePaths);
75 | startActivityForResult(intent, REQUEST_PREVIEW_CODE);
76 | }
77 | }
78 | });
79 | imagePaths.add("paizhao");
80 | gridAdapter = new GridAdapter(imagePaths);
81 | gridView.setAdapter(gridAdapter);
82 | tv_click.setOnClickListener(new View.OnClickListener() {
83 | @Override
84 | public void onClick(View v) {
85 | }
86 | });
87 | }
88 |
89 |
90 | @Override
91 | protected void onResume() {
92 | super.onResume();
93 | }
94 |
95 | @Override
96 | protected void onActivityResult(int requestCode, int resultCode, Intent data) {
97 | super.onActivityResult(requestCode, resultCode, data);
98 | if(resultCode == RESULT_OK) {
99 | switch (requestCode) {
100 | // 选择照片
101 | case REQUEST_CAMERA_CODE:
102 | ArrayList list = data.getStringArrayListExtra(PhotoPickerActivity.EXTRA_RESULT);
103 | Log.d(TAG, "数量:"+list.size());
104 | loadAdpater(list);
105 | break;
106 | // 预览
107 | case REQUEST_PREVIEW_CODE:
108 | ArrayList ListExtra = data.getStringArrayListExtra(PhotoPreviewActivity.EXTRA_RESULT);
109 | loadAdpater(ListExtra);
110 | break;
111 | }
112 | }
113 | }
114 |
115 | private void loadAdpater(ArrayList paths){
116 | if (imagePaths!=null&& imagePaths.size()>0){
117 | imagePaths.clear();
118 | }
119 | if (paths.contains("paizhao")){
120 | paths.remove("paizhao");
121 | }
122 | paths.add("paizhao");
123 | imagePaths.addAll(paths);
124 | gridAdapter = new GridAdapter(imagePaths);
125 | gridView.setAdapter(gridAdapter);
126 | try{
127 | JSONArray obj = new JSONArray(imagePaths);
128 | }catch (Exception e){
129 | e.printStackTrace();
130 | }
131 | }
132 |
133 | private class GridAdapter extends BaseAdapter {
134 | private ArrayList listUrls;
135 | private LayoutInflater inflater;
136 | public GridAdapter(ArrayList listUrls) {
137 | this.listUrls = listUrls;
138 | if(listUrls.size() == 7){
139 | listUrls.remove(listUrls.size()-1);
140 | }
141 | inflater = LayoutInflater.from(MainActivity.this);
142 | }
143 |
144 | public int getCount(){
145 | return listUrls.size();
146 | }
147 | @Override
148 | public String getItem(int position) {
149 | return listUrls.get(position);
150 | }
151 |
152 | @Override
153 | public long getItemId(int position) {
154 | return position;
155 | }
156 |
157 | @Override
158 | public View getView(int position, View convertView, ViewGroup parent) {
159 | ViewHolder holder = null;
160 | if (convertView == null) {
161 | holder = new ViewHolder();
162 | convertView = inflater.inflate(R.layout.item, parent,false);
163 | holder.image = (ImageView) convertView.findViewById(R.id.imageView);
164 | convertView.setTag(holder);
165 | } else {
166 | holder = (ViewHolder)convertView.getTag();
167 | }
168 |
169 | final String path=listUrls.get(position);
170 | if (path.equals("paizhao")){
171 | holder.image.setImageResource(R.mipmap.find_add_img);
172 | }else {
173 | Glide.with(MainActivity.this)
174 | .load(path)
175 | .placeholder(R.mipmap.default_error)
176 | .error(R.mipmap.default_error)
177 | .centerCrop()
178 | .crossFade()
179 | .into(holder.image);
180 | }
181 | return convertView;
182 | }
183 | class ViewHolder {
184 | ImageView image;
185 | }
186 | }
187 | }
188 |
--------------------------------------------------------------------------------
/pictureselector/src/main/java/com/lidong/photopicker/ImageGridAdapter.java:
--------------------------------------------------------------------------------
1 | package com.lidong.photopicker;
2 |
3 | import android.content.Context;
4 | import android.view.LayoutInflater;
5 | import android.view.View;
6 | import android.view.ViewGroup;
7 | import android.widget.BaseAdapter;
8 | import android.widget.GridView;
9 | import android.widget.ImageView;
10 |
11 | import com.bumptech.glide.Glide;
12 |
13 | import java.io.File;
14 | import java.util.ArrayList;
15 | import java.util.List;
16 |
17 | /**
18 | * ͼƬAdapter
19 | */
20 | public class ImageGridAdapter extends BaseAdapter {
21 |
22 | private static final int TYPE_CAMERA = 0;
23 | private static final int TYPE_NORMAL = 1;
24 |
25 | private Context mContext;
26 |
27 | private LayoutInflater mInflater;
28 | private boolean showCamera = true;
29 | private boolean showSelectIndicator = true;
30 |
31 | private List mImages = new ArrayList<>();
32 | private List mSelectedImages = new ArrayList<>();
33 |
34 | private int mItemSize;
35 | private GridView.LayoutParams mItemLayoutParams;
36 |
37 | public ImageGridAdapter(Context context, boolean showCamera, int itemSize){
38 | mContext = context;
39 | mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
40 | this.showCamera = showCamera;
41 | this.mItemSize = itemSize;
42 | mItemLayoutParams = new GridView.LayoutParams(mItemSize, mItemSize);
43 | }
44 |
45 | /**
46 | * 显示选择指示器
47 | * @param b
48 | */
49 | public void showSelectIndicator(boolean b) {
50 | showSelectIndicator = b;
51 | }
52 |
53 | public void setShowCamera(boolean b){
54 | if(showCamera == b) return;
55 |
56 | showCamera = b;
57 | notifyDataSetChanged();
58 | }
59 |
60 | public boolean isShowCamera(){
61 | return showCamera;
62 | }
63 |
64 | /**
65 | * 选择某个图片,改变选择状态
66 | * @param image
67 | */
68 | public void select(Image image) {
69 | if(mSelectedImages.contains(image)){
70 | mSelectedImages.remove(image);
71 | }else{
72 | mSelectedImages.add(image);
73 | }
74 | notifyDataSetChanged();
75 | }
76 |
77 | /**
78 | * 通过图片路径设置默认选择
79 | * @param resultList
80 | */
81 | public void setDefaultSelected(ArrayList resultList) {
82 | mSelectedImages.clear();
83 | for(String path : resultList){
84 | Image image = getImageByPath(path);
85 | if(image != null){
86 | mSelectedImages.add(image);
87 | }
88 | }
89 | notifyDataSetChanged();
90 | }
91 |
92 | private Image getImageByPath(String path){
93 | if(mImages != null && mImages.size() > 0){
94 | for(Image image : mImages){
95 | if(image.path.equalsIgnoreCase(path)){
96 | return image;
97 | }
98 | }
99 | }
100 | return null;
101 | }
102 |
103 | /**
104 | * 设置数据集
105 | * @param images
106 | */
107 | public void setData(List images) {
108 | mSelectedImages.clear();
109 |
110 | if(images != null && images.size() > 0){
111 | mImages = images;
112 | }else{
113 | mImages.clear();
114 | }
115 | notifyDataSetChanged();
116 | }
117 |
118 | /**
119 | * 重置每个Column的Size
120 | * @param columnWidth
121 | */
122 | public void setItemSize(int columnWidth) {
123 |
124 | if(mItemSize == columnWidth){
125 | return;
126 | }
127 |
128 | mItemSize = columnWidth;
129 |
130 | mItemLayoutParams = new GridView.LayoutParams(mItemSize, mItemSize);
131 |
132 | notifyDataSetChanged();
133 | }
134 |
135 | @Override
136 | public int getViewTypeCount() {
137 | return 2;
138 | }
139 |
140 | @Override
141 | public int getItemViewType(int position) {
142 | if(showCamera){
143 | return position == 0 ? TYPE_CAMERA : TYPE_NORMAL;
144 | }
145 | return TYPE_NORMAL;
146 | }
147 |
148 | @Override
149 | public int getCount() {
150 | return showCamera ? mImages.size() + 1 : mImages.size();
151 | }
152 |
153 | @Override
154 | public Image getItem(int i) {
155 | if(showCamera){
156 | if(i == 0){
157 | return null;
158 | }
159 | return mImages.get(i - 1);
160 | }else{
161 | return mImages.get(i);
162 | }
163 | }
164 |
165 | @Override
166 | public long getItemId(int i) {
167 | return i;
168 | }
169 |
170 | @Override
171 | public View getView(int i, View view, ViewGroup viewGroup) {
172 |
173 | int type = getItemViewType(i);
174 | if(type == TYPE_CAMERA){
175 | view = mInflater.inflate(R.layout.item_camera, viewGroup, false);
176 | view.setTag(null);
177 | }else if(type == TYPE_NORMAL){
178 | ViewHolde holde;
179 | if(view == null){
180 | view = mInflater.inflate(R.layout.item_select_image, viewGroup, false);
181 | holde = new ViewHolde(view);
182 | }else{
183 | holde = (ViewHolde) view.getTag();
184 | if(holde == null){
185 | view = mInflater.inflate(R.layout.item_select_image, viewGroup, false);
186 | holde = new ViewHolde(view);
187 | }
188 | }
189 | if(holde != null) {
190 | holde.bindData(getItem(i));
191 | }
192 | }
193 |
194 | /** Fixed View Size */
195 | GridView.LayoutParams lp = (GridView.LayoutParams) view.getLayoutParams();
196 | if(lp.height != mItemSize){
197 | view.setLayoutParams(mItemLayoutParams);
198 | }
199 |
200 | return view;
201 | }
202 |
203 | class ViewHolde {
204 | ImageView image;
205 | ImageView indicator;
206 | View mask;
207 |
208 | ViewHolde(View view){
209 | image = (ImageView) view.findViewById(R.id.image);
210 | indicator = (ImageView) view.findViewById(R.id.checkmark);
211 | mask = view.findViewById(R.id.mask);
212 | view.setTag(this);
213 | }
214 |
215 | void bindData(final Image data){
216 | if(data == null) return;
217 | // 处理单选和多选状态
218 | if(showSelectIndicator){
219 | indicator.setVisibility(View.VISIBLE);
220 | if(mSelectedImages.contains(data)){
221 | // 设置选中状态
222 | indicator.setImageResource(R.mipmap.btn_selected);
223 | mask.setVisibility(View.VISIBLE);
224 | }else{
225 | // 未选择
226 | indicator.setImageResource(R.mipmap.btn_unselected);
227 | mask.setVisibility(View.GONE);
228 | }
229 | }else{
230 | indicator.setVisibility(View.GONE);
231 | }
232 | File imageFile = new File(data.path);
233 |
234 | if(mItemSize > 0) {
235 | // 显示图片
236 | Glide.with(mContext)
237 | .load(imageFile)
238 | .placeholder(R.mipmap.default_error)
239 | .error(R.mipmap.default_error)
240 | .override(mItemSize, mItemSize)
241 | .centerCrop()
242 | .into(image);
243 | }
244 | }
245 | }
246 |
247 | }
248 |
--------------------------------------------------------------------------------
/pictureselector/src/main/java/com/lidong/photopicker/PhotoPickerActivity.java:
--------------------------------------------------------------------------------
1 | package com.lidong.photopicker;
2 |
3 | import android.content.Context;
4 | import android.content.Intent;
5 | import android.content.res.Configuration;
6 | import android.database.Cursor;
7 | import android.graphics.Color;
8 | import android.graphics.drawable.ColorDrawable;
9 | import android.os.Bundle;
10 | import android.os.Handler;
11 | import android.provider.MediaStore;
12 | import android.support.v4.app.LoaderManager;
13 | import android.support.v4.content.CursorLoader;
14 | import android.support.v4.content.Loader;
15 | import android.support.v7.app.AppCompatActivity;
16 | import android.support.v7.widget.ListPopupWindow;
17 | import android.support.v7.widget.Toolbar;
18 | import android.util.Log;
19 | import android.view.Menu;
20 | import android.view.MenuItem;
21 | import android.view.View;
22 | import android.widget.AdapterView;
23 | import android.widget.Button;
24 | import android.widget.GridView;
25 | import android.widget.Toast;
26 |
27 | import com.lidong.photopicker.intent.PhotoPreviewIntent;
28 |
29 | import java.io.File;
30 | import java.io.IOException;
31 | import java.util.ArrayList;
32 | import java.util.List;
33 |
34 | public class PhotoPickerActivity extends AppCompatActivity{
35 |
36 | public static final String TAG = PhotoPickerActivity.class.getName();
37 |
38 | private Context mCxt;
39 |
40 | /** 图片选择模式,int类型 */
41 | public static final String EXTRA_SELECT_MODE = "select_count_mode";
42 | /** 单选 */
43 | public static final int MODE_SINGLE = 0;
44 | /** 多选 */
45 | public static final int MODE_MULTI = 1;
46 | /** 最大图片选择次数,int类型 */
47 | public static final String EXTRA_SELECT_COUNT = "max_select_count";
48 | /** 默认最大照片数量 */
49 | public static final int DEFAULT_MAX_TOTAL= 9;
50 | /** 是否显示相机,boolean类型 */
51 | public static final String EXTRA_SHOW_CAMERA = "show_camera";
52 | /** 默认选择的数据集 */
53 | public static final String EXTRA_DEFAULT_SELECTED_LIST = "default_result";
54 | /** 筛选照片配置信息 */
55 | public static final String EXTRA_IMAGE_CONFIG = "image_config";
56 | /** 选择结果,返回为 ArrayList<String> 图片路径集合 */
57 | public static final String EXTRA_RESULT = "select_result";
58 |
59 | // 结果数据
60 | private ArrayList resultList = new ArrayList<>();
61 | // 文件夹数据
62 | private ArrayList mResultFolder = new ArrayList<>();
63 |
64 | // 不同loader定义
65 | private static final int LOADER_ALL = 0;
66 | private static final int LOADER_CATEGORY = 1;
67 |
68 | private MenuItem menuDoneItem;
69 | private GridView mGridView;
70 | private View mPopupAnchorView;
71 | private Button btnAlbum;
72 | private Button btnPreview;
73 |
74 | // 最大照片数量
75 | private ImageCaptureManager captureManager;
76 | private int mDesireImageCount;
77 | private ImageConfig imageConfig; // 照片配置
78 |
79 | private ImageGridAdapter mImageAdapter;
80 | private FolderAdapter mFolderAdapter;
81 | private ListPopupWindow mFolderPopupWindow;
82 |
83 | private boolean hasFolderGened = false;
84 | private boolean mIsShowCamera = false;
85 |
86 | @Override
87 | protected void onCreate(Bundle savedInstanceState) {
88 | super.onCreate(savedInstanceState);
89 | setContentView(R.layout.activity_photopicker);
90 |
91 | initViews();
92 |
93 | // 照片属性
94 | imageConfig = getIntent().getParcelableExtra(EXTRA_IMAGE_CONFIG);
95 |
96 | // 首次加载所有图片
97 | getSupportLoaderManager().initLoader(LOADER_ALL, null, mLoaderCallback);
98 |
99 | // 选择图片数量
100 | mDesireImageCount = getIntent().getIntExtra(EXTRA_SELECT_COUNT, DEFAULT_MAX_TOTAL);
101 |
102 | // 图片选择模式
103 | final int mode = getIntent().getExtras().getInt(EXTRA_SELECT_MODE, MODE_SINGLE);
104 |
105 | // 默认选择
106 | if(mode == MODE_MULTI) {
107 | ArrayList tmp = getIntent().getStringArrayListExtra(EXTRA_DEFAULT_SELECTED_LIST);
108 | if(tmp != null && tmp.size() > 0) {
109 | // resultList.addAll(tmp);
110 | }
111 | }
112 |
113 | // 是否显示照相机
114 | mIsShowCamera = getIntent().getBooleanExtra(EXTRA_SHOW_CAMERA, false);
115 | mImageAdapter = new ImageGridAdapter(mCxt, mIsShowCamera, getItemImageWidth());
116 | // 是否显示选择指示器
117 | mImageAdapter.showSelectIndicator(mode == MODE_MULTI);
118 | mGridView.setAdapter(mImageAdapter);
119 |
120 | mGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
121 | @Override
122 | public void onItemClick(AdapterView> adapterView, View view, int i, long l) {
123 | if (mImageAdapter.isShowCamera()) {
124 | // 如果显示照相机,则第一个Grid显示为照相机,处理特殊逻辑
125 | if (i == 0) {
126 | if(mode == MODE_MULTI){
127 | // 判断选择数量问题
128 | if(mDesireImageCount == resultList.size()-1){
129 | Toast.makeText(mCxt, R.string.msg_amount_limit, Toast.LENGTH_SHORT).show();
130 | return;
131 | }
132 | }
133 | showCameraAction();
134 | } else {
135 | // 正常操作
136 | Image image = (Image) adapterView.getAdapter().getItem(i);
137 | selectImageFromGrid(image, mode);
138 | }
139 | } else {
140 | // 正常操作
141 | Image image = (Image) adapterView.getAdapter().getItem(i);
142 | selectImageFromGrid(image, mode);
143 | }
144 | }
145 | });
146 |
147 | mFolderAdapter = new FolderAdapter(mCxt);
148 |
149 | // 打开相册列表
150 | btnAlbum.setOnClickListener(new View.OnClickListener() {
151 | @Override
152 | public void onClick(View v) {
153 | if (mFolderPopupWindow == null) {
154 | createPopupFolderList();
155 | }
156 |
157 | if (mFolderPopupWindow.isShowing()) {
158 | mFolderPopupWindow.dismiss();
159 | } else {
160 | mFolderPopupWindow.show();
161 | int index = mFolderAdapter.getSelectIndex();
162 | index = index == 0 ? index : index - 1;
163 | mFolderPopupWindow.getListView().setSelection(index);
164 | }
165 | }
166 | });
167 |
168 | // 预览
169 | btnPreview.setOnClickListener(new View.OnClickListener() {
170 | @Override
171 | public void onClick(View v) {
172 | PhotoPreviewIntent intent = new PhotoPreviewIntent(mCxt);
173 | intent.setCurrentItem(0);
174 | intent.setPhotoPaths(resultList);
175 | startActivityForResult(intent, PhotoPreviewActivity.REQUEST_PREVIEW);
176 | }
177 | });
178 |
179 | }
180 |
181 | private void initViews(){
182 | mCxt = this;
183 | captureManager = new ImageCaptureManager(mCxt);
184 | // ActionBar Setting
185 | Toolbar toolbar = (Toolbar) findViewById(R.id.pickerToolbar);
186 | setSupportActionBar(toolbar);
187 | getSupportActionBar().setTitle(getResources().getString(R.string.image));
188 | getSupportActionBar().setDisplayHomeAsUpEnabled(true);
189 |
190 | mGridView = (GridView) findViewById(R.id.grid);
191 | mGridView.setNumColumns(getNumColnums());
192 |
193 | mPopupAnchorView = findViewById(R.id.photo_picker_footer);
194 | btnAlbum = (Button) findViewById(R.id.btnAlbum);
195 | btnPreview = (Button) findViewById(R.id.btnPreview);
196 | }
197 |
198 | private void createPopupFolderList(){
199 |
200 | mFolderPopupWindow = new ListPopupWindow(mCxt);
201 | mFolderPopupWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
202 | mFolderPopupWindow.setAdapter(mFolderAdapter);
203 | mFolderPopupWindow.setContentWidth(ListPopupWindow.MATCH_PARENT);
204 | mFolderPopupWindow.setWidth(ListPopupWindow.MATCH_PARENT);
205 |
206 | // 计算ListPopupWindow内容的高度(忽略mPopupAnchorView.height),R.layout.item_foloer
207 | int folderItemViewHeight =
208 | // 图片高度
209 | getResources().getDimensionPixelOffset(R.dimen.folder_cover_size) +
210 | // Padding Top
211 | getResources().getDimensionPixelOffset(R.dimen.folder_padding) +
212 | // Padding Bottom
213 | getResources().getDimensionPixelOffset(R.dimen.folder_padding);
214 | int folderViewHeight = mFolderAdapter.getCount() * folderItemViewHeight;
215 |
216 | int screenHeigh = getResources().getDisplayMetrics().heightPixels;
217 | if(folderViewHeight >= screenHeigh){
218 | mFolderPopupWindow.setHeight(Math.round(screenHeigh * 0.6f));
219 | }else{
220 | mFolderPopupWindow.setHeight(ListPopupWindow.WRAP_CONTENT);
221 | }
222 |
223 | mFolderPopupWindow.setAnchorView(mPopupAnchorView);
224 | mFolderPopupWindow.setModal(true);
225 | mFolderPopupWindow.setAnimationStyle(R.style.Animation_AppCompat_DropDownUp);
226 | mFolderPopupWindow.setOnItemClickListener(new AdapterView.OnItemClickListener() {
227 | @Override
228 | public void onItemClick(AdapterView> parent, View view, int position, long id) {
229 |
230 | mFolderAdapter.setSelectIndex(position);
231 |
232 | final int index = position;
233 | final AdapterView v = parent;
234 |
235 | new Handler().postDelayed(new Runnable() {
236 | @Override
237 | public void run() {
238 | mFolderPopupWindow.dismiss();
239 |
240 | if (index == 0) {
241 | getSupportLoaderManager().restartLoader(LOADER_ALL, null, mLoaderCallback);
242 | btnAlbum.setText(R.string.all_image);
243 | mImageAdapter.setShowCamera(mIsShowCamera);
244 | } else {
245 | Folder folder = (Folder) v.getAdapter().getItem(index);
246 | if (null != folder) {
247 | mImageAdapter.setData(folder.images);
248 | btnAlbum.setText(folder.name);
249 | // 设定默认选择
250 | if (resultList != null && resultList.size() > 0) {
251 | mImageAdapter.setDefaultSelected(resultList);
252 | }
253 | }
254 | mImageAdapter.setShowCamera(false);
255 | }
256 |
257 | // 滑动到最初始位置
258 | mGridView.smoothScrollToPosition(0);
259 | }
260 | }, 100);
261 | }
262 | });
263 | }
264 |
265 | public void onSingleImageSelected(String path) {
266 | Intent data = new Intent();
267 | resultList.add(path);
268 | data.putStringArrayListExtra(EXTRA_RESULT, resultList);
269 | setResult(RESULT_OK, data);
270 | finish();
271 | }
272 |
273 | public void onImageSelected(String path) {
274 | if(!resultList.contains(path)) {
275 | resultList.add(path);
276 | }
277 | refreshActionStatus();
278 | }
279 |
280 | public void onImageUnselected(String path) {
281 | if(resultList.contains(path)){
282 | resultList.remove(path);
283 | }
284 | refreshActionStatus();
285 | }
286 |
287 | @Override
288 | public void onActivityResult(int requestCode, int resultCode, Intent data) {
289 | super.onActivityResult(requestCode, resultCode, data);
290 |
291 | if(resultCode == RESULT_OK){
292 | switch (requestCode){
293 | // 相机拍照完成后,返回图片路径
294 | case ImageCaptureManager.REQUEST_TAKE_PHOTO:
295 | if(captureManager.getCurrentPhotoPath() != null) {
296 | captureManager.galleryAddPic();
297 | resultList.add(captureManager.getCurrentPhotoPath());
298 | }
299 | complete();
300 | break;
301 | // 预览照片
302 | case PhotoPreviewActivity.REQUEST_PREVIEW:
303 | ArrayList pathArr = data.getStringArrayListExtra(PhotoPreviewActivity.EXTRA_RESULT);
304 | // 刷新页面
305 | if(pathArr != null && pathArr.size() != resultList.size()){
306 | resultList = pathArr;
307 | refreshActionStatus();
308 | mImageAdapter.setDefaultSelected(resultList);
309 | }
310 | break;
311 | }
312 | }
313 | }
314 |
315 | @Override
316 | public void onConfigurationChanged(Configuration newConfig) {
317 | Log.d(TAG, "on change");
318 |
319 | // 重置列数
320 | mGridView.setNumColumns(getNumColnums());
321 | // 重置Item宽度
322 | mImageAdapter.setItemSize(getItemImageWidth());
323 |
324 | if(mFolderPopupWindow != null){
325 | if(mFolderPopupWindow.isShowing()){
326 | mFolderPopupWindow.dismiss();
327 | }
328 |
329 | // 重置PopupWindow高度
330 | int screenHeigh = getResources().getDisplayMetrics().heightPixels;
331 | mFolderPopupWindow.setHeight(Math.round(screenHeigh * 0.6f));
332 | }
333 |
334 | super.onConfigurationChanged(newConfig);
335 | }
336 |
337 | /**
338 | * 选择相机
339 | */
340 | private void showCameraAction() {
341 | try {
342 | Intent intent = captureManager.dispatchTakePictureIntent();
343 | startActivityForResult(intent, ImageCaptureManager.REQUEST_TAKE_PHOTO);
344 | } catch (IOException e) {
345 | Toast.makeText(mCxt, R.string.msg_no_camera, Toast.LENGTH_SHORT).show();
346 | e.printStackTrace();
347 | }
348 | }
349 |
350 | /**
351 | * 选择图片操作
352 | * @param image
353 | */
354 | private void selectImageFromGrid(Image image, int mode) {
355 | if(image != null) {
356 | // 多选模式
357 | if(mode == MODE_MULTI) {
358 | if (resultList.contains(image.path)) {
359 | resultList.remove(image.path);
360 | onImageUnselected(image.path);
361 | } else {
362 | // 判断选择数量问题
363 | if(mDesireImageCount == resultList.size()){
364 | Toast.makeText(mCxt, R.string.msg_amount_limit, Toast.LENGTH_SHORT).show();
365 | return;
366 | }
367 | resultList.add(image.path);
368 | onImageSelected(image.path);
369 | }
370 | mImageAdapter.select(image);
371 | }else if(mode == MODE_SINGLE){
372 | // 单选模式
373 | onSingleImageSelected(image.path);
374 | }
375 | }
376 | }
377 |
378 | /**
379 | * 刷新操作按钮状态
380 | */
381 | private void refreshActionStatus(){
382 | if(resultList.contains("000000")){
383 | resultList.remove("000000");
384 | }
385 | String text = getString(R.string.done_with_count, resultList.size(), mDesireImageCount);
386 | menuDoneItem.setTitle(text);
387 | boolean hasSelected = resultList.size() > 0;
388 | menuDoneItem.setVisible(hasSelected);
389 | btnPreview.setEnabled(hasSelected);
390 | if(hasSelected){
391 | btnPreview.setText(getResources().getString(R.string.preview) + "(" + (resultList.size()) + ")");
392 | } else {
393 | btnPreview.setText(getResources().getString(R.string.preview));
394 | }
395 | }
396 |
397 | private LoaderManager.LoaderCallbacks mLoaderCallback = new LoaderManager.LoaderCallbacks() {
398 |
399 | private final String[] IMAGE_PROJECTION = {
400 | MediaStore.Images.Media.DATA,
401 | MediaStore.Images.Media.DISPLAY_NAME,
402 | MediaStore.Images.Media.DATE_ADDED,
403 | MediaStore.Images.Media._ID };
404 |
405 | @Override
406 | public Loader onCreateLoader(int id, Bundle args) {
407 |
408 | // 根据图片设置参数新增验证条件
409 | StringBuilder selectionArgs = new StringBuilder();
410 |
411 | if(imageConfig != null){
412 | if(imageConfig.minWidth != 0){
413 | selectionArgs.append(MediaStore.Images.Media.WIDTH + " >= " + imageConfig.minWidth);
414 | }
415 |
416 | if(imageConfig.minHeight != 0){
417 | selectionArgs.append("".equals(selectionArgs.toString()) ? "" : " and ");
418 | selectionArgs.append(MediaStore.Images.Media.HEIGHT + " >= " + imageConfig.minHeight);
419 | }
420 |
421 | if(imageConfig.minSize != 0f){
422 | selectionArgs.append("".equals(selectionArgs.toString()) ? "" : " and ");
423 | selectionArgs.append(MediaStore.Images.Media.SIZE + " >= " + imageConfig.minSize);
424 | }
425 |
426 | if(imageConfig.mimeType != null){
427 | selectionArgs.append(" and (");
428 | for(int i = 0, len = imageConfig.mimeType.length; i < len; i++){
429 | if(i != 0){
430 | selectionArgs.append(" or ");
431 | }
432 | selectionArgs.append(MediaStore.Images.Media.MIME_TYPE + " = '" + imageConfig.mimeType[i] + "'");
433 | }
434 | selectionArgs.append(")");
435 | }
436 | }
437 |
438 | if(id == LOADER_ALL) {
439 | CursorLoader cursorLoader = new CursorLoader(mCxt,
440 | MediaStore.Images.Media.EXTERNAL_CONTENT_URI, IMAGE_PROJECTION,
441 | selectionArgs.toString(), null, IMAGE_PROJECTION[2] + " DESC");
442 | return cursorLoader;
443 | }else if(id == LOADER_CATEGORY){
444 | String selectionStr = selectionArgs.toString();
445 | if(!"".equals(selectionStr)){
446 | selectionStr += " and" + selectionStr;
447 | }
448 | CursorLoader cursorLoader = new CursorLoader(mCxt,
449 | MediaStore.Images.Media.EXTERNAL_CONTENT_URI, IMAGE_PROJECTION,
450 | IMAGE_PROJECTION[0] + " like '%" + args.getString("path") + "%'" + selectionStr, null,
451 | IMAGE_PROJECTION[2] + " DESC");
452 | return cursorLoader;
453 | }
454 |
455 | return null;
456 | }
457 |
458 | @Override
459 | public void onLoadFinished(Loader loader, Cursor data) {
460 | if (data != null) {
461 | List images = new ArrayList<>();
462 | int count = data.getCount();
463 | if (count > 0) {
464 | data.moveToFirst();
465 | do{
466 | String path = data.getString(data.getColumnIndexOrThrow(IMAGE_PROJECTION[0]));
467 | String name = data.getString(data.getColumnIndexOrThrow(IMAGE_PROJECTION[1]));
468 | long dateTime = data.getLong(data.getColumnIndexOrThrow(IMAGE_PROJECTION[2]));
469 |
470 | Image image = new Image(path, name, dateTime);
471 | images.add(image);
472 | if( !hasFolderGened ) {
473 | // 获取文件夹名称
474 | File imageFile = new File(path);
475 | File folderFile = imageFile.getParentFile();
476 | Folder folder = new Folder();
477 | folder.name = folderFile.getName();
478 | folder.path = folderFile.getAbsolutePath();
479 | folder.cover = image;
480 | if (!mResultFolder.contains(folder)) {
481 | List imageList = new ArrayList<>();
482 | imageList.add(image);
483 | folder.images = imageList;
484 | mResultFolder.add(folder);
485 | } else {
486 | // 更新
487 | Folder f = mResultFolder.get(mResultFolder.indexOf(folder));
488 | f.images.add(image);
489 | }
490 | }
491 |
492 | }while(data.moveToNext());
493 |
494 | mImageAdapter.setData(images);
495 |
496 | // 设定默认选择
497 | if(resultList != null && resultList.size()>0){
498 | mImageAdapter.setDefaultSelected(resultList);
499 | }
500 |
501 | mFolderAdapter.setData(mResultFolder);
502 | hasFolderGened = true;
503 |
504 | }
505 | }
506 | }
507 |
508 | @Override
509 | public void onLoaderReset(Loader loader) {
510 |
511 | }
512 | };
513 |
514 | /**
515 | * 获取GridView Item宽度
516 | * @return
517 | */
518 | private int getItemImageWidth(){
519 | int cols = getNumColnums();
520 | int screenWidth = getResources().getDisplayMetrics().widthPixels;
521 | int columnSpace = getResources().getDimensionPixelOffset(R.dimen.space_size);
522 | return (screenWidth - columnSpace * (cols-1)) / cols;
523 | }
524 |
525 | /**
526 | * 根据屏幕宽度与密度计算GridView显示的列数, 最少为三列
527 | * @return
528 | */
529 | private int getNumColnums(){
530 | int cols = getResources().getDisplayMetrics().widthPixels / getResources().getDisplayMetrics().densityDpi;
531 | return cols < 3 ? 3 : cols;
532 | }
533 |
534 | @Override
535 | public boolean onCreateOptionsMenu(Menu menu) {
536 | getMenuInflater().inflate(R.menu.menu_picker, menu);
537 | menuDoneItem = menu.findItem(R.id.action_picker_done);
538 | menuDoneItem.setVisible(false);
539 | refreshActionStatus();
540 | return true;
541 | }
542 |
543 | @Override
544 | public boolean onOptionsItemSelected(MenuItem item) {
545 |
546 | if(item.getItemId() == android.R.id.home){
547 | finish();
548 | return true;
549 | }
550 |
551 | if(item.getItemId() == R.id.action_picker_done){
552 | complete();
553 | return true;
554 | }
555 |
556 | return super.onOptionsItemSelected(item);
557 | }
558 |
559 | // 返回已选择的图片数据
560 | private void complete(){
561 | Intent data = new Intent();
562 | data.putStringArrayListExtra(EXTRA_RESULT, resultList);
563 | setResult(RESULT_OK, data);
564 | finish();
565 | }
566 |
567 | @Override
568 | public void onSaveInstanceState(Bundle outState) {
569 | captureManager.onSaveInstanceState(outState);
570 | super.onSaveInstanceState(outState);
571 | }
572 |
573 | @Override
574 | protected void onRestoreInstanceState(Bundle savedInstanceState) {
575 | captureManager.onRestoreInstanceState(savedInstanceState);
576 | super.onRestoreInstanceState(savedInstanceState);
577 | }
578 | }
579 |
--------------------------------------------------------------------------------