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.deskclock.settings;
17 
18 import android.content.Context;
19 import android.content.Intent;
20 import android.media.RingtoneManager;
21 import android.preference.RingtonePreference;
22 import android.support.annotation.NonNull;
23 import android.util.AttributeSet;
24 
25 import com.android.deskclock.data.DataModel;
26 
27 /**
28  * A custom RingtonePreference that presents the application's default timer ringtone as the value
29  * behind the default selection.
30  */
31 public final class TimerRingtonePreference extends RingtonePreference {
32 
TimerRingtonePreference(Context context)33     public TimerRingtonePreference(Context context) {
34         super(context);
35     }
36 
TimerRingtonePreference(Context context, AttributeSet attrs)37     public TimerRingtonePreference(Context context, AttributeSet attrs) {
38         super(context, attrs);
39     }
40 
TimerRingtonePreference(Context context, AttributeSet attrs, int defStyleAttr)41     public TimerRingtonePreference(Context context, AttributeSet attrs, int defStyleAttr) {
42         super(context, attrs, defStyleAttr);
43     }
44 
TimerRingtonePreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)45     public TimerRingtonePreference(Context context, AttributeSet attrs, int defStyleAttr,
46             int defStyleRes) {
47         super(context, attrs, defStyleAttr, defStyleRes);
48     }
49 
50     @Override
onPrepareRingtonePickerIntent(@onNull Intent ringtonePickerIntent)51     protected void onPrepareRingtonePickerIntent(@NonNull Intent ringtonePickerIntent) {
52         super.onPrepareRingtonePickerIntent(ringtonePickerIntent);
53 
54         // Replace the default ringtone uri with the beeping ringtone for timers.
55         ringtonePickerIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI,
56                 DataModel.getDataModel().getDefaultTimerRingtoneUri());
57     }
58 }