• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 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.settings.notification;
18 
19 import android.content.Context;
20 import android.media.Ringtone;
21 import android.media.RingtoneManager;
22 import android.net.Uri;
23 
24 import androidx.preference.Preference;
25 
26 import com.android.settings.core.PreferenceControllerMixin;
27 import com.android.settingslib.core.AbstractPreferenceController;
28 import com.android.settingslib.utils.ThreadUtils;
29 
30 public abstract class RingtonePreferenceControllerBase extends AbstractPreferenceController
31         implements PreferenceControllerMixin {
32 
RingtonePreferenceControllerBase(Context context)33     public RingtonePreferenceControllerBase(Context context) {
34         super(context);
35     }
36 
37     @Override
handlePreferenceTreeClick(Preference preference)38     public boolean handlePreferenceTreeClick(Preference preference) {
39         return false;
40     }
41 
42     @Override
isAvailable()43     public boolean isAvailable() {
44         return true;
45     }
46 
47     @Override
updateState(Preference preference)48     public void updateState(Preference preference) {
49         ThreadUtils.postOnBackgroundThread(() -> updateSummary(preference));
50     }
51 
updateSummary(Preference preference)52     private void updateSummary(Preference preference) {
53         final Uri ringtoneUri = RingtoneManager.getActualDefaultRingtoneUri(
54                 mContext, getRingtoneType());
55 
56         final CharSequence summary;
57         if (ringtoneUri == null) {
58             summary = null;
59         } else {
60             summary = Ringtone.getTitle(
61                     mContext, ringtoneUri, false /* followSettingsUri */, true /* allowRemote */);
62         }
63         if (summary != null) {
64             ThreadUtils.postOnMainThread(() -> preference.setSummary(summary));
65         }
66     }
67 
getRingtoneType()68     public abstract int getRingtoneType();
69 
70 }
71