/** * 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; }
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)); } } }