예제 #1
0
  @Override
  protected void onResume() {
    super.onResume();

    map = MainActivity.map;

    // Clear tabs.
    tabHost = (TabHost) findViewById(R.id.tabHost);
    tabHost.setup();
    tabHost.clearAllTabs();

    // Clear signal data table.
    TableLayout table = (TableLayout) findViewById(R.id.signalsTable);
    table.removeViews(1, table.getChildCount() - 1);

    // Populates sensors list.
    sensors = BaseSensor.getRegisteredSensors();

    charts = new HashMap<String, LineChart>();

    // Initialize sensors.
    // After that, sensor will trigger sources events.
    checkboxs = new ArrayList<CheckBoxSource>();
    for (BaseSensor sensor : sensors) {
      sensor.registerListener(this);
      try {
        sensor.init();
      } catch (SensorNotSupportedException sne) {
        Toast.makeText(this, R.string.geomagnetic_sensor_error, Toast.LENGTH_LONG).show();
      }
    }

    // Track lost focus event on x,y text inputs.
    findViewById(R.id.xText).setOnFocusChangeListener(this);
    findViewById(R.id.yText).setOnFocusChangeListener(this);
    findViewById(R.id.labelText).setOnFocusChangeListener(this);

    // Sets initial x, y values.
    float x = getIntent().getFloatExtra("x", 0f);
    float y = getIntent().getFloatExtra("y", 0f);
    getTextView(R.id.xText).setText(String.format(Locale.ENGLISH, "%.2f", x));
    getTextView(R.id.yText).setText(String.format(Locale.ENGLISH, "%.2f", y));

    currentPoint = getCurrentPoint();
    getTextView(R.id.labelText).setText(currentPoint.getLabel());

    // Loads point data (chart and table).
    loadChartData();
  }
예제 #2
0
 /** Refreshs all charts. */
 public void refreshCharts() {
   // for (CheckBoxSource cbs : checkboxs)
   for (BaseSensor sensor : sensors) refreshChartOfSignal(sensor.getSignalTypeId());
 }
예제 #3
0
 /**
  * Add a point and all its data to chart.
  *
  * @param p
  */
 public void addToGraph(MapPoint p) {
   for (BaseSensor sensor : sensors) refreshChartOfSignal(p, sensor.getSignalTypeId());
 }
예제 #4
0
 /**
  * Stop button tap.
  *
  * @param v
  */
 public void onStopTap(View v) {
   for (BaseSensor sensor : sensors) sensor.endRecord();
 }
예제 #5
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));
      }
    }
  }
예제 #6
0
 protected void onPause() {
   super.onPause();
   for (BaseSensor sensor : sensors) sensor.finalize();
 }