use of com.backendless.geo.GeoPoint in project Android-SDK by Backendless.
the class DialogMessageActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.dialog_message);
LinearLayout linearLayout = (LinearLayout) findViewById(R.id.mainLay);
linearLayout.setVisibility(View.GONE);
Intent intent = getIntent();
currentName = intent.getStringExtra(Defaults.CURRENT_USER_NAME);
targetName = intent.getStringExtra(Defaults.TARGET_USER_NAME);
type = intent.getStringExtra("type");
progressDialog = UIFactory.getDefaultProgressDialog(this);
BackendlessGeoQuery backendlessGeoQuery = new BackendlessGeoQuery(BackendlessUser.EMAIL_KEY, Backendless.UserService.CurrentUser().getEmail());
Backendless.Geo.getPoints(backendlessGeoQuery, new AsyncCallback<Collection<GeoPoint>>() {
@Override
public void handleResponse(Collection<GeoPoint> response) {
List<GeoPoint> points = response.getCurrentPage();
if (!points.isEmpty()) {
myLocation = points.get(0);
}
if (type.equals("ping")) {
titleMessage = "New ping!";
sendMessage = "You were pinged by " + currentName;
} else {
titleMessage = "New message!";
sendMessage = "You got a new message from " + currentName;
}
LayoutInflater layoutInflater = getLayoutInflater();
View checkBoxView = layoutInflater.inflate(R.layout.dialog_message, null);
final CheckBox checkBox = (CheckBox) checkBoxView.findViewById(R.id.checkBox);
progressDialog.cancel();
AlertDialog.Builder builder = new AlertDialog.Builder(DialogMessageActivity.this);
builder.setTitle(titleMessage);
builder.setMessage(sendMessage);
builder.setView(checkBoxView);
builder.setCancelable(false);
builder.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
checkBoxResult = "NOT checked";
if (checkBox.isChecked())
checkBoxResult = "checked";
myLocation.putMetadata(currentName, checkBoxResult);
Backendless.Geo.savePoint(myLocation, new AsyncCallback<GeoPoint>() {
@Override
public void handleResponse(GeoPoint geoPoint) {
// Toast.makeText( DialogMessageActivity.this, "Changes successfully saved", Toast.LENGTH_LONG ).show();
}
@Override
public void handleFault(BackendlessFault backendlessFault) {
Toast.makeText(DialogMessageActivity.this, backendlessFault.getMessage(), Toast.LENGTH_LONG).show();
}
});
dialog.dismiss();
finish();
}
});
if (myLocation.getMetadata(currentName) == null || !myLocation.getMetadata(currentName).equals("checked")) {
AlertDialog dialog = builder.create();
dialog.show();
} else
finish();
}
@Override
public void handleFault(BackendlessFault fault) {
Toast.makeText(DialogMessageActivity.this, fault.getMessage(), Toast.LENGTH_LONG).show();
}
});
}
use of com.backendless.geo.GeoPoint in project Android-SDK by Backendless.
the class MatchViewActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.matchview);
progressDialog = UIFactory.getDefaultProgressDialog(this);
TextView nameField = (TextView) findViewById(R.id.nameField);
TextView genderField = (TextView) findViewById(R.id.genderField);
TextView ageField = (TextView) findViewById(R.id.ageField);
ImageView avatarImage = (ImageView) findViewById(R.id.avatarImage);
ImageView genderImage = (ImageView) findViewById(R.id.genderImage);
matchPercentField = (TextView) findViewById(R.id.matchPercents);
foodMatchValue = (TextView) findViewById(R.id.foodMatchValue);
foodProgressBar = (ProgressBar) findViewById(R.id.foodProgressBar);
musicMatchValue = (TextView) findViewById(R.id.musicMatchValue);
musicProgressBar = (ProgressBar) findViewById(R.id.musicProgressBar);
hobbiesMatchValue = (TextView) findViewById(R.id.hobbiesMatchValue);
hobbiesProgressBar = (ProgressBar) findViewById(R.id.hobbiesProgressBar);
travelMatchValue = (TextView) findViewById(R.id.travelMatchValue);
travelProgressBar = (ProgressBar) findViewById(R.id.travelProgressBar);
currentUserGeoPoint = (GeoPoint) getIntent().getSerializableExtra(Defaults.CURRENT_USER_GEO_POINT_BUNDLE_TAG);
targetUserGeoPoint = (GeoPoint) getIntent().getSerializableExtra(Defaults.TARGET_USER_GEO_POINT_BUNDLE_TAG);
triger = getIntent().getStringExtra(Defaults.TRIGER);
String targetUserEmail = targetUserGeoPoint.getMetadata(BackendlessUser.EMAIL_KEY);
targetUserName = targetUserGeoPoint.getMetadata(Defaults.NAME_PROPERTY);
Gender targetUserGender = Gender.valueOf(targetUserGeoPoint.getMetadata(Defaults.GENDER_PROPERTY));
targetUserDeviceRegistrationId = targetUserGeoPoint.getMetadata(Defaults.DEVICE_REGISTRATION_ID_PROPERTY);
Date userBirthDate;
try {
userBirthDate = Defaults.DEFAULT_DATE_FORMATTER.parse(targetUserGeoPoint.getMetadata(Defaults.BIRTH_DATE_PROPERTY));
} catch (ParseException e) {
progressDialog.cancel();
Log.logLine(e);
return;
}
Button actionButton = (Button) findViewById(R.id.actionButton);
if (!targetUserGeoPoint.getMetadata().containsKey(Backendless.UserService.CurrentUser().getEmail()) || !currentUserGeoPoint.getMetadata().containsKey(targetUserEmail)) {
actionButton.setText(getResources().getText(R.string.button_match_ping));
actionButton.setOnClickListener(pingUserListener);
} else {
actionButton.setText(getResources().getText(R.string.button_sendmessage));
actionButton.setOnClickListener(sendMessageListener);
}
nameField.setText(targetUserName);
genderField.setText(targetUserGender.name());
if (targetUserGender == Gender.male) {
avatarImage.setImageDrawable(getResources().getDrawable(R.drawable.avatar_default_male));
genderImage.setImageDrawable(getResources().getDrawable(R.drawable.icon_male));
} else {
avatarImage.setImageDrawable(getResources().getDrawable(R.drawable.avatar_default_female));
genderImage.setImageDrawable(getResources().getDrawable(R.drawable.icon_female));
}
ageField.setText(String.valueOf(SimpleMath.getAgeFromDate(userBirthDate)));
Map<String, String> metaDataMap = currentUserGeoPoint.getMetadata();
Map<String, String> metaDataFood = new HashMap<String, String>();
Map<String, String> metaDataMusic = new HashMap<String, String>();
Map<String, String> metaDataHobbies = new HashMap<String, String>();
Map<String, String> metaDataTravel = new HashMap<String, String>();
for (Map.Entry<String, String> map : metaDataMap.entrySet()) {
String value = map.getValue();
String key = map.getKey();
if (value.equals(foodName))
metaDataFood.put(key, foodName);
if (value.equals(musicName))
metaDataMusic.put(key, musicName);
if (value.equals(hobbiesName))
metaDataHobbies.put(key, hobbiesName);
if (value.equals(travelName))
metaDataTravel.put(key, travelName);
}
int maxPoints = 10;
if (!metaDataFood.isEmpty()) {
BackendlessGeoQuery backendlessGeoQuery = new BackendlessGeoQuery(metaDataFood, maxPoints);
backendlessGeoQuery.setPageSize(50);
backendlessGeoQuery.setIncludeMeta(true);
food = false;
Backendless.Geo.relativeFind(backendlessGeoQuery, gotFoodCallback);
} else {
foodMatchValue.setText(String.valueOf(0));
foodProgressBar.setProgress(0);
food = true;
}
if (!metaDataMusic.isEmpty()) {
BackendlessGeoQuery backendlessGeoQuery = new BackendlessGeoQuery(metaDataMusic, maxPoints);
backendlessGeoQuery.setPageSize(50);
backendlessGeoQuery.setIncludeMeta(true);
music = false;
Backendless.Geo.relativeFind(backendlessGeoQuery, gotMusicCallback);
} else {
musicMatchValue.setText(String.valueOf(0));
musicProgressBar.setProgress(0);
music = true;
}
if (!metaDataHobbies.isEmpty()) {
BackendlessGeoQuery backendlessGeoQuery = new BackendlessGeoQuery(metaDataHobbies, maxPoints);
backendlessGeoQuery.setPageSize(50);
backendlessGeoQuery.setIncludeMeta(true);
hobbies = false;
Backendless.Geo.relativeFind(backendlessGeoQuery, gotHobbiesCallback);
} else {
hobbiesMatchValue.setText(String.valueOf(0));
hobbiesProgressBar.setProgress(0);
hobbies = true;
}
if (!metaDataTravel.isEmpty()) {
BackendlessGeoQuery backendlessGeoQuery = new BackendlessGeoQuery(metaDataTravel, maxPoints);
backendlessGeoQuery.setPageSize(50);
backendlessGeoQuery.setIncludeMeta(true);
travel = false;
Backendless.Geo.relativeFind(backendlessGeoQuery, gotTravelCallback);
} else {
travelMatchValue.setText(String.valueOf(0));
travelProgressBar.setProgress(0);
travel = true;
}
}
use of com.backendless.geo.GeoPoint in project Android-SDK by Backendless.
the class EndlessTaggingActivity method searchRectanglePoints.
private void searchRectanglePoints(List<String> categoriesNames) {
final ProgressBar progressBar = (ProgressBar) findViewById(R.id.progressBar);
final TextView textView = (TextView) findViewById(R.id.textLoading);
textView.setVisibility(TextView.VISIBLE);
progressBar.setVisibility(ProgressBar.VISIBLE);
backendlessGeoQuery = new BackendlessGeoQuery();
backendlessGeoQuery.setSearchRectangle(new double[] { NELat, SWLon, SWLat, NELon });
backendlessGeoQuery.setCategories(categoriesNames);
Backendless.Geo.getPoints(backendlessGeoQuery, new AsyncCallback<Collection<GeoPoint>>() {
@Override
public void handleResponse(Collection<GeoPoint> geoPointBackendlessCollection) {
List<GeoPoint> points = geoPointBackendlessCollection.getCurrentPage();
double newLatitude, newLongitude;
adapter.clear();
if (!points.isEmpty())
adapter.addAll(points);
adapter.notifyDataSetChanged();
for (GeoPoint point : points) {
newLatitude = point.getLatitude();
newLongitude = point.getLongitude();
Map<String, String> newMetaData = point.getMetadata();
String endlessTagging = newMetaData.get("endlessTagging");
if (endlessTagging != null) {
String pointName = newMetaData.get("pointName");
String pointDescription = newMetaData.get("pointDescription");
LatLng newPosition = new LatLng(newLatitude, newLongitude);
googleMap.addMarker(new MarkerOptions().position(newPosition).title(pointName).snippet(pointDescription).icon(BitmapDescriptorFactory.fromResource(R.drawable.marker_blue)));
}
}
textView.setVisibility(TextView.INVISIBLE);
progressBar.setVisibility(ProgressBar.INVISIBLE);
}
@Override
public void handleFault(BackendlessFault backendlessFault) {
textView.setVisibility(TextView.INVISIBLE);
progressBar.setVisibility(ProgressBar.INVISIBLE);
Toast.makeText(EndlessTaggingActivity.this, backendlessFault.getMessage(), Toast.LENGTH_LONG).show();
}
});
}
use of com.backendless.geo.GeoPoint in project Android-SDK by Backendless.
the class EndlessTaggingActivity method onActivityResult.
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (data == null)
return;
switch(requestCode) {
case Default.CATEGORY_RESULT_SEARCH:
googleMap.clear();
googleMap.addMarker(new MarkerOptions().position(myPosition).icon(BitmapDescriptorFactory.fromResource(R.drawable.marker_red)));
List<String> searchCategory = Arrays.asList(data.getStringArrayExtra(Default.SEARCH_CATEGORY_NAME));
selectedCategories = new ArrayList<String>();
selectedCategories = searchCategory;
searchRectanglePoints(selectedCategories.isEmpty() ? categoriesNames : selectedCategories);
break;
case Default.ADD_NEW_CATEGORY_RESULT:
String categoryTriger = data.getStringExtra(Default.CATEGORY_TRIGER);
if (categoryTriger.equals("1"))
category = data.getStringExtra(Default.NEW_CATEGORY_NAME);
if (categoryTriger.equals("2"))
pointCategories = Arrays.asList(data.getStringArrayExtra(Default.SEARCH_CATEGORY_NAME));
if (categoryTriger.equals("3")) {
category = data.getStringExtra(Default.NEW_CATEGORY_NAME);
pointCategories = Arrays.asList(data.getStringArrayExtra(Default.SEARCH_CATEGORY_NAME));
}
Intent intentComment = new Intent(EndlessTaggingActivity.this, AddCommentActivity.class);
intentComment.putExtra(Default.FILE_PATH, filePath);
startActivityForResult(intentComment, Default.ADD_NEW_POINT_RESULT);
break;
case Default.ADD_NEW_POINT_RESULT:
pointNameNew = data.getStringExtra(Default.NEW_POINT_NAME);
googleMap.clear();
if (category != null && pointCategories.isEmpty()) {
AlertDialog.Builder builder = new AlertDialog.Builder(EndlessTaggingActivity.this);
builder.setMessage(R.string.save_data);
builder.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
List<String> categories = new ArrayList<String>();
categories.add(category);
Map<String, String> metadata = new HashMap<String, String>();
metadata.put("pointName", pointNameNew);
metadata.put("pointDescription", category);
metadata.put("photoUrl", photoUrl);
metadata.put("endlessTagging", "true");
if (onMapClick) {
latitude = latitudeOnMap;
longitude = longitudeOnMap;
}
GeoPoint geoPoint = new GeoPoint(latitude, longitude, categories, metadata);
progressDialog = ProgressDialog.show(EndlessTaggingActivity.this, "", "Loading", true);
Backendless.Geo.savePoint(geoPoint, new AsyncCallback<GeoPoint>() {
@Override
public void handleResponse(GeoPoint geoPoint) {
adapter.add(geoPoint);
progressDialog.cancel();
selectedCategories = new ArrayList<String>();
selectedCategories.add(category);
searchRectanglePoints(selectedCategories.isEmpty() ? categoriesNames : selectedCategories);
}
@Override
public void handleFault(BackendlessFault backendlessFault) {
progressDialog.cancel();
Toast.makeText(EndlessTaggingActivity.this, backendlessFault.getMessage(), Toast.LENGTH_LONG).show();
}
});
}
});
builder.setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent(EndlessTaggingActivity.this, AddCommentActivity.class);
startActivity(intent);
finish();
}
});
AlertDialog dialog = builder.create();
dialog.show();
} else if (category == null && !pointCategories.isEmpty()) {
AlertDialog.Builder builder = new AlertDialog.Builder(EndlessTaggingActivity.this);
builder.setMessage(R.string.save_data);
builder.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
List<String> categories = new ArrayList<String>();
categories.addAll(pointCategories);
StringBuilder result = new StringBuilder();
for (int i = 0; i < pointCategories.size(); i++) {
result.append(pointCategories.get(i));
if (i < pointCategories.size() - 1)
result.append(", ");
}
categoryInLine = result.toString();
Map<String, String> metadata = new HashMap<String, String>();
metadata.put("pointName", pointNameNew);
metadata.put("pointDescription", categoryInLine);
metadata.put("photoUrl", photoUrl);
metadata.put("endlessTagging", "true");
if (onMapClick) {
latitude = latitudeOnMap;
longitude = longitudeOnMap;
}
GeoPoint geoPoint = new GeoPoint(latitude, longitude, categories, metadata);
progressDialog = ProgressDialog.show(EndlessTaggingActivity.this, "", "Loading", true);
Backendless.Geo.savePoint(geoPoint, new AsyncCallback<GeoPoint>() {
@Override
public void handleResponse(GeoPoint geoPoint) {
adapter.add(geoPoint);
selectedCategories = new ArrayList<String>();
selectedCategories.addAll(pointCategories);
searchRectanglePoints(selectedCategories.isEmpty() ? categoriesNames : selectedCategories);
progressDialog.cancel();
}
@Override
public void handleFault(BackendlessFault backendlessFault) {
progressDialog.cancel();
Toast.makeText(EndlessTaggingActivity.this, backendlessFault.getMessage(), Toast.LENGTH_LONG).show();
}
});
}
});
builder.setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent(EndlessTaggingActivity.this, AddCommentActivity.class);
startActivity(intent);
finish();
}
});
AlertDialog dialog = builder.create();
dialog.show();
} else if (category != null && !pointCategories.isEmpty()) {
AlertDialog.Builder builder = new AlertDialog.Builder(EndlessTaggingActivity.this);
builder.setMessage(R.string.save_data);
builder.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
List<String> categories = new ArrayList<String>();
categories.add(category);
categories.addAll(pointCategories);
StringBuilder result = new StringBuilder();
for (int i = 0; i < categories.size(); i++) {
result.append(categories.get(i));
if (i < categories.size() - 1)
result.append(", ");
}
categoryInLine = result.toString();
Map<String, String> metadata = new HashMap<String, String>();
metadata.put("pointName", pointNameNew);
metadata.put("pointDescription", categoryInLine);
metadata.put("photoUrl", photoUrl);
metadata.put("endlessTagging", "true");
if (onMapClick) {
latitude = latitudeOnMap;
longitude = longitudeOnMap;
}
GeoPoint geoPoint = new GeoPoint(latitude, longitude, categories, metadata);
progressDialog = ProgressDialog.show(EndlessTaggingActivity.this, "", "Loading", true);
Backendless.Geo.savePoint(geoPoint, new AsyncCallback<GeoPoint>() {
@Override
public void handleResponse(GeoPoint geoPoint) {
adapter.add(geoPoint);
progressDialog.cancel();
selectedCategories = new ArrayList<String>();
selectedCategories.add(category);
selectedCategories.addAll(pointCategories);
searchRectanglePoints(selectedCategories.isEmpty() ? categoriesNames : selectedCategories);
}
@Override
public void handleFault(BackendlessFault backendlessFault) {
progressDialog.cancel();
Toast.makeText(EndlessTaggingActivity.this, backendlessFault.getMessage(), Toast.LENGTH_LONG).show();
}
});
}
});
builder.setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent(EndlessTaggingActivity.this, AddCommentActivity.class);
startActivity(intent);
finish();
}
});
AlertDialog dialog = builder.create();
dialog.show();
}
break;
case Default.ADD_NEW_COMMENT:
googleMap.clear();
googleMap.addMarker(new MarkerOptions().position(myPosition).icon(BitmapDescriptorFactory.fromResource(R.drawable.marker_red)));
String nameCategory = data.getStringExtra(Default.SEARCH_CATEGORY_NAME);
selectedCategories = new ArrayList<String>();
selectedCategories.add(nameCategory);
searchRectanglePoints(selectedCategories.isEmpty() ? categoriesNames : selectedCategories);
break;
case Default.ADD_NEW_PHOTO_RESULT:
photoUrl = data.getStringExtra(Default.PHOTO_CAMERA_URL);
if (photoUrl == null)
photoUrl = data.getStringExtra(Default.PHOTO_BROWSE_URL);
filePath = data.getStringExtra(Default.FILE_PATH);
Intent intent = new Intent(EndlessTaggingActivity.this, CreateNewCategoryActivity.class);
startActivityForResult(intent, Default.ADD_NEW_CATEGORY_RESULT);
break;
default:
break;
}
}
Aggregations