Пример #1
0
  /** Called when a menu item is selected. */
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
      case LOCATION_MOCKUP_SWITCH_ID:
        if (locationSource.getMode() == LocationSource.REAL_MODE) {
          // From REAL mode to MOCK mode:
          locationSource.setMode(LocationSource.MOCK_MODE);
          item.setTitle(R.string.map_menu_realGPS);
        } else {
          // From MOCK mode to REAL mode:
          locationSource.setMode(LocationSource.REAL_MODE);
          item.setTitle(R.string.map_menu_mockGPS);
        }
        break;
      case START_AR_VIEW_ID:
        startARViewBasic();
        break;
      case CENTER_MAP_ON_CURRENT_LOCATION_ID:
        Location lastLoc = locationListener.getLastLocation();
        if (lastLoc != null) myMapCtrl.animateTo(location2GP(locationListener.getLastLocation()));
        break;
    }

    return super.onOptionsItemSelected(item);
  }
Пример #2
0
 /** Called right before your activity's option menu is displayed. */
 @Override
 public boolean onPrepareOptionsMenu(Menu menu) {
   super.onPrepareOptionsMenu(menu);
   menu.getItem(LOCATION_MOCKUP_SWITCH_ID - 1)
       .setEnabled(locationSource != null && LocationSource.canBeUsed(getApplicationContext()));
   return true;
 }
Пример #3
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();
  }