質問編集履歴
1
プログラムの全文
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,22 +1,126 @@
|
|
1
|
-
このタッチイベントを取得
|
1
|
+
このタッチイベントを取得してCSVに書き込むプログラムでログ出力されている部分を文字列に変えたいのですがどのようにすればよろしいか教えてください。
|
2
|
+
|
3
|
+
|
4
|
+
|
2
|
-
|
5
|
+
package com.example.admin.tatchme;
|
6
|
+
|
7
|
+
|
8
|
+
|
3
|
-
|
9
|
+
import android.app.Activity;
|
10
|
+
|
4
|
-
|
11
|
+
import android.os.Bundle;
|
12
|
+
|
5
|
-
|
13
|
+
import android.os.Environment;
|
14
|
+
|
6
|
-
|
15
|
+
import android.util.Log;
|
16
|
+
|
17
|
+
import java.io.PrintWriter;
|
18
|
+
|
19
|
+
import android.view.MotionEvent;
|
20
|
+
|
21
|
+
import android.view.View;
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
import java.io.*;
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
public class tatchme extends Activity {
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
long num = 0;
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
@Override
|
40
|
+
|
41
|
+
protected void onCreate(Bundle savedInstanceState) {
|
42
|
+
|
43
|
+
super.onCreate(savedInstanceState);
|
44
|
+
|
45
|
+
setContentView(R.layout.activity_tatchme);
|
46
|
+
|
47
|
+
}
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
public void insert(View view) {
|
52
|
+
|
53
|
+
String filePath =
|
54
|
+
|
55
|
+
Environment.getExternalStorageDirectory() + "/102.csv";
|
56
|
+
|
57
|
+
File file = new File(filePath);
|
58
|
+
|
59
|
+
file.getParentFile().mkdir();
|
60
|
+
|
61
|
+
FileOutputStream fis = null;
|
62
|
+
|
63
|
+
BufferedWriter PrintWriter = null;
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
try {
|
68
|
+
|
69
|
+
fis = new FileOutputStream(file, true);
|
70
|
+
|
71
|
+
PrintWriter = new BufferedWriter(new OutputStreamWriter(fis));
|
72
|
+
|
73
|
+
PrintWriter.newLine();
|
74
|
+
|
75
|
+
PrintWriter.write("保存");
|
76
|
+
|
77
|
+
PrintWriter.flush();
|
78
|
+
|
79
|
+
} catch (IOException e) {
|
80
|
+
|
81
|
+
e.printStackTrace();
|
82
|
+
|
83
|
+
} finally {
|
84
|
+
|
85
|
+
if (PrintWriter != null) {
|
86
|
+
|
87
|
+
try {
|
88
|
+
|
89
|
+
PrintWriter.close();
|
90
|
+
|
91
|
+
} catch (IOException e) {
|
92
|
+
|
93
|
+
e.printStackTrace();
|
94
|
+
|
95
|
+
}
|
96
|
+
|
97
|
+
}
|
98
|
+
|
99
|
+
// return false;
|
100
|
+
|
101
|
+
}
|
102
|
+
|
103
|
+
}
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
@Override
|
110
|
+
|
7
|
-
public boolean onTouchEvent(MotionEvent motionEvent) {
|
111
|
+
public boolean onTouchEvent(MotionEvent motionEvent) {
|
8
112
|
|
9
113
|
switch (motionEvent.getAction()) {
|
10
114
|
|
11
|
-
|
115
|
+
|
12
116
|
|
13
117
|
case MotionEvent.ACTION_DOWN:
|
14
118
|
|
15
|
-
Log.d("",
|
119
|
+
Log.d("","EventLocation X:"+(int)motionEvent.getX());
|
16
|
-
|
120
|
+
|
17
|
-
Log.d("", "EventLocation Y:" + (int) motionEvent.getY());
|
121
|
+
Log.d("", "EventLocation Y:" + (int) motionEvent.getY());
|
18
|
-
|
122
|
+
|
19
|
-
Log.d("", "p" + num + ": " + motionEvent.getDownTime());
|
123
|
+
Log.d("", "p" + num + ": " + motionEvent.getDownTime());
|
20
124
|
|
21
125
|
Log.d("", "Press" + num + ": " + (double) motionEvent.getPressure());
|
22
126
|
|
@@ -39,3 +143,71 @@
|
|
39
143
|
Log.d("", "ACTION_CANCEL");
|
40
144
|
|
41
145
|
break;
|
146
|
+
|
147
|
+
//str+= namae+","
|
148
|
+
|
149
|
+
|
150
|
+
|
151
|
+
}
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
String filePath =
|
156
|
+
|
157
|
+
Environment.getExternalStorageDirectory() + "/102.csv";
|
158
|
+
|
159
|
+
File file = new File(filePath);
|
160
|
+
|
161
|
+
file.getParentFile().mkdir();
|
162
|
+
|
163
|
+
FileOutputStream fis = null;
|
164
|
+
|
165
|
+
BufferedWriter PrintWriter = null;
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
try {
|
170
|
+
|
171
|
+
fis = new FileOutputStream(file, true);
|
172
|
+
|
173
|
+
PrintWriter = new BufferedWriter(new OutputStreamWriter(fis));
|
174
|
+
|
175
|
+
PrintWriter.newLine();
|
176
|
+
|
177
|
+
PrintWriter.write(motionEvent.getX() + "," + motionEvent.getY()+","+ motionEvent.getDownTime()+","+ motionEvent.getEventTime()+","+(double) motionEvent.getPressure());
|
178
|
+
|
179
|
+
PrintWriter.newLine();
|
180
|
+
|
181
|
+
PrintWriter.flush();
|
182
|
+
|
183
|
+
} catch (IOException e) {
|
184
|
+
|
185
|
+
e.printStackTrace();
|
186
|
+
|
187
|
+
} finally {
|
188
|
+
|
189
|
+
if (PrintWriter != null) {
|
190
|
+
|
191
|
+
try {
|
192
|
+
|
193
|
+
PrintWriter.close();
|
194
|
+
|
195
|
+
} catch (IOException e) {
|
196
|
+
|
197
|
+
e.printStackTrace();
|
198
|
+
|
199
|
+
}
|
200
|
+
|
201
|
+
}
|
202
|
+
|
203
|
+
|
204
|
+
|
205
|
+
|
206
|
+
|
207
|
+
return false;
|
208
|
+
|
209
|
+
}
|
210
|
+
|
211
|
+
}
|
212
|
+
|
213
|
+
}
|