├── sample
├── .gitignore
├── src
│ └── main
│ │ ├── res
│ │ ├── values
│ │ │ ├── strings.xml
│ │ │ ├── colors.xml
│ │ │ ├── dimens.xml
│ │ │ └── styles.xml
│ │ ├── mipmap-hdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-mdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-xhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxxhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-anydpi-v26
│ │ │ ├── ic_launcher.xml
│ │ │ └── ic_launcher_round.xml
│ │ ├── layout
│ │ │ └── activity_main.xml
│ │ ├── drawable-v24
│ │ │ └── ic_launcher_foreground.xml
│ │ └── drawable
│ │ │ └── ic_launcher_background.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ └── com
│ │ └── jay
│ │ └── daguerre
│ │ └── app
│ │ └── MainActivity.java
├── proguard-rules.pro
└── build.gradle
├── daguerre
├── .gitignore
├── src
│ └── main
│ │ ├── res
│ │ ├── xml
│ │ │ └── daguerre_file_provider.xml
│ │ ├── menu
│ │ │ ├── daguerre_action_mode.xml
│ │ │ ├── daguerre_action_camera.xml
│ │ │ └── daguerre_action_video.xml
│ │ ├── layout
│ │ │ ├── daguerre_preview_resource_item.xml
│ │ │ ├── daguerre_activity_preview_resource.xml
│ │ │ ├── daguerre_activity.xml
│ │ │ ├── daguerre_resource_item.xml
│ │ │ └── daguerre_albums_item.xml
│ │ ├── values
│ │ │ ├── strings.xml
│ │ │ └── styles.xml
│ │ ├── drawable
│ │ │ ├── daguerre_ic_done.xml
│ │ │ ├── daguerre_ic_badge_video.xml
│ │ │ ├── daguerre_ic_video.xml
│ │ │ ├── daguerre_btn_check_material.xml
│ │ │ ├── daguerre_ic_camera.xml
│ │ │ ├── daguerre_circle_checked.xml
│ │ │ ├── daguerre_circle_unchecked.xml
│ │ │ └── daguerre_ic_badge_gif.xml
│ │ └── values-v19
│ │ │ └── styles.xml
│ │ ├── java
│ │ └── com
│ │ │ └── jay
│ │ │ └── daguerre
│ │ │ ├── provider
│ │ │ ├── DaguerreFileProvider.java
│ │ │ └── ImageLoader.java
│ │ │ ├── widget
│ │ │ └── SquareFrameLayout.java
│ │ │ ├── internal
│ │ │ ├── ConfigParams.java
│ │ │ ├── BaseRecyclerAdapter.java
│ │ │ ├── PreviewResourceAdapter.java
│ │ │ ├── Media.java
│ │ │ ├── PreviewResourceActivity.java
│ │ │ ├── AlbumsItemAdapter.java
│ │ │ ├── ResourceItemAdapter.java
│ │ │ └── DaguerreActivity.java
│ │ │ ├── MimeType.java
│ │ │ └── Daguerre.java
│ │ └── AndroidManifest.xml
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── apk
└── sample-debug.apk
├── images
├── apkqrcode.png
├── screenshot_preview.png
├── screenshot_select.png
└── screenshot_select_album.png
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitignore
├── gradle.properties
├── gradlew.bat
├── README.md
└── gradlew
/sample/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/daguerre/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':sample', ':daguerre'
2 |
--------------------------------------------------------------------------------
/apk/sample-debug.apk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/qiujiecn/Daguerre/HEAD/apk/sample-debug.apk
--------------------------------------------------------------------------------
/images/apkqrcode.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/qiujiecn/Daguerre/HEAD/images/apkqrcode.png
--------------------------------------------------------------------------------
/images/screenshot_preview.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/qiujiecn/Daguerre/HEAD/images/screenshot_preview.png
--------------------------------------------------------------------------------
/images/screenshot_select.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/qiujiecn/Daguerre/HEAD/images/screenshot_select.png
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/qiujiecn/Daguerre/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/images/screenshot_select_album.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/qiujiecn/Daguerre/HEAD/images/screenshot_select_album.png
--------------------------------------------------------------------------------
/sample/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Daguerre
3 |
4 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea
5 | .DS_Store
6 | /build
7 | /captures
8 | .externalNativeBuild
9 |
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/qiujiecn/Daguerre/HEAD/sample/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/qiujiecn/Daguerre/HEAD/sample/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/qiujiecn/Daguerre/HEAD/sample/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/qiujiecn/Daguerre/HEAD/sample/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/qiujiecn/Daguerre/HEAD/sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/qiujiecn/Daguerre/HEAD/sample/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/qiujiecn/Daguerre/HEAD/sample/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/qiujiecn/Daguerre/HEAD/sample/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/qiujiecn/Daguerre/HEAD/sample/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/qiujiecn/Daguerre/HEAD/sample/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/daguerre/src/main/res/xml/daguerre_file_provider.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
--------------------------------------------------------------------------------
/sample/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #FA8CBE
4 | #FA8CBE
5 | #FA8CBE
6 |
7 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Thu Nov 23 15:00:47 CST 2017
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-4.1-all.zip
7 |
--------------------------------------------------------------------------------
/daguerre/src/main/java/com/jay/daguerre/provider/DaguerreFileProvider.java:
--------------------------------------------------------------------------------
1 | package com.jay.daguerre.provider;
2 |
3 | import android.support.v4.content.FileProvider;
4 |
5 | /**
6 | * Created by jay on 2017/12/29 上午11:57
7 | */
8 | public class DaguerreFileProvider extends FileProvider {
9 | }
10 |
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/daguerre/src/main/res/menu/daguerre_action_mode.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/sample/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 | 8dp
6 | 176dp
7 | 16dp
8 |
--------------------------------------------------------------------------------
/daguerre/src/main/res/menu/daguerre_action_camera.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/daguerre/src/main/res/menu/daguerre_action_video.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/daguerre/src/main/res/layout/daguerre_preview_resource_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/daguerre/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | com.jay.daguerre.fileprovider
4 | 全部
5 | 找不到相机应用
6 | 最多选择%1$d项
7 | 已选择%1$d项
8 | %1$d项
9 |
--------------------------------------------------------------------------------
/daguerre/src/main/res/drawable/daguerre_ic_done.xml:
--------------------------------------------------------------------------------
1 |
7 |
11 |
12 |
--------------------------------------------------------------------------------
/daguerre/src/main/res/values-v19/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
10 |
--------------------------------------------------------------------------------
/daguerre/src/main/res/drawable/daguerre_ic_badge_video.xml:
--------------------------------------------------------------------------------
1 |
7 |
11 |
12 |
--------------------------------------------------------------------------------
/daguerre/src/main/res/drawable/daguerre_ic_video.xml:
--------------------------------------------------------------------------------
1 |
7 |
11 |
12 |
--------------------------------------------------------------------------------
/daguerre/src/main/res/drawable/daguerre_btn_check_material.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/daguerre/src/main/java/com/jay/daguerre/widget/SquareFrameLayout.java:
--------------------------------------------------------------------------------
1 | package com.jay.daguerre.widget;
2 |
3 | import android.content.Context;
4 | import android.support.annotation.NonNull;
5 | import android.support.annotation.Nullable;
6 | import android.util.AttributeSet;
7 | import android.widget.FrameLayout;
8 |
9 | /**
10 | * Created by jay on 2017/11/24 下午5:26
11 | */
12 | public class SquareFrameLayout extends FrameLayout {
13 | public SquareFrameLayout(@NonNull Context context, @Nullable AttributeSet attrs) {
14 | super(context, attrs);
15 | }
16 |
17 | @Override
18 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
19 | super.onMeasure(widthMeasureSpec, widthMeasureSpec);
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 |
--------------------------------------------------------------------------------
/sample/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/daguerre/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/daguerre/src/main/java/com/jay/daguerre/provider/ImageLoader.java:
--------------------------------------------------------------------------------
1 | package com.jay.daguerre.provider;
2 |
3 |
4 | import android.content.Context;
5 | import android.widget.ImageView;
6 |
7 | /**
8 | * Created by jay on 2017/11/23 下午4:12
9 | */
10 | public interface ImageLoader {
11 | /**
12 | * 加载列表图片
13 | *
14 | * @param uri photo path
15 | */
16 | void loadImage(Context context, ImageView imageView, String uri, boolean isGif, boolean isVideo);
17 |
18 | /**
19 | * 加载预览大图
20 | *
21 | * @param uri photo path
22 | */
23 | void loadPreviewImage(Context context, ImageView imageView, String uri, boolean isGif, boolean isVideo);
24 |
25 | /**
26 | * 加载 Album 列表封面图片
27 | *
28 | * @param uri photo path
29 | */
30 | void loadAlbumImage(Context context, ImageView imageView, String uri);
31 | }
32 |
--------------------------------------------------------------------------------
/daguerre/src/main/res/drawable/daguerre_ic_camera.xml:
--------------------------------------------------------------------------------
1 |
7 |
11 |
15 |
16 |
--------------------------------------------------------------------------------
/sample/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 27
5 | buildToolsVersion '27.0.3'
6 | defaultConfig {
7 | applicationId "com.jay.daguerre.app"
8 | minSdkVersion 19
9 | targetSdkVersion 27
10 | versionCode 1
11 | versionName "1.0"
12 | vectorDrawables.useSupportLibrary = true
13 | }
14 |
15 | buildTypes {
16 | release {
17 | minifyEnabled false
18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
19 | }
20 | }
21 |
22 | }
23 |
24 | dependencies {
25 | implementation fileTree(include: ['*.jar'], dir: 'libs')
26 | implementation 'com.android.support:appcompat-v7:27.1.0'
27 | implementation project(':daguerre')
28 | implementation 'com.github.bumptech.glide:glide:4.3.1'
29 | }
30 |
--------------------------------------------------------------------------------
/daguerre/src/main/res/drawable/daguerre_circle_checked.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
10 |
11 |
15 |
18 |
19 |
--------------------------------------------------------------------------------
/sample/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/sample/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
18 |
19 |
--------------------------------------------------------------------------------
/daguerre/src/main/res/drawable/daguerre_circle_unchecked.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
21 |
25 |
26 |
--------------------------------------------------------------------------------
/daguerre/src/main/res/layout/daguerre_activity_preview_resource.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
13 |
14 |
18 |
19 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/daguerre/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
10 |
11 |
16 |
17 |
22 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
12 |
17 |
22 |
27 |
28 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/daguerre/src/main/java/com/jay/daguerre/internal/ConfigParams.java:
--------------------------------------------------------------------------------
1 | package com.jay.daguerre.internal;
2 |
3 | import com.jay.daguerre.provider.ImageLoader;
4 |
5 | /**
6 | * Created by jay on 2017/11/24 下午5:09
7 | */
8 | public class ConfigParams {
9 |
10 | private ImageLoader mImageLoader;
11 | private String[] mimeTypes;
12 | private int mimeType;
13 |
14 | private ConfigParams() {
15 | }
16 |
17 | public static ConfigParams getInstance() {
18 | return InstanceHolder.INSTANCE;
19 | }
20 |
21 |
22 | public ConfigParams setImageLoader(ImageLoader imageLoader) {
23 | mImageLoader = imageLoader;
24 | return this;
25 | }
26 |
27 | ImageLoader getImageLoader() {
28 | return mImageLoader;
29 | }
30 |
31 | public void setMimeType(int mimeType, String[] mimeTypes) {
32 | this.mimeType = mimeType;
33 | this.mimeTypes = mimeTypes;
34 | }
35 |
36 | String[] getMimeTypes() {
37 | return mimeTypes;
38 | }
39 |
40 | public int getMimeType() {
41 | return mimeType;
42 | }
43 |
44 | private static final class InstanceHolder {
45 | private static final ConfigParams INSTANCE = new ConfigParams();
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/daguerre/src/main/java/com/jay/daguerre/internal/BaseRecyclerAdapter.java:
--------------------------------------------------------------------------------
1 | package com.jay.daguerre.internal;
2 |
3 | import android.content.Context;
4 | import android.support.v4.view.LayoutInflaterCompat;
5 | import android.support.v7.widget.RecyclerView;
6 | import android.util.AttributeSet;
7 | import android.view.LayoutInflater;
8 | import android.view.View;
9 |
10 | import java.util.List;
11 |
12 | /**
13 | * Created by jay on 2017/11/23 下午4:14
14 | */
15 | abstract class BaseRecyclerAdapter extends RecyclerView.Adapter {
16 | final Context mContext;
17 | private List mDatas;
18 | LayoutInflater mLayoutInflater;
19 |
20 |
21 | BaseRecyclerAdapter(Context context) {
22 | this(context, null);
23 | }
24 |
25 | BaseRecyclerAdapter(Context context, List datas) {
26 | this.mContext = context;
27 | this.mDatas = datas;
28 | mLayoutInflater = LayoutInflater.from(mContext);
29 | }
30 |
31 | @Override
32 | public int getItemCount() {
33 | return mDatas != null ? mDatas.size() : 0;
34 | }
35 |
36 | public void setData(List datas) {
37 | mDatas = datas;
38 | }
39 |
40 | D getItem(int position) {
41 | return mDatas.get(position);
42 | }
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/daguerre/src/main/res/drawable/daguerre_ic_badge_gif.xml:
--------------------------------------------------------------------------------
1 |
7 |
11 |
12 |
--------------------------------------------------------------------------------
/daguerre/src/main/res/layout/daguerre_activity.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
12 |
15 |
16 |
20 |
21 |
27 |
28 |
29 |
36 |
37 |
--------------------------------------------------------------------------------
/daguerre/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'com.github.dcendents.android-maven' // ADD THIS
3 |
4 | group='com.github.qiujayen'
5 | android {
6 | compileSdkVersion 27
7 | defaultConfig {
8 | minSdkVersion 16
9 | targetSdkVersion 27
10 | versionCode 8
11 | versionName "1.0.8"
12 | vectorDrawables.useSupportLibrary = true
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | buildToolsVersion '27.0.3'
21 | }
22 |
23 | dependencies {
24 | implementation fileTree(include: ['*.jar'], dir: 'libs')
25 | implementation 'com.android.support:appcompat-v7:27.1.0'
26 | implementation 'com.android.support:recyclerview-v7:27.1.0'
27 | implementation 'com.github.chrisbanes:PhotoView:2.1.3'
28 | }
29 | // build a jar with source files
30 | task sourcesJar(type: Jar) {
31 | from android.sourceSets.main.java.srcDirs
32 | classifier = 'sources'
33 | }
34 |
35 | task javadoc(type: Javadoc) {
36 | failOnError false
37 | source = android.sourceSets.main.java.sourceFiles
38 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
39 | classpath += configurations.compile
40 | }
41 |
42 | // build a jar with javadoc
43 | task javadocJar(type: Jar, dependsOn: javadoc) {
44 | classifier = 'javadoc'
45 | from javadoc.destinationDir
46 | }
47 |
48 | artifacts {
49 | archives sourcesJar
50 | archives javadocJar
51 | }
--------------------------------------------------------------------------------
/daguerre/src/main/res/layout/daguerre_resource_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
10 |
17 |
18 |
24 |
25 |
31 |
32 |
--------------------------------------------------------------------------------
/daguerre/src/main/java/com/jay/daguerre/internal/PreviewResourceAdapter.java:
--------------------------------------------------------------------------------
1 | package com.jay.daguerre.internal;
2 |
3 | import android.content.Context;
4 | import android.support.v7.widget.RecyclerView;
5 | import android.view.View;
6 | import android.view.ViewGroup;
7 | import android.widget.ImageView;
8 |
9 | import com.jay.daguerre.R;
10 | import com.jay.daguerre.provider.ImageLoader;
11 |
12 | import java.util.List;
13 |
14 | /**
15 | * Created by jay on 2017/11/27 下午4:31
16 | */
17 | class PreviewResourceAdapter extends BaseRecyclerAdapter {
18 |
19 |
20 | PreviewResourceAdapter(Context context, List datas) {
21 | super(context, datas);
22 | }
23 |
24 | @Override
25 | public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
26 | View inflate = mLayoutInflater.inflate(R.layout.daguerre_preview_resource_item, parent, false);
27 | return new ViewHolder(inflate);
28 | }
29 |
30 | @Override
31 | public void onBindViewHolder(ViewHolder holder, int position) {
32 | ImageLoader imageLoader = ConfigParams.getInstance().getImageLoader();
33 | if (imageLoader != null) {
34 | Media.Resource item = getItem(position);
35 | imageLoader.loadPreviewImage(mContext, holder.mImageView, item.data, item.isGif(), item.isVideo());
36 | }
37 | }
38 |
39 | static class ViewHolder extends RecyclerView.ViewHolder {
40 |
41 | private final ImageView mImageView;
42 |
43 | ViewHolder(View itemView) {
44 | super(itemView);
45 | mImageView = itemView.findViewById(R.id.image);
46 | }
47 | }
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/daguerre/src/main/res/layout/daguerre_albums_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
18 |
19 |
25 |
26 |
33 |
34 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/daguerre/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
21 |
22 |
25 |
26 |
31 |
--------------------------------------------------------------------------------
/sample/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/daguerre/src/main/java/com/jay/daguerre/MimeType.java:
--------------------------------------------------------------------------------
1 | package com.jay.daguerre;
2 |
3 | /**
4 | * Created by jay on 2017/11/29 下午4:28
5 | */
6 | public final class MimeType {
7 |
8 | /**
9 | * image
10 | */
11 | public final static int IMAGE = 1;
12 | /**
13 | * video
14 | */
15 | public final static int VIDEO = 2;
16 | /**
17 | * image + video
18 | */
19 | public final static int IMAGE_AND_VIDEO = 3;
20 |
21 | // IMAGE
22 | public final static String JPG = "image/jpeg";
23 | public final static String JPEG = "image/jpeg";
24 | public final static String GIF = "image/gif";
25 | public final static String PNG = "image/png";
26 | public final static String BMP = "image/x-ms-bmp";
27 | public final static String WBMP = "image/vnd.wap.wbmp";
28 | public final static String DNG = "image/x-adobe-dng";
29 | public final static String CR2 = "image/x-canon-cr2";
30 | public final static String NEF = "image/x-nikon-nef";
31 | public final static String NRW = "image/x-nikon-nrw";
32 | public final static String ARW = "image/x-sony-arw";
33 | public final static String RW2 = "image/x-panasonic-rw2";
34 | public final static String ORF = "image/x-olympus-orf";
35 | public final static String RAF = "image/x-fuji-raf";
36 | public final static String PEF = "image/x-pentax-pef";
37 | public final static String SRW = "image/x-samsung-srw";
38 |
39 | // VIDEO
40 | public final static String MPEG = "video/mpeg";
41 | public final static String MPG = "video/mpeg";
42 | public final static String MP4 = "video/mp4";
43 | public final static String M4V = "video/mp4";
44 | public final static String MOV = "video/quicktime";
45 | public final static String THREEGP = "video/3gpp";
46 | public final static String THREEGPP = "video/3gpp";
47 | public final static String THREEG2 = "video/3gpp2";
48 | public final static String THREEGPP2 = "video/3gpp2";
49 | public final static String MKV = "video/x-matroska";
50 | public final static String WEBM = "video/webm";
51 | public final static String TS = "video/mp2ts";
52 | public final static String AVI = "video/avi";
53 | public final static String WMV = "video/x-ms-wmv";
54 | public final static String ASF = "video/x-ms-asf";
55 | }
56 |
--------------------------------------------------------------------------------
/daguerre/src/main/java/com/jay/daguerre/internal/Media.java:
--------------------------------------------------------------------------------
1 | package com.jay.daguerre.internal;
2 |
3 | import com.jay.daguerre.MimeType;
4 |
5 | import java.util.ArrayList;
6 |
7 | /**
8 | * Created by jay on 2017/11/23 下午3:29
9 | */
10 | final class Media {
11 | static class Resource{
12 | String id;
13 | String data = ""; //file path
14 | // long size;
15 | String displayName = ""; // xxx.jpg
16 | String mineType; // image/jpeg
17 | // String title;
18 | // long dateAdded; // 时间戳
19 | // long dateModified; // 时间戳
20 | // String description;
21 | // String picasaId;
22 | // String isPrivate;
23 | // String latitude;
24 | // String longitude;
25 | // String dateTaken;
26 | // int orientation;
27 | // String miniThumbMagic;
28 | // String bucketId;
29 | String bucketDisplayName = "";
30 | // int width;
31 | // int height;
32 | boolean isChecked;
33 |
34 | public Resource(String id, String data, String displayName, String mineType, String bucketDisplayName) {
35 | this.id = id;
36 | this.data = data;
37 | this.displayName = displayName;
38 | this.mineType = mineType;
39 | this.bucketDisplayName = bucketDisplayName;
40 | }
41 |
42 | public boolean isVideo() {
43 | return mineType != null && mineType.contains("video");
44 | }
45 |
46 | public boolean isGif() {
47 | return mineType != null && mineType.equals(MimeType.GIF);
48 | }
49 |
50 | }
51 |
52 | static class Album {
53 | String name;
54 | Resource cover;
55 | ArrayList resources = new ArrayList<>();
56 | int resourceCount;
57 | }
58 |
59 | static ResourceStore getResourceStoreInstance() {
60 | return ResourceStore.instance;
61 | }
62 |
63 | static class ResourceStore{
64 |
65 | private ArrayList mResources = new ArrayList<>();
66 | static ResourceStore instance = new ResourceStore();
67 |
68 | private ResourceStore() {
69 |
70 | }
71 |
72 | ArrayList getResources() {
73 | return mResources;
74 | }
75 | }
76 | }
--------------------------------------------------------------------------------
/daguerre/src/main/java/com/jay/daguerre/internal/PreviewResourceActivity.java:
--------------------------------------------------------------------------------
1 | package com.jay.daguerre.internal;
2 |
3 | import android.content.Intent;
4 | import android.os.Build;
5 | import android.os.Bundle;
6 | import android.support.annotation.Nullable;
7 | import android.support.v7.app.ActionBar;
8 | import android.support.v7.app.AppCompatActivity;
9 | import android.support.v7.widget.LinearLayoutManager;
10 | import android.support.v7.widget.PagerSnapHelper;
11 | import android.support.v7.widget.RecyclerView;
12 | import android.support.v7.widget.Toolbar;
13 | import android.view.MenuItem;
14 |
15 | import com.jay.daguerre.R;
16 |
17 | import java.util.ArrayList;
18 |
19 | /**
20 | * Created by jay on 2017/11/27 下午3:12
21 | */
22 | public class PreviewResourceActivity extends AppCompatActivity{
23 | @Override
24 | protected void onCreate(@Nullable Bundle savedInstanceState) {
25 | super.onCreate(savedInstanceState);
26 | Intent intent = getIntent();
27 | int position = intent.getIntExtra("position", 0);
28 | ArrayList images = Media.getResourceStoreInstance().getResources();
29 |
30 | setContentView(R.layout.daguerre_activity_preview_resource);
31 | Toolbar toolbar = findViewById(R.id.toolbar);
32 | setSupportActionBar(toolbar);
33 |
34 | ActionBar actionBar = getSupportActionBar();
35 | assert actionBar != null;
36 | actionBar.setDisplayShowTitleEnabled(false);
37 | actionBar.setDisplayHomeAsUpEnabled(true);
38 |
39 |
40 |
41 | RecyclerView recyclerView = findViewById(R.id.recycler_view);
42 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
43 | recyclerView.setTransitionName("element");
44 | }
45 |
46 | recyclerView.setHasFixedSize(true);
47 | recyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false));
48 | new PagerSnapHelper().attachToRecyclerView(recyclerView);
49 |
50 |
51 | PreviewResourceAdapter adapter = new PreviewResourceAdapter(this, images);
52 | recyclerView.setAdapter(adapter);
53 | recyclerView.scrollToPosition(position);
54 | }
55 |
56 | @Override
57 | public boolean onOptionsItemSelected(MenuItem item) {
58 | if (item.getItemId() == android.R.id.home) {
59 | onBackPressed();
60 | return true;
61 | }
62 | return super.onOptionsItemSelected(item);
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/daguerre/src/main/java/com/jay/daguerre/internal/AlbumsItemAdapter.java:
--------------------------------------------------------------------------------
1 | package com.jay.daguerre.internal;
2 |
3 | import android.content.Context;
4 | import android.support.v7.widget.RecyclerView;
5 | import android.view.View;
6 | import android.view.ViewGroup;
7 | import android.widget.ImageView;
8 | import android.widget.TextView;
9 |
10 | import com.jay.daguerre.R;
11 | import com.jay.daguerre.provider.ImageLoader;
12 |
13 | /**
14 | * Created by jay on 2017/11/29 上午10:18
15 | */
16 | class AlbumsItemAdapter extends BaseRecyclerAdapter {
17 |
18 |
19 | private OnItemClickListener mOnItemClickListener;
20 |
21 | AlbumsItemAdapter(Context context) {
22 | super(context);
23 | }
24 |
25 | @Override
26 | public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
27 | View inflate = mLayoutInflater.inflate(R.layout.daguerre_albums_item, parent, false);
28 | return new ViewHolder(inflate);
29 | }
30 |
31 | @Override
32 | public void onBindViewHolder(ViewHolder holder, int position) {
33 | Media.Album item = getItem(position);
34 | holder.mTextName.setText(item.name);
35 | holder.mTextCount.setText(mContext.getString(R.string.daguerre_albums_member_count, item.resourceCount));
36 | ImageLoader imageLoader = ConfigParams.getInstance().getImageLoader();
37 | if (imageLoader != null) {
38 | imageLoader.loadAlbumImage(mContext, holder.mImage, item.cover.data);
39 | }
40 |
41 | holder.itemView.setOnClickListener(new View.OnClickListener() {
42 | @Override
43 | public void onClick(View v) {
44 | if (mOnItemClickListener != null) {
45 | mOnItemClickListener.onAlbumsItemClick(v);
46 | }
47 | }
48 | });
49 | }
50 |
51 | void setOnItemClickListener(OnItemClickListener onItemClickListener) {
52 | mOnItemClickListener = onItemClickListener;
53 | }
54 |
55 | static class ViewHolder extends RecyclerView.ViewHolder {
56 |
57 | private final ImageView mImage;
58 | private final TextView mTextName;
59 | private final TextView mTextCount;
60 |
61 | ViewHolder(View itemView) {
62 | super(itemView);
63 | mImage = itemView.findViewById(R.id.image);
64 | mTextName = itemView.findViewById(R.id.text_name);
65 | mTextCount = itemView.findViewById(R.id.text_count);
66 | }
67 | }
68 |
69 | interface OnItemClickListener {
70 | void onAlbumsItemClick(View itemView);
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/daguerre/src/main/java/com/jay/daguerre/internal/ResourceItemAdapter.java:
--------------------------------------------------------------------------------
1 | package com.jay.daguerre.internal;
2 |
3 | import android.content.Context;
4 | import android.support.v7.widget.RecyclerView;
5 | import android.view.View;
6 | import android.view.ViewGroup;
7 | import android.widget.CheckBox;
8 | import android.widget.CompoundButton;
9 | import android.widget.ImageView;
10 |
11 | import com.jay.daguerre.R;
12 | import com.jay.daguerre.provider.ImageLoader;
13 |
14 | /**
15 | * Created by jay on 2017/11/23 下午4:57
16 | */
17 | class ResourceItemAdapter extends BaseRecyclerAdapter {
18 |
19 |
20 | private CompoundButton.OnCheckedChangeListener mOnCheckedChangeListener;
21 | private OnItemClickListener mOnItemClickListener;
22 |
23 | ResourceItemAdapter(Context context) {
24 | super(context);
25 | }
26 |
27 | @Override
28 | public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
29 | View inflate = mLayoutInflater.inflate(R.layout.daguerre_resource_item, parent, false);
30 | return new ViewHolder(inflate);
31 | }
32 |
33 | @Override
34 | public void onBindViewHolder(ViewHolder holder, int position) {
35 | ImageLoader imageLoader = ConfigParams.getInstance().getImageLoader();
36 | Media.Resource item = getItem(position);
37 | if (imageLoader != null) {
38 | imageLoader.loadImage(mContext, holder.mImage, item.data, item.isGif(), item.isVideo());
39 | }
40 | holder.itemView.setOnClickListener(new View.OnClickListener() {
41 | @Override
42 | public void onClick(View v) {
43 | if (mOnItemClickListener != null) {
44 | mOnItemClickListener.onListItemClick(v);
45 | }
46 | }
47 | });
48 | holder.mImageFlagIcon.setVisibility(View.VISIBLE);
49 | if (item.isGif()) {
50 | holder.mImageFlagIcon.setImageResource(R.drawable.daguerre_ic_badge_gif);
51 | } else if (item.isVideo()) {
52 | holder.mImageFlagIcon.setImageResource(R.drawable.daguerre_ic_badge_video);
53 | } else {
54 | holder.mImageFlagIcon.setVisibility(View.GONE);
55 | }
56 | holder.mCheckBox.setChecked(getItem(position).isChecked);
57 | holder.mCheckBox.setOnCheckedChangeListener(mOnCheckedChangeListener);
58 | }
59 |
60 | void setOnCheckedChangeListener(CompoundButton.OnCheckedChangeListener listener) {
61 | mOnCheckedChangeListener = listener;
62 | }
63 |
64 | void setOnItemClickListener(OnItemClickListener onItemClickListener) {
65 | mOnItemClickListener = onItemClickListener;
66 | }
67 |
68 | interface OnItemClickListener {
69 | void onListItemClick(View itemView);
70 | }
71 |
72 | static class ViewHolder extends RecyclerView.ViewHolder {
73 |
74 | private final ImageView mImage;
75 | private final ImageView mImageFlagIcon;
76 | private final CheckBox mCheckBox;
77 |
78 | ViewHolder(View itemView) {
79 | super(itemView);
80 | mImage = itemView.findViewById(R.id.image);
81 | mImageFlagIcon = itemView.findViewById(R.id.image_flag_icon);
82 | mCheckBox = itemView.findViewById(android.R.id.checkbox);
83 | }
84 | }
85 | }
86 |
--------------------------------------------------------------------------------
/daguerre/src/main/java/com/jay/daguerre/Daguerre.java:
--------------------------------------------------------------------------------
1 | package com.jay.daguerre;
2 |
3 | import android.app.Activity;
4 | import android.content.Context;
5 | import android.content.Intent;
6 | import android.support.annotation.StyleRes;
7 | import android.support.v4.app.Fragment;
8 |
9 | import com.jay.daguerre.internal.ConfigParams;
10 | import com.jay.daguerre.internal.DaguerreActivity;
11 | import com.jay.daguerre.provider.ImageLoader;
12 |
13 | import java.util.ArrayList;
14 |
15 | /**
16 | * Created by jay on 2017/11/23 下午3:03
17 | * daguerre main class
18 | */
19 | public final class Daguerre {
20 |
21 | public final static String INTENT_EXTRA_KEY_MAX = "maxSelectable";
22 | public final static String INTENT_EXTRA_KEY_SPAN_COUNT = "spanCount";
23 | public final static String INTENT_EXTRA_KEY_THEME = "theme";
24 | public final static String INTENT_EXTRA_RESULT = "result";
25 |
26 | private Activity mActivity;
27 | private Fragment mFragment;
28 | private Intent mIntent;
29 |
30 | private Daguerre(Activity activity) {
31 | mActivity = activity;
32 | mIntent = new Intent(activity, DaguerreActivity.class);
33 | }
34 |
35 | private Daguerre(Fragment fragment) {
36 | mFragment = fragment;
37 | mIntent = new Intent(fragment.getContext(), DaguerreActivity.class);
38 | }
39 |
40 | public static Daguerre with(Activity activity) {
41 | return new Daguerre(activity);
42 | }
43 |
44 | public static Daguerre with(Fragment fragment) {
45 | return new Daguerre(fragment);
46 | }
47 |
48 | /**
49 | * 设置图片加载器
50 | *
51 | * @param imageLoader {@link ImageLoader}
52 | */
53 | public Daguerre setImageLoader(ImageLoader imageLoader) {
54 | ConfigParams.getInstance().setImageLoader(imageLoader);
55 | return this;
56 | }
57 |
58 | /**
59 | * 设置最大选择数据,默认为1
60 | *
61 | * @param max value
62 | */
63 | public Daguerre maxSelectable(int max) {
64 | mIntent.putExtra(INTENT_EXTRA_KEY_MAX, max);
65 | return this;
66 | }
67 |
68 | /**
69 | * 设置列表列数
70 | *
71 | * @param spanCount 列数
72 | */
73 | public Daguerre spanCount(int spanCount) {
74 | mIntent.putExtra(INTENT_EXTRA_KEY_SPAN_COUNT, spanCount);
75 | return this;
76 | }
77 |
78 | /**
79 | * 设置主题样式
80 | *
81 | * @param theme 主题样式资源
82 | */
83 | public Daguerre theme(@StyleRes int theme) {
84 | mIntent.putExtra(INTENT_EXTRA_KEY_THEME, theme);
85 | return this;
86 | }
87 |
88 | /**
89 | * 设置 mine 类型
90 | *
91 | * @param mimeTypes mine 类型,可传多个
92 | */
93 | public Daguerre mimeType(int mimeType, String... mimeTypes) {
94 | ConfigParams.getInstance().setMimeType(mimeType,mimeTypes);
95 | return this;
96 | }
97 |
98 | /**
99 | * @return 获得选择结果的第一个,一般单选操作时调用此方法
100 | */
101 | public static String obtainResult(Intent data) {
102 | ArrayList result = data.getStringArrayListExtra(INTENT_EXTRA_RESULT);
103 | return result.get(0);
104 | }
105 |
106 | /**
107 | * @return 获得选择结果集
108 | */
109 | public static ArrayList obtainResultSet(Intent data) {
110 | return data.getStringArrayListExtra(INTENT_EXTRA_RESULT);
111 | }
112 |
113 | /**
114 | * 启动库
115 | *
116 | * @param requestCode 请求码,用于返回给 {@link Activity#onActivityResult(int, int, Intent)} 判断操作类型
117 | */
118 | public void launch(int requestCode) {
119 | if (mActivity != null) {
120 | mActivity.startActivityForResult(mIntent, requestCode);
121 | } else if (mFragment != null) {
122 | mFragment.startActivityForResult(mIntent, requestCode);
123 | }
124 | }
125 | }
126 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | [](https://jitpack.io/#qiujayen/Daguerre)
2 |
3 | # Daguerre
4 | 一个`Android`本地图片和视频的选择器
5 | - 可以在Activity或Fragment中使用
6 | - 选择图片支持多种格式,如:JPEG, PNG, GIF
7 | - 选择视频支持多种格式,如:3GP, MPEG, MP4
8 | - 可以自定义主题样式
9 | - 可自定义不同的图片加载器
10 |
11 | | Select Image 1 | Select Image 1 | Preview |
12 | |:------------------------------:|:---------------------------------:|:--------------------------------:|
13 | | |  | |
14 |
15 | ## Download Demo Apk
16 | |[apk](apk/sample-debug.apk)|
17 | |:-:|
18 | ||
19 |
20 | ## How to
21 | ### Step 1. Add the JitPack repository to your build file
22 | Add it in your root build.gradle at the end of repositories:
23 | ```groovy
24 | allprojects {
25 | repositories {
26 | ...
27 | maven { url 'https://jitpack.io' }
28 | }
29 | }
30 | ```
31 |
32 | ### Step 2. Add the dependency
33 | ```groovy
34 | dependencies {
35 | implementation 'com.github.qiujayen:Daguerre:last-version'
36 | }
37 | ```
38 | ### This library dependencies
39 | ```groovy
40 | implementation 'com.android.support:appcompat-v7:version code'
41 | implementation 'com.android.support:recyclerview-v7:version code'
42 | implementation 'com.github.chrisbanes:PhotoView:version code'
43 | ```
44 |
45 | ## How to use Daguerre?
46 | #### Permission
47 | The library requires two permissions:
48 | - `android.permission.READ_EXTERNAL_STORAGE`
49 | - `android.permission.WRITE_EXTERNAL_STORAGE`
50 |
51 | So if you are targeting Android 6.0+, you need to handle runtime permission request before next step.
52 |
53 | #### Simple use
54 | ```java
55 | Daguerre.with(this)
56 | .theme(R.style.CustomTheme) // 设置主题样式,不设置则使用默认主题
57 | .spanCount(3) // 设置列表列数,默认为3
58 | .maxSelectable(3) // 设置最大选择数据,默认为1
59 | .mimeType(MimeType.IMAGE, MimeType.JPEG) // 设置mimeType,默认会显示所有图片与视频
60 | .setImageLoader(new ImageLoader()) // 设置图片加载器,必须设置的参数,否则图片等资源无法显示
61 | .launch(REQUEST_CODE);
62 | ```
63 | #### Obtain Result
64 | ```java
65 | @Override
66 | protected void onActivityResult(int requestCode, int resultCode, Intent data) {
67 | super.onActivityResult(requestCode, resultCode, data);
68 | if (requestCode == PHOTO && resultCode == RESULT_OK) {
69 | ArrayList photos = Daguerre.obtainResultSet(data);
70 | } else if (requestCode == VIDEO && resultCode == RESULT_OK) {
71 | String videoPath = Daguerre.obtainResult(data);
72 | }
73 | }
74 | ```
75 |
76 | #### Themes attrs
77 |
78 | | attr | doc | default value|
79 | |:------------------------------|:------------------------------|:------------------------------:|
80 | | daguerreCheckButtonColor | 选择图片 CheckBox 按钮颜色 | white |
81 | | daguerreActionDrawableColor | ActionBar 菜单图标颜色 | white |
82 | | daguerreActionModeDrawableColor| ActionMode 确认按钮图标颜色 | white |
83 | | daguerreBadgeColor | 列表中标记视频的图标颜色 | white |
84 |
85 | #### Themes Style
86 | 参考`Activity`主题样式设置
87 |
88 | #### More
89 | Find more details about Daguerre in [wiki](https://github.com/qiujayen/Daguerre/wiki).
90 |
91 | ## Thanks
92 | This library is inspired by [Matisse](https://github.com/zhihu/Matisse) and uses some of its source code.
93 |
94 | ## License
95 | Copyright 2017 QiuJay Inc.
96 |
97 | Licensed under the Apache License, Version 2.0 (the "License");
98 | you may not use this file except in compliance with the License.
99 | You may obtain a copy of the License at
100 |
101 | http://www.apache.org/licenses/LICENSE-2.0
102 |
103 | Unless required by applicable law or agreed to in writing, software
104 | distributed under the License is distributed on an "AS IS" BASIS,
105 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
106 | See the License for the specific language governing permissions and
107 | limitations under the License.
108 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/jay/daguerre/app/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.jay.daguerre.app;
2 |
3 | import android.content.Context;
4 | import android.content.Intent;
5 | import android.os.Bundle;
6 | import android.os.CountDownTimer;
7 | import android.support.v7.app.AppCompatActivity;
8 | import android.support.v7.app.AppCompatDelegate;
9 | import android.view.View;
10 | import android.widget.ImageView;
11 | import android.widget.TextView;
12 |
13 | import com.bumptech.glide.Glide;
14 | import com.bumptech.glide.load.engine.DiskCacheStrategy;
15 | import com.bumptech.glide.request.RequestOptions;
16 | import com.jay.daguerre.Daguerre;
17 | import com.jay.daguerre.MimeType;
18 | import com.jay.daguerre.provider.ImageLoader;
19 |
20 | import java.text.SimpleDateFormat;
21 | import java.util.ArrayList;
22 | import java.util.Date;
23 |
24 | public class MainActivity extends AppCompatActivity implements View.OnClickListener {
25 |
26 | private static final int PHOTO = 123;
27 | private static final int VIDEO = 124;
28 | private TextView mTextResult;
29 | @Override
30 | protected void onCreate(Bundle savedInstanceState) {
31 | super.onCreate(savedInstanceState);
32 | setContentView(R.layout.activity_main);
33 |
34 | findViewById(R.id.btn_photo).setOnClickListener(this);
35 | findViewById(R.id.btn_video).setOnClickListener(this);
36 | findViewById(R.id.btn_image_video).setOnClickListener(this);
37 | mTextResult = findViewById(R.id.text_result);
38 |
39 |
40 | }
41 |
42 | @Override
43 | public void onClick(View v) {
44 | switch (v.getId()) {
45 | case R.id.btn_photo:
46 | Daguerre.with(this)
47 | .theme(R.style.DaguerreTheme) // 设置主题样式
48 | .spanCount(3) // 设置列表列数,默认为3
49 | .maxSelectable(3) // 设置最大选择数据,默认为1
50 | .mimeType(MimeType.IMAGE, MimeType.JPEG) // 设置mimeType,默认会显示所有图片与视频
51 | .setImageLoader(new MyImageLoader()) // 设置图片加载器,必须设置的参数,否则图片等资源无法显示
52 | .launch(PHOTO);
53 | break;
54 | case R.id.btn_video:
55 | Daguerre.with(this)
56 | .theme(R.style.DaguerreTheme) // 设置主题样式
57 | .spanCount(2) // 设置列表列数,默认为3
58 | .maxSelectable(1) // 设置最大选择数据,默认为1
59 | .mimeType(MimeType.VIDEO, MimeType.MP4) // 设置mimeType,默认会显示所有图片与视频
60 | .setImageLoader(new MyImageLoader()) // 设置图片加载器,必须设置的参数,否则图片等资源无法显示
61 | .launch(VIDEO);
62 | break;
63 | case R.id.btn_image_video:
64 | Daguerre.with(this)
65 | .theme(R.style.DaguerreTheme) // 设置主题样式
66 | .spanCount(4) // 设置列表列数,默认为3
67 | .maxSelectable(1) // 设置最大选择数据,默认为1
68 | .mimeType(MimeType.IMAGE_AND_VIDEO, MimeType.MP4, MimeType.JPEG, MimeType.GIF) // 设置mimeType,默认会显示所有图片与视频
69 | .setImageLoader(new MyImageLoader()) // 设置图片加载器,必须设置的参数,否则图片等资源无法显示
70 | .launch(VIDEO);
71 | break;
72 | default:
73 | }
74 | }
75 |
76 | @Override
77 | protected void onActivityResult(int requestCode, int resultCode, Intent data) {
78 | super.onActivityResult(requestCode, resultCode, data);
79 | if (requestCode == PHOTO && resultCode == RESULT_OK) {
80 | ArrayList photos = Daguerre.obtainResultSet(data);
81 | mTextResult.setText("");
82 | for (String photo : photos) {
83 | mTextResult.append(photo);
84 | mTextResult.append("\n");
85 | }
86 | } else if (requestCode == VIDEO && resultCode == RESULT_OK) {
87 | String videoPath = Daguerre.obtainResult(data);
88 | mTextResult.setText(videoPath);
89 | }
90 | }
91 |
92 | class MyImageLoader implements ImageLoader {
93 |
94 | @Override
95 | public void loadImage(Context context, ImageView imageView, String uri, boolean isGif, boolean isVideo) {
96 | RequestOptions requestOptions = new RequestOptions()
97 | .centerCrop().diskCacheStrategy(DiskCacheStrategy.NONE)
98 | .override(120, 120);
99 | Glide.with(context).load(uri).apply(requestOptions).into(imageView);
100 | }
101 |
102 | @Override
103 | public void loadPreviewImage(Context context, ImageView imageView, String uri, boolean isGif, boolean isVideo) {
104 | RequestOptions requestOptions = new RequestOptions()
105 | .diskCacheStrategy(DiskCacheStrategy.NONE);
106 | Glide.with(context).load(uri).apply(requestOptions).into(imageView);
107 | }
108 |
109 | @Override
110 | public void loadAlbumImage(Context context, ImageView imageView, String uri) {
111 | RequestOptions requestOptions = new RequestOptions()
112 | .centerCrop().diskCacheStrategy(DiskCacheStrategy.NONE)
113 | .override(120, 120);
114 | Glide.with(context).load(uri).apply(requestOptions).into(imageView);
115 | }
116 | }
117 | }
118 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/sample/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
11 |
16 |
21 |
26 |
31 |
36 |
41 |
46 |
51 |
56 |
61 |
66 |
71 |
76 |
81 |
86 |
91 |
96 |
101 |
106 |
111 |
116 |
121 |
126 |
131 |
136 |
141 |
146 |
151 |
156 |
161 |
166 |
171 |
172 |
--------------------------------------------------------------------------------
/daguerre/src/main/java/com/jay/daguerre/internal/DaguerreActivity.java:
--------------------------------------------------------------------------------
1 | package com.jay.daguerre.internal;
2 |
3 | import android.Manifest;
4 | import android.app.LoaderManager;
5 | import android.content.CursorLoader;
6 | import android.content.Intent;
7 | import android.content.Loader;
8 | import android.content.pm.PackageManager;
9 | import android.database.Cursor;
10 | import android.graphics.Rect;
11 | import android.net.Uri;
12 | import android.os.Build;
13 | import android.os.Bundle;
14 | import android.os.Environment;
15 | import android.provider.MediaStore;
16 | import android.support.annotation.NonNull;
17 | import android.support.annotation.Nullable;
18 | import android.support.v4.app.ActivityCompat;
19 | import android.support.v4.app.ActivityOptionsCompat;
20 | import android.support.v4.content.ContextCompat;
21 | import android.support.v4.content.FileProvider;
22 | import android.support.v4.widget.ContentLoadingProgressBar;
23 | import android.support.v4.widget.DrawerLayout;
24 | import android.support.v7.app.ActionBar;
25 | import android.support.v7.app.ActionBarDrawerToggle;
26 | import android.support.v7.app.AppCompatActivity;
27 | import android.support.v7.view.ActionMode;
28 | import android.support.v7.widget.DividerItemDecoration;
29 | import android.support.v7.widget.GridLayoutManager;
30 | import android.support.v7.widget.LinearLayoutManager;
31 | import android.support.v7.widget.RecyclerView;
32 | import android.support.v7.widget.Toolbar;
33 | import android.text.TextUtils;
34 | import android.view.Menu;
35 | import android.view.MenuItem;
36 | import android.view.View;
37 | import android.widget.CompoundButton;
38 | import android.widget.Toast;
39 |
40 | import com.jay.daguerre.Daguerre;
41 | import com.jay.daguerre.MimeType;
42 | import com.jay.daguerre.R;
43 |
44 | import java.io.File;
45 | import java.text.SimpleDateFormat;
46 | import java.util.ArrayList;
47 | import java.util.Date;
48 | import java.util.Locale;
49 |
50 | /**
51 | * Created by jay on 2017/11/23 下午3:09
52 | */
53 | public class DaguerreActivity extends AppCompatActivity
54 | implements LoaderManager.LoaderCallbacks,
55 | ActionMode.Callback,
56 | CompoundButton.OnCheckedChangeListener,
57 | ResourceItemAdapter.OnItemClickListener,
58 | AlbumsItemAdapter.OnItemClickListener {
59 | private static final int REQUEST_READ_EXTERNAL_STORAGE_PERMISSION = 123;
60 | private static final int REQUEST_CAMERA_IMAGE = 124;
61 | private static final int REQUEST_CAMERA_VIDEO = 125;
62 | private static final int REQUEST_CAMERA_APP = 126;
63 |
64 | private static final String _ID = MediaStore.Files.FileColumns._ID;
65 | private static final String DATA = MediaStore.Files.FileColumns.DATA;
66 | private static final String DISPLAY_NAME = MediaStore.Files.FileColumns.DISPLAY_NAME;
67 | private static final String MIME_TYPE = MediaStore.Files.FileColumns.MIME_TYPE;
68 | private static final String BUCKET_DISPLAY_NAME = "bucket_display_name";
69 | private static final String[] COLUMNS_NAME = {
70 | _ID,
71 | DATA,
72 | DISPLAY_NAME,
73 | MIME_TYPE, BUCKET_DISPLAY_NAME
74 | };
75 |
76 | private ArrayList mResources = Media.getResourceStoreInstance().getResources();
77 | private ArrayList mAlbums = new ArrayList<>();
78 | private RecyclerView mRecyclerView;
79 | private ResourceItemAdapter mAdapter;
80 | private ActionMode mActionModel;
81 |
82 | private ArrayList mSelectResources = new ArrayList<>();
83 | /**
84 | * 最大选择数量
85 | */
86 | private int max = 1;
87 | private File mCameraOutPutFile;
88 | private RecyclerView mNavRecyclerView;
89 | private AlbumsItemAdapter mAlbumsItemAdapter;
90 | private DrawerLayout mDrawerLayout;
91 | private ContentLoadingProgressBar mContentLoadingProgressBar;
92 |
93 | @Override
94 | protected void onSaveInstanceState(Bundle outState) {
95 | super.onSaveInstanceState(outState);
96 | if (mCameraOutPutFile != null) {
97 | outState.putString("take_photo_file", mCameraOutPutFile.getAbsolutePath());
98 | }
99 | }
100 |
101 | @Override
102 | protected void onCreate(@Nullable Bundle savedInstanceState) {
103 | Intent intent = getIntent();
104 | int theme = intent.getIntExtra(Daguerre.INTENT_EXTRA_KEY_THEME, R.style.Daguerre_Activity_Theme);
105 | setTheme(theme);
106 | super.onCreate(savedInstanceState);
107 | setContentView(R.layout.daguerre_activity);
108 | ActionBar actionBar = getSupportActionBar();
109 | assert actionBar != null;
110 | actionBar.setDisplayHomeAsUpEnabled(true);
111 |
112 | Toolbar toolbar = findViewById(android.support.v7.appcompat.R.id.action_bar);
113 | mDrawerLayout = findViewById(R.id.drawer_layout);
114 | ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
115 | this, mDrawerLayout, toolbar, 0, 0);
116 | mDrawerLayout.addDrawerListener(toggle);
117 | toggle.syncState();
118 |
119 | mContentLoadingProgressBar = findViewById(R.id.content_progress_bar);
120 |
121 | if (savedInstanceState != null) {
122 | // 恢复数据
123 | String take_photo_file = savedInstanceState.getString("take_photo_file", null);
124 | if (!TextUtils.isEmpty(take_photo_file)) {
125 | mCameraOutPutFile = new File(take_photo_file);
126 | }
127 | }
128 |
129 | max = intent.getIntExtra(Daguerre.INTENT_EXTRA_KEY_MAX, 1);
130 |
131 | int spanCount = intent.getIntExtra(Daguerre.INTENT_EXTRA_KEY_SPAN_COUNT, 3);
132 |
133 | mRecyclerView = findViewById(R.id.recycler_view);
134 | mRecyclerView.setHasFixedSize(true);
135 | mRecyclerView.setLayoutManager(new GridLayoutManager(this, spanCount));
136 | mRecyclerView.addItemDecoration(new RecyclerView.ItemDecoration() {
137 | @Override
138 | public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
139 | outRect.set(16, 16, 16, 16);
140 | }
141 | });
142 |
143 | mAdapter = new ResourceItemAdapter(this);
144 | mAdapter.setOnItemClickListener(this);
145 | mAdapter.setOnCheckedChangeListener(this);
146 | mRecyclerView.setAdapter(mAdapter);
147 |
148 |
149 | mNavRecyclerView = findViewById(R.id.nav_recycler_view);
150 | mNavRecyclerView.setHasFixedSize(true);
151 | mNavRecyclerView.setLayoutManager(new LinearLayoutManager(this));
152 | mNavRecyclerView.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL));
153 |
154 | mAlbumsItemAdapter = new AlbumsItemAdapter(this);
155 | mAlbumsItemAdapter.setOnItemClickListener(this);
156 | mNavRecyclerView.setAdapter(mAlbumsItemAdapter);
157 |
158 | // 检测读取、写入权限
159 | if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE)
160 | == PackageManager.PERMISSION_GRANTED &&
161 | ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)
162 | == PackageManager.PERMISSION_GRANTED) {
163 | startLoader();
164 | } else if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.READ_EXTERNAL_STORAGE)
165 | || ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
166 | // empty code
167 | } else {
168 | ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE},
169 | REQUEST_READ_EXTERNAL_STORAGE_PERMISSION);
170 | }
171 | }
172 |
173 | @Override
174 | public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
175 | super.onRequestPermissionsResult(requestCode, permissions, grantResults);
176 | // 权限授权结果
177 | if (requestCode == REQUEST_READ_EXTERNAL_STORAGE_PERMISSION &&
178 | grantResults[0] == PackageManager.PERMISSION_GRANTED &&
179 | grantResults[1] == PackageManager.PERMISSION_GRANTED) {
180 | startLoader();
181 | }
182 | }
183 |
184 | private void startLoader() {
185 | getLoaderManager().initLoader(0, null, this);
186 | }
187 |
188 | @Override
189 | public Loader onCreateLoader(int id, Bundle args) {
190 | String selection = null;
191 | String[] mimeTypes = ConfigParams.getInstance().getMimeTypes();
192 | if (mimeTypes != null) {
193 | StringBuilder sb = new StringBuilder();
194 | for (int i = 0; i < mimeTypes.length; i++) {
195 | sb.append("mime_type=?");
196 | if (i + 1 < mimeTypes.length) {
197 | sb.append(" or ");
198 | }
199 | }
200 | selection = sb.toString();
201 | }
202 |
203 | int mimeType = ConfigParams.getInstance().getMimeType();
204 | Uri uri;
205 | switch (mimeType) {
206 | case MimeType.IMAGE:
207 | uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
208 | break;
209 | case MimeType.VIDEO:
210 | uri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
211 | break;
212 | default:
213 | uri = MediaStore.Files.getContentUri("external");
214 | }
215 |
216 | return new CursorLoader(
217 | this,
218 | uri,
219 | COLUMNS_NAME,
220 | selection,
221 | mimeTypes,
222 | MediaStore.Files.FileColumns.DATE_ADDED + " DESC"
223 | );
224 | }
225 |
226 | @Override
227 | public void onLoadFinished(Loader loader, Cursor data) {
228 | mResources.clear();
229 | mAlbums.clear();
230 |
231 | Media.Album allAlbum = new Media.Album();
232 | allAlbum.name = getString(R.string.daguerre_all);
233 |
234 | if (data != null && data.getCount() > 0 && data.moveToFirst()) {
235 | do {
236 | String _id = data.getString(data.getColumnIndex(_ID));
237 | String _data = data.getString(data.getColumnIndex(DATA));
238 | String _display_name = data.getString(data.getColumnIndex(DISPLAY_NAME));
239 | String mime_type = data.getString(data.getColumnIndex(MIME_TYPE));
240 | String bucket_display_name = data.getString(data.getColumnIndex(BUCKET_DISPLAY_NAME));
241 | Media.Resource resource = new Media.Resource(_id, _data, _display_name, mime_type, bucket_display_name);
242 | mResources.add(resource);
243 |
244 | // 统计专辑列表
245 | Media.Album album = filterAlbumByBucketName(bucket_display_name);
246 | if (album == null) {
247 | album = new Media.Album();
248 | album.name = bucket_display_name;
249 | album.cover = resource;
250 | album.resourceCount++;
251 | mAlbums.add(album);
252 | } else {
253 | album.resourceCount++;
254 | }
255 | album.resources.add(resource);
256 | allAlbum.resources.add(resource);
257 | } while (data.moveToNext());
258 |
259 | mAdapter.setData(mResources);
260 | mAdapter.notifyDataSetChanged();
261 | setTitle(allAlbum.name);
262 |
263 | Media.Album firstAlbum = mAlbums.get(0);
264 |
265 | allAlbum.cover = firstAlbum.cover;
266 | allAlbum.resourceCount = data.getCount();
267 | mAlbums.add(0, allAlbum);
268 | mAlbumsItemAdapter.setData(mAlbums);
269 | mAlbumsItemAdapter.notifyDataSetChanged();
270 | }
271 | mContentLoadingProgressBar.hide();
272 | }
273 |
274 | /**
275 | * 根据 bucketName 进行筛选是否已经存在 Album
276 | *
277 | * @return 存在返回 {@link Media.Album},反之返回null
278 | */
279 | private Media.Album filterAlbumByBucketName(String bucketName) {
280 | for (Media.Album album : mAlbums) {
281 | if (TextUtils.equals(album.name, bucketName)) {
282 | return album;
283 | }
284 | }
285 | return null;
286 | }
287 |
288 |
289 | @Override
290 | public void onLoaderReset(Loader loader) {
291 | mResources.clear();
292 | mAdapter.notifyDataSetChanged();
293 | }
294 |
295 | @Override
296 | public void onListItemClick(View itemView) {
297 | int adapterPosition = mRecyclerView.getChildViewHolder(itemView).getAdapterPosition();
298 | Intent intent = new Intent(this, PreviewResourceActivity.class);
299 | intent.putExtra("position", adapterPosition);
300 |
301 | ActivityOptionsCompat options = ActivityOptionsCompat
302 | .makeSceneTransitionAnimation(this, itemView.findViewById(R.id.image), "element");
303 | ActivityCompat.startActivity(this, intent, options.toBundle());
304 | }
305 |
306 | @Override
307 | public void onAlbumsItemClick(View itemView) {
308 | int adapterPosition = mNavRecyclerView.getChildViewHolder(itemView).getAdapterPosition();
309 | Media.Album album = mAlbums.get(adapterPosition);
310 | mResources = album.resources;
311 | mAdapter.setData(mResources);
312 | mAdapter.notifyDataSetChanged();
313 |
314 | setTitle(album.name);
315 | mDrawerLayout.closeDrawers();
316 | if (mActionModel != null) {
317 | mActionModel.finish();
318 | }
319 | }
320 |
321 | @Override
322 | public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
323 | View itemView = (View) buttonView.getParent();
324 | int adapterPosition = mRecyclerView.getChildViewHolder(itemView).getAdapterPosition();
325 |
326 | Media.Resource resource = mAdapter.getItem(adapterPosition);
327 | String data = resource.data;
328 | resource.isChecked = isChecked;
329 | if (isChecked) {
330 | if (!mSelectResources.contains(data)) {
331 | if (mSelectResources.size() == max) {
332 | buttonView.setChecked(false);
333 | resource.isChecked = false;
334 | Toast.makeText(this, getString(R.string.daguerre_max_select, max), Toast.LENGTH_SHORT).show();
335 | return;
336 | }
337 | mSelectResources.add(data);
338 | }
339 | if (mActionModel == null) {
340 | startSupportActionMode(this);
341 | }
342 | } else {
343 | if (mSelectResources.contains(data))
344 | mSelectResources.remove(data);
345 | }
346 | if (mActionModel != null) {
347 | if (mSelectResources.isEmpty()) {
348 | mActionModel.finish();
349 | } else {
350 | mActionModel.setTitle(getString(R.string.daguerre_select, mSelectResources.size()));
351 | }
352 | }
353 | }
354 |
355 | @Override
356 | public boolean onCreateOptionsMenu(Menu menu) {
357 | switch (ConfigParams.getInstance().getMimeType()) {
358 | case MimeType.IMAGE:
359 | getMenuInflater().inflate(R.menu.daguerre_action_camera, menu);
360 | break;
361 | case MimeType.VIDEO:
362 | getMenuInflater().inflate(R.menu.daguerre_action_video, menu);
363 | break;
364 | default:
365 | }
366 |
367 | return super.onCreateOptionsMenu(menu);
368 | }
369 |
370 | @Override
371 | public boolean onOptionsItemSelected(MenuItem item) {
372 | int itemId = item.getItemId();
373 | if (itemId == android.R.id.home) {
374 | finish();
375 | return true;
376 | } else if (itemId == R.id.menu_camera) {
377 | launchCameraApp(REQUEST_CAMERA_IMAGE);
378 | return true;
379 | } else if (itemId == R.id.menu_video) {
380 | launchCameraApp(REQUEST_CAMERA_VIDEO);
381 | return true;
382 | }
383 | return super.onOptionsItemSelected(item);
384 | }
385 |
386 | /**
387 | * start the camera app
388 | */
389 | private void launchCameraApp(int useType) {
390 | Intent cameraIntent = new Intent();
391 | if (useType == REQUEST_CAMERA_VIDEO) {
392 | cameraIntent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
393 | cameraIntent.setAction(MediaStore.ACTION_VIDEO_CAPTURE);
394 | } else {
395 | cameraIntent.setAction(MediaStore.ACTION_IMAGE_CAPTURE);
396 | }
397 | if (cameraIntent.resolveActivity(getPackageManager()) != null) {
398 | if (useType == REQUEST_CAMERA_VIDEO) {
399 | mCameraOutPutFile = createVideoFile();
400 | } else {
401 | mCameraOutPutFile = createPhotoFile();
402 | }
403 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
404 | // 适配 7.0+ 系统
405 | Uri uri = FileProvider.getUriForFile(this, getPackageName() + ".daguerre.fileprovider", mCameraOutPutFile);
406 | cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
407 | cameraIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
408 | } else {
409 | cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(mCameraOutPutFile));
410 | }
411 | if (useType == REQUEST_CAMERA_VIDEO) {
412 | cameraIntent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
413 | }
414 | startActivityForResult(cameraIntent, REQUEST_CAMERA_APP);
415 | } else {
416 | Toast.makeText(this, R.string.daguerre_not_found_camera_app, Toast.LENGTH_SHORT).show();
417 | }
418 | }
419 |
420 | /**
421 | * create a photo file storage path
422 | */
423 | private static File createPhotoFile() {
424 | String timeStamp =
425 | new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.getDefault()).format(new Date());
426 | File dcimFile = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM);
427 | return new File(dcimFile, "Camera/IMG_" + timeStamp + ".jpg");
428 | }
429 |
430 | private static File createVideoFile() {
431 | String timeStamp =
432 | new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.getDefault()).format(new Date());
433 | File dcimFile = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM);
434 | return new File(dcimFile, "Camera/VID_" + timeStamp + ".mp4");
435 | }
436 |
437 | @Override
438 | protected void onActivityResult(int requestCode, int resultCode, Intent data) {
439 | super.onActivityResult(requestCode, resultCode, data);
440 | if (resultCode == RESULT_OK && requestCode == REQUEST_CAMERA_APP) {
441 | // 拍照回来
442 | sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(mCameraOutPutFile)));
443 | }
444 | }
445 |
446 | @Override
447 | public boolean onCreateActionMode(ActionMode mode, Menu menu) {
448 | mActionModel = mode;
449 | mode.getMenuInflater().inflate(R.menu.daguerre_action_mode, menu);
450 | return true;
451 | }
452 |
453 | @Override
454 | public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
455 | return false;
456 | }
457 |
458 | @Override
459 | public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
460 | if (item.getItemId() == R.id.menu_done) {
461 | Intent intent = new Intent();
462 | intent.putExtra(Daguerre.INTENT_EXTRA_RESULT, mSelectResources);
463 | setResult(RESULT_OK, intent);
464 | finish();
465 | return true;
466 | }
467 | return false;
468 | }
469 |
470 | @Override
471 | public void onDestroyActionMode(ActionMode mode) {
472 | mode.setTitle("");
473 | mActionModel = null;
474 | for (Media.Resource resource : mResources) {
475 | resource.isChecked = false;
476 | }
477 | mSelectResources.clear();
478 | mAdapter.notifyDataSetChanged();
479 | }
480 | }
--------------------------------------------------------------------------------