diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9c4de58 --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +.gradle +/local.properties +/.idea/workspace.xml +/.idea/libraries +.DS_Store +/build +/captures diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..aed2878 --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +DriverGeoFence-master \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..96cc43e --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml new file mode 100644 index 0000000..e7bedf3 --- /dev/null +++ b/.idea/copyright/profiles_settings.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..97626ba --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..8d2df47 --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,18 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..fbb6828 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..d46b61a --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml new file mode 100644 index 0000000..7f68460 --- /dev/null +++ b/.idea/runConfigurations.xml @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..6564d52 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/DriverGeoFence-master.iml b/DriverGeoFence-master.iml new file mode 100644 index 0000000..4be68f6 --- /dev/null +++ b/DriverGeoFence-master.iml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/DriverGeoFence.iml b/DriverGeoFence.iml new file mode 100644 index 0000000..9fa91b8 --- /dev/null +++ b/DriverGeoFence.iml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Parse-Starter-Project-1.11.0.zip b/Parse-Starter-Project-1.11.0.zip new file mode 100644 index 0000000..57c2ed3 Binary files /dev/null and b/Parse-Starter-Project-1.11.0.zip differ diff --git a/ParseStarterProject/.idea/.name b/ParseStarterProject/.idea/.name new file mode 100644 index 0000000..8f78c90 --- /dev/null +++ b/ParseStarterProject/.idea/.name @@ -0,0 +1 @@ +ParseStarterProject \ No newline at end of file diff --git a/ParseStarterProject/.idea/compiler.xml b/ParseStarterProject/.idea/compiler.xml new file mode 100644 index 0000000..96cc43e --- /dev/null +++ b/ParseStarterProject/.idea/compiler.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ParseStarterProject/.idea/copyright/profiles_settings.xml b/ParseStarterProject/.idea/copyright/profiles_settings.xml new file mode 100644 index 0000000..e7bedf3 --- /dev/null +++ b/ParseStarterProject/.idea/copyright/profiles_settings.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/ParseStarterProject/.idea/gradle.xml b/ParseStarterProject/.idea/gradle.xml new file mode 100644 index 0000000..a9bb903 --- /dev/null +++ b/ParseStarterProject/.idea/gradle.xml @@ -0,0 +1,13 @@ + + + + + + \ No newline at end of file diff --git a/ParseStarterProject/.idea/misc.xml b/ParseStarterProject/.idea/misc.xml new file mode 100644 index 0000000..6eabdcd --- /dev/null +++ b/ParseStarterProject/.idea/misc.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ParseStarterProject/.idea/modules.xml b/ParseStarterProject/.idea/modules.xml new file mode 100644 index 0000000..82fcbfe --- /dev/null +++ b/ParseStarterProject/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/ParseStarterProject/.idea/runConfigurations.xml b/ParseStarterProject/.idea/runConfigurations.xml new file mode 100644 index 0000000..7f68460 --- /dev/null +++ b/ParseStarterProject/.idea/runConfigurations.xml @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/ParseStarterProject/.idea/vcs.xml b/ParseStarterProject/.idea/vcs.xml new file mode 100644 index 0000000..6564d52 --- /dev/null +++ b/ParseStarterProject/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/ParseStarterProject/.idea/workspace.xml b/ParseStarterProject/.idea/workspace.xml new file mode 100644 index 0000000..15fc5aa --- /dev/null +++ b/ParseStarterProject/.idea/workspace.xml @@ -0,0 +1,218 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1449354955705 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ParseStarterProject/ParseStarterProject.iml b/ParseStarterProject/ParseStarterProject.iml new file mode 100644 index 0000000..48cfef7 --- /dev/null +++ b/ParseStarterProject/ParseStarterProject.iml @@ -0,0 +1,99 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ParseStarterProject/build.gradle b/ParseStarterProject/build.gradle new file mode 100644 index 0000000..2b49abd --- /dev/null +++ b/ParseStarterProject/build.gradle @@ -0,0 +1,48 @@ +apply plugin: 'com.android.application' +apply plugin: 'com.parse' + +buildscript { + repositories { + mavenCentral() + maven { url 'https://maven.parse.com/repo' } + } + dependencies { + classpath 'com.parse.tools:gradle:1.+' + } +} + +android { + compileSdkVersion rootProject.ext.compileSdkVersion + buildToolsVersion rootProject.ext.buildToolsVersion + + defaultConfig { + applicationId "com.parse.starter" + minSdkVersion rootProject.ext.minSdkVersion + targetSdkVersion rootProject.ext.targetSdkVersion + versionCode 1 + versionName "1.0" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } +} + +dependencies { + compile 'com.android.support:appcompat-v7:22.2.0' + + compile 'com.parse.bolts:bolts-tasks:1.3.0' + compile 'com.parse:parse-android:1.11.0' +} + +/* Uncomment if you enable ProGuard and you want to automatically upload symbols on build. +parse { + applicationId "YOUR_APPLICATION_ID" + masterKey "YOUR_MASTER_KEY" + + // Make symbol upload automatic. Otherwise, use e.g. ../gradlew parseUploadSymbolsDebug; + uploadSymbols true +} +*/ diff --git a/ParseStarterProject/gradle/wrapper/gradle-wrapper.jar b/ParseStarterProject/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..05ef575 Binary files /dev/null and b/ParseStarterProject/gradle/wrapper/gradle-wrapper.jar differ diff --git a/ParseStarterProject/gradle/wrapper/gradle-wrapper.properties b/ParseStarterProject/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..f23df6e --- /dev/null +++ b/ParseStarterProject/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Wed Oct 21 11:34:03 PDT 2015 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-2.8-all.zip diff --git a/ParseStarterProject/gradlew b/ParseStarterProject/gradlew new file mode 100644 index 0000000..9d82f78 --- /dev/null +++ b/ParseStarterProject/gradlew @@ -0,0 +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 "$@" diff --git a/ParseStarterProject/gradlew.bat b/ParseStarterProject/gradlew.bat new file mode 100644 index 0000000..8a0b282 --- /dev/null +++ b/ParseStarterProject/gradlew.bat @@ -0,0 +1,90 @@ +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS= + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windowz variants + +if not "%OS%" == "Windows_NT" goto win9xME_args +if "%@eval[2+2]" == "4" goto 4NT_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* +goto execute + +:4NT_args +@rem Get arguments from the 4NT Shell from JP Software +set CMD_LINE_ARGS=%$ + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/ParseStarterProject/local.properties b/ParseStarterProject/local.properties new file mode 100644 index 0000000..6b8b85f --- /dev/null +++ b/ParseStarterProject/local.properties @@ -0,0 +1,11 @@ +## 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. +#Sun Dec 06 04:05:54 IST 2015 +sdk.dir=C\:\\Users\\dell-15\\AppData\\Local\\Android\\sdk diff --git a/ParseStarterProject/proguard-rules.pro b/ParseStarterProject/proguard-rules.pro new file mode 100644 index 0000000..fcd0a5d --- /dev/null +++ b/ParseStarterProject/proguard-rules.pro @@ -0,0 +1,29 @@ +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in /usr/local/opt/android-sdk/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the proguardFiles +# directive in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Keep source file names, line numbers, and Parse class/method names for easier debugging +-keepattributes SourceFile,LineNumberTable +-keepnames class com.parse.** { *; } + +# Required for Parse +-keepattributes *Annotation* +-keepattributes Signature +-dontwarn android.net.SSLCertificateSocketFactory +-dontwarn android.app.Notification +-dontwarn com.squareup.** +-dontwarn okio.** diff --git a/ParseStarterProject/src/main/AndroidManifest.xml b/ParseStarterProject/src/main/AndroidManifest.xml new file mode 100644 index 0000000..0ddb9ae --- /dev/null +++ b/ParseStarterProject/src/main/AndroidManifest.xml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/ParseStarterProject/src/main/java/com/parse/starter/MainActivity.java b/ParseStarterProject/src/main/java/com/parse/starter/MainActivity.java new file mode 100644 index 0000000..c3d3d2e --- /dev/null +++ b/ParseStarterProject/src/main/java/com/parse/starter/MainActivity.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2015-present, Parse, LLC. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ +package com.parse.starter; + +import android.os.Bundle; +import android.support.v7.app.ActionBarActivity; +import android.view.Menu; +import android.view.MenuItem; + +import com.parse.ParseAnalytics; + + +public class MainActivity extends ActionBarActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + + ParseAnalytics.trackAppOpenedInBackground(getIntent()); + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + // Inflate the menu; this adds items to the action bar if it is present. + getMenuInflater().inflate(R.menu.menu_main, menu); + return true; + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + // Handle action bar item clicks here. The action bar will + // automatically handle clicks on the Home/Up button, so long + // as you specify a parent activity in AndroidManifest.xml. + int id = item.getItemId(); + + //noinspection SimplifiableIfStatement + if (id == R.id.action_settings) { + return true; + } + + return super.onOptionsItemSelected(item); + } +} diff --git a/ParseStarterProject/src/main/java/com/parse/starter/StarterApplication.java b/ParseStarterProject/src/main/java/com/parse/starter/StarterApplication.java new file mode 100644 index 0000000..cc4170e --- /dev/null +++ b/ParseStarterProject/src/main/java/com/parse/starter/StarterApplication.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2015-present, Parse, LLC. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ +package com.parse.starter; + +import android.app.Application; + +import com.parse.Parse; +import com.parse.ParseACL; +import com.parse.ParseUser; + + +public class StarterApplication extends Application { + + @Override + public void onCreate() { + super.onCreate(); + + // Enable Local Datastore. + Parse.enableLocalDatastore(this); + + // Add your initialization code here + Parse.initialize(this); + + ParseUser.enableAutomaticUser(); + ParseACL defaultACL = new ParseACL(); + // Optionally enable public read access. + // defaultACL.setPublicReadAccess(true); + ParseACL.setDefaultACL(defaultACL, true); + } +} diff --git a/ParseStarterProject/src/main/res/layout/activity_main.xml b/ParseStarterProject/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..5985da7 --- /dev/null +++ b/ParseStarterProject/src/main/res/layout/activity_main.xml @@ -0,0 +1,24 @@ + + + + + + diff --git a/ParseStarterProject/src/main/res/menu/menu_main.xml b/ParseStarterProject/src/main/res/menu/menu_main.xml new file mode 100644 index 0000000..3ffc1aa --- /dev/null +++ b/ParseStarterProject/src/main/res/menu/menu_main.xml @@ -0,0 +1,17 @@ + + + + diff --git a/ParseStarterProject/src/main/res/mipmap-hdpi/ic_launcher.png b/ParseStarterProject/src/main/res/mipmap-hdpi/ic_launcher.png new file mode 100644 index 0000000..cde69bc Binary files /dev/null and b/ParseStarterProject/src/main/res/mipmap-hdpi/ic_launcher.png differ diff --git a/ParseStarterProject/src/main/res/mipmap-mdpi/ic_launcher.png b/ParseStarterProject/src/main/res/mipmap-mdpi/ic_launcher.png new file mode 100644 index 0000000..c133a0c Binary files /dev/null and b/ParseStarterProject/src/main/res/mipmap-mdpi/ic_launcher.png differ diff --git a/ParseStarterProject/src/main/res/mipmap-xhdpi/ic_launcher.png b/ParseStarterProject/src/main/res/mipmap-xhdpi/ic_launcher.png new file mode 100644 index 0000000..bfa42f0 Binary files /dev/null and b/ParseStarterProject/src/main/res/mipmap-xhdpi/ic_launcher.png differ diff --git a/ParseStarterProject/src/main/res/mipmap-xxhdpi/ic_launcher.png b/ParseStarterProject/src/main/res/mipmap-xxhdpi/ic_launcher.png new file mode 100644 index 0000000..324e72c Binary files /dev/null and b/ParseStarterProject/src/main/res/mipmap-xxhdpi/ic_launcher.png differ diff --git a/ParseStarterProject/src/main/res/values-w820dp/dimens.xml b/ParseStarterProject/src/main/res/values-w820dp/dimens.xml new file mode 100644 index 0000000..2594198 --- /dev/null +++ b/ParseStarterProject/src/main/res/values-w820dp/dimens.xml @@ -0,0 +1,14 @@ + + + + 64dp + diff --git a/ParseStarterProject/src/main/res/values/dimens.xml b/ParseStarterProject/src/main/res/values/dimens.xml new file mode 100644 index 0000000..3f29312 --- /dev/null +++ b/ParseStarterProject/src/main/res/values/dimens.xml @@ -0,0 +1,13 @@ + + + + 16dp + 16dp + diff --git a/ParseStarterProject/src/main/res/values/strings.xml b/ParseStarterProject/src/main/res/values/strings.xml new file mode 100644 index 0000000..5c0bf13 --- /dev/null +++ b/ParseStarterProject/src/main/res/values/strings.xml @@ -0,0 +1,18 @@ + + + + YOUR_APPLICATION_ID + YOUR_CLIENT_KEY + + Parse Starter Project + + Hello World! + Settings + diff --git a/ParseStarterProject/src/main/res/values/styles.xml b/ParseStarterProject/src/main/res/values/styles.xml new file mode 100644 index 0000000..7577122 --- /dev/null +++ b/ParseStarterProject/src/main/res/values/styles.xml @@ -0,0 +1,16 @@ + + + + + + + diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/app/app.iml b/app/app.iml new file mode 100644 index 0000000..d9b5a0f --- /dev/null +++ b/app/app.iml @@ -0,0 +1,150 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 0000000..15d9a7b --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,33 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 23 + buildToolsVersion "23.0.2" + + defaultConfig { + applicationId "com.geofence.drivergeofence" + minSdkVersion 17 + targetSdkVersion 23 + versionCode 1 + versionName "1.0" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } +} + +dependencies { + compile fileTree(include: ['*.jar'], dir: 'libs') + compile 'com.android.support:appcompat-v7:23.1.1' + compile 'com.android.support:design:23.1.1' + compile 'com.google.android.gms:play-services:8.3.0' + compile 'com.google.android.gms:play-services-ads:8.3.0' + compile 'com.google.android.gms:play-services-identity:8.3.0' + compile 'com.google.android.gms:play-services-gcm:8.3.0' + compile 'com.android.support:support-v4:23.1.1' + compile 'com.parse.bolts:bolts-android:1.+' + compile 'com.parse:parse-android:1.+' +} diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..d169105 --- /dev/null +++ b/app/proguard-rules.pro @@ -0,0 +1,17 @@ +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in C:\Program Files (x86)\Android\android-sdk/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the proguardFiles +# directive in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} diff --git a/app/src/androidTest/java/com/geofence/drivergeofence/ApplicationTest.java b/app/src/androidTest/java/com/geofence/drivergeofence/ApplicationTest.java new file mode 100644 index 0000000..92e8da8 --- /dev/null +++ b/app/src/androidTest/java/com/geofence/drivergeofence/ApplicationTest.java @@ -0,0 +1,13 @@ +package com.geofence.drivergeofence; + +import android.app.Application; +import android.test.ApplicationTestCase; + +/** + * Testing Fundamentals + */ +public class ApplicationTest extends ApplicationTestCase { + public ApplicationTest() { + super(Application.class); + } +} \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..05db657 --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,73 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/java/com/geofence/drivergeofence/AutoComplete.java b/app/src/main/java/com/geofence/drivergeofence/AutoComplete.java new file mode 100644 index 0000000..38adace --- /dev/null +++ b/app/src/main/java/com/geofence/drivergeofence/AutoComplete.java @@ -0,0 +1,212 @@ +/* + * Copyright (C) 2015 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.geofence.drivergeofence; + +import android.content.res.Resources; +import android.net.Uri; +import android.os.Bundle; +import android.text.Html; +import android.text.Spanned; +import android.view.View; +import android.widget.AdapterView; +import android.widget.AutoCompleteTextView; +import android.widget.Button; +import android.widget.TextView; +import android.widget.Toast; + +import com.geofence.drivergeofence.logger.Log; +import com.google.android.gms.common.ConnectionResult; +import com.google.android.gms.common.api.GoogleApiClient; +import com.google.android.gms.common.api.PendingResult; +import com.google.android.gms.common.api.ResultCallback; +import com.google.android.gms.location.places.AutocompletePrediction; +import com.google.android.gms.location.places.Place; +import com.google.android.gms.location.places.PlaceBuffer; +import com.google.android.gms.location.places.Places; +import com.google.android.gms.maps.model.LatLng; +import com.google.android.gms.maps.model.LatLngBounds; + +public class AutoComplete extends SampleActivityBase + implements GoogleApiClient.OnConnectionFailedListener { + + /** + * GoogleApiClient wraps our service connection to Google Play Services and provides access + * to the user's sign in state as well as the Google's APIs. + */ + protected GoogleApiClient mGoogleApiClient; + + private PlaceAutocompleteAdapter mAdapter; + + private AutoCompleteTextView mAutocompleteView; + private AutoCompleteTextView mAutocompleteView2; + private TextView mPlaceDetailsText; + + private TextView mPlaceDetailsAttribution; + + private static final LatLngBounds BOUNDS_GREATER_SYDNEY = new LatLngBounds( + new LatLng(-34.041458, 150.790100), new LatLng(-33.682247, 151.383362)); + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + + mGoogleApiClient = new GoogleApiClient.Builder(this) + .enableAutoManage(this, 0 /* clientId */, this) + .addApi(Places.GEO_DATA_API) + .addApi(Places.PLACE_DETECTION_API) + .build(); + + setContentView(R.layout.search); + + // Retrieve the AutoCompleteTextView that will display Place suggestions. + mAutocompleteView = (AutoCompleteTextView) + findViewById(R.id.autocomplete_places); + + // Register a listener that receives callbacks when a suggestion has been selected + mAutocompleteView.setOnItemClickListener(mAutocompleteClickListener); + mAutocompleteView2 = (AutoCompleteTextView) + findViewById(R.id.autocomplete_places2); + + // Register a listener that receives callbacks when a suggestion has been selected + mAutocompleteView2.setOnItemClickListener(mAutocompleteClickListener); + // Retrieve the TextViews that will display details and attributions of the selected place. + mPlaceDetailsText = (TextView) findViewById(R.id.place_details); + mPlaceDetailsAttribution = (TextView) findViewById(R.id.place_attribution); + + // Set up the adapter that will retrieve suggestions from the Places Geo Data API that cover + // the entire world. + mAdapter = new PlaceAutocompleteAdapter(this, mGoogleApiClient, BOUNDS_GREATER_SYDNEY, + null); + mAutocompleteView.setAdapter(mAdapter); + mAutocompleteView2.setAdapter(mAdapter); + + // Set up the 'clear text' button that clears the text in the autocomplete view + Button clearButton = (Button) findViewById(R.id.button_clear); + clearButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + mAutocompleteView.setText(""); + mAutocompleteView2.setText(""); + } + }); + } + + /** + * Listener that handles selections from suggestions from the AutoCompleteTextView that + * displays Place suggestions. + * Gets the place id of the selected item and issues a request to the Places Geo Data API + * to retrieve more details about the place. + * + * @see com.google.android.gms.location.places.GeoDataApi#getPlaceById(com.google.android.gms.common.api.GoogleApiClient, + * String...) + */ + private AdapterView.OnItemClickListener mAutocompleteClickListener + = new AdapterView.OnItemClickListener() { + @Override + public void onItemClick(AdapterView parent, View view, int position, long id) { + /* + Retrieve the place ID of the selected item from the Adapter. + The adapter stores each Place suggestion in a AutocompletePrediction from which we + read the place ID and title. + */ + final AutocompletePrediction item = mAdapter.getItem(position); + final String placeId = item.getPlaceId(); + final CharSequence primaryText = item.getPrimaryText(null); + + Log.i(TAG1, "Autocomplete item selected: " + primaryText); + + /* + Issue a request to th/e Places Geo Data API to retrieve a Place object with additional + details about the place. + */ + PendingResult placeResult = Places.GeoDataApi + .getPlaceById(mGoogleApiClient, placeId); + placeResult.setResultCallback(mUpdatePlaceDetailsCallback); + + Toast.makeText(getApplicationContext(), "Clicked: " + primaryText, + Toast.LENGTH_SHORT).show(); + Log.i(TAG1, "Called getPlaceById to get Place details for " + placeId); + } + }; + + /** + * Callback for results from a Places Geo Data API query that shows the first place result in + * the details view on screen. + */ + private ResultCallback mUpdatePlaceDetailsCallback + = new ResultCallback() { + @Override + public void onResult(PlaceBuffer places) { + if (!places.getStatus().isSuccess()) { + // Request did not complete successfully + Log.e(TAG1, "Place query did not complete. Error: " + places.getStatus().toString()); + places.release(); + return; + } + // Get the Place object from the buffer. + final Place place = places.get(0); + + // Format details of the place for display and show it in a TextView. + mPlaceDetailsText.setText(formatPlaceDetails(getResources(), place.getName(), + place.getId(), place.getAddress(), place.getPhoneNumber(), + place.getWebsiteUri())); + + // Display the third party attributions if set. + final CharSequence thirdPartyAttribution = places.getAttributions(); + if (thirdPartyAttribution == null) { + mPlaceDetailsAttribution.setVisibility(View.GONE); + } else { + mPlaceDetailsAttribution.setVisibility(View.VISIBLE); + mPlaceDetailsAttribution.setText(Html.fromHtml(thirdPartyAttribution.toString())); + } + + Log.i(TAG1, "Place details received: " + place.getName()); + + places.release(); + } + }; + + private static Spanned formatPlaceDetails(Resources res, CharSequence name, String id, + CharSequence address, CharSequence phoneNumber, Uri websiteUri) { + Log.e(TAG1, res.getString(R.string.place_details, name, id, address, phoneNumber, + websiteUri)); + return Html.fromHtml(res.getString(R.string.place_details, name, id, address, phoneNumber, + websiteUri)); + + } + + /** + * Called when the Activity could not connect to Google Play services and the auto manager + * could resolve the error automatically. + * In this case the API is not available and notify the user. + * + * @param connectionResult can be inspected to determine the cause of the failure + */ + @Override + public void onConnectionFailed(ConnectionResult connectionResult) { + + Log.e(TAG1, "onConnectionFailed: ConnectionResult.getErrorCode() = " + + connectionResult.getErrorCode()); + + // TODO(Developer): Check error code and notify the user of error state and resolution. + Toast.makeText(this, + "Could not connect to Google API Client: Error " + connectionResult.getErrorCode(), + Toast.LENGTH_SHORT).show(); + } + +} diff --git a/app/src/main/java/com/geofence/drivergeofence/DriverMapsActivity.java b/app/src/main/java/com/geofence/drivergeofence/DriverMapsActivity.java new file mode 100644 index 0000000..d514d37 --- /dev/null +++ b/app/src/main/java/com/geofence/drivergeofence/DriverMapsActivity.java @@ -0,0 +1,364 @@ +package com.geofence.drivergeofence; + +import android.Manifest; +import android.content.Intent; +import android.content.pm.PackageManager; +import android.graphics.Color; +import android.location.Criteria; +import android.location.Location; +import android.location.LocationManager; +import android.os.Bundle; +import android.support.v4.app.ActivityCompat; +import android.support.v4.app.FragmentActivity; +import android.support.v4.content.ContextCompat; +import android.util.Log; +import android.widget.TextView; +import android.widget.Toast; + +import com.geofence.drivergeofence.R; +import com.google.android.gms.common.api.GoogleApiClient; +import com.google.android.gms.common.ConnectionResult; +import com.google.android.gms.common.api.GoogleApiClient; +import com.google.android.gms.location.LocationListener; +import com.google.android.gms.location.LocationRequest; +import com.google.android.gms.location.LocationServices; +import com.google.android.gms.maps.CameraUpdateFactory; +import com.google.android.gms.maps.GoogleMap; +import com.google.android.gms.maps.MapView; +import com.google.android.gms.maps.OnMapReadyCallback; +import com.google.android.gms.maps.SupportMapFragment; +import com.google.android.gms.maps.UiSettings; +import com.google.android.gms.maps.model.BitmapDescriptorFactory; +import com.google.android.gms.maps.model.LatLng; +import com.google.android.gms.maps.model.Marker; +import com.google.android.gms.maps.model.MarkerOptions; +import com.google.android.gms.maps.model.PolygonOptions; +import com.google.android.gms.maps.model.PolylineOptions; +import com.google.android.gms.vision.barcode.Barcode; +import com.parse.GetCallback; +import com.parse.Parse; +import com.parse.ParseGeoPoint; +import com.parse.ParseInstallation; +import com.parse.ParseObject; +import com.parse.ParsePush; +import com.parse.ParseQuery; + +import java.util.ArrayList; +import java.util.Collections; + +import static com.google.android.gms.maps.UiSettings.*; + +/** + * Created by pc on 12/3/2015. + */ +public class DriverMapsActivity extends FragmentActivity implements OnMapReadyCallback,LocationListener, GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener { + + private GoogleMap mMap; + MapView mMapView; + Marker startPerc; + GoogleApiClient mGoogleApiClient; + private LocationManager locationManager; + PolylineOptions lineOpt; + PolygonOptions polyOpt; + String src, dest; + LocationRequest mLocationRequest; + LatLng prev; + ArrayList pathList = new ArrayList(); + ArrayList leftFenceList = new ArrayList(); + ArrayList rightFenceList = new ArrayList(); +ArrayList path=new ArrayList<>(); + ArrayList left=new ArrayList<>(); + ArrayList right=new ArrayList<>(); + private Location mLastLocation; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_maps); + Intent i = getIntent(); + + Bundle b =i.getBundleExtra("pathBundle"); + Bundle bPt = getIntent().getExtras(); + +// if(b!=null) { +// String jsondata=b.getString("com.parse.Data"); +// +// Log.d("json:", jsondata); +// } + if (b != null) { + // list1 = (ArrayList) b.getStringArrayList("list"); + pathList = b.getParcelableArrayList("pathLatLng"); + leftFenceList = b.getParcelableArrayList("leftFenceLatLng"); + rightFenceList = b.getParcelableArrayList("rightFenceLatLng"); + + src = bPt.getString("Source"); + dest = bPt.getString("Destination"); + Log.d("pathlist", pathList.toString()); + } + + initializemap(); + buildGoogleApiClient(); + createLocationRequest(); + } +private ArrayList getvertexlist(){ + ArrayList vertices=new ArrayList<>(); +// for(LatLng ll:pathList){ +// double lat = (ll.latitude * 1E6); +// double lng = (ll.longitude * 1E6); +// Barcode.GeoPoint point = new Barcode.GeoPoint(1,lat,lng); +// path.add(point); +// +// } +// for(LatLng ll:leftFenceList){ +// double lat = (ll.latitude * 1E6); +// double lng = (ll.longitude * 1E6); +// Barcode.GeoPoint point = new Barcode.GeoPoint(1,lat,lng); +// left.add(point); +// +// } + vertices.addAll(leftFenceList); +// for(LatLng ll:rightFenceList){ +// double lat = (ll.latitude * 1E6); +// double lng = (ll.longitude * 1E6); +// Barcode.GeoPoint point = new Barcode.GeoPoint(1,lat,lng); +// right.add(point); +// +// } + //Collections.reverse(right); + vertices.addAll(rightFenceList); + + return vertices; +} + private void initializemap() { + setUpMapIfNeeded(); + + if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) + == PackageManager.PERMISSION_GRANTED) { + mMap.setMyLocationEnabled(true); + + } + +// locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); +// +// // Create a criteria object to retrieve provider +// Criteria criteria = new Criteria(); +// +// // Get the name of the best provider +// String provider = locationManager.getBestProvider(criteria, true); +// +// // Get Current Location +// Location myLocation = locationManager.getLastKnownLocation(LocationManager.PASSIVE_PROVIDER); +// +// //set map type +// mMap.setMapType(GoogleMap.MAP_TYPE_NORMAL); +// +// // Get latitude of the current location +// double latitude = myLocation.getLatitude(); +// +// // Get longitude of the current location +// double longitude = myLocation.getLongitude(); +// +// // Create a LatLng object for the current location +// LatLng latLng = new LatLng(latitude, longitude); +// +// // Show the current location in Google Map +// mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng)); +// +// // Zoom in the Google Map +// mMap.animateCamera(CameraUpdateFactory.zoomTo(15)); +// mMap.addMarker(new MarkerOptions().position(new LatLng(latitude, longitude)).title("You are here!")); + + mMap.clear(); + mMap.addMarker(new MarkerOptions().position(pathList.get(0)).title("Start")); + mMap.addMarker(new MarkerOptions().position(pathList.get(pathList.size() - 1)).title("End")); + mMap.moveCamera(CameraUpdateFactory.newLatLng(pathList.get(0))); + mMap.animateCamera(CameraUpdateFactory.zoomTo(15)); + + lineOpt = new PolylineOptions(); + polyOpt = new PolygonOptions(); + + lineOpt.addAll(pathList); + lineOpt.width(10); + lineOpt.color(Color.RED); + + mMap.addPolyline(lineOpt); + + Collections.reverse(rightFenceList); + polyOpt.addAll(leftFenceList).strokeColor(Color.BLUE).strokeWidth(3); + polyOpt.addAll(rightFenceList).strokeColor(Color.BLUE).strokeWidth(3); + + mMap.addPolygon(polyOpt); + + } + + @Override + public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { + // if (requestCode == MY_LOCATION_REQUEST_CODE) { + if (permissions.length == 1 && + permissions[0] == Manifest.permission.ACCESS_FINE_LOCATION && + grantResults[0] == PackageManager.PERMISSION_GRANTED) { + mMap.setMyLocationEnabled(true); + Location mLastLocation = LocationServices.FusedLocationApi.getLastLocation( + mGoogleApiClient); + + onLocationChanged(mLastLocation); + } else { + // Permission was denied. Display an error message. + } + } + + protected synchronized void buildGoogleApiClient() { + mGoogleApiClient = new GoogleApiClient.Builder(this) + .addConnectionCallbacks(this) + .addOnConnectionFailedListener(this) + .addApi(LocationServices.API) + .build(); + } + + @Override + public void onMapReady(GoogleMap googleMap) { + mMap = googleMap; + } + + public void onLocationChanged(Location location) { + double latitude = location.getLatitude(); + double longitude = location.getLongitude(); + LatLng latLng = new LatLng(latitude, longitude); + // mMap.addMarker(new MarkerOptions().position(latLng)); +// mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng)); +// mMap.animateCamera(CameraUpdateFactory.zoomTo(15)); +// startPerc.setIcon(BitmapDescriptorFactory.fromResource(R.drawable.ic_launcher)); +// LatLng origin = new LatLng(3.214732, 101.747047); +// LatLng dest = new LatLng(3.214507, 101.749697); + //LatLng tmp= new LatLng(location.getLatitude(),location.getLongitude()); + if(prev!=null){ + //mMap. + } + prev=latLng; + + final ParseGeoPoint driverLoc=new ParseGeoPoint(location.getLatitude(),location.getLongitude()); + final LatLng driverloclatlng=new LatLng(location.getLatitude(),location.getLongitude()); +final ArrayList vertices=getvertexlist(); + + ParseQuery query2 = ParseQuery.getQuery("PathFence"); + query2.whereEqualTo("Source", src).whereEqualTo("Destination", dest); + query2.getFirstInBackground(new GetCallback() { + @Override + public void done(ParseObject objects, com.parse.ParseException e) { + if(objects != null){ + objects.put("DriverLocation", driverLoc); + objects.saveInBackground(); + //Toast.makeText(getApplication(),"sucessfully updated",Toast.LENGTH_LONG).show(); + boolean check=isPointInPolygon(driverloclatlng,vertices); + if(!check){ + Toast.makeText(getApplicationContext(),"Outside",Toast.LENGTH_SHORT).show(); + ParseInstallation.getCurrentInstallation().saveInBackground(); + ParsePush push = new ParsePush(); + //push.setQuery(pushQuery); // Set our Installation query + + push.setChannel("sendtoowner"); + push.setMessage("Driver is outside the fence"); + push.sendInBackground(); + } + else + { + Toast.makeText(getApplicationContext(),"Inside",Toast.LENGTH_SHORT).show(); + } + } else { + Log.d("score", "Error: " + e.getMessage()); + } + } + }); + + if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { + + return; + } + //locationManager.removeUpdates((android.location.LocationListener) this); + } + + private void setUpMapIfNeeded() { + // Do a null check to confirm that we have not already instantiated the map. + if (mMap == null) { + // Try to obtain the map from the SupportMapFragment. + mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)) + .getMap(); + // Check if we were successful in obtaining the map. +// if (mMap != null) { +// setUpMap(); +// } + } + } + + @Override + public void onConnected(Bundle bundle) { + mLastLocation = LocationServices.FusedLocationApi.getLastLocation( + mGoogleApiClient); + if (mLastLocation != null) { + Log.d("DriverLoc", String.valueOf(mLastLocation.getLatitude())); + Log.d("DriverLoc", String.valueOf(mLastLocation.getLongitude())); +// Toast.makeText(this, "Latitude:" + mLastLocation.getLatitude() + ", Longitude:" + mLastLocation.getLongitude(), Toast.LENGTH_LONG).show(); + + } + startLocationUpdates(); + } + protected void createLocationRequest() { + mLocationRequest = new LocationRequest(); + mLocationRequest.setInterval(10000); + mLocationRequest.setFastestInterval(5000); + mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); + } + protected void startLocationUpdates() { + LocationServices.FusedLocationApi.requestLocationUpdates( + mGoogleApiClient, mLocationRequest, this); + } + @Override + public void onConnectionSuspended(int i) { + + } + @Override + protected void onStart(){ + super.onStart(); + if(mGoogleApiClient!=null) + { + mGoogleApiClient.connect(); + } + } + @Override + public void onConnectionFailed(ConnectionResult connectionResult) { + + } + private boolean isPointInPolygon(LatLng tap, ArrayList vertices) { + int intersectCount = 0; + for(int j=0; jpY && bY>pY) || (aY pX; + } + +// private void setUpMap() { +// mMap.addMarker(new MarkerOptions().position(new LatLng(0, 0)).title("Marker")); +// } +} diff --git a/app/src/main/java/com/geofence/drivergeofence/MainActivity.java b/app/src/main/java/com/geofence/drivergeofence/MainActivity.java new file mode 100644 index 0000000..7333478 --- /dev/null +++ b/app/src/main/java/com/geofence/drivergeofence/MainActivity.java @@ -0,0 +1,158 @@ +package com.geofence.drivergeofence; + +import android.content.Intent; +import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; +import android.util.Log; +import android.view.Menu; +import android.view.MenuItem; +import android.view.View; +import android.widget.Button; +import android.widget.EditText; + +import com.google.android.gms.maps.model.LatLng; +import com.parse.FindCallback; +import com.parse.GetCallback; +import com.parse.Parse; +import com.parse.ParseException; +import com.parse.ParseGeoPoint; +import com.parse.ParseInstallation; +import com.parse.ParseObject; +import com.parse.ParsePush; +import com.parse.ParseQuery; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class MainActivity extends AppCompatActivity { + + Button routeBtn; + EditText src, dest; +// JSONArray retrObj; + List pathList = new ArrayList(); + List leftFenceList = new ArrayList(); + List rightFenceList = new ArrayList(); + + ArrayList leftFenceLatLng = new ArrayList(); + ArrayList rightFenceLatLng = new ArrayList(); + ArrayList pathLatLng = new ArrayList(); + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + src = (EditText)findViewById(R.id.src); + dest = (EditText)findViewById(R.id.dest); + routeBtn = (Button) findViewById(R.id.routeBtn); + ParseInstallation.getCurrentInstallation().saveInBackground(); + + ParsePush.subscribeInBackground("arpit"); + + Intent i = getIntent(); + + Bundle b =i.getExtras(); + //Bundle bPt = getIntent().getExtras(); + + if(b!=null) { + String jsondata=b.getString("com.parse.Data"); + if(jsondata!=null) { + Log.d("json:", jsondata.toString()); + src.setText(jsondata.toString()); + } + } + + ParseQuery query1 = ParseQuery.getQuery("PathFence").orderByDescending("updatedAt").setLimit(1); + query1.getFirstInBackground(new GetCallback() { + @Override + public void done(ParseObject objects, com.parse.ParseException e) { + src.setText(objects.get("Source").toString()); + dest.setText(objects.getString("Destination").toString()); + } + }); +// Log.d("Test", src.getText().toString()); +// Log.d("Test", dest.getText().toString()); + + routeBtn.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + + ParseQuery query1 = ParseQuery.getQuery("PathFence"); + query1.whereEqualTo("Source", src.getText().toString()).whereEqualTo("Destination", dest.getText().toString()); + query1.getFirstInBackground(new GetCallback() { + @Override + public void done(ParseObject objects, com.parse.ParseException e) { + pathList = objects.getList("ParsePoints"); + leftFenceList = objects.getList("ParseLeftPoints"); + rightFenceList = objects.getList("ParseRightPoints"); + Log.d("PathSize", String.valueOf(pathList.size())); + Log.d("PathSize", String.valueOf(leftFenceList.size())); + Log.d("PathSize", String.valueOf(rightFenceList.size())); + + ParseGeoPoint pg = pathList.get(0); + Log.d("GeoPoint", String.valueOf(pg.getLatitude())); + Log.d("GeoPoint", String.valueOf(pg.getLongitude())); + + for (int i = 0; i < pathList.size(); i++) { + ParseGeoPoint pgp = pathList.get(i); +// Log.d("GeoPoint", pgp.toString()); + pathLatLng.add(new LatLng(pgp.getLatitude(), pgp.getLongitude())); + + pgp = leftFenceList.get(i); + leftFenceLatLng.add(new LatLng(pgp.getLatitude(), pgp.getLongitude())); + + pgp = rightFenceList.get(i); + rightFenceLatLng.add(new LatLng(pgp.getLatitude(), pgp.getLongitude())); + } + + Log.d("PathLng", pathLatLng.toString()); +// Log.d("PtList", pathLatLng.toString()); + Intent intent = new Intent(MainActivity.this, DriverMapsActivity.class); + + Bundle bundle = new Bundle(); + bundle.putParcelableArrayList("pathLatLng", pathLatLng); + bundle.putParcelableArrayList("leftFenceLatLng", leftFenceLatLng); + bundle.putParcelableArrayList("rightFenceLatLng", rightFenceLatLng); + + + intent.putExtra("pathBundle", bundle); + intent.putExtra("Source", src.getText().toString()); + intent.putExtra("Destination", dest.getText().toString()); + startActivity(intent); + } + + }); + + //Log.d("PathLng2", pathLatLng.toString()); + + } + }); + + +// for (int i=0; i + * Note that this adapter requires a valid {@link com.google.android.gms.common.api.GoogleApiClient}. + * The API client must be maintained in the encapsulating Activity, including all lifecycle and + * connection states. The API client must be connected with the {@link Places#GEO_DATA_API} API. + */ +public class PlaceAutocompleteAdapter + extends ArrayAdapter implements Filterable { + + private static final String TAG = "PlaceAutocompleteAdapter"; + private static final CharacterStyle STYLE_BOLD = new StyleSpan(Typeface.BOLD); + /** + * Current results returned by this adapter. + */ + private ArrayList mResultList; + + /** + * Handles autocomplete requests. + */ + private GoogleApiClient mGoogleApiClient; + + /** + * The bounds used for Places Geo Data autocomplete API requests. + */ + private LatLngBounds mBounds; + + /** + * The autocomplete filter used to restrict queries to a specific set of place types. + */ + private AutocompleteFilter mPlaceFilter; + + /** + * Initializes with a resource for text rows and autocomplete query bounds. + * + * @see ArrayAdapter#ArrayAdapter(Context, int) + */ + public PlaceAutocompleteAdapter(Context context, GoogleApiClient googleApiClient, + LatLngBounds bounds, AutocompleteFilter filter) { + super(context, android.R.layout.simple_expandable_list_item_2, android.R.id.text1); + mGoogleApiClient = googleApiClient; + mBounds = bounds; + mPlaceFilter = null; + } + + /** + * Sets the bounds for all subsequent queries. + */ + public void setBounds(LatLngBounds bounds) { + mBounds = bounds; + } + + /** + * Returns the number of results received in the last autocomplete query. + */ + @Override + public int getCount() { + return mResultList.size(); + } + + /** + * Returns an item from the last autocomplete query. + */ + @Override + public AutocompletePrediction getItem(int position) { + return mResultList.get(position); + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + View row = super.getView(position, convertView, parent); + + // Sets the primary and secondary text for a row. + // Note that getPrimaryText() and getSecondaryText() return a CharSequence that may contain + // styling based on the given CharacterStyle. + + AutocompletePrediction item = getItem(position); + + TextView textView1 = (TextView) row.findViewById(android.R.id.text1); + TextView textView2 = (TextView) row.findViewById(android.R.id.text2); + textView1.setText(item.getPrimaryText(STYLE_BOLD)); + textView2.setText(item.getSecondaryText(STYLE_BOLD)); + + return row; + } + + /** + * Returns the filter for the current set of autocomplete results. + */ + @Override + public Filter getFilter() { + return new Filter() { + @Override + protected FilterResults performFiltering(CharSequence constraint) { + FilterResults results = new FilterResults(); + // Skip the autocomplete query if no constraints are given. + if (constraint != null) { + // Query the autocomplete API for the (constraint) MainActivity string. + mResultList = getAutocomplete(constraint); + if (mResultList != null) { + // The API successfully returned results. + results.values = mResultList; + results.count = mResultList.size(); + } + } + return results; + } + + @Override + protected void publishResults(CharSequence constraint, FilterResults results) { + if (results != null && results.count > 0) { + // The API returned at least one result, update the data. + notifyDataSetChanged(); + } else { + // The API did not return any results, invalidate the data set. + notifyDataSetInvalidated(); + } + } + + @Override + public CharSequence convertResultToString(Object resultValue) { + // Override this method to display a readable result in the AutocompleteTextView + // when clicked. + if (resultValue instanceof AutocompletePrediction) { + return ((AutocompletePrediction) resultValue).getFullText(null); + } else { + return super.convertResultToString(resultValue); + } + } + }; + } + + /** + * Submits an autocomplete query to the Places Geo Data Autocomplete API. + * Results are returned as frozen AutocompletePrediction objects, ready to be cached. + * objects to store the Place ID and description that the API returns. + * Returns an empty list if no results were found. + * Returns null if the API client is not available or the query did not complete + * successfully. + * This method MUST be called off the main UI thread, as it will block until data is returned + * from the API, which may include a network request. + * + * @param constraint Autocomplete query string + * @return Results from the autocomplete API or null if the query was not successful. + * @see Places#GEO_DATA_API#getAutocomplete(CharSequence) + * @see AutocompletePrediction#freeze() + */ + private ArrayList getAutocomplete(CharSequence constraint) { + if (mGoogleApiClient.isConnected()) { + Log.i(TAG, "Starting autocomplete query for: " + constraint); + + // Submit the query to the autocomplete API and retrieve a PendingResult that will + // contain the results when the query completes. + PendingResult results = + Places.GeoDataApi + .getAutocompletePredictions(mGoogleApiClient, constraint.toString(), + mBounds, mPlaceFilter); + + // This method should have been called off the main UI thread. Block and wait for at most 60s + // for a result from the API. + AutocompletePredictionBuffer autocompletePredictions = results + .await(60, TimeUnit.SECONDS); + + // Confirm that the query completed successfully, otherwise return null + final Status status = autocompletePredictions.getStatus(); + if (!status.isSuccess()) { + Toast.makeText(getContext(), "Error contacting API: " + status.toString(), + Toast.LENGTH_SHORT).show(); + Log.e(TAG, "Error getting autocomplete prediction API call: " + status.toString()); + autocompletePredictions.release(); + return null; + } + + Log.i(TAG, "Query completed. Received " + autocompletePredictions.getCount() + + " predictions."); + + // Freeze the results immutable representation that can be stored safely. + return DataBufferUtils.freezeAndClose(autocompletePredictions); + } + Log.e(TAG, "Google API client is not connected for autocomplete query."); + return null; + } + + +} diff --git a/app/src/main/java/com/geofence/drivergeofence/SampleActivityBase.java b/app/src/main/java/com/geofence/drivergeofence/SampleActivityBase.java new file mode 100644 index 0000000..8a06c91 --- /dev/null +++ b/app/src/main/java/com/geofence/drivergeofence/SampleActivityBase.java @@ -0,0 +1,52 @@ +/* +* Copyright 2013 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +package com.geofence.drivergeofence; + +import android.os.Bundle; +import android.support.v4.app.FragmentActivity; + +import com.geofence.drivergeofence.logger.Log; +import com.geofence.drivergeofence.logger.LogWrapper; + +/** + * Base launcher activity, to handle most of the common plumbing for samples. + */ +public class SampleActivityBase extends FragmentActivity { + + public static final String TAG1 = "SampleActivityBase"; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + } + + @Override + protected void onStart() { + super.onStart(); + initializeLogging(); + } + + /** Set up targets to receive log data */ + public void initializeLogging() { + // Using Log, front-end to the logging chain, emulates android.util.log method signatures. + // Wraps Android's native log framework + LogWrapper logWrapper = new LogWrapper(); + Log.setLogNode(logWrapper); + + Log.i(TAG1, "Ready"); + } +} diff --git a/app/src/main/java/com/geofence/drivergeofence/logger/Log.java b/app/src/main/java/com/geofence/drivergeofence/logger/Log.java new file mode 100644 index 0000000..4adbbd5 --- /dev/null +++ b/app/src/main/java/com/geofence/drivergeofence/logger/Log.java @@ -0,0 +1,236 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.geofence.drivergeofence.logger; + +/** + * Helper class for a list (or tree) of LoggerNodes. + * + *

When this is set as the head of the list, + * an instance of it can function as a drop-in replacement for {@link android.util.Log}. + * Most of the methods in this class server only to map a method call in Log to its equivalent + * in LogNode.

+ */ +public class Log { + // Grabbing the native values from Android's native logging facilities, + // to make for easy migration and interop. + public static final int NONE = -1; + public static final int VERBOSE = android.util.Log.VERBOSE; + public static final int DEBUG = android.util.Log.DEBUG; + public static final int INFO = android.util.Log.INFO; + public static final int WARN = android.util.Log.WARN; + public static final int ERROR = android.util.Log.ERROR; + public static final int ASSERT = android.util.Log.ASSERT; + + // Stores the beginning of the LogNode topology. + private static LogNode mLogNode; + + /** + * Returns the next LogNode in the linked list. + */ + public static LogNode getLogNode() { + return mLogNode; + } + + /** + * Sets the LogNode data will be sent to. + */ + public static void setLogNode(LogNode node) { + mLogNode = node; + } + + /** + * Instructs the LogNode to print the log data provided. Other LogNodes can + * be chained to the end of the LogNode as desired. + * + * @param priority Log level of the data being logged. Verbose, Error, etc. + * @param tag Tag for for the log data. Can be used to organize log statements. + * @param msg The actual message to be logged. + * @param tr If an exception was thrown, this can be sent along for the logging facilities + * to extract and print useful information. + */ + public static void println(int priority, String tag, String msg, Throwable tr) { + if (mLogNode != null) { + mLogNode.println(priority, tag, msg, tr); + } + } + + /** + * Instructs the LogNode to print the log data provided. Other LogNodes can + * be chained to the end of the LogNode as desired. + * + * @param priority Log level of the data being logged. Verbose, Error, etc. + * @param tag Tag for for the log data. Can be used to organize log statements. + * @param msg The actual message to be logged. The actual message to be logged. + */ + public static void println(int priority, String tag, String msg) { + println(priority, tag, msg, null); + } + + /** + * Prints a message at VERBOSE priority. + * + * @param tag Tag for for the log data. Can be used to organize log statements. + * @param msg The actual message to be logged. + * @param tr If an exception was thrown, this can be sent along for the logging facilities + * to extract and print useful information. + */ + public static void v(String tag, String msg, Throwable tr) { + println(VERBOSE, tag, msg, tr); + } + + /** + * Prints a message at VERBOSE priority. + * + * @param tag Tag for for the log data. Can be used to organize log statements. + * @param msg The actual message to be logged. + */ + public static void v(String tag, String msg) { + v(tag, msg, null); + } + + + /** + * Prints a message at DEBUG priority. + * + * @param tag Tag for for the log data. Can be used to organize log statements. + * @param msg The actual message to be logged. + * @param tr If an exception was thrown, this can be sent along for the logging facilities + * to extract and print useful information. + */ + public static void d(String tag, String msg, Throwable tr) { + println(DEBUG, tag, msg, tr); + } + + /** + * Prints a message at DEBUG priority. + * + * @param tag Tag for for the log data. Can be used to organize log statements. + * @param msg The actual message to be logged. + */ + public static void d(String tag, String msg) { + d(tag, msg, null); + } + + /** + * Prints a message at INFO priority. + * + * @param tag Tag for for the log data. Can be used to organize log statements. + * @param msg The actual message to be logged. + * @param tr If an exception was thrown, this can be sent along for the logging facilities + * to extract and print useful information. + */ + public static void i(String tag, String msg, Throwable tr) { + println(INFO, tag, msg, tr); + } + + /** + * Prints a message at INFO priority. + * + * @param tag Tag for for the log data. Can be used to organize log statements. + * @param msg The actual message to be logged. + */ + public static void i(String tag, String msg) { + i(tag, msg, null); + } + + /** + * Prints a message at WARN priority. + * + * @param tag Tag for for the log data. Can be used to organize log statements. + * @param msg The actual message to be logged. + * @param tr If an exception was thrown, this can be sent along for the logging facilities + * to extract and print useful information. + */ + public static void w(String tag, String msg, Throwable tr) { + println(WARN, tag, msg, tr); + } + + /** + * Prints a message at WARN priority. + * + * @param tag Tag for for the log data. Can be used to organize log statements. + * @param msg The actual message to be logged. + */ + public static void w(String tag, String msg) { + w(tag, msg, null); + } + + /** + * Prints a message at WARN priority. + * + * @param tag Tag for for the log data. Can be used to organize log statements. + * @param tr If an exception was thrown, this can be sent along for the logging facilities + * to extract and print useful information. + */ + public static void w(String tag, Throwable tr) { + w(tag, null, tr); + } + + /** + * Prints a message at ERROR priority. + * + * @param tag Tag for for the log data. Can be used to organize log statements. + * @param msg The actual message to be logged. + * @param tr If an exception was thrown, this can be sent along for the logging facilities + * to extract and print useful information. + */ + public static void e(String tag, String msg, Throwable tr) { + println(ERROR, tag, msg, tr); + } + + /** + * Prints a message at ERROR priority. + * + * @param tag Tag for for the log data. Can be used to organize log statements. + * @param msg The actual message to be logged. + */ + public static void e(String tag, String msg) { + e(tag, msg, null); + } + + /** + * Prints a message at ASSERT priority. + * + * @param tag Tag for for the log data. Can be used to organize log statements. + * @param msg The actual message to be logged. + * @param tr If an exception was thrown, this can be sent along for the logging facilities + * to extract and print useful information. + */ + public static void wtf(String tag, String msg, Throwable tr) { + println(ASSERT, tag, msg, tr); + } + + /** + * Prints a message at ASSERT priority. + * + * @param tag Tag for for the log data. Can be used to organize log statements. + * @param msg The actual message to be logged. + */ + public static void wtf(String tag, String msg) { + wtf(tag, msg, null); + } + + /** + * Prints a message at ASSERT priority. + * + * @param tag Tag for for the log data. Can be used to organize log statements. + * @param tr If an exception was thrown, this can be sent along for the logging facilities + * to extract and print useful information. + */ + public static void wtf(String tag, Throwable tr) { + wtf(tag, null, tr); + } +} diff --git a/app/src/main/java/com/geofence/drivergeofence/logger/LogFragment.java b/app/src/main/java/com/geofence/drivergeofence/logger/LogFragment.java new file mode 100644 index 0000000..c94bb4c --- /dev/null +++ b/app/src/main/java/com/geofence/drivergeofence/logger/LogFragment.java @@ -0,0 +1,94 @@ +/* +* Copyright 2013 The Android Open Source Project +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +package com.geofence.drivergeofence.logger; + +import android.graphics.Typeface; +import android.os.Bundle; +import android.support.v4.app.Fragment; +import android.text.Editable; +import android.text.TextWatcher; +import android.view.Gravity; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ScrollView; + +/** + * Simple fraggment which contains a LogView and uses is to output log data it receives + * through the LogNode interface. + */ +public class LogFragment extends Fragment { + + private LogView mLogView; + private ScrollView mScrollView; + + public LogFragment() {} + + public View inflateViews() { + mScrollView = new ScrollView(getActivity()); + ViewGroup.LayoutParams scrollParams = new ViewGroup.LayoutParams( + ViewGroup.LayoutParams.MATCH_PARENT, + ViewGroup.LayoutParams.MATCH_PARENT); + mScrollView.setLayoutParams(scrollParams); + + mLogView = new LogView(getActivity()); + ViewGroup.LayoutParams logParams = new ViewGroup.LayoutParams(scrollParams); + logParams.height = ViewGroup.LayoutParams.WRAP_CONTENT; + mLogView.setLayoutParams(logParams); + mLogView.setClickable(true); + mLogView.setFocusable(true); + mLogView.setTypeface(Typeface.MONOSPACE); + + // Want to set padding as 16 dips, setPadding takes pixels. Hooray math! + int paddingDips = 16; + double scale = getResources().getDisplayMetrics().density; + int paddingPixels = (int) ((paddingDips * (scale)) + .5); + mLogView.setPadding(paddingPixels, paddingPixels, paddingPixels, paddingPixels); + mLogView.setCompoundDrawablePadding(paddingPixels); + + mLogView.setGravity(Gravity.BOTTOM); + mLogView.setTextAppearance(getActivity(), android.R.style.TextAppearance_Holo_Medium); + + mScrollView.addView(mLogView); + return mScrollView; + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + + View result = inflateViews(); + + mLogView.addTextChangedListener(new TextWatcher() { + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) {} + + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) {} + + @Override + public void afterTextChanged(Editable s) { + mScrollView.fullScroll(ScrollView.FOCUS_DOWN); + } + }); + return result; + } + + public LogView getLogView() { + return mLogView; + } +} diff --git a/app/src/main/java/com/geofence/drivergeofence/logger/LogNode.java b/app/src/main/java/com/geofence/drivergeofence/logger/LogNode.java new file mode 100644 index 0000000..e8a49cc --- /dev/null +++ b/app/src/main/java/com/geofence/drivergeofence/logger/LogNode.java @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.geofence.drivergeofence.logger; + +/** + * Basic interface for a logging system that can output to one or more targets. + * Note that in addition to classes that will output these logs in some format, + * one can also implement this interface over a filter and insert that in the chain, + * such that no targets further down see certain data, or see manipulated forms of the data. + * You could, for instance, write a "ToHtmlLoggerNode" that just converted all the log data + * it received to HTML and sent it along to the next node in the chain, without printing it + * anywhere. + */ +public interface LogNode { + + /** + * Instructs first LogNode in the list to print the log data provided. + * @param priority Log level of the data being logged. Verbose, Error, etc. + * @param tag Tag for for the log data. Can be used to organize log statements. + * @param msg The actual message to be logged. The actual message to be logged. + * @param tr If an exception was thrown, this can be sent along for the logging facilities + * to extract and print useful information. + */ + public void println(int priority, String tag, String msg, Throwable tr); + +} diff --git a/app/src/main/java/com/geofence/drivergeofence/logger/LogView.java b/app/src/main/java/com/geofence/drivergeofence/logger/LogView.java new file mode 100644 index 0000000..781589b --- /dev/null +++ b/app/src/main/java/com/geofence/drivergeofence/logger/LogView.java @@ -0,0 +1,145 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.geofence.drivergeofence.logger; + +import android.app.Activity; +import android.content.Context; +import android.util.AttributeSet; +import android.widget.TextView; + +/** Simple TextView which is used to output log data received through the LogNode interface. +*/ +public class LogView extends TextView implements LogNode { + + public LogView(Context context) { + super(context); + } + + public LogView(Context context, AttributeSet attrs) { + super(context, attrs); + } + + public LogView(Context context, AttributeSet attrs, int defStyle) { + super(context, attrs, defStyle); + } + + /** + * Formats the log data and prints it out to the LogView. + * @param priority Log level of the data being logged. Verbose, Error, etc. + * @param tag Tag for for the log data. Can be used to organize log statements. + * @param msg The actual message to be logged. The actual message to be logged. + * @param tr If an exception was thrown, this can be sent along for the logging facilities + * to extract and print useful information. + */ + @Override + public void println(int priority, String tag, String msg, Throwable tr) { + + + String priorityStr = null; + + // For the purposes of this View, we want to print the priority as readable text. + switch(priority) { + case android.util.Log.VERBOSE: + priorityStr = "VERBOSE"; + break; + case android.util.Log.DEBUG: + priorityStr = "DEBUG"; + break; + case android.util.Log.INFO: + priorityStr = "INFO"; + break; + case android.util.Log.WARN: + priorityStr = "WARN"; + break; + case android.util.Log.ERROR: + priorityStr = "ERROR"; + break; + case android.util.Log.ASSERT: + priorityStr = "ASSERT"; + break; + default: + break; + } + + // Handily, the Log class has a facility for converting a stack trace into a usable string. + String exceptionStr = null; + if (tr != null) { + exceptionStr = android.util.Log.getStackTraceString(tr); + } + + // Take the priority, tag, message, and exception, and concatenate as necessary + // into one usable line of text. + final StringBuilder outputBuilder = new StringBuilder(); + + String delimiter = "\t"; + appendIfNotNull(outputBuilder, priorityStr, delimiter); + appendIfNotNull(outputBuilder, tag, delimiter); + appendIfNotNull(outputBuilder, msg, delimiter); + appendIfNotNull(outputBuilder, exceptionStr, delimiter); + + // In case this was originally called from an AsyncTask or some other off-UI thread, + // make sure the update occurs within the UI thread. + ((Activity) getContext()).runOnUiThread( (new Thread(new Runnable() { + @Override + public void run() { + // Display the text we just generated within the LogView. + appendToLog(outputBuilder.toString()); + } + }))); + + if (mNext != null) { + mNext.println(priority, tag, msg, tr); + } + } + + public LogNode getNext() { + return mNext; + } + + public void setNext(LogNode node) { + mNext = node; + } + + /** Takes a string and adds to it, with a separator, if the bit to be added isn't null. Since + * the logger takes so many arguments that might be null, this method helps cut out some of the + * agonizing tedium of writing the same 3 lines over and over. + * @param source StringBuilder containing the text to append to. + * @param addStr The String to append + * @param delimiter The String to separate the source and appended strings. A tab or comma, + * for instance. + * @return The fully concatenated String as a StringBuilder + */ + private StringBuilder appendIfNotNull(StringBuilder source, String addStr, String delimiter) { + if (addStr != null) { + if (addStr.length() == 0) { + delimiter = ""; + } + + return source.append(addStr).append(delimiter); + } + return source; + } + + // The next LogNode in the chain. + LogNode mNext; + + /** Outputs the string as a new line of log data in the LogView. */ + public void appendToLog(String s) { + append("\n" + s); + } + + +} diff --git a/app/src/main/java/com/geofence/drivergeofence/logger/LogWrapper.java b/app/src/main/java/com/geofence/drivergeofence/logger/LogWrapper.java new file mode 100644 index 0000000..ebb162c --- /dev/null +++ b/app/src/main/java/com/geofence/drivergeofence/logger/LogWrapper.java @@ -0,0 +1,75 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.geofence.drivergeofence.logger; + +import android.util.Log; + +/** + * Helper class which wraps Android's native Log utility in the Logger interface. This way + * normal DDMS output can be one of the many targets receiving and outputting logs simultaneously. + */ +public class LogWrapper implements LogNode { + + // For piping: The next node to receive Log data after this one has done its work. + private LogNode mNext; + + /** + * Returns the next LogNode in the linked list. + */ + public LogNode getNext() { + return mNext; + } + + /** + * Sets the LogNode data will be sent to.. + */ + public void setNext(LogNode node) { + mNext = node; + } + + /** + * Prints data out to the console using Android's native log mechanism. + * @param priority Log level of the data being logged. Verbose, Error, etc. + * @param tag Tag for for the log data. Can be used to organize log statements. + * @param msg The actual message to be logged. The actual message to be logged. + * @param tr If an exception was thrown, this can be sent along for the logging facilities + * to extract and print useful information. + */ + @Override + public void println(int priority, String tag, String msg, Throwable tr) { + // There actually are log methods that don't take a msg parameter. For now, + // if that's the case, just convert null to the empty string and move on. + String useMsg = msg; + if (useMsg == null) { + useMsg = ""; + } + + // If an exeption was provided, convert that exception to a usable string and attach + // it to the end of the msg method. + if (tr != null) { + msg += "\n" + Log.getStackTraceString(tr); + } + + // This is functionally identical to Log.x(tag, useMsg); + // For instance, if priority were Log.VERBOSE, this would be the same as Log.v(tag, useMsg) + Log.println(priority, tag, useMsg); + + // If this isn't the last node in the chain, move things along. + if (mNext != null) { + mNext.println(priority, tag, msg, tr); + } + } +} diff --git a/app/src/main/java/com/geofence/drivergeofence/logger/MessageOnlyLogFilter.java b/app/src/main/java/com/geofence/drivergeofence/logger/MessageOnlyLogFilter.java new file mode 100644 index 0000000..88b2846 --- /dev/null +++ b/app/src/main/java/com/geofence/drivergeofence/logger/MessageOnlyLogFilter.java @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.geofence.drivergeofence.logger; + +/** + * Simple {@link LogNode} filter, removes everything except the message. + * Useful for situations like on-screen log output where you don't want a lot of metadata displayed, + * just easy-to-read message updates as they're happening. + */ +public class MessageOnlyLogFilter implements LogNode { + + LogNode mNext; + + /** + * Takes the "next" LogNode as a parameter, to simplify chaining. + * + * @param next The next LogNode in the pipeline. + */ + public MessageOnlyLogFilter(LogNode next) { + mNext = next; + } + + public MessageOnlyLogFilter() { + } + + @Override + public void println(int priority, String tag, String msg, Throwable tr) { + if (mNext != null) { + getNext().println(Log.NONE, null, msg, null); + } + } + + /** + * Returns the next LogNode in the chain. + */ + public LogNode getNext() { + return mNext; + } + + /** + * Sets the LogNode data will be sent to.. + */ + public void setNext(LogNode node) { + mNext = node; + } + +} diff --git a/app/src/main/res/drawable/ic_launcher.png b/app/src/main/res/drawable/ic_launcher.png new file mode 100644 index 0000000..cde69bc Binary files /dev/null and b/app/src/main/res/drawable/ic_launcher.png differ diff --git a/app/src/main/res/drawable/road.png b/app/src/main/res/drawable/road.png new file mode 100644 index 0000000..4d064db Binary files /dev/null and b/app/src/main/res/drawable/road.png differ diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..fd7b337 --- /dev/null +++ b/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,41 @@ + + + + + + + + + + +