1+ /*
2+ * @licence app begin@
3+ *
4+ * This Source Code Form is subject to the terms of the
5+ * Mozilla Public License (MPL), v. 2.0.
6+ * If a copy of the MPL was not distributed with this file,
7+ * You can obtain one at http://mozilla.org/MPL/2.0/.
8+ *
9+ * @licence end@
10+ */
11+
12+ package com .zeerd .dltviewer ;
13+
14+ import java .util .List ;
15+
16+ import android .app .Activity ;
17+ import android .util .Log ;
18+ import android .view .LayoutInflater ;
19+ import android .view .View ;
20+ import android .view .ViewGroup ;
21+ import android .widget .BaseAdapter ;
22+ import android .widget .TextView ;
23+
24+ public class LogTableAdapter extends BaseAdapter {
25+ private Activity activity ;
26+ private List <LogRow > rows ;
27+ private static final String TAG = "DLT-Viewer" ;
28+
29+ public LogTableAdapter (Activity activity , List <LogRow > rows ) {
30+ super ();
31+ this .activity = activity ;
32+ this .rows = rows ;
33+ }
34+
35+ @ Override
36+ public int getCount () {
37+ return rows .size ();
38+ }
39+
40+ @ Override
41+ public Object getItem (int position ) {
42+ return rows .get (position );
43+ }
44+
45+ @ Override
46+ public long getItemId (int position ) {
47+ // TODO Auto-generated method stub
48+ return 0 ;
49+ }
50+
51+ @ Override
52+ public View getView (int position , View convertView , ViewGroup parent ) {
53+
54+ if (convertView == null ) {
55+ LayoutInflater inflater = activity .getLayoutInflater ();
56+ convertView = inflater .inflate (R .layout .log_row , null );
57+ }
58+ TextView col1 = (TextView ) convertView .findViewById (R .id .log_timestamp );
59+ TextView col2 = (TextView ) convertView .findViewById (R .id .log_ecuid );
60+ TextView col3 = (TextView ) convertView .findViewById (R .id .log_apid );
61+ TextView col4 = (TextView ) convertView .findViewById (R .id .log_ctid );
62+ TextView col5 = (TextView ) convertView .findViewById (R .id .log_subtype );
63+ TextView col6 = (TextView ) convertView .findViewById (R .id .log_payload );
64+
65+ String timestamp = rows .get (position ).getColumn (0 );
66+ String subtype = rows .get (position ).getColumn (4 );
67+
68+ int len = timestamp .length ();
69+ String new_timestamp = timestamp .substring (0 , len -4 ) + "." + timestamp .substring (len -4 , len );
70+ Log .i (TAG , timestamp +" vs " +new_timestamp );
71+ col1 .setText (new_timestamp );
72+ col2 .setText (rows .get (position ).getColumn (1 ));
73+ col3 .setText (rows .get (position ).getColumn (2 ));
74+ col4 .setText (rows .get (position ).getColumn (3 ));
75+ col5 .setText (subtype );
76+ col6 .setText (rows .get (position ).getColumn (5 ));
77+
78+ if (subtype .equals ("error" ) || subtype .equals ("fatal" )) {
79+ col1 .setBackgroundResource (R .drawable .border_red );
80+ col2 .setBackgroundResource (R .drawable .border_red );
81+ col3 .setBackgroundResource (R .drawable .border_red );
82+ col4 .setBackgroundResource (R .drawable .border_red );
83+ col5 .setBackgroundResource (R .drawable .border_red );
84+ col6 .setBackgroundResource (R .drawable .border_red );
85+ }
86+ else if (subtype .equals ("warn" )) {
87+ col1 .setBackgroundResource (R .drawable .border_yellow );
88+ col2 .setBackgroundResource (R .drawable .border_yellow );
89+ col3 .setBackgroundResource (R .drawable .border_yellow );
90+ col4 .setBackgroundResource (R .drawable .border_yellow );
91+ col5 .setBackgroundResource (R .drawable .border_yellow );
92+ col6 .setBackgroundResource (R .drawable .border_yellow );
93+ }
94+ else {
95+ col1 .setBackgroundResource (R .drawable .border );
96+ col2 .setBackgroundResource (R .drawable .border );
97+ col3 .setBackgroundResource (R .drawable .border );
98+ col4 .setBackgroundResource (R .drawable .border );
99+ col5 .setBackgroundResource (R .drawable .border );
100+ col6 .setBackgroundResource (R .drawable .border );
101+ }
102+
103+ return convertView ;
104+ }
105+ }
0 commit comments