Skip to content

Commit 29410e6

Browse files
committed
add search function
1 parent fc3409d commit 29410e6

File tree

15 files changed

+1004
-31
lines changed

15 files changed

+1004
-31
lines changed

AndroidManifest.xml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version='1.0'?>
2-
<manifest xmlns:a='http://schemas.android.com/apk/res/android' package='com.zeerd.dltviewer' a:versionCode='0' a:versionName='0.0.4'>
2+
<manifest xmlns:a='http://schemas.android.com/apk/res/android' package='com.zeerd.dltviewer' a:versionCode='5' a:versionName='0.0.5'>
33
<uses-permission a:name='android.permission.INTERNET'/>
44
<uses-permission a:name='android.permission.WRITE_EXTERNAL_STORAGE'/>
55
<uses-permission a:name="android.permission.ACCESS_WIFI_STATE" />
@@ -22,6 +22,12 @@
2222
a:name="android.support.PARENT_ACTIVITY"
2323
a:value=".MainActivity" />
2424
</activity>
25+
<activity a:name=".SearchActivity"
26+
a:parentActivityName=".MainActivity" >
27+
<meta-data
28+
a:name="android.support.PARENT_ACTIVITY"
29+
a:value=".MainActivity" />
30+
</activity>
2531
<activity a:name=".HelpActivity"
2632
a:parentActivityName=".MainActivity" >
2733
<meta-data

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,9 @@ So I use some special way to build this project.
4444
[Android table column width 50 / 50](https://stackoverflow.com/questions/22383932/android-table-column-width-50-50)
4545

4646
[How can I read a text file in Android?](https://stackoverflow.com/questions/12421814/how-can-i-read-a-text-file-in-android)
47+
48+
[Quick and dirty demonstration of a large, two-way scrollable data table/spreadsheet.](https://github.com/klarson2/android-table-test)
49+
50+
[How to run the same asynctask more than once?](https://stackoverflow.com/questions/6879584/how-to-run-the-same-asynctask-more-than-once)
51+
52+
[Show a context menu for long-clicks in an Android ListView](https://www.mikeplate.com/2010/01/21/show-a-context-menu-for-long-clicks-in-an-android-listview/)

build.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ mv src/com/zeerd/dltviewer/R.java java/src/com/zeerd/dltviewer/R.java
1919

2020
echo "Compiling..."
2121
install -d obj
22+
javac -d obj -classpath java/src -bootclasspath $PLATFORM -source 1.7 -target 1.7 java/src/com/zeerd/dltviewer/SearchActivity.java
2223
javac -d obj -classpath java/src -bootclasspath $PLATFORM -source 1.7 -target 1.7 java/src/com/zeerd/dltviewer/SettingActivity.java
2324
javac -d obj -classpath java/src -bootclasspath $PLATFORM -source 1.7 -target 1.7 java/src/com/zeerd/dltviewer/HelpActivity.java
2425
javac -d obj -classpath java/src -bootclasspath $PLATFORM -source 1.7 -target 1.7 java/src/com/zeerd/dltviewer/ControlActivity.java

java/src/com/zeerd/dltviewer/LogRow.java

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,18 @@
1616

1717
public class LogRow {
1818

19-
private String[] column = new String[6];
19+
private String[] column = new String[7];
20+
21+
public static final int ROW_INDEX = 0;
22+
public static final int ROW_TIMESTAMP = 1;
23+
public static final int ROW_ECUID = 2;
24+
public static final int ROW_APID = 3;
25+
public static final int ROW_CTID = 4;
26+
public static final int ROW_SUBTYPE = 5;
27+
public static final int ROW_PAYLOAD = 6;
2028

2129
public LogRow(
30+
String index,
2231
String timestamp,
2332
String ecuid,
2433
String apid,
@@ -27,12 +36,13 @@ public LogRow(
2736
String payload) {
2837

2938
super();
30-
this.column[0] = timestamp;
31-
this.column[1] = ecuid;
32-
this.column[2] = apid;
33-
this.column[3] = ctid;
34-
this.column[4] = subtype;
35-
this.column[5] = payload;
39+
this.column[ROW_INDEX] = index;
40+
this.column[ROW_TIMESTAMP] = timestamp;
41+
this.column[ROW_ECUID] = ecuid;
42+
this.column[ROW_APID] = apid;
43+
this.column[ROW_CTID] = ctid;
44+
this.column[ROW_SUBTYPE] = subtype;
45+
this.column[ROW_PAYLOAD] = payload;
3646
}
3747

3848
public String getColumn(int index) {
@@ -41,4 +51,8 @@ public String getColumn(int index) {
4151
public void setColumn(int index, String str) {
4252
this.column[index] = str;
4353
}
54+
55+
public int getIndex() {
56+
return Integer.parseInt(this.column[ROW_INDEX]);
57+
}
4458
}

java/src/com/zeerd/dltviewer/LogTableAdapter.java

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,27 @@ public LogTableAdapter(Activity activity, List<LogRow> rows) {
3232
this.rows = rows;
3333
}
3434

35+
public LogTableAdapter(Activity activity) {
36+
super();
37+
this.activity = activity;
38+
}
39+
40+
public void setData(List<LogRow> rows) {
41+
this.rows = rows;
42+
}
43+
44+
public List<LogRow> getData() {
45+
return this.rows;
46+
}
47+
3548
@Override
3649
public int getCount() {
37-
return rows.size();
50+
if(rows == null) {
51+
return 0;
52+
}
53+
else {
54+
return rows.size();
55+
}
3856
}
3957

4058
@Override
@@ -55,27 +73,30 @@ public View getView(int position, View convertView, ViewGroup parent) {
5573
LayoutInflater inflater = activity.getLayoutInflater();
5674
convertView = inflater.inflate(R.layout.log_row, null);
5775
}
76+
TextView col0 = (TextView) convertView.findViewById(R.id.log_index);
5877
TextView col1 = (TextView) convertView.findViewById(R.id.log_timestamp);
5978
TextView col2 = (TextView) convertView.findViewById(R.id.log_ecuid);
6079
TextView col3 = (TextView) convertView.findViewById(R.id.log_apid);
6180
TextView col4 = (TextView) convertView.findViewById(R.id.log_ctid);
6281
TextView col5 = (TextView) convertView.findViewById(R.id.log_subtype);
6382
TextView col6 = (TextView) convertView.findViewById(R.id.log_payload);
6483

65-
String timestamp = rows.get(position).getColumn(0);
66-
String subtype = rows.get(position).getColumn(4);
84+
String timestamp = rows.get(position).getColumn(LogRow.ROW_TIMESTAMP);
85+
String subtype = rows.get(position).getColumn(LogRow.ROW_SUBTYPE);
6786

6887
int len = timestamp.length();
6988
String new_timestamp = timestamp.substring(0, len-4) + "." + timestamp.substring(len-4, len);
70-
Log.i(TAG, timestamp+" vs "+new_timestamp);
89+
// Log.i(TAG, timestamp+" vs "+new_timestamp);
90+
col0.setText(rows.get(position).getColumn(LogRow.ROW_INDEX));
7191
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));
92+
col2.setText(rows.get(position).getColumn(LogRow.ROW_ECUID));
93+
col3.setText(rows.get(position).getColumn(LogRow.ROW_APID));
94+
col4.setText(rows.get(position).getColumn(LogRow.ROW_CTID));
7595
col5.setText(subtype);
76-
col6.setText(rows.get(position).getColumn(5));
96+
col6.setText(rows.get(position).getColumn(LogRow.ROW_PAYLOAD));
7797

7898
if(subtype.equals("error") || subtype.equals("fatal")) {
99+
col0.setBackgroundResource(R.drawable.border_red);
79100
col1.setBackgroundResource(R.drawable.border_red);
80101
col2.setBackgroundResource(R.drawable.border_red);
81102
col3.setBackgroundResource(R.drawable.border_red);
@@ -84,6 +105,7 @@ public View getView(int position, View convertView, ViewGroup parent) {
84105
col6.setBackgroundResource(R.drawable.border_red);
85106
}
86107
else if(subtype.equals("warn")) {
108+
col0.setBackgroundResource(R.drawable.border_yellow);
87109
col1.setBackgroundResource(R.drawable.border_yellow);
88110
col2.setBackgroundResource(R.drawable.border_yellow);
89111
col3.setBackgroundResource(R.drawable.border_yellow);
@@ -92,6 +114,7 @@ else if(subtype.equals("warn")) {
92114
col6.setBackgroundResource(R.drawable.border_yellow);
93115
}
94116
else {
117+
col0.setBackgroundResource(R.drawable.border);
95118
col1.setBackgroundResource(R.drawable.border);
96119
col2.setBackgroundResource(R.drawable.border);
97120
col3.setBackgroundResource(R.drawable.border);

java/src/com/zeerd/dltviewer/MainActivity.java

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,11 @@ public class MainActivity extends Activity {
6464
private EditText ip;
6565
private String dltFile;
6666
private ListView listviewLogTable;
67-
private List<LogRow> logsList;
6867
private LogTableAdapter adapterLogs;
6968

69+
public static List<LogRow> logsList;
70+
public static int search_index;
71+
7072
@Override
7173
protected void onCreate(Bundle savedInstanceState) {
7274
super.onCreate(savedInstanceState);
@@ -116,6 +118,17 @@ public void handleMessage(Message msg) {
116118
logsList = new ArrayList<LogRow>();
117119
adapterLogs = new LogTableAdapter(this, logsList);
118120
listviewLogTable.setAdapter(adapterLogs);
121+
122+
search_index = -1;
123+
}
124+
125+
@Override
126+
public void onResume() {
127+
super.onResume();
128+
if(search_index > 0 && search_index < adapterLogs.getCount()) {
129+
listviewLogTable.setSelection(search_index - 1);
130+
checkBox.setChecked(false);
131+
}
119132
}
120133

121134
private CompoundButton.OnCheckedChangeListener connListener =
@@ -195,7 +208,14 @@ else if(type == 1) {
195208

196209
if(!splited[7].equals("control")) {
197210

198-
logsList.add(new LogRow(splited[2], splited[4], splited[5], splited[6], splited[8], string));
211+
logsList.add(new LogRow(
212+
""+(logsList.size()+1),
213+
splited[2],
214+
splited[4],
215+
splited[5],
216+
splited[6],
217+
splited[8],
218+
string));
199219
adapterLogs.notifyDataSetChanged();
200220

201221
if(checkBox.isChecked()) {
@@ -256,6 +276,11 @@ public boolean onMenuItemClick(MenuItem item) {
256276
startActivity(intent);
257277
}
258278
return true;
279+
case R.id.search: {
280+
Intent intent = new Intent(getBaseContext(), SearchActivity.class);
281+
startActivity(intent);
282+
}
283+
return true;
259284
case R.id.help: {
260285
Intent intent = new Intent(getBaseContext(), HelpActivity.class);
261286
startActivity(intent);
@@ -317,12 +342,12 @@ public void writeToFile()
317342

318343
for (int i = 0; i < logsList.size(); i++) {
319344
LogRow row = logsList.get(i);
320-
myOutWriter.append(row.getColumn(0) + " ");
321-
myOutWriter.append(row.getColumn(1) + " ");
322-
myOutWriter.append(row.getColumn(2) + " ");
323-
myOutWriter.append(row.getColumn(3) + " ");
324-
myOutWriter.append(row.getColumn(4) + " ");
325-
myOutWriter.append(row.getColumn(5) + "\n");
345+
myOutWriter.append(row.getColumn(LogRow.ROW_TIMESTAMP) + " ");
346+
myOutWriter.append(row.getColumn(LogRow.ROW_ECUID) + " ");
347+
myOutWriter.append(row.getColumn(LogRow.ROW_APID) + " ");
348+
myOutWriter.append(row.getColumn(LogRow.ROW_CTID) + " ");
349+
myOutWriter.append(row.getColumn(LogRow.ROW_SUBTYPE) + " ");
350+
myOutWriter.append(row.getColumn(LogRow.ROW_PAYLOAD) + "\n");
326351
}
327352

328353
myOutWriter.close();

0 commit comments

Comments
 (0)