Exemplo n.º 1
0
  /** Displayd a dataset in the data table. */
  public void updateDataTable(SignalDataSet dataSet) {
    // Creates a line within table to store
    // datasource info.
    createDataRow(dataSet);
    SignalSource source = dataSet.getSource();

    // Sets row data.
    AndroidUtil.getTextViewByTag(this, dataSet.getId() + "-signalTypeText")
        .setText(source.getSignalType());
    AndroidUtil.getTextViewByTag(this, dataSet.getId() + "-sourceIdText").setText(source.getId());
    AndroidUtil.getTextViewByTag(this, dataSet.getId() + "-samplesCountText")
        .setText(dataSet.size() + "");

    SimpleDateFormat dt = new SimpleDateFormat("MM-dd hh:mm:ss");
    AndroidUtil.getTextViewByTag(this, dataSet.getId() + "-dateText")
        .setText(dt.format(dataSet.getDate()));

    DoubleSignalDataSet doubleSignalDataSet = (DoubleSignalDataSet) dataSet;
    AndroidUtil.getTextViewByTag(this, dataSet.getId() + "-minText")
        .setText(String.format("%.2f", doubleSignalDataSet.getMinValue()));
    AndroidUtil.getTextViewByTag(this, dataSet.getId() + "-maxText")
        .setText(String.format("%.2f", doubleSignalDataSet.getMaxValue()));
    AndroidUtil.getTextViewByTag(this, dataSet.getId() + "-avgText")
        .setText(String.format("%.2f", doubleSignalDataSet.getAverage()));
  }
Exemplo n.º 2
0
  /**
   * Creates a row in the data table to store a signal source data (source, date, count, min, max
   * and avg).
   */
  public void createDataRow(SignalDataSet dataSet) {
    SignalSource source = dataSet.getSource();
    ArrayList<View> containers = AndroidUtil.getViewsByTag(this, dataSet.getId() + "-dataRow");
    if (containers.size() == 0) { // There is NO row

      TableRow row = new TableRow(this);
      TableRow.LayoutParams lp =
          new TableRow.LayoutParams(
              TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT);
      row.setLayoutParams(lp);
      row.setTag(dataSet.getId() + "-dataRow");

      // Signal type.
      TextView signalType =
          createDataRowText(dataSet.getId() + "-signalTypeText", source.getSignalType(), 20f);

      // Source id.
      TextView sourceId = createDataRowText(dataSet.getId() + "-sourceIdText", source.getId(), 35f);

      // Record date.
      TextView date = createDataRowText(dataSet.getId() + "-dateText", "", 20f);

      // Samples recorded.
      TextView samplesCount = createDataRowText(dataSet.getId() + "-samplesCountText", "0", 15f);

      // Min, max and avg.
      TextView min = createDataRowText(dataSet.getId() + "-minText", "---", 15f);
      TextView max = createDataRowText(dataSet.getId() + "-maxText", "---", 15f);
      TextView avg = createDataRowText(dataSet.getId() + "-avgText", "---", 15f);

      row.addView(signalType);
      row.addView(sourceId);
      row.addView(date);
      row.addView(samplesCount);
      row.addView(min);
      row.addView(max);
      row.addView(avg);

      TableLayout table = (TableLayout) findViewById(R.id.dataTable);
      table.addView(row);
    }
  }
Exemplo n.º 3
0
  /**
   * Creates a row in signals table to store the signal sources checkboxs. Returns the signal
   * sources checkboxs container.
   *
   * @param signalTypeId
   * @return
   */
  public LinearLayout getSourcesCheckboxsContainer(String signalTypeId) {
    // Is there already a row for this signal type?
    LinearLayout checkboxContainer;
    ArrayList<View> containers =
        AndroidUtil.getViewsByTag(this, signalTypeId + "-checkboxContainer");
    if (containers.size() == 0) { // There is NO row

      TableRow row = new TableRow(this);
      TableRow.LayoutParams lp =
          new TableRow.LayoutParams(
              TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT);
      row.setLayoutParams(lp);
      row.setTag(signalTypeId + "-row");

      // Signal name.
      TextView signalType = new TextView(this);
      signalType.setText(signalTypeId);
      signalType.setTextColor(Color.BLACK);
      signalType.setBackgroundResource(R.drawable.table_border);
      signalType.setLayoutParams(
          new TableRow.LayoutParams(0, TableRow.LayoutParams.MATCH_PARENT, 17f));
      signalType.setGravity(Gravity.CENTER);

      // Signal samples (of each source).
      EditText signalSamples = new EditText(this);
      signalSamples.setInputType(InputType.TYPE_CLASS_NUMBER);
      signalSamples.setBackgroundResource(R.drawable.table_border);
      signalSamples.setTag(signalTypeId + "-samples");
      signalSamples.setLayoutParams(
          new TableRow.LayoutParams(0, TableRow.LayoutParams.MATCH_PARENT, 17f));
      signalSamples.setText(
          Preferences.readString(
              this.getClass().getSimpleName(),
              "Signal_" + signalTypeId,
              DEFAULT_SAMPLES_COUNT + ""));
      signalSamples.setTextColor(Color.BLACK);
      signalSamples.setEms(10);

      // Container for sources checkboxs.
      checkboxContainer = new LinearLayout(this);
      checkboxContainer.setOrientation(LinearLayout.HORIZONTAL);
      checkboxContainer.setTag(signalTypeId + "-checkboxContainer");
      // checkboxContainer.setLayoutParams(new TableRow.LayoutParams(0,
      // TableRow.LayoutParams.MATCH_PARENT, 60f));

      LinearLayout left = new LinearLayout(this);
      left.setOrientation(LinearLayout.VERTICAL);
      LinearLayout right = new LinearLayout(this);
      right.setOrientation(LinearLayout.VERTICAL);
      checkboxContainer.addView(left);
      checkboxContainer.addView(right);

      row.addView(signalType);
      row.addView(signalSamples);

      ScrollViewWithMaxHeight scrollView = new ScrollViewWithMaxHeight(this);
      scrollView.setMaxHeight(500);
      // ScrollView scrollView = new ScrollView(this);
      scrollView.setLayoutParams(
          new TableRow.LayoutParams(0, TableRow.LayoutParams.MATCH_PARENT, 66f));
      scrollView.addView(checkboxContainer);
      row.addView(scrollView);
      // row.addView(checkboxContainer);

      TableLayout table = (TableLayout) findViewById(R.id.signalsTable);
      table.addView(row);
    } else // There is a row
    {
      checkboxContainer = (LinearLayout) containers.get(0);
    }

    return checkboxContainer;
  }
Exemplo n.º 4
0
  public void onStartTap(View v) {
    // Get point object from map.
    try {
      currentPoint = getCurrentPoint();
    } catch (Exception e) {
      Toast.makeText(this, R.string.error_invalid_coordinate, Toast.LENGTH_LONG).show();
      return;
    }

    // Stores the list of listened signals.
    recordedSignalTypes = new ArrayList<String>();

    // Stores, for each signal type, the desired samples amount.
    HashMap<String, Integer> signalsSamplesCount = new HashMap<String, Integer>();
    for (CheckBoxSource cbs : checkboxs) {
      if (cbs.getCheckbox().isChecked()) {
        Preferences.writeBoolean(
            this.getClass().getSimpleName(), "Source_" + cbs.getSourceId(), true);

        String signalTypeId = cbs.getSignalTypeId();
        if (!recordedSignalTypes.contains(signalTypeId)) recordedSignalTypes.add(signalTypeId);

        if (!signalsSamplesCount.containsKey(signalTypeId)) {
          ArrayList<View> containers = AndroidUtil.getViewsByTag(this, signalTypeId + "-samples");
          EditText samplesEditText = (EditText) containers.get(0);
          try {
            int samplesCount = Integer.parseInt(samplesEditText.getText().toString());
            Preferences.writeString(
                this.getClass().getSimpleName(), "Signal_" + signalTypeId, samplesCount + "");
            signalsSamplesCount.put(signalTypeId, samplesCount);
          } catch (Exception e) {
            Toast.makeText(this, R.string.error_samples_count, Toast.LENGTH_LONG).show();
            return;
          }
        }
      } else {
        Preferences.writeBoolean(
            this.getClass().getSimpleName(), "Source_" + cbs.getSourceId(), false);
      }
    }

    // Stores, for each signal type, the desired sources.
    HashMap<String, List<String>> signalSources = new HashMap<String, List<String>>();
    for (CheckBoxSource cbs : checkboxs) {
      if (cbs.getCheckbox().isChecked()) {
        if (!signalSources.containsKey(cbs.getSignalTypeId()))
          signalSources.put(cbs.getSignalTypeId(), new ArrayList<String>());

        List<String> sources = signalSources.get(cbs.getSignalTypeId());
        sources.add(cbs.getSourceId());
      }
    }

    // Begins record process at each sensor.
    for (BaseSensor sensor : sensors) {
      String signalTypeId = sensor.getSignalTypeId();
      if (signalSources.containsKey(signalTypeId)) {
        // Log.i("NewPointActivity", "starting record: "+signalTypeId+ "
        // ("+signalsSamplesCount.get(signalTypeId)+" samples)");
        List<String> sources = signalSources.get(signalTypeId);
        sensor.beginRecord(sources, signalsSamplesCount.get(signalTypeId));
      }
    }
  }