├── MyAddressBook-final
├── settings.gradle
├── gradle
│ └── wrapper
│ │ ├── gradle-wrapper.jar
│ │ └── gradle-wrapper.properties
├── app
│ ├── src
│ │ └── main
│ │ │ ├── res
│ │ │ ├── mipmap-hdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── values
│ │ │ │ ├── dimens.xml
│ │ │ │ ├── colors.xml
│ │ │ │ ├── styles.xml
│ │ │ │ └── strings.xml
│ │ │ ├── drawable
│ │ │ │ ├── ic_add.xml
│ │ │ │ ├── ic_pass.xml
│ │ │ │ ├── ic_fail.xml
│ │ │ │ └── ic_person.xml
│ │ │ ├── layout
│ │ │ │ ├── content_contacts.xml
│ │ │ │ ├── activity_contacts.xml
│ │ │ │ ├── contact_list_item.xml
│ │ │ │ └── input_contact_dialog.xml
│ │ │ └── menu
│ │ │ │ └── menu_contacts.xml
│ │ │ ├── java
│ │ │ └── com
│ │ │ │ └── example
│ │ │ │ └── android
│ │ │ │ └── myaddressbook
│ │ │ │ ├── Contact.kt
│ │ │ │ ├── Extensions.kt
│ │ │ │ └── ContactsActivity.kt
│ │ │ ├── AndroidManifest.xml
│ │ │ └── assets
│ │ │ └── mock_contacts.json
│ ├── proguard-rules.pro
│ └── build.gradle
├── build.gradle
├── gradle.properties
├── gradlew.bat
└── gradlew
├── MyAddressBook-starter
├── settings.gradle
├── gradle
│ └── wrapper
│ │ ├── gradle-wrapper.jar
│ │ └── gradle-wrapper.properties
├── app
│ ├── src
│ │ └── main
│ │ │ ├── res
│ │ │ ├── mipmap-hdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── values
│ │ │ │ ├── dimens.xml
│ │ │ │ ├── colors.xml
│ │ │ │ ├── strings.xml
│ │ │ │ └── styles.xml
│ │ │ ├── drawable
│ │ │ │ ├── ic_add.xml
│ │ │ │ ├── ic_pass.xml
│ │ │ │ ├── ic_fail.xml
│ │ │ │ └── ic_person.xml
│ │ │ ├── menu
│ │ │ │ └── menu_contacts.xml
│ │ │ └── layout
│ │ │ │ ├── content_contacts.xml
│ │ │ │ ├── activity_contacts.xml
│ │ │ │ ├── contact_list_item.xml
│ │ │ │ └── input_contact_dialog.xml
│ │ │ ├── java
│ │ │ └── com
│ │ │ │ └── example
│ │ │ │ └── android
│ │ │ │ └── myaddressbook
│ │ │ │ └── Contact.java
│ │ │ ├── AndroidManifest.xml
│ │ │ └── assets
│ │ │ └── mock_contacts.json
│ ├── build.gradle
│ └── proguard-rules.pro
├── build.gradle
├── gradle.properties
├── gradlew.bat
└── gradlew
├── MyAddressBook-step3
├── settings.gradle
├── gradle
│ └── wrapper
│ │ ├── gradle-wrapper.jar
│ │ └── gradle-wrapper.properties
├── app
│ ├── src
│ │ └── main
│ │ │ ├── res
│ │ │ ├── mipmap-hdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── values
│ │ │ │ ├── dimens.xml
│ │ │ │ ├── colors.xml
│ │ │ │ ├── strings.xml
│ │ │ │ └── styles.xml
│ │ │ ├── drawable
│ │ │ │ ├── ic_add.xml
│ │ │ │ ├── ic_pass.xml
│ │ │ │ ├── ic_fail.xml
│ │ │ │ └── ic_person.xml
│ │ │ ├── menu
│ │ │ │ └── menu_contacts.xml
│ │ │ └── layout
│ │ │ │ ├── content_contacts.xml
│ │ │ │ ├── activity_contacts.xml
│ │ │ │ ├── contact_list_item.xml
│ │ │ │ └── input_contact_dialog.xml
│ │ │ ├── java
│ │ │ └── com
│ │ │ │ └── example
│ │ │ │ └── android
│ │ │ │ └── myaddressbook
│ │ │ │ ├── Contact.kt
│ │ │ │ └── ContactsActivity.kt
│ │ │ ├── AndroidManifest.xml
│ │ │ └── assets
│ │ │ └── mock_contacts.json
│ ├── build.gradle
│ └── proguard-rules.pro
├── build.gradle
├── gradle.properties
├── gradlew.bat
└── gradlew
├── MyAddressBook-step4
├── settings.gradle
├── gradle
│ └── wrapper
│ │ ├── gradle-wrapper.jar
│ │ └── gradle-wrapper.properties
├── app
│ ├── src
│ │ └── main
│ │ │ ├── res
│ │ │ ├── mipmap-hdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── values
│ │ │ │ ├── dimens.xml
│ │ │ │ ├── colors.xml
│ │ │ │ ├── styles.xml
│ │ │ │ └── strings.xml
│ │ │ ├── drawable
│ │ │ │ ├── ic_add.xml
│ │ │ │ ├── ic_pass.xml
│ │ │ │ ├── ic_fail.xml
│ │ │ │ └── ic_person.xml
│ │ │ ├── layout
│ │ │ │ ├── content_contacts.xml
│ │ │ │ ├── activity_contacts.xml
│ │ │ │ ├── contact_list_item.xml
│ │ │ │ └── input_contact_dialog.xml
│ │ │ └── menu
│ │ │ │ └── menu_contacts.xml
│ │ │ ├── java
│ │ │ └── com
│ │ │ │ └── example
│ │ │ │ └── android
│ │ │ │ └── myaddressbook
│ │ │ │ ├── Contact.kt
│ │ │ │ └── ContactsActivity.kt
│ │ │ ├── AndroidManifest.xml
│ │ │ └── assets
│ │ │ └── mock_contacts.json
│ ├── proguard-rules.pro
│ └── build.gradle
├── build.gradle
├── gradle.properties
├── gradlew.bat
└── gradlew
├── .gitignore
├── CONTRIBUTING.md
└── README.md
/MyAddressBook-final/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/MyAddressBook-starter/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/MyAddressBook-step3/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/MyAddressBook-step4/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/MyAddressBook-final/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android/codelab-android-using-kotlin/HEAD/MyAddressBook-final/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/MyAddressBook-step3/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android/codelab-android-using-kotlin/HEAD/MyAddressBook-step3/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/MyAddressBook-step4/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android/codelab-android-using-kotlin/HEAD/MyAddressBook-step4/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/MyAddressBook-starter/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android/codelab-android-using-kotlin/HEAD/MyAddressBook-starter/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/MyAddressBook-final/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android/codelab-android-using-kotlin/HEAD/MyAddressBook-final/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/MyAddressBook-final/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android/codelab-android-using-kotlin/HEAD/MyAddressBook-final/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/MyAddressBook-final/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android/codelab-android-using-kotlin/HEAD/MyAddressBook-final/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/MyAddressBook-step3/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android/codelab-android-using-kotlin/HEAD/MyAddressBook-step3/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/MyAddressBook-step3/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android/codelab-android-using-kotlin/HEAD/MyAddressBook-step3/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/MyAddressBook-step3/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android/codelab-android-using-kotlin/HEAD/MyAddressBook-step3/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/MyAddressBook-step4/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android/codelab-android-using-kotlin/HEAD/MyAddressBook-step4/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/MyAddressBook-step4/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android/codelab-android-using-kotlin/HEAD/MyAddressBook-step4/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/MyAddressBook-step4/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android/codelab-android-using-kotlin/HEAD/MyAddressBook-step4/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/MyAddressBook-final/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android/codelab-android-using-kotlin/HEAD/MyAddressBook-final/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/MyAddressBook-final/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android/codelab-android-using-kotlin/HEAD/MyAddressBook-final/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/MyAddressBook-starter/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android/codelab-android-using-kotlin/HEAD/MyAddressBook-starter/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/MyAddressBook-starter/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android/codelab-android-using-kotlin/HEAD/MyAddressBook-starter/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/MyAddressBook-starter/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android/codelab-android-using-kotlin/HEAD/MyAddressBook-starter/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/MyAddressBook-starter/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android/codelab-android-using-kotlin/HEAD/MyAddressBook-starter/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/MyAddressBook-step3/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android/codelab-android-using-kotlin/HEAD/MyAddressBook-step3/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/MyAddressBook-step3/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android/codelab-android-using-kotlin/HEAD/MyAddressBook-step3/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/MyAddressBook-step4/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android/codelab-android-using-kotlin/HEAD/MyAddressBook-step4/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/MyAddressBook-step4/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android/codelab-android-using-kotlin/HEAD/MyAddressBook-step4/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/MyAddressBook-final/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android/codelab-android-using-kotlin/HEAD/MyAddressBook-final/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/MyAddressBook-final/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android/codelab-android-using-kotlin/HEAD/MyAddressBook-final/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/MyAddressBook-starter/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android/codelab-android-using-kotlin/HEAD/MyAddressBook-starter/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/MyAddressBook-step3/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android/codelab-android-using-kotlin/HEAD/MyAddressBook-step3/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/MyAddressBook-step3/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android/codelab-android-using-kotlin/HEAD/MyAddressBook-step3/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/MyAddressBook-step4/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android/codelab-android-using-kotlin/HEAD/MyAddressBook-step4/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/MyAddressBook-step4/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android/codelab-android-using-kotlin/HEAD/MyAddressBook-step4/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/MyAddressBook-final/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android/codelab-android-using-kotlin/HEAD/MyAddressBook-final/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/MyAddressBook-final/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android/codelab-android-using-kotlin/HEAD/MyAddressBook-final/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/MyAddressBook-final/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android/codelab-android-using-kotlin/HEAD/MyAddressBook-final/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/MyAddressBook-starter/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android/codelab-android-using-kotlin/HEAD/MyAddressBook-starter/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/MyAddressBook-starter/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android/codelab-android-using-kotlin/HEAD/MyAddressBook-starter/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/MyAddressBook-starter/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android/codelab-android-using-kotlin/HEAD/MyAddressBook-starter/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/MyAddressBook-step3/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android/codelab-android-using-kotlin/HEAD/MyAddressBook-step3/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/MyAddressBook-step3/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android/codelab-android-using-kotlin/HEAD/MyAddressBook-step3/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/MyAddressBook-step3/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android/codelab-android-using-kotlin/HEAD/MyAddressBook-step3/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/MyAddressBook-step4/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android/codelab-android-using-kotlin/HEAD/MyAddressBook-step4/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/MyAddressBook-step4/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android/codelab-android-using-kotlin/HEAD/MyAddressBook-step4/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/MyAddressBook-step4/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android/codelab-android-using-kotlin/HEAD/MyAddressBook-step4/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/MyAddressBook-starter/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android/codelab-android-using-kotlin/HEAD/MyAddressBook-starter/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/MyAddressBook-starter/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/android/codelab-android-using-kotlin/HEAD/MyAddressBook-starter/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/MyAddressBook-final/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Apr 02 09:33:06 PDT 2018
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-4.4-all.zip
7 |
--------------------------------------------------------------------------------
/MyAddressBook-starter/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Apr 02 09:33:06 PDT 2018
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-4.4-all.zip
7 |
--------------------------------------------------------------------------------
/MyAddressBook-step3/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Apr 02 09:33:06 PDT 2018
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-4.4-all.zip
7 |
--------------------------------------------------------------------------------
/MyAddressBook-step4/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Apr 02 09:33:06 PDT 2018
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-4.4-all.zip
7 |
--------------------------------------------------------------------------------
/MyAddressBook-starter/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 | google()
7 | }
8 | dependencies {
9 | classpath 'com.android.tools.build:gradle:3.1.0'
10 |
11 | // NOTE: Do not place your application dependencies here; they belong
12 | // in the individual module build.gradle files
13 | }
14 | }
15 |
16 | allprojects {
17 | repositories {
18 | jcenter()
19 | google()
20 | }
21 | }
22 |
23 | task clean(type: Delete) {
24 | delete rootProject.buildDir
25 | }
26 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 |
2 | */.gitignore
3 | .gradle
4 | .DS_Store
5 |
6 | # built application files
7 | *.apk
8 | *.ap_
9 |
10 | # files for the dex VM
11 | *.dex
12 |
13 | # Java class files
14 | *.class
15 |
16 | # generated files
17 | bin/
18 | out/
19 | gen/
20 |
21 | # Libraries used by the app
22 | # Can explicitly add if we want, but shouldn't do so blindly. Licenses, bloat, etc.
23 | /libs
24 |
25 |
26 | # Build stuff (auto-generated by android update project ...)
27 | build.xml
28 | ant.properties
29 | local.properties
30 | project.properties
31 |
32 | # Eclipse project files
33 | .classpath
34 | .project
35 |
36 | # idea project files
37 | .idea/
38 | .idea/.name
39 | *.iml
40 | *.ipr
41 | *.iws
42 |
43 | ##Gradle-based build
44 | .gradle
45 | build/
46 |
--------------------------------------------------------------------------------
/MyAddressBook-step3/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | ext.kotlin_version = '1.2.31'
5 | repositories {
6 | jcenter()
7 | google()
8 | }
9 | dependencies {
10 | classpath 'com.android.tools.build:gradle:3.1.0'
11 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
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 | google()
21 | }
22 | }
23 |
24 | task clean(type: Delete) {
25 | delete rootProject.buildDir
26 | }
27 |
--------------------------------------------------------------------------------
/MyAddressBook-step4/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | ext.kotlin_version = '1.2.31'
5 | repositories {
6 | jcenter()
7 | google()
8 | }
9 | dependencies {
10 | classpath 'com.android.tools.build:gradle:3.1.0'
11 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
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 | google()
21 | }
22 | }
23 |
24 | task clean(type: Delete) {
25 | delete rootProject.buildDir
26 | }
27 |
--------------------------------------------------------------------------------
/MyAddressBook-final/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | ext.kotlin_version = '1.2.31'
5 | repositories {
6 | jcenter()
7 | google()
8 | }
9 | dependencies {
10 | classpath 'com.android.tools.build:gradle:3.1.0'
11 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
12 |
13 | // NOTE: Do not place your application dependencies here; they belong
14 | // in the individual module build.gradle files
15 | }
16 | }
17 |
18 | allprojects {
19 | repositories {
20 | jcenter()
21 | google()
22 | }
23 | }
24 |
25 | task clean(type: Delete) {
26 | delete rootProject.buildDir
27 | }
28 |
--------------------------------------------------------------------------------
/MyAddressBook-final/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 | 16dp
18 | 56dp
19 |
20 |
--------------------------------------------------------------------------------
/MyAddressBook-starter/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 | 16dp
18 | 56dp
19 |
20 |
--------------------------------------------------------------------------------
/MyAddressBook-step3/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 | 16dp
18 | 56dp
19 |
20 |
--------------------------------------------------------------------------------
/MyAddressBook-step4/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 | 16dp
18 | 56dp
19 |
20 |
--------------------------------------------------------------------------------
/MyAddressBook-final/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 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/MyAddressBook-step3/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 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/MyAddressBook-step4/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 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/MyAddressBook-starter/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 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/MyAddressBook-final/app/src/main/java/com/example/android/myaddressbook/Contact.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Google Inc.
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 | package com.example.android.myaddressbook
17 |
18 | internal data class Contact(val firstName: String, val lastName: String, var email: String?)
19 |
--------------------------------------------------------------------------------
/MyAddressBook-step3/app/src/main/java/com/example/android/myaddressbook/Contact.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Google Inc.
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 | package com.example.android.myaddressbook
17 |
18 | internal data class Contact(val firstName: String, val lastName: String, var email: String?)
19 |
--------------------------------------------------------------------------------
/MyAddressBook-step4/app/src/main/java/com/example/android/myaddressbook/Contact.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Google Inc.
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 | package com.example.android.myaddressbook
17 |
18 | internal data class Contact(val firstName: String, val lastName: String, var email: String?)
19 |
--------------------------------------------------------------------------------
/MyAddressBook-starter/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 27
5 | defaultConfig {
6 | applicationId "com.example.android.myaddressbook"
7 | minSdkVersion 15
8 | targetSdkVersion 27
9 | versionCode 1
10 | versionName "1.0"
11 | }
12 | buildTypes {
13 | release {
14 | minifyEnabled false
15 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
16 | }
17 | }
18 | }
19 |
20 | dependencies {
21 | implementation fileTree(dir: 'libs', include: ['*.jar'])
22 | implementation 'com.android.support:appcompat-v7:27.1.0'
23 | implementation 'com.android.support.constraint:constraint-layout:1.0.2'
24 | implementation 'com.android.support:design:27.1.0'
25 | implementation 'com.google.code.gson:gson:2.8.2'
26 | }
27 |
--------------------------------------------------------------------------------
/MyAddressBook-final/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 | #3F51B5
19 | #303F9F
20 | #FF4081
21 |
22 |
--------------------------------------------------------------------------------
/MyAddressBook-starter/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 | #3F51B5
19 | #303F9F
20 | #FF4081
21 |
22 |
--------------------------------------------------------------------------------
/MyAddressBook-step3/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 | #3F51B5
19 | #303F9F
20 | #FF4081
21 |
22 |
--------------------------------------------------------------------------------
/MyAddressBook-step4/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 | #3F51B5
19 | #303F9F
20 | #FF4081
21 |
22 |
--------------------------------------------------------------------------------
/MyAddressBook-final/app/src/main/res/drawable/ic_add.xml:
--------------------------------------------------------------------------------
1 |
16 |
21 |
24 |
25 |
--------------------------------------------------------------------------------
/MyAddressBook-starter/app/src/main/res/drawable/ic_add.xml:
--------------------------------------------------------------------------------
1 |
16 |
21 |
24 |
25 |
--------------------------------------------------------------------------------
/MyAddressBook-step3/app/src/main/res/drawable/ic_add.xml:
--------------------------------------------------------------------------------
1 |
16 |
21 |
24 |
25 |
--------------------------------------------------------------------------------
/MyAddressBook-step4/app/src/main/res/drawable/ic_add.xml:
--------------------------------------------------------------------------------
1 |
16 |
21 |
24 |
25 |
--------------------------------------------------------------------------------
/MyAddressBook-final/app/src/main/res/drawable/ic_pass.xml:
--------------------------------------------------------------------------------
1 |
16 |
21 |
24 |
25 |
--------------------------------------------------------------------------------
/MyAddressBook-step3/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 | apply plugin: 'kotlin-android'
3 |
4 | android {
5 | compileSdkVersion 27
6 | defaultConfig {
7 | applicationId "com.example.android.myaddressbook"
8 | minSdkVersion 15
9 | targetSdkVersion 27
10 | versionCode 1
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 |
21 | dependencies {
22 | implementation fileTree(dir: 'libs', include: ['*.jar'])
23 | implementation 'com.android.support:appcompat-v7:27.1.0'
24 | implementation 'com.android.support.constraint:constraint-layout:1.0.2'
25 | implementation 'com.android.support:design:27.1.0'
26 | implementation 'com.google.code.gson:gson:2.8.2'
27 | compile "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
28 | }
29 | repositories {
30 | mavenCentral()
31 | }
32 |
--------------------------------------------------------------------------------
/MyAddressBook-step3/app/src/main/res/drawable/ic_pass.xml:
--------------------------------------------------------------------------------
1 |
16 |
21 |
24 |
25 |
--------------------------------------------------------------------------------
/MyAddressBook-step4/app/src/main/res/drawable/ic_pass.xml:
--------------------------------------------------------------------------------
1 |
16 |
21 |
24 |
25 |
--------------------------------------------------------------------------------
/MyAddressBook-starter/app/src/main/res/drawable/ic_pass.xml:
--------------------------------------------------------------------------------
1 |
16 |
21 |
24 |
25 |
--------------------------------------------------------------------------------
/MyAddressBook-final/app/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/ngamolsky/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 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/MyAddressBook-starter/app/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/ngamolsky/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 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/MyAddressBook-step3/app/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/ngamolsky/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 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/MyAddressBook-step4/app/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/ngamolsky/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 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/MyAddressBook-final/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 | apply plugin: 'kotlin-android'
3 | apply plugin: 'kotlin-android-extensions'
4 |
5 | android {
6 | compileSdkVersion 27
7 | defaultConfig {
8 | applicationId "com.example.android.myaddressbook"
9 | minSdkVersion 15
10 | targetSdkVersion 27
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 | implementation fileTree(dir: 'libs', include: ['*.jar'])
24 | implementation 'com.android.support:appcompat-v7:27.1.0'
25 | implementation 'com.android.support.constraint:constraint-layout:1.0.2'
26 | implementation 'com.android.support:design:27.1.0'
27 | implementation 'com.google.code.gson:gson:2.8.2'
28 | compile "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
29 | }
30 | repositories {
31 | mavenCentral()
32 | }
33 |
--------------------------------------------------------------------------------
/MyAddressBook-step4/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 | apply plugin: 'kotlin-android'
3 | apply plugin: 'kotlin-android-extensions'
4 |
5 | android {
6 | compileSdkVersion 27
7 | defaultConfig {
8 | applicationId "com.example.android.myaddressbook"
9 | minSdkVersion 15
10 | targetSdkVersion 27
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 | implementation fileTree(dir: 'libs', include: ['*.jar'])
24 | implementation 'com.android.support:appcompat-v7:27.1.0'
25 | implementation 'com.android.support.constraint:constraint-layout:1.0.2'
26 | implementation 'com.android.support:design:27.1.0'
27 | implementation 'com.google.code.gson:gson:2.8.2'
28 | compile "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
29 | }
30 | repositories {
31 | mavenCentral()
32 | }
33 |
--------------------------------------------------------------------------------
/MyAddressBook-final/app/src/main/res/drawable/ic_fail.xml:
--------------------------------------------------------------------------------
1 |
16 |
21 |
24 |
25 |
--------------------------------------------------------------------------------
/MyAddressBook-starter/app/src/main/res/drawable/ic_fail.xml:
--------------------------------------------------------------------------------
1 |
16 |
21 |
24 |
25 |
--------------------------------------------------------------------------------
/MyAddressBook-step3/app/src/main/res/drawable/ic_fail.xml:
--------------------------------------------------------------------------------
1 |
16 |
21 |
24 |
25 |
--------------------------------------------------------------------------------
/MyAddressBook-step4/app/src/main/res/drawable/ic_fail.xml:
--------------------------------------------------------------------------------
1 |
16 |
21 |
24 |
25 |
--------------------------------------------------------------------------------
/MyAddressBook-final/app/src/main/res/drawable/ic_person.xml:
--------------------------------------------------------------------------------
1 |
16 |
21 |
24 |
25 |
--------------------------------------------------------------------------------
/MyAddressBook-step3/app/src/main/res/drawable/ic_person.xml:
--------------------------------------------------------------------------------
1 |
16 |
21 |
24 |
25 |
--------------------------------------------------------------------------------
/MyAddressBook-step4/app/src/main/res/drawable/ic_person.xml:
--------------------------------------------------------------------------------
1 |
16 |
21 |
24 |
25 |
--------------------------------------------------------------------------------
/MyAddressBook-starter/app/src/main/res/drawable/ic_person.xml:
--------------------------------------------------------------------------------
1 |
16 |
21 |
24 |
25 |
--------------------------------------------------------------------------------
/MyAddressBook-starter/app/src/main/res/menu/menu_contacts.xml:
--------------------------------------------------------------------------------
1 |
16 |
31 |
--------------------------------------------------------------------------------
/MyAddressBook-step3/app/src/main/res/menu/menu_contacts.xml:
--------------------------------------------------------------------------------
1 |
16 |
31 |
--------------------------------------------------------------------------------
/MyAddressBook-final/app/src/main/java/com/example/android/myaddressbook/Extensions.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Google Inc.
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 | package com.example.android.myaddressbook
17 |
18 | import android.graphics.drawable.Drawable
19 | import android.support.v4.content.ContextCompat
20 | import android.widget.EditText
21 | import android.widget.TextView
22 |
23 | internal inline fun EditText.validateWith
24 | (passIcon: Drawable? = ContextCompat.getDrawable(context, R.drawable.ic_pass),
25 | failIcon: Drawable? = ContextCompat.getDrawable(context, R.drawable.ic_fail),
26 | validator: TextView.() -> Boolean): Boolean {
27 |
28 | setCompoundDrawablesWithIntrinsicBounds(null, null,
29 | if (validator()) passIcon else failIcon, null)
30 | return validator()
31 | }
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/MyAddressBook-starter/app/src/main/java/com/example/android/myaddressbook/Contact.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Google Inc.
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 | package com.example.android.myaddressbook;
17 |
18 | class Contact {
19 |
20 | private String firstName;
21 | private String lastName;
22 | private String email;
23 |
24 |
25 | Contact(String firstName, String lastName, String email) {
26 | this.firstName = firstName;
27 | this.lastName = lastName;
28 | this.email = email;
29 | }
30 |
31 | String getFirstName() {
32 | return firstName;
33 | }
34 |
35 | String getLastName() {
36 | return lastName;
37 | }
38 |
39 | String getEmail() {
40 | return email;
41 | }
42 |
43 | void setEmail(String email) {
44 | this.email = email;
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/MyAddressBook-starter/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 | MyAddressBook
18 | Settings
19 | Contact Thubmnail Picture
20 | Clear
21 | New Contact
22 | Save
23 | Cancel
24 | Please enter valid contact information
25 | Generate
26 | First Name
27 | Last Name
28 | Email Address
29 | Edit Contact
30 |
31 |
--------------------------------------------------------------------------------
/MyAddressBook-step3/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 | MyAddressBook
18 | Settings
19 | Contact Thubmnail Picture
20 | Clear
21 | New Contact
22 | Save
23 | Cancel
24 | Please enter valid contact information
25 | Generate
26 | First Name
27 | Last Name
28 | Email Address
29 | Edit Contact
30 |
31 |
--------------------------------------------------------------------------------
/MyAddressBook-final/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
18 |
19 |
25 |
26 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/MyAddressBook-starter/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
18 |
19 |
25 |
26 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/MyAddressBook-step3/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
18 |
19 |
25 |
26 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/MyAddressBook-step4/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 |
18 |
19 |
25 |
26 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/MyAddressBook-final/app/src/main/res/layout/content_contacts.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
32 |
33 |
--------------------------------------------------------------------------------
/MyAddressBook-starter/app/src/main/res/layout/content_contacts.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
32 |
33 |
--------------------------------------------------------------------------------
/MyAddressBook-step3/app/src/main/res/layout/content_contacts.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
32 |
33 |
--------------------------------------------------------------------------------
/MyAddressBook-step4/app/src/main/res/layout/content_contacts.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
32 |
33 |
--------------------------------------------------------------------------------
/MyAddressBook-final/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 | MyAddressBook
18 | Settings
19 | Contact Thubmnail Picture
20 | Clear
21 | New Contact
22 | Save
23 | Cancel
24 | Please enter valid contact information
25 | Generate
26 | First Name
27 | Last Name
28 | Email Address
29 | Edit Contact
30 | Sort by First Name
31 | Sort by Last Name
32 |
33 |
--------------------------------------------------------------------------------
/MyAddressBook-step4/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 | MyAddressBook
18 | Settings
19 | Contact Thubmnail Picture
20 | Clear
21 | New Contact
22 | Save
23 | Cancel
24 | Please enter valid contact information
25 | Generate
26 | First Name
27 | Last Name
28 | Email Address
29 | Edit Contact
30 | Sort by First Name
31 | Sort by Last Name
32 |
33 |
--------------------------------------------------------------------------------
/MyAddressBook-final/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
19 |
20 |
27 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/MyAddressBook-starter/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
19 |
20 |
27 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/MyAddressBook-step3/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
19 |
20 |
27 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/MyAddressBook-step4/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
19 |
20 |
27 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/MyAddressBook-final/app/src/main/res/menu/menu_contacts.xml:
--------------------------------------------------------------------------------
1 |
16 |
42 |
--------------------------------------------------------------------------------
/MyAddressBook-step4/app/src/main/res/menu/menu_contacts.xml:
--------------------------------------------------------------------------------
1 |
16 |
42 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # How to become a contributor and submit your own code
2 |
3 | ## Contributor License Agreements
4 |
5 | We'd love to accept your sample apps and patches! Before we can take them, we
6 | have to jump a couple of legal hurdles.
7 |
8 | Please fill out either the individual or corporate Contributor License Agreement
9 | (CLA).
10 |
11 | * If you are an individual writing original source code and you're sure you
12 | own the intellectual property, then you'll need to sign an [individual CLA]
13 | (https://developers.google.com/open-source/cla/individual).
14 | * If you work for a company that wants to allow you to contribute your work,
15 | then you'll need to sign a [corporate CLA]
16 | (https://developers.google.com/open-source/cla/corporate).
17 |
18 | Follow either of the two links above to access the appropriate CLA and
19 | instructions for how to sign and return it. Once we receive it, we'll be able to
20 | accept your pull requests.
21 |
22 | ## Contributing A Patch
23 |
24 | 1. Submit an issue describing your proposed change to the repo in question.
25 | 1. The repo owner will respond to your issue promptly.
26 | 1. If your proposed change is accepted, and you haven't already done so, sign a
27 | Contributor License Agreement (see details above).
28 | 1. Fork the desired repo, develop and test your code changes.
29 | 1. Ensure that your code adheres to the existing style in the sample to which
30 | you are contributing. Refer to the
31 | [Google Cloud Platform Samples Style Guide]
32 | (https://github.com/GoogleCloudPlatform/Template/wiki/style.html) for the
33 | recommended coding standards for this organization.
34 | 1. Ensure that your code has an appropriate set of unit tests which all pass.
35 | 1. Submit a pull request.
36 |
37 |
--------------------------------------------------------------------------------
/MyAddressBook-final/app/src/main/assets/mock_contacts.json:
--------------------------------------------------------------------------------
1 | [{"first_name":"Kort","last_name":"Wickliffe","email":"kwickliffe0@orciconsectetuer.com"},
2 | {"first_name":"Bernard","last_name":"Tudbald","email":"btudbald1@nonummyipsum.co.uk"},
3 | {"first_name":"Kaleb","last_name":"Nuccitelli","email":"knuccitelli2@uncsollicitudin.edu"},
4 | {"first_name":"Swen","last_name":"Fransinelli","email":"sfransinelli3@nullacras.ca"},
5 | {"first_name":"Lexis","last_name":"Shelmardine","email":"lshelmardine4@nullain.org"},
6 | {"first_name":"Amalia","last_name":"Antushev","email":"aantushev5@uttinciduntorci.net"},
7 | {"first_name":"Viola","last_name":"Harborow","email":"vharborow6@egestasligulanullam.com"},
8 | {"first_name":"Bing","last_name":"Zamorano","email":"bzamorano7@ut.com"},
9 | {"first_name":"Corrinne","last_name":"Gingle","email":"cgingle8@nunc.org"},
10 | {"first_name":"Whitman","last_name":"Dressel","email":"wdressel9@convallis.ca"},
11 | {"first_name":"Zacharia","last_name":"Klewer","email":"zklewera@natoquepenatibus.org"},
12 | {"first_name":"Yetta","last_name":"Skylett","email":"yskylettb@nonummy.org"},
13 | {"first_name":"Rora","last_name":"Mylechreest","email":"rmylechreestc@fringilla.org"},
14 | {"first_name":"Silvanus","last_name":"Farlow","email":"sfarlowd@lectusnullam.ca"},
15 | {"first_name":"Annalee","last_name":"Gallanders","email":"agallanderse@diam.net"},
16 | {"first_name":"Eliot","last_name":"Carver","email":"ecarverf@dignissimmaecenasornare.ca"},
17 | {"first_name":"Giulio","last_name":"Sabate","email":"gsabateg@etnuncquisque.edu"},
18 | {"first_name":"Brenda","last_name":"Bubbings","email":"bbubbingsh@nec.org"},
19 | {"first_name":"Tadeas","last_name":"Phizaclea","email":"tphizacleai@posuere.ca"},
20 | {"first_name":"Brit","last_name":"Melbourn","email":"bmelbournj@morbivehiculapellentesque.co.uk"}]
--------------------------------------------------------------------------------
/MyAddressBook-step3/app/src/main/assets/mock_contacts.json:
--------------------------------------------------------------------------------
1 | [{"first_name":"Kort","last_name":"Wickliffe","email":"kwickliffe0@orciconsectetuer.com"},
2 | {"first_name":"Bernard","last_name":"Tudbald","email":"btudbald1@nonummyipsum.co.uk"},
3 | {"first_name":"Kaleb","last_name":"Nuccitelli","email":"knuccitelli2@uncsollicitudin.edu"},
4 | {"first_name":"Swen","last_name":"Fransinelli","email":"sfransinelli3@nullacras.ca"},
5 | {"first_name":"Lexis","last_name":"Shelmardine","email":"lshelmardine4@nullain.org"},
6 | {"first_name":"Amalia","last_name":"Antushev","email":"aantushev5@uttinciduntorci.net"},
7 | {"first_name":"Viola","last_name":"Harborow","email":"vharborow6@egestasligulanullam.com"},
8 | {"first_name":"Bing","last_name":"Zamorano","email":"bzamorano7@ut.com"},
9 | {"first_name":"Corrinne","last_name":"Gingle","email":"cgingle8@nunc.org"},
10 | {"first_name":"Whitman","last_name":"Dressel","email":"wdressel9@convallis.ca"},
11 | {"first_name":"Zacharia","last_name":"Klewer","email":"zklewera@natoquepenatibus.org"},
12 | {"first_name":"Yetta","last_name":"Skylett","email":"yskylettb@nonummy.org"},
13 | {"first_name":"Rora","last_name":"Mylechreest","email":"rmylechreestc@fringilla.org"},
14 | {"first_name":"Silvanus","last_name":"Farlow","email":"sfarlowd@lectusnullam.ca"},
15 | {"first_name":"Annalee","last_name":"Gallanders","email":"agallanderse@diam.net"},
16 | {"first_name":"Eliot","last_name":"Carver","email":"ecarverf@dignissimmaecenasornare.ca"},
17 | {"first_name":"Giulio","last_name":"Sabate","email":"gsabateg@etnuncquisque.edu"},
18 | {"first_name":"Brenda","last_name":"Bubbings","email":"bbubbingsh@nec.org"},
19 | {"first_name":"Tadeas","last_name":"Phizaclea","email":"tphizacleai@posuere.ca"},
20 | {"first_name":"Brit","last_name":"Melbourn","email":"bmelbournj@morbivehiculapellentesque.co.uk"}]
--------------------------------------------------------------------------------
/MyAddressBook-step4/app/src/main/assets/mock_contacts.json:
--------------------------------------------------------------------------------
1 | [{"first_name":"Kort","last_name":"Wickliffe","email":"kwickliffe0@orciconsectetuer.com"},
2 | {"first_name":"Bernard","last_name":"Tudbald","email":"btudbald1@nonummyipsum.co.uk"},
3 | {"first_name":"Kaleb","last_name":"Nuccitelli","email":"knuccitelli2@uncsollicitudin.edu"},
4 | {"first_name":"Swen","last_name":"Fransinelli","email":"sfransinelli3@nullacras.ca"},
5 | {"first_name":"Lexis","last_name":"Shelmardine","email":"lshelmardine4@nullain.org"},
6 | {"first_name":"Amalia","last_name":"Antushev","email":"aantushev5@uttinciduntorci.net"},
7 | {"first_name":"Viola","last_name":"Harborow","email":"vharborow6@egestasligulanullam.com"},
8 | {"first_name":"Bing","last_name":"Zamorano","email":"bzamorano7@ut.com"},
9 | {"first_name":"Corrinne","last_name":"Gingle","email":"cgingle8@nunc.org"},
10 | {"first_name":"Whitman","last_name":"Dressel","email":"wdressel9@convallis.ca"},
11 | {"first_name":"Zacharia","last_name":"Klewer","email":"zklewera@natoquepenatibus.org"},
12 | {"first_name":"Yetta","last_name":"Skylett","email":"yskylettb@nonummy.org"},
13 | {"first_name":"Rora","last_name":"Mylechreest","email":"rmylechreestc@fringilla.org"},
14 | {"first_name":"Silvanus","last_name":"Farlow","email":"sfarlowd@lectusnullam.ca"},
15 | {"first_name":"Annalee","last_name":"Gallanders","email":"agallanderse@diam.net"},
16 | {"first_name":"Eliot","last_name":"Carver","email":"ecarverf@dignissimmaecenasornare.ca"},
17 | {"first_name":"Giulio","last_name":"Sabate","email":"gsabateg@etnuncquisque.edu"},
18 | {"first_name":"Brenda","last_name":"Bubbings","email":"bbubbingsh@nec.org"},
19 | {"first_name":"Tadeas","last_name":"Phizaclea","email":"tphizacleai@posuere.ca"},
20 | {"first_name":"Brit","last_name":"Melbourn","email":"bmelbournj@morbivehiculapellentesque.co.uk"}]
--------------------------------------------------------------------------------
/MyAddressBook-starter/app/src/main/assets/mock_contacts.json:
--------------------------------------------------------------------------------
1 | [{"first_name":"Kort","last_name":"Wickliffe","email":"kwickliffe0@orciconsectetuer.com"},
2 | {"first_name":"Bernard","last_name":"Tudbald","email":"btudbald1@nonummyipsum.co.uk"},
3 | {"first_name":"Kaleb","last_name":"Nuccitelli","email":"knuccitelli2@uncsollicitudin.edu"},
4 | {"first_name":"Swen","last_name":"Fransinelli","email":"sfransinelli3@nullacras.ca"},
5 | {"first_name":"Lexis","last_name":"Shelmardine","email":"lshelmardine4@nullain.org"},
6 | {"first_name":"Amalia","last_name":"Antushev","email":"aantushev5@uttinciduntorci.net"},
7 | {"first_name":"Viola","last_name":"Harborow","email":"vharborow6@egestasligulanullam.com"},
8 | {"first_name":"Bing","last_name":"Zamorano","email":"bzamorano7@ut.com"},
9 | {"first_name":"Corrinne","last_name":"Gingle","email":"cgingle8@nunc.org"},
10 | {"first_name":"Whitman","last_name":"Dressel","email":"wdressel9@convallis.ca"},
11 | {"first_name":"Zacharia","last_name":"Klewer","email":"zklewera@natoquepenatibus.org"},
12 | {"first_name":"Yetta","last_name":"Skylett","email":"yskylettb@nonummy.org"},
13 | {"first_name":"Rora","last_name":"Mylechreest","email":"rmylechreestc@fringilla.org"},
14 | {"first_name":"Silvanus","last_name":"Farlow","email":"sfarlowd@lectusnullam.ca"},
15 | {"first_name":"Annalee","last_name":"Gallanders","email":"agallanderse@diam.net"},
16 | {"first_name":"Eliot","last_name":"Carver","email":"ecarverf@dignissimmaecenasornare.ca"},
17 | {"first_name":"Giulio","last_name":"Sabate","email":"gsabateg@etnuncquisque.edu"},
18 | {"first_name":"Brenda","last_name":"Bubbings","email":"bbubbingsh@nec.org"},
19 | {"first_name":"Tadeas","last_name":"Phizaclea","email":"tphizacleai@posuere.ca"},
20 | {"first_name":"Brit","last_name":"Melbourn","email":"bmelbournj@morbivehiculapellentesque.co.uk"}]
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | MyAddressBook
2 | =============
3 |
4 | This is the repository that contains both the starter and finished app for the
5 | [Taking Advantage of Kotlin codelab](https://codelabs.developers.google.com/codelabs/taking-advantage-of-kotlin/#0). The starter app is written
6 | in Java, which is then converted to Kotlin and extended.
7 |
8 | Introduction
9 | ------------
10 | MyAddressBook is an address book android application, that lists contacts
11 | containing a first name, last name, and email address. The contacts can be
12 | generated quickly from an included JSON file, or created manually in the app.
13 | It contains validation for the input fields, stores the data in
14 | SharedPreferences, and supports swipe to delete in the RecyclerView.
15 |
16 | Pre-requisites
17 | --------------
18 | A basic knowledge of developing Android apps in Java, specifically:
19 | - Displaying data in a RecyclerView.
20 | - Using SharedPreferences to persist data.
21 | - How to create JavaBean objects.
22 | - Creating layouts using ConstraintLayout.
23 | - Displaying an AlertDialog.
24 | - Validating user input in an EditText.
25 |
26 | Getting Started
27 | ---------------
28 | 1. Download the code.
29 | 2. Pick either the starter or finished directory and open the respective folder
30 | in Android Studio 3.0.
31 | 3. Run the app.
32 |
33 |
34 | License
35 | -------
36 |
37 | Copyright 2018 Google, Inc.
38 |
39 | Licensed to the Apache Software Foundation (ASF) under one or more contributor
40 | license agreements. See the NOTICE file distributed with this work for
41 | additional information regarding copyright ownership. The ASF licenses this
42 | file to you under the Apache License, Version 2.0 (the "License"); you may not
43 | use this file except in compliance with the License. You may obtain a copy of
44 | the License at
45 |
46 | http://www.apache.org/licenses/LICENSE-2.0
47 |
48 | Unless required by applicable law or agreed to in writing, software
49 | distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
50 | WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
51 | License for the specific language governing permissions and limitations under
52 | the License.
53 |
--------------------------------------------------------------------------------
/MyAddressBook-final/app/src/main/res/layout/activity_contacts.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
23 |
24 |
28 |
29 |
35 |
36 |
37 |
38 |
47 |
48 |
49 |
50 |
51 |
--------------------------------------------------------------------------------
/MyAddressBook-step3/app/src/main/res/layout/activity_contacts.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
23 |
24 |
28 |
29 |
35 |
36 |
37 |
38 |
47 |
48 |
49 |
50 |
51 |
--------------------------------------------------------------------------------
/MyAddressBook-step4/app/src/main/res/layout/activity_contacts.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
23 |
24 |
28 |
29 |
35 |
36 |
37 |
38 |
47 |
48 |
49 |
50 |
51 |
--------------------------------------------------------------------------------
/MyAddressBook-starter/app/src/main/res/layout/activity_contacts.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
23 |
24 |
28 |
29 |
35 |
36 |
37 |
38 |
47 |
48 |
49 |
50 |
51 |
--------------------------------------------------------------------------------
/MyAddressBook-final/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 |
--------------------------------------------------------------------------------
/MyAddressBook-starter/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 |
--------------------------------------------------------------------------------
/MyAddressBook-step3/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 |
--------------------------------------------------------------------------------
/MyAddressBook-step4/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 |
--------------------------------------------------------------------------------
/MyAddressBook-final/app/src/main/res/layout/contact_list_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
24 |
25 |
40 |
41 |
56 |
57 |
72 |
73 |
74 |
--------------------------------------------------------------------------------
/MyAddressBook-step3/app/src/main/res/layout/contact_list_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
24 |
25 |
40 |
41 |
56 |
57 |
72 |
73 |
74 |
--------------------------------------------------------------------------------
/MyAddressBook-step4/app/src/main/res/layout/contact_list_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
24 |
25 |
40 |
41 |
56 |
57 |
72 |
73 |
74 |
--------------------------------------------------------------------------------
/MyAddressBook-starter/app/src/main/res/layout/contact_list_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
24 |
25 |
40 |
41 |
56 |
57 |
72 |
73 |
74 |
--------------------------------------------------------------------------------
/MyAddressBook-final/app/src/main/res/layout/input_contact_dialog.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
22 |
23 |
40 |
41 |
58 |
59 |
76 |
77 |
78 |
79 |
--------------------------------------------------------------------------------
/MyAddressBook-step3/app/src/main/res/layout/input_contact_dialog.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
22 |
23 |
40 |
41 |
58 |
59 |
76 |
77 |
78 |
79 |
--------------------------------------------------------------------------------
/MyAddressBook-step4/app/src/main/res/layout/input_contact_dialog.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
22 |
23 |
40 |
41 |
58 |
59 |
76 |
77 |
78 |
79 |
--------------------------------------------------------------------------------
/MyAddressBook-starter/app/src/main/res/layout/input_contact_dialog.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
22 |
23 |
40 |
41 |
58 |
59 |
76 |
77 |
78 |
79 |
--------------------------------------------------------------------------------
/MyAddressBook-final/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 |
--------------------------------------------------------------------------------
/MyAddressBook-starter/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 |
--------------------------------------------------------------------------------
/MyAddressBook-step3/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 |
--------------------------------------------------------------------------------
/MyAddressBook-step4/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 |
--------------------------------------------------------------------------------
/MyAddressBook-final/app/src/main/java/com/example/android/myaddressbook/ContactsActivity.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Google Inc.
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 | package com.example.android.myaddressbook
17 |
18 | import android.annotation.SuppressLint
19 | import android.content.Context
20 | import android.content.SharedPreferences
21 | import android.os.Bundle
22 | import android.support.v7.app.AlertDialog
23 | import android.support.v7.app.AppCompatActivity
24 | import android.support.v7.widget.DividerItemDecoration
25 | import android.support.v7.widget.RecyclerView
26 | import android.support.v7.widget.helper.ItemTouchHelper
27 | import android.text.Editable
28 | import android.text.TextWatcher
29 | import android.util.Log
30 | import android.util.Patterns
31 | import android.view.*
32 | import android.widget.EditText
33 | import android.widget.TextView
34 | import android.widget.Toast
35 | import com.google.gson.Gson
36 | import kotlinx.android.synthetic.main.activity_contacts.*
37 | import kotlinx.android.synthetic.main.contact_list_item.view.*
38 | import kotlinx.android.synthetic.main.content_contacts.*
39 | import kotlinx.android.synthetic.main.input_contact_dialog.view.*
40 | import org.json.JSONArray
41 | import org.json.JSONException
42 | import java.io.IOException
43 | import java.util.*
44 |
45 | class ContactsActivity : AppCompatActivity(), TextWatcher {
46 |
47 | private lateinit var mContacts: ArrayList
48 | private lateinit var mAdapter: ContactsAdapter
49 |
50 | private lateinit var mPrefs: SharedPreferences
51 |
52 | private lateinit var mFirstNameEdit: EditText
53 | private lateinit var mLastNameEdit: EditText
54 | private lateinit var mEmailEdit: EditText
55 |
56 | private var mEntryValid = false
57 |
58 | override fun onCreate(savedInstanceState: Bundle?) {
59 | super.onCreate(savedInstanceState)
60 | setContentView(R.layout.activity_contacts)
61 |
62 | mPrefs = getPreferences(Context.MODE_PRIVATE)
63 | mContacts = loadContacts()
64 | mAdapter = ContactsAdapter(mContacts)
65 |
66 | setSupportActionBar(toolbar)
67 | setupRecyclerView()
68 |
69 | fab.setOnClickListener { showAddContactDialog(-1) }
70 | }
71 |
72 | /**
73 | * Loads the contacts from SharedPreferences, and deserializes them into
74 | * a Contact data type using Gson.
75 | */
76 | private fun loadContacts(): ArrayList {
77 | val contactSet = mPrefs.getStringSet(CONTACT_KEY, HashSet())
78 | return contactSet.mapTo(ArrayList()) { Gson().fromJson(it, Contact::class.java) }
79 | }
80 |
81 | /**
82 | * Saves the contacts to SharedPreferences by serializing them with Gson.
83 | */
84 | private fun saveContacts() {
85 | val editor = mPrefs.edit()
86 | editor.clear()
87 | val contactSet = mContacts.map { Gson().toJson(it) }.toSet()
88 | editor.putStringSet(CONTACT_KEY, contactSet)
89 | editor.apply()
90 | }
91 |
92 | /**
93 | * Sets up the RecyclerView: empty data set, item dividers, swipe to delete.
94 | */
95 | private fun setupRecyclerView() {
96 | contact_list.addItemDecoration(DividerItemDecoration(this,
97 | DividerItemDecoration.VERTICAL))
98 | contact_list.adapter = mAdapter
99 |
100 | // Implements swipe to delete
101 | val helper = ItemTouchHelper(
102 | object : ItemTouchHelper.SimpleCallback(0,
103 | ItemTouchHelper.LEFT or ItemTouchHelper.RIGHT) {
104 | override fun onMove(rV: RecyclerView,
105 | viewHolder: RecyclerView.ViewHolder,
106 | target: RecyclerView.ViewHolder): Boolean {
107 | return false
108 | }
109 |
110 | override fun onSwiped(viewHolder: RecyclerView.ViewHolder,
111 | direction: Int) {
112 | val position = viewHolder.adapterPosition
113 | mContacts.removeAt(position)
114 | mAdapter.notifyItemRemoved(position)
115 | saveContacts()
116 | }
117 | })
118 |
119 | helper.attachToRecyclerView(contact_list)
120 | }
121 |
122 | /**
123 | * Shows the AlertDialog for entering a new contact and performs validation
124 | * on the user input.
125 | *
126 | * @param contactPosition The position of the contact being edited, -1
127 | * if the user is creating a new contact.
128 | */
129 | @SuppressLint("InflateParams")
130 | private fun showAddContactDialog(contactPosition: Int) {
131 | // Inflates the dialog view
132 | val dialogView = LayoutInflater.from(this)
133 | .inflate(R.layout.input_contact_dialog, null)
134 |
135 | mFirstNameEdit = dialogView.edittext_firstname
136 | mLastNameEdit = dialogView.edittext_lastname
137 | mEmailEdit = dialogView.edittext_email
138 |
139 | // Listens to text changes to validate after each key press
140 | mFirstNameEdit.addTextChangedListener(this)
141 | mLastNameEdit.addTextChangedListener(this)
142 | mEmailEdit.addTextChangedListener(this)
143 |
144 | // Checks if the user is editing an existing contact
145 | val editing = contactPosition > -1
146 |
147 | val dialogTitle = if (editing)
148 | getString(R.string.edit_contact)
149 | else
150 | getString(R.string.new_contact)
151 |
152 | // Builds the AlertDialog and sets the custom view. Pass null for
153 | // the positive and negative buttons, as you will override the button
154 | // presses manually to perform validation before closing the dialog
155 | val builder = AlertDialog.Builder(this)
156 | .setView(dialogView)
157 | .setTitle(dialogTitle)
158 | .setPositiveButton(R.string.save, null)
159 | .setNegativeButton(R.string.cancel, null)
160 |
161 | val dialog = builder.show()
162 |
163 | // If the contact is being edited, populates the EditText with the old
164 | // information
165 | if (editing) {
166 | val (firstName, lastName, email) = mContacts[contactPosition]
167 | mFirstNameEdit.setText(firstName)
168 | mFirstNameEdit.isEnabled = false
169 | mLastNameEdit.setText(lastName)
170 | mLastNameEdit.isEnabled = false
171 | mEmailEdit.setText(email)
172 | }
173 | // Overrides the "Save" button press and check for valid input
174 | dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {
175 | // If input is valid, creates and saves the new contact,
176 | // or replaces it if the contact is being edited
177 | if (mEntryValid) {
178 | if (editing) {
179 | val editedContact = mContacts[contactPosition]
180 | editedContact.email = mEmailEdit.text.toString()
181 | mContacts[contactPosition] = editedContact
182 | mAdapter.notifyItemChanged(contactPosition)
183 | } else {
184 | val newContact = Contact(
185 | mFirstNameEdit.text.toString(),
186 | mLastNameEdit.text.toString(),
187 | mEmailEdit.text.toString()
188 | )
189 |
190 | mContacts.add(newContact)
191 | mAdapter.notifyItemInserted(mContacts.size)
192 | }
193 | saveContacts()
194 | dialog.dismiss()
195 | } else {
196 | // Otherwise, shows an error Toast
197 | Toast.makeText(this@ContactsActivity,
198 | R.string.contact_not_valid,
199 | Toast.LENGTH_SHORT).show()
200 | }
201 | }
202 | }
203 |
204 |
205 | override fun onCreateOptionsMenu(menu: Menu): Boolean {
206 | // Inflate the menu; this adds items to the action bar if it is present.
207 | menuInflater.inflate(R.menu.menu_contacts, menu)
208 | return true
209 | }
210 |
211 | override fun onOptionsItemSelected(item: MenuItem): Boolean {
212 | // Handle action bar item clicks here. The action bar will
213 | // automatically handle clicks on the Home/Up button, so long
214 | // as you specify a parent activity in AndroidManifest.xml.
215 | val id = item.itemId
216 |
217 | when (id) {
218 | R.id.action_clear -> {
219 | clearContacts()
220 | return true
221 | }
222 | R.id.action_generate -> {
223 | generateContacts()
224 | return true
225 | }
226 | R.id.action_sort_first -> {
227 | mContacts.sortBy { it.firstName }
228 | mAdapter.notifyDataSetChanged()
229 | return true
230 | }
231 | R.id.action_sort_last -> {
232 | mContacts.sortBy { it.lastName }
233 | mAdapter.notifyDataSetChanged()
234 | return true
235 | }
236 | }
237 |
238 | return super.onOptionsItemSelected(item)
239 | }
240 |
241 |
242 | /**
243 | * Clears the contacts from SharedPreferences and the adapter, called from
244 | * the options menu.
245 | */
246 | private fun clearContacts() {
247 | mContacts.clear()
248 | saveContacts()
249 | mAdapter.notifyDataSetChanged()
250 | }
251 |
252 | /**
253 | * Generates mock contact data to populate the UI from a JSON file in the
254 | * assets directory, called from the options menu.
255 | */
256 | private fun generateContacts() {
257 | val contactsString = readContactJsonFile()
258 | try {
259 | val contactsJson = JSONArray(contactsString)
260 | for (i in 0 until contactsJson.length()) {
261 | val contactJson = contactsJson.getJSONObject(i)
262 | val contact = Contact(
263 | contactJson.getString("first_name"),
264 | contactJson.getString("last_name"),
265 | contactJson.getString("email"))
266 | Log.d(TAG, "generateContacts: " + contact.toString())
267 | mContacts.add(contact)
268 | }
269 |
270 | mAdapter.notifyDataSetChanged()
271 | saveContacts()
272 | } catch (e: JSONException) {
273 | e.printStackTrace()
274 | }
275 |
276 | }
277 |
278 | /**
279 | * Reads a file from the assets directory and returns it as a string.
280 | *
281 | * @return The resulting string.
282 | */
283 | private fun readContactJsonFile(): String? {
284 | var contactsString: String? = null
285 | try {
286 | val inputStream = assets.open("mock_contacts.json")
287 | val size = inputStream.available()
288 | val buffer = ByteArray(size)
289 | inputStream.read(buffer)
290 | inputStream.close()
291 |
292 | contactsString = String(buffer)
293 | } catch (e: IOException) {
294 | e.printStackTrace()
295 | }
296 |
297 | return contactsString
298 | }
299 |
300 | /**
301 | * Override methods for the TextWatcher interface, used to validate user
302 | * input.
303 | */
304 |
305 |
306 | override fun beforeTextChanged(charSequence: CharSequence, i: Int, i1: Int,
307 | i2: Int) {
308 |
309 | }
310 |
311 | override fun onTextChanged(charSequence: CharSequence, i: Int, i1: Int,
312 | i2: Int) {
313 |
314 | }
315 |
316 | /**
317 | * Validates the user input when adding a new contact each time the test
318 | * is changed.
319 | *
320 | * @param editable The text that was changed. It is not used as you get the
321 | * text from member variables.
322 | */
323 | override fun afterTextChanged(editable: Editable) {
324 | val notEmpty: TextView.() -> Boolean = { text.isNotEmpty() }
325 | val isEmail: TextView.() -> Boolean = { Patterns.EMAIL_ADDRESS.matcher(text).matches() }
326 |
327 | mEntryValid = mFirstNameEdit.validateWith(validator = notEmpty) and
328 | mLastNameEdit.validateWith(validator = notEmpty) and
329 | mEmailEdit.validateWith(validator = isEmail)
330 | }
331 |
332 | private inner class ContactsAdapter internal constructor(
333 | private val mContacts: ArrayList) :
334 | RecyclerView.Adapter() {
335 |
336 | override fun onCreateViewHolder(
337 | parent: ViewGroup, viewType: Int): ViewHolder {
338 | val view = LayoutInflater.from(parent.context)
339 | .inflate(R.layout.contact_list_item, parent, false)
340 | return ViewHolder(view)
341 | }
342 |
343 | override fun onBindViewHolder(
344 | holder: ViewHolder, position: Int) {
345 | val (firstName, lastName, email) = mContacts[position]
346 | val fullName = "$firstName $lastName"
347 | holder.nameLabel.text = fullName
348 | holder.emailLabel.text = email
349 | }
350 |
351 | override fun getItemCount(): Int {
352 | return mContacts.size
353 | }
354 |
355 | internal inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
356 | var nameLabel: TextView = itemView.textview_name
357 | var emailLabel: TextView = itemView.textview_email
358 |
359 | init {
360 | itemView.setOnClickListener { showAddContactDialog(adapterPosition) }
361 | }
362 | }
363 | }
364 |
365 | companion object {
366 |
367 | private val CONTACT_KEY = "contact_key"
368 | private val TAG = ContactsActivity::class.java.simpleName
369 | }
370 | }
371 |
--------------------------------------------------------------------------------
/MyAddressBook-step3/app/src/main/java/com/example/android/myaddressbook/ContactsActivity.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Google Inc.
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 | package com.example.android.myaddressbook
17 |
18 | import android.annotation.SuppressLint
19 | import android.content.Context
20 | import android.content.SharedPreferences
21 | import android.os.Bundle
22 | import android.support.design.widget.FloatingActionButton
23 | import android.support.v4.content.ContextCompat
24 | import android.support.v7.app.AlertDialog
25 | import android.support.v7.app.AppCompatActivity
26 | import android.support.v7.widget.DividerItemDecoration
27 | import android.support.v7.widget.RecyclerView
28 | import android.support.v7.widget.Toolbar
29 | import android.support.v7.widget.helper.ItemTouchHelper
30 | import android.text.Editable
31 | import android.text.TextWatcher
32 | import android.util.Log
33 | import android.util.Patterns
34 | import android.view.*
35 | import android.widget.EditText
36 | import android.widget.TextView
37 | import android.widget.Toast
38 | import com.google.gson.Gson
39 | import org.json.JSONArray
40 | import org.json.JSONException
41 | import java.io.IOException
42 | import java.util.*
43 |
44 | class ContactsActivity : AppCompatActivity(), TextWatcher {
45 |
46 | private lateinit var mContacts: ArrayList
47 | private lateinit var mAdapter: ContactsAdapter
48 |
49 | private lateinit var mPrefs: SharedPreferences
50 |
51 | private lateinit var mFirstNameEdit: EditText
52 | private lateinit var mLastNameEdit: EditText
53 | private lateinit var mEmailEdit: EditText
54 |
55 | private var mEntryValid = false
56 |
57 | override fun onCreate(savedInstanceState: Bundle?) {
58 | super.onCreate(savedInstanceState)
59 | setContentView(R.layout.activity_contacts)
60 |
61 | val toolbar = findViewById(R.id.toolbar)
62 | val fab = findViewById(R.id.fab)
63 |
64 | mPrefs = getPreferences(Context.MODE_PRIVATE)
65 | mContacts = loadContacts()
66 | mAdapter = ContactsAdapter(mContacts)
67 |
68 | setSupportActionBar(toolbar)
69 | setupRecyclerView()
70 |
71 | fab.setOnClickListener { showAddContactDialog(-1) }
72 | }
73 |
74 | /**
75 | * Loads the contacts from SharedPreferences, and deserializes them into
76 | * a Contact data type using Gson.
77 | */
78 | private fun loadContacts(): ArrayList {
79 | val contactSet = mPrefs.getStringSet(CONTACT_KEY, HashSet())
80 | val contacts = ArrayList()
81 | for (contactString in contactSet) {
82 | contacts.add(Gson().fromJson(contactString, Contact::class.java))
83 | }
84 | return contacts
85 | }
86 |
87 | /**
88 | * Saves the contacts to SharedPreferences by serializing them with Gson.
89 | */
90 | private fun saveContacts() {
91 | val editor = mPrefs.edit()
92 | editor.clear()
93 | val contactSet = HashSet()
94 | for (contact in mContacts) {
95 | contactSet.add(Gson().toJson(contact))
96 | }
97 | editor.putStringSet(CONTACT_KEY, contactSet)
98 | editor.apply()
99 | }
100 |
101 | /**
102 | * Sets up the RecyclerView: empty data set, item dividers, swipe to delete.
103 | */
104 | private fun setupRecyclerView() {
105 | val recyclerView = findViewById(R.id.contact_list)
106 |
107 | recyclerView.addItemDecoration(DividerItemDecoration(this,
108 | DividerItemDecoration.VERTICAL))
109 | recyclerView.adapter = mAdapter
110 |
111 | // Implements swipe to delete
112 | val helper = ItemTouchHelper(
113 | object : ItemTouchHelper.SimpleCallback(0,
114 | ItemTouchHelper.LEFT or ItemTouchHelper.RIGHT) {
115 | override fun onMove(rV: RecyclerView,
116 | viewHolder: RecyclerView.ViewHolder,
117 | target: RecyclerView.ViewHolder): Boolean {
118 | return false
119 | }
120 |
121 | override fun onSwiped(viewHolder: RecyclerView.ViewHolder,
122 | direction: Int) {
123 | val position = viewHolder.adapterPosition
124 | mContacts.removeAt(position)
125 | mAdapter.notifyItemRemoved(position)
126 | saveContacts()
127 | }
128 | })
129 |
130 | helper.attachToRecyclerView(recyclerView)
131 | }
132 |
133 | /**
134 | * Shows the AlertDialog for entering a new contact and performs validation
135 | * on the user input.
136 | *
137 | * @param contactPosition The position of the contact being edited, -1
138 | * if the user is creating a new contact.
139 | */
140 | @SuppressLint("InflateParams")
141 | private fun showAddContactDialog(contactPosition: Int) {
142 | // Inflates the dialog view
143 | val dialogView = LayoutInflater.from(this)
144 | .inflate(R.layout.input_contact_dialog, null)
145 |
146 | mFirstNameEdit = dialogView.findViewById(R.id.edittext_firstname)
147 | mLastNameEdit = dialogView.findViewById(R.id.edittext_lastname)
148 | mEmailEdit = dialogView.findViewById(R.id.edittext_email)
149 |
150 | // Listens to text changes to validate after each key press
151 | mFirstNameEdit.addTextChangedListener(this)
152 | mLastNameEdit.addTextChangedListener(this)
153 | mEmailEdit.addTextChangedListener(this)
154 |
155 | // Checks if the user is editing an existing contact
156 | val editing = contactPosition > -1
157 |
158 | val dialogTitle = if (editing)
159 | getString(R.string.edit_contact)
160 | else
161 | getString(R.string.new_contact)
162 |
163 | // Builds the AlertDialog and sets the custom view. Pass null for
164 | // the positive and negative buttons, as you will override the button
165 | // presses manually to perform validation before closing the dialog
166 | val builder = AlertDialog.Builder(this)
167 | .setView(dialogView)
168 | .setTitle(dialogTitle)
169 | .setPositiveButton(R.string.save, null)
170 | .setNegativeButton(R.string.cancel, null)
171 |
172 | val dialog = builder.show()
173 |
174 | // If the contact is being edited, populates the EditText with the old
175 | // information
176 | if (editing) {
177 | val (firstName, lastName, email) = mContacts[contactPosition]
178 | mFirstNameEdit.setText(firstName)
179 | mFirstNameEdit.isEnabled = false
180 | mLastNameEdit.setText(lastName)
181 | mLastNameEdit.isEnabled = false
182 | mEmailEdit.setText(email)
183 | }
184 | // Overrides the "Save" button press and check for valid input
185 | dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {
186 | // If input is valid, creates and saves the new contact,
187 | // or replaces it if the contact is being edited
188 | if (mEntryValid) {
189 | if (editing) {
190 | val editedContact = mContacts[contactPosition]
191 | editedContact.email = mEmailEdit.text.toString()
192 | mContacts[contactPosition] = editedContact
193 | mAdapter.notifyItemChanged(contactPosition)
194 | } else {
195 | val newContact = Contact(
196 | mFirstNameEdit.text.toString(),
197 | mLastNameEdit.text.toString(),
198 | mEmailEdit.text.toString()
199 | )
200 |
201 | mContacts.add(newContact)
202 | mAdapter.notifyItemInserted(mContacts.size)
203 | }
204 | saveContacts()
205 | dialog.dismiss()
206 | } else {
207 | // Otherwise, shows an error Toast
208 | Toast.makeText(this@ContactsActivity,
209 | R.string.contact_not_valid,
210 | Toast.LENGTH_SHORT).show()
211 | }
212 | }
213 | }
214 |
215 |
216 | override fun onCreateOptionsMenu(menu: Menu): Boolean {
217 | // Inflate the menu; this adds items to the action bar if it is present.
218 | menuInflater.inflate(R.menu.menu_contacts, menu)
219 | return true
220 | }
221 |
222 | override fun onOptionsItemSelected(item: MenuItem): Boolean {
223 | // Handle action bar item clicks here. The action bar will
224 | // automatically handle clicks on the Home/Up button, so long
225 | // as you specify a parent activity in AndroidManifest.xml.
226 | val id = item.itemId
227 |
228 | when (id) {
229 | R.id.action_clear -> {
230 | clearContacts()
231 | return true
232 | }
233 | R.id.action_generate -> {
234 | generateContacts()
235 | return true
236 | }
237 | }
238 |
239 | return super.onOptionsItemSelected(item)
240 | }
241 |
242 |
243 | /**
244 | * Clears the contacts from SharedPreferences and the adapter, called from
245 | * the options menu.
246 | */
247 | private fun clearContacts() {
248 | mContacts.clear()
249 | saveContacts()
250 | mAdapter.notifyDataSetChanged()
251 | }
252 |
253 | /**
254 | * Generates mock contact data to populate the UI from a JSON file in the
255 | * assets directory, called from the options menu.
256 | */
257 | private fun generateContacts() {
258 | val contactsString = readContactJsonFile()
259 | try {
260 | val contactsJson = JSONArray(contactsString)
261 | for (i in 0 until contactsJson.length()) {
262 | val contactJson = contactsJson.getJSONObject(i)
263 | val contact = Contact(
264 | contactJson.getString("first_name"),
265 | contactJson.getString("last_name"),
266 | contactJson.getString("email"))
267 | Log.d(TAG, "generateContacts: " + contact.toString())
268 | mContacts.add(contact)
269 | }
270 |
271 | mAdapter.notifyDataSetChanged()
272 | saveContacts()
273 | } catch (e: JSONException) {
274 | e.printStackTrace()
275 | }
276 |
277 | }
278 |
279 | /**
280 | * Reads a file from the assets directory and returns it as a string.
281 | *
282 | * @return The resulting string.
283 | */
284 | private fun readContactJsonFile(): String? {
285 | var contactsString: String? = null
286 | try {
287 | val inputStream = assets.open("mock_contacts.json")
288 | val size = inputStream.available()
289 | val buffer = ByteArray(size)
290 | inputStream.read(buffer)
291 | inputStream.close()
292 |
293 | contactsString = String(buffer)
294 | } catch (e: IOException) {
295 | e.printStackTrace()
296 | }
297 |
298 | return contactsString
299 | }
300 |
301 | /**
302 | * Override methods for the TextWatcher interface, used to validate user
303 | * input.
304 | */
305 |
306 |
307 | override fun beforeTextChanged(charSequence: CharSequence, i: Int, i1: Int,
308 | i2: Int) {
309 |
310 | }
311 |
312 | override fun onTextChanged(charSequence: CharSequence, i: Int, i1: Int,
313 | i2: Int) {
314 |
315 | }
316 |
317 | /**
318 | * Validates the user input when adding a new contact each time the test
319 | * is changed.
320 | *
321 | * @param editable The text that was changed. It is not used as you get the
322 | * text from member variables.
323 | */
324 | override fun afterTextChanged(editable: Editable) {
325 | val firstNameValid = !mFirstNameEdit.text.toString().isEmpty()
326 | val lastNameValid = !mLastNameEdit.text.toString().isEmpty()
327 | val emailValid = Patterns.EMAIL_ADDRESS
328 | .matcher(mEmailEdit.text).matches()
329 |
330 | val failIcon = ContextCompat.getDrawable(this,
331 | R.drawable.ic_fail)
332 | val passIcon = ContextCompat.getDrawable(this,
333 | R.drawable.ic_pass)
334 |
335 | mFirstNameEdit.setCompoundDrawablesWithIntrinsicBounds(null, null,
336 | if (firstNameValid) passIcon else failIcon, null)
337 | mLastNameEdit.setCompoundDrawablesWithIntrinsicBounds(null, null,
338 | if (lastNameValid) passIcon else failIcon, null)
339 | mEmailEdit.setCompoundDrawablesWithIntrinsicBounds(null, null,
340 | if (emailValid) passIcon else failIcon, null)
341 |
342 | mEntryValid = firstNameValid and lastNameValid and emailValid
343 | }
344 |
345 | private inner class ContactsAdapter internal constructor(
346 | private val mContacts: ArrayList) :
347 | RecyclerView.Adapter() {
348 |
349 | override fun onCreateViewHolder(
350 | parent: ViewGroup, viewType: Int): ViewHolder {
351 | val view = LayoutInflater.from(parent.context)
352 | .inflate(R.layout.contact_list_item, parent, false)
353 | return ViewHolder(view)
354 | }
355 |
356 | override fun onBindViewHolder(
357 | holder: ViewHolder, position: Int) {
358 | val (firstName, lastName, email) = mContacts[position]
359 | val fullName = "$firstName $lastName"
360 | holder.nameLabel.text = fullName
361 | holder.emailLabel.text = email
362 | }
363 |
364 | override fun getItemCount(): Int {
365 | return mContacts.size
366 | }
367 |
368 | internal inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
369 | var nameLabel: TextView = itemView.findViewById(R.id.textview_name)
370 | var emailLabel: TextView = itemView.findViewById(R.id.textview_email)
371 |
372 | init {
373 | itemView.setOnClickListener { showAddContactDialog(adapterPosition) }
374 | }
375 | }
376 | }
377 |
378 | companion object {
379 |
380 | private val CONTACT_KEY = "contact_key"
381 | private val TAG = ContactsActivity::class.java.simpleName
382 | }
383 | }
384 |
--------------------------------------------------------------------------------
/MyAddressBook-step4/app/src/main/java/com/example/android/myaddressbook/ContactsActivity.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Google Inc.
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 | package com.example.android.myaddressbook
17 |
18 | import android.annotation.SuppressLint
19 | import android.content.Context
20 | import android.content.SharedPreferences
21 | import android.os.Bundle
22 | import android.support.v4.content.ContextCompat
23 | import android.support.v7.app.AlertDialog
24 | import android.support.v7.app.AppCompatActivity
25 | import android.support.v7.widget.DividerItemDecoration
26 | import android.support.v7.widget.RecyclerView
27 | import android.support.v7.widget.helper.ItemTouchHelper
28 | import android.text.Editable
29 | import android.text.TextWatcher
30 | import android.util.Log
31 | import android.util.Patterns
32 | import android.view.*
33 | import android.widget.EditText
34 | import android.widget.TextView
35 | import android.widget.Toast
36 | import com.google.gson.Gson
37 | import kotlinx.android.synthetic.main.activity_contacts.*
38 | import kotlinx.android.synthetic.main.contact_list_item.view.*
39 | import kotlinx.android.synthetic.main.content_contacts.*
40 | import kotlinx.android.synthetic.main.input_contact_dialog.view.*
41 | import org.json.JSONArray
42 | import org.json.JSONException
43 | import java.io.IOException
44 | import java.util.*
45 |
46 | class ContactsActivity : AppCompatActivity(), TextWatcher {
47 |
48 | private lateinit var mContacts: ArrayList
49 | private lateinit var mAdapter: ContactsAdapter
50 |
51 | private lateinit var mPrefs: SharedPreferences
52 |
53 | private lateinit var mFirstNameEdit: EditText
54 | private lateinit var mLastNameEdit: EditText
55 | private lateinit var mEmailEdit: EditText
56 |
57 | private var mEntryValid = false
58 |
59 | override fun onCreate(savedInstanceState: Bundle?) {
60 | super.onCreate(savedInstanceState)
61 | setContentView(R.layout.activity_contacts)
62 |
63 | mPrefs = getPreferences(Context.MODE_PRIVATE)
64 | mContacts = loadContacts()
65 | mAdapter = ContactsAdapter(mContacts)
66 |
67 | setSupportActionBar(toolbar)
68 | setupRecyclerView()
69 |
70 | fab.setOnClickListener { showAddContactDialog(-1) }
71 | }
72 |
73 | /**
74 | * Loads the contacts from SharedPreferences, and deserializes them into
75 | * a Contact data type using Gson.
76 | */
77 | private fun loadContacts(): ArrayList {
78 | val contactSet = mPrefs.getStringSet(CONTACT_KEY, HashSet())
79 | return contactSet.mapTo(ArrayList()) { Gson().fromJson(it, Contact::class.java) }
80 | }
81 |
82 | /**
83 | * Saves the contacts to SharedPreferences by serializing them with Gson.
84 | */
85 | private fun saveContacts() {
86 | val editor = mPrefs.edit()
87 | editor.clear()
88 | val contactSet = mContacts.map { Gson().toJson(it) }.toSet()
89 | editor.putStringSet(CONTACT_KEY, contactSet)
90 | editor.apply()
91 | }
92 |
93 | /**
94 | * Sets up the RecyclerView: empty data set, item dividers, swipe to delete.
95 | */
96 | private fun setupRecyclerView() {
97 | contact_list.addItemDecoration(DividerItemDecoration(this,
98 | DividerItemDecoration.VERTICAL))
99 | contact_list.adapter = mAdapter
100 |
101 | // Implements swipe to delete
102 | val helper = ItemTouchHelper(
103 | object : ItemTouchHelper.SimpleCallback(0,
104 | ItemTouchHelper.LEFT or ItemTouchHelper.RIGHT) {
105 | override fun onMove(rV: RecyclerView,
106 | viewHolder: RecyclerView.ViewHolder,
107 | target: RecyclerView.ViewHolder): Boolean {
108 | return false
109 | }
110 |
111 | override fun onSwiped(viewHolder: RecyclerView.ViewHolder,
112 | direction: Int) {
113 | val position = viewHolder.adapterPosition
114 | mContacts.removeAt(position)
115 | mAdapter.notifyItemRemoved(position)
116 | saveContacts()
117 | }
118 | })
119 |
120 | helper.attachToRecyclerView(contact_list)
121 | }
122 |
123 | /**
124 | * Shows the AlertDialog for entering a new contact and performs validation
125 | * on the user input.
126 | *
127 | * @param contactPosition The position of the contact being edited, -1
128 | * if the user is creating a new contact.
129 | */
130 | @SuppressLint("InflateParams")
131 | private fun showAddContactDialog(contactPosition: Int) {
132 | // Inflates the dialog view
133 | val dialogView = LayoutInflater.from(this)
134 | .inflate(R.layout.input_contact_dialog, null)
135 |
136 | mFirstNameEdit = dialogView.edittext_firstname
137 | mLastNameEdit = dialogView.edittext_lastname
138 | mEmailEdit = dialogView.edittext_email
139 |
140 | // Listens to text changes to validate after each key press
141 | mFirstNameEdit.addTextChangedListener(this)
142 | mLastNameEdit.addTextChangedListener(this)
143 | mEmailEdit.addTextChangedListener(this)
144 |
145 | // Checks if the user is editing an existing contact
146 | val editing = contactPosition > -1
147 |
148 | val dialogTitle = if (editing)
149 | getString(R.string.edit_contact)
150 | else
151 | getString(R.string.new_contact)
152 |
153 | // Builds the AlertDialog and sets the custom view. Pass null for
154 | // the positive and negative buttons, as you will override the button
155 | // presses manually to perform validation before closing the dialog
156 | val builder = AlertDialog.Builder(this)
157 | .setView(dialogView)
158 | .setTitle(dialogTitle)
159 | .setPositiveButton(R.string.save, null)
160 | .setNegativeButton(R.string.cancel, null)
161 |
162 | val dialog = builder.show()
163 |
164 | // If the contact is being edited, populates the EditText with the old
165 | // information
166 | if (editing) {
167 | val (firstName, lastName, email) = mContacts[contactPosition]
168 | mFirstNameEdit.setText(firstName)
169 | mFirstNameEdit.isEnabled = false
170 | mLastNameEdit.setText(lastName)
171 | mLastNameEdit.isEnabled = false
172 | mEmailEdit.setText(email)
173 | }
174 | // Overrides the "Save" button press and check for valid input
175 | dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {
176 | // If input is valid, creates and saves the new contact,
177 | // or replaces it if the contact is being edited
178 | if (mEntryValid) {
179 | if (editing) {
180 | val editedContact = mContacts[contactPosition]
181 | editedContact.email = mEmailEdit.text.toString()
182 | mContacts[contactPosition] = editedContact
183 | mAdapter.notifyItemChanged(contactPosition)
184 | } else {
185 | val newContact = Contact(
186 | mFirstNameEdit.text.toString(),
187 | mLastNameEdit.text.toString(),
188 | mEmailEdit.text.toString()
189 | )
190 |
191 | mContacts.add(newContact)
192 | mAdapter.notifyItemInserted(mContacts.size)
193 | }
194 | saveContacts()
195 | dialog.dismiss()
196 | } else {
197 | // Otherwise, shows an error Toast
198 | Toast.makeText(this@ContactsActivity,
199 | R.string.contact_not_valid,
200 | Toast.LENGTH_SHORT).show()
201 | }
202 | }
203 | }
204 |
205 |
206 | override fun onCreateOptionsMenu(menu: Menu): Boolean {
207 | // Inflate the menu; this adds items to the action bar if it is present.
208 | menuInflater.inflate(R.menu.menu_contacts, menu)
209 | return true
210 | }
211 |
212 | override fun onOptionsItemSelected(item: MenuItem): Boolean {
213 | // Handle action bar item clicks here. The action bar will
214 | // automatically handle clicks on the Home/Up button, so long
215 | // as you specify a parent activity in AndroidManifest.xml.
216 | val id = item.itemId
217 |
218 | when (id) {
219 | R.id.action_clear -> {
220 | clearContacts()
221 | return true
222 | }
223 | R.id.action_generate -> {
224 | generateContacts()
225 | return true
226 | }
227 | R.id.action_sort_first -> {
228 | mContacts.sortBy { it.firstName }
229 | mAdapter.notifyDataSetChanged()
230 | return true
231 | }
232 | R.id.action_sort_last -> {
233 | mContacts.sortBy { it.lastName }
234 | mAdapter.notifyDataSetChanged()
235 | return true
236 | }
237 | }
238 |
239 | return super.onOptionsItemSelected(item)
240 | }
241 |
242 |
243 | /**
244 | * Clears the contacts from SharedPreferences and the adapter, called from
245 | * the options menu.
246 | */
247 | private fun clearContacts() {
248 | mContacts.clear()
249 | saveContacts()
250 | mAdapter.notifyDataSetChanged()
251 | }
252 |
253 | /**
254 | * Generates mock contact data to populate the UI from a JSON file in the
255 | * assets directory, called from the options menu.
256 | */
257 | private fun generateContacts() {
258 | val contactsString = readContactJsonFile()
259 | try {
260 | val contactsJson = JSONArray(contactsString)
261 | for (i in 0 until contactsJson.length()) {
262 | val contactJson = contactsJson.getJSONObject(i)
263 | val contact = Contact(
264 | contactJson.getString("first_name"),
265 | contactJson.getString("last_name"),
266 | contactJson.getString("email"))
267 | Log.d(TAG, "generateContacts: " + contact.toString())
268 | mContacts.add(contact)
269 | }
270 |
271 | mAdapter.notifyDataSetChanged()
272 | saveContacts()
273 | } catch (e: JSONException) {
274 | e.printStackTrace()
275 | }
276 |
277 | }
278 |
279 | /**
280 | * Reads a file from the assets directory and returns it as a string.
281 | *
282 | * @return The resulting string.
283 | */
284 | private fun readContactJsonFile(): String? {
285 | var contactsString: String? = null
286 | try {
287 | val inputStream = assets.open("mock_contacts.json")
288 | val size = inputStream.available()
289 | val buffer = ByteArray(size)
290 | inputStream.read(buffer)
291 | inputStream.close()
292 |
293 | contactsString = String(buffer)
294 | } catch (e: IOException) {
295 | e.printStackTrace()
296 | }
297 |
298 | return contactsString
299 | }
300 |
301 | /**
302 | * Override methods for the TextWatcher interface, used to validate user
303 | * input.
304 | */
305 |
306 |
307 | override fun beforeTextChanged(charSequence: CharSequence, i: Int, i1: Int,
308 | i2: Int) {
309 |
310 | }
311 |
312 | override fun onTextChanged(charSequence: CharSequence, i: Int, i1: Int,
313 | i2: Int) {
314 |
315 | }
316 |
317 | /**
318 | * Validates the user input when adding a new contact each time the test
319 | * is changed.
320 | *
321 | * @param editable The text that was changed. It is not used as you get the
322 | * text from member variables.
323 | */
324 | override fun afterTextChanged(editable: Editable) {
325 | val notEmpty: (TextView) -> Boolean = { it.text.isNotEmpty() }
326 | val isEmail: (TextView) -> Boolean = { Patterns.EMAIL_ADDRESS.matcher(it.text).matches() }
327 |
328 | val failIcon = ContextCompat.getDrawable(this,
329 | R.drawable.ic_fail)
330 | val passIcon = ContextCompat.getDrawable(this,
331 | R.drawable.ic_pass)
332 |
333 | mFirstNameEdit.setCompoundDrawablesWithIntrinsicBounds(null, null,
334 | if (notEmpty(mFirstNameEdit)) passIcon else failIcon, null)
335 | mLastNameEdit.setCompoundDrawablesWithIntrinsicBounds(null, null,
336 | if (notEmpty(mLastNameEdit)) passIcon else failIcon, null)
337 | mEmailEdit.setCompoundDrawablesWithIntrinsicBounds(null, null,
338 | if (isEmail(mEmailEdit)) passIcon else failIcon, null)
339 |
340 | mEntryValid = notEmpty(mFirstNameEdit) and notEmpty(mLastNameEdit) and isEmail(mEmailEdit)
341 | }
342 |
343 | private inner class ContactsAdapter internal constructor(
344 | private val mContacts: ArrayList) :
345 | RecyclerView.Adapter() {
346 |
347 | override fun onCreateViewHolder(
348 | parent: ViewGroup, viewType: Int): ViewHolder {
349 | val view = LayoutInflater.from(parent.context)
350 | .inflate(R.layout.contact_list_item, parent, false)
351 | return ViewHolder(view)
352 | }
353 |
354 | override fun onBindViewHolder(
355 | holder: ViewHolder, position: Int) {
356 | val (firstName, lastName, email) = mContacts[position]
357 | val fullName = "$firstName $lastName"
358 | holder.nameLabel.text = fullName
359 | holder.emailLabel.text = email
360 | }
361 |
362 | override fun getItemCount(): Int {
363 | return mContacts.size
364 | }
365 |
366 | internal inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
367 | var nameLabel: TextView = itemView.textview_name
368 | var emailLabel: TextView = itemView.textview_email
369 |
370 | init {
371 | itemView.setOnClickListener { showAddContactDialog(adapterPosition) }
372 | }
373 | }
374 | }
375 |
376 | companion object {
377 |
378 | private val CONTACT_KEY = "contact_key"
379 | private val TAG = ContactsActivity::class.java.simpleName
380 | }
381 | }
382 |
--------------------------------------------------------------------------------