├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── raw
│ │ │ │ ├── ss1.png
│ │ │ │ ├── ss2.png
│ │ │ │ ├── ss3.png
│ │ │ │ ├── ss4.png
│ │ │ │ └── ss5.png
│ │ │ ├── drawable
│ │ │ │ ├── logo.png
│ │ │ │ ├── locomoto.png
│ │ │ │ ├── startbutton.xml
│ │ │ │ ├── statusview.xml
│ │ │ │ ├── request_button.xml
│ │ │ │ └── acceptrequest_button.xml
│ │ │ ├── mipmap-hdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── values
│ │ │ │ ├── colors.xml
│ │ │ │ ├── dimens.xml
│ │ │ │ ├── strings.xml
│ │ │ │ └── styles.xml
│ │ │ ├── values-v21
│ │ │ │ └── styles.xml
│ │ │ ├── values-w820dp
│ │ │ │ └── dimens.xml
│ │ │ ├── menu
│ │ │ │ └── menu_main.xml
│ │ │ └── layout
│ │ │ │ ├── activity_main.xml
│ │ │ │ ├── content_view_available.xml
│ │ │ │ ├── activity_view_available.xml
│ │ │ │ ├── activity_view_rider_location.xml
│ │ │ │ ├── activity_your_location.xml
│ │ │ │ └── content_main.xml
│ │ ├── assets
│ │ │ └── fonts
│ │ │ │ ├── Bangers.ttf
│ │ │ │ └── OpenSans.ttf
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── com
│ │ │ └── akashbhave
│ │ │ └── locomoto
│ │ │ ├── MainActivity.java
│ │ │ ├── ViewRiderLocation.java
│ │ │ ├── ViewAvailable.java
│ │ │ └── YourLocation.java
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── akashbhave
│ │ │ └── locomoto
│ │ │ └── ExampleUnitTest.java
│ ├── androidTest
│ │ └── java
│ │ │ └── com
│ │ │ └── akashbhave
│ │ │ └── locomoto
│ │ │ └── ApplicationTest.java
│ ├── release
│ │ └── res
│ │ │ └── values
│ │ │ └── google_maps_api.xml
│ └── debug
│ │ └── res
│ │ └── values
│ │ └── google_maps_api.xml
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── .idea
├── copyright
│ └── profiles_settings.xml
├── vcs.xml
├── modules.xml
├── runConfigurations.xml
├── compiler.xml
├── gradle.xml
└── misc.xml
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitignore
├── gradle.properties
├── gradlew.bat
├── README.md
└── gradlew
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/app/src/main/res/raw/ss1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AkashBhave/locomoto/HEAD/app/src/main/res/raw/ss1.png
--------------------------------------------------------------------------------
/app/src/main/res/raw/ss2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AkashBhave/locomoto/HEAD/app/src/main/res/raw/ss2.png
--------------------------------------------------------------------------------
/app/src/main/res/raw/ss3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AkashBhave/locomoto/HEAD/app/src/main/res/raw/ss3.png
--------------------------------------------------------------------------------
/app/src/main/res/raw/ss4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AkashBhave/locomoto/HEAD/app/src/main/res/raw/ss4.png
--------------------------------------------------------------------------------
/app/src/main/res/raw/ss5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AkashBhave/locomoto/HEAD/app/src/main/res/raw/ss5.png
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AkashBhave/locomoto/HEAD/app/src/main/res/drawable/logo.png
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AkashBhave/locomoto/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/assets/fonts/Bangers.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AkashBhave/locomoto/HEAD/app/src/main/assets/fonts/Bangers.ttf
--------------------------------------------------------------------------------
/app/src/main/assets/fonts/OpenSans.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AkashBhave/locomoto/HEAD/app/src/main/assets/fonts/OpenSans.ttf
--------------------------------------------------------------------------------
/app/src/main/res/drawable/locomoto.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AkashBhave/locomoto/HEAD/app/src/main/res/drawable/locomoto.png
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AkashBhave/locomoto/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AkashBhave/locomoto/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AkashBhave/locomoto/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AkashBhave/locomoto/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AkashBhave/locomoto/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #FFC107
4 | #FFA000
5 | #00BFA5
6 |
7 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Dec 26 20:20:20 EST 2016
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 | 16dp
6 |
7 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/values-v21/styles.xml:
--------------------------------------------------------------------------------
1 | >
2 |
3 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | LocoMoto
3 | Settings
4 | Your Location
5 | Available Requests
6 | View Rider Location
7 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/test/java/com/akashbhave/locomoto/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.akashbhave.locomoto;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
9 | */
10 | public class ExampleUnitTest {
11 | @Test
12 | public void addition_isCorrect() throws Exception {
13 | assertEquals(4, 2 + 2);
14 | }
15 | }
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/akashbhave/locomoto/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.akashbhave.locomoto;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/app/src/main/res/menu/menu_main.xml:
--------------------------------------------------------------------------------
1 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/startbutton.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
9 |
15 |
19 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/statusview.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
9 |
13 |
19 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/request_button.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
9 |
13 |
19 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/acceptrequest_button.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
9 |
13 |
19 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in C:\Users\akash\AppData\Local\Android\sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/app/src/release/res/values/google_maps_api.xml:
--------------------------------------------------------------------------------
1 |
2 |
19 |
20 | YOUR_KEY_HERE
21 |
22 |
23 |
--------------------------------------------------------------------------------
/app/src/debug/res/values/google_maps_api.xml:
--------------------------------------------------------------------------------
1 |
2 |
18 |
19 | AIzaSyBAkGQ3JUBgVWhi2IVZpiqdK858qpmxL1c
20 |
21 |
22 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/content_view_available.xml:
--------------------------------------------------------------------------------
1 |
2 |
14 |
15 |
21 |
22 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion "23.0.2"
6 |
7 | defaultConfig {
8 | applicationId "com.akashbhave.locomoto"
9 | minSdkVersion 16
10 | targetSdkVersion 23
11 | versionCode 1
12 | versionName "1.0"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | packagingOptions {
21 | exclude 'META-INF/LICENSE'
22 | exclude 'META-INF/LICENSE-FIREBASE.txt'
23 | exclude 'META-INF/NOTICE'
24 | }
25 | }
26 |
27 | dependencies {
28 | compile fileTree(dir: 'libs', include: ['*.jar'])
29 | testCompile 'junit:junit:4.12'
30 | compile 'com.android.support:appcompat-v7:23.1.1'
31 | compile 'com.android.support:design:23.1.1'
32 | compile 'com.google.android.gms:play-services:8.4.0'
33 | // https://mvnrepository.com/artifact/io.cloudboost/JavaSDK
34 | compile group: 'io.cloudboost', name: 'JavaSDK', version: '1.0.7'
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_view_available.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
14 |
15 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_view_rider_location.xml:
--------------------------------------------------------------------------------
1 |
9 |
10 |
17 |
18 |
34 |
35 |
46 |
47 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_your_location.xml:
--------------------------------------------------------------------------------
1 |
8 |
9 |
16 |
17 |
18 |
34 |
35 |
51 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
15 |
16 |
17 |
18 |
24 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
43 |
46 |
47 |
50 |
54 |
57 |
58 |
59 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/content_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
20 |
21 |
27 |
28 |
38 |
39 |
40 |
50 |
51 |
63 |
64 |
77 |
78 |
86 |
87 |
98 |
99 |
109 |
110 |
111 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # LocoMoto
2 |
3 | LocoMoto is an Android application that has Uber-like features and is similar to a taxi service.
4 |
5 | ## User Types
6 |
7 | - **Rider:** You can request a ride while looking at your location (which is updated very frequently) on a map. Once you click the 'Request Ride' button, your request is stored on the online database. You also have the option to cancel your request, which will in turn remove it from the database. Any drivers in the area can see your request.
8 | - **Driver:** You can view available requests from other riders, which is all displayed in an [Android ListView](http://developer.android.com/guide/topics/ui/layout/listview.html), which is essentially a vertical table with clickable elements. The requests are in order from closest to farthest. Once you click on a request, you see the rider's postition relative to yours on a map. Accepting the request brings up a navigation dialog to the rider's position.
9 |
10 | ## Application Information
11 |
12 | - To store all the data, the application uses a service called [Cloudboost](http://www.cloudboost.io). The app id on the database is 'ktdffagvxbnq'. With this, alongside the client key, you can access the database using specific commands.
13 | - The name of the package is "com.akashbhave.locomoto", which can be seen in the 'Apps' tab of the Android Settings.
14 | - This application is compatible with Android versions 4.1 (Jelly Bean, API 16) and up, but it recommended for Android versions 5.0 (Lollipop, API 21) and up.
15 | - You must have an Internet connection at all times.
16 | - A GPS connection is optional.
17 |
18 | ## Structure
19 |
20 | - The Java files are located [here](https://github.com/AkashBhave/LocoMoto/tree/master/app/src/main/java/com/akashbhave/locomoto), in the 'java' directory. These files are in the .java file format.
21 |
22 | - [MainActivity.java](https://github.com/AkashBhave/LocoMoto/blob/master/app/src/main/java/com/akashbhave/locomoto/MainActivity.java): Reponsible for the signup/login part of the app, doesn't load if you have already saved your role on the device.
23 | - [YourLocation.java](https://github.com/AkashBhave/LocoMoto/blob/master/app/src/main/java/com/akashbhave/locomoto/YourLocation.java): Mainly used while in the 'rider' role. Contains a Google Map and some buttons on top.
24 | - [ViewAvailable.java](https://github.com/AkashBhave/LocoMoto/blob/master/app/src/main/java/com/akashbhave/locomoto/ViewAvailable.java): Used while in the 'driver' role, lets you see all the current requests from other riders in order of nearest to farthest from your location.
25 | - [ViewRiderLocation.java](https://github.com/AkashBhave/LocoMoto/blob/master/app/src/main/java/com/akashbhave/locomoto/ViewRiderLocation.java): Used when looking at the rider's position relative to yours in the 'driver' role. You can also navigate to the rider's position using Google Maps, which is prompted.
26 |
27 | - The layout files are located [here](https://github.com/AkashBhave/LocoMoto/tree/master/app/src/main/res/layout), in the 'layout' directory. These files are in the .xml file format. Here you can find the layout of the UI (User Interface).
28 | - [activity_main.xml](https://github.com/AkashBhave/LocoMoto/blob/master/app/src/main/res/layout/activity_main.xml) and [content_main.xml](https://github.com/AkashBhave/LocoMoto/blob/master/app/src/main/res/layout/content_main.xml): Responsible for the layout of the "MainActivity.java" page, or the signup/login part of the app.
29 | - [activity_your_location.xml](https://github.com/AkashBhave/LocoMoto/blob/master/app/src/main/res/layout/activity_your_location.xml): Responsible for the layout and interface of the rider's map portion of the app.
30 | - [activity_view_available.xml](https://github.com/AkashBhave/LocoMoto/blob/master/app/src/main/res/layout/activity_view_available.xml) and [content_view_available.xml](https://github.com/AkashBhave/LocoMoto/blob/master/app/src/main/res/layout/content_view_available.xml): Responsible for the driver's ListView of the app, which also will contain the map of the locations.
31 | - [activity_view_rider_location.xml](https://github.com/AkashBhave/LocoMoto/blob/master/app/src/main/res/layout/activity_view_rider_location.xml): Responsible for the map of the driver and the rider, in the 'driver' role.
32 | - **NOTE:** Some activities (like ViewAvailable) have both activity files and content files. Some activities (like YourLocation) have only the activity file, which has all the information in one file.
33 |
34 | ## Screenshots
35 |
36 |
37 |
38 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/app/src/main/java/com/akashbhave/locomoto/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.akashbhave.locomoto;
2 |
3 | import android.content.Intent;
4 | import android.content.SharedPreferences;
5 | import android.graphics.Typeface;
6 | import android.location.Location;
7 | import android.os.AsyncTask;
8 | import android.os.Bundle;
9 | import android.support.v7.app.AppCompatActivity;
10 | import android.util.Log;
11 | import android.view.Menu;
12 | import android.view.MenuItem;
13 | import android.view.View;
14 | import android.widget.Button;
15 | import android.widget.EditText;
16 | import android.widget.RadioGroup;
17 | import android.widget.TextView;
18 | import android.widget.Toast;
19 |
20 | import com.google.android.gms.location.places.Place;
21 | import com.google.android.gms.location.places.ui.PlacePicker;
22 | import com.google.android.gms.maps.GoogleMap;
23 |
24 | import java.util.UUID;
25 |
26 | import io.cloudboost.CloudApp;
27 | import io.cloudboost.CloudException;
28 | import io.cloudboost.CloudUser;
29 | import io.cloudboost.CloudUserCallback;
30 |
31 |
32 | public class MainActivity extends AppCompatActivity {
33 |
34 | SharedPreferences sharedPreferences;
35 |
36 | TextView roleDescView;
37 | TextView selectView;
38 | EditText nameInput;
39 | Button startButton;
40 | RadioGroup radioGroup;
41 |
42 | // If the user is a driver or a rider
43 | String userRole;
44 | String userName;
45 | boolean roleSelected = false;
46 |
47 | class DTask extends AsyncTask {
48 | String toastMessage = "";
49 |
50 | @Override
51 | protected Void doInBackground(String... params) {
52 | try {
53 | if(roleSelected) {
54 | CloudUser aUser = new CloudUser();
55 | // Creates a random id/username for each user
56 | final String id = UUID.randomUUID().toString().replaceAll("-", "");
57 | aUser.set("username", id);
58 | aUser.set("password", "pass");
59 | aUser.set("email", "");
60 | aUser.set("role", userRole);
61 | System.out.println(userRole);
62 | aUser.set("actualName", userName);
63 | aUser.signUp(new CloudUserCallback() {
64 | @Override
65 | public void done(CloudUser user, CloudException e) throws CloudException {
66 | if (e == null) {
67 | Log.i("User Sign In", "Role: " + userRole);
68 |
69 | // Puts in a SharedPreferences that user has already logged in
70 | sharedPreferences.edit().putBoolean("isUserIn", true).apply();
71 | sharedPreferences.edit().putString("role", userRole).apply();
72 | sharedPreferences.edit().putString("currentUser", id).apply();
73 | redirectUser();
74 | } else {
75 | e.printStackTrace();
76 | }
77 | }
78 | });
79 | } else {
80 | toastMessage = "Please select a role";
81 | }
82 | } catch (Exception c) {
83 | c.printStackTrace();
84 | }
85 | return null;
86 | }
87 |
88 | @Override
89 | protected void onPostExecute(Void aVoid) {
90 | super.onPostExecute(aVoid);
91 | if (!toastMessage.equals("")) {
92 | Toast.makeText(getApplicationContext(), toastMessage, Toast.LENGTH_SHORT).show();
93 | }
94 | }
95 | }
96 |
97 |
98 | public void getStarted(View view) throws CloudException {
99 | userName = nameInput.getText().toString();
100 | if (userName.length() > 5) {
101 | DTask registerUser = new DTask();
102 | registerUser.execute("");
103 | } else {
104 | Toast.makeText(MainActivity.this, "Your name must be at least 6 characters", Toast.LENGTH_LONG).show();
105 | }
106 | }
107 |
108 | public void redirectUser() {
109 | if (sharedPreferences.getString("role", "").equals("rider")) {
110 | Log.i("Rider", "Redirect Map");
111 | Intent toRiderMap = new Intent(getApplicationContext(), YourLocation.class);
112 | startActivity(toRiderMap);
113 | } else {
114 | Log.i("Driver", "Redirect Map");
115 | Intent toDriverMap = new Intent(getApplicationContext(), ViewAvailable.class);
116 | startActivity(toDriverMap);
117 | }
118 | }
119 |
120 | @Override
121 | protected void onCreate(Bundle savedInstanceState) {
122 | super.onCreate(savedInstanceState);
123 | setContentView(R.layout.activity_main);
124 |
125 | // Initializes the app in the databases
126 | CloudApp.init("izjqixzyfjbd", "2be811d8-124e-49da-ad43-6bac3ad5f28c");
127 |
128 | // Checks to see if user has already opened app and set up
129 | sharedPreferences = this.getSharedPreferences(getPackageName(), MODE_PRIVATE);
130 | boolean isUserIn = sharedPreferences.getBoolean("isUserIn", false);
131 | if (isUserIn) redirectUser();
132 |
133 | Typeface OpenSans = Typeface.createFromAsset(getAssets(), "fonts/OpenSans.ttf");
134 |
135 | roleDescView = (TextView) findViewById(R.id.roleDescView);
136 | roleDescView.setTypeface(OpenSans);
137 | selectView = (TextView) findViewById(R.id.selectView);
138 | nameInput = (EditText) findViewById(R.id.nameInput);
139 | startButton = (Button) findViewById(R.id.startButton);
140 | radioGroup = (RadioGroup) findViewById(R.id.radioGroup);
141 | radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
142 | @Override
143 | public void onCheckedChanged(RadioGroup group, int checkedId) {
144 | if (checkedId == R.id.driverRButton) {
145 | roleDescView.setText("You are going to be a driver.");
146 | userRole = "driver";
147 | roleSelected = true;
148 | } else if (checkedId == R.id.riderRButton) {
149 | roleDescView.setText("You are going to be a rider.");
150 | userRole = "rider";
151 | roleSelected = true;
152 | }
153 | }
154 | });
155 |
156 | }
157 |
158 |
159 | @Override
160 | public boolean onCreateOptionsMenu(Menu menu) {
161 | // Inflate the menu; this adds items to the action bar if it is present.
162 | getMenuInflater().inflate(R.menu.menu_main, menu);
163 | return true;
164 | }
165 |
166 | @Override
167 | public boolean onOptionsItemSelected(MenuItem item) {
168 | // Handle action bar item clicks here. The action bar will
169 | // automatically handle clicks on the Home/Up button, so long
170 | // as you specify a parent activity in AndroidManifest.xml.
171 | int id = item.getItemId();
172 |
173 | //noinspection SimplifiableIfStatement
174 | if (id == R.id.action_settings) {
175 | return true;
176 | }
177 |
178 | return super.onOptionsItemSelected(item);
179 | }
180 |
181 |
182 | }
183 |
--------------------------------------------------------------------------------
/app/src/main/java/com/akashbhave/locomoto/ViewRiderLocation.java:
--------------------------------------------------------------------------------
1 | package com.akashbhave.locomoto;
2 |
3 | import android.content.Intent;
4 | import android.net.Uri;
5 | import android.os.AsyncTask;
6 | import android.os.Bundle;
7 | import android.support.v4.app.FragmentActivity;
8 | import android.util.Log;
9 | import android.view.View;
10 | import android.view.ViewTreeObserver;
11 | import android.widget.RelativeLayout;
12 | import android.widget.Toast;
13 |
14 | import com.google.android.gms.maps.CameraUpdate;
15 | import com.google.android.gms.maps.CameraUpdateFactory;
16 | import com.google.android.gms.maps.GoogleMap;
17 | import com.google.android.gms.maps.OnMapReadyCallback;
18 | import com.google.android.gms.maps.SupportMapFragment;
19 | import com.google.android.gms.maps.model.BitmapDescriptor;
20 | import com.google.android.gms.maps.model.BitmapDescriptorFactory;
21 | import com.google.android.gms.maps.model.LatLng;
22 | import com.google.android.gms.maps.model.LatLngBounds;
23 | import com.google.android.gms.maps.model.Marker;
24 | import com.google.android.gms.maps.model.MarkerOptions;
25 |
26 | import java.util.ArrayList;
27 |
28 | import io.cloudboost.CloudException;
29 | import io.cloudboost.CloudObject;
30 | import io.cloudboost.CloudObjectArrayCallback;
31 | import io.cloudboost.CloudObjectCallback;
32 | import io.cloudboost.CloudQuery;
33 |
34 | public class ViewRiderLocation extends FragmentActivity implements OnMapReadyCallback {
35 |
36 | private GoogleMap mMap;
37 | Intent getRiderInfo;
38 |
39 | // Variables of the rider's and driver's properties
40 | Double riderLat;
41 | Double riderLng;
42 | String riderUsername;
43 | Double driverLat;
44 | Double driverLng;
45 | String driverUsername;
46 |
47 |
48 | String downloadTaskType = "";
49 |
50 | public class DownloadTask extends AsyncTask {
51 |
52 | String toastMessage = "";
53 |
54 | @Override
55 | protected Void doInBackground(String... params) {
56 | if (downloadTaskType.equals("acceptRequest")) {
57 | try {
58 | CloudQuery query = new CloudQuery("Requests");
59 | query.equalTo("reqUsername", riderUsername);
60 | query.setLimit(1);
61 | query.find(new CloudObjectArrayCallback() {
62 | @Override
63 | public void done(CloudObject[] x, CloudException t) throws CloudException {
64 | if (x != null && x.length > 0) {
65 | for (CloudObject object : x) {
66 | object.set("driverUsername", driverUsername);
67 | object.save(new CloudObjectCallback() {
68 | @Override
69 | public void done(CloudObject x, CloudException t) throws CloudException {
70 | toastMessage = "Request has been accepted!";
71 | // Starts the directions Intent
72 | Intent directionsIntent = new Intent(android.content.Intent.ACTION_VIEW,
73 | Uri.parse("http://maps.google.com/maps?saddr=" + driverLat + "," + driverLng
74 | + "&daddr=" + riderLat + "," + riderLng));
75 | directionsIntent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
76 | startActivity(directionsIntent);
77 | }
78 | });
79 | }
80 | }
81 | }
82 | });
83 | } catch (CloudException e) {
84 | e.printStackTrace();
85 | }
86 | }
87 | return null;
88 | }
89 |
90 | @Override
91 | protected void onPostExecute(Void aVoid) {
92 | super.onPostExecute(aVoid);
93 | if (!toastMessage.equals(""))
94 | Toast.makeText(getApplicationContext(), toastMessage, Toast.LENGTH_SHORT).show();
95 | }
96 | }
97 |
98 | public void goBack(View view) {
99 | Intent viewAvailableIntent = new Intent(this, ViewAvailable.class);
100 | startActivity(viewAvailableIntent);
101 | }
102 |
103 | public void acceptRequest(View view) throws CloudException {
104 | DownloadTask acceptRequestTask = new DownloadTask();
105 | downloadTaskType = "acceptRequest";
106 | acceptRequestTask.execute("");
107 | }
108 |
109 | @Override
110 | protected void onCreate(Bundle savedInstanceState) {
111 | super.onCreate(savedInstanceState);
112 | setContentView(R.layout.activity_view_rider_location);
113 |
114 | // Obtains the information parsed by the 'ViewAvailable' class that contains the rider's information
115 | getRiderInfo = getIntent();
116 | riderLat = getRiderInfo.getDoubleExtra("riderLat", 0);
117 | riderLng = getRiderInfo.getDoubleExtra("riderLng", 0);
118 | riderUsername = getRiderInfo.getStringExtra("riderUsername");
119 | driverLat = getRiderInfo.getDoubleExtra("driverLat", 0);
120 | driverLng = getRiderInfo.getDoubleExtra("driverLng", 0);
121 | driverUsername = getRiderInfo.getStringExtra("driverUsername");
122 |
123 | // Obtain the SupportMapFragment and get notified when the map is ready to be used.
124 | SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
125 | .findFragmentById(R.id.map);
126 | mapFragment.getMapAsync(this);
127 | }
128 |
129 |
130 | /**
131 | * Manipulates the map once available.
132 | * This callback is triggered when the map is ready to be used.
133 | * This is where we can add markers or lines, add listeners or move the camera. In this case,
134 | * we just add a marker near Sydney, Australia.
135 | * If Google Play services is not installed on the device, the user will be prompted to install
136 | * it inside the SupportMapFragment. This method will only be triggered once the user has
137 | * installed Google Play services and returned to the app.
138 | */
139 | @Override
140 | public void onMapReady(GoogleMap googleMap) {
141 | mMap = googleMap;
142 | mMap.clear();
143 |
144 | RelativeLayout mapLayout = (RelativeLayout) findViewById(R.id.relativeLayout);
145 | mapLayout.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
146 | @Override
147 | public void onGlobalLayout() {
148 |
149 | // Ensures the two markers are in view
150 | LatLngBounds.Builder builder = new LatLngBounds.Builder();
151 | ArrayList markers = new ArrayList();
152 |
153 | // Custom icons for markers
154 | BitmapDescriptor locIcon1 = BitmapDescriptorFactory.fromResource(R.drawable.location1);
155 | BitmapDescriptor locIcon2 = BitmapDescriptorFactory.fromResource(R.drawable.location2);
156 | markers.add(mMap.addMarker(new MarkerOptions().position(new LatLng(riderLat, riderLng)).title("Your Location").icon(locIcon1)));
157 | markers.add(mMap.addMarker(new MarkerOptions().position(new LatLng(driverLat, driverLng)).title("Rider's Location").icon(locIcon2)));
158 |
159 | for (Marker marker : markers) {
160 | builder.include(marker.getPosition());
161 | }
162 | LatLngBounds bounds = builder.build();
163 | int padding = 100; // offset from edges of the map in pixels
164 | CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, padding);
165 | mMap.animateCamera(cu);
166 | }
167 | });
168 |
169 | Log.i("Rider's Information", riderUsername + " - " + riderLat + ", " + riderLng);
170 | }
171 | }
172 |
--------------------------------------------------------------------------------
/app/src/main/java/com/akashbhave/locomoto/ViewAvailable.java:
--------------------------------------------------------------------------------
1 | package com.akashbhave.locomoto;
2 |
3 | import android.content.Intent;
4 | import android.content.SharedPreferences;
5 | import android.location.Criteria;
6 | import android.location.Location;
7 | import android.location.LocationListener;
8 | import android.location.LocationManager;
9 | import android.os.AsyncTask;
10 | import android.os.Bundle;
11 | import android.support.v7.app.AppCompatActivity;
12 | import android.support.v7.widget.Toolbar;
13 | import android.util.Log;
14 | import android.view.KeyEvent;
15 | import android.view.View;
16 | import android.view.ViewGroup;
17 | import android.widget.AdapterView;
18 | import android.widget.ArrayAdapter;
19 | import android.widget.ListView;
20 | import android.widget.TextView;
21 |
22 | import org.json.JSONException;
23 | import org.json.JSONObject;
24 |
25 | import java.util.ArrayList;
26 |
27 | import io.cloudboost.CloudException;
28 | import io.cloudboost.CloudGeoPoint;
29 | import io.cloudboost.CloudObject;
30 | import io.cloudboost.CloudObjectArrayCallback;
31 | import io.cloudboost.CloudObjectCallback;
32 | import io.cloudboost.CloudQuery;
33 |
34 | public class ViewAvailable extends AppCompatActivity implements LocationListener {
35 |
36 | ListView listView;
37 | ArrayList usersNames = new ArrayList();
38 | ArrayList actualNames = new ArrayList();
39 | ArrayList usersLocations = new ArrayList();
40 | ArrayList distances = new ArrayList();
41 | ArrayAdapter arrayAdapter;
42 |
43 | LocationManager locationManager;
44 | String provider;
45 | // For saving the user's location
46 | Location usersCurrentLocation;
47 |
48 | // If user's request is still wanted
49 | boolean requestActive = false;
50 |
51 | SharedPreferences sharedPreferences;
52 |
53 | String downloadTaskType = "";
54 |
55 | public class DownloadTask extends AsyncTask {
56 |
57 | boolean resultGood = false;
58 |
59 | @Override
60 | protected Void doInBackground(String... params) {
61 | if (downloadTaskType.equals("updateLocation")) {
62 | try {
63 | CloudQuery putDriverLocation = new CloudQuery("User");
64 | putDriverLocation.equalTo("username", sharedPreferences.getString("currentUser", ""));
65 | putDriverLocation.find(new CloudObjectArrayCallback() {
66 | @Override
67 | public void done(CloudObject[] x, CloudException t) throws CloudException {
68 | if (x != null) {
69 | for (CloudObject object : x) {
70 | String myBearing = String.valueOf(usersCurrentLocation.getBearing());
71 | CloudGeoPoint location = new CloudGeoPoint(usersCurrentLocation.getLatitude(), usersCurrentLocation.getLongitude());
72 | object.set("location", location);
73 | object.set("bearing", myBearing);
74 | object.save(new CloudObjectCallback() {
75 | @Override
76 | public void done(CloudObject x, CloudException t) throws CloudException {
77 |
78 | }
79 | });
80 | }
81 | } else {
82 | t.printStackTrace();
83 | }
84 | }
85 | });
86 |
87 | final Location driverLocation = new Location(provider);
88 | driverLocation.setLatitude(usersCurrentLocation.getLatitude());
89 | driverLocation.setLongitude(usersCurrentLocation.getLongitude());
90 |
91 | // 'driverUsername' can be equal to one of two conditions (below)
92 | CloudQuery query1 = new CloudQuery("Requests");
93 | query1.equalTo("driverUsername", null);
94 | CloudQuery query2 = new CloudQuery("Requests");
95 | query2.equalTo("driverUsername", "");
96 |
97 | CloudQuery query = CloudQuery.or(query1, query2);
98 | query.orderByDesc("reqLocation");
99 | query.setLimit(10);
100 | query.find(new CloudObjectArrayCallback() {
101 | @Override
102 | public void done(CloudObject[] x, CloudException t) throws CloudException {
103 | if (x != null) {
104 | resultGood = true;
105 | Log.i("Amount", String.valueOf(x.length));
106 | usersNames.clear();
107 | usersLocations.clear();
108 | distances.clear();
109 | for (CloudObject object : x) {
110 | try {
111 | JSONObject geopoint = new JSONObject(object.get("reqLocation").toString());
112 | // retrieve the coordinates
113 | String coordinates = geopoint.getString("coordinates").replace("[", "").replace("]", "");
114 | String[] latLng = coordinates.split(",");
115 | String stringLat = latLng[1].replace(",", "");
116 | String stringLng = latLng[0].replace(",", "");
117 | Double latitude = Double.parseDouble(stringLat);
118 | Double longitude = Double.parseDouble(stringLng);
119 |
120 | Location aUserLocation = new Location(provider);
121 | aUserLocation.setLatitude(latitude);
122 | aUserLocation.setLongitude(longitude);
123 |
124 | Log.i("User Lat/Lng", String.valueOf(aUserLocation.getLatitude()) + "/" + String.valueOf(aUserLocation.getLongitude()));
125 |
126 | double distance = driverLocation.distanceTo(aUserLocation);
127 | double distanceMiles = Math.round((distance * 0.000621371) * 100) / 100;
128 |
129 | usersNames.add(object.get("reqUsername").toString());
130 | actualNames.add(object.get("reqActualName").toString());
131 | usersLocations.add(aUserLocation);
132 | distances.add(String.valueOf(distanceMiles));
133 | Log.i("Distance", String.valueOf(distanceMiles));
134 |
135 | } catch (JSONException e) {
136 | e.printStackTrace();
137 | }
138 | }
139 | } else if (t != null) {
140 | t.printStackTrace();
141 | }
142 | }
143 | });
144 |
145 | } catch (CloudException c) {
146 | c.printStackTrace();
147 | }
148 | }
149 | return null;
150 | }
151 |
152 | @Override
153 | protected void onPostExecute(Void aVoid) {
154 | super.onPostExecute(aVoid);
155 | if (resultGood) {
156 | if (downloadTaskType.equals("updateLocation")) {
157 | // Changes the listView
158 | arrayAdapter.notifyDataSetChanged();
159 | }
160 | }
161 | }
162 | }
163 |
164 | @Override
165 | protected void onCreate(Bundle savedInstanceState) {
166 | super.onCreate(savedInstanceState);
167 | setContentView(R.layout.activity_view_available);
168 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
169 | setSupportActionBar(toolbar);
170 | sharedPreferences = this.getSharedPreferences(getPackageName(), MODE_PRIVATE);
171 |
172 | locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
173 | provider = locationManager.getBestProvider(new Criteria(), false);
174 |
175 | // All location services
176 | locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 400, 1, this);
177 |
178 | requestActive = true;
179 | try {
180 | Location location = locationManager.getLastKnownLocation(provider);
181 | if (requestActive) {
182 | usersCurrentLocation = location;
183 | DownloadTask saveLocationTask = new DownloadTask();
184 | downloadTaskType = "updateLocation";
185 | saveLocationTask.execute("");
186 | }
187 | } catch (NullPointerException n) {
188 |
189 | }
190 |
191 | usersNames.addAll(distances);
192 | listView = (ListView) findViewById(R.id.listView);
193 | arrayAdapter = new ArrayAdapter(this, android.R.layout.simple_list_item_2, android.R.id.text1, usersNames) {
194 | @Override
195 | public View getView(int position, View convertView, ViewGroup parent) {
196 | View view = super.getView(position, convertView, parent);
197 |
198 | String entry1 = actualNames.get(position);
199 | String entry2 = distances.get(position);
200 |
201 | TextView text1 = (TextView) view.findViewById(android.R.id.text1);
202 | TextView text2 = (TextView) view.findViewById(android.R.id.text2);
203 | text1.setText(entry1);
204 | text2.setText(entry2);
205 |
206 | return view;
207 | }
208 | };
209 |
210 | listView.setAdapter(arrayAdapter);
211 |
212 | listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
213 | @Override
214 | public void onItemClick(AdapterView> parent, View view, int position, long id) {
215 | // Sends the clicked riders information to the 'ViewRiderLocation' activity
216 | Intent viewLocationIntent = new Intent(getApplicationContext(), ViewRiderLocation.class);
217 | viewLocationIntent.putExtra("riderUsername", usersNames.get(position));
218 | viewLocationIntent.putExtra("riderLat", usersLocations.get(position).getLatitude());
219 | viewLocationIntent.putExtra("riderLng", usersLocations.get(position).getLongitude());
220 | viewLocationIntent.putExtra("driverLat", usersCurrentLocation.getLatitude());
221 | viewLocationIntent.putExtra("driverLng", usersCurrentLocation.getLongitude());
222 | viewLocationIntent.putExtra("driverUsername", sharedPreferences.getString("currentUser", ""));
223 | startActivity(viewLocationIntent);
224 | Log.i("Username", usersNames.get(position));
225 | Log.i("Location", String.valueOf(usersLocations.get(position).getLatitude() + " " + usersLocations.get(position).getLongitude()));
226 | }
227 | });
228 | }
229 |
230 | @Override
231 | protected void onResume() {
232 | super.onResume();
233 | locationManager.requestLocationUpdates(provider, 400, 1, this);
234 | }
235 |
236 | @Override
237 | protected void onPause() {
238 | super.onPause();
239 | locationManager.removeUpdates(this);
240 | }
241 |
242 |
243 | @Override
244 | public void onLocationChanged(Location location) {
245 | // Updates user's location in the database
246 | if (requestActive) {
247 | usersCurrentLocation = location;
248 | DownloadTask saveLocationTask = new DownloadTask();
249 | downloadTaskType = "updateLocation";
250 | saveLocationTask.execute("");
251 | }
252 | }
253 |
254 | @Override
255 | public void onStatusChanged(String provider, int status, Bundle extras) {
256 |
257 | }
258 |
259 | @Override
260 | public void onProviderEnabled(String provider) {
261 |
262 | }
263 |
264 | @Override
265 | public void onProviderDisabled(String provider) {
266 | }
267 |
268 | @Override
269 | public void onBackPressed() {
270 | // Prevents the user from clicking the back button and returning to the signup page.
271 | }
272 |
273 |
274 | }
275 |
--------------------------------------------------------------------------------
/app/src/main/java/com/akashbhave/locomoto/YourLocation.java:
--------------------------------------------------------------------------------
1 | package com.akashbhave.locomoto;
2 |
3 | import android.app.NotificationManager;
4 | import android.app.PendingIntent;
5 | import android.content.Intent;
6 | import android.content.SharedPreferences;
7 | import android.location.Criteria;
8 | import android.location.Location;
9 | import android.location.LocationListener;
10 | import android.location.LocationManager;
11 | import android.os.AsyncTask;
12 | import android.os.Bundle;
13 | import android.os.Handler;
14 | import android.support.v4.app.FragmentActivity;
15 | import android.support.v4.app.NotificationCompat;
16 | import android.util.Log;
17 | import android.view.View;
18 | import android.widget.Button;
19 | import android.widget.TextView;
20 |
21 | import com.google.android.gms.maps.CameraUpdate;
22 | import com.google.android.gms.maps.CameraUpdateFactory;
23 | import com.google.android.gms.maps.GoogleMap;
24 | import com.google.android.gms.maps.OnMapReadyCallback;
25 | import com.google.android.gms.maps.SupportMapFragment;
26 | import com.google.android.gms.maps.model.BitmapDescriptor;
27 | import com.google.android.gms.maps.model.BitmapDescriptorFactory;
28 | import com.google.android.gms.maps.model.LatLng;
29 | import com.google.android.gms.maps.model.LatLngBounds;
30 | import com.google.android.gms.maps.model.Marker;
31 | import com.google.android.gms.maps.model.MarkerOptions;
32 |
33 | import org.json.JSONException;
34 | import org.json.JSONObject;
35 |
36 | import java.util.ArrayList;
37 |
38 | import io.cloudboost.CloudException;
39 | import io.cloudboost.CloudGeoPoint;
40 | import io.cloudboost.CloudObject;
41 | import io.cloudboost.CloudObjectArrayCallback;
42 | import io.cloudboost.CloudObjectCallback;
43 | import io.cloudboost.CloudQuery;
44 |
45 | public class YourLocation extends FragmentActivity implements OnMapReadyCallback, LocationListener {
46 |
47 | private GoogleMap mMap;
48 |
49 | LocationManager locationManager;
50 | String provider;
51 | // For saving the user's location
52 | Location usersCurrentLocation = new Location(provider);
53 | // A custom marker
54 | BitmapDescriptor locIcon1;
55 | BitmapDescriptor locIcon3;
56 |
57 | TextView requestStatusView;
58 | Button requestButton;
59 |
60 | // If user's request is still wanted
61 | boolean requestActive = false;
62 | Location driverLocation = new Location(provider);
63 |
64 | // Handler that will update the rider and driver's location in DownloadTask (downloadTaskType = 'saveLocation')
65 | Handler handler = new Handler();
66 | Handler anotherHandler = new Handler();
67 | Handler reqHandler = new Handler();
68 | Runnable reqRunnable;
69 |
70 | SharedPreferences sharedPreferences;
71 |
72 | String downloadTaskType = "";
73 |
74 | public class DownloadTask extends AsyncTask {
75 |
76 | boolean resultGood = false;
77 | String resultType = "";
78 | String resultType2 = "";
79 |
80 | double driverDistance;
81 | float driverBearing;
82 |
83 | @Override
84 | protected Void doInBackground(final String... params) {
85 | if (downloadTaskType.equals("request")) {
86 | try {
87 | final CloudGeoPoint riderLocation = new CloudGeoPoint(usersCurrentLocation.getLatitude(), usersCurrentLocation.getLongitude());
88 | final String[] reqActualName = new String[1];
89 |
90 | // Saves the requester's actual name
91 | CloudQuery actualNameObject = new CloudQuery("User");
92 | actualNameObject.equalTo("username", sharedPreferences.getString("currentUser", ""));
93 | actualNameObject.find(new CloudObjectArrayCallback() {
94 | @Override
95 | public void done(CloudObject[] x, CloudException t) throws CloudException {
96 | if (x != null) {
97 | for (CloudObject object : x) {
98 | reqActualName[0] = object.getString("actualName");
99 | }
100 | } else {
101 | t.printStackTrace();
102 | }
103 | }
104 | });
105 |
106 | CloudObject requestsObject = new CloudObject("Requests");
107 | requestsObject.set("reqUsername", sharedPreferences.getString("currentUser", ""));
108 | requestsObject.set("reqLocation", riderLocation);
109 | requestsObject.set("reqActualName", reqActualName[0]);
110 | requestsObject.save(new CloudObjectCallback() {
111 | @Override
112 | public void done(CloudObject x, CloudException t) throws CloudException {
113 | Log.i("Rider's Location", "Saved");
114 | Log.i("Rider Requester", "Saved");
115 | resultGood = true;
116 | requestActive = true;
117 | }
118 | });
119 |
120 | } catch (CloudException e) {
121 | e.printStackTrace();
122 | }
123 |
124 |
125 | } else if (downloadTaskType.equals("cancelRequest")) {
126 | try {
127 | // See who gave the request
128 | CloudQuery userQuery = new CloudQuery("Requests");
129 | Log.d("Cancel Request", "Executed");
130 | userQuery.equalTo("reqUsername", sharedPreferences.getString("currentUser", ""));
131 | userQuery.find(new CloudObjectArrayCallback() {
132 | @Override
133 | public void done(CloudObject[] x, CloudException t) throws CloudException {
134 | if (x != null) {
135 | for (CloudObject object : x) {
136 | object.delete(new CloudObjectCallback() {
137 | @Override
138 | public void done(CloudObject x, CloudException t) throws CloudException {
139 | if (x != null) {
140 | Log.i("Request", "Deleted");
141 | resultGood = true;
142 | } else {
143 | t.printStackTrace();
144 | }
145 | }
146 | });
147 | }
148 | } else {
149 | t.printStackTrace();
150 | }
151 | }
152 | });
153 | } catch (CloudException e) {
154 | e.printStackTrace();
155 | }
156 |
157 |
158 | } else if (downloadTaskType.equals("saveLocation")) {
159 | try {
160 | final CloudGeoPoint riderLocation = new CloudGeoPoint(usersCurrentLocation.getLatitude(), usersCurrentLocation.getLongitude());
161 | final String[] driverUsername = {""};
162 | // Updates the user's location
163 | CloudQuery userQuery = new CloudQuery("Requests");
164 | userQuery.equalTo("reqUsername", sharedPreferences.getString("currentUser", ""));
165 | userQuery.find(new CloudObjectArrayCallback() {
166 | @Override
167 | public void done(CloudObject[] x, CloudException t) throws CloudException {
168 | if (x != null) {
169 | for (CloudObject object : x) {
170 | driverUsername[0] = object.getString("driverUsername");
171 | object.set("reqLocation", riderLocation);
172 | object.save(new CloudObjectCallback() {
173 | @Override
174 | public void done(CloudObject x, CloudException t) throws CloudException {
175 | Log.i("Rider's Location", "Saved");
176 | resultGood = true;
177 | }
178 | });
179 | }
180 | } else {
181 | t.printStackTrace();
182 | }
183 | }
184 | });
185 |
186 | // Updates the driver's location
187 | CloudQuery driverQuery = new CloudQuery("User");
188 | driverQuery.equalTo("username", driverUsername[0]);
189 | driverQuery.find(new CloudObjectArrayCallback() {
190 | @Override
191 | public void done(CloudObject[] x, CloudException t) throws CloudException {
192 | if (x != null) {
193 | if (x.length > 0) {
194 | for (CloudObject object : x) {
195 | try {
196 | driverBearing = Float.parseFloat(object.getString("bearing"));
197 | JSONObject geopoint = new JSONObject(object.get("location").toString());
198 | // retrieve the coordinates
199 | String coordinates = geopoint.getString("coordinates").replace("[", "").replace("]", "");
200 | String[] latLng = coordinates.split(",");
201 | String stringLat = latLng[1].replace(",", "");
202 | String stringLng = latLng[0].replace(",", "");
203 | Double latitude = Double.parseDouble(stringLat);
204 | Double longitude = Double.parseDouble(stringLng);
205 | driverLocation.setLatitude(latitude);
206 | driverLocation.setLongitude(longitude);
207 | } catch (JSONException e) {
208 | e.printStackTrace();
209 | }
210 | }
211 | }
212 | } else {
213 | t.printStackTrace();
214 | }
215 | }
216 | });
217 |
218 | if (driverLocation.getLatitude() != 0 && driverLocation.getLongitude() != 0) {
219 | Log.i("Driver Location", driverLocation.getLatitude() + "," + driverLocation.getLongitude());
220 | double distance = usersCurrentLocation.distanceTo(driverLocation);
221 | driverDistance = (double) (Math.round((distance * 0.000621371) * 100) / 100);
222 | resultGood = true;
223 | resultType = "driverDistance";
224 | if (driverDistance == 0) {
225 | resultType = "driverDistance0";
226 | // Make a notification when the driver has arrived
227 | final NotificationCompat.Builder nBuilder =
228 | new NotificationCompat.Builder(getApplicationContext())
229 | .setSmallIcon(R.drawable.location1)
230 | .setContentTitle("Your Driver is Here!")
231 | .setContentText("Your driver has arrived at your location.")
232 | .setVibrate(new long[]{0, 1000, 500, 1000, 500})
233 | .setAutoCancel(true);
234 | // Intent that executes when you click on the notification
235 | Intent resultIntent = new Intent(getApplicationContext(), YourLocation.class);
236 | PendingIntent pendingIntent = PendingIntent.getActivity(
237 | getApplicationContext(),
238 | 0,
239 | resultIntent,
240 | PendingIntent.FLAG_UPDATE_CURRENT
241 | );
242 | nBuilder.setContentIntent(pendingIntent);
243 | // Issues the notification
244 | int mNotificationId = 1; // Sets an ID for the notification
245 |
246 | final NotificationManager mNotifyMgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
247 | // Builds the notification and issues it.
248 | mNotifyMgr.notify(mNotificationId, nBuilder.build());
249 |
250 | anotherHandler.postDelayed(new Runnable() {
251 | @Override
252 | public void run() {
253 | // Resets the location so the vibration stops
254 | driverLocation = new Location(provider);
255 | DownloadTask cancelRequestTask = new DownloadTask();
256 | downloadTaskType = "cancelRequest";
257 | cancelRequestTask.execute("");
258 | }
259 | }, 3000);
260 | }
261 | }
262 | } catch (CloudException e) {
263 | e.printStackTrace();
264 | }
265 |
266 | handler.postDelayed(new Runnable() {
267 | @Override
268 | public void run() {
269 | if (requestActive) {
270 | DownloadTask updateLocations = new DownloadTask();
271 | downloadTaskType = "saveLocation";
272 | updateLocations.execute("");
273 | } else {
274 | Log.i("Update Runnable", "Stopped");
275 | handler.removeCallbacksAndMessages(null);
276 | }
277 | }
278 | }, 5000);
279 | } else if (downloadTaskType.equals("getCurrentRequests")) {
280 | CloudQuery myRequests = new CloudQuery("Requests");
281 | myRequests.equalTo("reqUsername", sharedPreferences.getString("currentUser", ""));
282 | try {
283 | myRequests.find(new CloudObjectArrayCallback() {
284 | @Override
285 | public void done(CloudObject[] x, CloudException t) throws CloudException {
286 | if (x != null) {
287 | if (x.length > 0) {
288 | Log.i("My Requests Amount", String.valueOf(x.length));
289 | for (CloudObject object : x) {
290 | try {
291 | String possibleTerm = object.get("driverUsername").toString();
292 | if (possibleTerm == null || possibleTerm.equals("")) {
293 |
294 | } else {
295 | String driverUsername = object.getString("driverUsername");
296 | Log.i("My Requests", "Driver Accepted: " + driverUsername);
297 | resultGood = true;
298 | resultType2 = "yes";
299 | reqHandler.removeCallbacksAndMessages(reqRunnable);
300 | }
301 | } catch (NullPointerException n) {
302 | Log.i("My Requests", "Driver Hasn't Accepted");
303 | resultGood = true;
304 | resultType2 = "no";
305 |
306 | reqRunnable = new Runnable() {
307 | @Override
308 | public void run() {
309 | DownloadTask seeRequestsTask = new DownloadTask();
310 | downloadTaskType = "getCurrentRequests";
311 | seeRequestsTask.execute("");
312 | }
313 | };
314 | reqHandler.postDelayed(reqRunnable, 5000);
315 | }
316 | }
317 | } else {
318 | Log.i("My Requests", "None");
319 | requestActive = false;
320 | }
321 | } else {
322 | t.printStackTrace();
323 | }
324 | }
325 | });
326 | } catch (CloudException e) {
327 | e.printStackTrace();
328 | }
329 | }
330 |
331 | return null;
332 | }
333 |
334 | @Override
335 | protected void onPostExecute(Void aVoid) {
336 | super.onPostExecute(aVoid);
337 | if (resultGood) {
338 | if (downloadTaskType.equals("request")) {
339 | if (resultGood) {
340 | requestStatusView.setText("Finding a driver...");
341 | requestButton.setVisibility(View.VISIBLE);
342 | requestButton.setText("Cancel Request");
343 | requestActive = true;
344 | DownloadTask seeRequestsTask = new DownloadTask();
345 | downloadTaskType = "getCurrentRequests";
346 | seeRequestsTask.execute("");
347 | } else {
348 | Log.i("Request Ride", "Not Successful");
349 | }
350 | } else if (downloadTaskType.equals("cancelRequest")) {
351 | requestStatusView.setVisibility(View.INVISIBLE);
352 | requestButton.setVisibility(View.VISIBLE);
353 | requestButton.setText("Request Ride");
354 |
355 | } else if (downloadTaskType.equals("saveLocation")) {
356 | if (resultGood) {
357 | Marker driverMarker = mMap.addMarker(new MarkerOptions().position(new LatLng(0, 0)));
358 | if (resultType.equals("driverDistance")) {
359 | requestStatusView.setText("Your driver is " + String.valueOf(driverDistance) + " miles away.");
360 | requestStatusView.setVisibility(View.VISIBLE);
361 |
362 | // Ensures the two markers are in view
363 | mMap.clear();
364 | LatLngBounds.Builder builder = new LatLngBounds.Builder();
365 | ArrayList markers = new ArrayList();
366 | markers.add(mMap.addMarker(new MarkerOptions().position(new LatLng(usersCurrentLocation.getLatitude(), usersCurrentLocation.getLongitude()))
367 | .title("Your Location")
368 | .icon(locIcon1)));
369 | driverMarker = mMap.addMarker(new MarkerOptions().position(new LatLng(driverLocation.getLatitude(), driverLocation.getLongitude()))
370 | .title("Rider's Location")
371 | .icon(locIcon3)
372 | .rotation(driverBearing)
373 | .anchor(0.5f, 0.5f));
374 | markers.add(driverMarker);
375 |
376 | for (Marker marker : markers) {
377 | builder.include(marker.getPosition());
378 | }
379 | LatLngBounds bounds = builder.build();
380 | int padding = 100; // offset from edges of the map in pixels
381 | CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, padding);
382 | mMap.animateCamera(cu);
383 | } else if (resultType.equals("driverDistance0")) {
384 | requestActive = false;
385 | requestStatusView.setText("Your driver has arrived!");
386 | requestStatusView.setVisibility(View.VISIBLE);
387 | requestButton.setText("Request Ride");
388 | requestButton.setVisibility(View.VISIBLE);
389 | driverMarker.remove();
390 | }
391 | }
392 | } else if (downloadTaskType.equals("getCurrentRequests")) {
393 | if (resultGood) {
394 | if (resultType2.equals("yes")) {
395 | requestStatusView.setText("A driver is on their way!");
396 | requestButton.setVisibility(View.INVISIBLE);
397 | DownloadTask startUpdatingTask = new DownloadTask();
398 | downloadTaskType = "saveLocation";
399 | startUpdatingTask.execute("");
400 | } else {
401 | requestStatusView.setText("Finding a driver...");
402 | requestButton.setVisibility(View.VISIBLE);
403 | }
404 | requestButton.setText("Cancel Request");
405 | requestStatusView.setVisibility(View.VISIBLE);
406 | }
407 | }
408 | }
409 | }
410 | }
411 |
412 | public void requestRide(View view) {
413 | if (requestActive) {
414 | requestActive = false;
415 | downloadTaskType = "cancelRequest";
416 | Log.i("Rider Map", "Ride Cancelled");
417 | DownloadTask cancelRequestTask = new DownloadTask();
418 | cancelRequestTask.execute("");
419 | } else {
420 | requestStatusView.setVisibility(View.VISIBLE);
421 | downloadTaskType = "request";
422 | Log.i("Rider Map", "Ride Requested");
423 | DownloadTask requestRideTask = new DownloadTask();
424 | requestRideTask.execute("");
425 | }
426 | }
427 |
428 | @Override
429 | protected void onCreate(Bundle savedInstanceState) {
430 | super.onCreate(savedInstanceState);
431 | setContentView(R.layout.activity_your_location);
432 | // Obtain the SupportMapFragment and get notified when the map is ready to be used.
433 | SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
434 | .findFragmentById(R.id.map);
435 | mapFragment.getMapAsync(this);
436 |
437 | requestStatusView = (TextView) findViewById(R.id.requestStatusView);
438 | requestButton = (Button) findViewById(R.id.requestButton);
439 |
440 | sharedPreferences = this.getSharedPreferences(getPackageName(), MODE_PRIVATE);
441 | Log.i("My Username", sharedPreferences.getString("currentUser", ""));
442 |
443 | locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
444 | provider = locationManager.getBestProvider(new Criteria(), false);
445 | locIcon1 = BitmapDescriptorFactory.fromResource(R.drawable.location1);
446 | locIcon3 = BitmapDescriptorFactory.fromResource(R.drawable.location3);
447 |
448 | // All location services
449 | locationManager.requestLocationUpdates(provider, 400, 1, this);
450 |
451 | try {
452 | Location location = locationManager.getLastKnownLocation(provider);
453 | //if (location != null) {
454 | if (requestActive) {
455 | usersCurrentLocation = location;
456 | DownloadTask saveLocationTask = new DownloadTask();
457 | downloadTaskType = "saveLocation";
458 | saveLocationTask.execute("");
459 | } else {
460 | // Checks to see if there are any current requests made by the current user
461 | usersCurrentLocation = location;
462 | DownloadTask getCurrentRequestsTask = new DownloadTask();
463 | downloadTaskType = "getCurrentRequests";
464 | getCurrentRequestsTask.execute("");
465 | }
466 | //}
467 | usersCurrentLocation = location;
468 | Log.i("Users Location", location.getLatitude() + " " + location.getLongitude());
469 | mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(location.getLatitude(), location.getLongitude()), 10));
470 | mMap.addMarker(new MarkerOptions().position(new LatLng(location.getLatitude(), location.getLongitude())).title("Your Location").icon(locIcon1));
471 | } catch (NullPointerException n) {
472 |
473 | }
474 | }
475 |
476 | @Override
477 | protected void onResume() {
478 | super.onResume();
479 | locationManager.requestLocationUpdates(provider, 400, 1, this);
480 | }
481 |
482 | @Override
483 | protected void onPause() {
484 | super.onPause();
485 | locationManager.removeUpdates(this);
486 | }
487 |
488 | /**
489 | * Manipulates the map once available.
490 | * This callback is triggered when the map is ready to be used.
491 | * This is where we can add markers or lines, add listeners or move the camera. In this case,
492 | * we just add a marker near Sydney, Australia.
493 | * If Google Play services is not installed on the device, the user will be prompted to install
494 | * it inside the SupportMapFragment. This method will only be triggered once the user has
495 | * installed Google Play services and returned to the app.
496 | */
497 | @Override
498 | public void onMapReady(GoogleMap googleMap) {
499 | mMap = googleMap;
500 |
501 | mMap.clear();
502 | mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(usersCurrentLocation.getLatitude(), usersCurrentLocation.getLongitude()), 10));
503 | mMap.addMarker(new MarkerOptions()
504 | .position(new LatLng(usersCurrentLocation.getLatitude(), usersCurrentLocation.getLongitude()))
505 | .title("Your Location")
506 | .icon(locIcon1));
507 | }
508 |
509 | @Override
510 | public void onLocationChanged(Location location) {
511 | Log.i("Users Updated Location", location.getLatitude() + " " + location.getLongitude());
512 | mMap.clear();
513 | mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(location.getLatitude(), location.getLongitude()), 10));
514 | mMap.addMarker(new MarkerOptions().position(new LatLng(location.getLatitude(), location.getLongitude())).title("Your Location").icon(locIcon1));
515 |
516 | // Updates user's location in the database
517 | if (requestActive) {
518 | usersCurrentLocation = location;
519 | DownloadTask saveLocationTask = new DownloadTask();
520 | downloadTaskType = "saveLocation";
521 | saveLocationTask.execute("");
522 | }
523 | }
524 |
525 | @Override
526 | public void onStatusChanged(String provider, int status, Bundle extras) {
527 |
528 | }
529 |
530 | @Override
531 | public void onProviderEnabled(String provider) {
532 |
533 | }
534 |
535 | @Override
536 | public void onProviderDisabled(String provider) {
537 |
538 | }
539 |
540 | @Override
541 | public void onBackPressed() {
542 | // Prevents the user from clicking the back button and returning to the signup page.
543 | }
544 | }
545 |
--------------------------------------------------------------------------------