1
+ package net .tjado .usbgadget ;
2
+
3
+ import android .graphics .Typeface ;
4
+ import android .os .Bundle ;
5
+ import android .text .Html ;
6
+ import android .view .LayoutInflater ;
7
+ import android .view .View ;
8
+ import android .view .ViewGroup ;
9
+ import android .widget .LinearLayout ;
10
+ import android .widget .TextView ;
11
+
12
+ import androidx .fragment .app .Fragment ;
13
+ import androidx .lifecycle .LiveData ;
14
+ import androidx .lifecycle .MutableLiveData ;
15
+
16
+ import java .io .BufferedReader ;
17
+ import java .io .StringReader ;
18
+ import java .util .HashMap ;
19
+ import java .util .Map ;
20
+ import java .util .TreeMap ;
21
+
22
+ public class DeviceInfoFragment extends Fragment {
23
+
24
+ private MutableLiveData <TreeMap <String ,String >> deviceData ;
25
+ private View v ;
26
+
27
+ public DeviceInfoFragment () {}
28
+
29
+ @ Override
30
+ public View onCreateView (LayoutInflater inflater , ViewGroup container , Bundle savedInstanceState ) {
31
+ this .v = inflater .inflate (R .layout .fragment_device_info , container , false );
32
+
33
+ deviceData = new MutableLiveData <>();
34
+ deviceData .setValue (new TreeMap <>(new DeviceInfoMapComparator ()));
35
+
36
+ deviceData .observe (getViewLifecycleOwner (), item -> {
37
+ this .loadData (item );
38
+ });
39
+
40
+ GadgetShellApi gsa = new GadgetShellApi ();
41
+ gsa .updateDeviceInfo (deviceData );
42
+
43
+ return v ;
44
+ }
45
+
46
+ private void loadData (Map <String , String > deviceData ) {
47
+
48
+ LinearLayout list = this .v .findViewById (R .id .list_device_data );
49
+ list .removeAllViews ();
50
+
51
+ View viHead = getLayoutInflater ().inflate (R .layout .row_device_info , null );
52
+
53
+ TextView tvHeadName = viHead .findViewById (R .id .name );
54
+ tvHeadName .setText ("Kernel Config Parameter" );
55
+ tvHeadName .setTypeface (null , Typeface .BOLD );
56
+
57
+ TextView tvHeadValue = viHead .findViewById (R .id .value );
58
+ tvHeadValue .setText ("Value" );
59
+ tvHeadValue .setTypeface (null , Typeface .BOLD );
60
+ list .addView (viHead );
61
+
62
+ for (Map .Entry <String , String > entry : deviceData .entrySet ()) {
63
+ View vi = getLayoutInflater ().inflate (R .layout .row_device_info , null );
64
+
65
+ TextView tvName = vi .findViewById (R .id .name );
66
+ tvName .setText (entry .getKey ().toUpperCase ());
67
+
68
+ TextView tvValue = vi .findViewById (R .id .value );
69
+ String value = entry .getValue ();
70
+
71
+ String color ;
72
+ switch (value ) {
73
+ case "y" :
74
+ value = "Yes" ;
75
+ color = "#008000" ;
76
+ break ;
77
+ case "n" :
78
+ value = "No" ;
79
+ color = "#ff0000" ;
80
+ break ;
81
+ case "NOT_SET" :
82
+ value = "Not set" ;
83
+ color = "#ff0000" ;
84
+ break ;
85
+ default :
86
+ color = "#000000" ;
87
+ }
88
+
89
+ tvValue .setText (Html .fromHtml (String .format ("<font color=%s>%s</font>" , color , value ), Html .FROM_HTML_MODE_LEGACY ));
90
+
91
+ list .addView (vi );
92
+ }
93
+ }
94
+ }
0 commit comments