Search in sources :

Example 1 with Contact

use of de.opendiabetes.vault.plugin.importer.googlecrawler.models.Contact in project BachelorPraktikum by lucasbuschlinger.

the class GooglePlaces method fetchOwnAddresses.

// /**
// * Setter for the query keyword search params.
// * @param keywordSearchParams valid search params that will be appended to the query
// */
// public void setKeywordSearchParams(final String[] keywordSearchParams) {
// for (String param : keywordSearchParams) {
// keywordSearch = keywordSearch + " OR (" + param.toLowerCase() + ")";
// }
// }
// 
// /**
// * Searches the context with the previously set keyword search params
// * and the given location (latitude, longitude) and radius (accuracy).
// * @param latitude a valid latitude
// * @param longitude a valid longitude
// * @param accuracy a radius in meters
// * @return The name of the result if there was a place found with the given query params, otherwise "AWAY"
// */
// public String keywordSearch(final double latitude, final double longitude, final int accuracy) {
// try {
// PlacesSearchResult[] results = PlacesApi
// .nearbySearchQuery(context, new LatLng(latitude, longitude))
// .radius(accuracy)
// .keyword(keywordSearch)
// .await().results;
// if (results.length == 1) {
// return results[0].name;
// } else {
// for (PlacesSearchResult sr : results) {
// boolean isPolitical = false;
// for (String st : sr.types) {
// if (st.equals("political")) {
// isPolitical = true;
// }
// }
// 
// if (!isPolitical) {
// return sr.name;
// }
// }
// }
// } catch (ApiException | InterruptedException | IOException e) {
// e.printStackTrace();
// }
// 
// return "AWAY";
// }
/**
 * Retrieves the own addresses of the current user.
 */
public void fetchOwnAddresses() {
    if (context != null) {
        Person me = GooglePeople.getInstance().getProfile();
        if (me.getAddresses() != null) {
            for (Address res : me.getAddresses()) {
                String name = res.getFormattedType();
                List<Address> address = Arrays.asList(res);
                ownAddresses.add(new Contact(name, address));
            }
        }
    }
}
Also used : Address(com.google.api.services.people.v1.model.Address) Person(com.google.api.services.people.v1.model.Person) Contact(de.opendiabetes.vault.plugin.importer.googlecrawler.models.Contact)

Example 2 with Contact

use of de.opendiabetes.vault.plugin.importer.googlecrawler.models.Contact in project BachelorPraktikum by lucasbuschlinger.

the class GooglePeople method getAllProfiles.

/**
 * Fetches the list of all profiles from the currently logged in user and passes them into the address book controller.
 */
public void getAllProfiles() {
    try {
        List<Person> persons = peopleService.people().connections().list("people/me").setPersonFields("names,addresses").setPageSize(PAGE_SIZE).execute().getConnections();
        for (Person p : persons) {
            if (p.getAddresses() != null) {
                Contact c = new Contact(p.getNames().get(0).getDisplayName(), p.getAddresses());
                AddressBook.getInstance().addContact(c);
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : IOException(java.io.IOException) Person(com.google.api.services.people.v1.model.Person) Contact(de.opendiabetes.vault.plugin.importer.googlecrawler.models.Contact)

Aggregations

Person (com.google.api.services.people.v1.model.Person)2 Contact (de.opendiabetes.vault.plugin.importer.googlecrawler.models.Contact)2 Address (com.google.api.services.people.v1.model.Address)1 IOException (java.io.IOException)1