示例#1
0
 /**
  * Called when a button has been clicked (non-Javadoc)
  *
  * @see android.view.View.OnClickListener#onClick(android.view.View)
  */
 @Override
 public void onClick(View v) {
   if (v.getId() == R.id.show_both) showBoth();
   else if (v.getId() == R.id.mark_my_location) markMyLocation();
   else if (v.getId() == R.id.my_location) myLocation();
   else if (v.getId() == R.id.directions) directions();
   else if (v.getId() == R.id.map_mode) changeMapMode();
   else if (v.getId() == R.id.parking_timer)
     if (!Main.isFull) Main.featureInFullDialog(getActivity());
     else getActivity().startActivity(new Intent(getActivity(), ParkignTimerActivity.class));
 }
示例#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());
  }