phone_disconnected_view.cc 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. // Copyright 2020 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "ash/system/phonehub/phone_disconnected_view.h"
  5. #include <memory>
  6. #include "ash/components/phonehub/connection_scheduler.h"
  7. #include "ash/components/phonehub/url_constants.h"
  8. #include "ash/public/cpp/new_window_delegate.h"
  9. #include "ash/public/cpp/resources/grit/ash_public_unscaled_resources.h"
  10. #include "ash/strings/grit/ash_strings.h"
  11. #include "ash/style/ash_color_provider.h"
  12. #include "ash/style/pill_button.h"
  13. #include "ash/system/phonehub/phone_hub_interstitial_view.h"
  14. #include "ash/system/phonehub/phone_hub_metrics.h"
  15. #include "ash/system/phonehub/phone_hub_view_ids.h"
  16. #include "ash/system/phonehub/ui_constants.h"
  17. #include "base/bind.h"
  18. #include "ui/base/l10n/l10n_util.h"
  19. #include "ui/base/metadata/metadata_impl_macros.h"
  20. #include "ui/base/resource/resource_bundle.h"
  21. #include "ui/views/layout/fill_layout.h"
  22. namespace ash {
  23. using phone_hub_metrics::InterstitialScreenEvent;
  24. using phone_hub_metrics::Screen;
  25. PhoneDisconnectedView::PhoneDisconnectedView(
  26. phonehub::ConnectionScheduler* connection_scheduler)
  27. : connection_scheduler_(connection_scheduler) {
  28. SetID(PhoneHubViewID::kDisconnectedView);
  29. SetLayoutManager(std::make_unique<views::FillLayout>());
  30. content_view_ = AddChildView(std::make_unique<PhoneHubInterstitialView>(
  31. /*show_progress=*/false));
  32. content_view_->SetImage(
  33. ui::ResourceBundle::GetSharedInstance().GetThemedLottieImageNamed(
  34. IDR_PHONE_HUB_ERROR_STATE_IMAGE));
  35. content_view_->SetTitle(l10n_util::GetStringUTF16(
  36. IDS_ASH_PHONE_HUB_PHONE_DISCONNECTED_DIALOG_TITLE));
  37. content_view_->SetDescription(l10n_util::GetStringUTF16(
  38. IDS_ASH_PHONE_HUB_PHONE_DISCONNECTED_DIALOG_DESCRIPTION));
  39. // Add "Learn more" and "Refresh" buttons.
  40. auto learn_more = std::make_unique<PillButton>(
  41. base::BindRepeating(
  42. &PhoneDisconnectedView::ButtonPressed, base::Unretained(this),
  43. InterstitialScreenEvent::kLearnMore,
  44. base::BindRepeating(
  45. &NewWindowDelegate::OpenUrl,
  46. base::Unretained(NewWindowDelegate::GetPrimary()),
  47. GURL(phonehub::kPhoneHubLearnMoreLink),
  48. NewWindowDelegate::OpenUrlFrom::kUserInteraction,
  49. NewWindowDelegate::Disposition::kNewForegroundTab)),
  50. l10n_util::GetStringUTF16(
  51. IDS_ASH_PHONE_HUB_PHONE_DISCONNECTED_DIALOG_LEARN_MORE_BUTTON),
  52. PillButton::Type::kIconlessFloating, /*icon=*/nullptr);
  53. learn_more->SetID(PhoneHubViewID::kDisconnectedLearnMoreButton);
  54. content_view_->AddButton(std::move(learn_more));
  55. auto refresh = std::make_unique<PillButton>(
  56. base::BindRepeating(
  57. &PhoneDisconnectedView::ButtonPressed, base::Unretained(this),
  58. InterstitialScreenEvent::kConfirm,
  59. base::BindRepeating(
  60. &phonehub::ConnectionScheduler::ScheduleConnectionNow,
  61. base::Unretained(connection_scheduler_))),
  62. l10n_util::GetStringUTF16(
  63. IDS_ASH_PHONE_HUB_PHONE_DISCONNECTED_DIALOG_REFRESH_BUTTON),
  64. PillButton::Type::kIconless, /*icon=*/nullptr);
  65. refresh->SetID(PhoneHubViewID::kDisconnectedRefreshButton);
  66. content_view_->AddButton(std::move(refresh));
  67. LogInterstitialScreenEvent(InterstitialScreenEvent::kShown);
  68. }
  69. PhoneDisconnectedView::~PhoneDisconnectedView() = default;
  70. phone_hub_metrics::Screen PhoneDisconnectedView::GetScreenForMetrics() const {
  71. return Screen::kPhoneDisconnected;
  72. }
  73. void PhoneDisconnectedView::ButtonPressed(InterstitialScreenEvent event,
  74. base::RepeatingClosure callback) {
  75. LogInterstitialScreenEvent(event);
  76. std::move(callback).Run();
  77. }
  78. BEGIN_METADATA(PhoneDisconnectedView, views::View)
  79. END_METADATA
  80. } // namespace ash