Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,30 @@ android {
targetSdkVersion 26
versionCode 1
versionName "1.0"
multiDexEnabled true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
renderscriptTargetApi 18
renderscriptSupportModeEnabled true
}
buildTypes {
release {
minifyEnabled false

proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support:cardview-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.google.android.gms:play-services-maps:11.8.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
compile 'com.android.volley:volley:1.0.0'
compile "com.google.android.gms:play-services-location:11.8.0"

compile 'com.google.android.gms:play-services-location:11.8.0'
implementation 'com.google.android.gms:play-services:12.0.1'
}
2 changes: 2 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
<activity
android:name=".MapsActivity"
android:label="@string/title_activity_maps"></activity>

<service android:name=".MapsActivity" />
</application>

</manifest>
201 changes: 61 additions & 140 deletions app/src/main/java/com/example/a/myapplication/Car.java
Original file line number Diff line number Diff line change
@@ -1,164 +1,85 @@
package com.example.a.myapplication;

import android.content.Context;
import android.util.Log;
import android.view.View;
import android.widget.Toast;

import com.android.volley.AuthFailureError;
import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.google.android.gms.maps.model.LatLng;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static android.content.ContentValues.TAG;

/**
* Created by user on 05/04/2018.
*/

public class Car {

LocationObject position;
private String carID;
LocationObject location;
private int carID;
private int driverID;
private String driverName;
List<Car> neighbourCars=new ArrayList<>();

public Car(LocationObject pos, int dID) {
this.position = pos;
this.driverID = dID;
}

public Car(LocationObject pos, String cID, int dID) {
this.position = pos;
public Car(int carID, int driverID)
{
this.carID = carID;
this.driverID = driverID;
}
public Car(LocationObject pos, int cID, int dID)
{
this.location = pos;
this.carID = cID;
this.driverID = dID;
}

public LocationObject getPosition() {return this.getPosition();}

public Car(LocationObject neighbourPosition, String driverName, int neighbourDriverID)
{
this.location = neighbourPosition;
this.driverName = driverName;
this.driverID = neighbourDriverID;
}

public String getCarID() {return carID;}
public void setCarID(String carID) {this.carID = carID;}
public LocationObject getPosition() {return this.getPosition();}

public int getCarID() {return carID;}
public int getDriverID() {return driverID;}

public void setCarID(int carID) {this.carID = carID;}
public void setDriverID(int driverID) {this.driverID = driverID;}

// public void setInformation()
// {
// int userID=SharedPrefManager.getInstance(this).getUserId();
// driver.setID(userID);
// carID=SharedPrefManager.getInstance(getApplicationContext()).getCarId();
// }
//
// private void setLocation(final LocationObject locationObject){
//
// latitude=locationObject.getLatitude();
// longitude=locationObject.getLongitude();
// altitude=locationObject.getAltitude();
//
// StringRequest stringRequest = new StringRequest(
// Request.Method.POST,
// Constants.LOCATION_SET,
// new Response.Listener<String>() {
// @Override
// public void onResponse(String response) {
// try {
// JSONObject obj = new JSONObject(response);
// if(!obj.getBoolean("error"))
// {
// }
// else
// {
//
// }
// } catch (JSONException e) {
// e.printStackTrace();
// }
// }
// },
// new Response.ErrorListener() {
// @Override
// public void onErrorResponse(VolleyError error)
// {
//
// }
// }
// ){
// @Override
// protected Map<String, String> getParams() throws AuthFailureError {
// String timeStamp = new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss").format(new java.util.Date());
//
// Map<String, String> params = new HashMap<>();
// params.put("latitude", String.valueOf(latitude));
// params.put("longitude", String.valueOf(longitude));
// params.put("altitude", String.valueOf(altitude));
// params.put("userID", String.valueOf(driver.getID()));
// params.put("carID", String.valueOf(carID));
// params.put("locationTime", timeStamp);
//
// return params;
// }
//
// };
//
// RequestHandler.getInstance(this).addToRequestQueue(stringRequest);
// }
//
//
// public List<Car> getNeighbours(View view)
// {
// List<Car> cars=new ArrayList<>();
//
// LocationManipulating locationManipulating=new LocationManipulating(getApplicationContext());
// LocationObject currentLocation=locationManipulating.getLocation();
// setLocation(currentLocation);
// cars = getNeighboursFromDb(driver.getID(),currentLocation);
//
// return cars;
// }
//
// public List<Car> getNeighboursFromDb(int userID, final LocationObject curr)
// {
// //final JSONObject retJSON;
// List<Car> cars=new ArrayList<>();
// StringRequest stringRequest = new StringRequest(
// Request.Method.POST,
// Constants.URL_NEIGBOURS,
// new Response.Listener<String>() {
// @Override
// public void onResponse(String response) {
//
// try {
// JSONObject obj = new JSONObject(response);
// //retJSON=new JSONObject(response);
// if(!obj.getBoolean("error"))
// {
//
// // finish();
// }
// else{
//
// }
// } catch (JSONException e) {
// }
// }
// },
// new Response.ErrorListener() {
// @Override
// public void onErrorResponse(VolleyError error) {
//
//
// }
// }
// ){
// @Override
// protected Map<String, String> getParams() throws AuthFailureError {
// String timeStamp = new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss").format(new java.util.Date());
//
// Map<String, String> params = new HashMap<>();
// params.put("latitude", String.valueOf(curr.getLatitude()));
// params.put("longitude", String.valueOf(curr.getLongitude()));
// params.put("altitude", String.valueOf(curr.getAltitude()));
// params.put("userID", String.valueOf(SharedPrefManager.getInstance(getApplicationContext()).getUserId()));
// //params.put("carID", String.valueOf(SharedPrefManager.getInstance(getApplicationContext()).getCarId()));
// //params.put("locationTime", timeStamp);
//
// return params;
// }
//
// };
//
// RequestHandler.getInstance(this).addToRequestQueue(stringRequest);
// return cars;
// }
public void setLocation(Context ctx,LocationObject locationObject, Driver driver)
{
carID=this.getCarID();
driverID=this.getDriverID();
DatabaseOperations dbOperations = new DatabaseOperations();;
location=locationObject;
Log.d("Car: location is"," latitude "+location.getLatitude()+" longitude "+location.getLongitude()+" altitude "+location.getAltitude());
dbOperations.addLocationToDB(ctx, location,carID,driverID);
}

public List<Car> getNeighbours(Context ctx,int driverID,LocationObject driverLocation)
{
DatabaseOperations dbOperations=new DatabaseOperations();
Log.d("Car Class "," getNeighbours");
neighbourCars = dbOperations.getNeighboursFromDb(ctx,driverID,driverLocation);
return neighbourCars;
}

}
Loading