forked from opensensorhub/osh-android
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathAppStatusActivity.java
More file actions
80 lines (67 loc) · 3.36 KB
/
AppStatusActivity.java
File metadata and controls
80 lines (67 loc) · 3.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package org.sensorhub.android;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.GradientDrawable;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.ContextCompat;
import com.google.android.material.appbar.MaterialToolbar;
public class AppStatusActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_app_status);
// Set up toolbar with back navigation
MaterialToolbar toolbar = findViewById(R.id.status_toolbar);
setSupportActionBar(toolbar);
toolbar.setNavigationOnClickListener(v -> onBackPressed());
Intent intent = getIntent();
String sosStatus = intent.getStringExtra("sosService");
String consSysStatus = intent.getStringExtra("conSysService");
String discoveryStatus = intent.getStringExtra("discoveryService");
String httpStatus = intent.getStringExtra("httpStatus");
String sensorStatus = intent.getStringExtra("androidSensorStatus");
String sensorStorageStatus = intent.getStringExtra("sensorStorageStatus");
// Set status text
TextView sosStatusView = findViewById(R.id.sos_service_state);
TextView conSysStatusView = findViewById(R.id.consys_service_state);
TextView discoveryStatusView = findViewById(R.id.discovery_service_state);
TextView httpStatusView = findViewById(R.id.http_service_state);
TextView sensorStatusView = findViewById(R.id.sensor_service_state);
TextView storageStatusView = findViewById(R.id.storage_service_state);
sosStatusView.setText(sosStatus);
conSysStatusView.setText(consSysStatus);
discoveryStatusView.setText(discoveryStatus);
httpStatusView.setText(httpStatus);
sensorStatusView.setText(sensorStatus);
storageStatusView.setText(sensorStorageStatus);
// Color the status indicator dots
setStatusDotColor(findViewById(R.id.sos_status_dot), sosStatus);
setStatusDotColor(findViewById(R.id.consys_status_dot), consSysStatus);
setStatusDotColor(findViewById(R.id.discovery_status_dot), discoveryStatus);
setStatusDotColor(findViewById(R.id.http_status_dot), httpStatus);
setStatusDotColor(findViewById(R.id.sensor_status_dot), sensorStatus);
setStatusDotColor(findViewById(R.id.storage_status_dot), sensorStorageStatus);
}
private void setStatusDotColor(View dot, String status) {
int colorRes;
if (status == null) {
colorRes = R.color.status_unknown;
} else {
String lower = status.toLowerCase();
if (lower.contains("started")) {
colorRes = R.color.status_started;
} else if (lower.contains("stopped")) {
colorRes = R.color.status_stopped;
} else if (lower.contains("starting") || lower.contains("initializ")) {
colorRes = R.color.status_initializing;
} else {
colorRes = R.color.status_unknown;
}
}
GradientDrawable background = (GradientDrawable) dot.getBackground();
background.setColor(ContextCompat.getColor(this, colorRes));
}
}