1 /* 2 * Copyright (C) 2018 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.car.settings.sound; 18 19 import android.content.Context; 20 import android.content.res.TypedArray; 21 import android.media.RingtoneManager; 22 import android.util.AttributeSet; 23 24 import androidx.preference.Preference; 25 26 import com.android.car.ui.preference.CarUiPreference; 27 28 /** 29 * A {@link Preference} which extracts relevant ringtone attributes from XML. When used in 30 * conjunction with {@link RingtonePreferenceController}, it can be used to select a default 31 * ringtone for a given ringtone type. 32 * 33 * @attr ref android.R.styleable#RingtonePreference_ringtoneType 34 * @attr ref android.R.styleable#RingtonePreference_showSilent 35 */ 36 public class RingtonePreference extends CarUiPreference { 37 38 private boolean mShowSilent; 39 private int mRingtoneType; 40 RingtonePreference(Context context, AttributeSet attrs)41 public RingtonePreference(Context context, AttributeSet attrs) { 42 super(context, attrs); 43 44 TypedArray a = context.obtainStyledAttributes(attrs, 45 com.android.internal.R.styleable.RingtonePreference, 0, 0); 46 mRingtoneType = a.getInt(com.android.internal.R.styleable.RingtonePreference_ringtoneType, 47 RingtoneManager.TYPE_RINGTONE); 48 mShowSilent = a.getBoolean(com.android.internal.R.styleable.RingtonePreference_showSilent, 49 true); 50 a.recycle(); 51 } 52 53 /** 54 * Returns the sound type(s) that are shown in the picker. 55 * 56 * @see #setRingtoneType(int) 57 */ getRingtoneType()58 public int getRingtoneType() { 59 return mRingtoneType; 60 } 61 62 /** 63 * Sets the sound type(s) that are shown in the picker. 64 * 65 * @param type The sound type(s) that are shown in the picker. 66 * @see RingtoneManager#EXTRA_RINGTONE_TYPE 67 */ setRingtoneType(int type)68 public void setRingtoneType(int type) { 69 mRingtoneType = type; 70 } 71 72 /** 73 * Returns whether to a show an item for 'Silent'. 74 */ getShowSilent()75 public boolean getShowSilent() { 76 return mShowSilent; 77 } 78 79 /** 80 * Sets whether to show an item for 'Silent'. 81 * 82 * @param showSilent Whether to show 'Silent'. 83 * @see RingtoneManager#EXTRA_RINGTONE_SHOW_SILENT 84 */ setShowSilent(boolean showSilent)85 public void setShowSilent(boolean showSilent) { 86 mShowSilent = showSilent; 87 } 88 } 89