8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/wordstack/app/src/test/java/com/google/engedu/wordstack/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | /* Copyright 2016 Google Inc.
2 | *
3 | * Licensed under the Apache License, Version 2.0 (the "License");
4 | * you may not use this file except in compliance with the License.
5 | * You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software
10 | * distributed under the License is distributed on an "AS IS" BASIS,
11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | * See the License for the specific language governing permissions and
13 | * limitations under the License.
14 | */
15 |
16 | package com.google.engedu.wordstack;
17 |
18 | import org.junit.Test;
19 |
20 | import static org.junit.Assert.*;
21 |
22 | /**
23 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
24 | */
25 | public class ExampleUnitTest {
26 | @Test
27 | public void addition_isCorrect() throws Exception {
28 | assertEquals(4, 2 + 2);
29 | }
30 | }
--------------------------------------------------------------------------------
/wordstack/app/src/androidTest/java/com/google/engedu/wordstack/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | /* Copyright 2016 Google Inc.
2 | *
3 | * Licensed under the Apache License, Version 2.0 (the "License");
4 | * you may not use this file except in compliance with the License.
5 | * You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software
10 | * distributed under the License is distributed on an "AS IS" BASIS,
11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | * See the License for the specific language governing permissions and
13 | * limitations under the License.
14 | */
15 |
16 | package com.google.engedu.wordstack;
17 |
18 | import android.app.Application;
19 | import android.test.ApplicationTestCase;
20 |
21 | /**
22 | * Testing Fundamentals
23 | */
24 | public class ApplicationTest extends ApplicationTestCase {
25 | public ApplicationTest() {
26 | super(Application.class);
27 | }
28 | }
--------------------------------------------------------------------------------
/ghost_starter/app/src/main/java/com/google/engedu/ghost/FastDictionary.java:
--------------------------------------------------------------------------------
1 | package com.google.engedu.ghost;
2 |
3 | import java.io.BufferedReader;
4 | import java.io.IOException;
5 | import java.io.InputStream;
6 | import java.io.InputStreamReader;
7 |
8 |
9 | public class FastDictionary implements GhostDictionary {
10 |
11 | private TrieNode root;
12 |
13 | public FastDictionary(InputStream wordListStream) throws IOException {
14 | BufferedReader in = new BufferedReader(new InputStreamReader(wordListStream));
15 | root = new TrieNode();
16 | String line = null;
17 | while((line = in.readLine()) != null) {
18 | String word = line.trim();
19 | if (word.length() >= MIN_WORD_LENGTH)
20 | root.add(line.trim());
21 | }
22 | }
23 | @Override
24 | public boolean isWord(String word) {
25 | return root.isWord(word);
26 | }
27 |
28 | @Override
29 | public String getAnyWordStartingWith(String prefix) {
30 | return root.getAnyWordStartingWith(prefix);
31 | }
32 |
33 | @Override
34 | public String getGoodWordStartingWith(String prefix) {
35 | return root.getGoodWordStartingWith(prefix);
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/wordstack/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
19 |
20 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/anagrams_starter/app/src/main/res/layout/activity_anagrams.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
11 |
12 |
15 |
16 |
17 |
18 |
19 |
20 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Applied CS with Android Beginner Workshop
2 |
3 |
4 |
5 |
6 |
7 | ### Build Android games.
8 | ### Learn computer science.
9 | Applied CS is a free online course by Google designed to prepare you for your CS career through hands on coding experience.
10 |
11 | ##### PREREQUISITES
12 | - A university-level data structures and algorithms class
13 | - Basic familiarity with Java (syntax and built-in libraries)
14 | - No prior Android experience is needed.
15 |
16 | ##### REQUIRED MATERIALS
17 | - A computer (with Android Studio installed)
18 | - A Gmail account
19 | - You can run code on Android Studio Emulator or your own mobile device running Gingerbread or higher.
20 |
21 |
64 |
65 |
66 |
67 |
68 |
69 |
--------------------------------------------------------------------------------
/wordstack/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
26 |
27 |
32 |
33 |
38 |
39 |
49 |
50 |
60 |
61 |
62 |
70 |
71 |
81 |
82 |
--------------------------------------------------------------------------------
/ghost_starter/app/src/main/java/com/google/engedu/ghost/TrieNode.java:
--------------------------------------------------------------------------------
1 | package com.google.engedu.ghost;
2 |
3 | import java.util.HashMap;
4 | import java.util.Random;
5 | import java.util.Set;
6 |
7 |
8 | public class TrieNode {
9 | private HashMap children;
10 | private boolean isWord;
11 |
12 | public TrieNode() {
13 | children = new HashMap<>();
14 | isWord = false;
15 | }
16 |
17 | public void add(String s) {
18 |
19 | //get the root node in this object
20 | TrieNode currentNode = this;
21 | String key;
22 |
23 | //loop through all the chars in the word
24 | for (int i = 0; i < s.length(); i++) {
25 | //fetch individual characters in the word and check if that char exists as a key
26 | key = "" + s.charAt(i);
27 | if (!currentNode.children.containsKey(key)) {
28 | //if it doesn't exist then add it as a new key with empty node as child
29 | currentNode.children.put(key, new TrieNode());
30 | }
31 | //go to the next child in that node( with next char as key)
32 | currentNode = currentNode.children.get(key);
33 | }
34 |
35 | //make the boolean true after the whole word is added
36 | currentNode.isWord = true;
37 |
38 | }
39 |
40 |
41 | public boolean isWord(String s) {
42 |
43 | //get the root node of this object
44 | TrieNode currentNode = this;
45 | String key;
46 |
47 | //maintain a boolean to check for end of word
48 | boolean isFound = false;
49 |
50 | //loop through all the chars
51 | for (int i = 0; i < s.length(); i++) {
52 | key = "" + s.charAt(i);
53 | //if the current char is present as a key , then go to its child node and further so on
54 | if (currentNode.children.containsKey(key)) {
55 | currentNode = currentNode.children.get(key);
56 | }
57 | //if any char is not found , then break out of the loop
58 | else {
59 | isFound = false;
60 | return isFound;
61 | }
62 | }
63 |
64 | //if the loop was completed with all chars present in the node, then make the boolean true and return it.
65 | if (currentNode.isWord) {
66 | isFound = true;
67 | }
68 | return isFound;
69 |
70 | }
71 |
72 | public String getAnyWordStartingWith(String s) {
73 | //fetch the current node of that object
74 | TrieNode currentNode = this;
75 |
76 | //a set to fetch all the keys of the last node( char)
77 | Set keyList;
78 |
79 | String key;
80 | String word = "";
81 |
82 |
83 | if (!s.isEmpty()) {
84 |
85 | //loop through the characters of the prefix s
86 | for (int i = 0; i < s.length(); i++) {
87 |
88 | key = "" + s.charAt(i);
89 | //add the char to the word to be returned
90 | word += key;
91 | //check if that char is present as a key, if not then that word is not a valid word so break out and return
92 | if (currentNode.children.containsKey(key)) {
93 | currentNode = currentNode.children.get(key);
94 | } else {
95 | return null;
96 | }
97 |
98 | }
99 | }
100 |
101 | //after you have obtained the last node in the prefix word
102 | //then get all the next keys possible and select a random next key till that word is completed( i.e check for the boolean isWord)
103 | while (!currentNode.isWord) {
104 | keyList = currentNode.children.keySet();
105 | key = keyList.toArray()[new Random().nextInt(keyList.size())].toString();
106 | word += key;
107 | currentNode = currentNode.children.get(key);
108 | }
109 |
110 | return word;
111 |
112 | }
113 |
114 | public String getGoodWordStartingWith(String s) {
115 | return null;
116 | }
117 | }
118 |
--------------------------------------------------------------------------------
/Scarnesdice/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 |
--------------------------------------------------------------------------------
/wordstack/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 |
--------------------------------------------------------------------------------
/ghost_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 | # For Cygwin, ensure paths are in UNIX format before anything is touched.
46 | if $cygwin ; then
47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
48 | fi
49 |
50 | # Attempt to set APP_HOME
51 | # Resolve links: $0 may be a link
52 | PRG="$0"
53 | # Need this for relative symlinks.
54 | while [ -h "$PRG" ] ; do
55 | ls=`ls -ld "$PRG"`
56 | link=`expr "$ls" : '.*-> \(.*\)$'`
57 | if expr "$link" : '/.*' > /dev/null; then
58 | PRG="$link"
59 | else
60 | PRG=`dirname "$PRG"`"/$link"
61 | fi
62 | done
63 | SAVED="`pwd`"
64 | cd "`dirname \"$PRG\"`/" >&-
65 | APP_HOME="`pwd -P`"
66 | cd "$SAVED" >&-
67 |
68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
69 |
70 | # Determine the Java command to use to start the JVM.
71 | if [ -n "$JAVA_HOME" ] ; then
72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
73 | # IBM's JDK on AIX uses strange locations for the executables
74 | JAVACMD="$JAVA_HOME/jre/sh/java"
75 | else
76 | JAVACMD="$JAVA_HOME/bin/java"
77 | fi
78 | if [ ! -x "$JAVACMD" ] ; then
79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
80 |
81 | Please set the JAVA_HOME variable in your environment to match the
82 | location of your Java installation."
83 | fi
84 | else
85 | JAVACMD="java"
86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
87 |
88 | Please set the JAVA_HOME variable in your environment to match the
89 | location of your Java installation."
90 | fi
91 |
92 | # Increase the maximum file descriptors if we can.
93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
94 | MAX_FD_LIMIT=`ulimit -H -n`
95 | if [ $? -eq 0 ] ; then
96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
97 | MAX_FD="$MAX_FD_LIMIT"
98 | fi
99 | ulimit -n $MAX_FD
100 | if [ $? -ne 0 ] ; then
101 | warn "Could not set maximum file descriptor limit: $MAX_FD"
102 | fi
103 | else
104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
105 | fi
106 | fi
107 |
108 | # For Darwin, add options to specify how the application appears in the dock
109 | if $darwin; then
110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
111 | fi
112 |
113 | # For Cygwin, switch paths to Windows format before running java
114 | if $cygwin ; then
115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
158 | function splitJvmOpts() {
159 | JVM_OPTS=("$@")
160 | }
161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
163 |
164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
165 |
--------------------------------------------------------------------------------
/anagrams_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 | # For Cygwin, ensure paths are in UNIX format before anything is touched.
46 | if $cygwin ; then
47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
48 | fi
49 |
50 | # Attempt to set APP_HOME
51 | # Resolve links: $0 may be a link
52 | PRG="$0"
53 | # Need this for relative symlinks.
54 | while [ -h "$PRG" ] ; do
55 | ls=`ls -ld "$PRG"`
56 | link=`expr "$ls" : '.*-> \(.*\)$'`
57 | if expr "$link" : '/.*' > /dev/null; then
58 | PRG="$link"
59 | else
60 | PRG=`dirname "$PRG"`"/$link"
61 | fi
62 | done
63 | SAVED="`pwd`"
64 | cd "`dirname \"$PRG\"`/" >&-
65 | APP_HOME="`pwd -P`"
66 | cd "$SAVED" >&-
67 |
68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
69 |
70 | # Determine the Java command to use to start the JVM.
71 | if [ -n "$JAVA_HOME" ] ; then
72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
73 | # IBM's JDK on AIX uses strange locations for the executables
74 | JAVACMD="$JAVA_HOME/jre/sh/java"
75 | else
76 | JAVACMD="$JAVA_HOME/bin/java"
77 | fi
78 | if [ ! -x "$JAVACMD" ] ; then
79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
80 |
81 | Please set the JAVA_HOME variable in your environment to match the
82 | location of your Java installation."
83 | fi
84 | else
85 | JAVACMD="java"
86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
87 |
88 | Please set the JAVA_HOME variable in your environment to match the
89 | location of your Java installation."
90 | fi
91 |
92 | # Increase the maximum file descriptors if we can.
93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
94 | MAX_FD_LIMIT=`ulimit -H -n`
95 | if [ $? -eq 0 ] ; then
96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
97 | MAX_FD="$MAX_FD_LIMIT"
98 | fi
99 | ulimit -n $MAX_FD
100 | if [ $? -ne 0 ] ; then
101 | warn "Could not set maximum file descriptor limit: $MAX_FD"
102 | fi
103 | else
104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
105 | fi
106 | fi
107 |
108 | # For Darwin, add options to specify how the application appears in the dock
109 | if $darwin; then
110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
111 | fi
112 |
113 | # For Cygwin, switch paths to Windows format before running java
114 | if $cygwin ; then
115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
158 | function splitJvmOpts() {
159 | JVM_OPTS=("$@")
160 | }
161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
163 |
164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
165 |
--------------------------------------------------------------------------------
/anagrams_starter/app/src/main/java/com/google/engedu/anagrams/AnagramsActivity.java:
--------------------------------------------------------------------------------
1 | package com.google.engedu.anagrams;
2 |
3 | import android.content.Context;
4 | import android.content.res.AssetManager;
5 | import android.os.Bundle;
6 | import android.support.design.widget.FloatingActionButton;
7 | import android.support.v7.app.AppCompatActivity;
8 | import android.support.v7.widget.Toolbar;
9 | import android.text.Html;
10 | import android.text.InputType;
11 | import android.text.TextUtils;
12 | import android.view.KeyEvent;
13 | import android.view.Menu;
14 | import android.view.MenuItem;
15 | import android.view.View;
16 | import android.view.inputmethod.EditorInfo;
17 | import android.view.inputmethod.InputMethodManager;
18 | import android.widget.EditText;
19 | import android.widget.TextView;
20 | import android.widget.Toast;
21 |
22 | import java.io.IOException;
23 | import java.io.InputStream;
24 | import java.util.ArrayList;
25 |
26 |
27 | public class AnagramsActivity extends AppCompatActivity {
28 |
29 | public static final String START_MESSAGE = "Find as many words as possible that can be formed by adding one letter to %s (but that do not contain the substring %s).";
30 | private AnagramDictionary dictionary;
31 | private String currentWord;
32 | private ArrayList anagrams;
33 |
34 |
35 |
36 | @Override
37 | protected void onCreate(Bundle savedInstanceState) {
38 | super.onCreate(savedInstanceState);
39 | setContentView(R.layout.activity_anagrams);
40 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
41 | setSupportActionBar(toolbar);
42 | AssetManager assetManager = getAssets();
43 | try {
44 | InputStream inputStream = assetManager.open("words.txt");
45 | dictionary = new AnagramDictionary(inputStream);
46 | } catch (IOException e) {
47 | Toast toast = Toast.makeText(this, "Could not load dictionary", Toast.LENGTH_LONG);
48 | toast.show();
49 | }
50 | // Set up the EditText box to process the content of the box when the user hits 'enter'
51 | final EditText editText = (EditText) findViewById(R.id.editText);
52 | editText.setRawInputType(InputType.TYPE_CLASS_TEXT);
53 | editText.setImeOptions(EditorInfo.IME_ACTION_GO);
54 | editText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
55 | @Override
56 | public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
57 | boolean handled = false;
58 | if (actionId == EditorInfo.IME_ACTION_GO) {
59 | processWord(editText);
60 | handled = true;
61 | }
62 | return handled;
63 | }
64 | });
65 | }
66 |
67 | private void processWord(EditText editText) {
68 | TextView resultView = (TextView) findViewById(R.id.resultView);
69 | String word = editText.getText().toString().trim().toLowerCase();
70 | if (word.length() == 0) {
71 | return;
72 | }
73 | String color = "#cc0029";
74 | if (dictionary.isGoodWord(word, currentWord) && anagrams.contains(word)) {
75 | anagrams.remove(word);
76 | color = "#00aa29";
77 | } else {
78 | word = "X " + word;
79 | }
80 | resultView.append(Html.fromHtml(String.format("%s ", color, word)));
81 | editText.setText("");
82 | FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
83 | fab.show();
84 | }
85 |
86 | @Override
87 | public boolean onCreateOptionsMenu(Menu menu) {
88 | // Inflate the menu; this adds items to the action bar if it is present.
89 | getMenuInflater().inflate(R.menu.menu_anagrams, menu);
90 | return true;
91 | }
92 |
93 | @Override
94 | public boolean onOptionsItemSelected(MenuItem item) {
95 | // Handle action bar item clicks here. The action bar will
96 | // automatically handle clicks on the Home/Up button, so long
97 | // as you specify a parent activity in AndroidManifest.xml.
98 | int id = item.getItemId();
99 |
100 | //noinspection SimplifiableIfStatement
101 | if (id == R.id.action_settings) {
102 | return true;
103 | }
104 |
105 | return super.onOptionsItemSelected(item);
106 | }
107 |
108 | public boolean defaultAction(View view) {
109 | TextView gameStatus = (TextView) findViewById(R.id.gameStatusView);
110 | FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
111 | EditText editText = (EditText) findViewById(R.id.editText);
112 | TextView resultView = (TextView) findViewById(R.id.resultView);
113 | if (currentWord == null) {
114 | currentWord = dictionary.pickGoodStarterWord();
115 | anagrams = dictionary.getAnagramsWithOneMoreLetter(currentWord);
116 | gameStatus.setText(Html.fromHtml(String.format(START_MESSAGE, currentWord.toUpperCase(), currentWord)));
117 | fab.setImageResource(android.R.drawable.ic_menu_help);
118 | fab.hide();
119 | resultView.setText("");
120 | editText.setText("");
121 | editText.setEnabled(true);
122 | editText.requestFocus();
123 | InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
124 | imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);
125 | } else {
126 | editText.setText(currentWord);
127 | editText.setEnabled(false);
128 | fab.setImageResource(android.R.drawable.ic_media_play);
129 | currentWord = null;
130 | resultView.append(TextUtils.join("\n", anagrams));
131 | gameStatus.append(" Hit 'Play' to start again");
132 | }
133 | return true;
134 | }
135 | }
136 |
--------------------------------------------------------------------------------
/anagrams_starter/app/src/main/java/com/google/engedu/anagrams/AnagramDictionary.java:
--------------------------------------------------------------------------------
1 | package com.google.engedu.anagrams;
2 |
3 | import java.io.BufferedReader;
4 | import java.io.IOException;
5 | import java.io.InputStream;
6 | import java.io.InputStreamReader;
7 | import java.util.ArrayList;
8 | import java.util.Arrays;
9 | import java.util.HashMap;
10 | import java.util.HashSet;
11 | import java.util.Random;
12 |
13 | public class AnagramDictionary {
14 |
15 | private static final int MIN_NUM_ANAGRAMS = 5;
16 | private static final int DEFAULT_WORD_LENGTH = 3;
17 | private static final int MAX_WORD_LENGTH = 7;
18 | private Random random = new Random();
19 |
20 | private int wordLength = DEFAULT_WORD_LENGTH;
21 |
22 |
23 | public ArrayList wordList = new ArrayList<>();
24 | public HashMap> lettersToWord = new HashMap<>();
25 | public HashSet wordSet = new HashSet<>();
26 |
27 | public HashMap> sizeToWords = new HashMap<>();
28 |
29 | public AnagramDictionary(InputStream wordListStream) throws IOException {
30 |
31 |
32 | BufferedReader in = new BufferedReader(new InputStreamReader(wordListStream));
33 | String line;
34 | while ((line = in.readLine()) != null) {
35 | String word = line.trim();
36 |
37 | //add to the arrayList data structure
38 | wordList.add(word);
39 |
40 | //add the same word to a hashSet and hashMap
41 | wordSet.add(word);
42 |
43 | String sortedWord = sortLetters(word);
44 |
45 | //if hm already contains the key, we add it to the same key
46 | if (lettersToWord.containsKey(sortedWord)) {
47 | lettersToWord.get(sortedWord).add(word);
48 | }
49 | //else we create a new arrayList and add that as the value to that key in the hm
50 | else {
51 | ArrayList temp = new ArrayList<>();
52 | temp.add(word);
53 | lettersToWord.put(sortedWord, temp);
54 | }
55 |
56 | //check word length and store in sizeToWords
57 | if (sizeToWords.containsKey(word.length())) {
58 | sizeToWords.get(word.length()).add(word);
59 | } else {
60 | ArrayList temp = new ArrayList<>();
61 | temp.add(word);
62 | sizeToWords.put(word.length(), temp);
63 | }
64 |
65 | }
66 | }
67 |
68 | public boolean isGoodWord(String word, String base) {
69 |
70 | //if valid, then hashSet has that word in it && the word should not be a subString of the baseWord; i.e prefix or postfix
71 | return wordSet.contains(word) && !word.contains(base);
72 | }
73 |
74 | public ArrayList getAnagrams(String targetWord) {
75 | ArrayList result = new ArrayList();
76 |
77 | //sort the target word
78 | String sortedTargetWord = sortLetters(targetWord);
79 |
80 | //first step is to iterate through all 10000 words and find the anagrams
81 | for (String word : wordList) {
82 | //sort the word
83 | String sortedWord = sortLetters(word);
84 |
85 | //if it matches to sortedTargetWord, then it's an anagram of it
86 | if (sortedTargetWord.equals(sortedWord)) {
87 | //add the original word
88 | result.add(word);
89 | }
90 | }
91 |
92 | return result;
93 | }
94 |
95 | public ArrayList getAnagramsWithOneMoreLetter(String word) {
96 | ArrayList result = new ArrayList();
97 |
98 | String alphabets = "abcdefghijklmnopqrstuvwxyz";
99 | for (int i = 0; i < alphabets.length(); i++) {
100 |
101 | String tempString = word;
102 |
103 | //add every letter and get the key
104 | tempString += alphabets.charAt(i);
105 |
106 | String key = sortLetters(tempString);
107 |
108 | //check if that key exists
109 | if (lettersToWord.containsKey(key)) {
110 |
111 | //get all the values for that key
112 | ArrayList tempList = lettersToWord.get(key);
113 |
114 | //check if the obtained words are notGoodWords again
115 | ArrayList removeList = new ArrayList<>();
116 | for (String test : tempList) {
117 | if (!isGoodWord(test, word)) {
118 | removeList.add(test);
119 | }
120 | }
121 |
122 | //remove all the notGoodWords
123 | tempList.removeAll(removeList);
124 |
125 | //add the list to the remaining list to be returned
126 | result.addAll(tempList);
127 | }
128 | }
129 |
130 | return result;
131 | }
132 |
133 | public String pickGoodStarterWord() {
134 |
135 | while (true) {
136 |
137 | //get all words with 3/4/5 letters and pick from them only
138 | ArrayList tempList = sizeToWords.get(wordLength);
139 |
140 | //generate a random number between 0 and sizeOf list obtained
141 | Random random = new Random();
142 | int num = random.nextInt(tempList.size());
143 |
144 |
145 | //pick random word from the arrayList
146 | //String randomWord = wordList.get(num);
147 | String randomWord = tempList.get(num);
148 |
149 | //get all the anagrams for that random word
150 | ArrayList arrayList = getAnagramsWithOneMoreLetter(randomWord);
151 |
152 | //validate the conditions given
153 | if ((randomWord.length() == wordLength) && arrayList.size() > MIN_NUM_ANAGRAMS) {
154 |
155 | //increment the wordLength for next stage
156 | if (wordLength < MAX_WORD_LENGTH) wordLength++;
157 | return randomWord;
158 | }
159 | }
160 |
161 | }
162 |
163 | public String sortLetters(String word) {
164 | char[] words = word.toCharArray();
165 | Arrays.sort(words);
166 | return new String(words);
167 | }
168 | }
169 |
--------------------------------------------------------------------------------
/ghost_starter/app/src/main/java/com/google/engedu/ghost/GhostActivity.java:
--------------------------------------------------------------------------------
1 | package com.google.engedu.ghost;
2 |
3 | import android.content.res.AssetManager;
4 | import android.os.Bundle;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.util.Log;
7 | import android.view.KeyEvent;
8 | import android.view.Menu;
9 | import android.view.MenuItem;
10 | import android.view.View;
11 | import android.widget.TextView;
12 | import android.widget.Toast;
13 |
14 | import java.io.IOException;
15 | import java.io.InputStream;
16 | import java.util.Random;
17 |
18 |
19 | public class GhostActivity extends AppCompatActivity {
20 | private static final String COMPUTER_TURN = "Computer's turn";
21 | private static final String USER_TURN = "Your turn";
22 | private GhostDictionary dictionary;
23 | private boolean userTurn = false;
24 | private Random random = new Random();
25 |
26 | TextView ghostTv, label;
27 |
28 | @Override
29 | protected void onCreate(Bundle savedInstanceState) {
30 | super.onCreate(savedInstanceState);
31 | setContentView(R.layout.activity_ghost);
32 |
33 | //Link views using fv
34 | ghostTv = (TextView) findViewById(R.id.ghostText);
35 | label = (TextView) findViewById(R.id.gameStatus);
36 |
37 | AssetManager assetManager = getAssets();
38 | try {
39 | InputStream inputStream = assetManager.open("words.txt");
40 | dictionary = new FastDictionary(inputStream);
41 | } catch (IOException e) {
42 | Toast toast = Toast.makeText(this, "Could not load dictionary", Toast.LENGTH_LONG);
43 | toast.show();
44 | }
45 | onStart(null);
46 | }
47 |
48 | @Override
49 | public boolean onCreateOptionsMenu(Menu menu) {
50 | // Inflate the menu; this adds items to the action bar if it is present.
51 | getMenuInflater().inflate(R.menu.menu_ghost, menu);
52 | return true;
53 | }
54 |
55 | @Override
56 | public boolean onOptionsItemSelected(MenuItem item) {
57 |
58 | int id = item.getItemId();
59 |
60 |
61 | //noinspection SimplifiableIfStatement
62 | if (id == R.id.action_settings) {
63 | return true;
64 | }
65 |
66 | return super.onOptionsItemSelected(item);
67 | }
68 |
69 | /**
70 | * Handler for the "Reset" button.
71 | * Randomly determines whether the game starts with a user turn or a computer turn.
72 | *
73 | * @param view
74 | * @return true
75 | */
76 | public boolean onStart(View view) {
77 | userTurn = random.nextBoolean();
78 | TextView text = (TextView) findViewById(R.id.ghostText);
79 | text.setText("");
80 | TextView label = (TextView) findViewById(R.id.gameStatus);
81 | if (userTurn) {
82 | label.setText(USER_TURN);
83 | } else {
84 | label.setText(COMPUTER_TURN);
85 | computerTurn();
86 | }
87 | return true;
88 | }
89 |
90 | private void computerTurn() {
91 | // Do computer turn stuff then make it the user's turn again
92 |
93 | //fetch the existing word
94 | String word = ghostTv.getText().toString();
95 |
96 | //if the word in completed(valid word)
97 | if (dictionary.isWord(word) && word.length() >= 4) {
98 | Log.d("TAG", "computerTurn: true");
99 | label.setText("Computer won");
100 | }
101 | //else get the existing word and check for its prefix
102 | else {
103 |
104 | String longerWord = dictionary.getAnyWordStartingWith(word);
105 |
106 | //if the word with the existing word as prefix exists then add the
107 | //next character to the existing word
108 | if (longerWord != null) {
109 | char nextChar = longerWord.charAt(word.length());
110 | word += nextChar;
111 | ghostTv.setText(word);
112 | label.setText(USER_TURN);
113 | } else {
114 |
115 | //if no word exists with the entered word as a prefix then tell the user that he can't make up words which are not in dictionary
116 | label.setText("you can't bluff this , you lost");
117 | }
118 | }
119 |
120 |
121 | userTurn = true;
122 | // label.setText(USER_TURN);
123 | }
124 |
125 | @Override
126 | public boolean onKeyUp(int keyCode, KeyEvent event) {
127 |
128 | Log.d("TAG", "onKeyUp: "+keyCode+" "+ (char) event.getUnicodeChar());
129 |
130 | char keyPressed = (char) event.getUnicodeChar();
131 |
132 | if (Character.isLetter(keyPressed)) {
133 | String existingWord = ghostTv.getText().toString();
134 | existingWord += keyPressed;
135 | ghostTv.setText(existingWord);
136 |
137 |
138 | //call the computer turn
139 | computerTurn();
140 | //check for the validity
141 | // if (dictionary.isWord(existingWord)) {
142 | // label.setText("VALID WORD");
143 | // } else
144 | // label.setText("INVALID WORD");
145 | return true;
146 | } else
147 |
148 | return super.onKeyUp(keyCode, event);
149 | }
150 |
151 | public void challenge(View view) {
152 |
153 | //get the existing word
154 | String currentWord = ghostTv.getText().toString();
155 |
156 | //if the word is a valid word then the challenge is successful
157 | if (currentWord.length() > 3 && dictionary.isWord(currentWord)) {
158 | label.setText("you won");
159 | } else {
160 | // if a word can be formed with the fragment as prefix, declare victory for the computer and display a possible word
161 | String anotherWord = dictionary.getAnyWordStartingWith(currentWord);
162 | if (anotherWord != null) {
163 | label.setText("computer won");
164 | ghostTv.setText(anotherWord);
165 | }
166 | //If a word cannot be formed with the fragment, declare victory for the user
167 | else {
168 | label.setText("you won, computer lost this game");
169 | }
170 | }
171 |
172 |
173 | }
174 | }
175 |
--------------------------------------------------------------------------------
/wordstack/app/src/main/java/com/google/engedu/wordstack/MainActivity.java:
--------------------------------------------------------------------------------
1 | /* Copyright 2016 Google Inc.
2 | *
3 | * Licensed under the Apache License, Version 2.0 (the "License");
4 | * you may not use this file except in compliance with the License.
5 | * You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software
10 | * distributed under the License is distributed on an "AS IS" BASIS,
11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | * See the License for the specific language governing permissions and
13 | * limitations under the License.
14 | */
15 |
16 | package com.google.engedu.wordstack;
17 |
18 | import android.content.res.AssetManager;
19 | import android.graphics.Color;
20 | import android.os.Bundle;
21 | import android.support.v7.app.AppCompatActivity;
22 | import android.util.Log;
23 | import android.view.DragEvent;
24 | import android.view.MotionEvent;
25 | import android.view.View;
26 | import android.view.ViewGroup;
27 | import android.widget.LinearLayout;
28 | import android.widget.TextView;
29 | import android.widget.Toast;
30 |
31 | import java.io.BufferedReader;
32 | import java.io.IOException;
33 | import java.io.InputStream;
34 | import java.io.InputStreamReader;
35 | import java.util.ArrayList;
36 | import java.util.Random;
37 | import java.util.Stack;
38 |
39 | public class MainActivity extends AppCompatActivity {
40 |
41 | private static final int WORD_LENGTH = 3;
42 | public static final int LIGHT_BLUE = Color.rgb(176, 200, 255);
43 | public static final int LIGHT_GREEN = Color.rgb(200, 255, 200);
44 | private ArrayList words = new ArrayList<>();
45 | private Random random = new Random();
46 | private StackedLayout stackedLayout;
47 | private String word1, word2;
48 |
49 | private Stack placedTiles;
50 |
51 | @Override
52 | protected void onCreate(Bundle savedInstanceState) {
53 | super.onCreate(savedInstanceState);
54 | setContentView(R.layout.activity_main);
55 | AssetManager assetManager = getAssets();
56 | try {
57 | InputStream inputStream = assetManager.open("words.txt");
58 | BufferedReader in = new BufferedReader(new InputStreamReader(inputStream));
59 | String line = null;
60 | while((line = in.readLine()) != null) {
61 | String word = line.trim();
62 | if(word.length() == WORD_LENGTH)
63 | words.add(word);
64 | /**
65 | **
66 | ** YOUR CODE GOES HERE
67 | **
68 | **/
69 | }
70 | } catch (IOException e) {
71 | Toast toast = Toast.makeText(this, "Could not load dictionary", Toast.LENGTH_LONG);
72 | toast.show();
73 | }
74 | LinearLayout verticalLayout = (LinearLayout) findViewById(R.id.vertical_layout);
75 | stackedLayout = new StackedLayout(this);
76 | verticalLayout.addView(stackedLayout, 3);
77 |
78 | View word1LinearLayout = findViewById(R.id.word1);
79 | //word1LinearLayout.setOnTouchListener(new TouchListener());
80 | word1LinearLayout.setOnDragListener(new DragListener());
81 | View word2LinearLayout = findViewById(R.id.word2);
82 | //word2LinearLayout.setOnTouchListener(new TouchListener());
83 | word2LinearLayout.setOnDragListener(new DragListener());
84 | }
85 |
86 | private class TouchListener implements View.OnTouchListener {
87 |
88 | @Override
89 | public boolean onTouch(View v, MotionEvent event) {
90 | if (event.getAction() == MotionEvent.ACTION_DOWN && !stackedLayout.empty()) {
91 | LetterTile tile = (LetterTile) stackedLayout.peek();
92 | tile.moveToViewGroup((ViewGroup) v);
93 | if (stackedLayout.empty()) {
94 | TextView messageBox = (TextView) findViewById(R.id.message_box);
95 | messageBox.setText(word1 + " " + word2);
96 | }
97 |
98 | placedTiles.push(tile);
99 | /**
100 | **
101 | ** YOUR CODE GOES HERE
102 | **
103 | **/
104 | return true;
105 | }
106 | return false;
107 | }
108 | }
109 |
110 | private class DragListener implements View.OnDragListener {
111 |
112 | public boolean onDrag(View v, DragEvent event) {
113 | int action = event.getAction();
114 | switch (event.getAction()) {
115 | case DragEvent.ACTION_DRAG_STARTED:
116 | v.setBackgroundColor(LIGHT_BLUE);
117 | v.invalidate();
118 | Log.e("tag","drag started!");
119 | return true;
120 | case DragEvent.ACTION_DRAG_ENTERED:
121 | v.setBackgroundColor(LIGHT_GREEN);
122 | v.invalidate();
123 | return true;
124 | case DragEvent.ACTION_DRAG_EXITED:
125 | v.setBackgroundColor(LIGHT_BLUE);
126 | v.invalidate();
127 | return true;
128 | case DragEvent.ACTION_DRAG_ENDED:
129 | v.setBackgroundColor(Color.WHITE);
130 | v.invalidate();
131 | return true;
132 | case DragEvent.ACTION_DROP:
133 | // Dropped, reassign Tile to the target Layout
134 | LetterTile tile = (LetterTile) event.getLocalState();
135 | tile.moveToViewGroup((ViewGroup) v);
136 | if (stackedLayout.empty()) {
137 | TextView messageBox = (TextView) findViewById(R.id.message_box);
138 | messageBox.setText(word1 + " " + word2);
139 | }
140 |
141 | placedTiles.push(tile);
142 |
143 | /**
144 | **
145 | ** YOUR CODE GOES HERE
146 | **
147 | **/
148 | return true;
149 | }
150 | return false;
151 | }
152 | }
153 |
154 | public boolean onStartGame(View view) {
155 |
156 | placedTiles = new Stack<>();
157 | LinearLayout word1LinearLayout = (LinearLayout)findViewById(R.id.word1);
158 | word1LinearLayout.removeAllViews();
159 | LinearLayout word2LinearLayout = (LinearLayout)findViewById(R.id.word2);
160 | word2LinearLayout.removeAllViews();
161 | stackedLayout.clear();
162 |
163 | TextView messageBox = (TextView) findViewById(R.id.message_box);
164 | messageBox.setText("Game started");
165 |
166 | word1 = words.get(random.nextInt(words.size()));
167 | word2 = words.get(random.nextInt(words.size()));
168 |
169 | Log.e("tag",word1 + " "+word2);
170 |
171 | int counter1=0,counter2=0;
172 | String scramble = "";
173 |
174 | while(counter1 < WORD_LENGTH && counter2 < WORD_LENGTH){
175 | int whichWord = random.nextInt(2);
176 | if (whichWord == 0){
177 | scramble += word1.charAt(counter1);
178 | counter1++;
179 | } else {
180 | scramble+=word2.charAt(counter2);
181 | counter2++;
182 | }
183 | }
184 |
185 | if (counter1 == WORD_LENGTH && counter2 < WORD_LENGTH){
186 | scramble +=word2.substring(counter2);
187 | }
188 |
189 | if (counter2 == WORD_LENGTH && counter1 < WORD_LENGTH){
190 | scramble +=word1.substring(counter1);
191 | }
192 |
193 | messageBox.setText(scramble);
194 | for (int i = scramble.length() - 1; i >= 0 ; i--){
195 | stackedLayout.push(new LetterTile(this, scramble.charAt(i)));
196 | }
197 |
198 | return true;
199 | }
200 |
201 | public boolean onUndo(View view) {
202 |
203 | if(!placedTiles.isEmpty()){
204 | LetterTile tile = placedTiles.pop();
205 | tile.moveToViewGroup(stackedLayout);
206 | }
207 |
208 | return true;
209 | }
210 | }
211 |
--------------------------------------------------------------------------------
/anagrams_starter/app/app.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 | generateDebugSources
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
--------------------------------------------------------------------------------
/Scarnesdice/app/src/main/java/com/dark/scarnesdice/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.dark.scarnesdice;
2 |
3 | import android.os.Bundle;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.text.Html;
6 | import android.util.Log;
7 | import android.view.View;
8 | import android.widget.Button;
9 | import android.widget.ImageView;
10 | import android.widget.TextView;
11 |
12 | import java.util.Random;
13 | import java.util.Timer;
14 | import java.util.TimerTask;
15 |
16 | public class MainActivity extends AppCompatActivity {
17 |
18 | private static final String TAG = "TEST_TAG";
19 |
20 | Timer myTimer;
21 |
22 | public int userOverallScore = 0, userTurnScore = 0;
23 | public int computerOverallScore = 0, computerTurnScore = 0;
24 |
25 | Button rollButton, holdButton;
26 | TextView label;
27 | ImageView imageView;
28 |
29 | String userScoreLabel = "Your score : ";
30 | String compScoreLabel = " Computer score : ";
31 | String userTurnScoreLabel = " Your turn score : ";
32 | String compTurnScoreLabel = "\ncomputer turn score : ";
33 |
34 | String labelText = userScoreLabel + userOverallScore + compScoreLabel + computerOverallScore;
35 |
36 | int[] drawables = {R.drawable.dice1,
37 | R.drawable.dice2,
38 | R.drawable.dice3,
39 | R.drawable.dice4,
40 | R.drawable.dice5,
41 | R.drawable.dice6
42 | };
43 |
44 |
45 | @Override
46 | protected void onCreate(Bundle savedInstanceState) {
47 | super.onCreate(savedInstanceState);
48 | setContentView(R.layout.activity_main);
49 |
50 | rollButton = (Button) findViewById(R.id.roll);
51 | holdButton = (Button) findViewById(R.id.hold);
52 | label = (TextView) findViewById(R.id.label);
53 | imageView = (ImageView) findViewById(R.id.imageView);
54 |
55 | label.setText(Html.fromHtml(labelText));
56 |
57 | }
58 |
59 | public void rollButtonClick(View view) {
60 |
61 | Log.d(TAG, "rollButtonClick called ");
62 |
63 | int rolledNumber = rollDice();
64 | imageView.setImageResource(drawables[rolledNumber]);
65 | rolledNumber++;
66 |
67 | if (rolledNumber == 1) {
68 | userTurnScore = 0;
69 | labelText = userScoreLabel + userOverallScore + compScoreLabel + computerOverallScore + userTurnScoreLabel + userTurnScore + "\n you lost your chance";
70 | computerTurn();
71 | } else {
72 | userTurnScore += rolledNumber;
73 | labelText = userScoreLabel + userOverallScore + compScoreLabel + computerOverallScore + userTurnScoreLabel + userTurnScore;
74 | }
75 | label.setText(Html.fromHtml(labelText));
76 |
77 | }
78 |
79 | public void computerTurn() {
80 |
81 |
82 | myTimer = new Timer();
83 | myTimer.schedule(new TimerTask() {
84 | @Override
85 | public void run() {
86 |
87 |
88 | //disable the buttons while computer is playing
89 | runOnUiThread(new Runnable() {
90 | @Override
91 | public void run() {
92 | enableButtons(false);
93 | }
94 | });
95 |
96 | //roll dice for comp
97 | int computerRolledNumber = rollDice();
98 |
99 | //update the image on the ui thread
100 | final int finalComputerRolledNumber = computerRolledNumber;
101 | runOnUiThread(new Runnable() {
102 | @Override
103 | public void run() {
104 | imageView.setImageResource(drawables[finalComputerRolledNumber]);
105 | }
106 | });
107 |
108 | computerRolledNumber++;
109 |
110 | //if computer looses, set turnSCore to 0 and enable buttons for user's turn
111 | if (computerRolledNumber == 1) {
112 | computerTurnScore = 0;
113 | labelText = userScoreLabel + userOverallScore + compScoreLabel + computerOverallScore + userTurnScoreLabel + userTurnScore +
114 | "\n computer rolled a one and lost it's chance";
115 |
116 |
117 | //enable buttons, on ui thread
118 | runOnUiThread(new Runnable() {
119 | @Override
120 | public void run() {
121 | enableButtons(true);
122 | }
123 | });
124 |
125 | //update the label
126 | runOnUiThread(new Runnable() {
127 | @Override
128 | public void run() {
129 | label.setText(Html.fromHtml(labelText));
130 | }
131 | });
132 |
133 | //cancel the timer, this is exiting out of function
134 | myTimer.cancel();
135 |
136 | }
137 |
138 | //if not 1, add the score to turn score
139 | else {
140 | computerTurnScore += computerRolledNumber;
141 | labelText = userScoreLabel + userOverallScore + compScoreLabel + computerOverallScore + userTurnScoreLabel + userTurnScore
142 | + "\nComputer rolled a " + computerRolledNumber
143 | + compTurnScoreLabel + computerTurnScore;
144 |
145 | //update the label
146 | runOnUiThread(new Runnable() {
147 | @Override
148 | public void run() {
149 | label.setText(Html.fromHtml(labelText));
150 | }
151 | });
152 |
153 | //if the turn score is greater than 20 stop rolling and hold(update the comp score and cancel timer)
154 | if (computerTurnScore > 20) {
155 |
156 | runOnUiThread(new Runnable() {
157 | @Override
158 | public void run() {
159 | enableButtons(true);
160 | }
161 | });
162 |
163 | computerOverallScore += computerTurnScore;
164 | computerTurnScore = 0;
165 | labelText = userScoreLabel + userOverallScore + compScoreLabel + computerOverallScore + "\nComputer holds";
166 |
167 | runOnUiThread(new Runnable() {
168 | @Override
169 | public void run() {
170 | label.setText(Html.fromHtml(labelText));
171 | }
172 | });
173 |
174 |
175 | myTimer.cancel();
176 |
177 |
178 | }
179 |
180 | }
181 |
182 | }
183 |
184 | }, 0, 2000);
185 |
186 |
187 | }
188 |
189 |
190 |
191 | /*private void computerTurn() {
192 |
193 | Log.d(TAG, "computerTurn called ");
194 |
195 | //disable all the buttons first
196 | enableButtons(false);
197 |
198 | //infinite loop until computer loses turn
199 | while (true) {
200 | //roll dice by comp
201 | int computerRolledNumber = rollDice();
202 | imageView.setImageResource(drawables[computerRolledNumber]);
203 | computerRolledNumber++;
204 |
205 | Log.d(TAG, "computerTurn: " + computerRolledNumber);
206 |
207 | //if comp rolled 1, make the turnScore 0, update the labels and enable the buttons
208 | if (computerRolledNumber == 1) {
209 | computerTurnScore = 0;
210 | labelText = userScoreLabel + userOverallScore + compScoreLabel + computerOverallScore + userTurnScoreLabel + userTurnScore
211 | + "\n computer rolled a one and lost it's chance";
212 | enableButtons(true);
213 | label.setText(Html.fromHtml(labelText));
214 | return;
215 | }
216 |
217 | //else add the score to turnScore and update the label
218 | else {
219 | computerTurnScore += computerRolledNumber;
220 | labelText = userScoreLabel + userOverallScore + compScoreLabel + computerOverallScore + userTurnScoreLabel + userTurnScore
221 | + "\nComputer rolled a " + computerRolledNumber;
222 | label.setText(Html.fromHtml(labelText));
223 | }
224 |
225 | //hold strategy for comp...if turnScore is > 20 then hold and save the turnScore and exit from this function, also enable the buttons
226 | if (computerTurnScore > 20) {
227 | computerOverallScore += computerTurnScore;
228 | computerTurnScore = 0;
229 | labelText = userScoreLabel + userOverallScore + compScoreLabel + computerOverallScore + "\n" +
230 | "Computer holds";
231 |
232 | label.setText(Html.fromHtml(labelText));
233 |
234 | enableButtons(true);
235 |
236 | return;
237 | }
238 | }
239 |
240 | }*/
241 |
242 | public void holdButtonClick(View view) {
243 |
244 | userOverallScore += userTurnScore;
245 | userTurnScore = 0;
246 |
247 | labelText = userScoreLabel + userOverallScore + compScoreLabel + computerOverallScore + userTurnScoreLabel + userTurnScore;
248 | label.setText(Html.fromHtml(labelText));
249 |
250 |
251 | computerTurn();
252 | }
253 |
254 | public void resetButtonClick(View view) {
255 |
256 | userOverallScore = 0;
257 | userTurnScore = 0;
258 | computerOverallScore = 0;
259 | computerTurnScore = 0;
260 |
261 | labelText = userScoreLabel + userOverallScore + compScoreLabel + computerOverallScore;
262 | label.setText(Html.fromHtml(labelText));
263 |
264 | enableButtons(true);
265 |
266 | }
267 |
268 | private int rollDice() {
269 |
270 | Random random = new Random();
271 | int randomNumber = random.nextInt(6);
272 | Log.d(TAG, "rollBtnClick: " + randomNumber);
273 |
274 | return randomNumber;
275 |
276 | }
277 |
278 | private void enableButtons(boolean isEnabled) {
279 | rollButton.setEnabled(isEnabled);
280 | holdButton.setEnabled(isEnabled);
281 | }
282 | }
283 |
--------------------------------------------------------------------------------
/wordstack/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright 2016 Google Inc. All rights reserved.
2 |
3 | Apache License
4 | Version 2.0, January 2004
5 | http://www.apache.org/licenses/
6 |
7 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
8 |
9 | 1. Definitions.
10 |
11 | "License" shall mean the terms and conditions for use, reproduction,
12 | and distribution as defined by Sections 1 through 9 of this document.
13 |
14 | "Licensor" shall mean the copyright owner or entity authorized by
15 | the copyright owner that is granting the License.
16 |
17 | "Legal Entity" shall mean the union of the acting entity and all
18 | other entities that control, are controlled by, or are under common
19 | control with that entity. For the purposes of this definition,
20 | "control" means (i) the power, direct or indirect, to cause the
21 | direction or management of such entity, whether by contract or
22 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
23 | outstanding shares, or (iii) beneficial ownership of such entity.
24 |
25 | "You" (or "Your") shall mean an individual or Legal Entity
26 | exercising permissions granted by this License.
27 |
28 | "Source" form shall mean the preferred form for making modifications,
29 | including but not limited to software source code, documentation
30 | source, and configuration files.
31 |
32 | "Object" form shall mean any form resulting from mechanical
33 | transformation or translation of a Source form, including but
34 | not limited to compiled object code, generated documentation,
35 | and conversions to other media types.
36 |
37 | "Work" shall mean the work of authorship, whether in Source or
38 | Object form, made available under the License, as indicated by a
39 | copyright notice that is included in or attached to the work
40 | (an example is provided in the Appendix below).
41 |
42 | "Derivative Works" shall mean any work, whether in Source or Object
43 | form, that is based on (or derived from) the Work and for which the
44 | editorial revisions, annotations, elaborations, or other modifications
45 | represent, as a whole, an original work of authorship. For the purposes
46 | of this License, Derivative Works shall not include works that remain
47 | separable from, or merely link (or bind by name) to the interfaces of,
48 | the Work and Derivative Works thereof.
49 |
50 | "Contribution" shall mean any work of authorship, including
51 | the original version of the Work and any modifications or additions
52 | to that Work or Derivative Works thereof, that is intentionally
53 | submitted to Licensor for inclusion in the Work by the copyright owner
54 | or by an individual or Legal Entity authorized to submit on behalf of
55 | the copyright owner. For the purposes of this definition, "submitted"
56 | means any form of electronic, verbal, or written communication sent
57 | to the Licensor or its representatives, including but not limited to
58 | communication on electronic mailing lists, source code control systems,
59 | and issue tracking systems that are managed by, or on behalf of, the
60 | Licensor for the purpose of discussing and improving the Work, but
61 | excluding communication that is conspicuously marked or otherwise
62 | designated in writing by the copyright owner as "Not a Contribution."
63 |
64 | "Contributor" shall mean Licensor and any individual or Legal Entity
65 | on behalf of whom a Contribution has been received by Licensor and
66 | subsequently incorporated within the Work.
67 |
68 | 2. Grant of Copyright License. Subject to the terms and conditions of
69 | this License, each Contributor hereby grants to You a perpetual,
70 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
71 | copyright license to reproduce, prepare Derivative Works of,
72 | publicly display, publicly perform, sublicense, and distribute the
73 | Work and such Derivative Works in Source or Object form.
74 |
75 | 3. Grant of Patent License. Subject to the terms and conditions of
76 | this License, each Contributor hereby grants to You a perpetual,
77 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
78 | (except as stated in this section) patent license to make, have made,
79 | use, offer to sell, sell, import, and otherwise transfer the Work,
80 | where such license applies only to those patent claims licensable
81 | by such Contributor that are necessarily infringed by their
82 | Contribution(s) alone or by combination of their Contribution(s)
83 | with the Work to which such Contribution(s) was submitted. If You
84 | institute patent litigation against any entity (including a
85 | cross-claim or counterclaim in a lawsuit) alleging that the Work
86 | or a Contribution incorporated within the Work constitutes direct
87 | or contributory patent infringement, then any patent licenses
88 | granted to You under this License for that Work shall terminate
89 | as of the date such litigation is filed.
90 |
91 | 4. Redistribution. You may reproduce and distribute copies of the
92 | Work or Derivative Works thereof in any medium, with or without
93 | modifications, and in Source or Object form, provided that You
94 | meet the following conditions:
95 |
96 | (a) You must give any other recipients of the Work or
97 | Derivative Works a copy of this License; and
98 |
99 | (b) You must cause any modified files to carry prominent notices
100 | stating that You changed the files; and
101 |
102 | (c) You must retain, in the Source form of any Derivative Works
103 | that You distribute, all copyright, patent, trademark, and
104 | attribution notices from the Source form of the Work,
105 | excluding those notices that do not pertain to any part of
106 | the Derivative Works; and
107 |
108 | (d) If the Work includes a "NOTICE" text file as part of its
109 | distribution, then any Derivative Works that You distribute must
110 | include a readable copy of the attribution notices contained
111 | within such NOTICE file, excluding those notices that do not
112 | pertain to any part of the Derivative Works, in at least one
113 | of the following places: within a NOTICE text file distributed
114 | as part of the Derivative Works; within the Source form or
115 | documentation, if provided along with the Derivative Works; or,
116 | within a display generated by the Derivative Works, if and
117 | wherever such third-party notices normally appear. The contents
118 | of the NOTICE file are for informational purposes only and
119 | do not modify the License. You may add Your own attribution
120 | notices within Derivative Works that You distribute, alongside
121 | or as an addendum to the NOTICE text from the Work, provided
122 | that such additional attribution notices cannot be construed
123 | as modifying the License.
124 |
125 | You may add Your own copyright statement to Your modifications and
126 | may provide additional or different license terms and conditions
127 | for use, reproduction, or distribution of Your modifications, or
128 | for any such Derivative Works as a whole, provided Your use,
129 | reproduction, and distribution of the Work otherwise complies with
130 | the conditions stated in this License.
131 |
132 | 5. Submission of Contributions. Unless You explicitly state otherwise,
133 | any Contribution intentionally submitted for inclusion in the Work
134 | by You to the Licensor shall be under the terms and conditions of
135 | this License, without any additional terms or conditions.
136 | Notwithstanding the above, nothing herein shall supersede or modify
137 | the terms of any separate license agreement you may have executed
138 | with Licensor regarding such Contributions.
139 |
140 | 6. Trademarks. This License does not grant permission to use the trade
141 | names, trademarks, service marks, or product names of the Licensor,
142 | except as required for reasonable and customary use in describing the
143 | origin of the Work and reproducing the content of the NOTICE file.
144 |
145 | 7. Disclaimer of Warranty. Unless required by applicable law or
146 | agreed to in writing, Licensor provides the Work (and each
147 | Contributor provides its Contributions) on an "AS IS" BASIS,
148 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
149 | implied, including, without limitation, any warranties or conditions
150 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
151 | PARTICULAR PURPOSE. You are solely responsible for determining the
152 | appropriateness of using or redistributing the Work and assume any
153 | risks associated with Your exercise of permissions under this License.
154 |
155 | 8. Limitation of Liability. In no event and under no legal theory,
156 | whether in tort (including negligence), contract, or otherwise,
157 | unless required by applicable law (such as deliberate and grossly
158 | negligent acts) or agreed to in writing, shall any Contributor be
159 | liable to You for damages, including any direct, indirect, special,
160 | incidental, or consequential damages of any character arising as a
161 | result of this License or out of the use or inability to use the
162 | Work (including but not limited to damages for loss of goodwill,
163 | work stoppage, computer failure or malfunction, or any and all
164 | other commercial damages or losses), even if such Contributor
165 | has been advised of the possibility of such damages.
166 |
167 | 9. Accepting Warranty or Additional Liability. While redistributing
168 | the Work or Derivative Works thereof, You may choose to offer,
169 | and charge a fee for, acceptance of support, warranty, indemnity,
170 | or other liability obligations and/or rights consistent with this
171 | License. However, in accepting such obligations, You may act only
172 | on Your own behalf and on Your sole responsibility, not on behalf
173 | of any other Contributor, and only if You agree to indemnify,
174 | defend, and hold each Contributor harmless for any liability
175 | incurred by, or claims asserted against, such Contributor by reason
176 | of your accepting any such warranty or additional liability.
177 |
--------------------------------------------------------------------------------
/ghost_starter/app/app.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |