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 package com.android.messaging.util; 17 18 import android.content.Context; 19 import android.net.Uri; 20 import android.provider.Settings; 21 import android.text.TextUtils; 22 23 import com.android.messaging.Factory; 24 import com.android.messaging.R; 25 26 public class RingtoneUtil { 27 /** 28 * Return a ringtone Uri for the string representation passed in. Use the app 29 * and system defaults as fallbacks 30 * @param ringtoneString is the ringtone to resolve 31 * @return the Uri of the ringtone or the fallback ringtone 32 */ getNotificationRingtoneUri(String ringtoneString)33 public static Uri getNotificationRingtoneUri(String ringtoneString) { 34 if (ringtoneString == null) { 35 // No override specified, fall back to system-wide setting. 36 final BuglePrefs prefs = BuglePrefs.getApplicationPrefs(); 37 final Context context = Factory.get().getApplicationContext(); 38 final String prefKey = context.getString(R.string.notification_sound_pref_key); 39 ringtoneString = prefs.getString(prefKey, null); 40 } 41 42 if (!TextUtils.isEmpty(ringtoneString)) { 43 // We have set a value, even if it is the default Uri at some point 44 return Uri.parse(ringtoneString); 45 } else if (ringtoneString == null) { 46 // We have no setting specified (== null), so we default to the system default 47 return Settings.System.DEFAULT_NOTIFICATION_URI; 48 } else { 49 // An empty string (== "") here is the result of selecting "None" as the ringtone 50 return null; 51 } 52 } 53 } 54