質問編集履歴

1

項目名の修正、コードの追加

2017/01/22 12:57

投稿

ko20vonobird
ko20vonobird

スコア50

test CHANGED
File without changes
test CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
 
6
6
 
7
- ###発生している問題・エラーメッセージ
7
+ ###発生している問題
8
8
 
9
9
  なぜか値が0になります。また、下記の試したことで書いたようにインスタンスを作成してインスタンス.定数;としてみたのですが、うまくいきませんでした。
10
10
 
@@ -12,63 +12,477 @@
12
12
 
13
13
  ###該当のソースコード
14
14
 
15
+ 全文
16
+
15
- ```Java
17
+ ```java
18
+
19
+ package com.gmail.archerygame;
20
+
21
+
22
+
23
+ //import ゾーン
24
+
25
+
16
26
 
17
27
  public class Main extends Activity {
18
28
 
19
- private int winWM, winHM;
20
-
21
- @Override
22
-
23
- protected void onCreate(Bundle savedInstanceState) {
24
-
25
- super.onCreate(savedInstanceState);
29
+ //コンストラクタ的ゾーン
30
+
31
+ private TextView title;
32
+
33
+ private int winWM, winHM;
34
+
35
+ private int winWMl, winHMl;
36
+
37
+ private int a, r, g, b, cnt;
38
+
39
+ private int sw = 0;
40
+
41
+ private double kaku;
42
+
43
+ private float titley;
44
+
45
+ private float titleh;
46
+
47
+ private int deltay;
48
+
49
+ private double rad;
50
+
51
+ private Handler mHandler;
52
+
53
+ private Runnable titleloop;
54
+
55
+ private Handler stHandler = new Handler();
56
+
57
+ private Runnable st;
58
+
59
+ private Handler cbHandler;
60
+
61
+ private Runnable circlebreaking;
62
+
63
+ private Handler cbrunHandler = new Handler();
64
+
65
+ private Runnable circlemake;
66
+
67
+ Ct cta;
68
+
69
+ float s = 37.0f;
70
+
71
+ public int getWinWM(){//##########
72
+
73
+ return winWM;
74
+
75
+ }
76
+
77
+ public int getWinHM(){//##########
78
+
79
+ return winHM;
80
+
81
+ }
82
+
83
+ @Override
84
+
85
+ protected void onCreate(Bundle savedInstanceState) {
86
+
87
+ super.onCreate(savedInstanceState);
88
+
89
+ setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
90
+
91
+ //setContentView(R.layout.activity_main);
92
+
93
+ //ステータスバー非表示
94
+
95
+ getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
96
+
97
+ //タイトルバー非表示
98
+
99
+ requestWindowFeature(Window.FEATURE_NO_TITLE);
100
+
101
+ }
102
+
103
+ public void onResume() {
104
+
105
+ super.onResume();
106
+
107
+ if (mHandler != null){
108
+
109
+ mHandler.postDelayed(titleloop, 1000);
110
+
111
+ }
112
+
113
+ if (stHandler != null){
114
+
115
+ stHandler.postDelayed(st, 1000);
116
+
117
+ }
118
+
119
+ if (cbHandler != null){
120
+
121
+ cbHandler.postDelayed(circlebreaking, 1000);
122
+
123
+ }
124
+
125
+ if (cbrunHandler != null){
126
+
127
+ cbrunHandler.postDelayed(circlemake, 1000);
128
+
129
+ }
130
+
131
+ cta = new Ct(this);
132
+
133
+ parts();
134
+
135
+ }
136
+
137
+ public void parts() {
138
+
139
+ WindowManager wmM = (WindowManager)getSystemService(WINDOW_SERVICE);
140
+
141
+ Display dpM = wmM.getDefaultDisplay();
142
+
143
+ Point poM = new Point();
144
+
145
+ dpM.getSize(poM);
146
+
147
+ winWM = poM.x;
148
+
149
+ winHM = poM.y;
150
+
151
+ FrameLayout fl = new FrameLayout(this);
152
+
153
+ this.setContentView(fl);
154
+
155
+ fl.addView(cta);
156
+
157
+ final LinearLayout ll = new LinearLayout(this);
158
+
159
+ ll.setOrientation(LinearLayout.VERTICAL);
160
+
161
+ fl.addView(ll);
162
+
163
+ title = new TextView(this);
164
+
165
+ title.setText("N!ce・Sl!ngshot");
166
+
167
+ title.setTextSize(17.0f);
168
+
169
+ title.setTypeface(Typeface.SERIF);
170
+
171
+ float titlewidth = title.getCompoundPaddingLeft() + title.getCompoundPaddingRight() + Layout.getDesiredWidth(title.getText(),title.getPaint());
172
+
173
+ float titlemiddle = titlewidth;
174
+
175
+ int titlewhere = (int)((winWM / 2) - (titlemiddle / 2));
176
+
177
+ float titlewheref = (float)titlewhere;
178
+
179
+ title.setTranslationX(titlewheref);
180
+
181
+ ll.addView(title);
182
+
183
+ title.setVisibility(View.GONE);
184
+
185
+ st = new Runnable() {
186
+
187
+ @Override
188
+
189
+ public void run() {
190
+
191
+ stHandler.removeCallbacks(st);
192
+
193
+ looper();
194
+
195
+ }
196
+
197
+ };
198
+
199
+ stHandler.postDelayed(st, 3000);
200
+
201
+ }
202
+
203
+ public void looper() {
204
+
205
+ WindowManager wmMl = (WindowManager)getSystemService(WINDOW_SERVICE);
206
+
207
+ Display dpMl = wmMl.getDefaultDisplay();
208
+
209
+ Point poMl = new Point();
210
+
211
+ dpMl.getSize(poMl);
212
+
213
+ final int winWMl = poMl.x;
214
+
215
+ final int winHMl = poMl.y;
216
+
217
+ mHandler = new Handler();
218
+
219
+ a = 35;
220
+
221
+ r = 0;
222
+
223
+ g = 0;
224
+
225
+ b = 0;
226
+
227
+ cnt = 0;
228
+
229
+ kaku = 0;
230
+
231
+ titley = winWMl - titleh;
232
+
233
+ titleloop = new Runnable() {
234
+
235
+ @Override
236
+
237
+ public void run() {
238
+
239
+ title.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
240
+
241
+ titleh = title.getCompoundPaddingTop() + title.getCompoundPaddingBottom() + title.getMeasuredHeight();
242
+
243
+ float titlewidthcb = title.getCompoundPaddingLeft() + title.getCompoundPaddingRight() + Layout.getDesiredWidth(title.getText(),title.getPaint());
244
+
245
+ float titlewherecb = (winWMl / 2) - (titlewidthcb / 2);
246
+
247
+ title.setTranslationX(titlewherecb);
248
+
249
+ title.setTranslationY(titley);
250
+
251
+ title.setTypeface(Typeface.SERIF);
252
+
253
+ switch(title.getVisibility()){
254
+
255
+ case View.VISIBLE:
256
+
257
+ break;
258
+
259
+ case View.GONE:
260
+
261
+ title.setVisibility(View.VISIBLE);
262
+
263
+ break;
264
+
265
+ }
266
+
267
+ s = s + 0.4f;
268
+
269
+ kaku = -1 * cnt * 7.2;
270
+
271
+ rad = kaku * Math.PI / 180;
272
+
273
+ int deltay = (int)(winHMl * Math.sin(rad));
274
+
275
+ titley = winHMl + deltay;
276
+
277
+ title.setTextSize(s);
278
+
279
+ title.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
280
+
281
+ titleh = title.getCompoundPaddingTop() + title.getCompoundPaddingBottom() + title.getMeasuredHeight();
282
+
283
+ float titlewidthc = title.getCompoundPaddingLeft() + title.getCompoundPaddingRight() + Layout.getDesiredWidth(title.getText(),title.getPaint());
284
+
285
+ float titlewherec = (winWMl / 2) - (titlewidthc / 2);
286
+
287
+ title.setTranslationX(titlewherec);
288
+
289
+ title.setTranslationY(titley);
290
+
291
+ if (titley + titleh > winHMl) {
292
+
293
+ titley = winHMl - titleh;
294
+
295
+ title.setTranslationY(titley);
296
+
297
+ }
298
+
299
+ title.setTypeface(Typeface.SERIF);
300
+
301
+ title.setTextColor(Color.argb(a, r, g, b));
302
+
303
+ a = a + 4;
304
+
305
+ mHandler.postDelayed(titleloop, 15);
306
+
307
+ if (s >= 59.0f) {
308
+
309
+ mHandler.removeCallbacks(titleloop);
310
+
311
+ //次のまで数秒のハンドラ作成
312
+
313
+ cbHandler = new Handler();
314
+
315
+ circlebreaking = new Runnable() {
316
+
317
+ @Override
318
+
319
+ public void run() {
320
+
321
+ cb();
322
+
323
+ }
324
+
325
+ };
326
+
327
+ cbHandler.postDelayed(circlebreaking, 1500);
328
+
329
+ }
330
+
331
+ cnt = cnt + 1;
332
+
333
+ }
334
+
335
+ };
336
+
337
+ mHandler.postDelayed(titleloop, 15);
338
+
339
+ }
340
+
341
+ public void cb() {
342
+
343
+ cbHandler.removeCallbacks(circlebreaking);
344
+
345
+ Paint cipa = new Paint();
346
+
347
+ circlemake = new Runnable() {
348
+
349
+ @Override
350
+
351
+ public void run() {
352
+
353
+ //円のアニメーション描画
354
+
355
+ sw = 1;
356
+
357
+ cta.endraw();
358
+
359
+ cbrunHandler.removeCallbacks(circlemake);
360
+
361
+ }
362
+
363
+ };
364
+
365
+ cbrunHandler.postDelayed(circlemake, 15);
366
+
367
+ }
368
+
369
+ public class Ct extends View {
370
+
371
+ float gw = getWinWM();//##########
372
+
373
+ float gh = getWinHM();//##########
374
+
375
+ private float r1 = gw + 20;
376
+
377
+ private float cx = gw / 2;
378
+
379
+ private float cy = (gh / 2) - (gh / 6);
380
+
381
+ public Ct(Context context){
382
+
383
+ super(context);
384
+
385
+ }
386
+
387
+ protected void onDraw(Canvas canvas){
388
+
389
+ super.onDraw(canvas);
390
+
391
+ Paint pam = new Paint();
392
+
393
+ if (sw == 1){
394
+
395
+ //ここにすべての処理を書いていく↓
396
+
397
+ pam.setColor(Color.argb(255, 0, 0, 0));
398
+
399
+ pam.setStyle(Paint.Style.STROKE);
400
+
401
+ pam.setStrokeWidth(3);
402
+
403
+ canvas.drawCircle(cx, cy, r1, pam);
404
+
405
+ //ここにすべての処理を書いていく↑
406
+
407
+ }
408
+
409
+ }
410
+
411
+ public void endraw(){
412
+
413
+ invalidate();
414
+
415
+ }
416
+
417
+ }
418
+
419
+ public void onPause() {
420
+
421
+ super.onPause();
422
+
423
+ if (mHandler != null){
424
+
425
+ mHandler.removeCallbacks(titleloop);
426
+
427
+ }
428
+
429
+ if (stHandler != null){
430
+
431
+ stHandler.removeCallbacks(st);
432
+
433
+ }
434
+
435
+ if (cbHandler != null){
436
+
437
+ cbHandler.removeCallbacks(circlebreaking);
438
+
439
+ }
440
+
441
+ if (cbrunHandler != null) {
442
+
443
+ cbrunHandler.removeCallbacks(circlemake);
444
+
445
+ }
446
+
447
+ }
448
+
449
+ public void onDestroy() {
450
+
451
+ super.onDestroy();
452
+
453
+ if (mHandler != null){
454
+
455
+ mHandler.removeCallbacks(titleloop);
456
+
457
+ }
458
+
459
+ if (stHandler != null){
460
+
461
+ stHandler.removeCallbacks(st);
462
+
463
+ }
464
+
465
+ if (cbHandler != null){
466
+
467
+ cbHandler.removeCallbacks(circlebreaking);
468
+
469
+ }
470
+
471
+ if (cbrunHandler != null){
472
+
473
+ cbrunHandler.removeCallbacks(circlemake);
474
+
475
+ }
476
+
477
+ }
26
478
 
27
479
  }
28
480
 
29
- public void onResume() {
481
+
30
-
31
- super.onResume();
32
-
33
- parts();
34
-
35
- }
36
-
37
- public void parts() {
38
-
39
- WindowManager wmM = (WindowManager)getSystemService(WINDOW_SERVICE);
40
-
41
- Display dpM = wmM.getDefaultDisplay();
42
-
43
- Point poM = new Point();
44
-
45
- dpM.getSize(poM);
46
-
47
- final int winWM = poM.x;
48
-
49
- final int winHM = poM.y;
50
-
51
- }
52
-
53
- public class Ct extends View {
54
-
55
- Main ma = new Main();
56
-
57
- private float r1 = ma.winWM + 20;
58
-
59
- private float cx = winWM / 2;
60
-
61
- private float cy = (winHM / 2) - (winHM / 6);
62
-
63
- }
64
-
65
- }
66
482
 
67
483
  ```
68
484
 
69
- こんな感じです
485
+ 問題個所に//##########を付けました
70
-
71
-
72
486
 
73
487
  ###試したこと
74
488