Merge "Make volume sliders sliceable" into pi-dev am: 4ef7b5f97b
am: 3fa5b4fad4
Change-Id: Idcbc7acf0343ff74f198ea960b8e6ca3d2e16a20
This commit is contained in:
@@ -27,6 +27,7 @@
|
|||||||
android:key="media_volume"
|
android:key="media_volume"
|
||||||
android:icon="@*android:drawable/ic_audio_media"
|
android:icon="@*android:drawable/ic_audio_media"
|
||||||
android:title="@string/media_volume_option_title"
|
android:title="@string/media_volume_option_title"
|
||||||
|
settings:controller="com.android.settings.notification.MediaVolumePreferenceController"
|
||||||
android:order="-170"/>
|
android:order="-170"/>
|
||||||
|
|
||||||
<!-- Alarm volume -->
|
<!-- Alarm volume -->
|
||||||
@@ -34,6 +35,7 @@
|
|||||||
android:key="alarm_volume"
|
android:key="alarm_volume"
|
||||||
android:icon="@*android:drawable/ic_audio_alarm"
|
android:icon="@*android:drawable/ic_audio_alarm"
|
||||||
android:title="@string/alarm_volume_option_title"
|
android:title="@string/alarm_volume_option_title"
|
||||||
|
settings:controller="com.android.settings.notification.AlarmVolumePreferenceController"
|
||||||
android:order="-160"/>
|
android:order="-160"/>
|
||||||
|
|
||||||
<!-- Ring volume -->
|
<!-- Ring volume -->
|
||||||
@@ -41,6 +43,7 @@
|
|||||||
android:key="ring_volume"
|
android:key="ring_volume"
|
||||||
android:icon="@*android:drawable/ic_audio_ring_notif"
|
android:icon="@*android:drawable/ic_audio_ring_notif"
|
||||||
android:title="@string/ring_volume_option_title"
|
android:title="@string/ring_volume_option_title"
|
||||||
|
settings:controller="com.android.settings.notification.RingVolumePreferenceController"
|
||||||
android:order="-150"/>
|
android:order="-150"/>
|
||||||
|
|
||||||
<!-- Notification volume -->
|
<!-- Notification volume -->
|
||||||
@@ -48,6 +51,7 @@
|
|||||||
android:key="notification_volume"
|
android:key="notification_volume"
|
||||||
android:icon="@*android:drawable/ic_audio_ring_notif"
|
android:icon="@*android:drawable/ic_audio_ring_notif"
|
||||||
android:title="@string/notification_volume_option_title"
|
android:title="@string/notification_volume_option_title"
|
||||||
|
settings:controller="com.android.settings.notification.NotificationVolumePreferenceController"
|
||||||
android:order="-140"/>
|
android:order="-140"/>
|
||||||
|
|
||||||
<!-- Also vibrate for calls -->
|
<!-- Also vibrate for calls -->
|
||||||
|
@@ -24,6 +24,7 @@ import android.support.v7.preference.Preference;
|
|||||||
import com.android.internal.annotations.VisibleForTesting;
|
import com.android.internal.annotations.VisibleForTesting;
|
||||||
import com.android.settings.accounts.AccountRestrictionHelper;
|
import com.android.settings.accounts.AccountRestrictionHelper;
|
||||||
import com.android.settings.core.PreferenceControllerMixin;
|
import com.android.settings.core.PreferenceControllerMixin;
|
||||||
|
import com.android.settings.core.SliderPreferenceController;
|
||||||
import com.android.settingslib.RestrictedPreference;
|
import com.android.settingslib.RestrictedPreference;
|
||||||
import com.android.settingslib.core.AbstractPreferenceController;
|
import com.android.settingslib.core.AbstractPreferenceController;
|
||||||
|
|
||||||
@@ -32,17 +33,18 @@ import com.android.settingslib.core.AbstractPreferenceController;
|
|||||||
* restriction
|
* restriction
|
||||||
*/
|
*/
|
||||||
public abstract class AdjustVolumeRestrictedPreferenceController extends
|
public abstract class AdjustVolumeRestrictedPreferenceController extends
|
||||||
AbstractPreferenceController implements PreferenceControllerMixin {
|
SliderPreferenceController implements PreferenceControllerMixin {
|
||||||
|
|
||||||
private AccountRestrictionHelper mHelper;
|
private AccountRestrictionHelper mHelper;
|
||||||
|
|
||||||
public AdjustVolumeRestrictedPreferenceController(Context context) {
|
public AdjustVolumeRestrictedPreferenceController(Context context, String key) {
|
||||||
this(context, new AccountRestrictionHelper(context));
|
this(context, new AccountRestrictionHelper(context), key);
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
AdjustVolumeRestrictedPreferenceController(Context context, AccountRestrictionHelper helper) {
|
AdjustVolumeRestrictedPreferenceController(Context context, AccountRestrictionHelper helper,
|
||||||
super(context);
|
String key) {
|
||||||
|
super(context, key);
|
||||||
mHelper = helper;
|
mHelper = helper;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -20,32 +20,21 @@ import android.content.Context;
|
|||||||
import android.media.AudioManager;
|
import android.media.AudioManager;
|
||||||
|
|
||||||
import com.android.internal.annotations.VisibleForTesting;
|
import com.android.internal.annotations.VisibleForTesting;
|
||||||
import com.android.settings.notification.VolumeSeekBarPreference.Callback;
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
|
||||||
|
|
||||||
public class AlarmVolumePreferenceController extends
|
public class AlarmVolumePreferenceController extends
|
||||||
VolumeSeekBarPreferenceController {
|
VolumeSeekBarPreferenceController {
|
||||||
|
|
||||||
private static final String KEY_ALARM_VOLUME = "alarm_volume";
|
private static final String KEY_ALARM_VOLUME = "alarm_volume";
|
||||||
private AudioHelper mHelper;
|
|
||||||
|
|
||||||
public AlarmVolumePreferenceController(Context context, Callback callback,
|
public AlarmVolumePreferenceController(Context context) {
|
||||||
Lifecycle lifecycle) {
|
super(context, KEY_ALARM_VOLUME);
|
||||||
this(context, callback, lifecycle, new AudioHelper(context));
|
|
||||||
}
|
|
||||||
|
|
||||||
@VisibleForTesting
|
|
||||||
AlarmVolumePreferenceController(Context context, Callback callback, Lifecycle lifecycle,
|
|
||||||
AudioHelper helper) {
|
|
||||||
super(context, callback, lifecycle);
|
|
||||||
mHelper = helper;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isAvailable() {
|
public int getAvailabilityStatus() {
|
||||||
return mContext.getResources().getBoolean(R.bool.config_show_alarm_volume)
|
return mContext.getResources().getBoolean(R.bool.config_show_alarm_volume)
|
||||||
&& !mHelper.isSingleVolume();
|
&& !mHelper.isSingleVolume() ? AVAILABLE : DISABLED_UNSUPPORTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -62,5 +51,4 @@ public class AlarmVolumePreferenceController extends
|
|||||||
public int getMuteIcon() {
|
public int getMuteIcon() {
|
||||||
return com.android.internal.R.drawable.ic_audio_alarm_mute;
|
return com.android.internal.R.drawable.ic_audio_alarm_mute;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -18,6 +18,7 @@ package com.android.settings.notification;
|
|||||||
|
|
||||||
import android.annotation.UserIdInt;
|
import android.annotation.UserIdInt;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.media.AudioManager;
|
||||||
import android.media.AudioSystem;
|
import android.media.AudioSystem;
|
||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
import android.os.UserManager;
|
import android.os.UserManager;
|
||||||
@@ -29,9 +30,11 @@ import com.android.settings.Utils;
|
|||||||
public class AudioHelper {
|
public class AudioHelper {
|
||||||
|
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
|
private AudioManager mAudioManager;
|
||||||
|
|
||||||
public AudioHelper(Context context) {
|
public AudioHelper(Context context) {
|
||||||
mContext = context;
|
mContext = context;
|
||||||
|
mAudioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isSingleVolume() {
|
public boolean isSingleVolume() {
|
||||||
@@ -49,4 +52,25 @@ public class AudioHelper {
|
|||||||
public Context createPackageContextAsUser(@UserIdInt int profileId) {
|
public Context createPackageContextAsUser(@UserIdInt int profileId) {
|
||||||
return Utils.createPackageContextAsUser(mContext, profileId);
|
return Utils.createPackageContextAsUser(mContext, profileId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getRingerModeInternal() {
|
||||||
|
return mAudioManager.getRingerModeInternal();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getLastAudibleStreamVolume(int stream) {
|
||||||
|
return mAudioManager.getLastAudibleStreamVolume(stream);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getStreamVolume(int stream) {
|
||||||
|
return mAudioManager.getStreamVolume(stream);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean setStreamVolume(int stream, int volume) {
|
||||||
|
mAudioManager.setStreamVolume(stream, volume, 0);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getMaxVolume(int stream) {
|
||||||
|
return mAudioManager.getStreamMaxVolume(stream);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -27,13 +27,15 @@ public class MediaVolumePreferenceController extends
|
|||||||
|
|
||||||
private static final String KEY_MEDIA_VOLUME = "media_volume";
|
private static final String KEY_MEDIA_VOLUME = "media_volume";
|
||||||
|
|
||||||
public MediaVolumePreferenceController(Context context, Callback callback, Lifecycle lifecycle) {
|
public MediaVolumePreferenceController(Context context) {
|
||||||
super(context, callback, lifecycle);
|
super(context, KEY_MEDIA_VOLUME);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isAvailable() {
|
public int getAvailabilityStatus() {
|
||||||
return mContext.getResources().getBoolean(R.bool.config_show_media_volume);
|
return mContext.getResources().getBoolean(R.bool.config_show_media_volume)
|
||||||
|
? AVAILABLE
|
||||||
|
: DISABLED_UNSUPPORTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -50,5 +52,4 @@ public class MediaVolumePreferenceController extends
|
|||||||
public int getMuteIcon() {
|
public int getMuteIcon() {
|
||||||
return com.android.internal.R.drawable.ic_audio_media_mute;
|
return com.android.internal.R.drawable.ic_audio_media_mute;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -22,32 +22,21 @@ import android.media.AudioManager;
|
|||||||
import com.android.internal.annotations.VisibleForTesting;
|
import com.android.internal.annotations.VisibleForTesting;
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.Utils;
|
import com.android.settings.Utils;
|
||||||
import com.android.settings.notification.VolumeSeekBarPreference.Callback;
|
|
||||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
|
||||||
|
|
||||||
public class NotificationVolumePreferenceController extends
|
public class NotificationVolumePreferenceController extends
|
||||||
RingVolumePreferenceController {
|
RingVolumePreferenceController {
|
||||||
|
|
||||||
private static final String KEY_NOTIFICATION_VOLUME = "notification_volume";
|
private static final String KEY_NOTIFICATION_VOLUME = "notification_volume";
|
||||||
private AudioHelper mHelper;
|
|
||||||
|
|
||||||
public NotificationVolumePreferenceController(Context context, Callback callback,
|
public NotificationVolumePreferenceController(Context context) {
|
||||||
Lifecycle lifecycle) {
|
super(context, KEY_NOTIFICATION_VOLUME);
|
||||||
this(context, callback, lifecycle, new AudioHelper(context));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
|
||||||
NotificationVolumePreferenceController(Context context,
|
|
||||||
Callback callback, Lifecycle lifecycle, AudioHelper helper) {
|
|
||||||
super(context, callback, lifecycle);
|
|
||||||
mHelper = helper;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isAvailable() {
|
public int getAvailabilityStatus() {
|
||||||
return mContext.getResources().getBoolean(R.bool.config_show_notification_volume)
|
return mContext.getResources().getBoolean(R.bool.config_show_notification_volume)
|
||||||
&& !Utils.isVoiceCapable(mContext) && !mHelper.isSingleVolume();
|
&& !Utils.isVoiceCapable(mContext) && !mHelper.isSingleVolume()
|
||||||
|
? AVAILABLE : DISABLED_UNSUPPORTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -31,8 +31,6 @@ import android.os.Vibrator;
|
|||||||
import com.android.internal.annotations.VisibleForTesting;
|
import com.android.internal.annotations.VisibleForTesting;
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.Utils;
|
import com.android.settings.Utils;
|
||||||
import com.android.settings.notification.VolumeSeekBarPreference.Callback;
|
|
||||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
@@ -41,24 +39,18 @@ public class RingVolumePreferenceController extends VolumeSeekBarPreferenceContr
|
|||||||
private static final String TAG = "RingVolumeController";
|
private static final String TAG = "RingVolumeController";
|
||||||
private static final String KEY_RING_VOLUME = "ring_volume";
|
private static final String KEY_RING_VOLUME = "ring_volume";
|
||||||
|
|
||||||
private AudioManager mAudioManager;
|
|
||||||
private Vibrator mVibrator;
|
private Vibrator mVibrator;
|
||||||
private int mRingerMode = -1;
|
private int mRingerMode = -1;
|
||||||
private ComponentName mSuppressor;
|
private ComponentName mSuppressor;
|
||||||
private final RingReceiver mReceiver = new RingReceiver();
|
private final RingReceiver mReceiver = new RingReceiver();
|
||||||
private final H mHandler = new H();
|
private final H mHandler = new H();
|
||||||
private AudioHelper mHelper;
|
|
||||||
|
|
||||||
public RingVolumePreferenceController(Context context, Callback callback, Lifecycle lifecycle) {
|
public RingVolumePreferenceController(Context context) {
|
||||||
this(context, callback, lifecycle, new AudioHelper(context));
|
this(context, KEY_RING_VOLUME);
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
public RingVolumePreferenceController(Context context, String key) {
|
||||||
RingVolumePreferenceController(Context context, Callback callback, Lifecycle lifecycle,
|
super(context, key);
|
||||||
AudioHelper helper) {
|
|
||||||
super(context, callback, lifecycle);
|
|
||||||
mHelper = helper;
|
|
||||||
mAudioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
|
|
||||||
mVibrator = (Vibrator) mContext.getSystemService(Context.VIBRATOR_SERVICE);
|
mVibrator = (Vibrator) mContext.getSystemService(Context.VIBRATOR_SERVICE);
|
||||||
if (mVibrator != null && !mVibrator.hasVibrator()) {
|
if (mVibrator != null && !mVibrator.hasVibrator()) {
|
||||||
mVibrator = null;
|
mVibrator = null;
|
||||||
@@ -86,8 +78,9 @@ public class RingVolumePreferenceController extends VolumeSeekBarPreferenceContr
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isAvailable() {
|
public int getAvailabilityStatus() {
|
||||||
return Utils.isVoiceCapable(mContext) && !mHelper.isSingleVolume();
|
return Utils.isVoiceCapable(mContext) && !mHelper.isSingleVolume()
|
||||||
|
? AVAILABLE : DISABLED_UNSUPPORTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -101,7 +94,7 @@ public class RingVolumePreferenceController extends VolumeSeekBarPreferenceContr
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void updateRingerMode() {
|
private void updateRingerMode() {
|
||||||
final int ringerMode = mAudioManager.getRingerModeInternal();
|
final int ringerMode = mHelper.getRingerModeInternal();
|
||||||
if (mRingerMode == ringerMode) return;
|
if (mRingerMode == ringerMode) return;
|
||||||
mRingerMode = ringerMode;
|
mRingerMode = ringerMode;
|
||||||
updatePreferenceIcon();
|
updatePreferenceIcon();
|
||||||
@@ -109,7 +102,7 @@ public class RingVolumePreferenceController extends VolumeSeekBarPreferenceContr
|
|||||||
|
|
||||||
private boolean wasRingerModeVibrate() {
|
private boolean wasRingerModeVibrate() {
|
||||||
return mVibrator != null && mRingerMode == AudioManager.RINGER_MODE_SILENT
|
return mVibrator != null && mRingerMode == AudioManager.RINGER_MODE_SILENT
|
||||||
&& mAudioManager.getLastAudibleStreamVolume(AudioManager.STREAM_RING) == 0;
|
&& mHelper.getLastAudibleStreamVolume(getAudioStream()) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateEffectsSuppressor() {
|
private void updateEffectsSuppressor() {
|
||||||
|
@@ -126,7 +126,7 @@ public class SoundSettings extends DashboardFragment {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
|
protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
|
||||||
return buildPreferenceControllers(context, this, mVolumeCallback, getLifecycle());
|
return buildPreferenceControllers(context, this, getLifecycle());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -145,6 +145,15 @@ public class SoundSettings extends DashboardFragment {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAttach(Context context) {
|
||||||
|
super.onAttach(context);
|
||||||
|
use(AlarmVolumePreferenceController.class).setCallback(mVolumeCallback);
|
||||||
|
use(MediaVolumePreferenceController.class).setCallback(mVolumeCallback);
|
||||||
|
use(RingVolumePreferenceController.class).setCallback(mVolumeCallback);
|
||||||
|
use(NotificationVolumePreferenceController.class).setCallback(mVolumeCallback);
|
||||||
|
}
|
||||||
|
|
||||||
// === Volumes ===
|
// === Volumes ===
|
||||||
|
|
||||||
final class VolumePreferenceCallback implements VolumeSeekBarPreference.Callback {
|
final class VolumePreferenceCallback implements VolumeSeekBarPreference.Callback {
|
||||||
@@ -178,18 +187,12 @@ public class SoundSettings extends DashboardFragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static List<AbstractPreferenceController> buildPreferenceControllers(Context context,
|
private static List<AbstractPreferenceController> buildPreferenceControllers(Context context,
|
||||||
SoundSettings fragment, VolumeSeekBarPreference.Callback callback,
|
SoundSettings fragment, Lifecycle lifecycle) {
|
||||||
Lifecycle lifecycle) {
|
|
||||||
final List<AbstractPreferenceController> controllers = new ArrayList<>();
|
final List<AbstractPreferenceController> controllers = new ArrayList<>();
|
||||||
controllers.add(new ZenModePreferenceController(context, lifecycle, KEY_ZEN_MODE));
|
controllers.add(new ZenModePreferenceController(context, lifecycle, KEY_ZEN_MODE));
|
||||||
controllers.add(new VibrateWhenRingPreferenceController(context));
|
controllers.add(new VibrateWhenRingPreferenceController(context));
|
||||||
|
|
||||||
// === Volumes ===
|
// Volumes are added via xml
|
||||||
controllers.add(new AlarmVolumePreferenceController(context, callback, lifecycle));
|
|
||||||
controllers.add(new MediaVolumePreferenceController(context, callback, lifecycle));
|
|
||||||
controllers.add(
|
|
||||||
new NotificationVolumePreferenceController(context, callback, lifecycle));
|
|
||||||
controllers.add(new RingVolumePreferenceController(context, callback, lifecycle));
|
|
||||||
|
|
||||||
// === Phone & notification ringtone ===
|
// === Phone & notification ringtone ===
|
||||||
controllers.add(new PhoneRingtonePreferenceController(context));
|
controllers.add(new PhoneRingtonePreferenceController(context));
|
||||||
@@ -259,7 +262,7 @@ public class SoundSettings extends DashboardFragment {
|
|||||||
public List<AbstractPreferenceController> createPreferenceControllers(
|
public List<AbstractPreferenceController> createPreferenceControllers(
|
||||||
Context context) {
|
Context context) {
|
||||||
return buildPreferenceControllers(context, null /* fragment */,
|
return buildPreferenceControllers(context, null /* fragment */,
|
||||||
null /* callback */, null /* lifecycle */);
|
null /* lifecycle */);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -16,31 +16,37 @@
|
|||||||
|
|
||||||
package com.android.settings.notification;
|
package com.android.settings.notification;
|
||||||
|
|
||||||
|
import android.arch.lifecycle.LifecycleObserver;
|
||||||
|
import android.arch.lifecycle.OnLifecycleEvent;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.support.v7.preference.PreferenceScreen;
|
import android.support.v7.preference.PreferenceScreen;
|
||||||
|
|
||||||
|
import com.android.internal.annotations.VisibleForTesting;
|
||||||
import com.android.settings.notification.VolumeSeekBarPreference.Callback;
|
import com.android.settings.notification.VolumeSeekBarPreference.Callback;
|
||||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||||
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
|
||||||
import com.android.settingslib.core.lifecycle.events.OnPause;
|
|
||||||
import com.android.settingslib.core.lifecycle.events.OnResume;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base class for preference controller that handles VolumeSeekBarPreference
|
* Base class for preference controller that handles VolumeSeekBarPreference
|
||||||
*/
|
*/
|
||||||
public abstract class VolumeSeekBarPreferenceController extends
|
public abstract class VolumeSeekBarPreferenceController extends
|
||||||
AdjustVolumeRestrictedPreferenceController implements LifecycleObserver, OnResume, OnPause {
|
AdjustVolumeRestrictedPreferenceController implements LifecycleObserver {
|
||||||
|
|
||||||
protected VolumeSeekBarPreference mPreference;
|
protected VolumeSeekBarPreference mPreference;
|
||||||
protected VolumeSeekBarPreference.Callback mVolumePreferenceCallback;
|
protected VolumeSeekBarPreference.Callback mVolumePreferenceCallback;
|
||||||
|
protected AudioHelper mHelper;
|
||||||
|
|
||||||
public VolumeSeekBarPreferenceController(Context context, Callback callback,
|
public VolumeSeekBarPreferenceController(Context context, String key) {
|
||||||
Lifecycle lifecycle) {
|
super(context, key);
|
||||||
super(context);
|
setAudioHelper(new AudioHelper(context));
|
||||||
|
}
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
void setAudioHelper(AudioHelper helper) {
|
||||||
|
mHelper = helper;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCallback(Callback callback) {
|
||||||
mVolumePreferenceCallback = callback;
|
mVolumePreferenceCallback = callback;
|
||||||
if (lifecycle != null) {
|
|
||||||
lifecycle.addObserver(this);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -54,20 +60,44 @@ public abstract class VolumeSeekBarPreferenceController extends
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
if (mPreference != null) {
|
if (mPreference != null) {
|
||||||
mPreference.onActivityResume();
|
mPreference.onActivityResume();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@OnLifecycleEvent(Lifecycle.Event.ON_PAUSE)
|
||||||
public void onPause() {
|
public void onPause() {
|
||||||
if (mPreference != null) {
|
if (mPreference != null) {
|
||||||
mPreference.onActivityPause();
|
mPreference.onActivityPause();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getSliderPosition() {
|
||||||
|
if (mPreference != null) {
|
||||||
|
return mPreference.getProgress();
|
||||||
|
}
|
||||||
|
return mHelper.getStreamVolume(getAudioStream());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean setSliderPosition(int position) {
|
||||||
|
if (mPreference != null) {
|
||||||
|
mPreference.setProgress(position);
|
||||||
|
}
|
||||||
|
return mHelper.setStreamVolume(getAudioStream(), position);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMaxSteps() {
|
||||||
|
if (mPreference != null) {
|
||||||
|
return mPreference.getMax();
|
||||||
|
}
|
||||||
|
return mHelper.getMaxVolume(getAudioStream());
|
||||||
|
}
|
||||||
|
|
||||||
protected abstract int getAudioStream();
|
protected abstract int getAudioStream();
|
||||||
|
|
||||||
protected abstract int getMuteIcon();
|
protected abstract int getMuteIcon();
|
||||||
|
@@ -27,13 +27,15 @@ import android.support.v7.preference.Preference;
|
|||||||
import android.support.v7.preference.PreferenceScreen;
|
import android.support.v7.preference.PreferenceScreen;
|
||||||
import android.util.Slog;
|
import android.util.Slog;
|
||||||
|
|
||||||
|
import com.android.settings.core.PreferenceControllerMixin;
|
||||||
|
import com.android.settingslib.core.AbstractPreferenceController;
|
||||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||||
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||||
import com.android.settingslib.core.lifecycle.events.OnPause;
|
import com.android.settingslib.core.lifecycle.events.OnPause;
|
||||||
import com.android.settingslib.core.lifecycle.events.OnResume;
|
import com.android.settingslib.core.lifecycle.events.OnResume;
|
||||||
|
|
||||||
public class ZenModePreferenceController extends AdjustVolumeRestrictedPreferenceController
|
public class ZenModePreferenceController extends AbstractPreferenceController
|
||||||
implements LifecycleObserver, OnResume, OnPause {
|
implements LifecycleObserver, OnResume, OnPause, PreferenceControllerMixin {
|
||||||
|
|
||||||
private final String mKey;
|
private final String mKey;
|
||||||
private SettingObserver mSettingObserver;
|
private SettingObserver mSettingObserver;
|
||||||
|
@@ -43,6 +43,7 @@ import org.robolectric.RuntimeEnvironment;
|
|||||||
@RunWith(SettingsRobolectricTestRunner.class)
|
@RunWith(SettingsRobolectricTestRunner.class)
|
||||||
public class AdjustVolumeRestrictedPreferenceControllerTest {
|
public class AdjustVolumeRestrictedPreferenceControllerTest {
|
||||||
|
|
||||||
|
private static final String KEY = "key";
|
||||||
@Mock
|
@Mock
|
||||||
private AccountRestrictionHelper mAccountHelper;
|
private AccountRestrictionHelper mAccountHelper;
|
||||||
|
|
||||||
@@ -54,7 +55,7 @@ public class AdjustVolumeRestrictedPreferenceControllerTest {
|
|||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
mContext = spy(RuntimeEnvironment.application);
|
mContext = spy(RuntimeEnvironment.application);
|
||||||
mController =
|
mController =
|
||||||
new AdjustVolumeRestrictedPreferenceControllerTestable(mContext, mAccountHelper);
|
new AdjustVolumeRestrictedPreferenceControllerTestable(mContext, mAccountHelper, KEY);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -88,13 +89,18 @@ public class AdjustVolumeRestrictedPreferenceControllerTest {
|
|||||||
extends AdjustVolumeRestrictedPreferenceController {
|
extends AdjustVolumeRestrictedPreferenceController {
|
||||||
|
|
||||||
private AdjustVolumeRestrictedPreferenceControllerTestable(Context context,
|
private AdjustVolumeRestrictedPreferenceControllerTestable(Context context,
|
||||||
AccountRestrictionHelper helper) {
|
AccountRestrictionHelper helper, String key) {
|
||||||
super(context, helper);
|
super(context, helper, key);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getAvailabilityStatus() {
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getPreferenceKey() {
|
public String getPreferenceKey() {
|
||||||
return null;
|
return KEY;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -103,8 +109,18 @@ public class AdjustVolumeRestrictedPreferenceControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isAvailable() {
|
public int getSliderPosition() {
|
||||||
return true;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean setSliderPosition(int position) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMaxSteps() {
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -45,7 +45,8 @@ public class AlarmVolumePreferenceControllerTest {
|
|||||||
public void setUp() {
|
public void setUp() {
|
||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
mContext = RuntimeEnvironment.application;
|
mContext = RuntimeEnvironment.application;
|
||||||
mController = new AlarmVolumePreferenceController(mContext, null, null, mHelper);
|
mController = new AlarmVolumePreferenceController(mContext);
|
||||||
|
mController.setAudioHelper(mHelper);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@@ -35,8 +35,7 @@ public class MediaVolumePreferenceControllerTest {
|
|||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
mController =
|
mController = new MediaVolumePreferenceController(RuntimeEnvironment.application);
|
||||||
new MediaVolumePreferenceController(RuntimeEnvironment.application, null, null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@@ -57,7 +57,8 @@ public class NotificationVolumePreferenceControllerTest {
|
|||||||
when(mContext.getSystemService(Context.TELEPHONY_SERVICE)).thenReturn(mTelephonyManager);
|
when(mContext.getSystemService(Context.TELEPHONY_SERVICE)).thenReturn(mTelephonyManager);
|
||||||
when(mContext.getSystemService(Context.AUDIO_SERVICE)).thenReturn(mAudioManager);
|
when(mContext.getSystemService(Context.AUDIO_SERVICE)).thenReturn(mAudioManager);
|
||||||
when(mContext.getSystemService(Context.VIBRATOR_SERVICE)).thenReturn(mVibrator);
|
when(mContext.getSystemService(Context.VIBRATOR_SERVICE)).thenReturn(mVibrator);
|
||||||
mController = new NotificationVolumePreferenceController(mContext, null, null, mHelper);
|
mController = new NotificationVolumePreferenceController(mContext);
|
||||||
|
mController.setAudioHelper(mHelper);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@@ -65,7 +65,8 @@ public class RingVolumePreferenceControllerTest {
|
|||||||
shadowContext.setSystemService(Context.NOTIFICATION_SERVICE, mNotificationManager);
|
shadowContext.setSystemService(Context.NOTIFICATION_SERVICE, mNotificationManager);
|
||||||
mContext = RuntimeEnvironment.application;
|
mContext = RuntimeEnvironment.application;
|
||||||
when(mNotificationManager.getEffectsSuppressor()).thenReturn(mSuppressor);
|
when(mNotificationManager.getEffectsSuppressor()).thenReturn(mSuppressor);
|
||||||
mController = new RingVolumePreferenceController(mContext, null, null, mHelper);
|
mController = new RingVolumePreferenceController(mContext);
|
||||||
|
mController.setAudioHelper(mHelper);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package com.android.settings.notification;
|
package com.android.settings.notification;
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
import static org.mockito.ArgumentMatchers.nullable;
|
import static org.mockito.ArgumentMatchers.nullable;
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.Matchers.any;
|
||||||
import static org.mockito.Matchers.anyInt;
|
import static org.mockito.Matchers.anyInt;
|
||||||
@@ -46,6 +47,8 @@ public class VolumeSeekBarPreferenceControllerTest {
|
|||||||
private VolumeSeekBarPreference mPreference;
|
private VolumeSeekBarPreference mPreference;
|
||||||
@Mock
|
@Mock
|
||||||
private VolumeSeekBarPreference.Callback mCallback;
|
private VolumeSeekBarPreference.Callback mCallback;
|
||||||
|
@Mock
|
||||||
|
private AudioHelper mHelper;
|
||||||
|
|
||||||
private VolumeSeekBarPreferenceControllerTestable mController;
|
private VolumeSeekBarPreferenceControllerTestable mController;
|
||||||
|
|
||||||
@@ -53,7 +56,10 @@ public class VolumeSeekBarPreferenceControllerTest {
|
|||||||
public void setUp() {
|
public void setUp() {
|
||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
when(mScreen.findPreference(nullable(String.class))).thenReturn(mPreference);
|
when(mScreen.findPreference(nullable(String.class))).thenReturn(mPreference);
|
||||||
mController = new VolumeSeekBarPreferenceControllerTestable(mContext, mCallback);
|
when(mPreference.getKey()).thenReturn("key");
|
||||||
|
mController = new VolumeSeekBarPreferenceControllerTestable(mContext, mCallback,
|
||||||
|
mPreference.getKey());
|
||||||
|
mController.setAudioHelper(mHelper);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -67,7 +73,8 @@ public class VolumeSeekBarPreferenceControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void displayPreference_notAvailable_shouldNotUpdatePreference() {
|
public void displayPreference_notAvailable_shouldNotUpdatePreference() {
|
||||||
mController = new VolumeSeekBarPreferenceControllerTestable(mContext, mCallback, false);
|
mController = new VolumeSeekBarPreferenceControllerTestable(mContext, mCallback, false,
|
||||||
|
mPreference.getKey());
|
||||||
|
|
||||||
mController.displayPreference(mScreen);
|
mController.displayPreference(mScreen);
|
||||||
|
|
||||||
@@ -94,6 +101,42 @@ public class VolumeSeekBarPreferenceControllerTest {
|
|||||||
verify(mPreference).onActivityPause();
|
verify(mPreference).onActivityPause();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void sliderMethods_handleNullPreference() {
|
||||||
|
when(mHelper.getStreamVolume(mController.getAudioStream())).thenReturn(4);
|
||||||
|
when(mHelper.getMaxVolume(mController.getAudioStream())).thenReturn(10);
|
||||||
|
|
||||||
|
assertThat(mController.getMaxSteps()).isEqualTo(10);
|
||||||
|
assertThat(mController.getSliderPosition()).isEqualTo(4);
|
||||||
|
|
||||||
|
mController.setSliderPosition(9);
|
||||||
|
verify(mHelper).setStreamVolume(mController.getAudioStream(), 9);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void setSliderPosition_passesAlongValue() {
|
||||||
|
mController.displayPreference(mScreen);
|
||||||
|
|
||||||
|
mController.setSliderPosition(2);
|
||||||
|
verify(mPreference).setProgress(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getMaxSteps_passesAlongValue() {
|
||||||
|
when(mPreference.getMax()).thenReturn(6);
|
||||||
|
mController.displayPreference(mScreen);
|
||||||
|
|
||||||
|
assertThat(mController.getMaxSteps()).isEqualTo(6);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getSliderPosition_passesAlongValue() {
|
||||||
|
when(mPreference.getProgress()).thenReturn(7);
|
||||||
|
mController.displayPreference(mScreen);
|
||||||
|
|
||||||
|
assertThat(mController.getSliderPosition()).isEqualTo(7);
|
||||||
|
}
|
||||||
|
|
||||||
private class VolumeSeekBarPreferenceControllerTestable
|
private class VolumeSeekBarPreferenceControllerTestable
|
||||||
extends VolumeSeekBarPreferenceController {
|
extends VolumeSeekBarPreferenceController {
|
||||||
|
|
||||||
@@ -103,19 +146,20 @@ public class VolumeSeekBarPreferenceControllerTest {
|
|||||||
private boolean mAvailable;
|
private boolean mAvailable;
|
||||||
|
|
||||||
VolumeSeekBarPreferenceControllerTestable(Context context,
|
VolumeSeekBarPreferenceControllerTestable(Context context,
|
||||||
VolumeSeekBarPreference.Callback callback) {
|
VolumeSeekBarPreference.Callback callback, String key) {
|
||||||
this(context, callback, true);
|
this(context, callback, true, key);
|
||||||
}
|
}
|
||||||
|
|
||||||
VolumeSeekBarPreferenceControllerTestable(Context context,
|
VolumeSeekBarPreferenceControllerTestable(Context context,
|
||||||
VolumeSeekBarPreference.Callback callback, boolean available) {
|
VolumeSeekBarPreference.Callback callback, boolean available, String key) {
|
||||||
super(context, callback, null);
|
super(context, key);
|
||||||
|
setCallback(callback);
|
||||||
mAvailable = available;
|
mAvailable = available;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getPreferenceKey() {
|
public String getPreferenceKey() {
|
||||||
return null;
|
return "key";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -124,8 +168,8 @@ public class VolumeSeekBarPreferenceControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isAvailable() {
|
public int getAvailabilityStatus() {
|
||||||
return mAvailable;
|
return mAvailable ? AVAILABLE : DISABLED_UNSUPPORTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Reference in New Issue
Block a user