实例介绍
【实例简介】
一款国外游戏手机钢琴源码,比较简单值得参考
【实例截图】
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 | package com.javacc.android.piano; import java.util.HashMap; import android.app.Activity; import android.media.AudioManager; import android.media.SoundPool; import android.os.Bundle; import android.view.MotionEvent; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.ImageButton; import android.widget.LinearLayout; public class Freeplay extends Activity { private ImageButton imageButton_white1; private ImageButton imageButton_white2; private ImageButton imageButton_white3; private ImageButton imageButton_white4; private ImageButton imageButton_white5; private ImageButton imageButton_white6; private ImageButton imageButton_white7; private ImageButton imageButton_white21; private ImageButton imageButton_white22; private ImageButton imageButton_white23; private ImageButton imageButton_white24; private ImageButton imageButton_white25; private ImageButton imageButton_white26; private ImageButton imageButton_white27; private ImageButton imageButton_black1; private ImageButton imageButton_black2; private ImageButton imageButton_black3; private ImageButton imageButton_black4; private ImageButton imageButton_black5; private ImageButton imageButton_black21; private ImageButton imageButton_black22; private ImageButton imageButton_black23; private ImageButton imageButton_black24; private ImageButton imageButton_black25; SoundPool soundPool; HashMap<Integer, Integer> soundMap = new HashMap<Integer, Integer>(); @Override protected void onCreate(Bundle bundle) { super .onCreate(bundle); setContentView(R.layout.main); soundPool = new SoundPool( 25 , AudioManager.STREAM_SYSTEM, 5 ); soundMap.put( 1 , soundPool.load( this , R.raw.white1, 1 )); soundMap.put( 2 , soundPool.load( this , R.raw.white2, 1 )); soundMap.put( 3 , soundPool.load( this , R.raw.white3, 1 )); soundMap.put( 4 , soundPool.load( this , R.raw.white4, 1 )); soundMap.put( 5 , soundPool.load( this , R.raw.white5, 1 )); soundMap.put( 6 , soundPool.load( this , R.raw.white6, 1 )); soundMap.put( 7 , soundPool.load( this , R.raw.white7, 1 )); soundMap.put( 14 , soundPool.load( this , R.raw.white21, 1 )); soundMap.put( 15 , soundPool.load( this , R.raw.white22, 1 )); soundMap.put( 16 , soundPool.load( this , R.raw.white23, 1 )); soundMap.put( 17 , soundPool.load( this , R.raw.white24, 1 )); soundMap.put( 18 , soundPool.load( this , R.raw.white25, 1 )); soundMap.put( 19 , soundPool.load( this , R.raw.white26, 1 )); soundMap.put( 20 , soundPool.load( this , R.raw.white27, 1 )); soundMap.put( 9 , soundPool.load( this , R.raw.black1, 1 )); soundMap.put( 10 , soundPool.load( this , R.raw.black2, 1 )); soundMap.put( 11 , soundPool.load( this , R.raw.black3, 1 )); soundMap.put( 12 , soundPool.load( this , R.raw.black4, 1 )); soundMap.put( 13 , soundPool.load( this , R.raw.black5, 1 )); soundMap.put( 21 , soundPool.load( this , R.raw.black21, 1 )); soundMap.put( 22 , soundPool.load( this , R.raw.black22, 1 )); soundMap.put( 23 , soundPool.load( this , R.raw.black23, 1 )); soundMap.put( 24 , soundPool.load( this , R.raw.black24, 1 )); soundMap.put( 25 , soundPool.load( this , R.raw.black25, 1 )); imageButton_white1 = (ImageButton) findViewById(R.id.white1); imageButton_white2 = (ImageButton) findViewById(R.id.white2); imageButton_white3 = (ImageButton) findViewById(R.id.white3); imageButton_white4 = (ImageButton) findViewById(R.id.white4); imageButton_white5 = (ImageButton) findViewById(R.id.white5); imageButton_white6 = (ImageButton) findViewById(R.id.white6); imageButton_white7 = (ImageButton) findViewById(R.id.white7); imageButton_white21 = (ImageButton) findViewById(R.id.white21); imageButton_white22 = (ImageButton) findViewById(R.id.white22); imageButton_white23 = (ImageButton) findViewById(R.id.white23); imageButton_white24 = (ImageButton) findViewById(R.id.white24); imageButton_white25 = (ImageButton) findViewById(R.id.white25); imageButton_white26 = (ImageButton) findViewById(R.id.white26); imageButton_white27 = (ImageButton) findViewById(R.id.white27); imageButton_black1 = (ImageButton) findViewById(R.id.black1); imageButton_black2 = (ImageButton) findViewById(R.id.black2); imageButton_black3 = (ImageButton) findViewById(R.id.black3); imageButton_black4 = (ImageButton) findViewById(R.id.black4); imageButton_black5 = (ImageButton) findViewById(R.id.black5); imageButton_black21 = (ImageButton) findViewById(R.id.black21); imageButton_black22 = (ImageButton) findViewById(R.id.black22); imageButton_black23 = (ImageButton) findViewById(R.id.black23); imageButton_black24 = (ImageButton) findViewById(R.id.black24); imageButton_black25 = (ImageButton) findViewById(R.id.black25); imageButton_white1.setOnTouchListener( new View.OnTouchListener() { public boolean onTouch(View view, MotionEvent motionEvent) { if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) { soundPool.play(soundMap.get( 1 ), 1 , 1 , 0 , 0 , 1 ); imageButton_white1.setImageResource(R.drawable.whiteback1); } if (motionEvent.getAction() == MotionEvent.ACTION_UP) { imageButton_white1.setImageResource(R.drawable.white1); } return false ; } }); imageButton_white2.setOnTouchListener( new View.OnTouchListener() { public boolean onTouch(View view, MotionEvent motionEvent) { if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) { soundPool.play(soundMap.get( 2 ), 1 , 1 , 0 , 0 , 1 ); imageButton_white2.setImageResource(R.drawable.whiteback2); } if (motionEvent.getAction() == MotionEvent.ACTION_UP) { imageButton_white2.setImageResource(R.drawable.white2); } return false ; } }); // imageButton_white3.setOnTouchListener( new View.OnTouchListener() { public boolean onTouch(View view, MotionEvent motionEvent) { if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) { soundPool.play(soundMap.get( 3 ), 1 , 1 , 0 , 0 , 1 ); imageButton_white3.setImageResource(R.drawable.whiteback3); } if (motionEvent.getAction() == MotionEvent.ACTION_UP) { imageButton_white3.setImageResource(R.drawable.white3); } return false ; } }); imageButton_white4.setOnTouchListener( new View.OnTouchListener() { public boolean onTouch(View view, MotionEvent motionEvent) { if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) { soundPool.play(soundMap.get( 4 ), 1 , 1 , 0 , 0 , 1 ); imageButton_white4.setImageResource(R.drawable.whiteback4); } if (motionEvent.getAction() == MotionEvent.ACTION_UP) { imageButton_white4.setImageResource(R.drawable.white4); } return false ; } }); imageButton_white5.setOnTouchListener( new View.OnTouchListener() { public boolean onTouch(View view, MotionEvent motionEvent) { if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) { soundPool.play(soundMap.get( 5 ), 1 , 1 , 0 , 0 , 1 ); imageButton_white5.setImageResource(R.drawable.whiteback5); } if (motionEvent.getAction() == MotionEvent.ACTION_UP) { imageButton_white5.setImageResource(R.drawable.white5); } return false ; } }); imageButton_white6.setOnTouchListener( new View.OnTouchListener() { public boolean onTouch(View view, MotionEvent motionEvent) { if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) { soundPool.play(soundMap.get( 6 ), 1 , 1 , 0 , 0 , 1 ); imageButton_white6.setImageResource(R.drawable.whiteback6); } if (motionEvent.getAction() == MotionEvent.ACTION_UP) { imageButton_white6.setImageResource(R.drawable.white6); } return false ; } }); imageButton_white7.setOnTouchListener( new View.OnTouchListener() { public boolean onTouch(View view, MotionEvent motionEvent) { if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) { soundPool.play(soundMap.get( 7 ), 1 , 1 , 0 , 0 , 1 ); imageButton_white7.setImageResource(R.drawable.whiteback7); } if (motionEvent.getAction() == MotionEvent.ACTION_UP) { imageButton_white7.setImageResource(R.drawable.white7); } return false ; } }); imageButton_white21.setOnTouchListener( new View.OnTouchListener() { public boolean onTouch(View view, MotionEvent motionEvent) { if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) { soundPool.play(soundMap.get( 14 ), 1 , 1 , 0 , 0 , 1 ); imageButton_white21.setImageResource(R.drawable.whiteback21); } if (motionEvent.getAction() == MotionEvent.ACTION_UP) { imageButton_white21.setImageResource(R.drawable.white21); } return false ; } }); imageButton_white22.setOnTouchListener( new View.OnTouchListener() { public boolean onTouch(View view, MotionEvent motionEvent) { if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) { soundPool.play(soundMap.get( 15 ), 1 , 1 , 0 , 0 , 1 ); imageButton_white22.setImageResource(R.drawable.whiteback22); } if (motionEvent.getAction() == MotionEvent.ACTION_UP) { imageButton_white22.setImageResource(R.drawable.white22); } return false ; } }); imageButton_white23.setOnTouchListener( new View.OnTouchListener() { public boolean onTouch(View view, MotionEvent motionEvent) { if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) { soundPool.play(soundMap.get( 16 ), 1 , 1 , 0 , 0 , 1 ); imageButton_white23.setImageResource(R.drawable.whiteback23); } if (motionEvent.getAction() == MotionEvent.ACTION_UP) { imageButton_white23.setImageResource(R.drawable.white23); } return false ; } }); imageButton_white24.setOnTouchListener( new View.OnTouchListener() { public boolean onTouch(View view, MotionEvent motionEvent) { if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) { soundPool.play(soundMap.get( 17 ), 1 , 1 , 0 , 0 , 1 ); imageButton_white24.setImageResource(R.drawable.whiteback24); } if (motionEvent.getAction() == MotionEvent.ACTION_UP) { imageButton_white24.setImageResource(R.drawable.white24); } return false ; } }); imageButton_white25.setOnTouchListener( new View.OnTouchListener() { public boolean onTouch(View view, MotionEvent motionEvent) { if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) { soundPool.play(soundMap.get( 18 ), 1 , 1 , 0 , 0 , 1 ); imageButton_white25.setImageResource(R.drawable.whiteback25); } if (motionEvent.getAction() == MotionEvent.ACTION_UP) { imageButton_white25.setImageResource(R.drawable.white25); } return false ; } }); imageButton_white26.setOnTouchListener( new View.OnTouchListener() { public boolean onTouch(View view, MotionEvent motionEvent) { if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) { soundPool.play(soundMap.get( 19 ), 1 , 1 , 0 , 0 , 1 ); imageButton_white26.setImageResource(R.drawable.whiteback26); } if (motionEvent.getAction() == MotionEvent.ACTION_UP) { imageButton_white26.setImageResource(R.drawable.white26); } return false ; } }); imageButton_white27.setOnTouchListener( new View.OnTouchListener() { public boolean onTouch(View view, MotionEvent motionEvent) { if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) { soundPool.play(soundMap.get( 20 ), 1 , 1 , 0 , 0 , 1 ); imageButton_white27.setImageResource(R.drawable.whiteback27); } if (motionEvent.getAction() == MotionEvent.ACTION_UP) { imageButton_white27.setImageResource(R.drawable.white27); } return false ; } }); imageButton_black1.setOnTouchListener( new View.OnTouchListener() { public boolean onTouch(View view, MotionEvent motionEvent) { if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) { soundPool.play(soundMap.get( 9 ), 1 , 1 , 0 , 0 , 1 ); } if (motionEvent.getAction() == MotionEvent.ACTION_UP) { imageButton_black1.setImageResource(R.drawable.black1); } return false ; } }); imageButton_black2.setOnTouchListener( new View.OnTouchListener() { public boolean onTouch(View view, MotionEvent motionEvent) { if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) { soundPool.play(soundMap.get( 10 ), 1 , 1 , 0 , 0 , 1 ); } if (motionEvent.getAction() == MotionEvent.ACTION_UP) { imageButton_black2.setImageResource(R.drawable.black2); } return false ; } }); imageButton_black3.setOnTouchListener( new View.OnTouchListener() { public boolean onTouch(View view, MotionEvent motionEvent) { if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) { soundPool.play(soundMap.get( 11 ), 1 , 1 , 0 , 0 , 1 ); } if (motionEvent.getAction() == MotionEvent.ACTION_UP) { imageButton_black3.setImageResource(R.drawable.black3); } return false ; } }); imageButton_black4.setOnTouchListener( new View.OnTouchListener() { public boolean onTouch(View view, MotionEvent motionEvent) { if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) { soundPool.play(soundMap.get( 12 ), 1 , 1 , 0 , 0 , 1 ); } if (motionEvent.getAction() == MotionEvent.ACTION_UP) { imageButton_black4.setImageResource(R.drawable.black4); } return false ; } }); imageButton_black5.setOnTouchListener( new View.OnTouchListener() { public boolean onTouch(View view, MotionEvent motionEvent) { if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) { soundPool.play(soundMap.get( 13 ), 1 , 1 , 0 , 0 , 1 ); } if (motionEvent.getAction() == MotionEvent.ACTION_UP) { imageButton_black5.setImageResource(R.drawable.black5); } return false ; } }); imageButton_black21.setOnTouchListener( new View.OnTouchListener() { public boolean onTouch(View view, MotionEvent motionEvent) { if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) { soundPool.play(soundMap.get( 21 ), 1 , 1 , 0 , 0 , 1 ); } if (motionEvent.getAction() == MotionEvent.ACTION_UP) { imageButton_black21.setImageResource(R.drawable.black21); } return false ; } }); imageButton_black22.setOnTouchListener( new View.OnTouchListener() { public boolean onTouch(View view, MotionEvent motionEvent) { if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) { soundPool.play(soundMap.get( 22 ), 1 , 1 , 0 , 0 , 1 ); } if (motionEvent.getAction() == MotionEvent.ACTION_UP) { imageButton_black22.setImageResource(R.drawable.black22); } return false ; } }); imageButton_black23.setOnTouchListener( new View.OnTouchListener() { public boolean onTouch(View view, MotionEvent motionEvent) { if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) { soundPool.play(soundMap.get( 23 ), 1 , 1 , 0 , 0 , 1 ); } if (motionEvent.getAction() == MotionEvent.ACTION_UP) { imageButton_black23.setImageResource(R.drawable.black23); } return false ; } }); imageButton_black24.setOnTouchListener( new View.OnTouchListener() { public boolean onTouch(View view, MotionEvent motionEvent) { if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) { soundPool.play(soundMap.get( 24 ), 1 , 1 , 0 , 0 , 1 ); } if (motionEvent.getAction() == MotionEvent.ACTION_UP) { imageButton_black24.setImageResource(R.drawable.black24); } return false ; } }); imageButton_black25.setOnTouchListener( new View.OnTouchListener() { public boolean onTouch(View view, MotionEvent motionEvent) { if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) { soundPool.play(soundMap.get( 25 ), 1 , 1 , 0 , 0 , 1 ); } if (motionEvent.getAction() == MotionEvent.ACTION_UP) { imageButton_black25.setImageResource(R.drawable.black25); } return false ; } }); // 获取应用程序中的bn11按钮 Button bn11 = (Button) findViewById(R.id.bn11); // 为bn11按钮绑定事件监听器 bn11.setOnClickListener( new OnClickListener() { public void onClick(View source) { //结束当前Activity finish(); } }); } } |
好例子网口号:伸出你的我的手 — 分享!
小贴士
感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。
- 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
- 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
- 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
- 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
关于好例子网
本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明
网友评论
我要评论