回答編集履歴

1

コード部を指定の記入に修正しました。よろしくお願いいいたします

2021/11/17 10:26

投稿

SanaeToyoda
SanaeToyoda

スコア1

test CHANGED
@@ -1,224 +1,224 @@
1
1
  ```java
2
2
 
3
+ public class WaikikipuzzleActivity extends AppCompatActivity {
4
+
5
+
6
+
7
+ private GameView gameView;
8
+
9
+ int level = 3;
10
+
11
+ private int photo = 1;
12
+
13
+
14
+
15
+
16
+
17
+ private InterstitialAd mInterstitialAd;
18
+
19
+ AdRequest adRequest_interstitial;
20
+
21
+ String AdMobID = "ca-app-pub-3940256099942544/1033173712";
22
+
23
+
24
+
25
+
26
+
27
+
28
+
29
+ @Override
30
+
31
+ protected void onCreate(Bundle savedInstanceState) {
32
+
33
+ super.onCreate(savedInstanceState);
34
+
35
+ setContentView(R.layout.activity_waikikipuzzle);
36
+
37
+
38
+
39
+
40
+
41
+
42
+
43
+ //全画面表示
44
+
45
+ View decor = getWindow().getDecorView();
46
+
47
+ decor.setSystemUiVisibility(
48
+
49
+ View.SYSTEM_UI_FLAG_LAYOUT_STABLE
50
+
51
+ | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
52
+
53
+ | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
54
+
55
+ | View.SYSTEM_UI_FLAG_FULLSCREEN
56
+
57
+ | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
58
+
59
+ | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
60
+
61
+
62
+
63
+
64
+
65
+
66
+
67
+ //ダイアログ表示
68
+
69
+ DisplayMetrics metrics = getResources().getDisplayMetrics();
70
+
71
+ int dialogWidth2 = (int)(metrics.widthPixels * 0.9);
72
+
73
+
74
+
75
+ final AppCompatDialog dialog2 = new AppCompatDialog(this);
76
+
77
+
78
+
79
+ dialog2.setContentView(R.layout.waikikipuzzleclear);
80
+
81
+
82
+
83
+ WindowManager.LayoutParams lp2 = dialog2.getWindow().getAttributes(); // コンテンツを追加したあと、showの前に記述
84
+
85
+ lp2.width = dialogWidth2;
86
+
87
+ dialog2.getWindow().setAttributes(lp2);
88
+
89
+
90
+
91
+ Toolbar toolbar = (Toolbar) findViewById(R.id.ac_toolbar_toolbar);
92
+
93
+
94
+
95
+ setSupportActionBar(toolbar);
96
+
97
+ gameView = (GameView) this.findViewById(R.id.game_view);
98
+
99
+ gameView.setPhoto(photo);
100
+
101
+ gameView.setOnFinishListener(new GameView.OnFinishListener(){
102
+
103
+ @Override
104
+
105
+ public void onFinish() {
106
+
107
+ Toast.makeText(WaikikipuzzleActivity.this, "完成!", Toast.LENGTH_LONG).show();
108
+
109
+ dialog2.show();
110
+
111
+
112
+
113
+
114
+
115
+ }
116
+
117
+
118
+
3
- コード
119
+ });
120
+
121
+
4
122
 
5
123
  ```
6
124
 
7
- public class WaikikipuzzleActivity extends AppCompatActivity {
8
-
9
-
10
-
11
- private GameView gameView;
12
-
13
- int level = 3;
14
-
15
- private int photo = 1;
16
-
17
-
18
-
19
-
20
-
21
- private InterstitialAd mInterstitialAd;
22
-
23
- AdRequest adRequest_interstitial;
24
-
25
- String AdMobID = "ca-app-pub-3940256099942544/1033173712";
26
-
27
-
28
-
29
-
30
-
31
-
32
-
33
- @Override
34
-
35
- protected void onCreate(Bundle savedInstanceState) {
36
-
37
- super.onCreate(savedInstanceState);
38
-
39
- setContentView(R.layout.activity_waikikipuzzle);
40
-
41
-
42
-
43
-
44
-
45
-
46
-
47
- //全画面表示
48
-
49
- View decor = getWindow().getDecorView();
50
-
51
- decor.setSystemUiVisibility(
52
-
53
- View.SYSTEM_UI_FLAG_LAYOUT_STABLE
54
-
55
- | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
56
-
57
- | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
58
-
59
- | View.SYSTEM_UI_FLAG_FULLSCREEN
60
-
61
- | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
62
-
63
- | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
64
-
65
-
66
-
67
-
68
-
69
-
70
-
71
- //ダイアログ表示
72
-
73
- DisplayMetrics metrics = getResources().getDisplayMetrics();
74
-
75
- int dialogWidth2 = (int)(metrics.widthPixels * 0.9);
76
-
77
-
78
-
79
- final AppCompatDialog dialog2 = new AppCompatDialog(this);
80
-
81
-
82
-
83
- dialog2.setContentView(R.layout.waikikipuzzleclear);
84
-
85
-
86
-
87
- WindowManager.LayoutParams lp2 = dialog2.getWindow().getAttributes(); // コンテンツを追加したあと、showの前に記述
88
-
89
- lp2.width = dialogWidth2;
90
-
91
- dialog2.getWindow().setAttributes(lp2);
92
-
93
-
94
-
95
- Toolbar toolbar = (Toolbar) findViewById(R.id.ac_toolbar_toolbar);
96
-
97
-
98
-
99
- setSupportActionBar(toolbar);
100
-
101
- gameView = (GameView) this.findViewById(R.id.game_view);
102
-
103
- gameView.setPhoto(photo);
104
-
105
- gameView.setOnFinishListener(new GameView.OnFinishListener(){
106
-
107
- @Override
108
-
109
- public void onFinish() {
110
-
111
- Toast.makeText(WaikikipuzzleActivity.this, "完成!", Toast.LENGTH_LONG).show();
112
-
113
- dialog2.show();
114
-
115
-
116
-
117
-
118
-
119
- }
120
-
121
-
122
-
123
- });
124
-
125
125
 
126
126
 
127
127
  ```java
128
128
 
129
+ public class GameView extends View {
130
+
131
+
132
+
133
+ private Context mycontext;
134
+
135
+ private Random random = new Random();
136
+
137
+ private int level = 3;//默认分3层
138
+
139
+ private int padding = 3;
140
+
141
+ private int photo;
142
+
143
+ private Resources mResources;
144
+
145
+ private Bitmap mBitmap;
146
+
147
+ private ArrayList<Patch> patches;
148
+
149
+ private int viewH;//view的高度
150
+
151
+ private int viewW;//view的宽度
152
+
153
+ private int canvasH;//一格画布的高度
154
+
155
+ private int canvasW;//一格画布的宽度
156
+
157
+ private int bitmapH;//一片图片的高度
158
+
159
+ private int bitmapW;//一片图片的宽度
160
+
161
+
162
+
163
+ private SoundPool soundPool;//声音池
164
+
165
+ private int s_move;//移动声音
166
+
167
+ private int s_error;//不能移动声音
168
+
169
+ private OnFinishListener listener;
170
+
171
+
172
+
173
+
174
+
175
+ int[] mImageResources = { R.drawable.waikikibeach, R.drawable.diyamondophoto};
176
+
177
+
178
+
179
+ public void setPhoto(int photo) {
180
+
181
+ this.photo = photo;
182
+
183
+ invalidate();
184
+
185
+
186
+
129
- コード
187
+ }
188
+
189
+
190
+
191
+ public GameView(Context context){
192
+
193
+ this(context, null);
194
+
195
+ }
196
+
197
+ public GameView(Context context, AttributeSet attrs) {
198
+
199
+
200
+
201
+ super(context, attrs);
202
+
203
+ mycontext = context;
204
+
205
+ mResources = getResources();
206
+
207
+ mBitmap = ((BitmapDrawable)mResources.getDrawable(mImageResources[photo])).getBitmap();
208
+
209
+ bitmapW = mBitmap.getWidth()/level;
210
+
211
+ bitmapH = mBitmap.getHeight()/level;
212
+
213
+ initPatches();
214
+
215
+ initSound();
216
+
217
+ }
130
218
 
131
219
  ```
132
220
 
133
- public class GameView extends View {
221
+
134
-
135
-
136
-
137
- private Context mycontext;
138
-
139
- private Random random = new Random();
140
-
141
- private int level = 3;//默认分3层
142
-
143
- private int padding = 3;
144
-
145
- private int photo;
146
-
147
- private Resources mResources;
148
-
149
- private Bitmap mBitmap;
150
-
151
- private ArrayList<Patch> patches;
152
-
153
- private int viewH;//view的高度
154
-
155
- private int viewW;//view的宽度
156
-
157
- private int canvasH;//一格画布的高度
158
-
159
- private int canvasW;//一格画布的宽度
160
-
161
- private int bitmapH;//一片图片的高度
162
-
163
- private int bitmapW;//一片图片的宽度
164
-
165
-
166
-
167
- private SoundPool soundPool;//声音池
168
-
169
- private int s_move;//移动声音
170
-
171
- private int s_error;//不能移动声音
172
-
173
- private OnFinishListener listener;
174
-
175
-
176
-
177
-
178
-
179
- int[] mImageResources = { R.drawable.waikikibeach, R.drawable.diyamondophoto};
180
-
181
-
182
-
183
- public void setPhoto(int photo) {
184
-
185
- this.photo = photo;
186
-
187
- invalidate();
188
-
189
-
190
-
191
- }
192
-
193
-
194
-
195
- public GameView(Context context){
196
-
197
- this(context, null);
198
-
199
- }
200
-
201
- public GameView(Context context, AttributeSet attrs) {
202
-
203
-
204
-
205
- super(context, attrs);
206
-
207
- mycontext = context;
208
-
209
- mResources = getResources();
210
-
211
- mBitmap = ((BitmapDrawable)mResources.getDrawable(mImageResources[photo])).getBitmap();
212
-
213
- bitmapW = mBitmap.getWidth()/level;
214
-
215
- bitmapH = mBitmap.getHeight()/level;
216
-
217
- initPatches();
218
-
219
- initSound();
220
-
221
- }
222
222
 
223
223
 
224
224