summaryrefslogtreecommitdiff
path: root/app/src/main/java/no/topi/fiken/display/DisplayControlActivity.java
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/no/topi/fiken/display/DisplayControlActivity.java')
-rw-r--r--app/src/main/java/no/topi/fiken/display/DisplayControlActivity.java58
1 files changed, 54 insertions, 4 deletions
diff --git a/app/src/main/java/no/topi/fiken/display/DisplayControlActivity.java b/app/src/main/java/no/topi/fiken/display/DisplayControlActivity.java
index 1a537d9..8cd16ec 100644
--- a/app/src/main/java/no/topi/fiken/display/DisplayControlActivity.java
+++ b/app/src/main/java/no/topi/fiken/display/DisplayControlActivity.java
@@ -12,6 +12,7 @@ import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
+import android.widget.SeekBar;
import android.widget.TextView;
import static java.lang.String.valueOf;
@@ -28,7 +29,6 @@ public class DisplayControlActivity extends Activity {
private TextView deviceNameView;
private TextView deviceRssiView;
- private TextView gaugeCountView;
private LinearLayout gaugesLayout;
@Override
@@ -46,7 +46,6 @@ public class DisplayControlActivity extends Activity {
deviceNameView = (TextView) findViewById(R.id.device_name);
deviceRssiView = (TextView) findViewById(R.id.device_rssi);
- gaugeCountView = (TextView) findViewById(R.id.gauge_count);
gaugesLayout = (LinearLayout) findViewById(R.id.gauges);
Button disconnectButton = (Button) findViewById(R.id.button_disconnect);
@@ -63,7 +62,6 @@ public class DisplayControlActivity extends Activity {
private void updateValues() {
deviceNameView.setText(deviceInfo.name != null ? deviceInfo.name : getText(R.string.name_unknown));
deviceRssiView.setText(getText(R.string.rssi) + ": " + (deviceInfo.rssi != 0 ? valueOf(deviceInfo.rssi) : ""));
- gaugeCountView.setText(getText(R.string.gauge_count) + ": " + (deviceInfo.gaugeCount));
}
@Override
@@ -135,7 +133,59 @@ public class DisplayControlActivity extends Activity {
finish();
}
}
- updateValues();
+ if (intent.hasExtra(IntentExtra.GAUGE_COUNT.name())) {
+ int count = intent.getIntExtra(IntentExtra.GAUGE_COUNT.name(), 0);
+
+ if (gaugesLayout.getChildCount() == 0) {
+ for (int i = 0; i < count; i++) {
+ final int gauge = i;
+ View gaugeView = getLayoutInflater().inflate(R.layout.fragment_gauge, null);
+
+ final TextView title = (TextView) gaugeView.findViewById(R.id.gauge_title);
+ title.setText("Gauge " + (i + 1));
+
+ SeekBar value = (SeekBar) gaugeView.findViewById(R.id.gauge_seek_bar);
+ value.setMax(255);
+ value.setProgress(0);
+ value.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
+ @Override
+ public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
+ }
+
+ @Override
+ public void onStartTrackingTouch(SeekBar seekBar) {
+ }
+
+ @Override
+ public void onStopTrackingTouch(SeekBar seekBar) {
+ int value = seekBar.getProgress();
+ title.setText("Value: " + value);
+ displayService.setGauge(gauge, value);
+ }
+ });
+ gaugesLayout.addView(gaugeView);
+ }
+ }
+ }
+ if (intent.hasExtra(IntentExtra.GAUGE_VALUE_CHANGED.name())) {
+ for (int gauge = 0; gauge < gaugesLayout.getChildCount(); gauge++) {
+ FikenStatusPanel statusPanel = displayService.getStatusPanel();
+ Integer gaugeValue = statusPanel.get(gauge);
+ if (gaugeValue != null) {
+ View gaugeView = gaugesLayout.getChildAt(gauge);
+ SeekBar seekBar = (SeekBar) gaugeView.findViewById(R.id.gauge_seek_bar);
+ if (seekBar != null) {
+ seekBar.setProgress(gaugeValue);
+ }
+
+ TextView title = (TextView) gaugeView.findViewById(R.id.gauge_title);
+ if (title != null) {
+ title.setText("Gauge " + gaugeValue);
+ }
+ }
+ }
+ updateValues();
+ }
}
});
}