-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDataViewerActivity.java
126 lines (102 loc) · 3.92 KB
/
DataViewerActivity.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package com.example.mohamed.blue11;
import android.app.Activity;
import android.app.ActivityManager;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
* Created by Mohamed on 2015-02-17.
*/
public class DataViewerActivity extends Activity {
private TextView mChannel1;
private TextView mChannel2;
private TextView mChannel3;
private TextView mChannel4;
private TextView mChannel5;
private TextView mChannel6;
private TextView mChannel7;
private TextView mChannel8;
private Button mGraph;
//private BluetoothChatService mChatService = null;
Thread updateChannels;
Handler handler;
String ch1;
String ch2;
String ch3;
String ch4;
String ch5;
String ch6;
String ch7;
String ch8;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.data_viewer_layout);
mGraph = (Button)findViewById(R.id.btnGraph);
mGraph.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
mChannel1 = (TextView) findViewById(R.id.mChannel1TextView);
mChannel2 = (TextView) findViewById(R.id.mChannel2TextView);
mChannel3 = (TextView) findViewById(R.id.mChannel3TextView);
mChannel4 = (TextView) findViewById(R.id.mChannel4TextView);
mChannel5 = (TextView) findViewById(R.id.mChannel5TextView);
mChannel6 = (TextView) findViewById(R.id.mChannel6TextView);
mChannel7 = (TextView) findViewById(R.id.mChannel7TextView);
mChannel8 = (TextView) findViewById(R.id.mChannel8TextView);
if (isRunning(getApplication())==true){
updateChannels = new Thread(new UpdateThread());
updateChannels.start();
handler = new Handler() {
@Override
public void handleMessage(Message msg) {
ch1 = msg.getData().getString("channel1");
mChannel1.setText(ch1);
ch2 = msg.getData().getString("channel2");
mChannel2.setText(ch2);
}
};
}}
class UpdateThread implements Runnable{
@Override
public void run() {
while (isRunning(getApplication())){
Message message = Message.obtain();
Bundle bundle = new Bundle();
ch1 = new String(Constants.buffer2).substring(0,2);
ch2 = new String(Constants.buffer2).substring(2,4);
bundle.putString("channel1",ch1);
bundle.putString("channel2",ch2);
message.setData(bundle);
handler.sendMessage(message);
}
}
}
public boolean isRunning(Context ctx) {
ActivityManager activityManager = (ActivityManager) ctx.getSystemService(Context.ACTIVITY_SERVICE);
final Set<String> activePackages = new HashSet<String>();
final List<ActivityManager.RunningAppProcessInfo> processInfos = activityManager.getRunningAppProcesses();
for (ActivityManager.RunningAppProcessInfo processInfo : processInfos) {
if (processInfo.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND) {
activePackages.addAll(Arrays.asList(processInfo.pkgList));
return true;
}
// for (ActivityManager.RunningTaskInfo task : ) {
// if (ctx.getPackageName().equalsIgnoreCase(task.baseActivity.getPackageName()))
// return true;
}
return false;
}
}