コード例 #1
0
  // Callback method used by PlaceDownloaderTask
  public void addNewPlace(PlaceRecord place) {
    Log.i(TAG, "Entered addNewPlace()");

    if (place.getCountryName() == null || place.getCountryName().isEmpty()) {
      showToast(getString(R.string.no_country_string));
    } else if (!mAdapter.intersects(place.getLocation())) {
      place.setDateVisited(new Date());
      mAdapter.add(place);
      mAdapter.notifyDataSetChanged();
    } else {
      showToast(getString(R.string.duplicate_location_string));
    }
  }
コード例 #2
0
  // Callback method used by PlaceDownloaderTask
  public void addNewPlace(PlaceRecord place) {

    // TODO - Attempt to add place to the adapter, considering the following cases

    // A PlaceBadge for this location already exists - issue a Toast message
    // with the text - "You already have this location badge." Use the PlaceRecord
    // class' intersects() method to determine whether a PlaceBadge already exists
    // for a given location. Do not add the PlaceBadge to the adapter

    // The place is null - issue a Toast message with the text
    // "PlaceBadge could not be acquired"
    // Do not add the PlaceBadge to the adapter

    // The place has no country name - issue a Toast message
    // with the text - "There is no country at this location".
    // Do not add the PlaceBadge to the adapter

    // Otherwise - add the PlaceBadge to the adapter
    if (null == place) {
      Toast.makeText(
              this.getApplicationContext(), "PlaceBadge could not be acquired", Toast.LENGTH_LONG)
          .show();
    } else if (mAdapter.intersects(place.getLocation())) {
      Toast.makeText(
              this.getApplicationContext(),
              getText(R.string.duplicate_location_string),
              Toast.LENGTH_LONG)
          .show();
    } else if (null == place.getCountryName() || place.getCountryName().equals("")) {
      Toast.makeText(
              this.getApplicationContext(), getText(R.string.no_country_string), Toast.LENGTH_LONG)
          .show();
    } else {
      mAdapter.add(place);
    }
  }
  @Override
  protected PlaceRecord doInBackground(Location... location) {
    PlaceRecord place = null;

    if (mHasNetwork) {

      // Get the PlaceBadge information
      place = getPlaceFromURL(generateURL(USERNAME, location[0]));
      place.setLocation(location[0]);

      if ("" != place.getCountryName()) {
        place.setFlagBitmap(getFlagFromURL(place.getFlagUrl()));
      } else {
        place.setFlagBitmap(sStubBitmap);
      }
    } else {

      place = new PlaceRecord();
      place.setLocation(location[0]);
      place.setFlagBitmap(sStubBitmap);
      place.setFlagUrl("file://stub.gif");

      if (place.intersects(sMockLoc1)) {
        place.setCountryName(sMockCountryName1);
        place.setPlace(sMockPlaceName1);
      } else if (place.intersects(sMockLoc2)) {
        place.setCountryName(sMockCountryName1);
        place.setPlace(sMockPlaceName2);
      } else {
        place.setCountryName(sMockCountryNameInvalid);
        place.setPlace(sMockPlaceNameInvalid);
      }
    }

    return place;
  }
コード例 #4
0
  @Override
  protected PlaceRecord doInBackground(Location... location) {

    PlaceRecord place = null;

    if (HAS_NETWORK) {

      place = getPlaceFromURL(generateURL(USERNAME, location[0]));

      if ("" != place.getCountryName()) {
        place.setLocation(location[0]);
        place.setFlagBitmap(getFlagFromURL(place.getFlagUrl()));
      } else {
        place = null;
      }

    } else {
      place = new PlaceRecord(location[0]);
      if (location[0].distanceTo(mockLoc1) < 100) {
        place.setCountryName("United States");
        place.setPlace("The Greenhouse");
        place.setFlagBitmap(mStubBitmap);
      } else {
        place.setCountryName("United States");
        place.setPlace("Berwyn");
        place.setFlagBitmap(mStubBitmap);
      }
    }

    return place;
  }