blob: e0211748bc8a61f17eac1a7a03748a42a01f41aa [file] [log] [blame]
/*
* 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.Intent;
import android.content.res.TypedArray;
import android.media.RingtoneManager;
import android.util.AttributeSet;
import androidx.preference.Preference;
/**
* 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 Preference {
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);
setIntent(new Intent(RingtoneManager.ACTION_RINGTONE_PICKER));
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;
}
}