質問編集履歴

2

修正

2019/01/28 07:23

投稿

kimukou1205
kimukou1205

スコア13

test CHANGED
File without changes
test CHANGED
@@ -13,3 +13,335 @@
13
13
  ![イメージ説明](0a663d1ab003272dee022e87c283095c.png)
14
14
 
15
15
  しかし、今のままだと値がクリアせず元の画面に戻ってもセットした時間がまだ存在している。コード全般[GitHub](https://github.com/kimukou1205/Shake-Alarm_check)
16
+
17
+
18
+
19
+ ```ここに言語を入力
20
+
21
+
22
+
23
+ @Override
24
+
25
+ public boolean dispatchKeyEvent(KeyEvent event) {
26
+
27
+ if (event.getAction()==KeyEvent.ACTION_DOWN) {
28
+
29
+ switch (event.getKeyCode()) {
30
+
31
+ case KeyEvent.KEYCODE_BACK:
32
+
33
+ // ダイアログ表示など特定の処理を行いたい場合はここに記述
34
+
35
+ // 親クラスのdispatchKeyEvent()を呼び出さずにtrueを返す
36
+
37
+ return true;
38
+
39
+ }
40
+
41
+ }
42
+
43
+ return super.dispatchKeyEvent(event);
44
+
45
+ }
46
+
47
+
48
+
49
+ @Override
50
+
51
+ protected void onCreate(Bundle savedInstanceState) {
52
+
53
+ super.onCreate(savedInstanceState);
54
+
55
+ setContentView(R.layout.activity_play_sound);
56
+
57
+ getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD |
58
+
59
+ WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
60
+
61
+ WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON |
62
+
63
+ WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
64
+
65
+
66
+
67
+
68
+
69
+
70
+
71
+ SharedPreferences data = getSharedPreferences("DataSave", Context.MODE_PRIVATE);
72
+
73
+ final int Level = data.getInt("LevelSave", 1); // 第2引数は値がなかったときのデフォルト
74
+
75
+
76
+
77
+ //ShakeGestureManager mGestureManager = new ShakeGestureManager(this, mListener);
78
+
79
+ //mGestureManager.startSensing();
80
+
81
+
82
+
83
+ startService(new Intent(this, PlaySoundService.class));
84
+
85
+ Random rand = new Random();
86
+
87
+ randnum = rand.nextInt(10);
88
+
89
+ // randnum = Level;
90
+
91
+ textView3 = (TextView) findViewById(R.id.textView3);
92
+
93
+ textView = (TextView) findViewById(R.id.textView2);
94
+
95
+ editText= (EditText) findViewById(R.id.editText);
96
+
97
+
98
+
99
+ if(Level == 1){
100
+
101
+ // 低の問題
102
+
103
+ if(randnum==0){
104
+
105
+ textView.setText("11×11");//121
106
+
107
+ }else if(randnum==1){
108
+
109
+ textView.setText("1+2+3+4+5+6+7+8+9");//45
110
+
111
+ }else if(randnum==2){
112
+
113
+ textView.setText("33×33");//1089
114
+
115
+ }else if(randnum==3){
116
+
117
+ textView.setText("1+3+9+27+81+243");//364
118
+
119
+ }
120
+
121
+ }
122
+
123
+ if(Level == 2){
124
+
125
+ // 中の問題
126
+
127
+ if(randnum==0){
128
+
129
+ textView.setText("111×111");//12321
130
+
131
+ }else if(randnum==1){
132
+
133
+ textView.setText("(100-13)×(100+13)");//9831
134
+
135
+ }else if(randnum==2){
136
+
137
+ textView.setText("2×(-5)");//-10
138
+
139
+ }else if(randnum==3) {
140
+
141
+ textView.setText("(-2)×(-5)");//10
142
+
143
+ }
144
+
145
+ }
146
+
147
+
148
+
149
+ if(Level == 3) {
150
+
151
+ // 高の問題
152
+
153
+ if (randnum == 0) {
154
+
155
+ textView.setText("99×(8+287-22)×0");//0
156
+
157
+ } else if (randnum == 1) {
158
+
159
+ textView.setText("11×11÷121");//1
160
+
161
+ } else if (randnum == 2) {
162
+
163
+ textView.setText("(-2)^3");//-8
164
+
165
+ } else if (randnum == 3) {
166
+
167
+ textView.setText("(-1)^2017");//-1
168
+
169
+ }
170
+
171
+ }
172
+
173
+ final Intent intent = new Intent(this, MainActivity.class);
174
+
175
+
176
+
177
+ if(count==10){
178
+
179
+ stopsound();
180
+
181
+ }
182
+
183
+ stop = (Button) findViewById(R.id.stop);
184
+
185
+ stop.setOnClickListener(new View.OnClickListener() {
186
+
187
+ @Override
188
+
189
+ public void onClick(View view) {
190
+
191
+ if (Level == 1) {
192
+
193
+ // 低の問題
194
+
195
+ if (randnum == 0 && editText.getText().toString().equals("121")) {
196
+
197
+ stopsound();
198
+
199
+ textView3.setText("正解!!");
200
+
201
+ finish();
202
+
203
+ } else if (randnum == 1 && editText.getText().toString().equals("45")) {
204
+
205
+ stopsound();
206
+
207
+ textView3.setText("正解!!");
208
+
209
+ onResume();
210
+
211
+ finish();
212
+
213
+ } else if (randnum == 2 && editText.getText().toString().equals("1089")) {
214
+
215
+ stopsound();
216
+
217
+ textView3.setText("正解!!");
218
+
219
+ finish();
220
+
221
+ } else if (randnum == 3 && editText.getText().toString().equals("364")) {
222
+
223
+ stopsound();
224
+
225
+ textView3.setText("正解!!");
226
+
227
+ finish();
228
+
229
+ }
230
+
231
+ }else if (editText.getText().toString().equals("")) {
232
+
233
+ Toast.makeText(PlaySoundActivity.this, "数字を入力してください", Toast.LENGTH_LONG).show();
234
+
235
+ }
236
+
237
+ }
238
+
239
+ if (Level == 2) {
240
+
241
+ // 中の問題
242
+
243
+ if (randnum == 0 && editText.getText().toString().equals("12321")) {
244
+
245
+ stopsound();
246
+
247
+ textView3.setText("正解!!");
248
+
249
+ finish();
250
+
251
+ } else if (randnum == 1 && editText.getText().toString().equals("9831")) {
252
+
253
+ stopsound();
254
+
255
+ textView3.setText("正解!!");
256
+
257
+ finish();
258
+
259
+ } else if (randnum == 2 && editText.getText().toString().equals("-10")) {
260
+
261
+ stopsound();
262
+
263
+ textView3.setText("正解!!");
264
+
265
+ finish();
266
+
267
+ } else if (randnum == 3 && editText.getText().toString().equals("10")) {
268
+
269
+ stopsound();
270
+
271
+ textView3.setText("正解!!");
272
+
273
+ finish();
274
+
275
+ }
276
+
277
+ }else if (editText.getText().toString().equals("")) {
278
+
279
+ Toast.makeText(PlaySoundActivity.this, "数字を入力してください", Toast.LENGTH_LONG).show();
280
+
281
+ }
282
+
283
+
284
+
285
+ }if (Level == 3) {
286
+
287
+ // 高の問題
288
+
289
+ if (randnum == 0 && editText.getText().toString().equals("0")) {
290
+
291
+ stopsound();
292
+
293
+ textView3.setText("正解!!");
294
+
295
+ finish();
296
+
297
+ } else if (randnum == 1 && editText.getText().toString().equals("1")) {
298
+
299
+ stopsound();
300
+
301
+ textView3.setText("正解!!");
302
+
303
+ finish();
304
+
305
+ } else if (randnum == 2 && editText.getText().toString().equals("-8")) {
306
+
307
+ stopsound();
308
+
309
+ textView3.setText("正解!!");
310
+
311
+ finish();
312
+
313
+ } else if (randnum == 3 && editText.getText().toString().equals("-1")) {
314
+
315
+ stopsound();
316
+
317
+ textView3.setText("正解!!");
318
+
319
+ finish();
320
+
321
+ }
322
+
323
+ }
324
+
325
+ }
326
+
327
+ });
328
+
329
+ }
330
+
331
+
332
+
333
+ public void stopsound(){
334
+
335
+ stopService(new Intent(PlaySoundActivity.this, PlaySoundService.class));
336
+
337
+ PreferenceUtil pref = new PreferenceUtil(PlaySoundActivity.this);
338
+
339
+ pref.delete(com.example.axu1.richarddawkinsalarmclock.MainActivity.ALARM_TIME);
340
+
341
+
342
+
343
+ }
344
+
345
+
346
+
347
+ ```

1

修正

2019/01/28 07:23

投稿

kimukou1205
kimukou1205

スコア13

test CHANGED
File without changes
test CHANGED
@@ -12,4 +12,4 @@
12
12
 
13
13
  ![イメージ説明](0a663d1ab003272dee022e87c283095c.png)
14
14
 
15
- しかし、今のままだと値がクリアせず元の画面に戻ってもセットした時間がまだ存在している。
15
+ しかし、今のままだと値がクリアせず元の画面に戻ってもセットした時間がまだ存在している。コード全般[GitHub](https://github.com/kimukou1205/Shake-Alarm_check)