Settings: Add back increasing ring feature (2/3)
This is a squash of the following commits: Author: Danny Baumann <dannybaumann@web.de> Date: Tue Nov 11 13:14:07 2014 +0100 Add back increasing ring feature (2/3). Change-Id: Iafc79a57651db327a100e0f1723b62f442b638be Author: Danny Baumann <dannybaumann@web.de> Date: Mon Nov 24 13:05:39 2014 +0100 Fix NPE. When entering the notification prefs sub activity without the increasing ring pref being visible and leaving it right away, onActivityStop() threw an NPE because the handler wasn't yet constructed. Change-Id: Ia4291d8ac3d1dbf76d432db7e0e973844163c4ae Author: Danny Baumann <dannybaumann@web.de> Date: Fri May 29 08:48:46 2015 +0200 Fix up increasing ring tone volume preview behaviour. Change-Id: Ibe7fdf1ee7f0aa1c7c76052df69fa92e8b6a2ffd Author: Keith Mok <kmok@cyngn.com> Date: Tue Jul 12 09:45:45 2016 -0700 Settings: Always set ramp-up time value during bindView onProgressChange is not always called if we set the ramp up time to 5 sec (0 in seekbar value, since it is the default value, no change). Causing the text showing the ramp up time text value not updated and display as empty when user enable/disable increasing ring volume with ramp up time set to 5 sec. FEIJ-1572 Change-Id: Id32d6b51aab05e80be59bc1912c4ae7c5d114ac5 Author: Zhao Wei Liew <zhaoweiliew@gmail.com> Date: Wed, 18 Jan 2017 15:55:13 +0800 Move notif volume pref on top of increasing ring pref Change Iafc79a57651db327a100e0f1723b62f442b638be added two increasing ringtone-related preferences between the notification volume preference and the ring volume preference. However, the notification volume preference should be grouped together with the media, alarm, and ring volume preferences. Hence, move the notification volume preference back to where it should be. Change-Id: I138e6f78b6c231643d86746858e0cbdfcb0942eb Author: Bruno Martins <bgcngm@gmail.com> Date: Mon Dec 11 23:45:39 2017 +0000 Adapt increasing ring feature to O-MR1 and new Settings UI * Make it depend on SettingsLib's version of Lifecycle and Mixin. * Create a custom style for the IncreasingRingtonePreference and match the new UI in Oreo Settings app. Change-Id: I25462159fa39f5cdaddb1898c71f536572e900a4 Author: Bruno Martins <bgcngm@gmail.com> Date: Fri Jan 14 17:56:29 2022 +0000 Adapt increasing ring feature to S and new Settings UI Change-Id: Ib70f6f71f62e59c945d69ab9c23ca185fde4a4b0 Change-Id: I3f22c77504a5014f9dbd40909d760149143570fe
This commit is contained in:
20
res/color/audio_icon.xml
Normal file
20
res/color/audio_icon.xml
Normal file
@@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (C) 2014 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.
|
||||
-->
|
||||
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:state_enabled="false" android:color="#24000000" />
|
||||
<item android:color="#8a000000" />
|
||||
</selector>
|
||||
29
res/drawable/ring_notif_increasing.xml
Normal file
29
res/drawable/ring_notif_increasing.xml
Normal file
@@ -0,0 +1,29 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (C) 2014 The CyanogenMod Project
|
||||
Copyright (C) 2018 The LineageOS 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.
|
||||
-->
|
||||
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:tint="?android:attr/colorControlNormal"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
|
||||
<path
|
||||
android:fillColor="#FFFFFFFF"
|
||||
android:pathData="M12,22c1.105,0,2-0.898,2-2h-4C10,21.102,10.896,22,12,22Z M18.5,16v-5.5c0-3.075-2.135-5.643-5-6.321V3.5 C13.5,2.67,12.828,2,12,2s-1.5,0.67-1.5,1.5v0.679c-2.865,0.678-5,3.246-5,6.321V16l-2,2v1h17v-1L18.5,16z M16.504,14.558H7.561 V13.25l8.943-3.808V14.558z" />
|
||||
</vector>
|
||||
|
||||
120
res/layout/preference_increasing_ring.xml
Normal file
120
res/layout/preference_increasing_ring.xml
Normal file
@@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (C) 2014 The CyanogenMod 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.
|
||||
-->
|
||||
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:minHeight="?android:attr/listPreferredItemHeightSmall"
|
||||
android:gravity="center_vertical"
|
||||
android:paddingStart="?android:attr/listPreferredItemPaddingStart"
|
||||
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
|
||||
android:background="?android:attr/selectableItemBackground"
|
||||
android:clipToPadding="false">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/icon_container"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:minWidth="44dp"
|
||||
android:gravity="start|center_vertical"
|
||||
android:orientation="horizontal"
|
||||
android:paddingEnd="12dp"
|
||||
android:paddingTop="4dp"
|
||||
android:paddingBottom="4dp">
|
||||
<com.android.internal.widget.PreferenceImageView
|
||||
android:id="@android:id/icon"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:maxWidth="48dp"
|
||||
android:maxHeight="48dp"/>
|
||||
</LinearLayout>
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:paddingTop="12dp"
|
||||
android:paddingBottom="12dp">
|
||||
|
||||
<TextView android:id="@android:id/title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:singleLine="true"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:ellipsize="marquee"
|
||||
android:fadingEdge="horizontal" />
|
||||
|
||||
<TextView android:id="@+id/start_volume_label"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@android:id/title"
|
||||
android:layout_alignStart="@android:id/title"
|
||||
android:paddingStart="18dp"
|
||||
android:text="@string/increasing_ring_min_volume_title"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||
android:textColor="?android:attr/textColorSecondary"
|
||||
android:singleLine="true" />
|
||||
|
||||
<SeekBar android:id="@+id/start_volume"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/start_volume_label"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:max="1000" />
|
||||
|
||||
<TextView android:id="@+id/ramp_up_time_label"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/start_volume"
|
||||
android:layout_alignStart="@android:id/title"
|
||||
android:paddingStart="18dp"
|
||||
android:text="@string/increasing_ring_ramp_up_time_title"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||
android:textColor="?android:attr/textColorSecondary"
|
||||
android:singleLine="true" />
|
||||
|
||||
<TextView android:id="@+id/ramp_up_time_value"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/start_volume"
|
||||
android:layout_toEndOf="@id/ramp_up_time_label"
|
||||
android:layout_alignBaseline="@id/ramp_up_time_label"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:gravity="end"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||
android:textColor="?android:attr/textColorSecondary"
|
||||
android:singleLine="true" />
|
||||
|
||||
<SeekBar android:id="@+id/ramp_up_time"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/ramp_up_time_label"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:max="11" />
|
||||
|
||||
<TextView android:id="@android:id/summary"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/ramp_up_time"
|
||||
android:layout_alignStart="@android:id/title"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||
android:textColor="?android:attr/textColorSecondary"
|
||||
android:maxLines="4" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
</LinearLayout>
|
||||
@@ -243,4 +243,9 @@
|
||||
|
||||
<!-- Label for a numbered SIM card. [CHAR LIMIT=40] -->
|
||||
<string name="sim_card_number_title" translatable="false">SIM <xliff:g id="card_number">%1$d</xliff:g></string>
|
||||
|
||||
<!-- Increasing ring tone volume -->
|
||||
<string name="increasing_ring_volume_option_title">Increasing ring volume</string>
|
||||
<string name="increasing_ring_min_volume_title">Start volume</string>
|
||||
<string name="increasing_ring_ramp_up_time_title">Ramp-up time</string>
|
||||
</resources>
|
||||
|
||||
@@ -95,6 +95,22 @@
|
||||
settings:userRestriction="no_adjust_volume"
|
||||
settings:controller="com.android.settings.notification.AlarmVolumePreferenceController"/>
|
||||
|
||||
<!-- Increasing ring -->
|
||||
<org.evolution.settings.preferences.SystemSettingSwitchPreference
|
||||
android:key="increasing_ring"
|
||||
android:title="@string/increasing_ring_volume_option_title"
|
||||
android:order="-137"
|
||||
android:defaultValue="false"
|
||||
settings:controller="com.android.settings.notification.IncreasingRingPreferenceController" />
|
||||
|
||||
<!-- Increasing ring volume -->
|
||||
<com.android.settings.notification.IncreasingRingVolumePreference
|
||||
android:key="increasing_ring_volume"
|
||||
android:icon="@drawable/ring_notif_increasing"
|
||||
android:dependency="increasing_ring"
|
||||
android:order="-136"
|
||||
settings:controller="com.android.settings.notification.IncreasingRingVolumePreferenceController" />
|
||||
|
||||
<!-- TODO(b/174964721): make this a PrimarySwitchPreference -->
|
||||
<!-- Interruptions -->
|
||||
<com.android.settingslib.RestrictedPreference
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.settings.notification;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
|
||||
public class IncreasingRingPreferenceController extends BasePreferenceController {
|
||||
private static final String KEY_INCREASING_RING = "increasing_ring";
|
||||
|
||||
public IncreasingRingPreferenceController(Context context) {
|
||||
super(context, KEY_INCREASING_RING);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return Utils.isVoiceCapable(mContext) ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,255 @@
|
||||
/*
|
||||
* Copyright (C) 2014 CyanogenMod 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.settings.notification;
|
||||
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.media.AudioAttributes;
|
||||
import android.media.AudioManager;
|
||||
import android.media.Ringtone;
|
||||
import android.media.RingtoneManager;
|
||||
import android.os.Handler;
|
||||
import android.os.HandlerThread;
|
||||
import android.os.Message;
|
||||
import android.provider.Settings;
|
||||
import android.text.format.Formatter;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.widget.SeekBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.core.content.res.TypedArrayUtils;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceViewHolder;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
public class IncreasingRingVolumePreference extends Preference
|
||||
implements Handler.Callback, SeekBar.OnSeekBarChangeListener {
|
||||
private static final String TAG = "IncreasingRingMinVolumePreference";
|
||||
|
||||
public interface Callback {
|
||||
void onSampleStarting(IncreasingRingVolumePreference pref);
|
||||
}
|
||||
|
||||
private SeekBar mStartVolumeSeekBar;
|
||||
private SeekBar mRampUpTimeSeekBar;
|
||||
private TextView mRampUpTimeValue;
|
||||
|
||||
private Ringtone mRingtone;
|
||||
private Callback mCallback;
|
||||
|
||||
private Handler mHandler;
|
||||
private final Handler mMainHandler = new Handler(this);
|
||||
|
||||
private static final int MSG_START_SAMPLE = 1;
|
||||
private static final int MSG_STOP_SAMPLE = 2;
|
||||
private static final int MSG_INIT_SAMPLE = 3;
|
||||
private static final int MSG_SET_VOLUME = 4;
|
||||
private static final int CHECK_RINGTONE_PLAYBACK_DELAY_MS = 1000;
|
||||
|
||||
public IncreasingRingVolumePreference(Context context) {
|
||||
this(context, null);
|
||||
}
|
||||
|
||||
public IncreasingRingVolumePreference(Context context, AttributeSet attrs) {
|
||||
this(context, attrs, TypedArrayUtils.getAttr(context,
|
||||
androidx.preference.R.attr.preferenceStyle, android.R.attr.preferenceStyle));
|
||||
}
|
||||
|
||||
public IncreasingRingVolumePreference(Context context, AttributeSet attrs,
|
||||
int defStyleAttr) {
|
||||
this(context, attrs, defStyleAttr, 0);
|
||||
}
|
||||
|
||||
public IncreasingRingVolumePreference(Context context, AttributeSet attrs,
|
||||
int defStyleAttr, int defStyleRes) {
|
||||
super(context, attrs, defStyleAttr, defStyleRes);
|
||||
setLayoutResource(R.layout.preference_increasing_ring);
|
||||
initHandler();
|
||||
}
|
||||
|
||||
public void setCallback(Callback callback) {
|
||||
mCallback = callback;
|
||||
}
|
||||
|
||||
public void onActivityResume() {
|
||||
initHandler();
|
||||
}
|
||||
|
||||
public void onActivityStop() {
|
||||
if (mHandler != null) {
|
||||
postStopSample();
|
||||
mHandler.getLooper().quitSafely();
|
||||
mHandler = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleMessage(Message msg) {
|
||||
switch (msg.what) {
|
||||
case MSG_START_SAMPLE:
|
||||
onStartSample((float) msg.arg1 / 1000F);
|
||||
break;
|
||||
case MSG_STOP_SAMPLE:
|
||||
onStopSample();
|
||||
break;
|
||||
case MSG_INIT_SAMPLE:
|
||||
onInitSample();
|
||||
break;
|
||||
case MSG_SET_VOLUME:
|
||||
onSetVolume((float) msg.arg1 / 1000F);
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(PreferenceViewHolder holder) {
|
||||
super.onBindViewHolder(holder);
|
||||
|
||||
initHandler();
|
||||
|
||||
final SeekBar seekBar = (SeekBar) holder.findViewById(R.id.start_volume);
|
||||
if (seekBar == mStartVolumeSeekBar) return;
|
||||
|
||||
mStartVolumeSeekBar = seekBar;
|
||||
mRampUpTimeSeekBar = (SeekBar) holder.findViewById(R.id.ramp_up_time);
|
||||
mRampUpTimeValue = (TextView) holder.findViewById(R.id.ramp_up_time_value);
|
||||
|
||||
final ContentResolver cr = getContext().getContentResolver();
|
||||
float startVolume = Settings.System.getFloat(cr,
|
||||
Settings.System.INCREASING_RING_START_VOLUME, 0.1f);
|
||||
int rampUpTime = Settings.System.getInt(cr,
|
||||
Settings.System.INCREASING_RING_RAMP_UP_TIME, 10);
|
||||
|
||||
mStartVolumeSeekBar.setProgress(Math.round(startVolume * 1000F));
|
||||
mStartVolumeSeekBar.setOnSeekBarChangeListener(this);
|
||||
mRampUpTimeSeekBar.setOnSeekBarChangeListener(this);
|
||||
mRampUpTimeSeekBar.setProgress((rampUpTime / 5) - 1);
|
||||
mRampUpTimeValue.setText(
|
||||
Formatter.formatShortElapsedTime(getContext(), rampUpTime * 1000));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStartTrackingTouch(SeekBar seekBar) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStopTrackingTouch(SeekBar seekBar) {
|
||||
if (seekBar == mStartVolumeSeekBar) {
|
||||
postStartSample(seekBar.getProgress());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromTouch) {
|
||||
ContentResolver cr = getContext().getContentResolver();
|
||||
if (fromTouch && seekBar == mStartVolumeSeekBar) {
|
||||
Settings.System.putFloat(cr,
|
||||
Settings.System.INCREASING_RING_START_VOLUME, (float) progress / 1000F);
|
||||
} else if (seekBar == mRampUpTimeSeekBar) {
|
||||
int seconds = (progress + 1) * 5;
|
||||
mRampUpTimeValue.setText(
|
||||
Formatter.formatShortElapsedTime(getContext(), seconds * 1000));
|
||||
if (fromTouch) {
|
||||
Settings.System.putInt(cr,
|
||||
Settings.System.INCREASING_RING_RAMP_UP_TIME, seconds);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void initHandler() {
|
||||
if (mHandler != null) return;
|
||||
|
||||
HandlerThread thread = new HandlerThread(TAG + ".CallbackHandler");
|
||||
thread.start();
|
||||
|
||||
mHandler = new Handler(thread.getLooper(), this);
|
||||
mHandler.sendEmptyMessage(MSG_INIT_SAMPLE);
|
||||
}
|
||||
|
||||
private void onInitSample() {
|
||||
mRingtone = RingtoneManager.getRingtone(getContext(),
|
||||
Settings.System.DEFAULT_RINGTONE_URI);
|
||||
if (mRingtone != null) {
|
||||
mRingtone.setStreamType(AudioManager.STREAM_RING);
|
||||
mRingtone.setAudioAttributes(
|
||||
new AudioAttributes.Builder(mRingtone.getAudioAttributes())
|
||||
.setFlags(AudioAttributes.FLAG_BYPASS_INTERRUPTION_POLICY |
|
||||
AudioAttributes.FLAG_BYPASS_MUTE)
|
||||
.build());
|
||||
}
|
||||
}
|
||||
|
||||
private void postStartSample(int progress) {
|
||||
boolean playing = isSamplePlaying();
|
||||
mHandler.removeMessages(MSG_START_SAMPLE);
|
||||
mHandler.removeMessages(MSG_SET_VOLUME);
|
||||
mHandler.sendMessageDelayed(mHandler.obtainMessage(MSG_START_SAMPLE, progress, 0),
|
||||
playing ? CHECK_RINGTONE_PLAYBACK_DELAY_MS : 0);
|
||||
if (playing) {
|
||||
mHandler.sendMessage(mHandler.obtainMessage(MSG_SET_VOLUME, progress, 0));
|
||||
}
|
||||
}
|
||||
|
||||
private void onStartSample(float volume) {
|
||||
if (mRingtone == null) {
|
||||
return;
|
||||
}
|
||||
if (!isSamplePlaying()) {
|
||||
if (mCallback != null) {
|
||||
mCallback.onSampleStarting(this);
|
||||
}
|
||||
try {
|
||||
mRingtone.play();
|
||||
} catch (Throwable e) {
|
||||
Log.w(TAG, "Error playing ringtone", e);
|
||||
}
|
||||
}
|
||||
mRingtone.setVolume(volume);
|
||||
}
|
||||
|
||||
private void onSetVolume(float volume) {
|
||||
if (mRingtone != null) {
|
||||
mRingtone.setVolume(volume);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isSamplePlaying() {
|
||||
return mRingtone != null && mRingtone.isPlaying();
|
||||
}
|
||||
|
||||
public void stopSample() {
|
||||
if (mHandler != null) {
|
||||
postStopSample();
|
||||
}
|
||||
}
|
||||
|
||||
private void postStopSample() {
|
||||
// remove pending delayed start messages
|
||||
mHandler.removeMessages(MSG_START_SAMPLE);
|
||||
mHandler.removeMessages(MSG_STOP_SAMPLE);
|
||||
mHandler.sendEmptyMessage(MSG_STOP_SAMPLE);
|
||||
}
|
||||
|
||||
private void onStopSample() {
|
||||
if (mRingtone != null) {
|
||||
mRingtone.stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
/*
|
||||
* Copyright (C) 2016 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.settings.notification;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settings.slices.SliceData;
|
||||
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||
import com.android.settingslib.core.lifecycle.events.OnResume;
|
||||
import com.android.settingslib.core.lifecycle.events.OnStop;
|
||||
|
||||
/**
|
||||
* Base class for preference controller that handles VolumeSeekBarPreference
|
||||
*/
|
||||
public class IncreasingRingVolumePreferenceController
|
||||
extends AdjustVolumeRestrictedPreferenceController
|
||||
implements LifecycleObserver, OnResume, OnStop {
|
||||
|
||||
private static final String KEY_INCREASING_RING_VOLUME = "increasing_ring_volume";
|
||||
|
||||
private IncreasingRingVolumePreference mPreference;
|
||||
private IncreasingRingVolumePreference.Callback mCallback;
|
||||
private AudioHelper mHelper;
|
||||
|
||||
public IncreasingRingVolumePreferenceController(Context context) {
|
||||
super(context, KEY_INCREASING_RING_VOLUME);
|
||||
mHelper = new AudioHelper(context);
|
||||
}
|
||||
|
||||
public void setCallback(IncreasingRingVolumePreference.Callback callback) {
|
||||
mCallback = callback;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
if (isAvailable()) {
|
||||
mPreference = screen.findPreference(getPreferenceKey());
|
||||
mPreference.setCallback(mCallback);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
if (mPreference != null) {
|
||||
mPreference.onActivityResume();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
if (mPreference != null) {
|
||||
mPreference.onActivityStop();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferenceKey() {
|
||||
return KEY_INCREASING_RING_VOLUME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSliderPosition() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setSliderPosition(int position) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMin() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMax() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return Utils.isVoiceCapable(mContext) && !mHelper.isSingleVolume() ?
|
||||
AVAILABLE : UNSUPPORTED_ON_DEVICE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSliceType() {
|
||||
return SliceData.SliceType.INTENT;
|
||||
}
|
||||
}
|
||||
@@ -73,6 +73,8 @@ public class SoundSettings extends DashboardFragment implements OnActivityResult
|
||||
|
||||
@VisibleForTesting
|
||||
final VolumePreferenceCallback mVolumeCallback = new VolumePreferenceCallback();
|
||||
private final IncreasingRingVolumePreferenceCallback mIncreasingRingVolumeCallback =
|
||||
new IncreasingRingVolumePreferenceCallback();
|
||||
@VisibleForTesting
|
||||
final Handler mHandler = new Handler(Looper.getMainLooper()) {
|
||||
@Override
|
||||
@@ -80,6 +82,7 @@ public class SoundSettings extends DashboardFragment implements OnActivityResult
|
||||
switch (msg.what) {
|
||||
case STOP_SAMPLE:
|
||||
mVolumeCallback.stopSample();
|
||||
mIncreasingRingVolumeCallback.stopSample();
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -150,6 +153,7 @@ public class SoundSettings extends DashboardFragment implements OnActivityResult
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
mVolumeCallback.stopSample();
|
||||
mIncreasingRingVolumeCallback.stopSample();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -226,6 +230,11 @@ public class SoundSettings extends DashboardFragment implements OnActivityResult
|
||||
onPreferenceDataChanged(listPreference));
|
||||
mHfpOutputControllerKey =
|
||||
use(HandsFreeProfileOutputPreferenceController.class).getPreferenceKey();
|
||||
|
||||
IncreasingRingVolumePreferenceController irvpc =
|
||||
use(IncreasingRingVolumePreferenceController.class);
|
||||
irvpc.setCallback(mIncreasingRingVolumeCallback);
|
||||
getLifecycle().addObserver(irvpc);
|
||||
}
|
||||
|
||||
// === Volumes ===
|
||||
@@ -235,6 +244,7 @@ public class SoundSettings extends DashboardFragment implements OnActivityResult
|
||||
|
||||
@Override
|
||||
public void onSampleStarting(SeekBarVolumizer sbv) {
|
||||
mIncreasingRingVolumeCallback.stopSample();
|
||||
if (mCurrent != null) {
|
||||
mHandler.removeMessages(STOP_SAMPLE);
|
||||
mHandler.sendEmptyMessageDelayed(STOP_SAMPLE, SAMPLE_CUTOFF);
|
||||
@@ -265,6 +275,26 @@ public class SoundSettings extends DashboardFragment implements OnActivityResult
|
||||
}
|
||||
}
|
||||
|
||||
final class IncreasingRingVolumePreferenceCallback implements
|
||||
IncreasingRingVolumePreference.Callback {
|
||||
private IncreasingRingVolumePreference mPlayingPref;
|
||||
|
||||
@Override
|
||||
public void onSampleStarting(IncreasingRingVolumePreference pref) {
|
||||
mPlayingPref = pref;
|
||||
mVolumeCallback.stopSample();
|
||||
mHandler.removeMessages(STOP_SAMPLE);
|
||||
mHandler.sendEmptyMessageDelayed(STOP_SAMPLE, SAMPLE_CUTOFF);
|
||||
}
|
||||
|
||||
public void stopSample() {
|
||||
if (mPlayingPref != null) {
|
||||
mPlayingPref.stopSample();
|
||||
mPlayingPref = null;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private static List<AbstractPreferenceController> buildPreferenceControllers(Context context,
|
||||
SoundSettings fragment, Lifecycle lifecycle) {
|
||||
final List<AbstractPreferenceController> controllers = new ArrayList<>();
|
||||
@@ -276,6 +306,8 @@ public class SoundSettings extends DashboardFragment implements OnActivityResult
|
||||
controllers.add(new PhoneRingtone2PreferenceController(context));
|
||||
controllers.add(new AlarmRingtonePreferenceController(context));
|
||||
controllers.add(new NotificationRingtonePreferenceController(context));
|
||||
controllers.add(new IncreasingRingPreferenceController(context));
|
||||
controllers.add(new IncreasingRingVolumePreferenceController(context));
|
||||
|
||||
// === Other Sound Settings ===
|
||||
final DialPadTonePreferenceController dialPadTonePreferenceController =
|
||||
|
||||
Reference in New Issue
Block a user