Commit 375b89e8 authored by wutao's avatar wutao Committed by Commit Bot

ambient: Move media string view to avoid screen burn

The music note icon is static. To avoid screen burn, we move the media
string view similar to the attribution.
1. Move `MediaStringView` to `AmbientBackgroundImageView` so that we can
   reuse the same logic to move attribution.
2. Move media string view in small steps on each refresh with in a fixed
   bounds.

Bug: b/168568042
Test: manual
Change-Id: Ieff99fbabb559139cb99cb2db808b65234af04d0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2437736
Commit-Queue: Tao Wu <wutao@chromium.org>
Reviewed-by: default avatarXiaohui Chen <xiaohuic@chromium.org>
Cr-Commit-Position: refs/heads/master@{#813104}
parent 4ecf4d41
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "ash/ambient/ambient_constants.h" #include "ash/ambient/ambient_constants.h"
#include "ash/ambient/ui/glanceable_info_view.h" #include "ash/ambient/ui/glanceable_info_view.h"
#include "ash/ambient/ui/media_string_view.h"
#include "ash/ambient/util/ambient_util.h" #include "ash/ambient/util/ambient_util.h"
#include "ash/assistant/ui/assistant_view_ids.h" #include "ash/assistant/ui/assistant_view_ids.h"
#include "base/rand_util.h" #include "base/rand_util.h"
...@@ -30,6 +31,7 @@ namespace { ...@@ -30,6 +31,7 @@ namespace {
// Appearance. // Appearance.
constexpr int kMarginDip = 16; constexpr int kMarginDip = 16;
constexpr int kSpacingDip = 8; constexpr int kSpacingDip = 8;
constexpr int kMediaStringMarginDip = 32;
// Typography. // Typography.
constexpr SkColor kTextColor = SK_ColorWHITE; constexpr SkColor kTextColor = SK_ColorWHITE;
...@@ -228,6 +230,25 @@ void AmbientBackgroundImageView::InitLayout() { ...@@ -228,6 +230,25 @@ void AmbientBackgroundImageView::InitLayout() {
details_label_->SetShadows(ambient::util::GetTextShadowValues()); details_label_->SetShadows(ambient::util::GetTextShadowValues());
details_label_->SetPaintToLayer(); details_label_->SetPaintToLayer();
details_label_->layer()->SetFillsBoundsOpaquely(false); details_label_->layer()->SetFillsBoundsOpaquely(false);
// Inits the media string view. The media string view is positioned on the
// right-top corner of the container.
views::View* media_string_view_container_ =
AddChildView(std::make_unique<views::View>());
views::BoxLayout* media_string_layout =
media_string_view_container_->SetLayoutManager(
std::make_unique<views::BoxLayout>(
views::BoxLayout::Orientation::kVertical));
media_string_layout->set_main_axis_alignment(
views::BoxLayout::MainAxisAlignment::kStart);
media_string_layout->set_cross_axis_alignment(
views::BoxLayout::CrossAxisAlignment::kEnd);
media_string_layout->set_inside_border_insets(
gfx::Insets(kMediaStringMarginDip + shadow_insets.top(), 0, 0,
kMediaStringMarginDip + shadow_insets.right()));
media_string_view_ = media_string_view_container_->AddChildView(
std::make_unique<MediaStringView>());
media_string_view_->SetVisible(false);
} }
void AmbientBackgroundImageView::UpdateGlanceableInfoPosition() { void AmbientBackgroundImageView::UpdateGlanceableInfoPosition() {
...@@ -262,6 +283,13 @@ void AmbientBackgroundImageView::UpdateGlanceableInfoPosition() { ...@@ -262,6 +283,13 @@ void AmbientBackgroundImageView::UpdateGlanceableInfoPosition() {
transform.Translate(current_x_translation, current_y_translation); transform.Translate(current_x_translation, current_y_translation);
glanceable_info_view_->layer()->SetTransform(transform); glanceable_info_view_->layer()->SetTransform(transform);
details_label_->layer()->SetTransform(transform); details_label_->layer()->SetTransform(transform);
if (media_string_view_->GetVisible()) {
gfx::Transform media_string_transform;
media_string_transform.Translate(-current_x_translation,
-current_y_translation);
media_string_view_->layer()->SetTransform(media_string_transform);
}
} }
bool AmbientBackgroundImageView::UpdateRelatedImageViewVisibility() { bool AmbientBackgroundImageView::UpdateRelatedImageViewVisibility() {
......
...@@ -22,6 +22,7 @@ class Label; ...@@ -22,6 +22,7 @@ class Label;
namespace ash { namespace ash {
class GlanceableInfoView; class GlanceableInfoView;
class MediaStringView;
// AmbientBackgroundImageView-------------------------------------------------- // AmbientBackgroundImageView--------------------------------------------------
// A custom ImageView to display photo image and details information on ambient. // A custom ImageView to display photo image and details information on ambient.
...@@ -90,6 +91,8 @@ class ASH_EXPORT AmbientBackgroundImageView : public views::View, ...@@ -90,6 +91,8 @@ class ASH_EXPORT AmbientBackgroundImageView : public views::View,
// current image. Owned by the view hierarchy. // current image. Owned by the view hierarchy.
views::Label* details_label_ = nullptr; views::Label* details_label_ = nullptr;
MediaStringView* media_string_view_ = nullptr;
ScopedObserver<views::View, views::ViewObserver> observed_views_{this}; ScopedObserver<views::View, views::ViewObserver> observed_views_{this};
}; };
} // namespace ash } // namespace ash
......
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
#include "ash/ambient/ui/ambient_assistant_container_view.h" #include "ash/ambient/ui/ambient_assistant_container_view.h"
#include "ash/ambient/ui/ambient_view_delegate.h" #include "ash/ambient/ui/ambient_view_delegate.h"
#include "ash/ambient/ui/media_string_view.h"
#include "ash/ambient/ui/photo_view.h" #include "ash/ambient/ui/photo_view.h"
#include "ash/ambient/util/ambient_util.h" #include "ash/ambient/util/ambient_util.h"
#include "ash/assistant/ui/assistant_view_ids.h" #include "ash/assistant/ui/assistant_view_ids.h"
...@@ -38,7 +37,6 @@ using chromeos::assistant::features::IsAmbientAssistantEnabled; ...@@ -38,7 +37,6 @@ using chromeos::assistant::features::IsAmbientAssistantEnabled;
// Appearance. // Appearance.
constexpr int kAssistantPreferredHeightDip = 128; constexpr int kAssistantPreferredHeightDip = 128;
constexpr int kMediaStringMarginDip = 32;
// A tolerance threshold used to ignore spurious mouse move. // A tolerance threshold used to ignore spurious mouse move.
constexpr int kMouseMoveErrorTolerancePx = 3; constexpr int kMouseMoveErrorTolerancePx = 3;
...@@ -135,7 +133,7 @@ gfx::Size AmbientContainerView::CalculatePreferredSize() const { ...@@ -135,7 +133,7 @@ gfx::Size AmbientContainerView::CalculatePreferredSize() const {
void AmbientContainerView::Layout() { void AmbientContainerView::Layout() {
// Layout child views first to have proper bounds set for children. // Layout child views first to have proper bounds set for children.
LayoutPhotoView(); LayoutPhotoView();
LayoutMediaStringView();
// The assistant view may not exist if |kAmbientAssistant| feature is // The assistant view may not exist if |kAmbientAssistant| feature is
// disabled. // disabled.
if (ambient_assistant_container_view_) if (ambient_assistant_container_view_)
...@@ -156,9 +154,6 @@ void AmbientContainerView::Init() { ...@@ -156,9 +154,6 @@ void AmbientContainerView::Init() {
photo_view_ = AddChildView(std::make_unique<PhotoView>(delegate_)); photo_view_ = AddChildView(std::make_unique<PhotoView>(delegate_));
media_string_view_ = AddChildView(std::make_unique<MediaStringView>());
media_string_view_->SetVisible(false);
if (IsAmbientAssistantEnabled()) { if (IsAmbientAssistantEnabled()) {
ambient_assistant_container_view_ = ambient_assistant_container_view_ =
AddChildView(std::make_unique<AmbientAssistantContainerView>()); AddChildView(std::make_unique<AmbientAssistantContainerView>());
...@@ -178,19 +173,6 @@ void AmbientContainerView::LayoutAssistantView() { ...@@ -178,19 +173,6 @@ void AmbientContainerView::LayoutAssistantView() {
gfx::Rect(0, 0, preferred_width, preferred_height)); gfx::Rect(0, 0, preferred_width, preferred_height));
} }
void AmbientContainerView::LayoutMediaStringView() {
const gfx::Size container_size = GetLocalBounds().size();
const gfx::Size preferred_size = media_string_view_->GetPreferredSize();
// The media string view is positioned on the right-top corner of the
// container.
int x =
container_size.width() - kMediaStringMarginDip - preferred_size.width();
int y = kMediaStringMarginDip;
media_string_view_->SetBoundsRect(
gfx::Rect(x, y, preferred_size.width(), preferred_size.height()));
}
void AmbientContainerView::HandleEvent() { void AmbientContainerView::HandleEvent() {
delegate_->OnBackgroundPhotoEvents(); delegate_->OnBackgroundPhotoEvents();
} }
......
...@@ -16,7 +16,6 @@ namespace ash { ...@@ -16,7 +16,6 @@ namespace ash {
class AmbientAssistantContainerView; class AmbientAssistantContainerView;
class AmbientViewDelegate; class AmbientViewDelegate;
class PhotoView; class PhotoView;
class MediaStringView;
// Container view to display all Ambient Mode related views, i.e. photo frame, // Container view to display all Ambient Mode related views, i.e. photo frame,
// weather info. // weather info.
...@@ -42,7 +41,6 @@ class ASH_EXPORT AmbientContainerView : public views::View { ...@@ -42,7 +41,6 @@ class ASH_EXPORT AmbientContainerView : public views::View {
// Layout(). See b/163170162. // Layout(). See b/163170162.
void LayoutPhotoView(); void LayoutPhotoView();
void LayoutAssistantView(); void LayoutAssistantView();
void LayoutMediaStringView();
// Invoked on specific types of events. // Invoked on specific types of events.
void HandleEvent(); void HandleEvent();
...@@ -52,7 +50,6 @@ class ASH_EXPORT AmbientContainerView : public views::View { ...@@ -52,7 +50,6 @@ class ASH_EXPORT AmbientContainerView : public views::View {
// Owned by view hierarchy. // Owned by view hierarchy.
PhotoView* photo_view_ = nullptr; PhotoView* photo_view_ = nullptr;
AmbientAssistantContainerView* ambient_assistant_container_view_ = nullptr; AmbientAssistantContainerView* ambient_assistant_container_view_ = nullptr;
MediaStringView* media_string_view_ = nullptr;
// Observes events from its host widget. // Observes events from its host widget.
std::unique_ptr<HostWidgetEventObserver> event_observer_; std::unique_ptr<HostWidgetEventObserver> event_observer_;
......
...@@ -28,6 +28,11 @@ class MediaStringViewTest : public AmbientAshTestBase { ...@@ -28,6 +28,11 @@ class MediaStringViewTest : public AmbientAshTestBase {
GetSessionControllerClient()->set_show_lock_screen_views(true); GetSessionControllerClient()->set_show_lock_screen_views(true);
} }
void TearDown() override {
CloseAmbientScreen();
AmbientAshTestBase::TearDown();
}
const base::string16& GetText() { const base::string16& GetText() {
return GetMediaStringViewTextLabel()->GetText(); return GetMediaStringViewTextLabel()->GetText();
} }
...@@ -260,6 +265,8 @@ TEST_F(MediaStringViewTest, HasNoMaskLayerWithShortText) { ...@@ -260,6 +265,8 @@ TEST_F(MediaStringViewTest, HasNoMaskLayerWithShortText) {
metadata.title = base::ASCIIToUTF16("title"); metadata.title = base::ASCIIToUTF16("title");
metadata.artist = base::ASCIIToUTF16("artist"); metadata.artist = base::ASCIIToUTF16("artist");
SimulateMediaPlaybackStateChanged(
media_session::mojom::MediaPlaybackState::kPlaying);
SimulateMediaMetadataChanged(metadata); SimulateMediaMetadataChanged(metadata);
// Force re-layout. // Force re-layout.
container_view()->Layout(); container_view()->Layout();
...@@ -277,6 +284,8 @@ TEST_F(MediaStringViewTest, HasMaskLayerWithLongText) { ...@@ -277,6 +284,8 @@ TEST_F(MediaStringViewTest, HasMaskLayerWithLongText) {
metadata.title = base::ASCIIToUTF16("A super duper long title"); metadata.title = base::ASCIIToUTF16("A super duper long title");
metadata.artist = base::ASCIIToUTF16("A super duper long artist name"); metadata.artist = base::ASCIIToUTF16("A super duper long artist name");
SimulateMediaPlaybackStateChanged(
media_session::mojom::MediaPlaybackState::kPlaying);
SimulateMediaMetadataChanged(metadata); SimulateMediaMetadataChanged(metadata);
// Force re-layout. // Force re-layout.
container_view()->Layout(); container_view()->Layout();
...@@ -294,6 +303,8 @@ TEST_F(MediaStringViewTest, MaskLayerShouldUpdate) { ...@@ -294,6 +303,8 @@ TEST_F(MediaStringViewTest, MaskLayerShouldUpdate) {
metadata.title = base::ASCIIToUTF16("title"); metadata.title = base::ASCIIToUTF16("title");
metadata.artist = base::ASCIIToUTF16("artist"); metadata.artist = base::ASCIIToUTF16("artist");
SimulateMediaPlaybackStateChanged(
media_session::mojom::MediaPlaybackState::kPlaying);
SimulateMediaMetadataChanged(metadata); SimulateMediaMetadataChanged(metadata);
// Force re-layout. // Force re-layout.
container_view()->Layout(); container_view()->Layout();
...@@ -357,7 +368,6 @@ TEST_F(MediaStringViewTest, DoNotShowOnLockScreenIfPrefIsDisabled) { ...@@ -357,7 +368,6 @@ TEST_F(MediaStringViewTest, DoNotShowOnLockScreenIfPrefIsDisabled) {
PrefService* pref = PrefService* pref =
Shell::Get()->session_controller()->GetPrimaryUserPrefService(); Shell::Get()->session_controller()->GetPrimaryUserPrefService();
pref->SetBoolean(prefs::kLockScreenMediaControlsEnabled, false); pref->SetBoolean(prefs::kLockScreenMediaControlsEnabled, false);
// Simulates Ambient Mode shown on lock-screen. // Simulates Ambient Mode shown on lock-screen.
LockScreen(); LockScreen();
FastForwardToInactivity(); FastForwardToInactivity();
...@@ -370,4 +380,28 @@ TEST_F(MediaStringViewTest, DoNotShowOnLockScreenIfPrefIsDisabled) { ...@@ -370,4 +380,28 @@ TEST_F(MediaStringViewTest, DoNotShowOnLockScreenIfPrefIsDisabled) {
EXPECT_FALSE(GetMediaStringView()->GetVisible()); EXPECT_FALSE(GetMediaStringView()->GetVisible());
} }
TEST_F(MediaStringViewTest, ShouldHasDifferentTransform) {
ShowAmbientScreen();
// Sets metadata for current session.
media_session::MediaMetadata metadata;
metadata.title = base::ASCIIToUTF16("title");
metadata.artist = base::ASCIIToUTF16("artist");
SimulateMediaPlaybackStateChanged(
media_session::mojom::MediaPlaybackState::kPlaying);
SimulateMediaMetadataChanged(metadata);
EXPECT_TRUE(GetMediaStringView()->GetVisible());
// It is theoretically that the transforms could be the same in two
// consecutive updates, therefore we test with two updates.
gfx::Transform transform1 =
GetMediaStringView()->layer()->GetTargetTransform();
FastForwardToNextImage();
FastForwardToNextImage();
gfx::Transform transform2 =
GetMediaStringView()->layer()->GetTargetTransform();
EXPECT_NE(transform1, transform2);
}
} // namespace ash } // namespace ash
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment