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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
5564580fe160 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
1 package com.five_ten_sg.connectbot.monitor;
5564580fe160 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
2
5564580fe160 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
3 import java.io.BufferedReader;
5564580fe160 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
4 import java.io.IOException;
5564580fe160 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
5 import java.io.InputStreamReader;
5564580fe160 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
6 import java.net.ServerSocket;
5564580fe160 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
7 import java.net.Socket;
5564580fe160 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
8
5564580fe160 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
9 import android.app.Activity;
5564580fe160 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
10 import android.content.ComponentName;
5564580fe160 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
11 import android.content.Context;
5564580fe160 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
12 import android.content.Intent;
5564580fe160 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
13 import android.content.ServiceConnection;
5564580fe160 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
14 import android.net.wifi.WifiManager.WifiLock;
5564580fe160 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
15 import android.net.wifi.WifiManager;
5564580fe160 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
16 import android.os.Binder;
5564580fe160 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
17 import android.os.Bundle;
5564580fe160 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
18 import android.os.Handler;
5564580fe160 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
19 import android.os.IBinder;
5564580fe160 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
20 import android.os.Message;
5564580fe160 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
21 import android.os.PowerManager;
5564580fe160 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
22 import android.util.Log;
5564580fe160 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
23 import android.widget.TextView;
5564580fe160 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
24
5564580fe160 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
25 public class MonitorActivity extends Activity {
5564580fe160 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
26 public final static String TAG = "ConnectBot.MonitorActivity";
5564580fe160 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
27
5564580fe160 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
28 public static final int MESSAGE_CODE_PRINT = 6000;
5564580fe160 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
29 private final int LINES = 20;
5564580fe160 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
30 private String[] texts = new String[LINES];
5564580fe160 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
31 private int start = 0;
5564580fe160 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
32 private int count = 0;
5564580fe160 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
33 private TextView text = null;
5564580fe160 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
34 private MonitorService bound = null;
5564580fe160 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
35 private Handler handler = new Handler() {
5564580fe160 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
36 @Override
5564580fe160 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
37 public void handleMessage (Message msg) {
5564580fe160 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
38 if (msg.what == MESSAGE_CODE_PRINT) {
2
f6a1aabf384f add copyright
Carl Byington <carl@five-ten-sg.com>
parents: 0
diff changeset
39 printer((String)msg.obj);
0
5564580fe160 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
40 } else {
5564580fe160 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
41 super.handleMessage(msg);
5564580fe160 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
42 }
5564580fe160 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
43 }
5564580fe160 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
44 };
5564580fe160 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
45 private ServiceConnection connection = new ServiceConnection() {
5564580fe160 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
46 public void onServiceConnected(ComponentName className, IBinder service) {
5564580fe160 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
47 Log.i(TAG, "onServiceConnected()");
5564580fe160 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
48 bound = ((MonitorService.MonitorBinder)service).getService();
5564580fe160 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
49 bound.handler = handler;
5564580fe160 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
50 }
5564580fe160 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
51 public void onServiceDisconnected(ComponentName className) {
5564580fe160 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
52 Log.i(TAG, "onServiceDisconnected()");
5564580fe160 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
53 bound = null;
5564580fe160 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
54 }
5564580fe160 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
55 };
5564580fe160 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
56
5564580fe160 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
57 @Override
5564580fe160 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
58 public void onCreate(Bundle savedInstanceState) {
5564580fe160 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
59 super.onCreate(savedInstanceState);
5564580fe160 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
60 setContentView(R.layout.main);
5564580fe160 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
61 text = (TextView) findViewById(R.id.text2);
2
f6a1aabf384f add copyright
Carl Byington <carl@five-ten-sg.com>
parents: 0
diff changeset
62 printer(getString(R.string.copyright));
0
5564580fe160 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
63 Log.i(TAG, "binding to monitor service");
5564580fe160 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
64 Intent intent = new Intent ("com.five_ten_sg.connectbot.monitor.MonitorService");
5564580fe160 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
65 bindService(intent, connection, Context.BIND_AUTO_CREATE);
5564580fe160 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
66 }
5564580fe160 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
67
2
f6a1aabf384f add copyright
Carl Byington <carl@five-ten-sg.com>
parents: 0
diff changeset
68 private void printer(String msg) {
f6a1aabf384f add copyright
Carl Byington <carl@five-ten-sg.com>
parents: 0
diff changeset
69 if (count < LINES) count++;
f6a1aabf384f add copyright
Carl Byington <carl@five-ten-sg.com>
parents: 0
diff changeset
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
f6a1aabf384f add copyright
Carl Byington <carl@five-ten-sg.com>
parents: 0
diff changeset
72 String c = "";
f6a1aabf384f add copyright
Carl Byington <carl@five-ten-sg.com>
parents: 0
diff changeset
73 for (int i=0; i<count; i++) c = c.concat(texts[(start+i) % LINES]);
f6a1aabf384f add copyright
Carl Byington <carl@five-ten-sg.com>
parents: 0
diff changeset
74 text.setText(c);
0
5564580fe160 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
75 }
5564580fe160 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
76
5564580fe160 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
77 @Override
5564580fe160 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
78 protected void onStart() {
5564580fe160 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
79 super.onStart();
5564580fe160 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
80 Log.i(TAG, "activity onStart()");
5564580fe160 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
81 }
5564580fe160 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
82
5564580fe160 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
83 @Override
5564580fe160 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
84 protected void onRestart() {
5564580fe160 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
85 super.onRestart();
5564580fe160 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
86 Log.i(TAG, "activity onRestart()");
5564580fe160 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
87 }
5564580fe160 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
88
5564580fe160 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
89 @Override
5564580fe160 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
90 protected void onStop() {
5564580fe160 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
91 super.onStop();
5564580fe160 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
92 Log.i(TAG, "activity onStop()");
5564580fe160 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
93 }
5564580fe160 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
94
5564580fe160 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
95 @Override
5564580fe160 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
96 protected void onDestroy() {
5564580fe160 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
97 Log.i(TAG, "activity onDestroy()");
5564580fe160 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
98 unbindService(connection);
5564580fe160 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
99 super.onDestroy();
5564580fe160 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
100 }
5564580fe160 initial version
Carl Byington <carl@five-ten-sg.com>
parents:
diff changeset
101 }