| /* |
| * Copyright (C) 2018 The Android Open Source Project |
| * |
| * Licensed under the Apache License, Version 2.0 (the "License"); |
| * you may not use this file except in compliance with the License. |
| * You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| * See the License for the specific language governing permissions and |
| * limitations under the License. |
| */ |
| |
| package com.android.car.settings.sound; |
| |
| import android.content.Context; |
| import android.content.res.TypedArray; |
| import android.media.RingtoneManager; |
| import android.util.AttributeSet; |
| |
| import androidx.preference.Preference; |
| |
| import com.android.car.ui.preference.CarUiPreference; |
| |
| /** |
| * A {@link Preference} which extracts relevant ringtone attributes from XML. When used in |
| * conjunction with {@link RingtonePreferenceController}, it can be used to select a default |
| * ringtone for a given ringtone type. |
| * |
| * @attr ref android.R.styleable#RingtonePreference_ringtoneType |
| * @attr ref android.R.styleable#RingtonePreference_showSilent |
| */ |
| public class RingtonePreference extends CarUiPreference { |
| |
| private boolean mShowSilent; |
| private int mRingtoneType; |
| |
| public RingtonePreference(Context context, AttributeSet attrs) { |
| super(context, attrs); |
| |
| TypedArray a = context.obtainStyledAttributes(attrs, |
| com.android.internal.R.styleable.RingtonePreference, 0, 0); |
| mRingtoneType = a.getInt(com.android.internal.R.styleable.RingtonePreference_ringtoneType, |
| RingtoneManager.TYPE_RINGTONE); |
| mShowSilent = a.getBoolean(com.android.internal.R.styleable.RingtonePreference_showSilent, |
| true); |
| a.recycle(); |
| } |
| |
| /** |
| * Returns the sound type(s) that are shown in the picker. |
| * |
| * @see #setRingtoneType(int) |
| */ |
| public int getRingtoneType() { |
| return mRingtoneType; |
| } |
| |
| /** |
| * Sets the sound type(s) that are shown in the picker. |
| * |
| * @param type The sound type(s) that are shown in the picker. |
| * @see RingtoneManager#EXTRA_RINGTONE_TYPE |
| */ |
| public void setRingtoneType(int type) { |
| mRingtoneType = type; |
| } |
| |
| /** |
| * Returns whether to a show an item for 'Silent'. |
| */ |
| public boolean getShowSilent() { |
| return mShowSilent; |
| } |
| |
| /** |
| * Sets whether to show an item for 'Silent'. |
| * |
| * @param showSilent Whether to show 'Silent'. |
| * @see RingtoneManager#EXTRA_RINGTONE_SHOW_SILENT |
| */ |
| public void setShowSilent(boolean showSilent) { |
| mShowSilent = showSilent; |
| } |
| } |