├── .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 | 4 | 5 | 11 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /sample/src/main/java/com/julienarzul/simpledialogfragment/sample/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.julienarzul.simpledialogfragment.sample; 2 | 3 | import android.content.DialogInterface; 4 | import android.os.Bundle; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.support.v7.widget.Toolbar; 7 | import android.widget.Toast; 8 | 9 | import com.julienarzul.simpledialogfragment.SimpleDialogContent; 10 | import com.julienarzul.simpledialogfragment.SimpleDialogFragment; 11 | 12 | import butterknife.ButterKnife; 13 | import butterknife.OnClick; 14 | 15 | public class MainActivity extends AppCompatActivity implements SimpleDialogFragment.OnPositiveButtonClickListener, 16 | SimpleDialogFragment.OnNegativeButtonClickListener, SimpleDialogFragment.OnNeutralButtonClickListener { 17 | 18 | private static final int SIMPLE_DIALOG_ONE_BUTTON_REQUEST_CODE = 1; 19 | private static final int SIMPLE_DIALOG_TWO_BUTTONS_REQUEST_CODE = 2; 20 | private static final int SIMPLE_DIALOG_NOT_CANCELABLE_REQUEST_CODE = 3; 21 | private static final int SIMPLE_DIALOG_THREE_BUTTONS_REQUEST_CODE = 4; 22 | 23 | @Override 24 | protected void onCreate(Bundle savedInstanceState) { 25 | super.onCreate(savedInstanceState); 26 | setContentView(R.layout.activity_main); 27 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 28 | setSupportActionBar(toolbar); 29 | 30 | ButterKnife.bind(this); 31 | 32 | if (savedInstanceState == null) { 33 | this.getSupportFragmentManager() 34 | .beginTransaction() 35 | .add(R.id.simple_dialog_fragment_container, NestedFragment.newInstance()) 36 | .commit(); 37 | } 38 | } 39 | 40 | private void displaySimpleDialogFragment(SimpleDialogContent dialogContent) { 41 | SimpleDialogFragment.newInstance(dialogContent) 42 | .show(this.getSupportFragmentManager(), SimpleDialogFragment.TAG); 43 | } 44 | 45 | @OnClick(R.id.simple_dialog_no_title_button) 46 | void onNoTitleButtonClicked() { 47 | this.displaySimpleDialogFragment( 48 | SimpleDialogContent.builder() 49 | .setMessage(this.getString(R.string.dialog_message)) 50 | .build()); 51 | } 52 | 53 | @OnClick(R.id.simple_dialog_with_title_button) 54 | void onWithTitleButtonClicked() { 55 | this.displaySimpleDialogFragment( 56 | SimpleDialogContent.builder() 57 | .setTitle(this.getString(R.string.dialog_title)) 58 | .setMessage(this.getString(R.string.dialog_message)) 59 | .build()); 60 | } 61 | 62 | @OnClick(R.id.simple_dialog_one_button_button) 63 | void onOneButtonButtonClicked() { 64 | this.displaySimpleDialogFragment( 65 | SimpleDialogContent.builder() 66 | .setTitle(R.string.dialog_title) 67 | .setMessage(R.string.dialog_message) 68 | .setPositiveButtonText(R.string.dialog_button_positive) 69 | .setRequestCode(SIMPLE_DIALOG_ONE_BUTTON_REQUEST_CODE) 70 | .build()); 71 | } 72 | 73 | @OnClick(R.id.simple_dialog_two_buttons_button) 74 | void onTwoButtonsButtonClicked() { 75 | this.displaySimpleDialogFragment( 76 | SimpleDialogContent.builder() 77 | .setTitle(this.getString(R.string.dialog_title)) 78 | .setMessage(this.getString(R.string.dialog_message)) 79 | .setPositiveButtonText(this.getString(R.string.dialog_button_positive)) 80 | .setNegativeButtonText(this.getString(R.string.dialog_button_negative)) 81 | .setRequestCode(SIMPLE_DIALOG_TWO_BUTTONS_REQUEST_CODE) 82 | .build()); 83 | } 84 | 85 | @OnClick(R.id.simple_dialog_three_buttons_button) 86 | void onThreeButtonsButtonClicked() { 87 | this.displaySimpleDialogFragment( 88 | SimpleDialogContent.builder() 89 | .setTitle(R.string.dialog_title) 90 | .setMessage(R.string.dialog_message) 91 | .setPositiveButtonText(R.string.dialog_button_positive) 92 | .setNegativeButtonText(R.string.dialog_button_negative) 93 | .setNeutralButtonText(R.string.dialog_button_neutral) 94 | .setRequestCode(SIMPLE_DIALOG_THREE_BUTTONS_REQUEST_CODE) 95 | .build()); 96 | } 97 | 98 | @OnClick(R.id.simple_dialog_not_cancelable_button) 99 | void onNotCancelableButtonClicked() { 100 | this.displaySimpleDialogFragment( 101 | SimpleDialogContent.builder() 102 | .setTitle(this.getString(R.string.dialog_title)) 103 | .setMessage(this.getString(R.string.dialog_message)) 104 | .setPositiveButtonText(this.getString(R.string.dialog_button_positive)) 105 | .setRequestCode(SIMPLE_DIALOG_NOT_CANCELABLE_REQUEST_CODE) 106 | .setCancelable(false) 107 | .build()); 108 | } 109 | 110 | @Override 111 | public void onDialogPositiveButtonClicked(DialogInterface dialog, Integer requestCode) { 112 | if (requestCode != null) { 113 | switch (requestCode) { 114 | case SIMPLE_DIALOG_ONE_BUTTON_REQUEST_CODE: 115 | Toast.makeText(this, "One button - Positive button clicked", Toast.LENGTH_SHORT).show(); 116 | break; 117 | 118 | case SIMPLE_DIALOG_TWO_BUTTONS_REQUEST_CODE: 119 | Toast.makeText(this, "Two buttons - Positive button clicked", Toast.LENGTH_SHORT).show(); 120 | break; 121 | 122 | case SIMPLE_DIALOG_THREE_BUTTONS_REQUEST_CODE: 123 | Toast.makeText(this, "Three buttons - Positive button clicked", Toast.LENGTH_SHORT).show(); 124 | break; 125 | 126 | case SIMPLE_DIALOG_NOT_CANCELABLE_REQUEST_CODE: 127 | Toast.makeText(this, "Not cancelable - Positive button clicked", Toast.LENGTH_SHORT).show(); 128 | break; 129 | } 130 | } 131 | } 132 | 133 | @Override 134 | public void onDialogNegativeButtonClicked(DialogInterface dialog, Integer requestCode) { 135 | if (requestCode != null) { 136 | switch (requestCode) { 137 | case SIMPLE_DIALOG_ONE_BUTTON_REQUEST_CODE: 138 | // No negative button 139 | break; 140 | 141 | case SIMPLE_DIALOG_TWO_BUTTONS_REQUEST_CODE: 142 | Toast.makeText(this, "Two buttons - Negative button clicked", Toast.LENGTH_SHORT).show(); 143 | break; 144 | 145 | case SIMPLE_DIALOG_THREE_BUTTONS_REQUEST_CODE: 146 | Toast.makeText(this, "Three buttons - Negative button clicked", Toast.LENGTH_SHORT).show(); 147 | break; 148 | 149 | case SIMPLE_DIALOG_NOT_CANCELABLE_REQUEST_CODE: 150 | // No negative button 151 | break; 152 | } 153 | } 154 | } 155 | 156 | @Override 157 | public void onDialogNeutralButtonClicked(DialogInterface dialog, Integer requestCode) { 158 | if (requestCode != null) { 159 | switch (requestCode) { 160 | case SIMPLE_DIALOG_ONE_BUTTON_REQUEST_CODE: 161 | // No neutral button 162 | break; 163 | 164 | case SIMPLE_DIALOG_TWO_BUTTONS_REQUEST_CODE: 165 | // No neutral button 166 | break; 167 | 168 | case SIMPLE_DIALOG_THREE_BUTTONS_REQUEST_CODE: 169 | Toast.makeText(this, "Three buttons - Neutral button clicked", Toast.LENGTH_SHORT).show(); 170 | break; 171 | 172 | case SIMPLE_DIALOG_NOT_CANCELABLE_REQUEST_CODE: 173 | // No neutral button 174 | break; 175 | } 176 | } 177 | } 178 | } 179 | -------------------------------------------------------------------------------- /sample/src/main/java/com/julienarzul/simpledialogfragment/sample/NestedFragment.java: -------------------------------------------------------------------------------- 1 | package com.julienarzul.simpledialogfragment.sample; 2 | 3 | import android.content.DialogInterface; 4 | import android.os.Bundle; 5 | import android.support.annotation.Nullable; 6 | import android.support.v4.app.Fragment; 7 | import android.view.LayoutInflater; 8 | import android.view.View; 9 | import android.view.ViewGroup; 10 | import android.widget.Toast; 11 | 12 | import com.julienarzul.simpledialogfragment.SimpleDialogContent; 13 | import com.julienarzul.simpledialogfragment.SimpleDialogFragment; 14 | 15 | import butterknife.ButterKnife; 16 | import butterknife.OnClick; 17 | import butterknife.Unbinder; 18 | 19 | /** 20 | * Created by Julien Arzul on 3/2/17. 21 | * Copyright @ Julien Arzul 2017 22 | */ 23 | 24 | public class NestedFragment extends Fragment implements SimpleDialogFragment.OnPositiveButtonClickListener, 25 | SimpleDialogFragment.OnNegativeButtonClickListener { 26 | 27 | private static final int SIMPLE_DIALOG_NESTED_IN_FRAGMENT_REQUEST_CODE = 101; 28 | 29 | private Unbinder unbinder; 30 | 31 | public static NestedFragment newInstance() { 32 | Bundle args = new Bundle(); 33 | 34 | NestedFragment fragment = new NestedFragment(); 35 | fragment.setArguments(args); 36 | return fragment; 37 | } 38 | 39 | @Nullable 40 | @Override 41 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 42 | View v = inflater.inflate(R.layout.fragment_nested, container, false); 43 | 44 | this.unbinder = ButterKnife.bind(this, v); 45 | 46 | return v; 47 | } 48 | 49 | @Override 50 | public void onDestroyView() { 51 | super.onDestroyView(); 52 | 53 | if (this.unbinder != null) { 54 | this.unbinder.unbind(); 55 | this.unbinder = null; 56 | } 57 | } 58 | 59 | @OnClick(R.id.simple_dialog_nested_in_fragment_button) 60 | void onNestedInFragmentButtonClicked() { 61 | SimpleDialogContent dialogContent = SimpleDialogContent.builder() 62 | .setTitle(this.getString(R.string.dialog_title)) 63 | .setMessage(this.getString(R.string.dialog_message)) 64 | .setPositiveButtonText(this.getString(R.string.dialog_button_positive)) 65 | .setNegativeButtonText(this.getString(R.string.dialog_button_negative)) 66 | .setRequestCode(SIMPLE_DIALOG_NESTED_IN_FRAGMENT_REQUEST_CODE) 67 | .build(); 68 | 69 | SimpleDialogFragment.newInstance(dialogContent) 70 | .show(this.getChildFragmentManager(), SimpleDialogFragment.TAG); 71 | } 72 | 73 | @Override 74 | public void onDialogPositiveButtonClicked(DialogInterface dialog, Integer requestCode) { 75 | if (requestCode != null) { 76 | switch (requestCode) { 77 | case SIMPLE_DIALOG_NESTED_IN_FRAGMENT_REQUEST_CODE: 78 | Toast.makeText(this.getContext(), "Nested in Fragment - Positive button clicked", Toast.LENGTH_SHORT).show(); 79 | break; 80 | } 81 | } 82 | } 83 | 84 | @Override 85 | public void onDialogNegativeButtonClicked(DialogInterface dialog, Integer requestCode) { 86 | if (requestCode != null) { 87 | switch (requestCode) { 88 | case SIMPLE_DIALOG_NESTED_IN_FRAGMENT_REQUEST_CODE: 89 | Toast.makeText(this.getContext(), "Nested in Fragment - Negative button clicked", Toast.LENGTH_SHORT).show(); 90 | break; 91 | } 92 | } 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 15 | 16 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/content_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 |