use of com.backendless.geo.GeoPoint in project Android-SDK by Backendless.
the class FenceDemo method initGeoPoint.
private void initGeoPoint() {
// to create a geopoint
geoPoint = new GeoPoint();
// to add metadata for the created geopoint (optionally)
geoPoint.addMetadata("number", 7);
geoPoint.addMetadata("string", "backendless");
geoPoint.addMetadata("__deviceId", Backendless.Messaging.DEVICE_ID);
}
use of com.backendless.geo.GeoPoint in project Android-SDK by Backendless.
the class FindMatchesActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.findmatches);
adapter = new PointsAdapter(FindMatchesActivity.this);
MapFragment mapFragment = (MapFragment) getFragmentManager().findFragmentById(R.id.map);
googleMap = mapFragment.getMap();
googleMap.setMyLocationEnabled(true);
progressDialog = UIFactory.getDefaultProgressDialog(this);
progressBar = (ProgressBar) findViewById(R.id.progressBar);
matchesFound = (TextView) findViewById(R.id.matchesFound);
matchesFound.setText("0");
textFoundGlobal = (TextView) findViewById(R.id.textFoundGlobal);
textFoundGlobal.setText("0");
LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);
criteria.setPowerRequirement(Criteria.POWER_LOW);
criteria.setAltitudeRequired(false);
criteria.setBearingRequired(false);
criteria.setSpeedRequired(false);
criteria.setCostAllowed(true);
boolean enabledGPS = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
if (!enabledGPS)
Toast.makeText(FindMatchesActivity.this, "No GPS signal", Toast.LENGTH_LONG).show();
boolean networkIsEnabled = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
if (!networkIsEnabled)
Toast.makeText(FindMatchesActivity.this, "No Network signal", Toast.LENGTH_LONG).show();
String provider = locationManager.getBestProvider(criteria, true);
LocationListener myLocationListener = new LocationListener() {
@Override
public void onLocationChanged(Location location) {
if (location == null)
Toast.makeText(FindMatchesActivity.this, "Location unknown", Toast.LENGTH_LONG).show();
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// To change body of implemented methods use File | Settings | File Templates.
}
@Override
public void onProviderEnabled(String provider) {
// To change body of implemented methods use File | Settings | File Templates.
}
@Override
public void onProviderDisabled(String provider) {
// To change body of implemented methods use File | Settings | File Templates.
}
};
Location location = locationManager.getLastKnownLocation(provider);
locationManager.requestSingleUpdate(criteria, myLocationListener, null);
if (provider == null) {
UIFactory.getLocationSettingsDialog(this).show();
finish();
}
if (location != null) {
latitude = location.getLatitude();
longitude = location.getLongitude();
myLocation = new GeoPoint(latitude, longitude);
myPosition = new LatLng(latitude, longitude);
SharedPreferences settings = getSharedPreferences(PREF_TAG, 0);
String email = settings.getString(EMAIL_PREF, null);
BackendlessGeoQuery backendlessGeoQuery = new BackendlessGeoQuery(BackendlessUser.EMAIL_KEY, email);
Backendless.Geo.getPoints(backendlessGeoQuery, gotCurrentUserGeoPointCallback);
BackendlessGeoQuery backendlessGeoQueryGlobal = new BackendlessGeoQuery();
Backendless.Geo.getPoints(backendlessGeoQueryGlobal, new AsyncCallback<Collection<GeoPoint>>() {
@Override
public void handleResponse(Collection<GeoPoint> geoPointBackendlessCollection) {
List<GeoPoint> geoPoints = geoPointBackendlessCollection.getCurrentPage();
if (!geoPoints.isEmpty())
textFoundGlobal.setText(String.valueOf(geoPoints.size() - 1));
}
@Override
public void handleFault(BackendlessFault backendlessFault) {
Toast.makeText(FindMatchesActivity.this, backendlessFault.getMessage(), Toast.LENGTH_LONG).show();
}
});
} else
Toast.makeText(FindMatchesActivity.this, "Can't determine your location. Check the settings your device and restart the application.", Toast.LENGTH_LONG).show();
googleMap.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() {
@Override
public View getInfoWindow(Marker marker) {
return null;
}
@Override
public View getInfoContents(Marker marker) {
View view = getLayoutInflater().inflate(R.layout.custom_info_window, null);
ImageView imageView = (ImageView) view.findViewById(R.id.imagePhoto);
if (bitmapToMarkerMap.containsKey(marker))
imageView.setImageBitmap(bitmapToMarkerMap.get(marker));
TextView title = (TextView) view.findViewById(R.id.textTitlePoint);
title.setText(marker.getTitle());
TextView sniped = (TextView) view.findViewById(R.id.textSnipedPoint);
sniped.setText(marker.getSnippet());
imageView.setImageResource(sniped.getText().equals("male") ? R.drawable.avatar_default_male : R.drawable.avatar_default_female);
return view;
}
});
googleMap.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {
@Override
public void onInfoWindowClick(Marker marker) {
for (int i = 0; i < adapter.pointsList.size(); i++) {
GeoPoint pointData = adapter.pointsList.get(i);
Map<String, String> newMetaData = pointData.getMetadata();
String pointName = newMetaData.get(Defaults.NAME_PROPERTY);
if (pointName.equals(marker.getTitle()))
Lifecycle.runMatchViewActivity(FindMatchesActivity.this, myLocation, pointData);
}
}
});
googleMap.setOnCameraChangeListener(new GoogleMap.OnCameraChangeListener() {
@Override
public void onCameraChange(CameraPosition cameraPosition) {
LatLngBounds visibleRegion = googleMap.getProjection().getVisibleRegion().latLngBounds;
LatLng topRight = visibleRegion.northeast;
LatLng botDown = visibleRegion.southwest;
SWLat = botDown.latitude;
SWLon = botDown.longitude;
NELat = topRight.latitude;
NELon = topRight.longitude;
findMatches();
}
});
findViewById(R.id.profileButton).setOnClickListener(profileListener);
findViewById(R.id.pingsButton).setOnClickListener(pingsListener);
}
use of com.backendless.geo.GeoPoint in project Android-SDK by Backendless.
the class PingsActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.pings);
progressDialog = UIFactory.getDefaultProgressDialog(this);
pingedContainer = (LinearLayout) findViewById(R.id.pingedContainer);
werePingedContainer = (LinearLayout) findViewById(R.id.werePingedContainer);
callbackPingsContainer = (LinearLayout) findViewById(R.id.callbackPingsContainer);
currentUserGeoPoint = (GeoPoint) getIntent().getSerializableExtra(Defaults.CURRENT_USER_GEO_POINT_BUNDLE_TAG);
Map<String, String> metaDataForSearch = new HashMap<String, String>();
metaDataForSearch.put("Asian", food);
metaDataForSearch.put("Caribean", food);
metaDataForSearch.put("Bar food", food);
metaDataForSearch.put("French", food);
metaDataForSearch.put("Mediterranean", food);
metaDataForSearch.put("Greek", food);
metaDataForSearch.put("Spanish", food);
metaDataForSearch.put("Mexican", food);
metaDataForSearch.put("Thai", food);
// Music
metaDataForSearch.put("Classical", music);
metaDataForSearch.put("Jazz", music);
metaDataForSearch.put("Hip-hop", music);
metaDataForSearch.put("Reggae", music);
metaDataForSearch.put("Blues", music);
metaDataForSearch.put("Trance", music);
metaDataForSearch.put("House", music);
metaDataForSearch.put("Rock", music);
metaDataForSearch.put("Folk", music);
// Hobbies
metaDataForSearch.put("Fishing", hobbies);
metaDataForSearch.put("Diving", hobbies);
metaDataForSearch.put("Rock climbing", hobbies);
metaDataForSearch.put("Hiking", hobbies);
metaDataForSearch.put("Reading", hobbies);
metaDataForSearch.put("Dancing", hobbies);
metaDataForSearch.put("Cooking", hobbies);
metaDataForSearch.put("Surfing", hobbies);
metaDataForSearch.put("Photography", hobbies);
// Travel
metaDataForSearch.put("Cruise", travel);
metaDataForSearch.put("B&B", travel);
metaDataForSearch.put("Europe", travel);
metaDataForSearch.put("Asia", travel);
metaDataForSearch.put("Caribean", travel);
metaDataForSearch.put("Mountains", travel);
metaDataForSearch.put("Whale watching", travel);
metaDataForSearch.put("Active travel", travel);
int maxPoints = 10;
BackendlessGeoQuery backendlessGeoQuery = new BackendlessGeoQuery(metaDataForSearch, maxPoints);
backendlessGeoQuery.setPageSize(50);
backendlessGeoQuery.setIncludeMeta(true);
Backendless.Geo.relativeFind(backendlessGeoQuery, gotPingsCallback);
}
use of com.backendless.geo.GeoPoint in project Android-SDK by Backendless.
the class EndlessTaggingActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.act_endless_tagging);
TextView textEndless = (TextView) findViewById(R.id.textEndless);
Typeface typeface = Typeface.createFromAsset(getAssets(), "fonts/verdana.ttf");
textEndless.setTypeface(typeface);
adapter = new PointsAdapter(EndlessTaggingActivity.this);
MapFragment mapFragment = (MapFragment) getFragmentManager().findFragmentById(R.id.map);
googleMap = mapFragment.getMap();
googleMap.setMyLocationEnabled(true);
LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);
criteria.setPowerRequirement(Criteria.POWER_LOW);
criteria.setAltitudeRequired(false);
criteria.setBearingRequired(false);
criteria.setSpeedRequired(false);
criteria.setCostAllowed(true);
boolean enabledGPS = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
if (!enabledGPS) {
Toast.makeText(EndlessTaggingActivity.this, "No GPS signal", Toast.LENGTH_LONG).show();
}
boolean networkIsEnabled = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
if (!networkIsEnabled) {
Toast.makeText(EndlessTaggingActivity.this, "No Network signal", Toast.LENGTH_LONG).show();
}
String provider = locationManager.getBestProvider(criteria, true);
LocationListener myLocationListener = new LocationListener() {
@Override
public void onLocationChanged(Location location) {
// To change body of implemented methods use File | Settings | File Templates.
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// To change body of implemented methods use File | Settings | File Templates.
}
@Override
public void onProviderEnabled(String provider) {
// To change body of implemented methods use File | Settings | File Templates.
}
@Override
public void onProviderDisabled(String provider) {
// To change body of implemented methods use File | Settings | File Templates.
}
};
Location location = locationManager.getLastKnownLocation(provider);
locationManager.requestSingleUpdate(criteria, myLocationListener, null);
if (location != null) {
latitude = location.getLatitude();
longitude = location.getLongitude();
myPosition = new LatLng(latitude, longitude);
googleMap.addMarker(new MarkerOptions().position(myPosition).icon(BitmapDescriptorFactory.fromResource(R.drawable.marker_red)));
googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(myPosition, 11));
googleMap.animateCamera(CameraUpdateFactory.zoomTo(14), 2000, null);
getCategory();
} else
Toast.makeText(EndlessTaggingActivity.this, "Can't determine your location. Check the settings your device and restart the application.", Toast.LENGTH_LONG).show();
googleMap.setOnMapLongClickListener(new GoogleMap.OnMapLongClickListener() {
@Override
public void onMapLongClick(LatLng latLng) {
latitudeOnMap = latLng.latitude;
longitudeOnMap = latLng.longitude;
onMapClick = true;
AlertDialog.Builder builder = new AlertDialog.Builder(EndlessTaggingActivity.this);
builder.setMessage(R.string.new_point);
builder.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent(EndlessTaggingActivity.this, MakeChoiceActivity.class);
startActivityForResult(intent, Default.ADD_NEW_PHOTO_RESULT);
}
});
builder.setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
AlertDialog dialog = builder.create();
dialog.show();
}
});
googleMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
@Override
public boolean onMarkerClick(Marker marker) {
GeoPoint pointEndless = adapter.getPointByMarker(marker);
if (pointEndless == null || !pointEndless.getMetadata().containsKey("endlessTagging")) {
return true;
}
if (!bitmapToMarkerMap.containsKey(marker)) {
String markerPhotoUrl = pointEndless.getMetadata("photoUrl");
new DownloadImageTask(marker).execute(markerPhotoUrl);
} else
marker.showInfoWindow();
return true;
}
});
googleMap.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() {
@Override
public View getInfoWindow(Marker marker) {
return null;
}
@Override
public View getInfoContents(Marker marker) {
View view = getLayoutInflater().inflate(R.layout.custom_info_window, null);
ImageView imageView = (ImageView) view.findViewById(R.id.imagePhoto);
if (bitmapToMarkerMap.containsKey(marker))
imageView.setImageBitmap(bitmapToMarkerMap.get(marker));
TextView title = (TextView) view.findViewById(R.id.textTitlePoint);
title.setText(marker.getTitle());
TextView sniped = (TextView) view.findViewById(R.id.textSnipedPoint);
sniped.setText(marker.getSnippet());
return view;
}
});
googleMap.setOnCameraChangeListener(new GoogleMap.OnCameraChangeListener() {
@Override
public void onCameraChange(CameraPosition cameraPosition) {
LatLngBounds visibleRegion = googleMap.getProjection().getVisibleRegion().latLngBounds;
LatLng topRight = visibleRegion.northeast;
LatLng botDown = visibleRegion.southwest;
SWLat = botDown.latitude;
SWLon = botDown.longitude;
NELat = topRight.latitude;
NELon = topRight.longitude;
searchRectanglePoints(selectedCategories.isEmpty() ? categoriesNames : selectedCategories);
}
});
googleMap.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {
@Override
public void onInfoWindowClick(Marker marker) {
for (int i = 0; i < adapter.pointsList.size(); i++) {
GeoPoint pointData = adapter.pointsList.get(i);
Map<String, String> newMetaData = pointData.getMetadata();
final String geoPointId = pointData.getObjectId();
String name = null;
String pointName = newMetaData.get("pointName");
List<String> categoriesPoint = pointData.getCategories();
for (String category : categoriesPoint) {
name = category.toString();
}
if (pointName.equals(marker.getTitle())) {
Intent intent = new Intent(EndlessTaggingActivity.this, PointCommentsActivity.class);
intent.putExtra(Default.SEARCH_CATEGORY_NAME, name);
intent.putExtra(Default.GEO_POINT_ID, geoPointId);
intent.putExtra(Default.SEND_BITMAP, bitmapToMarkerMap.get(marker));
startActivityForResult(intent, Default.ADD_NEW_COMMENT);
}
}
}
});
Button tagBtn = (Button) findViewById(R.id.tagBtn);
tagBtn.setTypeface(typeface);
tagBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(EndlessTaggingActivity.this, MakeChoiceActivity.class);
startActivityForResult(intent, Default.ADD_NEW_PHOTO_RESULT);
}
});
Button filterBtn = (Button) findViewById(R.id.filterBtn);
filterBtn.setTypeface(typeface);
filterBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (selectedCategories.size() == 0) {
Intent intent = new Intent(EndlessTaggingActivity.this, FilterActivity.class);
startActivityForResult(intent, Default.CATEGORY_RESULT_SEARCH);
} else {
Intent intent = new Intent(EndlessTaggingActivity.this, FilterActivity.class);
String[] array = new String[selectedCategories.size()];
array = selectedCategories.toArray(array);
intent.putExtra(Default.SEARCH_CHECK_BOX, array);
startActivityForResult(intent, Default.CATEGORY_RESULT_SEARCH);
}
}
});
}
use of com.backendless.geo.GeoPoint in project Android-SDK by Backendless.
the class BackendlessSerializer method serializeToMap.
public Object serializeToMap(Object entity, Map<Object, Map<String, Object>> serializedCache) {
if (entity.getClass().isArray())
return serializeArray(entity, serializedCache);
if (entity.getClass().isEnum())
return ((Enum) entity).name();
Map<String, Object> serializedEntity = new HashMap<String, Object>();
if (entity.getClass() == BackendlessUser.class)
serializedEntity = ((BackendlessUser) entity).getProperties();
else
weborb.util.ObjectInspector.getObjectProperties(entity.getClass(), entity, (HashMap) serializedEntity, new ArrayList(), true, shouldTraverse());
serializedCache.put(entity, serializedEntity);
FootprintsManager.getInstance().Inner.putMissingPropsToEntityMap(entity, serializedEntity);
// put ___class field, otherwise server will not be able to detect class
serializedEntity.put(Persistence.REST_CLASS_FIELD, getSimpleName(entity.getClass()));
// recursively serialize object properties
Iterator<Map.Entry<String, Object>> entityIterator = serializedEntity.entrySet().iterator();
while (entityIterator.hasNext()) {
Map.Entry<String, Object> entityEntry = entityIterator.next();
// ignoring properties which contain $. This occurs in InstantRun in AndroidStudio - it injects $change property.
if (entityEntry.getKey().contains("$")) {
entityIterator.remove();
continue;
}
// http://developer.android.com/reference/android/os/Parcelable.html
if (Backendless.isAndroid() && entityEntry.getKey().equals(Persistence.PARCELABLE_CREATOR_FIELD_NAME)) {
entityIterator.remove();
continue;
}
Object entityEntryValue = entityEntry.getValue();
// ignore null entries and GeoPoints
if (entityEntryValue == null || entityEntryValue instanceof GeoPoint)
continue;
// check for anonymous class entry
if (entityEntryValue.getClass().isAnonymousClass())
throw new BackendlessException(String.format(ExceptionMessage.ANONYMOUS_CLASSES_PROHIBITED, entityEntry.getKey()));
// check if entity entry is collection
if (entityEntryValue instanceof List) {
List listEntry = (List) entityEntryValue;
// empty lists should not be sent to the server
if (listEntry.isEmpty()) {
// if there is no object id, remove empty list
if (!serializedEntity.containsKey(Persistence.DEFAULT_OBJECT_ID_FIELD) || serializedEntity.get(Persistence.DEFAULT_OBJECT_ID_FIELD) == null)
entityIterator.remove();
continue;
}
// do nothing with lists of GeoPoints
if (listEntry.iterator().next() instanceof GeoPoint)
continue;
// check for anonymous class entry
if (listEntry.iterator().next().getClass().isAnonymousClass())
throw new BackendlessException(String.format(ExceptionMessage.ANONYMOUS_CLASSES_PROHIBITED, entityEntry.getKey()));
List<Object> newCollection = new ArrayList<Object>();
for (Object listEntryItem : listEntry) if (!isBelongsJdk(listEntryItem.getClass()))
newCollection.add(getOrMakeSerializedObject(listEntryItem, serializedCache));
else
newCollection.add(listEntryItem);
entityEntry.setValue(newCollection);
} else if (entityEntryValue instanceof Object[]) {
Object[] arrayEntry = (Object[]) entityEntryValue;
// do nothing with empty arrays and arrays of GeoPoints
if (arrayEntry.length == 0 || arrayEntry[0] instanceof GeoPoint)
continue;
// check for anonymous class entry
if (arrayEntry[0].getClass().isAnonymousClass())
throw new BackendlessException(String.format(ExceptionMessage.ANONYMOUS_CLASSES_PROHIBITED, entityEntry.getKey()));
List<Object> newCollection = new ArrayList<Object>();
for (Object arrayEntryItem : arrayEntry) if (!isBelongsJdk(arrayEntryItem.getClass()))
newCollection.add(getOrMakeSerializedObject(arrayEntryItem, serializedCache));
else
newCollection.add(arrayEntryItem);
entityEntry.setValue(newCollection);
} else // not collection
{
if (!isBelongsJdk(entityEntryValue.getClass()))
entityEntry.setValue(getOrMakeSerializedObject(entityEntryValue, serializedCache));
}
}
return serializedEntity;
}
Aggregations