Exemplo n.º 1
0
  /**
   * Saves an Array of Entries to the specified location on the sdcard
   *
   * @param ds
   * @param path
   */
  public static void saveToSdCard(ArrayList<Entry> entries, String path) {

    File sdcard = Environment.getExternalStorageDirectory();

    File saved = new File(sdcard, path);
    if (!saved.exists()) {
      try {
        saved.createNewFile();
      } catch (IOException e) {
        Log.e(LOG, e.toString());
      }
    }
    try {
      // BufferedWriter for performance, true to set append to file flag
      BufferedWriter buf = new BufferedWriter(new FileWriter(saved, true));

      for (Entry e : entries) {

        buf.append(e.getVal() + "#" + e.getXIndex());
        buf.newLine();
      }

      buf.close();
    } catch (IOException e) {
      Log.e(LOG, e.toString());
    }
  }
Exemplo n.º 2
0
  /**
   * Adds an Entry to the DataSet at the specified index. Entries are added to the end of the list.
   *
   * @param e
   * @param dataSetIndex
   */
  public void addEntry(Entry e, int dataSetIndex) {

    float val = e.getVal();

    mYValCount += 1;
    mYValueSum += val;

    if (mYMax < val) mYMax = val;
    if (mYMin > val) mYMin = val;

    if (mDataSets == null) mDataSets = new ArrayList<T>();

    if (mDataSets.size() > dataSetIndex) {

      T set = mDataSets.get(dataSetIndex);

      if (set != null) {

        // add the entry to the dataset
        set.addEntry(e);
      }
    } else {
      Log.e("addEntry", "Cannot add Entry because dataSetIndex too high.");
    }
  }
Exemplo n.º 3
0
  /**
   * Adds an Entry to the DataSet at the specified index. Entries are added to the end of the list.
   *
   * @param e
   * @param dataSetIndex
   */
  public void addEntry(Entry e, int dataSetIndex) {

    if (mDataSets.size() > dataSetIndex && dataSetIndex >= 0) {

      IDataSet set = mDataSets.get(dataSetIndex);
      // add the entry to the dataset
      if (!set.addEntry(e)) return;

      float val = e.getVal();

      if (mYValCount == 0) {
        mYMin = val;
        mYMax = val;

        if (set.getAxisDependency() == AxisDependency.LEFT) {

          mLeftAxisMax = e.getVal();
          mLeftAxisMin = e.getVal();
        } else {
          mRightAxisMax = e.getVal();
          mRightAxisMin = e.getVal();
        }
      } else {

        if (mYMax < val) mYMax = val;
        if (mYMin > val) mYMin = val;

        if (set.getAxisDependency() == AxisDependency.LEFT) {

          if (mLeftAxisMax < e.getVal()) mLeftAxisMax = e.getVal();
          if (mLeftAxisMin > e.getVal()) mLeftAxisMin = e.getVal();
        } else {
          if (mRightAxisMax < e.getVal()) mRightAxisMax = e.getVal();
          if (mRightAxisMin > e.getVal()) mRightAxisMin = e.getVal();
        }
      }

      mYValCount += 1;

      handleEmptyAxis(getFirstLeft(), getFirstRight());

    } else {
      Log.e("addEntry", "Cannot add Entry because dataSetIndex too high or too low.");
    }
  }
Exemplo n.º 4
0
  /**
   * Removes the given Entry object from the DataSet at the specified index.
   *
   * @param e
   * @param dataSetIndex
   */
  public boolean removeEntry(Entry e, int dataSetIndex) {

    // entry null, outofbounds
    if (e == null || dataSetIndex >= mDataSets.size()) return false;

    // remove the entry from the dataset
    boolean removed = mDataSets.get(dataSetIndex).removeEntry(e.getXIndex());

    if (removed) {

      float val = e.getVal();

      mYValCount -= 1;
      mYValueSum -= val;

      calcMinMax(mDataSets);
    }

    return removed;
  }