├── .gitignore
├── README.md
├── bintray-settings.gradle
├── build.gradle
├── external
└── gradle_scripts
│ ├── bintrayv1.gradle
│ └── installv1.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── sample
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── julienarzul
│ │ └── simpledialogfragment
│ │ └── sample
│ │ ├── MainActivity.java
│ │ └── NestedFragment.java
│ └── res
│ ├── layout
│ ├── activity_main.xml
│ ├── content_main.xml
│ └── fragment_nested.xml
│ ├── mipmap-hdpi
│ └── ic_launcher.png
│ ├── mipmap-mdpi
│ └── ic_launcher.png
│ ├── mipmap-xhdpi
│ └── ic_launcher.png
│ ├── mipmap-xxhdpi
│ └── ic_launcher.png
│ ├── mipmap-xxxhdpi
│ └── ic_launcher.png
│ ├── values-v21
│ └── styles.xml
│ ├── values-w820dp
│ └── dimens.xml
│ └── values
│ ├── colors.xml
│ ├── dimens.xml
│ ├── strings.xml
│ └── styles.xml
├── settings.gradle
└── simpledialogfragment
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
└── main
├── AndroidManifest.xml
├── java
└── com
│ └── julienarzul
│ └── simpledialogfragment
│ ├── AndroidStringResource.java
│ ├── SimpleDialogContent.java
│ └── SimpleDialogFragment.java
└── res
└── values
└── strings.xml
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea
5 | .DS_Store
6 | /build
7 | /captures
8 | .externalNativeBuild
9 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # SimpleDialogFragment
2 | An Android library that provides a simple implementation of a DialogFragment.
3 |
4 | Are you tired of creating a new DialogFragment for each Dialog that you want to display?
5 |
6 | The current recommended way of displaying Dialogs in an Android application involves the creation of a subclass of a DialogFragment (official documentation can be found [here](https://developer.android.com/guide/topics/ui/dialogs.html)).
7 | Creating a new DialogFragment subclass for each Dialog we need to display in an application is tedious and we all know that an application often contains a lot of these dialogs. This leads to lots of DialogFragment classes that provide no value to the project.
8 | What if we could eliminate those?
9 |
10 | This library is a simple implementation of a DialogFragment that allows you to specify the content of the Dialog, while still using the recommended DialogFragment and all its lifecycle benefits.
11 |
12 | Example of use :
13 |
14 | SimpleDialogFragment.newInstance(
15 | SimpleDialogContent.builder()
16 | .setTitle("My Title")
17 | .setMessage("My Dialog Message")
18 | .build())
19 | .show(this.getSupportFragmentManager(), SimpleDialogFragment.TAG);
20 |
21 |
22 | ## Getting started
23 |
24 | dependencies {
25 | compile 'com.julienarzul:simpledialogfragment:1.1.1'
26 | }
27 |
28 | ## How to use
29 | ### Basic Use
30 | The simplest way to use this library is to show a Dialog with a title, message and a positive button.
31 |
32 | In order to do that, we simply need to create and show a new instance of the SimpleDialogFragment class. The instance created must be given a SimpleDialogContent object that will define the content of the Dialog shown.
33 |
34 | The following example shows the code to use to display a dialog with a custom title, custom message and custom positive button text (this is the enclosing Activity or Fragment):
35 |
36 | SimpleDialogFragment.newInstance(
37 | SimpleDialogContent.builder()
38 | .setTitle("My Title")
39 | .setMessage("My Dialog Message")
40 | .setPositiveButtonText("Got it")
41 | .build())
42 | .show(this.getSupportFragmentManager(), SimpleDialogFragment.TAG);
43 |
44 | ### Supported AlertDialog content
45 | The SimpleDialogContent object given to the SimpleDialogFragment supports defining:
46 | * a title
47 | * a message
48 | * a positive button
49 | * a negative button
50 | * a neutral button
51 | * whether the Dialog should be cancelable or not
52 |
53 | Any combination of these attributes can easily be created via the SimpleDialogContent.Builder.
54 |
55 | It is mandatory to specify at least a non-null message to the dialog.
56 |
57 | ### Specify button listeners
58 | More often than not, we need to implement some behaviour when the user has agreed (or disagreed) to the content of the Dialog. For that purpose, we need to add listeners to the SimpleDialogFragment. The Android documentation shows an example where the Activity containing the DialogFragment is the dialog's buttons listener ([here](https://developer.android.com/guide/topics/ui/dialogs.html#PassingEvents)). Implementing it that way allows the listener to be kept on activity lifecycle events (such as activity destruction/recreation).
59 |
60 | This library uses the exact same principle. The enclosing activity must implement an interface if it want to listen to the dialog's buttons click events. The below example shows how to listen to the positive and negative buttons click events:
61 |
62 | public class MyActivity extends AppCompatActivity implements SimpleDialogFragment.OnPositiveButtonClickListener,
63 | SimpleDialogFragment.OnNegativeButtonClickListener
64 |
65 | There are three interfaces that the activity can implement:
66 | * SimpleDialogFragment.OnPositiveButtonClickListener
67 | * SimpleDialogFragment.OnNegativeButtonClickListener
68 | * SimpleDialogFragment.OnNeutralButtonClickListener
69 |
70 | #### Particular case: Dialogs inside Fragments
71 | When displaying a DialogFragment inside a Fragment, we probably would like to perform our Dialog click behavior directly in our Fragment and completely bypass the Activity.
72 | SimpleDialogFragment allows you to do that easily.
73 |
74 | Implement the listener interfaces directly in your Fragment:
75 |
76 | public class NestedFragment extends Fragment implements SimpleDialogFragment.OnPositiveButtonClickListener,
77 | SimpleDialogFragment.OnNegativeButtonClickListener
78 |
79 | and display the SimpleDialogFragment:
80 |
81 | SimpleDialogFragment.newInstance(dialogContent)
82 | .show(this.getChildFragmentManager(), SimpleDialogFragment.TAG);
83 |
84 | **Warning:** Since we're nesting a fragment into another one, you must use the *getChildFragmentManager()* method to show the dialog.
85 |
86 | #### Particular case: Displaying several SimpleDialogFragments
87 | When displaying several SimpleDialogFragment in the same Activity (or Fragment), we need a way to know which dialog triggered a click on the buttons.
88 | To fix that problem, SimpleDialogFragment uses a Request Code, in the same manner than with onActivityResult.
89 |
90 | When creating a SimpleDialogContent object, you can give it a request code:
91 |
92 | SimpleDialogContent dialogContent = SimpleDialogContent.builder()
93 | .setMessage("Fire missiles?")
94 | .setPositiveButtonText("Fire")
95 | .setNegativeButtonText("Cancel")
96 | .setRequestCode(SIMPLE_DIALOG_FRAGMENT_MY_REQUEST_CODE)
97 | .build();
98 |
99 | That request code is then passed to you in each of the click events triggered by the listeners:
100 |
101 | @Override
102 | public void onDialogPositiveButtonClicked(DialogInterface dialog, Integer requestCode) {
103 | if (requestCode != null) {
104 | switch (requestCode) {
105 | case SIMPLE_DIALOG_FRAGMENT_MY_REQUEST_CODE:
106 | // TODO: Implement positive button behaviour
107 | break;
108 | }
109 | }
110 | }
111 |
112 | ## Contributing
113 | Any contributions is welcome through Pull Requests. Please take the time to clearly explain the feature you wish to add or the bug you're trying to fix.
114 |
115 | Don't hesitate to raise an issue before opening a pull request so that we can discuss it before-hand.
116 |
117 | ## License
118 |
119 | Copyright 2017 Julien Arzul
120 |
121 | Licensed under the Apache License, Version 2.0 (the "License");
122 | you may not use this file except in compliance with the License.
123 | You may obtain a copy of the License at
124 |
125 | http://www.apache.org/licenses/LICENSE-2.0
126 |
127 | Unless required by applicable law or agreed to in writing, software
128 | distributed under the License is distributed on an "AS IS" BASIS,
129 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
130 | See the License for the specific language governing permissions and
131 | limitations under the License.
132 |
--------------------------------------------------------------------------------
/bintray-settings.gradle:
--------------------------------------------------------------------------------
1 | ext {
2 | bintrayRepo = 'AndroidLibraries'
3 | bintrayName = 'SimpleDialogFragment'
4 |
5 | publishedGroupId = 'com.julienarzul'
6 | libraryName = 'SimpleDialogFragment'
7 | artifact = 'simpledialogfragment'
8 |
9 | libraryDescription = 'An Android library that provides a simple implementation of a DialogFragment'
10 |
11 | siteUrl = 'https://github.com/JulienArzul/SimpleDialogFragment'
12 | gitUrl = 'https://github.com/JulienArzul/SimpleDialogFragment.git'
13 |
14 | libraryVersion = '1.1.1'
15 |
16 | developerId = 'JulienArzul'
17 | developerName = 'Julien Arzul'
18 | developerEmail = 'julien.arzul@gmail.com'
19 |
20 | licenseName = 'The Apache Software License, Version 2.0'
21 | licenseUrl = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
22 | allLicenses = ["Apache-2.0"]
23 | }
--------------------------------------------------------------------------------
/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.2'
9 | classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.4'
10 | classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'
11 |
12 | // NOTE: Do not place your application dependencies here; they belong
13 | // in the individual module build.gradle files
14 | }
15 | }
16 |
17 | allprojects {
18 | repositories {
19 | jcenter()
20 | }
21 | }
22 |
23 | ext {
24 | // Build tools
25 | compileSdkVersion = 25
26 | buildToolsVersion = "25.0.2"
27 | minSdkVersion = 15
28 | targetSdkVersion = 25
29 |
30 | // Google Versions
31 | supportVersion = "25.1.1"
32 | autoValueVersion = "1.2"
33 |
34 | // Square Versions
35 | butterknifeVersion = "8.5.1"
36 |
37 | // Other Versions
38 | autoParcelVersion = "1.0.3"
39 |
40 | // Tests Libs versions
41 | junitVersion = "4.12"
42 | espressoVersion = "2.2.2"
43 | }
44 |
45 | task clean(type: Delete) {
46 | delete rootProject.buildDir
47 | }
48 |
--------------------------------------------------------------------------------
/external/gradle_scripts/bintrayv1.gradle:
--------------------------------------------------------------------------------
1 | // Copied from https://github.com/nuuneoi/JCenter
2 |
3 | apply plugin: 'com.jfrog.bintray'
4 |
5 | version = libraryVersion
6 |
7 | if (project.hasProperty("android")) { // Android libraries
8 | task sourcesJar(type: Jar) {
9 | classifier = 'sources'
10 | from android.sourceSets.main.java.srcDirs
11 | }
12 |
13 | task javadoc(type: Javadoc) {
14 | source = android.sourceSets.main.java.srcDirs
15 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
16 | }
17 | } else { // Java libraries
18 | task sourcesJar(type: Jar, dependsOn: classes) {
19 | classifier = 'sources'
20 | from sourceSets.main.allSource
21 | }
22 | }
23 |
24 | task javadocJar(type: Jar, dependsOn: javadoc) {
25 | classifier = 'javadoc'
26 | from javadoc.destinationDir
27 | }
28 |
29 | artifacts {
30 | archives javadocJar
31 | archives sourcesJar
32 | }
33 |
34 | // Bintray
35 | Properties properties = new Properties()
36 | properties.load(project.rootProject.file('local.properties').newDataInputStream())
37 |
38 | bintray {
39 | user = properties.getProperty("bintray.user")
40 | key = properties.getProperty("bintray.apikey")
41 |
42 | configurations = ['archives']
43 | pkg {
44 | repo = bintrayRepo
45 | name = bintrayName
46 | desc = libraryDescription
47 | websiteUrl = siteUrl
48 | vcsUrl = gitUrl
49 | licenses = allLicenses
50 | publish = true
51 | publicDownloadNumbers = true
52 | version {
53 | desc = libraryDescription
54 | gpg {
55 | sign = true //Determines whether to GPG sign the files. The default is false
56 | passphrase = properties.getProperty("bintray.gpg.password")
57 | //Optional. The passphrase for GPG signing'
58 | }
59 | }
60 | }
61 | }
62 |
63 | // Added to handle dependencies link in the Javadoc :
64 | // http://stackoverflow.com/questions/34571371/android-studio-javadoc-cannot-find-symbol
65 | afterEvaluate {
66 | javadoc.classpath += files(android.libraryVariants.collect { variant ->
67 | variant.javaCompile.classpath.files
68 | })
69 | }
--------------------------------------------------------------------------------
/external/gradle_scripts/installv1.gradle:
--------------------------------------------------------------------------------
1 | // Copied from https://github.com/nuuneoi/JCenter
2 |
3 | apply plugin: 'com.github.dcendents.android-maven'
4 |
5 | group = publishedGroupId // Maven Group ID for the artifact
6 |
7 | install {
8 | repositories.mavenInstaller {
9 | // This generates POM.xml with proper parameters
10 | pom {
11 | project {
12 | packaging 'aar'
13 | groupId publishedGroupId
14 | artifactId artifact
15 |
16 | // Add your description here
17 | name libraryName
18 | description libraryDescription
19 | url siteUrl
20 |
21 | // Set your license
22 | licenses {
23 | license {
24 | name licenseName
25 | url licenseUrl
26 | }
27 | }
28 | developers {
29 | developer {
30 | id developerId
31 | name developerName
32 | email developerEmail
33 | }
34 | }
35 | scm {
36 | connection gitUrl
37 | developerConnection gitUrl
38 | url siteUrl
39 |
40 | }
41 | }
42 | }
43 | }
44 | }
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx1536m
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JulienArzul/SimpleDialogFragment/322de5fdf1dd95ef85182dfb2afd3f891ec91d53/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sat May 20 14:25:40 AEST 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 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/sample/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/sample/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion rootProject.ext.compileSdkVersion
5 | buildToolsVersion rootProject.ext.buildToolsVersion
6 |
7 | defaultConfig {
8 | applicationId "com.julienarzul.simpledialogfragment.sample"
9 | minSdkVersion rootProject.ext.minSdkVersion
10 | targetSdkVersion rootProject.ext.targetSdkVersion
11 | versionCode 2
12 | versionName "1.1.1"
13 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
14 | }
15 | buildTypes {
16 | release {
17 | minifyEnabled false
18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
19 | }
20 | }
21 | }
22 |
23 | dependencies {
24 | compile project(':simpledialogfragment')
25 |
26 | compile "com.android.support:appcompat-v7:$rootProject.ext.supportVersion"
27 | compile "com.android.support:design:$rootProject.ext.supportVersion"
28 |
29 | compile "com.jakewharton:butterknife:$rootProject.ext.butterknifeVersion"
30 | annotationProcessor "com.jakewharton:butterknife-compiler:$rootProject.ext.butterknifeVersion"
31 |
32 | testCompile "junit:junit:$rootProject.ext.junitVersion"
33 | androidTestCompile("com.android.support.test.espresso:espresso-core:$rootProject.ext.espressoVersion", {
34 | exclude group: 'com.android.support', module: 'support-annotations'
35 | })
36 | }
37 |
--------------------------------------------------------------------------------
/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 /Users/julienarzul/Library/Android/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/sample/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
13 | * Copyright @ Julien Arzul 2017 14 | */ 15 | @AutoValue 16 | abstract class AndroidStringResource implements Parcelable { 17 | 18 | static AndroidStringResource create(@StringRes int stringResId) { 19 | return new AutoValue_AndroidStringResource(null, stringResId); 20 | } 21 | 22 | static AndroidStringResource create(String string) { 23 | return new AutoValue_AndroidStringResource(string, 0); 24 | } 25 | 26 | static String valueOf(AndroidStringResource androidStringResource, Context context) { 27 | if (androidStringResource == null) { 28 | return null; 29 | } 30 | 31 | return androidStringResource.value(context); 32 | } 33 | 34 | @Nullable 35 | abstract String string(); 36 | 37 | @StringRes 38 | abstract int resId(); 39 | 40 | String value(Context context) { 41 | String result = string(); 42 | 43 | if (result == null) { 44 | int resId = resId(); 45 | if (resId != 0) { 46 | result = context.getString(resId); 47 | } 48 | } 49 | 50 | return result; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /simpledialogfragment/src/main/java/com/julienarzul/simpledialogfragment/SimpleDialogContent.java: -------------------------------------------------------------------------------- 1 | package com.julienarzul.simpledialogfragment; 2 | 3 | import android.content.Context; 4 | import android.os.Parcelable; 5 | import android.support.annotation.Nullable; 6 | import android.support.annotation.StringRes; 7 | 8 | import com.google.auto.value.AutoValue; 9 | 10 | /** 11 | * Immutable value class that represents the content of an AlertDialog shown with {@link SimpleDialogFragment}. 12 | * The class is Parcelable in order to be given to the DialogFragment as a bundle argument. 13 | *
14 | * Create an instance of this class with a {@link SimpleDialogContent.Builder}, retrieved through the static method 15 | * {@link #builder()}. 16 | *
17 | * The only required @NotNull field is the message of the dialog. 18 | *
19 | * Copyright @ Julien Arzul 2016 20 | */ 21 | @AutoValue 22 | public abstract class SimpleDialogContent implements Parcelable { 23 | 24 | public static Builder builder() { 25 | return new AutoValue_SimpleDialogContent.Builder() 26 | .setCancelable(true); 27 | } 28 | 29 | @Nullable 30 | abstract AndroidStringResource title(); 31 | 32 | abstract AndroidStringResource message(); 33 | 34 | @Nullable 35 | abstract AndroidStringResource positiveButtonText(); 36 | 37 | @Nullable 38 | abstract AndroidStringResource negativeButtonText(); 39 | 40 | @Nullable 41 | abstract AndroidStringResource neutralButtonText(); 42 | 43 | @Nullable 44 | public abstract Integer requestCode(); 45 | 46 | public abstract boolean cancelable(); 47 | 48 | public String title(Context context) { 49 | return AndroidStringResource.valueOf(this.title(), context); 50 | } 51 | 52 | public String message(Context context) { 53 | return AndroidStringResource.valueOf(this.message(), context); 54 | } 55 | 56 | public String positiveButtonText(Context context) { 57 | return AndroidStringResource.valueOf(this.positiveButtonText(), context); 58 | } 59 | 60 | public String negativeButtonText(Context context) { 61 | return AndroidStringResource.valueOf(this.negativeButtonText(), context); 62 | } 63 | 64 | public String neutralButtonText(Context context) { 65 | return AndroidStringResource.valueOf(this.neutralButtonText(), context); 66 | } 67 | 68 | @AutoValue.Builder 69 | public abstract static class Builder { 70 | 71 | abstract Builder setTitle(AndroidStringResource title); 72 | 73 | abstract Builder setMessage(AndroidStringResource message); 74 | 75 | abstract Builder setPositiveButtonText(AndroidStringResource positiveButtonText); 76 | 77 | abstract Builder setNegativeButtonText(AndroidStringResource negativeButtonText); 78 | 79 | abstract Builder setNeutralButtonText(AndroidStringResource neutralButtonText); 80 | 81 | public abstract Builder setRequestCode(Integer requestCode); 82 | 83 | public abstract Builder setCancelable(boolean cancelable); 84 | 85 | public abstract SimpleDialogContent build(); 86 | 87 | public Builder setTitle(String title) { 88 | return this.setTitle(AndroidStringResource.create(title)); 89 | } 90 | 91 | public Builder setTitle(@StringRes int title) { 92 | return this.setTitle(AndroidStringResource.create(title)); 93 | } 94 | 95 | public Builder setMessage(String message) { 96 | return this.setMessage(AndroidStringResource.create(message)); 97 | } 98 | 99 | public Builder setMessage(@StringRes int message) { 100 | return this.setMessage(AndroidStringResource.create(message)); 101 | } 102 | 103 | public Builder setPositiveButtonText(String positiveButtonText) { 104 | return this.setPositiveButtonText(AndroidStringResource.create(positiveButtonText)); 105 | } 106 | 107 | public Builder setPositiveButtonText(@StringRes int positiveButtonText) { 108 | return this.setPositiveButtonText(AndroidStringResource.create(positiveButtonText)); 109 | } 110 | 111 | public Builder setNegativeButtonText(String negativeButtonText) { 112 | return this.setNegativeButtonText(AndroidStringResource.create(negativeButtonText)); 113 | } 114 | 115 | public Builder setNegativeButtonText(@StringRes int negativeButtonText) { 116 | return this.setNegativeButtonText(AndroidStringResource.create(negativeButtonText)); 117 | } 118 | 119 | public Builder setNeutralButtonText(String neutralButtonText) { 120 | return this.setNeutralButtonText(AndroidStringResource.create(neutralButtonText)); 121 | } 122 | 123 | public Builder setNeutralButtonText(@StringRes int neutralButtonText) { 124 | return this.setNeutralButtonText(AndroidStringResource.create(neutralButtonText)); 125 | } 126 | } 127 | } 128 | -------------------------------------------------------------------------------- /simpledialogfragment/src/main/java/com/julienarzul/simpledialogfragment/SimpleDialogFragment.java: -------------------------------------------------------------------------------- 1 | package com.julienarzul.simpledialogfragment; 2 | 3 | import android.app.Dialog; 4 | import android.content.Context; 5 | import android.content.DialogInterface; 6 | import android.os.Bundle; 7 | import android.support.annotation.NonNull; 8 | import android.support.annotation.Nullable; 9 | import android.support.v4.app.DialogFragment; 10 | import android.support.v4.app.Fragment; 11 | import android.support.v4.app.FragmentActivity; 12 | import android.support.v4.app.FragmentManager; 13 | import android.support.v4.util.Pair; 14 | import android.support.v7.app.AlertDialog; 15 | import android.text.TextUtils; 16 | 17 | /** 18 | * Simple implementation of a DialogFragment that allows you to specify the content of the AlertDialog 19 | * displayed without subclassing it. 20 | *
21 | * This DialogFragment must be instantiated with a {@link SimpleDialogContent} via the factory method {@link 22 | * #newInstance(SimpleDialogContent)} 23 | *
24 | * You can easily define listeners for the buttons set in the {@link SimpleDialogContent} with one of the two methods: 25 | *
31 | * There are three different listener interfaces that you can implement: 32 | *
42 | * Copyright @ Julien Arzul 2016
43 | */
44 | public class SimpleDialogFragment extends DialogFragment implements DialogInterface.OnClickListener {
45 |
46 | public static final String TAG = "SimpleDialogFragment";
47 |
48 | private static final Integer DEFAULT_REQUEST_CODE = 0;
49 |
50 | private static final String DIALOG_CONTENT_BUNDLE_KEY = "com.julienarzul.simpledialogfragment.SimpleDialogFragment.dialogContent";
51 |
52 | private SimpleDialogContent dialogContent = null;
53 |
54 | /**
55 | * Creates a new instance of a {@link SimpleDialogFragment}. It must be given a {@link SimpleDialogContent} to
56 | * define the {@link AlertDialog} content.
57 | *
58 | * @param dialogContent Instance of {@link SimpleDialogContent} representing the content of the {@link AlertDialog}
59 | * that will be displayed.
60 | *
61 | * @return A new instance of {@link SimpleDialogFragment}. Don't forget to call {{@link #show(FragmentManager,
62 | * String)}} to actually display the {@link DialogFragment}
63 | */
64 | public static SimpleDialogFragment newInstance(SimpleDialogContent dialogContent) {
65 | Bundle args = new Bundle();
66 |
67 | args.putParcelable(DIALOG_CONTENT_BUNDLE_KEY, dialogContent);
68 |
69 | SimpleDialogFragment fragment = new SimpleDialogFragment();
70 | fragment.setArguments(args);
71 | return fragment;
72 | }
73 |
74 | @Override
75 | public void onCreate(@Nullable Bundle savedInstanceState) {
76 | super.onCreate(savedInstanceState);
77 |
78 | Bundle arguments = getArguments();
79 | if (arguments != null) {
80 | this.dialogContent = arguments.getParcelable(DIALOG_CONTENT_BUNDLE_KEY);
81 |
82 | if (this.dialogContent != null) {
83 | this.setCancelable(this.dialogContent.cancelable());
84 | }
85 | }
86 | }
87 |
88 | @NonNull
89 | @Override
90 | public Dialog onCreateDialog(Bundle savedInstanceState) {
91 | AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
92 | Context context = this.getContext();
93 |
94 | String title = null, message = null, positiveButtonText = null, negativeButtonText = null, neutralButtonText = null;
95 | if (this.dialogContent != null) {
96 | title = this.dialogContent.title(context);
97 | message = this.dialogContent.message(context);
98 | positiveButtonText = this.dialogContent.positiveButtonText(context);
99 | negativeButtonText = this.dialogContent.negativeButtonText(context);
100 | neutralButtonText = this.dialogContent.neutralButtonText(context);
101 | }
102 |
103 | if (!TextUtils.isEmpty(title)) {
104 | builder.setTitle(title);
105 | }
106 | if (!TextUtils.isEmpty(message)) {
107 | builder.setMessage(message);
108 | }
109 | if (!TextUtils.isEmpty(positiveButtonText)) {
110 | builder.setPositiveButton(positiveButtonText, this);
111 | }
112 | if (!TextUtils.isEmpty(negativeButtonText)) {
113 | builder.setNegativeButton(negativeButtonText, this);
114 | }
115 | if (!TextUtils.isEmpty(neutralButtonText)) {
116 | builder.setNeutralButton(neutralButtonText, this);
117 | }
118 |
119 | return builder.create();
120 | }
121 |
122 | @Override
123 | public void onClick(DialogInterface dialog, int which) {
124 | switch (which) {
125 | case DialogInterface.BUTTON_POSITIVE:
126 | Pair