├── .gitignore
├── README.md
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── images
├── Colored_icons.png
├── Open.png
└── Save.png
├── library
├── .gitignore
├── build.gradle
├── gradle.properties
├── maven-push.gradle
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── rustamg
│ │ └── filedialogs
│ │ ├── ExtensionFilter.java
│ │ ├── FileDialog.java
│ │ ├── FileListAdapter.java
│ │ ├── FileNameValidator.java
│ │ ├── OpenFileDialog.java
│ │ ├── SaveFileDialog.java
│ │ └── utils
│ │ ├── KeyboardUtils.java
│ │ └── TextUtils.java
│ └── res
│ ├── drawable-hdpi
│ ├── ic_action_accept.png
│ ├── ic_cross.png
│ ├── ic_file.png
│ └── ic_folder.png
│ ├── drawable-mdpi
│ ├── ic_action_accept.png
│ ├── ic_cross.png
│ ├── ic_file.png
│ └── ic_folder.png
│ ├── drawable-xhdpi
│ ├── ic_action_accept.png
│ ├── ic_cross.png
│ ├── ic_file.png
│ └── ic_folder.png
│ ├── drawable-xxhdpi
│ ├── ic_action_accept.png
│ ├── ic_cross.png
│ ├── ic_file.png
│ └── ic_folder.png
│ ├── layout
│ ├── dialog_open_file.xml
│ ├── dialog_save_file.xml
│ └── list_item_file.xml
│ ├── menu
│ └── dialog_save.xml
│ └── values
│ ├── attrs.xml
│ ├── dimens.xml
│ └── strings.xml
├── sample
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── rustamg
│ │ └── filedialogs
│ │ └── ApplicationTest.java
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── rustamg
│ │ └── filedialogs
│ │ └── sample
│ │ └── MainActivity.java
│ └── res
│ ├── layout
│ └── activity_main.xml
│ ├── mipmap-hdpi
│ └── ic_launcher.png
│ ├── mipmap-mdpi
│ └── ic_launcher.png
│ ├── mipmap-xhdpi
│ └── ic_launcher.png
│ ├── mipmap-xxhdpi
│ └── ic_launcher.png
│ ├── values-w820dp
│ └── dimens.xml
│ └── values
│ ├── colors.xml
│ ├── dimens.xml
│ ├── strings.xml
│ └── styles.xml
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | .gradle
2 | /local.properties
3 | /.idea
4 | .DS_Store
5 | /build
6 | *.iml
7 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # File Dialogs
2 | Android library with save and open file dialogs.
3 |
4 |
5 | ## Features
6 | **Open file dialog** | **Save file dialog**
7 | -------------------- | --------------------
8 |
|
9 |
10 |
11 |
12 | ## Usage
13 | ```java
14 | // You can use either OpenFileDialog or SaveFileDialog depending on your needs
15 | FileDialog dialog = new OpenFileDialog();
16 | dialog.setStyle(DialogFragment.STYLE_NO_TITLE, R.style.Your_Theme);
17 | dialog.show(getSupportFragmentManager(), OpenFileDialog.class.getName());
18 | ```
19 | #### Specifying file extension
20 |
21 | If you need to show files with specific extension add the following lines before showing the dialog:
22 |
23 | ```java
24 | Bundle args = new Bundle();
25 | args.putString(FileDialog.EXTENSION, "png"); // file extension is optional
26 | dialog.setArguments(args);
27 | ```
28 |
29 | To receive callbacks when user selected a file (either for open or save) make your fragment or activity implement ```FileDialog.OnFileSelectedListener```.
30 |
31 |
32 | #### Changing Toolbar icons color
33 |
34 | In order to change the color of icons in a toolbar, add the following item to your theme declaration:
35 | ```xml
36 | - #ff3f4aff
37 | ```
38 |
39 |
40 |
41 | Please refer to the sample project to see how it works.
42 |
43 | For more detailed toolbar customization please use toolbarStyle item (without ```android:``` prefix) in the theme that is used for the dialog.
44 |
45 | ## Download
46 | Gradle:
47 | ```groovy
48 | compile 'com.github.rustamg:file-dialogs:1.0'
49 | ```
50 |
51 | Maven:
52 | ```xml
53 |
54 | com.github.rustamg
55 | file-dialogs
56 | 1.0
57 | aar
58 |
59 | ```
60 |
61 | ### MIT License
62 |
63 | ```
64 | The MIT License (MIT)
65 |
66 | Copyright (c) 2015 Rustam Gilyaev
67 |
68 | Permission is hereby granted, free of charge, to any person obtaining a copy
69 | of this software and associated documentation files (the "Software"), to deal
70 | in the Software without restriction, including without limitation the rights
71 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
72 | copies of the Software, and to permit persons to whom the Software is
73 | furnished to do so, subject to the following conditions:
74 |
75 | The above copyright notice and this permission notice shall be included in
76 | all copies or substantial portions of the Software.
77 |
78 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
79 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
80 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
81 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
82 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
83 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
84 | THE SOFTWARE.
85 | ```
86 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:2.3.0'
9 |
10 | // NOTE: Do not place your application dependencies here; they belong
11 | // in the individual module build.gradle files
12 | }
13 | }
14 |
15 | allprojects {
16 | repositories {
17 | jcenter()
18 | }
19 | }
20 |
21 | ext {
22 | verMinSdk = 16
23 | verCompileSdk = 25
24 | verTargetSdk = verCompileSdk
25 | verBuildTools = '25.0.2'
26 | verSupportLibrary = '25.2.0'
27 |
28 | appCompat = "com.android.support:appcompat-v7:$verSupportLibrary"
29 | supportV4 = "com.android.support:support-v4:$verSupportLibrary"
30 | recyclerView = 'com.android.support:recyclerview-v7:25.2.0'
31 | materialEditText = 'com.rengwuxian.materialedittext:library:2.1.4'
32 | butterknife = 'com.jakewharton:butterknife:6.1.0'
33 |
34 | rxPermissions = 'com.tbruyelle.rxpermissions:rxpermissions:0.9.3@aar'
35 | rxJava = 'io.reactivex:rxjava:1.2.2'
36 | }
37 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
19 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RustamG/file-dialogs/230b8302b95bd1a577ba0f1fd441f1fdc615190d/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Mar 27 20:37:21 SAMT 2017
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # For Cygwin, ensure paths are in UNIX format before anything is touched.
46 | if $cygwin ; then
47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
48 | fi
49 |
50 | # Attempt to set APP_HOME
51 | # Resolve links: $0 may be a link
52 | PRG="$0"
53 | # Need this for relative symlinks.
54 | while [ -h "$PRG" ] ; do
55 | ls=`ls -ld "$PRG"`
56 | link=`expr "$ls" : '.*-> \(.*\)$'`
57 | if expr "$link" : '/.*' > /dev/null; then
58 | PRG="$link"
59 | else
60 | PRG=`dirname "$PRG"`"/$link"
61 | fi
62 | done
63 | SAVED="`pwd`"
64 | cd "`dirname \"$PRG\"`/" >&-
65 | APP_HOME="`pwd -P`"
66 | cd "$SAVED" >&-
67 |
68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
69 |
70 | # Determine the Java command to use to start the JVM.
71 | if [ -n "$JAVA_HOME" ] ; then
72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
73 | # IBM's JDK on AIX uses strange locations for the executables
74 | JAVACMD="$JAVA_HOME/jre/sh/java"
75 | else
76 | JAVACMD="$JAVA_HOME/bin/java"
77 | fi
78 | if [ ! -x "$JAVACMD" ] ; then
79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
80 |
81 | Please set the JAVA_HOME variable in your environment to match the
82 | location of your Java installation."
83 | fi
84 | else
85 | JAVACMD="java"
86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
87 |
88 | Please set the JAVA_HOME variable in your environment to match the
89 | location of your Java installation."
90 | fi
91 |
92 | # Increase the maximum file descriptors if we can.
93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
94 | MAX_FD_LIMIT=`ulimit -H -n`
95 | if [ $? -eq 0 ] ; then
96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
97 | MAX_FD="$MAX_FD_LIMIT"
98 | fi
99 | ulimit -n $MAX_FD
100 | if [ $? -ne 0 ] ; then
101 | warn "Could not set maximum file descriptor limit: $MAX_FD"
102 | fi
103 | else
104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
105 | fi
106 | fi
107 |
108 | # For Darwin, add options to specify how the application appears in the dock
109 | if $darwin; then
110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
111 | fi
112 |
113 | # For Cygwin, switch paths to Windows format before running java
114 | if $cygwin ; then
115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
158 | function splitJvmOpts() {
159 | JVM_OPTS=("$@")
160 | }
161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
163 |
164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
165 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/images/Colored_icons.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RustamG/file-dialogs/230b8302b95bd1a577ba0f1fd441f1fdc615190d/images/Colored_icons.png
--------------------------------------------------------------------------------
/images/Open.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RustamG/file-dialogs/230b8302b95bd1a577ba0f1fd441f1fdc615190d/images/Open.png
--------------------------------------------------------------------------------
/images/Save.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RustamG/file-dialogs/230b8302b95bd1a577ba0f1fd441f1fdc615190d/images/Save.png
--------------------------------------------------------------------------------
/library/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 | maven-credentials.properties
3 |
--------------------------------------------------------------------------------
/library/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 25
5 | buildToolsVersion "25.0.2"
6 |
7 | defaultConfig {
8 | minSdkVersion 15
9 | targetSdkVersion 25
10 | versionCode 3
11 | versionName "1.0"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 |
20 | compileOptions {
21 | sourceCompatibility JavaVersion.VERSION_1_7
22 | targetCompatibility JavaVersion.VERSION_1_7
23 | }
24 |
25 | packagingOptions {
26 | exclude 'META-INF/DEPENDENCIES.txt'
27 | exclude 'META-INF/DEPENDENCIES'
28 | exclude 'META-INF/LICENSE.txt'
29 | exclude 'META-INF/LICENSE'
30 | exclude 'META-INF/NOTICE.txt'
31 | exclude 'META-INF/NOTICE'
32 | }
33 | }
34 |
35 | dependencies {
36 | compile fileTree(dir: 'libs', include: ['*.jar'])
37 |
38 | compile rootProject.ext.appCompat
39 |
40 | compile rootProject.ext.materialEditText
41 | compile rootProject.ext.recyclerView
42 | }
43 |
44 | apply from: 'maven-push.gradle'
45 |
--------------------------------------------------------------------------------
/library/gradle.properties:
--------------------------------------------------------------------------------
1 | POM_NAME=File Dialogs
2 | POM_ARTIFACT_ID=file-dialogs
3 | POM_PACKAGING=aar
4 | VERSION_NAME=1.0
5 | VERSION_CODE=6
6 | GROUP=com.github.rustamg
7 |
8 | POM_DESCRIPTION=Material File Dialogs library for Android
9 | POM_URL=https://github.com/RustamG/file-dialogs
10 | POM_SCM_URL=https://github.com/RustamG/file-dialogs.git
11 | POM_SCM_CONNECTION=scm:git@github.com:RustamG/file-dialogs
12 | POM_SCM_DEV_CONNECTION=scm:git@github.com:RustamG/file-dialogs
13 | POM_LICENCE_NAME=MIT License
14 | POM_LICENCE_URL=http://www.opensource.org/licenses/mit-license.php
15 | POM_LICENCE_DIST=repo
16 | POM_DEVELOPER_ID=rustamg
17 | POM_DEVELOPER_NAME=rustamg
18 |
19 | SNAPSHOT_REPOSITORY_URL=https://oss.sonatype.org/content/repositories/snapshots
20 | RELEASE_REPOSITORY_URL=https://oss.sonatype.org/service/local/staging/deploy/maven2
21 |
--------------------------------------------------------------------------------
/library/maven-push.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Chris Banes
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | apply plugin: 'maven'
18 | apply plugin: 'signing'
19 |
20 | Properties props = new Properties()
21 | props.load(new FileInputStream("$project.projectDir/maven-credentials.properties"))
22 | props.each { prop ->
23 | project.ext.set(prop.key, prop.value)
24 | }
25 |
26 | def isReleaseBuild() {
27 | return VERSION_NAME.contains("SNAPSHOT") == false
28 | }
29 |
30 | def getReleaseRepositoryUrl() {
31 | return hasProperty('RELEASE_REPOSITORY_URL') ? RELEASE_REPOSITORY_URL
32 | : "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
33 | }
34 |
35 | def getSnapshotRepositoryUrl() {
36 | return hasProperty('SNAPSHOT_REPOSITORY_URL') ? SNAPSHOT_REPOSITORY_URL
37 | : "https://oss.sonatype.org/content/repositories/snapshots/"
38 | }
39 |
40 | def getRepositoryUsername() {
41 | return hasProperty('NEXUS_USERNAME') ? NEXUS_USERNAME : project.ext.NEXUS_USERNAME
42 | }
43 |
44 | def getRepositoryPassword() {
45 | return hasProperty('NEXUS_PASSWORD') ? NEXUS_PASSWORD : project.ext.NEXUS_PASSWORD
46 | }
47 |
48 | afterEvaluate { project ->
49 | uploadArchives {
50 | repositories {
51 | mavenDeployer {
52 | beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
53 |
54 | pom.groupId = GROUP
55 | pom.artifactId = POM_ARTIFACT_ID
56 | pom.version = VERSION_NAME
57 |
58 | repository(url: getReleaseRepositoryUrl()) {
59 | authentication(userName: getRepositoryUsername(), password: getRepositoryPassword())
60 | }
61 | snapshotRepository(url: getSnapshotRepositoryUrl()) {
62 | authentication(userName: getRepositoryUsername(), password: getRepositoryPassword())
63 | }
64 |
65 | pom.project {
66 | name POM_NAME
67 | packaging POM_PACKAGING
68 | description POM_DESCRIPTION
69 | url POM_URL
70 |
71 | scm {
72 | url POM_SCM_URL
73 | connection POM_SCM_CONNECTION
74 | developerConnection POM_SCM_DEV_CONNECTION
75 | }
76 |
77 | licenses {
78 | license {
79 | name POM_LICENCE_NAME
80 | url POM_LICENCE_URL
81 | distribution POM_LICENCE_DIST
82 | }
83 | }
84 |
85 | developers {
86 | developer {
87 | id POM_DEVELOPER_ID
88 | name POM_DEVELOPER_NAME
89 | }
90 | }
91 | }
92 | }
93 | }
94 | }
95 |
96 | signing {
97 | required { isReleaseBuild() && gradle.taskGraph.hasTask("uploadArchives") }
98 | sign configurations.archives
99 | }
100 |
101 | //task androidJavadocs(type: Javadoc) {
102 | //source = android.sourceSets.main.allJava
103 | //}
104 |
105 | //task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) {
106 | //classifier = 'javadoc'
107 | //from androidJavadocs.destinationDir
108 | //}
109 |
110 | task androidSourcesJar(type: Jar) {
111 | classifier = 'sources'
112 | from android.sourceSets.main.java.sourceFiles
113 | }
114 |
115 | artifacts {
116 | archives androidSourcesJar
117 | }
118 | }
119 |
--------------------------------------------------------------------------------
/library/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Library/AndroidSDK/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/library/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
--------------------------------------------------------------------------------
/library/src/main/java/com/rustamg/filedialogs/ExtensionFilter.java:
--------------------------------------------------------------------------------
1 | package com.rustamg.filedialogs;
2 | import java.io.File;
3 | import java.io.FileFilter;
4 |
5 |
6 | public class ExtensionFilter implements FileFilter {
7 |
8 |
9 | private final String mExtension;
10 |
11 | public ExtensionFilter(String extension) {
12 |
13 | extension = extension.toLowerCase().replaceAll("\\.", "");
14 |
15 | if (!extension.isEmpty()) {
16 | extension = "." + extension;
17 | }
18 |
19 | mExtension = extension;
20 | }
21 |
22 | @Override
23 | public boolean accept(File file) {
24 |
25 | return file.isDirectory() || file.getName().toLowerCase().endsWith(mExtension);
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/library/src/main/java/com/rustamg/filedialogs/FileDialog.java:
--------------------------------------------------------------------------------
1 | package com.rustamg.filedialogs;
2 | import android.app.Activity;
3 | import android.content.DialogInterface;
4 | import android.content.res.TypedArray;
5 | import android.graphics.Color;
6 | import android.graphics.PorterDuff;
7 | import android.graphics.drawable.Drawable;
8 | import android.os.AsyncTask;
9 | import android.os.Bundle;
10 | import android.os.Environment;
11 | import android.support.annotation.Nullable;
12 | import android.support.v4.app.DialogFragment;
13 | import android.support.v4.app.Fragment;
14 | import android.support.v4.content.res.ResourcesCompat;
15 | import android.support.v7.widget.LinearLayoutManager;
16 | import android.support.v7.widget.RecyclerView;
17 | import android.support.v7.widget.Toolbar;
18 | import android.util.TypedValue;
19 | import android.view.LayoutInflater;
20 | import android.view.View;
21 | import android.view.ViewGroup;
22 | import android.widget.ProgressBar;
23 |
24 | import com.rustamg.filedialogs.utils.KeyboardUtils;
25 |
26 | import java.io.File;
27 | import java.io.FileFilter;
28 |
29 |
30 | /**
31 | * Created at 31/01/15 12:27
32 | *
33 | * @author rustamg
34 | */
35 | public abstract class FileDialog extends DialogFragment implements FileListAdapter.OnFileSelectedListener {
36 |
37 | public static final String ROOT_DIRECTORY = "root_directory";
38 | public static final String START_DIRECTORY = "start_directory";
39 | public static final String EXTENSION = "extension";
40 |
41 | private static final String OUT_STATE_CURRENT_DIRECTORY = "out_state_current_dir";
42 | private static final String EXTERNAL_ROOT_PATH = Environment.getExternalStorageDirectory().getPath();
43 |
44 | protected File mCurrentDir;
45 | protected File mRootDir;
46 | protected FileFilter mFilesFilter;
47 |
48 | protected Toolbar mToolbar;
49 | protected ProgressBar mProgress;
50 | protected RecyclerView mRecyclerView;
51 | protected int mIconColor;
52 |
53 | private UpdateFilesTask mUpdateFilesTask;
54 | protected String mExtension;
55 |
56 | private String mRootPathDisplayName; // todo: create an argument for this
57 |
58 |
59 | @Override
60 | public void onAttach(Activity activity) {
61 |
62 | super.onAttach(activity);
63 |
64 | int[] iconColorAttr = new int[] { R.attr.file_dialog_toolbar_icons_color };
65 | int indexOfAttrIconColor = 0;
66 | TypedValue typedValue = new TypedValue();
67 | TypedArray a = activity.obtainStyledAttributes(typedValue.data, iconColorAttr);
68 | mIconColor = a.getColor(indexOfAttrIconColor, Color.WHITE);
69 | a.recycle();
70 | }
71 |
72 | @Override
73 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
74 | @Nullable Bundle savedInstanceState) {
75 |
76 | // getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);
77 |
78 | return inflater.inflate(getLayoutResourceId(), container);
79 | }
80 |
81 | @Override
82 | public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
83 |
84 | super.onViewCreated(view, savedInstanceState);
85 |
86 | mToolbar = (Toolbar) view.findViewById(R.id.toolbar);
87 | mProgress = (ProgressBar) view.findViewById(R.id.progress);
88 | mRecyclerView = (RecyclerView) view.findViewById(R.id.rv_files);
89 |
90 | mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
91 |
92 | @Override
93 | public void onClick(View v) {
94 |
95 | if (mCurrentDir.getPath().equalsIgnoreCase(EXTERNAL_ROOT_PATH)) {
96 | dismiss();
97 | }
98 | else {
99 | mCurrentDir = mCurrentDir.getParentFile();
100 | refresh();
101 | }
102 | }
103 | });
104 |
105 | extractArguments(savedInstanceState);
106 |
107 | initList();
108 | }
109 |
110 | protected void extractArguments(Bundle savedInstanceState) {
111 |
112 | Bundle arguments = getArguments();
113 |
114 | mRootDir = arguments != null ? (File) arguments.getSerializable(ROOT_DIRECTORY) : null;
115 |
116 | if (savedInstanceState != null) {
117 | mCurrentDir = (File) savedInstanceState.getSerializable(OUT_STATE_CURRENT_DIRECTORY);
118 | }
119 | else {
120 | mCurrentDir = (File) (arguments != null ? arguments.getSerializable(START_DIRECTORY) : null);
121 | }
122 |
123 | if (mCurrentDir == null) {
124 | mCurrentDir = new File(EXTERNAL_ROOT_PATH);
125 | }
126 |
127 | if (mRootDir == null) {
128 | mRootDir = mCurrentDir;
129 | }
130 |
131 | if (arguments != null && arguments.containsKey(EXTENSION)) {
132 | mExtension = arguments.getString(EXTENSION);
133 | mFilesFilter = new ExtensionFilter(mExtension);
134 | }
135 | }
136 |
137 | private void initList() {
138 |
139 | mRecyclerView.setHasFixedSize(true);
140 | mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
141 | }
142 |
143 | @Override
144 | public void onStart() {
145 |
146 | super.onStart();
147 |
148 | refresh();
149 | }
150 |
151 | public void refresh() {
152 |
153 | if (mUpdateFilesTask == null || mUpdateFilesTask.getStatus() == AsyncTask.Status.FINISHED) {
154 |
155 | mUpdateFilesTask = new UpdateFilesTask();
156 | mUpdateFilesTask.execute(mCurrentDir);
157 | }
158 | }
159 |
160 | @Override
161 | public void onStop() {
162 |
163 | super.onStop();
164 | mUpdateFilesTask.cancel(false);
165 | }
166 |
167 | @Override
168 | public void onFileSelected(File file) {
169 |
170 | if (file.isDirectory()) {
171 | mCurrentDir = file;
172 | refresh();
173 | }
174 | }
175 |
176 | @Override
177 | public void onSaveInstanceState(Bundle outState) {
178 |
179 | super.onSaveInstanceState(outState);
180 |
181 | outState.putSerializable(OUT_STATE_CURRENT_DIRECTORY, mCurrentDir);
182 | }
183 |
184 | protected void sendResult(File file) {
185 |
186 | Fragment targetFragment = getParentFragment();
187 |
188 | if (targetFragment != null && targetFragment instanceof OnFileSelectedListener) {
189 | ((OnFileSelectedListener) targetFragment).onFileSelected(this, file);
190 | }
191 | else {
192 | Activity activity = getActivity();
193 | if (activity != null && activity instanceof OnFileSelectedListener) {
194 | ((OnFileSelectedListener) activity).onFileSelected(this, file);
195 | }
196 | }
197 |
198 | dismiss();
199 | }
200 |
201 | protected abstract int getLayoutResourceId();
202 |
203 | private class UpdateFilesTask extends AsyncTask {
204 |
205 | private File[] mFileArray;
206 | private File mDirectory;
207 |
208 | private UpdateFilesTask() {
209 |
210 | }
211 |
212 | @Override
213 | protected void onPreExecute() {
214 |
215 | super.onPreExecute();
216 |
217 | mProgress.setVisibility(View.VISIBLE);
218 | }
219 |
220 | @Override
221 | protected File[] doInBackground(File... files) {
222 |
223 | mDirectory = files[0];
224 | mFileArray = files[0].listFiles(mFilesFilter);
225 |
226 | return mFileArray;
227 | }
228 |
229 | @Override
230 | protected void onPostExecute(File[] localFiles) {
231 |
232 | super.onPostExecute(localFiles);
233 |
234 | if (!isCancelled() && getActivity() != null) {
235 |
236 | Drawable navIcon;
237 |
238 | if (mDirectory.getPath().equalsIgnoreCase(EXTERNAL_ROOT_PATH)) {
239 |
240 | mToolbar.setTitle(mRootPathDisplayName);
241 | navIcon = ResourcesCompat.getDrawable(getResources(), R.drawable.ic_cross, null);
242 | }
243 | else {
244 | mToolbar.setTitle(mCurrentDir.getName());
245 | navIcon = ResourcesCompat.getDrawable(getResources(), R.drawable.abc_ic_ab_back_material, null);
246 | }
247 |
248 | navIcon.setColorFilter(mIconColor, PorterDuff.Mode.SRC_IN);
249 | mToolbar.setNavigationIcon(navIcon);
250 |
251 | mRecyclerView.setAdapter(new FileListAdapter(getActivity(), localFiles, FileDialog.this));
252 |
253 | mProgress.setVisibility(View.GONE);
254 | }
255 | }
256 | }
257 |
258 | @Override
259 | public void onDismiss(DialogInterface dialog) {
260 |
261 | if (getActivity() != null) {
262 | KeyboardUtils.hideKeyboard(getActivity());
263 | }
264 | super.onDismiss(dialog);
265 | }
266 |
267 | public interface OnFileSelectedListener {
268 |
269 | void onFileSelected(FileDialog dialog, File file);
270 | }
271 | }
272 |
--------------------------------------------------------------------------------
/library/src/main/java/com/rustamg/filedialogs/FileListAdapter.java:
--------------------------------------------------------------------------------
1 | package com.rustamg.filedialogs;
2 | import android.content.Context;
3 | import android.support.v7.widget.RecyclerView;
4 | import android.view.LayoutInflater;
5 | import android.view.View;
6 | import android.view.ViewGroup;
7 | import android.widget.ImageView;
8 | import android.widget.TextView;
9 |
10 | import java.io.File;
11 | import java.text.DateFormat;
12 | import java.util.Date;
13 |
14 |
15 | /**
16 | * Created at 30/01/15 21:18
17 | *
18 | * @author rustamg
19 | */
20 | public class FileListAdapter extends RecyclerView.Adapter {
21 |
22 | private static DateFormat sModificationTimeFormat = DateFormat.getDateTimeInstance();
23 |
24 | private final File[] mFiles;
25 | private final LayoutInflater mInflater;
26 | private final OnFileSelectedListener mOnFileSelectedListener;
27 |
28 | public FileListAdapter(Context context, File[] files, OnFileSelectedListener fileSelectedListener) {
29 |
30 | if (files == null) {
31 | throw new IllegalArgumentException("Files list is null. " +
32 | "Please make sure that you have read permission to this directory. " +
33 | "Have you added android.permission.READ_EXTERNAL_STORAGE permission to your AndroidManifest.xml?");
34 | }
35 |
36 | mFiles = files;
37 | mInflater = LayoutInflater.from(context);
38 | mOnFileSelectedListener = fileSelectedListener;
39 | }
40 |
41 | @Override
42 | public FileViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
43 |
44 | View view = mInflater.inflate(R.layout.list_item_file, parent, false);
45 |
46 | return new FileViewHolder(view);
47 | }
48 |
49 | @Override
50 | public void onBindViewHolder(final FileViewHolder holder, int position) {
51 |
52 | holder.bind(mFiles[position]);
53 |
54 | holder.getView().setOnClickListener(new View.OnClickListener() {
55 |
56 | @Override
57 | public void onClick(View v) {
58 |
59 | if (mOnFileSelectedListener != null) {
60 | mOnFileSelectedListener.onFileSelected(holder.getFile());
61 | }
62 | }
63 | });
64 | }
65 |
66 | @Override
67 | public int getItemCount() {
68 |
69 | return mFiles.length;
70 | }
71 |
72 | public class FileViewHolder extends RecyclerView.ViewHolder {
73 |
74 | private View mView;
75 | private File mFile;
76 |
77 | protected TextView mFileNameText;
78 | protected TextView mFileModifiedText;
79 | protected ImageView mFileIcon;
80 |
81 | public FileViewHolder(View itemView) {
82 |
83 | super(itemView);
84 |
85 | mView = itemView;
86 |
87 | mFileNameText = (TextView) itemView.findViewById(R.id.tv_file_name);
88 | mFileModifiedText = (TextView) itemView.findViewById(R.id.tv_file_modified);
89 | mFileIcon = (ImageView) itemView.findViewById(R.id.iv_file_icon);
90 | }
91 |
92 | public void bind(File file) {
93 |
94 | mFile = file;
95 |
96 | if (file.isDirectory()) {
97 |
98 | mFileIcon.setImageResource(R.drawable.ic_folder);
99 | }
100 | else {
101 | mFileIcon.setImageResource(R.drawable.ic_file);
102 | }
103 |
104 | mFileNameText.setText(file.getName());
105 | mFileModifiedText.setText(sModificationTimeFormat.format(new Date(file.lastModified())));
106 | }
107 |
108 | public File getFile() {
109 |
110 | return mFile;
111 | }
112 |
113 | public View getView() {
114 |
115 | return mView;
116 | }
117 | }
118 |
119 |
120 | public interface OnFileSelectedListener {
121 |
122 | void onFileSelected(File item);
123 | }
124 | }
125 |
--------------------------------------------------------------------------------
/library/src/main/java/com/rustamg/filedialogs/FileNameValidator.java:
--------------------------------------------------------------------------------
1 | package com.rustamg.filedialogs;
2 | import android.support.annotation.NonNull;
3 |
4 | import com.rengwuxian.materialedittext.validation.METValidator;
5 | import com.rustamg.filedialogs.utils.TextUtils;
6 |
7 |
8 | /**
9 | * Created at 31/01/15 13:29
10 | *
11 | * @author rustamg
12 | */
13 | public class FileNameValidator extends METValidator {
14 |
15 | private final String mEmptyMessage;
16 | private final String mInvalidMessage;
17 |
18 | public FileNameValidator(String invalidMessage, String emptyMessage) {
19 |
20 | super(emptyMessage);
21 |
22 | mInvalidMessage = invalidMessage;
23 | mEmptyMessage = emptyMessage;
24 | }
25 |
26 | @Override
27 | public boolean isValid(@NonNull CharSequence charSequence, boolean isEmpty) {
28 |
29 | if (isEmpty || TextUtils.isEmpty(charSequence.toString())) {
30 | errorMessage = mEmptyMessage;
31 | return false;
32 | }
33 |
34 | if (charSequence.toString().matches("^[^A-Za-z_\\-\\s0-9\\.]+$")) {
35 | errorMessage = mInvalidMessage;
36 | return false;
37 | }
38 |
39 | return true;
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/library/src/main/java/com/rustamg/filedialogs/OpenFileDialog.java:
--------------------------------------------------------------------------------
1 | package com.rustamg.filedialogs;
2 |
3 | import java.io.File;
4 |
5 |
6 | /**
7 | * Created at 30/01/15 18:58
8 | *
9 | * @author rustamg
10 | */
11 | public class OpenFileDialog extends FileDialog {
12 |
13 |
14 | @Override
15 | protected int getLayoutResourceId() {
16 |
17 | return R.layout.dialog_open_file;
18 | }
19 |
20 | @Override
21 | public void onFileSelected(File file) {
22 |
23 | if (file.isFile()) {
24 | sendResult(file);
25 | }
26 | else {
27 | super.onFileSelected(file);
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/library/src/main/java/com/rustamg/filedialogs/SaveFileDialog.java:
--------------------------------------------------------------------------------
1 | package com.rustamg.filedialogs;
2 | import android.app.AlertDialog;
3 | import android.content.DialogInterface;
4 | import android.graphics.PorterDuff;
5 | import android.os.Bundle;
6 | import android.support.annotation.Nullable;
7 | import android.support.v7.widget.Toolbar;
8 | import android.view.MenuItem;
9 | import android.view.View;
10 |
11 | import com.rengwuxian.materialedittext.MaterialEditText;
12 |
13 | import java.io.File;
14 |
15 |
16 | /**
17 | * Created at 31/01/15 12:07
18 | *
19 | * @author rustamg
20 | */
21 | public class SaveFileDialog extends FileDialog implements Toolbar.OnMenuItemClickListener {
22 |
23 |
24 | protected MaterialEditText mFileNameText;
25 |
26 | @Override
27 | protected int getLayoutResourceId() {
28 |
29 | return R.layout.dialog_save_file;
30 | }
31 |
32 | @Override
33 | public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
34 |
35 | super.onViewCreated(view, savedInstanceState);
36 |
37 | mFileNameText = (MaterialEditText) view.findViewById(R.id.et_filename);
38 |
39 | mToolbar.inflateMenu(R.menu.dialog_save);
40 | mToolbar.getMenu().findItem(R.id.menu_apply).getIcon().setColorFilter(mIconColor, PorterDuff.Mode.SRC_IN);
41 | mToolbar.setOnMenuItemClickListener(this);
42 |
43 | mFileNameText.addValidator(new FileNameValidator(getString(R.string.error_invalid_file_name),
44 | getString(R.string.error_empty_field)));
45 | }
46 |
47 | @Override
48 | public void onFileSelected(final File file) {
49 |
50 | if (file.isFile()) {
51 |
52 | confirmOverwrite(file);
53 | }
54 | else {
55 | super.onFileSelected(file);
56 | }
57 | }
58 |
59 | private void confirmOverwrite(final File file) {
60 |
61 | new AlertDialog.Builder(getActivity())
62 | .setMessage(R.string.confirm_overwrite_file)
63 | .setPositiveButton(R.string.label_button_overwrite, new DialogInterface.OnClickListener() {
64 |
65 | @Override
66 | public void onClick(DialogInterface dialog, int which) {
67 |
68 | sendResult(file);
69 | }
70 | })
71 | .setNegativeButton(R.string.label_button_cancel, null)
72 | .create().show();
73 | }
74 |
75 |
76 | @Override
77 | public boolean onMenuItemClick(MenuItem menuItem) {
78 |
79 | if (menuItem.getItemId() == R.id.menu_apply && mFileNameText.validate()) {
80 |
81 | String input = mFileNameText.getText().toString();
82 | String inputExtension = "";
83 |
84 | if(mExtension != null) {
85 | if (!input.endsWith("." + mExtension)) {
86 | inputExtension = "." + mExtension;
87 | }
88 | }
89 |
90 | File result = new File(mCurrentDir, mFileNameText.getText() + inputExtension);
91 |
92 |
93 | if (result.exists()) {
94 | confirmOverwrite(result);
95 | }
96 | else {
97 | sendResult(result);
98 | }
99 | }
100 |
101 | return false;
102 | }
103 | }
104 |
--------------------------------------------------------------------------------
/library/src/main/java/com/rustamg/filedialogs/utils/KeyboardUtils.java:
--------------------------------------------------------------------------------
1 | package com.rustamg.filedialogs.utils;
2 | import android.app.Activity;
3 | import android.content.Context;
4 | import android.view.View;
5 | import android.view.inputmethod.InputMethodManager;
6 |
7 |
8 | /**
9 | * Created at 17/02/15 18:22
10 | *
11 | * @author rustamg
12 | */
13 | public class KeyboardUtils {
14 |
15 | public static void hideKeyboard(Activity activity) {
16 |
17 | InputMethodManager inputManager = (InputMethodManager) activity.getSystemService(
18 | Context.INPUT_METHOD_SERVICE);
19 |
20 | // check if no view has focus:
21 | View view = activity.getCurrentFocus();
22 | if (view != null) {
23 | inputManager.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/library/src/main/java/com/rustamg/filedialogs/utils/TextUtils.java:
--------------------------------------------------------------------------------
1 | package com.rustamg.filedialogs.utils;
2 | import java.util.ArrayList;
3 | import java.util.List;
4 |
5 |
6 | /**
7 | * Created at 17/02/15 18:10
8 | *
9 | * @author rustamg
10 | */
11 | public class TextUtils {
12 |
13 | public static boolean isEmpty(String string) {
14 |
15 | return string == null || string.trim().length() == 0;
16 | }
17 |
18 |
19 | public static String getIntegersCommaSeparated(List array) {
20 |
21 | StringBuilder sb = new StringBuilder();
22 |
23 | sb.append(array.get(0));
24 |
25 | for (int i = 1; i < array.size(); i++) {
26 | sb.append(",");
27 | sb.append(array.get(i));
28 | }
29 |
30 | return sb.toString();
31 | }
32 |
33 | public static String getLongsCommaSeparated(List array) {
34 |
35 | StringBuilder sb = new StringBuilder();
36 |
37 | sb.append(array.get(0));
38 |
39 | for (int i = 1; i < array.size(); i++) {
40 | sb.append(",");
41 | sb.append(array.get(i));
42 | }
43 |
44 | return sb.toString();
45 | }
46 |
47 | public static List getLongs(String commaSeparatedString) {
48 |
49 | List longs = new ArrayList<>();
50 |
51 | String[] strings = commaSeparatedString.split(",");
52 |
53 | for (String s : strings) {
54 | longs.add(Long.parseLong(s));
55 | }
56 |
57 | return longs;
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/library/src/main/res/drawable-hdpi/ic_action_accept.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RustamG/file-dialogs/230b8302b95bd1a577ba0f1fd441f1fdc615190d/library/src/main/res/drawable-hdpi/ic_action_accept.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-hdpi/ic_cross.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RustamG/file-dialogs/230b8302b95bd1a577ba0f1fd441f1fdc615190d/library/src/main/res/drawable-hdpi/ic_cross.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-hdpi/ic_file.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RustamG/file-dialogs/230b8302b95bd1a577ba0f1fd441f1fdc615190d/library/src/main/res/drawable-hdpi/ic_file.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-hdpi/ic_folder.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RustamG/file-dialogs/230b8302b95bd1a577ba0f1fd441f1fdc615190d/library/src/main/res/drawable-hdpi/ic_folder.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-mdpi/ic_action_accept.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RustamG/file-dialogs/230b8302b95bd1a577ba0f1fd441f1fdc615190d/library/src/main/res/drawable-mdpi/ic_action_accept.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-mdpi/ic_cross.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RustamG/file-dialogs/230b8302b95bd1a577ba0f1fd441f1fdc615190d/library/src/main/res/drawable-mdpi/ic_cross.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-mdpi/ic_file.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RustamG/file-dialogs/230b8302b95bd1a577ba0f1fd441f1fdc615190d/library/src/main/res/drawable-mdpi/ic_file.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-mdpi/ic_folder.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RustamG/file-dialogs/230b8302b95bd1a577ba0f1fd441f1fdc615190d/library/src/main/res/drawable-mdpi/ic_folder.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-xhdpi/ic_action_accept.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RustamG/file-dialogs/230b8302b95bd1a577ba0f1fd441f1fdc615190d/library/src/main/res/drawable-xhdpi/ic_action_accept.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-xhdpi/ic_cross.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RustamG/file-dialogs/230b8302b95bd1a577ba0f1fd441f1fdc615190d/library/src/main/res/drawable-xhdpi/ic_cross.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-xhdpi/ic_file.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RustamG/file-dialogs/230b8302b95bd1a577ba0f1fd441f1fdc615190d/library/src/main/res/drawable-xhdpi/ic_file.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-xhdpi/ic_folder.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RustamG/file-dialogs/230b8302b95bd1a577ba0f1fd441f1fdc615190d/library/src/main/res/drawable-xhdpi/ic_folder.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-xxhdpi/ic_action_accept.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RustamG/file-dialogs/230b8302b95bd1a577ba0f1fd441f1fdc615190d/library/src/main/res/drawable-xxhdpi/ic_action_accept.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-xxhdpi/ic_cross.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RustamG/file-dialogs/230b8302b95bd1a577ba0f1fd441f1fdc615190d/library/src/main/res/drawable-xxhdpi/ic_cross.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-xxhdpi/ic_file.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RustamG/file-dialogs/230b8302b95bd1a577ba0f1fd441f1fdc615190d/library/src/main/res/drawable-xxhdpi/ic_file.png
--------------------------------------------------------------------------------
/library/src/main/res/drawable-xxhdpi/ic_folder.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RustamG/file-dialogs/230b8302b95bd1a577ba0f1fd441f1fdc615190d/library/src/main/res/drawable-xxhdpi/ic_folder.png
--------------------------------------------------------------------------------
/library/src/main/res/layout/dialog_open_file.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
9 |
16 |
17 |
20 |
21 |
29 |
30 |
35 |
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/library/src/main/res/layout/dialog_save_file.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
9 |
16 |
17 |
21 |
22 |
30 |
31 |
36 |
37 |
38 |
39 |
40 |
44 |
45 |
52 |
53 |
54 |
55 |
--------------------------------------------------------------------------------
/library/src/main/res/layout/list_item_file.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
11 |
15 |
16 |
21 |
22 |
29 |
30 |
38 |
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/library/src/main/res/menu/dialog_save.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
--------------------------------------------------------------------------------
/library/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/library/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 16dp
5 | 8dp
6 | 56dp
7 |
8 |
--------------------------------------------------------------------------------
/library/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Library
3 |
4 | Enter file name
5 |
6 | Invalid file name
7 | This field is required
8 |
9 | Save
10 | Overwrite the file?
11 | Overwrite
12 | Cancel
13 |
14 |
15 |
--------------------------------------------------------------------------------
/sample/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/sample/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion rootProject.ext.verCompileSdk
5 | buildToolsVersion rootProject.ext.verBuildTools
6 |
7 | defaultConfig {
8 | applicationId "com.rustamg.filedialogs"
9 | minSdkVersion rootProject.ext.verMinSdk
10 | targetSdkVersion rootProject.ext.verTargetSdk
11 | versionCode 1
12 | versionName "1.0"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(dir: 'libs', include: ['*.jar'])
24 | compile rootProject.ext.appCompat
25 | compile rootProject.ext.butterknife
26 | compile rootProject.ext.rxPermissions
27 | compile rootProject.ext.rxJava
28 | compile 'com.github.rustamg:file-dialogs:1.0'
29 | // compile project(':library')
30 | }
31 |
--------------------------------------------------------------------------------
/sample/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Library/AndroidSDK/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/sample/src/androidTest/java/com/rustamg/filedialogs/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.rustamg.filedialogs;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 |
7 | /**
8 | * Testing Fundamentals
9 | */
10 | public class ApplicationTest extends ApplicationTestCase {
11 |
12 | public ApplicationTest() {
13 |
14 | super(Application.class);
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/sample/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
12 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/sample/src/main/java/com/rustamg/filedialogs/sample/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.rustamg.filedialogs.sample;
2 |
3 | import android.Manifest;
4 | import android.os.Bundle;
5 | import android.support.v4.app.DialogFragment;
6 | import android.support.v7.app.AppCompatActivity;
7 | import android.widget.Button;
8 | import android.widget.EditText;
9 | import android.widget.Toast;
10 |
11 | import com.rustamg.filedialogs.FileDialog;
12 | import com.rustamg.filedialogs.OpenFileDialog;
13 | import com.rustamg.filedialogs.SaveFileDialog;
14 | import com.tbruyelle.rxpermissions.RxPermissions;
15 |
16 | import java.io.File;
17 |
18 | import butterknife.ButterKnife;
19 | import butterknife.InjectView;
20 | import butterknife.OnClick;
21 | import rx.functions.Action1;
22 |
23 |
24 | public class MainActivity extends AppCompatActivity implements FileDialog.OnFileSelectedListener {
25 |
26 | @InjectView(R.id.et_extension)
27 | protected EditText mExtensionText;
28 | @InjectView(R.id.btn_test_open_dialog)
29 | protected Button mOpenFileButton;
30 | @InjectView(R.id.btn_test_save_dialog)
31 | protected Button mSaveFileButton;
32 |
33 | private boolean mStoragePermissionGranted;
34 |
35 | @Override
36 | protected void onCreate(Bundle savedInstanceState) {
37 |
38 | super.onCreate(savedInstanceState);
39 | setContentView(R.layout.activity_main);
40 |
41 | ButterKnife.inject(this);
42 |
43 | requestStoragePermissions();
44 | }
45 |
46 | private void requestStoragePermissions() {
47 |
48 | new RxPermissions(this)
49 | .request(Manifest.permission.READ_EXTERNAL_STORAGE)
50 | .subscribe(new Action1() {
51 |
52 | @Override
53 | public void call(Boolean granted) {
54 |
55 | mStoragePermissionGranted = granted;
56 | }
57 | });
58 | }
59 |
60 | @OnClick(R.id.btn_test_open_dialog)
61 | protected void onOpenDialogClick() {
62 |
63 | if (mStoragePermissionGranted) {
64 | showFileDialog(new OpenFileDialog(), OpenFileDialog.class.getName());
65 | }
66 | else {
67 | showPermissionError();
68 | }
69 | }
70 |
71 | @OnClick(R.id.btn_test_save_dialog)
72 | protected void onSaveDialogClick() {
73 |
74 | if (mStoragePermissionGranted) {
75 | showFileDialog(new SaveFileDialog(), SaveFileDialog.class.getName());
76 | }
77 | else {
78 | showPermissionError();
79 | }
80 | }
81 |
82 | private void showPermissionError() {
83 |
84 | Toast.makeText(this, "Storage permission is not granted", Toast.LENGTH_LONG).show();
85 | }
86 |
87 | private void showFileDialog(FileDialog dialog, String tag) {
88 |
89 | Bundle args = new Bundle();
90 | args.putString(FileDialog.EXTENSION, mExtensionText.getText().toString());
91 | dialog.setArguments(args);
92 | dialog.setStyle(DialogFragment.STYLE_NO_TITLE, R.style.Theme_Sample);
93 | dialog.show(getSupportFragmentManager(), tag);
94 | }
95 |
96 | @Override
97 | public void onFileSelected(FileDialog dialog, File file) {
98 |
99 | Toast.makeText(this, getString(R.string.toast_file_selected, file.getName()), Toast.LENGTH_LONG).show();
100 | }
101 | }
102 |
--------------------------------------------------------------------------------
/sample/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
16 |
17 |
23 |
24 |
29 |
30 |
35 |
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RustamG/file-dialogs/230b8302b95bd1a577ba0f1fd441f1fdc615190d/sample/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RustamG/file-dialogs/230b8302b95bd1a577ba0f1fd441f1fdc615190d/sample/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RustamG/file-dialogs/230b8302b95bd1a577ba0f1fd441f1fdc615190d/sample/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RustamG/file-dialogs/230b8302b95bd1a577ba0f1fd441f1fdc615190d/sample/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/sample/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | #4CAF50
5 | #388E3C
6 | #C8E6C9
7 | #8BC34A
8 | #FFFFFF
9 | #B6B6B6
10 |
11 | #212121
12 | #727272
13 |
14 |
--------------------------------------------------------------------------------
/sample/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/sample/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | File Dialogs
3 | MainActivity
4 |
5 | Hello world!
6 | Settings
7 | Open file dialog
8 | Save File dialog
9 | Selected file: %1$s
10 | Extension Filter
11 |
12 |
--------------------------------------------------------------------------------
/sample/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
17 |
18 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':sample', ':library'
2 |
--------------------------------------------------------------------------------