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 {
// NetworkDropdownButton
// static
const int NetworkDropdownButton::kThrobDuration = 1000;
const int NetworkDropdownButton::kThrobDuration = 750;
NetworkDropdownButton::NetworkDropdownButton(bool browser_mode,
gfx::NativeWindow parent_window)
......@@ -34,7 +34,7 @@ NetworkDropdownButton::NetworkDropdownButton(bool browser_mode,
ALLOW_THIS_IN_INITIALIZER_LIST(animation_connecting_(this)),
parent_window_(parent_window) {
animation_connecting_.SetThrobDuration(kThrobDuration);
animation_connecting_.SetTweenType(ui::Tween::EASE_IN_OUT);
animation_connecting_.SetTweenType(ui::Tween::LINEAR);
CrosLibrary::Get()->GetNetworkLibrary()->AddNetworkManagerObserver(this);
// The initial state will be updated on Refresh.
// See network_selection_view.cc.
......
......@@ -33,6 +33,9 @@
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.
std::string EscapeAmpersands(const std::string& input) {
std::string str = input;
......@@ -1168,13 +1171,10 @@ const int NetworkMenu::kBarsImagesVLowData[kNumBarsImages] = {
#endif
// static
const int NetworkMenu::kNumAnimatingImages = 10;
// static
SkBitmap NetworkMenu::kAnimatingImages[kNumAnimatingImages];
SkBitmap NetworkMenu::kAnimatingImages[kNumBarsImages];
// static
SkBitmap NetworkMenu::kAnimatingImagesBlack[kNumAnimatingImages];
SkBitmap NetworkMenu::kAnimatingImagesBlack[kNumBarsImages];
NetworkMenu::NetworkMenu() : min_width_(kDefaultMinimumWidth) {
main_menu_model_.reset(new MainMenuModel(this));
......@@ -1240,27 +1240,32 @@ const SkBitmap* NetworkMenu::IconForNetworkStrength(
// static
const SkBitmap* NetworkMenu::IconForNetworkConnecting(double animation_value,
bool black) {
// Draw animation of bars icon fading in and out.
// We are fading between 0 bars and a third of the opacity of 4 bars.
// Use the current value of the animation to calculate the alpha value
// of how transparent the icon is.
// Fade bars a bit and show the different bar states.
const int* source_image_ids = black ? kBarsImagesBlack : kBarsImages;
SkBitmap* images = black ? kAnimatingImagesBlack : kAnimatingImages;
int index = static_cast<int>(animation_value *
nextafter(static_cast<float>(kNumAnimatingImages), 0));
index = std::max(std::min(index, kNumAnimatingImages - 1), 0);
nextafter(static_cast<float>(kNumBarsImages), 0));
index = std::max(std::min(index, kNumBarsImages - 1), 0);
SkBitmap* images = black ? kAnimatingImagesBlack : kAnimatingImages;
// Lazily cache images.
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();
images[index] = SkBitmapOperations::CreateBlendedBitmap(
*rb.GetBitmapNamed(black ? IDR_STATUSBAR_NETWORK_BARS0_BLACK :
IDR_STATUSBAR_NETWORK_BARS0),
*rb.GetBitmapNamed(black ? IDR_STATUSBAR_NETWORK_BARS4_BLACK :
IDR_STATUSBAR_NETWORK_BARS4),
alpha);
SkBitmap source = *rb.GetBitmapNamed(source_image_ids[index]);
// Create an empty image to fade against.
SkBitmap empty_image;
empty_image.setConfig(SkBitmap::kARGB_8888_Config,
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];
}
......
......@@ -166,8 +166,6 @@ class NetworkMenu : public views::ViewMenuDelegate {
// TODO(chocobo): Add this back when we decide to do colored bars again.
// static const int kBarsImagesVLowData[];
// The number of animating images for network connecting.
static const int kNumAnimatingImages;
// Animation images. These are created lazily.
static SkBitmap kAnimatingImages[];
static SkBitmap kAnimatingImagesBlack[];
......
......@@ -95,7 +95,7 @@ namespace chromeos {
// NetworkMenuButton
// static
const int NetworkMenuButton::kThrobDuration = 1000;
const int NetworkMenuButton::kThrobDuration = 750;
NetworkMenuButton::NetworkMenuButton(StatusAreaHost* host)
: StatusAreaButton(host, this),
......@@ -108,7 +108,7 @@ NetworkMenuButton::NetworkMenuButton(StatusAreaHost* host)
ALLOW_THIS_IN_INITIALIZER_LIST(animation_connecting_(this)),
ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) {
animation_connecting_.SetThrobDuration(kThrobDuration);
animation_connecting_.SetTweenType(ui::Tween::EASE_IN_OUT);
animation_connecting_.SetTweenType(ui::Tween::LINEAR);
NetworkLibrary* network_library = CrosLibrary::Get()->GetNetworkLibrary();
OnNetworkManagerChanged(network_library);
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