use of com.google.firebase.database.ChildEventListener in project GogoNew by kuldeep725.
the class MapsActivity method getNearestBus.
private void getNearestBus() {
minimumDistance = Double.MAX_VALUE;
if (mCurrentLocation == null)
return;
if (mDatabase != null) {
final DatabaseReference userDatabase = mDatabase.child(USER);
userDatabase.addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
keyStr = dataSnapshot.getKey();
Log.d(TAG, "keyStr = " + keyStr);
Log.d(TAG, "myDataSnapShot = " + dataSnapshot);
Log.d(TAG, "dataSnapshot.child(keyStr).child(\"location\").child(\"latitude\") : " + dataSnapshot.child("location").child("latitude"));
String latStr = (String) dataSnapshot.child("location").child("latitude").getValue();
String lngStr = (String) dataSnapshot.child("location").child("longitude").getValue();
Log.d(TAG, "latStr = " + latStr);
Log.d(TAG, "lngStr = " + lngStr);
Double latdub = Double.parseDouble(latStr);
Double lngdub = Double.parseDouble(lngStr);
// Double diff = SphericalUtil.computeDistanceBetween(
// new LatLng(mCurrentLocation.getLatitude(), mCurrentLocation.getLongitude()),
// new LatLng(latdub, lngdub));
diff = CalculationByDistance(new LatLng(mCurrentLocation.getLatitude(), mCurrentLocation.getLongitude()), new LatLng(latdub, lngdub)) * 1000;
Log.d(TAG, "diff = " + diff);
if (diff < minimumDistance) {
minimumDistance = diff;
// minimumLocation = new LatLng(latdub, lngdub);
if (keyStr.contains("b"))
radiobuttonId = Integer.parseInt(keyStr.split("b")[1]);
}
Log.d(TAG, "radiobuttonId = " + radiobuttonId);
// if (mCurrentLocation != null) {
// String url = "https://maps.googleapis.com/maps/api/directions/json?origin="
// + mCurrentLocation.getLatitude() + "," + mCurrentLocation.getLongitude()
// + "&destination=" + latStr + "," + lngStr + "&key=AIzaSyChXllnUaESuRZPDpSHtb3oyXgL1edHITg";// + R.string.google_direction_api_key;
// /*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);
// 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);
// }
}
@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) {
}
});
userDatabase.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
Log.d(TAG, "@addListener radioButtonId = " + radiobuttonId);
radiobutton = (RadioButton) findViewById(radiobuttonId);
checkBusSelection = radiobuttonId;
if (lastButton != null) {
Log.d(TAG, "LASTBUTTON = " + lastButton.toString());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
lastButton.setBackground(getResources().getDrawable(R.drawable.radio_button_event));
lastButton.setPaintFlags(radiobutton.getPaintFlags() & (~Paint.UNDERLINE_TEXT_FLAG));
if (lastButton != pickMeRadioButton) {
lastButton.setTypeface(Typeface.DEFAULT);
}
}
if (lastButton != pickMeRadioButton) {
lastButton.setTextColor(Color.BLACK);
}
}
radiobutton.setTextColor(Color.parseColor(primeColorString));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
radiobutton.setBackground(getDrawable(R.drawable.underline));
} else {
radiobutton.setPaintFlags(radiobutton.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
radiobutton.setBackgroundColor(Color.parseColor("#FFFFFF"));
}
if (mMap != null) {
mMap.clear();
onMapReady(mMap);
}
makeMarkerOnTheLocation();
showMarkers();
// previousSelection = -1;
// for using google distance api in showDistanceInBetween
flagShowDistanceInBetween = 0;
showDistanceInBetween();
// String dist = distance.getText().toString();
Log.e(TAG, "minDistance = " + minimumDistance);
long distLong = Math.round(minimumDistance);
String distStr;
if (minimumDistance < 1000) {
distStr = String.valueOf(distLong) + " m";
Log.d(TAG, "distStr = " + distStr);
// long timeLong =Math.round(9 * distLong / 100); // 40km/hr into m/s
} else {
distLong = Math.round(distLong / 1000);
distStr = String.valueOf(distLong + " km");
Log.d(TAG, "distStr = " + distStr);
}
String str = "The nearest bus is Bus " + checkBusSelection + " at distance " + distStr;
Toast.makeText(MapsActivity.this, str, Toast.LENGTH_SHORT).show();
// Log.d(TAG, "minDistStr = " + minDistStr);
// Log.d(TAG, "minimum Time = " + minimumTime);
// distance.setText(minDistStr);
// duration.setText(minimumTime);
lastButton = radiobutton;
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
}
use of com.google.firebase.database.ChildEventListener in project SEProject by NicholasBarreyre.
the class TeamDetailActivity method populateMemberList.
/**
* Populates the list of teams associated with the user
*/
private void populateMemberList() {
final ListView teamMemberListView = findViewById(R.id.memberList);
// retrieve database reference to the team members
FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference teamsReference = database.getReference("teams/" + team.getId() + "/teamMembers");
teamMemberAdapter = new TeamMembersAdapter(this, new ArrayList<String>());
teamsReference.addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
teamMemberAdapter.add(dataSnapshot.getValue(String.class));
}
@Override
public void onChildChanged(DataSnapshot dataSnapshot, String s) {
}
@Override
public void onChildRemoved(DataSnapshot dataSnapshot) {
teamMemberAdapter.remove(dataSnapshot.getValue(String.class));
}
@Override
public void onChildMoved(DataSnapshot dataSnapshot, String s) {
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
teamMemberListView.setAdapter(teamMemberAdapter);
teamMemberListView.setOnItemClickListener(new TeamDetailActivity.TeamMemberListClickListener());
}
use of com.google.firebase.database.ChildEventListener in project SEProject by NicholasBarreyre.
the class SearchResultsActivity method populateListWithSearchResults.
private void populateListWithSearchResults(final String query) {
// Get the reference to the UI contents
final ListView teamListView = findViewById(R.id.teamList);
// retrieve database reference to the teams
FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference teamsReference = database.getReference("teams");
teamAdapter = new TeamsAdapter(this, new ArrayList<Team>());
teamsReference.addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
// TODO: Don't add teams already a member of
if (dataSnapshot.getValue(Team.class).getName().toUpperCase().contains(query.toUpperCase())) {
teamAdapter.add(dataSnapshot.getValue(Team.class));
teamAdapter.notifyDataSetChanged();
}
}
@Override
public void onChildChanged(DataSnapshot dataSnapshot, String s) {
// TODO: Don't add teams already a member of
if (dataSnapshot.getValue(Team.class).getName().toUpperCase().contains(query.toUpperCase())) {
teamAdapter.add(dataSnapshot.getValue(Team.class));
}
}
@Override
public void onChildRemoved(DataSnapshot dataSnapshot) {
if (teamAdapter.getPosition(dataSnapshot.getValue(Team.class)) != -1) {
teamAdapter.remove(dataSnapshot.getValue(Team.class));
}
}
@Override
public void onChildMoved(DataSnapshot dataSnapshot, String s) {
Log.d("TeamList", dataSnapshot.getValue(Team.class).getName() + "has moved locations...");
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
teamListView.setAdapter(teamAdapter);
teamListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
final Team team = teamAdapter.getItem(position);
AlertDialog.Builder builder = new AlertDialog.Builder(SearchResultsActivity.this);
builder.setNegativeButton("Close", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
}
});
builder.setPositiveButton("Apply", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
final AlertDialog.Builder confirmDialog = new AlertDialog.Builder(SearchResultsActivity.this);
confirmDialog.setNegativeButton("No", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
confirmDialog.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
TeamManager.requestToJoinTeam(team, user);
dialog.dismiss();
finish();
}
});
confirmDialog.setTitle("Confirm Application").setMessage("Are you sure you want to apply to " + team.getName() + "?").show();
}
});
builder.setTitle("Apply To Team").setMessage("\nDo you want to apply to " + team.getName()).show();
}
});
}
Aggregations