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
81
82
83
84
85
86
|
package org.sufficientlysecure.keychain.ui;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.service.OperationResultParcel;
import org.sufficientlysecure.keychain.service.OperationResultParcel.LogEntryParcel;
import java.util.ArrayList;
public class LogDisplayFragment extends ListFragment {
LogAdapter mAdapter;
public static final String EXTRA_RESULT = "log";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
Intent intent = getActivity().getIntent();
if (intent.getExtras() == null || !intent.getExtras().containsKey(EXTRA_RESULT)) {
getActivity().finish();
return;
}
OperationResultParcel result = intent.<OperationResultParcel>getParcelableExtra(EXTRA_RESULT);
if (result == null) {
getActivity().finish();
return;
}
mAdapter = new LogAdapter(getActivity(), result.getLog());
setListAdapter(mAdapter);
}
private class LogAdapter extends ArrayAdapter<LogEntryParcel> {
private LayoutInflater mInflater;
private int dipFactor;
public LogAdapter(Context context, ArrayList<LogEntryParcel> log) {
super(context, R.layout.log_display_item, log);
mInflater = LayoutInflater.from(getContext());
dipFactor = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
(float) 10, getResources().getDisplayMetrics());
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LogEntryParcel entry = getItem(position);
TextView text;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.log_display_item, parent, false);
text = (TextView) convertView.findViewById(R.id.log_text);
convertView.setTag(text);
} else {
text = (TextView) convertView.getTag();
}
text.setPadding(entry.mIndent*dipFactor, 0, 0, 0);
text.setText(getResources().getString(entry.mType.getMsgId(), (Object[]) entry.mParameters));
switch (entry.mLevel) {
case DEBUG: text.setTextColor(Color.GRAY); break;
case INFO: text.setTextColor(Color.BLACK); break;
case WARN: text.setTextColor(Color.YELLOW); break;
case ERROR: text.setTextColor(Color.RED); break;
}
return convertView;
}
}
}
|