├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── colors.xml
│ │ │ │ ├── dimens.xml
│ │ │ │ └── styles.xml
│ │ │ ├── mipmap-hdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── values-w820dp
│ │ │ │ └── dimens.xml
│ │ │ └── layout
│ │ │ │ └── activity_main.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── com
│ │ │ └── zetenterprises
│ │ │ └── sample
│ │ │ └── MainActivity.java
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── zetenterprises
│ │ │ └── sample
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── zetenterprises
│ │ └── sample
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
└── build.gradle
├── _config.yml
├── multimediapicker
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── xml
│ │ │ │ └── paths.xml
│ │ │ ├── drawable-hdpi
│ │ │ │ ├── ic_arrow_back.png
│ │ │ │ ├── ic_done_white.png
│ │ │ │ ├── ic_camera_white.png
│ │ │ │ └── ic_videocam_white_24dp.png
│ │ │ ├── drawable-mdpi
│ │ │ │ ├── ic_arrow_back.png
│ │ │ │ ├── ic_done_white.png
│ │ │ │ ├── ic_camera_white.png
│ │ │ │ └── ic_videocam_white_24dp.png
│ │ │ ├── drawable-xhdpi
│ │ │ │ ├── ic_arrow_back.png
│ │ │ │ ├── ic_done_white.png
│ │ │ │ ├── ic_camera_white.png
│ │ │ │ └── ic_videocam_white_24dp.png
│ │ │ ├── drawable-xxhdpi
│ │ │ │ ├── ic_arrow_back.png
│ │ │ │ ├── ic_camera_white.png
│ │ │ │ ├── ic_done_white.png
│ │ │ │ └── ic_videocam_white_24dp.png
│ │ │ ├── drawable-xxxhdpi
│ │ │ │ ├── ic_arrow_back.png
│ │ │ │ ├── ic_done_white.png
│ │ │ │ ├── ic_camera_white.png
│ │ │ │ └── ic_videocam_white_24dp.png
│ │ │ ├── drawable
│ │ │ │ ├── folder_placeholder.xml
│ │ │ │ └── image_placeholder.xml
│ │ │ ├── values-w820dp
│ │ │ │ └── dimens.xml
│ │ │ ├── values
│ │ │ │ ├── colors.xml
│ │ │ │ ├── dimens.xml
│ │ │ │ ├── attrs.xml
│ │ │ │ ├── styles.xml
│ │ │ │ └── strings.xml
│ │ │ └── layout
│ │ │ │ ├── image_item.xml
│ │ │ │ ├── activity_gallery_picker.xml
│ │ │ │ ├── folder_item.xml
│ │ │ │ └── fragment_container.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── zet
│ │ │ │ └── enterprises
│ │ │ │ └── multimediapicker
│ │ │ │ ├── listeners
│ │ │ │ ├── OnImageClickListener.java
│ │ │ │ └── OnFolderClickListener.java
│ │ │ │ ├── utils
│ │ │ │ ├── Constants.java
│ │ │ │ └── ImageUtils.java
│ │ │ │ ├── model
│ │ │ │ ├── Folder.java
│ │ │ │ └── Image.java
│ │ │ │ ├── custom
│ │ │ │ ├── CustomFrame.java
│ │ │ │ ├── GridSpacingItemDecoration.java
│ │ │ │ └── ProgressWheel.java
│ │ │ │ ├── adapter
│ │ │ │ ├── FolderPickerAdapter.java
│ │ │ │ └── ImagePickerAdapter.java
│ │ │ │ ├── MultimediaPicker.java
│ │ │ │ ├── GalleryPickerActivity.java
│ │ │ │ └── ContainerFragment.java
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── zet
│ │ │ └── enterprises
│ │ │ └── multimediapicker
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── zet
│ │ └── enterprises
│ │ └── multimediapicker
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── .idea
├── copyright
│ └── profiles_settings.xml
├── modules.xml
├── runConfigurations.xml
├── gradle.xml
├── compiler.xml
└── misc.xml
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitignore
├── .gitattributes
├── gradle.properties
├── README.md
├── gradlew.bat
└── gradlew
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/_config.yml:
--------------------------------------------------------------------------------
1 | theme: jekyll-theme-cayman
--------------------------------------------------------------------------------
/multimediapicker/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':multimediapicker'
2 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | sample
3 |
4 |
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ZetDeveloper/WhastappMultimediaPicker/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ZetDeveloper/WhastappMultimediaPicker/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ZetDeveloper/WhastappMultimediaPicker/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ZetDeveloper/WhastappMultimediaPicker/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/multimediapicker/src/main/res/xml/paths.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ZetDeveloper/WhastappMultimediaPicker/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ZetDeveloper/WhastappMultimediaPicker/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 | .externalNativeBuild
10 |
--------------------------------------------------------------------------------
/multimediapicker/src/main/res/drawable-hdpi/ic_arrow_back.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ZetDeveloper/WhastappMultimediaPicker/HEAD/multimediapicker/src/main/res/drawable-hdpi/ic_arrow_back.png
--------------------------------------------------------------------------------
/multimediapicker/src/main/res/drawable-hdpi/ic_done_white.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ZetDeveloper/WhastappMultimediaPicker/HEAD/multimediapicker/src/main/res/drawable-hdpi/ic_done_white.png
--------------------------------------------------------------------------------
/multimediapicker/src/main/res/drawable-mdpi/ic_arrow_back.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ZetDeveloper/WhastappMultimediaPicker/HEAD/multimediapicker/src/main/res/drawable-mdpi/ic_arrow_back.png
--------------------------------------------------------------------------------
/multimediapicker/src/main/res/drawable-mdpi/ic_done_white.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ZetDeveloper/WhastappMultimediaPicker/HEAD/multimediapicker/src/main/res/drawable-mdpi/ic_done_white.png
--------------------------------------------------------------------------------
/multimediapicker/src/main/res/drawable-xhdpi/ic_arrow_back.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ZetDeveloper/WhastappMultimediaPicker/HEAD/multimediapicker/src/main/res/drawable-xhdpi/ic_arrow_back.png
--------------------------------------------------------------------------------
/multimediapicker/src/main/res/drawable-xhdpi/ic_done_white.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ZetDeveloper/WhastappMultimediaPicker/HEAD/multimediapicker/src/main/res/drawable-xhdpi/ic_done_white.png
--------------------------------------------------------------------------------
/multimediapicker/src/main/res/drawable-hdpi/ic_camera_white.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ZetDeveloper/WhastappMultimediaPicker/HEAD/multimediapicker/src/main/res/drawable-hdpi/ic_camera_white.png
--------------------------------------------------------------------------------
/multimediapicker/src/main/res/drawable-mdpi/ic_camera_white.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ZetDeveloper/WhastappMultimediaPicker/HEAD/multimediapicker/src/main/res/drawable-mdpi/ic_camera_white.png
--------------------------------------------------------------------------------
/multimediapicker/src/main/res/drawable-xhdpi/ic_camera_white.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ZetDeveloper/WhastappMultimediaPicker/HEAD/multimediapicker/src/main/res/drawable-xhdpi/ic_camera_white.png
--------------------------------------------------------------------------------
/multimediapicker/src/main/res/drawable-xxhdpi/ic_arrow_back.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ZetDeveloper/WhastappMultimediaPicker/HEAD/multimediapicker/src/main/res/drawable-xxhdpi/ic_arrow_back.png
--------------------------------------------------------------------------------
/multimediapicker/src/main/res/drawable-xxhdpi/ic_camera_white.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ZetDeveloper/WhastappMultimediaPicker/HEAD/multimediapicker/src/main/res/drawable-xxhdpi/ic_camera_white.png
--------------------------------------------------------------------------------
/multimediapicker/src/main/res/drawable-xxhdpi/ic_done_white.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ZetDeveloper/WhastappMultimediaPicker/HEAD/multimediapicker/src/main/res/drawable-xxhdpi/ic_done_white.png
--------------------------------------------------------------------------------
/multimediapicker/src/main/res/drawable-xxxhdpi/ic_arrow_back.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ZetDeveloper/WhastappMultimediaPicker/HEAD/multimediapicker/src/main/res/drawable-xxxhdpi/ic_arrow_back.png
--------------------------------------------------------------------------------
/multimediapicker/src/main/res/drawable-xxxhdpi/ic_done_white.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ZetDeveloper/WhastappMultimediaPicker/HEAD/multimediapicker/src/main/res/drawable-xxxhdpi/ic_done_white.png
--------------------------------------------------------------------------------
/multimediapicker/src/main/res/drawable-xxxhdpi/ic_camera_white.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ZetDeveloper/WhastappMultimediaPicker/HEAD/multimediapicker/src/main/res/drawable-xxxhdpi/ic_camera_white.png
--------------------------------------------------------------------------------
/multimediapicker/src/main/res/drawable-hdpi/ic_videocam_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ZetDeveloper/WhastappMultimediaPicker/HEAD/multimediapicker/src/main/res/drawable-hdpi/ic_videocam_white_24dp.png
--------------------------------------------------------------------------------
/multimediapicker/src/main/res/drawable-mdpi/ic_videocam_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ZetDeveloper/WhastappMultimediaPicker/HEAD/multimediapicker/src/main/res/drawable-mdpi/ic_videocam_white_24dp.png
--------------------------------------------------------------------------------
/multimediapicker/src/main/res/drawable-xhdpi/ic_videocam_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ZetDeveloper/WhastappMultimediaPicker/HEAD/multimediapicker/src/main/res/drawable-xhdpi/ic_videocam_white_24dp.png
--------------------------------------------------------------------------------
/multimediapicker/src/main/res/drawable-xxhdpi/ic_videocam_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ZetDeveloper/WhastappMultimediaPicker/HEAD/multimediapicker/src/main/res/drawable-xxhdpi/ic_videocam_white_24dp.png
--------------------------------------------------------------------------------
/multimediapicker/src/main/res/drawable-xxxhdpi/ic_videocam_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ZetDeveloper/WhastappMultimediaPicker/HEAD/multimediapicker/src/main/res/drawable-xxxhdpi/ic_videocam_white_24dp.png
--------------------------------------------------------------------------------
/multimediapicker/src/main/res/drawable/folder_placeholder.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
--------------------------------------------------------------------------------
/multimediapicker/src/main/res/drawable/image_placeholder.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Dec 28 10:00:20 PST 2015
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
7 |
--------------------------------------------------------------------------------
/multimediapicker/src/main/java/com/zet/enterprises/multimediapicker/listeners/OnImageClickListener.java:
--------------------------------------------------------------------------------
1 | package com.zet.enterprises.multimediapicker.listeners;
2 |
3 | import android.view.View;
4 |
5 | /**
6 | * Created by admin on 03/02/2017.
7 | */
8 |
9 | public interface OnImageClickListener {
10 | void onClick(View view, int position);
11 | }
12 |
13 |
--------------------------------------------------------------------------------
/multimediapicker/src/main/java/com/zet/enterprises/multimediapicker/listeners/OnFolderClickListener.java:
--------------------------------------------------------------------------------
1 | package com.zet.enterprises.multimediapicker.listeners;
2 |
3 | import com.zet.enterprises.multimediapicker.model.Folder;
4 |
5 | /**
6 | * Created by admin on 03/02/2017.
7 | */
8 |
9 | public interface OnFolderClickListener {
10 |
11 | void onFolderClick(Folder bucket);
12 | }
13 |
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
4 | # Custom for Visual Studio
5 | *.cs diff=csharp
6 |
7 | # Standard to msysgit
8 | *.doc diff=astextplain
9 | *.DOC diff=astextplain
10 | *.docx diff=astextplain
11 | *.DOCX diff=astextplain
12 | *.dot diff=astextplain
13 | *.DOT diff=astextplain
14 | *.pdf diff=astextplain
15 | *.PDF diff=astextplain
16 | *.rtf diff=astextplain
17 | *.RTF diff=astextplain
18 |
--------------------------------------------------------------------------------
/multimediapicker/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 | 15sp
7 | 20sp
8 |
9 |
--------------------------------------------------------------------------------
/app/src/test/java/com/zetenterprises/sample/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.zetenterprises.sample;
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 | }
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/multimediapicker/src/test/java/com/zet/enterprises/multimediapicker/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.zet.enterprises.multimediapicker;
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 | }
--------------------------------------------------------------------------------
/multimediapicker/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 | #FFFFFF
7 |
8 | #FFFFFF
9 | #9E9E9E
10 | #000000
11 | #80000000
12 | #009688
13 |
14 |
15 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
--------------------------------------------------------------------------------
/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 C:\Users\admin\AppData\Local\Android\Sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/multimediapicker/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 C:\Users\admin\AppData\Local\Android\Sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/multimediapicker/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 | 1dp
6 |
7 | 5dp
8 | 10dp
9 | 15dp
10 |
11 | 5dp
12 | 10dp
13 | 15dp
14 |
15 | 12sp
16 | 16sp
17 | 40dp
18 |
19 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/multimediapicker/src/main/res/layout/image_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
12 |
13 |
18 |
--------------------------------------------------------------------------------
/multimediapicker/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/multimediapicker/src/main/java/com/zet/enterprises/multimediapicker/utils/Constants.java:
--------------------------------------------------------------------------------
1 | package com.zet.enterprises.multimediapicker.utils;
2 |
3 | /**
4 | * Created by admin on 03/02/2017.
5 | */
6 |
7 | public class Constants {
8 |
9 | public static final int REQUEST_CODE_CAPTURE = 2000;
10 |
11 | public static final int FETCH_STARTED = 2001;
12 | public static final int FETCH_COMPLETED = 2002;
13 | public static final int ERROR = 2003;
14 |
15 | public static final int MAX_LIMIT = 999;
16 |
17 | public static final int PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE = 23;
18 | public static final int PERMISSION_REQUEST_CAMERA = 24;
19 |
20 | public static final String PREF_WRITE_EXTERNAL_STORAGE_REQUESTED = "writeExternalRequested";
21 | public static final String PREF_CAMERA_REQUESTED = "cameraRequested";
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/multimediapicker/src/main/java/com/zet/enterprises/multimediapicker/model/Folder.java:
--------------------------------------------------------------------------------
1 | package com.zet.enterprises.multimediapicker.model;
2 |
3 | import java.util.ArrayList;
4 |
5 | /**
6 | * Created by admin on 03/02/2017.
7 | */
8 |
9 | public class Folder {
10 |
11 | private String folderName;
12 | private ArrayList images;
13 |
14 | public Folder(String bucket) {
15 | folderName = bucket;
16 | images = new ArrayList<>();
17 | }
18 |
19 | public String getFolderName() {
20 | return folderName;
21 | }
22 |
23 | public void setFolderName(String folderName) {
24 | this.folderName = folderName;
25 | }
26 |
27 | public ArrayList getImages() {
28 | return images;
29 | }
30 |
31 | public void setImages(ArrayList images) {
32 | this.images = images;
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/multimediapicker/src/main/java/com/zet/enterprises/multimediapicker/custom/CustomFrame.java:
--------------------------------------------------------------------------------
1 | package com.zet.enterprises.multimediapicker.custom;
2 |
3 | import android.content.Context;
4 | import android.util.AttributeSet;
5 | import android.widget.FrameLayout;
6 |
7 | /**
8 | * Created by admin on 03/02/2017.
9 | */
10 |
11 | public class CustomFrame extends FrameLayout {
12 | public CustomFrame(Context context) {
13 | super(context);
14 | }
15 |
16 | public CustomFrame(Context context, AttributeSet attrs) {
17 | super(context, attrs);
18 | }
19 |
20 | public CustomFrame(Context context, AttributeSet attrs, int defStyleAttr) {
21 | super(context, attrs, defStyleAttr);
22 | }
23 |
24 | @Override
25 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
26 | super.onMeasure(widthMeasureSpec, widthMeasureSpec);
27 | }
28 | }
29 |
30 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/zetenterprises/sample/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.zetenterprises.sample;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.zetenterprises.sample", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/multimediapicker/src/androidTest/java/com/zet/enterprises/multimediapicker/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.zet.enterprises.multimediapicker;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.zet.enterprises.multimediapicker.test", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 25
5 | buildToolsVersion "25.0.0"
6 | defaultConfig {
7 | applicationId "com.zetenterprises.sample"
8 | minSdkVersion 14
9 | targetSdkVersion 25
10 | versionCode 1
11 | versionName "1.0"
12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(dir: 'libs', include: ['*.jar'])
24 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
25 | exclude group: 'com.android.support', module: 'support-annotations'
26 | })
27 | compile 'com.android.support:appcompat-v7:25.1.0'
28 | compile project(':multimediapicker')
29 | testCompile 'junit:junit:4.12'
30 | }
31 |
--------------------------------------------------------------------------------
/multimediapicker/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 25
5 | buildToolsVersion "25.0.0"
6 |
7 | defaultConfig {
8 | minSdkVersion 14
9 | targetSdkVersion 25
10 | versionCode 1
11 | versionName "1.0"
12 |
13 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
14 |
15 | }
16 | buildTypes {
17 | release {
18 | minifyEnabled false
19 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
20 | }
21 | }
22 | }
23 |
24 | dependencies {
25 | compile fileTree(dir: 'libs', include: ['*.jar'])
26 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
27 | exclude group: 'com.android.support', module: 'support-annotations'
28 | })
29 | compile 'com.android.support:appcompat-v7:25.0.1'
30 | compile 'com.android.support:recyclerview-v7:25.0.1'
31 | compile 'com.android.support:design:25.0.1'
32 | compile 'com.github.bumptech.glide:glide:3.7.0'
33 | testCompile 'junit:junit:4.12'
34 | }
35 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
13 |
14 |
19 |
20 |
28 |
29 |
--------------------------------------------------------------------------------
/multimediapicker/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
14 |
19 |
22 |
23 |
24 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/multimediapicker/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
11 |
12 |
18 |
19 |
22 |
23 |
27 |
28 |
--------------------------------------------------------------------------------
/multimediapicker/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | MultimediaPicker
3 |
4 |
5 | No se encontraron imagenes
6 | Por favor, permita seleccionar imagenes
7 | Por favor, permita tomar fotos
8 | Limite de selección
9 | Por favor, permita acceder a sus imagenes
10 |
11 | OK
12 | Ok
13 | Cámara
14 | Camera
15 |
16 | Folder
17 | Toque para elegir
18 | Permiso denegado
19 |
20 | %d seleccionado(s)
21 | %1$d/%2$d
22 |
23 | Error al guardar imagen
24 | La cámara no funciona
25 | Error, intente de nuevo mas tarde
26 |
27 |
--------------------------------------------------------------------------------
/multimediapicker/src/main/java/com/zet/enterprises/multimediapicker/utils/ImageUtils.java:
--------------------------------------------------------------------------------
1 | package com.zet.enterprises.multimediapicker.utils;
2 |
3 | import android.os.Environment;
4 | import android.util.Log;
5 |
6 | import java.io.File;
7 | import java.io.IOException;
8 | import java.text.SimpleDateFormat;
9 | import java.util.Date;
10 |
11 | /**
12 | * Created by admin on 03/02/2017.
13 | */
14 |
15 | public class ImageUtils {
16 |
17 | private static final String TAG = "ImageUtils";
18 |
19 | public static File createImageFile(String directory) {
20 |
21 | // External sdcard location
22 | File mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), directory);
23 |
24 | // Create the storage directory if it does not exist
25 | if (!mediaStorageDir.exists()) {
26 | if (!mediaStorageDir.mkdirs()) {
27 | Log.d(TAG, "Oops! Failed create " + directory + " directory");
28 | return null;
29 | }
30 | }
31 |
32 | // Create a media file name
33 | String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
34 | String imageFileName = "IMG_" + timeStamp;
35 |
36 | File imageFile = null;
37 | try {
38 | imageFile = File.createTempFile(imageFileName, ".jpg", mediaStorageDir);
39 | } catch (IOException e) {
40 | Log.d(TAG, "Oops! Failed create " + imageFileName + " file");
41 | }
42 | return imageFile;
43 | }
44 |
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 | #Multimedia Picker like wahtsapp
3 |
4 | A simple library to select images and video from the gallery and camera.
5 |
6 | 
7 |
8 | ```java
9 | MultimediaPicker.create(this)
10 | .folderMode(true) // folder mode (false by default)
11 | .folderTitle("Folder") // folder selection title
12 | .imageTitle("Tap to select") // image selection title
13 | .setOnlyImages(true) //show only images tab
14 | .setOnlyVideos(true) //show only videos tab
15 | .single() // single mode
16 | .multi() // multi mode (default mode)
17 | .limit(10) // max images can be selected (999 by default)
18 | .showCamera(true) // show camera or not (true by default)
19 | .imageDirectory("Camera") // directory name for captured image ("Camera" folder by default)
20 | .origin(images) // original selected images, used in multi mode
21 | .start(REQUEST_CODE_PICKER); // start image picker activity with request code
22 | ```
23 |
24 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
25 |
26 | http://www.apache.org/licenses/LICENSE-2.0
27 |
28 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
29 |
--------------------------------------------------------------------------------
/multimediapicker/src/main/res/layout/activity_gallery_picker.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
18 |
19 |
29 |
30 |
31 |
36 |
37 |
--------------------------------------------------------------------------------
/multimediapicker/src/main/res/layout/folder_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
14 |
15 |
22 |
23 |
32 |
33 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/multimediapicker/src/main/java/com/zet/enterprises/multimediapicker/custom/GridSpacingItemDecoration.java:
--------------------------------------------------------------------------------
1 | package com.zet.enterprises.multimediapicker.custom;
2 |
3 | import android.graphics.Rect;
4 | import android.support.v7.widget.RecyclerView;
5 | import android.view.View;
6 |
7 | /**
8 | * Created by admin on 03/02/2017.
9 | */
10 |
11 | public class GridSpacingItemDecoration extends RecyclerView.ItemDecoration {
12 |
13 | private int spanCount;
14 | private int spacing;
15 | private boolean includeEdge;
16 |
17 | public GridSpacingItemDecoration(int spanCount, int spacing, boolean includeEdge) {
18 | this.spanCount = spanCount;
19 | this.spacing = spacing;
20 | this.includeEdge = includeEdge;
21 | }
22 |
23 | @Override
24 | public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
25 | int position = parent.getChildAdapterPosition(view);
26 | int column = position % spanCount;
27 |
28 | if (includeEdge) {
29 | outRect.left = spacing - column * spacing / spanCount; // spacing - column * ((1f / spanCount) * spacing)
30 | outRect.right = (column + 1) * spacing / spanCount; // (column + 1) * ((1f / spanCount) * spacing)
31 |
32 | if (position < spanCount) {
33 | outRect.top = spacing;
34 | }
35 | outRect.bottom = spacing;
36 | } else {
37 | outRect.left = column * spacing / spanCount; // column * ((1f / spanCount) * spacing)
38 | outRect.right = spacing - (column + 1) * spacing / spanCount; // spacing - (column + 1) * ((1f / spanCount) * spacing)
39 | if (position >= spanCount) {
40 | outRect.top = spacing;
41 | }
42 | }
43 | }
44 | }
45 |
46 |
--------------------------------------------------------------------------------
/multimediapicker/src/main/res/layout/fragment_container.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
13 |
22 |
23 |
31 |
32 |
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/multimediapicker/src/main/java/com/zet/enterprises/multimediapicker/model/Image.java:
--------------------------------------------------------------------------------
1 | package com.zet.enterprises.multimediapicker.model;
2 |
3 | import android.os.Parcel;
4 | import android.os.Parcelable;
5 |
6 | /**
7 | * Created by admin on 03/02/2017.
8 | */
9 |
10 | public class Image implements Parcelable {
11 |
12 | private long id;
13 | private String name;
14 | private String path;
15 | private boolean isSelected;
16 |
17 | public Image(long id, String name, String path, boolean isSelected) {
18 | this.id = id;
19 | this.name = name;
20 | this.path = path;
21 | this.isSelected = isSelected;
22 | }
23 |
24 | public long getId() {
25 | return id;
26 | }
27 |
28 | public void setId(long id) {
29 | this.id = id;
30 | }
31 |
32 | public String getName() {
33 | return name;
34 | }
35 |
36 | public void setName(String name) {
37 | this.name = name;
38 | }
39 |
40 | public String getPath() {
41 | return path;
42 | }
43 |
44 | public void setPath(String path) {
45 | this.path = path;
46 | }
47 |
48 | public boolean isSelected() {
49 | return isSelected;
50 | }
51 |
52 | public void setSelected(boolean selected) {
53 | isSelected = selected;
54 | }
55 |
56 |
57 | @Override
58 | public int describeContents() {
59 | return 0;
60 | }
61 |
62 | @Override
63 | public void writeToParcel(Parcel dest, int flags) {
64 | dest.writeLong(this.id);
65 | dest.writeString(this.name);
66 | dest.writeString(this.path);
67 | dest.writeByte(this.isSelected ? (byte) 1 : (byte) 0);
68 | }
69 |
70 | protected Image(Parcel in) {
71 | this.id = in.readLong();
72 | this.name = in.readString();
73 | this.path = in.readString();
74 | this.isSelected = in.readByte() != 0;
75 | }
76 |
77 | public static final Creator CREATOR = new Creator() {
78 | @Override
79 | public Image createFromParcel(Parcel source) {
80 | return new Image(source);
81 | }
82 |
83 | @Override
84 | public Image[] newArray(int size) {
85 | return new Image[size];
86 | }
87 | };
88 | }
89 |
90 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/multimediapicker/src/main/java/com/zet/enterprises/multimediapicker/adapter/FolderPickerAdapter.java:
--------------------------------------------------------------------------------
1 | package com.zet.enterprises.multimediapicker.adapter;
2 |
3 | import android.content.Context;
4 | import android.support.v7.widget.RecyclerView;
5 | import android.view.LayoutInflater;
6 | import android.view.View;
7 | import android.view.ViewGroup;
8 | import android.widget.ImageView;
9 | import android.widget.TextView;
10 |
11 | import com.bumptech.glide.Glide;
12 | import com.zet.enterprises.multimediapicker.R;
13 | import com.zet.enterprises.multimediapicker.listeners.OnFolderClickListener;
14 | import com.zet.enterprises.multimediapicker.model.Folder;
15 |
16 | import java.util.List;
17 |
18 | /**
19 | * Created by admin on 03/02/2017.
20 | */
21 |
22 | public class FolderPickerAdapter extends RecyclerView.Adapter {
23 |
24 | private Context context;
25 | private LayoutInflater inflater;
26 | private final OnFolderClickListener folderClickListener;
27 |
28 | private List folders;
29 |
30 | public FolderPickerAdapter(Context context, OnFolderClickListener folderClickListener) {
31 | this.context = context;
32 | this.folderClickListener = folderClickListener;
33 | inflater = LayoutInflater.from(this.context);
34 | }
35 |
36 | @Override
37 | public FolderViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
38 | View itemView = inflater.inflate(R.layout.folder_item, parent, false);
39 | return new FolderViewHolder(itemView);
40 | }
41 |
42 | @Override
43 | public void onBindViewHolder(final FolderViewHolder holder, int position) {
44 |
45 | final Folder folder = folders.get(position);
46 |
47 |
48 | Glide.with(context)
49 | .load(folder.getImages().get(0).getPath())
50 | .placeholder(R.drawable.folder_placeholder)
51 | .error(R.drawable.folder_placeholder)
52 | //.animate( animationObject )
53 | .crossFade()
54 | .into(holder.image);
55 |
56 | holder.name.setText(folders.get(position).getFolderName());
57 | holder.number.setText(String.valueOf(folders.get(position).getImages().size()));
58 |
59 | holder.itemView.setOnClickListener(new View.OnClickListener() {
60 | @Override
61 | public void onClick(View v) {
62 | if (folderClickListener != null)
63 | folderClickListener.onFolderClick(folder);
64 | }
65 | });
66 | }
67 |
68 | public void setData(List folders) {
69 | this.folders = folders;
70 |
71 | notifyDataSetChanged();
72 | }
73 |
74 | @Override
75 | public int getItemCount() {
76 | return folders.size();
77 | }
78 |
79 | public static class FolderViewHolder extends RecyclerView.ViewHolder {
80 |
81 | private ImageView image;
82 | private TextView name;
83 | private TextView number;
84 |
85 | public FolderViewHolder(View itemView) {
86 | super(itemView);
87 |
88 | image = (ImageView) itemView.findViewById(R.id.image);
89 | name = (TextView) itemView.findViewById(R.id.tv_name);
90 | number = (TextView) itemView.findViewById(R.id.tv_number);
91 | }
92 | }
93 | }
94 |
95 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zetenterprises/sample/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.zetenterprises.sample;
2 |
3 | import android.content.Intent;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.os.Bundle;
6 | import android.view.View;
7 | import android.widget.Button;
8 | import android.widget.TextView;
9 |
10 | import com.zet.enterprises.multimediapicker.GalleryPickerActivity;
11 | import com.zet.enterprises.multimediapicker.MultimediaPicker;
12 | import com.zet.enterprises.multimediapicker.model.Image;
13 |
14 | import java.util.ArrayList;
15 |
16 | public class MainActivity extends AppCompatActivity {
17 |
18 | private TextView textView;
19 | private Button buttonPickImage;
20 |
21 | private ArrayList images = new ArrayList<>();
22 |
23 | private int REQUEST_CODE_PICKER = 2000;
24 |
25 | @Override
26 | protected void onCreate(Bundle savedInstanceState) {
27 | super.onCreate(savedInstanceState);
28 | setContentView(R.layout.activity_main);
29 |
30 | textView = (TextView) findViewById(R.id.text_view);
31 | buttonPickImage = (Button) findViewById(R.id.button_pick_image);
32 | buttonPickImage.setOnClickListener(new View.OnClickListener() {
33 | @Override
34 | public void onClick(View view) {
35 | start();
36 | }
37 | });
38 |
39 |
40 | }
41 |
42 |
43 | // Recomended builder
44 | public void start() {
45 | MultimediaPicker.create(this)
46 | .folderMode(true) // set folder mode (false by default)
47 | .folderTitle("Folder") // folder selection title
48 | .imageTitle("Tap to select") // image selection title
49 | .single() // single mode
50 | .multi() // multi mode (default mode)
51 | .limit(10) // max images can be selected (999 by default)
52 | .showCamera(true) // show camera or not (true by default)
53 | .imageDirectory("Camera") // captured image directory name ("Camera" folder by default)
54 | .origin(images) // original selected images, used in multi mode
55 | .start(REQUEST_CODE_PICKER); // start image picker activity with request code
56 | }
57 |
58 | // Traditional intent
59 | public void startWithIntent() {
60 | Intent intent = new Intent(this, GalleryPickerActivity.class);
61 |
62 | intent.putExtra(GalleryPickerActivity.INTENT_EXTRA_FOLDER_MODE, true);
63 | intent.putExtra(GalleryPickerActivity.INTENT_EXTRA_MODE, GalleryPickerActivity.MODE_MULTIPLE);
64 | intent.putExtra(GalleryPickerActivity.INTENT_EXTRA_LIMIT, 10);
65 | intent.putExtra(GalleryPickerActivity.INTENT_EXTRA_SHOW_CAMERA, true);
66 | intent.putExtra(GalleryPickerActivity.INTENT_EXTRA_SELECTED_IMAGES, images);
67 | intent.putExtra(GalleryPickerActivity.INTENT_EXTRA_FOLDER_TITLE, "Album");
68 | intent.putExtra(GalleryPickerActivity.INTENT_EXTRA_IMAGE_TITLE, "Tap to select images");
69 | intent.putExtra(GalleryPickerActivity.INTENT_EXTRA_IMAGE_DIRECTORY, "Camera");
70 | startActivityForResult(intent, REQUEST_CODE_PICKER);
71 | }
72 |
73 | @Override
74 | protected void onActivityResult(int requestCode, int resultCode, Intent data) {
75 | if (requestCode == REQUEST_CODE_PICKER && resultCode == RESULT_OK && data != null) {
76 | images = data.getParcelableArrayListExtra(GalleryPickerActivity.INTENT_EXTRA_SELECTED_IMAGES);
77 | StringBuilder sb = new StringBuilder();
78 | for (int i = 0, l = images.size(); i < l; i++) {
79 | sb.append(images.get(i).getPath() + "\n");
80 | }
81 | textView.setText(sb.toString());
82 | }
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/multimediapicker/src/main/java/com/zet/enterprises/multimediapicker/MultimediaPicker.java:
--------------------------------------------------------------------------------
1 | package com.zet.enterprises.multimediapicker;
2 |
3 | import android.app.Activity;
4 | import android.content.Intent;
5 | import android.support.v4.app.Fragment;
6 |
7 | import com.zet.enterprises.multimediapicker.model.Image;
8 | import com.zet.enterprises.multimediapicker.utils.Constants;
9 |
10 | import java.util.ArrayList;
11 |
12 | /**
13 | * Created by admin on 03/02/2017.
14 | */
15 |
16 | public abstract class MultimediaPicker {
17 |
18 | private int mode;
19 | private int limit;
20 | private boolean showCamera;
21 | private String folderTitle;
22 | private String imageTitle;
23 | private ArrayList selectedImages;
24 | private boolean folderMode;
25 | private String imageDirectory;
26 |
27 | public static boolean onlyVideos = false;
28 | public static boolean onlyImages = false;
29 |
30 | public abstract void start(int requestCode);
31 |
32 | public static class MultimediaPickerWithActivity extends MultimediaPicker {
33 |
34 | private Activity activity;
35 |
36 | public MultimediaPickerWithActivity(Activity activity) {
37 | this.activity = activity;
38 | init(activity);
39 | }
40 |
41 | @Override
42 | public void start(int requestCode) {
43 | Intent intent = getIntent(activity);
44 | activity.startActivityForResult(intent, requestCode);
45 | }
46 | }
47 |
48 | public static class MultimediaPickerWithFragment extends MultimediaPicker {
49 |
50 | private Fragment fragment;
51 |
52 | public MultimediaPickerWithFragment(Fragment fragment) {
53 | this.fragment = fragment;
54 | init(fragment.getActivity());
55 | }
56 |
57 | @Override
58 | public void start(int requestCode) {
59 | Intent intent = getIntent(fragment.getActivity());
60 | fragment.startActivityForResult(intent, requestCode);
61 | }
62 | }
63 |
64 |
65 | public void init(Activity activity) {
66 | this.mode = GalleryPickerActivity.MODE_MULTIPLE;
67 | this.limit = Constants.MAX_LIMIT;
68 | this.showCamera = true;
69 | this.folderTitle = activity.getString(R.string.title_folder);
70 | this.imageTitle = activity.getString(R.string.title_select_image);
71 | this.selectedImages = new ArrayList<>();
72 | this.folderMode = false;
73 | this.imageDirectory = activity.getString(R.string.image_directory);
74 | }
75 |
76 |
77 | public static MultimediaPickerWithActivity create(Activity activity) {
78 | return new MultimediaPickerWithActivity(activity);
79 | }
80 |
81 | public static MultimediaPickerWithFragment create(Fragment fragment) {
82 | return new MultimediaPickerWithFragment(fragment);
83 | }
84 |
85 | public MultimediaPicker single() {
86 | mode = GalleryPickerActivity.MODE_SINGLE;
87 | return this;
88 | }
89 |
90 | public MultimediaPicker setOnlyImages(boolean onlyImages) {
91 | this.onlyImages = onlyImages;
92 | return this;
93 | }
94 |
95 | public MultimediaPicker setOnlyVideos(boolean onlyVideos) {
96 | this.onlyVideos = onlyVideos;
97 | return this;
98 | }
99 |
100 | public MultimediaPicker multi() {
101 | mode = GalleryPickerActivity.MODE_MULTIPLE;
102 | return this;
103 | }
104 |
105 |
106 | public MultimediaPicker limit(int count) {
107 | limit = count;
108 | return this;
109 | }
110 |
111 | public MultimediaPicker showCamera(boolean show) {
112 | showCamera = show;
113 | return this;
114 | }
115 |
116 | public MultimediaPicker folderTitle(String title) {
117 | this.folderTitle = title;
118 | return this;
119 | }
120 |
121 | public MultimediaPicker imageTitle(String title) {
122 | this.imageTitle = title;
123 | return this;
124 | }
125 |
126 | public MultimediaPicker origin(ArrayList images) {
127 | selectedImages = images;
128 | return this;
129 | }
130 |
131 | public MultimediaPicker folderMode(boolean folderMode) {
132 | this.folderMode = folderMode;
133 | return this;
134 | }
135 |
136 | public MultimediaPicker imageDirectory(String directory) {
137 | this.imageDirectory = directory;
138 | return this;
139 | }
140 |
141 | public Intent getIntent(Activity activity) {
142 | Intent intent = new Intent(activity, GalleryPickerActivity.class);
143 | intent.putExtra(GalleryPickerActivity.INTENT_EXTRA_MODE, mode);
144 | intent.putExtra(GalleryPickerActivity.INTENT_EXTRA_LIMIT, limit);
145 | intent.putExtra(GalleryPickerActivity.INTENT_EXTRA_SHOW_CAMERA, showCamera);
146 | intent.putExtra(GalleryPickerActivity.INTENT_EXTRA_FOLDER_TITLE, folderTitle);
147 | intent.putExtra(GalleryPickerActivity.INTENT_EXTRA_IMAGE_TITLE, imageTitle);
148 | intent.putExtra(GalleryPickerActivity.INTENT_EXTRA_SELECTED_IMAGES, selectedImages);
149 | intent.putExtra(GalleryPickerActivity.INTENT_EXTRA_FOLDER_MODE, folderMode);
150 | intent.putExtra(GalleryPickerActivity.INTENT_EXTRA_IMAGE_DIRECTORY, imageDirectory);
151 |
152 | intent.putExtra(GalleryPickerActivity.INTENT_EXTRA_ONLY_IMAGES, onlyImages);
153 | intent.putExtra(GalleryPickerActivity.INTENT_EXTRA_ONLY_VIDEO, onlyVideos);
154 |
155 | return intent;
156 | }
157 |
158 |
159 | }
160 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/multimediapicker/src/main/java/com/zet/enterprises/multimediapicker/adapter/ImagePickerAdapter.java:
--------------------------------------------------------------------------------
1 | package com.zet.enterprises.multimediapicker.adapter;
2 |
3 | import android.animation.ObjectAnimator;
4 | import android.content.Context;
5 | import android.support.v4.content.ContextCompat;
6 | import android.support.v7.widget.RecyclerView;
7 | import android.view.LayoutInflater;
8 | import android.view.View;
9 | import android.view.ViewGroup;
10 | import android.widget.FrameLayout;
11 | import android.widget.ImageView;
12 |
13 | import com.bumptech.glide.Glide;
14 | import com.bumptech.glide.request.animation.ViewPropertyAnimation;
15 | import com.zet.enterprises.multimediapicker.R;
16 | import com.zet.enterprises.multimediapicker.listeners.OnImageClickListener;
17 | import com.zet.enterprises.multimediapicker.model.Image;
18 |
19 | import java.util.List;
20 |
21 | /**
22 | * Created by admin on 03/02/2017.
23 | */
24 |
25 | public class ImagePickerAdapter extends RecyclerView.Adapter {
26 |
27 | private Context context;
28 | private LayoutInflater inflater;
29 | private List images;
30 | private List selectedImages;
31 | private OnImageClickListener itemClickListener;
32 |
33 | public ImagePickerAdapter(Context context, List images, List selectedImages, OnImageClickListener itemClickListener) {
34 | this.context = context;
35 | this.images = images;
36 | this.selectedImages = selectedImages;
37 | this.itemClickListener = itemClickListener;
38 | inflater = LayoutInflater.from(this.context);
39 | }
40 |
41 | @Override
42 | public ImageViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
43 | View itemView = inflater.inflate(R.layout.image_item, parent, false);
44 | return new ImageViewHolder(itemView, itemClickListener);
45 | }
46 |
47 | @Override
48 | public void onBindViewHolder(ImageViewHolder viewHolder, int position) {
49 |
50 | ViewPropertyAnimation.Animator animationObject = new ViewPropertyAnimation.Animator() {
51 | @Override
52 | public void animate(View view) {
53 | // if it's a custom view class, cast it here
54 | // then find subviews and do the animations
55 | // here, we just use the entire view for the fade animation
56 | view.setAlpha( 0f );
57 |
58 | ObjectAnimator fadeAnim = ObjectAnimator.ofFloat( view, "alpha", 0f, 1f );
59 | fadeAnim.setDuration(500);
60 | fadeAnim.start();
61 | }
62 | };
63 |
64 | Image image = images.get(position);
65 |
66 | Glide.with(context)
67 | .load(image.getPath())
68 | .placeholder(R.drawable.image_placeholder)
69 | .error(R.drawable.image_placeholder)
70 | .animate(animationObject)
71 | .into(viewHolder.imageView);
72 |
73 | if (isSelected(image)) {
74 | viewHolder.alphaView.setAlpha(0.5f);
75 | ((FrameLayout) viewHolder.itemView).setForeground(ContextCompat.getDrawable(context, R.drawable.ic_done_white));
76 | } else {
77 | viewHolder.alphaView.setAlpha(0.0f);
78 | ((FrameLayout) viewHolder.itemView).setForeground(null);
79 | }
80 |
81 | }
82 |
83 | private boolean isSelected(Image image) {
84 | for (Image selectedImage : selectedImages) {
85 | if (selectedImage.getPath().equals(image.getPath())) {
86 | return true;
87 | }
88 | }
89 |
90 | return false;
91 | }
92 |
93 | @Override
94 | public int getItemCount() {
95 | return images.size();
96 | }
97 |
98 |
99 | public void setData(List images) {
100 | this.images.clear();
101 | this.images.addAll(images);
102 | }
103 |
104 | public void addAll(List images) {
105 | int startIndex = this.images.size();
106 | this.images.addAll(startIndex, images);
107 | notifyItemRangeInserted(startIndex, images.size());
108 | }
109 |
110 | public void addSelected(Image image) {
111 | selectedImages.add(image);
112 | notifyItemChanged(images.indexOf(image));
113 | }
114 |
115 | public void removeSelectedImage(Image image) {
116 | selectedImages.remove(image);
117 | notifyItemChanged(images.indexOf(image));
118 | }
119 |
120 | public void removeSelectedPosition(int position, int clickPosition) {
121 | selectedImages.remove(position);
122 | notifyItemChanged(clickPosition);
123 | }
124 |
125 | public void removeAllSelectedSingleClick() {
126 | selectedImages.clear();
127 | notifyDataSetChanged();
128 | }
129 |
130 |
131 | public static class ImageViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
132 |
133 | private ImageView imageView;
134 | private View alphaView;
135 | private final OnImageClickListener itemClickListener;
136 |
137 | public ImageViewHolder(View itemView, OnImageClickListener itemClickListener) {
138 | super(itemView);
139 | imageView = (ImageView) itemView.findViewById(R.id.image_view);
140 | alphaView = itemView.findViewById(R.id.view_alpha);
141 | this.itemClickListener = itemClickListener;
142 | itemView.setOnClickListener(this);
143 | }
144 |
145 | @Override
146 | public void onClick(View view) {
147 | view.setSelected(true);
148 | itemClickListener.onClick(view, getAdapterPosition());
149 | }
150 | }
151 |
152 |
153 | }
154 |
155 |
--------------------------------------------------------------------------------
/multimediapicker/src/main/java/com/zet/enterprises/multimediapicker/GalleryPickerActivity.java:
--------------------------------------------------------------------------------
1 | package com.zet.enterprises.multimediapicker;
2 |
3 | import android.content.Context;
4 | import android.content.Intent;
5 | import android.net.Uri;
6 | import android.support.design.widget.TabLayout;
7 | import android.support.v4.app.Fragment;
8 | import android.support.v4.app.FragmentManager;
9 | import android.support.v4.app.FragmentPagerAdapter;
10 | import android.support.v4.view.ViewPager;
11 | import android.support.v7.app.ActionBar;
12 | import android.support.v7.app.AppCompatActivity;
13 | import android.os.Bundle;
14 | import android.support.v7.widget.Toolbar;
15 | import android.text.TextUtils;
16 | import android.view.Menu;
17 | import android.view.MenuItem;
18 |
19 | import com.zet.enterprises.multimediapicker.model.Folder;
20 | import com.zet.enterprises.multimediapicker.model.Image;
21 | import com.zet.enterprises.multimediapicker.utils.Constants;
22 |
23 | import java.io.File;
24 | import java.util.ArrayList;
25 | import java.util.List;
26 |
27 | public class GalleryPickerActivity extends AppCompatActivity implements ContainerFragment.OnFragmentInteractionListener {
28 |
29 | @Override
30 | public void onFragmentInteraction(Uri uri) {
31 | }
32 |
33 |
34 |
35 | public static MenuItem menuDone, menuCamera;
36 | public static final int menuDoneId = 100;
37 | public static final int menuCameraId = 101;
38 |
39 | private static final String TAG = "ImagePickerActivity";
40 | private ActionBar actionBar;
41 |
42 | private TabLayout tabGallery;
43 |
44 | class ViewPagerAdapter extends FragmentPagerAdapter {
45 | private final List mFragmentList = new ArrayList<>();
46 | private final List mFragmentTitleList = new ArrayList<>();
47 |
48 | public ViewPagerAdapter(FragmentManager manager) {
49 | super(manager);
50 | }
51 |
52 | @Override
53 | public Fragment getItem(int position) {
54 | return mFragmentList.get(position);
55 | }
56 |
57 | @Override
58 | public int getCount() {
59 | return mFragmentList.size();
60 | }
61 |
62 | public void addFragment(Fragment fragment, String title) {
63 | mFragmentList.add(fragment);
64 | mFragmentTitleList.add(title);
65 | }
66 |
67 | @Override
68 | public CharSequence getPageTitle(int position) {
69 | return mFragmentTitleList.get(position);
70 | }
71 | }
72 |
73 | public static List folders;
74 |
75 | public static String currentImagePath;
76 | public static String imageDirectory;
77 |
78 |
79 |
80 | public static boolean showCamera;
81 | public static int mode;
82 | public static boolean folderMode;
83 | public static int limit;
84 | public static String folderTitle, imageTitle;
85 | public static boolean onlyVideos = false;
86 | public static boolean onlyImages = false;
87 |
88 | public static Context c;
89 |
90 |
91 | public static final int MODE_SINGLE = 1;
92 | public static final int MODE_MULTIPLE = 2;
93 |
94 | public static final String INTENT_EXTRA_ONLY_VIDEO = "onlyVideos";
95 | public static final String INTENT_EXTRA_ONLY_IMAGES = "onlyImages";
96 | public static final String INTENT_EXTRA_SELECTED_IMAGES = "selectedImages";
97 | public static final String INTENT_EXTRA_LIMIT = "limit";
98 | public static final String INTENT_EXTRA_SHOW_CAMERA = "showCamera";
99 | public static final String INTENT_EXTRA_MODE = "mode";
100 | public static final String INTENT_EXTRA_FOLDER_MODE = "folderMode";
101 | public static final String INTENT_EXTRA_FOLDER_TITLE = "folderTitle";
102 | public static final String INTENT_EXTRA_IMAGE_TITLE = "imageTitle";
103 | public static final String INTENT_EXTRA_IMAGE_DIRECTORY = "imageDirectory";
104 |
105 | ContainerFragment imagen;
106 | ContainerFragment video;
107 | private int indexTab = 0;
108 |
109 | @Override
110 | protected void onCreate(Bundle savedInstanceState) {
111 | super.onCreate(savedInstanceState);
112 | setContentView(R.layout.activity_gallery_picker);
113 |
114 | Intent intent = getIntent();
115 | if (intent == null) {
116 | finish();
117 | }
118 |
119 | c = this;
120 |
121 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_g);
122 | setSupportActionBar(toolbar);
123 | actionBar = getSupportActionBar();
124 |
125 | if (actionBar != null) {
126 | actionBar.setDisplayHomeAsUpEnabled(true);
127 | actionBar.setHomeAsUpIndicator(R.drawable.ic_arrow_back);
128 | actionBar.setDisplayShowTitleEnabled(true);
129 | }
130 |
131 | /** Set activity title */
132 | if (actionBar != null) {
133 | actionBar.setTitle(folderMode ? folderTitle : imageTitle);
134 | }
135 |
136 |
137 | /** Get extras */
138 | onlyImages = intent.getBooleanExtra(GalleryPickerActivity.INTENT_EXTRA_ONLY_IMAGES, false);
139 | onlyVideos = intent.getBooleanExtra(GalleryPickerActivity.INTENT_EXTRA_ONLY_VIDEO, false);
140 |
141 | limit = intent.getIntExtra(GalleryPickerActivity.INTENT_EXTRA_LIMIT, Constants.MAX_LIMIT);
142 | mode = intent.getIntExtra(GalleryPickerActivity.INTENT_EXTRA_MODE, GalleryPickerActivity.MODE_MULTIPLE);
143 | folderMode = intent.getBooleanExtra(GalleryPickerActivity.INTENT_EXTRA_FOLDER_MODE, false);
144 |
145 | if (intent.hasExtra(INTENT_EXTRA_FOLDER_TITLE)) {
146 | folderTitle = intent.getStringExtra(GalleryPickerActivity.INTENT_EXTRA_FOLDER_TITLE);
147 | } else {
148 | folderTitle = getString(R.string.title_folder);
149 | }
150 |
151 | if (intent.hasExtra(INTENT_EXTRA_IMAGE_TITLE)) {
152 | imageTitle = intent.getStringExtra(GalleryPickerActivity.INTENT_EXTRA_IMAGE_TITLE);
153 | } else {
154 | imageTitle = getString(R.string.title_select_image);
155 | }
156 |
157 | imageDirectory = intent.getStringExtra(GalleryPickerActivity.INTENT_EXTRA_IMAGE_DIRECTORY);
158 | if (imageDirectory == null || TextUtils.isEmpty(imageDirectory)) {
159 | imageDirectory = getString(R.string.image_directory);
160 | }
161 |
162 | showCamera = intent.getBooleanExtra(GalleryPickerActivity.INTENT_EXTRA_SHOW_CAMERA, true);
163 |
164 | ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager());
165 |
166 | imagen = ContainerFragment.newInstance(false,10);
167 | video = ContainerFragment.newInstance(true,1);
168 |
169 | if(onlyVideos)
170 | {
171 | adapter.addFragment(video, "Videos");
172 | }
173 |
174 | if(onlyImages)
175 | {
176 | adapter.addFragment(imagen, "Imagenes");
177 | }
178 |
179 | if(onlyVideos == false && onlyImages == false) {
180 | adapter.addFragment(imagen, "Imagenes");
181 | adapter.addFragment(video, "Videos");
182 | }
183 |
184 | ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager);
185 | viewPager.setAdapter(adapter);
186 |
187 | tabGallery = (TabLayout)findViewById(R.id.tabs);
188 | tabGallery.setupWithViewPager(viewPager);
189 | tabGallery.setSelectedTabIndicatorColor(getResources().getColor(R.color.colorAccent));
190 |
191 | if (mode == GalleryPickerActivity.MODE_MULTIPLE && intent.hasExtra(GalleryPickerActivity.INTENT_EXTRA_SELECTED_IMAGES)) {
192 | imagen.selectedImages = intent.getParcelableArrayListExtra(GalleryPickerActivity.INTENT_EXTRA_SELECTED_IMAGES);
193 | video.selectedImages = intent.getParcelableArrayListExtra(GalleryPickerActivity.INTENT_EXTRA_SELECTED_IMAGES);
194 | }
195 | if (imagen.selectedImages == null)
196 | imagen.selectedImages = new ArrayList<>();
197 | imagen.images = new ArrayList<>();
198 |
199 | if (video.selectedImages == null)
200 | video.selectedImages = new ArrayList<>();
201 | video.images = new ArrayList<>();
202 |
203 | tabGallery.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
204 | @Override
205 | public void onTabSelected(TabLayout.Tab tab) {
206 | int i = (tab.getPosition());
207 | indexTab = i;
208 |
209 | if(i==0)
210 | {
211 |
212 | imagen.showVideo = false;
213 | menuCamera.setIcon(R.drawable.ic_camera_white);
214 | mode = MODE_MULTIPLE;
215 | imagen.setFolderAdapter();
216 | video.setFolderAdapter();
217 | //imagen.reload();
218 | }else
219 | {
220 | video.showVideo = true;
221 | menuCamera.setIcon(R.drawable.ic_videocam_white_24dp);
222 | mode = MODE_SINGLE;
223 | imagen.setFolderAdapter();
224 | video.setFolderAdapter();
225 | //video.reload();
226 | }
227 |
228 |
229 | }
230 |
231 | @Override
232 | public void onTabUnselected(TabLayout.Tab tab) {
233 |
234 | }
235 |
236 | @Override
237 | public void onTabReselected(TabLayout.Tab tab) {
238 |
239 | }
240 | });
241 |
242 | }
243 |
244 |
245 | @Override
246 | public boolean onCreateOptionsMenu(Menu menu) {
247 |
248 | if (menu.findItem(menuCameraId) == null) {
249 | menuCamera = menu.add(Menu.NONE, menuCameraId, 1, getString(R.string.camera));
250 | menuCamera.setIcon(R.drawable.ic_camera_white);
251 | menuCamera.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
252 | menuCamera.setVisible(showCamera);
253 | }
254 |
255 | if (menu.findItem(menuDoneId) == null) {
256 | menuDone = menu.add(Menu.NONE, menuDoneId, 2, getString(R.string.done));
257 | menuDone.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
258 | }
259 |
260 | updateTitle(imageTitle);
261 |
262 | return true;
263 | }
264 |
265 | public static void updateTitle2(String titulo)
266 | {
267 | GalleryPickerActivity tmp = (GalleryPickerActivity)c;
268 | tmp.updateTitle(titulo);
269 | }
270 |
271 | private void updateTitle(String titulo) {
272 | if(indexTab==0) {
273 |
274 | if (menuDone != null && menuCamera != null) {
275 | if (imagen.isDisplayingFolderView()) {
276 | actionBar.setTitle(folderTitle);
277 | menuDone.setVisible(false);
278 | } else {
279 | if (imagen.selectedImages.size() == 0) {
280 | actionBar.setTitle(titulo);
281 | if (menuDone != null)
282 | menuDone.setVisible(false);
283 | } else {
284 | if (mode == GalleryPickerActivity.MODE_MULTIPLE) {
285 | if (limit == Constants.MAX_LIMIT)
286 | actionBar.setTitle(String.format(getString(R.string.selected), imagen.selectedImages.size()));
287 | else
288 | actionBar.setTitle(titulo + " " + String.format(getString(R.string.selected_with_limit), imagen.selectedImages.size(), limit));
289 | }
290 | if (menuDone != null)
291 | menuDone.setVisible(true);
292 | }
293 | }
294 | }
295 | }else
296 | {
297 | if (menuDone != null && menuCamera != null) {
298 | if (video.isDisplayingFolderView()) {
299 | actionBar.setTitle(folderTitle);
300 | menuDone.setVisible(false);
301 | } else {
302 | if (video.selectedImages.size() == 0) {
303 | actionBar.setTitle(titulo);
304 | if (menuDone != null)
305 | menuDone.setVisible(false);
306 | } else {
307 | if (mode == GalleryPickerActivity.MODE_MULTIPLE) {
308 | if (limit == Constants.MAX_LIMIT)
309 | actionBar.setTitle(String.format(getString(R.string.selected), video.selectedImages.size()));
310 | else
311 | actionBar.setTitle(titulo + " " + String.format(getString(R.string.selected_with_limit), video.selectedImages.size(), limit));
312 | }
313 | if (menuDone != null)
314 | menuDone.setVisible(true);
315 | }
316 | }
317 | }
318 | }
319 | }
320 |
321 | /**
322 | * Handle option menu's click event
323 | */
324 | @Override
325 | public boolean onOptionsItemSelected(MenuItem item) {
326 | int id = item.getItemId();
327 |
328 | if (id == android.R.id.home) {
329 | onBackPressed();
330 | return true;
331 | }
332 |
333 | if (id == menuDoneId) {
334 |
335 | if(indexTab==0) {
336 | if (imagen.selectedImages != null && imagen.selectedImages.size() > 0) {
337 |
338 | /** Scan selected images which not existed */
339 | for (int i = 0; i < imagen.selectedImages.size(); i++) {
340 | Image image = imagen.selectedImages.get(i);
341 | File file = new File(image.getPath());
342 | if (!file.exists()) {
343 | imagen.selectedImages.remove(i);
344 | i--;
345 | }
346 | }
347 |
348 | Intent data = new Intent();
349 | data.putParcelableArrayListExtra(GalleryPickerActivity.INTENT_EXTRA_SELECTED_IMAGES, imagen.selectedImages);
350 | setResult(RESULT_OK, data);
351 | finish();
352 | }
353 | }
354 | else
355 | {
356 | if (video.selectedImages != null && video.selectedImages.size() > 0) {
357 |
358 | /** Scan selected images which not existed */
359 | for (int i = 0; i < video.selectedImages.size(); i++) {
360 | Image image = video.selectedImages.get(i);
361 | File file = new File(image.getPath());
362 | if (!file.exists()) {
363 | video.selectedImages.remove(i);
364 | i--;
365 | }
366 | }
367 |
368 | Intent data = new Intent();
369 | data.putParcelableArrayListExtra(GalleryPickerActivity.INTENT_EXTRA_SELECTED_IMAGES, video.selectedImages);
370 | setResult(RESULT_OK, data);
371 | finish();
372 | }
373 | }
374 | return true;
375 | }
376 |
377 | if (id == menuCameraId) {
378 | //captureImage();
379 | if(indexTab == 0) {
380 |
381 | imagen.captureImageWithPermission();
382 | }
383 | else
384 | {
385 | video.captureImageWithPermission();
386 | }
387 | return true;
388 | }
389 | return super.onOptionsItemSelected(item);
390 | }
391 |
392 |
393 |
394 | @Override
395 | public void onBackPressed() {
396 |
397 | if(indexTab == 0) {
398 | if (GalleryPickerActivity.folderMode && !imagen.isDisplayingFolderView()) {
399 | imagen.onBackPressed();
400 | return;
401 | } else {
402 | imagen.onBackPressed();
403 |
404 | super.onBackPressed();
405 | }
406 | }else
407 | {
408 | if (GalleryPickerActivity.folderMode && !video.isDisplayingFolderView()) {
409 | video.onBackPressed();
410 | return;
411 | } else {
412 | video.onBackPressed();
413 |
414 | super.onBackPressed();
415 | }
416 | }
417 | }
418 |
419 |
420 | }
421 |
--------------------------------------------------------------------------------
/multimediapicker/src/main/java/com/zet/enterprises/multimediapicker/custom/ProgressWheel.java:
--------------------------------------------------------------------------------
1 | package com.zet.enterprises.multimediapicker.custom;
2 |
3 | /**
4 | * Created by admin on 03/02/2017.
5 | */
6 |
7 | import android.annotation.TargetApi;
8 | import android.content.Context;
9 | import android.content.res.TypedArray;
10 | import android.graphics.Canvas;
11 | import android.graphics.Paint;
12 | import android.graphics.RectF;
13 | import android.os.Build;
14 | import android.os.Parcel;
15 | import android.os.Parcelable;
16 | import android.os.SystemClock;
17 | import android.provider.Settings;
18 | import android.util.AttributeSet;
19 | import android.util.DisplayMetrics;
20 | import android.util.TypedValue;
21 | import android.view.View;
22 |
23 | import com.zet.enterprises.multimediapicker.R;
24 |
25 | /**
26 | * A Material style progress wheel, compatible up to 2.2.
27 | * Todd Davies' Progress Wheel https://github.com/Todd-Davies/ProgressWheel
28 | *
29 | * @author Nico Hormazábal
30 | *
31 | * Licensed under the Apache License 2.0 license see:
32 | * http://www.apache.org/licenses/LICENSE-2.0
33 | */
34 | public class ProgressWheel extends View {
35 | private static final String TAG = ProgressWheel.class.getSimpleName();
36 | private final int barLength = 16;
37 | private final int barMaxLength = 270;
38 | private final long pauseGrowingTime = 200;
39 | /**
40 | * *********
41 | * DEFAULTS *
42 | * **********
43 | */
44 | //Sizes (with defaults in DP)
45 | private int circleRadius = 28;
46 | private int barWidth = 4;
47 | private int rimWidth = 4;
48 | private boolean fillRadius = false;
49 | private double timeStartGrowing = 0;
50 | private double barSpinCycleTime = 460;
51 | private float barExtraLength = 0;
52 | private boolean barGrowingFromFront = true;
53 | private long pausedTimeWithoutGrowing = 0;
54 | //Colors (with defaults)
55 | private int barColor = 0xAA000000;
56 | private int rimColor = 0x00FFFFFF;
57 |
58 | //Paints
59 | private Paint barPaint = new Paint();
60 | private Paint rimPaint = new Paint();
61 |
62 | //Rectangles
63 | private RectF circleBounds = new RectF();
64 |
65 | //Animation
66 | //The amount of degrees per second
67 | private float spinSpeed = 230.0f;
68 | //private float spinSpeed = 120.0f;
69 | // The last time the spinner was animated
70 | private long lastTimeAnimated = 0;
71 |
72 | private boolean linearProgress;
73 |
74 | private float mProgress = 0.0f;
75 | private float mTargetProgress = 0.0f;
76 | private boolean isSpinning = false;
77 |
78 | private ProgressCallback callback;
79 |
80 | private boolean shouldAnimate;
81 |
82 | /**
83 | * The constructor for the ProgressWheel
84 | */
85 | public ProgressWheel(Context context, AttributeSet attrs) {
86 | super(context, attrs);
87 |
88 | parseAttributes(context.obtainStyledAttributes(attrs, R.styleable.ProgressWheel));
89 |
90 | setAnimationEnabled();
91 | }
92 |
93 | /**
94 | * The constructor for the ProgressWheel
95 | */
96 | public ProgressWheel(Context context) {
97 | super(context);
98 | setAnimationEnabled();
99 | }
100 |
101 | @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) private void setAnimationEnabled() {
102 | int currentApiVersion = Build.VERSION.SDK_INT;
103 |
104 | float animationValue;
105 | if (currentApiVersion >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
106 | animationValue = Settings.Global.getFloat(getContext().getContentResolver(),
107 | Settings.Global.ANIMATOR_DURATION_SCALE, 1);
108 | } else {
109 | animationValue = Settings.System.getFloat(getContext().getContentResolver(),
110 | Settings.System.ANIMATOR_DURATION_SCALE, 1);
111 | }
112 |
113 | shouldAnimate = animationValue != 0;
114 | }
115 |
116 | //----------------------------------
117 | //Setting up stuff
118 | //----------------------------------
119 |
120 | @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
121 | super.onMeasure(widthMeasureSpec, heightMeasureSpec);
122 |
123 | int viewWidth = circleRadius + this.getPaddingLeft() + this.getPaddingRight();
124 | int viewHeight = circleRadius + this.getPaddingTop() + this.getPaddingBottom();
125 |
126 | int widthMode = MeasureSpec.getMode(widthMeasureSpec);
127 | int widthSize = MeasureSpec.getSize(widthMeasureSpec);
128 | int heightMode = MeasureSpec.getMode(heightMeasureSpec);
129 | int heightSize = MeasureSpec.getSize(heightMeasureSpec);
130 |
131 | int width;
132 | int height;
133 |
134 | //Measure Width
135 | if (widthMode == MeasureSpec.EXACTLY) {
136 | //Must be this size
137 | width = widthSize;
138 | } else if (widthMode == MeasureSpec.AT_MOST) {
139 | //Can't be bigger than...
140 | width = Math.min(viewWidth, widthSize);
141 | } else {
142 | //Be whatever you want
143 | width = viewWidth;
144 | }
145 |
146 | //Measure Height
147 | if (heightMode == MeasureSpec.EXACTLY || widthMode == MeasureSpec.EXACTLY) {
148 | //Must be this size
149 | height = heightSize;
150 | } else if (heightMode == MeasureSpec.AT_MOST) {
151 | //Can't be bigger than...
152 | height = Math.min(viewHeight, heightSize);
153 | } else {
154 | //Be whatever you want
155 | height = viewHeight;
156 | }
157 |
158 | setMeasuredDimension(width, height);
159 | }
160 |
161 | /**
162 | * Use onSizeChanged instead of onAttachedToWindow to get the dimensions of the view,
163 | * because this method is called after measuring the dimensions of MATCH_PARENT & WRAP_CONTENT.
164 | * Use this dimensions to setup the bounds and paints.
165 | */
166 | @Override protected void onSizeChanged(int w, int h, int oldw, int oldh) {
167 | super.onSizeChanged(w, h, oldw, oldh);
168 |
169 | setupBounds(w, h);
170 | setupPaints();
171 | invalidate();
172 | }
173 |
174 | /**
175 | * Set the properties of the paints we're using to
176 | * draw the progress wheel
177 | */
178 | private void setupPaints() {
179 | barPaint.setColor(barColor);
180 | barPaint.setAntiAlias(true);
181 | barPaint.setStyle(Paint.Style.STROKE);
182 | barPaint.setStrokeWidth(barWidth);
183 |
184 | rimPaint.setColor(rimColor);
185 | rimPaint.setAntiAlias(true);
186 | rimPaint.setStyle(Paint.Style.STROKE);
187 | rimPaint.setStrokeWidth(rimWidth);
188 | }
189 |
190 | /**
191 | * Set the bounds of the component
192 | */
193 | private void setupBounds(int layout_width, int layout_height) {
194 | int paddingTop = getPaddingTop();
195 | int paddingBottom = getPaddingBottom();
196 | int paddingLeft = getPaddingLeft();
197 | int paddingRight = getPaddingRight();
198 |
199 | if (!fillRadius) {
200 | // Width should equal to Height, find the min value to setup the circle
201 | int minValue = Math.min(layout_width - paddingLeft - paddingRight,
202 | layout_height - paddingBottom - paddingTop);
203 |
204 | int circleDiameter = Math.min(minValue, circleRadius * 2 - barWidth * 2);
205 |
206 | // Calc the Offset if needed for centering the wheel in the available space
207 | int xOffset = (layout_width - paddingLeft - paddingRight - circleDiameter) / 2 + paddingLeft;
208 | int yOffset = (layout_height - paddingTop - paddingBottom - circleDiameter) / 2 + paddingTop;
209 |
210 | circleBounds =
211 | new RectF(xOffset + barWidth, yOffset + barWidth, xOffset + circleDiameter - barWidth,
212 | yOffset + circleDiameter - barWidth);
213 | } else {
214 | circleBounds = new RectF(paddingLeft + barWidth, paddingTop + barWidth,
215 | layout_width - paddingRight - barWidth, layout_height - paddingBottom - barWidth);
216 | }
217 | }
218 |
219 | /**
220 | * Parse the attributes passed to the view from the XML
221 | *
222 | * @param a the attributes to parse
223 | */
224 | private void parseAttributes(TypedArray a) {
225 | // We transform the default values from DIP to pixels
226 | DisplayMetrics metrics = getContext().getResources().getDisplayMetrics();
227 | barWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, barWidth, metrics);
228 | rimWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, rimWidth, metrics);
229 | circleRadius =
230 | (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, circleRadius, metrics);
231 |
232 | circleRadius =
233 | (int) a.getDimension(R.styleable.ProgressWheel_matProg_circleRadius, circleRadius);
234 |
235 | fillRadius = a.getBoolean(R.styleable.ProgressWheel_matProg_fillRadius, false);
236 |
237 | barWidth = (int) a.getDimension(R.styleable.ProgressWheel_matProg_barWidth, barWidth);
238 |
239 | rimWidth = (int) a.getDimension(R.styleable.ProgressWheel_matProg_rimWidth, rimWidth);
240 |
241 | float baseSpinSpeed =
242 | a.getFloat(R.styleable.ProgressWheel_matProg_spinSpeed, spinSpeed / 360.0f);
243 | spinSpeed = baseSpinSpeed * 360;
244 |
245 | barSpinCycleTime =
246 | a.getInt(R.styleable.ProgressWheel_matProg_barSpinCycleTime, (int) barSpinCycleTime);
247 |
248 | barColor = a.getColor(R.styleable.ProgressWheel_matProg_barColor, barColor);
249 |
250 | rimColor = a.getColor(R.styleable.ProgressWheel_matProg_rimColor, rimColor);
251 |
252 | linearProgress = a.getBoolean(R.styleable.ProgressWheel_matProg_linearProgress, false);
253 |
254 | if (a.getBoolean(R.styleable.ProgressWheel_matProg_progressIndeterminate, false)) {
255 | spin();
256 | }
257 |
258 | // Recycle
259 | a.recycle();
260 | }
261 |
262 | public void setCallback(ProgressCallback progressCallback) {
263 | callback = progressCallback;
264 |
265 | if (!isSpinning) {
266 | runCallback();
267 | }
268 | }
269 |
270 | //----------------------------------
271 | //Animation stuff
272 | //----------------------------------
273 |
274 | protected void onDraw(Canvas canvas) {
275 | super.onDraw(canvas);
276 |
277 | canvas.drawArc(circleBounds, 360, 360, false, rimPaint);
278 |
279 | boolean mustInvalidate = false;
280 |
281 | if (!shouldAnimate) {
282 | return;
283 | }
284 |
285 | if (isSpinning) {
286 | //Draw the spinning bar
287 | mustInvalidate = true;
288 |
289 | long deltaTime = (SystemClock.uptimeMillis() - lastTimeAnimated);
290 | float deltaNormalized = deltaTime * spinSpeed / 1000.0f;
291 |
292 | updateBarLength(deltaTime);
293 |
294 | mProgress += deltaNormalized;
295 | if (mProgress > 360) {
296 | mProgress -= 360f;
297 |
298 | // A full turn has been completed
299 | // we run the callback with -1 in case we want to
300 | // do something, like changing the color
301 | runCallback(-1.0f);
302 | }
303 | lastTimeAnimated = SystemClock.uptimeMillis();
304 |
305 | float from = mProgress - 90;
306 | float length = barLength + barExtraLength;
307 |
308 | if (isInEditMode()) {
309 | from = 0;
310 | length = 135;
311 | }
312 |
313 | canvas.drawArc(circleBounds, from, length, false, barPaint);
314 | } else {
315 | float oldProgress = mProgress;
316 |
317 | if (mProgress != mTargetProgress) {
318 | //We smoothly increase the progress bar
319 | mustInvalidate = true;
320 |
321 | float deltaTime = (float) (SystemClock.uptimeMillis() - lastTimeAnimated) / 1000;
322 | float deltaNormalized = deltaTime * spinSpeed;
323 |
324 | mProgress = Math.min(mProgress + deltaNormalized, mTargetProgress);
325 | lastTimeAnimated = SystemClock.uptimeMillis();
326 | }
327 |
328 | if (oldProgress != mProgress) {
329 | runCallback();
330 | }
331 |
332 | float offset = 0.0f;
333 | float progress = mProgress;
334 | if (!linearProgress) {
335 | float factor = 2.0f;
336 | offset = (float) (1.0f - Math.pow(1.0f - mProgress / 360.0f, 2.0f * factor)) * 360.0f;
337 | progress = (float) (1.0f - Math.pow(1.0f - mProgress / 360.0f, factor)) * 360.0f;
338 | }
339 |
340 | if (isInEditMode()) {
341 | progress = 360;
342 | }
343 |
344 | canvas.drawArc(circleBounds, offset - 90, progress, false, barPaint);
345 | }
346 |
347 | if (mustInvalidate) {
348 | invalidate();
349 | }
350 | }
351 |
352 | @Override protected void onVisibilityChanged(View changedView, int visibility) {
353 | super.onVisibilityChanged(changedView, visibility);
354 |
355 | if (visibility == VISIBLE) {
356 | lastTimeAnimated = SystemClock.uptimeMillis();
357 | }
358 | }
359 |
360 | private void updateBarLength(long deltaTimeInMilliSeconds) {
361 | if (pausedTimeWithoutGrowing >= pauseGrowingTime) {
362 | timeStartGrowing += deltaTimeInMilliSeconds;
363 |
364 | if (timeStartGrowing > barSpinCycleTime) {
365 | // We completed a size change cycle
366 | // (growing or shrinking)
367 | timeStartGrowing -= barSpinCycleTime;
368 | //if(barGrowingFromFront) {
369 | pausedTimeWithoutGrowing = 0;
370 | //}
371 | barGrowingFromFront = !barGrowingFromFront;
372 | }
373 |
374 | float distance =
375 | (float) Math.cos((timeStartGrowing / barSpinCycleTime + 1) * Math.PI) / 2 + 0.5f;
376 | float destLength = (barMaxLength - barLength);
377 |
378 | if (barGrowingFromFront) {
379 | barExtraLength = distance * destLength;
380 | } else {
381 | float newLength = destLength * (1 - distance);
382 | mProgress += (barExtraLength - newLength);
383 | barExtraLength = newLength;
384 | }
385 | } else {
386 | pausedTimeWithoutGrowing += deltaTimeInMilliSeconds;
387 | }
388 | }
389 |
390 | /**
391 | * Check if the wheel is currently spinning
392 | */
393 |
394 | public boolean isSpinning() {
395 | return isSpinning;
396 | }
397 |
398 | /**
399 | * Reset the count (in increment mode)
400 | */
401 | public void resetCount() {
402 | mProgress = 0.0f;
403 | mTargetProgress = 0.0f;
404 | invalidate();
405 | }
406 |
407 | /**
408 | * Turn off spin mode
409 | */
410 | public void stopSpinning() {
411 | isSpinning = false;
412 | mProgress = 0.0f;
413 | mTargetProgress = 0.0f;
414 | invalidate();
415 | }
416 |
417 | /**
418 | * Puts the view on spin mode
419 | */
420 | public void spin() {
421 | lastTimeAnimated = SystemClock.uptimeMillis();
422 | isSpinning = true;
423 | invalidate();
424 | }
425 |
426 | private void runCallback(float value) {
427 | if (callback != null) {
428 | callback.onProgressUpdate(value);
429 | }
430 | }
431 |
432 | private void runCallback() {
433 | if (callback != null) {
434 | float normalizedProgress = (float) Math.round(mProgress * 100 / 360.0f) / 100;
435 | callback.onProgressUpdate(normalizedProgress);
436 | }
437 | }
438 |
439 | /**
440 | * Set the progress to a specific value,
441 | * the bar will be set instantly to that value
442 | *
443 | * @param progress the progress between 0 and 1
444 | */
445 | public void setInstantProgress(float progress) {
446 | if (isSpinning) {
447 | mProgress = 0.0f;
448 | isSpinning = false;
449 | }
450 |
451 | if (progress > 1.0f) {
452 | progress -= 1.0f;
453 | } else if (progress < 0) {
454 | progress = 0;
455 | }
456 |
457 | if (progress == mTargetProgress) {
458 | return;
459 | }
460 |
461 | mTargetProgress = Math.min(progress * 360.0f, 360.0f);
462 | mProgress = mTargetProgress;
463 | lastTimeAnimated = SystemClock.uptimeMillis();
464 | invalidate();
465 | }
466 |
467 | // Great way to save a view's state http://stackoverflow.com/a/7089687/1991053
468 | @Override public Parcelable onSaveInstanceState() {
469 | Parcelable superState = super.onSaveInstanceState();
470 |
471 | WheelSavedState ss = new WheelSavedState(superState);
472 |
473 | // We save everything that can be changed at runtime
474 | ss.mProgress = this.mProgress;
475 | ss.mTargetProgress = this.mTargetProgress;
476 | ss.isSpinning = this.isSpinning;
477 | ss.spinSpeed = this.spinSpeed;
478 | ss.barWidth = this.barWidth;
479 | ss.barColor = this.barColor;
480 | ss.rimWidth = this.rimWidth;
481 | ss.rimColor = this.rimColor;
482 | ss.circleRadius = this.circleRadius;
483 | ss.linearProgress = this.linearProgress;
484 | ss.fillRadius = this.fillRadius;
485 |
486 | return ss;
487 | }
488 |
489 | @Override public void onRestoreInstanceState(Parcelable state) {
490 | if (!(state instanceof WheelSavedState)) {
491 | super.onRestoreInstanceState(state);
492 | return;
493 | }
494 |
495 | WheelSavedState ss = (WheelSavedState) state;
496 | super.onRestoreInstanceState(ss.getSuperState());
497 |
498 | this.mProgress = ss.mProgress;
499 | this.mTargetProgress = ss.mTargetProgress;
500 | this.isSpinning = ss.isSpinning;
501 | this.spinSpeed = ss.spinSpeed;
502 | this.barWidth = ss.barWidth;
503 | this.barColor = ss.barColor;
504 | this.rimWidth = ss.rimWidth;
505 | this.rimColor = ss.rimColor;
506 | this.circleRadius = ss.circleRadius;
507 | this.linearProgress = ss.linearProgress;
508 | this.fillRadius = ss.fillRadius;
509 |
510 | this.lastTimeAnimated = SystemClock.uptimeMillis();
511 | }
512 |
513 | /**
514 | * @return the current progress between 0.0 and 1.0,
515 | * if the wheel is indeterminate, then the result is -1
516 | */
517 | public float getProgress() {
518 | return isSpinning ? -1 : mProgress / 360.0f;
519 | }
520 |
521 | //----------------------------------
522 | //Getters + setters
523 | //----------------------------------
524 |
525 | /**
526 | * Set the progress to a specific value,
527 | * the bar will smoothly animate until that value
528 | *
529 | * @param progress the progress between 0 and 1
530 | */
531 | public void setProgress(float progress) {
532 | if (isSpinning) {
533 | mProgress = 0.0f;
534 | isSpinning = false;
535 |
536 | runCallback();
537 | }
538 |
539 | if (progress > 1.0f) {
540 | progress -= 1.0f;
541 | } else if (progress < 0) {
542 | progress = 0;
543 | }
544 |
545 | if (progress == mTargetProgress) {
546 | return;
547 | }
548 |
549 | // If we are currently in the right position
550 | // we set again the last time animated so the
551 | // animation starts smooth from here
552 | if (mProgress == mTargetProgress) {
553 | lastTimeAnimated = SystemClock.uptimeMillis();
554 | }
555 |
556 | mTargetProgress = Math.min(progress * 360.0f, 360.0f);
557 |
558 | invalidate();
559 | }
560 |
561 | /**
562 | * Sets the determinate progress mode
563 | *
564 | * @param isLinear if the progress should increase linearly
565 | */
566 | public void setLinearProgress(boolean isLinear) {
567 | linearProgress = isLinear;
568 | if (!isSpinning) {
569 | invalidate();
570 | }
571 | }
572 |
573 | /**
574 | * @return the radius of the wheel in pixels
575 | */
576 | public int getCircleRadius() {
577 | return circleRadius;
578 | }
579 |
580 | /**
581 | * Sets the radius of the wheel
582 | *
583 | * @param circleRadius the expected radius, in pixels
584 | */
585 | public void setCircleRadius(int circleRadius) {
586 | this.circleRadius = circleRadius;
587 | if (!isSpinning) {
588 | invalidate();
589 | }
590 | }
591 |
592 | /**
593 | * @return the width of the spinning bar
594 | */
595 | public int getBarWidth() {
596 | return barWidth;
597 | }
598 |
599 | /**
600 | * Sets the width of the spinning bar
601 | *
602 | * @param barWidth the spinning bar width in pixels
603 | */
604 | public void setBarWidth(int barWidth) {
605 | this.barWidth = barWidth;
606 | if (!isSpinning) {
607 | invalidate();
608 | }
609 | }
610 |
611 | /**
612 | * @return the color of the spinning bar
613 | */
614 | public int getBarColor() {
615 | return barColor;
616 | }
617 |
618 | /**
619 | * Sets the color of the spinning bar
620 | *
621 | * @param barColor The spinning bar color
622 | */
623 | public void setBarColor(int barColor) {
624 | this.barColor = barColor;
625 | setupPaints();
626 | if (!isSpinning) {
627 | invalidate();
628 | }
629 | }
630 |
631 | /**
632 | * @return the color of the wheel's contour
633 | */
634 | public int getRimColor() {
635 | return rimColor;
636 | }
637 |
638 | /**
639 | * Sets the color of the wheel's contour
640 | *
641 | * @param rimColor the color for the wheel
642 | */
643 | public void setRimColor(int rimColor) {
644 | this.rimColor = rimColor;
645 | setupPaints();
646 | if (!isSpinning) {
647 | invalidate();
648 | }
649 | }
650 |
651 | /**
652 | * @return the base spinning speed, in full circle turns per second
653 | * (1.0 equals on full turn in one second), this value also is applied for
654 | * the smoothness when setting a progress
655 | */
656 | public float getSpinSpeed() {
657 | return spinSpeed / 360.0f;
658 | }
659 |
660 | /**
661 | * Sets the base spinning speed, in full circle turns per second
662 | * (1.0 equals on full turn in one second), this value also is applied for
663 | * the smoothness when setting a progress
664 | *
665 | * @param spinSpeed the desired base speed in full turns per second
666 | */
667 | public void setSpinSpeed(float spinSpeed) {
668 | this.spinSpeed = spinSpeed * 360.0f;
669 | }
670 |
671 | /**
672 | * @return the width of the wheel's contour in pixels
673 | */
674 | public int getRimWidth() {
675 | return rimWidth;
676 | }
677 |
678 | /**
679 | * Sets the width of the wheel's contour
680 | *
681 | * @param rimWidth the width in pixels
682 | */
683 | public void setRimWidth(int rimWidth) {
684 | this.rimWidth = rimWidth;
685 | if (!isSpinning) {
686 | invalidate();
687 | }
688 | }
689 |
690 | public interface ProgressCallback {
691 | /**
692 | * Method to call when the progress reaches a value
693 | * in order to avoid float precision issues, the progress
694 | * is rounded to a float with two decimals.
695 | *
696 | * In indeterminate mode, the callback is called each time
697 | * the wheel completes an animation cycle, with, the progress value is -1.0f
698 | *
699 | * @param progress a double value between 0.00 and 1.00 both included
700 | */
701 | public void onProgressUpdate(float progress);
702 | }
703 |
704 | static class WheelSavedState extends BaseSavedState {
705 | //required field that makes Parcelables from a Parcel
706 | public static final Creator CREATOR =
707 | new Creator() {
708 | public WheelSavedState createFromParcel(Parcel in) {
709 | return new WheelSavedState(in);
710 | }
711 |
712 | public WheelSavedState[] newArray(int size) {
713 | return new WheelSavedState[size];
714 | }
715 | };
716 | float mProgress;
717 | float mTargetProgress;
718 | boolean isSpinning;
719 | float spinSpeed;
720 | int barWidth;
721 | int barColor;
722 | int rimWidth;
723 | int rimColor;
724 | int circleRadius;
725 | boolean linearProgress;
726 | boolean fillRadius;
727 |
728 | WheelSavedState(Parcelable superState) {
729 | super(superState);
730 | }
731 |
732 | private WheelSavedState(Parcel in) {
733 | super(in);
734 | this.mProgress = in.readFloat();
735 | this.mTargetProgress = in.readFloat();
736 | this.isSpinning = in.readByte() != 0;
737 | this.spinSpeed = in.readFloat();
738 | this.barWidth = in.readInt();
739 | this.barColor = in.readInt();
740 | this.rimWidth = in.readInt();
741 | this.rimColor = in.readInt();
742 | this.circleRadius = in.readInt();
743 | this.linearProgress = in.readByte() != 0;
744 | this.fillRadius = in.readByte() != 0;
745 | }
746 |
747 | @Override public void writeToParcel(Parcel out, int flags) {
748 | super.writeToParcel(out, flags);
749 | out.writeFloat(this.mProgress);
750 | out.writeFloat(this.mTargetProgress);
751 | out.writeByte((byte) (isSpinning ? 1 : 0));
752 | out.writeFloat(this.spinSpeed);
753 | out.writeInt(this.barWidth);
754 | out.writeInt(this.barColor);
755 | out.writeInt(this.rimWidth);
756 | out.writeInt(this.rimColor);
757 | out.writeInt(this.circleRadius);
758 | out.writeByte((byte) (linearProgress ? 1 : 0));
759 | out.writeByte((byte) (fillRadius ? 1 : 0));
760 | }
761 | }
762 | }
763 |
--------------------------------------------------------------------------------
/multimediapicker/src/main/java/com/zet/enterprises/multimediapicker/ContainerFragment.java:
--------------------------------------------------------------------------------
1 | package com.zet.enterprises.multimediapicker;
2 |
3 | import android.Manifest;
4 | import android.content.Context;
5 | import android.content.Intent;
6 | import android.content.SharedPreferences;
7 | import android.content.pm.PackageManager;
8 | import android.content.res.Configuration;
9 | import android.database.ContentObserver;
10 | import android.database.Cursor;
11 | import android.media.MediaScannerConnection;
12 | import android.net.Uri;
13 | import android.os.Build;
14 | import android.os.Bundle;
15 | import android.os.Handler;
16 | import android.os.Message;
17 | import android.os.Parcelable;
18 | import android.os.Process;
19 | import android.preference.PreferenceManager;
20 | import android.provider.MediaStore;
21 | import android.provider.Settings;
22 | import android.support.annotation.NonNull;
23 | import android.support.design.widget.Snackbar;
24 | import android.support.v4.app.ActivityCompat;
25 | import android.support.v4.app.Fragment;
26 | import android.support.v4.content.FileProvider;
27 | import android.support.v7.widget.GridLayoutManager;
28 | import android.support.v7.widget.RecyclerView;
29 | import android.view.LayoutInflater;
30 | import android.view.View;
31 | import android.view.ViewGroup;
32 | import android.widget.RelativeLayout;
33 | import android.widget.TextView;
34 | import android.widget.Toast;
35 |
36 | import com.zet.enterprises.multimediapicker.adapter.FolderPickerAdapter;
37 | import com.zet.enterprises.multimediapicker.adapter.ImagePickerAdapter;
38 | import com.zet.enterprises.multimediapicker.custom.GridSpacingItemDecoration;
39 | import com.zet.enterprises.multimediapicker.custom.ProgressWheel;
40 | import com.zet.enterprises.multimediapicker.listeners.OnFolderClickListener;
41 | import com.zet.enterprises.multimediapicker.listeners.OnImageClickListener;
42 | import com.zet.enterprises.multimediapicker.model.Folder;
43 | import com.zet.enterprises.multimediapicker.model.Image;
44 | import com.zet.enterprises.multimediapicker.utils.Constants;
45 | import com.zet.enterprises.multimediapicker.utils.ImageUtils;
46 |
47 | import java.io.File;
48 | import java.util.ArrayList;
49 | import java.util.List;
50 |
51 | import static android.app.Activity.RESULT_CANCELED;
52 | import static android.app.Activity.RESULT_OK;
53 | import static com.zet.enterprises.multimediapicker.GalleryPickerActivity.folderMode;
54 | import static com.zet.enterprises.multimediapicker.GalleryPickerActivity.mode;
55 | import static com.zet.enterprises.multimediapicker.GalleryPickerActivity.updateTitle2;
56 |
57 | /**
58 | * Created by admin on 03/02/2017.
59 | */
60 |
61 | public class ContainerFragment extends Fragment implements OnImageClickListener {
62 | // TODO: Rename parameter arguments, choose names that match
63 | // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
64 | private static final String SHOW_VIDEO = "video" ;
65 |
66 | public boolean showVideo = false;
67 |
68 | private List folders;
69 | private String currentImagePath;
70 | private String imageDirectory;
71 | private boolean showCamera;
72 |
73 |
74 | private int limit;
75 | private String folderTitle, imageTitle;
76 |
77 | public ArrayList images;
78 | public ArrayList selectedImages;
79 |
80 | private RelativeLayout mainLayout;
81 | private ProgressWheel progressBar;
82 | private TextView emptyTextView;
83 | private RecyclerView recyclerView;
84 |
85 | private GridLayoutManager layoutManager;
86 | private GridSpacingItemDecoration itemOffsetDecoration;
87 |
88 | private int imageColumns;
89 | private int folderColumns;
90 |
91 | private ImagePickerAdapter imageAdapter;
92 | private FolderPickerAdapter folderAdapter;
93 |
94 | private ContentObserver observer;
95 | private Handler handler;
96 | private Thread thread;
97 |
98 | private final String[] projection = new String[]{MediaStore.Images.Media._ID, MediaStore.Images.Media.DISPLAY_NAME, MediaStore.Images.Media.DATA, MediaStore.Images.Media.BUCKET_DISPLAY_NAME};
99 |
100 | private Parcelable foldersState;
101 |
102 | private String parent = "";
103 |
104 |
105 | protected View mView;
106 | private final int REQUEST_VIDEO_CAPTURE = 1;
107 |
108 | private OnFragmentInteractionListener mListener;
109 |
110 | public ContainerFragment() {
111 | // Required empty public constructor
112 | }
113 |
114 |
115 | public static ContainerFragment newInstance(boolean showVideo,int limit) {
116 | ContainerFragment fragment = new ContainerFragment();
117 | fragment.showVideo = showVideo;
118 | fragment.limit = limit;
119 | fragment.imageDirectory = "Camera";
120 | Bundle args = new Bundle();
121 | args.putBoolean(SHOW_VIDEO, showVideo);
122 |
123 | fragment.setArguments(args);
124 | return fragment;
125 | }
126 |
127 |
128 | @Override
129 | public void onCreate(Bundle savedInstanceState) {
130 | super.onCreate(savedInstanceState);
131 |
132 | }
133 |
134 | @Override
135 | public void onResume() {
136 | super.onResume();
137 | getDataWithPermission();
138 | }
139 |
140 | /**
141 | * Set image adapter
142 | * 1. Set new data
143 | * 2. Update item decoration
144 | * 3. Update title
145 | */
146 | private void setImageAdapter(ArrayList images) {
147 | imageAdapter.setData(images);
148 | setItemDecoration(imageColumns);
149 | recyclerView.setAdapter(imageAdapter);
150 |
151 | File file = new File(images.get(0).getPath());
152 |
153 | parent = file.getParentFile().getName();
154 |
155 | updateTitle2(parent);
156 | }
157 |
158 |
159 | /**
160 | * Check permission
161 | */
162 | private void getDataWithPermission() {
163 | int rc = ActivityCompat.checkSelfPermission( getActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE);
164 | if (rc == PackageManager.PERMISSION_GRANTED)
165 | getData();
166 | else
167 | requestWriteExternalPermission();
168 | }
169 |
170 | /**
171 | * Get data
172 | */
173 | private void getData() {
174 | abortLoading();
175 |
176 | ImageLoaderRunnable runnable = new ImageLoaderRunnable();
177 | thread = new Thread(runnable);
178 | thread.start();
179 | }
180 |
181 | /**
182 | * Request for permission
183 | * If permission denied or app is first launched, request for permission
184 | * If permission denied and user choose 'Nerver Ask Again', show snackbar with an action that navigate to app settings
185 | */
186 | private void requestWriteExternalPermission() {
187 |
188 | final String[] permissions = new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE};
189 |
190 | if (ActivityCompat.shouldShowRequestPermissionRationale( getActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
191 | ActivityCompat.requestPermissions( getActivity(), permissions, Constants.PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE);
192 | } else {
193 | if (!isPermissionRequested(Constants.PREF_WRITE_EXTERNAL_STORAGE_REQUESTED)) {
194 | ActivityCompat.requestPermissions( getActivity(), permissions, Constants.PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE);
195 | setPermissionRequested(Constants.PREF_WRITE_EXTERNAL_STORAGE_REQUESTED);
196 | } else {
197 | Snackbar snackbar = Snackbar.make(mainLayout, R.string.msg_no_write_external_permission,
198 | Snackbar.LENGTH_INDEFINITE);
199 | snackbar.setAction(R.string.ok, new View.OnClickListener() {
200 | @Override
201 | public void onClick(View view) {
202 | openAppSettings();
203 | }
204 | });
205 | snackbar.show();
206 | }
207 | }
208 |
209 | }
210 |
211 |
212 | private void requestCameraPermission() {
213 |
214 | final String[] permissions = new String[]{Manifest.permission.CAMERA};
215 |
216 | if (ActivityCompat.shouldShowRequestPermissionRationale( getActivity(), Manifest.permission.CAMERA)) {
217 | ActivityCompat.requestPermissions( getActivity(), permissions, Constants.PERMISSION_REQUEST_CAMERA);
218 | } else {
219 | if (!isPermissionRequested(Constants.PREF_CAMERA_REQUESTED)) {
220 | ActivityCompat.requestPermissions( getActivity(), permissions, Constants.PERMISSION_REQUEST_CAMERA);
221 | setPermissionRequested(Constants.PREF_CAMERA_REQUESTED);
222 | } else {
223 | Snackbar snackbar = Snackbar.make(mainLayout, R.string.msg_no_camera_permission,
224 | Snackbar.LENGTH_INDEFINITE);
225 | snackbar.setAction(R.string.ok, new View.OnClickListener() {
226 | @Override
227 | public void onClick(View view) {
228 | openAppSettings();
229 | }
230 | });
231 | snackbar.show();
232 | }
233 | }
234 | }
235 |
236 | /**
237 | * Handle permission results
238 | */
239 | @Override
240 | public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
241 |
242 | switch (requestCode) {
243 | case Constants.PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE: {
244 | if (grantResults.length != 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
245 |
246 | getData();
247 | return;
248 | }
249 |
250 | getActivity().finish();
251 | }
252 | case Constants.PERMISSION_REQUEST_CAMERA: {
253 | if (grantResults.length != 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
254 |
255 | captureImage();
256 | return;
257 | }
258 |
259 | break;
260 | }
261 | default: {
262 |
263 | super.onRequestPermissionsResult(requestCode, permissions, grantResults);
264 | break;
265 | }
266 | }
267 | }
268 |
269 | /**
270 | * Open app settings screen
271 | */
272 | private void openAppSettings() {
273 | Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
274 | Uri.fromParts("package", getActivity().getPackageName(), null));
275 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
276 | startActivity(intent);
277 | }
278 |
279 | /**
280 | * Set a permission is requested
281 | */
282 | private void setPermissionRequested(String permission) {
283 | SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences( getActivity());
284 | SharedPreferences.Editor editor = preferences.edit();
285 | editor.putBoolean(permission, true);
286 | editor.apply();
287 | }
288 |
289 | /**
290 | * Check if a permission is requestted or not (false by default)
291 | */
292 | private boolean isPermissionRequested(String permission) {
293 | SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences( getActivity());
294 | return preferences.getBoolean(permission, false);
295 | }
296 |
297 | @Override
298 | public void onClick(View view, int position) {
299 | clickImage(position);
300 | }
301 |
302 | /**
303 | * Handle image selection event: add or remove selected image, change title
304 | */
305 | private void clickImage(int position) {
306 | int selectedItemPosition = selectedImagePosition(images.get(position));
307 | if (mode == GalleryPickerActivity.MODE_MULTIPLE) {
308 | if (selectedItemPosition == -1) {
309 | if (selectedImages.size() < limit) {
310 | imageAdapter.addSelected(images.get(position));
311 | } else {
312 | Toast.makeText(getActivity(), R.string.msg_limit_images, Toast.LENGTH_SHORT).show();
313 | }
314 | } else {
315 | imageAdapter.removeSelectedPosition(selectedItemPosition, position);
316 | }
317 | } else {
318 | if (selectedItemPosition != -1)
319 | imageAdapter.removeSelectedPosition(selectedItemPosition, position);
320 | else {
321 | if (selectedImages.size() > 0) {
322 | imageAdapter.removeAllSelectedSingleClick();
323 | }
324 | imageAdapter.addSelected(images.get(position));
325 | }
326 | }
327 | updateTitle2(parent);
328 | }
329 |
330 | private int selectedImagePosition(Image image) {
331 | for (int i = 0; i < selectedImages.size(); i++) {
332 | if (selectedImages.get(i).getPath().equals(image.getPath())) {
333 | return i;
334 | }
335 | }
336 |
337 | return -1;
338 | }
339 |
340 | public void reload()
341 | {
342 | abortLoading();
343 |
344 | showLoading();
345 |
346 | ImageLoaderRunnable runnable = new ImageLoaderRunnable();
347 | thread = new Thread(runnable);
348 | thread.start();
349 | }
350 |
351 | public String getRealPathFromURI(Uri contentUri) {
352 | String[] proj = { MediaStore.Images.Media.DATA };
353 | Cursor cursor = getActivity().managedQuery(contentUri, proj, null, null, null);
354 | int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
355 | cursor.moveToFirst();
356 | return cursor.getString(column_index);
357 | }
358 |
359 |
360 | public void setFolderAdapter() {
361 |
362 | imageAdapter.removeAllSelectedSingleClick();
363 |
364 | folderAdapter.setData(folders);
365 | setItemDecoration(folderColumns);
366 | recyclerView.setAdapter(folderAdapter);
367 |
368 | if (foldersState != null) {
369 | layoutManager.setSpanCount(folderColumns);
370 | recyclerView.getLayoutManager().onRestoreInstanceState(foldersState);
371 | }
372 | updateTitle2("dan");
373 | }
374 |
375 | @Override
376 | public void onConfigurationChanged(Configuration newConfig) {
377 | super.onConfigurationChanged(newConfig);
378 | orientationBasedUI(newConfig.orientation);
379 | }
380 | /**
381 | * Set item size, column size base on the screen orientation
382 | */
383 | private void orientationBasedUI(int orientation) {
384 | imageColumns = orientation == Configuration.ORIENTATION_PORTRAIT ? 3 : 5;
385 | folderColumns = orientation == Configuration.ORIENTATION_PORTRAIT ? 2 : 4;
386 |
387 | int columns = isDisplayingFolderView() ? folderColumns : imageColumns;
388 | layoutManager = new GridLayoutManager( getActivity(), columns);
389 | recyclerView.setLayoutManager(layoutManager);
390 | recyclerView.setHasFixedSize(true);
391 | setItemDecoration(columns);
392 | }
393 |
394 | /**
395 | * Set item decoration
396 | */
397 | private void setItemDecoration(int columns) {
398 | layoutManager.setSpanCount(columns);
399 | if (itemOffsetDecoration != null)
400 | recyclerView.removeItemDecoration(itemOffsetDecoration);
401 | itemOffsetDecoration = new GridSpacingItemDecoration(columns, getResources().getDimensionPixelSize(R.dimen.item_padding), false);
402 | recyclerView.addItemDecoration(itemOffsetDecoration);
403 | }
404 |
405 | public void captureImageWithPermission() {
406 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
407 | int rc = ActivityCompat.checkSelfPermission( getActivity(), Manifest.permission.CAMERA);
408 | if (rc == PackageManager.PERMISSION_GRANTED) {
409 | captureImage();
410 | } else {
411 | requestCameraPermission();
412 | }
413 | } else {
414 | captureImage();
415 | }
416 | }
417 |
418 | /**
419 | * Start camera intent
420 | * Create a temporary file and pass file Uri to camera intent
421 | */
422 | private void captureImage() {
423 |
424 |
425 | Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
426 | if (intent.resolveActivity( getActivity().getPackageManager()) != null) {
427 | File imageFile = ImageUtils.createImageFile(imageDirectory);
428 | if (imageFile != null) {
429 |
430 | if(!showVideo) {
431 | String authority = getActivity().getPackageName() + ".fileprovider";
432 | Uri uri = FileProvider.getUriForFile( getActivity(), authority, imageFile);
433 | currentImagePath = "file:" + imageFile.getAbsolutePath();
434 |
435 |
436 | File file = new File(imageFile.getAbsolutePath());
437 | String dirAsFile = file.getParent();
438 |
439 | File folder = new File(dirAsFile);
440 |
441 | boolean success = true;
442 | if (!folder.exists()) {
443 | success = folder.mkdir();
444 | }
445 |
446 | String imageFilePath = imageFile.getAbsolutePath();
447 | File imageFile2 = new File(imageFilePath);
448 | Uri imageFileUri = Uri.fromFile(imageFile2); // convert path to Uri
449 |
450 | Intent it = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
451 | it.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, imageFileUri);
452 | startActivityForResult(it, Constants.REQUEST_CODE_CAPTURE);
453 | //intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
454 | //startActivityForResult(intent, Constants.REQUEST_CODE_CAPTURE);
455 | }else
456 | {
457 | Intent takeVideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
458 | if (takeVideoIntent.resolveActivity( getActivity().getPackageManager()) != null) {
459 | startActivityForResult(takeVideoIntent, REQUEST_VIDEO_CAPTURE);
460 | }
461 | }
462 | } else {
463 | Toast.makeText( getActivity(), getString(R.string.error_create_image_file), Toast.LENGTH_LONG).show();
464 | }
465 | } else {
466 | Toast.makeText( getActivity(), getString(R.string.error_no_camera), Toast.LENGTH_LONG).show();
467 | }
468 | }
469 |
470 |
471 | /**
472 | * Init handler to handle loading data results
473 | */
474 | @Override
475 | public void onStart() {
476 | super.onStart();
477 |
478 | handler = new Handler() {
479 | @Override
480 | public void handleMessage(Message msg) {
481 | switch (msg.what) {
482 | case Constants.FETCH_STARTED: {
483 | showLoading();
484 | break;
485 | }
486 | case Constants.FETCH_COMPLETED: {
487 | ArrayList temps = new ArrayList<>();
488 | temps.addAll(selectedImages);
489 |
490 | ArrayList newImages = new ArrayList<>();
491 | newImages.addAll(images);
492 |
493 |
494 | if (folderMode) {
495 | setFolderAdapter();
496 | if (folders.size() != 0)
497 | hideLoading();
498 | else
499 | showEmpty();
500 |
501 | } else {
502 | setImageAdapter(newImages);
503 | if (images.size() != 0)
504 | hideLoading();
505 | else
506 | showEmpty();
507 | }
508 |
509 | break;
510 | }
511 | default: {
512 | super.handleMessage(msg);
513 | }
514 | }
515 | }
516 | };
517 | observer = new ContentObserver(handler) {
518 | @Override
519 | public void onChange(boolean selfChange) {
520 | getData();
521 | }
522 | };
523 | if(!showVideo) {
524 |
525 | getActivity().getContentResolver().registerContentObserver(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, false, observer);
526 | }else
527 | {
528 | getActivity().getContentResolver().registerContentObserver(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, false, observer);
529 | }
530 | }
531 |
532 | /**
533 | * Stop loading data task
534 | */
535 | private void abortLoading() {
536 | if (thread == null)
537 | return;
538 | if (thread.isAlive()) {
539 | thread.interrupt();
540 | try {
541 | thread.join();
542 | } catch (InterruptedException e) {
543 | e.printStackTrace();
544 | }
545 | }
546 | }
547 |
548 | /**
549 | * Check if displaying folders view
550 | */
551 | public boolean isDisplayingFolderView() {
552 | return (folderMode &&
553 | (recyclerView.getAdapter() == null || recyclerView.getAdapter() instanceof FolderPickerAdapter));
554 | }
555 |
556 | /**
557 | * Update activity title
558 | * If we're displaying folder, set folder title
559 | * If we're displaying images, show number of selected images
560 | */
561 |
562 |
563 |
564 | public void onBackPressed() {
565 | if (folderMode && !isDisplayingFolderView()) {
566 | setFolderAdapter();
567 | return;
568 | }
569 |
570 | getActivity().setResult(RESULT_CANCELED);
571 |
572 | }
573 |
574 |
575 | /**
576 | * Show progessbar when loading data
577 | */
578 | private void showLoading() {
579 | progressBar.setVisibility(View.VISIBLE);
580 | recyclerView.setVisibility(View.GONE);
581 | emptyTextView.setVisibility(View.GONE);
582 | }
583 |
584 | /**
585 | * Hide progressbar when data loaded
586 | */
587 | private void hideLoading() {
588 | progressBar.setVisibility(View.GONE);
589 | recyclerView.setVisibility(View.VISIBLE);
590 | emptyTextView.setVisibility(View.GONE);
591 | }
592 |
593 | /**
594 | * Show empty data
595 | */
596 | private void showEmpty() {
597 | progressBar.setVisibility(View.GONE);
598 | recyclerView.setVisibility(View.GONE);
599 | emptyTextView.setVisibility(View.VISIBLE);
600 | }
601 |
602 | @Override
603 | public void onDestroy() {
604 | super.onDestroy();
605 | abortLoading();
606 |
607 | getActivity().getContentResolver().unregisterContentObserver(observer);
608 |
609 | observer = null;
610 |
611 | if (handler != null) {
612 | handler.removeCallbacksAndMessages(null);
613 | handler = null;
614 | }
615 | }
616 |
617 | /**
618 | * Loading data task
619 | */
620 | private class ImageLoaderRunnable implements Runnable {
621 |
622 | private void Imagen()
623 | {
624 | Message message;
625 | if (recyclerView.getAdapter() == null) {
626 | /*
627 | If the adapter is null, this is first time this activity's view is
628 | being shown, hence send FETCH_STARTED message to show progress bar
629 | while images are loaded from phone
630 | */
631 | message = handler.obtainMessage();
632 | message.what = Constants.FETCH_STARTED;
633 | message.sendToTarget();
634 | }
635 |
636 | if (Thread.interrupted()) {
637 | return;
638 | }
639 |
640 | folders = new ArrayList<>();
641 |
642 |
643 | /*
644 | final String[] projectionPhotos2 = {
645 | MediaStore.Images.Media._ID,
646 | MediaStore.Images.Media.BUCKET_ID,
647 | MediaStore.Images.Media.BUCKET_DISPLAY_NAME,
648 | MediaStore.Images.Media.DATA,
649 | MediaStore.Images.Media.DATE_TAKEN,
650 | MediaStore.Images.Media.ORIENTATION,
651 | MediaStore.Images.Thumbnails.DATA
652 |
653 | };
654 | Cursor cursor2 = null;
655 | cursor2 = MediaStore.Images.Media.query(getContentResolver(), MediaStore.Images.Media.EXTERNAL_CONTENT_URI
656 | , projectionPhotos2, "", null, MediaStore.Images.Media.DATE_TAKEN + " DESC");*/
657 |
658 | final String[] projectionPhotos2 = {
659 | MediaStore.Images.Media._ID,
660 | MediaStore.Images.Media.BUCKET_ID,
661 | MediaStore.Images.Media.BUCKET_DISPLAY_NAME,
662 | MediaStore.Images.Media.DATA,
663 | MediaStore.Images.Media.DATE_TAKEN,
664 | MediaStore.Images.Media.ORIENTATION,
665 | MediaStore.Images.Thumbnails.DATA
666 |
667 | };
668 |
669 | GalleryPickerActivity pick = (GalleryPickerActivity)GalleryPickerActivity.c;
670 |
671 | Cursor cursor2 = null;
672 | cursor2 = MediaStore.Images.Media.query(pick.getContentResolver(), MediaStore.Images.Media.EXTERNAL_CONTENT_URI
673 | , projectionPhotos2, "", null, MediaStore.Images.Media.DATE_TAKEN + " DESC");
674 |
675 |
676 | File file2;
677 | ArrayList temp2 = new ArrayList<>(cursor2.getCount());
678 |
679 | if (cursor2 == null) {
680 | message = handler.obtainMessage();
681 | message.what = Constants.ERROR;
682 | message.sendToTarget();
683 | return;
684 | }
685 |
686 |
687 | if (cursor2 != null) {
688 |
689 | int bucketNameColumn = cursor2.getColumnIndex(MediaStore.Images.Media.BUCKET_DISPLAY_NAME);
690 | final int bucketIdColumn = cursor2.getColumnIndex(MediaStore.Images.Media.BUCKET_ID);
691 | while (cursor2.moveToNext()) {
692 |
693 | if (Thread.interrupted()) {
694 | return;
695 | }
696 |
697 | int bucketId = cursor2.getInt(bucketIdColumn);
698 | String bucketName = cursor2.getString(bucketNameColumn);
699 | final int dataColumn = cursor2.getColumnIndex(MediaStore.Images.Media.DATA);
700 | final int imageIdColumn = cursor2.getColumnIndex(MediaStore.Images.Media._ID);
701 | //int thumbImageColumn = cursor.getColumnIndex(MediaStore.Images.Thumbnails.DATA);
702 | final int imageId = cursor2.getInt(imageIdColumn);
703 | final String path = cursor2.getString(dataColumn);
704 |
705 |
706 |
707 | file2 = new File(path);
708 | if (file2.exists()) {
709 |
710 | String filename = path.substring(path.lastIndexOf("/")+1);
711 |
712 | Image image = new Image(imageId, filename, path, false);
713 | temp2.add(image);
714 |
715 | if (folderMode) {
716 | Folder folder = getFolder(bucketName);
717 | if (folder == null) {
718 | folder = new Folder(bucketName);
719 | folders.add(folder);
720 | }
721 |
722 | folder.getImages().add(image);
723 | }
724 | }
725 | }
726 | }
727 |
728 | cursor2.close();
729 |
730 |
731 | /*Cursor cursor = getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, projection,
732 | null, null, MediaStore.Images.Media.DATE_ADDED);
733 |
734 | if (cursor == null) {
735 | message = handler.obtainMessage();
736 | message.what = Constants.ERROR;
737 | message.sendToTarget();
738 | return;
739 | }
740 |
741 | ArrayList temp = new ArrayList<>(cursor.getCount());
742 | File file;
743 |
744 |
745 | if (cursor.moveToLast()) {
746 | do {
747 | if (Thread.interrupted()) {
748 | return;
749 | }
750 |
751 | long id = cursor.getLong(cursor.getColumnIndex(projection[0]));
752 | String name = cursor.getString(cursor.getColumnIndex(projection[1]));
753 | String path = cursor.getString(cursor.getColumnIndex(projection[2]));
754 | String bucket = cursor.getString(cursor.getColumnIndex(projection[3]));
755 |
756 | file = new File(path);
757 | if (file.exists()) {
758 | Image image = new Image(id, name, path, false);
759 | temp.add(image);
760 |
761 | if (folderMode) {
762 | Folder folder = getFolder(bucket);
763 | if (folder == null) {
764 | folder = new Folder(bucket);
765 | folders.add(folder);
766 | }
767 |
768 | folder.getImages().add(image);
769 | }
770 | }
771 |
772 | } while (cursor.moveToPrevious());
773 | }
774 | cursor.close();
775 | */
776 |
777 |
778 | if (images == null) {
779 | images = new ArrayList<>();
780 | }
781 | images.clear();
782 | images.addAll(temp2);
783 |
784 | if (handler != null) {
785 | message = handler.obtainMessage();
786 | message.what = Constants.FETCH_COMPLETED;
787 | message.sendToTarget();
788 | }
789 |
790 | Thread.interrupted();
791 | }
792 |
793 | private void Video()
794 | {
795 | Message message;
796 | if (recyclerView.getAdapter() == null) {
797 | /*
798 | If the adapter is null, this is first time this activity's view is
799 | being shown, hence send FETCH_STARTED message to show progress bar
800 | while images are loaded from phone
801 | */
802 | message = handler.obtainMessage();
803 | message.what = Constants.FETCH_STARTED;
804 | message.sendToTarget();
805 | }
806 |
807 | if (Thread.interrupted()) {
808 | return;
809 | }
810 |
811 | folders = new ArrayList<>();
812 |
813 |
814 | /*
815 | final String[] projectionPhotos2 = {
816 | MediaStore.Images.Media._ID,
817 | MediaStore.Images.Media.BUCKET_ID,
818 | MediaStore.Images.Media.BUCKET_DISPLAY_NAME,
819 | MediaStore.Images.Media.DATA,
820 | MediaStore.Images.Media.DATE_TAKEN,
821 | MediaStore.Images.Media.ORIENTATION,
822 | MediaStore.Images.Thumbnails.DATA
823 |
824 | };
825 | Cursor cursor2 = null;
826 | cursor2 = MediaStore.Images.Media.query(getContentResolver(), MediaStore.Images.Media.EXTERNAL_CONTENT_URI
827 | , projectionPhotos2, "", null, MediaStore.Images.Media.DATE_TAKEN + " DESC");*/
828 |
829 | final String[] projectionPhotos2 = {
830 | MediaStore.Video.Media._ID,
831 | MediaStore.Video.Media.BUCKET_ID,
832 | MediaStore.Video.Media.BUCKET_DISPLAY_NAME,
833 | MediaStore.Video.Media.DATA,
834 | MediaStore.Video.Media.DATE_TAKEN,
835 | //MediaStore.Video.Media.ORIENTATION,
836 | MediaStore.Video.Thumbnails.DATA
837 |
838 | };
839 |
840 | GalleryPickerActivity pick = (GalleryPickerActivity)GalleryPickerActivity.c;
841 |
842 | Cursor cursor2 = null;
843 | cursor2 = MediaStore.Images.Media.query(pick.getContentResolver(), MediaStore.Video.Media.EXTERNAL_CONTENT_URI
844 | , projectionPhotos2, "", null, MediaStore.Images.Media.DATE_TAKEN + " DESC");
845 |
846 |
847 | File file2;
848 | ArrayList temp2 = new ArrayList<>(cursor2.getCount());
849 |
850 | if (cursor2 == null) {
851 | message = handler.obtainMessage();
852 | message.what = Constants.ERROR;
853 | message.sendToTarget();
854 | return;
855 | }
856 |
857 |
858 | if (cursor2 != null) {
859 |
860 | int bucketNameColumn = cursor2.getColumnIndex(MediaStore.Video.Media.BUCKET_DISPLAY_NAME);
861 | final int bucketIdColumn = cursor2.getColumnIndex(MediaStore.Video.Media.BUCKET_ID);
862 | while (cursor2.moveToNext()) {
863 |
864 | if (Thread.interrupted()) {
865 | return;
866 | }
867 |
868 | int bucketId = cursor2.getInt(bucketIdColumn);
869 | String bucketName = cursor2.getString(bucketNameColumn);
870 | final int dataColumn = cursor2.getColumnIndex(MediaStore.Video.Media.DATA);
871 | final int imageIdColumn = cursor2.getColumnIndex(MediaStore.Video.Media._ID);
872 | //int thumbImageColumn = cursor.getColumnIndex(MediaStore.Images.Thumbnails.DATA);
873 | final int imageId = cursor2.getInt(imageIdColumn);
874 | final String path = cursor2.getString(dataColumn);
875 |
876 |
877 |
878 | file2 = new File(path);
879 | if (file2.exists()) {
880 |
881 | String filename = path.substring(path.lastIndexOf("/")+1);
882 |
883 | Image image = new Image(imageId, filename, path, false);
884 | temp2.add(image);
885 |
886 | if (folderMode) {
887 | Folder folder = getFolder(bucketName);
888 | if (folder == null) {
889 | folder = new Folder(bucketName);
890 | folders.add(folder);
891 | }
892 |
893 | folder.getImages().add(image);
894 | }
895 | }
896 | }
897 | }
898 |
899 | cursor2.close();
900 |
901 |
902 | /*Cursor cursor = getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, projection,
903 | null, null, MediaStore.Images.Media.DATE_ADDED);
904 |
905 | if (cursor == null) {
906 | message = handler.obtainMessage();
907 | message.what = Constants.ERROR;
908 | message.sendToTarget();
909 | return;
910 | }
911 |
912 | ArrayList temp = new ArrayList<>(cursor.getCount());
913 | File file;
914 |
915 |
916 | if (cursor.moveToLast()) {
917 | do {
918 | if (Thread.interrupted()) {
919 | return;
920 | }
921 |
922 | long id = cursor.getLong(cursor.getColumnIndex(projection[0]));
923 | String name = cursor.getString(cursor.getColumnIndex(projection[1]));
924 | String path = cursor.getString(cursor.getColumnIndex(projection[2]));
925 | String bucket = cursor.getString(cursor.getColumnIndex(projection[3]));
926 |
927 | file = new File(path);
928 | if (file.exists()) {
929 | Image image = new Image(id, name, path, false);
930 | temp.add(image);
931 |
932 | if (folderMode) {
933 | Folder folder = getFolder(bucket);
934 | if (folder == null) {
935 | folder = new Folder(bucket);
936 | folders.add(folder);
937 | }
938 |
939 | folder.getImages().add(image);
940 | }
941 | }
942 |
943 | } while (cursor.moveToPrevious());
944 | }
945 | cursor.close();
946 | */
947 |
948 |
949 | if (images == null) {
950 | images = new ArrayList<>();
951 | }
952 | images.clear();
953 | images.addAll(temp2);
954 |
955 | if (handler != null) {
956 | message = handler.obtainMessage();
957 | message.what = Constants.FETCH_COMPLETED;
958 | message.sendToTarget();
959 | }
960 |
961 | Thread.interrupted();
962 | }
963 |
964 | @Override
965 | public void run() {
966 | android.os.Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
967 |
968 | if(!showVideo) {
969 | Imagen();
970 | }else
971 | {
972 | Video();
973 | }
974 |
975 | }
976 | }
977 |
978 | /**
979 | * Return folder base on folder name
980 | */
981 | public Folder getFolder(String name) {
982 | for (Folder folder : folders) {
983 | if (folder.getFolderName().equals(name)) {
984 | return folder;
985 | }
986 | }
987 | return null;
988 | }
989 |
990 | @Override
991 | public void onActivityResult(int requestCode, int resultCode, Intent data) {
992 | super.onActivityResult(requestCode, resultCode, data);
993 |
994 | if (requestCode == REQUEST_VIDEO_CAPTURE && resultCode == RESULT_OK) {
995 | final Uri videoUri = data.getData();
996 |
997 | MediaScannerConnection.scanFile(GalleryPickerActivity.c,
998 | new String[]{videoUri.getPath()}, null,
999 | new MediaScannerConnection.OnScanCompletedListener() {
1000 | @Override
1001 | public void onScanCompleted(String path, Uri uri) {
1002 |
1003 | //getDataWithPermission();
1004 |
1005 | path = getRealPathFromURI(videoUri);
1006 |
1007 |
1008 | String filename = path.substring(path.lastIndexOf("/")+1);
1009 |
1010 | Image imagenCamara = new Image(-1999,filename,path,true);
1011 |
1012 |
1013 | selectedImages.add(imagenCamara);
1014 |
1015 | Intent data = new Intent();
1016 | data.putParcelableArrayListExtra(GalleryPickerActivity.INTENT_EXTRA_SELECTED_IMAGES, selectedImages);
1017 |
1018 | GalleryPickerActivity act = (GalleryPickerActivity)GalleryPickerActivity.c;
1019 |
1020 | act.setResult(RESULT_OK, data);
1021 | act.finish();
1022 |
1023 | }
1024 | });
1025 |
1026 | }
1027 |
1028 | if (requestCode == Constants.REQUEST_CODE_CAPTURE) {
1029 | if (resultCode == RESULT_OK && currentImagePath != null) {
1030 | Uri imageUri = Uri.parse(currentImagePath);
1031 | if (imageUri != null) {
1032 | MediaScannerConnection.scanFile(GalleryPickerActivity.c,
1033 | new String[]{imageUri.getPath()}, null,
1034 | new MediaScannerConnection.OnScanCompletedListener() {
1035 | @Override
1036 | public void onScanCompleted(String path, Uri uri) {
1037 |
1038 | //getDataWithPermission();
1039 |
1040 |
1041 | String filename = path.substring(path.lastIndexOf("/")+1);
1042 |
1043 | Image imagenCamara = new Image(-1999,filename,path,true);
1044 |
1045 |
1046 | selectedImages.add(imagenCamara);
1047 |
1048 | Intent data = new Intent();
1049 | data.putParcelableArrayListExtra(GalleryPickerActivity.INTENT_EXTRA_SELECTED_IMAGES, selectedImages);
1050 |
1051 | GalleryPickerActivity act = (GalleryPickerActivity)GalleryPickerActivity.c;
1052 |
1053 | act.setResult(RESULT_OK, data);
1054 | act.finish();
1055 | }
1056 | });
1057 | }
1058 | }
1059 | }
1060 | }
1061 |
1062 |
1063 | @Override
1064 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
1065 | Bundle savedInstanceState) {
1066 | // Inflate the layout for this fragment
1067 |
1068 | View view = inflater.inflate(R.layout.fragment_container, container, false);
1069 | this.mView = view;
1070 |
1071 |
1072 |
1073 | mainLayout = (RelativeLayout) mView.findViewById(R.id.mainFragment);
1074 | progressBar = (ProgressWheel) mView.findViewById(R.id.progress_bar);
1075 | emptyTextView = (TextView) mView.findViewById(R.id.tv_empty_images);
1076 | recyclerView = (RecyclerView) mView.findViewById(R.id.recyclerView);
1077 |
1078 |
1079 |
1080 | /** Init folder and image adapter */
1081 | imageAdapter = new ImagePickerAdapter(GalleryPickerActivity.c, images, selectedImages, this);
1082 | folderAdapter = new FolderPickerAdapter(GalleryPickerActivity.c, new OnFolderClickListener() {
1083 | @Override
1084 | public void onFolderClick(Folder bucket) {
1085 | foldersState = recyclerView.getLayoutManager().onSaveInstanceState();
1086 | setImageAdapter(bucket.getImages());
1087 | }
1088 | });
1089 |
1090 | orientationBasedUI(getResources().getConfiguration().orientation);
1091 |
1092 | imageAdapter.removeAllSelectedSingleClick();
1093 |
1094 |
1095 |
1096 | return view;
1097 |
1098 | }
1099 |
1100 | // TODO: Rename method, update argument and hook method into UI event
1101 | public void onButtonPressed(Uri uri) {
1102 | if (mListener != null) {
1103 | mListener.onFragmentInteraction(uri);
1104 | }
1105 | }
1106 |
1107 | @Override
1108 | public void onAttach(Context context) {
1109 | super.onAttach(context);
1110 | if (context instanceof OnFragmentInteractionListener) {
1111 | mListener = (OnFragmentInteractionListener) context;
1112 | } else {
1113 | throw new RuntimeException(context.toString()
1114 | + " must implement OnFragmentInteractionListener");
1115 | }
1116 | }
1117 |
1118 | @Override
1119 | public void onDetach() {
1120 | super.onDetach();
1121 | mListener = null;
1122 | }
1123 |
1124 |
1125 | public interface OnFragmentInteractionListener {
1126 | void onFragmentInteraction(Uri uri);
1127 | }
1128 | }
1129 |
1130 |
--------------------------------------------------------------------------------