├── sample
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── mipmap-hdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── styles.xml
│ │ │ │ ├── dimens.xml
│ │ │ │ └── colors.xml
│ │ │ ├── menu
│ │ │ │ └── menu_main.xml
│ │ │ ├── values-w820dp
│ │ │ │ └── dimens.xml
│ │ │ └── layout
│ │ │ │ └── activity_main.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── com
│ │ │ └── darsh
│ │ │ └── example
│ │ │ └── sample
│ │ │ └── MainActivity.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── darsh
│ │ └── example
│ │ └── sample
│ │ └── ApplicationTest.java
├── proguard-rules.pro
├── build.gradle
└── sample.iml
├── multipleimageselect
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── mipmap-hdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── drawable-hdpi
│ │ │ │ ├── ic_arrow_back.png
│ │ │ │ └── ic_done_white.png
│ │ │ ├── drawable-mdpi
│ │ │ │ ├── ic_arrow_back.png
│ │ │ │ └── ic_done_white.png
│ │ │ ├── drawable-xhdpi
│ │ │ │ ├── ic_arrow_back.png
│ │ │ │ └── ic_done_white.png
│ │ │ ├── drawable-xxhdpi
│ │ │ │ ├── ic_arrow_back.png
│ │ │ │ └── ic_done_white.png
│ │ │ ├── drawable
│ │ │ │ └── image_placeholder.xml
│ │ │ ├── values
│ │ │ │ ├── dimens.xml
│ │ │ │ ├── strings.xml
│ │ │ │ ├── colors.xml
│ │ │ │ └── styles.xml
│ │ │ ├── values-w820dp
│ │ │ │ └── dimens.xml
│ │ │ ├── menu
│ │ │ │ └── menu_contextual_action_bar.xml
│ │ │ ├── layout
│ │ │ │ ├── toolbar.xml
│ │ │ │ ├── grid_view_item_image_select.xml
│ │ │ │ ├── grid_view_item_album_select.xml
│ │ │ │ ├── activity_album_select.xml
│ │ │ │ └── activity_image_select.xml
│ │ │ ├── values-de
│ │ │ │ └── strings.xml
│ │ │ ├── values-ru
│ │ │ │ └── strings.xml
│ │ │ └── values-fr
│ │ │ │ └── strings.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── darsh
│ │ │ │ └── multipleimageselect
│ │ │ │ ├── models
│ │ │ │ ├── Album.java
│ │ │ │ └── Image.java
│ │ │ │ ├── helpers
│ │ │ │ └── Constants.java
│ │ │ │ ├── adapters
│ │ │ │ ├── CustomGenericAdapter.java
│ │ │ │ ├── CustomAlbumSelectAdapter.java
│ │ │ │ └── CustomImageSelectAdapter.java
│ │ │ │ └── activities
│ │ │ │ ├── HelperActivity.java
│ │ │ │ ├── AlbumSelectActivity.java
│ │ │ │ └── ImageSelectActivity.java
│ │ └── AndroidManifest.xml
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── darsh
│ │ └── multipleimageselect
│ │ └── ApplicationTest.java
├── proguard-rules.pro
├── build.gradle
└── multipleimageselect.iml
├── settings.gradle
├── screenshots
├── mis.gif
├── mis1.png
├── mis2.png
├── mis3.png
├── mis4.png
├── mis5.png
├── mis6.png
├── mis7.png
├── misCC.gif
└── misCT.gif
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitignore
├── .gitattributes
├── gradle.properties
├── MultipleImageSelect.iml
├── gradlew.bat
├── gradlew
├── README.md
└── LICENSE.txt
/sample/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/multipleimageselect/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':multipleimageselect', ':sample'
2 |
--------------------------------------------------------------------------------
/screenshots/mis.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darsh2/MultipleImageSelect/HEAD/screenshots/mis.gif
--------------------------------------------------------------------------------
/screenshots/mis1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darsh2/MultipleImageSelect/HEAD/screenshots/mis1.png
--------------------------------------------------------------------------------
/screenshots/mis2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darsh2/MultipleImageSelect/HEAD/screenshots/mis2.png
--------------------------------------------------------------------------------
/screenshots/mis3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darsh2/MultipleImageSelect/HEAD/screenshots/mis3.png
--------------------------------------------------------------------------------
/screenshots/mis4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darsh2/MultipleImageSelect/HEAD/screenshots/mis4.png
--------------------------------------------------------------------------------
/screenshots/mis5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darsh2/MultipleImageSelect/HEAD/screenshots/mis5.png
--------------------------------------------------------------------------------
/screenshots/mis6.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darsh2/MultipleImageSelect/HEAD/screenshots/mis6.png
--------------------------------------------------------------------------------
/screenshots/mis7.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darsh2/MultipleImageSelect/HEAD/screenshots/mis7.png
--------------------------------------------------------------------------------
/screenshots/misCC.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darsh2/MultipleImageSelect/HEAD/screenshots/misCC.gif
--------------------------------------------------------------------------------
/screenshots/misCT.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darsh2/MultipleImageSelect/HEAD/screenshots/misCT.gif
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darsh2/MultipleImageSelect/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .gradle
2 | /local.properties
3 | /.idea
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 |
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darsh2/MultipleImageSelect/HEAD/sample/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darsh2/MultipleImageSelect/HEAD/sample/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darsh2/MultipleImageSelect/HEAD/sample/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darsh2/MultipleImageSelect/HEAD/sample/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/multipleimageselect/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darsh2/MultipleImageSelect/HEAD/multipleimageselect/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/multipleimageselect/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darsh2/MultipleImageSelect/HEAD/multipleimageselect/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/multipleimageselect/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darsh2/MultipleImageSelect/HEAD/multipleimageselect/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/multipleimageselect/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darsh2/MultipleImageSelect/HEAD/multipleimageselect/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/multipleimageselect/src/main/res/drawable-hdpi/ic_arrow_back.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darsh2/MultipleImageSelect/HEAD/multipleimageselect/src/main/res/drawable-hdpi/ic_arrow_back.png
--------------------------------------------------------------------------------
/multipleimageselect/src/main/res/drawable-hdpi/ic_done_white.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darsh2/MultipleImageSelect/HEAD/multipleimageselect/src/main/res/drawable-hdpi/ic_done_white.png
--------------------------------------------------------------------------------
/multipleimageselect/src/main/res/drawable-mdpi/ic_arrow_back.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darsh2/MultipleImageSelect/HEAD/multipleimageselect/src/main/res/drawable-mdpi/ic_arrow_back.png
--------------------------------------------------------------------------------
/multipleimageselect/src/main/res/drawable-mdpi/ic_done_white.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darsh2/MultipleImageSelect/HEAD/multipleimageselect/src/main/res/drawable-mdpi/ic_done_white.png
--------------------------------------------------------------------------------
/multipleimageselect/src/main/res/drawable-xhdpi/ic_arrow_back.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darsh2/MultipleImageSelect/HEAD/multipleimageselect/src/main/res/drawable-xhdpi/ic_arrow_back.png
--------------------------------------------------------------------------------
/multipleimageselect/src/main/res/drawable-xhdpi/ic_done_white.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darsh2/MultipleImageSelect/HEAD/multipleimageselect/src/main/res/drawable-xhdpi/ic_done_white.png
--------------------------------------------------------------------------------
/multipleimageselect/src/main/res/drawable-xxhdpi/ic_arrow_back.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darsh2/MultipleImageSelect/HEAD/multipleimageselect/src/main/res/drawable-xxhdpi/ic_arrow_back.png
--------------------------------------------------------------------------------
/multipleimageselect/src/main/res/drawable-xxhdpi/ic_done_white.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/darsh2/MultipleImageSelect/HEAD/multipleimageselect/src/main/res/drawable-xxhdpi/ic_done_white.png
--------------------------------------------------------------------------------
/sample/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | sample
3 |
4 | Hello world!
5 | Settings
6 |
7 |
8 |
--------------------------------------------------------------------------------
/sample/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 |
--------------------------------------------------------------------------------
/multipleimageselect/src/main/res/drawable/image_placeholder.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
--------------------------------------------------------------------------------
/sample/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/multipleimageselect/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Fri Apr 08 15:04:30 IST 2016
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.10-all.zip
7 |
--------------------------------------------------------------------------------
/multipleimageselect/src/main/java/com/darsh/multipleimageselect/models/Album.java:
--------------------------------------------------------------------------------
1 | package com.darsh.multipleimageselect.models;
2 |
3 | /**
4 | * Created by Darshan on 4/14/2015.
5 | */
6 | public class Album {
7 | public String name;
8 | public String cover;
9 |
10 | public Album(String name, String cover) {
11 | this.name = name;
12 | this.cover = cover;
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/sample/src/main/res/menu/menu_main.xml:
--------------------------------------------------------------------------------
1 |
7 |
--------------------------------------------------------------------------------
/sample/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/multipleimageselect/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/multipleimageselect/src/main/res/menu/menu_contextual_action_bar.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/multipleimageselect/src/main/res/layout/toolbar.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
--------------------------------------------------------------------------------
/sample/src/androidTest/java/com/darsh/example/sample/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.darsh.example.sample;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/multipleimageselect/src/androidTest/java/com/darsh/multipleimageselect/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.darsh.multipleimageselect;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
4 | # Custom for Visual Studio
5 | *.cs diff=csharp
6 | *.sln merge=union
7 | *.csproj merge=union
8 | *.vbproj merge=union
9 | *.fsproj merge=union
10 | *.dbproj merge=union
11 |
12 | # Standard to msysgit
13 | *.doc diff=astextplain
14 | *.DOC diff=astextplain
15 | *.docx diff=astextplain
16 | *.DOCX diff=astextplain
17 | *.dot diff=astextplain
18 | *.DOT diff=astextplain
19 | *.pdf diff=astextplain
20 | *.PDF diff=astextplain
21 | *.rtf diff=astextplain
22 | *.RTF diff=astextplain
23 |
--------------------------------------------------------------------------------
/sample/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in E:\Android\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 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/multipleimageselect/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in E:\Android\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 |
--------------------------------------------------------------------------------
/multipleimageselect/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 24
5 | buildToolsVersion "24.0.1"
6 |
7 | defaultConfig {
8 | minSdkVersion 11
9 | targetSdkVersion 24
10 | versionCode 1
11 | versionName "1.0.0"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | }
20 |
21 | dependencies {
22 | compile fileTree(dir: 'libs', include: ['*.jar'])
23 | compile 'com.android.support:appcompat-v7:24.2.1'
24 | compile 'com.android.support:design:24.2.1'
25 | compile 'com.github.bumptech.glide:glide:3.6.0'
26 | }
27 |
--------------------------------------------------------------------------------
/sample/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 24
5 | buildToolsVersion "24.0.1"
6 |
7 | defaultConfig {
8 | applicationId "com.darsh.example.sample"
9 | minSdkVersion 11
10 | targetSdkVersion 24
11 | versionCode 1
12 | versionName "1.0"
13 | multiDexEnabled true
14 | }
15 | buildTypes {
16 | release {
17 | minifyEnabled false
18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
19 | }
20 | }
21 | }
22 |
23 | dependencies {
24 | compile fileTree(dir: 'libs', include: ['*.jar'])
25 | compile 'com.android.support:appcompat-v7:24.2.1'
26 | compile project(':multipleimageselect')
27 | }
28 |
--------------------------------------------------------------------------------
/sample/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #673AB7
4 | #512DA8
5 | #D1C4E9
6 | #536DFE
7 |
8 | #212121
9 | #727272
10 | #B6B6B6
11 |
12 | #FFFFFF
13 |
14 | #99FFFFFF
15 | #000000
16 |
--------------------------------------------------------------------------------
/multipleimageselect/src/main/res/values-de/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | Multiple Image Select
4 |
5 | Fotoalbum auswählen
6 | Tippen um Bilder auszuwählen
7 |
8 | HINZUFÜGEN
9 | ausgewählt
10 | Kann maximal %d Bilder auswählen
11 |
12 | Zugriff verweigert!
13 | Zugriff auf Fotos, Medien und Dateien auf dem Gerät erlauben, um die Alben anzuzeigen
14 | Zugriff auf Fotos, Medien und Dateien auf dem Gerät erlauben, um die Bilder anzuzeigen
15 |
--------------------------------------------------------------------------------
/multipleimageselect/src/main/res/values-ru/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | Multiple Image Select
4 |
5 | Выберите фотоальбом
6 | Кликните на изображение для выбора
7 |
8 | Добавить
9 | Выбрано
10 | Можно выбрать максимум %d изображений
11 |
12 | Отсутствует разрешение!
13 | Разрешите доступ к фотографиям, медиа и файлам на своём устройстве для просмотра альбомов
14 | Разрешите доступ к фотографиям, медиа и файлам на своём устройстве для просмотра изображений
15 |
--------------------------------------------------------------------------------
/multipleimageselect/src/main/res/layout/grid_view_item_image_select.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
15 |
16 |
21 |
--------------------------------------------------------------------------------
/multipleimageselect/src/main/res/values-fr/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | Multiple Image Select
4 |
5 | Sélectionnez un album photo
6 | Appuyez pour sélectionner des images
7 |
8 | Rajouter
9 | sélectionné
10 | Impossible de sélectionner plus que %d images
11 |
12 | Permission refusée!
13 | Veuillez permettre l\'accès aux photos, médias et fichiers sur votre appareil pour afficher les albums
14 | Veuillez permettre l\'accès aux photos, médias et fichiers sur votre appareil pour afficher les images
15 |
--------------------------------------------------------------------------------
/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 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/multipleimageselect/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Select photo album
3 | Tap to select images
4 |
5 | ADD
6 | selected
7 | Can select a maximum of %d images
8 |
9 | Oops, something went wrong!
10 |
11 |
12 | App requires permission to Storage to view images.
13 | App requires permission to Storage to view images. Tap Settings and go to Permissions to grant permission.
14 | OK
15 | Settings
16 | package
17 |
18 |
19 |
--------------------------------------------------------------------------------
/multipleimageselect/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #2E7D32
4 | #1B5E20
5 | #C8E6C9
6 | #4CAF50
7 |
8 | #212121
9 | #727272
10 | #B6B6B6
11 |
12 | #FFFFFF
13 |
14 | #99FFFFFF
15 | #000000
16 |
17 | #FFFFFF
18 |
19 |
--------------------------------------------------------------------------------
/multipleimageselect/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
14 |
15 |
18 |
19 |
--------------------------------------------------------------------------------
/MultipleImageSelect.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/sample/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
9 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/multipleimageselect/src/main/res/layout/grid_view_item_album_select.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
15 |
16 |
26 |
27 |
--------------------------------------------------------------------------------
/multipleimageselect/src/main/java/com/darsh/multipleimageselect/helpers/Constants.java:
--------------------------------------------------------------------------------
1 | package com.darsh.multipleimageselect.helpers;
2 |
3 | /**
4 | * Created by Darshan on 5/26/2015.
5 | */
6 | public class Constants {
7 | public static final int PERMISSION_REQUEST_CODE = 1000;
8 | public static final int PERMISSION_GRANTED = 1001;
9 | public static final int PERMISSION_DENIED = 1002;
10 |
11 | public static final int REQUEST_CODE = 2000;
12 |
13 | public static final int FETCH_STARTED = 2001;
14 | public static final int FETCH_COMPLETED = 2002;
15 | public static final int ERROR = 2005;
16 |
17 | /**
18 | * Request code for permission has to be < (1 << 8)
19 | * Otherwise throws java.lang.IllegalArgumentException: Can only use lower 8 bits for requestCode
20 | */
21 | public static final int PERMISSION_REQUEST_READ_EXTERNAL_STORAGE = 23;
22 |
23 | public static final String INTENT_EXTRA_ALBUM = "album";
24 | public static final String INTENT_EXTRA_IMAGES = "images";
25 | public static final String INTENT_EXTRA_LIMIT = "limit";
26 | public static final int DEFAULT_LIMIT = 10;
27 |
28 | //Maximum number of images that can be selected at a time
29 | public static int limit;
30 | }
31 |
--------------------------------------------------------------------------------
/multipleimageselect/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
10 |
15 |
16 |
17 |
18 |
19 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/multipleimageselect/src/main/java/com/darsh/multipleimageselect/adapters/CustomGenericAdapter.java:
--------------------------------------------------------------------------------
1 | package com.darsh.multipleimageselect.adapters;
2 |
3 | import android.content.Context;
4 | import android.view.LayoutInflater;
5 | import android.widget.BaseAdapter;
6 |
7 | import java.util.ArrayList;
8 |
9 | /**
10 | * Created by Darshan on 4/24/2015.
11 | */
12 | public abstract class CustomGenericAdapter extends BaseAdapter {
13 | protected ArrayList arrayList;
14 | protected Context context;
15 | protected LayoutInflater layoutInflater;
16 |
17 | protected int size;
18 |
19 | public CustomGenericAdapter(Context context, ArrayList arrayList) {
20 | this.arrayList = arrayList;
21 | this.context = context;
22 | this.layoutInflater = LayoutInflater.from(this.context);
23 | }
24 |
25 | @Override
26 | public int getCount() {
27 | return arrayList.size();
28 | }
29 |
30 | public T getItem(int position) {
31 | return arrayList.get(position);
32 | }
33 |
34 | @Override
35 | public long getItemId(int position) {
36 | return position;
37 | }
38 |
39 | public void setLayoutParams(int size) {
40 | this.size = size;
41 | }
42 |
43 | public void releaseResources() {
44 | arrayList = null;
45 | context = null;
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/multipleimageselect/src/main/res/layout/activity_album_select.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
12 |
13 |
18 |
19 |
25 |
26 |
36 |
--------------------------------------------------------------------------------
/multipleimageselect/src/main/res/layout/activity_image_select.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
12 |
13 |
18 |
19 |
25 |
26 |
36 |
--------------------------------------------------------------------------------
/multipleimageselect/src/main/java/com/darsh/multipleimageselect/models/Image.java:
--------------------------------------------------------------------------------
1 | package com.darsh.multipleimageselect.models;
2 |
3 | import android.os.Parcel;
4 | import android.os.Parcelable;
5 |
6 | /**
7 | * Created by Darshan on 4/18/2015.
8 | */
9 | public class Image implements Parcelable {
10 | public long id;
11 | public String name;
12 | public String path;
13 | public boolean isSelected;
14 |
15 | public Image(long id, String name, String path, boolean isSelected) {
16 | this.id = id;
17 | this.name = name;
18 | this.path = path;
19 | this.isSelected = isSelected;
20 | }
21 |
22 | @Override
23 | public int describeContents() {
24 | return 0;
25 | }
26 |
27 | @Override
28 | public void writeToParcel(Parcel dest, int flags) {
29 | dest.writeLong(id);
30 | dest.writeString(name);
31 | dest.writeString(path);
32 | }
33 |
34 | public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
35 | @Override
36 | public Image createFromParcel(Parcel source) {
37 | return new Image(source);
38 | }
39 |
40 | @Override
41 | public Image[] newArray(int size) {
42 | return new Image[size];
43 | }
44 | };
45 |
46 | private Image(Parcel in) {
47 | id = in.readLong();
48 | name = in.readString();
49 | path = in.readString();
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/multipleimageselect/src/main/java/com/darsh/multipleimageselect/adapters/CustomAlbumSelectAdapter.java:
--------------------------------------------------------------------------------
1 | package com.darsh.multipleimageselect.adapters;
2 |
3 | import android.content.Context;
4 | import android.view.View;
5 | import android.view.ViewGroup;
6 | import android.widget.ImageView;
7 | import android.widget.TextView;
8 |
9 | import com.bumptech.glide.Glide;
10 | import com.darsh.multipleimageselect.R;
11 | import com.darsh.multipleimageselect.models.Album;
12 |
13 | import java.util.ArrayList;
14 |
15 | /**
16 | * Created by Darshan on 4/14/2015.
17 | */
18 | public class CustomAlbumSelectAdapter extends CustomGenericAdapter {
19 | public CustomAlbumSelectAdapter(Context context, ArrayList albums) {
20 | super(context, albums);
21 | }
22 |
23 | @Override
24 | public View getView(int position, View convertView, ViewGroup parent) {
25 | ViewHolder viewHolder;
26 |
27 | if (convertView == null) {
28 | convertView = layoutInflater.inflate(R.layout.grid_view_item_album_select, null);
29 |
30 | viewHolder = new ViewHolder();
31 | viewHolder.imageView = (ImageView) convertView.findViewById(R.id.image_view_album_image);
32 | viewHolder.textView = (TextView) convertView.findViewById(R.id.text_view_album_name);
33 |
34 | convertView.setTag(viewHolder);
35 |
36 | } else {
37 | viewHolder = (ViewHolder) convertView.getTag();
38 | }
39 |
40 | viewHolder.imageView.getLayoutParams().width = size;
41 | viewHolder.imageView.getLayoutParams().height = size;
42 |
43 | viewHolder.textView.setText(arrayList.get(position).name);
44 | Glide.with(context)
45 | .load(arrayList.get(position).cover)
46 | .placeholder(R.drawable.image_placeholder).centerCrop().into(viewHolder.imageView);
47 |
48 | return convertView;
49 | }
50 |
51 | private static class ViewHolder {
52 | public ImageView imageView;
53 | public TextView textView;
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/multipleimageselect/src/main/java/com/darsh/multipleimageselect/adapters/CustomImageSelectAdapter.java:
--------------------------------------------------------------------------------
1 | package com.darsh.multipleimageselect.adapters;
2 |
3 | import android.content.Context;
4 | import android.view.View;
5 | import android.view.ViewGroup;
6 | import android.widget.FrameLayout;
7 | import android.widget.ImageView;
8 |
9 | import com.bumptech.glide.Glide;
10 | import com.darsh.multipleimageselect.R;
11 | import com.darsh.multipleimageselect.models.Image;
12 |
13 | import java.util.ArrayList;
14 |
15 | /**
16 | * Created by Darshan on 4/18/2015.
17 | */
18 | public class CustomImageSelectAdapter extends CustomGenericAdapter {
19 | public CustomImageSelectAdapter(Context context, ArrayList images) {
20 | super(context, images);
21 | }
22 |
23 | @Override
24 | public View getView(int position, View convertView, ViewGroup parent) {
25 | ViewHolder viewHolder;
26 |
27 | if (convertView == null) {
28 | convertView = layoutInflater.inflate(R.layout.grid_view_item_image_select, null);
29 |
30 | viewHolder = new ViewHolder();
31 | viewHolder.imageView = (ImageView) convertView.findViewById(R.id.image_view_image_select);
32 | viewHolder.view = convertView.findViewById(R.id.view_alpha);
33 |
34 | convertView.setTag(viewHolder);
35 |
36 | } else {
37 | viewHolder = (ViewHolder) convertView.getTag();
38 | }
39 |
40 | viewHolder.imageView.getLayoutParams().width = size;
41 | viewHolder.imageView.getLayoutParams().height = size;
42 |
43 | viewHolder.view.getLayoutParams().width = size;
44 | viewHolder.view.getLayoutParams().height = size;
45 |
46 | if (arrayList.get(position).isSelected) {
47 | viewHolder.view.setAlpha(0.5f);
48 | ((FrameLayout) convertView).setForeground(context.getResources().getDrawable(R.drawable.ic_done_white));
49 |
50 | } else {
51 | viewHolder.view.setAlpha(0.0f);
52 | ((FrameLayout) convertView).setForeground(null);
53 | }
54 |
55 | Glide.with(context)
56 | .load(arrayList.get(position).path)
57 | .placeholder(R.drawable.image_placeholder).into(viewHolder.imageView);
58 |
59 | return convertView;
60 | }
61 |
62 | private static class ViewHolder {
63 | public ImageView imageView;
64 | public View view;
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/darsh/example/sample/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.darsh.example.sample;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.view.Menu;
7 | import android.view.MenuItem;
8 | import android.widget.TextView;
9 |
10 | import com.darsh.multipleimageselect.activities.AlbumSelectActivity;
11 | import com.darsh.multipleimageselect.helpers.Constants;
12 | import com.darsh.multipleimageselect.models.Image;
13 |
14 | import java.util.ArrayList;
15 |
16 | public class MainActivity extends AppCompatActivity {
17 | private TextView textView;
18 |
19 | @Override
20 | protected void onCreate(Bundle savedInstanceState) {
21 | super.onCreate(savedInstanceState);
22 | setContentView(R.layout.activity_main);
23 |
24 | textView = (TextView) findViewById(R.id.text_view);
25 |
26 | Intent intent = new Intent(MainActivity.this, AlbumSelectActivity.class);
27 | intent.putExtra(Constants.INTENT_EXTRA_LIMIT, 3);
28 | startActivityForResult(intent, Constants.REQUEST_CODE);
29 | }
30 |
31 | @Override
32 | protected void onActivityResult(int requestCode, int resultCode, Intent data) {
33 | if (requestCode == Constants.REQUEST_CODE && resultCode == RESULT_OK && data != null) {
34 | ArrayList images = data.getParcelableArrayListExtra(Constants.INTENT_EXTRA_IMAGES);
35 | StringBuffer stringBuffer = new StringBuffer();
36 | for (int i = 0, l = images.size(); i < l; i++) {
37 | stringBuffer.append(images.get(i).path + "\n");
38 | }
39 | textView.setText(stringBuffer.toString());
40 | }
41 | }
42 |
43 | @Override
44 | public boolean onCreateOptionsMenu(Menu menu) {
45 | // Inflate the menu; this adds items to the action bar if it is present.
46 | getMenuInflater().inflate(R.menu.menu_main, menu);
47 | return true;
48 | }
49 |
50 | @Override
51 | public boolean onOptionsItemSelected(MenuItem item) {
52 | // Handle action bar item clicks here. The action bar will
53 | // automatically handle clicks on the Home/Up button, so long
54 | // as you specify a parent activity in AndroidManifest.xml.
55 | int id = item.getItemId();
56 |
57 | //noinspection SimplifiableIfStatement
58 | if (id == R.id.action_settings) {
59 | return true;
60 | }
61 |
62 | return super.onOptionsItemSelected(item);
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/multipleimageselect/src/main/java/com/darsh/multipleimageselect/activities/HelperActivity.java:
--------------------------------------------------------------------------------
1 | package com.darsh.multipleimageselect.activities;
2 |
3 | import android.Manifest;
4 | import android.content.Intent;
5 | import android.content.pm.PackageManager;
6 | import android.net.Uri;
7 | import android.provider.Settings;
8 | import android.support.annotation.NonNull;
9 | import android.support.design.widget.Snackbar;
10 | import android.support.v4.app.ActivityCompat;
11 | import android.support.v4.content.ContextCompat;
12 | import android.support.v7.app.AppCompatActivity;
13 | import android.view.View;
14 |
15 | import com.darsh.multipleimageselect.R;
16 | import com.darsh.multipleimageselect.helpers.Constants;
17 |
18 | /**
19 | * Created by darshan on 26/9/16.
20 | */
21 | public class HelperActivity extends AppCompatActivity {
22 | protected View view;
23 |
24 | private final int maxLines = 4;
25 | private final String[] permissions = new String[]{ Manifest.permission.WRITE_EXTERNAL_STORAGE };
26 |
27 | protected void checkPermission() {
28 | if (ContextCompat.checkSelfPermission(this,
29 | Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
30 | permissionGranted();
31 |
32 | } else {
33 | ActivityCompat.requestPermissions(this, permissions, Constants.PERMISSION_REQUEST_CODE);
34 | }
35 | }
36 |
37 | private void requestPermission() {
38 | if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
39 | showRequestPermissionRationale();
40 |
41 | } else {
42 | showAppPermissionSettings();
43 | }
44 | }
45 |
46 | private void showRequestPermissionRationale() {
47 | Snackbar snackbar = Snackbar.make(
48 | view,
49 | getString(R.string.permission_info),
50 | Snackbar.LENGTH_INDEFINITE)
51 | .setAction(getString(R.string.permission_ok), new View.OnClickListener() {
52 | @Override
53 | public void onClick(View v) {
54 | ActivityCompat.requestPermissions(
55 | HelperActivity.this,
56 | permissions,
57 | Constants.PERMISSION_REQUEST_CODE);
58 | }
59 | });
60 |
61 | /*((TextView) snackbar.getView()
62 | .findViewById(android.support.design.R.id.snackbar_text)).setMaxLines(maxLines);*/
63 | snackbar.show();
64 | }
65 |
66 | private void showAppPermissionSettings() {
67 | Snackbar snackbar = Snackbar.make(
68 | view,
69 | getString(R.string.permission_force),
70 | Snackbar.LENGTH_INDEFINITE)
71 | .setAction(getString(R.string.permission_settings), new View.OnClickListener() {
72 | @Override
73 | public void onClick(View v) {
74 | Uri uri = Uri.fromParts(
75 | getString(R.string.permission_package),
76 | HelperActivity.this.getPackageName(),
77 | null);
78 |
79 | Intent intent = new Intent();
80 | intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
81 | intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
82 | intent.setData(uri);
83 | startActivityForResult(intent, Constants.PERMISSION_REQUEST_CODE);
84 | }
85 | });
86 |
87 | /*((TextView) snackbar.getView()
88 | .findViewById(android.support.design.R.id.snackbar_text)).setMaxLines(maxLines);*/
89 | snackbar.show();
90 | }
91 |
92 | @Override
93 | public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
94 | super.onRequestPermissionsResult(requestCode, permissions, grantResults);
95 | if (requestCode != Constants.PERMISSION_REQUEST_CODE
96 | || grantResults.length == 0
97 | || grantResults[0] == PackageManager.PERMISSION_DENIED) {
98 | permissionDenied();
99 |
100 | } else {
101 | permissionGranted();
102 | }
103 | }
104 |
105 | protected void permissionGranted() {}
106 |
107 | private void permissionDenied() {
108 | hideViews();
109 | requestPermission();
110 | }
111 |
112 | protected void hideViews() {}
113 |
114 | protected void setView(View view) {
115 | this.view = view;
116 | }
117 | }
118 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # For Cygwin, ensure paths are in UNIX format before anything is touched.
46 | if $cygwin ; then
47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
48 | fi
49 |
50 | # Attempt to set APP_HOME
51 | # Resolve links: $0 may be a link
52 | PRG="$0"
53 | # Need this for relative symlinks.
54 | while [ -h "$PRG" ] ; do
55 | ls=`ls -ld "$PRG"`
56 | link=`expr "$ls" : '.*-> \(.*\)$'`
57 | if expr "$link" : '/.*' > /dev/null; then
58 | PRG="$link"
59 | else
60 | PRG=`dirname "$PRG"`"/$link"
61 | fi
62 | done
63 | SAVED="`pwd`"
64 | cd "`dirname \"$PRG\"`/" >&-
65 | APP_HOME="`pwd -P`"
66 | cd "$SAVED" >&-
67 |
68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
69 |
70 | # Determine the Java command to use to start the JVM.
71 | if [ -n "$JAVA_HOME" ] ; then
72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
73 | # IBM's JDK on AIX uses strange locations for the executables
74 | JAVACMD="$JAVA_HOME/jre/sh/java"
75 | else
76 | JAVACMD="$JAVA_HOME/bin/java"
77 | fi
78 | if [ ! -x "$JAVACMD" ] ; then
79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
80 |
81 | Please set the JAVA_HOME variable in your environment to match the
82 | location of your Java installation."
83 | fi
84 | else
85 | JAVACMD="java"
86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
87 |
88 | Please set the JAVA_HOME variable in your environment to match the
89 | location of your Java installation."
90 | fi
91 |
92 | # Increase the maximum file descriptors if we can.
93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
94 | MAX_FD_LIMIT=`ulimit -H -n`
95 | if [ $? -eq 0 ] ; then
96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
97 | MAX_FD="$MAX_FD_LIMIT"
98 | fi
99 | ulimit -n $MAX_FD
100 | if [ $? -ne 0 ] ; then
101 | warn "Could not set maximum file descriptor limit: $MAX_FD"
102 | fi
103 | else
104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
105 | fi
106 | fi
107 |
108 | # For Darwin, add options to specify how the application appears in the dock
109 | if $darwin; then
110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
111 | fi
112 |
113 | # For Cygwin, switch paths to Windows format before running java
114 | if $cygwin ; then
115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
158 | function splitJvmOpts() {
159 | JVM_OPTS=("$@")
160 | }
161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
163 |
164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
165 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | #MultipleImageSelect
2 |
3 | 
4 |
5 | An android library that allows selection of multiple images from gallery. It shows an initial
6 | album (buckets) chooser and then images in selected album. Can limit the number of images that
7 | can be selected. Can be used in apps with APK 11 onwards.
8 |
9 | Sample app can be found [here](https://github.com/darsh2/MultipleImageSelect/tree/master/sample)
10 | #Usage
11 | Include this library in your project using gradle (thanks to [JitPack.io](https://github.com/jitpack-io)).
12 |
13 | For stable build:
14 | ```gradle
15 | repositories {
16 | maven {
17 | url "https://jitpack.io"
18 | }
19 | }
20 |
21 | dependencies {
22 | compile 'com.github.darsh2:MultipleImageSelect:v0.0.4'
23 | }
24 | ```
25 |
26 | For using the latest build, replace the tag in dependencies above with latest commit hash. Example:
27 | ```gradle
28 | repositories {
29 | maven {
30 | url "https://jitpack.io"
31 | }
32 | }
33 |
34 | dependencies {
35 | compile 'com.github.darsh2:MultipleImageSelect:3474549'
36 | }
37 | ```
38 |
39 | In project's AndroidManifest.xml, add the following under application node:
40 | ```xml
41 |
44 |
45 |
46 |
47 |
48 | ```
49 | In the activity from where you want to call image selector, create Intent as follows:
50 | ```java
51 | Intent intent = new Intent(this, AlbumSelectActivity.class);
52 | //set limit on number of images that can be selected, default is 10
53 | intent.putExtra(Constants.INTENT_EXTRA_LIMIT, numberOfImagesToSelect);
54 | startActivityForResult(intent, Constants.REQUEST_CODE);
55 | ```
56 | and override onActivityResult as follows:
57 | ```java
58 | @Override
59 | protected void onActivityResult(int requestCode, int resultCode, Intent data) {
60 | if (requestCode == Constants.REQUEST_CODE && resultCode == RESULT_OK && data != null) {
61 | //The array list has the image paths of the selected images
62 | ArrayList images = data.getParcelableArrayListExtra(Constants.INTENT_EXTRA_IMAGES);
63 | ...
64 | }
65 | ```
66 | #Custom Styles
67 | 
68 |
69 | 1. To change the color of UI elements, in colors.xml file, override the following attributes with the desired colors. Example:
70 |
71 | ```xml
72 | #673AB7
73 | #512DA8
74 | #D1C4E9
75 | #536DFE
76 | #212121
77 | #727272
78 | #B6B6B6
79 | #FFFFFF
80 | #99FFFFFF
81 | #000000
82 | ```
83 |
84 | 
85 |
86 | 2. To change the theme altogether, do step 1, and make the following changes in styles.xml and manifest file:
87 |
88 | styles.xml:
89 | Create the theme you want to use along with a theme for toolbar and actionmode. Example:
90 |
91 | ```xml
92 |
99 |
102 |
104 | ```
105 |
106 | AndroidManifest.xml:
107 | Add ```tools:replace="android:theme"``` to AlbumSelectActivity and ImageSelectActivity and specify theme to use. Example:
108 |
109 | ```xml
110 |
113 |
114 |
117 |
118 |
119 |
120 |
121 |
124 |
125 |
126 |
127 |
128 | ```
129 | #Screenshots
130 | Can be found [here](https://github.com/darsh2/MultipleImageSelect/tree/master/screenshots)
131 | #Apps using this
132 | [Gallery Organizer](https://play.google.com/store/apps/details?id=com.darsh.galleryorganizer2)
133 |
134 | [PictureJam Collage Maker](https://play.google.com/store/apps/details?id=xyz.pichancer.picturejam.free)
135 | #Similar Projects
136 | Similar libraries can be found [here](https://android-arsenal.com/tag/157)
137 | #Acknowledgements
138 | This library makes use of [Glide](https://github.com/bumptech/glide) by Bump Technologies.
139 | (Thanks to [WindSekirun](https://github.com/WindSekirun) for suggesting Glide)
140 | #License
141 | ```license
142 | Copyright 2015 Darshan Dorai
143 |
144 | Licensed under the Apache License, Version 2.0 (the "License");
145 | you may not use this file except in compliance with the License.
146 | You may obtain a copy of the License at
147 |
148 | http://www.apache.org/licenses/LICENSE-2.0
149 |
150 | Unless required by applicable law or agreed to in writing, software
151 | distributed under the License is distributed on an "AS IS" BASIS,
152 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
153 | See the License for the specific language governing permissions and
154 | limitations under the License.
155 | ```
156 |
--------------------------------------------------------------------------------
/sample/sample.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 | generateDebugSources
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
--------------------------------------------------------------------------------
/multipleimageselect/multipleimageselect.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 | generateDebugSources
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright {yyyy} {name of copyright owner}
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/multipleimageselect/src/main/java/com/darsh/multipleimageselect/activities/AlbumSelectActivity.java:
--------------------------------------------------------------------------------
1 | package com.darsh.multipleimageselect.activities;
2 |
3 | import android.content.Context;
4 | import android.content.Intent;
5 | import android.content.res.Configuration;
6 | import android.database.ContentObserver;
7 | import android.database.Cursor;
8 | import android.net.Uri;
9 | import android.os.Bundle;
10 | import android.os.Handler;
11 | import android.os.Message;
12 | import android.os.Process;
13 | import android.provider.MediaStore;
14 | import android.support.v7.app.ActionBar;
15 | import android.support.v7.widget.Toolbar;
16 | import android.util.DisplayMetrics;
17 | import android.view.MenuItem;
18 | import android.view.View;
19 | import android.view.WindowManager;
20 | import android.widget.AdapterView;
21 | import android.widget.GridView;
22 | import android.widget.ProgressBar;
23 | import android.widget.TextView;
24 |
25 | import com.darsh.multipleimageselect.R;
26 | import com.darsh.multipleimageselect.adapters.CustomAlbumSelectAdapter;
27 | import com.darsh.multipleimageselect.helpers.Constants;
28 | import com.darsh.multipleimageselect.models.Album;
29 |
30 | import java.io.File;
31 | import java.util.ArrayList;
32 | import java.util.HashSet;
33 |
34 | /**
35 | * Created by Darshan on 4/14/2015.
36 | */
37 | public class AlbumSelectActivity extends HelperActivity {
38 | private ArrayList albums;
39 |
40 | private TextView errorDisplay;
41 |
42 | private ProgressBar progressBar;
43 | private GridView gridView;
44 | private CustomAlbumSelectAdapter adapter;
45 |
46 | private ActionBar actionBar;
47 |
48 | private ContentObserver observer;
49 | private Handler handler;
50 | private Thread thread;
51 |
52 | private final String[] projection = new String[]{
53 | MediaStore.Images.Media.BUCKET_ID,
54 | MediaStore.Images.Media.BUCKET_DISPLAY_NAME,
55 | MediaStore.Images.Media.DATA };
56 |
57 | @Override
58 | protected void onCreate(Bundle savedInstanceState) {
59 | super.onCreate(savedInstanceState);
60 | setContentView(R.layout.activity_album_select);
61 | setView(findViewById(R.id.layout_album_select));
62 |
63 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
64 | setSupportActionBar(toolbar);
65 |
66 | actionBar = getSupportActionBar();
67 | if (actionBar != null) {
68 | actionBar.setDisplayHomeAsUpEnabled(true);
69 | actionBar.setHomeAsUpIndicator(R.drawable.ic_arrow_back);
70 |
71 | actionBar.setDisplayShowTitleEnabled(true);
72 | actionBar.setTitle(R.string.album_view);
73 | }
74 |
75 | Intent intent = getIntent();
76 | if (intent == null) {
77 | finish();
78 | }
79 | Constants.limit = intent.getIntExtra(Constants.INTENT_EXTRA_LIMIT, Constants.DEFAULT_LIMIT);
80 |
81 | errorDisplay = (TextView) findViewById(R.id.text_view_error);
82 | errorDisplay.setVisibility(View.INVISIBLE);
83 |
84 | progressBar = (ProgressBar) findViewById(R.id.progress_bar_album_select);
85 | gridView = (GridView) findViewById(R.id.grid_view_album_select);
86 | gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
87 | @Override
88 | public void onItemClick(AdapterView> parent, View view, int position, long id) {
89 | Intent intent = new Intent(getApplicationContext(), ImageSelectActivity.class);
90 | intent.putExtra(Constants.INTENT_EXTRA_ALBUM, albums.get(position).name);
91 | startActivityForResult(intent, Constants.REQUEST_CODE);
92 | }
93 | });
94 | }
95 |
96 | @Override
97 | protected void onStart() {
98 | super.onStart();
99 |
100 | handler = new Handler() {
101 | @Override
102 | public void handleMessage(Message msg) {
103 | switch (msg.what) {
104 | case Constants.PERMISSION_GRANTED: {
105 | loadAlbums();
106 | break;
107 | }
108 |
109 | case Constants.FETCH_STARTED: {
110 | progressBar.setVisibility(View.VISIBLE);
111 | gridView.setVisibility(View.INVISIBLE);
112 | break;
113 | }
114 |
115 | case Constants.FETCH_COMPLETED: {
116 | if (adapter == null) {
117 | adapter = new CustomAlbumSelectAdapter(getApplicationContext(), albums);
118 | gridView.setAdapter(adapter);
119 |
120 | progressBar.setVisibility(View.INVISIBLE);
121 | gridView.setVisibility(View.VISIBLE);
122 | orientationBasedUI(getResources().getConfiguration().orientation);
123 |
124 | } else {
125 | adapter.notifyDataSetChanged();
126 | }
127 | break;
128 | }
129 |
130 | case Constants.ERROR: {
131 | progressBar.setVisibility(View.INVISIBLE);
132 | errorDisplay.setVisibility(View.VISIBLE);
133 | break;
134 | }
135 |
136 | default: {
137 | super.handleMessage(msg);
138 | }
139 | }
140 | }
141 | };
142 | observer = new ContentObserver(handler) {
143 | @Override
144 | public void onChange(boolean selfChange, Uri uri) {
145 | loadAlbums();
146 | }
147 | };
148 | getContentResolver().registerContentObserver(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, false, observer);
149 |
150 | checkPermission();
151 | }
152 |
153 | @Override
154 | protected void onStop() {
155 | super.onStop();
156 |
157 | stopThread();
158 |
159 | getContentResolver().unregisterContentObserver(observer);
160 | observer = null;
161 |
162 | if (handler != null) {
163 | handler.removeCallbacksAndMessages(null);
164 | handler = null;
165 | }
166 | }
167 |
168 | @Override
169 | protected void onDestroy() {
170 | super.onDestroy();
171 |
172 | if (actionBar != null) {
173 | actionBar.setHomeAsUpIndicator(null);
174 | }
175 | albums = null;
176 | if (adapter != null) {
177 | adapter.releaseResources();
178 | }
179 | gridView.setOnItemClickListener(null);
180 | }
181 |
182 | @Override
183 | public void onConfigurationChanged(Configuration newConfig) {
184 | super.onConfigurationChanged(newConfig);
185 | orientationBasedUI(newConfig.orientation);
186 | }
187 |
188 | private void orientationBasedUI(int orientation) {
189 | final WindowManager windowManager = (WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE);
190 | final DisplayMetrics metrics = new DisplayMetrics();
191 | windowManager.getDefaultDisplay().getMetrics(metrics);
192 |
193 | if (adapter != null) {
194 | int size = orientation == Configuration.ORIENTATION_PORTRAIT ? metrics.widthPixels / 2 : metrics.widthPixels / 4;
195 | adapter.setLayoutParams(size);
196 | }
197 | gridView.setNumColumns(orientation == Configuration.ORIENTATION_PORTRAIT ? 2 : 4);
198 | }
199 |
200 | @Override
201 | public void onBackPressed() {
202 | super.onBackPressed();
203 | setResult(RESULT_CANCELED);
204 | finish();
205 | }
206 |
207 | @Override
208 | protected void onActivityResult(int requestCode, int resultCode, Intent data) {
209 | super.onActivityResult(requestCode, resultCode, data);
210 |
211 | if (requestCode == Constants.REQUEST_CODE
212 | && resultCode == RESULT_OK
213 | && data != null) {
214 | setResult(RESULT_OK, data);
215 | finish();
216 | }
217 | }
218 |
219 | @Override
220 | public boolean onOptionsItemSelected(MenuItem item) {
221 | switch (item.getItemId()) {
222 | case android.R.id.home: {
223 | onBackPressed();
224 | return true;
225 | }
226 |
227 | default: {
228 | return false;
229 | }
230 | }
231 | }
232 |
233 | private void loadAlbums() {
234 | startThread(new AlbumLoaderRunnable());
235 | }
236 |
237 | private class AlbumLoaderRunnable implements Runnable {
238 | @Override
239 | public void run() {
240 | android.os.Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
241 |
242 | if (adapter == null) {
243 | sendMessage(Constants.FETCH_STARTED);
244 | }
245 |
246 | Cursor cursor = getApplicationContext().getContentResolver()
247 | .query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, projection,
248 | null, null, MediaStore.Images.Media.DATE_ADDED);
249 | if (cursor == null) {
250 | sendMessage(Constants.ERROR);
251 | return;
252 | }
253 |
254 | ArrayList temp = new ArrayList<>(cursor.getCount());
255 | HashSet albumSet = new HashSet<>();
256 | File file;
257 | if (cursor.moveToLast()) {
258 | do {
259 | if (Thread.interrupted()) {
260 | return;
261 | }
262 |
263 | long albumId = cursor.getLong(cursor.getColumnIndex(projection[0]));
264 | String album = cursor.getString(cursor.getColumnIndex(projection[1]));
265 | String image = cursor.getString(cursor.getColumnIndex(projection[2]));
266 |
267 | if (!albumSet.contains(albumId)) {
268 | /*
269 | It may happen that some image file paths are still present in cache,
270 | though image file does not exist. These last as long as media
271 | scanner is not run again. To avoid get such image file paths, check
272 | if image file exists.
273 | */
274 | file = new File(image);
275 | if (file.exists()) {
276 | temp.add(new Album(album, image));
277 | albumSet.add(albumId);
278 | }
279 | }
280 |
281 | } while (cursor.moveToPrevious());
282 | }
283 | cursor.close();
284 |
285 | if (albums == null) {
286 | albums = new ArrayList<>();
287 | }
288 | albums.clear();
289 | albums.addAll(temp);
290 |
291 | sendMessage(Constants.FETCH_COMPLETED);
292 | }
293 | }
294 |
295 | private void startThread(Runnable runnable) {
296 | stopThread();
297 | thread = new Thread(runnable);
298 | thread.start();
299 | }
300 |
301 | private void stopThread() {
302 | if (thread == null || !thread.isAlive()) {
303 | return;
304 | }
305 |
306 | thread.interrupt();
307 | try {
308 | thread.join();
309 | } catch (InterruptedException e) {
310 | e.printStackTrace();
311 | }
312 | }
313 |
314 | private void sendMessage(int what) {
315 | if (handler == null) {
316 | return;
317 | }
318 |
319 | Message message = handler.obtainMessage();
320 | message.what = what;
321 | message.sendToTarget();
322 | }
323 |
324 | @Override
325 | protected void permissionGranted() {
326 | Message message = handler.obtainMessage();
327 | message.what = Constants.PERMISSION_GRANTED;
328 | message.sendToTarget();
329 | }
330 |
331 | @Override
332 | protected void hideViews() {
333 | progressBar.setVisibility(View.INVISIBLE);
334 | gridView.setVisibility(View.INVISIBLE);
335 | }
336 | }
337 |
--------------------------------------------------------------------------------
/multipleimageselect/src/main/java/com/darsh/multipleimageselect/activities/ImageSelectActivity.java:
--------------------------------------------------------------------------------
1 | package com.darsh.multipleimageselect.activities;
2 |
3 | import android.content.Context;
4 | import android.content.Intent;
5 | import android.content.res.Configuration;
6 | import android.database.ContentObserver;
7 | import android.database.Cursor;
8 | import android.os.Bundle;
9 | import android.os.Handler;
10 | import android.os.Message;
11 | import android.os.Process;
12 | import android.provider.MediaStore;
13 | import android.support.v7.app.ActionBar;
14 | import android.support.v7.widget.Toolbar;
15 | import android.util.DisplayMetrics;
16 | import android.view.ActionMode;
17 | import android.view.Menu;
18 | import android.view.MenuInflater;
19 | import android.view.MenuItem;
20 | import android.view.View;
21 | import android.view.WindowManager;
22 | import android.widget.AdapterView;
23 | import android.widget.GridView;
24 | import android.widget.ProgressBar;
25 | import android.widget.TextView;
26 | import android.widget.Toast;
27 |
28 | import com.darsh.multipleimageselect.R;
29 | import com.darsh.multipleimageselect.adapters.CustomImageSelectAdapter;
30 | import com.darsh.multipleimageselect.helpers.Constants;
31 | import com.darsh.multipleimageselect.models.Image;
32 |
33 | import java.io.File;
34 | import java.util.ArrayList;
35 | import java.util.HashSet;
36 |
37 | /**
38 | * Created by Darshan on 4/18/2015.
39 | */
40 | public class ImageSelectActivity extends HelperActivity {
41 | private ArrayList images;
42 | private String album;
43 |
44 | private TextView errorDisplay;
45 |
46 | private ProgressBar progressBar;
47 | private GridView gridView;
48 | private CustomImageSelectAdapter adapter;
49 |
50 | private ActionBar actionBar;
51 |
52 | private ActionMode actionMode;
53 | private int countSelected;
54 |
55 | private ContentObserver observer;
56 | private Handler handler;
57 | private Thread thread;
58 |
59 | private final String[] projection = new String[]{ MediaStore.Images.Media._ID, MediaStore.Images.Media.DISPLAY_NAME, MediaStore.Images.Media.DATA };
60 |
61 | @Override
62 | protected void onCreate(Bundle savedInstanceState) {
63 | super.onCreate(savedInstanceState);
64 | setContentView(R.layout.activity_image_select);
65 | setView(findViewById(R.id.layout_image_select));
66 |
67 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
68 | setSupportActionBar(toolbar);
69 |
70 | actionBar = getSupportActionBar();
71 | if (actionBar != null) {
72 | actionBar.setDisplayHomeAsUpEnabled(true);
73 | actionBar.setHomeAsUpIndicator(R.drawable.ic_arrow_back);
74 |
75 | actionBar.setDisplayShowTitleEnabled(true);
76 | actionBar.setTitle(R.string.image_view);
77 | }
78 |
79 | Intent intent = getIntent();
80 | if (intent == null) {
81 | finish();
82 | }
83 | album = intent.getStringExtra(Constants.INTENT_EXTRA_ALBUM);
84 |
85 | errorDisplay = (TextView) findViewById(R.id.text_view_error);
86 | errorDisplay.setVisibility(View.INVISIBLE);
87 |
88 | progressBar = (ProgressBar) findViewById(R.id.progress_bar_image_select);
89 | gridView = (GridView) findViewById(R.id.grid_view_image_select);
90 | gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
91 | @Override
92 | public void onItemClick(AdapterView> parent, View view, int position, long id) {
93 | if (actionMode == null) {
94 | actionMode = ImageSelectActivity.this.startActionMode(callback);
95 | }
96 | toggleSelection(position);
97 | actionMode.setTitle(countSelected + " " + getString(R.string.selected));
98 |
99 | if (countSelected == 0) {
100 | actionMode.finish();
101 | }
102 | }
103 | });
104 | }
105 |
106 | @Override
107 | protected void onStart() {
108 | super.onStart();
109 |
110 | handler = new Handler() {
111 | @Override
112 | public void handleMessage(Message msg) {
113 | switch (msg.what) {
114 | case Constants.PERMISSION_GRANTED: {
115 | loadImages();
116 | break;
117 | }
118 |
119 | case Constants.FETCH_STARTED: {
120 | progressBar.setVisibility(View.VISIBLE);
121 | gridView.setVisibility(View.INVISIBLE);
122 | break;
123 | }
124 |
125 | case Constants.FETCH_COMPLETED: {
126 | /*
127 | If adapter is null, this implies that the loaded images will be shown
128 | for the first time, hence send FETCH_COMPLETED message.
129 | However, if adapter has been initialised, this thread was run either
130 | due to the activity being restarted or content being changed.
131 | */
132 | if (adapter == null) {
133 | adapter = new CustomImageSelectAdapter(getApplicationContext(), images);
134 | gridView.setAdapter(adapter);
135 |
136 | progressBar.setVisibility(View.INVISIBLE);
137 | gridView.setVisibility(View.VISIBLE);
138 | orientationBasedUI(getResources().getConfiguration().orientation);
139 |
140 | } else {
141 | adapter.notifyDataSetChanged();
142 | /*
143 | Some selected images may have been deleted
144 | hence update action mode title
145 | */
146 | if (actionMode != null) {
147 | countSelected = msg.arg1;
148 | actionMode.setTitle(countSelected + " " + getString(R.string.selected));
149 | }
150 | }
151 | break;
152 | }
153 |
154 | case Constants.ERROR: {
155 | progressBar.setVisibility(View.INVISIBLE);
156 | errorDisplay.setVisibility(View.VISIBLE);
157 | break;
158 | }
159 |
160 | default: {
161 | super.handleMessage(msg);
162 | }
163 | }
164 | }
165 | };
166 | observer = new ContentObserver(handler) {
167 | @Override
168 | public void onChange(boolean selfChange) {
169 | loadImages();
170 | }
171 | };
172 | getContentResolver().registerContentObserver(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, false, observer);
173 |
174 | checkPermission();
175 | }
176 |
177 | @Override
178 | protected void onStop() {
179 | super.onStop();
180 |
181 | stopThread();
182 |
183 | getContentResolver().unregisterContentObserver(observer);
184 | observer = null;
185 |
186 | if (handler != null) {
187 | handler.removeCallbacksAndMessages(null);
188 | handler = null;
189 | }
190 | }
191 |
192 | @Override
193 | protected void onDestroy() {
194 | super.onDestroy();
195 |
196 | if (actionBar != null) {
197 | actionBar.setHomeAsUpIndicator(null);
198 | }
199 | images = null;
200 | if (adapter != null) {
201 | adapter.releaseResources();
202 | }
203 | gridView.setOnItemClickListener(null);
204 | }
205 |
206 | @Override
207 | public void onConfigurationChanged(Configuration newConfig) {
208 | super.onConfigurationChanged(newConfig);
209 | orientationBasedUI(newConfig.orientation);
210 | }
211 |
212 | private void orientationBasedUI(int orientation) {
213 | final WindowManager windowManager = (WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE);
214 | final DisplayMetrics metrics = new DisplayMetrics();
215 | windowManager.getDefaultDisplay().getMetrics(metrics);
216 |
217 | if (adapter != null) {
218 | int size = orientation == Configuration.ORIENTATION_PORTRAIT ? metrics.widthPixels / 3 : metrics.widthPixels / 5;
219 | adapter.setLayoutParams(size);
220 | }
221 | gridView.setNumColumns(orientation == Configuration.ORIENTATION_PORTRAIT ? 3 : 5);
222 | }
223 |
224 | @Override
225 | public boolean onOptionsItemSelected(MenuItem item) {
226 | switch (item.getItemId()) {
227 | case android.R.id.home: {
228 | onBackPressed();
229 | return true;
230 | }
231 |
232 | default: {
233 | return false;
234 | }
235 | }
236 | }
237 |
238 | private ActionMode.Callback callback = new ActionMode.Callback() {
239 | @Override
240 | public boolean onCreateActionMode(ActionMode mode, Menu menu) {
241 | MenuInflater menuInflater = mode.getMenuInflater();
242 | menuInflater.inflate(R.menu.menu_contextual_action_bar, menu);
243 |
244 | actionMode = mode;
245 | countSelected = 0;
246 |
247 | return true;
248 | }
249 |
250 | @Override
251 | public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
252 | return false;
253 | }
254 |
255 | @Override
256 | public boolean onActionItemClicked(ActionMode mode, MenuItem item) {int i = item.getItemId();
257 | if (i == R.id.menu_item_add_image) {
258 | sendIntent();
259 | return true;
260 | }
261 | return false;
262 | }
263 |
264 | @Override
265 | public void onDestroyActionMode(ActionMode mode) {
266 | if (countSelected > 0) {
267 | deselectAll();
268 | }
269 | actionMode = null;
270 | }
271 | };
272 |
273 | private void toggleSelection(int position) {
274 | if (!images.get(position).isSelected && countSelected >= Constants.limit) {
275 | Toast.makeText(
276 | getApplicationContext(),
277 | String.format(getString(R.string.limit_exceeded), Constants.limit),
278 | Toast.LENGTH_SHORT)
279 | .show();
280 | return;
281 | }
282 |
283 | images.get(position).isSelected = !images.get(position).isSelected;
284 | if (images.get(position).isSelected) {
285 | countSelected++;
286 | } else {
287 | countSelected--;
288 | }
289 | adapter.notifyDataSetChanged();
290 | }
291 |
292 | private void deselectAll() {
293 | for (int i = 0, l = images.size(); i < l; i++) {
294 | images.get(i).isSelected = false;
295 | }
296 | countSelected = 0;
297 | adapter.notifyDataSetChanged();
298 | }
299 |
300 | private ArrayList getSelected() {
301 | ArrayList selectedImages = new ArrayList<>();
302 | for (int i = 0, l = images.size(); i < l; i++) {
303 | if (images.get(i).isSelected) {
304 | selectedImages.add(images.get(i));
305 | }
306 | }
307 | return selectedImages;
308 | }
309 |
310 | private void sendIntent() {
311 | Intent intent = new Intent();
312 | intent.putParcelableArrayListExtra(Constants.INTENT_EXTRA_IMAGES, getSelected());
313 | setResult(RESULT_OK, intent);
314 | finish();
315 | }
316 |
317 | private void loadImages() {
318 | startThread(new ImageLoaderRunnable());
319 | }
320 |
321 | private class ImageLoaderRunnable implements Runnable {
322 | @Override
323 | public void run() {
324 | android.os.Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
325 | /*
326 | If the adapter is null, this is first time this activity's view is
327 | being shown, hence send FETCH_STARTED message to show progress bar
328 | while images are loaded from phone
329 | */
330 | if (adapter == null) {
331 | sendMessage(Constants.FETCH_STARTED);
332 | }
333 |
334 | File file;
335 | HashSet selectedImages = new HashSet<>();
336 | if (images != null) {
337 | Image image;
338 | for (int i = 0, l = images.size(); i < l; i++) {
339 | image = images.get(i);
340 | file = new File(image.path);
341 | if (file.exists() && image.isSelected) {
342 | selectedImages.add(image.id);
343 | }
344 | }
345 | }
346 |
347 | Cursor cursor = getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, projection,
348 | MediaStore.Images.Media.BUCKET_DISPLAY_NAME + " =?", new String[]{ album }, MediaStore.Images.Media.DATE_ADDED);
349 | if (cursor == null) {
350 | sendMessage(Constants.ERROR);
351 | return;
352 | }
353 |
354 | /*
355 | In case this runnable is executed to onChange calling loadImages,
356 | using countSelected variable can result in a race condition. To avoid that,
357 | tempCountSelected keeps track of number of selected images. On handling
358 | FETCH_COMPLETED message, countSelected is assigned value of tempCountSelected.
359 | */
360 | int tempCountSelected = 0;
361 | ArrayList temp = new ArrayList<>(cursor.getCount());
362 | if (cursor.moveToLast()) {
363 | do {
364 | if (Thread.interrupted()) {
365 | return;
366 | }
367 |
368 | long id = cursor.getLong(cursor.getColumnIndex(projection[0]));
369 | String name = cursor.getString(cursor.getColumnIndex(projection[1]));
370 | String path = cursor.getString(cursor.getColumnIndex(projection[2]));
371 | boolean isSelected = selectedImages.contains(id);
372 | if (isSelected) {
373 | tempCountSelected++;
374 | }
375 |
376 | file = new File(path);
377 | if (file.exists()) {
378 | temp.add(new Image(id, name, path, isSelected));
379 | }
380 |
381 | } while (cursor.moveToPrevious());
382 | }
383 | cursor.close();
384 |
385 | if (images == null) {
386 | images = new ArrayList<>();
387 | }
388 | images.clear();
389 | images.addAll(temp);
390 |
391 | sendMessage(Constants.FETCH_COMPLETED, tempCountSelected);
392 | }
393 | }
394 |
395 | private void startThread(Runnable runnable) {
396 | stopThread();
397 | thread = new Thread(runnable);
398 | thread.start();
399 | }
400 |
401 | private void stopThread() {
402 | if (thread == null || !thread.isAlive()) {
403 | return;
404 | }
405 |
406 | thread.interrupt();
407 | try {
408 | thread.join();
409 | } catch (InterruptedException e) {
410 | e.printStackTrace();
411 | }
412 | }
413 |
414 | private void sendMessage(int what) {
415 | sendMessage(what, 0);
416 | }
417 |
418 | private void sendMessage(int what, int arg1) {
419 | if (handler == null) {
420 | return;
421 | }
422 |
423 | Message message = handler.obtainMessage();
424 | message.what = what;
425 | message.arg1 = arg1;
426 | message.sendToTarget();
427 | }
428 |
429 | @Override
430 | protected void permissionGranted() {
431 | sendMessage(Constants.PERMISSION_GRANTED);
432 | }
433 |
434 | @Override
435 | protected void hideViews() {
436 | progressBar.setVisibility(View.INVISIBLE);
437 | gridView.setVisibility(View.INVISIBLE);
438 | }
439 | }
440 |
--------------------------------------------------------------------------------