├── .gitignore
├── .idea
├── compiler.xml
├── copyright
│ └── profiles_settings.xml
├── dictionaries
│ └── lenovo.xml
├── encodings.xml
├── gradle.xml
├── misc.xml
├── modules.xml
└── vcs.xml
├── LICENSE
├── README.md
├── Screenshots
├── Screenshots1.png
├── Screenshots2.png
├── Screenshots3.png
├── Screenshots4.png
├── Screenshots5.png
├── Screenshots6.png
└── ios.gif
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── dmc
│ │ └── mediapickerpoject
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── dmc
│ │ │ └── mediapickerpoject
│ │ │ ├── ExampleApplication.java
│ │ │ └── MainActivity.java
│ └── res
│ │ ├── layout
│ │ └── activity_main.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
│ │ └── values
│ │ ├── colors.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── dmc
│ └── mediapickerpoject
│ └── ExampleUnitTest.java
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── mediapicker
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── dmcbig
│ │ │ └── mediapicker
│ │ │ ├── PickerActivity.java
│ │ │ ├── PickerConfig.java
│ │ │ ├── PreviewActivity.java
│ │ │ ├── TakePhotoActivity.java
│ │ │ ├── adapter
│ │ │ ├── FolderAdapter.java
│ │ │ ├── MediaGridAdapter.java
│ │ │ └── SpacingDecoration.java
│ │ │ ├── data
│ │ │ ├── DataCallback.java
│ │ │ ├── ImageLoader.java
│ │ │ ├── LoaderM.java
│ │ │ ├── MediaLoader.java
│ │ │ └── VideoLoader.java
│ │ │ ├── entity
│ │ │ ├── Folder.java
│ │ │ └── Media.java
│ │ │ ├── utils
│ │ │ ├── DmcFileProvider.java
│ │ │ ├── FileUtils.java
│ │ │ └── ScreenUtils.java
│ │ │ └── view
│ │ │ ├── HackyViewPager.java
│ │ │ ├── PreviewFragment.java
│ │ │ └── SquareFrameLayout.java
│ └── res
│ │ ├── color
│ │ └── default_text_color.xml
│ │ ├── drawable-xhdpi
│ │ ├── default_check.png
│ │ ├── default_image.png
│ │ ├── text_indicator.png
│ │ └── video.png
│ │ ├── drawable
│ │ ├── action_btn.xml
│ │ ├── btn_selected.png
│ │ ├── btn_unselected.png
│ │ └── ic_back.png
│ │ ├── layout
│ │ ├── folders_view_item.xml
│ │ ├── loading.xml
│ │ ├── main.xml
│ │ ├── media_view_item.xml
│ │ ├── picker_actionbar.xml
│ │ ├── preview_actionbar.xml
│ │ ├── preview_bottombar.xml
│ │ ├── preview_fragment_item.xml
│ │ └── preview_main.xml
│ │ ├── values-es
│ │ └── strings.xml
│ │ ├── values-pt-rBR
│ │ └── strings.xml
│ │ ├── values-pt-rPT
│ │ └── strings.xml
│ │ ├── values-zh
│ │ └── strings.xml
│ │ ├── values
│ │ └── strings.xml
│ │ └── xml
│ │ └── file_dmc_paths.xml
│ └── test
│ └── java
│ └── com
│ └── dmcbig
│ └── mediapicker
│ └── ExampleUnitTest.java
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/*
5 | .idea/
6 | /.idea/workspace.xml
7 | /.idea/libraries
8 | .DS_Store
9 | /build
10 | /captures
11 | .idea
12 | .externalNativeBuild
13 |
--------------------------------------------------------------------------------
/.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 |
23 |
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/.idea/dictionaries/lenovo.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
20 |
21 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2019 DMC
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | [](https://jitpack.io/#DmcSDK/MediaPickerPoject)
2 | # MediaPickerProject
3 |
4 | 仿微信视频图片选择器,代码撸的非常简洁好改,支持cordova调用,联系QQ:3451927565。
5 |
6 | 同类的库很多很多,但都过于强大而笨重,代码不容易在特别短的时间里面改动扩展,所以我创建了这个简单而轻量的库。
7 |
8 | 非常欢迎有空的小伙伴一同 pull requests 改进优化项目
9 |
10 | 特别是UI,我想再增加几种UI样式,比如模仿知乎图片选择UI风格,个人觉得知乎图片选择UI很清爽,如果有空的人可以加上后提交给我或者其他风格的也行,感谢。
11 |
12 | 怎么使用?
13 | -------------------
14 | [Cordova版](https://github.com/DmcSDK/cordova-plugin-mediaPicker) : https://github.com/DmcSDK/cordova-plugin-mediaPicker
15 |
16 | [IOS版](https://github.com/DmcSDK/IOSMediaPicker) : https://github.com/DmcSDK/IOSMediaPicker
17 |
18 | use Gradle:
19 |
20 | ```gradle
21 | dependencyResolutionManagement {
22 | repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
23 | repositories {
24 | mavenCentral()
25 | maven { url 'https://jitpack.io' }
26 | }
27 | }
28 |
29 | dependencies {
30 | implementation 'com.github.DmcSDK:MediaPickerPoject:Tag'
31 | }
32 | ```
33 |
34 | code:
35 | ```
36 | ArrayList select = new ArrayList<>();//装被选中的文件
37 | void go(){
38 | Intent intent =new Intent(MainActivity.this, PickerActivity.class);
39 | intent.putExtra(PickerConfig.SELECT_MODE,PickerConfig.PICKER_IMAGE_VIDEO);//设置选择类型,默认是图片和视频可一起选择(非必填参数)
40 | long maxSize=188743680L;//long long long long类型
41 | intent.putExtra(PickerConfig.MAX_SELECT_SIZE,maxSize); //最大选择大小,默认180M(非必填参数)
42 | intent.putExtra(PickerConfig.MAX_SELECT_COUNT,15); //最大选择数量,默认40(非必填参数)
43 | ArrayList defaultSelect = select;//可以设置默认选中的照片,比如把select刚刚选择的list设置成默认的。
44 | intent.putExtra(PickerConfig.DEFAULT_SELECTED_LIST,defaultSelect); //可以设置默认选中的照片(非必填参数)
45 | MainActivity.this.startActivityForResult(intent,200);
46 | }
47 |
48 | @Override
49 | protected void onActivityResult(int requestCode, int resultCode, Intent data) {
50 | super.onActivityResult(requestCode, resultCode, data);
51 | if(requestCode==200&&resultCode==PickerConfig.RESULT_CODE){
52 | select=data.getParcelableArrayListExtra(PickerConfig.EXTRA_RESULT);//选择完后返回的list
53 | }
54 | }
55 |
56 | //拍照
57 | // Intent intent =new Intent(MainActivity.this, TakePhotoActivity.class); //Take a photo with a camera
58 | // MainActivity.this.startActivityForResult(intent,200);
59 | ```
60 |
61 | # Screenshots
62 | 
63 | 
64 | 
65 | 
66 | 
67 | 
68 |
--------------------------------------------------------------------------------
/Screenshots/Screenshots1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DmcSDK/MediaPickerPoject/cf768d7ffff5de6e86b58d41f8c3d0947f17160f/Screenshots/Screenshots1.png
--------------------------------------------------------------------------------
/Screenshots/Screenshots2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DmcSDK/MediaPickerPoject/cf768d7ffff5de6e86b58d41f8c3d0947f17160f/Screenshots/Screenshots2.png
--------------------------------------------------------------------------------
/Screenshots/Screenshots3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DmcSDK/MediaPickerPoject/cf768d7ffff5de6e86b58d41f8c3d0947f17160f/Screenshots/Screenshots3.png
--------------------------------------------------------------------------------
/Screenshots/Screenshots4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DmcSDK/MediaPickerPoject/cf768d7ffff5de6e86b58d41f8c3d0947f17160f/Screenshots/Screenshots4.png
--------------------------------------------------------------------------------
/Screenshots/Screenshots5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DmcSDK/MediaPickerPoject/cf768d7ffff5de6e86b58d41f8c3d0947f17160f/Screenshots/Screenshots5.png
--------------------------------------------------------------------------------
/Screenshots/Screenshots6.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DmcSDK/MediaPickerPoject/cf768d7ffff5de6e86b58d41f8c3d0947f17160f/Screenshots/Screenshots6.png
--------------------------------------------------------------------------------
/Screenshots/ios.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DmcSDK/MediaPickerPoject/cf768d7ffff5de6e86b58d41f8c3d0947f17160f/Screenshots/ios.gif
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 33
5 | buildToolsVersion '29.0.3'
6 | defaultConfig {
7 | applicationId "dmc.mediapickerpoject"
8 | minSdkVersion 16
9 | targetSdkVersion 29
10 | versionCode 1
11 | versionName "1.0"
12 | testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
13 | }
14 | compileOptions {
15 | sourceCompatibility JavaVersion.VERSION_1_8
16 | targetCompatibility JavaVersion.VERSION_1_8
17 | }
18 | buildTypes {
19 | release {
20 | minifyEnabled false
21 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
22 | }
23 | }
24 | }
25 |
26 | dependencies {
27 | compile fileTree(include: ['*.jar'], dir: 'libs')
28 | androidTestCompile('androidx.test.espresso:espresso-core:3.1.0', {
29 | exclude group: 'com.android.support', module: 'support-annotations'
30 | })
31 | compile 'androidx.appcompat:appcompat:1.0.0'
32 | compile 'androidx.constraintlayout:constraintlayout:1.1.3'
33 | testCompile 'junit:junit:4.12'
34 | compile project(':mediapicker')
35 | }
36 |
--------------------------------------------------------------------------------
/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 E:\android_develop_tools\sdk1/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 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/dmc/mediapickerpoject/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package dmc.mediapickerpoject;
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("dmc.mediapickerpoject", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/app/src/main/java/dmc/mediapickerpoject/ExampleApplication.java:
--------------------------------------------------------------------------------
1 | package dmc.mediapickerpoject;
2 |
3 | import android.app.Application;
4 |
5 |
6 | /**
7 | * Created by dmcBig on 2017/7/25.
8 | */
9 |
10 | public class ExampleApplication extends Application {
11 |
12 | @Override public void onCreate() {
13 | super.onCreate();
14 | }
15 | }
--------------------------------------------------------------------------------
/app/src/main/java/dmc/mediapickerpoject/MainActivity.java:
--------------------------------------------------------------------------------
1 | package dmc.mediapickerpoject;
2 |
3 | import android.content.Intent;
4 | import android.net.Uri;
5 | import android.os.Bundle;
6 | import androidx.appcompat.app.AppCompatActivity;
7 | import android.util.Log;
8 | import android.view.View;
9 | import android.widget.ImageView;
10 |
11 | import com.dmcbig.mediapicker.PickerActivity;
12 | import com.dmcbig.mediapicker.PickerConfig;
13 | import com.dmcbig.mediapicker.TakePhotoActivity;
14 | import com.dmcbig.mediapicker.entity.Media;
15 |
16 | import java.net.URI;
17 | import java.util.ArrayList;
18 |
19 | public class MainActivity extends AppCompatActivity {
20 |
21 | ImageView imageView;
22 | @Override
23 | protected void onCreate(Bundle savedInstanceState) {
24 | super.onCreate(savedInstanceState);
25 | setContentView(R.layout.activity_main);
26 | imageView=(ImageView) findViewById(R.id.immmgg);
27 | findViewById(R.id.go).setOnClickListener(new View.OnClickListener() {
28 | @Override
29 | public void onClick(View v) {
30 | go();
31 | }
32 | });
33 |
34 | findViewById(R.id.take).setOnClickListener(new View.OnClickListener() {
35 | @Override
36 | public void onClick(View v) {
37 | Intent intent =new Intent(MainActivity.this, TakePhotoActivity.class); //Take a photo with a camera
38 | MainActivity.this.startActivityForResult(intent,200);
39 | }
40 | });
41 | }
42 |
43 | ArrayList select;
44 | void go(){
45 | Intent intent =new Intent(MainActivity.this, PickerActivity.class);
46 | intent.putExtra(PickerConfig.SELECT_MODE,PickerConfig.PICKER_IMAGE);//default image and video (Optional)
47 | long maxSize=188743680L;//long long long
48 | intent.putExtra(PickerConfig.MAX_SELECT_SIZE,maxSize); //default 180MB (Optional)
49 | intent.putExtra(PickerConfig.MAX_SELECT_COUNT,15); //default 40 (Optional)
50 | intent.putExtra(PickerConfig.DEFAULT_SELECTED_LIST,select); // (Optional)
51 | MainActivity.this.startActivityForResult(intent,200);
52 | }
53 |
54 | @Override
55 | protected void onActivityResult(int requestCode, int resultCode, Intent data) {
56 | super.onActivityResult(requestCode, resultCode, data);
57 | if(requestCode==200&&resultCode==PickerConfig.RESULT_CODE){
58 | select=data.getParcelableArrayListExtra(PickerConfig.EXTRA_RESULT);
59 | Log.i("select","select.size"+select.size());
60 | for(Media media:select){
61 | Log.i("media",media.path);
62 | Log.e("media","s:"+media.size);
63 | imageView.setImageURI(Uri.parse(media.path));
64 | }
65 | }
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
14 |
20 |
26 |
27 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DmcSDK/MediaPickerPoject/cf768d7ffff5de6e86b58d41f8c3d0947f17160f/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DmcSDK/MediaPickerPoject/cf768d7ffff5de6e86b58d41f8c3d0947f17160f/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DmcSDK/MediaPickerPoject/cf768d7ffff5de6e86b58d41f8c3d0947f17160f/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DmcSDK/MediaPickerPoject/cf768d7ffff5de6e86b58d41f8c3d0947f17160f/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DmcSDK/MediaPickerPoject/cf768d7ffff5de6e86b58d41f8c3d0947f17160f/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DmcSDK/MediaPickerPoject/cf768d7ffff5de6e86b58d41f8c3d0947f17160f/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DmcSDK/MediaPickerPoject/cf768d7ffff5de6e86b58d41f8c3d0947f17160f/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DmcSDK/MediaPickerPoject/cf768d7ffff5de6e86b58d41f8c3d0947f17160f/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DmcSDK/MediaPickerPoject/cf768d7ffff5de6e86b58d41f8c3d0947f17160f/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DmcSDK/MediaPickerPoject/cf768d7ffff5de6e86b58d41f8c3d0947f17160f/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | MediaPickerPoject
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/dmc/mediapickerpoject/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package dmc.mediapickerpoject;
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 | }
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | maven { url 'https://jitpack.io' }
6 | maven { url 'https://maven.aliyun.com/repository/public' }
7 | maven { url 'https://maven.aliyun.com/repository/central' }
8 | maven { url 'https://maven.aliyun.com/repository/google' }
9 | maven { url 'https://maven.aliyun.com/repository/public' }
10 | maven { url 'https://maven.aliyun.com/repository/gradle-plugin' }
11 | maven {
12 | url 'https://maven.google.com/'
13 | name 'Google'
14 | }
15 | jcenter()
16 | }
17 | dependencies {
18 | classpath 'com.android.tools.build:gradle:4.0.0'
19 | classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0'
20 | classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3'
21 | // NOTE: Do not place your application dependencies here; they belong
22 | // in the individual module build.gradle files
23 |
24 | }
25 | }
26 |
27 | allprojects {
28 | repositories {
29 | maven { url 'https://jitpack.io' }
30 | maven { url 'https://maven.aliyun.com/repository/public' }
31 | maven { url 'https://maven.aliyun.com/repository/central' }
32 | maven { url 'https://maven.aliyun.com/repository/google' }
33 | maven { url 'https://maven.aliyun.com/repository/public' }
34 | maven { url 'https://maven.aliyun.com/repository/gradle-plugin' }
35 | maven {
36 | url 'https://maven.google.com/'
37 | name 'Google'
38 | }
39 | jcenter()
40 | }
41 | }
42 |
43 | task clean(type: Delete) {
44 | delete rootProject.buildDir
45 | }
46 |
--------------------------------------------------------------------------------
/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 | android.enableJetifier=true
13 | android.useAndroidX=true
14 | org.gradle.jvmargs=-Xmx1536m
15 |
16 | # When configured, Gradle will run in incubating parallel mode.
17 | # This option should only be used with decoupled projects. More details, visit
18 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
19 | # org.gradle.parallel=true
20 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DmcSDK/MediaPickerPoject/cf768d7ffff5de6e86b58d41f8c3d0947f17160f/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Jul 07 10:40:41 CST 2021
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-6.1.1-all.zip
7 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/mediapicker/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/mediapicker/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'com.jfrog.bintray'
3 | apply plugin: 'com.github.dcendents.android-maven'
4 |
5 | def siteUrl = 'https://github.com/DmcSDK/MediaPickerPoject' // 项目的主页
6 | def gitUrl = 'https://github.com/DmcSDK/MediaPickerPoject.git' // Git仓库的url
7 | Properties properties = new Properties()
8 | properties.load(project.rootProject.file('local.properties').newDataInputStream())
9 |
10 | version = "3.3" //发布版本号
11 | group = "com.dmcBig" //最终引用形式,如compile 'com.**;
12 | android {
13 | compileSdkVersion 33
14 | buildToolsVersion '29.0.3'
15 |
16 | defaultConfig {
17 | minSdkVersion 16
18 | targetSdkVersion 29
19 | versionCode 1
20 | versionName "3.3"
21 |
22 | testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
23 |
24 | }
25 | compileOptions {
26 | sourceCompatibility JavaVersion.VERSION_1_8
27 | targetCompatibility JavaVersion.VERSION_1_8
28 | }
29 |
30 | buildTypes {
31 | release {
32 | minifyEnabled false
33 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
34 | }
35 | }
36 | }
37 |
38 |
39 | dependencies {
40 | compile fileTree(include: ['*.jar'], dir: 'libs')
41 | testCompile 'junit:junit:4.12'
42 | implementation 'com.github.bumptech.glide:glide:4.0.0'
43 | annotationProcessor 'com.github.bumptech.glide:compiler:4.0.0'
44 | implementation 'pub.devrel:easypermissions:3.0.0'
45 | implementation 'com.github.chrisbanes.photoview:library:1.2.4'
46 | implementation "androidx.recyclerview:recyclerview:1.2.1"
47 | implementation "androidx.activity:activity:1.6.1"
48 | }
49 |
50 | bintray {
51 | user = properties.getProperty("bintray.user")
52 | key = properties.getProperty("bintray.apikey")
53 | pkg {
54 | repo = 'dmcBig'//自己创建的仓库名字
55 | name = 'MediaPicker'//上传到JCenter的名字,最终引用的名字
56 | websiteUrl = siteUrl
57 | vcsUrl = gitUrl
58 | licenses = ['Apache-2.1']//不能随便写,只能是仓库创建时选择的license type
59 | userOrg = 'yuanwu' //自己创建的organization名称
60 | publish = true // 是否是公开项目,公开别人可以引用
61 |
62 | version {
63 | name = '3.3'
64 | desc = 'MediaPicker open library.'//描述,自己定义
65 | released = new Date()
66 | vcsTag = 'v1.1'
67 | attributes = ['gradle-plugin': 'com.use.less:com.use.less.gradle:gradle-useless-plugin']
68 | }
69 | }
70 | configurations = ['archives']
71 | }
72 |
73 | install {
74 | repositories.mavenInstaller {
75 | // This generates POM.xml with proper parameters
76 | pom {
77 | project {
78 | packaging 'aar'
79 | // Add your description here
80 | name 'mediaPicker Android'
81 | description 'MediaPicker open library.'
82 | url siteUrl
83 | // Set your license
84 | licenses {
85 | license {
86 | name 'The Apache Software License, Version 2.1'
87 | url 'http://www.apache.org/licenses/LICENSE-2.1.txt'
88 | }
89 | }
90 | developers {
91 | developer {
92 | id 'dmcBig' //填写bintray或者github的用户名
93 | name 'dmcBig' //姓名
94 | email 'yu911512152@gmail.com'//邮箱
95 | }
96 | }
97 | scm {
98 | connection gitUrl
99 | developerConnection gitUrl
100 | url siteUrl
101 | }
102 | }
103 | }
104 | }
105 | }
106 | task sourcesJar(type: Jar) {
107 | from android.sourceSets.main.java.srcDirs
108 | classifier = 'sources'
109 | }
110 | task javadoc(type: Javadoc) {
111 | failOnError false //必须添加以免出错
112 | source = android.sourceSets.main.java.srcDirs
113 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
114 | }
115 | task javadocJar(type: Jar, dependsOn: javadoc) {
116 | classifier = 'javadoc'
117 | from javadoc.destinationDir
118 | }
119 | artifacts {
120 | archives javadocJar
121 | archives sourcesJar
122 | }
123 |
124 | javadoc {
125 | options{
126 | //如果你的项目里面有中文注释的话,必须将格式设置为UTF-8,不然会出现乱码
127 | encoding "UTF-8"
128 | charSet 'UTF-8'
129 | author true
130 | version true
131 | links "http://docs.oracle.com/javase/7/docs/api"
132 | }
133 | }
134 |
--------------------------------------------------------------------------------
/mediapicker/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 E:\android_develop_tools\sdk1/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 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/mediapicker/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
11 |
12 |
17 |
20 |
21 |
26 |
31 |
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/mediapicker/src/main/java/com/dmcbig/mediapicker/PickerActivity.java:
--------------------------------------------------------------------------------
1 | package com.dmcbig.mediapicker;
2 |
3 | import android.Manifest;
4 | import android.app.Activity;
5 | import android.content.Intent;
6 | import android.content.res.Configuration;
7 | import android.database.Cursor;
8 | import android.graphics.Color;
9 | import android.graphics.drawable.ColorDrawable;
10 | import android.net.Uri;
11 | import android.os.Build;
12 | import android.os.Bundle;
13 |
14 | import androidx.activity.result.ActivityResultLauncher;
15 | import androidx.annotation.NonNull;
16 | import androidx.annotation.Nullable;
17 | import androidx.appcompat.app.AppCompatActivity;
18 | import androidx.fragment.app.FragmentActivity;
19 | import androidx.loader.app.LoaderManager;
20 | import androidx.recyclerview.widget.GridLayoutManager;
21 | import androidx.appcompat.widget.ListPopupWindow;
22 | import androidx.recyclerview.widget.RecyclerView;
23 |
24 | import android.provider.MediaStore;
25 | import android.util.Log;
26 | import android.view.View;
27 | import android.widget.AdapterView;
28 | import android.widget.Button;
29 | import android.widget.TextView;
30 | import android.widget.Toast;
31 |
32 | import com.bumptech.glide.Glide;
33 | import com.dmcbig.mediapicker.adapter.FolderAdapter;
34 | import com.dmcbig.mediapicker.adapter.MediaGridAdapter;
35 | import com.dmcbig.mediapicker.adapter.SpacingDecoration;
36 | import com.dmcbig.mediapicker.data.DataCallback;
37 | import com.dmcbig.mediapicker.data.ImageLoader;
38 | import com.dmcbig.mediapicker.data.MediaLoader;
39 | import com.dmcbig.mediapicker.data.VideoLoader;
40 | import com.dmcbig.mediapicker.entity.Folder;
41 | import com.dmcbig.mediapicker.entity.Media;
42 | import com.dmcbig.mediapicker.utils.ScreenUtils;
43 |
44 | import java.util.ArrayList;
45 |
46 | import pub.devrel.easypermissions.AfterPermissionGranted;
47 | import pub.devrel.easypermissions.EasyPermissions;
48 |
49 |
50 | /**
51 | * Created by dmcBig on 2017/6/9.
52 | */
53 |
54 | public class PickerActivity extends FragmentActivity implements DataCallback, View.OnClickListener {
55 |
56 | Intent argsIntent;
57 | RecyclerView recyclerView;
58 | Button done, category_btn, preview;
59 | MediaGridAdapter gridAdapter;
60 | ListPopupWindow mFolderPopupWindow;
61 | private FolderAdapter mFolderAdapter;
62 |
63 | @Override
64 | protected void onCreate(@Nullable Bundle savedInstanceState) {
65 | super.onCreate(savedInstanceState);
66 | argsIntent = getIntent();
67 | if (Build.VERSION.SDK_INT >= 33){
68 | setContentView(R.layout.loading);
69 | }else {
70 | setContentView(R.layout.main);
71 | recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
72 | findViewById(R.id.btn_back).setOnClickListener(this);
73 | setTitleBar();
74 | done = (Button) findViewById(R.id.done);
75 | category_btn = (Button) findViewById(R.id.category_btn);
76 | preview = (Button) findViewById(R.id.preview);
77 | done.setOnClickListener(this);
78 | category_btn.setOnClickListener(this);
79 | preview.setOnClickListener(this);
80 | //get view end
81 | createAdapter();
82 | createFolderAdapter();
83 | }
84 | getMediaData();
85 | }
86 |
87 |
88 | public void setTitleBar() {
89 | int type = argsIntent.getIntExtra(PickerConfig.SELECT_MODE, PickerConfig.PICKER_IMAGE_VIDEO);
90 | if (type == PickerConfig.PICKER_IMAGE_VIDEO) {
91 | ((TextView) findViewById(R.id.bar_title)).setText(getString(R.string.select_title));
92 | } else if (type == PickerConfig.PICKER_IMAGE) {
93 | ((TextView) findViewById(R.id.bar_title)).setText(getString(R.string.select_image_title));
94 | } else if (type == PickerConfig.PICKER_VIDEO) {
95 | ((TextView) findViewById(R.id.bar_title)).setText(getString(R.string.select_video_title));
96 | }
97 | }
98 |
99 | void createAdapter() {
100 | //创建默认的线性LayoutManager
101 | GridLayoutManager mLayoutManager = new GridLayoutManager(this, PickerConfig.GridSpanCount);
102 | recyclerView.setLayoutManager(mLayoutManager);
103 | recyclerView.addItemDecoration(new SpacingDecoration(PickerConfig.GridSpanCount, PickerConfig.GridSpace));
104 | //如果可以确定每个item的高度是固定的,设置这个选项可以提高性能
105 | recyclerView.setHasFixedSize(true);
106 | //创建并设置Adapter
107 | ArrayList medias = new ArrayList<>();
108 | ArrayList select = argsIntent.getParcelableArrayListExtra(PickerConfig.DEFAULT_SELECTED_LIST);
109 | int maxSelect = argsIntent.getIntExtra(PickerConfig.MAX_SELECT_COUNT, PickerConfig.DEFAULT_SELECTED_MAX_COUNT);
110 | long maxSize = argsIntent.getLongExtra(PickerConfig.MAX_SELECT_SIZE, PickerConfig.DEFAULT_SELECTED_MAX_SIZE);
111 | gridAdapter = new MediaGridAdapter(medias, this, select, maxSelect, maxSize);
112 | recyclerView.setAdapter(gridAdapter);
113 | }
114 |
115 | void createFolderAdapter() {
116 | ArrayList folders = new ArrayList<>();
117 | mFolderAdapter = new FolderAdapter(folders, this);
118 | mFolderPopupWindow = new ListPopupWindow(this);
119 | mFolderPopupWindow.setBackgroundDrawable(new ColorDrawable(Color.WHITE));
120 | mFolderPopupWindow.setAdapter(mFolderAdapter);
121 | mFolderPopupWindow.setHeight((int) (ScreenUtils.getScreenHeight(this) * 0.6));
122 | mFolderPopupWindow.setAnchorView(findViewById(R.id.footer));
123 | mFolderPopupWindow.setModal(true);
124 | mFolderPopupWindow.setOnItemClickListener(new AdapterView.OnItemClickListener() {
125 | @Override
126 | public void onItemClick(AdapterView> parent, View view, int position, long id) {
127 | mFolderAdapter.setSelectIndex(position);
128 | category_btn.setText(mFolderAdapter.getItem(position).name);
129 | gridAdapter.updateAdapter(mFolderAdapter.getSelectMedias());
130 | mFolderPopupWindow.dismiss();
131 | }
132 | });
133 | }
134 |
135 |
136 |
137 | @AfterPermissionGranted(119)
138 | void getMediaData() {
139 |
140 | if (Build.VERSION.SDK_INT >= 33){
141 | // if (EasyPermissions.hasPermissions(this, Manifest.permission.READ_MEDIA_IMAGES)) {
142 | // Toast.makeText(this,"get Media 33",Toast.LENGTH_LONG).show();
143 | // int type = argsIntent.getIntExtra(PickerConfig.SELECT_MODE, PickerConfig.PICKER_IMAGE_VIDEO);
144 | // if (type == PickerConfig.PICKER_IMAGE_VIDEO) {
145 | // LoaderManager.getInstance(this).initLoader(type, null, new MediaLoader(this, this));
146 | // } else if (type == PickerConfig.PICKER_IMAGE) {
147 | // LoaderManager.getInstance(this).initLoader(type, null, new ImageLoader(this, this));
148 | // } else if (type == PickerConfig.PICKER_VIDEO) {
149 | // LoaderManager.getInstance(this).initLoader(type, null, new VideoLoader(this, this));
150 | // }
151 |
152 | Intent intent = new Intent(MediaStore.ACTION_PICK_IMAGES);
153 | int type = argsIntent.getIntExtra(PickerConfig.SELECT_MODE, PickerConfig.PICKER_IMAGE_VIDEO);
154 | if (type == PickerConfig.PICKER_IMAGE) {
155 | intent.setType("image/*");
156 | } else if (type == PickerConfig.PICKER_VIDEO) {
157 | intent.setType("video/*");
158 | }
159 | int maxSelect = argsIntent.getIntExtra(PickerConfig.MAX_SELECT_COUNT, PickerConfig.DEFAULT_SELECTED_MAX_COUNT);
160 | long maxSize = argsIntent.getLongExtra(PickerConfig.MAX_SELECT_SIZE, PickerConfig.DEFAULT_SELECTED_MAX_SIZE);
161 | intent.putExtra(MediaStore.EXTRA_SIZE_LIMIT, maxSize);
162 | if(maxSelect>1){
163 | intent.putExtra(MediaStore.EXTRA_PICK_IMAGES_MAX, maxSelect);
164 | }
165 | this.startActivityForResult(intent,300);
166 |
167 |
168 | // }else{
169 | // EasyPermissions.requestPermissions(this, getString(R.string.READ_EXTERNAL_STORAGE), 119, Manifest.permission.READ_MEDIA_IMAGES, Manifest.permission.READ_MEDIA_VIDEO, Manifest.permission.READ_MEDIA_AUDIO);
170 | // }
171 | }else {
172 | if (EasyPermissions.hasPermissions(this, Manifest.permission.READ_EXTERNAL_STORAGE)) {
173 | int type = argsIntent.getIntExtra(PickerConfig.SELECT_MODE, PickerConfig.PICKER_IMAGE_VIDEO);
174 | if (type == PickerConfig.PICKER_IMAGE_VIDEO) {
175 | LoaderManager.getInstance(this).initLoader(type, null, new MediaLoader(this, this));
176 | } else if (type == PickerConfig.PICKER_IMAGE) {
177 | LoaderManager.getInstance(this).initLoader(type, null, new ImageLoader(this, this));
178 | } else if (type == PickerConfig.PICKER_VIDEO) {
179 | LoaderManager.getInstance(this).initLoader(type, null, new VideoLoader(this, this));
180 | }
181 | } else {
182 | EasyPermissions.requestPermissions(this, getString(R.string.READ_EXTERNAL_STORAGE), 119, Manifest.permission.READ_EXTERNAL_STORAGE);
183 | }
184 | }
185 | }
186 |
187 | @Override
188 | public void onData(ArrayList list) {
189 | setView(list);
190 | category_btn.setText(list.get(0).name);
191 | mFolderAdapter.updateAdapter(list);
192 | }
193 |
194 | void setView(ArrayList list) {
195 | gridAdapter.updateAdapter(list.get(0).getMedias());
196 | setButtonText();
197 | gridAdapter.setOnItemClickListener(new MediaGridAdapter.OnRecyclerViewItemClickListener() {
198 | @Override
199 | public void onItemClick(View view, Media data, ArrayList selectMedias) {
200 | setButtonText();
201 | }
202 | });
203 | }
204 |
205 | void setButtonText() {
206 | int max = argsIntent.getIntExtra(PickerConfig.MAX_SELECT_COUNT, PickerConfig.DEFAULT_SELECTED_MAX_COUNT);
207 | done.setText(getString(R.string.done) + "(" + gridAdapter.getSelectMedias().size() + "/" + max + ")");
208 | preview.setText(getString(R.string.preview) + "(" + gridAdapter.getSelectMedias().size() + ")");
209 | }
210 |
211 | @Override
212 | public void onClick(View v) {
213 | int id = v.getId();
214 | if (id == R.id.btn_back) {
215 | ArrayList selectMedias = new ArrayList<>();
216 | done(selectMedias);
217 | } else if (id == R.id.category_btn) {
218 | if (mFolderPopupWindow.isShowing()) {
219 | mFolderPopupWindow.dismiss();
220 | } else {
221 | mFolderPopupWindow.show();
222 | }
223 | } else if (id == R.id.done) {
224 | done(gridAdapter.getSelectMedias());
225 | } else if (id == R.id.preview) {
226 | if (gridAdapter.getSelectMedias().size() <= 0) {
227 | Toast.makeText(this, getString(R.string.select_null), Toast.LENGTH_SHORT).show();
228 | return;
229 | }
230 | Intent intent = new Intent(this, PreviewActivity.class);
231 | intent.putExtra(PickerConfig.MAX_SELECT_COUNT, argsIntent.getIntExtra(PickerConfig.MAX_SELECT_COUNT, PickerConfig.DEFAULT_SELECTED_MAX_COUNT));
232 | intent.putExtra(PickerConfig.PRE_RAW_LIST, gridAdapter.getSelectMedias());
233 | this.startActivityForResult(intent, 200);
234 | }
235 | }
236 |
237 | public void done(ArrayList selects) {
238 | Intent intent = new Intent();
239 | intent.putParcelableArrayListExtra(PickerConfig.EXTRA_RESULT, selects);
240 | setResult(PickerConfig.RESULT_CODE, intent);
241 | finish();
242 | }
243 |
244 | @Override
245 | protected void onDestroy() {
246 | Glide.get(this).clearMemory();
247 | super.onDestroy();
248 | }
249 |
250 | @Override
251 | public void onBackPressed() {
252 | ArrayList selectMedias = new ArrayList<>();
253 | done(selectMedias);
254 | super.onBackPressed();
255 | }
256 |
257 | @Override
258 | public void onConfigurationChanged(Configuration newConfig) {
259 | super.onConfigurationChanged(newConfig);
260 | }
261 |
262 | @Override
263 | public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
264 | super.onRequestPermissionsResult(requestCode, permissions, grantResults);
265 | EasyPermissions.onRequestPermissionsResult(requestCode, permissions, grantResults, this);
266 | }
267 |
268 | @Override
269 | protected void onActivityResult(int requestCode, int resultCode, Intent data) {
270 | super.onActivityResult(requestCode, resultCode, data);
271 | if (requestCode == 200) {
272 | ArrayList selects = data.getParcelableArrayListExtra(PickerConfig.EXTRA_RESULT);
273 | if (resultCode == PickerConfig.RESULT_UPDATE_CODE) {
274 | gridAdapter.updateSelectAdapter(selects);
275 | setButtonText();
276 | } else if (resultCode == PickerConfig.RESULT_CODE) {
277 | done(selects);
278 | }
279 | }else if(requestCode == 300){
280 | if(data==null){
281 | finish();
282 | return;
283 | }
284 | int count = data.getClipData().getItemCount();
285 | ArrayList selects=new ArrayList<>();
286 | for(int i=0; i= Build.VERSION_CODES.KITKAT) {
289 | int flag = Intent.FLAG_GRANT_READ_URI_PERMISSION;
290 | getContentResolver().takePersistableUriPermission(uri, flag);
291 | }
292 | String[] MEDIA_PROJECTION = {
293 | MediaStore.Files.FileColumns.DATA,
294 | MediaStore.Files.FileColumns.DISPLAY_NAME,
295 | MediaStore.Files.FileColumns.DATE_TAKEN,
296 | MediaStore.Files.FileColumns.MIME_TYPE,
297 | MediaStore.Files.FileColumns.SIZE};
298 | Cursor cursor =
299 | getContentResolver().query(uri, MEDIA_PROJECTION, null, null, null);
300 | cursor.moveToFirst();
301 | String path = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA));
302 | String name = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DISPLAY_NAME));
303 | long dateTime = cursor.getLong(cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATE_TAKEN));
304 | String mediaType = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Images.Media.MIME_TYPE));
305 | Log.e("dmc", "MIME_TYPE "+mediaType);
306 | long size = cursor.getLong(cursor.getColumnIndexOrThrow(MediaStore.Images.Media.SIZE));
307 |
308 | Media media = new Media(path, name, dateTime,getTypeByMIME_TYPE(mediaType), size, -1, "");
309 | Log.e("dmc", "path "+media.path);
310 | Log.e("dmc", "name "+media.name);
311 | Log.e("dmc", "size "+media.size);
312 | Log.e("dmc", "mediaType "+media.mediaType);
313 | Log.e("dmc", "time "+media.time);
314 | selects.add(media);
315 | cursor.close();
316 | }
317 | done(selects);
318 | }
319 | }
320 |
321 |
322 | public int getTypeByMIME_TYPE(String type){
323 | if(type.indexOf("image")!=-1){
324 | return 1;
325 | }else if(type.indexOf("video")!=-1){
326 | return 3;
327 | }
328 | return -1;
329 | }
330 | }
331 |
--------------------------------------------------------------------------------
/mediapicker/src/main/java/com/dmcbig/mediapicker/PickerConfig.java:
--------------------------------------------------------------------------------
1 | package com.dmcbig.mediapicker;
2 |
3 | /**
4 | * Created by dmcBig on 2017/6/9.
5 | */
6 |
7 | public class PickerConfig {
8 | public static final String LOG_TAG = "MediaPicker";
9 |
10 | /**
11 | * 最大图片选择次数,int类型,默认40
12 | */
13 | public static final String MAX_SELECT_COUNT = "max_select_count";
14 |
15 | public static final int DEFAULT_SELECTED_MAX_COUNT = 40;
16 |
17 | /**
18 | * 最大文件大小,int类型,默认180m
19 | */
20 | public static final String MAX_SELECT_SIZE = "max_select_size";
21 |
22 | public static final long DEFAULT_SELECTED_MAX_SIZE = 188743680;
23 |
24 | /**
25 | * 图片选择模式,默认选视频和图片
26 | */
27 | public static final String SELECT_MODE = "select_mode";
28 |
29 | /**
30 | * 选择结果,返回为 ArrayList<String> 图片路径集合
31 | */
32 | public static final String EXTRA_RESULT = "select_result";
33 | /**
34 | * 默认选择集
35 | */
36 | public static final String DEFAULT_SELECTED_LIST = "default_list";
37 | /**
38 | * 预览集
39 | */
40 | public static final String PRE_RAW_LIST = "pre_raw_List";
41 | public static final int RESULT_CODE = 19901026;
42 | public static final int RESULT_UPDATE_CODE = 1990;
43 | public static final int PICKER_IMAGE = 100;
44 | public static final int PICKER_VIDEO = 102;
45 | public static final int PICKER_IMAGE_VIDEO = 101;
46 | public static int GridSpanCount = 3;
47 | public static int GridSpace = 4;
48 | }
49 |
--------------------------------------------------------------------------------
/mediapicker/src/main/java/com/dmcbig/mediapicker/PreviewActivity.java:
--------------------------------------------------------------------------------
1 | package com.dmcbig.mediapicker;
2 |
3 |
4 | import android.content.Intent;
5 | import android.os.Bundle;
6 | import androidx.annotation.Nullable;
7 | import androidx.fragment.app.Fragment;
8 | import androidx.fragment.app.FragmentActivity;
9 | import androidx.fragment.app.FragmentManager;
10 | import androidx.fragment.app.FragmentStatePagerAdapter;
11 | import androidx.core.content.ContextCompat;
12 | import androidx.viewpager.widget.ViewPager;
13 | import androidx.appcompat.app.AppCompatActivity;
14 | import android.util.Log;
15 | import android.view.GestureDetector;
16 | import android.view.MotionEvent;
17 | import android.view.View;
18 | import android.widget.Button;
19 | import android.widget.ImageView;
20 | import android.widget.LinearLayout;
21 | import android.widget.TextView;
22 |
23 | import com.dmcbig.mediapicker.entity.Media;
24 | import com.dmcbig.mediapicker.view.PreviewFragment;
25 |
26 | import java.util.ArrayList;
27 | import java.util.Calendar;
28 | import java.util.List;
29 |
30 | /**
31 | * Created by dmcBig on 2017/8/9.
32 | */
33 |
34 | public class PreviewActivity extends FragmentActivity implements View.OnClickListener, ViewPager.OnPageChangeListener{
35 |
36 | Button done;
37 | LinearLayout check_layout;
38 | ImageView check_image;
39 | ViewPager viewpager;
40 | TextView bar_title;
41 | View top,bottom;
42 | ArrayList preRawList, selects;
43 | @Override
44 | protected void onCreate(@Nullable Bundle savedInstanceState) {
45 | super.onCreate(savedInstanceState);
46 | setContentView(R.layout.preview_main);
47 | findViewById(R.id.btn_back).setOnClickListener(this);
48 | check_image = (ImageView) findViewById(R.id.check_image);
49 | check_layout = (LinearLayout) findViewById(R.id.check_layout);
50 | check_layout.setOnClickListener(this);
51 | bar_title = (TextView) findViewById(R.id.bar_title);
52 | done = (Button) findViewById(R.id.done);
53 | done.setOnClickListener(this);
54 | top= findViewById(R.id.top);
55 | bottom= findViewById(R.id.bottom);
56 | viewpager = (ViewPager) findViewById(R.id.viewpager);
57 | preRawList = getIntent().getParcelableArrayListExtra(PickerConfig.PRE_RAW_LIST);
58 | selects = new ArrayList<>();
59 | selects.addAll(preRawList);
60 | setView(preRawList);
61 | }
62 |
63 | void setView(ArrayList default_list) {
64 | setDoneView(default_list.size());
65 | bar_title.setText(1 + "/" + preRawList.size());
66 | ArrayList fragmentArrayList = new ArrayList<>();
67 | for (Media media : default_list) {
68 | fragmentArrayList.add(PreviewFragment.newInstance(media, ""));
69 | }
70 | AdapterFragment adapterFragment = new AdapterFragment(getSupportFragmentManager(), fragmentArrayList);
71 | viewpager.setAdapter(adapterFragment);
72 | viewpager.addOnPageChangeListener(this);
73 | }
74 |
75 | void setDoneView(int num1) {
76 | done.setText(getString(R.string.done) + "(" + num1 + "/" + getIntent().getIntExtra(PickerConfig.MAX_SELECT_COUNT, PickerConfig.DEFAULT_SELECTED_MAX_COUNT) + ")");
77 | }
78 |
79 |
80 | @Override
81 | public void onClick(View v) {
82 | int id = v.getId();
83 | if (id == R.id.btn_back) {
84 | done(selects, PickerConfig.RESULT_UPDATE_CODE);
85 | } else if (id == R.id.done) {
86 | done(selects, PickerConfig.RESULT_CODE);
87 | } else if (id == R.id.check_layout) {
88 | Media media = preRawList.get(viewpager.getCurrentItem());
89 | int select = isSelect(media, selects);
90 | if (select < 0) {
91 | check_image.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.btn_selected));
92 | selects.add(media);
93 | } else {
94 | check_image.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.btn_unselected));
95 | selects.remove(select);
96 | }
97 | setDoneView(selects.size());
98 | }
99 | }
100 |
101 | /**
102 | * @param media
103 | * @return 大于等于0 就是表示以选择,返回的是在selectMedias中的下标
104 | */
105 | public int isSelect(Media media, ArrayList list) {
106 | int is = -1;
107 | if (list.size() <= 0) {
108 | return is;
109 | }
110 | for (int i = 0; i < list.size(); i++) {
111 | Media m = list.get(i);
112 | if (m.path.equals(media.path)) {
113 | is = i;
114 | break;
115 | }
116 | }
117 | return is;
118 | }
119 |
120 | public void done(ArrayList list, int code) {
121 | Intent intent = new Intent();
122 | intent.putParcelableArrayListExtra(PickerConfig.EXTRA_RESULT, list);
123 | setResult(code, intent);
124 | finish();
125 | }
126 |
127 | public void setBarStatus(){
128 | Log.e("setBarStatus","setBarStatus");
129 | if(top.getVisibility()==View.VISIBLE){
130 | top.setVisibility(View.GONE);
131 | bottom.setVisibility(View.GONE);
132 | }else{
133 | top.setVisibility(View.VISIBLE);
134 | bottom.setVisibility(View.VISIBLE);
135 | }
136 | }
137 |
138 |
139 |
140 | @Override
141 | public void onBackPressed() {
142 | done(selects, PickerConfig.RESULT_UPDATE_CODE);
143 | super.onBackPressed();
144 | }
145 |
146 |
147 |
148 | public class AdapterFragment extends FragmentStatePagerAdapter {
149 | private List mFragments;
150 |
151 | public AdapterFragment(FragmentManager fm, List mFragments) {
152 | super(fm);
153 | this.mFragments = mFragments;
154 | }
155 |
156 | @Override
157 | public Fragment getItem(int position) {
158 | return mFragments.get(position);
159 | }
160 |
161 | @Override
162 | public int getCount() {
163 | return mFragments.size();
164 | }
165 |
166 | }
167 |
168 | @Override
169 | public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
170 | }
171 |
172 | @Override
173 | public void onPageSelected(int position) {
174 | bar_title.setText((position + 1) + "/" + preRawList.size());
175 | check_image.setImageDrawable(isSelect(preRawList.get(position), selects) < 0 ? ContextCompat.getDrawable(this, R.drawable.btn_unselected) : ContextCompat.getDrawable(this, R.drawable.btn_selected));
176 | }
177 |
178 | @Override
179 | public void onPageScrollStateChanged(int state) {
180 | }
181 | }
182 |
--------------------------------------------------------------------------------
/mediapicker/src/main/java/com/dmcbig/mediapicker/TakePhotoActivity.java:
--------------------------------------------------------------------------------
1 | package com.dmcbig.mediapicker;
2 |
3 | import android.app.Activity;
4 | import android.content.Intent;
5 | import android.net.Uri;
6 | import android.os.Build;
7 | import android.os.Bundle;
8 | import android.os.Environment;
9 | import android.provider.MediaStore;
10 | import androidx.annotation.Nullable;
11 | import androidx.core.content.FileProvider;
12 | import android.widget.Toast;
13 |
14 | import com.dmcbig.mediapicker.entity.Media;
15 |
16 | import java.io.File;
17 | import java.io.IOException;
18 | import java.text.SimpleDateFormat;
19 | import java.util.ArrayList;
20 | import java.util.Date;
21 |
22 | /**
23 | * Created by dmcBig on 2017/11/14.
24 | */
25 |
26 | public class TakePhotoActivity extends Activity {
27 | Uri NuriForFile;
28 | File mTmpFile = null;
29 |
30 | @Override
31 | protected void onCreate(@Nullable Bundle savedInstanceState) {
32 | super.onCreate(savedInstanceState);
33 | Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
34 |
35 | try {
36 | mTmpFile = createImageFile();
37 | } catch (IOException e) {
38 | e.printStackTrace();
39 | }
40 |
41 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {//如果大于等于7.0使用FileProvider
42 | NuriForFile = FileProvider.getUriForFile(this, this.getPackageName() + ".dmc", mTmpFile);
43 | intent.putExtra(MediaStore.EXTRA_OUTPUT, NuriForFile);
44 | startActivityForResult(intent, 100);
45 | } else {
46 | if (mTmpFile != null && mTmpFile.exists()) {
47 | intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(mTmpFile));
48 | startActivityForResult(intent, 101);
49 | } else {
50 | Toast.makeText(this, "take error", Toast.LENGTH_SHORT).show();
51 | finish();
52 | }
53 | }
54 | }
55 |
56 | @Override
57 | protected void onActivityResult(int requestCode, int resultCode, Intent data) {
58 | super.onActivityResult(requestCode, resultCode, data);
59 | ArrayList medias = new ArrayList<>();
60 | if (requestCode == 100 || requestCode == 101 && resultCode == RESULT_OK&&mTmpFile.length() > 0) {
61 | Media media = new Media(mTmpFile.getPath(), mTmpFile.getName(), 0, 1, mTmpFile.length(), 0, "");
62 | medias.add(media);
63 | }
64 | Intent intent = new Intent();
65 | intent.putParcelableArrayListExtra(PickerConfig.EXTRA_RESULT, medias);
66 | setResult(PickerConfig.RESULT_CODE, intent);
67 | finish();
68 | }
69 |
70 | private File createImageFile() throws IOException {
71 | // Create an image file name
72 | String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
73 | String imageFileName = "JPEG_" + timeStamp + "_";
74 | File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES);
75 | File image = File.createTempFile(
76 | imageFileName, /* prefix */
77 | ".jpg", /* suffix */
78 | storageDir /* directory */
79 | );
80 | return image;
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/mediapicker/src/main/java/com/dmcbig/mediapicker/adapter/FolderAdapter.java:
--------------------------------------------------------------------------------
1 | package com.dmcbig.mediapicker.adapter;
2 |
3 | import android.content.Context;
4 | import android.net.Uri;
5 | import androidx.core.content.ContextCompat;
6 | import android.view.LayoutInflater;
7 | import android.view.View;
8 | import android.view.ViewGroup;
9 | import android.widget.BaseAdapter;
10 | import android.widget.ImageView;
11 | import android.widget.TextView;
12 |
13 | import com.bumptech.glide.Glide;
14 | import com.dmcbig.mediapicker.R;
15 | import com.dmcbig.mediapicker.entity.Folder;
16 | import com.dmcbig.mediapicker.entity.Media;
17 |
18 | import java.util.ArrayList;
19 |
20 | /**
21 | * Created by dmcBig on 2017/7/19.
22 | */
23 |
24 | public class FolderAdapter extends BaseAdapter {
25 | ArrayList folders;
26 | private LayoutInflater mInflater;
27 | private Context mContext;
28 | int lastSelected = 0;
29 |
30 | public FolderAdapter(ArrayList folders, Context context) {
31 | mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
32 | this.folders = folders;
33 | this.mContext = context;
34 | }
35 |
36 | @Override
37 | public int getCount() {
38 | return folders.size();
39 | }
40 |
41 | @Override
42 | public Folder getItem(int position) {
43 | return folders.get(position);
44 | }
45 |
46 | @Override
47 | public long getItemId(int position) {
48 | return 0;
49 | }
50 |
51 | public void updateAdapter(ArrayList list) {
52 | this.folders = list;
53 | notifyDataSetChanged();
54 | }
55 |
56 | @Override
57 | public View getView(int position, View view, ViewGroup viewGroup) {
58 | ViewHolder holder;
59 | if (view == null) {
60 | view = mInflater.inflate(R.layout.folders_view_item, viewGroup, false);
61 | holder = new ViewHolder(view);
62 | } else {
63 | holder = (ViewHolder) view.getTag();
64 | }
65 |
66 | Folder folder = getItem(position);
67 | Media media;
68 | if (folder.getMedias().size() > 0) {
69 | media = folder.getMedias().get(0);
70 | Glide.with(mContext)
71 | .load(Uri.parse("file://" + media.path))
72 | .into(holder.cover);
73 | } else {
74 | holder.cover.setImageDrawable(ContextCompat.getDrawable(mContext, R.drawable.default_image));
75 | }
76 |
77 | holder.name.setText(folder.name);
78 |
79 | holder.size.setText(folder.getMedias().size() + "" + mContext.getString(R.string.count_string));
80 | holder.indicator.setVisibility(lastSelected == position ? View.VISIBLE : View.INVISIBLE);
81 | return view;
82 | }
83 |
84 |
85 | public void setSelectIndex(int i) {
86 | if (lastSelected == i) return;
87 | lastSelected = i;
88 | notifyDataSetChanged();
89 | }
90 |
91 | public ArrayList getSelectMedias() {
92 | return folders.get(lastSelected).getMedias();
93 | }
94 |
95 | class ViewHolder {
96 | ImageView cover, indicator;
97 | TextView name, path, size;
98 |
99 | ViewHolder(View view) {
100 | cover = (ImageView) view.findViewById(R.id.cover);
101 | name = (TextView) view.findViewById(R.id.name);
102 | path = (TextView) view.findViewById(R.id.path);
103 | size = (TextView) view.findViewById(R.id.size);
104 | indicator = (ImageView) view.findViewById(R.id.indicator);
105 | view.setTag(this);
106 | }
107 | }
108 | }
109 |
--------------------------------------------------------------------------------
/mediapicker/src/main/java/com/dmcbig/mediapicker/adapter/MediaGridAdapter.java:
--------------------------------------------------------------------------------
1 | package com.dmcbig.mediapicker.adapter;
2 |
3 |
4 | import android.content.Context;
5 | import android.net.Uri;
6 | import androidx.core.content.ContextCompat;
7 | import androidx.recyclerview.widget.RecyclerView;
8 | import android.view.LayoutInflater;
9 | import android.view.View;
10 | import android.view.ViewGroup;
11 | import android.widget.AbsListView;
12 | import android.widget.ImageView;
13 | import android.widget.RelativeLayout;
14 | import android.widget.TextView;
15 | import android.widget.Toast;
16 |
17 | import com.bumptech.glide.Glide;
18 | import com.dmcbig.mediapicker.PickerConfig;
19 | import com.dmcbig.mediapicker.R;
20 | import com.dmcbig.mediapicker.entity.Media;
21 | import com.dmcbig.mediapicker.utils.FileUtils;
22 | import com.dmcbig.mediapicker.utils.ScreenUtils;
23 |
24 | import java.util.ArrayList;
25 |
26 | /**
27 | * Created by dmcBig on 2017/7/5.
28 | */
29 |
30 | public class MediaGridAdapter extends RecyclerView.Adapter {
31 |
32 | ArrayList medias;
33 | Context context;
34 | FileUtils fileUtils = new FileUtils();
35 | ArrayList selectMedias = new ArrayList<>();
36 | long maxSelect, maxSize;
37 |
38 | public MediaGridAdapter(ArrayList list, Context context, ArrayList select, int max, long maxSize) {
39 | if (select != null) {
40 | this.selectMedias = select;
41 | }
42 | this.maxSelect = max;
43 | this.maxSize = maxSize;
44 | this.medias = list;
45 | this.context = context;
46 | }
47 |
48 |
49 | public class MyViewHolder extends RecyclerView.ViewHolder {
50 | public ImageView media_image, check_image;
51 | public View mask_view;
52 | public TextView textView_size;
53 | public RelativeLayout gif_info;
54 | public RelativeLayout video_info;
55 |
56 | public MyViewHolder(View view) {
57 | super(view);
58 | media_image = (ImageView) view.findViewById(R.id.media_image);
59 | check_image = (ImageView) view.findViewById(R.id.check_image);
60 | mask_view = view.findViewById(R.id.mask_view);
61 | video_info = (RelativeLayout) view.findViewById(R.id.video_info);
62 | gif_info = (RelativeLayout) view.findViewById(R.id.gif_info);
63 | textView_size = (TextView) view.findViewById(R.id.textView_size);
64 | itemView.setLayoutParams(new AbsListView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, getItemWidth())); //让图片是个正方形
65 | }
66 | }
67 |
68 | int getItemWidth() {
69 | return (ScreenUtils.getScreenWidth(context) / PickerConfig.GridSpanCount) - PickerConfig.GridSpanCount;
70 | }
71 |
72 | @Override
73 | public MyViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
74 | View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.media_view_item, viewGroup, false);
75 | MyViewHolder vh = new MyViewHolder(view);
76 | return vh;
77 | }
78 |
79 | @Override
80 | public void onBindViewHolder(final MyViewHolder holder, int position) {
81 | final Media media = medias.get(position);
82 | Uri mediaUri = Uri.parse("file://" + media.path);
83 |
84 | Glide.with(context)
85 | .load(mediaUri)
86 | .into(holder.media_image);
87 |
88 | if (media.mediaType == 3) {
89 | holder.gif_info.setVisibility(View.INVISIBLE);
90 | holder.video_info.setVisibility(View.VISIBLE);
91 | holder.textView_size.setText(fileUtils.getSizeByUnit(media.size));
92 | } else {
93 | holder.video_info.setVisibility(View.INVISIBLE);
94 | holder.gif_info.setVisibility(".gif".equalsIgnoreCase(media.extension) ? View.VISIBLE : View.INVISIBLE);
95 | }
96 |
97 | int isSelect = isSelect(media);
98 | holder.mask_view.setVisibility(isSelect >= 0 ? View.VISIBLE : View.INVISIBLE);
99 | holder.check_image.setImageDrawable(isSelect >= 0 ? ContextCompat.getDrawable(context, R.drawable.btn_selected) : ContextCompat.getDrawable(context, R.drawable.btn_unselected));
100 |
101 |
102 | holder.media_image.setOnClickListener(new View.OnClickListener() {
103 | @Override
104 | public void onClick(View v) {
105 |
106 | int isSelect = isSelect(media);
107 | if (selectMedias.size() >= maxSelect && isSelect < 0) {
108 | Toast.makeText(context, context.getString(R.string.msg_amount_limit), Toast.LENGTH_SHORT).show();
109 | } else {
110 | if (media.size > maxSize) {
111 | Toast.makeText(context, context.getString(R.string.msg_size_limit) + (FileUtils.fileSize(maxSize)), Toast.LENGTH_LONG).show();
112 | } else {
113 | holder.mask_view.setVisibility(isSelect >= 0 ? View.INVISIBLE : View.VISIBLE);
114 | holder.check_image.setImageDrawable(isSelect >= 0 ? ContextCompat.getDrawable(context, R.drawable.btn_unselected) : ContextCompat.getDrawable(context, R.drawable.btn_selected));
115 | setSelectMedias(media);
116 | mOnItemClickListener.onItemClick(v, media, selectMedias);
117 | }
118 | }
119 |
120 | }
121 | });
122 | }
123 |
124 |
125 | public void setSelectMedias(Media media) {
126 | int index = isSelect(media);
127 | if (index == -1) {
128 | selectMedias.add(media);
129 | } else {
130 | selectMedias.remove(index);
131 | }
132 | }
133 |
134 | /**
135 | * @param media
136 | * @return 大于等于0 就是表示以选择,返回的是在selectMedias中的下标
137 | */
138 | public int isSelect(Media media) {
139 | int is = -1;
140 | if (selectMedias.size() <= 0) {
141 | return is;
142 | }
143 | for (int i = 0; i < selectMedias.size(); i++) {
144 | Media m = selectMedias.get(i);
145 | if (m.path.equals(media.path)) {
146 | is = i;
147 | break;
148 | }
149 | }
150 | return is;
151 | }
152 |
153 | public void updateSelectAdapter(ArrayList select) {
154 | if (select != null) {
155 | this.selectMedias = select;
156 | }
157 | notifyDataSetChanged();
158 | }
159 |
160 | public void updateAdapter(ArrayList list) {
161 | this.medias = list;
162 | notifyDataSetChanged();
163 | }
164 |
165 | private OnRecyclerViewItemClickListener mOnItemClickListener = null;
166 |
167 | public void setOnItemClickListener(OnRecyclerViewItemClickListener listener) {
168 | this.mOnItemClickListener = listener;
169 | }
170 |
171 | public ArrayList getSelectMedias() {
172 | return selectMedias;
173 | }
174 |
175 | @Override
176 | public int getItemCount() {
177 | return medias.size();
178 | }
179 |
180 | public interface OnRecyclerViewItemClickListener {
181 | void onItemClick(View view, Media data, ArrayList selectMedias);
182 | }
183 | }
184 |
--------------------------------------------------------------------------------
/mediapicker/src/main/java/com/dmcbig/mediapicker/adapter/SpacingDecoration.java:
--------------------------------------------------------------------------------
1 | package com.dmcbig.mediapicker.adapter;
2 |
3 | import android.graphics.Rect;
4 | import androidx.recyclerview.widget.RecyclerView;
5 | import android.view.View;
6 |
7 | /**
8 | * Created by dmcBig on 2017/7/11.
9 | */
10 |
11 | public class SpacingDecoration extends RecyclerView.ItemDecoration {
12 |
13 | private int space;
14 | private int spanCount;
15 |
16 | public SpacingDecoration(int spanCount, int space) {
17 | this.spanCount = spanCount;
18 | this.space = space;
19 | }
20 |
21 | @Override
22 | public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
23 | //不是第一个的格子都设一个左边和底部的间距
24 | outRect.left = space;
25 | outRect.bottom = space;
26 | int position = parent.getChildLayoutPosition(view);
27 | if (position % spanCount == 0) {
28 | outRect.left = 0;
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/mediapicker/src/main/java/com/dmcbig/mediapicker/data/DataCallback.java:
--------------------------------------------------------------------------------
1 | package com.dmcbig.mediapicker.data;
2 |
3 | import com.dmcbig.mediapicker.entity.Folder;
4 |
5 | import java.util.ArrayList;
6 |
7 |
8 | /**
9 | * Created by dmcBig on 2017/7/3.
10 | */
11 |
12 | public interface DataCallback {
13 |
14 |
15 | void onData(ArrayList list);
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/mediapicker/src/main/java/com/dmcbig/mediapicker/data/ImageLoader.java:
--------------------------------------------------------------------------------
1 | package com.dmcbig.mediapicker.data;
2 |
3 |
4 | import android.content.Context;
5 |
6 | import android.content.res.Resources;
7 | import android.database.Cursor;
8 | import android.net.Uri;
9 | import android.os.Bundle;
10 | import android.provider.MediaStore;
11 |
12 | import androidx.loader.app.LoaderManager;
13 | import androidx.loader.content.CursorLoader;
14 | import androidx.loader.content.Loader;
15 |
16 | import com.dmcbig.mediapicker.R;
17 | import com.dmcbig.mediapicker.entity.Folder;
18 | import com.dmcbig.mediapicker.entity.Media;
19 |
20 | import java.util.ArrayList;
21 |
22 | /**
23 | * Created by dmcBig on 2017/7/3.
24 | */
25 |
26 | public class ImageLoader extends LoaderM implements LoaderManager.LoaderCallbacks {
27 |
28 | String[] IMAGE_PROJECTION = {
29 | MediaStore.Images.Media.DATA,
30 | MediaStore.Images.Media.DISPLAY_NAME,
31 | MediaStore.Images.Media.DATE_ADDED,
32 | MediaStore.Images.Media.MIME_TYPE,
33 | MediaStore.Images.Media.SIZE,
34 | MediaStore.Images.Media._ID};
35 |
36 | Context mContext;
37 | DataCallback mLoader;
38 |
39 | public ImageLoader(Context context, DataCallback loader) {
40 | this.mContext = context;
41 | this.mLoader = loader;
42 | }
43 |
44 | @Override
45 | public Loader onCreateLoader(int picker_type, Bundle bundle) {
46 | Uri queryUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
47 | CursorLoader cursorLoader = new CursorLoader(
48 | mContext,
49 | queryUri,
50 | IMAGE_PROJECTION,
51 | null,
52 | null, // Selection args (none).
53 | MediaStore.Images.Media.DATE_ADDED + " DESC" // Sort order.
54 | );
55 | return cursorLoader;
56 | }
57 |
58 | @Override
59 | public void onLoadFinished(Loader loader, Object o) {
60 | try {
61 | ArrayList folders = new ArrayList<>();
62 | Folder allFolder = new Folder(mContext.getResources().getString(R.string.all_image));
63 | folders.add(allFolder);
64 | Cursor cursor = (Cursor) o;
65 | while (cursor.moveToNext()) {
66 |
67 | String path = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA));
68 | String name = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DISPLAY_NAME));
69 | long dateTime = cursor.getLong(cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATE_ADDED));
70 | int mediaType = cursor.getInt(cursor.getColumnIndexOrThrow(MediaStore.Images.Media.MIME_TYPE));
71 | long size = cursor.getLong(cursor.getColumnIndexOrThrow(MediaStore.Images.Media.SIZE));
72 | int id = cursor.getInt(cursor.getColumnIndexOrThrow(MediaStore.Images.Media._ID));
73 |
74 | if (size < 1) continue;
75 | if(path == null || path.equals("")) continue;
76 | String dirName = getParent(path);
77 | Media media = new Media(path, name, dateTime, mediaType, size, id, dirName);
78 | allFolder.addMedias(media);
79 |
80 | int index = hasDir(folders, dirName);
81 | if (index != -1) {
82 | folders.get(index).addMedias(media);
83 | } else {
84 | Folder folder = new Folder(dirName);
85 | folder.addMedias(media);
86 | folders.add(folder);
87 | }
88 | }
89 | mLoader.onData(folders);
90 | cursor.close();
91 | } catch (Exception e) {
92 | e.printStackTrace();
93 | }
94 | }
95 |
96 | @Override
97 | public void onLoaderReset(Loader loader) {
98 |
99 | }
100 |
101 |
102 | }
--------------------------------------------------------------------------------
/mediapicker/src/main/java/com/dmcbig/mediapicker/data/LoaderM.java:
--------------------------------------------------------------------------------
1 | package com.dmcbig.mediapicker.data;
2 |
3 | import com.dmcbig.mediapicker.entity.Folder;
4 |
5 | import java.util.ArrayList;
6 |
7 | /**
8 | * Created by dmcBig on 2017/7/20.
9 | */
10 |
11 | public class LoaderM {
12 |
13 | public String getParent(String path) {
14 | String sp[] = path.split("/");
15 | return sp[sp.length - 2];
16 | }
17 |
18 | public int hasDir(ArrayList folders, String dirName) {
19 | for (int i = 0; i < folders.size(); i++) {
20 | Folder folder = folders.get(i);
21 | if (folder.name.equals(dirName)) {
22 | return i;
23 | }
24 | }
25 | return -1;
26 | }
27 |
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/mediapicker/src/main/java/com/dmcbig/mediapicker/data/MediaLoader.java:
--------------------------------------------------------------------------------
1 | package com.dmcbig.mediapicker.data;
2 |
3 |
4 | import android.content.Context;
5 | import android.content.res.Resources;
6 | import android.database.Cursor;
7 | import android.net.Uri;
8 | import android.os.Bundle;
9 | import android.provider.MediaStore;
10 | import android.util.Log;
11 | import android.widget.Toast;
12 |
13 | import androidx.loader.app.LoaderManager;
14 | import androidx.loader.content.CursorLoader;
15 | import androidx.loader.content.Loader;
16 |
17 | import com.dmcbig.mediapicker.R;
18 | import com.dmcbig.mediapicker.entity.Folder;
19 | import com.dmcbig.mediapicker.entity.Media;
20 |
21 | import java.util.ArrayList;
22 |
23 |
24 | /**
25 | * Created by dmcBig on 2017/6/9.
26 | */
27 |
28 | public class MediaLoader extends LoaderM implements LoaderManager.LoaderCallbacks {
29 | String[] MEDIA_PROJECTION = {
30 | MediaStore.Files.FileColumns.DATA,
31 | MediaStore.Files.FileColumns.DISPLAY_NAME,
32 | MediaStore.Files.FileColumns.DATE_ADDED,
33 | MediaStore.Files.FileColumns.MEDIA_TYPE,
34 | MediaStore.Files.FileColumns.SIZE,
35 | MediaStore.Files.FileColumns._ID,
36 | MediaStore.Files.FileColumns.PARENT};
37 |
38 | Context mContext;
39 | DataCallback mLoader;
40 |
41 | public MediaLoader(Context context, DataCallback loader) {
42 | this.mContext = context;
43 | this.mLoader = loader;
44 | }
45 |
46 | @Override
47 | public Loader onCreateLoader(int picker_type, Bundle bundle) {
48 | String selection = MediaStore.Files.FileColumns.MEDIA_TYPE + "="
49 | + MediaStore.Files.FileColumns.MEDIA_TYPE_IMAGE
50 | + " OR "
51 | + MediaStore.Files.FileColumns.MEDIA_TYPE + "="
52 | + MediaStore.Files.FileColumns.MEDIA_TYPE_VIDEO;
53 |
54 | Uri queryUri = MediaStore.Files.getContentUri("external");
55 | CursorLoader cursorLoader = new CursorLoader(
56 | mContext,
57 | queryUri,
58 | MEDIA_PROJECTION,
59 | selection,
60 | null, // Selection args (none).
61 | MediaStore.Files.FileColumns.DATE_ADDED + " DESC" // Sort order.
62 | );
63 | return cursorLoader;
64 | }
65 |
66 | @Override
67 | public void onLoadFinished(Loader loader, Object o) {
68 | try {
69 | ArrayList folders = new ArrayList<>();
70 | Folder allFolder = new Folder(mContext.getResources().getString(R.string.all_dir_name));
71 | folders.add(allFolder);
72 | Folder allVideoDir = new Folder(mContext.getResources().getString(R.string.video_dir_name));
73 | folders.add(allVideoDir);
74 | Cursor cursor = (Cursor) o;
75 | while (cursor.moveToNext()) {
76 | String path = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Files.FileColumns.DATA));
77 | String name = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Files.FileColumns.DISPLAY_NAME));
78 | long dateTime = cursor.getLong(cursor.getColumnIndexOrThrow(MediaStore.Files.FileColumns.DATE_ADDED));
79 | int mediaType = cursor.getInt(cursor.getColumnIndexOrThrow(MediaStore.Files.FileColumns.MEDIA_TYPE));
80 | long size = cursor.getLong(cursor.getColumnIndexOrThrow(MediaStore.Files.FileColumns.SIZE));
81 | int id = cursor.getInt(cursor.getColumnIndexOrThrow(MediaStore.Files.FileColumns._ID));
82 |
83 | if (size < 1) continue;
84 | if(path == null || path.equals("")) continue;
85 | String dirName = getParent(path);
86 | Media media = new Media(path, name, dateTime, mediaType, size, id, dirName);
87 | allFolder.addMedias(media);
88 | if (mediaType == 3) {
89 | allVideoDir.addMedias(media);
90 | }
91 |
92 | int index = hasDir(folders, dirName);
93 | if (index != -1) {
94 | folders.get(index).addMedias(media);
95 | } else {
96 | Folder folder = new Folder(dirName);
97 | folder.addMedias(media);
98 | folders.add(folder);
99 | }
100 | }
101 | mLoader.onData(folders);
102 | cursor.close();
103 | } catch (Exception e) {
104 | e.printStackTrace();
105 | }
106 | }
107 |
108 |
109 | @Override
110 | public void onLoaderReset(Loader loader) {
111 |
112 | }
113 | }
114 |
--------------------------------------------------------------------------------
/mediapicker/src/main/java/com/dmcbig/mediapicker/data/VideoLoader.java:
--------------------------------------------------------------------------------
1 | package com.dmcbig.mediapicker.data;
2 |
3 |
4 | import android.content.Context;
5 | import android.content.res.Resources;
6 | import android.database.Cursor;
7 | import android.net.Uri;
8 | import android.os.Bundle;
9 | import android.provider.MediaStore;
10 | import android.util.Log;
11 |
12 | import androidx.loader.app.LoaderManager;
13 | import androidx.loader.content.CursorLoader;
14 | import androidx.loader.content.Loader;
15 |
16 | import com.dmcbig.mediapicker.R;
17 | import com.dmcbig.mediapicker.entity.Folder;
18 | import com.dmcbig.mediapicker.entity.Media;
19 |
20 | import java.util.ArrayList;
21 |
22 |
23 | /**
24 | * Created by dmcBig on 2017/6/9.
25 | */
26 |
27 | public class VideoLoader extends LoaderM implements LoaderManager.LoaderCallbacks {
28 | String[] MEDIA_PROJECTION = {
29 | MediaStore.Files.FileColumns.DATA,
30 | MediaStore.Files.FileColumns.DISPLAY_NAME,
31 | MediaStore.Files.FileColumns.DATE_ADDED,
32 | MediaStore.Files.FileColumns.MEDIA_TYPE,
33 | MediaStore.Files.FileColumns.SIZE,
34 | MediaStore.Files.FileColumns._ID,
35 | MediaStore.Files.FileColumns.PARENT};
36 |
37 | Context mContext;
38 | DataCallback mLoader;
39 |
40 | public VideoLoader(Context context, DataCallback loader) {
41 | this.mContext = context;
42 | this.mLoader = loader;
43 | }
44 |
45 | @Override
46 | public Loader onCreateLoader(int picker_type, Bundle bundle) {
47 | String selection = MediaStore.Files.FileColumns.MEDIA_TYPE + "="
48 | + MediaStore.Files.FileColumns.MEDIA_TYPE_VIDEO;
49 |
50 | Uri queryUri = MediaStore.Files.getContentUri("external");
51 | CursorLoader cursorLoader = new CursorLoader(
52 | mContext,
53 | queryUri,
54 | MEDIA_PROJECTION,
55 | selection,
56 | null, // Selection args (none).
57 | MediaStore.Files.FileColumns.DATE_ADDED + " DESC" // Sort order.
58 | );
59 | return cursorLoader;
60 | }
61 |
62 | @Override
63 | public void onLoadFinished(Loader loader, Object o) {
64 | try {
65 | ArrayList folders = new ArrayList<>();
66 | Folder allFolder = new Folder(mContext.getResources().getString(R.string.all_video));
67 | folders.add(allFolder);
68 | Cursor cursor = (Cursor) o;
69 | Log.e("dmc", cursor.getCount() + "数量数量");
70 | while (cursor.moveToNext()) {
71 | String path = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Files.FileColumns.DATA));
72 | String name = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Files.FileColumns.DISPLAY_NAME));
73 | long dateTime = cursor.getLong(cursor.getColumnIndexOrThrow(MediaStore.Files.FileColumns.DATE_ADDED));
74 | int mediaType = cursor.getInt(cursor.getColumnIndexOrThrow(MediaStore.Files.FileColumns.MEDIA_TYPE));
75 | long size = cursor.getLong(cursor.getColumnIndexOrThrow(MediaStore.Files.FileColumns.SIZE));
76 | int id = cursor.getInt(cursor.getColumnIndexOrThrow(MediaStore.Files.FileColumns._ID));
77 |
78 | if (size < 1) continue;
79 | if (path == null || path.equals("")) continue;
80 | String dirName = getParent(path);
81 | Media media = new Media(path, name, dateTime, mediaType, size, id, dirName);
82 | allFolder.addMedias(media);
83 |
84 | int index = hasDir(folders, dirName);
85 | if (index != -1) {
86 | folders.get(index).addMedias(media);
87 | } else {
88 | Folder folder = new Folder(dirName);
89 | folder.addMedias(media);
90 | folders.add(folder);
91 | }
92 | }
93 | mLoader.onData(folders);
94 | cursor.close();
95 | } catch (Exception e) {
96 | e.printStackTrace();
97 | }
98 | }
99 |
100 |
101 | @Override
102 | public void onLoaderReset(Loader loader) {
103 |
104 | }
105 | }
106 |
--------------------------------------------------------------------------------
/mediapicker/src/main/java/com/dmcbig/mediapicker/entity/Folder.java:
--------------------------------------------------------------------------------
1 | package com.dmcbig.mediapicker.entity;
2 |
3 | import android.os.Parcel;
4 | import android.os.Parcelable;
5 |
6 | import java.util.ArrayList;
7 |
8 | /**
9 | * Created by dmcBig on 2017/7/4.
10 | */
11 |
12 | public class Folder implements Parcelable {
13 |
14 | public String name;
15 |
16 | public int count;
17 |
18 | ArrayList medias = new ArrayList<>();
19 |
20 | public void addMedias(Media media) {
21 | medias.add(media);
22 | }
23 |
24 | public Folder(String name) {
25 | this.name = name;
26 | }
27 |
28 | public ArrayList getMedias() {
29 | return this.medias;
30 | }
31 |
32 |
33 | @Override
34 | public int describeContents() {
35 | return 0;
36 | }
37 |
38 | @Override
39 | public void writeToParcel(Parcel dest, int flags) {
40 | dest.writeString(this.name);
41 | dest.writeInt(this.count);
42 | dest.writeTypedList(this.medias);
43 | }
44 |
45 |
46 | protected Folder(Parcel in) {
47 | this.name = in.readString();
48 | this.count = in.readInt();
49 | this.medias = in.createTypedArrayList(Media.CREATOR);
50 | }
51 |
52 | public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
53 | @Override
54 | public Folder createFromParcel(Parcel source) {
55 | return new Folder(source);
56 | }
57 |
58 | @Override
59 | public Folder[] newArray(int size) {
60 | return new Folder[size];
61 | }
62 | };
63 | }
64 |
--------------------------------------------------------------------------------
/mediapicker/src/main/java/com/dmcbig/mediapicker/entity/Media.java:
--------------------------------------------------------------------------------
1 | package com.dmcbig.mediapicker.entity;
2 |
3 | import android.net.Uri;
4 | import android.os.Parcel;
5 | import android.os.Parcelable;
6 | import android.text.TextUtils;
7 |
8 | /**
9 | * Created by dmcBig on 2017/7/4.
10 | */
11 |
12 | public class Media implements Parcelable {
13 | public String uri;
14 | public String path;
15 | public String name;
16 | public String extension;
17 | public long time;
18 | public int mediaType;
19 | public long size;
20 | public int id;
21 | public String parentDir;
22 |
23 | public Media(String path, String name, long time, int mediaType, long size, int id, String parentDir) {
24 | this.uri = "";
25 | this.path = path;
26 | this.name = name;
27 | if (!TextUtils.isEmpty(name) && name.indexOf(".") != -1) {
28 | this.extension = name.substring(name.lastIndexOf("."), name.length());
29 | } else {
30 | this.extension = "null";
31 | }
32 | this.time = time;
33 | this.mediaType = mediaType;
34 | this.size = size;
35 | this.id = id;
36 | this.parentDir = parentDir;
37 | }
38 | public Media(String uri,String path, String name, long time, int mediaType, long size, int id, String parentDir) {
39 | this.uri = uri;
40 | this.path = path;
41 | this.name = name;
42 | if (!TextUtils.isEmpty(name) && name.indexOf(".") != -1) {
43 | this.extension = name.substring(name.lastIndexOf("."), name.length());
44 | } else {
45 | this.extension = "null";
46 | }
47 | this.time = time;
48 | this.mediaType = mediaType;
49 | this.size = size;
50 | this.id = id;
51 | this.parentDir = parentDir;
52 | }
53 |
54 | @Override
55 | public int describeContents() {
56 | return 0;
57 | }
58 |
59 | @Override
60 | public void writeToParcel(Parcel dest, int flags) {
61 | dest.writeString(this.uri);
62 | dest.writeString(this.path);
63 | dest.writeString(this.name);
64 | dest.writeString(this.extension);
65 | dest.writeLong(this.time);
66 | dest.writeInt(this.mediaType);
67 | dest.writeLong(this.size);
68 | dest.writeInt(this.id);
69 | dest.writeString(this.parentDir);
70 | }
71 |
72 | protected Media(Parcel in) {
73 | this.uri = in.readString();
74 | this.path = in.readString();
75 | this.name = in.readString();
76 | this.extension = in.readString();
77 | this.time = in.readLong();
78 | this.mediaType = in.readInt();
79 | this.size = in.readLong();
80 | this.id = in.readInt();
81 | this.parentDir = in.readString();
82 | }
83 |
84 |
85 | public static final Creator CREATOR = new Creator() {
86 | @Override
87 | public Media createFromParcel(Parcel source) {
88 | return new Media(source);
89 | }
90 |
91 | @Override
92 | public Media[] newArray(int size) {
93 | return new Media[size];
94 | }
95 | };
96 | }
97 |
--------------------------------------------------------------------------------
/mediapicker/src/main/java/com/dmcbig/mediapicker/utils/DmcFileProvider.java:
--------------------------------------------------------------------------------
1 | package com.dmcbig.mediapicker.utils;
2 |
3 | import androidx.core.content.FileProvider;
4 |
5 | /**
6 | * Created by dmcBig on 2018/5/8.
7 | */
8 |
9 | public class DmcFileProvider extends FileProvider {
10 | }
11 |
--------------------------------------------------------------------------------
/mediapicker/src/main/java/com/dmcbig/mediapicker/utils/FileUtils.java:
--------------------------------------------------------------------------------
1 | package com.dmcbig.mediapicker.utils;
2 |
3 | import android.content.ContentResolver;
4 | import android.content.Context;
5 | import android.content.pm.PackageManager;
6 | import android.database.Cursor;
7 | import android.net.Uri;
8 | import android.os.Environment;
9 | import android.provider.MediaStore;
10 | import android.text.TextUtils;
11 | import android.webkit.MimeTypeMap;
12 |
13 | import java.io.File;
14 | import java.io.IOException;
15 | import java.text.DecimalFormat;
16 | import java.util.Locale;
17 |
18 | import static android.os.Environment.MEDIA_MOUNTED;
19 |
20 | /**
21 | * 文件操作类
22 | * Created by Nereo on 2015/4/8.
23 | */
24 | public class FileUtils {
25 |
26 | private static final String JPEG_FILE_PREFIX = "IMG_";
27 | private static final String JPEG_FILE_SUFFIX = ".jpg";
28 |
29 | public static File createTmpFile(Context context) throws IOException {
30 | File dir = null;
31 | if (TextUtils.equals(Environment.getExternalStorageState(), Environment.MEDIA_MOUNTED)) {
32 | dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM);
33 | if (!dir.exists()) {
34 | dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM + "/Camera");
35 | if (!dir.exists()) {
36 | dir = getCacheDirectory(context, true);
37 | }
38 | }
39 | } else {
40 | dir = getCacheDirectory(context, true);
41 | }
42 | return File.createTempFile(JPEG_FILE_PREFIX, JPEG_FILE_SUFFIX, dir);
43 | }
44 |
45 |
46 | private static final String EXTERNAL_STORAGE_PERMISSION = "android.permission.WRITE_EXTERNAL_STORAGE";
47 |
48 | /**
49 | * Returns application cache directory. Cache directory will be created on SD card
50 | * ("/Android/data/[app_package_name]/cache") if card is mounted and app has appropriate permission. Else -
51 | * Android defines cache directory on device's file system.
52 | *
53 | * @param context Application context
54 | * @return Cache {@link File directory}.
55 | * NOTE: Can be null in some unpredictable cases (if SD card is unmounted and
56 | * {@link Context#getCacheDir() Context.getCacheDir()} returns null).
57 | */
58 | public static File getCacheDirectory(Context context) {
59 | return getCacheDirectory(context, true);
60 | }
61 |
62 | public static String getRealPathFromURI(Context context,Uri contentURI) {
63 | String result;
64 | Cursor cursor = context.getContentResolver().query(contentURI, null, null, null, null);
65 | if (cursor == null) { // Source is Dropbox or other similar local file path
66 | result = contentURI.getPath();
67 | } else {
68 | cursor.moveToFirst();
69 | int idx = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA);
70 | result = cursor.getString(idx);
71 | cursor.close();
72 | }
73 | return result;
74 | }
75 |
76 | /**
77 | * Returns application cache directory. Cache directory will be created on SD card
78 | * ("/Android/data/[app_package_name]/cache") (if card is mounted and app has appropriate permission) or
79 | * on device's file system depending incoming parameters.
80 | *
81 | * @param context Application context
82 | * @param preferExternal Whether prefer external location for cache
83 | * @return Cache {@link File directory}.
84 | * NOTE: Can be null in some unpredictable cases (if SD card is unmounted and
85 | * {@link Context#getCacheDir() Context.getCacheDir()} returns null).
86 | */
87 | public static File getCacheDirectory(Context context, boolean preferExternal) {
88 | File appCacheDir = null;
89 | String externalStorageState;
90 | try {
91 | externalStorageState = Environment.getExternalStorageState();
92 | } catch (NullPointerException e) { // (sh)it happens (Issue #660)
93 | externalStorageState = "";
94 | } catch (IncompatibleClassChangeError e) { // (sh)it happens too (Issue #989)
95 | externalStorageState = "";
96 | }
97 | if (preferExternal && MEDIA_MOUNTED.equals(externalStorageState) && hasExternalStoragePermission(context)) {
98 | appCacheDir = getExternalCacheDir(context);
99 | }
100 | if (appCacheDir == null) {
101 | appCacheDir = context.getCacheDir();
102 | }
103 | if (appCacheDir == null) {
104 | String cacheDirPath = "/data/data/" + context.getPackageName() + "/cache/";
105 | appCacheDir = new File(cacheDirPath);
106 | }
107 | return appCacheDir;
108 | }
109 |
110 | /**
111 | * Returns individual application cache directory (for only image caching from ImageLoader). Cache directory will be
112 | * created on SD card ("/Android/data/[app_package_name]/cache/uil-images") if card is mounted and app has
113 | * appropriate permission. Else - Android defines cache directory on device's file system.
114 | *
115 | * @param context Application context
116 | * @param cacheDir Cache directory path (e.g.: "AppCacheDir", "AppDir/cache/images")
117 | * @return Cache {@link File directory}
118 | */
119 | public static File getIndividualCacheDirectory(Context context, String cacheDir) {
120 | File appCacheDir = getCacheDirectory(context);
121 | File individualCacheDir = new File(appCacheDir, cacheDir);
122 | if (!individualCacheDir.exists()) {
123 | if (!individualCacheDir.mkdir()) {
124 | individualCacheDir = appCacheDir;
125 | }
126 | }
127 | return individualCacheDir;
128 | }
129 |
130 | private static File getExternalCacheDir(Context context) {
131 | File dataDir = new File(new File(Environment.getExternalStorageDirectory(), "Android"), "data");
132 | File appCacheDir = new File(new File(dataDir, context.getPackageName()), "cache");
133 | if (!appCacheDir.exists()) {
134 | if (!appCacheDir.mkdirs()) {
135 | return null;
136 | }
137 | try {
138 | new File(appCacheDir, ".nomedia").createNewFile();
139 | } catch (IOException e) {
140 | }
141 | }
142 | return appCacheDir;
143 | }
144 |
145 | private static final long MB = 1024 * 1024;
146 |
147 | public String getSizeByUnit(double size) {
148 |
149 | if (size == 0) {
150 | return "0K";
151 | }
152 | if (size >= MB) {
153 | double sizeInM = size / MB;
154 | return String.format(Locale.getDefault(), "%.1f", sizeInM) + "M";
155 | }
156 | double sizeInK = size / 1024;
157 | return String.format(Locale.getDefault(), "%.1f", sizeInK) + "K";
158 | }
159 |
160 | private static boolean hasExternalStoragePermission(Context context) {
161 | int perm = context.checkCallingOrSelfPermission(EXTERNAL_STORAGE_PERMISSION);
162 | return perm == PackageManager.PERMISSION_GRANTED;
163 | }
164 |
165 | public static String fileSize(long size) {
166 | if (size <= 0) return "0";
167 | final String[] units = new String[]{"B", "kB", "MB", "GB", "TB"};
168 | int digitGroups = (int) (Math.log10(size) / Math.log10(1024));
169 | return new DecimalFormat("#,##0.#").format(size / Math.pow(1024, digitGroups)) + " " + units[digitGroups];
170 | }
171 |
172 |
173 | /**
174 | * To find out the extension of required object in given uri
175 | * Solution by http://stackoverflow.com/a/36514823/1171484
176 | */
177 | public static String getMimeType(Context context, Uri uri) {
178 | String extension;
179 | //Check uri format to avoid null
180 | if (ContentResolver.SCHEME_CONTENT.equals(uri.getScheme())) {
181 | //If scheme is a content
182 | extension = MimeTypeMap.getSingleton().getExtensionFromMimeType(context.getContentResolver().getType(uri));
183 | if (TextUtils.isEmpty(extension)) {
184 | extension = MimeTypeMap.getFileExtensionFromUrl(Uri.fromFile(new File(uri.getPath())).toString());
185 | }
186 | } else {
187 | //If scheme is a File
188 | //This will replace white spaces with %20 and also other special characters. This will avoid returning null values on file
189 | // name with spaces and special characters.
190 | extension = MimeTypeMap.getFileExtensionFromUrl(Uri.fromFile(new File(uri.getPath())).toString());
191 | if (TextUtils.isEmpty(extension)) {
192 | extension = MimeTypeMap.getSingleton().getExtensionFromMimeType(context.getContentResolver().getType(uri));
193 | }
194 | }
195 | return extension;
196 | }
197 |
198 | public static String getMimeTypeByFileName(String fileName) {
199 | return fileName.substring(fileName.lastIndexOf("."), fileName.length());
200 | }
201 | }
202 |
--------------------------------------------------------------------------------
/mediapicker/src/main/java/com/dmcbig/mediapicker/utils/ScreenUtils.java:
--------------------------------------------------------------------------------
1 | package com.dmcbig.mediapicker.utils;
2 |
3 | import android.app.Activity;
4 | import android.content.Context;
5 | import android.content.res.Configuration;
6 | import android.util.DisplayMetrics;
7 | import android.util.TypedValue;
8 | import android.view.Display;
9 | import android.view.Window;
10 | import android.view.WindowManager;
11 |
12 | import java.lang.reflect.Method;
13 |
14 |
15 | /**
16 | * 这是一个屏幕工具类,所有方法与屏幕有关
17 | * Created by Shinlone on 2016/8/30.
18 | */
19 | public class ScreenUtils {
20 |
21 | private ScreenUtils() {
22 | throw new UnsupportedOperationException("本屏幕工具类不能被实例化,直接调用静态方法就好");
23 | }
24 |
25 | /**
26 | * 横竖屏
27 | *
28 | * @param context
29 | * @return
30 | */
31 | public static boolean isScreenOriatationPortrait(Context context) {
32 | return context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT;
33 | }
34 |
35 | /**
36 | * 获取屏幕dpi
37 | *
38 | * @param context
39 | * @return
40 | */
41 | public static int getDpi(Context context) {
42 | int dpi = 0;
43 | WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
44 | Display display = windowManager.getDefaultDisplay();
45 | DisplayMetrics displayMetrics = new DisplayMetrics();
46 | @SuppressWarnings("rawtypes")
47 | Class c;
48 | try {
49 | c = Class.forName("android.view.Display");
50 | @SuppressWarnings("unchecked")
51 | Method method = c.getMethod("getRealMetrics", DisplayMetrics.class);
52 | method.invoke(display, displayMetrics);
53 | dpi = displayMetrics.heightPixels;
54 | } catch (Exception e) {
55 | e.printStackTrace();
56 | }
57 | return dpi;
58 | }
59 |
60 | /**
61 | * 获取虚拟按键的高度
62 | *
63 | * @param context
64 | * @return
65 | */
66 | public static int getBottomStatusHeight(Context context) {
67 | int totalHeight = getDpi(context);
68 | int contentHeight = getScreenHeight(context);
69 | return totalHeight - contentHeight;
70 | }
71 |
72 | /**
73 | * 标题栏高度
74 | *
75 | * @return
76 | */
77 | public static int getTitleHeight(Activity activity) {
78 | return activity.getWindow().findViewById(Window.ID_ANDROID_CONTENT).getTop();
79 | }
80 |
81 | /**
82 | * 获得状态栏的高度
83 | *
84 | * @param context
85 | * @return
86 | */
87 | public static int getStatusHeight(Context context) {
88 |
89 | int statusHeight = -1;
90 | try {
91 | Class> clazz = Class.forName("com.android.internal.R$dimen");
92 | Object object = clazz.newInstance();
93 | int height = Integer.parseInt(clazz.getField("status_bar_height")
94 | .get(object).toString());
95 | statusHeight = context.getResources().getDimensionPixelSize(height);
96 | } catch (Exception e) {
97 | e.printStackTrace();
98 | }
99 | return statusHeight;
100 | }
101 |
102 |
103 | /**
104 | * 获得屏幕高度
105 | *
106 | * @param context
107 | * @return
108 | */
109 | public static int getScreenHeight(Context context) {
110 | WindowManager wm = (WindowManager) context
111 | .getSystemService(Context.WINDOW_SERVICE);
112 | DisplayMetrics outMetrics = new DisplayMetrics();
113 | wm.getDefaultDisplay().getMetrics(outMetrics);
114 | return outMetrics.heightPixels;
115 | }
116 |
117 | /**
118 | * 获得屏幕宽度
119 | *
120 | * @param context
121 | * @return
122 | */
123 | public static int getScreenWidth(Context context) {
124 | WindowManager wm = (WindowManager) context
125 | .getSystemService(Context.WINDOW_SERVICE);
126 | DisplayMetrics outMetrics = new DisplayMetrics();
127 | wm.getDefaultDisplay().getMetrics(outMetrics);
128 | return outMetrics.widthPixels;
129 | }
130 |
131 | /**
132 | * dp转px
133 | *
134 | * @param context
135 | * @param dpVal
136 | * @return
137 | */
138 | public static int dp2px(Context context, float dpVal) {
139 | return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
140 | dpVal, context.getResources().getDisplayMetrics());
141 | }
142 |
143 | /**
144 | * sp转px
145 | *
146 | * @param context
147 | * @param spVal
148 | * @return
149 | */
150 | public static int sp2px(Context context, float spVal) {
151 | return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP,
152 | spVal, context.getResources().getDisplayMetrics());
153 | }
154 |
155 | /**
156 | * px转dp
157 | *
158 | * @param context
159 | * @param pxVal
160 | * @return
161 | */
162 | public static float px2dp(Context context, float pxVal) {
163 | final float scale = context.getResources().getDisplayMetrics().density;
164 | return (pxVal / scale);
165 | }
166 |
167 | /**
168 | * px转sp
169 | *
170 | * @param context
171 | * @param pxVal
172 | * @return
173 | */
174 | public static float px2sp(Context context, float pxVal) {
175 | return (pxVal / context.getResources().getDisplayMetrics().scaledDensity);
176 | }
177 |
178 | }
179 |
--------------------------------------------------------------------------------
/mediapicker/src/main/java/com/dmcbig/mediapicker/view/HackyViewPager.java:
--------------------------------------------------------------------------------
1 | package com.dmcbig.mediapicker.view;
2 |
3 | import android.content.Context;
4 | import androidx.viewpager.widget.ViewPager;
5 | import android.util.AttributeSet;
6 | import android.view.MotionEvent;
7 |
8 | /**
9 | * Hacky fix for Issue #4 and
10 | * http://code.google.com/p/android/issues/detail?id=18990
11 | *
12 | * ScaleGestureDetector seems to mess up the touch events, which means that
13 | * ViewGroups which make use of onInterceptTouchEvent throw a lot of
14 | * IllegalArgumentException: pointerIndex out of range.
15 | *
16 | * There's not much I can do in my code for now, but we can mask the result by
17 | * just catching the problem and ignoring it.
18 | *
19 | * @author Chris Banes
20 | */
21 | public class HackyViewPager extends ViewPager {
22 |
23 | public HackyViewPager(Context context) {
24 | super(context);
25 | }
26 |
27 | public HackyViewPager(Context context, AttributeSet attrs) {
28 | super(context, attrs);
29 | }
30 |
31 | @Override
32 | public boolean onInterceptTouchEvent(MotionEvent ev) {
33 | try {
34 | return super.onInterceptTouchEvent(ev);
35 | } catch (IllegalArgumentException e) {
36 | return false;
37 | }
38 | }
39 | }
--------------------------------------------------------------------------------
/mediapicker/src/main/java/com/dmcbig/mediapicker/view/PreviewFragment.java:
--------------------------------------------------------------------------------
1 | package com.dmcbig.mediapicker.view;
2 |
3 | import android.content.Context;
4 | import android.content.Intent;
5 | import android.net.Uri;
6 | import android.os.Build;
7 | import android.os.Bundle;
8 | import androidx.annotation.Nullable;
9 | import androidx.fragment.app.Fragment;
10 | import androidx.core.content.FileProvider;
11 | import android.util.Log;
12 | import android.view.LayoutInflater;
13 | import android.view.View;
14 | import android.view.ViewGroup;
15 | import android.widget.ImageView;
16 | import android.widget.Toast;
17 |
18 | import com.bumptech.glide.Glide;
19 | import com.dmcbig.mediapicker.PreviewActivity;
20 | import com.dmcbig.mediapicker.R;
21 | import com.dmcbig.mediapicker.entity.Media;
22 |
23 | import java.io.File;
24 | import java.util.List;
25 |
26 | import uk.co.senab.photoview.PhotoView;
27 | import uk.co.senab.photoview.PhotoViewAttacher;
28 |
29 | /**
30 | * Created by dmcBig on 2017/8/16.
31 | */
32 |
33 | public class PreviewFragment extends Fragment {
34 | private PhotoView mPhotoView;
35 | ImageView play_view;
36 | // private PhotoViewAttacher mAttacher;
37 |
38 | public static PreviewFragment newInstance(Media media, String label) {
39 | PreviewFragment f = new PreviewFragment();
40 | Bundle b = new Bundle();
41 | b.putParcelable("media", media);
42 | f.setArguments(b);
43 | return f;
44 | }
45 |
46 | @Override
47 | public void onCreate(@Nullable Bundle savedInstanceState) {
48 | setRetainInstance(true);
49 | super.onCreate(savedInstanceState);
50 | }
51 |
52 | @Override
53 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
54 | return inflater.inflate(R.layout.preview_fragment_item, container, false);
55 | }
56 |
57 | @Override
58 | public void onViewCreated(View view, Bundle savedInstanceState) {
59 | super.onViewCreated(view, savedInstanceState);
60 | Media media = getArguments().getParcelable("media");
61 | play_view = (ImageView) view.findViewById(R.id.play_view);
62 | mPhotoView = (PhotoView) view.findViewById(R.id.photoview);
63 | mPhotoView.setMaximumScale(5);
64 | mPhotoView.setOnPhotoTapListener(new PhotoViewAttacher.OnPhotoTapListener() {
65 | @Override
66 | public void onPhotoTap(View view, float x, float y) {
67 | PreviewActivity previewActivity= (PreviewActivity)getActivity();
68 | previewActivity.setBarStatus();
69 | }
70 | });
71 | setPlayView(media);
72 | Glide.with(getActivity())
73 | .load(media.path)
74 | .into(mPhotoView);
75 | }
76 |
77 | void setPlayView(final Media media) {
78 | if (media.mediaType == 3) {
79 | play_view.setVisibility(View.VISIBLE);
80 | play_view.setOnClickListener(new View.OnClickListener() {
81 | @Override
82 | public void onClick(View v) {
83 | Intent intent = new Intent(Intent.ACTION_VIEW);
84 | intent.setDataAndType(getUri(media.path), "video/*");
85 | intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
86 | if (isIntentAvailable(getContext(), intent)) {
87 | startActivity(intent);
88 | } else {
89 | Toast.makeText(getContext(),getString(R.string.cant_play_video), Toast.LENGTH_SHORT).show();
90 | }
91 | }
92 | });
93 | }
94 | }
95 |
96 | Uri getUri(String path){
97 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
98 | return FileProvider.getUriForFile(getActivity(), getActivity().getPackageName()+ ".dmc", new File(path));
99 | }else {
100 | return Uri.fromFile(new File(path));
101 | }
102 | }
103 |
104 | /**
105 | * 检查是否有可以处理的程序
106 | *
107 | * @param context
108 | * @param intent
109 | * @return
110 | */
111 | private boolean isIntentAvailable(Context context, Intent intent) {
112 | List resolves = context.getPackageManager().queryIntentActivities(intent, 0);
113 | return resolves.size() > 0;
114 | }
115 |
116 | @Override
117 | public void onDestroyView() {
118 | super.onDestroyView();
119 | }
120 | }
--------------------------------------------------------------------------------
/mediapicker/src/main/java/com/dmcbig/mediapicker/view/SquareFrameLayout.java:
--------------------------------------------------------------------------------
1 | package com.dmcbig.mediapicker.view;
2 |
3 | /**
4 | * Created by dmcBig on 2017/7/11.
5 | */
6 |
7 | import android.annotation.TargetApi;
8 | import android.content.Context;
9 | import android.os.Build;
10 | import android.util.AttributeSet;
11 | import android.widget.FrameLayout;
12 |
13 | public class SquareFrameLayout extends FrameLayout {
14 |
15 | public SquareFrameLayout(Context context) {
16 | super(context);
17 | }
18 |
19 | public SquareFrameLayout(Context context, AttributeSet attrs) {
20 | super(context, attrs);
21 | }
22 |
23 | public SquareFrameLayout(Context context, AttributeSet attrs, int defStyleAttr) {
24 | super(context, attrs, defStyleAttr);
25 | }
26 |
27 | @TargetApi(Build.VERSION_CODES.LOLLIPOP)
28 | public SquareFrameLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
29 | super(context, attrs, defStyleAttr, defStyleRes);
30 | }
31 |
32 | @Override
33 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
34 | super.onMeasure(widthMeasureSpec, heightMeasureSpec);
35 | setMeasuredDimension(getMeasuredWidth(), getMeasuredWidth());
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/mediapicker/src/main/res/color/default_text_color.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/mediapicker/src/main/res/drawable-xhdpi/default_check.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DmcSDK/MediaPickerPoject/cf768d7ffff5de6e86b58d41f8c3d0947f17160f/mediapicker/src/main/res/drawable-xhdpi/default_check.png
--------------------------------------------------------------------------------
/mediapicker/src/main/res/drawable-xhdpi/default_image.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DmcSDK/MediaPickerPoject/cf768d7ffff5de6e86b58d41f8c3d0947f17160f/mediapicker/src/main/res/drawable-xhdpi/default_image.png
--------------------------------------------------------------------------------
/mediapicker/src/main/res/drawable-xhdpi/text_indicator.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DmcSDK/MediaPickerPoject/cf768d7ffff5de6e86b58d41f8c3d0947f17160f/mediapicker/src/main/res/drawable-xhdpi/text_indicator.png
--------------------------------------------------------------------------------
/mediapicker/src/main/res/drawable-xhdpi/video.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DmcSDK/MediaPickerPoject/cf768d7ffff5de6e86b58d41f8c3d0947f17160f/mediapicker/src/main/res/drawable-xhdpi/video.png
--------------------------------------------------------------------------------
/mediapicker/src/main/res/drawable/action_btn.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 |
--------------------------------------------------------------------------------
/mediapicker/src/main/res/drawable/btn_selected.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DmcSDK/MediaPickerPoject/cf768d7ffff5de6e86b58d41f8c3d0947f17160f/mediapicker/src/main/res/drawable/btn_selected.png
--------------------------------------------------------------------------------
/mediapicker/src/main/res/drawable/btn_unselected.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DmcSDK/MediaPickerPoject/cf768d7ffff5de6e86b58d41f8c3d0947f17160f/mediapicker/src/main/res/drawable/btn_unselected.png
--------------------------------------------------------------------------------
/mediapicker/src/main/res/drawable/ic_back.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DmcSDK/MediaPickerPoject/cf768d7ffff5de6e86b58d41f8c3d0947f17160f/mediapicker/src/main/res/drawable/ic_back.png
--------------------------------------------------------------------------------
/mediapicker/src/main/res/layout/folders_view_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
19 |
20 |
29 |
30 |
37 |
38 |
48 |
49 |
59 |
60 |
61 |
62 |
72 |
73 |
--------------------------------------------------------------------------------
/mediapicker/src/main/res/layout/loading.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
13 |
--------------------------------------------------------------------------------
/mediapicker/src/main/res/layout/main.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
9 |
10 |
17 |
18 |
19 |
35 |
36 |
53 |
54 |
55 |
56 |
63 |
64 |
--------------------------------------------------------------------------------
/mediapicker/src/main/res/layout/media_view_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
10 |
16 |
24 |
31 |
40 |
51 |
52 |
58 |
59 |
71 |
72 |
--------------------------------------------------------------------------------
/mediapicker/src/main/res/layout/picker_actionbar.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
16 |
17 |
24 |
25 |
35 |
36 |
54 |
--------------------------------------------------------------------------------
/mediapicker/src/main/res/layout/preview_actionbar.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
16 |
17 |
24 |
25 |
35 |
36 |
54 |
--------------------------------------------------------------------------------
/mediapicker/src/main/res/layout/preview_bottombar.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
15 |
16 |
23 |
33 |
34 |
--------------------------------------------------------------------------------
/mediapicker/src/main/res/layout/preview_fragment_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
11 |
18 |
--------------------------------------------------------------------------------
/mediapicker/src/main/res/layout/preview_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
10 |
11 |
16 |
17 |
18 |
21 |
22 |
25 |
--------------------------------------------------------------------------------
/mediapicker/src/main/res/values-es/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | MediaPicker
3 | Imágenes y Videos
4 | Videos
5 | Imágenes
6 | Seleccione
7 | Seleccione Videos
8 | Selecciones Imágenes
9 | Videos
10 | Has alcanzado el número maximo de selecciones
11 | The maximum file size is only
12 | Por favor seleccione un archivo
13 | Hecho
14 |
15 | vista previa
16 | Seleccione
17 | video
18 | No se puede reproducir
19 | Necesita permiso de almacenamiento
20 |
21 |
--------------------------------------------------------------------------------
/mediapicker/src/main/res/values-pt-rBR/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Seletor de Conteúdo
3 | Todas Imagens e Vídeos
4 | Todos os Vídeos
5 | Todas as Imagens
6 | Selecionar
7 | Selecionar Vídeo
8 | Selecionar Imagem
9 | Todos os Vídeos
10 | Atingiu o limite máximo de escolhas
11 | O tamanho máximo do arquivo é somente
12 | por favor selecionar arquivo
13 | Pronto
14 |
15 | Prévia
16 | Selecionar
17 | vídeo
18 | Nenhum programa para tocar!
19 | Precisa abrir a permissão de leitura de armazenamento
20 |
21 |
--------------------------------------------------------------------------------
/mediapicker/src/main/res/values-pt-rPT/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Seletor de Conteúdo
3 | Todas Imagens e Vídeos
4 | Todos os Vídeos
5 | Todas as Imagens
6 | Selecionar
7 | Selecionar Vídeo
8 | Selecionar Imagem
9 | Todos os Vídeos
10 | Atingiu o limite máximo de escolhas
11 | O tamanho máximo do arquivo é somente
12 | por favor selecionar arquivo
13 | Pronto
14 |
15 | Prévia
16 | Selecionar
17 | vídeo
18 | Nenhum programa para tocar!
19 | Precisa abrir a permissão de leitura de armazenamento
20 |
21 |
--------------------------------------------------------------------------------
/mediapicker/src/main/res/values-zh/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | 媒体选择器
3 | 所有图片和视频
4 | 所有视频
5 | 所有图片
6 | 选择图片和视频
7 | 选择视频
8 | 选择图片
9 | 所有视频
10 | 已达到选择数量上限
11 | 请压缩和剪切后上传,文件最大只支持
12 | 请选择文件
13 | 完成
14 | 个
15 | 预览
16 | 选择
17 | 视频
18 | 没有可以播放的程序
19 | 需要打开读取存储权限
20 |
21 |
22 |
--------------------------------------------------------------------------------
/mediapicker/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | MediaPicker
3 | All Image and Video
4 | All Video
5 | All Image
6 | Select Image and Video
7 | Select Video
8 | Select Image
9 | All Video
10 | Has reached the maximum number of choices
11 | The maximum file size is only
12 | please select file
13 | Done
14 |
15 | Preview
16 | Select
17 | video
18 | No program to play!
19 | Need to open read storage permissions
20 |
21 |
--------------------------------------------------------------------------------
/mediapicker/src/main/res/xml/file_dmc_paths.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/mediapicker/src/test/java/com/dmcbig/mediapicker/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.dmcbig.mediapicker;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.assertEquals;
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 | }
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':mediapicker'
2 |
--------------------------------------------------------------------------------