-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDebugActivity.java
70 lines (53 loc) · 1.89 KB
/
DebugActivity.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package com.example.tinyasync;
import java.lang.ref.WeakReference;
import com.example.tinyasync.R;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
public class DebugActivity extends Activity {
private static final String TAG = "DebugActivity";
String dstring = "*** Debug Started ***\n\n";
TextView dtv;
protected void dwrite(String dout) {
dstring += dout + "\n";
dtv.setText(dstring);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_debug);
dtv = (TextView) findViewById(R.id.debug_text);
dwrite(">>> DebugActivity started on thread #"
+ String.valueOf(android.os.Process.myTid()));
// Start an asynchronous task
WeakReference<DebugActivity> wr = new WeakReference<DebugActivity>(this);
(new HazTask(wr)).start_task();
dwrite(">>> onCreate finished!");
dwrite("");
}
// Sample Task subclass specific to this activity.
// Can make as many of these as needed.
public static class HazTask extends TinyAsync {
public HazTask(WeakReference<DebugActivity> wr) { super(wr); }
// Each actable subclass does something back on the activity
class dwrite extends Actable {
String dmsg;
public dwrite(String message) { dmsg = message; }
@Override public void actask() { ((DebugActivity) act_ref).dwrite(dmsg); }
}
// This is run on a background thread
@Override public void main() {
act(new dwrite("Task started on thread #"
+ String.valueOf(android.os.Process.myTid())));
String r = GetUrl.hitthepage("http://icanhazip.com");
if(null != r) { act(new dwrite("My IP is " + r)); }
}
}
}