From 507218b5771478a60b9bef88a709319249c981ec Mon Sep 17 00:00:00 2001 From: hughchen Date: Thu, 27 Feb 2020 14:16:11 +0800 Subject: [PATCH] Add setBackgroundColor() in VideoPreference - Add setBackgroundColor() to allow changed background color of VideoPreference. - Add test case. Bug: 149974597 Test: make -j42 RunSettingsRoboTests Change-Id: I14f849d54657dc0ccbd599c393de6f430e9352d4 --- .../settings/widget/VideoPreference.java | 18 ++++++++++++++++++ .../settings/widget/VideoPreferenceTest.java | 12 ++++++++++++ 2 files changed, 30 insertions(+) diff --git a/src/com/android/settings/widget/VideoPreference.java b/src/com/android/settings/widget/VideoPreference.java index 949ba9b8f1b..6356378e444 100644 --- a/src/com/android/settings/widget/VideoPreference.java +++ b/src/com/android/settings/widget/VideoPreference.java @@ -39,12 +39,18 @@ import com.android.settings.R; public class VideoPreference extends Preference { private static final String TAG = "VideoPreference"; + private static final int DEFAULT_BACKGROUND_RESOURCE_ID = -1; private final Context mContext; @VisibleForTesting AnimationController mAnimationController; @VisibleForTesting boolean mAnimationAvailable; + @VisibleForTesting + LinearLayout mAnimationView; + @VisibleForTesting + int mBackgroundResId = DEFAULT_BACKGROUND_RESOURCE_ID; + private float mAspectRatio = 1.0f; private int mPreviewId; private int mAnimationId; @@ -114,6 +120,7 @@ public class VideoPreference extends Preference { mVideo = (TextureView) holder.findViewById(R.id.video_texture_view); mPreviewImage = (ImageView) holder.findViewById(R.id.video_preview_image); mPlayButton = (ImageView) holder.findViewById(R.id.video_play_button); + mAnimationView = (LinearLayout) holder.itemView; final AspectRatioFrameLayout layout = (AspectRatioFrameLayout) holder.findViewById( R.id.video_container); @@ -123,6 +130,9 @@ public class VideoPreference extends Preference { layout.setLayoutParams(new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, mHeight)); } + if (mBackgroundResId != DEFAULT_BACKGROUND_RESOURCE_ID) { + mAnimationView.setBackgroundResource(mBackgroundResId); + } if (mAnimationController != null) { mAnimationController.attachView(mVideo, mPreviewImage, mPlayButton); } @@ -202,6 +212,14 @@ public class VideoPreference extends Preference { / (float) mAnimationController.getVideoHeight(); } + /** + * Set the background color of the video preference + * @param resId resource id of color + */ + public void setBackgroundColor(int resId) { + mBackgroundResId = resId; + } + /** * Handle animation operations. */ diff --git a/tests/robotests/src/com/android/settings/widget/VideoPreferenceTest.java b/tests/robotests/src/com/android/settings/widget/VideoPreferenceTest.java index 3439ca40377..720ad20fd57 100644 --- a/tests/robotests/src/com/android/settings/widget/VideoPreferenceTest.java +++ b/tests/robotests/src/com/android/settings/widget/VideoPreferenceTest.java @@ -32,6 +32,7 @@ import android.view.LayoutInflater; import android.view.TextureView; import android.view.View; import android.widget.ImageView; +import android.widget.LinearLayout; import androidx.preference.PreferenceFragmentCompat; import androidx.preference.PreferenceViewHolder; @@ -60,6 +61,9 @@ public class VideoPreferenceTest { private ImageView fakePreview; @Mock private ImageView fakePlayButton; + @Mock + private LinearLayout mAnimationView; + private Context mContext; private VideoPreference mVideoPreference; private PreferenceViewHolder mPreferenceViewHolder; @@ -73,6 +77,7 @@ public class VideoPreferenceTest { new MediaAnimationController(mContext, R.raw.accessibility_screen_magnification)); mVideoPreference = new VideoPreference(mContext, null /* attrs */); mVideoPreference.mAnimationController = mAnimationController; + mVideoPreference.mAnimationView = mAnimationView; when(mAnimationController.getVideoWidth()).thenReturn(VIDEO_WIDTH); when(mAnimationController.getVideoHeight()).thenReturn(VIDEO_HEIGHT); @@ -157,6 +162,13 @@ public class VideoPreferenceTest { assertThat(vp2.mAnimationController instanceof VectorAnimationController).isTrue(); } + @Test + public void setBackgroundColor_shouldBeCalled() { + mVideoPreference.setBackgroundColor(1111); + + assertThat(mVideoPreference.mBackgroundResId).isEqualTo(1111); + } + public static class TestFragment extends PreferenceFragmentCompat { @Override public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {