
import android.app.Activity;
import android.media.ToneGenerator;
import android.os.Bundle;
import android.view.View;
public class ToneGeneratorTestActivity extends Activity {
private ToneGenerator toneGenerator;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// ToneGenerator初期化
toneGenerator = new ToneGenerator(android.media.AudioManager.STREAM_DTMF,ToneGenerator.MAX_VOLUME);
}
protected void onStop() {
super.onStop();
toneGenerator.release();
}
//ボタンが押されたときの処理
public void ButtonClick(View v) {
switch (v.getId()) {
case R.id.Button01:
toneGenerator.startTone(ToneGenerator.TONE_DTMF_1, 200);// 再生時間200ミリ秒(35-1500)
break;
case R.id.Button02:
toneGenerator.startTone(ToneGenerator.TONE_DTMF_2, 200);
break;
case R.id.Button03:
toneGenerator.startTone(ToneGenerator.TONE_DTMF_3, 200);
break;
case R.id.Button04:
toneGenerator.startTone(ToneGenerator.TONE_DTMF_4, 200);
break;
case R.id.Button05:
toneGenerator.startTone(ToneGenerator.TONE_DTMF_5, 200);
break;
case R.id.Button06:
toneGenerator.startTone(ToneGenerator.TONE_DTMF_6, 200);
break;
case R.id.Button07:
toneGenerator.startTone(ToneGenerator.TONE_DTMF_7, 200);
break;
case R.id.Button08:
toneGenerator.startTone(ToneGenerator.TONE_DTMF_8, 200);
break;
case R.id.Button09:
toneGenerator.startTone(ToneGenerator.TONE_DTMF_9, 200);
break;
case R.id.Button00:
toneGenerator.startTone(ToneGenerator.TONE_DTMF_0, 200);
break;
case R.id.Button0A:
toneGenerator.startTone(ToneGenerator.TONE_DTMF_A, 200);
break;
case R.id.Button0S:
toneGenerator.startTone(ToneGenerator.TONE_DTMF_S, 200);
break;
case R.id.ButtonFinish:
finish();
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TableRow
android:id="@+id/TableRow03"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1" >
<Button
android:id="@+id/Button01"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="1" android:onClick="ButtonClick"/>
<Button
android:id="@+id/Button02"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="2" android:onClick="ButtonClick"/>
<Button
android:id="@+id/Button03"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="3" android:onClick="ButtonClick"/>
</TableRow>
<TableRow
android:id="@+id/TableRow02"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1" >
<Button
android:id="@+id/Button04"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="4" android:onClick="ButtonClick"/>
<Button
android:id="@+id/Button05"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="5" android:onClick="ButtonClick"/>
<Button
android:id="@+id/Button06"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="6" android:onClick="ButtonClick"/>
</TableRow>
<TableRow
android:id="@+id/TableRow01"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1" >
<Button
android:id="@+id/Button07"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="7" android:onClick="ButtonClick"/>
<Button
android:id="@+id/Button08"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="8" android:onClick="ButtonClick"/>
<Button
android:id="@+id/Button09"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="9" android:onClick="ButtonClick"/>
</TableRow>
<TableRow
android:id="@+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1" >
<Button
android:id="@+id/Button0A"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="*" android:onClick="ButtonClick"/>
<Button
android:id="@+id/Button00"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="0" android:onClick="ButtonClick"/>
<Button
android:id="@+id/Button0S"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#" android:onClick="ButtonClick"/>
</TableRow>
</TableLayout>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="終了" android:id="@+id/ButtonFinish" android:onClick="ButtonClick"/>
</LinearLayout>
0 件のコメント:
コメントを投稿