Commit 4d5e7b4b authored by xiaohuic's avatar xiaohuic Committed by Commit Bot

Update voice interaction burst animation

BUG=b:35624617
TEST=build and flash locally, saw the new animation

Review-Url: https://codereview.chromium.org/2972923002
Cr-Commit-Position: refs/heads/master@{#487128}
parent 0649c1bc
......@@ -45,6 +45,7 @@
namespace ash {
namespace {
constexpr int kVoiceInteractionAnimationDelayMs = 200;
constexpr int kVoiceInteractionAnimationHideDelayMs = 500;
} // namespace
constexpr uint8_t kVoiceInteractionRunningAlpha = 255; // 100% alpha
......@@ -77,6 +78,8 @@ AppListButton::AppListButton(InkDropButtonListener* listener,
AddChildView(voice_interaction_overlay_);
voice_interaction_overlay_->SetVisible(false);
voice_interaction_animation_delay_timer_.reset(new base::OneShotTimer());
voice_interaction_animation_hide_delay_timer_.reset(
new base::OneShotTimer());
} else {
voice_interaction_overlay_ = nullptr;
}
......@@ -84,8 +87,6 @@ AppListButton::AppListButton(InkDropButtonListener* listener,
AppListButton::~AppListButton() {
Shell::Get()->RemoveShellObserver(this);
if (voice_interaction_animation_delay_timer_)
voice_interaction_animation_delay_timer_->Stop();
}
void AppListButton::OnAppListShown() {
......@@ -135,8 +136,8 @@ void AppListButton::OnGestureEvent(ui::GestureEvent* event) {
FROM_HERE,
base::TimeDelta::FromMilliseconds(
kVoiceInteractionAnimationDelayMs),
base::Bind(&VoiceInteractionOverlay::StartAnimation,
base::Unretained(voice_interaction_overlay_)));
base::Bind(&AppListButton::StartVoiceInteractionAnimation,
base::Unretained(this)));
}
if (!Shell::Get()->IsAppListVisible())
AnimateInkDrop(views::InkDropState::ACTION_PENDING, event);
......@@ -320,6 +321,27 @@ void AppListButton::OnAppListVisibilityChanged(bool shown,
void AppListButton::OnVoiceInteractionStatusChanged(bool running) {
voice_interaction_running_ = running;
SchedulePaint();
// Voice interaction window shows up, we start hiding the animation if it is
// running.
if (running && voice_interaction_overlay_->IsBursting()) {
voice_interaction_animation_hide_delay_timer_->Start(
FROM_HERE,
base::TimeDelta::FromMilliseconds(
kVoiceInteractionAnimationHideDelayMs),
base::Bind(&VoiceInteractionOverlay::HideAnimation,
base::Unretained(voice_interaction_overlay_)));
}
}
void AppListButton::StartVoiceInteractionAnimation() {
// We only show the voice interaction icon and related animation when the
// shelf is at the bottom position and voice interaction is not running.
ShelfAlignment alignment = shelf_->alignment();
bool show_icon = (alignment == SHELF_ALIGNMENT_BOTTOM ||
alignment == SHELF_ALIGNMENT_BOTTOM_LOCKED) &&
!voice_interaction_running_;
voice_interaction_overlay_->StartAnimation(show_icon);
}
} // namespace ash
......@@ -67,6 +67,8 @@ class ASH_EXPORT AppListButton : public views::ImageButton,
aura::Window* root_window) override;
void OnVoiceInteractionStatusChanged(bool running) override;
void StartVoiceInteractionAnimation();
// True if the app list is currently showing for this display.
// This is useful because other IsApplistVisible functions aren't per-display.
bool is_showing_app_list_;
......@@ -80,6 +82,8 @@ class ASH_EXPORT AppListButton : public views::ImageButton,
VoiceInteractionOverlay* voice_interaction_overlay_;
std::unique_ptr<base::OneShotTimer> voice_interaction_animation_delay_timer_;
std::unique_ptr<base::OneShotTimer>
voice_interaction_animation_hide_delay_timer_;
bool voice_interaction_running_ = false;
......
This diff is collapsed.
......@@ -13,23 +13,33 @@
#include "ui/views/animation/ink_drop_painted_layer_delegates.h"
#include "ui/views/view.h"
namespace ui {
class CallbackLayerAnimationObserver;
} // namespace ui
namespace ash {
class AppListButton;
class VoiceInteractionIconBackground;
class ASH_EXPORT VoiceInteractionOverlay : public views::View {
public:
explicit VoiceInteractionOverlay(AppListButton* host_view);
~VoiceInteractionOverlay() override;
void StartAnimation();
void StartAnimation(bool show_icon);
void EndAnimation();
void BurstAnimation();
void HideAnimation();
bool IsBursting() const { return is_bursting_; }
private:
bool AnimationEndedCallback(
const ui::CallbackLayerAnimationObserver& observer);
std::unique_ptr<ui::Layer> ripple_layer_;
std::unique_ptr<ui::Layer> icon_layer_;
std::unique_ptr<ui::Layer> background_layer_;
std::unique_ptr<VoiceInteractionIconBackground> background_layer_;
AppListButton* host_view_;
......@@ -37,6 +47,13 @@ class ASH_EXPORT VoiceInteractionOverlay : public views::View {
// turning back.
bool is_bursting_;
// Whether showing the icon animation or not.
bool show_icon_;
// Whether we should hide the burst animation when the animation ends. This is
// used to synchronize the animation and the underlying window's appearance.
bool should_hide_animation_;
views::CircleLayerDelegate circle_layer_delegate_;
DISALLOW_COPY_AND_ASSIGN(VoiceInteractionOverlay);
......
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