Mercurial > 510ConnectbotMonitor
comparison app/src/main/java/com/five_ten_sg/connectbot/monitor/MonitorActivity.java @ 27:807f7e4eaebe
starting update to latest toolchain
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Thu, 08 Nov 2018 11:39:13 -0800 |
parents | |
children | 0bc0b4798d9e |
comparison
equal
deleted
inserted
replaced
26:3a5df66c0480 | 27:807f7e4eaebe |
---|---|
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.Environment; | |
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) { | |
40 printer((String)msg.obj); | |
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); | |
63 printer(getString(R.string.copyright)); | |
64 String external_dir = Environment.getExternalStorageDirectory().getAbsolutePath(); | |
65 printer(""); | |
66 printer(String.format("External directory is %s", external_dir)); | |
67 printer(""); | |
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 | |
73 private void printer(String msg) { | |
74 if (count < LINES) count++; | |
75 else start = (start+1) % LINES; | |
76 texts[(start+count-1) % LINES] = msg + "\n"; | |
77 String c = ""; | |
78 for (int i=0; i<count; i++) c = c.concat(texts[(start+i) % LINES]); | |
79 text.setText(c); | |
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 } |