Search in sources :

Example 1 with GenLocation

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

the class NewEntryDialog method getCurrentPlace.

public static void getCurrentPlace(Context context) {
    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(context, "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.models.GenLocation) Place(com.google.android.gms.location.places.Place)

Example 2 with GenLocation

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

the class NewEntryDialog method predictSourceAndDestination.

private void predictSourceAndDestination() {
    Calendar calendar = Calendar.getInstance();
    int day = calendar.get(Calendar.DAY_OF_WEEK);
    if (day == Calendar.SATURDAY || day == Calendar.SUNDAY) {
        findDestination.setText(R.string.uni_name);
        destination = new GenLocation(Globals.uniInfo.get("name"), Globals.uniInfo.get("address"), Double.parseDouble(Globals.uniInfo.get("latitude")), Double.parseDouble(Globals.uniInfo.get("longitude")));
    } else {
        findSource.setText(R.string.uni_name);
        source = new GenLocation(Globals.uniInfo.get("name"), Globals.uniInfo.get("address"), Double.parseDouble(Globals.uniInfo.get("latitude")), Double.parseDouble(Globals.uniInfo.get("longitude")));
    }
}
Also used : Calendar(java.util.Calendar) GenLocation(garbagecollectors.com.unipool.models.GenLocation) SuppressLint(android.annotation.SuppressLint)

Example 3 with GenLocation

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

the class LoginActivity method dummyInitFinalCurrentUser.

private void dummyInitFinalCurrentUser(FirebaseUser user) {
    GenLocation dummyGenLocation = new GenLocation("dummy", "dummy", 0d, 0d);
    TripEntry dummyTripEntry = new TripEntry("dummy", "dummyId", "DummyUser", "12:00", "1/11/12", dummyGenLocation, dummyGenLocation, "dummyMessage", "", "", true);
    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);
    PairUp dummyPairUp = new PairUp("dummydummy", "dummy", "dummy", "dummy", dummyUserIdList);
    HashMap<String, PairUp> dummyPairUps = new HashMap<>();
    dummyPairUps.put("dummy", dummyPairUp);
    FirebaseInstanceId.getInstance().getInstanceId().addOnSuccessListener(instanceIdResult -> {
        String deviceToken = instanceIdResult.getToken();
        String url = "";
        Uri photoUrl = user.getPhotoUrl();
        if (photoUrl != null)
            url = photoUrl.toString();
        finalCurrentUser = new User(user.getUid(), user.getDisplayName(), url, user.getEmail(), dummyUserEntries, dummyRequestSent, dummyRequestReceived, deviceToken, true, dummyPairUps);
    });
}
Also used : User(garbagecollectors.com.unipool.models.User) FirebaseUser(com.google.firebase.auth.FirebaseUser) BaseActivity.finalCurrentUser(garbagecollectors.com.unipool.activities.BaseActivity.finalCurrentUser) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) PairUp(garbagecollectors.com.unipool.models.PairUp) TripEntry(garbagecollectors.com.unipool.models.TripEntry) GenLocation(garbagecollectors.com.unipool.models.GenLocation) Uri(android.net.Uri)

Example 4 with GenLocation

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

the class BaseActivity method onActivityResult.

// +++++
// For NewEntryDialog
// A place has been received; use requestCode to track the request.
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == Activity.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();
                NewEntryDialog.source = new GenLocation(place.getName().toString(), place.getAddress().toString(), latLng.latitude, // check
                latLng.longitude);
                NewEntryDialog.sourceSet = (place.getName() + ",\n" + place.getAddress() + "\n" + // check
                place.getPhoneNumber());
                NewEntryDialog.findSource.setText(NewEntryDialog.sourceSet);
                break;
            case 2:
                latLng = place.getLatLng();
                NewEntryDialog.destination = new GenLocation(place.getName().toString(), place.getAddress().toString(), latLng.latitude, // check
                latLng.longitude);
                NewEntryDialog.destinationSet = (place.getName() + ",\n" + place.getAddress() + "\n" + // check
                place.getPhoneNumber());
                NewEntryDialog.findDestination.setText(NewEntryDialog.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.models.GenLocation) Place(com.google.android.gms.location.places.Place)

Aggregations

GenLocation (garbagecollectors.com.unipool.models.GenLocation)4 SuppressLint (android.annotation.SuppressLint)2 Place (com.google.android.gms.location.places.Place)2 LatLng (com.google.android.gms.maps.model.LatLng)2 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 BaseActivity.finalCurrentUser (garbagecollectors.com.unipool.activities.BaseActivity.finalCurrentUser)1 PairUp (garbagecollectors.com.unipool.models.PairUp)1 TripEntry (garbagecollectors.com.unipool.models.TripEntry)1 User (garbagecollectors.com.unipool.models.User)1 ArrayList (java.util.ArrayList)1 Calendar (java.util.Calendar)1 HashMap (java.util.HashMap)1