5
5
import android .content .Context ;
6
6
import android .content .Intent ;
7
7
import android .content .IntentFilter ;
8
+ import android .os .Handler ;
9
+ import android .os .Message ;
8
10
import android .support .v4 .content .LocalBroadcastManager ;
9
11
import android .os .Bundle ;
12
+ import android .text .Html ;
10
13
import android .util .AttributeSet ;
11
14
import android .widget .ScrollView ;
12
15
import android .widget .TextView ;
13
16
import org .mozilla .mozstumbler .R ;
14
17
import org .mozilla .mozstumbler .service .SharedConstants ;
18
+
19
+ import java .util .Date ;
15
20
import java .util .LinkedList ;
21
+ import java .util .Timer ;
22
+ import java .util .TimerTask ;
23
+ import java .util .concurrent .ConcurrentLinkedQueue ;
16
24
17
25
public class LogActivity extends Activity {
18
26
static LinkedList <String > buffer = new LinkedList <String >();
@@ -21,18 +29,33 @@ public class LogActivity extends Activity {
21
29
22
30
public static class LogMessageReceiver extends BroadcastReceiver {
23
31
32
+ Timer mFlushMessagesTimer = new Timer ();
33
+ Handler mMainThreadHandler = new Handler () {
34
+ public void handleMessage (Message m ) {
35
+ String msg = SharedConstants .guiLogMessageBuffer .poll ();
36
+ addMessageToBuffer (msg );
37
+ }
38
+ };
39
+
24
40
public static void createGlobalInstance (Context context ) {
25
41
sInstance = new LogMessageReceiver (context );
42
+ SharedConstants .guiLogMessageBuffer = new ConcurrentLinkedQueue <String >();
26
43
}
27
44
28
45
LogMessageReceiver (Context context ) {
29
46
LocalBroadcastManager .getInstance (context ).registerReceiver (this ,
30
47
new IntentFilter (SharedConstants .ACTION_GUI_LOG_MESSAGE ));
48
+
49
+ final int kMillis = 1000 * 3 ;
50
+ mFlushMessagesTimer .scheduleAtFixedRate (new TimerTask () {
51
+ @ Override
52
+ public void run () {
53
+ mMainThreadHandler .obtainMessage ().sendToTarget ();
54
+ }
55
+ }, kMillis , kMillis );
31
56
}
32
57
33
- @ Override
34
- public void onReceive (Context c , Intent intent ) {
35
- String s = intent .getStringExtra (SharedConstants .ACTION_GUI_LOG_MESSAGE_EXTRA );
58
+ void addMessageToBuffer (String s ) {
36
59
if (s == null )
37
60
return ;
38
61
@@ -44,6 +67,12 @@ public void onReceive(Context c, Intent intent) {
44
67
sConsoleView .println (s );
45
68
}
46
69
}
70
+
71
+ @ Override
72
+ public void onReceive (Context c , Intent intent ) {
73
+ String s = intent .getStringExtra (SharedConstants .ACTION_GUI_LOG_MESSAGE_EXTRA );
74
+ addMessageToBuffer (s );
75
+ }
47
76
}
48
77
49
78
ConsoleView mConsoleView ;
@@ -103,7 +132,7 @@ public void enableScroll(boolean v) {
103
132
}
104
133
105
134
public void print (String str ){
106
- tv .append (str );
135
+ tv .append (Html . fromHtml ( str + "<br />" ) );
107
136
108
137
if (enable_scroll ) {
109
138
scrollTo (0 ,tv .getBottom ());
0 commit comments