質問編集履歴
3
\(\)の追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -134,7 +134,7 @@
|
|
134
134
|
|
135
135
|
case MotionEvent.ACTION_DOWN:
|
136
136
|
|
137
|
-
if (pow(tx - (winW - 120),2) + pow(ty - (winH - 110),2) < 2500 || pow(tx - 120,2) + pow(ty - (winH - 110),2) < 2500 || 70 <= tx && tx <= 270 && winH - 160 <= ty && ty <= winH - 60 || winW - 270 <= tx && tx <= winW - 70 && winH - 160 <= ty && ty <= winH - 60){
|
137
|
+
if (pow(tx - (winW - 120),2) + pow(ty - (winH - 110),2) < 2500 || pow(tx - 120,2) + pow(ty - (winH - 110),2) < 2500 || (70 <= tx && tx <= 270) && (winH - 160 <= ty && ty <= winH - 60) || (winW - 270 <= tx && tx <= winW - 70) && (winH - 160 <= ty && ty <= winH - 60)){
|
138
138
|
|
139
139
|
sc.colchange();
|
140
140
|
|
@@ -148,7 +148,7 @@
|
|
148
148
|
|
149
149
|
case MotionEvent.ACTION_MOVE:
|
150
150
|
|
151
|
-
if (pow(tx - (winW - 120),2) + pow(ty - (winH - 110),2) < 2500 || pow(tx - 120,2) + pow(ty - (winH - 110),2) < 2500 || 70 <= tx && tx <= 270 && winH - 160 <= ty && ty <= winH - 60 || winW - 270 <= tx && tx <= winW - 70 && winH - 160 <= ty && ty <= winH - 60){
|
151
|
+
if (pow(tx - (winW - 120),2) + pow(ty - (winH - 110),2) < 2500 || pow(tx - 120,2) + pow(ty - (winH - 110),2) < 2500 || (70 <= tx && tx <= 270) && (winH - 160 <= ty && ty <= winH - 60) || (winW - 270 <= tx && tx <= winW - 70) && (winH - 160 <= ty && ty <= winH - 60)){
|
152
152
|
|
153
153
|
sc.colchange();
|
154
154
|
|
@@ -349,3 +349,5 @@
|
|
349
349
|
###修正点
|
350
350
|
|
351
351
|
・クリック処理を無くしました
|
352
|
+
|
353
|
+
・ORとANDにおいて()でくくるべき箇所を()でくくりました。
|
2
コードの変更、修正点の項目の追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -176,7 +176,7 @@
|
|
176
176
|
|
177
177
|
}
|
178
178
|
|
179
|
-
public class Screen extends View
|
179
|
+
public class Screen extends View {
|
180
180
|
|
181
181
|
public Screen(Context context) {
|
182
182
|
|
@@ -236,120 +236,116 @@
|
|
236
236
|
|
237
237
|
}
|
238
238
|
|
239
|
-
@Override
|
240
|
-
|
241
|
-
|
239
|
+
public void colchange() {
|
242
|
-
|
240
|
+
|
243
|
-
|
241
|
+
colchk = 1;
|
244
|
-
|
242
|
+
|
245
|
-
|
243
|
+
invalidate();
|
244
|
+
|
245
|
+
}
|
246
|
+
|
247
|
+
public void colreturn() {
|
248
|
+
|
249
|
+
colchk = 0;
|
250
|
+
|
251
|
+
invalidate();
|
252
|
+
|
253
|
+
}
|
254
|
+
|
255
|
+
}
|
256
|
+
|
257
|
+
}
|
258
|
+
|
259
|
+
```
|
260
|
+
|
261
|
+
以下で描画しています
|
262
|
+
|
263
|
+
```Java
|
264
|
+
|
265
|
+
WindowManager wm = (WindowManager)getSystemService(WINDOW_SERVICE);
|
266
|
+
|
267
|
+
Display dp = wm.getDefaultDisplay();
|
268
|
+
|
269
|
+
Point po = new Point();
|
270
|
+
|
271
|
+
dp.getSize(po);
|
272
|
+
|
273
|
+
winW = po.x;
|
274
|
+
|
275
|
+
winH = po.y;
|
276
|
+
|
277
|
+
int wxa = winW - 320;
|
278
|
+
|
279
|
+
int wxb = winW - 20;
|
280
|
+
|
281
|
+
int wya = winH - 160;
|
282
|
+
|
283
|
+
int wyb = winH - 60;
|
284
|
+
|
285
|
+
int r = 50;
|
286
|
+
|
287
|
+
RectF arear = new RectF(wxa, wya, wxb, wyb);
|
288
|
+
|
289
|
+
RectF areal = new RectF(20,wya,320,wyb);
|
290
|
+
|
291
|
+
Paint p = new Paint();
|
292
|
+
|
293
|
+
c.drawColor(Color.WHITE);
|
294
|
+
|
295
|
+
p.setARGB(100,50,215,50);
|
296
|
+
|
297
|
+
if (colchk == 1){
|
298
|
+
|
299
|
+
p.setARGB(100,200,50,50);
|
300
|
+
|
301
|
+
colchk = 0;
|
246
302
|
|
247
303
|
}
|
248
304
|
|
249
|
-
|
305
|
+
p.setStyle(Paint.Style.FILL);
|
250
|
-
|
251
|
-
|
306
|
+
|
252
|
-
|
253
|
-
invalidate();
|
254
|
-
|
255
|
-
}
|
256
|
-
|
257
|
-
|
307
|
+
c.drawRoundRect(arear,r,r,p);
|
258
|
-
|
259
|
-
|
308
|
+
|
260
|
-
|
261
|
-
|
309
|
+
c.drawRoundRect(areal,r,r,p);
|
262
|
-
|
263
|
-
}
|
264
|
-
|
265
|
-
}
|
266
|
-
|
267
|
-
}
|
268
310
|
|
269
311
|
```
|
270
312
|
|
271
|
-
以下で
|
313
|
+
以下が当たり判定の部分です
|
272
314
|
|
273
315
|
```Java
|
274
316
|
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
int wx
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
RectF areal = new RectF(20,wya,320,wyb);
|
300
|
-
|
301
|
-
Paint p = new Paint();
|
302
|
-
|
303
|
-
c.drawColor(Color.WHITE);
|
304
|
-
|
305
|
-
p.setARGB(100,50,215,50);
|
306
|
-
|
307
|
-
if (colchk == 1){
|
308
|
-
|
309
|
-
p.setARGB(100,200,50,50);
|
310
|
-
|
311
|
-
colchk = 0;
|
312
|
-
|
313
|
-
}
|
314
|
-
|
315
|
-
p.setStyle(Paint.Style.FILL);
|
316
|
-
|
317
|
-
c.drawRoundRect(arear,r,r,p);
|
318
|
-
|
319
|
-
c.drawRoundRect(areal,r,r,p);
|
317
|
+
if (pow(tx - (winW2 - 120),2) + pow(ty - (winH2 - 110),2) < 2500 || pow(tx - 120,2) + pow(ty - (winH2 - 110),2) < 2500 || 70 <= tx && tx <= 270 && winH2 - 160 <= ty && ty <= winH2 - 60 || winW2 - 270 <= tx && tx <= winW2 - 70 && winH2 - 160 <= ty && ty <= winH2 - 60){
|
318
|
+
|
319
|
+
sc.colchange();
|
320
|
+
|
321
|
+
}else{
|
322
|
+
|
323
|
+
sc.colreturn();
|
324
|
+
|
325
|
+
}
|
326
|
+
|
327
|
+
break;
|
328
|
+
|
329
|
+
case MotionEvent.ACTION_MOVE:
|
330
|
+
|
331
|
+
if (pow(tx - (winW2 - 120),2) + pow(ty - (winH2 - 110),2) < 2500 || pow(tx - 120,2) + pow(ty - (winH2 - 110),2) < 2500 || 70 <= tx && tx <= 270 && winH2 - 160 <= ty && ty <= winH2 - 60 || winW2 - 270 <= tx && tx <= winW2 - 70 && winH2 - 160 <= ty && ty <= winH2 - 60){
|
332
|
+
|
333
|
+
sc.colchange();
|
334
|
+
|
335
|
+
}else{
|
336
|
+
|
337
|
+
sc.colreturn();
|
338
|
+
|
339
|
+
}
|
320
340
|
|
321
341
|
```
|
322
342
|
|
323
|
-
以下が当たり判定の部分です
|
324
|
-
|
325
|
-
```Java
|
326
|
-
|
327
|
-
if (pow(tx - (winW2 - 120),2) + pow(ty - (winH2 - 110),2) < 2500 || pow(tx - 120,2) + pow(ty - (winH2 - 110),2) < 2500 || 70 <= tx && tx <= 270 && winH2 - 160 <= ty && ty <= winH2 - 60 || winW2 - 270 <= tx && tx <= winW2 - 70 && winH2 - 160 <= ty && ty <= winH2 - 60){
|
328
|
-
|
329
|
-
sc.colchange();
|
330
|
-
|
331
|
-
}else{
|
332
|
-
|
333
|
-
sc.colreturn();
|
334
|
-
|
335
|
-
}
|
336
|
-
|
337
|
-
break;
|
338
|
-
|
339
|
-
case MotionEvent.ACTION_MOVE:
|
340
|
-
|
341
|
-
if (pow(tx - (winW2 - 120),2) + pow(ty - (winH2 - 110),2) < 2500 || pow(tx - 120,2) + pow(ty - (winH2 - 110),2) < 2500 || 70 <= tx && tx <= 270 && winH2 - 160 <= ty && ty <= winH2 - 60 || winW2 - 270 <= tx && tx <= winW2 - 70 && winH2 - 160 <= ty && ty <= winH2 - 60){
|
342
|
-
|
343
|
-
sc.colchange();
|
344
|
-
|
345
|
-
}else{
|
346
|
-
|
347
|
-
sc.colreturn();
|
348
|
-
|
349
|
-
}
|
350
|
-
|
351
|
-
```
|
352
|
-
|
353
343
|
###補足
|
354
344
|
|
355
345
|
感覚ですが、四角い当たり判定のゾーンが存在しているのですが、その位置が描かれるものと数十ずれていると思われます。半円の部分が当たり判定されていないので円が当たり判定されていないのかと思われます。
|
346
|
+
|
347
|
+
|
348
|
+
|
349
|
+
###修正点
|
350
|
+
|
351
|
+
・クリック処理を無くしました
|
1
全文の記載
test
CHANGED
File without changes
|
test
CHANGED
@@ -12,6 +12,262 @@
|
|
12
12
|
|
13
13
|
###該当のソースコード
|
14
14
|
|
15
|
+
全文です
|
16
|
+
|
17
|
+
```Java
|
18
|
+
|
19
|
+
import android.app.Activity;
|
20
|
+
|
21
|
+
import android.content.Context;
|
22
|
+
|
23
|
+
import android.content.pm.ActivityInfo;
|
24
|
+
|
25
|
+
import android.graphics.Canvas;
|
26
|
+
|
27
|
+
import android.graphics.Color;
|
28
|
+
|
29
|
+
import android.graphics.Paint;
|
30
|
+
|
31
|
+
import android.graphics.Point;
|
32
|
+
|
33
|
+
import android.graphics.RectF;
|
34
|
+
|
35
|
+
import android.os.Bundle;
|
36
|
+
|
37
|
+
import android.view.Display;
|
38
|
+
|
39
|
+
import android.view.MotionEvent;
|
40
|
+
|
41
|
+
import android.view.View;
|
42
|
+
|
43
|
+
import android.view.WindowManager;
|
44
|
+
|
45
|
+
import android.widget.FrameLayout;
|
46
|
+
|
47
|
+
import android.widget.LinearLayout;
|
48
|
+
|
49
|
+
import android.widget.TextView;
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
import static java.lang.Math.pow;
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
public class Main extends Activity {
|
58
|
+
|
59
|
+
Screen sc;
|
60
|
+
|
61
|
+
private TextView textView;
|
62
|
+
|
63
|
+
private int winW, winH;
|
64
|
+
|
65
|
+
private int winW2,winH2;
|
66
|
+
|
67
|
+
private int colchk = 0;
|
68
|
+
|
69
|
+
@Override
|
70
|
+
|
71
|
+
protected void onCreate(Bundle savedInstanceState) {
|
72
|
+
|
73
|
+
super.onCreate(savedInstanceState);
|
74
|
+
|
75
|
+
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
|
76
|
+
|
77
|
+
//setContentView(R.layout.activity_main);
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
sc = new Screen(this);
|
82
|
+
|
83
|
+
parts();
|
84
|
+
|
85
|
+
}
|
86
|
+
|
87
|
+
public void parts() {
|
88
|
+
|
89
|
+
FrameLayout fl = new FrameLayout(this);
|
90
|
+
|
91
|
+
this.setContentView(fl);
|
92
|
+
|
93
|
+
fl.addView(sc);
|
94
|
+
|
95
|
+
LinearLayout ll = new LinearLayout(this);
|
96
|
+
|
97
|
+
ll.setOrientation(LinearLayout.VERTICAL);
|
98
|
+
|
99
|
+
fl.addView(ll);
|
100
|
+
|
101
|
+
String action = "Touch Event";
|
102
|
+
|
103
|
+
textView = new TextView(this);
|
104
|
+
|
105
|
+
textView.setText(action);
|
106
|
+
|
107
|
+
textView.setTextSize(36.0f);
|
108
|
+
|
109
|
+
ll.addView(textView);
|
110
|
+
|
111
|
+
}
|
112
|
+
|
113
|
+
@Override
|
114
|
+
|
115
|
+
public boolean onTouchEvent(MotionEvent event) {
|
116
|
+
|
117
|
+
float tx = event.getX();
|
118
|
+
|
119
|
+
float ty = event.getY();
|
120
|
+
|
121
|
+
WindowManager wm2 = (WindowManager)getSystemService(WINDOW_SERVICE);
|
122
|
+
|
123
|
+
Display dp2 = wm2.getDefaultDisplay();
|
124
|
+
|
125
|
+
Point po2 = new Point();
|
126
|
+
|
127
|
+
dp2.getSize(po2);
|
128
|
+
|
129
|
+
winW2 = po2.x;
|
130
|
+
|
131
|
+
winH2 = po2.y;
|
132
|
+
|
133
|
+
switch (event.getAction() & MotionEvent.ACTION_MASK) {
|
134
|
+
|
135
|
+
case MotionEvent.ACTION_DOWN:
|
136
|
+
|
137
|
+
if (pow(tx - (winW - 120),2) + pow(ty - (winH - 110),2) < 2500 || pow(tx - 120,2) + pow(ty - (winH - 110),2) < 2500 || 70 <= tx && tx <= 270 && winH - 160 <= ty && ty <= winH - 60 || winW - 270 <= tx && tx <= winW - 70 && winH - 160 <= ty && ty <= winH - 60){
|
138
|
+
|
139
|
+
sc.colchange();
|
140
|
+
|
141
|
+
}else{
|
142
|
+
|
143
|
+
sc.colreturn();
|
144
|
+
|
145
|
+
}
|
146
|
+
|
147
|
+
break;
|
148
|
+
|
149
|
+
case MotionEvent.ACTION_MOVE:
|
150
|
+
|
151
|
+
if (pow(tx - (winW - 120),2) + pow(ty - (winH - 110),2) < 2500 || pow(tx - 120,2) + pow(ty - (winH - 110),2) < 2500 || 70 <= tx && tx <= 270 && winH - 160 <= ty && ty <= winH - 60 || winW - 270 <= tx && tx <= winW - 70 && winH - 160 <= ty && ty <= winH - 60){
|
152
|
+
|
153
|
+
sc.colchange();
|
154
|
+
|
155
|
+
}else{
|
156
|
+
|
157
|
+
sc.colreturn();
|
158
|
+
|
159
|
+
}
|
160
|
+
|
161
|
+
break;
|
162
|
+
|
163
|
+
case MotionEvent.ACTION_UP:
|
164
|
+
|
165
|
+
sc.colreturn();
|
166
|
+
|
167
|
+
break;
|
168
|
+
|
169
|
+
}
|
170
|
+
|
171
|
+
textView.setText("x:" + tx + "y:" + ty);
|
172
|
+
|
173
|
+
textView.setTextSize(14.0f);
|
174
|
+
|
175
|
+
return super.onTouchEvent(event);
|
176
|
+
|
177
|
+
}
|
178
|
+
|
179
|
+
public class Screen extends View implements View.OnClickListener{
|
180
|
+
|
181
|
+
public Screen(Context context) {
|
182
|
+
|
183
|
+
super(context);
|
184
|
+
|
185
|
+
}
|
186
|
+
|
187
|
+
protected void onDraw(Canvas c) {
|
188
|
+
|
189
|
+
super.onDraw(c);
|
190
|
+
|
191
|
+
WindowManager wm = (WindowManager)getSystemService(WINDOW_SERVICE);
|
192
|
+
|
193
|
+
Display dp = wm.getDefaultDisplay();
|
194
|
+
|
195
|
+
Point po = new Point();
|
196
|
+
|
197
|
+
dp.getSize(po);
|
198
|
+
|
199
|
+
winW = po.x;
|
200
|
+
|
201
|
+
winH = po.y;
|
202
|
+
|
203
|
+
int wxa = winW - 320;
|
204
|
+
|
205
|
+
int wxb = winW - 20;
|
206
|
+
|
207
|
+
int wya = winH - 160;
|
208
|
+
|
209
|
+
int wyb = winH - 60;
|
210
|
+
|
211
|
+
int r = 50;
|
212
|
+
|
213
|
+
RectF arear = new RectF(wxa, wya, wxb, wyb);
|
214
|
+
|
215
|
+
RectF areal = new RectF(20,wya,320,wyb);
|
216
|
+
|
217
|
+
Paint p = new Paint();
|
218
|
+
|
219
|
+
c.drawColor(Color.WHITE);
|
220
|
+
|
221
|
+
p.setARGB(100,50,215,50);
|
222
|
+
|
223
|
+
if (colchk == 1){
|
224
|
+
|
225
|
+
p.setARGB(100,200,50,50);
|
226
|
+
|
227
|
+
colchk = 0;
|
228
|
+
|
229
|
+
}
|
230
|
+
|
231
|
+
p.setStyle(Paint.Style.FILL);
|
232
|
+
|
233
|
+
c.drawRoundRect(arear,r,r,p);
|
234
|
+
|
235
|
+
c.drawRoundRect(areal,r,r,p);
|
236
|
+
|
237
|
+
}
|
238
|
+
|
239
|
+
@Override
|
240
|
+
|
241
|
+
public void onClick(View v) {
|
242
|
+
|
243
|
+
colchk = 1;
|
244
|
+
|
245
|
+
invalidate();
|
246
|
+
|
247
|
+
}
|
248
|
+
|
249
|
+
public void colchange() {
|
250
|
+
|
251
|
+
colchk = 1;
|
252
|
+
|
253
|
+
invalidate();
|
254
|
+
|
255
|
+
}
|
256
|
+
|
257
|
+
public void colreturn() {
|
258
|
+
|
259
|
+
colchk = 0;
|
260
|
+
|
261
|
+
invalidate();
|
262
|
+
|
263
|
+
}
|
264
|
+
|
265
|
+
}
|
266
|
+
|
267
|
+
}
|
268
|
+
|
269
|
+
```
|
270
|
+
|
15
271
|
以下で描画しています
|
16
272
|
|
17
273
|
```Java
|