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