Merge "Fix issue in ring volume sample not always being played." into pi-dev
am: 1b899f2a0a
Change-Id: Ica29d1720bfe48a2002373cd1c85b437ed508451
This commit is contained in:
@@ -25,6 +25,7 @@ import android.os.Message;
|
|||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
import android.preference.SeekBarVolumizer;
|
import android.preference.SeekBarVolumizer;
|
||||||
import android.provider.SearchIndexableResource;
|
import android.provider.SearchIndexableResource;
|
||||||
|
import android.support.annotation.VisibleForTesting;
|
||||||
import android.support.v7.preference.Preference;
|
import android.support.v7.preference.Preference;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
|
||||||
@@ -50,8 +51,22 @@ public class SoundSettings extends DashboardFragment {
|
|||||||
|
|
||||||
private static final int SAMPLE_CUTOFF = 2000; // manually cap sample playback at 2 seconds
|
private static final int SAMPLE_CUTOFF = 2000; // manually cap sample playback at 2 seconds
|
||||||
|
|
||||||
private final VolumePreferenceCallback mVolumeCallback = new VolumePreferenceCallback();
|
@VisibleForTesting
|
||||||
private final H mHandler = new H();
|
static final int STOP_SAMPLE = 1;
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
final VolumePreferenceCallback mVolumeCallback = new VolumePreferenceCallback();
|
||||||
|
@VisibleForTesting
|
||||||
|
final Handler mHandler = new Handler(Looper.getMainLooper()) {
|
||||||
|
@Override
|
||||||
|
public void handleMessage(Message msg) {
|
||||||
|
switch (msg.what) {
|
||||||
|
case STOP_SAMPLE:
|
||||||
|
mVolumeCallback.stopSample();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
private RingtonePreference mRequestPreference;
|
private RingtonePreference mRequestPreference;
|
||||||
|
|
||||||
@@ -140,14 +155,17 @@ public class SoundSettings extends DashboardFragment {
|
|||||||
}
|
}
|
||||||
mCurrent = sbv;
|
mCurrent = sbv;
|
||||||
if (mCurrent != null) {
|
if (mCurrent != null) {
|
||||||
mHandler.removeMessages(H.STOP_SAMPLE);
|
mHandler.removeMessages(STOP_SAMPLE);
|
||||||
mHandler.sendEmptyMessageDelayed(H.STOP_SAMPLE, SAMPLE_CUTOFF);
|
mHandler.sendEmptyMessageDelayed(STOP_SAMPLE, SAMPLE_CUTOFF);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStreamValueChanged(int stream, int progress) {
|
public void onStreamValueChanged(int stream, int progress) {
|
||||||
// noop
|
if (mCurrent != null) {
|
||||||
|
mHandler.removeMessages(STOP_SAMPLE);
|
||||||
|
mHandler.sendEmptyMessageDelayed(STOP_SAMPLE, SAMPLE_CUTOFF);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stopSample() {
|
public void stopSample() {
|
||||||
@@ -157,26 +175,6 @@ public class SoundSettings extends DashboardFragment {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// === Callbacks ===
|
|
||||||
|
|
||||||
|
|
||||||
private final class H extends Handler {
|
|
||||||
private static final int STOP_SAMPLE = 1;
|
|
||||||
|
|
||||||
private H() {
|
|
||||||
super(Looper.getMainLooper());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void handleMessage(Message msg) {
|
|
||||||
switch (msg.what) {
|
|
||||||
case STOP_SAMPLE:
|
|
||||||
mVolumeCallback.stopSample();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static List<AbstractPreferenceController> buildPreferenceControllers(Context context,
|
private static List<AbstractPreferenceController> buildPreferenceControllers(Context context,
|
||||||
SoundSettings fragment, VolumeSeekBarPreference.Callback callback,
|
SoundSettings fragment, VolumeSeekBarPreference.Callback callback,
|
||||||
Lifecycle lifecycle) {
|
Lifecycle lifecycle) {
|
||||||
|
@@ -148,7 +148,6 @@ public class VolumeSeekBarPreference extends SeekBarPreference {
|
|||||||
mVolumizer.start();
|
mVolumizer.start();
|
||||||
mVolumizer.setSeekBar(mSeekBar);
|
mVolumizer.setSeekBar(mSeekBar);
|
||||||
updateIconView();
|
updateIconView();
|
||||||
mCallback.onStreamValueChanged(mStream, mSeekBar.getProgress());
|
|
||||||
updateSuppressionText();
|
updateSuppressionText();
|
||||||
if (!isEnabled()) {
|
if (!isEnabled()) {
|
||||||
mSeekBar.setEnabled(false);
|
mSeekBar.setEnabled(false);
|
||||||
@@ -156,15 +155,6 @@ public class VolumeSeekBarPreference extends SeekBarPreference {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// during initialization, this preference is the SeekBar listener
|
|
||||||
@Override
|
|
||||||
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromTouch) {
|
|
||||||
super.onProgressChanged(seekBar, progress, fromTouch);
|
|
||||||
if (mCallback != null) {
|
|
||||||
mCallback.onStreamValueChanged(mStream, progress);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateIconView() {
|
private void updateIconView() {
|
||||||
if (mIconView == null) return;
|
if (mIconView == null) return;
|
||||||
if (mIconResId != 0) {
|
if (mIconResId != 0) {
|
||||||
|
@@ -233,8 +233,7 @@ public class SeekBarPreference extends RestrictedPreference
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onProgressChanged(
|
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
|
||||||
SeekBar seekBar, int progress, boolean fromUser) {
|
|
||||||
if (fromUser && (mContinuousUpdates || !mTrackingTouch)) {
|
if (fromUser && (mContinuousUpdates || !mTrackingTouch)) {
|
||||||
syncProgress(seekBar);
|
syncProgress(seekBar);
|
||||||
}
|
}
|
||||||
|
@@ -24,8 +24,10 @@ import static org.mockito.Mockito.when;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.media.AudioManager;
|
import android.media.AudioManager;
|
||||||
|
import android.os.Handler;
|
||||||
import android.os.UserManager;
|
import android.os.UserManager;
|
||||||
|
|
||||||
|
import android.preference.SeekBarVolumizer;
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||||
import com.android.settings.testutils.XmlTestUtils;
|
import com.android.settings.testutils.XmlTestUtils;
|
||||||
@@ -36,6 +38,7 @@ import org.junit.Test;
|
|||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.robolectric.RuntimeEnvironment;
|
import org.robolectric.RuntimeEnvironment;
|
||||||
import org.robolectric.annotation.Config;
|
import org.robolectric.annotation.Config;
|
||||||
|
import org.robolectric.util.ReflectionHelpers;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -44,7 +47,7 @@ public class SoundSettingsTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Config(shadows = {ShadowUserManager.class, ShadowAudioHelper.class})
|
@Config(shadows = {ShadowUserManager.class, ShadowAudioHelper.class})
|
||||||
public void testNonIndexableKeys_existInXmlLayout() {
|
public void getNonIndexableKeys_existInXmlLayout() {
|
||||||
final Context context = spy(RuntimeEnvironment.application);
|
final Context context = spy(RuntimeEnvironment.application);
|
||||||
AudioManager audioManager = mock(AudioManager.class);
|
AudioManager audioManager = mock(AudioManager.class);
|
||||||
doReturn(audioManager).when(context).getSystemService(Context.AUDIO_SERVICE);
|
doReturn(audioManager).when(context).getSystemService(Context.AUDIO_SERVICE);
|
||||||
@@ -66,4 +69,16 @@ public class SoundSettingsTest {
|
|||||||
|
|
||||||
assertThat(keys).containsAllIn(niks);
|
assertThat(keys).containsAllIn(niks);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void onStreamValueChanged_shouldRepostStopSampleMessage() {
|
||||||
|
final SoundSettings settings = new SoundSettings();
|
||||||
|
final Handler handler = settings.mHandler;
|
||||||
|
ReflectionHelpers.setField(
|
||||||
|
settings.mVolumeCallback, "mCurrent", mock(SeekBarVolumizer.class));
|
||||||
|
|
||||||
|
settings.mVolumeCallback.onStreamValueChanged(0, 5);
|
||||||
|
|
||||||
|
assertThat(settings.mHandler.hasMessages(SoundSettings.STOP_SAMPLE)).isTrue();
|
||||||
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user