Commit 33fc6c64 authored by Xiaohui Chen's avatar Xiaohui Chen Committed by Commit Bot

Move assistant icon animation to CompositorAnimationOberver

BUG=None
TEST=locally build and see animation running as before.

Change-Id: I1eb62490108beaaec0795adb4251054c03b364e1
Reviewed-on: https://chromium-review.googlesource.com/748273
Commit-Queue: Xiaohui Chen <xiaohuic@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#513211}
parent b1adde25
......@@ -114,7 +114,8 @@ constexpr int kMoleculeOrder[] = {0, 2, 3, 1};
} // namespace
class VoiceInteractionIcon : public ui::Layer {
class VoiceInteractionIcon : public ui::Layer,
public ui::CompositorAnimationObserver {
public:
VoiceInteractionIcon() : Layer(ui::LAYER_NOT_DRAWN) {
set_name("VoiceInteractionOverlay:ICON_LAYER");
......@@ -126,14 +127,32 @@ class VoiceInteractionIcon : public ui::Layer {
}
void StartAnimation() {
animation_timer_.Start(FROM_HERE,
base::TimeDelta::FromMilliseconds(
base::TimeTicks::kMillisecondsPerSecond /
gfx::LinearAnimation::kDefaultFrameRate),
this, &VoiceInteractionIcon::AnimationProgressed);
if (!GetCompositor()->HasAnimationObserver(this))
GetCompositor()->AddAnimationObserver(this);
}
void StopAnimation() { animation_timer_.Stop(); }
void StopAnimation() {
if (GetCompositor()->HasAnimationObserver(this))
GetCompositor()->RemoveAnimationObserver(this);
}
// ui::CompositorAnimationObserver
void OnCompositingShuttingDown(ui::Compositor* compositor) override {}
void OnAnimationStep(base::TimeTicks timestamp) override {
uint64_t elapsed = (timestamp - base::TimeTicks()).InMilliseconds();
for (int i = 0; i < DOT_COUNT; ++i) {
float normalizedTime =
((elapsed - kMoleculeAnimationOffset * kMoleculeOrder[i]) %
kMoleculeAnimationDurationMs) /
static_cast<float>(kMoleculeAnimationDurationMs);
gfx::Transform transform;
transform.Translate(0,
kMoleculeAmplitude * sin(normalizedTime * 2 * M_PI));
dot_layers_[i]->SetTransform(transform);
}
}
private:
enum Dot {
......@@ -162,25 +181,6 @@ class VoiceInteractionIcon : public ui::Layer {
return "UNKNOWN";
}
void AnimationProgressed() {
gfx::Transform transform;
uint64_t now =
(base::TimeTicks::Now() - base::TimeTicks()).InMilliseconds();
for (int i = 0; i < DOT_COUNT; ++i) {
float normalizedTime =
((now - kMoleculeAnimationOffset * kMoleculeOrder[i]) %
kMoleculeAnimationDurationMs) /
static_cast<float>(kMoleculeAnimationDurationMs);
transform.MakeIdentity();
transform.Translate(0,
kMoleculeAmplitude * sin(normalizedTime * 2 * M_PI));
dot_layers_[i]->SetTransform(transform);
}
}
/**
* Convenience method to place dots to Molecule shape used by Molecule
* animations.
......@@ -209,8 +209,6 @@ class VoiceInteractionIcon : public ui::Layer {
std::unique_ptr<ui::Layer> dot_layers_[DOT_COUNT];
std::unique_ptr<views::CircleLayerDelegate> dot_layer_delegates_[DOT_COUNT];
base::RepeatingTimer animation_timer_;
DISALLOW_COPY_AND_ASSIGN(VoiceInteractionIcon);
};
......
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