TimerKlaxon.java revision 856483e7e18d5f042a338f7b3d472e28a386c4ad
1/* 2 * Copyright (C) 2015 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 17package com.android.deskclock.timer; 18 19import android.content.Context; 20import android.net.Uri; 21 22import com.android.deskclock.AsyncRingtonePlayer; 23import com.android.deskclock.LogUtils; 24import com.android.deskclock.SettingsActivity; 25import com.android.deskclock.data.DataModel; 26 27public abstract class TimerKlaxon { 28 29 private static boolean sStarted = false; 30 private static AsyncRingtonePlayer sAsyncRingtonePlayer; 31 32 private TimerKlaxon() { 33 } 34 35 public static void stop(Context context){ 36 if (sStarted) { 37 LogUtils.i("TimerKlaxon.stop()"); 38 sStarted = false; 39 getAsyncRingtonePlayer(context).stop(); 40 } 41 } 42 43 public static void start(Context context) { 44 // Make sure we are stopped before starting 45 stop(context); 46 LogUtils.i("TimerKlaxon.start()"); 47 48 // Look up user-selected timer ringtone. 49 final Uri uri = DataModel.getDataModel().getTimerRingtoneUri(); 50 getAsyncRingtonePlayer(context).play(uri); 51 52 sStarted = true; 53 } 54 55 private static synchronized AsyncRingtonePlayer getAsyncRingtonePlayer(Context context) { 56 if (sAsyncRingtonePlayer == null) { 57 sAsyncRingtonePlayer = new AsyncRingtonePlayer(context.getApplicationContext(), 58 SettingsActivity.KEY_TIMER_CRESCENDO); 59 } 60 61 return sAsyncRingtonePlayer; 62 } 63} 64