Mercurial > 510ConnectbotMonitor
annotate src/com/five_ten_sg/connectbot/monitor/MonitorActivity.java @ 13:5bf6d84cc5b8 stable-1.0.1
add showurl command
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Tue, 24 Jun 2014 07:58:13 -0700 |
parents | 2be5bca648ab |
children | 665324c9716e |
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)); |
0 | 63 Log.i(TAG, "binding to monitor service"); |
64 Intent intent = new Intent ("com.five_ten_sg.connectbot.monitor.MonitorService"); | |
65 bindService(intent, connection, Context.BIND_AUTO_CREATE); | |
66 } | |
67 | |
2 | 68 private void printer(String msg) { |
69 if (count < LINES) count++; | |
70 else start = (start+1) % LINES; | |
3
2be5bca648ab
switch to static functions
Carl Byington <carl@five-ten-sg.com>
parents:
2
diff
changeset
|
71 texts[(start+count-1) % LINES] = msg + "\n"; |
2 | 72 String c = ""; |
73 for (int i=0; i<count; i++) c = c.concat(texts[(start+i) % LINES]); | |
74 text.setText(c); | |
0 | 75 } |
76 | |
77 @Override | |
78 protected void onStart() { | |
79 super.onStart(); | |
80 Log.i(TAG, "activity onStart()"); | |
81 } | |
82 | |
83 @Override | |
84 protected void onRestart() { | |
85 super.onRestart(); | |
86 Log.i(TAG, "activity onRestart()"); | |
87 } | |
88 | |
89 @Override | |
90 protected void onStop() { | |
91 super.onStop(); | |
92 Log.i(TAG, "activity onStop()"); | |
93 } | |
94 | |
95 @Override | |
96 protected void onDestroy() { | |
97 Log.i(TAG, "activity onDestroy()"); | |
98 unbindService(connection); | |
99 super.onDestroy(); | |
100 } | |
101 } |