From: rtrimana Date: Mon, 30 Jul 2018 22:23:57 +0000 (-0700) Subject: The final version for lede-gui (the phone app for device registration) X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=0a970a0f6bbbb39b5b0a799ff60671421b1c1806;p=iot2.git The final version for lede-gui (the phone app for device registration) --- diff --git a/others/lede-gui/.gitignore b/others/lede-gui/.gitignore index 3543521..1f57ea9 100644 --- a/others/lede-gui/.gitignore +++ b/others/lede-gui/.gitignore @@ -1 +1,21 @@ /build +# built application files +*.apk +*.ap_ + +# files for the dex VM +*.dex + +# Java class files +*.class + +# generated files +bin/ +gen/ + +# Local configuration file (sdk path, etc) +local.properties + +.gradle +.iml +.idea \ No newline at end of file diff --git a/others/lede-gui/.gradle/3.3/taskArtifacts/fileHashes.bin b/others/lede-gui/.gradle/3.3/taskArtifacts/fileHashes.bin deleted file mode 100644 index 14472c9..0000000 Binary files a/others/lede-gui/.gradle/3.3/taskArtifacts/fileHashes.bin and /dev/null differ diff --git a/others/lede-gui/.gradle/3.3/taskArtifacts/fileSnapshots.bin b/others/lede-gui/.gradle/3.3/taskArtifacts/fileSnapshots.bin deleted file mode 100644 index c27ddb0..0000000 Binary files a/others/lede-gui/.gradle/3.3/taskArtifacts/fileSnapshots.bin and /dev/null differ diff --git a/others/lede-gui/.gradle/3.3/taskArtifacts/taskArtifacts.bin b/others/lede-gui/.gradle/3.3/taskArtifacts/taskArtifacts.bin deleted file mode 100644 index f1a6c2c..0000000 Binary files a/others/lede-gui/.gradle/3.3/taskArtifacts/taskArtifacts.bin and /dev/null differ diff --git a/others/lede-gui/.gradle/3.3/taskArtifacts/taskArtifacts.lock b/others/lede-gui/.gradle/3.3/taskArtifacts/taskArtifacts.lock deleted file mode 100644 index 9c87ff1..0000000 Binary files a/others/lede-gui/.gradle/3.3/taskArtifacts/taskArtifacts.lock and /dev/null differ diff --git a/others/lede-gui/.gradle/3.3/tasks/_compileDebugJavaWithJavac/localClassSetAnalysis/localClassSetAnalysis.bin b/others/lede-gui/.gradle/3.3/tasks/_compileDebugJavaWithJavac/localClassSetAnalysis/localClassSetAnalysis.bin deleted file mode 100644 index 7034f06..0000000 Binary files a/others/lede-gui/.gradle/3.3/tasks/_compileDebugJavaWithJavac/localClassSetAnalysis/localClassSetAnalysis.bin and /dev/null differ diff --git a/others/lede-gui/.gradle/3.3/tasks/_compileDebugJavaWithJavac/localClassSetAnalysis/localClassSetAnalysis.lock b/others/lede-gui/.gradle/3.3/tasks/_compileDebugJavaWithJavac/localClassSetAnalysis/localClassSetAnalysis.lock deleted file mode 100644 index 737c618..0000000 Binary files a/others/lede-gui/.gradle/3.3/tasks/_compileDebugJavaWithJavac/localClassSetAnalysis/localClassSetAnalysis.lock and /dev/null differ diff --git a/others/lede-gui/.gradle/3.3/tasks/_compileDebugJavaWithJavac/localJarClasspathSnapshot/localJarClasspathSnapshot.bin b/others/lede-gui/.gradle/3.3/tasks/_compileDebugJavaWithJavac/localJarClasspathSnapshot/localJarClasspathSnapshot.bin deleted file mode 100644 index fb93f2d..0000000 Binary files a/others/lede-gui/.gradle/3.3/tasks/_compileDebugJavaWithJavac/localJarClasspathSnapshot/localJarClasspathSnapshot.bin and /dev/null differ diff --git a/others/lede-gui/.gradle/3.3/tasks/_compileDebugJavaWithJavac/localJarClasspathSnapshot/localJarClasspathSnapshot.lock b/others/lede-gui/.gradle/3.3/tasks/_compileDebugJavaWithJavac/localJarClasspathSnapshot/localJarClasspathSnapshot.lock deleted file mode 100644 index 560430c..0000000 Binary files a/others/lede-gui/.gradle/3.3/tasks/_compileDebugJavaWithJavac/localJarClasspathSnapshot/localJarClasspathSnapshot.lock and /dev/null differ diff --git a/others/lede-gui/.idea/compiler.xml b/others/lede-gui/.idea/compiler.xml deleted file mode 100644 index 96cc43e..0000000 --- a/others/lede-gui/.idea/compiler.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/others/lede-gui/.idea/copyright/profiles_settings.xml b/others/lede-gui/.idea/copyright/profiles_settings.xml deleted file mode 100644 index c7d1c5a..0000000 --- a/others/lede-gui/.idea/copyright/profiles_settings.xml +++ /dev/null @@ -1,3 +0,0 @@ - - - \ No newline at end of file diff --git a/others/lede-gui/.idea/gradle.xml b/others/lede-gui/.idea/gradle.xml deleted file mode 100644 index 47bd81f..0000000 --- a/others/lede-gui/.idea/gradle.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/others/lede-gui/.idea/libraries/animated_vector_drawable_26_0_0_alpha1.xml b/others/lede-gui/.idea/libraries/animated_vector_drawable_26_0_0_alpha1.xml deleted file mode 100644 index 37594df..0000000 --- a/others/lede-gui/.idea/libraries/animated_vector_drawable_26_0_0_alpha1.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file diff --git a/others/lede-gui/.idea/libraries/appcompat_v7_26_0_0_alpha1.xml b/others/lede-gui/.idea/libraries/appcompat_v7_26_0_0_alpha1.xml deleted file mode 100644 index ff5b26d..0000000 --- a/others/lede-gui/.idea/libraries/appcompat_v7_26_0_0_alpha1.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file diff --git a/others/lede-gui/.idea/libraries/constraint_layout_1_0_2.xml b/others/lede-gui/.idea/libraries/constraint_layout_1_0_2.xml deleted file mode 100644 index 83b382d..0000000 --- a/others/lede-gui/.idea/libraries/constraint_layout_1_0_2.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/others/lede-gui/.idea/libraries/constraint_layout_solver_1_0_2.xml b/others/lede-gui/.idea/libraries/constraint_layout_solver_1_0_2.xml deleted file mode 100644 index f71d1a6..0000000 --- a/others/lede-gui/.idea/libraries/constraint_layout_solver_1_0_2.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/others/lede-gui/.idea/libraries/design_26_0_0_alpha1.xml b/others/lede-gui/.idea/libraries/design_26_0_0_alpha1.xml deleted file mode 100644 index ac70c61..0000000 --- a/others/lede-gui/.idea/libraries/design_26_0_0_alpha1.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file diff --git a/others/lede-gui/.idea/libraries/espresso_core_2_2_2.xml b/others/lede-gui/.idea/libraries/espresso_core_2_2_2.xml deleted file mode 100644 index 9113cc7..0000000 --- a/others/lede-gui/.idea/libraries/espresso_core_2_2_2.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file diff --git a/others/lede-gui/.idea/libraries/espresso_idling_resource_2_2_2.xml b/others/lede-gui/.idea/libraries/espresso_idling_resource_2_2_2.xml deleted file mode 100644 index 69cf85a..0000000 --- a/others/lede-gui/.idea/libraries/espresso_idling_resource_2_2_2.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file diff --git a/others/lede-gui/.idea/libraries/exposed_instrumentation_api_publish_0_5.xml b/others/lede-gui/.idea/libraries/exposed_instrumentation_api_publish_0_5.xml deleted file mode 100644 index de3e1d7..0000000 --- a/others/lede-gui/.idea/libraries/exposed_instrumentation_api_publish_0_5.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file diff --git a/others/lede-gui/.idea/libraries/hamcrest_core_1_3.xml b/others/lede-gui/.idea/libraries/hamcrest_core_1_3.xml deleted file mode 100644 index 157e3f3..0000000 --- a/others/lede-gui/.idea/libraries/hamcrest_core_1_3.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/others/lede-gui/.idea/libraries/hamcrest_integration_1_3.xml b/others/lede-gui/.idea/libraries/hamcrest_integration_1_3.xml deleted file mode 100644 index 58b2c4b..0000000 --- a/others/lede-gui/.idea/libraries/hamcrest_integration_1_3.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/others/lede-gui/.idea/libraries/hamcrest_library_1_3.xml b/others/lede-gui/.idea/libraries/hamcrest_library_1_3.xml deleted file mode 100644 index 676cc63..0000000 --- a/others/lede-gui/.idea/libraries/hamcrest_library_1_3.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/others/lede-gui/.idea/libraries/javawriter_2_1_1.xml b/others/lede-gui/.idea/libraries/javawriter_2_1_1.xml deleted file mode 100644 index a66fefb..0000000 --- a/others/lede-gui/.idea/libraries/javawriter_2_1_1.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/others/lede-gui/.idea/libraries/javax_annotation_api_1_2.xml b/others/lede-gui/.idea/libraries/javax_annotation_api_1_2.xml deleted file mode 100644 index 811e73f..0000000 --- a/others/lede-gui/.idea/libraries/javax_annotation_api_1_2.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/others/lede-gui/.idea/libraries/javax_inject_1.xml b/others/lede-gui/.idea/libraries/javax_inject_1.xml deleted file mode 100644 index 0d1d5fc..0000000 --- a/others/lede-gui/.idea/libraries/javax_inject_1.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/others/lede-gui/.idea/libraries/jsch_0_1_54.xml b/others/lede-gui/.idea/libraries/jsch_0_1_54.xml deleted file mode 100644 index 803717f..0000000 --- a/others/lede-gui/.idea/libraries/jsch_0_1_54.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/others/lede-gui/.idea/libraries/jsr305_2_0_1.xml b/others/lede-gui/.idea/libraries/jsr305_2_0_1.xml deleted file mode 100644 index cdf9878..0000000 --- a/others/lede-gui/.idea/libraries/jsr305_2_0_1.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/others/lede-gui/.idea/libraries/junit_4_12.xml b/others/lede-gui/.idea/libraries/junit_4_12.xml deleted file mode 100644 index 305df30..0000000 --- a/others/lede-gui/.idea/libraries/junit_4_12.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/others/lede-gui/.idea/libraries/recyclerview_v7_26_0_0_alpha1.xml b/others/lede-gui/.idea/libraries/recyclerview_v7_26_0_0_alpha1.xml deleted file mode 100644 index fb50ff2..0000000 --- a/others/lede-gui/.idea/libraries/recyclerview_v7_26_0_0_alpha1.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file diff --git a/others/lede-gui/.idea/libraries/rules_0_5.xml b/others/lede-gui/.idea/libraries/rules_0_5.xml deleted file mode 100644 index 91e07ed..0000000 --- a/others/lede-gui/.idea/libraries/rules_0_5.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file diff --git a/others/lede-gui/.idea/libraries/runner_0_5.xml b/others/lede-gui/.idea/libraries/runner_0_5.xml deleted file mode 100644 index 4c2562f..0000000 --- a/others/lede-gui/.idea/libraries/runner_0_5.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file diff --git a/others/lede-gui/.idea/libraries/support_annotations_26_0_0_alpha1.xml b/others/lede-gui/.idea/libraries/support_annotations_26_0_0_alpha1.xml deleted file mode 100644 index 44566c5..0000000 --- a/others/lede-gui/.idea/libraries/support_annotations_26_0_0_alpha1.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/others/lede-gui/.idea/libraries/support_compat_26_0_0_alpha1.xml b/others/lede-gui/.idea/libraries/support_compat_26_0_0_alpha1.xml deleted file mode 100644 index 5507d57..0000000 --- a/others/lede-gui/.idea/libraries/support_compat_26_0_0_alpha1.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file diff --git a/others/lede-gui/.idea/libraries/support_core_ui_26_0_0_alpha1.xml b/others/lede-gui/.idea/libraries/support_core_ui_26_0_0_alpha1.xml deleted file mode 100644 index 5ad1369..0000000 --- a/others/lede-gui/.idea/libraries/support_core_ui_26_0_0_alpha1.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file diff --git a/others/lede-gui/.idea/libraries/support_core_utils_26_0_0_alpha1.xml b/others/lede-gui/.idea/libraries/support_core_utils_26_0_0_alpha1.xml deleted file mode 100644 index 07958bb..0000000 --- a/others/lede-gui/.idea/libraries/support_core_utils_26_0_0_alpha1.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file diff --git a/others/lede-gui/.idea/libraries/support_fragment_26_0_0_alpha1.xml b/others/lede-gui/.idea/libraries/support_fragment_26_0_0_alpha1.xml deleted file mode 100644 index 520ccd2..0000000 --- a/others/lede-gui/.idea/libraries/support_fragment_26_0_0_alpha1.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file diff --git a/others/lede-gui/.idea/libraries/support_media_compat_26_0_0_alpha1.xml b/others/lede-gui/.idea/libraries/support_media_compat_26_0_0_alpha1.xml deleted file mode 100644 index cc2ac96..0000000 --- a/others/lede-gui/.idea/libraries/support_media_compat_26_0_0_alpha1.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file diff --git a/others/lede-gui/.idea/libraries/support_v4_26_0_0_alpha1.xml b/others/lede-gui/.idea/libraries/support_v4_26_0_0_alpha1.xml deleted file mode 100644 index 669a0bd..0000000 --- a/others/lede-gui/.idea/libraries/support_v4_26_0_0_alpha1.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file diff --git a/others/lede-gui/.idea/libraries/support_vector_drawable_26_0_0_alpha1.xml b/others/lede-gui/.idea/libraries/support_vector_drawable_26_0_0_alpha1.xml deleted file mode 100644 index dfe14f4..0000000 --- a/others/lede-gui/.idea/libraries/support_vector_drawable_26_0_0_alpha1.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file diff --git a/others/lede-gui/.idea/libraries/transition_26_0_0_alpha1.xml b/others/lede-gui/.idea/libraries/transition_26_0_0_alpha1.xml deleted file mode 100644 index 49ecf0a..0000000 --- a/others/lede-gui/.idea/libraries/transition_26_0_0_alpha1.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file diff --git a/others/lede-gui/.idea/misc.xml b/others/lede-gui/.idea/misc.xml deleted file mode 100644 index b0a270f..0000000 --- a/others/lede-gui/.idea/misc.xml +++ /dev/null @@ -1,36 +0,0 @@ - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/others/lede-gui/.idea/modules.xml b/others/lede-gui/.idea/modules.xml deleted file mode 100644 index e45091c..0000000 --- a/others/lede-gui/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/others/lede-gui/.idea/runConfigurations.xml b/others/lede-gui/.idea/runConfigurations.xml deleted file mode 100644 index 7f68460..0000000 --- a/others/lede-gui/.idea/runConfigurations.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/others/lede-gui/.idea/workspace.xml b/others/lede-gui/.idea/workspace.xml deleted file mode 100644 index e8ea71d..0000000 --- a/others/lede-gui/.idea/workspace.xml +++ /dev/null @@ -1,2412 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1501629053988 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/others/lede-gui/User Manual-Documentation/Edit of Vigilia User Manual.pdf b/others/lede-gui/User Manual-Documentation/Edit of Vigilia User Manual.pdf new file mode 100644 index 0000000..7df2f7f Binary files /dev/null and b/others/lede-gui/User Manual-Documentation/Edit of Vigilia User Manual.pdf differ diff --git a/others/lede-gui/git.iml b/others/lede-gui/git.iml new file mode 100644 index 0000000..cfb181f --- /dev/null +++ b/others/lede-gui/git.iml @@ -0,0 +1,139 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/others/lede-gui/gradle/wrapper/gradle-wrapper.properties b/others/lede-gui/gradle/wrapper/gradle-wrapper.properties index b483d86..9ff7dc9 100644 --- a/others/lede-gui/gradle/wrapper/gradle-wrapper.properties +++ b/others/lede-gui/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Wed Sep 20 13:44:40 PDT 2017 -distributionBase=GRADLE_USER_HOME -distributionPath=wrapper/dists -zipStoreBase=GRADLE_USER_HOME -zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip +#Wed Sep 20 13:44:40 PDT 2017 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip diff --git a/others/lede-gui/gradlew b/others/lede-gui/gradlew index 9d82f78..e834973 100644 --- a/others/lede-gui/gradlew +++ b/others/lede-gui/gradlew @@ -1,160 +1,160 @@ -#!/usr/bin/env bash - -############################################################################## -## -## Gradle start up script for UN*X -## -############################################################################## - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS="" - -APP_NAME="Gradle" -APP_BASE_NAME=`basename "$0"` - -# Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD="maximum" - -warn ( ) { - echo "$*" -} - -die ( ) { - echo - echo "$*" - echo - exit 1 -} - -# OS specific support (must be 'true' or 'false'). -cygwin=false -msys=false -darwin=false -case "`uname`" in - CYGWIN* ) - cygwin=true - ;; - Darwin* ) - darwin=true - ;; - MINGW* ) - msys=true - ;; -esac - -# Attempt to set APP_HOME -# Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi -done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >/dev/null -APP_HOME="`pwd -P`" -cd "$SAVED" >/dev/null - -CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar - -# Determine the Java command to use to start the JVM. -if [ -n "$JAVA_HOME" ] ; then - if [ -x "$JAVA_HOME/jre/sh/java" ] ; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" - else - JAVACMD="$JAVA_HOME/bin/java" - fi - if [ ! -x "$JAVACMD" ] ; then - die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." - fi -else - JAVACMD="java" - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." -fi - -# Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then - MAX_FD_LIMIT=`ulimit -H -n` - if [ $? -eq 0 ] ; then - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then - MAX_FD="$MAX_FD_LIMIT" - fi - ulimit -n $MAX_FD - if [ $? -ne 0 ] ; then - warn "Could not set maximum file descriptor limit: $MAX_FD" - fi - else - warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" - fi -fi - -# For Darwin, add options to specify how the application appears in the dock -if $darwin; then - GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" -fi - -# For Cygwin, switch paths to Windows format before running java -if $cygwin ; then - APP_HOME=`cygpath --path --mixed "$APP_HOME"` - CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - JAVACMD=`cygpath --unix "$JAVACMD"` - - # We build the pattern for arguments to be converted via cygpath - ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` - SEP="" - for dir in $ROOTDIRSRAW ; do - ROOTDIRS="$ROOTDIRS$SEP$dir" - SEP="|" - done - OURCYGPATTERN="(^($ROOTDIRS))" - # Add a user-defined pattern to the cygpath arguments - if [ "$GRADLE_CYGPATTERN" != "" ] ; then - OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" - fi - # Now convert the arguments - kludge to limit ourselves to /bin/sh - i=0 - for arg in "$@" ; do - CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` - CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option - - if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition - eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` - else - eval `echo args$i`="\"$arg\"" - fi - i=$((i+1)) - done - case $i in - (0) set -- ;; - (1) set -- "$args0" ;; - (2) set -- "$args0" "$args1" ;; - (3) set -- "$args0" "$args1" "$args2" ;; - (4) set -- "$args0" "$args1" "$args2" "$args3" ;; - (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; - esac -fi - -# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules -function splitJvmOpts() { - JVM_OPTS=("$@") -} -eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS -JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" - -exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" +#!/usr/bin/env bash + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn ( ) { + echo "$*" +} + +die ( ) { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; +esac + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules +function splitJvmOpts() { + JVM_OPTS=("$@") +} +eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS +JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" + +exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" diff --git a/others/lede-gui/lede-gui.iml b/others/lede-gui/lede-gui.iml index 6e6cf73..3c02267 100644 --- a/others/lede-gui/lede-gui.iml +++ b/others/lede-gui/lede-gui.iml @@ -1,136 +1,132 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/others/lede-gui/local.properties b/others/lede-gui/local.properties deleted file mode 100644 index 35ebc26..0000000 --- a/others/lede-gui/local.properties +++ /dev/null @@ -1,11 +0,0 @@ -## This file is automatically generated by Android Studio. -# Do not modify this file -- YOUR CHANGES WILL BE ERASED! -# -# This file must *NOT* be checked into Version Control Systems, -# as it contains information specific to your local configuration. -# -# Location of the SDK. This is only used by Gradle. -# For customization when using a Version Control System, please read the -# header note. -#Wed Sep 20 12:05:53 PDT 2017 -sdk.dir=/home/rtrimana/Android/Sdk diff --git a/others/lede-gui/src/main/AndroidManifest.xml b/others/lede-gui/src/main/AndroidManifest.xml index c51ae23..0dd771e 100644 --- a/others/lede-gui/src/main/AndroidManifest.xml +++ b/others/lede-gui/src/main/AndroidManifest.xml @@ -9,7 +9,7 @@ - - + - + + + + + + + + + + + + + + + + + + + + + + + + android:theme="@style/AppTheme.NoActionBar"/> \ No newline at end of file diff --git a/others/lede-gui/src/main/assets/1)_install_one_device.config b/others/lede-gui/src/main/assets/1)_install_one_device.config new file mode 100644 index 0000000..1113e2a --- /dev/null +++ b/others/lede-gui/src/main/assets/1)_install_one_device.config @@ -0,0 +1,15 @@ +IoTMain +ID CM4 +TYPE Camera +TYPESPECIFIC AmcrestCamera +END + +Table 2 +USERNAME VARCHAR 20 +PASSWORD VARCHAR 20 +END + +Data +admin +55779CatSoundz35 +END \ No newline at end of file diff --git a/others/lede-gui/src/main/assets/10)_delete_address.config b/others/lede-gui/src/main/assets/10)_delete_address.config new file mode 100644 index 0000000..99ab2cf --- /dev/null +++ b/others/lede-gui/src/main/assets/10)_delete_address.config @@ -0,0 +1 @@ +10) delete address \ No newline at end of file diff --git a/others/lede-gui/src/main/assets/11)_delete_device_address.config b/others/lede-gui/src/main/assets/11)_delete_device_address.config new file mode 100644 index 0000000..2f669bf --- /dev/null +++ b/others/lede-gui/src/main/assets/11)_delete_device_address.config @@ -0,0 +1 @@ +11) delete device address \ No newline at end of file diff --git a/others/lede-gui/src/main/assets/12)_delete_zigbee_device_address.config b/others/lede-gui/src/main/assets/12)_delete_zigbee_device_address.config new file mode 100644 index 0000000..82a0089 --- /dev/null +++ b/others/lede-gui/src/main/assets/12)_delete_zigbee_device_address.config @@ -0,0 +1 @@ +12) delete zigbee device addressS \ No newline at end of file diff --git a/others/lede-gui/src/main/assets/13)_delete_host.config b/others/lede-gui/src/main/assets/13)_delete_host.config new file mode 100644 index 0000000..d469c51 --- /dev/null +++ b/others/lede-gui/src/main/assets/13)_delete_host.config @@ -0,0 +1 @@ +13) delete host \ No newline at end of file diff --git a/others/lede-gui/src/main/assets/2)_install_comm_pattern.config b/others/lede-gui/src/main/assets/2)_install_comm_pattern.config new file mode 100644 index 0000000..af934cf --- /dev/null +++ b/others/lede-gui/src/main/assets/2)_install_comm_pattern.config @@ -0,0 +1,3 @@ +CM4 AmcrestCameraCM4 +LB4 LifxLightBulbLB4 +WRITE \ No newline at end of file diff --git a/others/lede-gui/src/main/assets/3)_install_two_devices_and_comm_pattern.config b/others/lede-gui/src/main/assets/3)_install_two_devices_and_comm_pattern.config new file mode 100644 index 0000000..c418910 --- /dev/null +++ b/others/lede-gui/src/main/assets/3)_install_two_devices_and_comm_pattern.config @@ -0,0 +1 @@ +3)install_two_devices_and_comm_pattern \ No newline at end of file diff --git a/others/lede-gui/src/main/assets/4)_install_address.config b/others/lede-gui/src/main/assets/4)_install_address.config new file mode 100644 index 0000000..4c13b6e --- /dev/null +++ b/others/lede-gui/src/main/assets/4)_install_address.config @@ -0,0 +1 @@ +4)install_address.config diff --git a/others/lede-gui/src/main/assets/5)_install_device_address.config b/others/lede-gui/src/main/assets/5)_install_device_address.config new file mode 100644 index 0000000..ed02bb9 --- /dev/null +++ b/others/lede-gui/src/main/assets/5)_install_device_address.config @@ -0,0 +1,8 @@ +ID=CM4 +ADDRESSFOR=AmcrestCameraAdd +DEVICEADDRESS=ab:cd:ef:12:34:56 +PORTNUMBER=888 +PROTOCOL=udp +SOURCEWILDCARD=false +DESTWILDCARD=false +END \ No newline at end of file diff --git a/others/lede-gui/src/main/assets/6)_install_zigbee_device_address.config b/others/lede-gui/src/main/assets/6)_install_zigbee_device_address.config new file mode 100644 index 0000000..5404a38 --- /dev/null +++ b/others/lede-gui/src/main/assets/6)_install_zigbee_device_address.config @@ -0,0 +1 @@ +6)_install zigbee device address \ No newline at end of file diff --git a/others/lede-gui/src/main/assets/7)_install_host.config b/others/lede-gui/src/main/assets/7)_install_host.config new file mode 100644 index 0000000..7862996 --- /dev/null +++ b/others/lede-gui/src/main/assets/7)_install_host.config @@ -0,0 +1 @@ +7)install host config \ No newline at end of file diff --git a/others/lede-gui/src/main/assets/8)_delete_entity.config b/others/lede-gui/src/main/assets/8)_delete_entity.config new file mode 100644 index 0000000..5b881c8 --- /dev/null +++ b/others/lede-gui/src/main/assets/8)_delete_entity.config @@ -0,0 +1 @@ +8) delete entity \ No newline at end of file diff --git a/others/lede-gui/src/main/assets/9)_delete_comm_pattern.config b/others/lede-gui/src/main/assets/9)_delete_comm_pattern.config new file mode 100644 index 0000000..57c56e1 --- /dev/null +++ b/others/lede-gui/src/main/assets/9)_delete_comm_pattern.config @@ -0,0 +1 @@ +9) delete comm pattern \ No newline at end of file diff --git a/others/lede-gui/src/main/assets/add_comm.config b/others/lede-gui/src/main/assets/add_comm.config deleted file mode 100644 index 0a8a2ac..0000000 --- a/others/lede-gui/src/main/assets/add_comm.config +++ /dev/null @@ -1,3 +0,0 @@ -CM4 AmcrestCameraCM4 -LB4 LifxLightBulbLB4 -WRITE \ No newline at end of file diff --git a/others/lede-gui/src/main/assets/add_device.config b/others/lede-gui/src/main/assets/add_device.config deleted file mode 100644 index 4ecf673..0000000 --- a/others/lede-gui/src/main/assets/add_device.config +++ /dev/null @@ -1,15 +0,0 @@ -IoTMain -ID CM4 -TYPE Camera -TYPESPECIFIC AmcrestCamera -END - -Table 2 -USERNAME VARCHAR 20 -PASSWORD VARCHAR 20 -END - -Data -admin -55779CatSoundz35 -END \ No newline at end of file diff --git a/others/lede-gui/src/main/assets/add_device_address.config b/others/lede-gui/src/main/assets/add_device_address.config deleted file mode 100644 index 9867d01..0000000 --- a/others/lede-gui/src/main/assets/add_device_address.config +++ /dev/null @@ -1,8 +0,0 @@ -ID=CM4 -ADDRESSFOR=AmcrestCameraAdd -DEVICEADDRESS=ab:cd:ef:12:34:56 -PORTNUMBER=888 -PROTOCOL=udp -SOURCEWILDCARD=false -DESTWILDCARD=false -END \ No newline at end of file diff --git a/others/lede-gui/src/main/assets/delete_address.config b/others/lede-gui/src/main/assets/delete_address.config new file mode 100644 index 0000000..e69de29 diff --git a/others/lede-gui/src/main/assets/delete_device_address.config b/others/lede-gui/src/main/assets/delete_device_address.config new file mode 100644 index 0000000..4ab20a5 --- /dev/null +++ b/others/lede-gui/src/main/assets/delete_device_address.config @@ -0,0 +1 @@ +//insert sample address input \ No newline at end of file diff --git a/others/lede-gui/src/main/java/com/example/lede2/AddDeviceActivity.java b/others/lede-gui/src/main/java/com/example/lede2/AddDeviceActivity.java index fc4a075..8a83c4e 100644 --- a/others/lede-gui/src/main/java/com/example/lede2/AddDeviceActivity.java +++ b/others/lede-gui/src/main/java/com/example/lede2/AddDeviceActivity.java @@ -1,102 +1,604 @@ -package com.example.lede2; - -import android.content.Context; -import android.content.Intent; -import android.os.Bundle; -import android.support.v7.app.AppCompatActivity; -import android.util.Log; -import android.view.Gravity; -import android.view.View; -import android.view.inputmethod.InputMethodManager; -import android.widget.Button; -import android.widget.EditText; -import android.widget.TextView; - -import java.io.IOException; -import java.io.InputStream; -import java.sql.*; - - -public class AddDeviceActivity extends AppCompatActivity implements View.OnClickListener,View.OnFocusChangeListener { - - Button doneButton; - TextView databaseInfo; - TextView databaseAddressInfo; - private SSH_MySQL ssh;//Connection object between Android & Host - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_add_device); - - doneButton = (Button) findViewById(R.id.doneButton); - databaseInfo = (EditText)findViewById(R.id.textInfo); - databaseAddressInfo = (EditText)findViewById(R.id.textInfoAddress); - - doneButton.setOnClickListener(this); - databaseInfo.setOnFocusChangeListener(this); - databaseAddressInfo.setOnFocusChangeListener(this); - ssh = new SSH_MySQL(); - // Set config text from file for device - try { - InputStream is = getAssets().open(MainActivity.DEF_ADD_DEVICE_FILE); - int size = is.available(); - byte[] buffer = new byte[size]; - is.read(buffer); - is.close(); - String text = new String(buffer); - databaseInfo.setGravity(Gravity.LEFT); - databaseInfo.setText(text); - Log.d("LOADINGFILE", "Add device info file is already loaded!"); - } catch (IOException ex) { - Log.d("LOADINGFILE", "Add device info file is NOT loaded!"); - ex.printStackTrace(); - } - // Set config text from file for device address - try { - InputStream is = getAssets().open(MainActivity.DEF_ADD_DEVICE_ADDRESS_FILE); - int size = is.available(); - byte[] buffer = new byte[size]; - is.read(buffer); - is.close(); - String text = new String(buffer); - databaseAddressInfo.setGravity(Gravity.LEFT); - databaseAddressInfo.setText(text); - Log.d("LOADINGFILE", "Add device address info file is already loaded!"); - } catch (IOException ex) { - Log.d("LOADINGFILE", "Add device address info file is NOT loaded!"); - ex.printStackTrace(); - } - - } - - @Override - public void onClick(View v) { - if(v == doneButton){ - // 1) Create a new file and insert the configuration - // 2) Run iotinstaller code for device installation - // 3) Remove the existing config file - // 4) Repeat 1, 2, and 3 for device address - ssh.execute("echo \"" + databaseInfo.getText().toString() + "\" >> " + - MainActivity.DEF_MYSQL_CONFIG_FILE + ";" + - MainActivity.DEF_INSTALL_CMD + " " + MainActivity.DEF_MYSQL_CONFIG_FILE + ";" + - "rm -rf " + MainActivity.DEF_MYSQL_CONFIG_FILE + ";" + - // repeat process for device address - "echo \"" + databaseAddressInfo.getText().toString() + "\" >> " + - MainActivity.DEF_MYSQL_CONFIG_FILE + ";" + - MainActivity.DEF_INSTALL_ADDRESS_CMD + " " + MainActivity.DEF_MYSQL_CONFIG_FILE + ";" + - "rm -rf " + MainActivity.DEF_MYSQL_CONFIG_FILE); - finish(); - } - } - - @Override - public void onFocusChange(View view, boolean hasFocus) { - InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); - if (hasFocus) { - imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); - } else { - imm.hideSoftInputFromWindow(view.getWindowToken(), 0); - } - } -} +package com.example.lede2; + +import android.app.ActivityManager; +import android.app.ProgressDialog; +import android.content.Context; +import android.os.AsyncTask; +import android.os.Bundle; +import android.os.Handler; +import android.support.design.widget.Snackbar; +import android.support.v7.app.AppCompatActivity; +import android.util.Log; +import android.util.Pair; +import android.view.View; +import android.view.WindowManager; +import android.view.inputmethod.InputMethodManager; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; +import android.widget.Button; +import android.widget.EditText; +import android.widget.ProgressBar; +import android.widget.Spinner; +import android.widget.TextView; +import android.widget.Toast; + +import java.io.File; +import java.nio.file.FileAlreadyExistsException; +import java.text.CollationElementIterator; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Set; + + +public class AddDeviceActivity extends AppCompatActivity implements View.OnClickListener,View.OnFocusChangeListener { + + DatabaseObject databaseObject; + //DatabaseSubtypeObject databaseSubtypeObject; + Button doneButton; + EditText databaseInfo; + Spinner spinner1; + Spinner spinner2; + Spinner spinner3; + Spinner spinner4; + ProgressBar progressBar; + private ArrayAdapter subtypeAdapter; + private ArrayAdapter paramAdapter; + private ArrayAdapter fieldAdapter; + String lastParamChosen; + TextView databaseAddressInfo; + protected String database_information_filename; + protected String id_information_filename; + Context context; + HashMap userInputs; + ProgressDialog dialog; + + + private SSH_MySQL ssh;//Connection object between Android & Host + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_add_device); + + + doneButton = (Button) findViewById(R.id.doneButton); + spinner1 = (Spinner) findViewById(R.id.spinner1); + spinner2 = (Spinner) findViewById(R.id.spinner2); + spinner3 = (Spinner) findViewById(R.id.spinner3); + spinner4 = (Spinner) findViewById(R.id.spinner4); + databaseInfo = (EditText)findViewById(R.id.textInfo); + progressBar = (ProgressBar)findViewById(R.id.progressBar); + progressBar.setVisibility(View.INVISIBLE); + progressBar.setMax(10); + //databaseAddressInfo = (EditText)findViewById(R.id.textInfoAddress); + database_information_filename = this.getString(R.string.device_param_config_filename); + id_information_filename = this.getString(R.string.device_id_config_filename); + userInputs = new HashMap(); + context = this; + lastParamChosen = ""; + + //looks through database to see possible subtypes for dropdown box 2 + spinner1.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + //set spinner2 values = subtypes of type chosen for spinner 1 + @Override + public void onItemSelected(AdapterView adapterView, View view, int i, long l) { + + String selectedType = spinner1.getSelectedItem().toString(); + Set keysForSubType = (databaseObject.getTypeObject(selectedType)).getKeySet(); + ArrayList subtypes = new ArrayList(); + for(String key: keysForSubType){ + subtypes.add(key); + } + Collections.sort(subtypes); + subtypeAdapter = new ArrayAdapter(context, android.R.layout.simple_spinner_dropdown_item, subtypes); + subtypeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + spinner2.setAdapter(subtypeAdapter); + + } + + @Override + public void onNothingSelected(AdapterView adapterView) { + + } + }); + spinner2.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + //set spinner 3 values based on if the selected subtype has params and/or addressparams + @Override + public void onItemSelected(AdapterView adapterView, View view, int i, long l) { + DatabaseSubtypeObject subtypeObject = getCurrentSubtypeObject(); + + ArrayList paramType = new ArrayList(); + if(subtypeObject.getParams().size() > 0){ + paramType.add("Device"); + } + if(subtypeObject.getAddressParams().size() > 0){ + paramType.add("Address"); + } + if(subtypeObject.getZigbeeAddressParams().size()>0){ + paramType.add("Zigbee"); + } + //if both empty(example room) + if(subtypeObject.getAddressParams().size() == 0 && subtypeObject.getParams().size() == 0){ + paramType.add("No Device or Address Parameters"); + } + Collections.sort(paramType); + paramAdapter = new ArrayAdapter(context, android.R.layout.simple_spinner_dropdown_item, paramType); + spinner3.setAdapter(paramAdapter); + } + + @Override + public void onNothingSelected(AdapterView adapterView) { + + } + }); + spinner3.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + //set spinner 4 value based on spinner1-3 values (actual params) + @Override + public void onItemSelected(AdapterView adapterView, View view, int i, long l) { + DatabaseSubtypeObject subtypeObject = getCurrentSubtypeObject(); + List keysForSubType = new ArrayList<>(); + //for devices that have no fields ex Rooms + if(spinner3.getSelectedItem().toString().equals("No Device or Address Parameters")) { + keysForSubType.add("No Fields"); + + databaseInfo.setVisibility(View.GONE); + } + if(spinner3.getSelectedItem().toString().equals("Device")) { + databaseInfo.setVisibility(View.VISIBLE); + if(subtypeObject.getNumParams() > 0){ + //add only params that have USER value + ArrayList> tempList = subtypeObject.getParams(); + for(int j = 0; j < tempList.size(); j++){ + if(tempList.get(j).second.equals("USER")){ + keysForSubType.add(tempList.get(j).first); + } + } + + } + } + else if(spinner3.getSelectedItem().toString().equals("Zigbee")){ + //setting field name for zigbee + databaseInfo.setVisibility(View.VISIBLE); + keysForSubType.add("DEVICEADDRESS"); + } + else{ + //if selected value is address + if(subtypeObject.getNumAddressParams() > 0){ + databaseInfo.setVisibility(View.VISIBLE); + //add only params that have USER value + ArrayList>> tempList = subtypeObject.getAddressParams(); + for(int j = 0; j < tempList.size(); j++){ + for(int k = 0; k < tempList.get(j).size(); k++){ + if(tempList.get(j).get(k).second.equals("USER")){ + if(!keysForSubType.contains(tempList.get(j).get(k).first)) { + keysForSubType.add(tempList.get(j).get(k).first); + } + } + } + + } + + } + } + //List keysForSubType = (databaseObject.getTypeObject(selectedType)).getSubtypeObject(selectedSubtype).getParams(); + + ArrayList params = new ArrayList(); + for(String key: keysForSubType){ + params.add(key); + } + Collections.sort(params); + fieldAdapter = new ArrayAdapter(context, android.R.layout.simple_spinner_dropdown_item, params); + fieldAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + spinner4.setAdapter(fieldAdapter); + } + + @Override + public void onNothingSelected(AdapterView adapterView) { + + } + }); + spinner4.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + //saves user input into a hashmap that is used later to create ssh command + @Override + public void onItemSelected(AdapterView adapterView, View view, int i, long l) { + + if(!spinner3.getSelectedItem().toString().equals("No Device or Address Parameters")) { + if (lastParamChosen.equals("")) { + lastParamChosen = spinner2.getSelectedItem().toString() + spinner3.getSelectedItem().toString() + spinner4.getSelectedItem().toString(); + + } else { + String enteredText = databaseInfo.getText().toString(); + userInputs.put(lastParamChosen, enteredText); + String currentSelections = spinner2.getSelectedItem().toString() + spinner3.getSelectedItem().toString() + spinner4.getSelectedItem().toString(); + if (!userInputs.containsKey(currentSelections)) { + userInputs.put(currentSelections, ""); + } + databaseInfo.setText(userInputs.get(currentSelections)); + lastParamChosen = currentSelections; + } + } + else{ + } + } + + @Override + public void onNothingSelected(AdapterView adapterView) { + + } + }); + doneButton.setOnClickListener(this); + // Set config text from file for device + //pull information from config file and uses it to generate main database object + + String idInformation = ConfigFileIO.readFromFile(id_information_filename, this); + databaseObject = ConfigFileIO.createDatabaseObject(this, idInformation ); + + + + //ConfigFileIO.printDatabaseObject(databaseObject); + Set keysForType = databaseObject.getKeySet(); + ArrayList types = new ArrayList(); + for(String key: keysForType){ + types.add(key); + } + //sets value for spinner 1 + Collections.sort(types); + ArrayAdapter typeAdapter = new ArrayAdapter(this, android.R.layout.simple_spinner_dropdown_item, types); + typeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + spinner1.setAdapter(typeAdapter); + + + } + + @Override + public void onClick(View v) { + if(v == doneButton){ + String enteredText = databaseInfo.getText().toString(); + //combines user input into a command for the pi + String keyForUserInput = spinner2.getSelectedItem().toString() + spinner3.getSelectedItem().toString() + spinner4.getSelectedItem().toString(); + userInputs.put(keyForUserInput, enteredText); + if(!sufficientEntries()) { + Snackbar done = Snackbar.make(findViewById(R.id.done), + "Please Enter all required fields for selected device type", 2000); + done.show(); + } + else { + Snackbar done = Snackbar.make(findViewById(R.id.done), "Updating IoTDeviceAddress.config", 2000); + done.show(); + progressBar.setVisibility(View.VISIBLE); + doneButton.setAlpha(.5f); + doneButton.setClickable(false); + + + + + + String sqlCommand = generateSQLCommand(); + System.out.println(sqlCommand); + Log.d("sqlcommand", sqlCommand); + System.out.println(""); + + ssh = new SSH_MySQL(); + ssh.execute(sqlCommand); + try { + Thread.sleep(1000); + List result = ssh.getResultLines(); + for (int i = 0; i < result.size(); i++) { + System.out.println("result" + result.get(i)); + } + } catch (Exception e) { + e.printStackTrace(); + } + updateDatabase(); + + updateIoTDeviceAddress(); +// done = Snackbar.make(findViewById(R.id.done), +// "Updating SetList.config", 2000); +// done.show(); + updateSetList(); + finish(); + } + } + } + //determines if all fields have been entered + public boolean sufficientEntries(){ + boolean sufficient = true; + DatabaseSubtypeObject subtypeObject = getCurrentSubtypeObject(); + ArrayList> params = subtypeObject.getParams(); + ArrayList>> addressParams = subtypeObject.getAddressParams(); + ArrayList>> zigbeeAddressParams = subtypeObject.getZigbeeAddressParams(); + if(spinner3.getSelectedItem().toString().equals("No Device or Address Parameters")) { + return true; + } + if(params.size()>0){ + for(int i = 0; i < params.size(); i++){ + if(!params.get(i).second.equals("USER")){ + continue; + } + if(!userInputs.containsKey(spinner2.getSelectedItem().toString() + "Device" + params.get(i).first) || + userInputs.get(spinner2.getSelectedItem().toString() + "Device" + params.get(i).first).equals("")){ + sufficient = false; + } + } + } + if(addressParams.size()>0){ + for(int i = 0; i < addressParams.size(); i++){ + for(int j = 0;j < addressParams.get(i).size(); j++) { + if(!addressParams.get(i).get(j).second.equals("USER")){ + continue; + } + if (!userInputs.containsKey(spinner2.getSelectedItem().toString() + "Address" + addressParams.get(i).get(j).first) || + userInputs.get(spinner2.getSelectedItem().toString() + "Address" + addressParams.get(i).get(j).first).equals("")) { + sufficient = false; + } + } + } + } + if(zigbeeAddressParams.size()>0){ + for(int i = 0; i < zigbeeAddressParams.size(); i++){ + for(int j = 0;j < zigbeeAddressParams.get(i).size(); j++) { + if(!zigbeeAddressParams.get(i).get(j).second.equals("USER")){ + continue; + } + if (!userInputs.containsKey(spinner2.getSelectedItem().toString() + "Zigbee" + zigbeeAddressParams.get(i).get(j).first) || + userInputs.get(spinner2.getSelectedItem().toString() + "Zigbee" + zigbeeAddressParams.get(i).get(j).first).equals("")) { + sufficient = false; + } + } + } + } + + return sufficient; + } + + @Override + public void onFocusChange(View view, boolean hasFocus) { + InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); + if (hasFocus) { + imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); + } else { + imm.hideSoftInputFromWindow(view.getWindowToken(), 0); + } + } + //generates command for adding both device and address device. May need to expand for zigbee + public String generateSQLCommand(){ + String command = ""; + String paramInfo = ""; + String addressParamInfo = ""; + DatabaseSubtypeObject subtypeObject = getCurrentSubtypeObject(); + int numAddresses = subtypeObject.getNumAddresses(); + int numZigbeeAddresses = subtypeObject.getNumZigbeeAddresses(); + // 1) Create a new file and insert the configuration + // 2) Run iotinstaller code for device installation + // 3) Remove the existing config file + // 4) Repeat 1, 2, and 3 for device address + command += "echo \"" + generateDevFields() + "\" >> " + + MainActivity.DEF_MYSQL_CONFIG_FILE + ";" + + MainActivity.DEF_INSTALL_CMD + " " + MainActivity.DEF_MYSQL_CONFIG_FILE + ";" + + "rm -rf " + MainActivity.DEF_MYSQL_CONFIG_FILE + ";"; + // repeat process for device address + for(int i = 0; i > " + + MainActivity.DEF_MYSQL_CONFIG_FILE + ";" + + MainActivity.DEF_INSTALL_ADDRESS_CMD + " " + MainActivity.DEF_MYSQL_CONFIG_FILE + ";" + + "rm -rf " + MainActivity.DEF_MYSQL_CONFIG_FILE + ";"; + } + for(int i = 0; i < numZigbeeAddresses; i++){ + boolean multiple = true; + if(numZigbeeAddresses == 1){ + multiple = false; + } + command += "echo \"" + generateZigBeeAddressFields(i, multiple) + "\" >> " + + MainActivity.DEF_MYSQL_CONFIG_FILE + ";" + + MainActivity.DEF_INSTALL_ZBADDRESS_CMD + " " + MainActivity.DEF_MYSQL_CONFIG_FILE + ";" + + "rm -rf " + MainActivity.DEF_MYSQL_CONFIG_FILE + ";"; + } + + return command; + + } + //specific device information to be inserted into the sql command. follows format seen in config file on pi + public String generateDevFields(){ + String fields = ""; + DatabaseSubtypeObject subtypeObject = getCurrentSubtypeObject(); + //IotMain Table + fields += context.getResources().getString(R.string.database_name) + "\n" + + "ID " + subtypeObject.getNextID() + "\n" + + "TYPE " + spinner1.getSelectedItem().toString()+ "\n" + + "TYPESPECIFIC " + spinner2.getSelectedItem().toString()+ "\n" + + "END" + "\n\n"; + //This sets up the param types and size. special case for devices with no params + if(subtypeObject.getNumParams() == 0){ + fields += "Table 1" + "\n" + + "EMPTY VARCHAR 0 " + "\n"; + } + + //Case for when there are params + else { + fields += "Table " + subtypeObject.getNumParams() + "\n"; + } + ArrayList> params = subtypeObject.getParams(); + for(int i = params.size()-1; i >= 0; i--){ + fields += params.get(i).first + " VARCHAR 20 \n"; + } + fields += "END\n\n"; + //data for params + fields += "Data \n"; + for(int i = params.size()-1; i >= 0; i--){ + fields += userInputs.get(spinner2.getSelectedItem().toString() + + "Device" + + params.get(i).first) + "\n"; + } + fields += "END\n\n"; + return fields; + } + + + //refactor with string builder but works for now + public String generateAddressFields(int i, boolean multiple){ + String fields = ""; + String addressNumber = ""; + if(multiple){ + addressNumber = Integer.toString(i+1); + } + DatabaseSubtypeObject subtypeObject = getCurrentSubtypeObject(); + fields += "ID=" + subtypeObject.getNextID() + "\n" ; + fields += "ADDRESSFOR=" + subtypeObject.getName()+ "Add"+ addressNumber + "\n" ; + ArrayList>> addressParams = subtypeObject.getAddressParams(); + String currentAddressParam = ""; + for(int j = 0; j >> zigbeeAddressParams = subtypeObject.getZigbeeAddressParams(); + String currentAddressParam = ""; + for(int j = 0; j < zigbeeAddressParams.get(i).size(); j++) { + //if the value for current address parameter is user, use the input values + if(zigbeeAddressParams.get(i).get(j).second.equals("USER")){ + currentAddressParam = zigbeeAddressParams.get(i).get(j).first; + fields += currentAddressParam + "=" + userInputs.get(spinner2.getSelectedItem().toString() + "Zigbee" + currentAddressParam) + "\n"; + } + //if the value for the current address is not user, use the predefined values + else{ + currentAddressParam = zigbeeAddressParams.get(i).get(j).first; + fields += currentAddressParam + "=" + zigbeeAddressParams.get(i).get(j).second + "\n"; + } + } + fields += "END\n\n"; + return fields; + } + + //update local database object and local database config file + public void updateDatabase(){ + DatabaseSubtypeObject subtypeObject = getCurrentSubtypeObject(); + String deviceID = subtypeObject.getName() + " " + subtypeObject.getNextID() + "\n"; + ConfigFileIO.writeToFile(id_information_filename, deviceID, this); + subtypeObject.insertID(); + } + private void updateSetList(){ + SSH_MySQL ssh = new SSH_MySQL(); + String command = this.getString(R.string.updateSetList); + List results = new ArrayList<>(); + String setListFilename = this.getString(R.string.setListFilename); + try { + ssh.execute(command); + Thread.sleep(1000);//To execute asyntask in ssh object, we have to sleep main thread + results = ssh.getResultLines(); + while(results.size() == 0){ + Thread.sleep(500); + results = ssh.getResultLines(); + } + System.out.println(results); + } catch (Exception e) { + Log.d("Sleep exception", "exception at getSetsAndRelations"); + } + } + private void updateIoTDeviceAddress(){ + SSH_MySQL ssh = new SSH_MySQL(); + String command = this.getString(R.string.updateIoTDeviceAddress); + List results = new ArrayList<>(); + String iotDeviceAddressFilename = this.getString(R.string.updateIoTDeviceAddress); + try { + ssh.execute(command); + Thread.sleep(1000);//To execute asyntask in ssh object, we have to sleep main thread + results = ssh.getResultLines(); + while(results.size() == 0){ + Thread.sleep(500); + results = ssh.getResultLines(); + } + System.out.println(results); + } catch (Exception e) { + Log.d("Sleep exception", "exception at getSetsAndRelations"); + } + + } + + protected void addSSHResultsToConfig(List results, String filename) { + ConfigFileIO.writeToNewFile(filename,"", this ); + File dir = getFilesDir(); + File file = new File(dir, filename); + file.delete(); + for (int i = 0; i < results.size(); i++) { + ConfigFileIO.writeToFile(filename, results.get(i), this); + } + } + + + public DatabaseSubtypeObject getCurrentSubtypeObject(){ + return databaseObject.getTypeObject(spinner1. + getSelectedItem().toString()).getSubtypeObject(spinner2.getSelectedItem().toString()); + } + + + public class Progress extends AsyncTask { + boolean finished; + + + @Override + protected void onPreExecute() { + super.onPreExecute(); + + Log.d("progress", "after dialog.show"); + } + + @Override + protected Void doInBackground(Void... voids) { + for(int i = 0; i < 10; i++){ + try { + Thread.sleep(100); + publishProgress(i); + } catch (InterruptedException e) { + e.printStackTrace(); + } + + } + return null; + } + + @Override + protected void onPostExecute(Void aVoid) { + super.onPostExecute(aVoid); + + } + + @Override + protected void onProgressUpdate(Integer... values) { + super.onProgressUpdate(values); + progressBar.setProgress(values[0]); + } + + + + + public void finished(){ + + } + } + +} diff --git a/others/lede-gui/src/main/java/com/example/lede2/AllInstallOptions.java b/others/lede-gui/src/main/java/com/example/lede2/AllInstallOptions.java new file mode 100644 index 0000000..2248620 --- /dev/null +++ b/others/lede-gui/src/main/java/com/example/lede2/AllInstallOptions.java @@ -0,0 +1,59 @@ +package com.example.lede2; + +import android.content.Context; +import android.content.Intent; +import android.os.Bundle; +import android.support.v7.app.AppCompatActivity; +import android.util.Log; +import android.view.View; +import android.view.inputmethod.InputMethodManager; +import android.widget.Button; + +/** + * Created by Brian on 2/16/2018. + */ + +public class AllInstallOptions extends AppCompatActivity implements View.OnClickListener, + View.OnFocusChangeListener { + Button installOneDeviceButton; + Button installCommPatternButton; + Button installTwoDevicesAndCommPattern; + Button installAddress; + Button installDeviceAddress; + Button installZigbeeDeviceAddress; + Button installHost; + + + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.install_options); + + installOneDeviceButton = (Button) findViewById(R.id.doneDrivers); + installZigbeeDeviceAddress = (Button) findViewById(R.id.install_zigbee_device_address); + installOneDeviceButton.setOnClickListener(this); + installZigbeeDeviceAddress.setOnClickListener(this); + + } + + @Override + public void onClick(View view) { + if (view == installOneDeviceButton) { + Log.d("CLICKING", "Clicking on add device!"); + startActivity(new Intent(this, AddDeviceActivity.class)); + } + if (view == installZigbeeDeviceAddress) { + Log.d("CLICKING", "Clicking on install zigbee!"); + startActivity(new Intent(this, InstallZigbeeDeviceAddress.class)); + } + + } + + public void onFocusChange(View view, boolean hasFocus) { + InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); + if (hasFocus) { + imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); + } else { + imm.hideSoftInputFromWindow(view.getWindowToken(), 0); + } + } +} \ No newline at end of file diff --git a/others/lede-gui/src/main/java/com/example/lede2/ApplicationWithRelations.java b/others/lede-gui/src/main/java/com/example/lede2/ApplicationWithRelations.java new file mode 100644 index 0000000..30c533c --- /dev/null +++ b/others/lede-gui/src/main/java/com/example/lede2/ApplicationWithRelations.java @@ -0,0 +1,443 @@ +package com.example.lede2; + +import android.app.ProgressDialog; +import android.content.Context; +import android.support.design.widget.Snackbar; +import android.support.v7.app.AppCompatActivity; +import android.util.Log; +import android.util.Pair; +import android.util.SparseBooleanArray; +import android.view.View; +import android.widget.ArrayAdapter; +import android.widget.Button; +import android.widget.ListView; +import android.widget.Spinner; +import android.widget.Toast; + +import com.jcraft.jsch.HASH; + +import java.io.File; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Properties; +import java.util.Scanner; +import java.util.Set; + + +/** + * Created by Brian on 4/27/2018. + */ + +public class ApplicationWithRelations extends AppCompatActivity implements View.OnClickListener { + protected HashMap> addedSetList; //list of sets that is currently being added and their values + protected int numFields; + protected Properties prop; + protected HashMap>> addedRelations; + protected HashMap> addedIndependentSets; + protected Context context; + protected HashMap> relations; + protected HashMap setHashMap; + protected Spinner relationNameSpinner; + protected Spinner relationLeftSpinner; + protected Spinner relationRightSpinner; + protected Spinner setOrRelationSpinner; + protected Button addRelationButton; + protected Button doneRelationButton; + protected Button deleteRelationButton; + protected HashMap independentSetList; + protected ArrayList independentSetNames; + protected boolean hasIndependentSets; + protected boolean hasRelations; + ArrayList addedRelationsArrayList; + ProgressDialog dialog; + protected Scanner scanner; + ArrayAdapter adapter; + ListView addRelationsListView; + protected HashSet applicationSetList; //list of all sets that should be used + + + + + protected void deleteFromSet(String device){ + Set keyset = addedSetList.keySet(); + for(String s: keyset){ + ArrayList tempSet = addedSetList.get(s); + tempSet.remove(device); + } + } + + protected void addSSHResultsToConfig(List results, String filename) { + ConfigFileIO.writeToNewFile(filename,"", this ); + File dir = getFilesDir(); + File file = new File(dir, filename); + file.delete(); + for (int i = 0; i < results.size(); i++) { + ConfigFileIO.writeToFile(filename, results.get(i), this); + } + } + + protected void callSSHCommandAddComm(){ + //default already in bin/installer (RELATION) + String installCommPatternCommand = ""; + for(int i = 0; i < numFields; i++){ + if(prop.getProperty("FIELD_TYPE_" + i).equals("IoTRelation")){ + String writeToRelConfigFileCommand = ""; + writeToRelConfigFileCommand += this.getString(R.string.changeToSQLConfigFileLocation); + + String filename = prop.getProperty("FIELD_CONFIG_FILENAME_"+i); + HashSet> tempSet = addedRelations.get(prop.getProperty("FIELD_" + i)); + + //insert roomCameraReal.config writing + writeToRelConfigFileCommand += "echo \"" + "SELECT RELATION FROM\n"+ + "FIRST\n" + + prop.getProperty("FIELD_CLASS_0_" + i) + "\n" + + "OTHER\n" + + prop.getProperty("FIELD_CLASS_1_" + i) + "\n" + + "WHERE\n"; //need to add where clauses for each case + int counter = 0; + //iterates through all of the added relations under the current relationName + //ex all relations under roomCameraRel + for(Pair pair: tempSet){ + int size = tempSet.size(); + Scanner scanner = new Scanner(pair.first); + String typeFirst = scanner.next(); + String idFirst = scanner.next(); + typeFirst += idFirst; + scanner = new Scanner(pair.second); + String typeSecond = scanner.next(); + String idSecond = scanner.next(); + typeSecond += idSecond; + + writeToRelConfigFileCommand += "(TYPE_SOURCE='" + typeFirst + "' AND TYPE_DESTINATION='" + typeSecond + "')"; + + + installCommPatternCommand += this.getString(R.string.changeToCommConfigFileLocation) + "echo \"" + idFirst + " " + typeFirst + "\n" + + idSecond + " " + typeSecond + "\n" + + "WRITE\" > " + filename + ";" + + "java -cp .:..:/usr/share/java/* iotinstaller.IoTInstaller -install_comm " + filename + ";" + + "rm " + filename + ";"; + + //if this is the last item, finish it by writing it into file + if(counter == size-1){ + writeToRelConfigFileCommand += "\n;\" > " + prop.getProperty("FIELD_" + i) + ".config; \n"; + installCommPatternCommand = writeToRelConfigFileCommand + installCommPatternCommand; + System.out.println("COMM" + installCommPatternCommand); + } + + //if it is not the last item, concatenate or and continue + else{ + writeToRelConfigFileCommand += "\nOR\n"; + System.out.println(installCommPatternCommand); + } + + SSH_MySQL ssh_mySQL = new SSH_MySQL(); + List results = new ArrayList<>(); + try { + ssh_mySQL.execute(installCommPatternCommand); + Thread.sleep(1000);//To execute asyntask in ssh object, we have to sleep main thread + results = ssh_mySQL.getResultLines(); + while(results.size() == 0){ + Thread.sleep(500); + results = ssh_mySQL.getResultLines(); + System.out.println(results); + } + System.out.println(results); + } catch (Exception e) { + Log.d("Sleep exception", "exception at getSetsAndRelations"); + } + installCommPatternCommand = ""; + counter++; + } + + } + } + } + + + protected HashMap> createSetList(String filename){ + HashMap> setListHashMap = new HashMap<>(); + String setData = ConfigFileIO.readFromFile(filename, context); + Scanner scanner = new Scanner(setData); + while (scanner.hasNextLine()){ + String temp = scanner.nextLine(); + if(temp.equals("START")){ + String setName = scanner.nextLine(); + temp = scanner.nextLine(); + ArrayList availableDevices = new ArrayList<>(); + while (!temp.equals("END")){ + availableDevices.add(temp); + temp = scanner.nextLine(); + } + setListHashMap.put(setName, availableDevices); + } + } + return setListHashMap; + } + + + //relationofTwoItems comes in form of ex: RoomSmart,LightBulbSmart. Splits them by commma and adds them to hashmap + protected void addPair(String name, String relationOfTwoItems){ + String firstItem = relationOfTwoItems.substring(0, relationOfTwoItems.indexOf(",")); + String secondItem = relationOfTwoItems.substring(relationOfTwoItems.indexOf(",")+1, relationOfTwoItems.length()); + Pair pair = new Pair<>(firstItem, secondItem); + relations.put(name,pair); + } + + protected ArrayList removeDuplicates(ArrayList list){ + HashSet set = new HashSet<>(); + set.addAll(list); + ArrayList noDups = new ArrayList<>(); + noDups.addAll(set); + return noDups; + } + protected String generateSQLQuery(String setName, ArrayList listOfDevices){ + String query = ""; + query = "SELECT * FROM\n" + + setName + "\n" + + "WHERE\n"; + for(int i = 0; i < listOfDevices.size(); i++){ + Scanner scanner = new Scanner(listOfDevices.get(i)); + String type = scanner.next(); + String id = scanner.next(); + query += "(TYPE='" + type + "' AND ID='" + id + "')"; + if(i == listOfDevices.size() -1){ + query +="\n;"; + } + else{ + query += "\nOR\n"; + } + } + return query; + } + + protected String generateSSHCommandRelation(){ + String command = ""; + //move to directory where the sql file should be located (SET) + command += this.getString(R.string.changeToSQLConfigFileLocation); + //go through all sets, and find their set type. + Set keySet = setHashMap.keySet(); + for(String s: keySet){ + String setType = setHashMap.get(s); + ArrayList list = addedSetList.get(setType); + list = removeDuplicates(list); + command += "echo \"" + generateSQLQuery(setType, list) + "\" > " + s + ".config" + ";"; + } + + keySet = addedIndependentSets.keySet(); + for(String s:keySet){ + String setType = independentSetList.get(s); + ArrayList list = new ArrayList<>(); + HashSet set = addedIndependentSets.get(s); + list.addAll(set); + command += "echo \"" + generateSQLQuery(setType, list) + "\" > " + s + ".config" + ";"; + } + + return command; + } + + @Override + public void onClick(View view) { + if(view == addRelationButton){ + if(setOrRelationSpinner.getSelectedItem().toString().equals("RELATIONS")) { + //adding the user selected relation into a relationset + String leftValue = relationLeftSpinner.getSelectedItem().toString(); + String rightValue = relationRightSpinner.getSelectedItem().toString(); + Pair pair = new Pair<>(leftValue, rightValue); + if ((addedRelations.get(relationNameSpinner.getSelectedItem().toString())) == null) { + HashSet> tempSet = new HashSet<>(); + tempSet.add(pair); + addedRelations.put(relationNameSpinner.getSelectedItem().toString(), tempSet); + adapter.notifyDataSetChanged(); + } else { + (addedRelations.get(relationNameSpinner.getSelectedItem().toString())).add(pair); + adapter.notifyDataSetChanged(); + } + + //adding selected Objects into their respective sets + String relationName = relationNameSpinner.getSelectedItem().toString(); + //get the left hand side of the generic selected relation + // ex: IoTRelation roomCameraRel, get "RoomSmart" + Pair tempPair = relations.get(relationName); + ArrayList tempArrayList = addedSetList.get(tempPair.first); + //add the selected Left Value to RoomSmart set + if (tempArrayList == null) { + tempArrayList = new ArrayList<>(); + tempArrayList.add(leftValue); + addedSetList.put(tempPair.first, tempArrayList); + } else { + tempArrayList.add(leftValue); + addedSetList.put(tempPair.first, tempArrayList); + } + + //repeat for the right side + tempArrayList = addedSetList.get(tempPair.second); + //ex: add to the selected Right Value CameraSmart set + if (tempArrayList == null) { + tempArrayList = new ArrayList<>(); + tempArrayList.add(rightValue); + addedSetList.put(tempPair.second, tempArrayList); + } else { + tempArrayList.add(rightValue); + addedSetList.put(tempPair.second, tempArrayList); + } + addedRelationsArrayList = new ArrayList<>(); + Set relationTypes = addedRelations.keySet(); + for (String s : relationTypes) { + for (Pair temp : addedRelations.get(s)) { + addedRelationsArrayList.add(temp.first + " " + temp.second); + } + } + if(hasIndependentSets){ + Set keys= addedIndependentSets.keySet(); + for (String s : keys) { + for (String temp : addedIndependentSets.get(s)) { + addedRelationsArrayList.add(temp); + } + } + adapter = new ArrayAdapter(context, android.R.layout.simple_list_item_multiple_choice, addedRelationsArrayList); + addRelationsListView.setAdapter(adapter); + } + else { + adapter = new ArrayAdapter(context, android.R.layout.simple_list_item_multiple_choice, addedRelationsArrayList); + addRelationsListView.setAdapter(adapter); + } + + } + else { + //user is adding to independent sets (sets that are not part of a relation) + String leftValue = relationLeftSpinner.getSelectedItem().toString(); + if ((addedIndependentSets.get(relationNameSpinner.getSelectedItem().toString())) == null) { + HashSet tempSet = new HashSet<>(); + tempSet.add(leftValue); + addedIndependentSets.put(relationNameSpinner.getSelectedItem().toString(), tempSet); + adapter.notifyDataSetChanged(); + } else { + (addedIndependentSets.get(relationNameSpinner.getSelectedItem().toString())).add(leftValue); + adapter.notifyDataSetChanged(); + } + addedRelationsArrayList = new ArrayList<>(); + Set relationTypes = addedRelations.keySet(); + for (String s : relationTypes) { + for (Pair temp : addedRelations.get(s)) { + addedRelationsArrayList.add(temp.first + " " + temp.second); + } + } + Set keys= addedIndependentSets.keySet(); + for (String s : keys) { + for (String temp : addedIndependentSets.get(s)) { + addedRelationsArrayList.add(temp); + } + } + adapter = new ArrayAdapter(context, android.R.layout.simple_list_item_multiple_choice, addedRelationsArrayList); + addRelationsListView.setAdapter(adapter); + + } + } + + if(view == doneRelationButton){ + + boolean allSetsHaveEntry = true; + for(String s: applicationSetList){ + ArrayList list = addedSetList.get(s); + if(list== null || list.size() == 0){ + allSetsHaveEntry = false; + System.out.println("NOT ALL RELATIONS HAVE ENTRIES"); + Toast t = Toast.makeText(ApplicationWithRelations.this, "Insufficient Entries",Toast.LENGTH_SHORT); + t.show(); + continue; + } + } + if(hasIndependentSets) { + for (int i = 0; i < independentSetNames.size(); i++) { + if (addedIndependentSets.get(independentSetNames.get(i)) == null || + (addedIndependentSets.get(independentSetNames.get(i))).size() == 0) { + allSetsHaveEntry = false; + System.out.println("NOT ALL SETS HAVE ENTRIES"); + continue; + } + } + } + System.out.println("all sets have entry" + allSetsHaveEntry); + if(allSetsHaveEntry){ + + //the ssh execution is within the following command. Add comm patterns to database + callSSHCommandAddComm(); + + //adding relations and their derived sets, add to localconfig/mysql files + String command = generateSSHCommandRelation(); + //System.out.println(command) + SSH_MySQL addConfigFiles = new SSH_MySQL(); + addConfigFiles.execute(command); + try { + Thread.sleep(1500); + List result = addConfigFiles.getResultLines(); + for (int i = 0; i < result.size(); i++) { + System.out.println("result" + result.get(i)); + } + } + catch (Exception e){ + e.printStackTrace(); + } + + + + + //add independent sets to their respective localconfig/mysql files + finish(); + } + + } + if (view == deleteRelationButton) { + //SparseBooleanArray's data is True or False + SparseBooleanArray checkedItems = addRelationsListView.getCheckedItemPositions();//to check which devices are checked in listview(check -> true, no check -> false) + int count = adapter.getCount();//number of items in listview + for (int i = count - 1; i >= 0; i--) {//scan from back + //i : index of IoT device which will be removed in tmp array + if (checkedItems.get(i)) {//if check + System.out.println("delete relation: " + i); + String selectedValue = (String)addRelationsListView.getItemAtPosition(i); + scanner = new Scanner(selectedValue); + String left = scanner.next() + " " + scanner.next(); + + if(scanner.hasNext()) { + String right = scanner.next() + " " + scanner.next(); + Pair pair = new Pair<>(left, right); + //remove from user-selected relations + Set relationTypes = addedRelations.keySet(); + for (String s : relationTypes) { + if (addedRelations.get(s).contains(pair)) { + addedRelations.get(s).remove(pair); + } + } + //remove from displaying on the check list + String temp = pair.first + " " + pair.second; + addedRelationsArrayList.remove(temp); + adapter.notifyDataSetChanged(); + //remove from addedsetlist + deleteFromSet(left); + deleteFromSet(right); + } + else{ + System.out.println("only has one word"); + Set keySet = addedIndependentSets.keySet(); + for(String s: keySet){ + HashSet tempSet = addedIndependentSets.get(s); + tempSet.remove(left); + } + addedRelationsArrayList.remove(left); + adapter.notifyDataSetChanged(); + } + } + } + + //update + adapter.notifyDataSetChanged(); + //delete checked mark in listview + addRelationsListView.clearChoices(); + + } + + } +} diff --git a/others/lede-gui/src/main/java/com/example/lede2/ApplicationsList.java b/others/lede-gui/src/main/java/com/example/lede2/ApplicationsList.java new file mode 100644 index 0000000..26036b6 --- /dev/null +++ b/others/lede-gui/src/main/java/com/example/lede2/ApplicationsList.java @@ -0,0 +1,80 @@ +package com.example.lede2; + +import android.app.ProgressDialog; +import android.content.Intent; +import android.os.Bundle; +import android.support.v7.app.AppCompatActivity; +import android.view.View; +import android.widget.Button; + +/** + * Created by Brian on 4/16/2018. + */ + +public class ApplicationsList extends AppCompatActivity implements View.OnClickListener { + private Button homeSecurityButton; + private Button irrigationButton; + private Button lifxTestButton; + private Button smartLightsButton; + private Button speakerButton; + private ProgressDialog dialog; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.applications); + homeSecurityButton = (Button) findViewById(R.id.homeSecurityButton); + irrigationButton = (Button) findViewById(R.id.irrigationButton); + lifxTestButton = (Button) findViewById(R.id.lifxTestButton); + smartLightsButton = (Button) findViewById(R.id.smartLightsButton); + speakerButton = (Button) findViewById(R.id.speakerButton); + + homeSecurityButton.setOnClickListener(this); + irrigationButton.setOnClickListener(this); + lifxTestButton.setOnClickListener(this); + smartLightsButton.setOnClickListener(this); + speakerButton.setOnClickListener(this); + + + + } + + @Override + public void onClick(View view) { + dialog = new ProgressDialog(this); + dialog.setMessage("Please Wait"); + dialog.setCancelable(false); + dialog.setInverseBackgroundForced(false); + dialog.show(); + + if(view == homeSecurityButton){ + startActivity(new Intent(this, HomeSecurity.class)); + } + if(view == irrigationButton){ + startActivity(new Intent(this, Irrigation.class)); + + } + if(view == lifxTestButton){ + startActivity(new Intent(this, Lifxtest.class)); + + } + if(view == smartLightsButton){ + startActivity(new Intent(this, SmartLights.class)); + + } + if(view == speakerButton){ + startActivity(new Intent(this, Speaker.class)); + + } + } + @Override + protected void onResume() { + super.onResume(); + if(dialog != null && dialog.isShowing()){ + dialog.dismiss(); + } + } +} + + + diff --git a/others/lede-gui/src/main/java/com/example/lede2/ConfigFileIO.java b/others/lede-gui/src/main/java/com/example/lede2/ConfigFileIO.java new file mode 100644 index 0000000..716eefe --- /dev/null +++ b/others/lede-gui/src/main/java/com/example/lede2/ConfigFileIO.java @@ -0,0 +1,245 @@ +package com.example.lede2; + +import android.content.Context; +import android.provider.ContactsContract; +import android.util.Log; +import android.util.Pair; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.OutputStreamWriter; +import java.util.ArrayList; +import java.util.List; +import java.util.Properties; +import java.util.Scanner; +import java.util.Set; + +/** + * Created by Brian on 2/28/2018. + */ + +public class ConfigFileIO { + + //appends information to the bottom of file + public static void writeToFile(String filename, String data, Context context) { + try { + OutputStreamWriter outputStreamWriter = new OutputStreamWriter(context. + openFileOutput(filename, + Context.MODE_APPEND | Context.MODE_PRIVATE)); + BufferedWriter writer = new BufferedWriter(outputStreamWriter); + writer.write(data); + writer.newLine(); + writer.close(); + } catch (IOException e) { + Log.e("Exception", "File write failed: " + e.toString()); + } + } + + //returns contents of file + public static String readFromFile(String filename, Context context) { + + String strscan = ""; + + try { + File scanfile = context.getFileStreamPath(filename); + Scanner scanner = new Scanner(scanfile); + while (scanner.hasNextLine()) { + strscan += scanner.nextLine() + "\n"; + } + + } catch (FileNotFoundException e) { + Log.e("login activity", "File not found: " + e.toString()); + } + + return strscan; + } + + + + //creates the local copy of the sql database object + public static DatabaseObject createDatabaseObject(Context context, String idInformation){ + Properties prop = new Properties(); + String filename = context.getString(R.string.device_param_config_filename); + File file = new File(context.getFilesDir() , filename); + FileInputStream fis = null; + try{ + fis = new FileInputStream(file); + prop.load(fis); + fis.close(); + } + catch (IOException ex){ + System.out.println("Error when reading SpeakerController Config file "); + ex.printStackTrace(); + } + + int numTypes = Integer.parseInt(prop.getProperty("NUM_OF_TYPES")); + System.out.println("numtypes: " + numTypes); + DatabaseObject databaseObject = new DatabaseObject(); + //add all types into databaseObject + for(int i = 0; i < numTypes; i++){ + String type = prop.getProperty("TYPE_" + i); + String tag = prop.getProperty("TAG_" + i); + //generates a type object, fill it with subtype objects + DatabaseTypeObject databaseTypeObject = new DatabaseTypeObject(type, tag); + int numSubtypes = Integer.parseInt(prop.getProperty("SUBTYPE_" + i)); + + //for each subtype, create the appropriate fields + for(int j = 0; j < numSubtypes; j++){ + String currentSubtype = "TYPE_" + i + "_" + j; + String subtypeName = prop.getProperty(currentSubtype); + int numAddresses = Integer.parseInt(prop.getProperty(currentSubtype + "_NUM_OF_ADDRESSES")); + int numZigbeeAddresses = Integer.parseInt(prop.getProperty(currentSubtype + "_NUM_OF_ZBADDRESSES")); + + DatabaseSubtypeObject databaseSubtypeObject = new DatabaseSubtypeObject(subtypeName, tag, numAddresses, numZigbeeAddresses); + + if(numAddresses > 0) { + String temp = prop.getProperty("TYPE_" + i + "_" + j + "_ADDRESS_FIELDS"); + Scanner scanner = new Scanner(temp); + ArrayList addressFieldNames = new ArrayList<>(); + while (scanner.hasNext()) { + addressFieldNames.add(scanner.next()); + } + //fill in the address fields for each subtype. May have to do multiple times for some subtypes + System.out.println("num addresses" + numAddresses); + for (int k = 0; k < numAddresses; k++) { + ArrayList> addressParamList = new ArrayList<>(); + for (int l = 0; l < addressFieldNames.size(); l++) { + System.out.println(prop.getProperty(addressFieldNames.get(l) + "_" + i + "_" + j + "_ADD_" + k)); + String fieldValue = prop.getProperty(addressFieldNames.get(l) + "_" + i + "_" + j + "_ADD_" + k); + Pair fieldPair = new Pair<>(addressFieldNames.get(l), fieldValue); + addressParamList.add(fieldPair); + } + databaseSubtypeObject.getAddressParams().add(addressParamList); + databaseSubtypeObject.setNumAddressParams(addressFieldNames.size()); + } + } + + if(numZigbeeAddresses > 0) { + String temp = prop.getProperty("TYPE_" + i + "_" + j + "_ZBADDRESS_FIELDS"); + Scanner scanner = new Scanner(temp); + ArrayList zigbeeAddressFieldNames = new ArrayList<>(); + while (scanner.hasNext()) { + zigbeeAddressFieldNames.add(scanner.next()); + } + //fill in the address fields for each subtype. May have to do multiple times for some subtypes + System.out.println("num addresses" + numZigbeeAddresses); + for (int k = 0; k < numZigbeeAddresses; k++) { + ArrayList> zigbeeAddressParamList = new ArrayList<>(); + for (int l = 0; l < zigbeeAddressFieldNames.size(); l++) { + // System.out.println(prop.getProperty(zigbeeAddressFieldNames.get(l) + "_" + i + "_" + j + "_ADD_" + k)); + String fieldValue = prop.getProperty(zigbeeAddressFieldNames.get(l) + "_" + i + "_" + j + "_ADD_" + k); + //System.out.println("prop command: " + " FIELD VALUE " + fieldValue); + Pair fieldPair = new Pair<>(zigbeeAddressFieldNames.get(l), fieldValue); + zigbeeAddressParamList.add(fieldPair); + } + databaseSubtypeObject.getZigbeeAddressParams().add(zigbeeAddressParamList); + databaseSubtypeObject.setNumZigbeeParams(zigbeeAddressFieldNames.size()); + } + } + + + + + + + + + + //fill in the device fields for each subtype. There should only be up to 1 set of device fields + int numDevFields = Integer.parseInt(prop.getProperty("TYPE_" + i + "_" + j + "_NUM_OF_DEVICE_INFO")); + if(numDevFields > 0) { + String temp = prop.getProperty("TYPE_" + i + "_" + j + "_" + "DEVICE_FIELDS"); + Scanner scanner = new Scanner(temp); + ArrayList addressFieldNames = new ArrayList<>(); + while (scanner.hasNext()) { + addressFieldNames.add(scanner.next()); + } + for (int l = 0; l < addressFieldNames.size(); l++) { + String fieldValue = prop.getProperty(addressFieldNames.get(l) + "_" + i + "_" + j); + Pair fieldPair = new Pair<>(addressFieldNames.get(l), fieldValue); + databaseSubtypeObject.addParam(fieldPair); + } + databaseSubtypeObject.setNumParams(addressFieldNames.size()); + } + databaseTypeObject.addSubtype(subtypeName, databaseSubtypeObject); + } + System.out.println(); + databaseObject.addTypeObject( type, databaseTypeObject); + } + //Now add individual instances of each device + + + Scanner scanner = new Scanner(idInformation); + String temp = ""; + while (scanner.hasNext()) { + temp = scanner.next(); + Set typeset = databaseObject.getKeySet(); + for (String key : typeset) { + DatabaseTypeObject typeObject = databaseObject.getTypeObject(key); + Set subtypeset = typeObject.getKeySet(); + if (subtypeset.contains(temp)) { + DatabaseSubtypeObject subtypeObject = typeObject.getSubtypeObject(temp); + subtypeObject.addDevice(scanner.next()); + break; + } + } + } + + + + + return databaseObject; + } + + + + //starts a new file instead of appending it + public static void writeToNewFile(String filename, String data, Context context) { + try { + OutputStreamWriter outputStreamWriter = new OutputStreamWriter(context. + openFileOutput(filename, Context.MODE_PRIVATE)); + BufferedWriter writer = new BufferedWriter(outputStreamWriter); + writer.write(data); + writer.newLine(); + writer.close(); + } catch (IOException e) { + Log.e("Exception", "File write failed: " + e.toString()); + } + } + + public static ArrayList getMACAddressesDevDat(String filename, Context context) { + ArrayList macAddresses = new ArrayList<>(); + String devicedat = ConfigFileIO.readFromFile(filename, context); + System.out.println(devicedat); + Scanner scanner = new Scanner(devicedat); + if(scanner.hasNext()) { + do { + scanner.next(); + macAddresses.add(scanner.next()); + scanner.next(); + } while (scanner.hasNext()); + System.out.println(devicedat); + } + return macAddresses; + } + + public static ArrayList getMACAddressesDHCP(String filename, Context context) { + ArrayList macAddresses = new ArrayList<>(); + String dhcp = ConfigFileIO.readFromFile(filename, context); + Scanner scanner = new Scanner(dhcp); + do{ + scanner.next(); + macAddresses.add(scanner.next()); + scanner.next(); + scanner.next(); + scanner.next(); + }while(scanner.hasNext()); + System.out.println(dhcp); + return macAddresses; + } + + +} diff --git a/others/lede-gui/src/main/java/com/example/lede2/DatabaseActivity.java b/others/lede-gui/src/main/java/com/example/lede2/DatabaseActivity.java new file mode 100644 index 0000000..d5a3161 --- /dev/null +++ b/others/lede-gui/src/main/java/com/example/lede2/DatabaseActivity.java @@ -0,0 +1,55 @@ +package com.example.lede2; + +import android.content.Context; +import android.content.Intent; +import android.os.Bundle; +import android.support.v7.app.AppCompatActivity; +import android.util.Log; +import android.view.View; +import android.view.inputmethod.InputMethodManager; +import android.widget.Button; + +/** + * Created by Brian on 2/16/2018. + */ + +public class DatabaseActivity extends AppCompatActivity implements View.OnClickListener, + View.OnFocusChangeListener { + Button insertToDatabase; + Button deleteFromDatabase; + + + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.database); + + insertToDatabase = (Button) findViewById(R.id.doneDrivers); + + deleteFromDatabase = (Button) findViewById(R.id.deleteFromDatabase); + insertToDatabase.setOnClickListener(this); + deleteFromDatabase.setOnClickListener(this); + + } + + @Override + public void onClick(View view) { + if (view == insertToDatabase) { + Log.d("CLICKING", "Clicking on add device!"); + startActivity(new Intent(this, AddDeviceActivity.class)); + } + if (view == deleteFromDatabase) { + Log.d("CLICKING", "Clicking on install zigbee!"); + startActivity(new Intent(this, DeleteDeviceActivity.class)); + } + + } + + public void onFocusChange(View view, boolean hasFocus) { + InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); + if (hasFocus) { + imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); + } else { + imm.hideSoftInputFromWindow(view.getWindowToken(), 0); + } + } +} \ No newline at end of file diff --git a/others/lede-gui/src/main/java/com/example/lede2/DatabaseObject.java b/others/lede-gui/src/main/java/com/example/lede2/DatabaseObject.java new file mode 100644 index 0000000..b49de7b --- /dev/null +++ b/others/lede-gui/src/main/java/com/example/lede2/DatabaseObject.java @@ -0,0 +1,44 @@ +package com.example.lede2; + +import android.provider.ContactsContract; + +import java.util.ArrayList; +import java.util.Hashtable; +import java.util.List; +import java.util.Set; + +/** + * Created by Brian on 2/28/2018. + */ + /*hierarchy of this object is dbobject -> dbtypeobject -> dbsubtypeobject + dbobject holds a hashtable of typeobject and typeobject holds a hashtable of subtypeobject + structure is similar across all levels, subtype obejct also holds the individual instances */ +public class DatabaseObject { + private int numTypes; + Hashtable types; + + public DatabaseObject(){ + numTypes = 0; + types = new Hashtable(); + + } + + public void addTypeObject(String name, DatabaseTypeObject typeObject){ + if(!types.contains(name)){ + types.put(name, typeObject); + numTypes++; + } + } + public void deleteTypeObject(String name){ + if(types.contains(name)){ + types.remove(name); + numTypes--; + } + } + public DatabaseTypeObject getTypeObject(String name){ + return types.get(name); + } + public Set getKeySet(){ + return types.keySet(); + } +} diff --git a/others/lede-gui/src/main/java/com/example/lede2/DatabaseSubtypeObject.java b/others/lede-gui/src/main/java/com/example/lede2/DatabaseSubtypeObject.java new file mode 100644 index 0000000..c53b344 --- /dev/null +++ b/others/lede-gui/src/main/java/com/example/lede2/DatabaseSubtypeObject.java @@ -0,0 +1,154 @@ +package com.example.lede2; + +import android.util.Pair; + +import java.lang.reflect.Array; +import java.util.ArrayList; +import java.util.List; + +import javax.sql.StatementEvent; + +/** + * Created by Brian on 3/5/2018. + */ + +public class DatabaseSubtypeObject { + + //param and address params are the database column names + //devices are the specific instances found on the database + private int numParams; + private int numAddresses; + private int numAddressParams; + private int numZigbeeParams; + private int numZigbeeAddresses; + private ArrayList> params; + //outer list = numOf addresses, inner list = num of params, inner pair = field name and value + private ArrayList>> addressParams; + private ArrayList>> zigbeeAddressParams; + private List devices; + private String nextID; + String name; + private String tag; + + + + public DatabaseSubtypeObject(String name, String tag, int numAddresses, int numZigbeeAddresses){ + numParams = 0; + numAddressParams = 0; + this.numAddresses = numAddresses; + this.numZigbeeAddresses = numZigbeeAddresses; + params = new ArrayList>(); + addressParams = new ArrayList<>(); + zigbeeAddressParams = new ArrayList<>(); + devices = new ArrayList(); + this.name = name; + this.tag = tag; + if(devices.isEmpty()){ + nextID = tag+"1"; + } + } + public void addDevice(String device){ + devices.add(device); + setNextID(); + } + public void addParam(Pair param){ + if(!params.contains(param)){ + params.add(param); + numParams++; + } + } + + public void addAddressParam(int i, Pair param){ + if(!addressParams.get(i).contains(param)){ + addressParams.get(i).add(param); + numAddressParams++; + } + } + + + public void deleteParam(String param){ + if(params.contains(param)){ + params.remove(param); + numParams--; + } + } + public ArrayList> getParams(){ + return this.params; + } + public ArrayList>> getAddressParams(){ + return this.addressParams; + } + public String getName(){ + return this.name; + } + public int getNumParams() { + return numParams; + } + + public int getNumAddressParams() { + return numAddressParams; + } + + public List getDevices() { + return devices; + } + public String getNextID(){ + return nextID; + } + + //sets the field which is used to generate the next available id + //needs to fix so it it doesn't rely on the first instance in the list + public void setNextID(){ + String id = ""; + ArrayList ids = new ArrayList<>(); + if(devices.isEmpty()){ + nextID = tag+"1"; + return; + } + if(devices.size() > 0 && devices.get(0) != null) { + for (int i = 0; i < devices.size(); i++) { + ids.add(devices.get(i).substring(2)); + } + } + int count = 1; + boolean doesNotContain = true; + + //should you set boolean to false or break; + while(doesNotContain) { + Integer idValue = new Integer(count); + if(ids.contains(idValue.toString())){ + count += 1; + } + else + { + doesNotContain = false; + } + } + + id = tag + String.valueOf(count); + nextID = id; + } + + public void insertID(){ + devices.add(this.nextID); + setNextID(); + } + + public void deleteDevice(String DeviceID){ + devices.remove(DeviceID); + setNextID(); + } + public void setNumAddressParams(int numParams){ + numAddressParams = numParams; + } + public void setNumParams(int numParams){ + numParams = numParams; + } + public void setNumZigbeeParams(int numParams){ this.numZigbeeParams = numParams; } + public int getNumAddresses(){ + return this.numAddresses; + } + public int getNumZigbeeAddresses(){ return this.numZigbeeAddresses; } + public ArrayList>> getZigbeeAddressParams(){return this.zigbeeAddressParams; } + +} diff --git a/others/lede-gui/src/main/java/com/example/lede2/DatabaseTypeObject.java b/others/lede-gui/src/main/java/com/example/lede2/DatabaseTypeObject.java new file mode 100644 index 0000000..3c1fcd3 --- /dev/null +++ b/others/lede-gui/src/main/java/com/example/lede2/DatabaseTypeObject.java @@ -0,0 +1,54 @@ +package com.example.lede2; + +import android.provider.ContactsContract; + +import java.util.ArrayList; +import java.util.Hashtable; +import java.util.List; +import java.util.Set; + +/** + * Created by Brian on 3/5/2018. + */ + +public class DatabaseTypeObject { + private int numSubtypes; + private Hashtable subtypes; + protected String tag; + private String name; + + public DatabaseTypeObject(String name, String tag){ + numSubtypes = 0; + subtypes = new Hashtable(); + this.name = name; + this.tag = tag; + } + + public void addSubtype(String name, DatabaseSubtypeObject subtypeObject){ + if(!subtypes.contains(name)){ + subtypes.put(name, subtypeObject); + numSubtypes++; + } + } + public void deleteSubtype(String name){ + if(subtypes.contains(name)){ + subtypes.remove(name); + numSubtypes--; + } + } + public DatabaseSubtypeObject getSubtypeObject(String name){ + return subtypes.get(name); + } + public Set getKeySet(){ + return subtypes.keySet(); + } + public String getName(){ + return this.name; + } + public void setTag(String tag){ + this.tag = tag; + } + public String getTag(){ + return tag; + } +} diff --git a/others/lede-gui/src/main/java/com/example/lede2/DeleteDeviceActivity.java b/others/lede-gui/src/main/java/com/example/lede2/DeleteDeviceActivity.java index 3036805..3f4a796 100644 --- a/others/lede-gui/src/main/java/com/example/lede2/DeleteDeviceActivity.java +++ b/others/lede-gui/src/main/java/com/example/lede2/DeleteDeviceActivity.java @@ -1,85 +1,291 @@ -package com.example.lede2; - -import android.content.Context; -import android.os.Bundle; -import android.support.v7.app.AppCompatActivity; -import android.view.View; -import android.view.inputmethod.InputMethodManager; -import android.widget.Button; -import android.widget.EditText; -import android.widget.TextView; - -public class DeleteDeviceActivity extends AppCompatActivity implements View.OnClickListener, View.OnFocusChangeListener { - - Button deleteButton; - Button doneButton; - EditText device_id; - EditText device_type; - EditText device_subtype; - EditText device_address_subtype; - TextView status; - private SSH_MySQL ssh;//Connection object between Android & Host - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_delete_device); - - deleteButton = (Button) findViewById(R.id.delete); - doneButton = (Button) findViewById(R.id.done); - device_id = (EditText)findViewById(R.id.device_id); - device_type = (EditText)findViewById(R.id.device_type); - device_subtype = (EditText)findViewById(R.id.device_subtype); - device_address_subtype = (EditText)findViewById(R.id.device_address_subtype); - status = (TextView)findViewById(R.id.textStatus); - - deleteButton.setOnClickListener(this); - doneButton.setOnClickListener(this); - device_id.setOnFocusChangeListener(this); - device_type.setOnFocusChangeListener(this); - device_subtype.setOnFocusChangeListener(this); - device_address_subtype.setOnFocusChangeListener(this); - ssh = new SSH_MySQL(); - } - - @Override - public void onClick(View v) { - if(v == deleteButton){ - // Remove the entry based on ID, type, and subtype - ssh.execute(MainActivity.DEF_DELETE_CMD + " " + - device_id.getText().toString() + " " + - device_type.getText().toString() + " " + - device_subtype.getText().toString() + ";" + - // Also remove the device address - MainActivity.DEF_DELETE_ADDRESS_CMD + " " + - device_id.getText().toString() + " " + - device_address_subtype.getText().toString() - ); - device_id.setText(""); - device_type.setText(""); - device_subtype.setText(""); - device_address_subtype.setText(""); - status.setText("Successfully deleted " + device_id.getText()); - /*try { - Thread.sleep(2000); - } catch (Exception ex) { - ex.printStackTrace(); - } - status.setText("");*/ - } - if(v == doneButton){ - finish(); - } - - } - - @Override - public void onFocusChange(View view, boolean hasFocus) { - InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); - if (hasFocus) { - imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); - } else { - imm.hideSoftInputFromWindow(view.getWindowToken(), 0); - } - } -} +package com.example.lede2; + +import android.app.ProgressDialog; +import android.content.Context; +import android.os.Bundle; +import android.support.v7.app.AppCompatActivity; +import android.util.Log; +import android.view.View; +import android.view.inputmethod.InputMethodManager; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; +import android.widget.Button; +import android.widget.EditText; +import android.widget.Spinner; + +import java.io.File; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Scanner; +import java.util.Set; + +public class DeleteDeviceActivity extends AppCompatActivity implements View.OnClickListener, View.OnFocusChangeListener { + + DatabaseObject databaseObject; + protected String database_information_filename; + protected String id_information_filename; + protected String local_id_information_filename; + Button deleteButton; + Button doneButton; + Spinner spinner1; + Spinner spinner2; + Spinner spinner3; + Context context; + private SSH_MySQL ssh;//Connection object between Android & Host + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_delete_device); + + database_information_filename = this.getString(R.string.device_param_config_filename); + id_information_filename = this.getString(R.string.device_id_config_filename); + local_id_information_filename = this.getString(R.string.device_id_config_filename); + deleteButton = (Button) findViewById(R.id.delDoneButton); + spinner1 = (Spinner) findViewById(R.id.delspinner1); + spinner2 = (Spinner) findViewById(R.id.delspinner2); + spinner3 = (Spinner) findViewById(R.id.delspinner3); + context = this; + + //similar to install format. Sets the subtypes to appear based on type chosen + spinner1.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + @Override + public void onItemSelected(AdapterView adapterView, View view, int i, long l) { + String selectedType = spinner1.getSelectedItem().toString(); + Set keysForSubType = (databaseObject.getTypeObject(selectedType)).getKeySet(); + ArrayList subtypes = new ArrayList(); + for(String key: keysForSubType){ + subtypes.add(key); + } + Collections.sort(subtypes); + ArrayAdapter subtypeAdapter = new ArrayAdapter(context, android.R.layout.simple_spinner_dropdown_item, subtypes); + subtypeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + spinner2.setAdapter(subtypeAdapter); + } + + + @Override + public void onNothingSelected(AdapterView adapterView) { + + } + }); + //sets the instances of devices to appear based on selected subtype + spinner2.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + @Override + public void onItemSelected(AdapterView adapterView, View view, int i, long l) { + DatabaseSubtypeObject subtypeObject = getCurrentSubtypeObject(); + List deviceList = subtypeObject.getDevices(); + Collections.sort(deviceList); + ArrayList devices = new ArrayList<>(); + for(String device: deviceList){ + devices.add(device); + } + Collections.sort(devices); + ArrayAdapter deviceAdapter = new ArrayAdapter(context, android.R.layout.simple_spinner_dropdown_item, devices); + deviceAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + spinner3.setAdapter(deviceAdapter); + } + + @Override + public void onNothingSelected(AdapterView adapterView) { + + } + }); + + + + + deleteButton.setOnClickListener(this); + ssh = new SSH_MySQL(); + String databaseInformation = ConfigFileIO.readFromFile( + database_information_filename, this); + String idInformation = ConfigFileIO.readFromFile(local_id_information_filename, this); + databaseObject = ConfigFileIO.createDatabaseObject(context, idInformation ); + Set keysForType = databaseObject.getKeySet(); + ArrayList types = new ArrayList(); + for(String key: keysForType){ + types.add(key); + } + Collections.sort(types); + ArrayAdapter typeAdapter = new ArrayAdapter(this, android.R.layout.simple_spinner_dropdown_item, types); + typeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + spinner1.setAdapter(typeAdapter); + } + + @Override + public void onClick(View v) { + if(v == deleteButton){ + DatabaseSubtypeObject subtypeObject = getSubtypeObject(); + // Remove the entry based on ID, type, and subtype + String deleteCommand = MainActivity.DEF_DELETE_CMD + " " + + spinner3.getSelectedItem().toString() + " " + + spinner1.getSelectedItem().toString() + " " + + spinner2.getSelectedItem().toString() + ";"; + + + // Also remove the device address. Some need multiple address deletions such as ihome + if(subtypeObject.getNumAddresses() > 1) { + for(int i = 1; i <= subtypeObject.getNumAddresses(); i++){ + deleteCommand += MainActivity.DEF_DELETE_ADDRESS_CMD + " " + + spinner3.getSelectedItem().toString() + " " + + spinner2.getSelectedItem().toString() + "Add" + i + ";"; + } + } + else{ + deleteCommand += MainActivity.DEF_DELETE_ADDRESS_CMD + " " + + spinner3.getSelectedItem().toString() + " " + + spinner2.getSelectedItem().toString() + "Add;"; + + } + + deleteCommand += context.getResources().getString(R.string.delete_zb_cmd) + " " + + spinner3.getSelectedItem().toString() + " " + + spinner2.getSelectedItem().toString() + "ZBAdd;"; + //need to add delete from zigbee + + + + ProgressDialog dialog = new ProgressDialog(this); + dialog.setMessage("Please Wait"); + dialog.setCancelable(false); + dialog.setInverseBackgroundForced(false); + dialog.show(); + + + System.out.println(deleteCommand); + ssh = new SSH_MySQL(); + ssh.execute(deleteCommand); + + deleteDeviceFromDatabase(); + updateIoTDeviceAddress(); + updateSetList(); + + dialog.dismiss(); + finish(); + + } + + + } + + @Override + public void onFocusChange(View view, boolean hasFocus) { + InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); + if (hasFocus) { + imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); + } else { + imm.hideSoftInputFromWindow(view.getWindowToken(), 0); + } + } + public DatabaseSubtypeObject getCurrentSubtypeObject(){ + return databaseObject.getTypeObject(spinner1. + getSelectedItem().toString()).getSubtypeObject(spinner2.getSelectedItem().toString()); + } + + //rewrites the local config file to not contain the deleted instance + public void deleteDeviceFromDatabase(){ + DatabaseSubtypeObject subtypeObject = getCurrentSubtypeObject(); + String subtype = spinner2.getSelectedItem().toString(); + String id = spinner3.getSelectedItem().toString(); + subtypeObject.deleteDevice(id); + String deviceToDelete = subtype + " " + id; + //do it for the database file. also need + String databaseInformation = ConfigFileIO.readFromFile(local_id_information_filename, this ); + Scanner scanner = new Scanner(databaseInformation); + ConfigFileIO.writeToNewFile(local_id_information_filename, "", this); + while (scanner.hasNextLine()){ + String temp = scanner.nextLine(); + if (!temp.equals(deviceToDelete)){ + ConfigFileIO.writeToFile(local_id_information_filename, temp, this); + } + } + } + + + private DatabaseSubtypeObject getSubtypeObject(){ + DatabaseSubtypeObject subtypeObject = databaseObject.getTypeObject( + spinner1.getSelectedItem().toString()).getSubtypeObject( + spinner2.getSelectedItem().toString()); + return subtypeObject; + } + + private void addSSHResultsToConfig(List results, String filename) { + File dir = getFilesDir(); + File file = new File(dir, filename); + file.delete(); + for (int i = 0; i < results.size(); i++) { + ConfigFileIO.writeToFile(filename, results.get(i), this); + } + finish(); + } + + private void updateSetList(){ + SSH_MySQL ssh = new SSH_MySQL(); + String command = this.getString(R.string.updateSetList); + List results = new ArrayList<>(); + String setListFilename = this.getString(R.string.setListFilename); + try { + ssh.execute(command); + Thread.sleep(1000);//To execute asyntask in ssh object, we have to sleep main thread + results = ssh.getResultLines(); + while(results.size() == 0){ + Thread.sleep(500); + results = ssh.getResultLines(); + } + System.out.println(results); + } catch (Exception e) { + Log.d("Sleep exception", "exception at getSetsAndRelations"); + } +// ssh = new SSH_MySQL(); +// command = this.getString(R.string.getSetList); +// try { +// ssh.execute(command); +// Thread.sleep(1000);//To execute asyntask in ssh object, we have to sleep main thread +// results = ssh.getResultLines(); +// while(results.size() == 0){ +// Thread.sleep(500); +// results = ssh.getResultLines(); +// } +// System.out.println(results); +// } catch (Exception e) { +// Log.d("Sleep exception", "exception at getSetsAndRelations"); +// } +// addSSHResultsToConfig(results, setListFilename); + + } + private void updateIoTDeviceAddress(){ + SSH_MySQL ssh = new SSH_MySQL(); + String command = this.getString(R.string.updateIoTDeviceAddress); + List results = new ArrayList<>(); + String iotDeviceAddressFilename = this.getString(R.string.updateIoTDeviceAddress); + try { + ssh.execute(command); + Thread.sleep(1000);//To execute asyntask in ssh object, we have to sleep main thread + results = ssh.getResultLines(); + while(results.size() == 0){ + Thread.sleep(500); + results = ssh.getResultLines(); + } + System.out.println(results); + } catch (Exception e) { + Log.d("Sleep exception", "exception at getSetsAndRelations"); + } +// ssh = new SSH_MySQL(); +// command = this.getString(R.string.getIoTDeviceAddress); +// try { +// ssh.execute(command); +// Thread.sleep(1000);//To execute asyntask in ssh object, we have to sleep main thread +// results = ssh.getResultLines(); +// while(results.size() == 0){ +// Thread.sleep(500); +// results = ssh.getResultLines(); +// } +// System.out.println(results); +// } catch (Exception e) { +// Log.d("Sleep exception", "exception at getSetsAndRelations"); +// } +// addSSHResultsToConfig(results, iotDeviceAddressFilename); + } + +} diff --git a/others/lede-gui/src/main/java/com/example/lede2/DriverTypeSelectActivity.java b/others/lede-gui/src/main/java/com/example/lede2/DriverTypeSelectActivity.java new file mode 100644 index 0000000..da74bf9 --- /dev/null +++ b/others/lede-gui/src/main/java/com/example/lede2/DriverTypeSelectActivity.java @@ -0,0 +1,8 @@ +package com.example.lede2; + +/** + * Created by Brian on 5/17/2018. + */ + +public class DriverTypeSelectActivity { +} diff --git a/others/lede-gui/src/main/java/com/example/lede2/DriversAddActivity.java b/others/lede-gui/src/main/java/com/example/lede2/DriversAddActivity.java new file mode 100644 index 0000000..e45aff4 --- /dev/null +++ b/others/lede-gui/src/main/java/com/example/lede2/DriversAddActivity.java @@ -0,0 +1,246 @@ +package com.example.lede2; + +import android.content.Context; +import android.content.Intent; +import android.os.Bundle; +import android.util.Log; +import android.util.Pair; +import android.view.View; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; +import android.widget.Button; +import android.widget.ListView; +import android.widget.Spinner; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Properties; +import java.util.Set; + +/** + * Created by Brian on 4/16/2018. + */ + +public class DriversAddActivity extends ApplicationWithRelations{ + + private SSH_MySQL getSetsAndRelations; + private SSH_MySQL getSetList; + private ArrayList relationNames; //relations in this application + + Context context; + private HashMap> availableSets; //all possible sets pulled from pi + + + @Override + protected void onCreate( Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.drivers_add); + super.context = this; + context = super.context; + getSetsAndRelations = new SSH_MySQL(); + getSetList = new SSH_MySQL(); + Intent intent = getIntent(); + String getSetsCommand = intent.getExtras().getString("getConfigCommand"); + + + String getIoTDeviceAddressListCommand = this.getString(R.string.getIoTDeviceAddress); //edit this to new file + List results = new ArrayList<>(); + final String driverConfigFilename = this.getString(R.string.driverConfigFilename); + relations = new HashMap<>(); + relationNames = new ArrayList<>(); + relationNameSpinner = (Spinner) findViewById(R.id.selectedRelation); + relationLeftSpinner = (Spinner) findViewById(R.id.relationLeftSpinner); + relationRightSpinner = (Spinner) findViewById(R.id.relationRightSpinner); + addRelationButton = (Button) findViewById(R.id.addRelationButton); + doneRelationButton = (Button) findViewById(R.id.addRelationDoneButton); + deleteRelationButton = (Button) findViewById(R.id.addRelationDeleteButton); + setOrRelationSpinner = (Spinner) findViewById(R.id.setsOrRelations); + super.hasIndependentSets = true; + super.independentSetNames = new ArrayList<>(); + super.independentSetList = new HashMap<>(); + super.addedSetList = new HashMap<>(); + super.addedIndependentSets = new HashMap<>(); + + super.hasRelations = false; + + addRelationButton.setOnClickListener(this); + doneRelationButton.setOnClickListener(this); + deleteRelationButton.setOnClickListener(this); + addRelationsListView = (ListView) findViewById(R.id.selectedRelationsList); + addRelationsListView.setFocusable(false); + super.addedRelations = new HashMap<>(); + HashSet> addedrelationsSet = new HashSet<>(); + //addedRelations.put("", addedrelationsSet); + super.applicationSetList = new HashSet<>(); + setHashMap = new HashMap<>(); + System.out.println("THIS COMMAND " + getSetsCommand); + + //pull data from config file on iotuser + try { + getSetsAndRelations.execute(getSetsCommand); + Thread.sleep(1000);//To execute asyntask in ssh object, we have to sleep main thread + results = getSetsAndRelations.getResultLines(); + while(results.size() == 0){ + Thread.sleep(500); + results = getSetsAndRelations.getResultLines(); + } + System.out.println(results); + } catch (Exception e) { + Log.d("Sleep exception", "exception at getSetsAndRelations"); + } + + addSSHResultsToConfig(results, driverConfigFilename); + System.out.println("read from file: " + ConfigFileIO.readFromFile(driverConfigFilename, this)); + super.prop = new Properties(); + File file = new File(getApplicationContext().getFilesDir(), driverConfigFilename); + FileInputStream fis = null; + try{ + fis = new FileInputStream(file); + super.prop.load(fis); + fis.close(); + } + catch (IOException ex){ + System.out.println("Error when reading SpeakerController Config file "); + ex.printStackTrace(); + } + + //add sets relations to the relation hashmap + super.numFields = Integer.parseInt(super.prop.getProperty("FIELD_NUMBER")); + for(int i = 0; i < super.numFields; i++){ + String name = (super.prop.getProperty("FIELD_" + i)); + if(super.prop.getProperty("FIELD_TYPE_" + i).equals("IoTRelation")) { + String relationPair = super.prop.getProperty("FIELD_CLASS_0_" + i) + "," + super.prop.getProperty("FIELD_CLASS_1_" + i); + addPair(name, relationPair); + super.hasRelations = true; + relationNames.add(name); + } + if(super.prop.getProperty("FIELD_TYPE_" + i).equals("IoTSet")) { + if(super.prop.getProperty("FIELD_INDEPENDENT_" + i).equals("TRUE")){ + independentSetList.put(name, super.prop.getProperty("FIELD_CLASS_" + i)); + independentSetNames.add(name); + } + else{ + setHashMap.put(name, super.prop.getProperty("FIELD_CLASS_" + i)); + + } + } + } + //pull availableSets file from iotuser + try { + getSetList.execute(getIoTDeviceAddressListCommand); + Thread.sleep(1000);//To execute asyntask in ssh object, we have to sleep main thread + results = getSetList.getResultLines(); + while(results.size() == 0){ + Thread.sleep(500); + results = getSetList.getResultLines(); + } + System.out.println(results); + } catch (Exception e) { + Log.d("Sleep exception", "exception at getSetsAndRelations"); + } + String setListFilename = this.getString(R.string.setListFilename); + addSSHResultsToConfig(results, setListFilename); + availableSets = createSetList(setListFilename); + System.out.println(); + + ArrayList setsOrRelationArrayList = new ArrayList<>(); + if(super.hasIndependentSets){ + setsOrRelationArrayList.add("SETS"); + + } + if(super.hasRelations) { + setsOrRelationArrayList.add("RELATIONS"); + } + ArrayAdapter setsOrRelationsArrayAdapter = new ArrayAdapter(context, android.R.layout.simple_spinner_dropdown_item, setsOrRelationArrayList); + setOrRelationSpinner.setAdapter(setsOrRelationsArrayAdapter); + + + + setOrRelationSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + @Override + public void onItemSelected(AdapterView adapterView, View view, int i, long l) { + //set array adapter values = listed relations + if(setOrRelationSpinner.getSelectedItem().toString().equals("RELATIONS")) { + ArrayAdapter nameAdapter = new ArrayAdapter(context, android.R.layout.simple_spinner_dropdown_item, relationNames); + nameAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + relationNameSpinner.setAdapter(nameAdapter); + } + else{ + ArrayAdapter nameAdapter = new ArrayAdapter(context, android.R.layout.simple_spinner_dropdown_item, independentSetNames); + nameAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + relationNameSpinner.setAdapter(nameAdapter); + } + } + + @Override + public void onNothingSelected(AdapterView adapterView) { + + } + }); + + + + + //sets left and right possible values to registered devices in the sets + relationNameSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + @Override + public void onItemSelected(AdapterView adapterView, View view, int i, long l) { + + + if(setOrRelationSpinner.getSelectedItem().toString().equals("RELATIONS")) { + relationRightSpinner.setVisibility(View.VISIBLE); + String selectedRelation = relationNameSpinner.getSelectedItem().toString(); + ArrayList availableDevicesLeft = availableSets.get(relations.get(selectedRelation).first); + ArrayList availableDevicesRight = availableSets.get(relations.get(selectedRelation).second); + + ArrayAdapter leftAdapter = new ArrayAdapter(context, android.R.layout.simple_spinner_dropdown_item, availableDevicesLeft); + ArrayAdapter rightAdapter = new ArrayAdapter(context, android.R.layout.simple_spinner_dropdown_item, availableDevicesRight); + + leftAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + rightAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + relationLeftSpinner.setAdapter(leftAdapter); + relationRightSpinner.setAdapter(rightAdapter); + } + else{ + relationRightSpinner.setVisibility(View.GONE); + + String selectedSet = relationNameSpinner.getSelectedItem().toString(); + ArrayList availableDevicesLeft = availableSets.get(independentSetList.get(selectedSet)); + Collections.sort(availableDevicesLeft); + ArrayAdapter leftAdapter = new ArrayAdapter(context, android.R.layout.simple_spinner_dropdown_item, availableDevicesLeft); + leftAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + relationLeftSpinner.setAdapter(leftAdapter); + } + } + @Override + public void onNothingSelected(AdapterView adapterView) { + } + }); + + ArrayList addedRelationsArrayList = new ArrayList<>(); + Set relationTypes = super.addedRelations.keySet(); + for(String s: relationTypes) { + for (Pair temp : super.addedRelations.get(s)) { + addedRelationsArrayList.add(temp.first + " " + temp.second); + } + } + adapter = new ArrayAdapter(context, android.R.layout.simple_list_item_multiple_choice, addedRelationsArrayList); + addRelationsListView.setAdapter(adapter); + addRelationsListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { + public void onItemClick(AdapterView parent, View view, int position, long id) { + }}); + for(int i= 0; i < relationNames.size(); i++){ + Pair tempPair = relations.get(relationNames.get(i)); + applicationSetList.add(tempPair.first); + applicationSetList.add(tempPair.second); + } + } + + +} + diff --git a/others/lede-gui/src/main/java/com/example/lede2/DriversSelectActivity.java b/others/lede-gui/src/main/java/com/example/lede2/DriversSelectActivity.java new file mode 100644 index 0000000..90c091f --- /dev/null +++ b/others/lede-gui/src/main/java/com/example/lede2/DriversSelectActivity.java @@ -0,0 +1,149 @@ +package com.example.lede2; + +import android.app.ProgressDialog; +import android.content.Context; +import android.content.Intent; +import android.os.Bundle; +import android.support.design.widget.Snackbar; +import android.support.v7.app.AppCompatActivity; +import android.util.Log; +import android.view.View; +import android.view.inputmethod.InputMethodManager; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; +import android.widget.Button; +import android.widget.Spinner; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Properties; + +/** + * Created by Brian on 2/16/2018. + */ + +public class DriversSelectActivity extends AppCompatActivity implements View.OnClickListener, View.OnFocusChangeListener { + Spinner typeSpinner; + Button doneButton; + Properties prop; + ProgressDialog dialog; + + + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.drivers); + SSH_MySQL getListOfDrivers = new SSH_MySQL(); + typeSpinner = (Spinner) findViewById(R.id.spinnerDrivers); + doneButton = (Button) findViewById(R.id.doneDrivers); + String getListOfDriversCommand = this.getString(R.string.getListOfDriversCommand); + List results = new ArrayList<>(); + String driversListFilename = this.getString(R.string.driversListFilename); + + //get list of all driver types + try { + getListOfDrivers.execute(getListOfDriversCommand); + Thread.sleep(1000);//To execute asyntask in ssh object, we have to sleep main thread + results = getListOfDrivers.getResultLines(); + while(results.size() == 0){ + Thread.sleep(500); + results = getListOfDrivers.getResultLines(); + } + System.out.println(results); + } catch (Exception e) { + Log.d("Sleep exception", "exception at getSetsAndRelations"); + } + + addSSHResultsToConfig(results, driversListFilename); + System.out.println("read from file: " + ConfigFileIO.readFromFile(driversListFilename, this)); + prop = new Properties(); + File file = new File(getApplicationContext().getFilesDir(), driversListFilename); + FileInputStream fis = null; + try{ + fis = new FileInputStream(file); + prop.load(fis); + fis.close(); + } + catch (IOException ex){ + System.out.println("Error when reading drivers list file "); + ex.printStackTrace(); + } + + ArrayList driverTypeList = new ArrayList(); + //add sets relations to the relation hashmap + int numFields = Integer.parseInt(prop.getProperty("FIELD_NUMBER")); + for(int i = 0; i < numFields; i++){ + driverTypeList.add(prop.getProperty("FIELD_" + i)); + } + ArrayAdapter typeAdapter = new ArrayAdapter(this, android.R.layout.simple_spinner_dropdown_item, driverTypeList); + typeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + typeSpinner.setAdapter(typeAdapter); + + + typeSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + @Override + public void onItemSelected(AdapterView adapterView, View view, int i, long l) { + } + + @Override + public void onNothingSelected(AdapterView adapterView) { + + } + }); + doneButton.setOnClickListener(this); + + } + + @Override + public void onClick(View view) { + if (view == doneButton) { + dialog = new ProgressDialog(this); + dialog.setMessage("Please Wait"); + dialog.setCancelable(false); + dialog.setInverseBackgroundForced(false); + dialog.show(); + + Log.d("CLICKING", "Clicking on done button!"); + //determine the where to cat based on user selection and go to next screen + //looks at config file for the command based on the user selection + String userSelection = typeSpinner.getSelectedItem().toString(); + String fromProperty = prop.getProperty(userSelection); + String command2 = prop.getProperty("COMMAND_PREFIX") + fromProperty; + Intent i = new Intent(this, DriversAddActivity.class); + i.putExtra("getConfigCommand", command2); + startActivity(i); + finish(); + } + + } + @Override + protected void onStop() { + super.onStop(); + if(dialog != null && dialog.isShowing()){ + dialog.dismiss(); + } + } + + + + public void onFocusChange(View view, boolean hasFocus) { + InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); + if (hasFocus) { + imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); + } else { + imm.hideSoftInputFromWindow(view.getWindowToken(), 0); + } + } + + protected void addSSHResultsToConfig(List results, String filename) { + ConfigFileIO.writeToNewFile(filename,"", this ); + File dir = getFilesDir(); + File file = new File(dir, filename); + file.delete(); + for (int i = 0; i < results.size(); i++) { + ConfigFileIO.writeToFile(filename, results.get(i), this); + } + } +} \ No newline at end of file diff --git a/others/lede-gui/src/main/java/com/example/lede2/EnrollDeviceActivity.java b/others/lede-gui/src/main/java/com/example/lede2/EnrollDeviceActivity.java deleted file mode 100644 index be1d04a..0000000 --- a/others/lede-gui/src/main/java/com/example/lede2/EnrollDeviceActivity.java +++ /dev/null @@ -1,167 +0,0 @@ -package com.example.lede2; - -import android.content.Context; -import android.content.Intent; -import android.net.ConnectivityManager; -import android.net.NetworkInfo; -import android.net.wifi.WifiInfo; -import android.net.wifi.WifiManager; -import android.support.v7.app.AppCompatActivity; -import android.os.Bundle; -import android.view.View; -import android.view.inputmethod.InputMethodManager; -import android.widget.Button; -import android.widget.EditText; -import android.widget.TextView; -import android.widget.Toast; -import android.util.Log; - -import java.util.Random; - -public class EnrollDeviceActivity extends AppCompatActivity implements View.OnClickListener, View.OnFocusChangeListener { - - private static final int REQUEST_RESULT = 1001; - Button done;//Done button in UI - Button wifi;//wifi button in UI - SSH ssh;//Connection object between Android & Router - Context context; - - TextView psk;//red letter in UI - String newpsk;//same as psk (different data type) - - EditText name;//device name newly registered in UI - String deviceName;//same as name(different data type) - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_enroll_device); - - ssh = new SSH(); - psk = (TextView) findViewById(R.id.add_psk); - done = (Button) findViewById(R.id.done); - wifi = (Button) findViewById(R.id.wifi); - name = (EditText) findViewById(R.id.name); - - done.setOnClickListener(this); - wifi.setOnClickListener(this); - name.setOnFocusChangeListener(this); - - //Make random password and show the password through EditText - newpsk = generateRandomPassword(); - psk.setText(newpsk); - // execute shell script (script's function -> change router password to newpsk) - ssh.execute("-ch " + newpsk); - try {//To execute asyntask in ssh object, we have to sleep main thread - Thread.sleep(1000); - } catch (Exception e) { - Log.d("SLEEP EXCEPTION", "SLEEP EXCEPTION occurs in onCreate method of EnrollDeviceActivity"); - } - } - - @Override - public void onFocusChange(View view, boolean hasFocus) {//function not to modify randomly generated password for newly registered device - InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); - if (hasFocus) { - imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); - } else { - imm.hideSoftInputFromWindow(view.getWindowToken(), 0); - } - } - - boolean isNetworkAvailable() {//check whether wifi connection is or not - Context context = getApplicationContext(); - ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); - NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); - boolean isConnected = activeNetwork != null && activeNetwork.isConnectedOrConnecting(); - return isConnected; - } - - @Override - public void onClick(View v) { - if (v == done) { - //Users try to execute shell scripts by pushing button, - //but problem could occur(application stop) if user push the button without wifi connection - //As a result, below function have to be implemented. - if (isNetworkAvailable() == false) {//without wifi connection - Toast t = Toast.makeText(this, R.string.connect, Toast.LENGTH_SHORT); - t.show(); - startActivity(new Intent(WifiManager.ACTION_PICK_WIFI_NETWORK)); - } else {//with wifi connection - deviceName = name.getText().toString(); - if(deviceName.equals("")){ - Toast t = Toast.makeText(this, R.string.empty_name,Toast.LENGTH_SHORT); - t.show(); - return; - } - context = getApplicationContext(); - if (getWifiName(context).equals("\""+ ConfigActivity.RSSID +"\"")) {//if wifi name is LEDE2 - String networkPass = psk.getText().toString();//random password - ssh = new SSH(); - - // execute shell script (script's function -> Save contents(Mac,Ip,Key,Name) on hostapd-psk) - ssh.execute("-co " + networkPass + " " + deviceName + " " + ConfigActivity.RPWD);//review!!!!!! - try {//To execute asyntask in ssh object, we have to sleep main thread - Thread.sleep(1000); - } catch (Exception e) { - Log.d("SLEEP EXCEPTION", "SLEEP EXCEPTION occurs in onClick method of EnrollDeviceActivity"); - } - finish();//Go back to the Main Activity - } else { //if name of wifi is not LEDE -> go to wifi configuration screen to change wifi type - Toast t = Toast.makeText(this, R.string.try_again, Toast.LENGTH_SHORT); - t.show(); - startActivity(new Intent(WifiManager.ACTION_PICK_WIFI_NETWORK)); - } - } - // Call activity that adds device - not doing this flow because we haven't found - // a way to change password without restarting WiFi - //startActivity(new Intent(this, AddDeviceActivity.class)); - //finish(); - } else if (v == wifi) { - startActivity(new Intent(WifiManager.ACTION_PICK_WIFI_NETWORK)); - } - } - - /******************************************************************************************************************************************************************/ - //Detect you are connected to a specific network. - /******************************************************************************************************************************************************************/ - public String getWifiName(Context context) { - WifiManager manager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); - if (manager.isWifiEnabled()) { - WifiInfo wifiInfo = manager.getConnectionInfo(); - if (wifiInfo != null) { - NetworkInfo.DetailedState state = WifiInfo.getDetailedStateOf(wifiInfo.getSupplicantState()); - if (state == NetworkInfo.DetailedState.CONNECTED || state == NetworkInfo.DetailedState.OBTAINING_IPADDR) { - return wifiInfo.getSSID(); - } - } - } - return null; - } - - /******************************************************************************************************************************************************************/ - // Generate a random password and return it - /******************************************************************************************************************************************************************/ - public String generateRandomPassword() { - String password = new String(); - - StringBuffer rndpassword = new StringBuffer(); - Random rnd = new Random(); - int digitnum = 20; - // Generate random 20digit password with upper / lower case alphabet + numbers - // There are 10 int nums, 26 lower alphabets, 26 upper alphabets. Total 62 - // So 2/12 possiblity of int, 5/12 lower, 5/12 upper alphabets. - for (int i = 0; i < digitnum; i++) { - int rIndex = rnd.nextInt(12); - if (rIndex >= 0 && rIndex < 2) { // 0 - 9 - rndpassword.append((rnd.nextInt(10))); - } else if (rIndex >= 2 && rIndex < 7) { // a-z - rndpassword.append((char) ((int) (rnd.nextInt(26)) + 97)); - } else { // A-Z - rndpassword.append((char) ((int) (rnd.nextInt(26)) + 65)); - } - } - password = rndpassword.toString(); - return password; - } -} diff --git a/others/lede-gui/src/main/java/com/example/lede2/HomeSecurity.java b/others/lede-gui/src/main/java/com/example/lede2/HomeSecurity.java new file mode 100644 index 0000000..513d70b --- /dev/null +++ b/others/lede-gui/src/main/java/com/example/lede2/HomeSecurity.java @@ -0,0 +1,232 @@ +package com.example.lede2; + +import android.content.Context; +import android.os.Bundle; +import android.util.Log; +import android.util.Pair; +import android.view.View; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; +import android.widget.Button; +import android.widget.ListView; +import android.widget.Spinner; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Properties; +import java.util.Set; + +/** + * Created by Brian on 4/16/2018. + */ + +public class HomeSecurity extends ApplicationWithRelations{ + + private SSH_MySQL getSetsAndRelations; + private SSH_MySQL getSetList; + private String filename; + private ArrayList relationNames; //relations in this application + + Context context; + private HashMap> availableSets; //all possible sets pulled from pi + + + @Override + protected void onCreate( Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.home_security); + super.context = this; + context = super.context; + getSetsAndRelations = new SSH_MySQL(); + getSetList = new SSH_MySQL(); + String getSetsAndRelationsCommand = this.getString(R.string.getHomeSecuritySetsAndRelationsCommand); + String getSetListCommand = this.getString(R.string.getSetList); + List results = new ArrayList<>(); + final String controllerConfigFilename = this.getString(R.string.homeSecurityControllerConfigFile); + filename = this.getString(R.string.setsAndRelationsFilename); + relations = new HashMap<>(); + relationNames = new ArrayList<>(); + relationNameSpinner = (Spinner) findViewById(R.id.selectedRelation); + relationLeftSpinner = (Spinner) findViewById(R.id.relationLeftSpinner); + relationRightSpinner = (Spinner) findViewById(R.id.relationRightSpinner); + addRelationButton = (Button) findViewById(R.id.addRelationButton); + doneRelationButton = (Button) findViewById(R.id.addRelationDoneButton); + deleteRelationButton = (Button) findViewById(R.id.addRelationDeleteButton); + setOrRelationSpinner = (Spinner) findViewById(R.id.setsOrRelations); + super.hasIndependentSets = true; + super.independentSetNames = new ArrayList<>(); + super.independentSetList = new HashMap<>(); + super.addedSetList = new HashMap<>(); + super.addedIndependentSets = new HashMap<>(); + + addRelationButton.setOnClickListener(this); + doneRelationButton.setOnClickListener(this); + deleteRelationButton.setOnClickListener(this); + addRelationsListView = (ListView) findViewById(R.id.selectedRelationsList); + addRelationsListView.setFocusable(false); + super.addedRelations = new HashMap<> (); + HashSet> addedrelationsSet = new HashSet<>(); + //addedRelations.put("", addedrelationsSet); + super.applicationSetList = new HashSet<>(); + setHashMap = new HashMap<>(); + //pull data from config file on iotuser + try { + getSetsAndRelations.execute(getSetsAndRelationsCommand); + Thread.sleep(1000);//To execute asyntask in ssh object, we have to sleep main thread + results = getSetsAndRelations.getResultLines(); + while(results.size() == 0){ + Thread.sleep(500); + results = getSetsAndRelations.getResultLines(); + } + System.out.println(results); + } catch (Exception e) { + Log.d("Sleep exception", "exception at getSetsAndRelations"); + } + + addSSHResultsToConfig(results, controllerConfigFilename); + System.out.println("read from file: " + ConfigFileIO.readFromFile(controllerConfigFilename, this)); + super.prop = new Properties(); + File file = new File(getApplicationContext().getFilesDir(), controllerConfigFilename); + FileInputStream fis = null; + try{ + fis = new FileInputStream(file); + super.prop.load(fis); + fis.close(); + } + catch (IOException ex){ + System.out.println("Error when reading SpeakerController Config file "); + ex.printStackTrace(); + } + + //add sets relations to the relation hashmap + super.numFields = Integer.parseInt(super.prop.getProperty("FIELD_NUMBER")); + for(int i = 0; i < super.numFields; i++){ + String name = (super.prop.getProperty("FIELD_" + i)); + if(super.prop.getProperty("FIELD_TYPE_" + i).equals("IoTRelation")) { + String relationPair = super.prop.getProperty("FIELD_CLASS_0_" + i) + "," + super.prop.getProperty("FIELD_CLASS_1_" + i); + addPair(name, relationPair); + relationNames.add(name); + } + if(super.prop.getProperty("FIELD_TYPE_" + i).equals("IoTSet")) { + if(super.prop.getProperty("FIELD_INDEPENDENT_" + i).equals("TRUE")){ + independentSetList.put(name, super.prop.getProperty("FIELD_CLASS_" + i)); + independentSetNames.add(name); + } + else{ + setHashMap.put(name, super.prop.getProperty("FIELD_CLASS_" + i)); + + } + } + } + //pull availableSets file from iotuser + try { + getSetList.execute(getSetListCommand); + Thread.sleep(1000);//To execute asyntask in ssh object, we have to sleep main thread + results = getSetList.getResultLines(); + while(results.size() == 0){ + Thread.sleep(500); + results = getSetList.getResultLines(); + } + System.out.println(results); + } catch (Exception e) { + Log.d("Sleep exception", "exception at getSetsAndRelations"); + } + String setListFilename = this.getString(R.string.setListFilename); + addSSHResultsToConfig(results, setListFilename); + availableSets = createSetList(setListFilename); + System.out.println(); + + ArrayList setsOrRelationArrayList = new ArrayList<>(); + setsOrRelationArrayList.add("SETS"); + setsOrRelationArrayList.add("RELATIONS"); + ArrayAdapter setsOrRelationsArrayAdapter = new ArrayAdapter(context, android.R.layout.simple_spinner_dropdown_item, setsOrRelationArrayList); + setOrRelationSpinner.setAdapter(setsOrRelationsArrayAdapter); + + + + setOrRelationSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + @Override + public void onItemSelected(AdapterView adapterView, View view, int i, long l) { + //set array adapter values = listed relations + if(setOrRelationSpinner.getSelectedItem().toString().equals("RELATIONS")) { + ArrayAdapter nameAdapter = new ArrayAdapter(context, android.R.layout.simple_spinner_dropdown_item, relationNames); + nameAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + relationNameSpinner.setAdapter(nameAdapter); + } + else{ + ArrayAdapter nameAdapter = new ArrayAdapter(context, android.R.layout.simple_spinner_dropdown_item, independentSetNames); + nameAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + relationNameSpinner.setAdapter(nameAdapter); + } + } + + @Override + public void onNothingSelected(AdapterView adapterView) { + + } + }); + + + + + //sets left and right possible values to registered devices in the sets + relationNameSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + @Override + public void onItemSelected(AdapterView adapterView, View view, int i, long l) { + + + if(setOrRelationSpinner.getSelectedItem().toString().equals("RELATIONS")) { + relationRightSpinner.setVisibility(View.VISIBLE); + String selectedRelation = relationNameSpinner.getSelectedItem().toString(); + ArrayList availableDevicesLeft = availableSets.get(relations.get(selectedRelation).first); + ArrayList availableDevicesRight = availableSets.get(relations.get(selectedRelation).second); + + ArrayAdapter leftAdapter = new ArrayAdapter(context, android.R.layout.simple_spinner_dropdown_item, availableDevicesLeft); + ArrayAdapter rightAdapter = new ArrayAdapter(context, android.R.layout.simple_spinner_dropdown_item, availableDevicesRight); + + leftAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + rightAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + relationLeftSpinner.setAdapter(leftAdapter); + relationRightSpinner.setAdapter(rightAdapter); + } + else{ + relationRightSpinner.setVisibility(View.GONE); + + String selectedSet = relationNameSpinner.getSelectedItem().toString(); + ArrayList availableDevicesLeft = availableSets.get(independentSetList.get(selectedSet)); + ArrayAdapter leftAdapter = new ArrayAdapter(context, android.R.layout.simple_spinner_dropdown_item, availableDevicesLeft); + leftAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + relationLeftSpinner.setAdapter(leftAdapter); + } + } + @Override + public void onNothingSelected(AdapterView adapterView) { + } + }); + + ArrayList addedRelationsArrayList = new ArrayList<>(); + Set relationTypes = super.addedRelations.keySet(); + for(String s: relationTypes) { + for (Pair temp : super.addedRelations.get(s)) { + addedRelationsArrayList.add(temp.first + " " + temp.second); + } + } + adapter = new ArrayAdapter(context, android.R.layout.simple_list_item_multiple_choice, addedRelationsArrayList); + addRelationsListView.setAdapter(adapter); + addRelationsListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { + public void onItemClick(AdapterView parent, View view, int position, long id) { + }}); + for(int i= 0; i < relationNames.size(); i++){ + Pair tempPair = relations.get(relationNames.get(i)); + applicationSetList.add(tempPair.first); + applicationSetList.add(tempPair.second); + } + } + + + +} diff --git a/others/lede-gui/src/main/java/com/example/lede2/InstallAddress.java b/others/lede-gui/src/main/java/com/example/lede2/InstallAddress.java new file mode 100644 index 0000000..9943447 --- /dev/null +++ b/others/lede-gui/src/main/java/com/example/lede2/InstallAddress.java @@ -0,0 +1,27 @@ +package com.example.lede2; + +import android.os.Bundle; +import android.support.v7.app.AppCompatActivity; +import android.view.View; + +/** + * Created by Brian on 2/21/2018. + */ + +public class InstallAddress extends AppCompatActivity implements View.OnClickListener,View.OnFocusChangeListener { + + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.install_address); + } + + @Override + public void onClick(View view) { + + } + + @Override + public void onFocusChange(View view, boolean b) { + + } +} diff --git a/others/lede-gui/src/main/java/com/example/lede2/InstallCommPattern.java b/others/lede-gui/src/main/java/com/example/lede2/InstallCommPattern.java new file mode 100644 index 0000000..75a910c --- /dev/null +++ b/others/lede-gui/src/main/java/com/example/lede2/InstallCommPattern.java @@ -0,0 +1,27 @@ +package com.example.lede2; + +import android.os.Bundle; +import android.support.v7.app.AppCompatActivity; +import android.view.View; + +/** + * Created by Brian on 2/21/2018. + */ + +public class InstallCommPattern extends AppCompatActivity implements View.OnClickListener,View.OnFocusChangeListener { + + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.install_comm_pattern); + } + + @Override + public void onClick(View view) { + + } + + @Override + public void onFocusChange(View view, boolean b) { + + } +} diff --git a/others/lede-gui/src/main/java/com/example/lede2/InstallHost.java b/others/lede-gui/src/main/java/com/example/lede2/InstallHost.java new file mode 100644 index 0000000..6e90d31 --- /dev/null +++ b/others/lede-gui/src/main/java/com/example/lede2/InstallHost.java @@ -0,0 +1,27 @@ +package com.example.lede2; + +import android.os.Bundle; +import android.support.v7.app.AppCompatActivity; +import android.view.View; + +/** + * Created by Brian on 2/21/2018. + */ + +public class InstallHost extends AppCompatActivity implements View.OnClickListener,View.OnFocusChangeListener { + + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.install_host); + } + + @Override + public void onClick(View view) { + + } + + @Override + public void onFocusChange(View view, boolean b) { + + } +} diff --git a/others/lede-gui/src/main/java/com/example/lede2/InstallTwoDevicesAndCommPattern.java b/others/lede-gui/src/main/java/com/example/lede2/InstallTwoDevicesAndCommPattern.java new file mode 100644 index 0000000..ed6ce63 --- /dev/null +++ b/others/lede-gui/src/main/java/com/example/lede2/InstallTwoDevicesAndCommPattern.java @@ -0,0 +1,27 @@ +package com.example.lede2; + +import android.os.Bundle; +import android.support.v7.app.AppCompatActivity; +import android.view.View; + +/** + * Created by Brian on 2/21/2018. + */ + +public class InstallTwoDevicesAndCommPattern extends AppCompatActivity implements View.OnClickListener,View.OnFocusChangeListener { + + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.install_two_devices_and_comm_pattern); + } + + @Override + public void onClick(View view) { + + } + + @Override + public void onFocusChange(View view, boolean b) { + + } +} diff --git a/others/lede-gui/src/main/java/com/example/lede2/InstallZigbeeDeviceAddress.java b/others/lede-gui/src/main/java/com/example/lede2/InstallZigbeeDeviceAddress.java new file mode 100644 index 0000000..60e1ccf --- /dev/null +++ b/others/lede-gui/src/main/java/com/example/lede2/InstallZigbeeDeviceAddress.java @@ -0,0 +1,27 @@ +package com.example.lede2; + +import android.os.Bundle; +import android.support.v7.app.AppCompatActivity; +import android.view.View; + +/** + * Created by Brian on 2/21/2018. + */ + +public class InstallZigbeeDeviceAddress extends AppCompatActivity implements View.OnClickListener,View.OnFocusChangeListener { + + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.install_zigbee_device_address); + } + + @Override + public void onClick(View view) { + + } + + @Override + public void onFocusChange(View view, boolean b) { + + } +} diff --git a/others/lede-gui/src/main/java/com/example/lede2/Irrigation.java b/others/lede-gui/src/main/java/com/example/lede2/Irrigation.java new file mode 100644 index 0000000..01336dd --- /dev/null +++ b/others/lede-gui/src/main/java/com/example/lede2/Irrigation.java @@ -0,0 +1,232 @@ +package com.example.lede2; + +import android.content.Context; +import android.os.Bundle; +import android.util.Log; +import android.util.Pair; +import android.view.View; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; +import android.widget.Button; +import android.widget.ListView; +import android.widget.Spinner; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Properties; +import java.util.Set; + +/** + * Created by Brian on 4/16/2018. + */ + +public class Irrigation extends ApplicationWithRelations{ + + private SSH_MySQL getSetsAndRelations; + private SSH_MySQL getSetList; + private String filename; + private ArrayList relationNames; //relations in this application + + Context context; + private HashMap> availableSets; //all possible sets pulled from pi + + + @Override + protected void onCreate( Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.home_security); + super.context = this; + context = super.context; + getSetsAndRelations = new SSH_MySQL(); + getSetList = new SSH_MySQL(); + String getSetsAndRelationsCommand = this.getString(R.string.getIrrigationSetsAndRelationsCommand); + String getSetListCommand = this.getString(R.string.getSetList); + List results = new ArrayList<>(); + final String controllerConfigFilename = this.getString(R.string.irrigationControllerConfigFile); + filename = this.getString(R.string.setsAndRelationsFilename); + relations = new HashMap<>(); + relationNames = new ArrayList<>(); + relationNameSpinner = (Spinner) findViewById(R.id.selectedRelation); + relationLeftSpinner = (Spinner) findViewById(R.id.relationLeftSpinner); + relationRightSpinner = (Spinner) findViewById(R.id.relationRightSpinner); + addRelationButton = (Button) findViewById(R.id.addRelationButton); + doneRelationButton = (Button) findViewById(R.id.addRelationDoneButton); + deleteRelationButton = (Button) findViewById(R.id.addRelationDeleteButton); + setOrRelationSpinner = (Spinner) findViewById(R.id.setsOrRelations); + super.hasIndependentSets = true; + super.independentSetNames = new ArrayList<>(); + super.independentSetList = new HashMap<>(); + super.addedSetList = new HashMap<>(); + super.addedIndependentSets = new HashMap<>(); + + addRelationButton.setOnClickListener(this); + doneRelationButton.setOnClickListener(this); + deleteRelationButton.setOnClickListener(this); + addRelationsListView = (ListView) findViewById(R.id.selectedRelationsList); + addRelationsListView.setFocusable(false); + super.addedRelations = new HashMap<> (); + HashSet> addedrelationsSet = new HashSet<>(); + //addedRelations.put("", addedrelationsSet); + super.applicationSetList = new HashSet<>(); + setHashMap = new HashMap<>(); + //pull data from config file on iotuser + try { + getSetsAndRelations.execute(getSetsAndRelationsCommand); + Thread.sleep(1000);//To execute asyntask in ssh object, we have to sleep main thread + results = getSetsAndRelations.getResultLines(); + while(results.size() == 0){ + Thread.sleep(500); + results = getSetsAndRelations.getResultLines(); + } + System.out.println(results); + } catch (Exception e) { + Log.d("Sleep exception", "exception at getSetsAndRelations"); + } + + addSSHResultsToConfig(results, controllerConfigFilename); + System.out.println("read from file: " + ConfigFileIO.readFromFile(controllerConfigFilename, this)); + super.prop = new Properties(); + File file = new File(getApplicationContext().getFilesDir(), controllerConfigFilename); + FileInputStream fis = null; + try{ + fis = new FileInputStream(file); + super.prop.load(fis); + fis.close(); + } + catch (IOException ex){ + System.out.println("Error when reading SpeakerController Config file "); + ex.printStackTrace(); + } + + //add sets relations to the relation hashmap + super.numFields = Integer.parseInt(super.prop.getProperty("FIELD_NUMBER")); + for(int i = 0; i < super.numFields; i++){ + String name = (super.prop.getProperty("FIELD_" + i)); + if(super.prop.getProperty("FIELD_TYPE_" + i).equals("IoTRelation")) { + String relationPair = super.prop.getProperty("FIELD_CLASS_0_" + i) + "," + super.prop.getProperty("FIELD_CLASS_1_" + i); + addPair(name, relationPair); + relationNames.add(name); + } + if(super.prop.getProperty("FIELD_TYPE_" + i).equals("IoTSet")) { + if(super.prop.getProperty("FIELD_INDEPENDENT_" + i).equals("TRUE")){ + independentSetList.put(name, super.prop.getProperty("FIELD_CLASS_" + i)); + independentSetNames.add(name); + } + else{ + setHashMap.put(name, super.prop.getProperty("FIELD_CLASS_" + i)); + + } + } + } + //pull availableSets file from iotuser + try { + getSetList.execute(getSetListCommand); + Thread.sleep(1000);//To execute asyntask in ssh object, we have to sleep main thread + results = getSetList.getResultLines(); + while(results.size() == 0){ + Thread.sleep(500); + results = getSetList.getResultLines(); + } + System.out.println(results); + } catch (Exception e) { + Log.d("Sleep exception", "exception at getSetsAndRelations"); + } + String setListFilename = this.getString(R.string.setListFilename); + addSSHResultsToConfig(results, setListFilename); + availableSets = createSetList(setListFilename); + System.out.println(); + + ArrayList setsOrRelationArrayList = new ArrayList<>(); + setsOrRelationArrayList.add("SETS"); + setsOrRelationArrayList.add("RELATIONS"); + ArrayAdapter setsOrRelationsArrayAdapter = new ArrayAdapter(context, android.R.layout.simple_spinner_dropdown_item, setsOrRelationArrayList); + setOrRelationSpinner.setAdapter(setsOrRelationsArrayAdapter); + + + + setOrRelationSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + @Override + public void onItemSelected(AdapterView adapterView, View view, int i, long l) { + //set array adapter values = listed relations + if(setOrRelationSpinner.getSelectedItem().toString().equals("RELATIONS")) { + ArrayAdapter nameAdapter = new ArrayAdapter(context, android.R.layout.simple_spinner_dropdown_item, relationNames); + nameAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + relationNameSpinner.setAdapter(nameAdapter); + } + else{ + ArrayAdapter nameAdapter = new ArrayAdapter(context, android.R.layout.simple_spinner_dropdown_item, independentSetNames); + nameAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + relationNameSpinner.setAdapter(nameAdapter); + } + } + + @Override + public void onNothingSelected(AdapterView adapterView) { + + } + }); + + + + + //sets left and right possible values to registered devices in the sets + relationNameSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + @Override + public void onItemSelected(AdapterView adapterView, View view, int i, long l) { + + + if(setOrRelationSpinner.getSelectedItem().toString().equals("RELATIONS")) { + relationRightSpinner.setVisibility(View.VISIBLE); + String selectedRelation = relationNameSpinner.getSelectedItem().toString(); + ArrayList availableDevicesLeft = availableSets.get(relations.get(selectedRelation).first); + ArrayList availableDevicesRight = availableSets.get(relations.get(selectedRelation).second); + + ArrayAdapter leftAdapter = new ArrayAdapter(context, android.R.layout.simple_spinner_dropdown_item, availableDevicesLeft); + ArrayAdapter rightAdapter = new ArrayAdapter(context, android.R.layout.simple_spinner_dropdown_item, availableDevicesRight); + + leftAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + rightAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + relationLeftSpinner.setAdapter(leftAdapter); + relationRightSpinner.setAdapter(rightAdapter); + } + else{ + relationRightSpinner.setVisibility(View.GONE); + + String selectedSet = relationNameSpinner.getSelectedItem().toString(); + ArrayList availableDevicesLeft = availableSets.get(independentSetList.get(selectedSet)); + ArrayAdapter leftAdapter = new ArrayAdapter(context, android.R.layout.simple_spinner_dropdown_item, availableDevicesLeft); + leftAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + relationLeftSpinner.setAdapter(leftAdapter); + } + } + @Override + public void onNothingSelected(AdapterView adapterView) { + } + }); + + ArrayList addedRelationsArrayList = new ArrayList<>(); + Set relationTypes = super.addedRelations.keySet(); + for(String s: relationTypes) { + for (Pair temp : super.addedRelations.get(s)) { + addedRelationsArrayList.add(temp.first + " " + temp.second); + } + } + adapter = new ArrayAdapter(context, android.R.layout.simple_list_item_multiple_choice, addedRelationsArrayList); + addRelationsListView.setAdapter(adapter); + addRelationsListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { + public void onItemClick(AdapterView parent, View view, int position, long id) { + }}); + for(int i= 0; i < relationNames.size(); i++){ + Pair tempPair = relations.get(relationNames.get(i)); + applicationSetList.add(tempPair.first); + applicationSetList.add(tempPair.second); + } + } + + + +} diff --git a/others/lede-gui/src/main/java/com/example/lede2/Lifxtest.java b/others/lede-gui/src/main/java/com/example/lede2/Lifxtest.java new file mode 100644 index 0000000..379ed80 --- /dev/null +++ b/others/lede-gui/src/main/java/com/example/lede2/Lifxtest.java @@ -0,0 +1,240 @@ +package com.example.lede2; + +import android.content.Context; +import android.os.Bundle; +import android.util.Log; +import android.util.Pair; +import android.view.View; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; +import android.widget.Button; +import android.widget.ListView; +import android.widget.Spinner; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Properties; +import java.util.Set; + +/** + * Created by Brian on 4/16/2018. + */ + +public class Lifxtest extends ApplicationWithRelations{ + + private SSH_MySQL getSetsAndRelations; + private SSH_MySQL getSetList; + private String filename; + private ArrayList relationNames; //relations in this application + + Context context; + private HashMap> availableSets; //all possible sets pulled from pi + + + @Override + protected void onCreate( Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.lifxtest); + super.context = this; + context = super.context; + getSetsAndRelations = new SSH_MySQL(); + getSetList = new SSH_MySQL(); + String getSetsAndRelationsCommand = this.getString(R.string.getlifxtestSetsAndRelationsCommand); + String getSetListCommand = this.getString(R.string.getSetList); + List results = new ArrayList<>(); + final String controllerConfigFilename = this.getString(R.string.lifxtestControllerConfigFile); + filename = this.getString(R.string.setsAndRelationsFilename); + relations = new HashMap<>(); + relationNames = new ArrayList<>(); + relationNameSpinner = (Spinner) findViewById(R.id.selectedRelation); + relationLeftSpinner = (Spinner) findViewById(R.id.relationLeftSpinner); + relationRightSpinner = (Spinner) findViewById(R.id.relationRightSpinnerLifx); + addRelationButton = (Button) findViewById(R.id.addRelationButton); + doneRelationButton = (Button) findViewById(R.id.addRelationDoneButton); + deleteRelationButton = (Button) findViewById(R.id.addRelationDeleteButton); + setOrRelationSpinner = (Spinner) findViewById(R.id.setsOrRelations); + super.hasIndependentSets = true; + super.independentSetNames = new ArrayList<>(); + super.independentSetList = new HashMap<>(); + super.addedSetList = new HashMap<>(); + super.addedIndependentSets = new HashMap<>(); + + super.hasRelations = false; + + addRelationButton.setOnClickListener(this); + doneRelationButton.setOnClickListener(this); + deleteRelationButton.setOnClickListener(this); + addRelationsListView = (ListView) findViewById(R.id.selectedRelationsList); + addRelationsListView.setFocusable(false); + super.addedRelations = new HashMap<> (); + HashSet> addedrelationsSet = new HashSet<>(); + //addedRelations.put("", addedrelationsSet); + super.applicationSetList = new HashSet<>(); + setHashMap = new HashMap<>(); + //pull data from config file on iotuser + try { + getSetsAndRelations.execute(getSetsAndRelationsCommand); + Thread.sleep(1000);//To execute asyntask in ssh object, we have to sleep main thread + results = getSetsAndRelations.getResultLines(); + while(results.size() == 0){ + Thread.sleep(500); + results = getSetsAndRelations.getResultLines(); + } + System.out.println(results); + } catch (Exception e) { + Log.d("Sleep exception", "exception at getSetsAndRelations"); + } + + addSSHResultsToConfig(results, controllerConfigFilename); + System.out.println("read from file: " + ConfigFileIO.readFromFile(controllerConfigFilename, this)); + super.prop = new Properties(); + File file = new File(getApplicationContext().getFilesDir(), controllerConfigFilename); + FileInputStream fis = null; + try{ + fis = new FileInputStream(file); + super.prop.load(fis); + fis.close(); + } + catch (IOException ex){ + System.out.println("Error when reading SpeakerController Config file "); + ex.printStackTrace(); + } + + //add sets relations to the relation hashmap + super.numFields = Integer.parseInt(super.prop.getProperty("FIELD_NUMBER")); + for(int i = 0; i < super.numFields; i++){ + String name = (super.prop.getProperty("FIELD_" + i)); + if(super.prop.getProperty("FIELD_TYPE_" + i).equals("IoTRelation")) { + String relationPair = super.prop.getProperty("FIELD_CLASS_0_" + i) + "," + super.prop.getProperty("FIELD_CLASS_1_" + i); + addPair(name, relationPair); + super.hasRelations = true; + relationNames.add(name); + } + if(super.prop.getProperty("FIELD_TYPE_" + i).equals("IoTSet")) { + if(super.prop.getProperty("FIELD_INDEPENDENT_" + i).equals("TRUE")){ + independentSetList.put(name, super.prop.getProperty("FIELD_CLASS_" + i)); + independentSetNames.add(name); + } + else{ + setHashMap.put(name, super.prop.getProperty("FIELD_CLASS_" + i)); + + } + } + } + //pull availableSets file from iotuser + try { + getSetList.execute(getSetListCommand); + Thread.sleep(1000);//To execute asyntask in ssh object, we have to sleep main thread + results = getSetList.getResultLines(); + while(results.size() == 0){ + Thread.sleep(500); + results = getSetList.getResultLines(); + } + System.out.println(results); + } catch (Exception e) { + Log.d("Sleep exception", "exception at getSetsAndRelations"); + } + String setListFilename = this.getString(R.string.setListFilename); + addSSHResultsToConfig(results, setListFilename); + availableSets = createSetList(setListFilename); + System.out.println(); + + ArrayList setsOrRelationArrayList = new ArrayList<>(); + if(super.hasIndependentSets){ + setsOrRelationArrayList.add("SETS"); + + } + if(super.hasRelations) { + setsOrRelationArrayList.add("RELATIONS"); + } + ArrayAdapter setsOrRelationsArrayAdapter = new ArrayAdapter(context, android.R.layout.simple_spinner_dropdown_item, setsOrRelationArrayList); + setOrRelationSpinner.setAdapter(setsOrRelationsArrayAdapter); + + + + setOrRelationSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + @Override + public void onItemSelected(AdapterView adapterView, View view, int i, long l) { + //set array adapter values = listed relations + if(setOrRelationSpinner.getSelectedItem().toString().equals("RELATIONS")) { + ArrayAdapter nameAdapter = new ArrayAdapter(context, android.R.layout.simple_spinner_dropdown_item, relationNames); + nameAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + relationNameSpinner.setAdapter(nameAdapter); + } + else{ + ArrayAdapter nameAdapter = new ArrayAdapter(context, android.R.layout.simple_spinner_dropdown_item, independentSetNames); + nameAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + relationNameSpinner.setAdapter(nameAdapter); + } + } + + @Override + public void onNothingSelected(AdapterView adapterView) { + + } + }); + + + + + //sets left and right possible values to registered devices in the sets + relationNameSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + @Override + public void onItemSelected(AdapterView adapterView, View view, int i, long l) { + + + if(setOrRelationSpinner.getSelectedItem().toString().equals("RELATIONS")) { + relationRightSpinner.setVisibility(View.VISIBLE); + String selectedRelation = relationNameSpinner.getSelectedItem().toString(); + ArrayList availableDevicesLeft = availableSets.get(relations.get(selectedRelation).first); + ArrayList availableDevicesRight = availableSets.get(relations.get(selectedRelation).second); + + ArrayAdapter leftAdapter = new ArrayAdapter(context, android.R.layout.simple_spinner_dropdown_item, availableDevicesLeft); + ArrayAdapter rightAdapter = new ArrayAdapter(context, android.R.layout.simple_spinner_dropdown_item, availableDevicesRight); + + leftAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + rightAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + relationLeftSpinner.setAdapter(leftAdapter); + relationRightSpinner.setAdapter(rightAdapter); + } + else{ + relationRightSpinner.setVisibility(View.GONE); + + String selectedSet = relationNameSpinner.getSelectedItem().toString(); + ArrayList availableDevicesLeft = availableSets.get(independentSetList.get(selectedSet)); + ArrayAdapter leftAdapter = new ArrayAdapter(context, android.R.layout.simple_spinner_dropdown_item, availableDevicesLeft); + leftAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + relationLeftSpinner.setAdapter(leftAdapter); + } + } + @Override + public void onNothingSelected(AdapterView adapterView) { + } + }); + + ArrayList addedRelationsArrayList = new ArrayList<>(); + Set relationTypes = super.addedRelations.keySet(); + for(String s: relationTypes) { + for (Pair temp : super.addedRelations.get(s)) { + addedRelationsArrayList.add(temp.first + " " + temp.second); + } + } + adapter = new ArrayAdapter(context, android.R.layout.simple_list_item_multiple_choice, addedRelationsArrayList); + addRelationsListView.setAdapter(adapter); + addRelationsListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { + public void onItemClick(AdapterView parent, View view, int position, long id) { + }}); + for(int i= 0; i < relationNames.size(); i++){ + Pair tempPair = relations.get(relationNames.get(i)); + applicationSetList.add(tempPair.first); + applicationSetList.add(tempPair.second); + } + } + + + +} diff --git a/others/lede-gui/src/main/java/com/example/lede2/ListActivity.java b/others/lede-gui/src/main/java/com/example/lede2/ListActivity.java index 5de1fd2..b6faf9f 100644 --- a/others/lede-gui/src/main/java/com/example/lede2/ListActivity.java +++ b/others/lede-gui/src/main/java/com/example/lede2/ListActivity.java @@ -1,6 +1,9 @@ package com.example.lede2; +import android.content.Context; import android.content.Intent; +import android.net.ConnectivityManager; +import android.net.NetworkInfo; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.util.Log; @@ -11,57 +14,111 @@ import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.EditText; import android.widget.ListView; +import android.widget.Spinner; import android.widget.TextView; import android.widget.Toast; +import java.util.ArrayList; +import java.util.Hashtable; import java.util.List; +import java.util.Scanner; +import java.util.Set; public class ListActivity extends AppCompatActivity implements View.OnClickListener { Button delete;//delete button in UI - Button deviceInfo;//select button in UI + Button back;//select button in UI ListView listview;//listview in UI SSH ssh;//Connection object between Android & Router List tmp;//data structure which has IoT device information already registered on LEDE2 ArrayAdapter adapter;//adapter between tmp and listview String device_info; protected String deviceIp; + ArrayList deviceList; TextView ip; TextView mac; + Hashtable nameAndValues; + Scanner scanner; + Spinner selectedDevice; + + + //have to check wifi before delete @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_list); - - ssh = new SSH(); - try { - tmp = ssh.execute("-ln").get(); - Thread.sleep(1000);//To execute asyntask in ssh object, we have to sleep main thread - } catch (Exception e) { + nameAndValues = new Hashtable<>(); + selectedDevice = (Spinner) findViewById(R.id.selectedName); + try{ + ssh = new SSH(); + ssh.execute("-ln"); + Thread.sleep(1000); + tmp = ssh.getResultLines(); + while(tmp.size() == 0){ + Thread.sleep(500); + tmp = ssh.getResultLines(); + } + } + catch (Exception e){ + e.printStackTrace(); + Log.d("cat device dat", "exception at cat device.dat"); } + tmp.remove(0); + for(int i = 0; i < tmp.size(); i++){ + Scanner scanner = new Scanner(tmp.get(i)); + if(scanner.hasNext()){ + nameAndValues.put(scanner.next(), tmp.get(i)); + } + } + Set nameAndValuesKeySet = nameAndValues.keySet(); + deviceList = new ArrayList(); + for(String key: nameAndValuesKeySet){ + deviceList.add(key); + } + delete = (Button) findViewById(R.id.delete); - deviceInfo = (Button) findViewById(R.id.deviceInfo); + back = (Button) findViewById(R.id.list_back); listview = (ListView) findViewById(R.id.listView1); ip = (TextView) findViewById(R.id.txt_ip); mac = (TextView) findViewById(R.id.txt_mac); - - adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_multiple_choice, tmp);//register tmp array to adapter + adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_multiple_choice, deviceList);//register tmp array to adapter delete.setOnClickListener(this); - deviceInfo.setOnClickListener(this); + back.setOnClickListener(this); listview.setAdapter(adapter); listview.setOnItemClickListener(new AdapterView.OnItemClickListener() { public void onItemClick(AdapterView parent, View view, int position, long id) { device_info = listview.getItemAtPosition(position).toString(); }}); + + ArrayAdapter typeAdapter = new ArrayAdapter(this, android.R.layout.simple_spinner_dropdown_item, deviceList); + typeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + selectedDevice.setAdapter(typeAdapter); + + selectedDevice.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + @Override + public void onItemSelected(AdapterView adapterView, View view, int i, long l) { + String nameIPMac = nameAndValues.get(selectedDevice.getSelectedItem().toString() ); + scanner = new Scanner(nameIPMac); + scanner.next(); + mac.setText(scanner.next()); + ip.setText(scanner.next()); + } + @Override + public void onNothingSelected(AdapterView adapterView) { + } + }); + + } @Override public void onClick(View v) { - if (v == delete) { - //SparseBooleanArray's data is Ture or False + System.out.println("device info: " + device_info); + if (v == delete && isNetworkAvailable()) { + //SparseBooleanArray's data is True or False SparseBooleanArray checkedItems = listview.getCheckedItemPositions();//to check which devices are checked in listview(check -> true, no check -> false) int count = adapter.getCount();//number of items in listview String command = "-dn "; //after, +'name ' @@ -69,10 +126,13 @@ public class ListActivity extends AppCompatActivity implements View.OnClickListe for (int i = count - 1; i >= 0; i--) {//scan from back //i : index of IoT device which will be removed in tmp array if (checkedItems.get(i)) {//if check - String rmName = tmp.get(i).toString();//save the name of checked IoT device - command += rmName + " ";//complete command + String selectedValue = (String)listview.getItemAtPosition(i); + scanner = new Scanner(selectedValue); + String name = scanner.next(); + command += name + " ";//complete command //remove this information on the listview - tmp.remove(i); + nameAndValues.remove(name); + deviceList.remove(name); //deviceIp = checkedItems. } } @@ -89,19 +149,19 @@ public class ListActivity extends AppCompatActivity implements View.OnClickListe //delete checked mark in listview listview.clearChoices(); - } else if (v == deviceInfo) { - String[] devInfo = device_info.split("\\s+"); - ip.setText(devInfo[1]); - mac.setText(devInfo[2]); - Toast t = Toast.makeText(this, device_info, Toast.LENGTH_SHORT); - t.show(); - /*} else if (v == selectAll) { - int count; - count = adapter.getCount(); - - for (int i = 0; i < count; i++) { - listview.setItemChecked(i, true); - }*/ } + else if (v == back && isNetworkAvailable()){ + finish(); + } + } + + boolean isNetworkAvailable() {//check whether wifi connection is or not + Context context = getApplicationContext(); + ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); + NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); + boolean isConnected = activeNetwork != null && activeNetwork.isConnectedOrConnecting(); + return isConnected; + } + } diff --git a/others/lede-gui/src/main/java/com/example/lede2/MainActivity.java b/others/lede-gui/src/main/java/com/example/lede2/MainActivity.java index d5dc4a5..e1fe951 100644 --- a/others/lede-gui/src/main/java/com/example/lede2/MainActivity.java +++ b/others/lede-gui/src/main/java/com/example/lede2/MainActivity.java @@ -1,5 +1,6 @@ package com.example.lede2; +import android.app.ProgressDialog; import android.content.Context; import android.content.Intent; import android.net.ConnectivityManager; @@ -15,13 +16,15 @@ import android.widget.Toast; public class MainActivity extends AppCompatActivity implements View.OnClickListener { + Button databaseButton; Button registerButton; Button listButton; - Button insertDBButton; - Button deleteDBButton; + Button applicationsButton; Button configButton; - Button relationButton; + Button driversButton; TextView ssid; + DatabaseObject databaseObject; + ProgressDialog dialog; protected static Context context; protected static String DEF_RSSID; protected static String DEF_RPWD; @@ -33,61 +36,117 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe protected static String DEF_CHANGE_DEFAULT_SCRIPT; protected static String DEF_CONNECT_DEVICE_SCRIPT; protected static String DEF_REGISTER_DEVICE_SCRIPT; - protected static String DEF_ADD_DEVICE_FILE; - protected static String DEF_ADD_DEVICE_ADDRESS_FILE; - protected static String DEF_ADD_DEVICE_COMM_FILE; + + protected static String DEF_INSTALL_DEVICE_FILE; + protected static String DEF_INSTALL_DEVICE_ADDRESS_FILE; + protected static String DEF_INSTALL_DEVICE_COMM_FILE; + protected static String DEF_INSTALL_ADDRESS_FILE; + protected static String DEF_INSTALL_TWO_DEVICES_AND_COMM_FILE; + protected static String DEF_INSTALL_ZIGBEE_DEVICE_ADDRESS_FILE; + protected static String DEF_INSTALL_HOST_FILE; + protected static String DEF_DELETE_ENTITY_FILE; + protected static String DEF_DELETE_COMM_PATTERN_FILE; + protected static String DEF_DELETE_ADDRESS_FILE; + protected static String DEF_DELETE_DEVICE_ADDRESS_FILE; + protected static String DEF_DELETE_ZIGBEE_DEVICE_ADDRESS_FILE; + protected static String DEF_DELETE_HOST_FILE; + + protected static String DEF_ADD_DEVICE_TO_MYSQL; protected static String DEF_MYSQL_CONFIG_FILE; protected static String DEF_INSTALL_CMD; protected static String DEF_DELETE_CMD; protected static String DEF_INSTALL_ADDRESS_CMD; + protected static String DEF_INSTALL_ZBADDRESS_CMD; protected static String DEF_DELETE_ADDRESS_CMD; protected static String DEF_INSTALL_RELATION_CMD; protected static String DEF_DELETE_RELATION_CMD; + protected static String DEF_DATABASE_NAME; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); - registerButton = (Button) findViewById(R.id.register); listButton = (Button) findViewById(R.id.list); - insertDBButton = (Button) findViewById(R.id.insert_db); - deleteDBButton = (Button) findViewById(R.id.delete_db); + databaseButton = (Button) findViewById(R.id.database); + applicationsButton = (Button) findViewById(R.id.applications); configButton = (Button) findViewById(R.id.config); - relationButton = (Button) findViewById(R.id.add_del_comm); + driversButton = (Button) findViewById(R.id.drivers); ssid = (TextView)findViewById(R.id.device_subtype); + registerButton.setOnClickListener(this); listButton.setOnClickListener(this); - insertDBButton.setOnClickListener(this); - deleteDBButton.setOnClickListener(this); + databaseButton.setOnClickListener(this); + applicationsButton.setOnClickListener(this); configButton.setOnClickListener(this); - relationButton.setOnClickListener(this); + driversButton.setOnClickListener(this); context = getApplicationContext(); DEF_RSSID = context.getResources().getString(R.string.default_rssid); DEF_RPWD = context.getResources().getString(R.string.default_rpwd); DEF_ROUTERIP = context.getResources().getString(R.string.default_routerip); DEF_ROUTERUSER = context.getResources().getString(R.string.default_routeruser); - DEF_CHANGE_DEFAULT_SCRIPT = context.getResources().getString(R.string.change_default_script); - DEF_CONNECT_DEVICE_SCRIPT = context.getResources().getString(R.string.connect_device_script); - DEF_REGISTER_DEVICE_SCRIPT = context.getResources().getString(R.string.register_device_script); - DEF_ADD_DEVICE_FILE = context.getResources().getString(R.string.add_device_file); - DEF_ADD_DEVICE_ADDRESS_FILE = context.getResources().getString(R.string.add_device_address_file); - DEF_ADD_DEVICE_COMM_FILE = context.getResources().getString(R.string.add_device_comm_file); + DEF_CHANGE_DEFAULT_SCRIPT = context.getResources() + .getString(R.string.change_default_script); + DEF_CONNECT_DEVICE_SCRIPT = context.getResources() + .getString(R.string.connect_device_script); + DEF_REGISTER_DEVICE_SCRIPT = context.getResources() + .getString(R.string.register_device_script); + DEF_INSTALL_DEVICE_FILE = context.getResources().getString(R.string.install_device_file); + DEF_INSTALL_DEVICE_ADDRESS_FILE = context.getResources().getString + (R.string.install_device_address_file); + DEF_INSTALL_TWO_DEVICES_AND_COMM_FILE = context.getResources() + .getString(R.string.install_two_devices_and_comm_file); + DEF_INSTALL_ADDRESS_FILE = context.getResources().getString(R.string.install_address_file); + DEF_INSTALL_DEVICE_COMM_FILE = context.getResources().getString(R.string.install_device_comm_file); + DEF_INSTALL_ZIGBEE_DEVICE_ADDRESS_FILE = context.getResources() + .getString(R.string.install_zigbee_device_address_file); + DEF_INSTALL_HOST_FILE = context.getResources().getString(R.string.install_host_file); + DEF_DELETE_ENTITY_FILE = context.getResources().getString(R.string.delete_entity_file); + DEF_DELETE_COMM_PATTERN_FILE = context.getResources() + .getString(R.string.delete_comm_pattern_file); + DEF_DELETE_ADDRESS_FILE = context.getResources().getString(R.string.delete_address_file); + DEF_DELETE_DEVICE_ADDRESS_FILE = context.getResources() + .getString(R.string.delete_device_address_file); + DEF_DELETE_ZIGBEE_DEVICE_ADDRESS_FILE = context.getResources() + .getString(R.string.delete_zigbee_device_address_file); + DEF_DELETE_HOST_FILE = context.getResources().getString(R.string.delete_host); + DEF_MYSQLHOSTUSER = context.getResources().getString(R.string.mysql_hostuser); DEF_MYSQLHOSTIP = context.getResources().getString(R.string.mysql_hostip); DEF_MYSQLHOSTPASSWORD = context.getResources().getString(R.string.mysql_hostpassword); DEF_ADD_DEVICE_TO_MYSQL = context.getResources().getString(R.string.add_device_to_mysql); + + DEF_MYSQL_CONFIG_FILE = context.getResources().getString(R.string.mysql_config_file); DEF_INSTALL_CMD = context.getResources().getString(R.string.install_cmd); DEF_DELETE_CMD = context.getResources().getString(R.string.delete_cmd); DEF_INSTALL_ADDRESS_CMD = context.getResources().getString(R.string.install_address_cmd); + DEF_INSTALL_ZBADDRESS_CMD = context.getResources().getString(R.string.install_zb_address_cmd); DEF_DELETE_ADDRESS_CMD = context.getResources().getString(R.string.delete_address_cmd); DEF_INSTALL_RELATION_CMD = context.getResources().getString(R.string.add_comm_cmd); DEF_DELETE_RELATION_CMD = context.getResources().getString(R.string.delete_comm_cmd); + + DEF_DATABASE_NAME = context.getResources().getString(R.string.database_name); + ssid.setText(DEF_RSSID); + databaseObject = new DatabaseObject(); + //Check if the user has wifi connection + if (isNetworkAvailable() == false) {//without wifi connection + Toast t = Toast.makeText(this, R.string.connect, Toast.LENGTH_SHORT); + t.show(); + Intent intent = new Intent(WifiManager.ACTION_PICK_WIFI_NETWORK); + intent.putExtra("only_access_points", true); + intent.putExtra("extra_prefs_show_button_bar", true); + intent.putExtra("wifi_enable_next_on_connect", true); + startActivityForResult(intent,1); + } + //sends to another page to update/retrieve information about the database from the pi + startActivity(new Intent(this, UpdateLocalConfigFiles.class)); + } public void onClick(View v) { @@ -95,35 +154,60 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe if(v == configButton){ startActivityForResult(new Intent(this,ConfigActivity.class),1000); } - //Users try to execute shell scripts by pushing button, //but problem could occur(application stop) if user push the button without wifi connection //As a result, below function have to be implemented. if (isNetworkAvailable() == false) {//without wifi connection Toast t = Toast.makeText(this, R.string.connect, Toast.LENGTH_SHORT); t.show(); - startActivity(new Intent(WifiManager.ACTION_PICK_WIFI_NETWORK)); + Intent intent = new Intent(WifiManager.ACTION_PICK_WIFI_NETWORK); + intent.putExtra("only_access_points", true); + intent.putExtra("extra_prefs_show_button_bar", true); + intent.putExtra("wifi_enable_next_on_connect", true); + startActivityForResult(intent,1); + System.out.println("STOPPPPP"); + //startActivity(new Intent(WifiManager.ACTION_PICK_WIFI_NETWORK)); // Not as good as the lines above } else {//with wifi connection + + dialog = new ProgressDialog(this); + dialog.setMessage("Please Wait"); + dialog.setCancelable(false); + dialog.setInverseBackgroundForced(false); + dialog.show(); + if (v == registerButton) { Log.d("CLICKING", "Clicking on register!"); - startActivity(new Intent(this, EnrollDeviceActivity.class)); + startActivity(new Intent(this, RegistrationRouterCheck.class)); +// dialog.hide(); //startActivity(new Intent(this, AddDeviceActivity.class)); } else if (v == listButton) { Log.d("CLICKING", "Clicking on list activity!"); startActivity(new Intent(this, ListActivity.class)); - } else if (v == insertDBButton) { +// dialog.hide(); + } else if (v == databaseButton) { + //Need to change. Not every install option needs its own page. Log.d("CLICKING", "Clicking on add device!"); - startActivity(new Intent(this, AddDeviceActivity.class)); - } else if (v == deleteDBButton) { + startActivity(new Intent(this, DatabaseActivity.class)); +// dialog.hide(); + } else if (v == applicationsButton) { Log.d("CLICKING", "Clicking on delete device!"); - startActivity(new Intent(this, DeleteDeviceActivity.class)); - } else if (v == relationButton) { + startActivity(new Intent(this, ApplicationsList.class)); +// dialog.hide(); + } else if (v == driversButton) { Log.d("CLICKING", "Clicking on add communication!"); - startActivity(new Intent(this, RelationActivity.class)); + startActivity(new Intent(this, DriversSelectActivity.class)); } } } + @Override + protected void onResume() { + super.onResume(); + if(dialog != null && dialog.isShowing()){ + dialog.dismiss(); + } + } + boolean isNetworkAvailable() {//check whether wifi connection is or not Context context = getApplicationContext(); ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); @@ -140,4 +224,4 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe ssid.setText(ConfigActivity.RSSID); } } -} +} \ No newline at end of file diff --git a/others/lede-gui/src/main/java/com/example/lede2/RegisterDeviceAdding.java b/others/lede-gui/src/main/java/com/example/lede2/RegisterDeviceAdding.java new file mode 100644 index 0000000..5c773db --- /dev/null +++ b/others/lede-gui/src/main/java/com/example/lede2/RegisterDeviceAdding.java @@ -0,0 +1,210 @@ +package com.example.lede2; + +import android.content.ClipData; +import android.content.ClipboardManager; +import android.content.Context; +import android.content.Intent; +import android.net.ConnectivityManager; +import android.net.NetworkInfo; +import android.net.wifi.WifiConfiguration; +import android.net.wifi.WifiInfo; +import android.net.wifi.WifiManager; +import android.os.Bundle; +import android.support.design.widget.Snackbar; +import android.support.v7.app.AppCompatActivity; +import android.util.Log; +import android.view.View; +import android.widget.ArrayAdapter; +import android.widget.Button; +import android.widget.EditText; +import android.widget.Spinner; +import android.widget.Toast; + +import java.util.ArrayList; +import java.util.List; +import java.util.Scanner; + +/** + * Created by Brian on 4/3/2018. + */ + +public class RegisterDeviceAdding extends AppCompatActivity implements View.OnClickListener { + private String devdat_macaddress_filename; + private String dhcp_macaddress_filename; + private Spinner macAddressSpinner; + private EditText name; + private String deviceName; + private Button wifi;//wifi button in UI + private SSH ssh;//Connection object between Android & Router + private Context context; + private String newpsk; + private WifiManager manager; + + private Button done; + + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.register_device_adding); + context = getApplicationContext(); + manager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); + Bundle extras = getIntent().getExtras(); + if(extras!= null){ + newpsk = extras.getString("newpsk"); + } + macAddressSpinner = (Spinner) findViewById(R.id.registerMACs); + wifi = (Button) findViewById(R.id.regAddWifi); + wifi.setOnClickListener(this); + devdat_macaddress_filename = this.getString(R.string.devices_dat_filename); + dhcp_macaddress_filename = "temp_DHCP.txt"; + name = (EditText)findViewById(R.id.registerName); + done = (Button)findViewById(R.id.registerDone); + done.setOnClickListener(this); + + ArrayList macAddressesdhcp = ConfigFileIO.getMACAddressesDHCP(dhcp_macaddress_filename, this); + ArrayList macAddressesdevdat = ConfigFileIO.getMACAddressesDevDat(devdat_macaddress_filename, this); + ArrayList macAddresses = new ArrayList<>(); + for(int i = 0; i < macAddressesdhcp.size();i++){ + if(!macAddressesdevdat.contains(macAddressesdhcp.get(i))){ + macAddresses.add(macAddressesdhcp.get(i)); + } + } + + //sets value for macAddressesSpinner + ArrayAdapter typeAdapter = new ArrayAdapter(this, android.R.layout.simple_spinner_dropdown_item, macAddresses); + typeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + macAddressSpinner.setAdapter(typeAdapter); + + + + + } + + @Override + public void onClick(View v) { + if (v == done) { + //Users try to execute shell scripts by pushing button, + //but problem could occur(application stop) if user push the button without wifi connection + //As a result, below function have to be implemented. + if (isNetworkAvailable() == false) {//without wifi connection + Toast t = Toast.makeText(this, R.string.connect, Toast.LENGTH_SHORT); + t.show(); + //choosing wifi connection + Intent intent = new Intent(WifiManager.ACTION_PICK_WIFI_NETWORK); + intent.putExtra("only_access_points", true); + intent.putExtra("extra_prefs_show_button_bar", true); + intent.putExtra("wifi_enable_next_on_connect", true); + startActivityForResult(intent,1); + //startActivity(new Intent(WifiManager.ACTION_PICK_WIFI_NETWORK)); + } else {//with wifi connection + deviceName = name.getText().toString(); + if(deviceName.equals("")){ + Toast t = Toast.makeText(this, R.string.empty_name,Toast.LENGTH_SHORT); + t.show(); + return; + } + Scanner scanner = new Scanner(deviceName); + scanner.next(); + if(scanner.hasNext()){ + Snackbar oneWordName = Snackbar.make(findViewById(R.id.oneWordName), + "Please only use one word names", 2000); + oneWordName.show(); + return; + } + String selectedMacAddress = macAddressSpinner.getSelectedItem().toString(); + context = getApplicationContext(); + if (getWifiName(context).equals("\""+ ConfigActivity.RSSID +"\"")) {//if wifi name is LEDE2 + ssh = new SSH(); + // execute shell script (script's function -> Save contents(Mac,Ip,Key,Name) on hostapd-psk) + List results = new ArrayList<>(); + try {//To execute asyntask in ssh object, we have to sleep main thread + ssh.execute("-co " + newpsk + " " + selectedMacAddress + " " + + deviceName + " " + ConfigActivity.RPWD ); + Thread.sleep(2000); + + List list = manager.getConfiguredNetworks(); + for( WifiConfiguration i : list ) { + if(i.SSID.equals("\"LEDE2\"")){ + manager.removeNetwork(i.networkId); + manager.saveConfiguration(); + System.out.println("deleted"); + } + } + WifiConfiguration wifiConfig = new WifiConfiguration(); + wifiConfig.SSID = String.format("\"%s\"", "LEDE2"); + wifiConfig.preSharedKey = String.format("\"%s\"", context.getResources().getString(R.string.default_rpwd)); + + int netId = manager.addNetwork(wifiConfig); + manager.disconnect(); + manager.enableNetwork(netId, true); + manager.reconnect(); + + + //To execute asyntask in ssh object, we have to sleep main thread +// results = ssh.getResultLines(); +// while(results.size() == 0){ +// Thread.sleep(500); +// results = ssh.getResultLines(); +// System.out.println(results); +// } + } catch (Exception e) { + Log.d("SLEEP EXCEPTION", "SLEEP EXCEPTION occurs in onClick method of EnrollDeviceActivity"); + } + } else { //if name of wifi is not LEDE -> go to wifi configuration screen to change wifi type + Toast t = Toast.makeText(this, R.string.try_again, Toast.LENGTH_SHORT); + t.show(); + //Choosing wifi connection + Intent intent = new Intent(WifiManager.ACTION_PICK_WIFI_NETWORK); + intent.putExtra("only_access_points", true); + intent.putExtra("extra_prefs_show_button_bar", true); + intent.putExtra("wifi_enable_next_on_connect", true); + startActivityForResult(intent,1); + //startActivity(new Intent(WifiManager.ACTION_PICK_WIFI_NETWORK)); + } + } + // Call activity that adds device - not doing this flow because we haven't found + // a way to change password without restarting WiFi + //startActivity(new Intent(this, AddDeviceActivity.class)); + //finish(); + } else if (v == wifi) { + Intent intent = new Intent(WifiManager.ACTION_PICK_WIFI_NETWORK); + intent.putExtra("only_access_points", true); + intent.putExtra("extra_prefs_show_button_bar", true); + intent.putExtra("wifi_enable_next_on_connect", true); + startActivityForResult(intent,1); + //startActivity(new Intent(WifiManager.ACTION_PICK_WIFI_NETWORK)); + } + + ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); + ClipData clip = ClipData.newPlainText("old password", context.getResources().getString(R.string.default_rpwd)); + clipboard.setPrimaryClip(clip); + finish(); + } + + + /******************************************************************************************************************************************************************/ + //Detect you are connected to a specific network. + /******************************************************************************************************************************************************************/ + public String getWifiName(Context context) { + WifiManager manager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); + if (manager.isWifiEnabled()) { + WifiInfo wifiInfo = manager.getConnectionInfo(); + if (wifiInfo != null) { + NetworkInfo.DetailedState state = WifiInfo.getDetailedStateOf(wifiInfo.getSupplicantState()); + if (state == NetworkInfo.DetailedState.CONNECTED || state == NetworkInfo.DetailedState.OBTAINING_IPADDR) { + return wifiInfo.getSSID(); + } + } + } + return null; + } + + boolean isNetworkAvailable() {//check whether wifi connection is or not + Context context = getApplicationContext(); + ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); + NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); + boolean isConnected = activeNetwork != null && activeNetwork.isConnectedOrConnecting(); + return isConnected; + } + + +} diff --git a/others/lede-gui/src/main/java/com/example/lede2/RegisterDeviceLoading.java b/others/lede-gui/src/main/java/com/example/lede2/RegisterDeviceLoading.java new file mode 100644 index 0000000..ffbf078 --- /dev/null +++ b/others/lede-gui/src/main/java/com/example/lede2/RegisterDeviceLoading.java @@ -0,0 +1,186 @@ +package com.example.lede2; + +import android.content.ClipData; +import android.content.ClipboardManager; +import android.content.Context; +import android.content.Intent; +import android.net.ConnectivityManager; +import android.net.NetworkInfo; +import android.net.wifi.WifiInfo; +import android.net.wifi.WifiManager; +import android.support.design.widget.Snackbar; +import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; +import android.view.View; +import android.view.inputmethod.InputMethodManager; +import android.widget.Button; +import android.widget.EditText; +import android.widget.TextView; +import android.widget.Toast; +import android.util.Log; + +import java.util.ArrayList; +import java.util.List; +import java.util.Random; + +public class RegisterDeviceLoading extends AppCompatActivity implements View.OnClickListener, View.OnFocusChangeListener { + + private static final int REQUEST_RESULT = 1001; + Button done;//Done button in UI + Button wifi;//wifi button in UI + SSH ssh;//Connection object between Android & Router + Context context; + TextView psk;//red letter in UI + String newpsk;//same as psk (different data type) + EditText name;//device name newly registered in UI + String deviceName;//same as name(different data type) + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_enroll_device); + + ssh = new SSH(); + psk = (TextView) findViewById(R.id.add_psk); + done = (Button) findViewById(R.id.done); + wifi = (Button) findViewById(R.id.wifi); + name = (EditText) findViewById(R.id.name); + + done.setOnClickListener(this); + wifi.setOnClickListener(this); + name.setOnFocusChangeListener(this); + + //Make random password and show the password through EditText + newpsk = generateRandomPassword(); + psk.setText(newpsk); + + try {//To execute asyntask in ssh object, we have to sleep main thread + ssh.execute("-ch " + newpsk); + Thread.sleep(1000); + } catch (Exception e) { + Log.d("SLEEP EXCEPTION", "SLEEP EXCEPTION occurs in onCreate method of EnrollDeviceActivity"); + } + } + + @Override + public void onFocusChange(View view, boolean hasFocus) {//function not to modify randomly generated password for newly registered device + InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); + if (hasFocus) { + imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); + } else { + imm.hideSoftInputFromWindow(view.getWindowToken(), 0); + } + } + + boolean isNetworkAvailable() {//check whether wifi connection is or not + Context context = getApplicationContext(); + ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); + NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); + boolean isConnected = activeNetwork != null && activeNetwork.isConnectedOrConnecting(); + return isConnected; + } + + @Override + public void onClick(View v) { + if (v == done) { + //Users try to execute shell scripts by pushing button, + //but problem could occur(application stop) if user push the button without wifi connection + //As a result, below function have to be implemented. + if (isNetworkAvailable() == false) {//without wifi connection + Toast t = Toast.makeText(this, R.string.connect, Toast.LENGTH_SHORT); + t.show(); + //choosing wifi connection + Intent intent = new Intent(WifiManager.ACTION_PICK_WIFI_NETWORK); + intent.putExtra("only_access_points", true); + intent.putExtra("extra_prefs_show_button_bar", true); + intent.putExtra("wifi_enable_next_on_connect", true); + startActivityForResult(intent,1); + //startActivity(new Intent(WifiManager.ACTION_PICK_WIFI_NETWORK)); + } else {//with wifi connection + deviceName = name.getText().toString(); + if(deviceName.equals("")){ + Toast t = Toast.makeText(this, R.string.empty_name,Toast.LENGTH_SHORT); + t.show(); + return; + } + context = getApplicationContext(); + if (getWifiName(context).equals("\""+ ConfigActivity.RSSID +"\"")) {//if wifi name is LEDE2 + String networkPass = psk.getText().toString();//random password + ssh = new SSH(); + + // execute shell script (script's function -> Save contents(Mac,Ip,Key,Name) on hostapd-psk) + ssh.execute("-co " + networkPass + " " + deviceName + " " + ConfigActivity.RPWD);//review!!!!!! + try {//To execute asyntask in ssh object, we have to sleep main thread + Thread.sleep(1000); + } catch (Exception e) { + Log.d("SLEEP EXCEPTION", "SLEEP EXCEPTION occurs in onClick method of EnrollDeviceActivity"); + } + finish();//Go back to the Main Activity + } else { //if name of wifi is not LEDE -> go to wifi configuration screen to change wifi type + Toast t = Toast.makeText(this, R.string.try_again, Toast.LENGTH_SHORT); + t.show(); + //Choosing wifi connection + Intent intent = new Intent(WifiManager.ACTION_PICK_WIFI_NETWORK); + intent.putExtra("only_access_points", true); + intent.putExtra("extra_prefs_show_button_bar", true); + intent.putExtra("wifi_enable_next_on_connect", true); + startActivityForResult(intent,1); + //startActivity(new Intent(WifiManager.ACTION_PICK_WIFI_NETWORK)); + } + } + // Call activity that adds device - not doing this flow because we haven't found + // a way to change password without restarting WiFi + //startActivity(new Intent(this, AddDeviceActivity.class)); + //finish(); + } else if (v == wifi) { + Intent intent = new Intent(WifiManager.ACTION_PICK_WIFI_NETWORK); + intent.putExtra("only_access_points", true); + intent.putExtra("extra_prefs_show_button_bar", true); + intent.putExtra("wifi_enable_next_on_connect", true); + startActivityForResult(intent,1); + } + } + + /******************************************************************************************************************************************************************/ + //Detect you are connected to a specific network. + /******************************************************************************************************************************************************************/ + public String getWifiName(Context context) { + WifiManager manager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); + if (manager.isWifiEnabled()) { + WifiInfo wifiInfo = manager.getConnectionInfo(); + if (wifiInfo != null) { + NetworkInfo.DetailedState state = WifiInfo.getDetailedStateOf(wifiInfo.getSupplicantState()); + if (state == NetworkInfo.DetailedState.CONNECTED || state == NetworkInfo.DetailedState.OBTAINING_IPADDR) { + return wifiInfo.getSSID(); + } + } + } + return null; + } + + /******************************************************************************************************************************************************************/ + // Generate a random password and return it + /******************************************************************************************************************************************************************/ + public String generateRandomPassword() { + String password = new String(); + + StringBuffer rndpassword = new StringBuffer(); + Random rnd = new Random(); + int digitnum = 20; + // Generate random 20digit password with upper / lower case alphabet + numbers + // There are 10 int nums, 26 lower alphabets, 26 upper alphabets. Total 62 + // So 2/12 possiblity of int, 5/12 lower, 5/12 upper alphabets. + for (int i = 0; i < digitnum; i++) { + int rIndex = rnd.nextInt(12); + if (rIndex >= 0 && rIndex < 2) { // 0 - 9 + rndpassword.append((rnd.nextInt(10))); + } else if (rIndex >= 2 && rIndex < 7) { // a-z + rndpassword.append((char) ((int) (rnd.nextInt(26)) + 97)); + } else { // A-Z + rndpassword.append((char) ((int) (rnd.nextInt(26)) + 65)); + } + } + password = rndpassword.toString(); + return password; + } +} diff --git a/others/lede-gui/src/main/java/com/example/lede2/RegistrationRouterCheck.java b/others/lede-gui/src/main/java/com/example/lede2/RegistrationRouterCheck.java new file mode 100644 index 0000000..3b53685 --- /dev/null +++ b/others/lede-gui/src/main/java/com/example/lede2/RegistrationRouterCheck.java @@ -0,0 +1,330 @@ +package com.example.lede2; + +import android.app.ProgressDialog; +import android.content.Intent; +import android.content.ClipData; +import android.content.ClipboardManager; +import android.content.Context; +import android.net.ConnectivityManager; +import android.net.NetworkInfo; +import android.net.wifi.WifiConfiguration; +import android.net.wifi.WifiInfo; +import android.net.wifi.WifiManager; +import android.os.SystemClock; +import android.support.design.widget.Snackbar; +import android.support.design.widget.CoordinatorLayout; +import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; +import android.view.View; +import android.view.WindowManager; +import android.view.inputmethod.InputMethodManager; +import android.widget.Button; +import android.widget.EditText; +import android.widget.TextView; +import android.widget.Toast; +import android.util.Log; + +import java.util.ArrayList; +import java.util.List; +import java.io.File; +import java.util.Random; +import java.lang.Thread; + + +/** + * Created by kevin on 4/3/2018. + */ + +public class RegistrationRouterCheck extends AppCompatActivity implements View.OnClickListener{ + private SSH routerConnection; + private SSH routerConnection2; + private String command; + public String temp_dhcp_filename; + public String initial_dhcp_filename; + public String initialDHCP; + private String tempDHCP; + private String newpsk; + private TextView password; + private boolean initialDHCPCall; + public String commandRouter = "cat /tmp/dhcp.leases"; + private WifiManager manager; + ProgressDialog dialog; + Button back; + Button check; + Button load; + + + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.registration_layout); + getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); + Context context = getApplicationContext(); + WifiManager manager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); + + + + password = (TextView) findViewById(R.id.newPassword); + back = (Button) findViewById(R.id.back); + load = (Button) findViewById(R.id.load); + check = (Button) findViewById(R.id.check); + + back.setOnClickListener(this); + load.setOnClickListener(this); + check.setOnClickListener(this); + + command = "cat /tmp/dhcp.leases"; + temp_dhcp_filename = "temp_DHCP.txt"; + initial_dhcp_filename = this.getString(R.string.initial_DHCP); + initialDHCPCall = false; + newpsk = generateRandomPassword(); + password.setText(newpsk); + + Snackbar mySnackBar = Snackbar.make(findViewById(R.id.main_layout_id), "Please Wait Until Wifi is Connected!", 2000); + mySnackBar.show(); + + try{ + routerConnection = new SSH(); + routerConnection.execute("-ch " + newpsk); + Thread.sleep(1000); + } catch (Exception e) { + Log.d("SLEEP EXCEPTION", "SLEEP EXCEPTION occurs in onCreate method of EnrollDeviceActivity"); + } + + List list = manager.getConfiguredNetworks(); + for( WifiConfiguration i : list ) { + if(i.SSID.equals("\"LEDE2\"")){ + manager.removeNetwork(i.networkId); + manager.saveConfiguration(); + System.out.println("deleted"); + } + } + WifiConfiguration wifiConfig = new WifiConfiguration(); + wifiConfig.SSID = String.format("\"%s\"", "LEDE2"); + wifiConfig.preSharedKey = String.format("\"%s\"", newpsk); + + int netId = manager.addNetwork(wifiConfig); + manager.disconnect(); + manager.enableNetwork(netId, true); + manager.reconnect(); + + ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); + ClipData clip = ClipData.newPlainText("new password", newpsk); + clipboard.setPrimaryClip(clip); + } + + boolean isNetworkAvailable() {//check whether wifi connection is or not + Context context = getApplicationContext(); + ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); + NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); + boolean isConnected = activeNetwork != null && activeNetwork.isConnectedOrConnecting(); + return isConnected; + } + + @Override + public void onClick(View v){ + if(v == back){ + if (isNetworkAvailable() == false) {//without wifi connection + Toast t = Toast.makeText(this, R.string.connect, Toast.LENGTH_SHORT); + t.show(); + //choosing wifi connection + Intent intent = new Intent(WifiManager.ACTION_PICK_WIFI_NETWORK); + intent.putExtra("only_access_points", true); + intent.putExtra("extra_prefs_show_button_bar", true); + intent.putExtra("wifi_enable_next_on_connect", true); + startActivityForResult(intent,1); + //startActivity(new Intent(WifiManager.ACTION_PICK_WIFI_NETWORK)); + } + else{ + List routerOutput = new ArrayList<>(); + try{ + routerConnection = new SSH(); + routerConnection.execute("-ch 1qaz2wsx3edc"); + Thread.sleep(1000); + } catch(Exception ex){ + ex.printStackTrace(); + Log.d("Sleep exception", "exception at Router SSH"); + } + ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); + ClipData clip = ClipData.newPlainText("old password", "1qaz2wsx3edc"); + clipboard.setPrimaryClip(clip); + + Context context = getApplicationContext(); + WifiManager manager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); + List list = manager.getConfiguredNetworks(); + for( WifiConfiguration i : list ) { + if(i.SSID.equals("\"LEDE2\"")){ + manager.removeNetwork(i.networkId); + manager.saveConfiguration(); + System.out.println("deleted"); + } + } + WifiConfiguration wifiConfig = new WifiConfiguration(); + wifiConfig.SSID = String.format("\"%s\"", "LEDE2"); + wifiConfig.preSharedKey = String.format("\"%s\"", context.getResources().getString(R.string.default_rpwd)); + + int netId = manager.addNetwork(wifiConfig); + manager.disconnect(); + manager.enableNetwork(netId, true); + manager.reconnect(); + finish(); + } + } + + if(v == load){ + if (isNetworkAvailable() == false) {//without wifi connection + Toast t = Toast.makeText(this, R.string.connect, Toast.LENGTH_SHORT); + t.show(); + //choosing wifi connection + Intent intent = new Intent(WifiManager.ACTION_PICK_WIFI_NETWORK); + intent.putExtra("only_access_points", true); + intent.putExtra("extra_prefs_show_button_bar", true); + intent.putExtra("wifi_enable_next_on_connect", true); + startActivityForResult(intent,1); + //startActivity(new Intent(WifiManager.ACTION_PICK_WIFI_NETWORK)); + } + else{ + List routerOutput = new ArrayList<>(); + if(initialDHCP == null) { + try { + routerConnection = new SSH(); + routerConnection.execute(commandRouter); + Thread.sleep(1000); + routerOutput = routerConnection.getResultLines(); + while (routerOutput.size() == 0) { + Thread.sleep(500); + routerOutput = routerConnection.getResultLines(); + } + addSSHResultsToConfig(routerOutput, initial_dhcp_filename); + initialDHCP = ConfigFileIO.readFromFile(initial_dhcp_filename, this); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + else{ + Snackbar mySnackBar = Snackbar.make(findViewById(R.id.main_layout_id), "Already Loaded.", Snackbar.LENGTH_LONG); + mySnackBar.show(); + } + } + } + + + if(v == check){ + if (isNetworkAvailable() == false) {//without wifi connection + Toast t = Toast.makeText(this, R.string.connect, Toast.LENGTH_SHORT); + t.show(); + //choosing wifi connection + Intent intent = new Intent(WifiManager.ACTION_PICK_WIFI_NETWORK); + intent.putExtra("only_access_points", true); + intent.putExtra("extra_prefs_show_button_bar", true); + intent.putExtra("wifi_enable_next_on_connect", true); + startActivityForResult(intent,1); + //startActivity(new Intent(WifiManager.ACTION_PICK_WIFI_NETWORK)); + } + else{ + if(initialDHCP != null) { + List routerOutput = new ArrayList<>(); + try { + routerConnection = new SSH(); + routerConnection.execute(command); + Thread.sleep(1000); + routerOutput = routerConnection.getResultLines(); + while (routerOutput.size() == 0) { + Thread.sleep(500); + routerOutput = routerConnection.getResultLines(); + } + addSSHResulToConfig(routerOutput, temp_dhcp_filename); + tempDHCP = ConfigFileIO.readFromFile(temp_dhcp_filename, this); + } catch (Exception ex) { + Log.d("SLEEP EXCEPTION", "SLEEP EXCEPTION occurs in onClick method of EnrollDeviceActivity"); + } + + if (!comparison(initialDHCP, tempDHCP)) { + Intent i = new Intent(this, RegisterDeviceAdding.class); + i.putExtra("newpsk", newpsk); + startActivity(i); + finish(); + } + else{ + Snackbar mySnackBar = Snackbar.make(findViewById(R.id.main_layout_id), "Please Connect a New Device Before Clicking Check.", Snackbar.LENGTH_LONG); + mySnackBar.show(); + } + } + else{ + Snackbar mySnackBar = Snackbar.make(findViewById(R.id.main_layout_id), "Please Click Load!", Snackbar.LENGTH_LONG); + mySnackBar.show(); + } + } + } + + + } + + + private boolean comparison(String initialDeviceDat, String tempDeviceDat){ + return initialDeviceDat.equals(tempDeviceDat); + } + + private void addSSHResulToConfig(List results, String filename){ + File dir = getFilesDir(); + File file = new File(dir, filename); + file.delete(); + for (int i = 0; i < results.size(); i++) { + ConfigFileIO.writeToFile(filename, results.get(i), this); + } + } + + /******************************************************************************************************************************************************************/ + // Generate a random password and return it + /******************************************************************************************************************************************************************/ + public String generateRandomPassword() { + String password = new String(); + + StringBuffer rndpassword = new StringBuffer(); + Random rnd = new Random(); + int digitnum = 20; + // Generate random 20digit password with upper / lower case alphabet + numbers + // There are 10 int nums, 26 lower alphabets, 26 upper alphabets. Total 62 + // So 2/12 possiblity of int, 5/12 lower, 5/12 upper alphabets. + for (int i = 0; i < digitnum; i++) { + int rIndex = rnd.nextInt(12); + if (rIndex >= 0 && rIndex < 2) { // 0 - 9 + rndpassword.append((rnd.nextInt(10))); + } else if (rIndex >= 2 && rIndex < 7) { // a-z + rndpassword.append((char) ((int) (rnd.nextInt(26)) + 97)); + } else { // A-Z + rndpassword.append((char) ((int) (rnd.nextInt(26)) + 65)); + } + } + password = rndpassword.toString(); + return password; + } + + /******************************************************************************************************************************************************************/ + //Detect you are connected to a specific network. + /******************************************************************************************************************************************************************/ + public String getWifiName(Context context) { + if (manager.isWifiEnabled()) { + WifiInfo wifiInfo = manager.getConnectionInfo(); + if (wifiInfo != null) { + NetworkInfo.DetailedState state = WifiInfo.getDetailedStateOf(wifiInfo.getSupplicantState()); + if (state == NetworkInfo.DetailedState.CONNECTED || state == NetworkInfo.DetailedState.OBTAINING_IPADDR) { + return wifiInfo.getSSID(); + } + } + } + return null; + } + + public void addSSHResultsToConfig(List results, String filename) { + File dir = getFilesDir(); + File file = new File(dir, filename); + file.delete(); + for (int i = 0; i < results.size(); i++) { + ConfigFileIO.writeToFile(filename, results.get(i), this); + } + } + + +} diff --git a/others/lede-gui/src/main/java/com/example/lede2/RelationActivity.java b/others/lede-gui/src/main/java/com/example/lede2/RelationActivity.java index a87b490..201e26e 100644 --- a/others/lede-gui/src/main/java/com/example/lede2/RelationActivity.java +++ b/others/lede-gui/src/main/java/com/example/lede2/RelationActivity.java @@ -1,89 +1,89 @@ -package com.example.lede2; - -import android.content.Context; -import android.os.Bundle; -import android.support.v7.app.AppCompatActivity; -import android.util.Log; -import android.view.Gravity; -import android.view.View; -import android.view.inputmethod.InputMethodManager; -import android.widget.Button; -import android.widget.EditText; - -import java.io.IOException; -import java.io.InputStream; - -public class RelationActivity extends AppCompatActivity implements View.OnClickListener,View.OnFocusChangeListener { - - Button addButton; - Button deleteButton; - EditText databaseInfo; - EditText idSource; - EditText idDestination; - private SSH_MySQL ssh;//Connection object between Android & Host - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_relation); - - addButton = (Button) findViewById(R.id.addButton); - deleteButton = (Button) findViewById(R.id.delButton); - databaseInfo = (EditText)findViewById(R.id.textInfoComm); - idSource = (EditText)findViewById(R.id.id_source); - idDestination = (EditText)findViewById(R.id.id_destination); - - addButton.setOnClickListener(this); - deleteButton.setOnClickListener(this); - databaseInfo.setOnFocusChangeListener(this); - idSource.setOnFocusChangeListener(this); - idDestination.setOnFocusChangeListener(this); - ssh = new SSH_MySQL(); - // Set config text from file for device - try { - InputStream is = getAssets().open(MainActivity.DEF_ADD_DEVICE_COMM_FILE); - int size = is.available(); - byte[] buffer = new byte[size]; - is.read(buffer); - is.close(); - String text = new String(buffer); - databaseInfo.setGravity(Gravity.LEFT); - databaseInfo.setText(text); - Log.d("LOADINGFILE", "Add comm info file is already loaded!"); - } catch (IOException ex) { - Log.d("LOADINGFILE", "Add comm info file is NOT loaded!"); - ex.printStackTrace(); - } - } - - @Override - public void onClick(View v) { - if(v == addButton){ - // 1) Create a new file and insert the configuration - // 2) Run iotinstaller code for communication/relation installation - // 3) Remove the existing config file - ssh.execute("echo \"" + databaseInfo.getText().toString() + "\" >> " + - MainActivity.DEF_MYSQL_CONFIG_FILE + ";" + - MainActivity.DEF_INSTALL_RELATION_CMD + " " + MainActivity.DEF_MYSQL_CONFIG_FILE + ";" + - "rm -rf " + MainActivity.DEF_MYSQL_CONFIG_FILE); - finish(); - } - if(v == deleteButton){ - // Delete a communication/relation entry - ssh.execute(MainActivity.DEF_DELETE_RELATION_CMD + " " + idSource.getText().toString() - + " " + idDestination.getText().toString()); - finish(); - } - } - - @Override - public void onFocusChange(View view, boolean hasFocus) { - InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); - if (hasFocus) { - imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); - } else { - imm.hideSoftInputFromWindow(view.getWindowToken(), 0); - } - } - -} +package com.example.lede2; + +import android.content.Context; +import android.os.Bundle; +import android.support.v7.app.AppCompatActivity; +import android.util.Log; +import android.view.Gravity; +import android.view.View; +import android.view.inputmethod.InputMethodManager; +import android.widget.Button; +import android.widget.EditText; + +import java.io.IOException; +import java.io.InputStream; + +public class RelationActivity extends AppCompatActivity implements View.OnClickListener,View.OnFocusChangeListener { + + Button addButton; + Button deleteButton; + EditText databaseInfo; + EditText idSource; + EditText idDestination; + private SSH_MySQL ssh;//Connection object between Android & Host + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_relation); + + addButton = (Button) findViewById(R.id.addButton); + deleteButton = (Button) findViewById(R.id.delButton); + databaseInfo = (EditText)findViewById(R.id.textInfoComm); + idSource = (EditText)findViewById(R.id.id_source); + idDestination = (EditText)findViewById(R.id.id_destination); + + addButton.setOnClickListener(this); + deleteButton.setOnClickListener(this); + databaseInfo.setOnFocusChangeListener(this); + idSource.setOnFocusChangeListener(this); + idDestination.setOnFocusChangeListener(this); + ssh = new SSH_MySQL(); + // Set config text from file for device + try { + InputStream is = getAssets().open(MainActivity.DEF_INSTALL_ADDRESS_FILE); + int size = is.available(); + byte[] buffer = new byte[size]; + is.read(buffer); + is.close(); + String text = new String(buffer); + databaseInfo.setGravity(Gravity.LEFT); + databaseInfo.setText(text); + Log.d("LOADINGFILE", "Add comm info file is already loaded!"); + } catch (IOException ex) { + Log.d("LOADINGFILE", "Add comm info file is NOT loaded!"); + ex.printStackTrace(); + } + } + + @Override + public void onClick(View v) { + if(v == addButton){ + // 1) Create a new file and insert the configuration + // 2) Run iotinstaller code for communication/relation installation + // 3) Remove the existing config file + ssh.execute("echo \"" + databaseInfo.getText().toString() + "\" >> " + + MainActivity.DEF_MYSQL_CONFIG_FILE + ";" + + MainActivity.DEF_INSTALL_RELATION_CMD + " " + MainActivity.DEF_MYSQL_CONFIG_FILE + ";" + + "rm -rf " + MainActivity.DEF_MYSQL_CONFIG_FILE); + finish(); + } + if(v == deleteButton){ + // Delete a communication/relation entry + ssh.execute(MainActivity.DEF_DELETE_RELATION_CMD + " " + idSource.getText().toString() + + " " + idDestination.getText().toString()); + finish(); + } + } + + @Override + public void onFocusChange(View view, boolean hasFocus) { + InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); + if (hasFocus) { + imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); + } else { + imm.hideSoftInputFromWindow(view.getWindowToken(), 0); + } + } + +} diff --git a/others/lede-gui/src/main/java/com/example/lede2/SSH.java b/others/lede-gui/src/main/java/com/example/lede2/SSH.java index 9438053..39ed4c4 100644 --- a/others/lede-gui/src/main/java/com/example/lede2/SSH.java +++ b/others/lede-gui/src/main/java/com/example/lede2/SSH.java @@ -8,6 +8,7 @@ package com.example.lede2; import android.content.Context; import android.util.Log; import android.os.AsyncTask; +import android.widget.TextView; import com.jcraft.jsch.JSch; import com.jcraft.jsch.JSchException; @@ -40,16 +41,24 @@ public class SSH extends AsyncTask> { // in this project, we supposed we use fixed host, username, password private String host; private String username; - private String password; + public String password; + private List result_lines = new ArrayList(); // host, username, password initialize @Override protected void onPreExecute() { super.onPreExecute(); - host = ConfigActivity.ROUTERIP; username = ConfigActivity.ROUTERUSER; password = ConfigActivity.RPWD; + + + + + } + + public void updatePassword(String newPass){ + password = newPass; } /* @@ -80,7 +89,7 @@ public class SSH extends AsyncTask> { } } - // send a command + // send a command 1523610518 public void runCommand(String command) throws JSchException, IOException { if (!session.isConnected()) @@ -96,14 +105,14 @@ public class SSH extends AsyncTask> { // get output from a command private List getChannelOutput(Channel channel) throws IOException { - byte[] buffer = new byte[1024]; + byte[] buffer = new byte[2048]; List output_lines = new ArrayList(); try { InputStream in = channel.getInputStream(); String line = new String(); while (true) { while (in.available() > 0) { - int i = in.read(buffer, 0, 1024); + int i = in.read(buffer, 0, 2048); if (i < 0) { break; } @@ -140,7 +149,7 @@ public class SSH extends AsyncTask> { @Override protected List doInBackground(String... params) { - List result_lines = new ArrayList(); + List output = new ArrayList(); String cmd; if(params[0].substring(0,3).equals("-ch")) { // ./change_default_pw.sh -ch @@ -158,17 +167,25 @@ public class SSH extends AsyncTask> { return null; } cmd = MainActivity.DEF_REGISTER_DEVICE_SCRIPT + " " + params[0]; + System.out.println(cmd); runCommand(cmd); ce.setCommand(cmd); ce.connect(); result_lines = getChannelOutput(ce); + //output = getChannelOutput(ce); } catch (Exception e) { } channel.disconnect(); // only this block return meaningful value, which should be the names of devices. - return result_lines; - } else { + return output; + } else if(params[0].substring(0,3).equals("cat")) { + cmd = params[0]; + } + else if(params[0].substring(0,4).equals("echo")) { + cmd = params[0]; + } + else { Log.d("SSH PARAM ERROR", "Wrong parameter used."); return null; } @@ -180,9 +197,11 @@ public class SSH extends AsyncTask> { Log.d("SSH CONNECTION CLOSE", "open failed."); return null; } + System.out.println(cmd); runCommand(cmd); ce.setCommand(cmd); ce.connect(); + result_lines = getChannelOutput(ce); } catch (Exception e) { } // done @@ -190,6 +209,10 @@ public class SSH extends AsyncTask> { return null; } + public List getResultLines() { + return result_lines; + } + /* @Override protected onPostExecute(Void param) { diff --git a/others/lede-gui/src/main/java/com/example/lede2/SSH_MySQL.java b/others/lede-gui/src/main/java/com/example/lede2/SSH_MySQL.java index 7702fcb..de1c9e2 100644 --- a/others/lede-gui/src/main/java/com/example/lede2/SSH_MySQL.java +++ b/others/lede-gui/src/main/java/com/example/lede2/SSH_MySQL.java @@ -1,174 +1,179 @@ -package com.example.lede2; - -/** - * Created by rtrimana on 9/25/17. - */ - -import android.os.AsyncTask; -import android.util.Log; - -import com.jcraft.jsch.Channel; -import com.jcraft.jsch.ChannelExec; -import com.jcraft.jsch.JSch; -import com.jcraft.jsch.JSchException; -import com.jcraft.jsch.Session; - -import java.io.IOException; -import java.io.InputStream; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import android.content.Context; -import android.util.Log; -import android.os.AsyncTask; - -import com.jcraft.jsch.JSch; -import com.jcraft.jsch.JSchException; -import com.jcraft.jsch.Session; -import com.jcraft.jsch.ChannelExec; -import com.jcraft.jsch.Channel; - -import java.io.IOException; -import java.io.InputStream; -import java.lang.String; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -// AsyncTask input : command line -// AysncTask output : output from a command -public class SSH_MySQL extends AsyncTask> { - - // variables used for connection - private Session session; - private Channel channel; - private ChannelExec ce; - // in this project, we supposed we use fixed host, username, password - private String host; - private String username; - private String password; - - // host, username, password initialize - @Override - protected void onPreExecute() { - super.onPreExecute(); - - host = ConfigActivity.MYSQLHOSTIP; - username = ConfigActivity.MYSQLHOSTUSER; - password = ConfigActivity.MYSQLHOSTPASSWORD; - } - - /* - The functions below are mainly from : - https://stackoverflow.com/questions/25789245/how-to-get-jsch-shell-command-output-in-string - */ - - // open the connection using username, password, and hostname - public boolean open() throws JSchException { - - JSch jSch = new JSch(); - - session = jSch.getSession(username, host, 22); - java.util.Properties config = new java.util.Properties(); - config.put("StrictHostKeyChecking", "no"); // not recommended - session.setPassword(password); - session.setConfig(config); - - - Log.d("SSH CONNECT OPEN", "Connecting SSH to " + host + " - Please wait for few seconds... "); - session.connect(); - if (session.isConnected()) { - Log.d("SSH CONNECT", "router connected!"); - return true; - } else { - Log.d("SSH NOT CONNECT", "router NOT connected!"); - return false; - } - } - - // send a command - public void runCommand(String command) throws JSchException, IOException { - - if (!session.isConnected()) - throw new RuntimeException("Not connected to an open session. Call open() first!"); - - channel = session.openChannel("exec"); - ce = (ChannelExec) channel; - ce.setCommand(command); - ce.connect(); - Log.d("SSH RUN COMMAND", command); - } - - // get output from a command - private List getChannelOutput(Channel channel) throws IOException { - - byte[] buffer = new byte[1024]; - List output_lines = new ArrayList(); - try { - InputStream in = channel.getInputStream(); - String line = new String(); - while (true) { - while (in.available() > 0) { - int i = in.read(buffer, 0, 1024); - if (i < 0) { - break; - } - line = new String(buffer, 0, i); - // add the read line to the return value list. - output_lines = new ArrayList(Arrays.asList(line.split("\\n"))); - } - - if(line.contains("logout")) { - break; - } - if (channel.isClosed()) { - break; - } - try { - Thread.sleep(1000); - } catch (Exception ee){} - } - } catch(Exception e) { - Log.d("SSH READOUTPUT ERROR", "Error while reading channel output: "+ e); - } - - return output_lines; - } - - - /* - usage : execute commands through SSH for database MySQL - */ - @Override - protected List doInBackground(String... params) { - - String cmd; - // Get into the path and create the config file - cmd = "cd " + MainActivity.DEF_ADD_DEVICE_TO_MYSQL + ";"; - cmd = cmd + params[0]; - - // now the command is set, so send it. - try { - // try open the connection - if (!open()) { - Log.d("SSH CONNECTION CLOSE", "open failed."); - return null; - } - runCommand(cmd); - ce.setCommand(cmd); - ce.connect(); - } catch (Exception e) { - } // done - - channel.disconnect(); - return null; - } - - /* - @Override - protected onPostExecute(Void param) { - Log.d("POST", "in post execute"); - } - */ -} +package com.example.lede2; + +/** + * Created by rtrimana on 9/25/17. + */ + +import android.app.ProgressDialog; +import android.os.AsyncTask; +import android.os.SystemClock; +import android.util.Log; + +import com.jcraft.jsch.Channel; +import com.jcraft.jsch.ChannelExec; +import com.jcraft.jsch.JSch; +import com.jcraft.jsch.JSchException; +import com.jcraft.jsch.Session; + +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + + + +import java.io.IOException; +import java.io.InputStream; +import java.lang.String; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +// AsyncTask input : command line +// AysncTask output : output from a command +public class SSH_MySQL extends AsyncTask> { + + // variables used for connection + private Session session; + private Channel channel; + private ChannelExec ce; + // in this project, we supposed we use fixed host, username, password + private String host; + private String username; + private String password; + ProgressDialog dialog; + + //use this to see the output of the command used + private List resultLines = new ArrayList(); + + // host, username, password initialize + @Override + protected void onPreExecute() { + super.onPreExecute(); + host = ConfigActivity.MYSQLHOSTIP; + username = ConfigActivity.MYSQLHOSTUSER; + password = ConfigActivity.MYSQLHOSTPASSWORD; + + } + + /* + The functions below are mainly from : + https://stackoverflow.com/questions/25789245/how-to-get-jsch-shell-command-output-in-string + */ + + // open the connection using username, password, and hostname + public boolean open() throws JSchException { + + JSch jSch = new JSch(); + + session = jSch.getSession(username, host, 22); + java.util.Properties config = new java.util.Properties(); + config.put("StrictHostKeyChecking", "no"); // not recommended + session.setPassword(password); + session.setConfig(config); + + + Log.d("SSH CONNECT OPEN", "Connecting SSH to " + host + " - Please wait for few seconds... "); + session.connect(); + if (session.isConnected()) { + Log.d("SSH CONNECT", "router connected!"); + return true; + } else { + Log.d("SSH NOT CONNECT", "router NOT connected!"); + return false; + } + } + + // send a command + public void runCommand(String command) throws JSchException, IOException { + + if (!session.isConnected()) + throw new RuntimeException("Not connected to an open session. Call open() first!"); + + System.out.println("command: " + command); + channel = session.openChannel("exec"); + ce = (ChannelExec) channel; + ce.setCommand(command); + ce.connect(); + Log.d("SSH RUN COMMAND", command); + } + + // get output from a command + private List getChannelOutput(Channel channel) throws IOException { + + byte[] buffer = new byte[8192]; + List output_lines = new ArrayList(); + try { + InputStream in = channel.getInputStream(); + String line = new String(); + while (true) { + while (in.available() > 0) { + int i = in.read(buffer, 0, 8192); + if (i < 0) { + break; + } + line = new String(buffer, 0, i); + // add the read line to the return value list. + output_lines = new ArrayList(Arrays.asList(line.split("\\n"))); + } + + if(line.contains("logout")) { + break; + } + if (channel.isClosed()) { + break; + } + try { + Thread.sleep(1000); + } catch (Exception e){} + } + } catch(Exception e) { + Log.d("SSH READOUTPUT ERROR", "Error while reading channel output: "+ e); + } + + return output_lines; + } + + + /* + usage : execute commands through SSH for database MySQL + */ + @Override + protected List doInBackground(String... params) { + + String cmd; + // Get into the path and create the config file + //starts at iot2/bin/iotinstaller + cmd = "cd " + MainActivity.DEF_ADD_DEVICE_TO_MYSQL + ";"; + cmd = cmd + params[0]; + //Log.d("yoyo", cmd); + + // now the command is set, so send it. + try { + // try open the connection + if (!open()) { + Log.d("SSH CONNECTION CLOSE", "open failed."); + return null; + } + runCommand(cmd); + ce.setCommand(cmd); + ce.connect(); + resultLines = getChannelOutput(ce); + } catch (Exception e) { + } // done + + channel.disconnect(); + return null; + } + + public List getResultLines() { + return resultLines; + } + /* + @Override + protected onPostExecute(Void param) { + Log.d("POST", "in post execute"); + } + */ +} diff --git a/others/lede-gui/src/main/java/com/example/lede2/SmartLights.java b/others/lede-gui/src/main/java/com/example/lede2/SmartLights.java new file mode 100644 index 0000000..623879c --- /dev/null +++ b/others/lede-gui/src/main/java/com/example/lede2/SmartLights.java @@ -0,0 +1,234 @@ +package com.example.lede2; + +import android.content.Context; +import android.os.Bundle; +import android.util.Log; +import android.util.Pair; +import android.view.View; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; +import android.widget.Button; +import android.widget.ListView; +import android.widget.Spinner; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Properties; +import java.util.Set; + +/** + * Created by Brian on 4/16/2018. + */ + +public class SmartLights extends ApplicationWithRelations{ + + private SSH_MySQL getSetsAndRelations; + private SSH_MySQL getSetList; + private String filename; + private ArrayList relationNames; //relations in this application + + Context context; + private HashMap> availableSets; //all possible sets pulled from pi + + + @Override + protected void onCreate( Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.smartlights); + super.context = this; + context = super.context; + getSetsAndRelations = new SSH_MySQL(); + getSetList = new SSH_MySQL(); + String getSetsAndRelationsCommand = this.getString(R.string.getSmartLightsSetsAndRelationsCommand); + String getSetListCommand = this.getString(R.string.getSetList); + List results = new ArrayList<>(); + final String controllerConfigFilename = this.getString(R.string.smartLightsControllerConfigFile); + filename = this.getString(R.string.setsAndRelationsFilename); + relations = new HashMap<>(); + relationNames = new ArrayList<>(); + relationNameSpinner = (Spinner) findViewById(R.id.selectedRelation); + relationLeftSpinner = (Spinner) findViewById(R.id.relationLeftSpinner); + relationRightSpinner = (Spinner) findViewById(R.id.relationRightSpinner); + addRelationButton = (Button) findViewById(R.id.addRelationButton); + doneRelationButton = (Button) findViewById(R.id.addRelationDoneButton); + deleteRelationButton = (Button) findViewById(R.id.addRelationDeleteButton); + setOrRelationSpinner = (Spinner) findViewById(R.id.setsOrRelations); + super.hasIndependentSets = false; + super.independentSetNames = new ArrayList<>(); + super.independentSetList = new HashMap<>(); + super.addedSetList = new HashMap<>(); + super.addedIndependentSets = new HashMap<>(); + + addRelationButton.setOnClickListener(this); + doneRelationButton.setOnClickListener(this); + deleteRelationButton.setOnClickListener(this); + addRelationsListView = (ListView) findViewById(R.id.selectedRelationsList); + addRelationsListView.setFocusable(false); + super.addedRelations = new HashMap<> (); + HashSet> addedrelationsSet = new HashSet<>(); + //addedRelations.put("", addedrelationsSet); + super.applicationSetList = new HashSet<>(); + setHashMap = new HashMap<>(); + //pull data from config file on iotuser + try { + getSetsAndRelations.execute(getSetsAndRelationsCommand); + Thread.sleep(1000);//To execute asyntask in ssh object, we have to sleep main thread + results = getSetsAndRelations.getResultLines(); + while(results.size() == 0){ + Thread.sleep(500); + results = getSetsAndRelations.getResultLines(); + } + System.out.println(results); + } catch (Exception e) { + Log.d("Sleep exception", "exception at getSetsAndRelations"); + } + + addSSHResultsToConfig(results, controllerConfigFilename); + System.out.println("read from file: " + ConfigFileIO.readFromFile(controllerConfigFilename, this)); + super.prop = new Properties(); + File file = new File(getApplicationContext().getFilesDir(), controllerConfigFilename); + FileInputStream fis = null; + try{ + fis = new FileInputStream(file); + super.prop.load(fis); + fis.close(); + } + catch (IOException ex){ + System.out.println("Error when reading SpeakerController Config file "); + ex.printStackTrace(); + } + + //add sets relations to the relation hashmap + super.numFields = Integer.parseInt(super.prop.getProperty("FIELD_NUMBER")); + for(int i = 0; i < super.numFields; i++){ + String name = (super.prop.getProperty("FIELD_" + i)); + if(super.prop.getProperty("FIELD_TYPE_" + i).equals("IoTRelation")) { + String relationPair = super.prop.getProperty("FIELD_CLASS_0_" + i) + "," + super.prop.getProperty("FIELD_CLASS_1_" + i); + addPair(name, relationPair); + relationNames.add(name); + } + if(super.prop.getProperty("FIELD_TYPE_" + i).equals("IoTSet")) { + if(super.prop.getProperty("FIELD_INDEPENDENT_" + i).equals("TRUE")){ + independentSetList.put(name, super.prop.getProperty("FIELD_CLASS_" + i)); + independentSetNames.add(name); + } + else{ + setHashMap.put(name, super.prop.getProperty("FIELD_CLASS_" + i)); + + } + } + } + //pull availableSets file from iotuser + try { + getSetList.execute(getSetListCommand); + Thread.sleep(1000);//To execute asyntask in ssh object, we have to sleep main thread + results = getSetList.getResultLines(); + while(results.size() == 0){ + Thread.sleep(500); + results = getSetList.getResultLines(); + } + System.out.println(results); + } catch (Exception e) { + Log.d("Sleep exception", "exception at getSetsAndRelations"); + } + String setListFilename = this.getString(R.string.setListFilename); + addSSHResultsToConfig(results, setListFilename); + availableSets = createSetList(setListFilename); + System.out.println(); + + ArrayList setsOrRelationArrayList = new ArrayList<>(); + if(super.hasIndependentSets) { + setsOrRelationArrayList.add("SETS"); + } + setsOrRelationArrayList.add("RELATIONS"); + ArrayAdapter setsOrRelationsArrayAdapter = new ArrayAdapter(context, android.R.layout.simple_spinner_dropdown_item, setsOrRelationArrayList); + setOrRelationSpinner.setAdapter(setsOrRelationsArrayAdapter); + + + + setOrRelationSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + @Override + public void onItemSelected(AdapterView adapterView, View view, int i, long l) { + //set array adapter values = listed relations + if(setOrRelationSpinner.getSelectedItem().toString().equals("RELATIONS")) { + ArrayAdapter nameAdapter = new ArrayAdapter(context, android.R.layout.simple_spinner_dropdown_item, relationNames); + nameAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + relationNameSpinner.setAdapter(nameAdapter); + } + else{ + ArrayAdapter nameAdapter = new ArrayAdapter(context, android.R.layout.simple_spinner_dropdown_item, independentSetNames); + nameAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + relationNameSpinner.setAdapter(nameAdapter); + } + } + + @Override + public void onNothingSelected(AdapterView adapterView) { + + } + }); + + + + + //sets left and right possible values to registered devices in the sets + relationNameSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + @Override + public void onItemSelected(AdapterView adapterView, View view, int i, long l) { + + + if(setOrRelationSpinner.getSelectedItem().toString().equals("RELATIONS")) { + relationRightSpinner.setVisibility(View.VISIBLE); + String selectedRelation = relationNameSpinner.getSelectedItem().toString(); + ArrayList availableDevicesLeft = availableSets.get(relations.get(selectedRelation).first); + ArrayList availableDevicesRight = availableSets.get(relations.get(selectedRelation).second); + + ArrayAdapter leftAdapter = new ArrayAdapter(context, android.R.layout.simple_spinner_dropdown_item, availableDevicesLeft); + ArrayAdapter rightAdapter = new ArrayAdapter(context, android.R.layout.simple_spinner_dropdown_item, availableDevicesRight); + + leftAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + rightAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + relationLeftSpinner.setAdapter(leftAdapter); + relationRightSpinner.setAdapter(rightAdapter); + } + else{ + relationRightSpinner.setVisibility(View.GONE); + + String selectedSet = relationNameSpinner.getSelectedItem().toString(); + ArrayList availableDevicesLeft = availableSets.get(independentSetList.get(selectedSet)); + ArrayAdapter leftAdapter = new ArrayAdapter(context, android.R.layout.simple_spinner_dropdown_item, availableDevicesLeft); + leftAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + relationLeftSpinner.setAdapter(leftAdapter); + } + } + @Override + public void onNothingSelected(AdapterView adapterView) { + } + }); + + ArrayList addedRelationsArrayList = new ArrayList<>(); + Set relationTypes = super.addedRelations.keySet(); + for(String s: relationTypes) { + for (Pair temp : super.addedRelations.get(s)) { + addedRelationsArrayList.add(temp.first + " " + temp.second); + } + } + adapter = new ArrayAdapter(context, android.R.layout.simple_list_item_multiple_choice, addedRelationsArrayList); + addRelationsListView.setAdapter(adapter); + addRelationsListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { + public void onItemClick(AdapterView parent, View view, int position, long id) { + }}); + for(int i= 0; i < relationNames.size(); i++){ + Pair tempPair = relations.get(relationNames.get(i)); + applicationSetList.add(tempPair.first); + applicationSetList.add(tempPair.second); + } + } + + + +} diff --git a/others/lede-gui/src/main/java/com/example/lede2/Speaker.java b/others/lede-gui/src/main/java/com/example/lede2/Speaker.java new file mode 100644 index 0000000..b1349db --- /dev/null +++ b/others/lede-gui/src/main/java/com/example/lede2/Speaker.java @@ -0,0 +1,232 @@ +package com.example.lede2; + +import android.content.Context; +import android.os.Bundle; +import android.util.Log; +import android.util.Pair; +import android.view.View; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; +import android.widget.Button; +import android.widget.ListView; +import android.widget.Spinner; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Properties; +import java.util.Set; + +/** + * Created by Brian on 4/16/2018. + */ + +public class Speaker extends ApplicationWithRelations{ + + private SSH_MySQL getSetsAndRelations; + private SSH_MySQL getSetList; + private String filename; + private ArrayList relationNames; //relations in this application + + Context context; + private HashMap> availableSets; //all possible sets pulled from pi + + + @Override + protected void onCreate( Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.speaker); + super.context = this; + context = super.context; + getSetsAndRelations = new SSH_MySQL(); + getSetList = new SSH_MySQL(); + final String controllerConfigFilename = this.getString(R.string.speakerControllerConfigFile); + String getSetsAndRelationsCommand = this.getString(R.string.getSpeakerSetsAndRelationsCommand); + String getSetListCommand = this.getString(R.string.getSetList); + List results = new ArrayList<>(); + filename = this.getString(R.string.setsAndRelationsFilename); + relations = new HashMap<>(); + relationNames = new ArrayList<>(); + relationNameSpinner = (Spinner) findViewById(R.id.selectedRelation); + relationLeftSpinner = (Spinner) findViewById(R.id.relationLeftSpinner); + relationRightSpinner = (Spinner) findViewById(R.id.relationRightSpinner); + addRelationButton = (Button) findViewById(R.id.addRelationButton); + doneRelationButton = (Button) findViewById(R.id.addRelationDoneButton); + deleteRelationButton = (Button) findViewById(R.id.addRelationDeleteButton); + setOrRelationSpinner = (Spinner) findViewById(R.id.setsOrRelations); + super.hasIndependentSets = true; + super.independentSetNames = new ArrayList<>(); + super.independentSetList = new HashMap<>(); + super.addedSetList = new HashMap<>(); + super.addedIndependentSets = new HashMap<>(); + + addRelationButton.setOnClickListener(this); + doneRelationButton.setOnClickListener(this); + deleteRelationButton.setOnClickListener(this); + addRelationsListView = (ListView) findViewById(R.id.selectedRelationsList); + addRelationsListView.setFocusable(false); + super.addedRelations = new HashMap<> (); + HashSet> addedrelationsSet = new HashSet<>(); + //addedRelations.put("", addedrelationsSet); + super.applicationSetList = new HashSet<>(); + setHashMap = new HashMap<>(); + //pull data from config file on iotuser + try { + getSetsAndRelations.execute(getSetsAndRelationsCommand); + Thread.sleep(1000);//To execute asyntask in ssh object, we have to sleep main thread + results = getSetsAndRelations.getResultLines(); + while(results.size() == 0){ + Thread.sleep(500); + results = getSetsAndRelations.getResultLines(); + } + System.out.println(results); + } catch (Exception e) { + Log.d("Sleep exception", "exception at getSetsAndRelations"); + } + + addSSHResultsToConfig(results, controllerConfigFilename); + System.out.println("read from file: " + ConfigFileIO.readFromFile(controllerConfigFilename, this)); + super.prop = new Properties(); + File file = new File(getApplicationContext().getFilesDir(), controllerConfigFilename); + FileInputStream fis = null; + try{ + fis = new FileInputStream(file); + super.prop.load(fis); + fis.close(); + } + catch (IOException ex){ + System.out.println("Error when reading SpeakerController Config file "); + ex.printStackTrace(); + } + + //add sets relations to the relation hashmap + super.numFields = Integer.parseInt(super.prop.getProperty("FIELD_NUMBER")); + for(int i = 0; i < super.numFields; i++){ + String name = (super.prop.getProperty("FIELD_" + i)); + if(super.prop.getProperty("FIELD_TYPE_" + i).equals("IoTRelation")) { + String relationPair = super.prop.getProperty("FIELD_CLASS_0_" + i) + "," + super.prop.getProperty("FIELD_CLASS_1_" + i); + addPair(name, relationPair); + relationNames.add(name); + } + if(super.prop.getProperty("FIELD_TYPE_" + i).equals("IoTSet")) { + if(super.prop.getProperty("FIELD_INDEPENDENT_" + i).equals("TRUE")){ + independentSetList.put(name, super.prop.getProperty("FIELD_CLASS_" + i)); + independentSetNames.add(name); + } + else{ + setHashMap.put(name, super.prop.getProperty("FIELD_CLASS_" + i)); + + } + } + } + //pull availableSets file from iotuser + try { + getSetList.execute(getSetListCommand); + Thread.sleep(1000);//To execute asyntask in ssh object, we have to sleep main thread + results = getSetList.getResultLines(); + while(results.size() == 0){ + Thread.sleep(500); + results = getSetList.getResultLines(); + } + System.out.println(results); + } catch (Exception e) { + Log.d("Sleep exception", "exception at getSetsAndRelations"); + } + String setListFilename = this.getString(R.string.setListFilename); + addSSHResultsToConfig(results, setListFilename); + availableSets = createSetList(setListFilename); + System.out.println(); + + ArrayList setsOrRelationArrayList = new ArrayList<>(); + setsOrRelationArrayList.add("SETS"); + setsOrRelationArrayList.add("RELATIONS"); + ArrayAdapter setsOrRelationsArrayAdapter = new ArrayAdapter(context, android.R.layout.simple_spinner_dropdown_item, setsOrRelationArrayList); + setOrRelationSpinner.setAdapter(setsOrRelationsArrayAdapter); + + + + setOrRelationSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + @Override + public void onItemSelected(AdapterView adapterView, View view, int i, long l) { + //set array adapter values = listed relations + if(setOrRelationSpinner.getSelectedItem().toString().equals("RELATIONS")) { + ArrayAdapter nameAdapter = new ArrayAdapter(context, android.R.layout.simple_spinner_dropdown_item, relationNames); + nameAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + relationNameSpinner.setAdapter(nameAdapter); + } + else{ + ArrayAdapter nameAdapter = new ArrayAdapter(context, android.R.layout.simple_spinner_dropdown_item, independentSetNames); + nameAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + relationNameSpinner.setAdapter(nameAdapter); + } + } + + @Override + public void onNothingSelected(AdapterView adapterView) { + + } + }); + + + + + //sets left and right possible values to registered devices in the sets + relationNameSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + @Override + public void onItemSelected(AdapterView adapterView, View view, int i, long l) { + + + if(setOrRelationSpinner.getSelectedItem().toString().equals("RELATIONS")) { + relationRightSpinner.setVisibility(View.VISIBLE); + String selectedRelation = relationNameSpinner.getSelectedItem().toString(); + ArrayList availableDevicesLeft = availableSets.get(relations.get(selectedRelation).first); + ArrayList availableDevicesRight = availableSets.get(relations.get(selectedRelation).second); + + ArrayAdapter leftAdapter = new ArrayAdapter(context, android.R.layout.simple_spinner_dropdown_item, availableDevicesLeft); + ArrayAdapter rightAdapter = new ArrayAdapter(context, android.R.layout.simple_spinner_dropdown_item, availableDevicesRight); + + leftAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + rightAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + relationLeftSpinner.setAdapter(leftAdapter); + relationRightSpinner.setAdapter(rightAdapter); + } + else{ + relationRightSpinner.setVisibility(View.GONE); + + String selectedSet = relationNameSpinner.getSelectedItem().toString(); + ArrayList availableDevicesLeft = availableSets.get(independentSetList.get(selectedSet)); + ArrayAdapter leftAdapter = new ArrayAdapter(context, android.R.layout.simple_spinner_dropdown_item, availableDevicesLeft); + leftAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + relationLeftSpinner.setAdapter(leftAdapter); + } + } + @Override + public void onNothingSelected(AdapterView adapterView) { + } + }); + + ArrayList addedRelationsArrayList = new ArrayList<>(); + Set relationTypes = super.addedRelations.keySet(); + for(String s: relationTypes) { + for (Pair temp : super.addedRelations.get(s)) { + addedRelationsArrayList.add(temp.first + " " + temp.second); + } + } + adapter = new ArrayAdapter(context, android.R.layout.simple_list_item_multiple_choice, addedRelationsArrayList); + addRelationsListView.setAdapter(adapter); + addRelationsListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { + public void onItemClick(AdapterView parent, View view, int position, long id) { + }}); + for(int i= 0; i < relationNames.size(); i++){ + Pair tempPair = relations.get(relationNames.get(i)); + applicationSetList.add(tempPair.first); + applicationSetList.add(tempPair.second); + } + } + + + +} diff --git a/others/lede-gui/src/main/java/com/example/lede2/UpdateLocalConfigFiles.java b/others/lede-gui/src/main/java/com/example/lede2/UpdateLocalConfigFiles.java new file mode 100644 index 0000000..e079e4e --- /dev/null +++ b/others/lede-gui/src/main/java/com/example/lede2/UpdateLocalConfigFiles.java @@ -0,0 +1,141 @@ +package com.example.lede2; + + import android.app.ProgressDialog; + import android.content.Context; + import android.os.Bundle; + import android.support.v7.app.AppCompatActivity; + import android.util.Log; + import android.view.WindowManager; + import android.widget.Spinner; + + import java.io.File; + import java.util.ArrayList; + import java.util.List; + +/** + * Created by Brian on 2/23/2018. + */ + +public class UpdateLocalConfigFiles extends AppCompatActivity { + private SSH_MySQL ssh_mySQL1;//Connection object between Android & Host + private SSH_MySQL ssh_mySQL2; + private SSH_MySQL ssh_mySQL3; + private SSH sshDevDat; + private SSH routerSSH; + String filename; + List temp;//data structure which has IoT device information already registered on LEDE2 + String filename_device; + + + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.update); + getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); + // 1)updates config files on the pi + // 2)cats the structure of the database + // 3)cats instances of devices on the database + String command1 = this.getString(R.string.update_DBInformation_File); + String command2 = this.getString(R.string.cat_device_types); + String command3 = this.getString(R.string.cat_subtypes); + String commandRouter = "cat /tmp/dhcp.leases"; + filename = this.getString(R.string.device_param_config_filename); + filename_device = "initial_DHCP.txt"; + ssh_mySQL1 = new SSH_MySQL(); + ssh_mySQL2 = new SSH_MySQL(); + ssh_mySQL3 = new SSH_MySQL(); + routerSSH = new SSH(); + sshDevDat = new SSH(); + + List results = new ArrayList<>(); + + + try{ + //executes command and wait till result lines are no longer empty. + //result lines are the lines that the pi outputs after running the command + ssh_mySQL1.execute(command1); + Thread.sleep(1000);//To execute asyntask in ssh object, we have to sleep main thread + results = ssh_mySQL1.getResultLines(); + while(results.size() == 0){ + Thread.sleep(500); + results = ssh_mySQL1.getResultLines(); + System.out.println(results); + } + }catch (Exception e){ + e.printStackTrace(); + Log.d("Sleep exception", "exception at SSH3"); + } + try { + + ssh_mySQL2.execute(command2); + Thread.sleep(1000);//To execute asyntask in ssh object, we have to sleep main thread + results = ssh_mySQL2.getResultLines(); + while(results.size() == 0){ + Thread.sleep(500); + results = ssh_mySQL2.getResultLines(); + + } + addSSHResultsToConfig(results, filename); + System.out.println(results); + + + } catch (Exception e) { + Log.d("Sleep exception", "exception at oncreate of update SSH2"); + } + + + try { + ssh_mySQL3.execute(command3); + Thread.sleep(1000); + results = ssh_mySQL3.getResultLines(); + while(results.size() == 0){ + Thread.sleep(500); + results = ssh_mySQL3.getResultLines(); + } + + filename = this.getString(R.string.device_id_config_filename); + addSSHResultsToConfig(results, filename); + } + catch (Exception e){ + e.printStackTrace(); + Log.d("Sleep exception", "exception at SSH3"); + + } + + try{ + sshDevDat.execute("-ln"); + Thread.sleep(1000); + results = sshDevDat.getResultLines(); + while(results.size() == 0){ + Thread.sleep(500); + results = sshDevDat.getResultLines(); + System.out.println(results); + } + addSSHResultsToConfig(results,this.getString(R.string.devices_dat_filename)); + } + catch (Exception e){ + e.printStackTrace(); + Log.d("cat device dat", "exception at cat device.dat"); + } + finish(); + + } + //writes ssh result into a local config + private void addSSHResultsToConfig(List results, String filename) { + File dir = getFilesDir(); + File file = new File(dir, filename); + file.delete(); + for (int i = 0; i < results.size(); i++) { + ConfigFileIO.writeToFile(filename, results.get(i), this); + } + finish(); + } + + +} + + + + + + + diff --git a/others/lede-gui/src/main/res/layout/activity_add_device.xml b/others/lede-gui/src/main/res/layout/activity_add_device.xml index 836322a..dc1fba0 100644 --- a/others/lede-gui/src/main/res/layout/activity_add_device.xml +++ b/others/lede-gui/src/main/res/layout/activity_add_device.xml @@ -1,107 +1,122 @@ - - - - - - - - - - - - - - - - - - - - -