예제 #1
0
  public void performRequest(
      IRequestListener<XmlableString> listener, HashMap<long[], XmlableString> storedData) {

    long[] key = new long[2];
    key[0] = get2DP(latitude);
    key[1] = get2DP(longitude);

    if (storedData.containsKey(key) && !storedData.get(key).outOfDate()) {
      listener.onRequestComplete(storedData.get(key));
    } else {
      Geocoder gc = new Geocoder(applicationContext);
      XmlableString place = null;
      try {
        List<Address> list = gc.getFromLocation(latitude, longitude, 5);
        int i = 0;
        while (i < list.size()) {
          String temp = list.get(i).getLocality();
          if (temp != null) {
            place = new XmlableString(temp);
            break;
          }
          i++;
        }
        if (place != null) {
          storedData.put(key, place);
        }
        listener.onRequestComplete(place);
      }
      // This is thrown if the phone has no Internet connection.
      catch (IOException e) {
        listener.onRequestFail(e);
      }
    }
  }
  private void internalInvoke(final Component component, final Object target) {
    // save a reference to the page because the component can be removed
    // during the invocation of the listener and thus lose its parent
    Page page = component.getPage();

    // initialization is required for stateless pages
    if (!page.isInitialized()) {
      page.internalInitialize();
    }

    ((IRequestListener) target).onRequest();
  }