回答編集履歴
1
ソースコードの記述場所が間違っていたため
test
CHANGED
@@ -2,172 +2,166 @@
|
|
2
2
|
|
3
3
|
参考までにソースを掲載します。
|
4
4
|
|
5
|
+
|
6
|
+
|
5
7
|
```java
|
6
|
-
|
7
|
-
```
|
8
8
|
|
9
9
|
import android.app.Activity;
|
10
10
|
|
11
|
-
import android.os.Bundle;
|
11
|
+
import android.os.Bundle;
|
12
12
|
|
13
|
-
import android.os.Handler;
|
13
|
+
import android.os.Handler;
|
14
14
|
|
15
|
-
import android.util.Log;
|
15
|
+
import android.util.Log;
|
16
16
|
|
17
|
-
import android.widget.ArrayAdapter;
|
17
|
+
import android.widget.ArrayAdapter;
|
18
18
|
|
19
|
-
import android.widget.TextView;
|
19
|
+
import android.widget.TextView;
|
20
20
|
|
21
21
|
|
22
22
|
|
23
23
|
import com.mlkcca.client.DataElement;
|
24
24
|
|
25
|
-
import com.mlkcca.client.DataStore;
|
25
|
+
import com.mlkcca.client.DataStore;
|
26
26
|
|
27
|
-
import com.mlkcca.client.DataStoreEventListener;
|
27
|
+
import com.mlkcca.client.DataStoreEventListener;
|
28
28
|
|
29
|
-
import com.mlkcca.client.MilkCocoa;
|
29
|
+
import com.mlkcca.client.MilkCocoa;
|
30
30
|
|
31
31
|
|
32
32
|
|
33
33
|
public class MainActivity extends Activity implements DataStoreEventListener {
|
34
34
|
|
35
|
-
|
35
|
+
String temp;
|
36
36
|
|
37
|
-
|
37
|
+
int temp0;
|
38
38
|
|
39
|
-
|
39
|
+
String temp2;
|
40
40
|
|
41
|
-
|
41
|
+
float temp1;
|
42
42
|
|
43
|
-
|
43
|
+
TextView t3;
|
44
44
|
|
45
|
-
|
45
|
+
private MilkCocoa m_milkCocoa;
|
46
46
|
|
47
|
-
|
47
|
+
private DataStore m_dataStore;
|
48
48
|
|
49
|
-
|
49
|
+
private Handler handler = new Handler();
|
50
50
|
|
51
|
-
|
51
|
+
private ArrayAdapter<String> adapter;
|
52
52
|
|
53
53
|
|
54
54
|
|
55
|
-
|
55
|
+
@Override
|
56
56
|
|
57
|
-
|
57
|
+
protected void onCreate(Bundle savedInstanceState) {
|
58
58
|
|
59
|
-
|
59
|
+
super.onCreate(savedInstanceState);
|
60
60
|
|
61
|
-
|
61
|
+
setContentView(R.layout.activity_main);
|
62
62
|
|
63
|
-
|
63
|
+
t3 = (TextView) findViewById(R.id.text3);
|
64
64
|
|
65
|
-
|
65
|
+
m_milkCocoa = new MilkCocoa("MY_MILKCOCOA_APP_ID");
|
66
66
|
|
67
|
-
|
67
|
+
m_dataStore = m_milkCocoa.dataStore("DATASTORE NAME");
|
68
68
|
|
69
|
-
|
69
|
+
m_dataStore.addDataStoreEventListener(this);
|
70
70
|
|
71
|
-
|
71
|
+
m_dataStore.on("push");
|
72
72
|
|
73
|
-
|
73
|
+
}
|
74
74
|
|
75
75
|
|
76
76
|
|
77
|
+
@Override
|
77
78
|
|
79
|
+
public void onPushed(DataElement dataElement) {
|
78
80
|
|
79
|
-
|
81
|
+
final DataElement pushed = dataElement;
|
80
82
|
|
81
|
-
|
83
|
+
new Thread(new Runnable() {
|
82
84
|
|
83
|
-
|
85
|
+
@Override
|
84
86
|
|
85
|
-
|
87
|
+
public void run() {
|
86
88
|
|
87
|
-
|
89
|
+
handler.post(new Runnable() {
|
88
90
|
|
89
|
-
|
91
|
+
@Override
|
90
92
|
|
91
|
-
|
93
|
+
public void run() {
|
92
94
|
|
93
|
-
|
95
|
+
String temp = pushed.getValue("temp");
|
94
96
|
|
95
|
-
|
97
|
+
int temp0 = Integer.parseInt(temp);
|
96
98
|
|
97
|
-
|
99
|
+
temp1 = (float) temp0 / 10;
|
98
100
|
|
99
|
-
|
101
|
+
Log.i("MC", "温度は" + temp1 + "℃です");
|
100
102
|
|
101
|
-
|
103
|
+
temp2 = "温度は" + temp1 + "℃です";
|
102
104
|
|
103
|
-
|
105
|
+
t3.setText(temp2);
|
104
106
|
|
105
|
-
|
107
|
+
}
|
106
108
|
|
107
|
-
|
109
|
+
});
|
108
110
|
|
109
|
-
|
111
|
+
}
|
110
|
-
|
111
|
-
});
|
112
|
-
|
113
|
-
}
|
114
112
|
|
115
113
|
|
116
114
|
|
117
|
-
|
115
|
+
}).start();
|
118
116
|
|
119
|
-
|
117
|
+
}
|
120
118
|
|
121
119
|
|
122
120
|
|
121
|
+
@Override
|
123
122
|
|
124
|
-
|
125
|
-
@Override
|
126
|
-
|
127
|
-
|
123
|
+
public void onSetted(DataElement dataElement) {
|
128
124
|
|
129
125
|
|
130
126
|
|
131
|
-
|
127
|
+
}
|
132
128
|
|
133
129
|
|
134
130
|
|
131
|
+
@Override
|
135
132
|
|
136
|
-
|
137
|
-
@Override
|
138
|
-
|
139
|
-
|
133
|
+
public void onSended(DataElement dataElement) {
|
140
134
|
|
141
135
|
|
142
136
|
|
143
|
-
|
137
|
+
}
|
144
138
|
|
145
139
|
|
146
140
|
|
141
|
+
@Override
|
147
142
|
|
148
|
-
|
149
|
-
@Override
|
150
|
-
|
151
|
-
|
143
|
+
public void onRemoved(DataElement dataElement) {
|
152
144
|
|
153
145
|
|
154
146
|
|
155
|
-
|
147
|
+
}
|
156
148
|
|
157
149
|
|
158
150
|
|
151
|
+
@Override
|
152
|
+
|
153
|
+
public void onPause() {
|
154
|
+
|
155
|
+
super.onPause();
|
156
|
+
|
157
|
+
finish();
|
158
|
+
|
159
|
+
android.os.Process.killProcess(android.os.Process.myPid());
|
160
|
+
|
161
|
+
}
|
162
|
+
|
163
|
+
}
|
164
|
+
|
165
|
+
```
|
159
166
|
|
160
167
|
|
161
|
-
@Override
|
162
|
-
|
163
|
-
public void onPause() {
|
164
|
-
|
165
|
-
super.onPause();
|
166
|
-
|
167
|
-
finish();
|
168
|
-
|
169
|
-
android.os.Process.killProcess(android.os.Process.myPid());
|
170
|
-
|
171
|
-
}
|
172
|
-
|
173
|
-
}
|