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. mToneMap.put(Tone.DIAL, ToneGenerator.TONE_SUP_DIAL)34 mToneMap.put(Tone.DIAL, ToneGenerator.TONE_SUP_DIAL); mToneMap.put(Tone.BUSY, ToneGenerator.TONE_SUP_BUSY)35 mToneMap.put(Tone.BUSY, ToneGenerator.TONE_SUP_BUSY); mToneMap.put(Tone.CONGESTION, ToneGenerator.TONE_SUP_CONGESTION)36 mToneMap.put(Tone.CONGESTION, ToneGenerator.TONE_SUP_CONGESTION); mToneMap.put(Tone.RADIO_PATH_ACK, ToneGenerator.TONE_SUP_RADIO_ACK)37 mToneMap.put(Tone.RADIO_PATH_ACK, ToneGenerator.TONE_SUP_RADIO_ACK); mToneMap.put(Tone.RADIO_PATH_NOT_AVAILABLE, ToneGenerator.TONE_SUP_RADIO_NOTAVAIL)38 mToneMap.put(Tone.RADIO_PATH_NOT_AVAILABLE, ToneGenerator.TONE_SUP_RADIO_NOTAVAIL); mToneMap.put(Tone.ERROR_SPECIAL_INFO, ToneGenerator.TONE_SUP_ERROR)39 mToneMap.put(Tone.ERROR_SPECIAL_INFO, ToneGenerator.TONE_SUP_ERROR); mToneMap.put(Tone.CALL_WAITING, ToneGenerator.TONE_SUP_CALL_WAITING)40 mToneMap.put(Tone.CALL_WAITING, ToneGenerator.TONE_SUP_CALL_WAITING); mToneMap.put(Tone.RINGING, ToneGenerator.TONE_SUP_RINGTONE)41 mToneMap.put(Tone.RINGING, ToneGenerator.TONE_SUP_RINGTONE); mToneMap.put(Tone.GENERAL_BEEP, ToneGenerator.TONE_PROP_BEEP)42 mToneMap.put(Tone.GENERAL_BEEP, ToneGenerator.TONE_PROP_BEEP); mToneMap.put(Tone.POSITIVE_ACK, ToneGenerator.TONE_PROP_ACK)43 mToneMap.put(Tone.POSITIVE_ACK, ToneGenerator.TONE_PROP_ACK); mToneMap.put(Tone.NEGATIVE_ACK, ToneGenerator.TONE_PROP_NACK)44 mToneMap.put(Tone.NEGATIVE_ACK, ToneGenerator.TONE_PROP_NACK); 45 } 46 47 private ToneGenerator mToneGenerator = null; 48 TonePlayer()49 TonePlayer() { 50 mToneGenerator = new ToneGenerator(AudioManager.STREAM_SYSTEM, 100); 51 } 52 play(Tone tone)53 public void play(Tone tone) { 54 int toneId = getToneId(tone); 55 if (toneId > 0 && mToneGenerator != null) { 56 mToneGenerator.startTone(toneId); 57 } 58 } 59 stop()60 public void stop() { 61 if (mToneGenerator != null) { 62 mToneGenerator.stopTone(); 63 } 64 } 65 release()66 public void release() { 67 mToneGenerator.release(); 68 } 69 getToneId(Tone tone)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