use of com.google.firebase.database.DatabaseReference in project GogoNew by kuldeep725.
the class MapsActivity method pickMe.
public void pickMe(View view) {
showInternetStatus();
if (!isInternetOn())
return;
if (!isWindowReady)
return;
if (null != mCurrentLocation && checkBusSelection != 0) {
Log.d(TAG, "pickMe fired...");
Log.d(TAG, "theKey = " + theKey);
BUS = "b" + checkBusSelection;
pickMeRadioButton = radiobutton;
pickMeBusDistance = distance.getText().toString().trim();
Log.e(TAG, "BUS (pickme before) = " + BUS);
if (pickMeRadioButton != null) {
pickMeRadioButton.setTypeface(Typeface.DEFAULT_BOLD);
pickMeRadioButton.setTextColor(getResources().getColor(R.color.primeColor));
}
String lat = String.valueOf(mCurrentLocation.getLatitude());
String lng = String.valueOf(mCurrentLocation.getLongitude());
findNearestBusStop();
Log.d(TAG, "findNearestBusStop has now STOPPED");
// Log.e(TAG, "BUS (pickme after) = " + BUS);
DatabaseReference routeDatabase = FirebaseDatabase.getInstance().getReference().child(USER).child(BUS).child("route");
/*NOTE : addListenerForSingleValueEvent runs only after all the instances of onChildAdded have been run*/
DatabaseReference vehicleDatabase = FirebaseDatabase.getInstance().getReference().child(VEHICLE).child(BUS);
// routeDatabase.addListenerForSingleValueEvent(new ValueEventListener() {
vehicleDatabase.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if (minName != null) {
Log.d(TAG, "minName = " + minName);
status = (String) dataSnapshot.child(minName).child("status").getValue();
Log.d(TAG, "status = " + status);
if (checkBusSelection != 0) {
// Log.d(TAG, "WE ARE INSIDE NOW....");
userDatabase = mDatabase.child(VEHICLE).child(BUS);
Map<String, String> userData = new HashMap<>();
if (minLocation == null) {
Log.d(TAG, "minLocation is NULL :(");
minLocation = mCurrentPosition;
}
minMarker = markerMap.get(minLocation);
if (minMarker != null) {
minMarker.remove();
if (mMap != null) {
minMarker = mMap.addMarker(new MarkerOptions().position(minLocation).title(markerNameList.get(minLocation)));
minMarker.setIcon(BitmapDescriptorFactory.fromResource(R.drawable.green_stop_10));
}
}
if (minName == null) {
minName = "bus stop";
}
Log.d(TAG, "minLocation.latitude = " + minLocation.latitude);
Log.d(TAG, "minLocation.longitude = " + minLocation.longitude);
Log.d(TAG, "minDistance = " + minDistance);
userData.put(LATITUDE, String.valueOf(minLocation.latitude));
userData.put(LONGITUDE, String.valueOf(minLocation.longitude));
if (theKey == null)
theKey = userDatabase.push().getKey();
Map<String, Map<String, String>> mSendingData = new HashMap<>();
mSendingData.put("LOCATION", userData);
/*Map<String, Map<String, Map<String, String>>> mFinalData = new HashMap<>();
mFinalData.put(INTERMEDIATE, mSendingData);*/
Log.e(TAG, "status = " + status);
if (status == null)
userDatabase.child(minName).child("status").setValue("0");
userDatabase.child(minName).child(theKey).setValue(mSendingData);
double difference = CalculationByDistance(new LatLng(latitudeBus, longitudeBus), minLocation);
Log.e(TAG, "difference = " + difference);
String differenceStr = "Bus " + checkBusSelection + " is at distance " + String.format(Locale.US, "%.2f", difference) + " km" + " from " + markerNameList.get(minLocation);
String toastString = "Request sent for " + markerNameList.get(minLocation);
Toast.makeText(MapsActivity.this, toastString, Toast.LENGTH_SHORT).show();
Toast.makeText(MapsActivity.this, differenceStr, Toast.LENGTH_SHORT).show();
pickMeBusDistance = "";
// floatingButton.setBackgroundTintList(ColorStateList.valueOf(getResources().getColor(R.color.primeColorOld)));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
// floatingButton.setBackground(getResources().getDrawable(R.drawable.ic_cancel_white_24dp));
floatingButton.setImageResource(R.drawable.ic_cancel_white_24dp);
// floatingButton.setBackgroundColor(Color.parseColor("#ff0000"));
floatingButton.setBackgroundTintList(ColorStateList.valueOf(getResources().getColor(R.color.myRed)));
}
pickMeDone = true;
Log.d(TAG, "findNearestBusStop has STOPPED");
} else {
Log.d(TAG, "location is null ...............");
}
// }
// @Override
// public void onCancelled(DatabaseError databaseError) {
//
// }
// });
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
}
use of com.google.firebase.database.DatabaseReference in project GogoNew by kuldeep725.
the class MapsActivity method signingOut.
private void signingOut() {
radiobuttonId = 0;
if (pickMeRadioButton != null) {
pickMeRadioButton.setTypeface(Typeface.DEFAULT);
pickMeRadioButton.setTextColor(Color.BLACK);
pickMeRadioButton = null;
if (theKey == null)
return;
DatabaseReference userDatabase = mDatabase.child(VEHICLE).child(BUS).child(theKey);
Log.d(TAG, "AWESOME @ = " + userDatabase.toString());
userDatabase.removeValue();
Log.d(TAG, "AWESOME2 @ = " + userDatabase.toString());
Toast.makeText(MapsActivity.this, "REQUEST ENDED", Toast.LENGTH_SHORT).show();
theKey = null;
}
Intent i = new Intent(MapsActivity.this, Login.class);
FirebaseAuth.getInstance().signOut();
progressDialog.setTitle("Catch App");
progressDialog.setMessage("Logging Out...");
progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
progressDialog.show();
progressDialog.setCancelable(true);
new Thread(new Runnable() {
public void run() {
try {
Thread.sleep(5000);
} catch (Exception e) {
e.printStackTrace();
}
if (progressDialog != null) {
progressDialog.dismiss();
progressDialog = null;
}
}
}).start();
startActivity(i);
finish();
}
use of com.google.firebase.database.DatabaseReference in project GogoNew by kuldeep725.
the class MapsActivity method showDistanceInBetween.
private void showDistanceInBetween() {
Log.e(TAG, "showDistanceInBetween fired...");
String BUS = "b" + checkBusSelection;
mDatabase = FirebaseDatabase.getInstance().getReference();
final DatabaseReference userDatabase = mDatabase.child(USER).child(BUS).child(LOCATION);
showInternetStatus();
if (!isInternetOn())
return;
userDatabase.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
String bus = "b" + checkBusSelection;
if (!userDatabase.toString().equals(mDatabase.child(USER).child(bus).child(LOCATION).toString()))
return;
GenericTypeIndicator<Map<String, String>> genericTypeIndicator = new GenericTypeIndicator<Map<String, String>>() {
};
Map<String, String> map = dataSnapshot.getValue(genericTypeIndicator);
// Log.d(TAG, "Data : " + dataSnapshot.getValue());
if (mCurrentLocation == null)
return;
assert map != null;
String latitudeStr = map.get("latitude");
String longitudeStr = map.get("longitude");
latitudeBus = Double.parseDouble(latitudeStr);
longitudeBus = Double.parseDouble(longitudeStr);
// Log.d(TAG, "mCurrentLocation = "+mCurrentLocation);
if (flagShowDistanceInBetween == 0) {
if (mCurrentLocation != null) {
flagShowDistanceInBetween = 1;
String url = "https://maps.googleapis.com/maps/api/directions/json?origin=" + mCurrentLocation.getLatitude() + "," + mCurrentLocation.getLongitude() + "&destination=" + latitudeStr + "," + longitudeStr + // + R.string.google_direction_api_key;
"&key=AIzaSyChXllnUaESuRZPDpSHtb3oyXgL1edHITg";
/*String url = "https://maps.googleapis.com/maps/api/directions/json?origin="
+ "40.81649,-73.907807&destination=40.819585,-73.90177"+ "&key=AIzaSyChXllnUaESuRZPDpSHtb3oyXgL1edHITg";// + R.string.google_direction_api_key;*/
// Log.d(TAG, "URL : " + url);
Log.d(TAG, url);
DownloadTask downloadTask = new DownloadTask();
// Log.d(TAG, "@busDistance (SphericalUtil.computeDistanceBetween) = " + SphericalUtil.computeDistanceBetween(mCurrentPosition, new LatLng(Double.parseDouble(latitudeStr), Double.parseDouble(longitudeStr))));
// Start downloading json data from Google Directions API
downloadTask.execute(url);
}
} else {
// double dist = SphericalUtil.computeDistanceBetween(mCurrentPosition, new LatLng(latitudeBus, longitudeBus));
double dist = CalculationByDistance(mCurrentPosition, new LatLng(latitudeBus, longitudeBus)) * 1000;
// Log.d(TAG, "dist = "+ dist);
long distLong = Math.round(dist);
String timeStr;
if (dist < 1000) {
String distStr = String.valueOf(distLong) + " m";
// Log.d(TAG, "distStr = " + distStr);
distance.setText(distStr);
distance.setPaintFlags(distance.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
// long timeLong =Math.round(9 * distLong / 100); // 40km/hr into m/s
// 30km/hr into m/s
long timeLong = Math.round(12 * distLong / 100);
if (timeLong > 60) {
timeLong = Math.round(timeLong / 60);
timeStr = String.valueOf(timeLong) + " min";
} else {
timeStr = String.valueOf(timeLong) + " s";
}
// Log.d(TAG, "timeStr = " +timeStr);
duration.setText(timeStr);
duration.setPaintFlags(duration.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
} else {
distLong = Math.round(distLong / 1000);
String distStr = String.valueOf(distLong + " km");
// Log.d(TAG, "distStr = " + distStr);
distance.setText(distStr);
distance.setPaintFlags(distance.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
// long timeLong = Math.round(3 * distLong / 2); // 40km/hr into km/min
// 30km/hr into km/min
long timeLong = Math.round(2 * distLong);
if (timeLong > 60) {
timeLong = Math.round(timeLong / 60);
timeStr = String.valueOf(timeLong) + " hr";
} else {
timeStr = String.valueOf(timeLong) + " min";
}
// Log.d(TAG, "timeStr = " +timeStr);
duration.setText(timeStr);
duration.setPaintFlags(duration.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
}
}
/*LatLng bus1_location = new LatLng(latitude, longitude);
LatLng myLocation = new LatLng(mCurrentLocation.getLatitude(), mCurrentLocation.getLongitude());
String DIFFERENCE = CalculationByDistance(myLocation, bus1_location);
String dist = DIFFERENCE + " Km";*/
// distance.setText(dist);
/*TextView time = (TextView) findViewById(R.id.time);
String theTime = latitudeStr + ", " + longitudeStr;
time.setText(theTime);*/
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
// return myClass.getLongitude();
}
use of com.google.firebase.database.DatabaseReference in project GogoNew by kuldeep725.
the class MapsActivity method findNearestBusStop.
private void findNearestBusStop() {
showInternetStatus();
if (!isInternetOn())
return;
DatabaseReference routeDatabase = FirebaseDatabase.getInstance().getReference().child(USER).child(BUS).child("route");
routeDatabase.addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
// Log.d(TAG, "onChildAdded findNearestBusStop() fired .. .. ");
GenericTypeIndicator<Map<String, String>> genericTypeIndicator = new GenericTypeIndicator<Map<String, String>>() {
};
// Log.d(TAG, " dataSnapshot.getValue(genericTypeIndicator) : " + dataSnapshot.getValue(genericTypeIndicator));
// Log.d(TAG, "postDataSnapshot.getKey() = " + dataSnapshot.getKey());
Map<String, String> map = dataSnapshot.getValue(genericTypeIndicator);
assert map != null;
String latitudeStr = map.get("latitude");
String longitudeStr = map.get("longitude");
// Log.d(TAG, "Latitude = " + latitudeStr);
// Log.d(TAG, "Longitude = " + longitudeStr);
double latitude = Double.parseDouble(latitudeStr);
double longitude = Double.parseDouble(longitudeStr);
LatLng busStop = new LatLng(latitude, longitude);
// String busName = "BUS " + checkBusSelection;
// double diff = SphericalUtil.computeDistanceBetween(mCurrentPosition, busStop);
double diff = CalculationByDistance(mCurrentPosition, busStop) * 1000;
// Log.d(TAG, "diff = " + diff);
if (diff < minDistance) {
minDistance = diff;
minLocation = new LatLng(latitude, longitude);
minName = dataSnapshot.getKey();
}
// Log.d(TAG, "minLocation.toString() = " + minLocation.toString());
}
@Override
public void onChildChanged(DataSnapshot dataSnapshot, String s) {
}
@Override
public void onChildRemoved(DataSnapshot dataSnapshot) {
}
@Override
public void onChildMoved(DataSnapshot dataSnapshot, String s) {
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
use of com.google.firebase.database.DatabaseReference in project SpotiQ by ZinoKader.
the class AppModule method providePartiesRepository.
@Provides
PartiesRepository providePartiesRepository() {
FirebaseDatabase firebaseDatabase = FirebaseDatabase.getInstance();
DatabaseReference databaseReference = firebaseDatabase.getReference().child(FirebaseConstants.CHILD_PARTYLIST);
return new PartiesRepository(databaseReference);
}
Aggregations