private void runOnExitAction() {

    final String fenceName = fenceNameField.getText().toString();

    if (fenceName.isEmpty()) {
      Toast.makeText(FenceDemo.this, "Fence name is empty!", Toast.LENGTH_SHORT).show();
    } else {
      Backendless.Geo.runOnExitAction(
          fenceName,
          new AsyncCallback<Integer>() {
            @Override
            public void handleResponse(Integer response) {
              Toast.makeText(
                      FenceDemo.this, "Action ran for: " + response + " points", Toast.LENGTH_SHORT)
                  .show();
            }

            @Override
            public void handleFault(BackendlessFault fault) {
              Toast.makeText(FenceDemo.this, "Failed: " + fault.toString(), Toast.LENGTH_LONG)
                  .show();
            }
          });
    }
  }
  private void stopFenceMonitoring() {
    String fenceName = fenceNameField.getText().toString();

    if (fenceName.isEmpty()) {
      try {
        Backendless.Geo.stopGeofenceMonitoring();
        Toast.makeText(FenceDemo.this, "Success", Toast.LENGTH_SHORT).show();
      } catch (Exception e) {
        Toast.makeText(FenceDemo.this, "Failed " + e.toString(), Toast.LENGTH_LONG).show();
      }
    } else {
      try {
        Backendless.Geo.stopGeofenceMonitoring(fenceName);
        Toast.makeText(FenceDemo.this, "Success. Fence name: " + fenceName, Toast.LENGTH_SHORT)
            .show();
      } catch (Exception e) {
        Toast.makeText(FenceDemo.this, "Failed " + e.toString(), Toast.LENGTH_LONG).show();
      }
    }
  }
        @Override
        public void onClick(View view) {
          progressDialog = UIFactory.getDefaultProgressDialog(MatchViewActivity.this);

          targetUserGeoPoint.putMetadata(
              Backendless.UserService.CurrentUser().getEmail(), Defaults.PING_TAG);
          Backendless.Geo.savePoint(
              targetUserGeoPoint,
              new ResponseAsyncCallback<GeoPoint>(MatchViewActivity.this) {
                @Override
                public void handleResponse(GeoPoint response) {
                  if (targetUserDeviceRegistrationId == null
                      || targetUserDeviceRegistrationId.equals("")) return;

                  DeliveryOptions deliveryOptions = new DeliveryOptions();
                  deliveryOptions.setPushBroadcast(PushBroadcastMask.ALL);
                  deliveryOptions.addPushSinglecast(targetUserDeviceRegistrationId);
                  Backendless.Messaging.publish(
                      Defaults.MESSAGING_CHANNEL,
                      targetUserName,
                      null,
                      deliveryOptions,
                      new ResponseAsyncCallback<MessageStatus>(MatchViewActivity.this) {
                        @Override
                        public void handleResponse(MessageStatus response) {
                          progressDialog.cancel();
                          String targetUserEmail =
                              targetUserGeoPoint.getMetadata(BackendlessUser.EMAIL_KEY);

                          if (currentUserGeoPoint.getMetadata().containsKey(targetUserEmail))
                            Lifecycle.runPingsActivity(MatchViewActivity.this, currentUserGeoPoint);
                          else
                            Toast.makeText(
                                    MatchViewActivity.this,
                                    "Your ping was successfully sent.",
                                    Toast.LENGTH_LONG)
                                .show();

                          Lifecycle.runFindMatchesActivity(MatchViewActivity.this);
                        }
                      });
                }
              });
        }
  private void getPointsFromFence() {
    final String fenceName = fenceNameField.getText().toString();
    final Boolean runForEach = ((Switch) findViewById(R.id.run_for_each_point_toggle)).isChecked();

    if (fenceName.isEmpty()) {
      Toast.makeText(FenceDemo.this, "Fence name is empty!", Toast.LENGTH_SHORT).show();
    } else {
      Backendless.Geo.getPoints(
          fenceName,
          new AsyncCallback<BackendlessCollection<GeoPoint>>() {
            @Override
            public void handleResponse(BackendlessCollection<GeoPoint> response) {
              int quantity = response.getTotalObjects();
              Toast.makeText(FenceDemo.this, "Found " + quantity + " points", Toast.LENGTH_SHORT)
                  .show();

              if (runForEach && response.getTotalObjects() != 0) {
                Iterator<GeoPoint> iterator = response.getData().iterator();

                while (iterator.hasNext()) {
                  GeoPoint point = iterator.next();
                  // run action for each
                  Backendless.Geo.runOnEnterAction(
                      fenceName,
                      point,
                      new AsyncCallback<Void>() {
                        @Override
                        public void handleResponse(Void vvoid) {
                          Toast.makeText(
                                  FenceDemo.this, "RunOnEnterAction passed", Toast.LENGTH_SHORT)
                              .show();
                        }

                        @Override
                        public void handleFault(BackendlessFault backendlessFault) {
                          Toast.makeText(
                                  FenceDemo.this,
                                  "RunOnEnterAction failed: " + backendlessFault.toString(),
                                  Toast.LENGTH_LONG)
                              .show();
                        }
                      });

                  Backendless.Geo.runOnExitAction(
                      fenceName,
                      point,
                      new AsyncCallback<Void>() {
                        @Override
                        public void handleResponse(Void aVoid) {
                          Toast.makeText(
                                  FenceDemo.this, "RunOnExitAction passed", Toast.LENGTH_SHORT)
                              .show();
                        }

                        @Override
                        public void handleFault(BackendlessFault backendlessFault) {
                          Toast.makeText(
                                  FenceDemo.this,
                                  "RunOnExitAction failed: " + backendlessFault.toString(),
                                  Toast.LENGTH_LONG)
                              .show();
                        }
                      });

                  Backendless.Geo.runOnStayAction(
                      fenceName,
                      point,
                      new AsyncCallback<Void>() {
                        @Override
                        public void handleResponse(Void aVoid) {
                          Toast.makeText(
                                  FenceDemo.this, "RunOnStayAction passed", Toast.LENGTH_SHORT)
                              .show();
                        }

                        @Override
                        public void handleFault(BackendlessFault backendlessFault) {
                          Toast.makeText(
                                  FenceDemo.this,
                                  "RunOnStayAction failed: " + backendlessFault.toString(),
                                  Toast.LENGTH_LONG)
                              .show();
                        }
                      });
                }
              }
            }

            @Override
            public void handleFault(BackendlessFault fault) {
              Toast.makeText(FenceDemo.this, "Failed: " + fault.toString(), Toast.LENGTH_LONG)
                  .show();
            }
          });
    }
  }
  private void startFenceMonitoring() {
    boolean useCustomCallback = ((Switch) findViewById(R.id.customCallbackToggle)).isChecked();
    final String fenceName = fenceNameField.getText().toString();
    IGeofenceCallback customCallback = new CustomCallBack();

    if (fenceName == null || fenceName.isEmpty()) {
      if (useCustomCallback) {
        Backendless.Geo.startGeofenceMonitoring(
            customCallback,
            new AsyncCallback<Void>() {
              @Override
              public void handleResponse(Void aVoid) {
                Toast.makeText(FenceDemo.this, "Fences monitoring started", Toast.LENGTH_SHORT)
                    .show();
              }

              @Override
              public void handleFault(BackendlessFault backendlessFault) {
                Toast.makeText(
                        FenceDemo.this, "Failed: " + backendlessFault.toString(), Toast.LENGTH_LONG)
                    .show();
              }
            });
      } else {
        Backendless.Geo.startGeofenceMonitoring(
            geoPoint,
            new AsyncCallback<Void>() {
              @Override
              public void handleResponse(Void aVoid) {
                Toast.makeText(FenceDemo.this, "Fences monitoring started", Toast.LENGTH_SHORT)
                    .show();
              }

              @Override
              public void handleFault(BackendlessFault backendlessFault) {
                Toast.makeText(
                        FenceDemo.this, "Failed: " + backendlessFault.toString(), Toast.LENGTH_LONG)
                    .show();
              }
            });
      }
    } else {
      if (useCustomCallback) {
        Backendless.Geo.startGeofenceMonitoring(
            fenceName,
            customCallback,
            new AsyncCallback<Void>() {
              @Override
              public void handleResponse(Void aVoid) {
                Toast.makeText(
                        FenceDemo.this,
                        "Fence " + fenceName + " monitoring started",
                        Toast.LENGTH_SHORT)
                    .show();
              }

              @Override
              public void handleFault(BackendlessFault backendlessFault) {
                Toast.makeText(
                        FenceDemo.this, "Failed: " + backendlessFault.toString(), Toast.LENGTH_LONG)
                    .show();
              }
            });
      } else {
        Backendless.Geo.startGeofenceMonitoring(
            fenceName,
            geoPoint,
            new AsyncCallback<Void>() {
              @Override
              public void handleResponse(Void aVoid) {
                Toast.makeText(
                        FenceDemo.this,
                        "Fence " + fenceName + " monitoring started",
                        Toast.LENGTH_SHORT)
                    .show();
              }

              @Override
              public void handleFault(BackendlessFault backendlessFault) {
                Toast.makeText(
                        FenceDemo.this, "Failed: " + backendlessFault.toString(), Toast.LENGTH_LONG)
                    .show();
              }
            });
      }
    }
  }
  @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)));

    // Food
    Map<String, String> metaDataFood = new HashMap<String, String>();
    metaDataFood.put("Asian", foodName);
    metaDataFood.put("Caribean", foodName);
    metaDataFood.put("Bar food", foodName);
    metaDataFood.put("French", foodName);
    metaDataFood.put("Mediterranean", foodName);
    metaDataFood.put("Greek", foodName);
    metaDataFood.put("Spanish", foodName);
    metaDataFood.put("Mexican", foodName);
    metaDataFood.put("Thai", foodName);
    int maxPoints = 10;
    BackendlessGeoQuery backendlessGeoQuery = new BackendlessGeoQuery(metaDataFood, maxPoints);
    backendlessGeoQuery.setPageSize(50);
    backendlessGeoQuery.setIncludeMeta(true);
    food = false;
    Backendless.Geo.relativeFind(backendlessGeoQuery, gotFoodCallback);
    // Music
    Map<String, String> metaDataMusic = new HashMap<String, String>();
    metaDataMusic.put("Classical", musicName);
    metaDataMusic.put("Jazz", musicName);
    metaDataMusic.put("Hip-hop", musicName);
    metaDataMusic.put("Reggae", musicName);
    metaDataMusic.put("Blues", musicName);
    metaDataMusic.put("Trance", musicName);
    metaDataMusic.put("House", musicName);
    metaDataMusic.put("Rock", musicName);
    metaDataMusic.put("Folk", musicName);
    backendlessGeoQuery = new BackendlessGeoQuery(metaDataMusic, maxPoints);
    backendlessGeoQuery.setPageSize(50);
    backendlessGeoQuery.setIncludeMeta(true);
    music = false;
    Backendless.Geo.relativeFind(backendlessGeoQuery, gotMusicCallback);
    // Hobbies
    Map<String, String> metaDataHobbies = new HashMap<String, String>();
    metaDataHobbies.put("Fishing", hobbiesName);
    metaDataHobbies.put("Diving", hobbiesName);
    metaDataHobbies.put("Rock climbing", hobbiesName);
    metaDataHobbies.put("Hiking", hobbiesName);
    metaDataHobbies.put("Reading", hobbiesName);
    metaDataHobbies.put("Dancing", hobbiesName);
    metaDataHobbies.put("Cooking", hobbiesName);
    metaDataHobbies.put("Surfing", hobbiesName);
    metaDataHobbies.put("Photography", hobbiesName);
    backendlessGeoQuery = new BackendlessGeoQuery(metaDataHobbies, maxPoints);
    backendlessGeoQuery.setPageSize(50);
    backendlessGeoQuery.setIncludeMeta(true);
    hobbies = false;
    Backendless.Geo.relativeFind(backendlessGeoQuery, gotHobbiesCallback);
    // Travel
    Map<String, String> metaDataTravel = new HashMap<String, String>();
    metaDataTravel.put("Cruise", travelName);
    metaDataTravel.put("B&B", travelName);
    metaDataTravel.put("Europe", travelName);
    metaDataTravel.put("Asia", travelName);
    metaDataTravel.put("Caribean", travelName);
    metaDataTravel.put("Mountains", travelName);
    metaDataTravel.put("Whale watching", travelName);
    metaDataTravel.put("Active travel", travelName);
    metaDataTravel.put("Passive travel", travelName);
    backendlessGeoQuery = new BackendlessGeoQuery(metaDataTravel, maxPoints);
    backendlessGeoQuery.setPageSize(50);
    backendlessGeoQuery.setIncludeMeta(true);
    travel = false;
    Backendless.Geo.relativeFind(backendlessGeoQuery, gotTravelCallback);
  }