Search in sources :

Example 6 with BackendlessGeoQuery

use of com.backendless.geo.BackendlessGeoQuery 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;
    }
}
Also used : Gender(com.backendless.examples.endless.matchmaker.models.local.Gender) BackendlessGeoQuery(com.backendless.geo.BackendlessGeoQuery) GeoPoint(com.backendless.geo.GeoPoint) ParseException(java.text.ParseException)

Example 7 with BackendlessGeoQuery

use of com.backendless.geo.BackendlessGeoQuery 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();
        }
    });
}
Also used : BackendlessGeoQuery(com.backendless.geo.BackendlessGeoQuery) BackendlessFault(com.backendless.exceptions.BackendlessFault) GeoPoint(com.backendless.geo.GeoPoint) BackendlessCollection(com.backendless.BackendlessCollection) GoogleMap(com.google.android.gms.maps.GoogleMap)

Aggregations

BackendlessGeoQuery (com.backendless.geo.BackendlessGeoQuery)7 GeoPoint (com.backendless.geo.GeoPoint)6 BackendlessCollection (com.backendless.BackendlessCollection)3 BackendlessFault (com.backendless.exceptions.BackendlessFault)3 Intent (android.content.Intent)2 View (android.view.View)2 GoogleMap (com.google.android.gms.maps.GoogleMap)2 AlertDialog (android.app.AlertDialog)1 DialogInterface (android.content.DialogInterface)1 SharedPreferences (android.content.SharedPreferences)1 Criteria (android.location.Criteria)1 Location (android.location.Location)1 LocationListener (android.location.LocationListener)1 LocationManager (android.location.LocationManager)1 Bundle (android.os.Bundle)1 LayoutInflater (android.view.LayoutInflater)1 ListView (android.widget.ListView)1 SeekBar (android.widget.SeekBar)1 TextView (android.widget.TextView)1 Gender (com.backendless.examples.endless.matchmaker.models.local.Gender)1