Exemple #1
0
 /** Simple GPS destination. No db query required */
 public Destination(StorageService service, double lon, double lat) {
   GpsParams params = service.getGpsParams();
   mPref = new Preferences(service.getApplicationContext());
   if (null != params) {
     mLonInit = params.getLongitude();
     mLatInit = params.getLatitude();
   } else {
     mLonInit = lon;
     mLatInit = lat;
   }
   mInited = true;
   mService = service;
   mDbType = GPS;
   mFound = true;
   mLooking = false;
   mRunways = new LinkedList<Runway>();
   mTrackShape = new TrackShape();
   mEte = new String("--:--");
   mEta = new String("--:--");
   mFuel = new String("-.-");
   mLond = lon;
   mLatd = lat;
   mParams = new LinkedHashMap<String, String>();
   mFreq = new LinkedHashMap<String, String>();
   mAwos = new LinkedList<Awos>();
   mParams.put(DataBaseHelper.LONGITUDE, "" + mLond);
   mParams.put(DataBaseHelper.LATITUDE, "" + mLatd);
   mParams.put(DataBaseHelper.FACILITY_NAME, GPS);
   addTime();
   mTrackShape.updateShape(new GpsParams(getLocationInit()), Destination.this);
   mAfdFound = null;
   mName = Helper.truncGeo(lat) + "&" + Helper.truncGeo(lon);
   mDestType = GPS;
 }
Exemple #2
0
    /* (non-Javadoc)
     * @see android.os.AsyncTask#doInBackground(Params[])
     */
    @Override
    protected Boolean doInBackground(Object... vals) {

      Thread.currentThread().setName("Destination");

      Boolean guess = (Boolean) vals[0];
      String dbType = (String) vals[1];

      /*
       * If we dont know type, find with a guess.
       */
      if (guess) {
        StringPreference s = mService.getDBResource().searchOne(mName);
        if (null == s) {
          return false;
        }
        mDestType = s.getType();
        mName = s.getId();
      }

      /*
       * If GPS/Maps, parse
       */
      if (mName.contains("&")) {
        parseGps(mName, mDestType);
      }

      mWinds = mService.getDBResource().getWindsAloft(mLond, mLatd);

      if (mDestType.equals(UDW)) {
        Waypoint p = mService.getUDWMgr().get(mName);
        if (null != p) {
          mLatd = p.getLat();
          mLond = p.getLon();
          mCmt = p.getCmt();
          mParams.put(DataBaseHelper.LONGITUDE, "" + mLond);
          mParams.put(DataBaseHelper.LATITUDE, "" + mLatd);
          mParams.put(DataBaseHelper.FACILITY_NAME, UDWMgr.UDWDESCRIPTION);
          addTime();
          mAfdFound = null;
          mFound = true;
          mLooking = false;
          mDbType = UDW;
          mTrackShape.updateShape(new GpsParams(getLocationInit()), Destination.this);
          return true;
        }
        return false;
      }

      if (mDestType.equals(GPS)) {
        /*
         * For GPS coordinates, simply put parsed lon/lat in params
         * No need to query database
         */
        mParams = new LinkedHashMap<String, String>();
        mFreq = new LinkedHashMap<String, String>();
        mAwos = new LinkedList<Awos>();
        mParams.put(DataBaseHelper.LONGITUDE, "" + mLond);
        mParams.put(DataBaseHelper.LATITUDE, "" + mLatd);
        mParams.put(DataBaseHelper.FACILITY_NAME, GPS);
        addTime();
        mAfdFound = null;
        mFound = true;
        mLooking = false;
        mDbType = GPS;
        mTrackShape.updateShape(new GpsParams(getLocationInit()), Destination.this);
        if (!isGPSValid(mName)) {
          mFound = false;
        }
        if (!mName.contains("&")) {
          /*
           * This comes from MAPS to GPS for user edited
           */
          mName += "@" + mLatd + "&" + mLond;
        }
        return true;
      }

      if (null == mDataSource) {
        return false;
      }

      /*
       * For Google maps address, if we have already geo decoded it using internet,
       * then no need to do again because internet may not be available on flight.
       * It could be coming from storage and not google maps.
       */
      if (mDestType.equals(MAPS)) {

        if (mLond == 0 && mLatd == 0) {
          /*
           * We have already decomposed it?
           * No.
           */
          String strAddress = mName;

          Geocoder coder = new Geocoder(mService);
          Address location = null;

          /*
           * Decompose
           */
          try {
            List<Address> address = coder.getFromLocationName(strAddress, 1);
            if (address != null) {
              location = address.get(0);
            }
          } catch (Exception e) {
            return false;
          }

          if (null == location) {
            return false;
          }

          /*
           * Decomposed it
           *
           */
          try {
            mLond = Helper.truncGeo(location.getLongitude());
            mLatd = Helper.truncGeo(location.getLatitude());
          } catch (Exception e) {

          }
          if ((!Helper.isLatitudeSane(mLatd)) || (!Helper.isLongitudeSane(mLond))) {
            return false;
          }
        }
        /*
         * Common stuff
         */
        mParams = new LinkedHashMap<String, String>();
        mFreq = new LinkedHashMap<String, String>();
        mAwos = new LinkedList<Awos>();
        mAfdFound = null;
        mDbType = mDestType;
        mParams.put(DataBaseHelper.TYPE, mDestType);
        mParams.put(DataBaseHelper.FACILITY_NAME, mName);
        mParams.put(DataBaseHelper.LONGITUDE, "" + mLond);
        mParams.put(DataBaseHelper.LATITUDE, "" + mLatd);
        addTime();
        mName += "@" + mLatd + "&" + mLond;
        return true;
      }

      /*
       * For all others, find in DB
       */
      mDataSource.findDestination(mName, mDestType, dbType, mParams, mRunways, mFreq, mAwos);

      if (mDestType.equals(BASE)) {

        /*
         * Find A/FD
         */
        mAfdFound = null;
        final LinkedList<String> afdName = mDataSource.findAFD(mName);
        if (afdName.size() > 0) {
          FilenameFilter filter =
              new FilenameFilter() {
                public boolean accept(File directory, String fileName) {
                  boolean match = false;
                  for (final String name : afdName) {
                    match |=
                        fileName.matches(name + Preferences.IMAGE_EXTENSION)
                            || fileName.matches(name + "-[0-9]+" + Preferences.IMAGE_EXTENSION);
                  }
                  return match;
                }
              };
          String afd[] = null;
          afd = new File(mPref.mapsFolder() + "/afd/").list(filter);
          if (null != afd) {
            java.util.Arrays.sort(afd);
            int len1 = afd.length;
            String tmp1[] = new String[len1];
            for (int count = 0; count < len1; count++) {
              /*
               * Add A/FD
               */
              String tokens[] = afd[count].split(Preferences.IMAGE_EXTENSION);
              tmp1[count] = mPref.mapsFolder() + "/afd/" + tokens[0];
            }
            if (len1 > 0) {
              mAfdFound = tmp1;
            }
          }
        }
      }

      return (!mParams.isEmpty());
    }
Exemple #3
0
    /* (non-Javadoc)
     * @see android.os.AsyncTask#doInBackground(Params[])
     */
    @Override
    protected String doInBackground(Object... vals) {
      Thread.currentThread().setName("Closest");
      if (null == mService) {
        return null;
      }

      String airport = null;
      lon = (Double) vals[0];
      lat = (Double) vals[1];

      // if the user is moving instead of doing a long press, give them a chance
      // to cancel us before we start doing anything
      try {
        Thread.sleep(200);
      } catch (Exception e) {
      }

      if (isCancelled()) return "";

      /*
       * Get TFR tfr if touched on its top
       */
      LinkedList<TFRShape> shapes = null;
      List<AirSigMet> mets = null;
      if (null != mService) {
        shapes = mService.getTFRShapes();
        if (!mPref.useAdsbWeather()) {
          mets = mService.getInternetWeatherCache().getAirSigMet();
        }
      }
      if (null != shapes) {
        for (int shape = 0; shape < shapes.size(); shape++) {
          TFRShape cshape = shapes.get(shape);
          /*
           * Set TFR tfr
           */
          String txt = cshape.getTextIfTouched(lon, lat);
          if (null != txt) {
            tfr += txt + "\n--\n";
          }
        }
      }
      /*
       * Air/sigmets
       */
      if (null != mets) {
        for (int i = 0; i < mets.size(); i++) {
          MetShape cshape = mets.get(i).shape;
          if (null != cshape) {
            /*
             * Set MET tfr
             */
            String txt = cshape.getTextIfTouched(lon, lat);
            if (null != txt) {
              textMets += txt + "\n--\n";
            }
          }
        }
      }

      airport = mService.getDBResource().findClosestAirportID(lon, lat);
      if (isCancelled()) {
        return "";
      }

      if (null == airport) {
        airport = "" + Helper.truncGeo(lat) + "&" + Helper.truncGeo(lon);
      } else {
        freq = mService.getDBResource().findFrequencies(airport);
        if (isCancelled()) {
          return "";
        }

        taf = mService.getDBResource().getTAF(airport);
        if (isCancelled()) {
          return "";
        }

        metar = mService.getDBResource().getMETAR(airport);
        if (isCancelled()) {
          return "";
        }

        runways = mService.getDBResource().findRunways(airport);
        if (isCancelled()) {
          return "";
        }

        elev = mService.getDBResource().findElev(airport);
        if (isCancelled()) {
          return "";
        }

        LinkedList<String> fl = mService.getDBResource().findFuelCost(airport);
        if (fl.size() == 0) {
          // If fuel not available, show its not
          fuel = mContext.getString(R.string.NotAvailable);
        } else {
          fuel = "";
        }
        // Concat all fuel reports
        for (String s : fl) {
          fuel += s + "\n\n";
        }
        if (isCancelled()) return "";

        LinkedList<String> cm = mService.getDBResource().findRatings(airport);
        if (cm.size() == 0) {
          // If ratings not available, show its not
          ratings = mContext.getString(R.string.NotAvailable);
        } else {
          ratings = "";
        }
        // Concat all fuel reports
        for (String s : cm) {
          ratings += s + "\n\n";
        }
        if (isCancelled()) return "";
      }

      /*
       * ADSB gets this info from weather cache
       */
      if (!mPref.useAdsbWeather()) {
        aireps = mService.getDBResource().getAireps(lon, lat);
        if (isCancelled()) {
          return "";
        }

        wa = mService.getDBResource().getWindsAloft(lon, lat);
        if (isCancelled()) {
          return "";
        }

        sua = mService.getDBResource().getSua(lon, lat);
        if (isCancelled()) {
          return "";
        }

        if (mLayer != null) {
          layer = mLayer.getDate();
        }
        if (isCancelled()) {
          return "";
        }
      }

      mPointProjection =
          new Projection(mGpsParams.getLongitude(), mGpsParams.getLatitude(), lon, lat);
      return airport;
    }