Mercurial > 510ConnectbotMonitor
annotate src/com/five_ten_sg/connectbot/monitor/MonitorActivity.java @ 23:2586a4f5c8c3
add mechanism to allow getfield from other threads
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Fri, 01 May 2015 11:52:31 -0700 |
parents | adc776858a2d |
children |
rev | line source |
---|---|
0 | 1 package com.five_ten_sg.connectbot.monitor; |
2 | |
3 import java.io.BufferedReader; | |
4 import java.io.IOException; | |
5 import java.io.InputStreamReader; | |
6 import java.net.ServerSocket; | |
7 import java.net.Socket; | |
8 | |
9 import android.app.Activity; | |
10 import android.content.ComponentName; | |
11 import android.content.Context; | |
12 import android.content.Intent; | |
13 import android.content.ServiceConnection; | |
14 import android.net.wifi.WifiManager.WifiLock; | |
15 import android.net.wifi.WifiManager; | |
16 import android.os.Binder; | |
17 import android.os.Bundle; | |
22
adc776858a2d
enable some debug logging
Carl Byington <carl@five-ten-sg.com>
parents:
21
diff
changeset
|
18 import android.os.Environment; |
0 | 19 import android.os.Handler; |
20 import android.os.IBinder; | |
21 import android.os.Message; | |
22 import android.os.PowerManager; | |
23 import android.util.Log; | |
24 import android.widget.TextView; | |
25 | |
26 public class MonitorActivity extends Activity { | |
27 public final static String TAG = "ConnectBot.MonitorActivity"; | |
28 | |
29 public static final int MESSAGE_CODE_PRINT = 6000; | |
30 private final int LINES = 20; | |
31 private String[] texts = new String[LINES]; | |
32 private int start = 0; | |
33 private int count = 0; | |
34 private TextView text = null; | |
35 private MonitorService bound = null; | |
36 private Handler handler = new Handler() { | |
37 @Override | |
38 public void handleMessage (Message msg) { | |
39 if (msg.what == MESSAGE_CODE_PRINT) { | |
2 | 40 printer((String)msg.obj); |
0 | 41 } else { |
42 super.handleMessage(msg); | |
43 } | |
44 } | |
45 }; | |
46 private ServiceConnection connection = new ServiceConnection() { | |
47 public void onServiceConnected(ComponentName className, IBinder service) { | |
48 Log.i(TAG, "onServiceConnected()"); | |
49 bound = ((MonitorService.MonitorBinder)service).getService(); | |
50 bound.handler = handler; | |
51 } | |
52 public void onServiceDisconnected(ComponentName className) { | |
53 Log.i(TAG, "onServiceDisconnected()"); | |
54 bound = null; | |
55 } | |
56 }; | |
57 | |
58 @Override | |
59 public void onCreate(Bundle savedInstanceState) { | |
60 super.onCreate(savedInstanceState); | |
61 setContentView(R.layout.main); | |
62 text = (TextView) findViewById(R.id.text2); | |
2 | 63 printer(getString(R.string.copyright)); |
21
665324c9716e
enable some debug logging
Carl Byington <carl@five-ten-sg.com>
parents:
3
diff
changeset
|
64 String external_dir = Environment.getExternalStorageDirectory().getAbsolutePath(); |
665324c9716e
enable some debug logging
Carl Byington <carl@five-ten-sg.com>
parents:
3
diff
changeset
|
65 printer(""); |
665324c9716e
enable some debug logging
Carl Byington <carl@five-ten-sg.com>
parents:
3
diff
changeset
|
66 printer(String.format("External directory is %s", external_dir)); |
665324c9716e
enable some debug logging
Carl Byington <carl@five-ten-sg.com>
parents:
3
diff
changeset
|
67 printer(""); |
0 | 68 Log.i(TAG, "binding to monitor service"); |
69 Intent intent = new Intent ("com.five_ten_sg.connectbot.monitor.MonitorService"); | |
70 bindService(intent, connection, Context.BIND_AUTO_CREATE); | |
71 } | |
72 | |
2 | 73 private void printer(String msg) { |
74 if (count < LINES) count++; | |
75 else start = (start+1) % LINES; | |
3
2be5bca648ab
switch to static functions
Carl Byington <carl@five-ten-sg.com>
parents:
2
diff
changeset
|
76 texts[(start+count-1) % LINES] = msg + "\n"; |
2 | 77 String c = ""; |
78 for (int i=0; i<count; i++) c = c.concat(texts[(start+i) % LINES]); | |
79 text.setText(c); | |
0 | 80 } |
81 | |
82 @Override | |
83 protected void onStart() { | |
84 super.onStart(); | |
85 Log.i(TAG, "activity onStart()"); | |
86 } | |
87 | |
88 @Override | |
89 protected void onRestart() { | |
90 super.onRestart(); | |
91 Log.i(TAG, "activity onRestart()"); | |
92 } | |
93 | |
94 @Override | |
95 protected void onStop() { | |
96 super.onStop(); | |
97 Log.i(TAG, "activity onStop()"); | |
98 } | |
99 | |
100 @Override | |
101 protected void onDestroy() { | |
102 Log.i(TAG, "activity onDestroy()"); | |
103 unbindService(connection); | |
104 super.onDestroy(); | |
105 } | |
106 } |