質問編集履歴
14
,
test
CHANGED
File without changes
|
test
CHANGED
File without changes
|
13
,
test
CHANGED
File without changes
|
test
CHANGED
@@ -394,7 +394,7 @@
|
|
394
394
|
|
395
395
|
<TextView
|
396
396
|
|
397
|
-
android:id="@+id/text"
|
397
|
+
android:id="@+id/textview"
|
398
398
|
|
399
399
|
android:layout_width="match_parent"
|
400
400
|
|
12
、
test
CHANGED
File without changes
|
test
CHANGED
@@ -220,17 +220,17 @@
|
|
220
220
|
|
221
221
|
if(inViewBounds(findViewById(viewId[numCol*COL+numRow]), (int)event.getX(), (int)event.getY())){
|
222
222
|
|
223
|
+
|
224
|
+
|
223
225
|
//今タッチした所
|
224
226
|
|
225
227
|
fromCol = numCol+1;
|
226
228
|
|
227
229
|
fromRow = numRow+0;
|
228
230
|
|
229
|
-
|
230
|
-
|
231
|
-
Log.d("fromId", String.valueOf(viewId[numCol*COL+numRow]));
|
232
|
-
|
233
|
-
fromId =
|
231
|
+
fromId =viewId[numCol*COL+numRow];
|
232
|
+
|
233
|
+
// Log.d("fromId", String.valueOf(fromId));
|
234
234
|
|
235
235
|
}
|
236
236
|
|
@@ -256,13 +256,11 @@
|
|
256
256
|
|
257
257
|
toRow = numRow+0;
|
258
258
|
|
259
|
-
|
260
|
-
|
261
|
-
Log.d("toId", String.valueOf(viewId[numCol*COL+numRow]));
|
262
|
-
|
263
259
|
toId = viewId[numCol*COL+numRow];
|
264
260
|
|
265
|
-
|
261
|
+
// Log.d("toId", String.valueOf(viewId[numCol*COL+numRow]));
|
262
|
+
|
263
|
+
|
266
264
|
|
267
265
|
fromView = findViewById(fromId);
|
268
266
|
|
@@ -274,7 +272,7 @@
|
|
274
272
|
|
275
273
|
if(fromId != toId){
|
276
274
|
|
277
|
-
|
275
|
+
|
278
276
|
|
279
277
|
}
|
280
278
|
|
11
View型の追加等
test
CHANGED
File without changes
|
test
CHANGED
@@ -98,14 +98,6 @@
|
|
98
98
|
|
99
99
|
|
100
100
|
|
101
|
-
//Log出力用
|
102
|
-
|
103
|
-
View fromid;
|
104
|
-
|
105
|
-
View toid;
|
106
|
-
|
107
|
-
|
108
|
-
|
109
101
|
MainActivity(){
|
110
102
|
|
111
103
|
Random rand = new Random();
|
@@ -234,9 +226,11 @@
|
|
234
226
|
|
235
227
|
fromRow = numRow+0;
|
236
228
|
|
229
|
+
|
230
|
+
|
237
231
|
Log.d("fromId", String.valueOf(viewId[numCol*COL+numRow]));
|
238
232
|
|
239
|
-
from
|
233
|
+
fromId = viewId[numCol*COL+numRow];
|
240
234
|
|
241
235
|
}
|
242
236
|
|
@@ -246,6 +240,14 @@
|
|
246
240
|
|
247
241
|
case MotionEvent.ACTION_MOVE:{
|
248
242
|
|
243
|
+
|
244
|
+
|
245
|
+
View fromView;
|
246
|
+
|
247
|
+
View toView;
|
248
|
+
|
249
|
+
|
250
|
+
|
249
251
|
if(inViewBounds(findViewById(viewId[numCol*COL+numRow]), (int)event.getX(), (int)event.getY())){
|
250
252
|
|
251
253
|
|
@@ -254,9 +256,17 @@
|
|
254
256
|
|
255
257
|
toRow = numRow+0;
|
256
258
|
|
259
|
+
|
260
|
+
|
257
261
|
Log.d("toId", String.valueOf(viewId[numCol*COL+numRow]));
|
258
262
|
|
263
|
+
toId = viewId[numCol*COL+numRow];
|
264
|
+
|
265
|
+
|
266
|
+
|
267
|
+
fromView = findViewById(fromId);
|
268
|
+
|
259
|
-
toi
|
269
|
+
toView = findViewById(toId);
|
260
270
|
|
261
271
|
|
262
272
|
|
@@ -264,15 +274,7 @@
|
|
264
274
|
|
265
275
|
if(fromId != toId){
|
266
276
|
|
267
|
-
|
268
|
-
|
269
|
-
|
277
|
+
|
270
|
-
|
271
|
-
int z = fromId;
|
272
|
-
|
273
|
-
fromId = toId;
|
274
|
-
|
275
|
-
toId = z;
|
276
278
|
|
277
279
|
}
|
278
280
|
|
10
,
test
CHANGED
File without changes
|
test
CHANGED
@@ -232,7 +232,7 @@
|
|
232
232
|
|
233
233
|
fromCol = numCol+1;
|
234
234
|
|
235
|
-
fromRow = numRow;
|
235
|
+
fromRow = numRow+0;
|
236
236
|
|
237
237
|
Log.d("fromId", String.valueOf(viewId[numCol*COL+numRow]));
|
238
238
|
|
@@ -252,7 +252,7 @@
|
|
252
252
|
|
253
253
|
toCol = numCol+1;
|
254
254
|
|
255
|
-
toRow = numRow;
|
255
|
+
toRow = numRow+0;
|
256
256
|
|
257
257
|
Log.d("toId", String.valueOf(viewId[numCol*COL+numRow]));
|
258
258
|
|
9
,
test
CHANGED
File without changes
|
test
CHANGED
@@ -234,7 +234,7 @@
|
|
234
234
|
|
235
235
|
fromRow = numRow;
|
236
236
|
|
237
|
-
Log.d("fromId", String.valueOf(numCol*COL+numRow));
|
237
|
+
Log.d("fromId", String.valueOf(viewId[numCol*COL+numRow]));
|
238
238
|
|
239
239
|
fromid = findViewById(viewId[fromId]);
|
240
240
|
|
@@ -254,7 +254,7 @@
|
|
254
254
|
|
255
255
|
toRow = numRow;
|
256
256
|
|
257
|
-
Log.d("toId", String.valueOf(numCol*COL+numRow));
|
257
|
+
Log.d("toId", String.valueOf(viewId[numCol*COL+numRow]));
|
258
258
|
|
259
259
|
toid = findViewById(viewId[toId]);
|
260
260
|
|
8
findViewByIdの修正、fromid,toidをView型で宣言
test
CHANGED
File without changes
|
test
CHANGED
@@ -60,7 +60,7 @@
|
|
60
60
|
|
61
61
|
public class MainActivity extends AppCompatActivity {
|
62
62
|
|
63
|
-
|
63
|
+
|
64
64
|
|
65
65
|
int COL=4;
|
66
66
|
|
@@ -98,6 +98,8 @@
|
|
98
98
|
|
99
99
|
|
100
100
|
|
101
|
+
//Log出力用
|
102
|
+
|
101
103
|
View fromid;
|
102
104
|
|
103
105
|
View toid;
|
@@ -234,7 +236,7 @@
|
|
234
236
|
|
235
237
|
Log.d("fromId", String.valueOf(numCol*COL+numRow));
|
236
238
|
|
237
|
-
fromid = findViewById(fromId);
|
239
|
+
fromid = findViewById(viewId[fromId]);
|
238
240
|
|
239
241
|
}
|
240
242
|
|
@@ -248,15 +250,21 @@
|
|
248
250
|
|
249
251
|
|
250
252
|
|
253
|
+
toCol = numCol+1;
|
254
|
+
|
255
|
+
toRow = numRow;
|
256
|
+
|
251
257
|
Log.d("toId", String.valueOf(numCol*COL+numRow));
|
252
258
|
|
253
|
-
toid = findViewById(toId);
|
259
|
+
toid = findViewById(viewId[toId]);
|
254
260
|
|
255
261
|
|
256
262
|
|
257
263
|
//隣のマス目にまたいだら入れ替え処理
|
258
264
|
|
259
|
-
if(from
|
265
|
+
if(fromId != toId){
|
266
|
+
|
267
|
+
|
260
268
|
|
261
269
|
//番号
|
262
270
|
|
@@ -272,8 +280,6 @@
|
|
272
280
|
|
273
281
|
}
|
274
282
|
|
275
|
-
|
276
|
-
|
277
283
|
}
|
278
284
|
|
279
285
|
}
|
7
log\.d等の追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -50,23 +50,17 @@
|
|
50
50
|
|
51
51
|
|
52
52
|
|
53
|
+
import org.w3c.dom.Text;
|
54
|
+
|
55
|
+
|
56
|
+
|
53
57
|
import java.util.Random;
|
54
58
|
|
55
59
|
|
56
60
|
|
57
61
|
public class MainActivity extends AppCompatActivity {
|
58
62
|
|
59
|
-
|
60
|
-
|
61
|
-
|
63
|
+
|
62
|
-
|
63
|
-
private boolean mSortable = false; // ソート中かどうか
|
64
|
-
|
65
|
-
//MotionEventは1pxでも動いたら発火、リストをまたいだ時だけ処理するためにタップ位置を持っている
|
66
|
-
|
67
|
-
private int mPosition = -1; // ドラッグ位置
|
68
|
-
|
69
|
-
|
70
64
|
|
71
65
|
int COL=4;
|
72
66
|
|
@@ -94,7 +88,7 @@
|
|
94
88
|
|
95
89
|
|
96
90
|
|
97
|
-
//現在タッチし
|
91
|
+
//現在タッチしたViewに書いてある番号を保持
|
98
92
|
|
99
93
|
private int toRow = -1;
|
100
94
|
|
@@ -104,6 +98,12 @@
|
|
104
98
|
|
105
99
|
|
106
100
|
|
101
|
+
View fromid;
|
102
|
+
|
103
|
+
View toid;
|
104
|
+
|
105
|
+
|
106
|
+
|
107
107
|
MainActivity(){
|
108
108
|
|
109
109
|
Random rand = new Random();
|
@@ -224,26 +224,56 @@
|
|
224
224
|
|
225
225
|
|
226
226
|
|
227
|
+
if(inViewBounds(findViewById(viewId[numCol*COL+numRow]), (int)event.getX(), (int)event.getY())){
|
228
|
+
|
227
|
-
//タッチした
|
229
|
+
//今タッチした所
|
228
|
-
|
230
|
+
|
229
|
-
fromCol = numCol+1;
|
231
|
+
fromCol = numCol+1;
|
230
|
-
|
232
|
+
|
231
|
-
fromRow = numRow;
|
233
|
+
fromRow = numRow;
|
234
|
+
|
232
|
-
|
235
|
+
Log.d("fromId", String.valueOf(numCol*COL+numRow));
|
236
|
+
|
233
|
-
from
|
237
|
+
fromid = findViewById(fromId);
|
238
|
+
|
234
|
-
|
239
|
+
}
|
235
|
-
|
240
|
+
|
241
|
+
|
236
242
|
|
237
243
|
}
|
238
244
|
|
239
245
|
case MotionEvent.ACTION_MOVE:{
|
240
246
|
|
247
|
+
if(inViewBounds(findViewById(viewId[numCol*COL+numRow]), (int)event.getX(), (int)event.getY())){
|
248
|
+
|
249
|
+
|
250
|
+
|
251
|
+
Log.d("toId", String.valueOf(numCol*COL+numRow));
|
252
|
+
|
253
|
+
toid = findViewById(toId);
|
254
|
+
|
255
|
+
|
256
|
+
|
257
|
+
//隣のマス目にまたいだら入れ替え処理
|
258
|
+
|
241
|
-
|
259
|
+
if(fromid != toid){
|
242
|
-
|
260
|
+
|
243
|
-
//
|
261
|
+
//番号
|
262
|
+
|
263
|
+
int z = fromId;
|
264
|
+
|
265
|
+
fromId = toId;
|
266
|
+
|
267
|
+
toId = z;
|
268
|
+
|
269
|
+
}
|
270
|
+
|
271
|
+
|
244
272
|
|
245
273
|
}
|
246
274
|
|
275
|
+
|
276
|
+
|
247
277
|
}
|
248
278
|
|
249
279
|
}
|
@@ -256,13 +286,13 @@
|
|
256
286
|
|
257
287
|
//各フィールド変数を更新
|
258
288
|
|
259
|
-
fromRow = // //;
|
289
|
+
// fromRow = // //;
|
260
|
-
|
290
|
+
|
261
|
-
fromCol = // //;
|
291
|
+
// fromCol = // //;
|
262
|
-
|
292
|
+
|
263
|
-
fromId = // //;
|
293
|
+
// fromId = // //;
|
294
|
+
|
264
|
-
|
295
|
+
//
|
265
|
-
|
266
296
|
|
267
297
|
return true;
|
268
298
|
|
6
,
test
CHANGED
File without changes
|
test
CHANGED
@@ -226,11 +226,11 @@
|
|
226
226
|
|
227
227
|
//タッチした部分を保存
|
228
228
|
|
229
|
-
fromCol =
|
229
|
+
fromCol = numCol+1;
|
230
|
-
|
230
|
+
|
231
|
-
fromRow =
|
231
|
+
fromRow = numRow;
|
232
|
-
|
232
|
+
|
233
|
-
fromId =
|
233
|
+
fromId = viewId[numCol*COL+numRow];
|
234
234
|
|
235
235
|
|
236
236
|
|
5
、
test
CHANGED
File without changes
|
test
CHANGED
@@ -94,7 +94,7 @@
|
|
94
94
|
|
95
95
|
|
96
96
|
|
97
|
-
//現在タッチし
|
97
|
+
//現在タッチしているViewに書いてある番号を保持
|
98
98
|
|
99
99
|
private int toRow = -1;
|
100
100
|
|
4
フィールド変数の修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -86,21 +86,21 @@
|
|
86
86
|
|
87
87
|
//最後にタッチしたViewの列番号と行番号を保持
|
88
88
|
|
89
|
-
private int fromRow =
|
89
|
+
private int fromRow = -1;
|
90
|
-
|
90
|
+
|
91
|
-
private int fromCol =
|
91
|
+
private int fromCol = -1;
|
92
|
-
|
92
|
+
|
93
|
-
private int fromId =
|
93
|
+
private int fromId = -1;
|
94
94
|
|
95
95
|
|
96
96
|
|
97
97
|
//現在タッチしたViewに書いてある番号を保持
|
98
98
|
|
99
|
-
private int toRow =
|
99
|
+
private int toRow = -1;
|
100
|
-
|
100
|
+
|
101
|
-
private int toCol =
|
101
|
+
private int toCol = -1;
|
102
|
-
|
102
|
+
|
103
|
-
private int toId =
|
103
|
+
private int toId = -1;
|
104
104
|
|
105
105
|
|
106
106
|
|
3
フィールド変数について自分なりに修正してみました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -86,11 +86,21 @@
|
|
86
86
|
|
87
87
|
//最後にタッチしたViewの列番号と行番号を保持
|
88
88
|
|
89
|
-
int fromRow = // //;
|
89
|
+
private int fromRow = // //;
|
90
|
-
|
90
|
+
|
91
|
-
int fromCol = // //;
|
91
|
+
private int fromCol = // //;
|
92
|
-
|
92
|
+
|
93
|
-
int fromId =
|
93
|
+
private int fromId = // //;
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
//現在タッチしたViewに書いてある番号を保持
|
98
|
+
|
99
|
+
private int toRow = // //;
|
100
|
+
|
101
|
+
private int toCol = // //;
|
102
|
+
|
103
|
+
private int toId = // //;
|
94
104
|
|
95
105
|
|
96
106
|
|
@@ -214,124 +224,108 @@
|
|
214
224
|
|
215
225
|
|
216
226
|
|
227
|
+
//タッチした部分を保存
|
228
|
+
|
229
|
+
fromCol = // //;
|
230
|
+
|
231
|
+
fromRow = // //;
|
232
|
+
|
233
|
+
fromId = // //;
|
234
|
+
|
235
|
+
|
236
|
+
|
217
237
|
}
|
218
238
|
|
219
239
|
case MotionEvent.ACTION_MOVE:{
|
220
240
|
|
221
|
-
//最後にタッチしたViewに書いてある番号を保持するフィールド変数を追加する
|
222
|
-
|
223
|
-
int toRow = // //;
|
224
|
-
|
225
|
-
int toCol = // //;
|
226
|
-
|
227
|
-
int toId = inViewBounds(findViewById(viewId[numCol*COL+numRow]), (int)event.getX(), (int)event.getY())
|
228
|
-
|
229
|
-
|
230
|
-
|
231
241
|
if(fromRow != toRow || fromCol != toCol){
|
232
242
|
|
233
243
|
//入れ替え処理
|
234
244
|
|
235
245
|
}
|
236
246
|
|
237
|
-
|
238
|
-
|
239
247
|
}
|
240
248
|
|
241
249
|
}
|
242
250
|
|
243
|
-
|
251
|
+
}
|
252
|
+
|
244
|
-
|
253
|
+
}
|
254
|
+
|
255
|
+
|
256
|
+
|
257
|
+
//各フィールド変数を更新
|
258
|
+
|
259
|
+
fromRow = // //;
|
260
|
+
|
261
|
+
fromCol = // //;
|
262
|
+
|
263
|
+
fromId = // //;
|
264
|
+
|
265
|
+
|
266
|
+
|
267
|
+
return true;
|
268
|
+
|
269
|
+
}
|
270
|
+
|
271
|
+
|
272
|
+
|
273
|
+
/* view内に(x,y)が存在するか */
|
274
|
+
|
275
|
+
private boolean inViewBounds(final View view, int x, int y){
|
276
|
+
|
277
|
+
Rect outRect = new Rect();
|
278
|
+
|
279
|
+
view.getDrawingRect(outRect);
|
280
|
+
|
281
|
+
int[] location = new int[2];
|
282
|
+
|
283
|
+
view.getLocationOnScreen(location);
|
284
|
+
|
285
|
+
outRect.offset(location[0], location[1]);
|
286
|
+
|
245
|
-
|
287
|
+
//Log.d("TouchEvsyent", "X:" + location[0] + ",Y:" + location[0]);
|
288
|
+
|
246
|
-
|
289
|
+
return outRect.contains(x, y);
|
290
|
+
|
291
|
+
}
|
292
|
+
|
293
|
+
|
294
|
+
|
295
|
+
private void randOnVib(){
|
296
|
+
|
297
|
+
boolean duplicate=false;
|
298
|
+
|
299
|
+
Random rnd = new Random();
|
300
|
+
|
301
|
+
for(int i=0;i<ON_VIB_NUM;i++) {
|
302
|
+
|
303
|
+
while(true) {
|
304
|
+
|
247
|
-
|
305
|
+
onVib[i] = rnd.nextInt(COL * ROW) + 1;
|
306
|
+
|
248
|
-
|
307
|
+
for (int j=0;j<i;j++) {
|
308
|
+
|
249
|
-
if(
|
309
|
+
if (onVib[i] == onVib[j]) {
|
250
|
-
|
251
|
-
|
252
|
-
|
310
|
+
|
253
|
-
|
311
|
+
duplicate = true;
|
312
|
+
|
254
|
-
|
313
|
+
}
|
255
|
-
|
256
314
|
|
257
315
|
}
|
258
316
|
|
259
|
-
|
317
|
+
if (!duplicate) {
|
318
|
+
|
319
|
+
break;
|
320
|
+
|
321
|
+
}
|
260
322
|
|
261
323
|
}
|
262
324
|
|
263
325
|
}
|
264
326
|
|
265
|
-
//各フィールド変数を更新
|
266
|
-
|
267
|
-
int fromRow = // //;
|
268
|
-
|
269
|
-
int fromCol = // //;
|
270
|
-
|
271
|
-
int fromId = // //;
|
272
|
-
|
273
|
-
return true;
|
274
|
-
|
275
327
|
}
|
276
328
|
|
277
|
-
|
278
|
-
|
279
|
-
/* view内に(x,y)が存在するか */
|
280
|
-
|
281
|
-
private boolean inViewBounds(final View view, int x, int y){
|
282
|
-
|
283
|
-
Rect outRect = new Rect();
|
284
|
-
|
285
|
-
view.getDrawingRect(outRect);
|
286
|
-
|
287
|
-
int[] location = new int[2];
|
288
|
-
|
289
|
-
view.getLocationOnScreen(location);
|
290
|
-
|
291
|
-
outRect.offset(location[0], location[1]);
|
292
|
-
|
293
|
-
//Log.d("TouchEvsyent", "X:" + location[0] + ",Y:" + location[0]);
|
294
|
-
|
295
|
-
return outRect.contains(x, y);
|
296
|
-
|
297
|
-
}
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
private void randOnVib(){
|
302
|
-
|
303
|
-
boolean duplicate=false;
|
304
|
-
|
305
|
-
Random rnd = new Random();
|
306
|
-
|
307
|
-
for(int i=0;i<ON_VIB_NUM;i++) {
|
308
|
-
|
309
|
-
while(true) {
|
310
|
-
|
311
|
-
onVib[i] = rnd.nextInt(COL * ROW) + 1;
|
312
|
-
|
313
|
-
for (int j=0;j<i;j++) {
|
314
|
-
|
315
|
-
if (onVib[i] == onVib[j]) {
|
316
|
-
|
317
|
-
duplicate = true;
|
318
|
-
|
319
|
-
}
|
320
|
-
|
321
|
-
}
|
322
|
-
|
323
|
-
if (!duplicate) {
|
324
|
-
|
325
|
-
break;
|
326
|
-
|
327
|
-
}
|
328
|
-
|
329
|
-
}
|
330
|
-
|
331
|
-
}
|
332
|
-
|
333
|
-
}
|
334
|
-
|
335
329
|
}
|
336
330
|
|
337
331
|
```
|
2
フィールド変数を追加しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -30,6 +30,8 @@
|
|
30
30
|
|
31
31
|
import android.os.Bundle;
|
32
32
|
|
33
|
+
import android.util.Log;
|
34
|
+
|
33
35
|
import android.view.Display;
|
34
36
|
|
35
37
|
import android.view.Gravity;
|
@@ -56,6 +58,16 @@
|
|
56
58
|
|
57
59
|
|
58
60
|
|
61
|
+
//ハンドルをタップするとtrue,指が画面から離れるとfalse
|
62
|
+
|
63
|
+
private boolean mSortable = false; // ソート中かどうか
|
64
|
+
|
65
|
+
//MotionEventは1pxでも動いたら発火、リストをまたいだ時だけ処理するためにタップ位置を持っている
|
66
|
+
|
67
|
+
private int mPosition = -1; // ドラッグ位置
|
68
|
+
|
69
|
+
|
70
|
+
|
59
71
|
int COL=4;
|
60
72
|
|
61
73
|
int ROW=4;
|
@@ -72,6 +84,16 @@
|
|
72
84
|
|
73
85
|
|
74
86
|
|
87
|
+
//最後にタッチしたViewの列番号と行番号を保持
|
88
|
+
|
89
|
+
int fromRow = // //;
|
90
|
+
|
91
|
+
int fromCol = // //;
|
92
|
+
|
93
|
+
int fromId = // //;
|
94
|
+
|
95
|
+
|
96
|
+
|
75
97
|
MainActivity(){
|
76
98
|
|
77
99
|
Random rand = new Random();
|
@@ -180,120 +202,138 @@
|
|
180
202
|
|
181
203
|
public boolean onTouchEvent(MotionEvent event) {
|
182
204
|
|
205
|
+
|
206
|
+
|
183
207
|
for(int numCol=0;numCol<COL;numCol++) {
|
184
208
|
|
185
209
|
for(int numRow = 1; numRow < ROW + 1; numRow++) {
|
186
210
|
|
211
|
+
switch (event.getAction()) {
|
212
|
+
|
213
|
+
case MotionEvent.ACTION_DOWN: {
|
214
|
+
|
215
|
+
|
216
|
+
|
217
|
+
}
|
218
|
+
|
219
|
+
case MotionEvent.ACTION_MOVE:{
|
220
|
+
|
221
|
+
//最後にタッチしたViewに書いてある番号を保持するフィールド変数を追加する
|
222
|
+
|
223
|
+
int toRow = // //;
|
224
|
+
|
225
|
+
int toCol = // //;
|
226
|
+
|
227
|
+
int toId = inViewBounds(findViewById(viewId[numCol*COL+numRow]), (int)event.getX(), (int)event.getY())
|
228
|
+
|
229
|
+
|
230
|
+
|
231
|
+
if(fromRow != toRow || fromCol != toCol){
|
232
|
+
|
233
|
+
//入れ替え処理
|
234
|
+
|
235
|
+
}
|
236
|
+
|
237
|
+
|
238
|
+
|
239
|
+
}
|
240
|
+
|
241
|
+
}
|
242
|
+
|
243
|
+
|
244
|
+
|
187
245
|
//Log.d("TouchEvent", "X:" + event.getX() + ",Y:" + event.getY());
|
188
246
|
|
189
247
|
/* タッチしている場所がテンキーの要素の中にあるか*/
|
190
248
|
|
191
249
|
if(inViewBounds(findViewById(viewId[numCol*COL+numRow]), (int)event.getX(), (int)event.getY())){
|
192
250
|
|
251
|
+
|
252
|
+
|
253
|
+
}else{
|
254
|
+
|
255
|
+
|
256
|
+
|
257
|
+
}
|
258
|
+
|
259
|
+
|
260
|
+
|
261
|
+
}
|
262
|
+
|
263
|
+
}
|
264
|
+
|
265
|
+
//各フィールド変数を更新
|
266
|
+
|
193
|
-
|
267
|
+
int fromRow = // //;
|
268
|
+
|
194
|
-
|
269
|
+
int fromCol = // //;
|
270
|
+
|
195
|
-
|
271
|
+
int fromId = // //;
|
272
|
+
|
196
|
-
|
273
|
+
return true;
|
274
|
+
|
275
|
+
}
|
276
|
+
|
277
|
+
|
278
|
+
|
197
|
-
|
279
|
+
/* view内に(x,y)が存在するか */
|
198
|
-
|
199
|
-
|
280
|
+
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
//バイブ有効
|
204
|
-
|
205
|
-
if(onVib[0]==numCol*COL+numRow||onVib[1]==numCol*COL+numRow||onVib[2]==numCol*COL+numRow||onVib[3]==numCol*COL+numRow) {
|
206
|
-
|
207
|
-
|
281
|
+
private boolean inViewBounds(final View view, int x, int y){
|
282
|
+
|
208
|
-
|
283
|
+
Rect outRect = new Rect();
|
284
|
+
|
209
|
-
|
285
|
+
view.getDrawingRect(outRect);
|
286
|
+
|
287
|
+
int[] location = new int[2];
|
288
|
+
|
289
|
+
view.getLocationOnScreen(location);
|
290
|
+
|
291
|
+
outRect.offset(location[0], location[1]);
|
292
|
+
|
293
|
+
//Log.d("TouchEvsyent", "X:" + location[0] + ",Y:" + location[0]);
|
294
|
+
|
295
|
+
return outRect.contains(x, y);
|
296
|
+
|
297
|
+
}
|
298
|
+
|
299
|
+
|
300
|
+
|
301
|
+
private void randOnVib(){
|
302
|
+
|
303
|
+
boolean duplicate=false;
|
304
|
+
|
305
|
+
Random rnd = new Random();
|
306
|
+
|
307
|
+
for(int i=0;i<ON_VIB_NUM;i++) {
|
308
|
+
|
309
|
+
while(true) {
|
310
|
+
|
311
|
+
onVib[i] = rnd.nextInt(COL * ROW) + 1;
|
312
|
+
|
313
|
+
for (int j=0;j<i;j++) {
|
314
|
+
|
315
|
+
if (onVib[i] == onVib[j]) {
|
316
|
+
|
317
|
+
duplicate = true;
|
210
318
|
|
211
319
|
}
|
212
320
|
|
213
|
-
}else{
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
/* なかったら白に戻す */
|
218
|
-
|
219
|
-
findViewById(viewId[numCol*COL+numRow]).setBackgroundColor(Color.WHITE);
|
220
|
-
|
221
321
|
}
|
222
322
|
|
323
|
+
if (!duplicate) {
|
324
|
+
|
325
|
+
break;
|
326
|
+
|
327
|
+
}
|
328
|
+
|
223
329
|
}
|
224
330
|
|
225
331
|
}
|
226
332
|
|
227
|
-
|
228
|
-
|
229
|
-
return true;
|
230
|
-
|
231
333
|
}
|
232
334
|
|
233
|
-
|
234
|
-
|
235
|
-
/* view内に(x,y)が存在するか */
|
236
|
-
|
237
|
-
private boolean inViewBounds(final View view, int x, int y){
|
238
|
-
|
239
|
-
Rect outRect = new Rect();
|
240
|
-
|
241
|
-
view.getDrawingRect(outRect);
|
242
|
-
|
243
|
-
int[] location = new int[2];
|
244
|
-
|
245
|
-
view.getLocationOnScreen(location);
|
246
|
-
|
247
|
-
outRect.offset(location[0], location[1]);
|
248
|
-
|
249
|
-
//Log.d("TouchEvsyent", "X:" + location[0] + ",Y:" + location[0]);
|
250
|
-
|
251
|
-
return outRect.contains(x, y);
|
252
|
-
|
253
|
-
}
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
private void randOnVib(){
|
258
|
-
|
259
|
-
boolean duplicate=false;
|
260
|
-
|
261
|
-
Random rnd = new Random();
|
262
|
-
|
263
|
-
for(int i=0;i<ON_VIB_NUM;i++) {
|
264
|
-
|
265
|
-
while(true) {
|
266
|
-
|
267
|
-
onVib[i] = rnd.nextInt(COL * ROW) + 1;
|
268
|
-
|
269
|
-
for (int j=0;j<i;j++) {
|
270
|
-
|
271
|
-
if (onVib[i] == onVib[j]) {
|
272
|
-
|
273
|
-
duplicate = true;
|
274
|
-
|
275
|
-
}
|
276
|
-
|
277
|
-
}
|
278
|
-
|
279
|
-
if (!duplicate) {
|
280
|
-
|
281
|
-
break;
|
282
|
-
|
283
|
-
}
|
284
|
-
|
285
|
-
}
|
286
|
-
|
287
|
-
}
|
288
|
-
|
289
|
-
}
|
290
|
-
|
291
335
|
}
|
292
336
|
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
337
|
```
|
298
338
|
|
299
339
|
```java
|
1
yona様 ご指摘ありがとうございます。修正いたしました。もしよろしければお力を貸していただけると幸いです。よろしくお願い致します。
test
CHANGED
File without changes
|
test
CHANGED
@@ -8,9 +8,11 @@
|
|
8
8
|
|
9
9
|
|
10
10
|
|
11
|
+
|
12
|
+
|
13
|
+
|
14
|
+
|
11
|
-
|
15
|
+
```java
|
12
|
-
|
13
|
-
|
14
16
|
|
15
17
|
package com.example.admin.a0116myapplication;
|
16
18
|
|
@@ -290,9 +292,11 @@
|
|
290
292
|
|
291
293
|
|
292
294
|
|
295
|
+
|
296
|
+
|
297
|
+
```
|
298
|
+
|
293
|
-
|
299
|
+
```java
|
294
|
-
|
295
|
-
|
296
300
|
|
297
301
|
<?xml version="1.0" encoding="utf-8"?>
|
298
302
|
|
@@ -362,16 +366,16 @@
|
|
362
366
|
|
363
367
|
</TableLayout>
|
364
368
|
|
365
|
-
|
366
|
-
|
367
|
-
★ten_key.xml
|
368
|
-
|
369
|
-
|
370
|
-
|
371
369
|
</RelativeLayout>
|
372
370
|
|
373
371
|
|
374
372
|
|
373
|
+
```
|
374
|
+
|
375
|
+
|
376
|
+
|
377
|
+
```java
|
378
|
+
|
375
379
|
<?xml version="1.0" encoding="utf-8"?>
|
376
380
|
|
377
381
|
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
@@ -386,9 +390,9 @@
|
|
386
390
|
|
387
391
|
|
388
392
|
|
393
|
+
```
|
394
|
+
|
389
|
-
|
395
|
+
```java
|
390
|
-
|
391
|
-
|
392
396
|
|
393
397
|
<?xml version="1.0" encoding="utf-8"?>
|
394
398
|
|
@@ -405,3 +409,5 @@
|
|
405
409
|
|
406
410
|
|
407
411
|
</TextView>
|
412
|
+
|
413
|
+
```
|