Skip to content

Commit

Permalink
added real time tracking of bus to user
Browse files Browse the repository at this point in the history
  • Loading branch information
aravindiiitb committed Apr 23, 2016
1 parent d408eb1 commit f5a2c9d
Show file tree
Hide file tree
Showing 20 changed files with 382 additions and 100 deletions.
29 changes: 28 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="@string/google_maps_key" />

<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
Expand Down Expand Up @@ -85,6 +84,15 @@
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.perseus14.vehicletracking.DriverLogin" />
</activity>
<activity
android:name=".AccountSettings"
android:label="@string/title_activity_account_settings"
android:parentActivityName=".ProfileActivity"
android:theme="@style/AppTheme.NoActionBar">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.perseus14.vehicletracking.ProfileActivity" />
</activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
package com.example.perseus14.vehicletracking;

import android.app.ProgressDialog;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

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

import java.util.HashMap;

public class AccountSettings extends AppCompatActivity {

EditText edtFname, edtEmail, edtPass, edtBusRadius, edtMobileNum;

String first_name, email, password, bus_radius, mobile_num;
Button btnUpdate;
UserLocalStore userLocalStore;
JSONParser jsonParser = new JSONParser();
ProgressDialog pDialog;
ModelUser modelUser;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_account_settings);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
getSupportActionBar().setDisplayHomeAsUpEnabled(true);

edtFname = (EditText) findViewById(R.id.username);
edtMobileNum = (EditText) findViewById(R.id.mobileNum);
edtEmail = (EditText) findViewById(R.id.email_id);
edtPass = (EditText) findViewById(R.id.password);
edtBusRadius = (EditText) findViewById(R.id.busRadius);

userLocalStore = new UserLocalStore(this);
modelUser = userLocalStore.getLoggedInUser();

edtBusRadius.setText(String.valueOf(modelUser.bus_radius));
edtPass.setText(modelUser.password);
edtEmail.setText(modelUser.email);
edtFname.setText(modelUser.name);
edtMobileNum.setText(modelUser.mobile_num);

btnUpdate = (Button) findViewById(R.id.update);

btnUpdate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new UpdateUserDetails().execute(Config.URL_UPDATE_USER_DETAILS);
}
});
}

class UpdateUserDetails extends AsyncTask<String,String,String>{
Boolean flag = false;
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(AccountSettings.this);
pDialog.setMessage("Updating your details ..");
pDialog.setIndeterminate(false);
pDialog.setCancelable(false);
pDialog.show();

first_name = edtFname.getText().toString();
password = edtPass.getText().toString();
email = edtEmail.getText().toString();
bus_radius = edtBusRadius.getText().toString();
mobile_num = edtMobileNum.getText().toString();
}

@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
if(flag){
Toast.makeText(getApplicationContext(), "For security reasons you have been logged out please login again", Toast.LENGTH_SHORT).show();
}
}

@Override
protected String doInBackground(String... params) {
HashMap<String, String> data = new HashMap<>();
data.put("name",first_name);
data.put("email", email);
data.put("password",password);
data.put("bus_radius",bus_radius);
data.put("mobile_num", mobile_num);
data.put("user_id", String.valueOf(modelUser.id));

try {
JSONObject jsonObject = jsonParser.makeHttpRequest(Config.URL_UPDATE_USER_DETAILS,"POST",data);
int success = jsonObject.getInt("success");
if(success == 1){
flag = true;
Intent intent = new Intent(getApplicationContext(),LoginActivity.class);
startActivity(intent);
}
} catch (JSONException e){
e.printStackTrace();
}
return null;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public Config(){
}
public static String URL_CREATE_USER = "http://vehicletracking.netau.net/create_user.php";
public static String URL_LOGIN_USER = "http://vehicletracking.netau.net/check_user.php";
//public static String URL_GET_ALL_BUSSES = "http://vehicletracking.netau.net/check_user.php";
public static String URL_UPDATE_USER_DETAILS = "http://vehicletracking.netau.net/update_user_details.php";
public static String URL_CHECK_BUS = "http://vehicletracking.netau.net/check_bus_details.php";
public static String URL_SEARCH_BUS = "http://vehicletracking.netau.net/search_bus.php";
public static String URL_UPDATE_BUS_COORDINATES = "http://vehicletracking.netau.net/update_bus_coordinates.php";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,15 @@ public void onClick(View v) {
}
});

bus_occup_level.setText("Bus Occupancy: " + String.valueOf(modelBusData.bus_occupancy_level));
if(modelBusData.bus_occupancy_level == 0){
bus_occup_level.setText("Bus Occupancy: low");
}
else if(modelBusData.bus_occupancy_level == 1){
bus_occup_level.setText("Bus Occupancy: Medium");
}
else{
bus_occup_level.setText("Bus Occupancy: High");
}
bus_reg_num.setText("Bus Registraion Num: " + modelBusData.bus_reg_num);
bus_ser_num.setText("Bus Service Num: " + modelBusData.bus_service_num);
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ protected String doInBackground(String... params) {
returnedUser.name = user.getString("name");
returnedUser.password = user.getString("password");
returnedUser.email = user.getString("email");

returnedUser.bus_radius = user.getInt("bus_radius");
returnedUser.mobile_num = user.getString("mobile_num");

userLocalStore.storeUserData(returnedUser);
userLocalStore.setUserLoggedIn(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ public class ModelUser implements Serializable {
public String email;
public String password;
public int id;
public int bus_radius;
public String mobile_num;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.example.perseus14.vehicletracking;

import android.app.AlertDialog;
import android.app.Fragment;
import android.app.FragmentManager;
import android.content.Context;
Expand Down Expand Up @@ -31,6 +32,7 @@
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.CameraPosition;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
Expand Down Expand Up @@ -71,8 +73,11 @@ protected void onCreate(Bundle savedInstanceState) {
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(ProfileActivity.this);
dialogBuilder.setMessage("You will now receive a SMS notification if the bus comes closer");
dialogBuilder.setPositiveButton("Ok", null);
dialogBuilder.setTitle("SMS Notification");
dialogBuilder.show();
}
});
userLocalStore = new UserLocalStore(this);
Expand All @@ -98,7 +103,7 @@ public void onClick(View view) {
email = (TextView) header.findViewById(R.id.email_id);
mHandler = new Handler();

//startRepeatingTask();
startRepeatingTask();

name.setText(userLocalStore.getLoggedInUser().name);
email.setText(userLocalStore.getLoggedInUser().email);
Expand All @@ -110,12 +115,11 @@ public void onClick(View v) {
});
}

/*Runnable mHandlerTask = new Runnable() {
Runnable mHandlerTask = new Runnable() {
@Override
public void run() {
Toast.makeText(getApplicationContext(),"This is " + i + "time",Toast.LENGTH_LONG).show();
i++;
mHandler .postDelayed(mHandlerTask,5000);
new ShowBuses().execute(Config.URL_SEARCH_BUS);
mHandler.postDelayed(mHandlerTask,5000);
}
};

Expand All @@ -128,7 +132,7 @@ void startRepeatingTask()
void stopRepeatingTask()
{
mHandler.removeCallbacks(mHandlerTask);
}*/
}

class ShowBuses extends AsyncTask<String,String,String> {
@Override
Expand Down Expand Up @@ -227,15 +231,16 @@ public boolean onNavigationItemSelected(MenuItem item) {
if (id == R.id.nav_camera) {
// Handle the camera action
} else if (id == R.id.nav_gallery) {
fragment = new HomeFragment();

} else if (id == R.id.nav_slideshow) {

} else if (id == R.id.nav_manage) {

} else if (id == R.id.nav_share) {

Intent intent = new Intent(this,AccountSettings.class);
startActivity(intent);
} else if (id == R.id.nav_send) {
//stopRepeatingTask();
stopRepeatingTask();
userLocalStore.clearUserData();
userLocalStore.setUserLoggedIn(false);
startActivity(new Intent(this,LoginActivity.class));
Expand Down Expand Up @@ -311,7 +316,20 @@ void plotPointsOnMap(){
LatLng latLng1 = new LatLng(Double.parseDouble(requestList.get(i).get("bus_lat")),Double.parseDouble(requestList.get(i).get("bus_long")));
MarkerOptions marker = new MarkerOptions();
marker.position(latLng1);
marker.title("Service Num: " + requestList.get(i).get("bus_service_num") + "Regis Num: " + requestList.get(i).get("bus_reg_num") + "Occupancy: "+ requestList.get(i).get("bus_occupancy_level"));
int occupancyLevel = Integer.parseInt(requestList.get(i).get("bus_occupancy_level"));
if(occupancyLevel == 0){
//marker.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN));
marker.icon(BitmapDescriptorFactory.fromResource(R.drawable.busstop));
marker.title("Regis Num: " + requestList.get(i).get("bus_reg_num") + "Occupancy: Less");
}
else if(occupancyLevel == 1){
marker.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_YELLOW));
marker.title("Regis Num: " + requestList.get(i).get("bus_reg_num") + "Occupancy: Medium");
}
else {
marker.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED));
marker.title("Regis Num: " + requestList.get(i).get("bus_reg_num") + "Occupancy: High");
}
mMap.addMarker(marker);
}
}
Expand Down
Loading

0 comments on commit f5a2c9d

Please sign in to comment.