Esempio n. 1
0
 // Build up a storage name using the values passed in
 public static String getStorageName(
     String destType, String dbType, String facilityName, String id) {
   StringPreference s = new StringPreference(destType, dbType, facilityName, id);
   return s.getHashedName();
 }
Esempio n. 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());
    }
Esempio n. 3
0
 /** @return */
 public String getStorageName() {
   StringPreference s = new StringPreference(mDestType, mDbType, getFacilityName(), getID());
   return s.getHashedName();
 }