예제 #1
0
 /**
  * called by the android framework when the activity gets active. Registers the myLocationOverlay
  * listeners.
  */
 @Override
 protected void onDestroy() {
   if (myLocationManager != null) myLocationManager.removeUpdates(locationListener);
   GeoQuestApp.getInstance().setGoogleMap(null);
   super.onDestroy();
 }
예제 #2
0
  /**
   * Called when the activity is first created. Setups google mapView, the map overlays and the
   * listeners
   */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    Log.d(this.getClass().getName(), "creating activity");
    super.onCreate(savedInstanceState);

    // get extras
    Bundle extras = getIntent().getExtras();
    String id = extras.getString("missionID");
    mission = Mission.get(id);
    mission.setStatus(Globals.STATUS_RUNNING);

    setContentView(R.layout.main);

    // Setup Google MapView
    myMapView = (MapView) findViewById(R.id.mapview);
    myMapView.setBuiltInZoomControls(false);
    myMapView.displayZoomControls(false);

    String mapKind = mission.xmlMissionNode.attributeValue("mapkind");
    if (mapKind == null || mapKind.equals("map")) myMapView.setSatellite(false);
    else myMapView.setSatellite(true);

    myMapCtrl = myMapView.getController();

    myMapCtrl.setZoom(18);
    String zoomLevel = mission.xmlMissionNode.attributeValue("zoomlevel");
    if (zoomLevel != null) {
      int zoomLevelInt = Integer.parseInt(zoomLevel);
      if (zoomLevelInt > 0 && zoomLevelInt < 24) myMapCtrl.setZoom(zoomLevelInt);
    }

    // Setup Zoom Controls:
    Button zoomIn = (Button) findViewById(R.id.zoom_in);
    zoomIn.setOnClickListener(
        new OnClickListener() {

          public void onClick(View v) {
            myMapCtrl.zoomIn();
          }
        });

    Button zoomOut = (Button) findViewById(R.id.zoom_out);
    zoomOut.setOnClickListener(
        new OnClickListener() {

          public void onClick(View v) {
            myMapCtrl.zoomOut();
          }
        });

    // Initialize location stuff:
    locationListener =
        new GeoQuestLocationListener(this) {
          public void onRelevantLocationChanged(Location location) {
            super.onRelevantLocationChanged(location);
            GeoPoint point = location2GP(location);
            myMapCtrl.animateTo(point);

            // calculate distance to hotspots
            for (Iterator<HotspotOld> i = hotspots.listIterator(); i.hasNext(); ) {
              HotspotOld hotspot = i.next(); // TODO: throws a
              // ConcurrentModificationException
              // sometimes (hm)
              hotspot.inRange(location);
            }
          }
        };

    try {
      long timeStepMockMode = Long.parseLong(getText(R.string.map_mockGPSTimeInterval).toString());
      locationSource =
          new LocationSource(getApplicationContext(), locationListener, handler, timeStepMockMode);
      locationSource.setMode(LocationSource.REAL_MODE);
    } catch (Exception e) {
      e.printStackTrace();
    }

    // startMissionsList
    startMissionPanel = (LinearLayout) findViewById(R.id.startMissionPanel);

    // Players Location Overlay
    myLocationOverlay = new MyLocationOverlay(this, myMapView);
    myLocationOverlay.enableCompass(); // doesn't work in the emulator?
    myLocationOverlay.enableMyLocation();
    myMapView.getOverlays().add(myLocationOverlay);

    GeoQuestApp.getInstance().setGoogleMap(myMapView);

    // Show loading screen to Parse the Game XML File
    // indirectly calls onCreateDialog() and initializes hotspots
    showDialog(READXML_DIALOG);

    mission.applyOnStartRules();
  }