Repository: AnilFurkanOkcun/UWMediaPicker-Android
Branch: master
Commit: 56ab70150e1f
Files: 82
Total size: 142.8 KB
Directory structure:
gitextract_twc3vq8r/
├── .gitignore
├── .idea/
│ ├── compiler.xml
│ ├── jarRepositories.xml
│ ├── misc.xml
│ ├── modules.xml
│ └── vcs.xml
├── LICENSE
├── README.md
├── build.gradle
├── gradle/
│ └── wrapper/
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradle.properties
├── gradlew
├── gradlew.bat
├── sample/
│ ├── .gitignore
│ ├── build.gradle
│ ├── proguard-rules.pro
│ ├── release/
│ │ └── output.json
│ └── src/
│ └── main/
│ ├── AndroidManifest.xml
│ ├── java/
│ │ └── com/
│ │ └── anilokcun/
│ │ └── uwandroidmediapicker/
│ │ ├── GalleryItemDecoration.kt
│ │ ├── MainActivity.kt
│ │ └── SelectedMediaRvAdapter.kt
│ └── res/
│ ├── color/
│ │ └── color_text_activatable.xml
│ ├── drawable/
│ │ ├── ic_launcher_background.xml
│ │ ├── selector_bg_et.xml
│ │ ├── shape_bg_btn.xml
│ │ ├── shape_bg_et_active.xml
│ │ ├── shape_bg_et_default.xml
│ │ ├── shape_bg_option.xml
│ │ ├── shape_bg_shadow.xml
│ │ └── shape_bg_tv_title.xml
│ ├── drawable-v24/
│ │ └── ic_launcher_foreground.xml
│ ├── layout/
│ │ └── activity_main.xml
│ ├── mipmap-anydpi-v26/
│ │ ├── ic_launcher.xml
│ │ └── ic_launcher_round.xml
│ └── values/
│ ├── colors.xml
│ ├── dimens.xml
│ ├── strings.xml
│ └── styles.xml
├── settings.gradle
└── uwmediapicker/
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src/
└── main/
├── AndroidManifest.xml
├── java/
│ └── com/
│ └── anilokcun/
│ └── uwmediapicker/
│ ├── ImageCompressor.kt
│ ├── UwMediaPicker.kt
│ ├── adapter/
│ │ └── GalleryMediaRvAdapter.kt
│ ├── helper/
│ │ └── Extensions.kt
│ ├── listener/
│ │ ├── GalleryMediaOnLongClickListener.kt
│ │ └── OnRVItemClickListener.kt
│ ├── model/
│ │ ├── BaseGalleryMediaModel.kt
│ │ ├── BaseGalleryModel.kt
│ │ ├── GalleryImageModel.kt
│ │ ├── GalleryMediaBucketModel.kt
│ │ ├── GalleryVideoModel.kt
│ │ ├── UWMediaPickerSettingsModel.kt
│ │ ├── UwMediaPickerMediaModel.kt
│ │ └── UwMediaPickerMediaType.kt
│ ├── provider/
│ │ └── GalleryMediaDataProvider.kt
│ ├── ui/
│ │ ├── GalleryItemDecoration.kt
│ │ ├── activity/
│ │ │ └── UwMediaPickerDialogFragment.kt
│ │ └── dialog/
│ │ └── ImagePreviewDialog.kt
│ └── viewholder/
│ ├── BaseGalleryMediaVH.kt
│ ├── GalleryImageVH.kt
│ ├── GalleryMediaBucketVH.kt
│ └── GalleryVideoVH.kt
└── res/
├── color/
│ └── uwmediapicker_color_btn_text_done.xml
├── drawable-nodpi/
│ ├── uwmediapicker_ic_arrow_back.xml
│ ├── uwmediapicker_ic_check_circled.xml
│ ├── uwmediapicker_selector_ic_media_selected.xml
│ ├── uwmediapicker_shape_bg_media_unselected.xml
│ ├── uwmediapicker_shape_bg_progress_dialog.xml
│ └── uwmediapicker_shape_bg_shadow.xml
├── layout/
│ ├── activity_uw_media_picker.xml
│ ├── uwmediapicker_dialog_progress.xml
│ ├── uwmediapicker_item_gallery_image.xml
│ ├── uwmediapicker_item_gallery_media_bucket.xml
│ └── uwmediapicker_item_gallery_video.xml
└── values/
├── colors.xml
├── dimens.xml
├── strings.xml
└── styles.xml
================================================
FILE CONTENTS
================================================
================================================
FILE: .gitignore
================================================
# Built application files
*.apk
*.ap_
# Files for the ART/Dalvik VM
*.dex
# Java class files
*.class
# Generated files
bin/
gen/
out/
# Gradle files
.gradle/
build/
# Local configuration file (sdk path, etc)
local.properties
# Proguard folder generated by Eclipse
proguard/
# Log Files
*.log
# Android Studio Navigation editor temp files
.navigation/
# Android Studio captures folder
captures/
# IntelliJ
*.iml
.idea/workspace.xml
.idea/tasks.xml
.idea/gradle.xml
.idea/assetWizardSettings.xml
.idea/dictionaries
.idea/libraries
.idea/caches
# Keystore files
# Uncomment the following line if you do not want to check your keystore files in.
#*.jks
# External native build folder generated in Android Studio 2.2 and later
.externalNativeBuild
# Google Services (e.g. APIs or Firebase)
google-services.json
# Freeline
freeline.py
freeline/
freeline_project_description.json
# fastlane
fastlane/report.xml
fastlane/Preview.html
fastlane/screenshots
fastlane/test_output
fastlane/readme.md
================================================
FILE: .idea/compiler.xml
================================================
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<bytecodeTargetLevel target="1.8" />
</component>
</project>
================================================
FILE: .idea/jarRepositories.xml
================================================
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RemoteRepositoriesConfiguration">
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Maven Central repository" />
<option name="url" value="https://repo1.maven.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="jboss.community" />
<option name="name" value="JBoss Community repository" />
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
</remote-repository>
<remote-repository>
<option name="id" value="BintrayJCenter" />
<option name="name" value="BintrayJCenter" />
<option name="url" value="https://jcenter.bintray.com/" />
</remote-repository>
<remote-repository>
<option name="id" value="Google" />
<option name="name" value="Google" />
<option name="url" value="https://dl.google.com/dl/android/maven2/" />
</remote-repository>
</component>
</project>
================================================
FILE: .idea/misc.xml
================================================
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK" />
</project>
================================================
FILE: .idea/modules.xml
================================================
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/UWMediaPicker-Android.iml" filepath="$PROJECT_DIR$/.idea/UWMediaPicker-Android.iml" />
<module fileurl="file://$PROJECT_DIR$/.idea/modules/sample/UWMediaPicker-Android.sample.iml" filepath="$PROJECT_DIR$/.idea/modules/sample/UWMediaPicker-Android.sample.iml" />
<module fileurl="file://$PROJECT_DIR$/.idea/modules/uwmediapicker/UWMediaPicker-Android.uwmediapicker.iml" filepath="$PROJECT_DIR$/.idea/modules/uwmediapicker/UWMediaPicker-Android.uwmediapicker.iml" />
</modules>
</component>
</project>
================================================
FILE: .idea/vcs.xml
================================================
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>
================================================
FILE: LICENSE
================================================
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
================================================
FILE: README.md
================================================

UW Media Picker-Android
=======
[](https://jitpack.io/#AnilFurkanOkcun/UWMediaPicker-Android)
[](https://github.com/AnilFurkanOkcun/UWMediaPicker-Android/blob/master/LICENSE)
Easy to use and customizable media picker library to pick multiple images(with compression) and videos for Android.
<p align="center">
<img src="https://github.com/AnilFurkanOkcun/UWMediaPicker-Android/blob/master/uw_media_picker_demo.gif?raw=true" alt="UW Media Picker"/>
</p>
[*See all screenshots*](https://github.com/AnilFurkanOkcun/UWMediaPicker-Android#screenshots)
## Supported Features
* Multiple image and/or video selecting
* Image compression
* Image preview by press and holding the image
* Async album loading with Kotlin Coroutine
* Limit the maximum number of selectable media
* Customizable grid column count
* All colors customizable by overriding it
* Easy to use with callback
## Installation
*You can have a look at the [sample project.](https://github.com/AnilFurkanOkcun/UWMediaPicker-Android/tree/master/sample)*
**Include library**
Add it in your root build.gradle at the end of repositories:
```gradle
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
```
Add the dependency to your app level build.gradle:
```gradle
dependencies {
...
implementation 'com.github.AnilFurkanOkcun:UWMediaPicker-Android:1.3.3'
}
```
## Usage
*Make sure you have `READ_EXTERNAL_STORAGE` permission.*\
*On Android Q, you should add `android:requestLegacyExternalStorage="true"` into your application tag in manifest*
**Initializing UW Media Picker**
```kotlin
UwMediaPicker
.with(this) // Activity or Fragment
.setGalleryMode(UwMediaPicker.GalleryMode.ImageGallery) // GalleryMode: ImageGallery/VideoGallery/ImageAndVideoGallery, default is ImageGallery
.setGridColumnCount(4) // Grid column count, default is 3
.setMaxSelectableMediaCount(10) // Maximum selectable media count, default is null which means infinite
.setLightStatusBar(true) // Is llight status bar enable, default is true
.enableImageCompression(true) // Is image compression enable, default is false
.setCompressionMaxWidth(1280F) // Compressed image's max width px, default is 1280
.setCompressionMaxHeight(720F) // Compressed image's max height px, default is 720
.setCompressFormat(Bitmap.CompressFormat.JPEG) // Compressed image's format, default is JPEG
.setCompressionQuality(85) // Image compression quality, default is 85
.setCompressedFileDestinationPath(destinationPath) // Compressed image file's destination path, default is "${application.getExternalFilesDir(null).path}/Pictures"
.setCancelCallback{ } // Will be called when user cancels media selection
.launch{selectedMediaList-> } // (::onMediaSelected) // Will be called when media is selected
```
## UI Customization
* You can override these colors in your `colors.xml` for ui customization.
```xml
<color name="colorUwMediaPickerStatusBar">#F6F6F6</color>
<color name="colorUwMediaPickerProgressBar">#CDCDCD</color>
<color name="colorUwMediaPickerPageBackground">#FFFFFF</color>
<color name="colorUwMediaPickerProgressDialogBg">#F9F9F9</color>
<color name="colorUwMediaPickerProgressDialogStroke">#D9D9D9</color>
<!-- Toolbar Colors -->
<color name="colorUwMediaPickerToolbarBg">#FFFFFF</color>
<color name="colorUwMediaPickerBackButton">#272727</color>
<color name="colorUwMediaPickerToolbarTitle">#404040</color>
<color name="colorUwMediaPickerToolbarSubtext">#8D8D8D</color>
<color name="colorUwMediaPickerBtnTextDoneEnable">#0192D2</color>
<color name="colorUwMediaPickerBtnTextDoneDisable">#B3B3B3</color>
<!-- Gallery Item Colors-->
<color name="colorUwMediaPickerBucketBottomStrip">#8C000000</color>
<color name="colorUwMediaPickerImagePlaceHolder">#F6F6F6</color>
<color name="colorUwMediaPickerUnselectedIconBg">#80FFFFFF</color>
<color name="colorUwMediaPickerSelectedIconBg">#0192D2</color>
<color name="colorUwMediaPickerSelectedIcon">#FFF</color>
<color name="colorUwMediaPickerMediaName">#FFFFFF</color>
<color name="colorUwMediaPickerAlbumMediaCount">#D9D9D9</color>
```
* You can override these strings in your `strings.xml` for ui and language changes.
```xml
<!-- Toolbar Texts -->
<string name="uwmediapicker_toolbar_title_image_library">Image Library</string>
<string name="uwmediapicker_toolbar_title_video_library">Video Library</string>
<string name="uwmediapicker_toolbar_title_image_and_video_library">Image&Video Library</string>
<string name="uwmediapicker_toolbar_text_uw_media_picker_selected_media_count">%d/%d selected</string>
<string name="uwmediapicker_toolbar_done">Done</string>
<!-- Snackbar Messages -->
<string name="uwmediapicker_snackbar_error_gallery_open_failed">Gallery could not be opened.</string>
<string name="uwmediapicker_snackbar_action_retry">Retry</string>
<!-- Toast Messages-->
<string name="uwmediapicker_toast_error_media_bucket_open_failed">Album could not be opened.</string>
<string name="uwmediapicker_toast_error_media_select_failed">Media could not be selected.</string>
<string name="uwmediapicker_toast_error_max_media_selected">You can not select any more media</string>
<string name="uwmediapicker_toast_error_some_media_select_failed">Some media could not be selected</string>
<!-- Time Formats -->
<string name="uwmediapicker_time_format_hour_min_sec">%02d:%02d:%02d</string>
<string name="uwmediapicker_time_format_min_sec">%02d:%02d</string>
<!-- Content Descriptions -->
<string name="uwmediapicker_content_description_back_button">Back button</string>
<string name="uwmediapicker_content_description_album_thumbnail">Album thumbnail</string>
<string name="uwmediapicker_content_description_image_thumbnail">Image thumbnail</string>
<string name="uwmediapicker_content_description_video_thumbnail">Video thumbnail</string>
<string name="uwmediapicker_content_description_selected_icon">Selected icon</string>
```
## Screenshots

## Credits
Thanks to [Chimzy](https://github.com/chimzycash) for the awesome icon.
## License
```
Copyright (c) 2018 Anıl Furkan Ökçün
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
```
================================================
FILE: build.gradle
================================================
buildscript {
ext {
projectConfig = [
application_id: 'com.anilokcun.uwmediapicker',
version_code : 1,
version_name : '1.3.3',
compile_sdk : 31,
min_sdk : 17,
target_sdk : 31
]
versions = [
glide : '4.12.0'
]
}
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.1.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.0"
}
}
allprojects {
repositories {
google()
mavenCentral()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
================================================
FILE: gradle/wrapper/gradle-wrapper.properties
================================================
#Sun Dec 20 17:09:44 EET 2020
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip
================================================
FILE: gradle.properties
================================================
# Project-wide Gradle settings.
# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
android.enableJetifier=true
android.useAndroidX=true
org.gradle.jvmargs=-Xmx1536m
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
================================================
FILE: gradlew
================================================
#!/usr/bin/env sh
##############################################################################
##
## Gradle start up script for UN*X
##
##############################################################################
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null
APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
warn () {
echo "$*"
}
die () {
echo
echo "$*"
echo
exit 1
}
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
nonstop=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
NONSTOP* )
nonstop=true
;;
esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD="java"
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
MAX_FD="$MAX_FD_LIMIT"
fi
ulimit -n $MAX_FD
if [ $? -ne 0 ] ; then
warn "Could not set maximum file descriptor limit: $MAX_FD"
fi
else
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi
# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi
# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`
# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
SEP=""
for dir in $ROOTDIRSRAW ; do
ROOTDIRS="$ROOTDIRS$SEP$dir"
SEP="|"
done
OURCYGPATTERN="(^($ROOTDIRS))"
# Add a user-defined pattern to the cygpath arguments
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
fi
# Now convert the arguments - kludge to limit ourselves to /bin/sh
i=0
for arg in "$@" ; do
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
else
eval `echo args$i`="\"$arg\""
fi
i=$((i+1))
done
case $i in
(0) set -- ;;
(1) set -- "$args0" ;;
(2) set -- "$args0" "$args1" ;;
(3) set -- "$args0" "$args1" "$args2" ;;
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi
# Escape application args
save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
APP_ARGS=$(save "$@")
# Collect all arguments for the java command, following the shell quoting and substitution rules
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
cd "$(dirname "$0")"
fi
exec "$JAVACMD" "$@"
================================================
FILE: gradlew.bat
================================================
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto init
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:init
@rem Get command-line arguments, handling Windows variants
if not "%OS%" == "Windows_NT" goto win9xME_args
:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2
:win9xME_args_slurp
if "x%~1" == "x" goto execute
set CMD_LINE_ARGS=%*
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega
================================================
FILE: sample/.gitignore
================================================
/build
================================================
FILE: sample/build.gradle
================================================
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
android {
compileSdkVersion projectConfig.compile_sdk
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
defaultConfig {
applicationId projectConfig.applicationId
minSdkVersion projectConfig.min_sdk
targetSdkVersion projectConfig.target_sdk
versionCode projectConfig.version_code
versionName projectConfig.version_name
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'androidx.appcompat:appcompat:1.4.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.recyclerview:recyclerview:1.2.1'
implementation project(':uwmediapicker')
implementation 'androidx.constraintlayout:constraintlayout:2.1.2'
// Glide
implementation "com.github.bumptech.glide:glide:$versions.glide"
}
apply plugin: 'kotlin-kapt'
================================================
FILE: sample/proguard-rules.pro
================================================
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
================================================
FILE: sample/release/output.json
================================================
[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":1,"versionName":"1.0","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}]
================================================
FILE: sample/src/main/AndroidManifest.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.anilokcun.uwandroidmediapicker">
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:requestLegacyExternalStorage="true"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:ignore="GoogleAppIndexingWarning">
<activity
android:name=".MainActivity"
android:screenOrientation="portrait"
tools:ignore="LockedOrientationActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
================================================
FILE: sample/src/main/java/com/anilokcun/uwandroidmediapicker/GalleryItemDecoration.kt
================================================
package com.anilokcun.uwandroidmediapicker
import android.graphics.Rect
import android.view.View
import androidx.recyclerview.widget.RecyclerView
/**
* Author : Anıl Furkan Ökçün
* Author mail : anilfurkanokcun@gmail.com
* Create Date : 30.08.2018
*/
internal class GalleryItemDecoration(
private val gridSpacingPx: Int,
private val gridColumnCount: Int
) : RecyclerView.ItemDecoration() {
private var isNeedLeftSpacing = false
override fun getItemOffsets(outRect: Rect, view: View, parent: RecyclerView, state: RecyclerView.State) {
val frameWidth = ((parent.width - gridSpacingPx.toFloat() * (gridColumnCount - 1)) / gridColumnCount).toInt()
val padding = parent.width / gridColumnCount - frameWidth
val itemPosition = (view.layoutParams as RecyclerView.LayoutParams).viewAdapterPosition
if (itemPosition < gridColumnCount) {
outRect.top = 0
} else {
outRect.top = gridSpacingPx
}
if (itemPosition % gridColumnCount == 0) {
outRect.left = 0
outRect.right = padding
isNeedLeftSpacing = true
} else if ((itemPosition + 1) % gridColumnCount == 0) {
isNeedLeftSpacing = false
outRect.right = 0
outRect.left = padding
} else if (isNeedLeftSpacing) {
isNeedLeftSpacing = false
outRect.left = gridSpacingPx - padding
if ((itemPosition + 2) % gridColumnCount == 0) {
outRect.right = gridSpacingPx - padding
} else {
outRect.right = gridSpacingPx / 2
}
} else if ((itemPosition + 2) % gridColumnCount == 0) {
isNeedLeftSpacing = false
outRect.left = gridSpacingPx / 2
outRect.right = gridSpacingPx - padding
} else {
isNeedLeftSpacing = false
outRect.left = gridSpacingPx / 2
outRect.right = gridSpacingPx / 2
}
outRect.bottom = 0
}
}
================================================
FILE: sample/src/main/java/com/anilokcun/uwandroidmediapicker/MainActivity.kt
================================================
package com.anilokcun.uwandroidmediapicker
import android.Manifest
import android.content.pm.PackageManager
import android.graphics.Bitmap
import android.os.Build
import android.os.Bundle
import android.util.DisplayMetrics
import android.view.View
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.app.AppCompatDelegate
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.DefaultItemAnimator
import androidx.recyclerview.widget.GridLayoutManager
import com.anilokcun.uwmediapicker.UwMediaPicker
import com.anilokcun.uwmediapicker.model.UwMediaPickerMediaModel
import kotlinx.android.synthetic.main.activity_main.*
/**
* Author : Anıl Furkan Ökçün
* Author mail : anilfurkanokcun@gmail.com
* Create Date : 30.08.2018
*/
class MainActivity : AppCompatActivity() {
private val selectedMediaGridColumnCount = 5
private val allSelectedMediaPaths by lazy { arrayListOf<String>() }
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
lytRoot.systemUiVisibility =
lytRoot.systemUiVisibility or View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
}
// Get Device Width in Px
val displayMetrics = DisplayMetrics()
windowManager.defaultDisplay.getMetrics(displayMetrics)
val deviceWidth = displayMetrics.widthPixels
val gridSize = deviceWidth / selectedMediaGridColumnCount
// Make compression options inactive
tvMaxWidth.isEnabled = false
etMaxWidth.isEnabled = false
tvMaxHeight.isEnabled = false
etMaxHeight.isEnabled = false
tvQuality.isEnabled = false
etQuality.isEnabled = false
// Set RecyclerView
rvSelectedMedia.layoutManager =
GridLayoutManager(applicationContext, selectedMediaGridColumnCount)
rvSelectedMedia.itemAnimator = DefaultItemAnimator()
rvSelectedMedia.addItemDecoration(GalleryItemDecoration(
resources.getDimensionPixelSize(com.anilokcun.uwmediapicker.R.dimen.uwmediapicker_gallery_spacing),
selectedMediaGridColumnCount
))
rvSelectedMedia.adapter = SelectedMediaRvAdapter(allSelectedMediaPaths, gridSize)
setListeners()
}
private fun setListeners() {
/* Image Compression Option Switch's CheckedChangeListener */
switchImageCompression.setOnCheckedChangeListener { _, isChecked ->
tvMaxWidth.isEnabled = isChecked
etMaxWidth.isEnabled = isChecked
tvMaxHeight.isEnabled = isChecked
etMaxHeight.isEnabled = isChecked
tvQuality.isEnabled = isChecked
etQuality.isEnabled = isChecked
lytRoot.requestFocus()
}
/* Image Gallery Button's ClickListener */
btnOpenImageGallery.setOnClickListener {
requestToOpenImagePicker(PERMISSION_REQUEST_CODE_PICK_IMAGE, UwMediaPicker.GalleryMode.ImageGallery, ::openUwMediaPicker)
}
/* Video Gallery Button's ClickListener */
btnOpenVideoGallery.setOnClickListener {
requestToOpenImagePicker(PERMISSION_REQUEST_CODE_PICK_VIDEO, UwMediaPicker.GalleryMode.VideoGallery, ::openUwMediaPicker)
}
/* Image and Video Gallery Button's ClickListener */
btnImageAndVideoGallery.setOnClickListener {
requestToOpenImagePicker(PERMISSION_REQUEST_CODE_PICK_IMAGE_VIDEO, UwMediaPicker.GalleryMode.ImageAndVideoGallery, ::openUwMediaPicker)
}
}
/** Opens UwMediaPicker for select images*/
private fun openUwMediaPicker(galleryMode: UwMediaPicker.GalleryMode) {
val gridColumnCount =
if (etGridColumnCount.text.isNotEmpty()) {
etGridColumnCount.text.toString().toInt()
} else {
3
}
val maxSelectableMediaCount =
if (etMaxSelectableMediaCount.text.isNotEmpty()) {
etMaxSelectableMediaCount.text.toString().toInt()
} else {
null
}
val maxWidth =
if (etMaxWidth.text.isNotEmpty()) {
etMaxWidth.text.toString().toFloat()
} else {
1280F
}
val maxHeight =
if (etMaxHeight.text.isNotEmpty()) {
etMaxHeight.text.toString().toFloat()
} else {
720F
}
val quality =
if (etQuality.text.isNotEmpty()) {
etQuality.text.toString().toInt()
} else {
85
}
UwMediaPicker.with(this)
.setGalleryMode(galleryMode)
.setGridColumnCount(gridColumnCount)
.setMaxSelectableMediaCount(maxSelectableMediaCount)
.setLightStatusBar(true)
.enableImageCompression(switchImageCompression.isChecked)
.setCompressionMaxWidth(maxWidth)
.setCompressionMaxHeight(maxHeight)
.setCompressFormat(Bitmap.CompressFormat.JPEG)
.setCompressionQuality(quality)
.setCompressedFileDestinationPath("${application.getExternalFilesDir(null)!!.path}/Pictures")
.setCancelCallback(::onMediaSelectionCancelled)
.launch(::onMediaSelected)
}
private fun onMediaSelected(selectedMediaList: List<UwMediaPickerMediaModel>?) {
if (selectedMediaList != null) {
val selectedMediaPathList = selectedMediaList.map { it.mediaPath }
allSelectedMediaPaths.addAll(selectedMediaPathList)
(rvSelectedMedia.adapter as SelectedMediaRvAdapter).update(allSelectedMediaPaths)
tvSelectedMediaTitle.visibility = View.VISIBLE
} else {
Toast.makeText(this, "Unexpected Error", Toast.LENGTH_SHORT).show()
}
}
private fun onMediaSelectionCancelled(){
Toast.makeText(this, "Media Selection Cancelled ", Toast.LENGTH_SHORT).show()
}
/** Request to open Image Picker Intent and Handle the permissions */
private fun requestToOpenImagePicker(requestCode: Int, galleryMode: UwMediaPicker.GalleryMode, openMediaPickerFunc: (UwMediaPicker.GalleryMode) -> Unit) {
if (ContextCompat.checkSelfPermission(this.applicationContext,
Manifest.permission.READ_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED) {
// Permission is not granted
if (ActivityCompat.shouldShowRequestPermissionRationale(this,
Manifest.permission.READ_EXTERNAL_STORAGE)) {
// First time
ActivityCompat.requestPermissions(this,
arrayOf(Manifest.permission.READ_EXTERNAL_STORAGE), requestCode)
} else {
// Not first time
ActivityCompat.requestPermissions(this,
arrayOf(Manifest.permission.READ_EXTERNAL_STORAGE), requestCode)
}
} else {
// Permission has already been granted
openMediaPickerFunc.invoke(galleryMode)
}
}
/** Handles Media Pick Request */
private fun handleMediaPickPermissionRequest(grantResults: IntArray, galleryMode: UwMediaPicker.GalleryMode, openMediaPicker: (UwMediaPicker.GalleryMode) -> Unit) {
// If request is cancelled, the result arrays are empty.
if ((grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED)) {
// Permission granted
openMediaPicker.invoke(galleryMode)
} else {
// Permission denied
if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.READ_EXTERNAL_STORAGE)) {
// Without "Never Ask Again" Checked
Toast.makeText(this, "Without permission you cant do that.", Toast.LENGTH_SHORT).show()
} else {
// With "Never Ask Again" Checked
Toast.makeText(this, "You need to give permission. Go to Settings...", Toast.LENGTH_SHORT).show()
}
}
return
}
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<String>, grantResults: IntArray) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
when (requestCode) {
PERMISSION_REQUEST_CODE_PICK_IMAGE -> {
handleMediaPickPermissionRequest(grantResults, UwMediaPicker.GalleryMode.ImageGallery, ::openUwMediaPicker)
}
PERMISSION_REQUEST_CODE_PICK_VIDEO -> {
handleMediaPickPermissionRequest(grantResults, UwMediaPicker.GalleryMode.VideoGallery, ::openUwMediaPicker)
}
PERMISSION_REQUEST_CODE_PICK_IMAGE_VIDEO -> {
handleMediaPickPermissionRequest(grantResults, UwMediaPicker.GalleryMode.ImageAndVideoGallery, ::openUwMediaPicker)
}
}
}
companion object {
const val PERMISSION_REQUEST_CODE_PICK_IMAGE = 9
const val PERMISSION_REQUEST_CODE_PICK_VIDEO = 10
const val PERMISSION_REQUEST_CODE_PICK_IMAGE_VIDEO = 11
init {
// For using vector drawables on lower APIs
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true)
}
}
}
================================================
FILE: sample/src/main/java/com/anilokcun/uwandroidmediapicker/SelectedMediaRvAdapter.kt
================================================
package com.anilokcun.uwandroidmediapicker
import android.graphics.drawable.ColorDrawable
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.bumptech.glide.request.RequestOptions
import java.util.*
/**
* Author : Anıl Furkan Ökçün
* Author mail : anilfurkanokcun@gmail.com
* Create Date : 30.08.2018
*/
internal class SelectedMediaRvAdapter(
private var itemList: ArrayList<String>,
private val gridSize: Int
) : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
/** Creates View for each item in the List */
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
return MediaVH(ImageView(parent.context).apply {
RecyclerView.LayoutParams(gridSize, gridSize)
adjustViewBounds = true
})
}
/** Binds the data on the List */
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
Glide.with(holder.itemView.context)
.load(itemList[position])
.apply(
RequestOptions()
.override(gridSize).centerCrop()
.placeholder(ColorDrawable(ContextCompat
.getColor(holder.itemView.context, R.color.colorImagePlaceHolder))))
.into(holder.itemView as ImageView)
}
/** Gets the 'Size of the List' or 'Item count in the RecyclerView'*/
override fun getItemCount(): Int = itemList.size
fun update(list: ArrayList<String>) {
itemList = list
notifyDataSetChanged()
}
class MediaVH(itemView: View) : RecyclerView.ViewHolder(itemView)
}
================================================
FILE: sample/src/main/res/color/color_text_activatable.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Active -->
<item android:color="@color/colorText" android:state_enabled="true" />
<!-- Inactive-->
<item android:color="@color/colorTextInactive" android:state_enabled="false" />
</selector>
================================================
FILE: sample/src/main/res/drawable/ic_launcher_background.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="108dp"
android:height="108dp"
android:viewportHeight="108"
android:viewportWidth="108">
<path
android:fillColor="#26A69A"
android:pathData="M0,0h108v108h-108z" />
<path
android:fillColor="#00000000"
android:pathData="M9,0L9,108"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M19,0L19,108"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M29,0L29,108"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M39,0L39,108"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M49,0L49,108"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M59,0L59,108"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M69,0L69,108"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M79,0L79,108"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M89,0L89,108"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M99,0L99,108"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M0,9L108,9"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M0,19L108,19"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M0,29L108,29"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M0,39L108,39"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M0,49L108,49"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M0,59L108,59"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M0,69L108,69"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M0,79L108,79"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M0,89L108,89"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M0,99L108,99"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M19,29L89,29"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M19,39L89,39"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M19,49L89,49"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M19,59L89,59"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M19,69L89,69"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M19,79L89,79"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M29,19L29,89"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M39,19L39,89"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M49,19L49,89"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M59,19L59,89"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M69,19L69,89"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M79,19L79,89"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
</vector>
================================================
FILE: sample/src/main/res/drawable/selector_bg_et.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Pressed -->
<item android:drawable="@drawable/shape_bg_et_active" android:state_focused="true"/>
<!-- Default -->
<item android:drawable="@drawable/shape_bg_et_default" />
</selector>
================================================
FILE: sample/src/main/res/drawable/shape_bg_btn.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<stroke
android:width="1dp"
android:color="@color/colorAccent" />
<corners android:radius="5dp" />
<solid android:color="@color/white"/>
</shape>
================================================
FILE: sample/src/main/res/drawable/shape_bg_et_active.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<stroke
android:width="1dp"
android:color="@color/colorAccent" />
<solid android:color="@color/colorPrimaryDark" />
<corners android:radius="5dp" />
</shape>
================================================
FILE: sample/src/main/res/drawable/shape_bg_et_default.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<stroke
android:width="1dp"
android:color="@color/silver" />
<solid android:color="@color/colorPrimaryDark" />
<corners android:radius="5dp" />
</shape>
================================================
FILE: sample/src/main/res/drawable/shape_bg_option.xml
================================================
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:bottom="0dp"
android:left="-2px"
android:right="-2px"
android:top="-2px">
<shape android:shape="rectangle">
<solid android:color="@color/white" />
<stroke
android:width="1px"
android:color="@color/silverDarken" />
</shape>
</item>
</layer-list>
================================================
FILE: sample/src/main/res/drawable/shape_bg_shadow.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:angle="90"
android:centerColor="#0D000000"
android:endColor="#1A000000"
android:startColor="@android:color/transparent" />
</shape>
================================================
FILE: sample/src/main/res/drawable/shape_bg_tv_title.xml
================================================
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:bottom="0dp"
android:left="-2px"
android:right="-2px"
android:top="0dp">
<shape android:shape="rectangle">
<solid android:color="@color/white" />
<stroke
android:width="1px"
android:color="@color/silverDarken" />
</shape>
</item>
</layer-list>
================================================
FILE: sample/src/main/res/drawable-v24/ic_launcher_foreground.xml
================================================
<vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:aapt="http://schemas.android.com/aapt"
android:width="108dp"
android:height="108dp"
android:viewportHeight="108"
android:viewportWidth="108">
<path
android:fillType="evenOdd"
android:pathData="M32,64C32,64 38.39,52.99 44.13,50.95C51.37,48.37 70.14,49.57 70.14,49.57L108.26,87.69L108,109.01L75.97,107.97L32,64Z"
android:strokeColor="#00000000"
android:strokeWidth="1">
<aapt:attr name="android:fillColor">
<gradient
android:endX="78.5885"
android:endY="90.9159"
android:startX="48.7653"
android:startY="61.0927"
android:type="linear">
<item
android:color="#44000000"
android:offset="0.0" />
<item
android:color="#00000000"
android:offset="1.0" />
</gradient>
</aapt:attr>
</path>
<path
android:fillColor="#FFFFFF"
android:fillType="nonZero"
android:pathData="M66.94,46.02L66.94,46.02C72.44,50.07 76,56.61 76,64L32,64C32,56.61 35.56,50.11 40.98,46.06L36.18,41.19C35.45,40.45 35.45,39.3 36.18,38.56C36.91,37.81 38.05,37.81 38.78,38.56L44.25,44.05C47.18,42.57 50.48,41.71 54,41.71C57.48,41.71 60.78,42.57 63.68,44.05L69.11,38.56C69.84,37.81 70.98,37.81 71.71,38.56C72.44,39.3 72.44,40.45 71.71,41.19L66.94,46.02ZM62.94,56.92C64.08,56.92 65,56.01 65,54.88C65,53.76 64.08,52.85 62.94,52.85C61.8,52.85 60.88,53.76 60.88,54.88C60.88,56.01 61.8,56.92 62.94,56.92ZM45.06,56.92C46.2,56.92 47.13,56.01 47.13,54.88C47.13,53.76 46.2,52.85 45.06,52.85C43.92,52.85 43,53.76 43,54.88C43,56.01 43.92,56.92 45.06,56.92Z"
android:strokeColor="#00000000"
android:strokeWidth="1" />
</vector>
================================================
FILE: sample/src/main/res/layout/activity_main.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/lytRoot"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusable="true"
android:clickable="true"
android:focusableInTouchMode="true"
android:background="@color/colorPageBackground"
tools:context=".MainActivity">
<TextView
android:layout_width="match_parent"
android:layout_height="@dimen/toolbar_height"
android:background="@color/white"
android:gravity="center"
android:text="@string/app_name"
android:textColor="@color/colorText"
android:textSize="@dimen/font_20"
android:textStyle="bold" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="@dimen/toolbar_height">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout style="@style/LytOption">
<TextView
style="@style/TvOption"
android:text="@string/grid_column_count" />
<EditText
android:id="@+id/etGridColumnCount"
android:text="3"
style="@style/EditText" />
</LinearLayout>
<LinearLayout style="@style/LytOption">
<TextView
style="@style/TvOption"
android:text="@string/max_selectable_media_count" />
<EditText
android:id="@+id/etMaxSelectableMediaCount"
style="@style/EditText" />
</LinearLayout>
<Switch
android:id="@+id/switchImageCompression"
style="@style/SwitchOption"
android:text="@string/image_compression" />
<LinearLayout style="@style/LytOption">
<TextView
android:id="@+id/tvMaxWidth"
style="@style/TvOption"
android:textColor="@color/color_text_activatable"
android:text="@string/compression_max_width" />
<EditText
android:id="@+id/etMaxWidth"
android:textColor="@color/color_text_activatable"
android:text="1280"
style="@style/EditText" />
</LinearLayout>
<LinearLayout style="@style/LytOption">
<TextView
android:id="@+id/tvMaxHeight"
style="@style/TvOption"
android:textColor="@color/color_text_activatable"
android:text="@string/compression_max_height" />
<EditText
android:id="@+id/etMaxHeight"
android:textColor="@color/color_text_activatable"
android:text="720"
style="@style/EditText" />
</LinearLayout>
<LinearLayout style="@style/LytOption">
<TextView
android:id="@+id/tvQuality"
style="@style/TvOption"
android:textColor="@color/color_text_activatable"
android:text="@string/compression_quality" />
<EditText
android:id="@+id/etQuality"
style="@style/EditText"
android:text="85"
android:textColor="@color/color_text_activatable"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/spacing_normal"
android:orientation="horizontal"
android:paddingEnd="@dimen/spacing_normal"
android:paddingStart="@dimen/spacing_normal">
<Button
android:id="@+id/btnOpenImageGallery"
style="@style/Button"
android:layout_marginEnd="@dimen/spacing_small"
android:layout_weight="1"
android:text="@string/image_gallery" />
<Button
android:id="@+id/btnOpenVideoGallery"
style="@style/Button"
android:layout_marginStart="@dimen/spacing_small"
android:layout_weight="1"
android:text="@string/video_gallery" />
<Button
android:id="@+id/btnImageAndVideoGallery"
style="@style/Button"
android:layout_marginStart="@dimen/spacing_small"
android:layout_weight="1"
android:text="@string/image_and_video_gallery" />
</LinearLayout>
<TextView
android:id="@+id/tvSelectedMediaTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/spacing_normal"
android:background="@drawable/shape_bg_tv_title"
android:gravity="center"
android:padding="@dimen/spacing_small"
android:text="@string/selected_media_title"
android:textColor="@color/colorText"
android:textSize="17sp"
android:visibility="gone" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rvSelectedMedia"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="1dp"/>
</LinearLayout>
</ScrollView>
<View
android:layout_width="match_parent"
android:layout_height="@dimen/shadow_height"
android:layout_marginTop="@dimen/toolbar_height"
android:background="@drawable/shape_bg_shadow" />
</FrameLayout>
================================================
FILE: sample/src/main/res/mipmap-anydpi-v26/ic_launcher.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@drawable/ic_launcher_background" />
<foreground android:drawable="@drawable/ic_launcher_foreground" />
</adaptive-icon>
================================================
FILE: sample/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@drawable/ic_launcher_background" />
<foreground android:drawable="@drawable/ic_launcher_foreground" />
</adaptive-icon>
================================================
FILE: sample/src/main/res/values/colors.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#FFFFFF</color>
<color name="colorPrimaryDark">#F6F6F6</color>
<color name="colorAccent">#0192d2</color>
<color name="colorPageBackground">#F4F5F6</color>
<color name="colorImagePlaceHolder">#FCFCFC</color>
<color name="white">#FFFFFF</color>
<color name="colorText">#202020</color>
<color name="colorTextInactive">#A6A6A6</color>
<color name="silverDarken">#A6A6A6</color>
<color name="silver">#CDCDCD</color>
</resources>
================================================
FILE: sample/src/main/res/values/dimens.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Font Sizes-->
<dimen name="font_20">20sp</dimen>
<dimen name="font_15">15sp</dimen>
<!-- Spacing -->
<dimen name="spacing_normal">16dp</dimen>
<dimen name="spacing_small">8dp</dimen>
<!-- Sizes -->
<dimen name="toolbar_height">48dp</dimen>
<dimen name="option_min_height">48dp</dimen>
<dimen name="shadow_height">4dp</dimen>
</resources>
================================================
FILE: sample/src/main/res/values/strings.xml
================================================
<resources>
<string name="app_name">UW Media Picker - Android</string>
<string name="max_selectable_media_count">Maximum selectable media count</string>
<string name="grid_column_count">Grid column count</string>
<string name="image_compression">Image compression</string>
<string name="compression_max_width">Compression maximum width</string>
<string name="compression_max_height">Compression maximum height</string>
<string name="compression_quality">Compression quality(%)</string>
<string name="image_gallery">Image Gallery</string>
<string name="video_gallery">Video Gallery</string>
<string name="image_and_video_gallery">Image & Video Gallery</string>
<string name="selected_media_title">Selected Media</string>
</resources>
================================================
FILE: sample/src/main/res/values/styles.xml
================================================
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="ViewBaseOption">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:minHeight">@dimen/option_min_height</item>
<item name="android:background">@drawable/shape_bg_option</item>
<item name="android:gravity">center_vertical</item>
<item name="android:paddingStart">@dimen/spacing_normal</item>
<item name="android:paddingEnd">@dimen/spacing_normal</item>
<item name="android:paddingTop">@dimen/spacing_small</item>
<item name="android:paddingBottom">@dimen/spacing_small</item>
</style>
<style name="LytOption" parent="ViewBaseOption">
<item name="android:orientation">horizontal</item>
</style>
<!-- TextView -->
<style name="TvOption">
<item name="android:layout_width">0dp</item>
<item name="android:layout_height">match_parent</item>
<item name="android:layout_weight">1</item>
<item name="android:gravity">center_vertical</item>
<item name="android:textAppearance">@style/textOption</item>
<item name="android:layout_marginEnd">@dimen/spacing_normal</item>
</style>
<!-- EditText -->
<style name="EditText">
<item name="android:layout_width">48dp</item>
<item name="android:layout_height">28dp</item>
<item name="android:background">@drawable/selector_bg_et</item>
<item name="android:gravity">center</item>
<item name="android:inputType">number</item>
<item name="android:textSize">@dimen/font_15</item>
<item name="android:textColor">@color/colorText</item>
</style>
<!-- Button -->
<style name="Button" parent="Base.Widget.AppCompat.Button.Borderless">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:minHeight">0dp</item>
<item name="android:background">@drawable/shape_bg_btn</item>
<item name="android:gravity">center</item>
<item name="android:paddingStart">@dimen/spacing_small</item>
<item name="android:paddingEnd">@dimen/spacing_small</item>
<item name="android:paddingTop">@dimen/spacing_small</item>
<item name="android:paddingBottom">@dimen/spacing_small</item>
<item name="android:textSize">@dimen/font_15</item>
<item name="android:textColor">@color/colorAccent</item>
</style>
<!-- Switch -->
<style name="SwitchBlueTheme">
<item name="colorControlActivated">@color/colorAccent</item>
<item name="android:colorForeground">@color/silverDarken</item>
</style>
<style name="SwitchOption" parent="ViewBaseOption">
<item name="android:switchPadding">@dimen/spacing_small</item>
<item name="android:theme">@style/SwitchBlueTheme</item>
<item name="android:textAppearance">@style/textOption</item>
<item name="android:textColor">@color/colorText</item>
</style>
<!-- Text Appearance -->
<style name="textOption" parent="@android:style/TextAppearance">
<item name="android:textColor">@color/colorText</item>
<item name="android:textSize">@dimen/font_15</item>
</style>
</resources>
================================================
FILE: settings.gradle
================================================
include ':sample', ':uwmediapicker'
================================================
FILE: uwmediapicker/.gitignore
================================================
/build
================================================
FILE: uwmediapicker/build.gradle
================================================
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin-android-extensions'
ext {
libraryName = 'UW Media Picker - Android'
libraryDescription = 'Easy to use and customizable media picker library to pick multiple images(with compression) and videos for Android.'
siteUrl = 'https://github.com/AnilFurkanOkcun/UWMediaPicker-Android'
gitUrl = 'https://github.com/AnilFurkanOkcun/UWMediaPicker-Android.git'
developerId = 'AnilFurkanOkcun'
developerName = 'Anıl Furkan Ökçün'
developerEmail = 'anilfurkanokcun@gmail.com'
licenseName = 'The Apache 2.0 License'
licenseUrl = 'https://github.com/AnilFurkanOkcun/UWMediaPicker-Android/blob/master/LICENSE'
allLicenses = ["Apache 2.0"]
}
android {
compileSdkVersion projectConfig.compile_sdk
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
defaultConfig {
applicationId projectConfig.applicationId
minSdkVersion projectConfig.min_sdk
targetSdkVersion projectConfig.target_sdk
versionCode projectConfig.version_code
versionName projectConfig.version_name
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
// Android
implementation 'androidx.appcompat:appcompat:1.4.0'
implementation "androidx.fragment:fragment-ktx:1.4.0"
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.2'
implementation 'androidx.recyclerview:recyclerview:1.2.1'
implementation 'androidx.exifinterface:exifinterface:1.3.3'
// Glide
implementation "com.github.bumptech.glide:glide:$versions.glide"
}
================================================
FILE: uwmediapicker/proguard-rules.pro
================================================
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
================================================
FILE: uwmediapicker/src/main/AndroidManifest.xml
================================================
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.anilokcun.uwmediapicker">
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
</manifest>
================================================
FILE: uwmediapicker/src/main/java/com/anilokcun/uwmediapicker/ImageCompressor.kt
================================================
package com.anilokcun.uwmediapicker
import android.graphics.*
import androidx.exifinterface.media.ExifInterface
import com.anilokcun.uwmediapicker.helper.logError
import java.io.File
import java.io.FileOutputStream
import java.io.IOException
import java.text.SimpleDateFormat
import java.util.*
/**
* Author : Anıl Furkan Ökçün
* Author mail : anilfurkanokcun@gmail.com
* Create Date : 30.08.2018
*/
internal class ImageCompressor(private val maxWidth: Float, private val maxHeight: Float,
private val compressFormat: Bitmap.CompressFormat,
private val quality: Int, private val destinationPath: String?) {
/** Compresses the given image and @return File*/
@Throws(IOException::class)
fun compress(imageFile: File): File {
var compressedFilePath = destinationPath + File.separator + getImageFileName(imageFile.extension)
var i = 0
while (File(compressedFilePath).exists()) {
compressedFilePath = destinationPath + File.separator + getImageFileName(imageFile.extension, i++)
}
var fileOutputStream: FileOutputStream? = null
val destinationParentFile = File(compressedFilePath).parentFile
if (destinationParentFile?.exists() == false) {
destinationParentFile.mkdirs()
}
try {
fileOutputStream = FileOutputStream(compressedFilePath)
decodeSampledBitmapFromFile(imageFile, maxWidth, maxHeight)?.compress(compressFormat, quality, fileOutputStream)
} catch (e: Exception) {
e.message.logError()
} finally {
fileOutputStream?.flush()
fileOutputStream?.close()
}
return File(compressedFilePath)
}
/** Decodes Sampled Bitmap from File and @return Bitmap with given maxWidth and maxHeight */
@Throws(IOException::class)
fun decodeSampledBitmapFromFile(imageFile: File, maxWidth: Float, maxHeight: Float): Bitmap? {
var scaledBitmap: Bitmap? = null
var bitmap: Bitmap?
val bitmapFactoryOptions = BitmapFactory.Options()
// Decode with inJustDecodeBounds=true to get dimensions
bitmapFactoryOptions.inJustDecodeBounds = true
bitmap = BitmapFactory.decodeFile(imageFile.absolutePath, bitmapFactoryOptions)
var imgHeight = bitmapFactoryOptions.outHeight
var imgWidth = bitmapFactoryOptions.outWidth
val imgAspectRatio = imgWidth.toFloat() / imgHeight.toFloat()
val maxAspectRatio = maxWidth / maxHeight
// Calculate width and height according to max size values
if (imgHeight > maxHeight || imgWidth > maxWidth) {
when {
imgAspectRatio < maxAspectRatio -> {
imgWidth = ((maxHeight / imgHeight) * imgWidth).toInt()
imgHeight = maxHeight.toInt()
}
imgAspectRatio > maxAspectRatio -> {
imgHeight = ((maxWidth / imgWidth) * imgHeight).toInt()
imgWidth = maxWidth.toInt()
}
else -> {
imgHeight = maxHeight.toInt()
imgWidth = maxWidth.toInt()
}
}
}
bitmapFactoryOptions.inSampleSize = calculateInSampleSize(bitmapFactoryOptions, imgWidth, imgHeight)
bitmapFactoryOptions.inJustDecodeBounds = false
bitmapFactoryOptions.inTempStorage = ByteArray(16 * 1024)
try {
bitmap = BitmapFactory.decodeFile(imageFile.absolutePath, bitmapFactoryOptions)
} catch (e: OutOfMemoryError) {
e.message.logError()
e.printStackTrace()
}
try {
scaledBitmap = Bitmap.createBitmap(imgWidth, imgHeight, Bitmap.Config.ARGB_8888)
} catch (e: OutOfMemoryError) {
e.message.logError()
e.printStackTrace()
}
val ratioX = imgWidth / bitmapFactoryOptions.outWidth.toFloat()
val ratioY = imgHeight / bitmapFactoryOptions.outHeight.toFloat()
val middleX = imgWidth / 2.0f
val middleY = imgHeight / 2.0f
val scaleMatrix = Matrix()
scaleMatrix.setScale(ratioX, ratioY, middleX, middleY)
val canvas = Canvas(scaledBitmap!!)
canvas.setMatrix(scaleMatrix)
canvas.drawBitmap(bitmap!!, middleX - bitmap.width / 2,
middleY - bitmap.height / 2, Paint(Paint.FILTER_BITMAP_FLAG))
bitmap.recycle()
try {
val exif = ExifInterface(imageFile.absolutePath)
val orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 0)
val matrix = Matrix()
when (orientation) {
ExifInterface.ORIENTATION_ROTATE_90 -> matrix.postRotate(90f)
ExifInterface.ORIENTATION_ROTATE_180 -> matrix.postRotate(180f)
ExifInterface.ORIENTATION_ROTATE_270 -> matrix.postRotate(270f)
}
scaledBitmap = Bitmap.createBitmap(scaledBitmap, 0, 0, scaledBitmap.width,
scaledBitmap.height, matrix, true)
} catch (e: IOException) {
e.message.logError()
e.printStackTrace()
}
return scaledBitmap
}
/** Calculates inSampleSize
* https://developer.android.com/topic/performance/graphics/load-bitmap*/
private fun calculateInSampleSize(options: BitmapFactory.Options, reqWidth: Int, reqHeight: Int): Int {
// Raw height and width of image
val (height: Int, width: Int) = options.run { outHeight to outWidth }
var inSampleSize = 1
if (height > reqHeight || width > reqWidth) {
val halfHeight: Int = height / 2
val halfWidth: Int = width / 2
// Calculate the largest inSampleSize value that is a power of 2 and keeps both
// height and width larger than the requested height and width.
while (halfHeight / inSampleSize >= reqHeight && halfWidth / inSampleSize >= reqWidth) {
inSampleSize *= 2
}
}
return inSampleSize
}
/** Returns image file name as IMG_yyyymmdd_hhmmss_index.extension */
private fun getImageFileName(fileExtension: String, index: Int = 0): String {
val dateFormatter = SimpleDateFormat("yyyyMMdd_HHmmss", Locale.UK)
val calendar = Calendar.getInstance()
calendar.timeInMillis = System.currentTimeMillis()
return if (index == 0) {
"IMG_${dateFormatter.format(calendar.time)}.$fileExtension"
} else {
"IMG_${dateFormatter.format(calendar.time)}_$index.$fileExtension"
}
}
}
================================================
FILE: uwmediapicker/src/main/java/com/anilokcun/uwmediapicker/UwMediaPicker.kt
================================================
package com.anilokcun.uwmediapicker
import android.graphics.Bitmap
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment
import com.anilokcun.uwmediapicker.model.UWMediaPickerSettingsModel
import com.anilokcun.uwmediapicker.model.UwMediaPickerMediaModel
import com.anilokcun.uwmediapicker.ui.activity.UwMediaPickerDialogFragment
import java.lang.ref.WeakReference
/**
* Author : Anıl Furkan Ökçün
* Author mail : anilfurkanokcun@gmail.com
* Create Date : 30.08.2018
*/
class UwMediaPicker private constructor() {
private var activityWeakReference: WeakReference<AppCompatActivity>? = null
private var fragmentWeakReference: WeakReference<Fragment>? = null
private var galleryMode: GalleryMode = GalleryMode.ImageGallery
private var maxSelectableMediaCount: Int? = null
private var gridColumnCount: Int = 3
private var lightStatusBar: Boolean = true
private var imageCompressionEnabled: Boolean = false
private var compressionMaxWidth = 1280F
private var compressionMaxHeight = 720F
private var compressFormat: Bitmap.CompressFormat = Bitmap.CompressFormat.JPEG
private var compressionQuality = 85
private var compressedFileDestinationPath: String? = null
private var cancelCallback: (() -> Unit)? = null
fun setGalleryMode(galleryMode: GalleryMode): UwMediaPicker {
this.galleryMode = galleryMode
return this
}
fun setMaxSelectableMediaCount(maxSelectableMediaCount: Int?): UwMediaPicker {
this.maxSelectableMediaCount =
if (maxSelectableMediaCount != null && maxSelectableMediaCount >= 1) {
maxSelectableMediaCount
} else null
return this
}
fun setGridColumnCount(gridColumnCount: Int): UwMediaPicker {
this.gridColumnCount =
if (gridColumnCount >= 1) gridColumnCount
else 1
return this
}
fun setLightStatusBar(lightStatusBar: Boolean): UwMediaPicker {
this.lightStatusBar = lightStatusBar
return this
}
fun enableImageCompression(imageCompressionEnabled: Boolean): UwMediaPicker {
this.imageCompressionEnabled = imageCompressionEnabled
return this
}
fun setCompressionMaxWidth(maxWidth: Float): UwMediaPicker {
this.compressionMaxHeight =
if (maxWidth < 1)
1F
else
maxWidth
return this
}
fun setCompressionMaxHeight(maxHeight: Float): UwMediaPicker {
this.compressionMaxHeight =
if (maxHeight < 1)
1F
else
maxHeight
return this
}
fun setCompressFormat(compressFormat: Bitmap.CompressFormat): UwMediaPicker {
this.compressFormat = compressFormat
return this
}
fun setCompressionQuality(quality: Int): UwMediaPicker {
this.compressionQuality =
when {
quality < 0 -> 0
quality > 100 -> 100
else -> quality
}
return this
}
fun setCompressedFileDestinationPath(destinationDirectoryPath: String): UwMediaPicker {
this.compressedFileDestinationPath = destinationDirectoryPath
return this
}
fun setCancelCallback(cancelCallback: (() -> Unit)): UwMediaPicker {
this.cancelCallback = cancelCallback
return this
}
fun launch(resultCallback: (List<UwMediaPickerMediaModel>?) -> Unit) {
val compressedFileDestinationPathValue = if (compressedFileDestinationPath == null) {
val application = if (activityWeakReference != null) {
activityWeakReference!!.get()!!.application
} else {
fragmentWeakReference!!.get()!!.requireActivity().application
}
"${application.getExternalFilesDir(null)!!.path}/Pictures"
} else {
compressedFileDestinationPath!!
}
val uwMediaPickerSettings = UWMediaPickerSettingsModel(
galleryMode,
maxSelectableMediaCount,
gridColumnCount,
lightStatusBar,
imageCompressionEnabled,
compressionMaxWidth,
compressionMaxHeight,
compressFormat,
compressionQuality,
compressedFileDestinationPathValue
)
val uwMediaPickerDialogFragment = UwMediaPickerDialogFragment.newInstance(uwMediaPickerSettings)
uwMediaPickerDialogFragment.setResultCallback(resultCallback)
cancelCallback?.let(uwMediaPickerDialogFragment::setCancelCallback)
val fragmentManager = if (activityWeakReference != null) {
activityWeakReference!!.get()!!.supportFragmentManager
} else {
fragmentWeakReference!!.get()!!.parentFragmentManager
}
uwMediaPickerDialogFragment.show(fragmentManager, "UwMediaPicker")
}
enum class GalleryMode { ImageGallery, VideoGallery, ImageAndVideoGallery }
companion object {
fun with(activity: AppCompatActivity) =
UwMediaPicker().apply { this.activityWeakReference = WeakReference(activity) }
fun with(fragment: Fragment) =
UwMediaPicker().apply { this.fragmentWeakReference = WeakReference(fragment) }
}
}
================================================
FILE: uwmediapicker/src/main/java/com/anilokcun/uwmediapicker/adapter/GalleryMediaRvAdapter.kt
================================================
package com.anilokcun.uwmediapicker.adapter
import android.content.Context
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.anilokcun.uwmediapicker.R
import com.anilokcun.uwmediapicker.listener.GalleryMediaOnLongClickListener
import com.anilokcun.uwmediapicker.listener.OnRVItemClickListener
import com.anilokcun.uwmediapicker.model.BaseGalleryModel
import com.anilokcun.uwmediapicker.model.GalleryImageModel
import com.anilokcun.uwmediapicker.model.GalleryMediaBucketModel
import com.anilokcun.uwmediapicker.model.GalleryVideoModel
import com.anilokcun.uwmediapicker.viewholder.GalleryImageVH
import com.anilokcun.uwmediapicker.viewholder.GalleryMediaBucketVH
import com.anilokcun.uwmediapicker.viewholder.GalleryVideoVH
import java.util.*
/**
* Author : Anıl Furkan Ökçün
* Author mail : anilfurkanokcun@gmail.com
* Create Date : 30.08.2018
*/
internal class GalleryMediaRvAdapter(
private var itemList: ArrayList<out BaseGalleryModel>,
private val galleryGridSize: Int,
private val galleryTextSize: Float,
private val onRVItemClickListener: OnRVItemClickListener,
private val galleryMediaOnLongClickListener: GalleryMediaOnLongClickListener? = null
) : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
var context: Context? = null
/** Creates View for each item in the List */
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
// Get context
if (context == null) context = parent.context
return when (viewType) {
// Gallery Media Bucket;
BaseGalleryModel.TYPE_GALLERY_MEDIA_BUCKET -> GalleryMediaBucketVH(LayoutInflater.from(context)
.inflate(R.layout.uwmediapicker_item_gallery_media_bucket, parent, false))
// Gallery Video;
BaseGalleryModel.TYPE_GALLERY_VIDEO -> GalleryVideoVH(LayoutInflater.from(context)
.inflate(R.layout.uwmediapicker_item_gallery_video, parent, false))
// Gallery Image;
BaseGalleryModel.TYPE_GALLERY_IMAGE -> GalleryImageVH(LayoutInflater.from(context)
.inflate(R.layout.uwmediapicker_item_gallery_image, parent, false))
// Error;
else -> throw IllegalArgumentException("UW Media Picker: Missing view type exception ViewType: $viewType")
}
}
/** Binds the data on the List */
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
when (itemList[position].itemType) {
// Gallery Media Bucket;
BaseGalleryModel.TYPE_GALLERY_MEDIA_BUCKET -> (holder as GalleryMediaBucketVH).bind(itemList[position] as GalleryMediaBucketModel, galleryGridSize, galleryTextSize, onRVItemClickListener)
// Gallery Video;
BaseGalleryModel.TYPE_GALLERY_VIDEO -> (holder as GalleryVideoVH).bind(itemList[position] as GalleryVideoModel, galleryGridSize, galleryTextSize, onRVItemClickListener)
// Gallery Image;
BaseGalleryModel.TYPE_GALLERY_IMAGE -> (holder as GalleryImageVH).bind(itemList[position] as GalleryImageModel, galleryGridSize, onRVItemClickListener, galleryMediaOnLongClickListener)
// Error;
else -> throw RuntimeException("UW Media Picker: Missing view type exception ViewType: ${itemList[position].itemType}")
}
}
/** Gets the 'Size of the List' or 'Item count in the RecyclerView'*/
override fun getItemCount(): Int = itemList.size
/** Gets the Type of the Item in the List*/
override fun getItemViewType(position: Int): Int = itemList[position].itemType
}
================================================
FILE: uwmediapicker/src/main/java/com/anilokcun/uwmediapicker/helper/Extensions.kt
================================================
package com.anilokcun.uwmediapicker.helper
import android.content.Context
import android.net.Uri
import android.util.Log
import android.widget.Toast
import com.anilokcun.uwmediapicker.BuildConfig
/**
* Author : Anıl Furkan Ökçün
* Author mail : anilfurkanokcun@gmail.com
* Create Date : 30.08.2018
*/
/** Extension for simplify create basic Toast Message with String resource */
internal fun Context.toastStringRes(resId: Int, duration: Int = Toast.LENGTH_SHORT): Toast {
return Toast.makeText(this, this.getString(resId), duration).apply { show() }
}
/** Converts strings to uri */
internal fun String.toUri(): Uri = Uri.parse("file://$this")
/** Logs Error */
internal fun String?.logError() {
if (BuildConfig.DEBUG) {
Log.e("UwMediaPicker", this.toString())
}
}
================================================
FILE: uwmediapicker/src/main/java/com/anilokcun/uwmediapicker/listener/GalleryMediaOnLongClickListener.kt
================================================
package com.anilokcun.uwmediapicker.listener
/**
* Author : Anıl Furkan Ökçün
* Author mail : anilfurkanokcun@gmail.com
* Create Date : 30.08.2018
*/
internal interface GalleryMediaOnLongClickListener {
fun onLongClick(imagePath: String?)
}
================================================
FILE: uwmediapicker/src/main/java/com/anilokcun/uwmediapicker/listener/OnRVItemClickListener.kt
================================================
package com.anilokcun.uwmediapicker.listener
/**
* Author : Anıl Furkan Ökçün
* Author mail : anilfurkanokcun@gmail.com
* Create Date : 30.08.2018
*/
internal interface OnRVItemClickListener {
fun onClick(position: Int)
}
================================================
FILE: uwmediapicker/src/main/java/com/anilokcun/uwmediapicker/model/BaseGalleryMediaModel.kt
================================================
package com.anilokcun.uwmediapicker.model
/**
* Author : Anıl Furkan Ökçün
* Author mail : anilfurkanokcun@gmail.com
* Create Date : 30.08.2018
*/
internal interface BaseGalleryMediaModel : BaseGalleryModel {
val mediaPath: String?
var selected: Boolean
}
================================================
FILE: uwmediapicker/src/main/java/com/anilokcun/uwmediapicker/model/BaseGalleryModel.kt
================================================
package com.anilokcun.uwmediapicker.model
/**
* Author : Anıl Furkan Ökçün
* Author mail : anilfurkanokcun@gmail.com
* Create Date : 30.08.2018
*/
internal interface BaseGalleryModel {
val itemType: Int
companion object {
/* Gallery Item Types */
const val TYPE_GALLERY_MEDIA_BUCKET = 600
const val TYPE_GALLERY_IMAGE = 601
const val TYPE_GALLERY_VIDEO = 602
}
}
================================================
FILE: uwmediapicker/src/main/java/com/anilokcun/uwmediapicker/model/GalleryImageModel.kt
================================================
package com.anilokcun.uwmediapicker.model
/**
* Author : Anıl Furkan Ökçün
* Author mail : anilfurkanokcun@gmail.com
* Create Date : 30.08.2018
*/
internal data class GalleryImageModel(
override val mediaPath: String?,
override var selected: Boolean,
override val itemType: Int = BaseGalleryModel.TYPE_GALLERY_IMAGE
) : BaseGalleryModel, BaseGalleryMediaModel
================================================
FILE: uwmediapicker/src/main/java/com/anilokcun/uwmediapicker/model/GalleryMediaBucketModel.kt
================================================
package com.anilokcun.uwmediapicker.model
/**
* Author : Anıl Furkan Ökçün
* Author mail : anilfurkanokcun@gmail.com
* Create Date : 30.08.2018
*/
internal data class GalleryMediaBucketModel(
val id: String?,
val name: String?,
val coverImagePath: String?,
val mediaCount: Int?,
override val itemType: Int = BaseGalleryModel.TYPE_GALLERY_MEDIA_BUCKET
) : BaseGalleryModel
================================================
FILE: uwmediapicker/src/main/java/com/anilokcun/uwmediapicker/model/GalleryVideoModel.kt
================================================
package com.anilokcun.uwmediapicker.model
/**
* Author : Anıl Furkan Ökçün
* Author mail : anilfurkanokcun@gmail.com
* Create Date : 30.08.2018
*/
internal data class GalleryVideoModel(
override val mediaPath: String?,
override var selected: Boolean,
val videoDuration: Long,
val videoSize: String?,
override val itemType: Int = BaseGalleryModel.TYPE_GALLERY_VIDEO
) : BaseGalleryModel, BaseGalleryMediaModel
================================================
FILE: uwmediapicker/src/main/java/com/anilokcun/uwmediapicker/model/UWMediaPickerSettingsModel.kt
================================================
package com.anilokcun.uwmediapicker.model
import android.graphics.Bitmap
import android.os.Parcelable
import com.anilokcun.uwmediapicker.UwMediaPicker
import kotlinx.android.parcel.Parcelize
/**
* Author : Anıl Furkan Ökçün
* Author mail : anilfurkanokcun@gmail.com
* Create Date : 30.08.2018
*/
@Parcelize
data class UWMediaPickerSettingsModel(
val galleryMode: UwMediaPicker.GalleryMode,
val maxSelectableMediaCount: Int?,
val gridColumnCount: Int,
val lightStatusBar: Boolean,
val imageCompressionEnabled: Boolean,
val compressionMaxWidth: Float,
val compressionMaxHeight: Float,
val compressFormat: Bitmap.CompressFormat,
val compressionQuality: Int,
val compressedFileDestinationPath: String
) : Parcelable
================================================
FILE: uwmediapicker/src/main/java/com/anilokcun/uwmediapicker/model/UwMediaPickerMediaModel.kt
================================================
package com.anilokcun.uwmediapicker.model
import android.os.Parcelable
import kotlinx.android.parcel.Parcelize
@Parcelize
data class UwMediaPickerMediaModel(
var mediaPath: String,
val mediaType: UwMediaPickerMediaType
) : Parcelable
================================================
FILE: uwmediapicker/src/main/java/com/anilokcun/uwmediapicker/model/UwMediaPickerMediaType.kt
================================================
package com.anilokcun.uwmediapicker.model
enum class UwMediaPickerMediaType {
IMAGE, VIDEO
}
================================================
FILE: uwmediapicker/src/main/java/com/anilokcun/uwmediapicker/provider/GalleryMediaDataProvider.kt
================================================
package com.anilokcun.uwmediapicker.provider
import android.content.Context
import android.database.Cursor
import android.net.Uri
import android.provider.MediaStore
import com.anilokcun.uwmediapicker.model.BaseGalleryMediaModel
import com.anilokcun.uwmediapicker.model.GalleryImageModel
import com.anilokcun.uwmediapicker.model.GalleryMediaBucketModel
import com.anilokcun.uwmediapicker.model.GalleryVideoModel
import java.io.File
import java.util.*
/**
* Author : Anıl Furkan Ökçün
* Author mail : anilfurkanokcun@gmail.com
* Create Date : 30.08.2018
*/
internal class GalleryMediaDataProvider(private val context: Context) {
private fun getSelectionImageAndVideo() =
"(${MediaStore.Files.FileColumns.MEDIA_TYPE}=${MediaStore.Files.FileColumns.MEDIA_TYPE_IMAGE}" +
" OR ${MediaStore.Files.FileColumns.MEDIA_TYPE}=${MediaStore.Files.FileColumns.MEDIA_TYPE_VIDEO})"
private fun getSelectionImageByBucketId(bucketId: String) = "${MediaStore.MediaColumns.BUCKET_ID}=$bucketId"
private fun getSelectionVideoByBucketId(bucketId: String) = "${MediaStore.MediaColumns.BUCKET_ID}=$bucketId"
private fun getSelectionImageAndVideoByBucketId(bucketId: String) = "${getSelectionImageAndVideo()} AND ${MediaStore.MediaColumns.BUCKET_ID}=$bucketId"
fun getImageAndVideoBuckets(): ArrayList<GalleryMediaBucketModel> {
val queryUri = MediaStore.Files.getContentUri("external")
val cursor = context.contentResolver.query(
queryUri,
arrayOf(MediaStore.MediaColumns.BUCKET_ID, MediaStore.MediaColumns.BUCKET_DISPLAY_NAME, MediaStore.MediaColumns.DATA),
getSelectionImageAndVideo(), null, MediaStore.MediaColumns.DATE_ADDED)
return getBuckets(cursor, queryUri, ::getSelectionImageAndVideoByBucketId)
}
/** Get Media Buckets that contains Images with BucketId, BucketName, BucketCoverImagePath, BucketMediaCount */
fun getImageBuckets(): ArrayList<GalleryMediaBucketModel> {
val cursor = context.contentResolver.query(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
arrayOf(MediaStore.MediaColumns.BUCKET_ID, MediaStore.MediaColumns.BUCKET_DISPLAY_NAME, MediaStore.MediaColumns.DATA),
null, null, MediaStore.Images.Media.DATE_ADDED)
return getBuckets(cursor, MediaStore.Images.Media.EXTERNAL_CONTENT_URI, ::getSelectionImageByBucketId)
}
/** Get Media Buckets that contains Videos with BucketId, BucketName, BucketCoverImagePath, BucketMediaCount */
fun getVideoBuckets(): ArrayList<GalleryMediaBucketModel> {
val cursor = context.contentResolver.query(
MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
arrayOf(MediaStore.MediaColumns.BUCKET_ID, MediaStore.MediaColumns.BUCKET_DISPLAY_NAME, MediaStore.MediaColumns.DATA),
null, null, MediaStore.Video.Media.DATE_ADDED)
return getBuckets(cursor, MediaStore.Video.Media.EXTERNAL_CONTENT_URI, ::getSelectionVideoByBucketId)
}
private fun getBuckets(cursor: Cursor?, queryUri: Uri, getSelectionByBucketIdFunction: (String) -> String): ArrayList<GalleryMediaBucketModel> {
val bucketsList = arrayListOf<GalleryMediaBucketModel>()
val bucketsIdList = HashSet<String>()
if (cursor?.moveToLast() == true) {
do {
if (Thread.interrupted()) {
return arrayListOf()
}
val bucketId = cursor.getString(cursor.getColumnIndex(MediaStore.MediaColumns.BUCKET_ID))
// Skip this bucket if already checked
if (bucketsIdList.contains(bucketId)) continue
bucketsIdList.add(bucketId)
val bucketImagePath = cursor.getString(cursor.getColumnIndex(MediaStore.MediaColumns.DATA))
// Skip this bucket if it's not a File
if (!File(bucketImagePath).exists()) continue
val bucketName = cursor.getString(cursor.getColumnIndex(MediaStore.MediaColumns.BUCKET_DISPLAY_NAME))
val bucketMediaCount = getMediaCount(queryUri, getSelectionByBucketIdFunction(bucketId))
bucketsList.add(GalleryMediaBucketModel(bucketId, bucketName, bucketImagePath, bucketMediaCount))
} while (cursor.moveToPrevious())
}
cursor?.close()
return bucketsList
}
/** Get Images in the Bucket that has given id
* @param bucketId BucketId
* @param selectedMediaPathList, for look to whether media already selected and mark them selected again */
fun getImagesOfBucket(bucketId: String, selectedMediaPathList: List<String>): ArrayList<GalleryImageModel> {
val cursor = context.contentResolver.query(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
arrayOf(MediaStore.MediaColumns.DATA),
"${MediaStore.MediaColumns.BUCKET_ID}=$bucketId", null, MediaStore.Images.Media.DATE_ADDED)
val imagesList = arrayListOf<GalleryImageModel>()
val imagesPathsList = HashSet<String>()
if (cursor?.moveToLast() == true) {
do {
if (Thread.interrupted()) {
return arrayListOf()
}
val imagePath = cursor.getString(cursor.getColumnIndex(MediaStore.MediaColumns.DATA))
// Skip this media if it's already checked or it's not a file
if (imagesPathsList.contains(imagePath)) continue
if (!File(imagePath).exists()) continue
imagesList.add(GalleryImageModel(
imagePath,
selectedMediaPathList.contains(imagePath)))
imagesPathsList.add(imagePath)
} while (cursor.moveToPrevious())
}
cursor?.close()
return imagesList
}
/** Get Videos in the Bucket that has given id
* @param bucketId BucketId
* @param selectedMediaPathList, for look to whether media already selected and mark them selected again */
fun getVideosOfBucket(bucketId: String, selectedMediaPathList: List<String>): ArrayList<GalleryVideoModel> {
val cursor = context.contentResolver.query(
MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
arrayOf(MediaStore.MediaColumns.DATA, MediaStore.Video.VideoColumns.DURATION, MediaStore.Video.VideoColumns.SIZE),
"${MediaStore.MediaColumns.BUCKET_ID}=$bucketId", null, MediaStore.Video.Media.DATE_ADDED)
val videosList = arrayListOf<GalleryVideoModel>()
val videosPathsList = HashSet<String>()
if (cursor?.moveToLast() == true) {
do {
if (Thread.interrupted()) {
return arrayListOf()
}
val videoPath = cursor.getString(cursor.getColumnIndex(MediaStore.MediaColumns.DATA))
// Skip this media if it's already checked or it's not a file
if (videosPathsList.contains(videoPath)) continue
if (!File(videoPath).exists()) continue
val videoDuration = cursor.getLong(cursor.getColumnIndex(MediaStore.Video.VideoColumns.DURATION))
val videoSize = cursor.getString(cursor.getColumnIndex(MediaStore.Video.VideoColumns.SIZE))
videosList.add(GalleryVideoModel(
videoPath,
selectedMediaPathList.contains(videoPath),
videoDuration,
videoSize))
videosPathsList.add(videoPath)
} while (cursor.moveToPrevious())
}
cursor?.close()
return videosList
}
fun getImagesAndVideosOfBucket(bucketId: String, selectedMediaPathList: List<String>): ArrayList<BaseGalleryMediaModel> {
val queryUri = MediaStore.Files.getContentUri("external")
val selection = "(${MediaStore.Files.FileColumns.MEDIA_TYPE}=${MediaStore.Files.FileColumns.MEDIA_TYPE_IMAGE}" +
" OR ${MediaStore.Files.FileColumns.MEDIA_TYPE}=${MediaStore.Files.FileColumns.MEDIA_TYPE_VIDEO})" +
" AND ${MediaStore.MediaColumns.BUCKET_ID}=$bucketId"
val cursor = context.contentResolver.query(
queryUri,
arrayOf(MediaStore.Files.FileColumns.MEDIA_TYPE, MediaStore.Files.FileColumns.DATA, MediaStore.Video.VideoColumns.DURATION, MediaStore.Video.VideoColumns.SIZE),
selection, null, MediaStore.Files.FileColumns.DATE_ADDED)
val imagesAndVideosList = arrayListOf<BaseGalleryMediaModel>()
val imagesPathsList = HashSet<String>()
val videosPathsList = HashSet<String>()
if (cursor?.moveToLast() == true) {
do {
if (Thread.interrupted()) {
return arrayListOf()
}
val mediaType = cursor.getInt(cursor.getColumnIndex(MediaStore.Files.FileColumns.MEDIA_TYPE))
val videoDuration = cursor.getLong(cursor.getColumnIndex(MediaStore.Video.VideoColumns.DURATION))
if (mediaType == MediaStore.Files.FileColumns.MEDIA_TYPE_VIDEO) {
val videoPath = cursor.getString(cursor.getColumnIndex(MediaStore.MediaColumns.DATA))
// Skip this media if it's already checked or it's not a file
if (videosPathsList.contains(videoPath)) continue
if (!File(videoPath).exists()) continue
val videoSize = cursor.getString(cursor.getColumnIndex(MediaStore.Video.VideoColumns.SIZE))
imagesAndVideosList.add(GalleryVideoModel(
videoPath,
selectedMediaPathList.contains(videoPath),
videoDuration,
videoSize))
videosPathsList.add(videoPath)
} else {
val imagePath = cursor.getString(cursor.getColumnIndex(MediaStore.Files.FileColumns.DATA))
// Skip this media if it's already checked or it's not a file
if (imagesPathsList.contains(imagePath)) continue
if (!File(imagePath).exists()) continue
imagesAndVideosList.add(GalleryImageModel(
imagePath,
selectedMediaPathList.contains(imagePath)))
imagesPathsList.add(imagePath)
}
} while (cursor.moveToPrevious())
}
cursor?.close()
return imagesAndVideosList
}
/** Get ImageCount in the Bucket that has given id */
private fun getMediaCount(queryUri: Uri, selection: String): Int {
try {
val cursor = context.contentResolver.query(
queryUri, null,
selection, null, MediaStore.MediaColumns.DATE_ADDED)
if (cursor?.count != null && cursor.count >= 0) {
return cursor.count
}
cursor?.close()
} catch (e: Exception) {
e.printStackTrace()
}
return 0
}
}
================================================
FILE: uwmediapicker/src/main/java/com/anilokcun/uwmediapicker/ui/GalleryItemDecoration.kt
================================================
package com.anilokcun.uwmediapicker.ui
import android.graphics.Rect
import android.view.View
import androidx.recyclerview.widget.RecyclerView
/**
* Author : Anıl Furkan Ökçün
* Author mail : anilfurkanokcun@gmail.com
* Create Date : 30.08.2018
*/
internal class GalleryItemDecoration(
private val gridSpacingPx: Int,
private val gridColumnCount: Int
) : RecyclerView.ItemDecoration() {
private var isNeedLeftSpacing = false
override fun getItemOffsets(outRect: Rect, view: View, parent: RecyclerView, state: RecyclerView.State) {
val frameWidth = ((parent.width - gridSpacingPx.toFloat() * (gridColumnCount - 1)) / gridColumnCount).toInt()
val padding = parent.width / gridColumnCount - frameWidth
val itemPosition = (view.layoutParams as RecyclerView.LayoutParams).viewAdapterPosition
if (itemPosition < gridColumnCount) {
outRect.top = 0
} else {
outRect.top = gridSpacingPx
}
if (itemPosition % gridColumnCount == 0) {
outRect.left = 0
outRect.right = padding
isNeedLeftSpacing = true
} else if ((itemPosition + 1) % gridColumnCount == 0) {
isNeedLeftSpacing = false
outRect.right = 0
outRect.left = padding
} else if (isNeedLeftSpacing) {
isNeedLeftSpacing = false
outRect.left = gridSpacingPx - padding
if ((itemPosition + 2) % gridColumnCount == 0) {
outRect.right = gridSpacingPx - padding
} else {
outRect.right = gridSpacingPx / 2
}
} else if ((itemPosition + 2) % gridColumnCount == 0) {
isNeedLeftSpacing = false
outRect.left = gridSpacingPx / 2
outRect.right = gridSpacingPx - padding
} else {
isNeedLeftSpacing = false
outRect.left = gridSpacingPx / 2
outRect.right = gridSpacingPx / 2
}
outRect.bottom = 0
}
}
================================================
FILE: uwmediapicker/src/main/java/com/anilokcun/uwmediapicker/ui/activity/UwMediaPickerDialogFragment.kt
================================================
package com.anilokcun.uwmediapicker.ui.activity
import android.annotation.SuppressLint
import android.app.Dialog
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.os.Build
import android.os.Bundle
import android.view.*
import android.view.animation.AlphaAnimation
import android.view.animation.Animation
import android.view.animation.LinearInterpolator
import android.widget.Toast
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatDelegate
import androidx.core.content.ContextCompat
import androidx.fragment.app.DialogFragment
import androidx.recyclerview.widget.DefaultItemAnimator
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.anilokcun.uwmediapicker.ImageCompressor
import com.anilokcun.uwmediapicker.R
import com.anilokcun.uwmediapicker.UwMediaPicker
import com.anilokcun.uwmediapicker.adapter.GalleryMediaRvAdapter
import com.anilokcun.uwmediapicker.helper.logError
import com.anilokcun.uwmediapicker.helper.toUri
import com.anilokcun.uwmediapicker.helper.toastStringRes
import com.anilokcun.uwmediapicker.listener.GalleryMediaOnLongClickListener
import com.anilokcun.uwmediapicker.listener.OnRVItemClickListener
import com.anilokcun.uwmediapicker.model.*
import com.anilokcun.uwmediapicker.provider.GalleryMediaDataProvider
import com.anilokcun.uwmediapicker.ui.GalleryItemDecoration
import com.anilokcun.uwmediapicker.ui.dialog.ImagePreviewDialog
import com.google.android.material.snackbar.Snackbar
import kotlinx.android.synthetic.main.activity_uw_media_picker.*
import kotlinx.coroutines.*
import java.io.File
/**
* Author : Anıl Furkan Ökçün
* Author mail : anilfurkanokcun@gmail.com
* Create Date : 30.08.2018
*/
internal class UwMediaPickerDialogFragment : DialogFragment() {
private var job = Job()
private val coroutineScope = CoroutineScope(Dispatchers.Main + job)
private val galleryMediaProvider by lazy { GalleryMediaDataProvider(requireContext()) }
private var resultCallback: ((List<UwMediaPickerMediaModel>?) -> Unit)? = null
private var cancelCallback: (() -> Unit)? = null
private lateinit var settings: UWMediaPickerSettingsModel
private var toastMaxMediaCountError: Toast? = null
private val blinkAnimation: AlphaAnimation by lazy {
// Change alpha from fully visible to invisible
AlphaAnimation(1f, 0f).apply {
this.duration = 300
this.interpolator = LinearInterpolator()
this.repeatCount = 3
this.repeatMode = Animation.REVERSE
}
}
private val imagePreviewDialog by lazy { ImagePreviewDialog() }
private var taskOpenMediaBucket: Deferred<ArrayList<out BaseGalleryMediaModel>>? = null
private val mediaBucketsList by lazy { arrayListOf<GalleryMediaBucketModel>() }
private val mediaList by lazy { arrayListOf<BaseGalleryMediaModel>() }
private val selectedMediaList by lazy { arrayListOf<UwMediaPickerMediaModel>() }
private var lastOpenedBucketName: String? = null
private var lastOpenedBucketId: String? = null
private var isBucketOpened: Boolean = false
private var galleryGridSize = 0
private var galleryTextSize = 10f
// MediaBucket Click Listener
private val galleryMediaBucketClickListener: OnRVItemClickListener by lazy {
object : OnRVItemClickListener {
override fun onClick(position: Int) {
onGalleryMediaBucketClick(position)
}
}
}
// GalleryMedia Click Listener
private val galleryMediaClickListener by lazy {
object : OnRVItemClickListener {
override fun onClick(position: Int) {
onGalleryMediaClick(position)
}
}
}
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val dialog = super.onCreateDialog(savedInstanceState)
// Add back button listener
dialog.setOnKeyListener { _, keyCode, keyEvent ->
// getAction to make sure this doesn't double fire
if (keyCode == KeyEvent.KEYCODE_BACK && keyEvent.action == KeyEvent.ACTION_UP) {
onBackPressed()
true // Capture onKey
} else false
// Don't capture
}
return dialog
}
override fun onStart() {
super.onStart()
dialog?.window?.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)
}
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.activity_uw_media_picker, container, false)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
initPage()
setListeners()
}
override fun getTheme() = R.style.Theme_AppCompat_Light_NoActionBar
/** Adds Listeners to UI elements */
private fun setListeners() {
// Toolbar Back Button
imgToolbarBack.setOnClickListener {
onBackPressed()
}
// Toolbar Done Button
tvToolbarDone.setOnClickListener {
returnResult()
}
}
/** Does initial actions */
private fun initPage() {
// Get Settings
settings = arguments?.getParcelable(KEY_SETTINGS)!!
// Set Status bar icon colors
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
dialog?.window?.statusBarColor = ContextCompat.getColor(requireContext(), R.color.colorUwMediaPickerStatusBar)
}
if (settings.lightStatusBar && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
tvToolbarDone.systemUiVisibility =
tvToolbarDone.systemUiVisibility or View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
}
// Get Device Width in Px
val deviceWidth = resources.displayMetrics.widthPixels
// Calculate gallery grid width (size)
galleryGridSize = deviceWidth / settings.gridColumnCount
// Set gallery items' texts size according to gridColumnCount
galleryTextSize = when (settings.gridColumnCount) {
1 -> 19F
2 -> 14F
else -> (14 - settings.gridColumnCount).toFloat()
}
// Set Title
updateToolbarTitle()
// Set RecyclerView
recyclerView.layoutManager = GridLayoutManager(requireContext(), settings.gridColumnCount)
recyclerView.itemAnimator = DefaultItemAnimator()
recyclerView.addItemDecoration(GalleryItemDecoration(
resources.getDimensionPixelSize(R.dimen.uwmediapicker_gallery_spacing),
settings.gridColumnCount
))
// Get Data for RecyclerView
// Async task started, show progress screen
lytProgressBar.visibility = View.VISIBLE
coroutineScope.launch {
try {
val buckets = withContext(Dispatchers.IO) {
when (settings.galleryMode) {
UwMediaPicker.GalleryMode.ImageGallery -> {
galleryMediaProvider.getImageBuckets()
}
UwMediaPicker.GalleryMode.VideoGallery -> {
galleryMediaProvider.getVideoBuckets()
}
UwMediaPicker.GalleryMode.ImageAndVideoGallery -> {
galleryMediaProvider.getImageAndVideoBuckets()
}
}
}
mediaBucketsList.addAll(buckets)
// This is UI/Main thread
recyclerView.adapter =
GalleryMediaRvAdapter(mediaBucketsList, galleryGridSize, galleryTextSize, galleryMediaBucketClickListener)
} catch (e: CancellationException) {
throw e
} catch (e: Exception) {
Snackbar
.make(
tvToolbarDone,
getString(R.string.uwmediapicker_snackbar_error_gallery_open_failed),
Snackbar.LENGTH_INDEFINITE)
.setAction(
getString(R.string.uwmediapicker_snackbar_action_retry)) {
initPage()
}.show()
} finally {
// Hide progress screen
lytProgressBar?.visibility = View.GONE
}
}
}
/** Sets Media Buckets(Albums) Recycler View */
private fun setupMediaBucketRecyclerView() {
// Setup recyclerView with mediaList, GalleryMediaClickListener and OnLongClickListener
recyclerView.adapter = GalleryMediaRvAdapter(mediaList, galleryGridSize, galleryTextSize, galleryMediaClickListener, object : GalleryMediaOnLongClickListener {
// Open ImagePreviewDialog when long clicked to image
override fun onLongClick(imagePath: String?) {
imagePreviewDialog.showPreview(parentFragmentManager, imagePath?.toUri())
}
})
// Add OnItemTouchListener to RecyclerView
recyclerView.addOnItemTouchListener(object : RecyclerView.OnItemTouchListener {
override fun onTouchEvent(rv: RecyclerView, e: MotionEvent) {}
override fun onInterceptTouchEvent(rv: RecyclerView, e: MotionEvent): Boolean {
// When touch intercept if user quit holding, close ImagePreviewDialog
if (imagePreviewDialog.isVisible && e.action == MotionEvent.ACTION_UP)
imagePreviewDialog.dismiss()
return false
}
override fun onRequestDisallowInterceptTouchEvent(disallowIntercept: Boolean) {}
})
}
/** Gallery Media Bucket's click function */
private fun onGalleryMediaBucketClick(position: Int) {
if (mediaBucketsList[position].id == null) {
requireContext().toastStringRes(R.string.uwmediapicker_toast_error_media_bucket_open_failed)
return
}
// Set isBucketOpened True
isBucketOpened = true
// If clicked bucket is not the last opened bucket; get this bucket's media to mediaList
if (lastOpenedBucketId != mediaBucketsList[position].id) {
// Save this bucket as a last opened bucket for this action and title updates
lastOpenedBucketName = mediaBucketsList[position].name
lastOpenedBucketId = mediaBucketsList[position].id
// Update ToolbarTitle
updateToolbarTitle()
mediaList.clear()
// Async task started, show progress screen
lytProgressBar.visibility = View.VISIBLE
coroutineScope.launch {
try {
taskOpenMediaBucket = async(Dispatchers.IO) {
val selectedMediaPaths = selectedMediaList.map { it.mediaPath }
// This is background thread.
when (settings.galleryMode) {
UwMediaPicker.GalleryMode.ImageGallery -> {
galleryMediaProvider.getImagesOfBucket(mediaBucketsList[position].id!!, selectedMediaPaths)
}
UwMediaPicker.GalleryMode.VideoGallery -> {
galleryMediaProvider.getVideosOfBucket(mediaBucketsList[position].id!!, selectedMediaPaths)
}
UwMediaPicker.GalleryMode.ImageAndVideoGallery -> {
galleryMediaProvider.getImagesAndVideosOfBucket(mediaBucketsList[position].id!!, selectedMediaPaths)
}
}
}
if (taskOpenMediaBucket != null) {
mediaList.addAll(taskOpenMediaBucket!!.await())
}
setupMediaBucketRecyclerView()
} catch (e: Exception) {
// If error occurred, do not save this bucket as a lastOpenedBucket and go back
e.toString().logError()
requireContext().toastStringRes(R.string.uwmediapicker_toast_error_media_bucket_open_failed)
lastOpenedBucketName = ""
lastOpenedBucketId = ""
onBackPressed()
} finally {
// Hide progress screen
lytProgressBar.visibility = View.GONE
}
}
} else {
// Hide progress screen
lytProgressBar.visibility = View.GONE
// Update ToolbarTitle
updateToolbarTitle()
// Setup RecyclerView
setupMediaBucketRecyclerView()
}
}
/** Gallery Media's click function */
private fun onGalleryMediaClick(position: Int) {
if (mediaList[position].mediaPath == null) {
requireContext().toastStringRes(R.string.uwmediapicker_toast_error_media_select_failed)
return
}
// If media already selected;
if (mediaList[position].selected) {
// Mark clicked media as unselected, remove media's path from selectedMediaPathList
selectedMediaList.removeAll {
it.mediaPath == mediaList[position].mediaPath
}
mediaList[position].selected = false
} else {
// If the maximum number of media is selected
if (settings.maxSelectableMediaCount != null && selectedMediaList.size == settings.maxSelectableMediaCount) {
toastMaxMediaCountError?.cancel()
// Show error toast about max selectable media count
toastMaxMediaCountError = requireContext().toastStringRes(R.string.uwmediapicker_toast_error_max_media_selected)
// Animate(Blink) MediaSelectCount Text
tvToolbarMediaSelectCount.startAnimation(blinkAnimation)
return
}//Else, select it;
// Mark clicked media as selected, add media's path to selectedMediaPathList
mediaList[position].mediaPath?.let {
val mediaType = if (mediaList[position] is GalleryImageModel) UwMediaPickerMediaType.IMAGE else UwMediaPickerMediaType.VIDEO
selectedMediaList.add(UwMediaPickerMediaModel(it, mediaType))
mediaList[position].selected = true
}
}
updateSelectedMediaCountTextAndDoneButton()
recyclerView.adapter?.notifyItemChanged(position)
}
/** Updates the ToolbarTitle according to opened library type or opened bucket's name */
private fun updateToolbarTitle() {
tvToolbarTitle.text =
if (!isBucketOpened) {
when (settings.galleryMode) {
UwMediaPicker.GalleryMode.ImageGallery -> getString(R.string.uwmediapicker_toolbar_title_image_library)
UwMediaPicker.GalleryMode.VideoGallery -> getString(R.string.uwmediapicker_toolbar_title_video_library)
UwMediaPicker.GalleryMode.ImageAndVideoGallery -> getString(R.string.uwmediapicker_toolbar_title_image_and_video_library)
}
} else {
lastOpenedBucketName
}
}
/** Updates the SelectedMediaCount Text, hide it if no media selected
* And if any media is selected activate the Done Button */
private fun updateSelectedMediaCountTextAndDoneButton() {
if (selectedMediaList.isNotEmpty()) {
if (settings.maxSelectableMediaCount != null) {
tvToolbarMediaSelectCount.text = getString(
R.string.uwmediapicker_toolbar_text_uw_media_picker_selected_media_count,
selectedMediaList.size, settings.maxSelectableMediaCount)
tvToolbarMediaSelectCount.visibility = View.VISIBLE
} else {
tvToolbarMediaSelectCount.visibility = View.GONE
}
tvToolbarDone.isEnabled = true
} else {
tvToolbarMediaSelectCount.visibility = View.GONE
tvToolbarDone.isEnabled = false
}
}
@SuppressLint("InflateParams")
/** Opens simple progress dialog */
private fun getProgressDialog(): AlertDialog {
// Inflates the dialog with custom view
val dialogView = LayoutInflater.from(requireContext()).inflate(R.layout.uwmediapicker_dialog_progress, null)
return AlertDialog.Builder(requireContext())
.setView(dialogView)
.setCancelable(false)
.create().apply {
window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
}
}
/** Returns selected image paths as result */
private fun returnResult() {
if (selectedMediaList.isEmpty()) {
requireContext().toastStringRes(R.string.uwmediapicker_toast_error_media_select_failed)
dismiss()
return
}
coroutineScope.launch {
val progressDialog = getProgressDialog().apply { show() }
var hasErrorOccurred = false
if (settings.imageCompressionEnabled) {
withContext(Dispatchers.IO) {
// This is background thread.
val imageCompressor = ImageCompressor(
settings.compressionMaxWidth,
settings.compressionMaxHeight,
settings.compressFormat,
settings.compressionQuality,
settings.compressedFileDestinationPath)
for ((index, selectedMedia) in selectedMediaList.withIndex()) {
if (selectedMedia.mediaType == UwMediaPickerMediaType.IMAGE) {
try {
val compressedImageFile = imageCompressor.compress(File(selectedMedia.mediaPath))
selectedMediaList[index].mediaPath = compressedImageFile.absolutePath
} catch (e: Exception) {
e.message.logError()
hasErrorOccurred = true
}
}
}
}
}
// This is UI/Main thread
progressDialog.dismiss()
// If an error has occurred and some media can still be selected; show toast message about it
if (hasErrorOccurred) {
requireContext().toastStringRes(R.string.uwmediapicker_toast_error_some_media_select_failed)
}
resultCallback?.invoke(selectedMediaList)
dismiss()
}
}
private fun onBackPressed() {
// If any bucked opened; close it
if (isBucketOpened) {
// Hide progress screen
lytProgressBar.visibility = View.GONE
// Cancel the open media bucket task
if (taskOpenMediaBucket != null) taskOpenMediaBucket?.cancel()
// Set RecyclerView with MediaBucketList
recyclerView.adapter = GalleryMediaRvAdapter(mediaBucketsList, galleryGridSize, galleryTextSize, galleryMediaBucketClickListener)
// Set isBucketOpened false
isBucketOpened = false
// Update ToolbarTitle
updateToolbarTitle()
} else {
cancelCallback?.invoke()
dismiss()
}
}
override fun onDestroy() {
job.cancel()
super.onDestroy()
}
fun setResultCallback(resultCallback: (List<UwMediaPickerMediaModel>?) -> Unit) {
this.resultCallback = resultCallback
}
fun setCancelCallback(cancelCallback: () -> Unit) {
this.cancelCallback = cancelCallback
}
companion object {
private const val KEY_SETTINGS = "KEY_SETTINGS"
fun newInstance(settings: UWMediaPickerSettingsModel): UwMediaPickerDialogFragment {
return UwMediaPickerDialogFragment().apply {
arguments = Bundle().apply {
putParcelable(KEY_SETTINGS, settings)
}
}
}
init {
// For using vector drawables on lower APIs
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true)
}
}
}
================================================
FILE: uwmediapicker/src/main/java/com/anilokcun/uwmediapicker/ui/dialog/ImagePreviewDialog.kt
================================================
package com.anilokcun.uwmediapicker.ui.dialog
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.net.Uri
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.Window
import android.widget.FrameLayout
import android.widget.ImageView
import androidx.fragment.app.FragmentManager
import com.bumptech.glide.Glide
/**
* Author : Anıl Furkan Ökçün
* Author mail : anilfurkanokcun@gmail.com
* Create Date : 30.08.2018
*/
internal class ImagePreviewDialog : androidx.fragment.app.DialogFragment() {
private var imageUri: Uri? = null
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
if (imageUri == null) {
dismiss()
return null
}
// Set rootView
val imgRootView = ImageView(inflater.context)
val root = FrameLayout(context!!)
root.layoutParams =
ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)
dialog?.apply {
requestWindowFeature(Window.FEATURE_NO_TITLE)
setContentView(root)
window?.setBackgroundDrawable(ColorDrawable(Color.BLACK))
window?.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)
}
Glide.with(this)
.load(imageUri)
.into(imgRootView)
return imgRootView
}
internal fun showPreview(manager: FragmentManager?, imageUri: Uri?) {
if (manager == null) return
super.show(manager, "ImagePreviewDialogTag")
this.imageUri = imageUri
}
}
================================================
FILE: uwmediapicker/src/main/java/com/anilokcun/uwmediapicker/viewholder/BaseGalleryMediaVH.kt
================================================
package com.anilokcun.uwmediapicker.viewholder
import android.graphics.drawable.ColorDrawable
import android.view.View
import android.widget.ImageView
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.RecyclerView
import com.anilokcun.uwmediapicker.R
import com.anilokcun.uwmediapicker.helper.toUri
import com.anilokcun.uwmediapicker.listener.OnRVItemClickListener
import com.anilokcun.uwmediapicker.model.BaseGalleryMediaModel
import com.bumptech.glide.Glide
import com.bumptech.glide.request.RequestOptions
/**
* Author : Anıl Furkan Ökçün
* Author mail : anilfurkanokcun@gmail.com
* Create Date : 30.08.2018
*/
internal open class BaseGalleryMediaVH(itemView: View) : RecyclerView.ViewHolder(itemView) {
open fun bind(item: BaseGalleryMediaModel, galleryGridSize: Int, onMediaClickListener: OnRVItemClickListener, imgThumbnail: ImageView, imgSelected: ImageView?) {
// Thumbnail
imgThumbnail.layoutParams.height = galleryGridSize
imgThumbnail.layoutParams.width = galleryGridSize
Glide.with(itemView).apply {
this.load(item.mediaPath?.toUri())
.apply(RequestOptions
.overrideOf(galleryGridSize, galleryGridSize)
.centerCrop()
.placeholder(ColorDrawable(ContextCompat.getColor(itemView.context, R.color.colorUwMediaPickerImagePlaceHolder))))
.into(imgThumbnail)
}
// Selected Icon
imgSelected?.isActivated = item.selected
// Item Click Event
itemView.setOnClickListener {
onMediaClickListener.onClick(adapterPosition)
}
}
}
================================================
FILE: uwmediapicker/src/main/java/com/anilokcun/uwmediapicker/viewholder/GalleryImageVH.kt
================================================
package com.anilokcun.uwmediapicker.viewholder
import android.view.View
import android.widget.ImageView
import com.anilokcun.uwmediapicker.R
import com.anilokcun.uwmediapicker.listener.GalleryMediaOnLongClickListener
import com.anilokcun.uwmediapicker.listener.OnRVItemClickListener
import com.anilokcun.uwmediapicker.model.GalleryImageModel
/**
* Author : Anıl Furkan Ökçün
* Author mail : anilfurkanokcun@gmail.com
* Create Date : 30.08.2018
*/
internal class GalleryImageVH(itemView: View) : BaseGalleryMediaVH(itemView) {
private val imgThumbnail = itemView.findViewById<ImageView>(R.id.item_gallery_image_img_thumbnail)
private val imgSelected = itemView.findViewById<ImageView>(R.id.item_gallery_image_img_selected)
fun bind(item: GalleryImageModel, galleryGridSize: Int, onMediaClickListener: OnRVItemClickListener, galleryMediaOnLongClickListener: GalleryMediaOnLongClickListener?) {
// Bind item click listener, thumbnail and selected icon in the base class
super.bind(item, galleryGridSize, onMediaClickListener, imgThumbnail, imgSelected)
// Item Long Click Event
itemView.setOnLongClickListener {
galleryMediaOnLongClickListener?.onLongClick(item.mediaPath)
false
}
}
}
================================================
FILE: uwmediapicker/src/main/java/com/anilokcun/uwmediapicker/viewholder/GalleryMediaBucketVH.kt
================================================
package com.anilokcun.uwmediapicker.viewholder
import android.graphics.drawable.ColorDrawable
import android.view.View
import android.widget.ImageView
import android.widget.TextView
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.RecyclerView
import com.anilokcun.uwmediapicker.R
import com.anilokcun.uwmediapicker.helper.toUri
import com.anilokcun.uwmediapicker.listener.OnRVItemClickListener
import com.anilokcun.uwmediapicker.model.GalleryMediaBucketModel
import com.bumptech.glide.Glide
import com.bumptech.glide.request.RequestOptions
/**
* Author : Anıl Furkan Ökçün
* Author mail : anilfurkanokcun@gmail.com
* Create Date : 30.08.2018
*/
internal class GalleryMediaBucketVH(itemView: View) : RecyclerView.ViewHolder(itemView) {
private val imgThumbnail = itemView.findViewById<ImageView>(R.id.item_gallery_media_bucket_img_thumbnail)
private val tvName = itemView.findViewById<TextView>(R.id.item_gallery_media_bucket_tv_name)
private val tvMediaCount = itemView.findViewById<TextView>(R.id.item_gallery_media_bucket_tv_media_count)
fun bind(item: GalleryMediaBucketModel, galleryGridSize: Int, galleryTextSize: Float, onMediaBucketClickListener: OnRVItemClickListener) {
// Thumbnail
imgThumbnail.layoutParams.height = galleryGridSize
imgThumbnail.layoutParams.width = galleryGridSize
Glide.with(itemView).apply {
this.load(item.coverImagePath?.toUri())
.apply(RequestOptions
.overrideOf(galleryGridSize, galleryGridSize)
.centerCrop()
.placeholder(ColorDrawable(ContextCompat.getColor(itemView.context, R.color.colorUwMediaPickerImagePlaceHolder))))
.into(imgThumbnail)
}
// Name
tvName.text = item.name
tvName.textSize = galleryTextSize
// Media Count
tvMediaCount.text = item.mediaCount.toString()
tvMediaCount.textSize = galleryTextSize
// Item Click Event
itemView.setOnClickListener {
onMediaBucketClickListener.onClick(adapterPosition)
}
}
}
================================================
FILE: uwmediapicker/src/main/java/com/anilokcun/uwmediapicker/viewholder/GalleryVideoVH.kt
================================================
package com.anilokcun.uwmediapicker.viewholder
import android.text.TextUtils
import android.view.View
import android.widget.ImageView
import android.widget.TextView
import com.anilokcun.uwmediapicker.R
import com.anilokcun.uwmediapicker.listener.OnRVItemClickListener
import com.anilokcun.uwmediapicker.model.GalleryVideoModel
import java.text.DecimalFormat
import java.util.concurrent.TimeUnit
import kotlin.math.log10
import kotlin.math.pow
/**
* Author : Anıl Furkan Ökçün
* Author mail : anilfurkanokcun@gmail.com
* Create Date : 30.08.2018
*/
internal class GalleryVideoVH(itemView: View) : BaseGalleryMediaVH(itemView) {
private val imgThumbnail = itemView.findViewById<ImageView>(R.id.item_gallery_video_img_thumbnail)
private val imgSelected = itemView.findViewById<ImageView>(R.id.item_gallery_video_img_selected)
private val tvVideoDuration = itemView.findViewById<TextView>(R.id.item_gallery_video_tv_video_duration)
private val tvVideoSize = itemView.findViewById<TextView>(R.id.item_gallery_video_tv_video_size)
fun bind(item: GalleryVideoModel, galleryGridSize: Int, galleryTextSize: Float, onMediaClickListener: OnRVItemClickListener) {
// Bind item click listener, thumbnail and selected icon in the base class
super.bind(item, galleryGridSize, onMediaClickListener, imgThumbnail, imgSelected)
// Video Duration
val videoDurationMillisecond = item.videoDuration
val videoDurationSecond = TimeUnit.MILLISECONDS.toSeconds(videoDurationMillisecond) % 60
val videoDurationMinute = TimeUnit.MILLISECONDS.toMinutes(videoDurationMillisecond) % 60
val videoDurationHour = TimeUnit.MILLISECONDS.toHours(videoDurationMillisecond)
tvVideoDuration.textSize = galleryTextSize
tvVideoDuration.text = if (videoDurationHour > 0) {
itemView.context
.getString(R.string.uwmediapicker_time_format_hour_min_sec,
videoDurationHour, videoDurationMinute, videoDurationSecond)
} else {
itemView.context
.getString(R.string.uwmediapicker_time_format_min_sec,
videoDurationMinute, videoDurationSecond)
}
// Video Size
tvVideoSize.textSize = galleryTextSize
tvVideoSize.text = if (item.videoSize != null) {
if (item.videoSize == "0") {
"0"
} else {
val units = arrayListOf("B", "KB", "MB", "GB", "TB")
val digitGroups = (log10(item.videoSize.toDouble()) / log10(1024.0)).toInt()
TextUtils.concat(DecimalFormat("#,##0.#").format(item.videoSize.toDouble()
/ (1024.0.pow(digitGroups.toDouble()))), " ", units[digitGroups])
}
} else ""
}
}
================================================
FILE: uwmediapicker/src/main/res/color/uwmediapicker_color_btn_text_done.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Active -->
<item android:color="@color/colorUwMediaPickerBtnTextDoneEnable" android:state_enabled="true" />
<!-- Inactive-->
<item android:color="@color/colorUwMediaPickerBtnTextDoneDisable" android:state_enabled="false" />
</selector>
================================================
FILE: uwmediapicker/src/main/res/drawable-nodpi/uwmediapicker_ic_arrow_back.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportHeight="24"
android:viewportWidth="24">
<path
android:fillColor="@color/colorUwMediaPickerBackButton"
android:pathData="M24,10.6 L24,13.6 L5.8,13.6 L14.1,21.9 L12,24.1 L0,12.1 L12,0.1 L14.2,2.3
L5.9,10.6 L24,10.6 Z" />
</vector>
================================================
FILE: uwmediapicker/src/main/res/drawable-nodpi/uwmediapicker_ic_check_circled.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportHeight="24"
android:viewportWidth="24">
<path
android:fillColor="@color/colorUwMediaPickerSelectedIconBg"
android:pathData="M12,0 C18.6274,0,24,5.37258,24,12 C24,18.6274,18.6274,24,12,24 C5.37258,24,0,18.6274,0,12 C0,5.37258,5.37258,0,12,0 Z" />
<path
android:fillColor="@color/colorUwMediaPickerSelectedIcon"
android:pathData="M17.9,8.4 L9.8,16.5 L6.1,12.8 L7,11.9 L9.7,14.6 L16.8,7.5 L17.9,8.4 Z" />
</vector>
================================================
FILE: uwmediapicker/src/main/res/drawable-nodpi/uwmediapicker_selector_ic_media_selected.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Inactive -->
<item android:drawable="@drawable/uwmediapicker_shape_bg_media_unselected" android:state_activated="false" />
<!-- Active -->
<item android:drawable="@drawable/uwmediapicker_ic_check_circled" android:state_activated="true" />
</selector>
================================================
FILE: uwmediapicker/src/main/res/drawable-nodpi/uwmediapicker_shape_bg_media_unselected.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/colorUwMediaPickerUnselectedIconBg" />
<stroke
android:width="0.75dp"
android:color="#FFF" />
<corners android:radius="50dp" />
</shape>
================================================
FILE: uwmediapicker/src/main/res/drawable-nodpi/uwmediapicker_shape_bg_progress_dialog.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/colorUwMediaPickerProgressDialogBg" />
<corners android:radius="6dp" />
<stroke
android:width="1dp"
android:color="@color/colorUwMediaPickerProgressDialogStroke" />
</shape>
================================================
FILE: uwmediapicker/src/main/res/drawable-nodpi/uwmediapicker_shape_bg_shadow.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:angle="90"
android:centerColor="#0D000000"
android:endColor="#1A000000"
android:startColor="@android:color/transparent" />
</shape>
================================================
FILE: uwmediapicker/src/main/res/layout/activity_uw_media_picker.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorUwMediaPickerPageBackground">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="@dimen/uwmediapicker_toolbar_height"
android:background="@color/colorUwMediaPickerToolbarBg">
<ImageView
android:id="@+id/imgToolbarBack"
android:layout_width="wrap_content"
android:layout_height="@dimen/uwmediapicker_toolbar_height"
android:layout_gravity="start"
android:adjustViewBounds="true"
android:contentDescription="@string/uwmediapicker_content_description_back_button"
android:padding="@dimen/uwmediapicker_spacing_normal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/tvToolbarTitle"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/uwmediapicker_ic_arrow_back" />
<TextView
android:id="@+id/tvToolbarTitle"
android:layout_width="0dp"
android:layout_height="wrap_content"
style="@style/UwMediaPickerTvToolbarTitle"
android:layout_marginEnd="@dimen/uwmediapicker_spacing_normal"
android:layout_marginStart="@dimen/uwmediapicker_spacing_small"
android:ellipsize="end"
android:maxLines="1"
app:layout_constraintBottom_toTopOf="@id/tvToolbarMediaSelectCount"
app:layout_constraintEnd_toStartOf="@id/tvToolbarDone"
app:layout_constraintStart_toEndOf="@id/imgToolbarBack"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_chainStyle="packed" />
<TextView
android:id="@+id/tvToolbarMediaSelectCount"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:padding="0dp"
android:textColor="@color/colorUwMediaPickerToolbarSubtext"
android:textSize="@dimen/uwmediapicker_text_size_toolbar_subtext"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/tvToolbarDone"
app:layout_constraintStart_toStartOf="@id/tvToolbarTitle"
app:layout_constraintTop_toBottomOf="@id/tvToolbarTitle" />
<TextView
android:id="@+id/tvToolbarDone"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center"
android:paddingEnd="@dimen/uwmediapicker_spacing_normal"
android:paddingStart="@dimen/uwmediapicker_spacing_normal"
android:text="@string/uwmediapicker_toolbar_done"
android:enabled="false"
android:textColor="@color/uwmediapicker_color_btn_text_done"
android:textSize="@dimen/uwmediapicker_text_size_toolbar_title"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/tvToolbarTitle"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="@dimen/uwmediapicker_toolbar_height"
android:background="@color/colorUwMediaPickerPageBackground" />
<FrameLayout
android:id="@+id/lytProgressBar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="@dimen/uwmediapicker_toolbar_height"
android:background="@color/colorUwMediaPickerPageBackground">
<ProgressBar
android:layout_width="@dimen/uwmediapicker_progressbar_size"
android:layout_height="@dimen/uwmediapicker_progressbar_size"
android:layout_gravity="center"
android:theme="@style/UwMediaPickerProgressBarTheme" />
</FrameLayout>
<View
android:layout_width="match_parent"
android:layout_height="@dimen/uwmediapicker_shadow_height"
android:layout_marginTop="@dimen/uwmediapicker_toolbar_height"
android:background="@drawable/uwmediapicker_shape_bg_shadow" />
</FrameLayout>
================================================
FILE: uwmediapicker/src/main/res/layout/uwmediapicker_dialog_progress.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/uwmediapicker_shape_bg_progress_dialog"
android:orientation="vertical">
<ProgressBar
android:layout_width="@dimen/uwmediapicker_progressbar_size"
android:layout_height="@dimen/uwmediapicker_progressbar_size"
android:layout_gravity="center"
android:layout_marginBottom="@dimen/uwmediapicker_spacing_small"
android:layout_marginEnd="@dimen/uwmediapicker_spacing_normal"
android:layout_marginStart="@dimen/uwmediapicker_spacing_normal"
android:layout_marginTop="@dimen/uwmediapicker_spacing_small"
android:theme="@style/UwMediaPickerProgressBarTheme" />
</LinearLayout>
</RelativeLayout>
================================================
FILE: uwmediapicker/src/main/res/layout/uwmediapicker_item_gallery_image.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
style="@style/UwMediaPickerLytGalleryMediaRoot">
<ImageView
android:id="@+id/item_gallery_image_img_thumbnail"
style="@style/UwMediaPickerImgGalleryMediaThumb"
android:contentDescription="@string/uwmediapicker_content_description_image_thumbnail" />
<ImageView
android:id="@+id/item_gallery_image_img_selected"
style="@style/UwMediaPickerImgGalleryMediaSelectedIcon"
tools:ignore="ContentDescription" />
</androidx.constraintlayout.widget.ConstraintLayout>
================================================
FILE: uwmediapicker/src/main/res/layout/uwmediapicker_item_gallery_media_bucket.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
style="@style/UwMediaPickerLytGalleryMediaRoot"
android:layout_width="match_parent">
<ImageView
android:id="@+id/item_gallery_media_bucket_img_thumbnail"
style="@style/UwMediaPickerImgGalleryMediaThumb"
android:contentDescription="@string/uwmediapicker_content_description_album_thumbnail" />
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="@color/colorUwMediaPickerBucketBottomStrip"
android:padding="@dimen/uwmediapicker_spacing_mini">
<TextView
android:id="@+id/item_gallery_media_bucket_tv_name"
style="@style/UwMediaPickerTvGalleryMediaSmallText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/uwmediapicker_spacing_mini"
android:ellipsize="end"
android:maxLines="2"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/item_gallery_media_bucket_tv_media_count"
app:layout_constraintHorizontal_chainStyle="spread_inside"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/item_gallery_media_bucket_tv_media_count"
style="@style/UwMediaPickerTvGalleryMediaSmallText"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:textColor="@color/colorUwMediaPickerAlbumMediaCount"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/item_gallery_media_bucket_tv_name"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</FrameLayout>
================================================
FILE: uwmediapicker/src/main/res/layout/uwmediapicker_item_gallery_video.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
style="@style/UwMediaPickerLytGalleryMediaRoot">
<ImageView
android:id="@+id/item_gallery_video_img_thumbnail"
style="@style/UwMediaPickerImgGalleryMediaThumb"
android:contentDescription="@string/uwmediapicker_content_description_video_thumbnail" />
<ImageView
android:id="@+id/item_gallery_video_img_selected"
style="@style/UwMediaPickerImgGalleryMediaSelectedIcon"
tools:ignore="ContentDescription" />
<TextView
android:id="@+id/item_gallery_video_tv_video_duration"
style="@style/UwMediaPickerTvGalleryVideoInfoText"
app:layout_constraintHorizontal_bias="0.03" />
<TextView
android:id="@+id/item_gallery_video_tv_video_size"
style="@style/UwMediaPickerTvGalleryVideoInfoText"
app:layout_constraintHorizontal_bias="0.97" />
</androidx.constraintlayout.widget.ConstraintLayout>
================================================
FILE: uwmediapicker/src/main/res/values/colors.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorUwMediaPickerStatusBar">#F6F6F6</color>
<color name="colorUwMediaPickerProgressBar">#CDCDCD</color>
<color name="colorUwMediaPickerPageBackground">#FFFFFF</color>
<color name="colorUwMediaPickerProgressDialogBg">#F9F9F9</color>
<color name="colorUwMediaPickerProgressDialogStroke">#D9D9D9</color>
<!-- Toolbar Colors -->
<color name="colorUwMediaPickerToolbarBg">#FFFFFF</color>
<color name="colorUwMediaPickerBackButton">#272727</color>
<color name="colorUwMediaPickerToolbarTitle">#404040</color>
<color name="colorUwMediaPickerToolbarSubtext">#8D8D8D</color>
<color name="colorUwMediaPickerBtnTextDoneEnable">#0192D2</color>
<color name="colorUwMediaPickerBtnTextDoneDisable">#B3B3B3</color>
<!-- Gallery Item Colors-->
<color name="colorUwMediaPickerBucketBottomStrip">#8C000000</color><!--%55 Opaque Black -->
<color name="colorUwMediaPickerImagePlaceHolder">#F6F6F6</color>
<color name="colorUwMediaPickerUnselectedIconBg">#80FFFFFF</color><!--%50 Opaque White -->
<color name="colorUwMediaPickerSelectedIconBg">#0192D2</color>
<color name="colorUwMediaPickerSelectedIcon">#FFF</color>
<color name="colorUwMediaPickerMediaName">#FFFFFF</color>
<color name="colorUwMediaPickerAlbumMediaCount">#D9D9D9</color>
</resources>
================================================
FILE: uwmediapicker/src/main/res/values/dimens.xml
================================================
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Font Sizes-->
<dimen name="uwmediapicker_text_size_toolbar_title">17sp</dimen>
<dimen name="uwmediapicker_text_size_toolbar_subtext">12sp</dimen>
<!-- Spacing -->
<dimen name="uwmediapicker_spacing_normal">16dp</dimen>
<dimen name="uwmediapicker_spacing_small">8dp</dimen>
<dimen name="uwmediapicker_spacing_mini">4dp</dimen>
<!-- Sizes -->
<dimen name="uwmediapicker_toolbar_height">48dp</dimen>
<dimen name="uwmediapicker_gallery_spacing">2dp</dimen>
<dimen name="uwmediapicker_shadow_height">4dp</dimen>
<dimen name="uwmediapicker_progressbar_size">42dp</dimen>
</resources>
================================================
FILE: uwmediapicker/src/main/res/values/strings.xml
================================================
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Toolbar Texts -->
<string name="uwmediapicker_toolbar_title_image_library">Image Library</string>
<string name="uwmediapicker_toolbar_title_video_library">Video Library</string>
<string name="uwmediapicker_toolbar_title_image_and_video_library">Image&Video Library</string>
<string name="uwmediapicker_toolbar_text_uw_media_picker_selected_media_count" tools:ignore="PluralsCandidate">%d/%d selected</string>
<string name="uwmediapicker_toolbar_done">Done</string>
<!-- Snackbar Messages -->
<string name="uwmediapicker_snackbar_error_gallery_open_failed">Gallery could not be opened.</string>
<string name="uwmediapicker_snackbar_action_retry">Retry</string>
<!-- Toast Messages-->
<string name="uwmediapicker_toast_error_media_bucket_open_failed">Album could not be opened.</string>
<string name="uwmediapicker_toast_error_media_select_failed">Media could not be selected.</string>
<string name="uwmediapicker_toast_error_max_media_selected">You can not select any more media</string>
<string name="uwmediapicker_toast_error_some_media_select_failed">Some media could not be selected</string>
<!-- Time Formats -->
<string name="uwmediapicker_time_format_hour_min_sec">%02d:%02d:%02d</string>
<string name="uwmediapicker_time_format_min_sec">%02d:%02d</string>
<!-- Content Descriptions -->
<string name="uwmediapicker_content_description_back_button">Back button</string>
<string name="uwmediapicker_content_description_album_thumbnail">Album thumbnail</string>
<string name="uwmediapicker_content_description_image_thumbnail">Image thumbnail</string>
<string name="uwmediapicker_content_description_video_thumbnail">Video thumbnail</string>
<string name="uwmediapicker_content_description_selected_icon">Selected icon</string>
</resources>
================================================
FILE: uwmediapicker/src/main/res/values/styles.xml
================================================
<resources>
<!-- Themes -->
<style name="UwMediaPickerProgressBarTheme">
<item name="colorAccent">@color/colorUwMediaPickerProgressBar</item>
</style>
<!-- Layout Styles -->
<style name="UwMediaPickerLytGalleryMediaRoot">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
</style>
<!-- TextView Styles -->
<style name="UwMediaPickerTvToolbarTitle">
<item name="android:textColor">@color/colorUwMediaPickerToolbarTitle</item>
<item name="android:textSize">@dimen/uwmediapicker_text_size_toolbar_title</item>
<item name="android:textStyle">bold</item>
</style>
<style name="UwMediaPickerTvGalleryMediaSmallText">
<item name="android:textColor">@color/colorUwMediaPickerMediaName</item>
<item name="android:textSize">10sp</item>
</style>
<style name="UwMediaPickerTvGalleryVideoInfoText" parent="UwMediaPickerTvGalleryMediaSmallText">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="layout_constraintStart_toStartOf">parent</item>
<item name="layout_constraintEnd_toEndOf">parent</item>
<item name="layout_constraintTop_toTopOf">parent</item>
<item name="layout_constraintBottom_toBottomOf">parent</item>
<item name="layout_constraintVertical_bias">0.97</item>
</style>
<!-- ImageView Styles -->
<style name="UwMediaPickerImgGalleryMediaThumb">
<item name="android:layout_width">0dp</item>
<item name="android:layout_height">0dp</item>
<item name="layout_constraintStart_toStartOf">parent</item>
<item name="layout_constraintEnd_toEndOf">parent</item>
<item name="layout_constraintTop_toTopOf">parent</item>
<item name="layout_constraintBottom_toBottomOf">parent</item>
<item name="android:contentDescription">
@string/uwmediapicker_content_description_image_thumbnail
</item>
</style>
<style name="UwMediaPickerImgGalleryMediaSelectedIcon">
<item name="android:layout_width">0dp</item>
<item name="android:layout_height">0dp</item>
<item name="android:background">@drawable/uwmediapicker_selector_ic_media_selected</item>
<item name="layout_constraintStart_toStartOf">parent</item>
<item name="layout_constraintEnd_toEndOf">parent</item>
<item name="layout_constraintTop_toTopOf">parent</item>
<item name="layout_constraintBottom_toBottomOf">parent</item>
<item name="layout_constraintHeight_percent">0.13</item>
<item name="layout_constraintHorizontal_bias">0.97</item>
<item name="layout_constraintVertical_bias">0.03</item>
<item name="layout_constraintWidth_percent">0.13</item>
<item name="layout_constraintHeight_default">percent</item>
<item name="layout_constraintWidth_default">percent</item>
<item name="android:contentDescription">
@string/uwmediapicker_content_description_selected_icon
</item>
</style>
</resources>
gitextract_twc3vq8r/
├── .gitignore
├── .idea/
│ ├── compiler.xml
│ ├── jarRepositories.xml
│ ├── misc.xml
│ ├── modules.xml
│ └── vcs.xml
├── LICENSE
├── README.md
├── build.gradle
├── gradle/
│ └── wrapper/
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradle.properties
├── gradlew
├── gradlew.bat
├── sample/
│ ├── .gitignore
│ ├── build.gradle
│ ├── proguard-rules.pro
│ ├── release/
│ │ └── output.json
│ └── src/
│ └── main/
│ ├── AndroidManifest.xml
│ ├── java/
│ │ └── com/
│ │ └── anilokcun/
│ │ └── uwandroidmediapicker/
│ │ ├── GalleryItemDecoration.kt
│ │ ├── MainActivity.kt
│ │ └── SelectedMediaRvAdapter.kt
│ └── res/
│ ├── color/
│ │ └── color_text_activatable.xml
│ ├── drawable/
│ │ ├── ic_launcher_background.xml
│ │ ├── selector_bg_et.xml
│ │ ├── shape_bg_btn.xml
│ │ ├── shape_bg_et_active.xml
│ │ ├── shape_bg_et_default.xml
│ │ ├── shape_bg_option.xml
│ │ ├── shape_bg_shadow.xml
│ │ └── shape_bg_tv_title.xml
│ ├── drawable-v24/
│ │ └── ic_launcher_foreground.xml
│ ├── layout/
│ │ └── activity_main.xml
│ ├── mipmap-anydpi-v26/
│ │ ├── ic_launcher.xml
│ │ └── ic_launcher_round.xml
│ └── values/
│ ├── colors.xml
│ ├── dimens.xml
│ ├── strings.xml
│ └── styles.xml
├── settings.gradle
└── uwmediapicker/
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src/
└── main/
├── AndroidManifest.xml
├── java/
│ └── com/
│ └── anilokcun/
│ └── uwmediapicker/
│ ├── ImageCompressor.kt
│ ├── UwMediaPicker.kt
│ ├── adapter/
│ │ └── GalleryMediaRvAdapter.kt
│ ├── helper/
│ │ └── Extensions.kt
│ ├── listener/
│ │ ├── GalleryMediaOnLongClickListener.kt
│ │ └── OnRVItemClickListener.kt
│ ├── model/
│ │ ├── BaseGalleryMediaModel.kt
│ │ ├── BaseGalleryModel.kt
│ │ ├── GalleryImageModel.kt
│ │ ├── GalleryMediaBucketModel.kt
│ │ ├── GalleryVideoModel.kt
│ │ ├── UWMediaPickerSettingsModel.kt
│ │ ├── UwMediaPickerMediaModel.kt
│ │ └── UwMediaPickerMediaType.kt
│ ├── provider/
│ │ └── GalleryMediaDataProvider.kt
│ ├── ui/
│ │ ├── GalleryItemDecoration.kt
│ │ ├── activity/
│ │ │ └── UwMediaPickerDialogFragment.kt
│ │ └── dialog/
│ │ └── ImagePreviewDialog.kt
│ └── viewholder/
│ ├── BaseGalleryMediaVH.kt
│ ├── GalleryImageVH.kt
│ ├── GalleryMediaBucketVH.kt
│ └── GalleryVideoVH.kt
└── res/
├── color/
│ └── uwmediapicker_color_btn_text_done.xml
├── drawable-nodpi/
│ ├── uwmediapicker_ic_arrow_back.xml
│ ├── uwmediapicker_ic_check_circled.xml
│ ├── uwmediapicker_selector_ic_media_selected.xml
│ ├── uwmediapicker_shape_bg_media_unselected.xml
│ ├── uwmediapicker_shape_bg_progress_dialog.xml
│ └── uwmediapicker_shape_bg_shadow.xml
├── layout/
│ ├── activity_uw_media_picker.xml
│ ├── uwmediapicker_dialog_progress.xml
│ ├── uwmediapicker_item_gallery_image.xml
│ ├── uwmediapicker_item_gallery_media_bucket.xml
│ └── uwmediapicker_item_gallery_video.xml
└── values/
├── colors.xml
├── dimens.xml
├── strings.xml
└── styles.xml
Condensed preview — 82 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (163K chars).
[
{
"path": ".gitignore",
"chars": 1002,
"preview": "# Built application files\n*.apk\n*.ap_\n\n# Files for the ART/Dalvik VM\n*.dex\n\n# Java class files\n*.class\n\n# Generated file"
},
{
"path": ".idea/compiler.xml",
"chars": 170,
"preview": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<project version=\"4\">\n <component name=\"CompilerConfiguration\">\n <bytecodeTar"
},
{
"path": ".idea/jarRepositories.xml",
"chars": 1052,
"preview": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<project version=\"4\">\n <component name=\"RemoteRepositoriesConfiguration\">\n <r"
},
{
"path": ".idea/misc.xml",
"chars": 214,
"preview": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<project version=\"4\">\n <component name=\"ProjectRootManager\" version=\"2\" language"
},
{
"path": ".idea/modules.xml",
"chars": 684,
"preview": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<project version=\"4\">\n <component name=\"ProjectModuleManager\">\n <modules>\n "
},
{
"path": ".idea/vcs.xml",
"chars": 167,
"preview": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<project version=\"4\">\n <component name=\"VcsDirectoryMappings\">\n <mapping dire"
},
{
"path": "LICENSE",
"chars": 11357,
"preview": " Apache License\n Version 2.0, January 2004\n "
},
{
"path": "README.md",
"chars": 7080,
"preview": " users:\n# Gradle settings configured through the IDE *will ov"
},
{
"path": "gradlew",
"chars": 5296,
"preview": "#!/usr/bin/env sh\n\n##############################################################################\n##\n## Gradle start up"
},
{
"path": "gradlew.bat",
"chars": 2176,
"preview": "@if \"%DEBUG%\" == \"\" @echo off\n@rem ##########################################################################\n@rem\n@rem "
},
{
"path": "sample/.gitignore",
"chars": 7,
"preview": "/build\n"
},
{
"path": "sample/build.gradle",
"chars": 1259,
"preview": "apply plugin: 'com.android.application'\napply plugin: 'kotlin-android'\napply plugin: 'kotlin-android-extensions'\napply p"
},
{
"path": "sample/proguard-rules.pro",
"chars": 751,
"preview": "# Add project specific ProGuard rules here.\n# You can control the set of applied configuration files using the\n# proguar"
},
{
"path": "sample/release/output.json",
"chars": 234,
"preview": "[{\"outputType\":{\"type\":\"APK\"},\"apkInfo\":{\"type\":\"MAIN\",\"splits\":[],\"versionCode\":1,\"versionName\":\"1.0\",\"enabled\":true,\"o"
},
{
"path": "sample/src/main/AndroidManifest.xml",
"chars": 1109,
"preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<manifest xmlns:android=\"http://schemas.android.com/apk/res/android\"\n xmlns:to"
},
{
"path": "sample/src/main/java/com/anilokcun/uwandroidmediapicker/GalleryItemDecoration.kt",
"chars": 1737,
"preview": "package com.anilokcun.uwandroidmediapicker\n\nimport android.graphics.Rect\nimport android.view.View\nimport androidx.recycl"
},
{
"path": "sample/src/main/java/com/anilokcun/uwandroidmediapicker/MainActivity.kt",
"chars": 8135,
"preview": "package com.anilokcun.uwandroidmediapicker\n\nimport android.Manifest\nimport android.content.pm.PackageManager\nimport andr"
},
{
"path": "sample/src/main/java/com/anilokcun/uwandroidmediapicker/SelectedMediaRvAdapter.kt",
"chars": 1620,
"preview": "package com.anilokcun.uwandroidmediapicker\n\nimport android.graphics.drawable.ColorDrawable\nimport android.view.View\nimpo"
},
{
"path": "sample/src/main/res/color/color_text_activatable.xml",
"chars": 320,
"preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<selector xmlns:android=\"http://schemas.android.com/apk/res/android\">\n <!-- Ac"
},
{
"path": "sample/src/main/res/drawable/ic_launcher_background.xml",
"chars": 5606,
"preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<vector xmlns:android=\"http://schemas.android.com/apk/res/android\"\n android:wi"
},
{
"path": "sample/src/main/res/drawable/selector_bg_et.xml",
"chars": 313,
"preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<selector xmlns:android=\"http://schemas.android.com/apk/res/android\">\n <!-- Pr"
},
{
"path": "sample/src/main/res/drawable/shape_bg_btn.xml",
"chars": 279,
"preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<shape xmlns:android=\"http://schemas.android.com/apk/res/android\">\n <stroke\n "
},
{
"path": "sample/src/main/res/drawable/shape_bg_et_active.xml",
"chars": 291,
"preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<shape xmlns:android=\"http://schemas.android.com/apk/res/android\">\n <stroke\n "
},
{
"path": "sample/src/main/res/drawable/shape_bg_et_default.xml",
"chars": 286,
"preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<shape xmlns:android=\"http://schemas.android.com/apk/res/android\">\n <stroke\n "
},
{
"path": "sample/src/main/res/drawable/shape_bg_option.xml",
"chars": 443,
"preview": "<layer-list xmlns:android=\"http://schemas.android.com/apk/res/android\">\n <item\n android:bottom=\"0dp\"\n a"
},
{
"path": "sample/src/main/res/drawable/shape_bg_shadow.xml",
"chars": 321,
"preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<shape xmlns:android=\"http://schemas.android.com/apk/res/android\"\n android:sha"
},
{
"path": "sample/src/main/res/drawable/shape_bg_tv_title.xml",
"chars": 442,
"preview": "<layer-list xmlns:android=\"http://schemas.android.com/apk/res/android\">\n <item\n android:bottom=\"0dp\"\n a"
},
{
"path": "sample/src/main/res/drawable-v24/ic_launcher_foreground.xml",
"chars": 1880,
"preview": "<vector xmlns:android=\"http://schemas.android.com/apk/res/android\"\n xmlns:aapt=\"http://schemas.android.com/aapt\"\n "
},
{
"path": "sample/src/main/res/layout/activity_main.xml",
"chars": 6150,
"preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<FrameLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"\n xmlns"
},
{
"path": "sample/src/main/res/mipmap-anydpi-v26/ic_launcher.xml",
"chars": 272,
"preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<adaptive-icon xmlns:android=\"http://schemas.android.com/apk/res/android\">\n <b"
},
{
"path": "sample/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml",
"chars": 272,
"preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<adaptive-icon xmlns:android=\"http://schemas.android.com/apk/res/android\">\n <b"
},
{
"path": "sample/src/main/res/values/colors.xml",
"chars": 544,
"preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<resources>\n <color name=\"colorPrimary\">#FFFFFF</color>\n <color name=\"color"
},
{
"path": "sample/src/main/res/values/dimens.xml",
"chars": 435,
"preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<resources>\n <!-- Font Sizes-->\n <dimen name=\"font_20\">20sp</dimen>\n <di"
},
{
"path": "sample/src/main/res/values/strings.xml",
"chars": 779,
"preview": "<resources>\n <string name=\"app_name\">UW Media Picker - Android</string>\n\n <string name=\"max_selectable_media_count"
},
{
"path": "sample/src/main/res/values/styles.xml",
"chars": 3653,
"preview": "<resources>\n <!-- Base application theme. -->\n <style name=\"AppTheme\" parent=\"Theme.AppCompat.NoActionBar\">\n "
},
{
"path": "settings.gradle",
"chars": 36,
"preview": "include ':sample', ':uwmediapicker'\n"
},
{
"path": "uwmediapicker/.gitignore",
"chars": 7,
"preview": "/build\n"
},
{
"path": "uwmediapicker/build.gradle",
"chars": 1970,
"preview": "apply plugin: 'com.android.library'\napply plugin: 'kotlin-android'\napply plugin: 'kotlin-kapt'\napply plugin: 'kotlin-and"
},
{
"path": "uwmediapicker/proguard-rules.pro",
"chars": 751,
"preview": "# Add project specific ProGuard rules here.\n# You can control the set of applied configuration files using the\n# proguar"
},
{
"path": "uwmediapicker/src/main/AndroidManifest.xml",
"chars": 210,
"preview": "<manifest xmlns:android=\"http://schemas.android.com/apk/res/android\"\n package=\"com.anilokcun.uwmediapicker\">\n \n "
},
{
"path": "uwmediapicker/src/main/java/com/anilokcun/uwmediapicker/ImageCompressor.kt",
"chars": 5761,
"preview": "package com.anilokcun.uwmediapicker\n\nimport android.graphics.*\nimport androidx.exifinterface.media.ExifInterface\nimport "
},
{
"path": "uwmediapicker/src/main/java/com/anilokcun/uwmediapicker/UwMediaPicker.kt",
"chars": 4628,
"preview": "package com.anilokcun.uwmediapicker\n\nimport android.graphics.Bitmap\nimport androidx.appcompat.app.AppCompatActivity\nimpo"
},
{
"path": "uwmediapicker/src/main/java/com/anilokcun/uwmediapicker/adapter/GalleryMediaRvAdapter.kt",
"chars": 3435,
"preview": "package com.anilokcun.uwmediapicker.adapter\n\nimport android.content.Context\nimport android.view.LayoutInflater\nimport an"
},
{
"path": "uwmediapicker/src/main/java/com/anilokcun/uwmediapicker/helper/Extensions.kt",
"chars": 783,
"preview": "package com.anilokcun.uwmediapicker.helper\n\nimport android.content.Context\nimport android.net.Uri\nimport android.util.Lo"
},
{
"path": "uwmediapicker/src/main/java/com/anilokcun/uwmediapicker/listener/GalleryMediaOnLongClickListener.kt",
"chars": 252,
"preview": "package com.anilokcun.uwmediapicker.listener\n\n/**\n * Author \t:\tAnıl Furkan Ökçün\n * Author mail\t:\tanilfurkanokcun@gm"
},
{
"path": "uwmediapicker/src/main/java/com/anilokcun/uwmediapicker/listener/OnRVItemClickListener.kt",
"chars": 233,
"preview": "package com.anilokcun.uwmediapicker.listener\n\n/**\n * Author \t:\tAnıl Furkan Ökçün\n * Author mail\t:\tanilfurkanokcun@gm"
},
{
"path": "uwmediapicker/src/main/java/com/anilokcun/uwmediapicker/model/BaseGalleryMediaModel.kt",
"chars": 268,
"preview": "package com.anilokcun.uwmediapicker.model\n\n/**\n * Author \t:\tAnıl Furkan Ökçün\n * Author mail\t:\tanilfurkanokcun@gmail"
},
{
"path": "uwmediapicker/src/main/java/com/anilokcun/uwmediapicker/model/BaseGalleryModel.kt",
"chars": 385,
"preview": "package com.anilokcun.uwmediapicker.model\n\n/**\n * Author \t:\tAnıl Furkan Ökçün\n * Author mail\t:\tanilfurkanokcun@gmail"
},
{
"path": "uwmediapicker/src/main/java/com/anilokcun/uwmediapicker/model/GalleryImageModel.kt",
"chars": 373,
"preview": "package com.anilokcun.uwmediapicker.model\n\n/**\n * Author \t:\tAnıl Furkan Ökçün\n * Author mail\t:\tanilfurkanokcun@gmail"
},
{
"path": "uwmediapicker/src/main/java/com/anilokcun/uwmediapicker/model/GalleryMediaBucketModel.kt",
"chars": 387,
"preview": "package com.anilokcun.uwmediapicker.model\n\n/**\n * Author \t:\tAnıl Furkan Ökçün\n * Author mail\t:\tanilfurkanokcun@gmail"
},
{
"path": "uwmediapicker/src/main/java/com/anilokcun/uwmediapicker/model/GalleryVideoModel.kt",
"chars": 424,
"preview": "package com.anilokcun.uwmediapicker.model\n\n/**\n * Author \t:\tAnıl Furkan Ökçün\n * Author mail\t:\tanilfurkanokcun@gmail"
},
{
"path": "uwmediapicker/src/main/java/com/anilokcun/uwmediapicker/model/UWMediaPickerSettingsModel.kt",
"chars": 733,
"preview": "package com.anilokcun.uwmediapicker.model\n\nimport android.graphics.Bitmap\nimport android.os.Parcelable\nimport com.anilok"
},
{
"path": "uwmediapicker/src/main/java/com/anilokcun/uwmediapicker/model/UwMediaPickerMediaModel.kt",
"chars": 237,
"preview": "package com.anilokcun.uwmediapicker.model\n\nimport android.os.Parcelable\nimport kotlinx.android.parcel.Parcelize\n\n@Parcel"
},
{
"path": "uwmediapicker/src/main/java/com/anilokcun/uwmediapicker/model/UwMediaPickerMediaType.kt",
"chars": 95,
"preview": "package com.anilokcun.uwmediapicker.model\n\nenum class UwMediaPickerMediaType {\n\tIMAGE, VIDEO\n}\n"
},
{
"path": "uwmediapicker/src/main/java/com/anilokcun/uwmediapicker/provider/GalleryMediaDataProvider.kt",
"chars": 9462,
"preview": "package com.anilokcun.uwmediapicker.provider\n\nimport android.content.Context\nimport android.database.Cursor\nimport andro"
},
{
"path": "uwmediapicker/src/main/java/com/anilokcun/uwmediapicker/ui/GalleryItemDecoration.kt",
"chars": 2029,
"preview": "package com.anilokcun.uwmediapicker.ui\n\nimport android.graphics.Rect\nimport android.view.View\nimport androidx.recyclervi"
},
{
"path": "uwmediapicker/src/main/java/com/anilokcun/uwmediapicker/ui/activity/UwMediaPickerDialogFragment.kt",
"chars": 17041,
"preview": "package com.anilokcun.uwmediapicker.ui.activity\n\nimport android.annotation.SuppressLint\nimport android.app.Dialog\nimport"
},
{
"path": "uwmediapicker/src/main/java/com/anilokcun/uwmediapicker/ui/dialog/ImagePreviewDialog.kt",
"chars": 1578,
"preview": "package com.anilokcun.uwmediapicker.ui.dialog\n\nimport android.graphics.Color\nimport android.graphics.drawable.ColorDrawa"
},
{
"path": "uwmediapicker/src/main/java/com/anilokcun/uwmediapicker/viewholder/BaseGalleryMediaVH.kt",
"chars": 1527,
"preview": "package com.anilokcun.uwmediapicker.viewholder\n\nimport android.graphics.drawable.ColorDrawable\nimport android.view.View\n"
},
{
"path": "uwmediapicker/src/main/java/com/anilokcun/uwmediapicker/viewholder/GalleryImageVH.kt",
"chars": 1220,
"preview": "package com.anilokcun.uwmediapicker.viewholder\n\nimport android.view.View\nimport android.widget.ImageView\nimport com.anil"
},
{
"path": "uwmediapicker/src/main/java/com/anilokcun/uwmediapicker/viewholder/GalleryMediaBucketVH.kt",
"chars": 1977,
"preview": "package com.anilokcun.uwmediapicker.viewholder\n\nimport android.graphics.drawable.ColorDrawable\nimport android.view.View\n"
},
{
"path": "uwmediapicker/src/main/java/com/anilokcun/uwmediapicker/viewholder/GalleryVideoVH.kt",
"chars": 2536,
"preview": "package com.anilokcun.uwmediapicker.viewholder\n\nimport android.text.TextUtils\nimport android.view.View\nimport android.wi"
},
{
"path": "uwmediapicker/src/main/res/color/uwmediapicker_color_btn_text_done.xml",
"chars": 353,
"preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<selector xmlns:android=\"http://schemas.android.com/apk/res/android\">\n\t<!-- Activ"
},
{
"path": "uwmediapicker/src/main/res/drawable-nodpi/uwmediapicker_ic_arrow_back.xml",
"chars": 430,
"preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<vector xmlns:android=\"http://schemas.android.com/apk/res/android\"\n android:wi"
},
{
"path": "uwmediapicker/src/main/res/drawable-nodpi/uwmediapicker_ic_check_circled.xml",
"chars": 633,
"preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<vector xmlns:android=\"http://schemas.android.com/apk/res/android\"\n android:wi"
},
{
"path": "uwmediapicker/src/main/res/drawable-nodpi/uwmediapicker_selector_ic_media_selected.xml",
"chars": 381,
"preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<selector xmlns:android=\"http://schemas.android.com/apk/res/android\">\n <!-- In"
},
{
"path": "uwmediapicker/src/main/res/drawable-nodpi/uwmediapicker_shape_bg_media_unselected.xml",
"chars": 299,
"preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<shape xmlns:android=\"http://schemas.android.com/apk/res/android\">\n <solid and"
},
{
"path": "uwmediapicker/src/main/res/drawable-nodpi/uwmediapicker_shape_bg_progress_dialog.xml",
"chars": 336,
"preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<shape xmlns:android=\"http://schemas.android.com/apk/res/android\">\n <solid and"
},
{
"path": "uwmediapicker/src/main/res/drawable-nodpi/uwmediapicker_shape_bg_shadow.xml",
"chars": 321,
"preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<shape xmlns:android=\"http://schemas.android.com/apk/res/android\"\n android:sha"
},
{
"path": "uwmediapicker/src/main/res/layout/activity_uw_media_picker.xml",
"chars": 4718,
"preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<FrameLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"\n xmlns"
},
{
"path": "uwmediapicker/src/main/res/layout/uwmediapicker_dialog_progress.xml",
"chars": 1084,
"preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<RelativeLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"\n an"
},
{
"path": "uwmediapicker/src/main/res/layout/uwmediapicker_item_gallery_image.xml",
"chars": 718,
"preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<androidx.constraintlayout.widget.ConstraintLayout xmlns:android=\"http://schemas."
},
{
"path": "uwmediapicker/src/main/res/layout/uwmediapicker_item_gallery_media_bucket.xml",
"chars": 2187,
"preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<FrameLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"\n xmlns"
},
{
"path": "uwmediapicker/src/main/res/layout/uwmediapicker_item_gallery_video.xml",
"chars": 1154,
"preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<androidx.constraintlayout.widget.ConstraintLayout xmlns:android=\"http://schemas."
},
{
"path": "uwmediapicker/src/main/res/values/colors.xml",
"chars": 1372,
"preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<resources>\n <color name=\"colorUwMediaPickerStatusBar\">#F6F6F6</color>\n <co"
},
{
"path": "uwmediapicker/src/main/res/values/dimens.xml",
"chars": 685,
"preview": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<resources>\n <!-- Font Sizes-->\n <dimen name=\"uwmediapicker_text_size_toolb"
},
{
"path": "uwmediapicker/src/main/res/values/strings.xml",
"chars": 1908,
"preview": "<resources xmlns:tools=\"http://schemas.android.com/tools\">\n <!-- Toolbar Texts -->\n <string name=\"uwmediapicker_to"
},
{
"path": "uwmediapicker/src/main/res/values/styles.xml",
"chars": 3165,
"preview": "<resources>\n <!-- Themes -->\n <style name=\"UwMediaPickerProgressBarTheme\">\n <item name=\"colorAccent\">@color"
}
]
// ... and 1 more files (download for full content)
About this extraction
This page contains the full source code of the AnilFurkanOkcun/UWMediaPicker-Android GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 82 files (142.8 KB), approximately 39.5k tokens. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.
Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.