5
5
import android .content .Intent ;
6
6
import android .content .IntentFilter ;
7
7
import android .content .SharedPreferences ;
8
- import android .graphics .Canvas ;
9
- import android .graphics .ColorFilter ;
10
- import android .graphics .PixelFormat ;
11
8
import android .graphics .Rect ;
12
- import android .graphics .drawable .Drawable ;
13
9
import android .hardware .usb .UsbManager ;
14
10
import android .net .Uri ;
15
11
import android .os .Build ;
18
14
import android .support .design .widget .FloatingActionButton ;
19
15
import android .support .design .widget .Snackbar ;
20
16
import android .support .v4 .content .ContextCompat ;
21
- import android .support .v4 .media .RatingCompat ;
22
- import android .support .v7 .graphics .drawable .DrawableWrapper ;
23
17
import android .support .v7 .widget .AppCompatCheckBox ;
24
18
import android .support .v7 .widget .AppCompatEditText ;
25
19
import android .support .v7 .widget .AppCompatTextView ;
36
30
import android .support .v7 .widget .Toolbar ;
37
31
import android .view .Menu ;
38
32
import android .view .MenuItem ;
39
- import android .view .ViewGroup ;
40
33
import android .view .WindowManager ;
41
34
import android .widget .AdapterView ;
42
35
import android .widget .ArrayAdapter ;
62
55
import com .jjoe64 .graphview .series .DataPoint ;
63
56
import com .jjoe64 .graphview .series .LineGraphSeries ;
64
57
58
+ import java .lang .reflect .Array ;
65
59
import java .util .ArrayList ;
60
+ import java .util .Arrays ;
66
61
67
62
import static android .widget .RelativeLayout .BELOW ;
68
63
import static android .widget .RelativeLayout .RIGHT_OF ;
@@ -75,6 +70,11 @@ public class MainActivity extends AppCompatActivity
75
70
public static final int BLUETOOTH = 1 ;
76
71
public static final int USB = 2 ;
77
72
73
+ public static final int labelID = 100 ;
74
+ public static final int spID = 200 ;
75
+ public static final int pbID = 300 ;
76
+ public static final int tvID = 400 ;
77
+
78
78
private static final int MAX_GRAPH_COUNT = 30 * 60 ; //30 amostras por minuto, 60 minutos
79
79
private static final String CURRENT_VIEW = "currentView" ;
80
80
private static final int GW = 0 ;
@@ -991,9 +991,10 @@ public void setIOscreen() {
991
991
tvIOs [i ] = new TextView (this );
992
992
pbIOs [i ] = new ProgressBar (this , null , android .R .attr .progressBarStyleHorizontal );
993
993
pbIOs [i ].setProgressDrawable (ContextCompat .getDrawable (getApplicationContext (),R .drawable .green_pb ));
994
- labelIOs [i ].setId (i +100 );
995
- tvIOs [i ].setId (i +200 );
996
- pbIOs [i ].setId (i +300 );
994
+ labelIOs [i ].setId (i +labelID );
995
+ spIOs [i ].setId (i +spID );
996
+ tvIOs [i ].setId (i +tvID );
997
+ pbIOs [i ].setId (i +pbID );
997
998
998
999
if (i ==0 ) {
999
1000
labelLP [i ].addRule (BELOW , R .id .tvIOs );
@@ -1027,11 +1028,31 @@ public void setIOscreen() {
1027
1028
pbIOs [i ].setProgress (0 );
1028
1029
pbIOs [i ].setMax (1 );
1029
1030
1030
- IOtypes [i ] = new ArrayList <>();
1031
- for (int j = 1 ; j <= numNodes ; j ++) IOtypes [i ].add (String .valueOf (j ));
1031
+ IOtypes [i ] = new ArrayList <>(Arrays .asList (getResources ().getStringArray (R .array .io_types )));
1032
1032
ArrayAdapter <String > spinnerArrayAdapter = new ArrayAdapter <>(this , R .layout .io_spinner , IOtypes [i ]); //selected item will look like a spinner set from XML
1033
1033
spinnerArrayAdapter .setDropDownViewResource (android .R .layout .simple_spinner_dropdown_item );
1034
1034
spIOs [i ].setAdapter (spinnerArrayAdapter );
1035
+ spIOs [i ].setTag (i );
1036
+
1037
+ spIOs [i ].setOnItemSelectedListener (new AdapterView .OnItemSelectedListener () {
1038
+ @ Override
1039
+ public void onItemSelected (AdapterView <?> adapter , View v , int position , long arg3 ) {
1040
+ int i = (int ) adapter .getTag ();
1041
+ if (position >0 ) {
1042
+ pbIOs [i ].setMax (0xFFFF );
1043
+ pbIOs [i ].getLayoutParams ().width = RelativeLayout .LayoutParams .MATCH_PARENT ;
1044
+ } else {
1045
+ pbIOs [i ].setMax (1 );
1046
+ pbIOs [i ].getLayoutParams ().width = 120 ;
1047
+ }
1048
+ pbIOs [i ].invalidate ();
1049
+ pbIOs [i ].requestLayout ();
1050
+ }
1051
+
1052
+ @ Override
1053
+ public void onNothingSelected (AdapterView <?> parentView ) {
1054
+ }
1055
+ });
1035
1056
}
1036
1057
1037
1058
ArrayList <String > nodeNums = new ArrayList <>();
@@ -1061,6 +1082,9 @@ public void onNothingSelected(AdapterView<?> parentView) {
1061
1082
}
1062
1083
}
1063
1084
1085
+
1086
+
1087
+
1064
1088
public void updateRRScreen () {
1065
1089
//for(int i=0;i<numNodes;i++) nodes[i].setValues(Arrays.copyOfRange(modbusArray,i*16+1,(i+1)*16));
1066
1090
}
@@ -1115,7 +1139,8 @@ public void updateIOScreen (){
1115
1139
1116
1140
for (int i =0 ; i <numIOs ; i ++){
1117
1141
pbIOs [i ].setProgress (data [i ]);
1118
- tvIOs [i ].setText (String .valueOf (data [i ]));
1142
+ String temp = String .valueOf (data [i ]);
1143
+ tvIOs [i ].setText (temp );
1119
1144
}
1120
1145
}
1121
1146
0 commit comments