Search in sources :

Example 1 with BackendlessGeoQuery

use of com.backendless.geo.BackendlessGeoQuery in project Android-SDK by Backendless.

the class FindMatchesActivity method findMatches.

private void findMatches() {
    if (progressBar.getVisibility() == View.VISIBLE)
        return;
    progressBar.setVisibility(View.VISIBLE);
    BackendlessGeoQuery backendlessGeoQuery = new BackendlessGeoQuery();
    backendlessGeoQuery.setSearchRectangle(new double[] { NELat, SWLon, SWLat, NELon });
    Backendless.Geo.getPoints(backendlessGeoQuery, gotPointsCallback);
}
Also used : BackendlessGeoQuery(com.backendless.geo.BackendlessGeoQuery)

Example 2 with BackendlessGeoQuery

use of com.backendless.geo.BackendlessGeoQuery 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);
}
Also used : Criteria(android.location.Criteria) BackendlessGeoQuery(com.backendless.geo.BackendlessGeoQuery) GeoPoint(com.backendless.geo.GeoPoint) GoogleMap(com.google.android.gms.maps.GoogleMap) LocationListener(android.location.LocationListener) LocationManager(android.location.LocationManager) SharedPreferences(android.content.SharedPreferences) Bundle(android.os.Bundle) MapFragment(com.google.android.gms.maps.MapFragment) BackendlessFault(com.backendless.exceptions.BackendlessFault) BackendlessCollection(com.backendless.BackendlessCollection) GoogleMap(com.google.android.gms.maps.GoogleMap) Location(android.location.Location)

Example 3 with BackendlessGeoQuery

use of com.backendless.geo.BackendlessGeoQuery 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);
}
Also used : HashMap(java.util.HashMap) BackendlessGeoQuery(com.backendless.geo.BackendlessGeoQuery) GeoPoint(com.backendless.geo.GeoPoint)

Example 4 with BackendlessGeoQuery

use of com.backendless.geo.BackendlessGeoQuery in project Android-SDK by Backendless.

the class PointsActivity method onCreate.

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.points);
    ListView listview = (ListView) findViewById(R.id.pointsView);
    View header = getLayoutInflater().inflate(R.layout.points_header, null);
    listview.addHeaderView(header);
    adapter = new PointsAdapter(this);
    listview.setAdapter(adapter);
    final TextView radiusField = (TextView) findViewById(R.id.radiusField);
    final SeekBar radiusBar = (SeekBar) findViewById(R.id.radiusBar);
    radiusBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            radiusField.setText(String.valueOf(progress));
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        /*stub*/
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
            int radius = seekBar.getProgress();
            backendlessGeoQuery.setRadius(radius == 0 ? 0.0000001 : radius);
            searchPoints();
        }
    });
    Intent intent = getIntent();
    double latitude = intent.getDoubleExtra(Defaults.LATITUDE_TAG, 0);
    double longitude = intent.getDoubleExtra(Defaults.LONGITUDE_TAG, 0);
    int radius = intent.getIntExtra(Defaults.RADIUS_TAG, 1);
    radiusBar.setProgress(radius);
    backendlessGeoQuery = new BackendlessGeoQuery(latitude, longitude, radius, Units.KILOMETERS);
    backendlessGeoQuery.addCategory(Defaults.SAMPLE_CATEGORY);
    backendlessGeoQuery.setIncludeMeta(true);
    searchPoints();
}
Also used : ListView(android.widget.ListView) SeekBar(android.widget.SeekBar) TextView(android.widget.TextView) Intent(android.content.Intent) BackendlessGeoQuery(com.backendless.geo.BackendlessGeoQuery) TextView(android.widget.TextView) View(android.view.View) ListView(android.widget.ListView) GeoPoint(com.backendless.geo.GeoPoint)

Example 5 with BackendlessGeoQuery

use of com.backendless.geo.BackendlessGeoQuery 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();
        }
    });
}
Also used : AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) Intent(android.content.Intent) BackendlessGeoQuery(com.backendless.geo.BackendlessGeoQuery) View(android.view.View) BackendlessFault(com.backendless.exceptions.BackendlessFault) GeoPoint(com.backendless.geo.GeoPoint) LayoutInflater(android.view.LayoutInflater) BackendlessCollection(com.backendless.BackendlessCollection) List(java.util.List)

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