示例#1
0
    @Override
    protected List<String> doInBackground(Void... params) {
      List<String> SpotNames = new ArrayList<String>();

      try {

        // if(act != null)
        // {
        Log.d(LOG_TAG, "Getting DB");
        Dao<SurfDataPointBase, Integer> surfDataPointBaseDao =
            getHelper().getSurfDataPointBaseDao();
        // Log.d(LOG_TAG, "Got instance of DB inside fragment.");

        List<SurfDataPointBase> pointList = surfDataPointBaseDao.queryForAll();

        Log.d(LOG_TAG, "Adding Spot Names");
        for (SurfDataPointBase s : pointList) {
          if (!SpotNames.contains(s.getSpotName())) {
            Log.d(LOG_TAG, "Adding " + s.getSpotName() + " to the spot name box.");
            SpotNames.add(s.getSpotName());
          }
        }
        // }

      } catch (SQLException e) {
        Log.d(LOG_TAG, "Sql Exception", e);
        e.printStackTrace();
      }

      return SpotNames;
    }
示例#2
0
  public void addNewSpot(View view) {
    Log.d(LOG_TAG, "Starting Add New Spot");

    EditText logText = (EditText) findViewById(R.id.surf_log);
    String logMessage = logText.getText().toString();

    EditText spotNameText = (EditText) findViewById(R.id.spot_name);
    String spotName = spotNameText.getText().toString();

    int spotId;
    Log.d(LOG_TAG, "Got log message - " + logMessage);

    try {
      Log.d(LOG_TAG, "Getting DB");
      Dao<SurfDataPointBase, Integer> surfDataPointBaseDao = getHelper().getSurfDataPointBaseDao();

      Log.d(LOG_TAG, "Getting Location");

      if (latitude == 0 || longitude == 0) {
        Log.d(LOG_TAG, "Location could not be found. Using default location.");
        latitude = 10;
        longitude = 10;
      }

      Log.d(LOG_TAG, "Putting point in DB.");
      SurfDataPointBase point =
          new SurfDataPointBase(
              new Date(),
              logMessage,
              true,
              latitude,
              longitude,
              spotName.isEmpty() ? "Default Spot" : spotName);

      surfDataPointBaseDao.create(point);
      spotId = point.getId();

      PopUpSpotAddedNotification();

      logText.setText("");
      spotNameText.setText("");

    } catch (SQLException e) {
      Log.e(LOG_TAG, "Database exception", e);
      return;
    } catch (Exception ex) {
      Log.e(LOG_TAG, "General exception", ex);
      return;
    }

    // Go get the Buoy Data and add it to the DB
    final int spotIdFinal = spotId;
    new Thread(
            new Runnable() {

              public void run() {
                try {
                  Log.d(LOG_TAG, "Getting Buoy Data");
                  BuoyData buoyData = new BuoyData();
                  buoyData = RSSReader.readBuoyData("46086");

                  Log.d(LOG_TAG, "Adding Buoy Data to DB");
                  Dao<BuoyDataPointBase, Integer> buoyDataPointBaseDao =
                      getHelper().getBuoyDataPointBaseDao();
                  BuoyDataPointBase buoyPoint =
                      new BuoyDataPointBase(buoyData, spotIdFinal, new DateTime(), false);
                  buoyDataPointBaseDao.create(buoyPoint);
                } catch (IOException e) {
                  Log.e(LOG_TAG, "IO exception", e);
                } catch (SQLException e) {
                  Log.e(LOG_TAG, "Database exception", e);
                }
              }
            })
        .start();

    // Go get the Tide Data and add it to the DB
    new Thread(
            new Runnable() {

              public void run() {
                try {
                  Log.d(LOG_TAG, "Getting Tide Data");
                  List<TidalData> tideData = new ArrayList<TidalData>();
                  tideData = TideDataReader.GetTideFromWebService("8454000");

                  if (tideData != null) {
                    Log.d(LOG_TAG, "Adding Tide Data to DB");
                    int len = tideData.size();
                    Dao<TidalDataPoint, Integer> tidalDataPointDao =
                        getHelper().getTidalDataPointDao();
                    for (int i = 0; i < len; i++) {
                      TidalDataPoint tidalPoint =
                          new TidalDataPoint(tideData.get(i), spotIdFinal, false);
                      tidalDataPointDao.create(tidalPoint);
                    }
                  }
                } catch (SQLException e) {
                  Log.e(LOG_TAG, "Database exception", e);
                }
              }
            })
        .start();
  }