Merge "Settings: Respect preference's visibility in VideoPreferenceController" am: 0e40f46fe2
am: 447674e100
am: 4cbb60c344
Change-Id: I2c4a9774c2ae463ed80810dc95a298e1302f4b5f
This commit is contained in:
@@ -80,6 +80,7 @@ public class VideoPreference extends Preference {
|
|||||||
try {
|
try {
|
||||||
// if these are already set that means they were set dynamically and don't need
|
// if these are already set that means they were set dynamically and don't need
|
||||||
// to be loaded from xml
|
// to be loaded from xml
|
||||||
|
mAnimationAvailable = false;
|
||||||
mAnimationId = mAnimationId == 0
|
mAnimationId = mAnimationId == 0
|
||||||
? attributes.getResourceId(R.styleable.VideoPreference_animation, 0)
|
? attributes.getResourceId(R.styleable.VideoPreference_animation, 0)
|
||||||
: mAnimationId;
|
: mAnimationId;
|
||||||
@@ -91,6 +92,7 @@ public class VideoPreference extends Preference {
|
|||||||
? attributes.getResourceId(R.styleable.VideoPreference_preview, 0)
|
? attributes.getResourceId(R.styleable.VideoPreference_preview, 0)
|
||||||
: mPreviewResource;
|
: mPreviewResource;
|
||||||
if (mPreviewResource == 0 && mAnimationId == 0) {
|
if (mPreviewResource == 0 && mAnimationId == 0) {
|
||||||
|
setVisible(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
initMediaPlayer();
|
initMediaPlayer();
|
||||||
@@ -250,6 +252,10 @@ public class VideoPreference extends Preference {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isAnimationAvailable() {
|
||||||
|
return mAnimationAvailable;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isVideoPaused() {
|
public boolean isVideoPaused() {
|
||||||
return mVideoPaused;
|
return mVideoPaused;
|
||||||
}
|
}
|
||||||
|
@@ -37,13 +37,14 @@ public class VideoPreferenceController extends BasePreferenceController implemen
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getAvailabilityStatus() {
|
public int getAvailabilityStatus() {
|
||||||
return AVAILABLE_UNSEARCHABLE;
|
return mVideoPreference.isAnimationAvailable() ?
|
||||||
|
AVAILABLE_UNSEARCHABLE : UNSUPPORTED_ON_DEVICE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void displayPreference(PreferenceScreen screen) {
|
public void displayPreference(PreferenceScreen screen) {
|
||||||
super.displayPreference(screen);
|
|
||||||
mVideoPreference = screen.findPreference(getPreferenceKey());
|
mVideoPreference = screen.findPreference(getPreferenceKey());
|
||||||
|
super.displayPreference(screen);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -17,10 +17,13 @@
|
|||||||
package com.android.settings.widget;
|
package com.android.settings.widget;
|
||||||
|
|
||||||
import static com.android.settings.core.BasePreferenceController.AVAILABLE_UNSEARCHABLE;
|
import static com.android.settings.core.BasePreferenceController.AVAILABLE_UNSEARCHABLE;
|
||||||
|
import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import static org.mockito.Mockito.anyBoolean;
|
import static org.mockito.Mockito.anyBoolean;
|
||||||
|
import static org.mockito.Mockito.doReturn;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
@@ -33,6 +36,7 @@ import org.mockito.Mock;
|
|||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.MockitoAnnotations;
|
||||||
import org.robolectric.RobolectricTestRunner;
|
import org.robolectric.RobolectricTestRunner;
|
||||||
import org.robolectric.RuntimeEnvironment;
|
import org.robolectric.RuntimeEnvironment;
|
||||||
|
import org.robolectric.util.ReflectionHelpers;
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
@RunWith(RobolectricTestRunner.class)
|
||||||
public class VideoPreferenceControllerTest {
|
public class VideoPreferenceControllerTest {
|
||||||
@@ -52,10 +56,27 @@ public class VideoPreferenceControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getAvailabilityStatus_isAlwaysAvailable() {
|
public void getAvailabilityStatus_isAvailableUnsearchable() {
|
||||||
|
final VideoPreference videoPreference = mock(VideoPreference.class);
|
||||||
|
|
||||||
|
// Assign mock object to mVideoPreference in controller
|
||||||
|
ReflectionHelpers.setField(mController, "mVideoPreference", videoPreference);
|
||||||
|
doReturn(true).when(videoPreference).isAnimationAvailable();
|
||||||
|
|
||||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE_UNSEARCHABLE);
|
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE_UNSEARCHABLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getAvailabilityStatus_isUnsupportedOnDevice() {
|
||||||
|
final VideoPreference videoPreference = mock(VideoPreference.class);
|
||||||
|
|
||||||
|
// Assign mock object to mVideoPreference in controller
|
||||||
|
ReflectionHelpers.setField(mController, "mVideoPreference", videoPreference);
|
||||||
|
doReturn(false).when(videoPreference).isAnimationAvailable();
|
||||||
|
|
||||||
|
assertThat(mController.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onPause_shouldCallOnViewInvisibleOnPrefernece() {
|
public void onPause_shouldCallOnViewInvisibleOnPrefernece() {
|
||||||
mController.displayPreference(mScreen);
|
mController.displayPreference(mScreen);
|
||||||
|
Reference in New Issue
Block a user