Esempio n. 1
0
  /**
   * Method handles actions respectively for input coordinate entered in EditText. When coordinate
   * argument is Double.NaN it means EditText field is empty, so error will be disabled and target
   * location set to null (reset). Proper coordinate argument will be set to customTargetLocation
   * and its Location will be passed to compassToLocationProvider. Passing a null will cause
   * resetting targetLocation, which is intended. Sets TitleTextView and coordinates EditTexts
   * errors status.
   *
   * @param latitude indicates whether coordinate is latitude or longitude coordinate
   * @param coordinate represents value of coordinate in Double
   */
  @Override
  public void onCoordinateChanged(boolean latitude, Double coordinate) {
    // when coordinate is NaN (i.e. when empty EditText)
    if (Double.isNaN(coordinate)) {
      clearCoordinateInputOutOfRangeError(latitude);
      setTitleTextView(getString(R.string.point_north_title), Color.BLACK);
      // set null location, so needle will reset its state
      compassToLocationProvider.setTargetLocation(null);
      return;
    }

    if (latitude) {
      customTargetLocation.setLatitude(coordinate);
    } else {
      customTargetLocation.setLongitude(coordinate);
    }
    // even when coordinate is out its of range, then target location will be set to null (reset)
    compassToLocationProvider.setTargetLocation(customTargetLocation.getLocation());

    if (customTargetLocation.isCorrect()) {
      setTitleTextView(getString(R.string.point_location_title), Color.BLACK);
      clearCoordinateInputOutOfRangeError(latitude);
    }
    // incorrect location doesn't mean that input value is incorrect!
    if (!Utils.isCoordinateInRange(coordinate, latitude)) {
      onEmptyOrWrongInput(latitude, true);
    }
  }
Esempio n. 2
0
 @Override
 public void setLayoutElementsOnProvider(boolean enabled) {
   setCoordinatesEditTextEnabled(enabled);
   if (enabled) {
     setSubtitleTextView(getString(R.string.info_text_subtitle), null);
     if (customTargetLocation.isCorrect()) {
       compassToLocationProvider.setTargetLocation(customTargetLocation.getLocation());
       setTitleTextView(getString(R.string.point_location_title), Color.BLACK);
     }
   } else {
     setTitleTextView(getString(R.string.point_north_title), Color.BLACK);
     setSubtitleTextView(
         getString(R.string.touch_info_error_subtitle),
         v -> setupLayoutOnLocationServicesCheckUp());
   }
 }