├── .github └── workflows │ └── manual.yml ├── .gitignore ├── .idea └── navEditor.xml ├── CODEOWNERS ├── LICENSE.txt ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── example │ │ └── android │ │ └── guesstheword │ │ └── ExampleInstrumentedTest.kt │ ├── main │ ├── AndroidManifest.xml │ ├── ic_guess_it-web.png │ ├── java │ │ └── com │ │ │ └── example │ │ │ └── android │ │ │ └── guesstheword │ │ │ ├── MainActivity.kt │ │ │ └── screens │ │ │ ├── game │ │ │ ├── GameFragment.kt │ │ │ └── GameViewModel.kt │ │ │ ├── score │ │ │ ├── ScoreFragment.kt │ │ │ ├── ScoreViewModel.kt │ │ │ └── ScoreViewModelFactory.kt │ │ │ └── title │ │ │ └── TitleFragment.kt │ └── res │ │ ├── anim │ │ ├── slide_in_right.xml │ │ └── slide_out_left.xml │ │ ├── drawable │ │ ├── ic_launcher_background.xml │ │ └── ic_launcher_foreground.xml │ │ ├── layout │ │ ├── game_fragment.xml │ │ ├── main_activity.xml │ │ ├── score_fragment.xml │ │ └── title_fragment.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_guess_it.xml │ │ └── ic_guess_it_round.xml │ │ ├── mipmap-hdpi │ │ ├── ic_guess_it.png │ │ └── ic_guess_it_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_guess_it.png │ │ └── ic_guess_it_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_guess_it.png │ │ └── ic_guess_it_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_guess_it.png │ │ └── ic_guess_it_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_guess_it.png │ │ └── ic_guess_it_round.png │ │ ├── navigation │ │ └── main_navigation.xml │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── example │ └── android │ └── guesstheword │ └── ExampleUnitTest.kt ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── screenshots ├── screen0.png ├── screen1.png └── screen2.png └── settings.gradle /.github/workflows/manual.yml: -------------------------------------------------------------------------------- 1 | # Workflow to ensure whenever a Github PR is submitted, 2 | # a JIRA ticket gets created automatically. 3 | name: Manual Workflow 4 | 5 | # Controls when the action will run. 6 | on: 7 | # Triggers the workflow on pull request events but only for the master branch 8 | pull_request_target: 9 | types: [opened, reopened] 10 | 11 | # Allows you to run this workflow manually from the Actions tab 12 | workflow_dispatch: 13 | 14 | jobs: 15 | test-transition-issue: 16 | name: Convert Github Issue to Jira Issue 17 | runs-on: ubuntu-latest 18 | steps: 19 | - name: Checkout 20 | uses: actions/checkout@master 21 | 22 | - name: Login 23 | uses: atlassian/gajira-login@master 24 | env: 25 | JIRA_BASE_URL: ${{ secrets.JIRA_BASE_URL }} 26 | JIRA_USER_EMAIL: ${{ secrets.JIRA_USER_EMAIL }} 27 | JIRA_API_TOKEN: ${{ secrets.JIRA_API_TOKEN }} 28 | 29 | - name: Create NEW JIRA ticket 30 | id: create 31 | uses: atlassian/gajira-create@master 32 | with: 33 | project: CONUPDATE 34 | issuetype: Task 35 | summary: | 36 | Github PR nd940 - Android Kotlin Developer | Repo: ${{ github.repository }} | PR# ${{github.event.number}} 37 | description: | 38 | Repo link: https://github.com/${{ github.repository }} 39 | PR no. ${{ github.event.pull_request.number }} 40 | PR title: ${{ github.event.pull_request.title }} 41 | PR description: ${{ github.event.pull_request.description }} 42 | In addition, please resolve other issues, if any. 43 | fields: '{"components": [{"name":"nd940 - Android Kotlin Developer"}], "customfield_16449":"https://classroom.udacity.com/", "customfield_16450":"Resolve the PR", "labels": ["github"], "priority":{"id": "4"}}' 44 | 45 | - name: Log created issue 46 | run: echo "Issue ${{ steps.create.outputs.issue }} was created" 47 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/* 5 | .DS_Store 6 | /build 7 | /captures 8 | .externalNativeBuild 9 | !/.idea/navEditor.xml 10 | -------------------------------------------------------------------------------- /.idea/navEditor.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 81 | 82 | -------------------------------------------------------------------------------- /CODEOWNERS: -------------------------------------------------------------------------------- 1 | * @udacity/active-public-content -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | All image and audio files (including *.png, *.jpg, *.svg, *.mp3, *.wav 2 | and *.ogg) are licensed under the CC BY 4.0 license. All other files are 3 | licensed under the Apache 2 license. 4 | 5 | ======================================================================= 6 | 7 | Apache License 8 | -------------- 9 | 10 | Version 2.0, January 2004 11 | http://www.apache.org/licenses/ 12 | 13 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 14 | 15 | 1. Definitions. 16 | 17 | "License" shall mean the terms and conditions for use, reproduction, 18 | and distribution as defined by Sections 1 through 9 of this document. 19 | 20 | "Licensor" shall mean the copyright owner or entity authorized by 21 | the copyright owner that is granting the License. 22 | 23 | "Legal Entity" shall mean the union of the acting entity and all 24 | other entities that control, are controlled by, or are under common 25 | control with that entity. For the purposes of this definition, 26 | "control" means (i) the power, direct or indirect, to cause the 27 | direction or management of such entity, whether by contract or 28 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 29 | outstanding shares, or (iii) beneficial ownership of such entity. 30 | 31 | "You" (or "Your") shall mean an individual or Legal Entity 32 | exercising permissions granted by this License. 33 | 34 | "Source" form shall mean the preferred form for making modifications, 35 | including but not limited to software source code, documentation 36 | source, and configuration files. 37 | 38 | "Object" form shall mean any form resulting from mechanical 39 | transformation or translation of a Source form, including but 40 | not limited to compiled object code, generated documentation, 41 | and conversions to other media types. 42 | 43 | "Work" shall mean the work of authorship, whether in Source or 44 | Object form, made available under the License, as indicated by a 45 | copyright notice that is included in or attached to the work 46 | (an example is provided in the Appendix below). 47 | 48 | "Derivative Works" shall mean any work, whether in Source or Object 49 | form, that is based on (or derived from) the Work and for which the 50 | editorial revisions, annotations, elaborations, or other modifications 51 | represent, as a whole, an original work of authorship. For the purposes 52 | of this License, Derivative Works shall not include works that remain 53 | separable from, or merely link (or bind by name) to the interfaces of, 54 | the Work and Derivative Works thereof. 55 | 56 | "Contribution" shall mean any work of authorship, including 57 | the original version of the Work and any modifications or additions 58 | to that Work or Derivative Works thereof, that is intentionally 59 | submitted to Licensor for inclusion in the Work by the copyright owner 60 | or by an individual or Legal Entity authorized to submit on behalf of 61 | the copyright owner. For the purposes of this definition, "submitted" 62 | means any form of electronic, verbal, or written communication sent 63 | to the Licensor or its representatives, including but not limited to 64 | communication on electronic mailing lists, source code control systems, 65 | and issue tracking systems that are managed by, or on behalf of, the 66 | Licensor for the purpose of discussing and improving the Work, but 67 | excluding communication that is conspicuously marked or otherwise 68 | designated in writing by the copyright owner as "Not a Contribution." 69 | 70 | "Contributor" shall mean Licensor and any individual or Legal Entity 71 | on behalf of whom a Contribution has been received by Licensor and 72 | subsequently incorporated within the Work. 73 | 74 | 2. Grant of Copyright License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | copyright license to reproduce, prepare Derivative Works of, 78 | publicly display, publicly perform, sublicense, and distribute the 79 | Work and such Derivative Works in Source or Object form. 80 | 81 | 3. Grant of Patent License. Subject to the terms and conditions of 82 | this License, each Contributor hereby grants to You a perpetual, 83 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 84 | (except as stated in this section) patent license to make, have made, 85 | use, offer to sell, sell, import, and otherwise transfer the Work, 86 | where such license applies only to those patent claims licensable 87 | by such Contributor that are necessarily infringed by their 88 | Contribution(s) alone or by combination of their Contribution(s) 89 | with the Work to which such Contribution(s) was submitted. If You 90 | institute patent litigation against any entity (including a 91 | cross-claim or counterclaim in a lawsuit) alleging that the Work 92 | or a Contribution incorporated within the Work constitutes direct 93 | or contributory patent infringement, then any patent licenses 94 | granted to You under this License for that Work shall terminate 95 | as of the date such litigation is filed. 96 | 97 | 4. Redistribution. You may reproduce and distribute copies of the 98 | Work or Derivative Works thereof in any medium, with or without 99 | modifications, and in Source or Object form, provided that You 100 | meet the following conditions: 101 | 102 | (a) You must give any other recipients of the Work or 103 | Derivative Works a copy of this License; and 104 | 105 | (b) You must cause any modified files to carry prominent notices 106 | stating that You changed the files; and 107 | 108 | (c) You must retain, in the Source form of any Derivative Works 109 | that You distribute, all copyright, patent, trademark, and 110 | attribution notices from the Source form of the Work, 111 | excluding those notices that do not pertain to any part of 112 | the Derivative Works; and 113 | 114 | (d) If the Work includes a "NOTICE" text file as part of its 115 | distribution, then any Derivative Works that You distribute must 116 | include a readable copy of the attribution notices contained 117 | within such NOTICE file, excluding those notices that do not 118 | pertain to any part of the Derivative Works, in at least one 119 | of the following places: within a NOTICE text file distributed 120 | as part of the Derivative Works; within the Source form or 121 | documentation, if provided along with the Derivative Works; or, 122 | within a display generated by the Derivative Works, if and 123 | wherever such third-party notices normally appear. The contents 124 | of the NOTICE file are for informational purposes only and 125 | do not modify the License. You may add Your own attribution 126 | notices within Derivative Works that You distribute, alongside 127 | or as an addendum to the NOTICE text from the Work, provided 128 | that such additional attribution notices cannot be construed 129 | as modifying the License. 130 | 131 | You may add Your own copyright statement to Your modifications and 132 | may provide additional or different license terms and conditions 133 | for use, reproduction, or distribution of Your modifications, or 134 | for any such Derivative Works as a whole, provided Your use, 135 | reproduction, and distribution of the Work otherwise complies with 136 | the conditions stated in this License. 137 | 138 | 5. Submission of Contributions. Unless You explicitly state otherwise, 139 | any Contribution intentionally submitted for inclusion in the Work 140 | by You to the Licensor shall be under the terms and conditions of 141 | this License, without any additional terms or conditions. 142 | Notwithstanding the above, nothing herein shall supersede or modify 143 | the terms of any separate license agreement you may have executed 144 | with Licensor regarding such Contributions. 145 | 146 | 6. Trademarks. This License does not grant permission to use the trade 147 | names, trademarks, service marks, or product names of the Licensor, 148 | except as required for reasonable and customary use in describing the 149 | origin of the Work and reproducing the content of the NOTICE file. 150 | 151 | 7. Disclaimer of Warranty. Unless required by applicable law or 152 | agreed to in writing, Licensor provides the Work (and each 153 | Contributor provides its Contributions) on an "AS IS" BASIS, 154 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 155 | implied, including, without limitation, any warranties or conditions 156 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 157 | PARTICULAR PURPOSE. You are solely responsible for determining the 158 | appropriateness of using or redistributing the Work and assume any 159 | risks associated with Your exercise of permissions under this License. 160 | 161 | 8. Limitation of Liability. In no event and under no legal theory, 162 | whether in tort (including negligence), contract, or otherwise, 163 | unless required by applicable law (such as deliberate and grossly 164 | negligent acts) or agreed to in writing, shall any Contributor be 165 | liable to You for damages, including any direct, indirect, special, 166 | incidental, or consequential damages of any character arising as a 167 | result of this License or out of the use or inability to use the 168 | Work (including but not limited to damages for loss of goodwill, 169 | work stoppage, computer failure or malfunction, or any and all 170 | other commercial damages or losses), even if such Contributor 171 | has been advised of the possibility of such damages. 172 | 173 | 9. Accepting Warranty or Additional Liability. While redistributing 174 | the Work or Derivative Works thereof, You may choose to offer, 175 | and charge a fee for, acceptance of support, warranty, indemnity, 176 | or other liability obligations and/or rights consistent with this 177 | License. However, in accepting such obligations, You may act only 178 | on Your own behalf and on Your sole responsibility, not on behalf 179 | of any other Contributor, and only if You agree to indemnify, 180 | defend, and hold each Contributor harmless for any liability 181 | incurred by, or claims asserted against, such Contributor by reason 182 | of your accepting any such warranty or additional liability. 183 | 184 | END OF TERMS AND CONDITIONS 185 | 186 | APPENDIX: How to apply the Apache License to your work. 187 | 188 | To apply the Apache License to your work, attach the following 189 | boilerplate notice, with the fields enclosed by brackets "{}" 190 | replaced with your own identifying information. (Don't include 191 | the brackets!) The text should be enclosed in the appropriate 192 | comment syntax for the file format. We also recommend that a 193 | file or class name and description of purpose be included on the 194 | same "printed page" as the copyright notice for easier 195 | identification within third-party archives. 196 | 197 | Copyright {yyyy} {name of copyright owner} 198 | 199 | Licensed under the Apache License, Version 2.0 (the "License"); 200 | you may not use this file except in compliance with the License. 201 | You may obtain a copy of the License at 202 | 203 | http://www.apache.org/licenses/LICENSE-2.0 204 | 205 | Unless required by applicable law or agreed to in writing, software 206 | distributed under the License is distributed on an "AS IS" BASIS, 207 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 208 | See the License for the specific language governing permissions and 209 | limitations under the License. 210 | 211 | All image and audio files (including *.png, *.jpg, *.svg, *.mp3, *.wav 212 | and *.ogg) are licensed under the CC BY 4.0 license. All other files are 213 | licensed under the Apache 2 license. 214 | 215 | CC-BY License 216 | ---------------- 217 | 218 | Attribution 4.0 International 219 | 220 | ======================================================================= 221 | 222 | Creative Commons Corporation ("Creative Commons") is not a law firm and 223 | does not provide legal services or legal advice. Distribution of 224 | Creative Commons public licenses does not create a lawyer-client or 225 | other relationship. Creative Commons makes its licenses and related 226 | information available on an "as-is" basis. Creative Commons gives no 227 | warranties regarding its licenses, any material licensed under their 228 | terms and conditions, or any related information. Creative Commons 229 | disclaims all liability for damages resulting from their use to the 230 | fullest extent possible. 231 | 232 | Using Creative Commons Public Licenses 233 | 234 | Creative Commons public licenses provide a standard set of terms and 235 | conditions that creators and other rights holders may use to share 236 | original works of authorship and other material subject to copyright 237 | and certain other rights specified in the public license below. The 238 | following considerations are for informational purposes only, are not 239 | exhaustive, and do not form part of our licenses. 240 | 241 | Considerations for licensors: Our public licenses are 242 | intended for use by those authorized to give the public 243 | permission to use material in ways otherwise restricted by 244 | copyright and certain other rights. Our licenses are 245 | irrevocable. Licensors should read and understand the terms 246 | and conditions of the license they choose before applying it. 247 | Licensors should also secure all rights necessary before 248 | applying our licenses so that the public can reuse the 249 | material as expected. Licensors should clearly mark any 250 | material not subject to the license. This includes other CC- 251 | licensed material, or material used under an exception or 252 | limitation to copyright. More considerations for licensors: 253 | wiki.creativecommons.org/Considerations_for_licensors 254 | 255 | Considerations for the public: By using one of our public 256 | licenses, a licensor grants the public permission to use the 257 | licensed material under specified terms and conditions. If 258 | the licensor's permission is not necessary for any reason--for 259 | example, because of any applicable exception or limitation to 260 | copyright--then that use is not regulated by the license. Our 261 | licenses grant only permissions under copyright and certain 262 | other rights that a licensor has authority to grant. Use of 263 | the licensed material may still be restricted for other 264 | reasons, including because others have copyright or other 265 | rights in the material. A licensor may make special requests, 266 | such as asking that all changes be marked or described. 267 | Although not required by our licenses, you are encouraged to 268 | respect those requests where reasonable. More_considerations 269 | for the public: 270 | wiki.creativecommons.org/Considerations_for_licensees 271 | 272 | ======================================================================= 273 | 274 | Creative Commons Attribution 4.0 International Public License 275 | 276 | By exercising the Licensed Rights (defined below), You accept and agree 277 | to be bound by the terms and conditions of this Creative Commons 278 | Attribution 4.0 International Public License ("Public License"). To the 279 | extent this Public License may be interpreted as a contract, You are 280 | granted the Licensed Rights in consideration of Your acceptance of 281 | these terms and conditions, and the Licensor grants You such rights in 282 | consideration of benefits the Licensor receives from making the 283 | Licensed Material available under these terms and conditions. 284 | 285 | 286 | Section 1 -- Definitions. 287 | 288 | a. Adapted Material means material subject to Copyright and Similar 289 | Rights that is derived from or based upon the Licensed Material 290 | and in which the Licensed Material is translated, altered, 291 | arranged, transformed, or otherwise modified in a manner requiring 292 | permission under the Copyright and Similar Rights held by the 293 | Licensor. For purposes of this Public License, where the Licensed 294 | Material is a musical work, performance, or sound recording, 295 | Adapted Material is always produced where the Licensed Material is 296 | synched in timed relation with a moving image. 297 | 298 | b. Adapter's License means the license You apply to Your Copyright 299 | and Similar Rights in Your contributions to Adapted Material in 300 | accordance with the terms and conditions of this Public License. 301 | 302 | c. Copyright and Similar Rights means copyright and/or similar rights 303 | closely related to copyright including, without limitation, 304 | performance, broadcast, sound recording, and Sui Generis Database 305 | Rights, without regard to how the rights are labeled or 306 | categorized. For purposes of this Public License, the rights 307 | specified in Section 2(b)(1)-(2) are not Copyright and Similar 308 | Rights. 309 | 310 | d. Effective Technological Measures means those measures that, in the 311 | absence of proper authority, may not be circumvented under laws 312 | fulfilling obligations under Article 11 of the WIPO Copyright 313 | Treaty adopted on December 20, 1996, and/or similar international 314 | agreements. 315 | 316 | e. Exceptions and Limitations means fair use, fair dealing, and/or 317 | any other exception or limitation to Copyright and Similar Rights 318 | that applies to Your use of the Licensed Material. 319 | 320 | f. Licensed Material means the artistic or literary work, database, 321 | or other material to which the Licensor applied this Public 322 | License. 323 | 324 | g. Licensed Rights means the rights granted to You subject to the 325 | terms and conditions of this Public License, which are limited to 326 | all Copyright and Similar Rights that apply to Your use of the 327 | Licensed Material and that the Licensor has authority to license. 328 | 329 | h. Licensor means the individual(s) or entity(ies) granting rights 330 | under this Public License. 331 | 332 | i. Share means to provide material to the public by any means or 333 | process that requires permission under the Licensed Rights, such 334 | as reproduction, public display, public performance, distribution, 335 | dissemination, communication, or importation, and to make material 336 | available to the public including in ways that members of the 337 | public may access the material from a place and at a time 338 | individually chosen by them. 339 | 340 | j. Sui Generis Database Rights means rights other than copyright 341 | resulting from Directive 96/9/EC of the European Parliament and of 342 | the Council of 11 March 1996 on the legal protection of databases, 343 | as amended and/or succeeded, as well as other essentially 344 | equivalent rights anywhere in the world. 345 | 346 | k. You means the individual or entity exercising the Licensed Rights 347 | under this Public License. Your has a corresponding meaning. 348 | 349 | 350 | Section 2 -- Scope. 351 | 352 | a. License grant. 353 | 354 | 1. Subject to the terms and conditions of this Public License, 355 | the Licensor hereby grants You a worldwide, royalty-free, 356 | non-sublicensable, non-exclusive, irrevocable license to 357 | exercise the Licensed Rights in the Licensed Material to: 358 | 359 | a. reproduce and Share the Licensed Material, in whole or 360 | in part; and 361 | 362 | b. produce, reproduce, and Share Adapted Material. 363 | 364 | 2. Exceptions and Limitations. For the avoidance of doubt, where 365 | Exceptions and Limitations apply to Your use, this Public 366 | License does not apply, and You do not need to comply with 367 | its terms and conditions. 368 | 369 | 3. Term. The term of this Public License is specified in Section 370 | 6(a). 371 | 372 | 4. Media and formats; technical modifications allowed. The 373 | Licensor authorizes You to exercise the Licensed Rights in 374 | all media and formats whether now known or hereafter created, 375 | and to make technical modifications necessary to do so. The 376 | Licensor waives and/or agrees not to assert any right or 377 | authority to forbid You from making technical modifications 378 | necessary to exercise the Licensed Rights, including 379 | technical modifications necessary to circumvent Effective 380 | Technological Measures. For purposes of this Public License, 381 | simply making modifications authorized by this Section 2(a) 382 | (4) never produces Adapted Material. 383 | 384 | 5. Downstream recipients. 385 | 386 | a. Offer from the Licensor -- Licensed Material. Every 387 | recipient of the Licensed Material automatically 388 | receives an offer from the Licensor to exercise the 389 | Licensed Rights under the terms and conditions of this 390 | Public License. 391 | 392 | b. No downstream restrictions. You may not offer or impose 393 | any additional or different terms or conditions on, or 394 | apply any Effective Technological Measures to, the 395 | Licensed Material if doing so restricts exercise of the 396 | Licensed Rights by any recipient of the Licensed 397 | Material. 398 | 399 | 6. No endorsement. Nothing in this Public License constitutes or 400 | may be construed as permission to assert or imply that You 401 | are, or that Your use of the Licensed Material is, connected 402 | with, or sponsored, endorsed, or granted official status by, 403 | the Licensor or others designated to receive attribution as 404 | provided in Section 3(a)(1)(A)(i). 405 | 406 | b. Other rights. 407 | 408 | 1. Moral rights, such as the right of integrity, are not 409 | licensed under this Public License, nor are publicity, 410 | privacy, and/or other similar personality rights; however, to 411 | the extent possible, the Licensor waives and/or agrees not to 412 | assert any such rights held by the Licensor to the limited 413 | extent necessary to allow You to exercise the Licensed 414 | Rights, but not otherwise. 415 | 416 | 2. Patent and trademark rights are not licensed under this 417 | Public License. 418 | 419 | 3. To the extent possible, the Licensor waives any right to 420 | collect royalties from You for the exercise of the Licensed 421 | Rights, whether directly or through a collecting society 422 | under any voluntary or waivable statutory or compulsory 423 | licensing scheme. In all other cases the Licensor expressly 424 | reserves any right to collect such royalties. 425 | 426 | 427 | Section 3 -- License Conditions. 428 | 429 | Your exercise of the Licensed Rights is expressly made subject to the 430 | following conditions. 431 | 432 | a. Attribution. 433 | 434 | 1. If You Share the Licensed Material (including in modified 435 | form), You must: 436 | 437 | a. retain the following if it is supplied by the Licensor 438 | with the Licensed Material: 439 | 440 | i. identification of the creator(s) of the Licensed 441 | Material and any others designated to receive 442 | attribution, in any reasonable manner requested by 443 | the Licensor (including by pseudonym if 444 | designated); 445 | 446 | ii. a copyright notice; 447 | 448 | iii. a notice that refers to this Public License; 449 | 450 | iv. a notice that refers to the disclaimer of 451 | warranties; 452 | 453 | v. a URI or hyperlink to the Licensed Material to the 454 | extent reasonably practicable; 455 | 456 | b. indicate if You modified the Licensed Material and 457 | retain an indication of any previous modifications; and 458 | 459 | c. indicate the Licensed Material is licensed under this 460 | Public License, and include the text of, or the URI or 461 | hyperlink to, this Public License. 462 | 463 | 2. You may satisfy the conditions in Section 3(a)(1) in any 464 | reasonable manner based on the medium, means, and context in 465 | which You Share the Licensed Material. For example, it may be 466 | reasonable to satisfy the conditions by providing a URI or 467 | hyperlink to a resource that includes the required 468 | information. 469 | 470 | 3. If requested by the Licensor, You must remove any of the 471 | information required by Section 3(a)(1)(A) to the extent 472 | reasonably practicable. 473 | 474 | 4. If You Share Adapted Material You produce, the Adapter's 475 | License You apply must not prevent recipients of the Adapted 476 | Material from complying with this Public License. 477 | 478 | 479 | Section 4 -- Sui Generis Database Rights. 480 | 481 | Where the Licensed Rights include Sui Generis Database Rights that 482 | apply to Your use of the Licensed Material: 483 | 484 | a. for the avoidance of doubt, Section 2(a)(1) grants You the right 485 | to extract, reuse, reproduce, and Share all or a substantial 486 | portion of the contents of the database; 487 | 488 | b. if You include all or a substantial portion of the database 489 | contents in a database in which You have Sui Generis Database 490 | Rights, then the database in which You have Sui Generis Database 491 | Rights (but not its individual contents) is Adapted Material; and 492 | 493 | c. You must comply with the conditions in Section 3(a) if You Share 494 | all or a substantial portion of the contents of the database. 495 | 496 | For the avoidance of doubt, this Section 4 supplements and does not 497 | replace Your obligations under this Public License where the Licensed 498 | Rights include other Copyright and Similar Rights. 499 | 500 | 501 | Section 5 -- Disclaimer of Warranties and Limitation of Liability. 502 | 503 | a. UNLESS OTHERWISE SEPARATELY UNDERTAKEN BY THE LICENSOR, TO THE 504 | EXTENT POSSIBLE, THE LICENSOR OFFERS THE LICENSED MATERIAL AS-IS 505 | AND AS-AVAILABLE, AND MAKES NO REPRESENTATIONS OR WARRANTIES OF 506 | ANY KIND CONCERNING THE LICENSED MATERIAL, WHETHER EXPRESS, 507 | IMPLIED, STATUTORY, OR OTHER. THIS INCLUDES, WITHOUT LIMITATION, 508 | WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR 509 | PURPOSE, NON-INFRINGEMENT, ABSENCE OF LATENT OR OTHER DEFECTS, 510 | ACCURACY, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT 511 | KNOWN OR DISCOVERABLE. WHERE DISCLAIMERS OF WARRANTIES ARE NOT 512 | ALLOWED IN FULL OR IN PART, THIS DISCLAIMER MAY NOT APPLY TO YOU. 513 | 514 | b. TO THE EXTENT POSSIBLE, IN NO EVENT WILL THE LICENSOR BE LIABLE 515 | TO YOU ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION, 516 | NEGLIGENCE) OR OTHERWISE FOR ANY DIRECT, SPECIAL, INDIRECT, 517 | INCIDENTAL, CONSEQUENTIAL, PUNITIVE, EXEMPLARY, OR OTHER LOSSES, 518 | COSTS, EXPENSES, OR DAMAGES ARISING OUT OF THIS PUBLIC LICENSE OR 519 | USE OF THE LICENSED MATERIAL, EVEN IF THE LICENSOR HAS BEEN 520 | ADVISED OF THE POSSIBILITY OF SUCH LOSSES, COSTS, EXPENSES, OR 521 | DAMAGES. WHERE A LIMITATION OF LIABILITY IS NOT ALLOWED IN FULL OR 522 | IN PART, THIS LIMITATION MAY NOT APPLY TO YOU. 523 | 524 | c. The disclaimer of warranties and limitation of liability provided 525 | above shall be interpreted in a manner that, to the extent 526 | possible, most closely approximates an absolute disclaimer and 527 | waiver of all liability. 528 | 529 | 530 | Section 6 -- Term and Termination. 531 | 532 | a. This Public License applies for the term of the Copyright and 533 | Similar Rights licensed here. However, if You fail to comply with 534 | this Public License, then Your rights under this Public License 535 | terminate automatically. 536 | 537 | b. Where Your right to use the Licensed Material has terminated under 538 | Section 6(a), it reinstates: 539 | 540 | 1. automatically as of the date the violation is cured, provided 541 | it is cured within 30 days of Your discovery of the 542 | violation; or 543 | 544 | 2. upon express reinstatement by the Licensor. 545 | 546 | For the avoidance of doubt, this Section 6(b) does not affect any 547 | right the Licensor may have to seek remedies for Your violations 548 | of this Public License. 549 | 550 | c. For the avoidance of doubt, the Licensor may also offer the 551 | Licensed Material under separate terms or conditions or stop 552 | distributing the Licensed Material at any time; however, doing so 553 | will not terminate this Public License. 554 | 555 | d. Sections 1, 5, 6, 7, and 8 survive termination of this Public 556 | License. 557 | 558 | 559 | Section 7 -- Other Terms and Conditions. 560 | 561 | a. The Licensor shall not be bound by any additional or different 562 | terms or conditions communicated by You unless expressly agreed. 563 | 564 | b. Any arrangements, understandings, or agreements regarding the 565 | Licensed Material not stated herein are separate from and 566 | independent of the terms and conditions of this Public License. 567 | 568 | 569 | Section 8 -- Interpretation. 570 | 571 | a. For the avoidance of doubt, this Public License does not, and 572 | shall not be interpreted to, reduce, limit, restrict, or impose 573 | conditions on any use of the Licensed Material that could lawfully 574 | be made without permission under this Public License. 575 | 576 | b. To the extent possible, if any provision of this Public License is 577 | deemed unenforceable, it shall be automatically reformed to the 578 | minimum extent necessary to make it enforceable. If the provision 579 | cannot be reformed, it shall be severed from this Public License 580 | without affecting the enforceability of the remaining terms and 581 | conditions. 582 | 583 | c. No term or condition of this Public License will be waived and no 584 | failure to comply consented to unless expressly agreed to by the 585 | Licensor. 586 | 587 | d. Nothing in this Public License constitutes or may be interpreted 588 | as a limitation upon, or waiver of, any privileges and immunities 589 | that apply to the Licensor or You, including from the legal 590 | processes of any jurisdiction or authority. 591 | 592 | 593 | ======================================================================= 594 | 595 | Creative Commons is not a party to its public 596 | licenses. Notwithstanding, Creative Commons may elect to apply one of 597 | its public licenses to material it publishes and in those instances 598 | will be considered the “Licensor.” The text of the Creative Commons 599 | public licenses is dedicated to the public domain under the CC0 Public 600 | Domain Dedication. Except for the limited purpose of indicating that 601 | material is shared under a Creative Commons public license or as 602 | otherwise permitted by the Creative Commons policies published at 603 | creativecommons.org/policies, Creative Commons does not authorize the 604 | use of the trademark "Creative Commons" or any other trademark or logo 605 | of Creative Commons without its prior written consent including, 606 | without limitation, in connection with any unauthorized modifications 607 | to any of its public licenses or any other arrangements, 608 | understandings, or agreements concerning use of licensed material. For 609 | the avoidance of doubt, this paragraph does not form part of the 610 | public licenses. 611 | 612 | Creative Commons may be contacted at creativecommons.org. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Application Architecture - The UI Layer - Guess It! 2 | This is the toy app for lesson 5 of the [Android App Development in Kotlin course on Udacity](https://www.udacity.com/course/developing-android-apps-with-kotlin--ud9012). 3 | 4 | ## Guess It! 5 | 6 | Guess It is a word guessing app you can play with one or more friends. To play, hold the device in landscape, facing away from you with your thumbs on the **Skip** and **Got It** buttons. Your friends can then give you clues to help you guess the word. 7 | 8 | If you get the word right, press **Got It**. If you're stuck, press **Skip**. The game runs for a minute and then shows you your score. 9 | 10 | 11 | ## Screenshots 12 | 13 | ![Screenshot 0](screenshots/screen0.png) ![Screenshot 1](screenshots/screen1.png) ![Screenshot 2](screenshots/screen2.png) 14 | 15 | ## How to use this repo while taking the course 16 | 17 | Each code repository in this class has a chain of commits that looks like this: 18 | 19 | ![listofcommits](https://d17h27t6h515a5.cloudfront.net/topher/2017/March/58befe2e_listofcommits/listofcommits.png) 20 | 21 | These commits show every step you'll take to create the app. Each commit contains instructions for completing the step. 22 | 23 | Each commit also has a **branch** associated with it of the same name as the commit message, as seen below: 24 | 25 | ![branches](https://d17h27t6h515a5.cloudfront.net/topher/2017/April/590390fe_branches-ud855/branches-ud855.png 26 | ) 27 | Access all branches from this tab. 28 | 29 | ![listofbranches](https://d17h27t6h515a5.cloudfront.net/topher/2017/March/58befe76_listofbranches/listofbranches.png 30 | ) 31 | 32 | 33 | ![branchesdropdown](https://d17h27t6h515a5.cloudfront.net/topher/2017/April/590391a3_branches-dropdown-ud855/branches-dropdown-ud855.png 34 | ) 35 | 36 | The branches are also accessible from the drop-down in the "Code" tab. 37 | 38 | 39 | ## Working with the Course Code 40 | 41 | Here are the basic steps for working with and completing exercises in the repo. 42 | 43 | The basic steps are: 44 | 45 | 1. Clone the repo. 46 | 2. `checkout` the branch corresponding to the step you want to attempt. 47 | 3. Find and complete the TODOs. 48 | 4. Optionally commit your code changes. 49 | 5. Compare your code with the solution. 50 | 6. Repeat steps 2-5 until you've gone trough all the steps to complete the toy app. 51 | 52 | 53 | **Step 1: Clone the repo** 54 | 55 | As you go through the course, you'll be instructed to clone the different exercise repositories, so you don't need to set these up now. You can clone a repository from GitHub in a folder of your choice with the command: 56 | 57 | ```bash 58 | git clone https://github.com/udacity/REPOSITORY_NAME.git 59 | ``` 60 | 61 | **Step 2: Check out the step branch** 62 | 63 | As you go through different steps in the code, you'll be told which step you're on, as well as given a link to the corresponding branch. 64 | 65 | Check out the branch associated with that step. The command to check out a branch is: 66 | 67 | ```bash 68 | git checkout BRANCH_NAME 69 | ``` 70 | 71 | **Step 3: Find and complete the TODOs** 72 | 73 | Once you've checked out the branch, you'll have the code in the exact state you need. You'll even have TODOs, which are special comments that tell you all the steps you need to complete the exercise. You can navigate to all the TODOs using Android Studio's TODO tool. To open the TODO tool, click the button at the bottom of the screen that says TODO. This will display a list of all comments with TODO in the project. 74 | 75 | We've numbered the TODO steps so you can do them in order: 76 | ![todos](https://d17h27t6h515a5.cloudfront.net/topher/2017/March/58bf00e7_todos/todos.png 77 | ) 78 | 79 | **Step 4: Commit your code changes** 80 | 81 | After you've completed the TODOs, you can optionally commit your changes. This will allow you to see the code you wrote whenever you return to the branch. The following git code will add and save **all** your changes. 82 | 83 | ```bash 84 | git add . 85 | git commit -m "Your commit message" 86 | ``` 87 | 88 | **Step 5: Compare with the solution** 89 | 90 | Most exercises will have a list of steps for you to check off in the classroom. Once you've checked these off, you'll see a pop up window with a link to the solution code. Note the **Diff** link after the Solution link: 91 | 92 | ![solutionwindow](https://d17h27t6h515a5.cloudfront.net/topher/2017/March/58bf00f9_solutionwindow/solutionwindow.png 93 | ) 94 | 95 | The **Diff** link will take you to a GitHub diff as seen below: 96 | ![diff](https://d17h27t6h515a5.cloudfront.net/topher/2017/March/58bf0108_diffsceenshot/diffsceenshot.png 97 | ) 98 | 99 | All of the code that was added in the solution is in green, and the removed code (which will usually be the TODO comments) is in red. 100 | 101 | You can also diff your local copy of the code with the corresponding branch as you are working on it: 102 | 103 | ```bash 104 | git diff BRANCH_NAME 105 | ``` 106 | 107 | ## Report Issues 108 | Notice any issues with a repository? Please file a GitHub issue in the repository. 109 | 110 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018, The Android Open Source Project 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 | plugins{ 17 | id 'com.android.application' 18 | id 'kotlin-android' 19 | id 'kotlin-kapt' 20 | id "org.jetbrains.kotlin.android" 21 | id "androidx.navigation.safeargs" 22 | } 23 | 24 | android { 25 | compileSdkVersion 31 26 | defaultConfig { 27 | applicationId "com.example.android.guesstheword" 28 | minSdkVersion 19 29 | targetSdkVersion 31 30 | versionCode 1 31 | versionName "1.0" 32 | testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner' 33 | } 34 | buildTypes { 35 | release { 36 | minifyEnabled false 37 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 38 | } 39 | } 40 | 41 | buildFeatures { 42 | dataBinding true 43 | } 44 | 45 | compileOptions { 46 | sourceCompatibility = JavaVersion.VERSION_1_8 47 | targetCompatibility = JavaVersion.VERSION_1_8 48 | } 49 | kotlinOptions { 50 | jvmTarget = JavaVersion.VERSION_1_8 51 | } 52 | } 53 | 54 | dependencies { 55 | implementation fileTree(dir: 'libs', include: ['*.jar']) 56 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" 57 | implementation 'androidx.appcompat:appcompat:1.4.1' 58 | implementation 'androidx.constraintlayout:constraintlayout:2.1.4' 59 | implementation 'androidx.legacy:legacy-support-v4:1.0.0' 60 | testImplementation 'junit:junit:4.13.2' 61 | androidTestImplementation 'androidx.test:runner:1.4.0' 62 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' 63 | 64 | // KTX 65 | implementation 'androidx.core:core-ktx:1.4.0-alpha01' 66 | 67 | // Navigation 68 | implementation "androidx.navigation:navigation-fragment-ktx:2.3.4" 69 | implementation "androidx.navigation:navigation-ui-ktx:2.3.4" 70 | 71 | // Lifecycles 72 | implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0' 73 | } 74 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/example/android/guesstheword/ExampleInstrumentedTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018, The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.example.android.guesstheword 18 | 19 | import androidx.test.InstrumentationRegistry 20 | import androidx.test.runner.AndroidJUnit4 21 | import org.junit.Assert.assertEquals 22 | import org.junit.Test 23 | import org.junit.runner.RunWith 24 | 25 | /** 26 | * Instrumented test, which will execute on an Android device. 27 | * 28 | * See [testing documentation](http://d.android.com/tools/testing). 29 | */ 30 | @RunWith(AndroidJUnit4::class) 31 | class ExampleInstrumentedTest { 32 | 33 | @Test 34 | fun useAppContext() { 35 | // Context of the app under test. 36 | val appContext = InstrumentationRegistry.getTargetContext() 37 | assertEquals("com.example.android.guesstheword", appContext.packageName) 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 20 | 21 | 22 | 23 | 24 | 32 | 33 | 34 | 35 | 36 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /app/src/main/ic_guess_it-web.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/udacity/andfun-kotlin-guess-it/667dd8bf52b95786d65626387d98461158663786/app/src/main/ic_guess_it-web.png -------------------------------------------------------------------------------- /app/src/main/java/com/example/android/guesstheword/MainActivity.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018, The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.example.android.guesstheword 18 | 19 | import android.os.Bundle 20 | import androidx.appcompat.app.AppCompatActivity 21 | 22 | /** 23 | * Creates an Activity that hosts all of the fragments in the app 24 | */ 25 | class MainActivity : AppCompatActivity() { 26 | 27 | override fun onCreate(savedInstanceState: Bundle?) { 28 | super.onCreate(savedInstanceState) 29 | setContentView(R.layout.main_activity) 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/android/guesstheword/screens/game/GameFragment.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018, The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.example.android.guesstheword.screens.game 18 | 19 | import android.os.Build 20 | import android.os.Bundle 21 | import android.os.VibrationEffect 22 | import android.os.Vibrator 23 | import android.view.LayoutInflater 24 | import android.view.View 25 | import android.view.ViewGroup 26 | import androidx.core.content.getSystemService 27 | import androidx.databinding.DataBindingUtil 28 | import androidx.fragment.app.Fragment 29 | import androidx.lifecycle.Observer 30 | import androidx.lifecycle.ViewModelProvider 31 | import androidx.navigation.fragment.NavHostFragment.findNavController 32 | import com.example.android.guesstheword.R 33 | import com.example.android.guesstheword.databinding.GameFragmentBinding 34 | 35 | /** 36 | * Fragment where the game is played 37 | */ 38 | class GameFragment : Fragment() { 39 | 40 | private lateinit var viewModel: GameViewModel 41 | 42 | private lateinit var binding: GameFragmentBinding 43 | 44 | override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, 45 | savedInstanceState: Bundle?): View? { 46 | 47 | // Inflate view and obtain an instance of the binding class 48 | binding = DataBindingUtil.inflate( 49 | inflater, 50 | R.layout.game_fragment, 51 | container, 52 | false 53 | ) 54 | 55 | // Get the viewmodel 56 | viewModel = ViewModelProvider(this).get(GameViewModel::class.java) 57 | 58 | // Set the viewmodel for databinding - this allows the bound layout access to all of the 59 | // data in the VieWModel 60 | binding.gameViewModel = viewModel 61 | 62 | // Specify the current activity as the lifecycle owner of the binding. This is used so that 63 | // the binding can observe LiveData updates 64 | binding.setLifecycleOwner(this) 65 | 66 | // Sets up event listening to navigate the player when the game is finished 67 | viewModel.eventGameFinish.observe(viewLifecycleOwner, Observer { isFinished -> 68 | if (isFinished) { 69 | val currentScore = viewModel.score.value ?: 0 70 | val action = GameFragmentDirections.actionGameToScore(currentScore) 71 | findNavController(this).navigate(action) 72 | viewModel.onGameFinishComplete() 73 | } 74 | }) 75 | 76 | // Buzzes when triggered with different buzz events 77 | viewModel.eventBuzz.observe(viewLifecycleOwner, Observer { buzzType -> 78 | if (buzzType != GameViewModel.BuzzType.NO_BUZZ) { 79 | buzz(buzzType.pattern) 80 | viewModel.onBuzzComplete() 81 | } 82 | }) 83 | 84 | return binding.root 85 | 86 | } 87 | 88 | /** 89 | * Given a pattern, this method makes sure the device buzzes 90 | */ 91 | private fun buzz(pattern: LongArray) { 92 | val buzzer = activity?.getSystemService() 93 | buzzer?.let { 94 | // Vibrate for 500 milliseconds 95 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { 96 | buzzer.vibrate(VibrationEffect.createWaveform(pattern, -1)) 97 | } else { 98 | //deprecated in API 26 99 | buzzer.vibrate(pattern, -1) 100 | } 101 | } 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/android/guesstheword/screens/game/GameViewModel.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018, The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.example.android.guesstheword.screens.game 18 | 19 | import android.os.CountDownTimer 20 | import android.text.format.DateUtils 21 | import androidx.lifecycle.LiveData 22 | import androidx.lifecycle.MutableLiveData 23 | import androidx.lifecycle.Transformations 24 | import androidx.lifecycle.ViewModel 25 | 26 | private val CORRECT_BUZZ_PATTERN = longArrayOf(100, 100, 100, 100, 100, 100) 27 | private val PANIC_BUZZ_PATTERN = longArrayOf(0, 200) 28 | private val GAME_OVER_BUZZ_PATTERN = longArrayOf(0, 2000) 29 | private val NO_BUZZ_PATTERN = longArrayOf(0) 30 | 31 | /** 32 | * ViewModel containing all the logic needed to run the game 33 | */ 34 | class GameViewModel : ViewModel() { 35 | 36 | // These are the three different types of buzzing in the game. Buzz pattern is the number of 37 | // milliseconds each interval of buzzing and non-buzzing takes. 38 | enum class BuzzType(val pattern: LongArray) { 39 | CORRECT(CORRECT_BUZZ_PATTERN), 40 | GAME_OVER(GAME_OVER_BUZZ_PATTERN), 41 | COUNTDOWN_PANIC(PANIC_BUZZ_PATTERN), 42 | NO_BUZZ(NO_BUZZ_PATTERN) 43 | } 44 | 45 | companion object { 46 | // These represent different important times in the game, such as game length. 47 | 48 | // This is when the game is over 49 | private const val DONE = 0L 50 | 51 | // This is the time when the phone will start buzzing each second 52 | private const val COUNTDOWN_PANIC_SECONDS = 10L 53 | 54 | // This is the number of milliseconds in a second 55 | private const val ONE_SECOND = 1000L 56 | 57 | // This is the total time of the game 58 | private const val COUNTDOWN_TIME = 60000L 59 | 60 | } 61 | 62 | private val timer: CountDownTimer 63 | 64 | private val _currentTime = MutableLiveData() 65 | val currentTime: LiveData 66 | get() = _currentTime 67 | 68 | // The String version of the current time 69 | val currentTimeString = Transformations.map(currentTime) { time -> 70 | DateUtils.formatElapsedTime(time) 71 | } 72 | 73 | // The current word 74 | private val _word = MutableLiveData() 75 | val word: LiveData 76 | get() = _word 77 | 78 | 79 | // The current score 80 | private val _score = MutableLiveData() 81 | val score: LiveData 82 | get() = _score 83 | 84 | 85 | // The list of words - the front of the list is the next word to guess 86 | private lateinit var wordList: MutableList 87 | 88 | // Event which triggers the end of the game 89 | private val _eventGameFinish = MutableLiveData() 90 | val eventGameFinish: LiveData 91 | get() = _eventGameFinish 92 | 93 | // Event that triggers the phone to buzz using different patterns, determined by BuzzType 94 | private val _eventBuzz = MutableLiveData() 95 | val eventBuzz: LiveData 96 | get() = _eventBuzz 97 | 98 | init { 99 | resetList() 100 | nextWord() 101 | _score.value = 0 102 | 103 | // Creates a timer which triggers the end of the game when it finishes 104 | timer = object : CountDownTimer(COUNTDOWN_TIME, ONE_SECOND) { 105 | 106 | override fun onTick(millisUntilFinished: Long) { 107 | _currentTime.value = (millisUntilFinished / ONE_SECOND) 108 | if (millisUntilFinished / ONE_SECOND <= COUNTDOWN_PANIC_SECONDS) { 109 | _eventBuzz.value = BuzzType.COUNTDOWN_PANIC 110 | } 111 | } 112 | 113 | override fun onFinish() { 114 | _currentTime.value = DONE 115 | _eventBuzz.value = BuzzType.GAME_OVER 116 | _eventGameFinish.value = true 117 | } 118 | } 119 | 120 | timer.start() 121 | } 122 | 123 | /** 124 | * Resets the list of words and randomizes the order 125 | */ 126 | private fun resetList() { 127 | wordList = mutableListOf( 128 | "queen", 129 | "hospital", 130 | "basketball", 131 | "cat", 132 | "change", 133 | "snail", 134 | "soup", 135 | "calendar", 136 | "sad", 137 | "desk", 138 | "guitar", 139 | "home", 140 | "railway", 141 | "zebra", 142 | "jelly", 143 | "car", 144 | "crow", 145 | "trade", 146 | "bag", 147 | "roll", 148 | "bubble" 149 | ) 150 | wordList.shuffle() 151 | } 152 | 153 | /** 154 | * Moves to the next word in the list 155 | */ 156 | private fun nextWord() { 157 | //Select and remove a word from the list 158 | if (wordList.isEmpty()) { 159 | resetList() 160 | } 161 | _word.value = wordList.removeAt(0) 162 | } 163 | 164 | /** Methods for buttons presses **/ 165 | 166 | fun onSkip() { 167 | _score.value = (_score.value)?.minus(1) 168 | nextWord() 169 | } 170 | 171 | fun onCorrect() { 172 | _score.value = (_score.value)?.plus(1) 173 | _eventBuzz.value = BuzzType.CORRECT 174 | nextWord() 175 | } 176 | 177 | /** Methods for completed events **/ 178 | 179 | fun onGameFinishComplete() { 180 | _eventGameFinish.value = false 181 | } 182 | 183 | fun onBuzzComplete() { 184 | _eventBuzz.value = BuzzType.NO_BUZZ 185 | } 186 | 187 | override fun onCleared() { 188 | super.onCleared() 189 | timer.cancel() 190 | } 191 | } 192 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/android/guesstheword/screens/score/ScoreFragment.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018, The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.example.android.guesstheword.screens.score 18 | 19 | import android.os.Bundle 20 | import android.view.LayoutInflater 21 | import android.view.View 22 | import android.view.ViewGroup 23 | import androidx.databinding.DataBindingUtil 24 | import androidx.fragment.app.Fragment 25 | import androidx.lifecycle.Observer 26 | import androidx.lifecycle.ViewModelProvider 27 | import androidx.navigation.fragment.findNavController 28 | import androidx.navigation.fragment.navArgs 29 | import com.example.android.guesstheword.R 30 | import com.example.android.guesstheword.databinding.ScoreFragmentBinding 31 | 32 | /** 33 | * Fragment where the final score is shown, after the game is over 34 | */ 35 | class ScoreFragment : Fragment() { 36 | 37 | private lateinit var viewModel: ScoreViewModel 38 | private lateinit var viewModelFactory: ScoreViewModelFactory 39 | 40 | override fun onCreateView( 41 | inflater: LayoutInflater, 42 | container: ViewGroup?, 43 | savedInstanceState: Bundle? 44 | ): View? { 45 | 46 | // Inflate view and obtain an instance of the binding class. 47 | val binding: ScoreFragmentBinding = DataBindingUtil.inflate( 48 | inflater, 49 | R.layout.score_fragment, 50 | container, 51 | false 52 | ) 53 | 54 | val scoreFragmentArgs by navArgs() 55 | 56 | viewModelFactory = ScoreViewModelFactory(scoreFragmentArgs.score) 57 | viewModel = ViewModelProvider(this, viewModelFactory) 58 | .get(ScoreViewModel::class.java) 59 | 60 | binding.scoreViewModel = viewModel 61 | 62 | // Specify the current activity as the lifecycle owner of the binding. This is used so that 63 | // the binding can observe LiveData updates 64 | binding.setLifecycleOwner(this) 65 | 66 | // Navigates back to title when button is pressed 67 | viewModel.eventPlayAgain.observe(this, Observer { playAgain -> 68 | if (playAgain) { 69 | findNavController().navigate(ScoreFragmentDirections.actionRestart()) 70 | viewModel.onPlayAgainComplete() 71 | } 72 | }) 73 | 74 | return binding.root 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/android/guesstheword/screens/score/ScoreViewModel.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018, The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.example.android.guesstheword.screens.score 18 | 19 | import androidx.lifecycle.LiveData 20 | import androidx.lifecycle.MutableLiveData 21 | import androidx.lifecycle.ViewModel 22 | 23 | /** 24 | * ViewModel for the final screen showing the score 25 | */ 26 | class ScoreViewModel(finalScore: Int) : ViewModel() { 27 | 28 | private val _eventPlayAgain = MutableLiveData() 29 | val eventPlayAgain: LiveData 30 | get() = _eventPlayAgain 31 | 32 | private val _score = MutableLiveData() 33 | val score: LiveData 34 | get() = _score 35 | 36 | init { 37 | _score.value = finalScore 38 | } 39 | 40 | fun onPlayAgain() { 41 | _eventPlayAgain.value = true 42 | } 43 | 44 | fun onPlayAgainComplete() { 45 | _eventPlayAgain.value = false 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/android/guesstheword/screens/score/ScoreViewModelFactory.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018, The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.example.android.guesstheword.screens.score 18 | 19 | 20 | import androidx.lifecycle.ViewModel 21 | import androidx.lifecycle.ViewModelProvider 22 | 23 | class ScoreViewModelFactory(private val finalScore: Int) : ViewModelProvider.Factory { 24 | override fun create(modelClass: Class): T { 25 | if (modelClass.isAssignableFrom(ScoreViewModel::class.java)) { 26 | return ScoreViewModel(finalScore) as T 27 | } 28 | throw IllegalArgumentException("Unknown ViewModel class") 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/android/guesstheword/screens/title/TitleFragment.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018, The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.example.android.guesstheword.screens.title 18 | 19 | import android.os.Bundle 20 | import android.view.LayoutInflater 21 | import android.view.View 22 | import android.view.ViewGroup 23 | import androidx.databinding.DataBindingUtil 24 | import androidx.fragment.app.Fragment 25 | import androidx.navigation.fragment.findNavController 26 | import com.example.android.guesstheword.R 27 | import com.example.android.guesstheword.databinding.TitleFragmentBinding 28 | 29 | /** 30 | * Fragment for the starting or title screen of the app 31 | */ 32 | class TitleFragment : Fragment() { 33 | 34 | override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, 35 | savedInstanceState: Bundle?): View { 36 | // Inflate the layout for this fragment 37 | val binding: TitleFragmentBinding = DataBindingUtil.inflate( 38 | inflater, R.layout.title_fragment, container, false) 39 | 40 | binding.playGameButton.setOnClickListener { 41 | findNavController().navigate(TitleFragmentDirections.actionTitleToGame()) 42 | } 43 | return binding.root 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /app/src/main/res/anim/slide_in_right.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | 25 | 26 | -------------------------------------------------------------------------------- /app/src/main/res/anim/slide_out_left.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | 25 | 26 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 12 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 12 | 15 | 18 | 25 | 32 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /app/src/main/res/layout/game_fragment.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 20 | 21 | 22 | 23 | 26 | 27 | 28 | 33 | 34 | 50 | 51 | 69 | 70 | 86 | 87 | 102 | 103 |