Exemplo n.º 1
0
  /**
   * computes a geopoint the is the central geopoint between the user and the car. also it zooms so
   * both marks are visible on the map
   *
   * @author ricky barrette
   */
  protected void showBoth() {
    if (mMap != null) {
      if (mCarPoint == null) {
        Toast.makeText(getActivity(), R.string.mark_car_first, Toast.LENGTH_LONG).show();
      } else if (mMap.getUserLocation() == null) {
        Toast.makeText(getActivity(), R.string.no_gps_signal, Toast.LENGTH_LONG).show();
      } else {
        if (mMap.getMap() != null) {
          mMap.getMap().getController().stopAnimation(false);
          mMap.followUser(false);
          final GeoPoint user = mMap.getUserLocation();

          /*
           * here we null check our next set of value before we send
           * them off to geoutils if they have became null for some
           * reason we disable show both mode
           */
          if (mCarPoint != null && user != null) {
            new Thread(
                    new Runnable() {
                      @Override
                      public void run() {
                        mHandler.sendMessage(
                            mHandler.obtainMessage(MIDPOINT, GeoUtils.midPoint(mCarPoint, user)));
                      }
                    })
                .start();
          }

        } else {
          Log.e(TAG, "showBoth.mMap.getMap() is null");
        }
      }
    }
  }
Exemplo n.º 2
0
  /**
   * loads saved settings from files
   *
   * @author ricky barrette
   */
  private void loadSettings() {

    int lat =
        mSettings.getInt(Settings.LAT, 0); // mFileStream.readInteger(getString(R.string.lat));
    int lon =
        mSettings.getInt(Settings.LON, 0); // mFileStream.readInteger(getString(R.string.lon));

    // sets car geopoint up if lat and lon != 0
    if (lat != 0 && lon != 0) {
      setCar(new GeoPoint(lat, lon));
    }

    // sets measurement unit preference
    String mu = mSettings.getString(Settings.MEASUREMENT_UNIT, null);
    if (mu != null) {
      if (mu.equalsIgnoreCase("Standard")) {
        isMetric = false;
      }
      if (mu.equalsIgnoreCase("Metric")) {
        isMetric = true;
      }
    }

    // load compass options
    String compass_option = mSettings.getString(Settings.COMPASS_OPTION, "Small");
    if (compass_option.equalsIgnoreCase("Large")) {
      mMap.setCompassDrawables(R.drawable.needle_lrg, R.drawable.compass_lrg, 110, 110);
    } else if (compass_option.equalsIgnoreCase("Small")) {
      mMap.setCompassDrawables(R.drawable.needle_sm, R.drawable.compass_sm, 40, 40);
    } else {
      mMap.setCompassDrawables(R.drawable.needle_med, R.drawable.compass_med, 70, 70);
    }
  }
Exemplo n.º 3
0
 /**
  * removes the previous car overlay and replaces it with a new car overlay that represents the
  * users car at a specific geopoint
  *
  * @param point for geopoint of car
  * @author WWPowers 3-31-2010
  * @author ricky barrette
  */
 public void setCar(GeoPoint point) {
   isCarFound = false;
   hasLeftCar = false;
   mCarPoint = point;
   mCarOverlay = new FindMyCarOverlay(getActivity(), point);
   mMap.getMap().getOverlays().add(mCarOverlay);
   mMap.setDestination(mCarPoint);
 }
Exemplo n.º 4
0
  /*
   * (non-Javadoc)
   *
   * @see com.google.android.maps.MapActivity#onCreate(android.os.Bundle)
   */
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    setHasOptionsMenu(true);
    container.removeAllViews();

    View view = inflater.inflate(R.layout.map, container, false);

    mMap = (UserOverlayMapFragment) getFragmentManager().findFragmentById(R.id.map_fragment);
    mMap.setGeoPointLocationListener(this);
    setUiHandler();

    mAccuracy = (TextView) view.findViewById(R.id.tvAccuracy);
    mDistance = (TextView) view.findViewById(R.id.tvDistance);
    mSettings = getActivity().getSharedPreferences(Settings.SETTINGS, Context.MODE_WORLD_WRITEABLE);

    view.findViewById(R.id.my_location).setOnClickListener(this);
    view.findViewById(R.id.mark_my_location).setOnClickListener(this);
    view.findViewById(R.id.show_both).setOnClickListener(this);
    view.findViewById(R.id.parking_timer).setOnClickListener(this);
    view.findViewById(R.id.directions).setOnClickListener(this);

    this.mMap.setBuiltInZoomControls(true);
    return view;
  }
Exemplo n.º 5
0
  /**
   * using the users lat/lon saves car location to lat/lon files and passes that geopoint info to
   * setCar also writes address to notes
   *
   * @author ricky barrette 3-31-2010
   * @author WWPowers 3-31-2010
   */
  private void markCar() {
    // removed old parking timer
    // ParkingTimerDialog.stopTimer(this);

    GeoPoint user = mMap.getUserLocation();

    /*
     * if the user location is not null then save car lat and lon to files
     * pass geopoint info to set car, which will setup and show the car
     * overlay get address info and add it to the notes file
     *
     * else inform user that they dont have a gps signal
     */
    if (user != null) {
      mSettings
          .edit()
          .putInt(Settings.LAT, user.getLatitudeE6())
          .putInt(Settings.LON, user.getLongitudeE6())
          .commit();

      setCar(user);

      mListener.onCarMarked(user);

    } else {
      Toast.makeText(getActivity(), R.string.no_gps_signal, Toast.LENGTH_LONG).show();
    }
  }
Exemplo n.º 6
0
  /**
   * Trys to pan the map to the users location
   *
   * @author ricky barrette
   * @return true if successfull
   */
  private boolean myLocation() {
    mMap.followUser(true);

    /*
     * if we have a gps signal, then pan to user location else notify user
     * that there is no GPS signal
     *
     * we switch from MyLocationOverlay.getMyLocation() to referencing the
     * static variable MyCustomLocationOverlay.gpUser because for some
     * reason getMyLocation() would become null.
     *
     * @author ricky barrette
     */
    if (!panToGeoPoint(mMap.getUserLocation(), true)) {
      Toast.makeText(getActivity(), R.string.no_gps_signal, Toast.LENGTH_LONG).show();
      return false;
    } else return true;
  }
Exemplo n.º 7
0
  /**
   * removes the car overlay from the mapview.
   *
   * @return true if successful
   * @author ricky barrette
   */
  public boolean removeCar() {

    mCarPoint = null;
    mDistance.setText("0");
    mSettings.edit().remove(Settings.LAT).remove(Settings.LON).commit();
    mMap.setDestination(null);
    if (mListener != null) mListener.onCarDeleted();
    if (mDirections != null) {
      mDirections.removePath();
      mDirections = null;
    }

    try {
      mMap.getMap().getOverlays().remove(mCarOverlay);
    } catch (Exception e) {
      return false;
    }
    return true;
  }
Exemplo n.º 8
0
 /**
  * pans maps to where the a geopoint is, and if zoomIn is true, zooms in to level 20
  *
  * @param GeoPoint point - lat and lon of point to pan to
  * @param boolean zoomIn - true if map needs to be zoomed in
  * @return boolean false it geopoint is null
  * @author ricky barrette
  */
 public boolean panToGeoPoint(GeoPoint point, boolean zoomIn) {
   if (point != null) {
     if (mMap != null) {
       try {
         mMap.getMap().getController().setCenter(point);
       } catch (Exception e) {
         e.printStackTrace();
       }
       if (zoomIn) {
         mMap.getMap().getController().setZoom((mMap.getMap().getMaxZoomLevel() - 2));
       }
     } else {
       Log.e(TAG, "panToGeoPoint call. mapcontroller was null");
     }
   } else {
     Log.e(TAG, "panToGeoPoint call. geopoint was null");
     return false;
   }
   return true;
 }
Exemplo n.º 9
0
  /**
   * Marks the user's location
   *
   * @author ricky barrette
   */
  private void markMyLocation() {
    mMap.followUser(true);

    /*
     * if we have a gps signal, then pan to user location and then if there
     * is no car, mark the car location as the users location else show mark
     * car dialog
     *
     * we switch from MyLocationOverlay.getMyLocation() to referencing the
     * static variable MyCustomLocationOverlay.gpUser because for some
     * reason getMyLocation() would become null.
     *
     * @author ricky barrette
     */
    if (myLocation())
      if (mCarPoint != null) markCarDialog();
      else markCar();
  }
Exemplo n.º 10
0
 @Override
 public void onFirstFix(boolean isFirstFix) {
   if (mMap != null) if (isFirstFix) mMap.disableGPSProgess();
 }
Exemplo n.º 11
0
 /**
  * changes the map mode
  *
  * @author ricky barrette
  */
 private void changeMapMode() {
   if (mMap.getMap() != null) mMap.getMap().setSatellite(!mMap.getMap().isSatellite());
 }
Exemplo n.º 12
0
  /**
   * Displays the walking directions on the map
   *
   * @author ricky barrette
   */
  private void directions() {
    if (Main.isFull) {
      /*
       * if there is no car marked, then notify user else check to see if
       * there is directions
       */
      if (mCarPoint == null) {
        Toast.makeText(getActivity(), R.string.mark_car_first, Toast.LENGTH_LONG).show();
      } else {

        /*
         * Remove old directions if the exist
         */
        if (mDirections != null) mDirections.removePath();

        /*
         * if there is no location fix then notify user else download
         * directions and display them
         */
        if (mMap.getUserLocation() == null) {
          Toast.makeText(getActivity(), R.string.no_gps_signal, Toast.LENGTH_LONG).show();
        } else {

          mProgress =
              ProgressDialog.show(
                  getActivity(), getText(R.string.directions), getText(R.string.calculating), true);
          new Thread(
                  new Runnable() {

                    /**
                     * Notifys user about the error that occurred outside of the UI thread
                     *
                     * @param e
                     * @author ricky barrette
                     */
                    public void notify(final Exception e) {
                      e.printStackTrace();
                      getActivity()
                          .runOnUiThread(
                              new Runnable() {
                                @Override
                                public void run() {
                                  Toast.makeText(getActivity(), e.getMessage(), Toast.LENGTH_LONG)
                                      .show();
                                  mProgress.dismiss();
                                }
                              });
                    }

                    @Override
                    public void run() {
                      try {
                        mDirections =
                            new DirectionsOverlay(
                                mMap.getMap(), mMap.getUserLocation(), mCarPoint, MapFragment.this);
                      } catch (IllegalStateException e) {
                        notify(e);
                      } catch (ClientProtocolException e) {
                        notify(e);
                      } catch (IOException e) {
                        notify(e);
                      } catch (JSONException e) {
                        notify(e);
                      }
                    }
                  })
              .start();
        }
      }

    } else Main.featureInFullDialog(getActivity());
  }
Exemplo n.º 13
0
 /**
  * (non-Javadoc)
  *
  * @see android.support.v4.app.Fragment#onResume()
  */
 @Override
 public void onResume() {
   loadSettings();
   if (mMap != null) mMap.enableGPSProgess();
   super.onResume();
 }