Change network connecting animation

BUG=chromium-os:15687
TEST=Disable / reenable wifi and check animation

Review URL: http://codereview.chromium.org/7067030

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@86630 0039d316-1c4b-4281-b951-d872f2087c98
parent f2d4c672
...@@ -21,7 +21,7 @@ namespace chromeos { ...@@ -21,7 +21,7 @@ namespace chromeos {
// NetworkDropdownButton // NetworkDropdownButton
// static // static
const int NetworkDropdownButton::kThrobDuration = 1000; const int NetworkDropdownButton::kThrobDuration = 750;
NetworkDropdownButton::NetworkDropdownButton(bool browser_mode, NetworkDropdownButton::NetworkDropdownButton(bool browser_mode,
gfx::NativeWindow parent_window) gfx::NativeWindow parent_window)
...@@ -34,7 +34,7 @@ NetworkDropdownButton::NetworkDropdownButton(bool browser_mode, ...@@ -34,7 +34,7 @@ NetworkDropdownButton::NetworkDropdownButton(bool browser_mode,
ALLOW_THIS_IN_INITIALIZER_LIST(animation_connecting_(this)), ALLOW_THIS_IN_INITIALIZER_LIST(animation_connecting_(this)),
parent_window_(parent_window) { parent_window_(parent_window) {
animation_connecting_.SetThrobDuration(kThrobDuration); animation_connecting_.SetThrobDuration(kThrobDuration);
animation_connecting_.SetTweenType(ui::Tween::EASE_IN_OUT); animation_connecting_.SetTweenType(ui::Tween::LINEAR);
CrosLibrary::Get()->GetNetworkLibrary()->AddNetworkManagerObserver(this); CrosLibrary::Get()->GetNetworkLibrary()->AddNetworkManagerObserver(this);
// The initial state will be updated on Refresh. // The initial state will be updated on Refresh.
// See network_selection_view.cc. // See network_selection_view.cc.
......
...@@ -33,6 +33,9 @@ ...@@ -33,6 +33,9 @@
namespace { namespace {
// Amount to fade icons while connecting.
const double kConnectingImageAlpha = 0.5;
// Replace '&' in a string with "&&" to allow it to be a menu item label. // Replace '&' in a string with "&&" to allow it to be a menu item label.
std::string EscapeAmpersands(const std::string& input) { std::string EscapeAmpersands(const std::string& input) {
std::string str = input; std::string str = input;
...@@ -1168,13 +1171,10 @@ const int NetworkMenu::kBarsImagesVLowData[kNumBarsImages] = { ...@@ -1168,13 +1171,10 @@ const int NetworkMenu::kBarsImagesVLowData[kNumBarsImages] = {
#endif #endif
// static // static
const int NetworkMenu::kNumAnimatingImages = 10; SkBitmap NetworkMenu::kAnimatingImages[kNumBarsImages];
// static
SkBitmap NetworkMenu::kAnimatingImages[kNumAnimatingImages];
// static // static
SkBitmap NetworkMenu::kAnimatingImagesBlack[kNumAnimatingImages]; SkBitmap NetworkMenu::kAnimatingImagesBlack[kNumBarsImages];
NetworkMenu::NetworkMenu() : min_width_(kDefaultMinimumWidth) { NetworkMenu::NetworkMenu() : min_width_(kDefaultMinimumWidth) {
main_menu_model_.reset(new MainMenuModel(this)); main_menu_model_.reset(new MainMenuModel(this));
...@@ -1240,27 +1240,32 @@ const SkBitmap* NetworkMenu::IconForNetworkStrength( ...@@ -1240,27 +1240,32 @@ const SkBitmap* NetworkMenu::IconForNetworkStrength(
// static // static
const SkBitmap* NetworkMenu::IconForNetworkConnecting(double animation_value, const SkBitmap* NetworkMenu::IconForNetworkConnecting(double animation_value,
bool black) { bool black) {
// Draw animation of bars icon fading in and out. // Fade bars a bit and show the different bar states.
// We are fading between 0 bars and a third of the opacity of 4 bars. const int* source_image_ids = black ? kBarsImagesBlack : kBarsImages;
// Use the current value of the animation to calculate the alpha value SkBitmap* images = black ? kAnimatingImagesBlack : kAnimatingImages;
// of how transparent the icon is.
int index = static_cast<int>(animation_value * int index = static_cast<int>(animation_value *
nextafter(static_cast<float>(kNumAnimatingImages), 0)); nextafter(static_cast<float>(kNumBarsImages), 0));
index = std::max(std::min(index, kNumAnimatingImages - 1), 0); index = std::max(std::min(index, kNumBarsImages - 1), 0);
SkBitmap* images = black ? kAnimatingImagesBlack : kAnimatingImages;
// Lazily cache images. // Lazily cache images.
if (images[index].empty()) { if (images[index].empty()) {
// Divide index (0-9) by 9 (assume kNumAnimatingImages==10) to get (0.0-1.0)
// Then we take a third of that for the alpha value.
double alpha = (static_cast<double>(index) / (kNumAnimatingImages - 1)) / 3;
ResourceBundle& rb = ResourceBundle::GetSharedInstance(); ResourceBundle& rb = ResourceBundle::GetSharedInstance();
images[index] = SkBitmapOperations::CreateBlendedBitmap( SkBitmap source = *rb.GetBitmapNamed(source_image_ids[index]);
*rb.GetBitmapNamed(black ? IDR_STATUSBAR_NETWORK_BARS0_BLACK :
IDR_STATUSBAR_NETWORK_BARS0), // Create an empty image to fade against.
*rb.GetBitmapNamed(black ? IDR_STATUSBAR_NETWORK_BARS4_BLACK : SkBitmap empty_image;
IDR_STATUSBAR_NETWORK_BARS4), empty_image.setConfig(SkBitmap::kARGB_8888_Config,
alpha); source.width(),
source.height(),
0);
empty_image.allocPixels();
empty_image.eraseARGB(0, 0, 0, 0);
images[index] =
SkBitmapOperations::CreateBlendedBitmap(
empty_image,
source,
kConnectingImageAlpha);
} }
return &images[index]; return &images[index];
} }
......
...@@ -166,8 +166,6 @@ class NetworkMenu : public views::ViewMenuDelegate { ...@@ -166,8 +166,6 @@ class NetworkMenu : public views::ViewMenuDelegate {
// TODO(chocobo): Add this back when we decide to do colored bars again. // TODO(chocobo): Add this back when we decide to do colored bars again.
// static const int kBarsImagesVLowData[]; // static const int kBarsImagesVLowData[];
// The number of animating images for network connecting.
static const int kNumAnimatingImages;
// Animation images. These are created lazily. // Animation images. These are created lazily.
static SkBitmap kAnimatingImages[]; static SkBitmap kAnimatingImages[];
static SkBitmap kAnimatingImagesBlack[]; static SkBitmap kAnimatingImagesBlack[];
......
...@@ -95,7 +95,7 @@ namespace chromeos { ...@@ -95,7 +95,7 @@ namespace chromeos {
// NetworkMenuButton // NetworkMenuButton
// static // static
const int NetworkMenuButton::kThrobDuration = 1000; const int NetworkMenuButton::kThrobDuration = 750;
NetworkMenuButton::NetworkMenuButton(StatusAreaHost* host) NetworkMenuButton::NetworkMenuButton(StatusAreaHost* host)
: StatusAreaButton(host, this), : StatusAreaButton(host, this),
...@@ -108,7 +108,7 @@ NetworkMenuButton::NetworkMenuButton(StatusAreaHost* host) ...@@ -108,7 +108,7 @@ NetworkMenuButton::NetworkMenuButton(StatusAreaHost* host)
ALLOW_THIS_IN_INITIALIZER_LIST(animation_connecting_(this)), ALLOW_THIS_IN_INITIALIZER_LIST(animation_connecting_(this)),
ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) {
animation_connecting_.SetThrobDuration(kThrobDuration); animation_connecting_.SetThrobDuration(kThrobDuration);
animation_connecting_.SetTweenType(ui::Tween::EASE_IN_OUT); animation_connecting_.SetTweenType(ui::Tween::LINEAR);
NetworkLibrary* network_library = CrosLibrary::Get()->GetNetworkLibrary(); NetworkLibrary* network_library = CrosLibrary::Get()->GetNetworkLibrary();
OnNetworkManagerChanged(network_library); OnNetworkManagerChanged(network_library);
network_library->AddNetworkManagerObserver(this); network_library->AddNetworkManagerObserver(this);
......
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