├── .gitignore ├── .idea ├── .name ├── compiler.xml ├── copyright │ ├── GPLv3.xml │ └── profiles_settings.xml ├── encodings.xml ├── gradle.xml ├── misc.xml ├── modules.xml ├── runConfigurations.xml └── vcs.xml ├── LICENSE ├── README.md ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── mobile ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── mycroft │ │ └── ai │ │ └── ExampleInstrumentationTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ ├── layout │ │ │ └── MycroftAppWidget.java │ │ └── mycroft │ │ │ └── ai │ │ │ ├── AppCompatPreferenceActivity.java │ │ │ ├── Constants.java │ │ │ ├── DiscoveryActivity.java │ │ │ ├── MainActivity.java │ │ │ ├── MessageParser.java │ │ │ ├── MycroftUtterances.java │ │ │ ├── SafeCallback.java │ │ │ ├── SettingsActivity.java │ │ │ ├── TTSManager.java │ │ │ ├── adapters │ │ │ └── MycroftAdapter.java │ │ │ ├── receivers │ │ │ └── NetworkChangeReceiver.java │ │ │ ├── services │ │ │ └── MycroftWearListenerService.java │ │ │ └── utils │ │ │ ├── NetworkAutoDiscoveryUtil.java │ │ │ ├── NetworkUtil.java │ │ │ └── PlayServicesUtil.java │ └── res │ │ ├── drawable-hdpi │ │ └── ic_mycroft.png │ │ ├── drawable-mdpi │ │ └── ic_mycroft.png │ │ ├── drawable-xhdpi │ │ └── ic_mycroft.png │ │ ├── drawable-xxhdpi │ │ └── ic_mycroft.png │ │ ├── drawable │ │ ├── ic_info_black_24dp.xml │ │ ├── ic_notifications_black_24dp.xml │ │ ├── ic_sync_black_24dp.xml │ │ ├── mycroft_big.png │ │ └── mycroft_logo_24dp.png │ │ ├── layout │ │ ├── activity_discovery.xml │ │ ├── activity_display.xml │ │ ├── activity_main.xml │ │ ├── card_layout.xml │ │ ├── content_main.xml │ │ └── mycroft_app_widget.xml │ │ ├── menu │ │ └── menu_setup.xml │ │ ├── mipmap-hdpi │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxxhdpi │ │ └── ic_mycroft.png │ │ ├── values-v14 │ │ └── dimens.xml │ │ ├── values-v21 │ │ └── styles.xml │ │ ├── values-w820dp │ │ └── dimens.xml │ │ ├── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ ├── styles.xml │ │ └── wear.xml │ │ └── xml │ │ ├── mycroft_app_widget_info.xml │ │ ├── pref_about.xml │ │ ├── pref_data_sync.xml │ │ ├── pref_general.xml │ │ ├── pref_headers.xml │ │ └── pref_notification.xml │ └── test │ └── java │ └── mycroft │ └── ai │ ├── ExampleUnitTest.java │ ├── LogAnswer.java │ └── TTSManagerTest.java ├── settings.gradle ├── shared ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── mycroft │ │ └── ai │ │ └── shared │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── mycroft │ │ │ └── ai │ │ │ └── shared │ │ │ ├── utilities │ │ │ └── GuiUtilities.java │ │ │ └── wear │ │ │ └── Constants.java │ └── res │ │ └── values │ │ └── strings.xml │ └── test │ └── java │ └── mycroft │ └── ai │ └── shared │ └── ExampleUnitTest.java └── wear ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src └── main ├── AndroidManifest.xml ├── java └── mycroft │ └── ai │ └── MainActivity.java └── res ├── drawable-hdpi └── ic_mycroft.png ├── drawable-mdpi └── ic_mycroft.png ├── drawable-xhdpi └── ic_mycroft.png ├── drawable-xxhdpi └── ic_mycroft.png ├── drawable └── mycroft_logo.png ├── layout └── activity_main.xml ├── mipmap-xxhdpi └── ic_mycroft.png └── values ├── strings.xml └── wear.xml /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | -------------------------------------------------------------------------------- /.idea/.name: -------------------------------------------------------------------------------- 1 | Mycroft-Android -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /.idea/copyright/GPLv3.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 19 | 20 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 19 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 46 | 47 | 48 | 49 | 50 | 1.7 51 | 52 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 68 | 69 | 70 | 71 | 72 | 73 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Mycroft-Android 2 | 3 | This is the Android companion app to Mycroft-core. It works by opening a websocket connection to the Mycroft-core messagebus 4 | and sending and receiving messages from there. 5 | 6 | It implements voice recognition and Text To Speech (TTS) via Google API's at the moment, but that may change soon. 7 | 8 | ## To Install 9 | 10 | Import the repo into Android Studio, or your IDE of choice. 11 | Build and deploy to a device 12 | 13 | Once the app is running on a device (Lollipop or later SDK 24), you will need to set the IP address of your Mycroft-core instance 14 | in the Settings -> General Options menu. That will then create a websocket connection to your Mycroft and off you go! 15 | 16 | ## To help out 17 | If you would like to help out on this project, please join the Mycroft community SlackHQ and ask where you can contribute! 18 | Design and UI/UX is most needed at this point, but any and all help is greatly appreciated! 19 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | buildscript { 3 | repositories { 4 | jcenter() 5 | } 6 | dependencies { 7 | classpath 'com.android.tools.build:gradle:2.2.1' 8 | 9 | // NOTE: Do not place your application dependencies here; they belong 10 | // in the individual module build.gradle files 11 | } 12 | } 13 | 14 | allprojects { 15 | repositories { 16 | jcenter() 17 | } 18 | 19 | ext.versionMajor = 1 20 | ext.versionMinor = 0 21 | ext.versionPatch = 1 22 | ext.versionClassifier = "SNAPSHOT" 23 | 24 | project.ext { 25 | versionCode = ext.versionMajor * 10000 + ext.versionMinor * 100 + ext.versionPatch 26 | versionName = getVersionName() 27 | } 28 | } 29 | 30 | task clean(type: Delete) { 31 | delete rootProject.buildDir 32 | } 33 | 34 | public String getVersionName() { 35 | String versionName = "${ext.versionMajor}.${ext.versionMinor}.${ext.versionPatch}" 36 | if (ext.versionClassifier != null && !ext.versionClassifier.isEmpty()) { 37 | versionName = versionName + "-" + ext.versionClassifier 38 | } 39 | return versionName; 40 | } -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | org.gradle.jvmargs=-Xmx1536m 13 | 14 | # When configured, Gradle will run in incubating parallel mode. 15 | # This option should only be used with decoupled projects. More details, visit 16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 17 | # org.gradle.parallel=true 18 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/seymour-bootay/Mycroft-Android/67e830987bf6d04d93a5c306d31df04c565119f4/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Sun Nov 27 20:36:28 CST 2016 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /mobile/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /mobile/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017. Mycroft AI, Inc. 3 | * 4 | * This file is part of Mycroft-Android a client for Mycroft Core. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | buildscript { 22 | repositories { 23 | maven { url 'https://maven.fabric.io/public' } 24 | } 25 | 26 | dependencies { 27 | classpath 'io.fabric.tools:gradle:1.+' 28 | } 29 | } 30 | apply plugin: 'com.android.application' 31 | apply plugin: 'io.fabric' 32 | 33 | repositories { 34 | maven { url 'https://maven.fabric.io/public' } 35 | } 36 | 37 | android { 38 | 39 | compileSdkVersion 24 40 | buildToolsVersion "24.0.0" 41 | defaultConfig { 42 | applicationId "mycroft.ai" 43 | minSdkVersion 21 44 | targetSdkVersion 24 45 | versionCode project.ext.versionCode 46 | versionName project.ext.versionName 47 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 48 | } 49 | buildTypes { 50 | release { 51 | minifyEnabled false 52 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 53 | } 54 | } 55 | } 56 | 57 | dependencies { 58 | compile fileTree(include: ['*.jar'], dir: 'libs') 59 | compile 'com.android.support:appcompat-v7:24.0.0' 60 | compile 'com.android.support:design:24.0.0' 61 | compile 'org.java-websocket:Java-WebSocket:1.3.0' 62 | compile 'com.android.support:support-v4:24.0.0' 63 | // layout deps 64 | compile 'com.android.support:cardview-v7:24.0.+' 65 | compile 'com.android.support:recyclerview-v7:24.0.+' 66 | // Unit test dependencies 67 | testCompile 'org.mockito:mockito-core:1.10.19' 68 | testCompile 'org.powermock:powermock-api-mockito:1.6.4' 69 | testCompile 'org.powermock:powermock-module-junit4-rule-agent:1.6.4' 70 | testCompile 'org.powermock:powermock-module-junit4-rule:1.6.4' 71 | testCompile 'org.powermock:powermock-module-junit4:1.6.4' 72 | testCompile 'junit:junit:4.12' 73 | // Instrumentation dependencies 74 | androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2' 75 | androidTestCompile 'com.android.support.test:runner:0.5' 76 | androidTestCompile 'com.android.support:support-annotations:24.0.0' 77 | compile('com.crashlytics.sdk.android:crashlytics:2.5.7@aar') { 78 | transitive = true; 79 | } 80 | compile 'com.google.android.gms:play-services-wearable:9.4.0' 81 | wearApp project(':wear') 82 | compile project(':shared') 83 | } -------------------------------------------------------------------------------- /mobile/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /opt/android-sdks/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /mobile/src/androidTest/java/mycroft/ai/ExampleInstrumentationTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017. Mycroft AI, Inc. 3 | * 4 | * This file is part of Mycroft-Android a client for Mycroft Core. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | package mycroft.ai; 22 | 23 | import android.content.Context; 24 | import android.support.test.InstrumentationRegistry; 25 | import android.support.test.filters.MediumTest; 26 | import android.support.test.runner.AndroidJUnit4; 27 | 28 | import org.junit.Test; 29 | import org.junit.runner.RunWith; 30 | 31 | 32 | import static org.junit.Assert.*; 33 | 34 | /** 35 | * Instrumentation test, which will execute on an Android device. 36 | * 37 | * @see Testing documentation 38 | */ 39 | @MediumTest 40 | @RunWith(AndroidJUnit4.class) 41 | public class ExampleInstrumentationTest { 42 | @Test 43 | public void useAppContext() throws Exception { 44 | // Context of the app under test. 45 | Context appContext = InstrumentationRegistry.getTargetContext(); 46 | 47 | assertEquals("mycroft.ai", appContext.getPackageName()); 48 | } 49 | } -------------------------------------------------------------------------------- /mobile/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 21 | 22 | 24 | 25 | 26 | 27 | 28 | 29 | 35 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 51 | 54 | 55 | 56 | 57 | 60 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 81 | 82 | 83 | 84 | 85 | 86 | -------------------------------------------------------------------------------- /mobile/src/main/java/layout/MycroftAppWidget.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017. Mycroft AI, Inc. 3 | * 4 | * This file is part of Mycroft-Android a client for Mycroft Core. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | package layout; 22 | 23 | import android.app.PendingIntent; 24 | import android.appwidget.AppWidgetManager; 25 | import android.appwidget.AppWidgetProvider; 26 | import android.content.ActivityNotFoundException; 27 | import android.content.Context; 28 | import android.content.Intent; 29 | import android.speech.RecognizerIntent; 30 | import android.widget.RemoteViews; 31 | import android.widget.Toast; 32 | 33 | import java.util.Locale; 34 | 35 | import mycroft.ai.MainActivity; 36 | import mycroft.ai.R; 37 | 38 | /** 39 | * Implementation of App Widget functionality. 40 | */ 41 | public class MycroftAppWidget extends AppWidgetProvider { 42 | 43 | static void updateAppWidget(Context context, AppWidgetManager appWidgetManager, int appWidgetId) { 44 | 45 | // Create an Intent to launch MainActivity 46 | Intent intent = new Intent(context, MainActivity.class); 47 | intent.putExtra("launchedFromWidget", true); 48 | intent.putExtra("autopromptForSpeech", true); 49 | PendingIntent pendingIntent = PendingIntent.getActivity(context, appWidgetId, intent, PendingIntent.FLAG_UPDATE_CURRENT); 50 | 51 | // Construct the RemoteViews object 52 | RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.mycroft_app_widget); 53 | views.setOnClickPendingIntent(R.id.appwidget_mycroft, pendingIntent); 54 | 55 | // Instruct the widget manager to update the widget 56 | appWidgetManager.updateAppWidget(appWidgetId, views); 57 | } 58 | 59 | @Override 60 | public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { 61 | // There may be multiple widgets active, so update all of them 62 | for (int appWidgetId : appWidgetIds) { 63 | updateAppWidget(context, appWidgetManager, appWidgetId); 64 | } 65 | } 66 | 67 | @Override 68 | public void onEnabled(Context context) { 69 | // Enter relevant functionality for when the first widget is created 70 | } 71 | 72 | @Override 73 | public void onDisabled(Context context) { 74 | // Enter relevant functionality for when the last widget is disabled 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /mobile/src/main/java/mycroft/ai/AppCompatPreferenceActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017. Mycroft AI, Inc. 3 | * 4 | * This file is part of Mycroft-Android a client for Mycroft Core. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | package mycroft.ai; 22 | 23 | import android.content.res.Configuration; 24 | import android.os.Bundle; 25 | import android.preference.PreferenceActivity; 26 | import android.support.annotation.LayoutRes; 27 | import android.support.annotation.Nullable; 28 | import android.support.v7.app.ActionBar; 29 | import android.support.v7.app.AppCompatDelegate; 30 | import android.support.v7.widget.Toolbar; 31 | import android.view.MenuInflater; 32 | import android.view.View; 33 | import android.view.ViewGroup; 34 | 35 | /** 36 | * A {@link android.preference.PreferenceActivity} which implements and proxies the necessary calls 37 | * to be used with AppCompat. 38 | */ 39 | public abstract class AppCompatPreferenceActivity extends PreferenceActivity { 40 | 41 | private AppCompatDelegate mDelegate; 42 | 43 | @Override 44 | protected void onCreate(Bundle savedInstanceState) { 45 | getDelegate().installViewFactory(); 46 | getDelegate().onCreate(savedInstanceState); 47 | super.onCreate(savedInstanceState); 48 | } 49 | 50 | @Override 51 | protected void onPostCreate(Bundle savedInstanceState) { 52 | super.onPostCreate(savedInstanceState); 53 | getDelegate().onPostCreate(savedInstanceState); 54 | } 55 | 56 | public ActionBar getSupportActionBar() { 57 | return getDelegate().getSupportActionBar(); 58 | } 59 | 60 | public void setSupportActionBar(@Nullable Toolbar toolbar) { 61 | getDelegate().setSupportActionBar(toolbar); 62 | } 63 | 64 | @Override 65 | public MenuInflater getMenuInflater() { 66 | return getDelegate().getMenuInflater(); 67 | } 68 | 69 | @Override 70 | public void setContentView(@LayoutRes int layoutResID) { 71 | getDelegate().setContentView(layoutResID); 72 | } 73 | 74 | @Override 75 | public void setContentView(View view) { 76 | getDelegate().setContentView(view); 77 | } 78 | 79 | @Override 80 | public void setContentView(View view, ViewGroup.LayoutParams params) { 81 | getDelegate().setContentView(view, params); 82 | } 83 | 84 | @Override 85 | public void addContentView(View view, ViewGroup.LayoutParams params) { 86 | getDelegate().addContentView(view, params); 87 | } 88 | 89 | @Override 90 | protected void onPostResume() { 91 | super.onPostResume(); 92 | getDelegate().onPostResume(); 93 | } 94 | 95 | @Override 96 | protected void onTitleChanged(CharSequence title, int color) { 97 | super.onTitleChanged(title, color); 98 | getDelegate().setTitle(title); 99 | } 100 | 101 | @Override 102 | public void onConfigurationChanged(Configuration newConfig) { 103 | super.onConfigurationChanged(newConfig); 104 | getDelegate().onConfigurationChanged(newConfig); 105 | } 106 | 107 | @Override 108 | protected void onStop() { 109 | super.onStop(); 110 | getDelegate().onStop(); 111 | } 112 | 113 | @Override 114 | protected void onDestroy() { 115 | super.onDestroy(); 116 | getDelegate().onDestroy(); 117 | } 118 | 119 | public void invalidateOptionsMenu() { 120 | getDelegate().invalidateOptionsMenu(); 121 | } 122 | 123 | private AppCompatDelegate getDelegate() { 124 | if (mDelegate == null) { 125 | mDelegate = AppCompatDelegate.create(this, null); 126 | } 127 | return mDelegate; 128 | } 129 | } 130 | -------------------------------------------------------------------------------- /mobile/src/main/java/mycroft/ai/Constants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017. Mycroft AI, Inc. 3 | * 4 | * This file is part of Mycroft-Android a client for Mycroft Core. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | package mycroft.ai; 22 | 23 | public class Constants { 24 | public static String VERSION_NAME_PREFERENCE_KEY = "versionName"; 25 | public static String VERSION_CODE_PREFERENCE_KEY = "versionCode"; 26 | } 27 | -------------------------------------------------------------------------------- /mobile/src/main/java/mycroft/ai/DiscoveryActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017. Mycroft AI, Inc. 3 | * 4 | * This file is part of Mycroft-Android a client for Mycroft Core. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | package mycroft.ai; 22 | 23 | import android.content.Context; 24 | import android.content.pm.ServiceInfo; 25 | import android.os.Bundle; 26 | import android.util.Log; 27 | 28 | import java.net.ServerSocket; 29 | 30 | 31 | import android.net.nsd.NsdManager; 32 | import android.net.nsd.NsdManager.DiscoveryListener; 33 | import android.net.nsd.NsdManager.RegistrationListener; 34 | import android.net.nsd.NsdManager.ResolveListener; 35 | import android.net.nsd.NsdServiceInfo; 36 | import android.annotation.SuppressLint; 37 | import android.app.Activity; 38 | 39 | import mycroft.ai.R; 40 | 41 | @SuppressLint("NewApi") 42 | public class DiscoveryActivity extends Activity { 43 | 44 | DiscoveryListener mDiscoveryListener; 45 | 46 | String mServiceName; 47 | NsdServiceInfo mServiceInfo; 48 | ServerSocket mServerSocket; 49 | int mLocalPort; 50 | 51 | NsdManager mNsdManager; 52 | 53 | final String TAG = "ServiceDiscovery"; 54 | final String SERVICE_TYPE = "_mycroft._tcp"; 55 | final String SERVICE_NAME = "MycroftAI Websocket"; 56 | 57 | @Override 58 | protected void onCreate(Bundle savedInstanceState) { 59 | super.onCreate(savedInstanceState); 60 | setContentView(R.layout.activity_main); 61 | 62 | mNsdManager = (NsdManager) getApplicationContext().getSystemService(Context.NSD_SERVICE); 63 | 64 | initializeDiscoveryListener(); 65 | 66 | mNsdManager.discoverServices( 67 | SERVICE_TYPE, NsdManager.PROTOCOL_DNS_SD, mDiscoveryListener); 68 | 69 | } 70 | 71 | public void initializeDiscoveryListener() { 72 | 73 | // Instantiate a new DiscoveryListener 74 | mDiscoveryListener = new NsdManager.DiscoveryListener() { 75 | 76 | // Called as soon as service discovery begins. 77 | @Override 78 | public void onDiscoveryStarted(String regType) { 79 | Log.d(TAG, "Service discovery started"); 80 | } 81 | 82 | @Override 83 | public void onServiceFound(NsdServiceInfo service) { 84 | // A service was found! Do something with it. 85 | Log.d(TAG, "Service discovery success: " + service); 86 | if (!service.getServiceType().equals(SERVICE_TYPE)) { 87 | // Service type is the string containing the protocol and 88 | // transport layer for this service. 89 | Log.d(TAG, "Mycroft found!: " + service.getServiceType() + " " + service.getHost() + " " + service.getPort()); 90 | resolveService(service); 91 | } 92 | } 93 | 94 | @Override 95 | public void onServiceLost(NsdServiceInfo service) { 96 | // When the network service is no longer available. 97 | // Internal bookkeeping code goes here. 98 | Log.e(TAG, "service lost: " + service); 99 | } 100 | 101 | @Override 102 | public void onDiscoveryStopped(String serviceType) { 103 | Log.i(TAG, "Discovery stopped: " + serviceType); 104 | } 105 | 106 | @Override 107 | public void onStartDiscoveryFailed(String serviceType, int errorCode) { 108 | Log.e(TAG, "Discovery failed: Error code: " + errorCode); 109 | mNsdManager.stopServiceDiscovery(this); 110 | } 111 | 112 | @Override 113 | public void onStopDiscoveryFailed(String serviceType, int errorCode) { 114 | Log.e(TAG, "Discovery failed: Error code: " + errorCode); 115 | mNsdManager.stopServiceDiscovery(this); 116 | } 117 | }; 118 | } 119 | 120 | private void resolveService(NsdServiceInfo service) { 121 | mNsdManager.resolveService(service, new ResolveListener() { 122 | 123 | @Override 124 | public void onServiceResolved(NsdServiceInfo serviceInfo) { 125 | Log.d(TAG, "Resolving service..."); 126 | Log.i(TAG, serviceInfo.getHost().toString()); 127 | Log.i(TAG, "Port: " + serviceInfo.getPort()); 128 | } 129 | 130 | @Override 131 | public void onResolveFailed(NsdServiceInfo serviceInfo, int errorCode) { 132 | // TODO Auto-generated method stub 133 | Log.d(TAG, "Service resolve failed!"); 134 | } 135 | }); 136 | } 137 | } -------------------------------------------------------------------------------- /mobile/src/main/java/mycroft/ai/MainActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017. Mycroft AI, Inc. 3 | * 4 | * This file is part of Mycroft-Android a client for Mycroft Core. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | package mycroft.ai; 22 | 23 | import android.content.ActivityNotFoundException; 24 | import android.content.BroadcastReceiver; 25 | import android.content.Context; 26 | import android.content.Intent; 27 | import android.content.IntentFilter; 28 | import android.content.SharedPreferences; 29 | import android.content.pm.PackageInfo; 30 | import android.content.pm.PackageManager; 31 | import android.net.Uri; 32 | import android.os.Bundle; 33 | import android.os.Handler; 34 | import android.preference.PreferenceManager; 35 | import android.speech.RecognizerIntent; 36 | import android.support.annotation.NonNull; 37 | import android.support.annotation.Nullable; 38 | import android.support.design.widget.FloatingActionButton; 39 | import android.support.v4.content.LocalBroadcastManager; 40 | import android.support.v7.app.AppCompatActivity; 41 | import android.support.v7.widget.LinearLayoutManager; 42 | import android.support.v7.widget.RecyclerView; 43 | import android.support.v7.widget.Toolbar; 44 | import android.util.Log; 45 | import android.view.Menu; 46 | import android.view.MenuItem; 47 | import android.view.View; 48 | import android.widget.CompoundButton; 49 | import android.widget.Switch; 50 | 51 | import com.crashlytics.android.Crashlytics; 52 | 53 | import org.java_websocket.client.WebSocketClient; 54 | import org.java_websocket.exceptions.WebsocketNotConnectedException; 55 | import org.java_websocket.handshake.ServerHandshake; 56 | 57 | import java.net.URI; 58 | import java.net.URISyntaxException; 59 | import java.util.ArrayList; 60 | import java.util.List; 61 | import java.util.Locale; 62 | 63 | import io.fabric.sdk.android.Fabric; 64 | import mycroft.ai.adapters.MycroftAdapter; 65 | import mycroft.ai.receivers.NetworkChangeReceiver; 66 | import mycroft.ai.shared.utilities.GuiUtilities; 67 | import mycroft.ai.shared.wear.Constants; 68 | import mycroft.ai.utils.NetworkUtil; 69 | 70 | import android.widget.CompoundButton.OnCheckedChangeListener; 71 | 72 | import static mycroft.ai.Constants.VERSION_CODE_PREFERENCE_KEY; 73 | import static mycroft.ai.Constants.VERSION_NAME_PREFERENCE_KEY; 74 | 75 | 76 | public class MainActivity extends AppCompatActivity { 77 | 78 | private static final String TAG = "Mycroft"; 79 | 80 | public WebSocketClient mWebSocketClient; 81 | private String wsip; 82 | 83 | private int maximumRetries = 1; 84 | 85 | private final int REQ_CODE_SPEECH_INPUT = 100; 86 | TTSManager ttsManager = null; 87 | private Switch voxSwitch; 88 | 89 | 90 | @NonNull 91 | private final List utterances = new ArrayList<>(); 92 | 93 | MycroftAdapter ma = new MycroftAdapter(utterances); 94 | 95 | NetworkChangeReceiver networkChangeReceiver; 96 | BroadcastReceiver wearBroadcastReceiver; 97 | 98 | private boolean isNetworkChangeReceiverRegistered; 99 | private boolean isWearBroadcastRevieverRegistered; 100 | 101 | RecyclerView recList; 102 | 103 | 104 | 105 | private SharedPreferences sharedPref; 106 | 107 | boolean launchedFromWidget = false; 108 | boolean autopromptForSpeech = false; 109 | 110 | @Override 111 | protected void onCreate(Bundle savedInstanceState) { 112 | super.onCreate(savedInstanceState); 113 | 114 | Fabric.with(this, new Crashlytics()); 115 | setContentView(R.layout.activity_main); 116 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 117 | setSupportActionBar(toolbar); 118 | 119 | FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); 120 | fab.setOnClickListener(new View.OnClickListener() { 121 | @Override 122 | public void onClick(View view) { 123 | promptSpeechInput(); 124 | } 125 | }); 126 | 127 | voxSwitch = (Switch) findViewById(R.id.voxswitch); 128 | 129 | //attach a listener to check for changes in state 130 | voxSwitch.setOnCheckedChangeListener(new OnCheckedChangeListener() { 131 | 132 | @Override 133 | public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { 134 | SharedPreferences.Editor editor = sharedPref.edit(); 135 | editor.putBoolean("appReaderSwitch", isChecked); 136 | editor.commit(); 137 | 138 | // stop tts from speaking if app reader disabled 139 | if (isChecked == false) { 140 | ttsManager.initQueue(""); 141 | } 142 | } 143 | }); 144 | 145 | recList = (RecyclerView) findViewById(R.id.cardList); 146 | recList.setHasFixedSize(true); 147 | LinearLayoutManager llm = new LinearLayoutManager(this); 148 | llm.setStackFromEnd(true); 149 | llm.setOrientation(LinearLayoutManager.VERTICAL); 150 | recList.setLayoutManager(llm); 151 | 152 | recList.setAdapter(ma); 153 | 154 | registerReceivers(); 155 | 156 | ttsManager = new TTSManager(this); 157 | 158 | // start the discovery activity (testing only) 159 | // startActivity(new Intent(this, DiscoveryActivity.class)); 160 | } 161 | 162 | @Override 163 | public boolean onCreateOptionsMenu(Menu menu) { 164 | // Inflate the menu; this adds items to the action bar if it is present. 165 | getMenuInflater().inflate(R.menu.menu_setup, menu); 166 | return true; 167 | } 168 | 169 | @Override 170 | public boolean onOptionsItemSelected(MenuItem item) { 171 | // Handle action bar item clicks here. The action bar will 172 | // automatically handle clicks on the Home/Up button, so long 173 | // as you specify a parent activity in AndroidManifest.xml. 174 | int id = item.getItemId(); 175 | 176 | boolean consumed = false; 177 | if (id == R.id.action_settings) { 178 | startActivity(new Intent(this, SettingsActivity.class)); 179 | consumed = true; 180 | } else if (id == R.id.action_home_mycroft_ai) { 181 | Intent intent= new Intent(Intent.ACTION_VIEW, Uri.parse("https://home.mycroft.ai")); 182 | startActivity(intent); 183 | } 184 | 185 | return consumed && super.onOptionsItemSelected(item); 186 | } 187 | 188 | public void connectWebSocket() { 189 | URI uri = deriveURI(); 190 | 191 | if (uri != null) { 192 | mWebSocketClient = new WebSocketClient(uri) { 193 | @Override 194 | public void onOpen(ServerHandshake serverHandshake) { 195 | Log.i("Websocket", "Opened"); 196 | } 197 | 198 | @Override 199 | public void onMessage(String s) { 200 | // Log.i(TAG, s); 201 | runOnUiThread(new MessageParser(s, new SafeCallback() { 202 | @Override 203 | public void call(@NonNull MycroftUtterances mu) { 204 | addData(mu); 205 | } 206 | })); 207 | } 208 | 209 | @Override 210 | public void onClose(int i, String s, boolean b) { 211 | Log.i("Websocket", "Closed " + s); 212 | 213 | } 214 | 215 | @Override 216 | public void onError(Exception e) { 217 | Log.i("Websocket", "Error " + e.getMessage()); 218 | } 219 | }; 220 | mWebSocketClient.connect(); 221 | } 222 | } 223 | 224 | private void addData(MycroftUtterances mu) { 225 | utterances.add(mu); 226 | ma.notifyItemInserted(utterances.size() - 1); 227 | if (voxSwitch.isChecked()) { 228 | ttsManager.addQueue(mu.utterance); 229 | } 230 | recList.smoothScrollToPosition(ma.getItemCount() - 1); 231 | } 232 | 233 | private void registerReceivers() { 234 | registerNetworkReceiver(); 235 | registerWearBroadcastReceiver(); 236 | } 237 | 238 | private void registerNetworkReceiver(){ 239 | if(!isNetworkChangeReceiverRegistered) { 240 | // set up the dynamic broadcast receiver for maintaining the socket 241 | networkChangeReceiver = new NetworkChangeReceiver(); 242 | networkChangeReceiver.setMainActivityHandler(this); 243 | 244 | // set up the intent filters 245 | IntentFilter connChange = new IntentFilter("android.net.conn.CONNECTIVITY_CHANGE"); 246 | IntentFilter wifiChange = new IntentFilter("android.net.wifi.WIFI_STATE_CHANGED"); 247 | registerReceiver(networkChangeReceiver, connChange); 248 | registerReceiver(networkChangeReceiver, wifiChange); 249 | 250 | isNetworkChangeReceiverRegistered = true; 251 | } 252 | } 253 | 254 | private void registerWearBroadcastReceiver() { 255 | if(!isWearBroadcastRevieverRegistered) { 256 | wearBroadcastReceiver = new BroadcastReceiver() { 257 | @Override 258 | public void onReceive(Context context, Intent intent) { 259 | String message = intent.getStringExtra(Constants.MYCROFT_WEAR_REQUEST_MESSAGE); 260 | // send to mycroft 261 | if(message != null) { 262 | Log.d(TAG, "Wear message received: [" + message +"] sending to Mycroft"); 263 | sendMessage(message); 264 | } 265 | } 266 | }; 267 | 268 | LocalBroadcastManager.getInstance(this).registerReceiver((wearBroadcastReceiver), new IntentFilter(Constants.MYCROFT_WEAR_REQUEST)); 269 | isWearBroadcastRevieverRegistered = true; 270 | } 271 | } 272 | 273 | private void unregisterReceivers() { 274 | unregisterBroadcastReceiver(networkChangeReceiver); 275 | unregisterBroadcastReceiver(wearBroadcastReceiver); 276 | 277 | isNetworkChangeReceiverRegistered = false; 278 | isWearBroadcastRevieverRegistered = false; 279 | } 280 | 281 | private void unregisterBroadcastReceiver(BroadcastReceiver broadcastReceiver) { 282 | LocalBroadcastManager.getInstance(this).unregisterReceiver(broadcastReceiver); 283 | } 284 | 285 | /** 286 | * This method will attach the correct path to the 287 | * {@link #wsip} hostname to allow for communication 288 | * with a Mycroft instance at that address. 289 | *

290 | * If {@link #wsip} cannot be used as a hostname 291 | * in a {@link URI} (e.g. because it's null), then 292 | * this method will return null. 293 | *

294 | * 295 | * @return a valid uri, or null 296 | */ 297 | @Nullable 298 | private URI deriveURI() { 299 | URI uri = null; 300 | 301 | if (wsip != null && !wsip.isEmpty()) { 302 | try { 303 | uri = new URI("ws://" + wsip + ":8181/core"); 304 | } catch (URISyntaxException e) { 305 | e.printStackTrace(); 306 | } 307 | } else { 308 | uri = null; 309 | } 310 | return uri; 311 | } 312 | 313 | public void sendMessage(String msg) { 314 | // let's keep it simple eh? 315 | //final String json = "{\"message_type\":\"recognizer_loop:utterance\", \"context\": null, \"metadata\": {\"utterances\": [\"" + msg + "\"]}}"; 316 | final String json = "{\"data\": {\"utterances\": [\"" + msg + "\"]}, \"type\": \"recognizer_loop:utterance\", \"context\": null}"; 317 | 318 | try { 319 | if (mWebSocketClient == null || mWebSocketClient.getConnection().isClosed()) { 320 | // try and reconnect 321 | if (NetworkUtil.getConnectivityStatus(this) == NetworkUtil.NETWORK_STATUS_WIFI) { //TODO: add config to specify wifi only. 322 | connectWebSocket(); 323 | } 324 | } 325 | 326 | Handler handler = new Handler(); 327 | handler.postDelayed(new Runnable() { 328 | public void run() { 329 | // Actions to do after 1 seconds 330 | try { 331 | mWebSocketClient.send(json); 332 | } catch (WebsocketNotConnectedException exception) { 333 | showToast(getResources().getString(R.string.websocket_closed)); 334 | } 335 | } 336 | }, 1000); 337 | 338 | } catch (WebsocketNotConnectedException exception) { 339 | showToast(getResources().getString(R.string.websocket_closed)); 340 | } 341 | } 342 | 343 | /** 344 | * Showing google speech input dialog 345 | */ 346 | private void promptSpeechInput() { 347 | Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); 348 | intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, 349 | RecognizerIntent.LANGUAGE_MODEL_FREE_FORM); 350 | intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.getDefault()); 351 | intent.putExtra(RecognizerIntent.EXTRA_PROMPT, 352 | getString(R.string.speech_prompt)); 353 | try { 354 | startActivityForResult(intent, REQ_CODE_SPEECH_INPUT); 355 | } catch (ActivityNotFoundException a) { 356 | showToast(getString(R.string.speech_not_supported)); 357 | } 358 | } 359 | 360 | /** 361 | * Receiving speech input 362 | */ 363 | @Override 364 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { 365 | super.onActivityResult(requestCode, resultCode, data); 366 | 367 | switch (requestCode) { 368 | case REQ_CODE_SPEECH_INPUT: { 369 | if (resultCode == RESULT_OK && null != data) { 370 | 371 | ArrayList result = data 372 | .getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS); 373 | 374 | sendMessage(result.get(0)); 375 | } 376 | break; 377 | } 378 | } 379 | } 380 | 381 | @Override 382 | public void onDestroy() { 383 | super.onDestroy(); 384 | ttsManager.shutDown(); 385 | isNetworkChangeReceiverRegistered = false; 386 | isWearBroadcastRevieverRegistered = false; 387 | } 388 | 389 | @Override 390 | public void onStart() { 391 | super.onStart(); 392 | loadPreferences(); 393 | recordVersionInfo(); 394 | registerReceivers(); 395 | checkIfLaunchedFromWidget(getIntent()); 396 | } 397 | 398 | @Override 399 | public void onStop() { 400 | super.onStop(); 401 | 402 | unregisterReceivers(); 403 | 404 | if (launchedFromWidget) { 405 | autopromptForSpeech = true; 406 | } 407 | } 408 | 409 | @Override 410 | protected void onNewIntent(Intent intent) { 411 | super.onNewIntent(intent); 412 | setIntent(intent); 413 | } 414 | 415 | private void loadPreferences(){ 416 | sharedPref = PreferenceManager.getDefaultSharedPreferences(this); 417 | 418 | // get mycroft-core ip address 419 | wsip = sharedPref.getString("ip", ""); 420 | if (wsip.isEmpty()) { 421 | // eep, show the settings intent! 422 | startActivity(new Intent(this, SettingsActivity.class)); 423 | } else if (mWebSocketClient == null || mWebSocketClient.getConnection().isClosed()) { 424 | connectWebSocket(); 425 | } 426 | 427 | // set app reader setting 428 | voxSwitch.setChecked(sharedPref.getBoolean("appReaderSwitch", true)); 429 | 430 | // determine if app reader should be visible 431 | if (sharedPref.getBoolean("displayAppReaderSwitch", true)) { 432 | voxSwitch.setVisibility(View.VISIBLE); 433 | } else { 434 | voxSwitch.setVisibility(View.INVISIBLE); 435 | } 436 | 437 | maximumRetries = Integer.parseInt(sharedPref.getString("maximumRetries", "1")); 438 | } 439 | 440 | protected void checkIfLaunchedFromWidget(Intent intent) { 441 | 442 | Bundle extras = getIntent().getExtras(); 443 | if (extras != null) { 444 | if (extras.containsKey("launchedFromWidget")) { 445 | launchedFromWidget = extras.getBoolean("launchedFromWidget"); 446 | autopromptForSpeech = extras.getBoolean("autopromptForSpeech"); 447 | } 448 | 449 | if (extras.containsKey(Constants.MYCROFT_WEAR_REQUEST_KEY_NAME)) { 450 | Log.d(TAG, "checkIfLaunchedFromWidget - extras contain key:" + Constants.MYCROFT_WEAR_REQUEST_KEY_NAME); 451 | sendMessage(extras.getString(Constants.MYCROFT_WEAR_REQUEST_KEY_NAME)); 452 | getIntent().removeExtra(Constants.MYCROFT_WEAR_REQUEST_KEY_NAME); 453 | 454 | } 455 | } else { 456 | Log.d(TAG, "checkIfLaunchedFromWidget - extras are null"); 457 | } 458 | 459 | if (autopromptForSpeech) { 460 | promptSpeechInput(); 461 | intent.putExtra("autopromptForSpeech", false); 462 | } 463 | } 464 | 465 | private void recordVersionInfo() { 466 | String versionName = ""; 467 | int versionCode = -1; 468 | try { 469 | PackageInfo packageInfo = getPackageManager().getPackageInfo(getPackageName(), 0); 470 | versionName = packageInfo.versionName; 471 | versionCode = packageInfo.versionCode; 472 | 473 | SharedPreferences.Editor editor = sharedPref.edit(); 474 | editor.putInt(VERSION_CODE_PREFERENCE_KEY, versionCode); 475 | editor.putString(VERSION_NAME_PREFERENCE_KEY, versionName); 476 | editor.apply(); 477 | } catch (PackageManager.NameNotFoundException e) { 478 | e.printStackTrace(); 479 | } 480 | } 481 | 482 | private void showToast(String message) { 483 | GuiUtilities.showToast(getApplicationContext(), message); 484 | } 485 | } -------------------------------------------------------------------------------- /mobile/src/main/java/mycroft/ai/MessageParser.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017. Mycroft AI, Inc. 3 | * 4 | * This file is part of Mycroft-Android a client for Mycroft Core. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | package mycroft.ai; 22 | 23 | import android.support.annotation.NonNull; 24 | import android.util.Log; 25 | 26 | import org.json.JSONException; 27 | import org.json.JSONObject; 28 | 29 | import java.util.Objects; 30 | 31 | /** 32 | * Specialised Runnable that parses the {@link JSONObject} in {@link #message} 33 | * when run. If it contains a {@link MycroftUtterances} object, the callback 34 | * defined in {@link #MessageParser(String, SafeCallback) the constructor} will 35 | * be {@link SafeCallback#call(Object) called} with that object as a parameter. 36 | *

37 | * TODO: Add error-aware callback for cases where the message is malformed. 38 | *

39 | * 40 | * @author Philip Cohn-Cort 41 | */ 42 | class MessageParser implements Runnable { 43 | 44 | private static final String TAG = "MessageParser"; 45 | 46 | @NonNull 47 | private final String message; 48 | @NonNull 49 | private final SafeCallback callback; 50 | 51 | /** 52 | * MessageParser is a simple mechanism for parsing a {@link JSONObject} out 53 | * of a String in a way conducive to scheduling. 54 | * 55 | * @param message any String. Must not be null 56 | * @param callback will be referenced if a {@link MycroftUtterances}' 57 | * {@link MycroftUtterances#utterance} 58 | * is found within the message. May not be null 59 | */ 60 | public MessageParser(@NonNull String message, @NonNull SafeCallback callback) { 61 | this.message = message; 62 | this.callback = callback; 63 | } 64 | 65 | @Override 66 | public void run() { 67 | Log.i(TAG, message); 68 | // new format 69 | // {"data": {"utterance": "There are only two hard problems in Computer Science: cache invalidation, naming things and off-by-one-errors."}, "type": "speak", "context": null} 70 | try { 71 | JSONObject obj = new JSONObject(message); 72 | String msgType = obj.optString("type"); 73 | if (Objects.equals(msgType, "speak")) { 74 | String ret = obj.getJSONObject("data").getString("utterance"); 75 | MycroftUtterances mu = new MycroftUtterances(); 76 | mu.utterance = ret; 77 | callback.call(mu); 78 | } 79 | 80 | } catch (JSONException e) { 81 | Log.w(TAG, "The response received did not conform to our expected JSON formats.", e); 82 | } 83 | 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /mobile/src/main/java/mycroft/ai/MycroftUtterances.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017. Mycroft AI, Inc. 3 | * 4 | * This file is part of Mycroft-Android a client for Mycroft Core. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | package mycroft.ai; 22 | 23 | /** 24 | * Created by paul on 2016/06/22. 25 | */ 26 | 27 | public class MycroftUtterances { 28 | 29 | public String utterance; 30 | 31 | public static final String UTTERANCE_PREFIX = "Mycroft says: "; 32 | } -------------------------------------------------------------------------------- /mobile/src/main/java/mycroft/ai/SafeCallback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017. Mycroft AI, Inc. 3 | * 4 | * This file is part of Mycroft-Android a client for Mycroft Core. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | package mycroft.ai; 22 | 23 | import android.support.annotation.NonNull; 24 | 25 | import java.util.concurrent.Callable; 26 | 27 | /** 28 | * Inversion of the {@link java.util.concurrent.Callable} interface. 29 | *

30 | * Note that the {@link #call(Object)} method in this class is 31 | * not allowed to throw exceptions. 32 | *

33 | * 34 | * @author Philip Cohn-Cort 35 | */ 36 | public interface SafeCallback { 37 | /** 38 | * Variant of {@link Callable#call()} 39 | * @param param any value. May be null. 40 | */ 41 | void call(@NonNull T param); 42 | } 43 | -------------------------------------------------------------------------------- /mobile/src/main/java/mycroft/ai/SettingsActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017. Mycroft AI, Inc. 3 | * 4 | * This file is part of Mycroft-Android a client for Mycroft Core. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | package mycroft.ai; 22 | 23 | 24 | import android.annotation.TargetApi; 25 | import android.content.Context; 26 | import android.content.Intent; 27 | import android.content.SharedPreferences; 28 | import android.content.res.Configuration; 29 | import android.media.Ringtone; 30 | import android.media.RingtoneManager; 31 | import android.net.Uri; 32 | import android.os.Build; 33 | import android.os.Bundle; 34 | import android.preference.ListPreference; 35 | import android.preference.Preference; 36 | import android.preference.PreferenceActivity; 37 | import android.support.v4.app.NavUtils; 38 | import android.support.v7.app.ActionBar; 39 | import android.preference.PreferenceFragment; 40 | import android.preference.PreferenceManager; 41 | import android.preference.RingtonePreference; 42 | import android.text.TextUtils; 43 | import android.view.MenuItem; 44 | 45 | import java.util.List; 46 | 47 | import static mycroft.ai.Constants.VERSION_CODE_PREFERENCE_KEY; 48 | import static mycroft.ai.Constants.VERSION_NAME_PREFERENCE_KEY; 49 | 50 | /** 51 | * A {@link PreferenceActivity} that presents a set of application settings. On 52 | * handset devices, settings are presented as a single list. On tablets, 53 | * settings are split by category, with category headers shown to the left of 54 | * the list of settings. 55 | *

56 | * See 57 | * Android Design: Settings for design guidelines and the Settings 59 | * API Guide for more information on developing a Settings UI. 60 | */ 61 | public class SettingsActivity extends AppCompatPreferenceActivity { 62 | /** 63 | * A preference value change listener that updates the preference's summary 64 | * to reflect its new value. 65 | */ 66 | private static Preference.OnPreferenceChangeListener sBindPreferenceSummaryToValueListener = new Preference.OnPreferenceChangeListener() { 67 | @Override 68 | public boolean onPreferenceChange(Preference preference, Object value) { 69 | String stringValue = value.toString(); 70 | 71 | if (preference instanceof ListPreference) { 72 | // For list preferences, look up the correct display value in 73 | // the preference's 'entries' list. 74 | ListPreference listPreference = (ListPreference) preference; 75 | int index = listPreference.findIndexOfValue(stringValue); 76 | 77 | // Set the summary to reflect the new value. 78 | preference.setSummary( 79 | index >= 0 80 | ? listPreference.getEntries()[index] 81 | : null); 82 | 83 | } else if (preference instanceof RingtonePreference) { 84 | // For ringtone preferences, look up the correct display value 85 | // using RingtoneManager. 86 | if (TextUtils.isEmpty(stringValue)) { 87 | // Empty values correspond to 'silent' (no ringtone). 88 | preference.setSummary(R.string.pref_ringtone_silent); 89 | 90 | } else { 91 | Ringtone ringtone = RingtoneManager.getRingtone( 92 | preference.getContext(), Uri.parse(stringValue)); 93 | 94 | if (ringtone == null) { 95 | // Clear the summary if there was a lookup error. 96 | preference.setSummary(null); 97 | } else { 98 | // Set the summary to reflect the new ringtone display 99 | // name. 100 | String name = ringtone.getTitle(preference.getContext()); 101 | preference.setSummary(name); 102 | } 103 | } 104 | 105 | } else { 106 | // For all other preferences, set the summary to the value's 107 | // simple string representation. 108 | preference.setSummary(stringValue); 109 | } 110 | return true; 111 | } 112 | }; 113 | 114 | /** 115 | * Helper method to determine if the device has an extra-large screen. For 116 | * example, 10" tablets are extra-large. 117 | */ 118 | private static boolean isXLargeTablet(Context context) { 119 | return (context.getResources().getConfiguration().screenLayout 120 | & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_XLARGE; 121 | } 122 | 123 | /** 124 | * Binds a preference's summary to its value. More specifically, when the 125 | * preference's value is changed, its summary (line of text below the 126 | * preference title) is updated to reflect the value. The summary is also 127 | * immediately updated upon calling this method. The exact display format is 128 | * dependent on the type of preference. 129 | * 130 | * @see #sBindPreferenceSummaryToValueListener 131 | */ 132 | private static void bindPreferenceSummaryToValue(Preference preference, Boolean isIntValue) { 133 | // Set the listener to watch for value changes. 134 | preference.setOnPreferenceChangeListener(sBindPreferenceSummaryToValueListener); 135 | 136 | // Trigger the listener immediately with the preference's 137 | // current value. 138 | SharedPreferences preferences = 139 | PreferenceManager.getDefaultSharedPreferences(preference.getContext()); 140 | 141 | String stringValue = ""; 142 | if (isIntValue) { 143 | stringValue = String.valueOf(preferences.getInt(preference.getKey(), 0)); 144 | } else { 145 | stringValue = preferences.getString(preference.getKey(), ""); 146 | } 147 | 148 | sBindPreferenceSummaryToValueListener.onPreferenceChange(preference, stringValue); 149 | } 150 | 151 | private static void bindPreferenceSummaryToValue(Preference preference) { 152 | bindPreferenceSummaryToValue(preference, false); 153 | } 154 | 155 | 156 | 157 | @Override 158 | protected void onCreate(Bundle savedInstanceState) { 159 | super.onCreate(savedInstanceState); 160 | setupActionBar(); 161 | } 162 | 163 | @Override 164 | public boolean onOptionsItemSelected(MenuItem item) { 165 | switch (item.getItemId()) { 166 | // Respond to the action bar's Up/Home button 167 | case android.R.id.home: 168 | NavUtils.navigateUpFromSameTask(this); 169 | return true; 170 | } 171 | return super.onOptionsItemSelected(item); 172 | } 173 | 174 | /** 175 | * Set up the {@link android.app.ActionBar}, if the API is available. 176 | */ 177 | private void setupActionBar() { 178 | ActionBar actionBar = getSupportActionBar(); 179 | if (actionBar != null) { 180 | // Show the Up button in the action bar. 181 | actionBar.setDisplayHomeAsUpEnabled(true); 182 | } 183 | } 184 | 185 | /** 186 | * {@inheritDoc} 187 | */ 188 | @Override 189 | public boolean onIsMultiPane() { 190 | return isXLargeTablet(this); 191 | } 192 | 193 | /** 194 | * {@inheritDoc} 195 | */ 196 | @Override 197 | @TargetApi(Build.VERSION_CODES.HONEYCOMB) 198 | public void onBuildHeaders(List

target) { 199 | loadHeadersFromResource(R.xml.pref_headers, target); 200 | } 201 | 202 | /** 203 | * This method stops fragment injection in malicious applications. 204 | * Make sure to deny any unknown fragments here. 205 | */ 206 | protected boolean isValidFragment(String fragmentName) { 207 | return PreferenceFragment.class.getName().equals(fragmentName) 208 | || GeneralPreferenceFragment.class.getName().equals(fragmentName) 209 | || AboutPreferenceFragment.class.getName().equals(fragmentName); 210 | } 211 | 212 | /** 213 | * This fragment shows general preferences only. It is used when the 214 | * activity is showing a two-pane settings UI. 215 | */ 216 | @TargetApi(Build.VERSION_CODES.HONEYCOMB) 217 | public static class GeneralPreferenceFragment extends PreferenceFragment { 218 | @Override 219 | public void onCreate(Bundle savedInstanceState) { 220 | super.onCreate(savedInstanceState); 221 | addPreferencesFromResource(R.xml.pref_general); 222 | setHasOptionsMenu(true); 223 | 224 | // Bind the summaries of EditText/List/Dialog/Ringtone preferences 225 | // to their values. When their values change, their summaries are 226 | // updated to reflect the new value, per the Android Design 227 | // guidelines. 228 | bindPreferenceSummaryToValue(findPreference("ip")); 229 | } 230 | 231 | @Override 232 | public boolean onOptionsItemSelected(MenuItem item) { 233 | int id = item.getItemId(); 234 | if (id == android.R.id.home) { 235 | startActivity(new Intent(getActivity(), SettingsActivity.class)); 236 | return true; 237 | } 238 | 239 | return super.onOptionsItemSelected(item); 240 | } 241 | } 242 | 243 | @TargetApi(Build.VERSION_CODES.HONEYCOMB) 244 | public static class AboutPreferenceFragment extends PreferenceFragment { 245 | @Override 246 | public void onCreate(Bundle savedInstanceState) { 247 | super.onCreate(savedInstanceState); 248 | addPreferencesFromResource(R.xml.pref_about); 249 | setHasOptionsMenu(true); 250 | 251 | bindPreferenceSummaryToValue(findPreference(VERSION_NAME_PREFERENCE_KEY)); 252 | bindPreferenceSummaryToValue(findPreference(VERSION_CODE_PREFERENCE_KEY), true); 253 | 254 | Preference licensePreference = findPreference("license"); 255 | 256 | licensePreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { 257 | @Override 258 | public boolean onPreferenceClick(Preference preference) { 259 | Intent intent= new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.gnu.org/licenses/gpl-3.0.en.html")); 260 | startActivity(intent); 261 | 262 | return true; 263 | } 264 | 265 | }); 266 | 267 | bindPreferenceSummaryToValue(licensePreference); 268 | } 269 | 270 | @Override 271 | public boolean onOptionsItemSelected(MenuItem item) { 272 | int id = item.getItemId(); 273 | if (id == android.R.id.home) { 274 | startActivity(new Intent(getActivity(), SettingsActivity.class)); 275 | return true; 276 | } 277 | 278 | return super.onOptionsItemSelected(item); 279 | } 280 | } 281 | } 282 | -------------------------------------------------------------------------------- /mobile/src/main/java/mycroft/ai/TTSManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017. Mycroft AI, Inc. 3 | * 4 | * This file is part of Mycroft-Android a client for Mycroft Core. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | package mycroft.ai; 22 | 23 | import android.app.Activity; 24 | import android.app.Service; 25 | import android.content.Context; 26 | import android.speech.tts.TextToSpeech; 27 | import android.support.annotation.NonNull; 28 | import android.support.annotation.Nullable; 29 | import android.util.Log; 30 | 31 | import java.util.Locale; 32 | 33 | 34 | /** 35 | * TTSManager is a wrapper around the Android System's Text-To-Speech ('TTS') 36 | * API. 37 | *

38 | * All constructors in this class require a context reference. 39 | * Make sure to clean up with {@link #shutDown()} when the context's 40 | * {@link Activity#onDestroy()} or {@link Service#onDestroy()} method is called. 41 | *

42 | * 43 | * @see TextToSpeech 44 | * 45 | * @author Paul Scott 46 | */ 47 | 48 | public class TTSManager { 49 | 50 | private static final String TAG = "TTSManager"; 51 | 52 | /** 53 | * Backing TTS for this instance. Should not (ever) be null. 54 | */ 55 | @NonNull 56 | private TextToSpeech mTts; 57 | /** 58 | * Whether the TTS is available for use (i.e. loaded into memory) 59 | */ 60 | private boolean isLoaded = false; 61 | 62 | /** 63 | * External listener for error and success events. May be null. 64 | */ 65 | @Nullable 66 | private TTSListener mTTSListener; 67 | 68 | /** 69 | * Create a new TTSManager attached to the given context. 70 | * 71 | * @param context any non-null context. 72 | */ 73 | protected TTSManager(@NonNull Context context) { 74 | mTts = new TextToSpeech(context, onInitListener); 75 | } 76 | 77 | /** 78 | * Special overload of constructor for testing purposes. 79 | * 80 | * @param textToSpeech the internal TTS this object will manage 81 | */ 82 | protected TTSManager(@NonNull TextToSpeech textToSpeech) { 83 | mTts = textToSpeech; 84 | } 85 | 86 | /* package local */ TextToSpeech.OnInitListener onInitListener = new TextToSpeech.OnInitListener() { 87 | @Override 88 | public void onInit(int status) { 89 | if (status == TextToSpeech.SUCCESS) { 90 | int result = mTts.setLanguage(Locale.US); 91 | isLoaded = true; 92 | Log.i(TAG, "TTS initialized"); 93 | 94 | if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) { 95 | logError("This Language is not supported"); 96 | } 97 | } else { 98 | logError("Initialization Failed!"); 99 | } 100 | } 101 | }; 102 | 103 | public void setTTSListener(TTSListener mTTSListener) { 104 | this.mTTSListener = mTTSListener; 105 | } 106 | 107 | /** 108 | * Wrapper for {@link TextToSpeech#shutdown()} 109 | */ 110 | public void shutDown() { 111 | mTts.shutdown(); 112 | } 113 | 114 | public void addQueue(String text) { 115 | if (isLoaded) 116 | mTts.speak(text, TextToSpeech.QUEUE_ADD, null); 117 | else { 118 | logError("TTS Not Initialized"); 119 | } 120 | } 121 | 122 | public void initQueue(String text) { 123 | 124 | if (isLoaded) 125 | mTts.speak(text, TextToSpeech.QUEUE_FLUSH, null); 126 | else 127 | logError("TTS Not Initialized"); 128 | } 129 | 130 | /** 131 | * Wrapper around {@link Log#e(String, String)} that also notifies 132 | * the {@link #setTTSListener(TTSListener)}, if present. 133 | * 134 | * @param msg any non-null message 135 | */ 136 | private void logError(@NonNull String msg) { 137 | if (mTTSListener != null) { 138 | mTTSListener.onError(msg); 139 | } 140 | Log.e(TAG, msg); 141 | } 142 | 143 | interface TTSListener { 144 | void onError(String message); 145 | } 146 | } 147 | -------------------------------------------------------------------------------- /mobile/src/main/java/mycroft/ai/adapters/MycroftAdapter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017. Mycroft AI, Inc. 3 | * 4 | * This file is part of Mycroft-Android a client for Mycroft Core. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | package mycroft.ai.adapters; 22 | 23 | import android.support.v7.widget.RecyclerView; 24 | import android.view.LayoutInflater; 25 | import android.view.View; 26 | import android.view.ViewGroup; 27 | import android.widget.TextView; 28 | 29 | import java.util.List; 30 | 31 | import mycroft.ai.MycroftUtterances; 32 | import mycroft.ai.R; 33 | 34 | /** 35 | * Created by paul on 2016/06/22. 36 | */ 37 | 38 | public class MycroftAdapter extends RecyclerView.Adapter { 39 | 40 | private List utteranceList; 41 | 42 | public MycroftAdapter(List utteranceList) { 43 | this.utteranceList = utteranceList; 44 | } 45 | 46 | @Override 47 | public int getItemCount() { 48 | return utteranceList.size(); 49 | } 50 | 51 | @Override 52 | public void onBindViewHolder(UtteranceViewHolder utteranceViewHolder, int i) { 53 | MycroftUtterances ci = utteranceList.get(i); 54 | utteranceViewHolder.vUtterance.setText(ci.UTTERANCE_PREFIX + " " + ci.utterance); 55 | } 56 | 57 | @Override 58 | public UtteranceViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) { 59 | View itemView = LayoutInflater. 60 | from(viewGroup.getContext()). 61 | inflate(R.layout.card_layout, viewGroup, false); 62 | 63 | return new UtteranceViewHolder(itemView); 64 | } 65 | 66 | public static class UtteranceViewHolder extends RecyclerView.ViewHolder { 67 | 68 | protected TextView vUtterance; 69 | 70 | public UtteranceViewHolder(View v) { 71 | super(v); 72 | vUtterance = (TextView) v.findViewById(R.id.utterance); 73 | } 74 | } 75 | } -------------------------------------------------------------------------------- /mobile/src/main/java/mycroft/ai/receivers/NetworkChangeReceiver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017. Mycroft AI, Inc. 3 | * 4 | * This file is part of Mycroft-Android a client for Mycroft Core. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | package mycroft.ai.receivers; 22 | 23 | import android.content.BroadcastReceiver; 24 | import android.content.Context; 25 | import android.content.Intent; 26 | import android.support.annotation.Nullable; 27 | 28 | import mycroft.ai.MainActivity; 29 | import mycroft.ai.utils.NetworkUtil; 30 | 31 | /** 32 | * Simple class to detect changes in network connectivity. 33 | *

34 | * It should trigger connection and disconnection actions 35 | * on the appropriate handler, which for now is {@link MainActivity}. 36 | *

37 | * 38 | * @see #setMainActivityHandler(MainActivity) 39 | * 40 | * @author Paul Scott 41 | */ 42 | 43 | public class NetworkChangeReceiver extends BroadcastReceiver { 44 | 45 | @Nullable 46 | private MainActivity main = null; 47 | 48 | public void setMainActivityHandler(@Nullable MainActivity main){ 49 | this.main = main; 50 | } 51 | 52 | @Override 53 | public void onReceive(final Context context, final Intent intent) { 54 | int status = NetworkUtil.getConnectivityStatusString(context); 55 | if (!"android.net.conn.CONNECTIVITY_CHANGE".equals(intent.getAction())) { 56 | if (status == NetworkUtil.NETWORK_STATUS_NOT_CONNECTED) { 57 | // do something about it.. IDK 58 | } else if (main != null) { 59 | // reconnect websocket 60 | if (main.mWebSocketClient == null || main.mWebSocketClient.getConnection().isClosed()) { 61 | main.connectWebSocket(); 62 | } 63 | } 64 | 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /mobile/src/main/java/mycroft/ai/services/MycroftWearListenerService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017. Mycroft AI, Inc. 3 | * 4 | * This file is part of Mycroft-Android a client for Mycroft Core. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | package mycroft.ai.services; 22 | 23 | import android.content.Intent; 24 | import android.support.v4.content.LocalBroadcastManager; 25 | import android.util.Log; 26 | 27 | import com.google.android.gms.wearable.MessageEvent; 28 | import com.google.android.gms.wearable.Node; 29 | import com.google.android.gms.wearable.WearableListenerService; 30 | 31 | import mycroft.ai.MainActivity; 32 | import mycroft.ai.shared.wear.Constants; 33 | 34 | 35 | /** 36 | * Created by jpoff on 9/7/2016. 37 | */ 38 | public class MycroftWearListenerService extends WearableListenerService { 39 | @Override 40 | public int onStartCommand(Intent intent, int flags, int startId) { 41 | return START_STICKY; 42 | } 43 | 44 | private static final String TAG = "Mycroft"; 45 | 46 | 47 | private LocalBroadcastManager localBroadcastManager; 48 | 49 | @Override 50 | public void onCreate() { 51 | super.onCreate(); 52 | localBroadcastManager = LocalBroadcastManager.getInstance(this); 53 | } 54 | 55 | @Override 56 | public void onMessageReceived(MessageEvent messageEvent) { 57 | 58 | String message = new String(messageEvent.getData()); 59 | 60 | if (messageEvent.getPath().equals(Constants.MYCROFT_QUERY_MESSAGE_PATH)) { 61 | Log.d(TAG, "MycroftWearRequest Message: " + message); 62 | 63 | Intent startIntent = new Intent(this, MainActivity.class); 64 | startIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 65 | startIntent.putExtra("MYCROFT_WEAR_REQUEST", message); 66 | startActivity(startIntent); 67 | 68 | handoffWearRequest(message); 69 | } 70 | } 71 | 72 | @Override 73 | public void onPeerConnected(Node node){ 74 | Log.d(TAG, "onPeerConnected"); 75 | } 76 | 77 | private void handoffWearRequest(String message) { 78 | Log.d(TAG, "Hand Off Wear Request"); 79 | 80 | if (message != null) { 81 | Intent intent = new Intent(Constants.MYCROFT_WEAR_REQUEST); 82 | intent.putExtra(Constants.MYCROFT_WEAR_REQUEST_MESSAGE, message); 83 | localBroadcastManager.sendBroadcast(intent); 84 | } 85 | } 86 | } 87 | 88 | 89 | -------------------------------------------------------------------------------- /mobile/src/main/java/mycroft/ai/utils/NetworkAutoDiscoveryUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017. Mycroft AI, Inc. 3 | * 4 | * This file is part of Mycroft-Android a client for Mycroft Core. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | package mycroft.ai.utils; 22 | 23 | import android.content.Context; 24 | import android.net.nsd.NsdServiceInfo; 25 | import android.net.nsd.NsdManager; 26 | import android.util.Log; 27 | 28 | /** 29 | * Created by paul on 2016/06/28. 30 | */ 31 | public class NetworkAutoDiscoveryUtil { 32 | 33 | private static final String TAG = "NetworkDiscovery"; 34 | private static final String SERVICE_TYPE = " _mycroft._tcp"; 35 | private String mServiceName = "MycroftAI Websocket"; 36 | private NsdServiceInfo mService; 37 | 38 | Context mContext; 39 | NsdManager mNsdManager; 40 | NsdManager.ResolveListener mResolveListener; 41 | NsdManager.DiscoveryListener mDiscoveryListener; 42 | NsdManager.RegistrationListener mRegistrationListener; 43 | 44 | 45 | public NetworkAutoDiscoveryUtil(Context context) { 46 | mContext = context; 47 | mNsdManager = (NsdManager) context.getSystemService(Context.NSD_SERVICE); 48 | } 49 | 50 | public void initializeNsd() { 51 | initializeResolveListener(); 52 | //mNsdManager.init(mContext.getMainLooper(), this); 53 | } 54 | 55 | public void initializeDiscoveryListener() { 56 | mDiscoveryListener = new NsdManager.DiscoveryListener() { 57 | @Override 58 | public void onDiscoveryStarted(String regType) { 59 | Log.d(TAG, "Service discovery started"); 60 | } 61 | 62 | @Override 63 | public void onServiceFound(NsdServiceInfo service) { 64 | Log.d(TAG, "Service discovery success" + service); 65 | if (!service.getServiceType().equals(SERVICE_TYPE)) { 66 | Log.d(TAG, "Unknown Service Type: " + service.getServiceType()); 67 | } else if (service.getServiceName().equals(mServiceName)) { 68 | Log.d(TAG, "Same machine: " + mServiceName); 69 | } else if (service.getServiceName().contains(mServiceName)) { 70 | mNsdManager.resolveService(service, mResolveListener); 71 | } 72 | } 73 | 74 | @Override 75 | public void onServiceLost(NsdServiceInfo service) { 76 | Log.e(TAG, "service lost" + service); 77 | if (mService == service) { 78 | mService = null; 79 | } 80 | } 81 | 82 | @Override 83 | public void onDiscoveryStopped(String serviceType) { 84 | Log.i(TAG, "Discovery stopped: " + serviceType); 85 | } 86 | 87 | @Override 88 | public void onStartDiscoveryFailed(String serviceType, int errorCode) { 89 | Log.e(TAG, "Discovery failed: Error code:" + errorCode); 90 | } 91 | 92 | @Override 93 | public void onStopDiscoveryFailed(String serviceType, int errorCode) { 94 | Log.e(TAG, "Discovery failed: Error code:" + errorCode); 95 | } 96 | }; 97 | } 98 | 99 | public void initializeResolveListener() { 100 | mResolveListener = new NsdManager.ResolveListener() { 101 | @Override 102 | public void onResolveFailed(NsdServiceInfo serviceInfo, int errorCode) { 103 | Log.e(TAG, "Resolve failed" + errorCode); 104 | } 105 | 106 | @Override 107 | public void onServiceResolved(NsdServiceInfo serviceInfo) { 108 | Log.e(TAG, "Resolve Succeeded. " + serviceInfo); 109 | if (serviceInfo.getServiceName().equals(mServiceName)) { 110 | Log.d(TAG, "Same IP."); 111 | return; 112 | } 113 | mService = serviceInfo; 114 | } 115 | }; 116 | } 117 | 118 | public void initializeRegistrationListener() { 119 | mRegistrationListener = new NsdManager.RegistrationListener() { 120 | @Override 121 | public void onServiceRegistered(NsdServiceInfo NsdServiceInfo) { 122 | mServiceName = NsdServiceInfo.getServiceName(); 123 | Log.d(TAG, "Service registered: " + mServiceName); 124 | } 125 | 126 | @Override 127 | public void onRegistrationFailed(NsdServiceInfo arg0, int arg1) { 128 | Log.d(TAG, "Service registration failed: " + arg1); 129 | } 130 | 131 | @Override 132 | public void onServiceUnregistered(NsdServiceInfo arg0) { 133 | Log.d(TAG, "Service unregistered: " + arg0.getServiceName()); 134 | } 135 | 136 | @Override 137 | public void onUnregistrationFailed(NsdServiceInfo serviceInfo, int errorCode) { 138 | Log.d(TAG, "Service unregistration failed: " + errorCode); 139 | } 140 | }; 141 | } 142 | 143 | public void registerService(int port) { 144 | tearDown(); // Cancel any previous registration request 145 | initializeRegistrationListener(); 146 | NsdServiceInfo serviceInfo = new NsdServiceInfo(); 147 | serviceInfo.setPort(port); 148 | serviceInfo.setServiceName(mServiceName); 149 | serviceInfo.setServiceType(SERVICE_TYPE); 150 | mNsdManager.registerService( 151 | serviceInfo, NsdManager.PROTOCOL_DNS_SD, mRegistrationListener); 152 | } 153 | 154 | public void discoverServices() { 155 | stopDiscovery(); // Cancel any existing discovery request 156 | initializeDiscoveryListener(); 157 | mNsdManager.discoverServices( 158 | SERVICE_TYPE, NsdManager.PROTOCOL_DNS_SD, mDiscoveryListener); 159 | } 160 | 161 | public void stopDiscovery() { 162 | if (mDiscoveryListener != null) { 163 | try { 164 | mNsdManager.stopServiceDiscovery(mDiscoveryListener); 165 | } finally { 166 | } 167 | mDiscoveryListener = null; 168 | } 169 | } 170 | 171 | public NsdServiceInfo getChosenServiceInfo() { 172 | return mService; 173 | } 174 | 175 | public void tearDown() { 176 | if (mRegistrationListener != null) { 177 | try { 178 | mNsdManager.unregisterService(mRegistrationListener); 179 | } finally { 180 | } 181 | mRegistrationListener = null; 182 | } 183 | } 184 | } 185 | -------------------------------------------------------------------------------- /mobile/src/main/java/mycroft/ai/utils/NetworkUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017. Mycroft AI, Inc. 3 | * 4 | * This file is part of Mycroft-Android a client for Mycroft Core. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | package mycroft.ai.utils; 22 | 23 | import android.content.Context; 24 | import android.net.ConnectivityManager; 25 | import android.net.NetworkInfo; 26 | 27 | /** 28 | * Created by paul on 2016/06/22. 29 | */ 30 | 31 | public class NetworkUtil { 32 | 33 | public static int TYPE_WIFI = 1; 34 | public static int TYPE_MOBILE = 2; 35 | public static int TYPE_NOT_CONNECTED = 0; 36 | public static final int NETWORK_STATUS_NOT_CONNECTED = 0, NETWORK_STATUS_WIFI = 1, NETWORK_STATUS_MOBILE = 2; 37 | 38 | public static int getConnectivityStatus(Context context) { 39 | ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); 40 | 41 | NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); 42 | if (null != activeNetwork) { 43 | if (activeNetwork.getType() == ConnectivityManager.TYPE_WIFI) 44 | return TYPE_WIFI; 45 | 46 | if (activeNetwork.getType() == ConnectivityManager.TYPE_MOBILE) 47 | return TYPE_MOBILE; 48 | } 49 | return TYPE_NOT_CONNECTED; 50 | } 51 | 52 | public static int getConnectivityStatusString(Context context) { 53 | int conn = NetworkUtil.getConnectivityStatus(context); 54 | int status = 0; 55 | 56 | if (conn == NetworkUtil.TYPE_WIFI) { 57 | status = NETWORK_STATUS_WIFI; 58 | } else if (conn == NetworkUtil.TYPE_MOBILE) { 59 | status = NETWORK_STATUS_MOBILE; 60 | } else if (conn == NetworkUtil.TYPE_NOT_CONNECTED) { 61 | status = NETWORK_STATUS_NOT_CONNECTED; 62 | } 63 | return status; 64 | } 65 | } -------------------------------------------------------------------------------- /mobile/src/main/java/mycroft/ai/utils/PlayServicesUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017. Mycroft AI, Inc. 3 | * 4 | * This file is part of Mycroft-Android a client for Mycroft Core. 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | package mycroft.ai.utils; 22 | 23 | import android.content.Context; 24 | import com.google.android.gms.common.ConnectionResult; 25 | import com.google.android.gms.common.GoogleApiAvailability; 26 | 27 | 28 | /** 29 | * Created by pscot on 6/25/2016. 30 | */ 31 | public class PlayServicesUtil { 32 | 33 | private boolean psInstalled; 34 | 35 | private static final int PLAY_SERVICES_RESOLUTION_REQUEST = 9000; 36 | private static final String TAG = "PlayServicesUtil"; 37 | 38 | private Context context; 39 | 40 | public PlayServicesUtil(Context context) { 41 | this.context = context; 42 | psInstalled = checkPlayServices(); 43 | } 44 | 45 | public boolean isPsInstalled() { 46 | return psInstalled; 47 | } 48 | 49 | /** 50 | * Check the device to make sure it has the Google Play Services APK. If 51 | * it doesn't, display a dialog that allows users to download the APK from 52 | * the Google Play Store or enable it in the device's system settings. 53 | */ 54 | private boolean checkPlayServices() { 55 | GoogleApiAvailability apiAvailability = GoogleApiAvailability.getInstance(); 56 | int resultCode = apiAvailability.isGooglePlayServicesAvailable(context.getApplicationContext()); 57 | if (resultCode != ConnectionResult.SUCCESS) { 58 | return false; 59 | } 60 | return true; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /mobile/src/main/res/drawable-hdpi/ic_mycroft.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/seymour-bootay/Mycroft-Android/67e830987bf6d04d93a5c306d31df04c565119f4/mobile/src/main/res/drawable-hdpi/ic_mycroft.png -------------------------------------------------------------------------------- /mobile/src/main/res/drawable-mdpi/ic_mycroft.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/seymour-bootay/Mycroft-Android/67e830987bf6d04d93a5c306d31df04c565119f4/mobile/src/main/res/drawable-mdpi/ic_mycroft.png -------------------------------------------------------------------------------- /mobile/src/main/res/drawable-xhdpi/ic_mycroft.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/seymour-bootay/Mycroft-Android/67e830987bf6d04d93a5c306d31df04c565119f4/mobile/src/main/res/drawable-xhdpi/ic_mycroft.png -------------------------------------------------------------------------------- /mobile/src/main/res/drawable-xxhdpi/ic_mycroft.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/seymour-bootay/Mycroft-Android/67e830987bf6d04d93a5c306d31df04c565119f4/mobile/src/main/res/drawable-xxhdpi/ic_mycroft.png -------------------------------------------------------------------------------- /mobile/src/main/res/drawable/ic_info_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 20 | 21 | 26 | 29 | 30 | -------------------------------------------------------------------------------- /mobile/src/main/res/drawable/ic_notifications_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 20 | 21 | 26 | 29 | 30 | -------------------------------------------------------------------------------- /mobile/src/main/res/drawable/ic_sync_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 20 | 21 | 26 | 29 | -------------------------------------------------------------------------------- /mobile/src/main/res/drawable/mycroft_big.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/seymour-bootay/Mycroft-Android/67e830987bf6d04d93a5c306d31df04c565119f4/mobile/src/main/res/drawable/mycroft_big.png -------------------------------------------------------------------------------- /mobile/src/main/res/drawable/mycroft_logo_24dp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/seymour-bootay/Mycroft-Android/67e830987bf6d04d93a5c306d31df04c565119f4/mobile/src/main/res/drawable/mycroft_logo_24dp.png -------------------------------------------------------------------------------- /mobile/src/main/res/layout/activity_discovery.xml: -------------------------------------------------------------------------------- 1 | 2 | 21 | 22 | 26 | 31 |