1 /* 2 * Copyright (C) 2007 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.stk; 18 19 import java.util.HashMap; 20 21 import android.media.AudioManager; 22 import android.media.ToneGenerator; 23 import com.android.internal.telephony.cat.Tone; 24 25 /** 26 * Class that implements a tones player for the SIM toolkit application. 27 * 28 */ 29 public class TonePlayer { 30 private static final HashMap<Tone, Integer> mToneMap = new HashMap<Tone, Integer>(); 31 32 static { 33 // Map STK tone ids to the system tone ids. 34 mToneMap.put(Tone.DIAL, ToneGenerator.TONE_SUP_DIAL); 35 mToneMap.put(Tone.BUSY, ToneGenerator.TONE_SUP_BUSY); 36 mToneMap.put(Tone.CONGESTION, ToneGenerator.TONE_SUP_CONGESTION); 37 mToneMap.put(Tone.RADIO_PATH_ACK, ToneGenerator.TONE_SUP_RADIO_ACK); 38 mToneMap.put(Tone.RADIO_PATH_NOT_AVAILABLE, ToneGenerator.TONE_SUP_RADIO_NOTAVAIL); 39 mToneMap.put(Tone.ERROR_SPECIAL_INFO, ToneGenerator.TONE_SUP_ERROR); 40 mToneMap.put(Tone.CALL_WAITING, ToneGenerator.TONE_SUP_CALL_WAITING); 41 mToneMap.put(Tone.RINGING, ToneGenerator.TONE_SUP_RINGTONE); 42 mToneMap.put(Tone.GENERAL_BEEP, ToneGenerator.TONE_PROP_BEEP); 43 mToneMap.put(Tone.POSITIVE_ACK, ToneGenerator.TONE_PROP_ACK); 44 mToneMap.put(Tone.NEGATIVE_ACK, ToneGenerator.TONE_PROP_NACK); 45 } 46 47 private ToneGenerator mToneGenerator = null; 48 49 TonePlayer() { 50 mToneGenerator = new ToneGenerator(AudioManager.STREAM_SYSTEM, 100); 51 } 52 53 public void play(Tone tone) { 54 int toneId = getToneId(tone); 55 if (toneId > 0 && mToneGenerator != null) { 56 mToneGenerator.startTone(toneId); 57 } 58 } 59 60 public void stop() { 61 if (mToneGenerator != null) { 62 mToneGenerator.stopTone(); 63 } 64 } 65 66 public void release() { 67 mToneGenerator.release(); 68 } 69 70 private int getToneId(Tone tone) { 71 int toneId = ToneGenerator.TONE_PROP_BEEP; 72 73 if (tone != null && mToneMap.containsKey(tone)) { 74 toneId = mToneMap.get(tone); 75 } 76 return toneId; 77 } 78 } 79