Search in sources :

Example 1 with GenLocation

use of garbagecollectors.com.unipool.GenLocation in project UniPool by divya21raj.

the class NewEntryActivity method getCurrentPlace.

private void getCurrentPlace() {
    final Place[] place = new Place[1];
    final LatLng[] latLng = new LatLng[1];
    @SuppressLint("MissingPermission") PendingResult<PlaceLikelihoodBuffer> result = Places.PlaceDetectionApi.getCurrentPlace(mGoogleApiClient, null);
    result.setResultCallback(likelyPlaces -> {
        try {
            PlaceLikelihood placeLikelihood = likelyPlaces.get(0);
            place[0] = placeLikelihood.getPlace();
            latLng[0] = place[0].getLatLng();
            if (currentLocationView.getTag().equals("gct_source")) {
                source = new GenLocation(place[0].getName().toString(), place[0].getAddress().toString(), latLng[0].latitude, latLng[0].longitude);
                sourceSet = (place[0].getName() + ",\n" + place[0].getAddress() + "\n" + // check
                place[0].getPhoneNumber());
                findSource.setText(sourceSet);
            } else if (currentLocationView.getTag().equals("gct_destination")) {
                destination = new GenLocation(place[0].getName().toString(), place[0].getAddress().toString(), latLng[0].latitude, latLng[0].longitude);
                destinationSet = (place[0].getName() + ",\n" + place[0].getAddress() + "\n" + // check
                place[0].getPhoneNumber());
                findDestination.setText(destinationSet);
            }
            likelyPlaces.release();
        } catch (IllegalStateException ils) {
            Toast.makeText(getApplicationContext(), "Turn on 'Location' option on your phone to use this feature...", Toast.LENGTH_LONG).show();
            findSource.setText("Source");
            findDestination.setText("Destination");
        }
    });
}
Also used : PlaceLikelihoodBuffer(com.google.android.gms.location.places.PlaceLikelihoodBuffer) SuppressLint(android.annotation.SuppressLint) LatLng(com.google.android.gms.maps.model.LatLng) PlaceLikelihood(com.google.android.gms.location.places.PlaceLikelihood) GenLocation(garbagecollectors.com.unipool.GenLocation) Place(com.google.android.gms.location.places.Place)

Example 2 with GenLocation

use of garbagecollectors.com.unipool.GenLocation in project UniPool by divya21raj.

the class LoginActivity method dummyInitFinalCurrentUser.

private void dummyInitFinalCurrentUser(FirebaseUser user) throws ParseException {
    HashMap<String, Float> dummyLambdaMap = new HashMap<>();
    dummyLambdaMap.put("123", 0f);
    GenLocation dummyGenLocation = new GenLocation("dummy", "dummy", 0d, 0d);
    TripEntry dummyTripEntry = new TripEntry("dummy", "dummyId", "DummyUser", "12:00", "1/11/12", dummyGenLocation, dummyGenLocation, dummyLambdaMap);
    HashMap<String, TripEntry> dummyUserEntries = new HashMap<>();
    dummyUserEntries.put("dummy", dummyTripEntry);
    HashMap<String, TripEntry> dummyRequestSent = new HashMap<>();
    dummyRequestSent.put(dummyTripEntry.getEntry_id(), dummyTripEntry);
    ArrayList<String> dummyUserIdList = new ArrayList<>();
    dummyUserIdList.add("dummy");
    HashMap<String, ArrayList<String>> dummyRequestReceived = new HashMap<>();
    dummyRequestReceived.put("dummy", dummyUserIdList);
    Message dummyMessage = new Message("dummy", "", "", "dummy", "dummy", 1L);
    ArrayList<Message> dummyMessages = new ArrayList<>();
    dummyMessages.add(dummyMessage);
    PairUp dummyPairUp = new PairUp("dummydummy", "dummy", "dummy", "dummy", dummyUserIdList);
    HashMap<String, PairUp> dummyPairUps = new HashMap<>();
    dummyPairUps.put("dummy", dummyPairUp);
    String deviceToken = FirebaseInstanceId.getInstance().getToken();
    String url = "";
    Uri photoUrl = user.getPhotoUrl();
    if (photoUrl != null)
        url = photoUrl.toString();
    finalCurrentUser = new User(user.getUid(), user.getDisplayName(), url, dummyUserEntries, dummyRequestSent, dummyRequestReceived, deviceToken, true, dummyPairUps);
}
Also used : User(garbagecollectors.com.unipool.User) FirebaseUser(com.google.firebase.auth.FirebaseUser) BaseActivity.finalCurrentUser(garbagecollectors.com.unipool.activities.BaseActivity.finalCurrentUser) Message(garbagecollectors.com.unipool.Message) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) TripEntry(garbagecollectors.com.unipool.TripEntry) Uri(android.net.Uri) PairUp(garbagecollectors.com.unipool.PairUp) GenLocation(garbagecollectors.com.unipool.GenLocation)

Example 3 with GenLocation

use of garbagecollectors.com.unipool.GenLocation in project UniPool by divya21raj.

the class NewEntryActivity method onActivityResult.

// A place has been received; use requestCode to track the request.
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == RESULT_OK) {
        Place place = PlaceAutocomplete.getPlace(this, data);
        Log.e("Tag", "Place: " + place.getAddress() + place.getPhoneNumber());
        LatLng latLng;
        switch(requestCode) {
            case 1:
                latLng = place.getLatLng();
                source = new GenLocation(place.getName().toString(), place.getAddress().toString(), latLng.latitude, // check
                latLng.longitude);
                sourceSet = (place.getName() + ",\n" + place.getAddress() + "\n" + // check
                place.getPhoneNumber());
                findSource.setText(sourceSet);
                break;
            case 2:
                latLng = place.getLatLng();
                destination = new GenLocation(place.getName().toString(), place.getAddress().toString(), latLng.latitude, // check
                latLng.longitude);
                destinationSet = (place.getName() + ",\n" + place.getAddress() + "\n" + // check
                place.getPhoneNumber());
                findDestination.setText(destinationSet);
                break;
        }
    } else if (resultCode == PlaceAutocomplete.RESULT_ERROR) {
        Status status = PlaceAutocomplete.getStatus(this, data);
        // TODO: Handle the error.
        Log.e("Tag", status.getStatusMessage());
    } else if (resultCode == RESULT_CANCELED) {
    // The user canceled the operation.
    // Toast.makeText(getApplicationContext(), "Cancelled...", Toast.LENGTH_SHORT).show();
    }
}
Also used : Status(com.google.android.gms.common.api.Status) LatLng(com.google.android.gms.maps.model.LatLng) GenLocation(garbagecollectors.com.unipool.GenLocation) Place(com.google.android.gms.location.places.Place)

Aggregations

GenLocation (garbagecollectors.com.unipool.GenLocation)3 Place (com.google.android.gms.location.places.Place)2 LatLng (com.google.android.gms.maps.model.LatLng)2 SuppressLint (android.annotation.SuppressLint)1 Uri (android.net.Uri)1 Status (com.google.android.gms.common.api.Status)1 PlaceLikelihood (com.google.android.gms.location.places.PlaceLikelihood)1 PlaceLikelihoodBuffer (com.google.android.gms.location.places.PlaceLikelihoodBuffer)1 FirebaseUser (com.google.firebase.auth.FirebaseUser)1 Message (garbagecollectors.com.unipool.Message)1 PairUp (garbagecollectors.com.unipool.PairUp)1 TripEntry (garbagecollectors.com.unipool.TripEntry)1 User (garbagecollectors.com.unipool.User)1 BaseActivity.finalCurrentUser (garbagecollectors.com.unipool.activities.BaseActivity.finalCurrentUser)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1