Example #1
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;
  }
Example #2
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());
  }