Avi Drissman | 3a215d1e | 2022-09-07 19:43:09 | [diff] [blame] | 1 | // Copyright 2020 The Chromium Authors |
Meilin Wang | 418ae71 | 2020-09-17 05:50:03 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "ash/system/phonehub/onboarding_view.h" |
| 6 | |
| 7 | #include <algorithm> |
| 8 | #include <memory> |
Jan Wilken Dörrie | ad587c3 | 2021-03-11 14:09:27 | [diff] [blame] | 9 | #include <string> |
Meilin Wang | 418ae71 | 2020-09-17 05:50:03 | [diff] [blame] | 10 | #include <vector> |
| 11 | |
| 12 | #include "ash/public/cpp/resources/grit/ash_public_unscaled_resources.h" |
Meilin Wang | 98efd1be | 2020-10-01 22:25:35 | [diff] [blame] | 13 | #include "ash/public/cpp/system_tray_client.h" |
Meilin Wang | d626fde | 2020-10-23 17:53:36 | [diff] [blame] | 14 | #include "ash/root_window_controller.h" |
Meilin Wang | 98efd1be | 2020-10-01 22:25:35 | [diff] [blame] | 15 | #include "ash/shell.h" |
Meilin Wang | 418ae71 | 2020-09-17 05:50:03 | [diff] [blame] | 16 | #include "ash/strings/grit/ash_strings.h" |
| 17 | #include "ash/style/ash_color_provider.h" |
minch | 9cfa2b0 | 2021-11-12 20:42:41 | [diff] [blame] | 18 | #include "ash/style/pill_button.h" |
Meilin Wang | 98efd1be | 2020-10-01 22:25:35 | [diff] [blame] | 19 | #include "ash/system/model/system_tray_model.h" |
Meilin Wang | d626fde | 2020-10-23 17:53:36 | [diff] [blame] | 20 | #include "ash/system/phonehub/phone_hub_content_view.h" |
Meilin Wang | 418ae71 | 2020-09-17 05:50:03 | [diff] [blame] | 21 | #include "ash/system/phonehub/phone_hub_interstitial_view.h" |
Tim Song | 8530370 | 2020-10-16 04:57:00 | [diff] [blame] | 22 | #include "ash/system/phonehub/phone_hub_metrics.h" |
Meilin Wang | d626fde | 2020-10-23 17:53:36 | [diff] [blame] | 23 | #include "ash/system/phonehub/phone_hub_tray.h" |
Meilin Wang | 98efd1be | 2020-10-01 22:25:35 | [diff] [blame] | 24 | #include "ash/system/phonehub/phone_hub_view_ids.h" |
Meilin Wang | d626fde | 2020-10-23 17:53:36 | [diff] [blame] | 25 | #include "ash/system/status_area_widget.h" |
| 26 | #include "ash/system/tray/tray_bubble_view.h" |
Avi Drissman | 4de6dab | 2023-01-06 23:17:35 | [diff] [blame] | 27 | #include "base/functional/bind.h" |
Arthur Sonzogni | 834e018f | 2023-04-22 10:20:02 | [diff] [blame] | 28 | #include "base/memory/raw_ptr.h" |
Meilin Wang | d626fde | 2020-10-23 17:53:36 | [diff] [blame] | 29 | #include "base/strings/strcat.h" |
Henrique Ferreiro | fadda06 | 2022-12-01 16:27:14 | [diff] [blame] | 30 | #include "chromeos/ash/components/phonehub/onboarding_ui_tracker.h" |
Meilin Wang | 418ae71 | 2020-09-17 05:50:03 | [diff] [blame] | 31 | #include "ui/base/l10n/l10n_util.h" |
Allen Bauer | a66b3eed | 2021-05-05 02:42:12 | [diff] [blame] | 32 | #include "ui/base/metadata/metadata_impl_macros.h" |
Meilin Wang | 418ae71 | 2020-09-17 05:50:03 | [diff] [blame] | 33 | #include "ui/base/resource/resource_bundle.h" |
Andre Le | 09e38cd | 2020-11-05 19:49:16 | [diff] [blame] | 34 | #include "ui/chromeos/devicetype_utils.h" |
Meilin Wang | 418ae71 | 2020-09-17 05:50:03 | [diff] [blame] | 35 | #include "ui/views/layout/fill_layout.h" |
| 36 | |
| 37 | namespace ash { |
| 38 | |
Tim Song | 8530370 | 2020-10-16 04:57:00 | [diff] [blame] | 39 | using phone_hub_metrics::InterstitialScreenEvent; |
Tim Song | 947932a | 2020-10-31 00:38:45 | [diff] [blame] | 40 | using phone_hub_metrics::Screen; |
Tim Song | 8530370 | 2020-10-16 04:57:00 | [diff] [blame] | 41 | |
Meilin Wang | d626fde | 2020-10-23 17:53:36 | [diff] [blame] | 42 | // OnboardingMainView --------------------------------------------------------- |
| 43 | // Main onboarding screen with Phone Hub feature description and two buttons |
| 44 | // (Get Started and Dismiss), where user can either choose to grant permission |
| 45 | // to enable this feature or dismiss the screen. |
Peter Kasting | 5aacfd49 | 2020-10-31 03:33:14 | [diff] [blame] | 46 | class OnboardingMainView : public PhoneHubInterstitialView { |
David Yeung | adb2744 | 2023-11-14 22:49:51 | [diff] [blame] | 47 | METADATA_HEADER(OnboardingMainView, PhoneHubInterstitialView) |
| 48 | |
Meilin Wang | d626fde | 2020-10-23 17:53:36 | [diff] [blame] | 49 | public: |
Henrique Ferreiro | 91fb61df | 2021-11-12 15:51:03 | [diff] [blame] | 50 | OnboardingMainView(phonehub::OnboardingUiTracker* onboarding_ui_tracker, |
| 51 | OnboardingView* parent_view, |
| 52 | OnboardingView::OnboardingFlow onboarding_flow) |
Meilin Wang | d626fde | 2020-10-23 17:53:36 | [diff] [blame] | 53 | : PhoneHubInterstitialView(/*show_progress=*/false), |
| 54 | onboarding_ui_tracker_(onboarding_ui_tracker), |
Tim Song | 5a9883f5 | 2020-11-04 19:40:03 | [diff] [blame] | 55 | parent_view_(parent_view), |
| 56 | onboarding_flow_(onboarding_flow) { |
Meilin Wang | d626fde | 2020-10-23 17:53:36 | [diff] [blame] | 57 | SetID(PhoneHubViewID::kOnboardingMainView); |
| 58 | InitLayout(); |
| 59 | } |
| 60 | |
Tim Song | 947932a | 2020-10-31 00:38:45 | [diff] [blame] | 61 | // PhoneHubInterstitialView: |
| 62 | Screen GetScreenForMetrics() const override { |
Tim Song | 5a9883f5 | 2020-11-04 19:40:03 | [diff] [blame] | 63 | switch (onboarding_flow_) { |
| 64 | case OnboardingView::kExistingMultideviceUser: |
| 65 | return Screen::kOnboardingExistingMultideviceUser; |
| 66 | case OnboardingView::kNewMultideviceUser: |
| 67 | return Screen::kOnboardingNewMultideviceUser; |
| 68 | } |
Tim Song | 947932a | 2020-10-31 00:38:45 | [diff] [blame] | 69 | } |
| 70 | |
Meilin Wang | d626fde | 2020-10-23 17:53:36 | [diff] [blame] | 71 | private: |
| 72 | void InitLayout() { |
Avery Musbach | 5ebb29fa | 2022-01-28 17:12:48 | [diff] [blame] | 73 | SetImage(ui::ResourceBundle::GetSharedInstance().GetThemedLottieImageNamed( |
| 74 | IDR_PHONE_HUB_ONBOARDING_IMAGE)); |
Meilin Wang | d626fde | 2020-10-23 17:53:36 | [diff] [blame] | 75 | SetTitle( |
| 76 | l10n_util::GetStringUTF16(IDS_ASH_PHONE_HUB_ONBOARDING_DIALOG_TITLE)); |
Kyle Horimoto | fe7173b | 2021-01-14 22:32:48 | [diff] [blame] | 77 | SetDescription(l10n_util::GetStringUTF16( |
| 78 | IDS_ASH_PHONE_HUB_ONBOARDING_DIALOG_DESCRIPTION)); |
Meilin Wang | d626fde | 2020-10-23 17:53:36 | [diff] [blame] | 79 | |
minch | a067493 | 2021-10-18 17:56:21 | [diff] [blame] | 80 | auto get_started = std::make_unique<PillButton>( |
Peter Kasting | 5aacfd49 | 2020-10-31 03:33:14 | [diff] [blame] | 81 | base::BindRepeating(&OnboardingMainView::GetStartedButtonPressed, |
| 82 | base::Unretained(this)), |
Meilin Wang | d626fde | 2020-10-23 17:53:36 | [diff] [blame] | 83 | l10n_util::GetStringUTF16( |
| 84 | IDS_ASH_PHONE_HUB_ONBOARDING_DIALOG_GET_STARTED_BUTTON), |
Crisrael Lucero | ecff8b8 | 2024-01-29 21:20:32 | [diff] [blame] | 85 | PillButton::Type::kPrimaryWithoutIcon, |
Crisrael Lucero | f1392ae | 2023-05-12 23:17:45 | [diff] [blame] | 86 | /*icon=*/nullptr); |
Meilin Wang | d626fde | 2020-10-23 17:53:36 | [diff] [blame] | 87 | get_started->SetID(PhoneHubViewID::kOnboardingGetStartedButton); |
| 88 | AddButton(std::move(get_started)); |
| 89 | } |
| 90 | |
Peter Kasting | 5aacfd49 | 2020-10-31 03:33:14 | [diff] [blame] | 91 | void GetStartedButtonPressed() { |
Tim Song | a6682b15 | 2020-11-03 21:24:24 | [diff] [blame] | 92 | LogInterstitialScreenEvent(InterstitialScreenEvent::kConfirm); |
Pu Shi | 0efed35f | 2023-08-07 19:21:24 | [diff] [blame] | 93 | onboarding_ui_tracker_->HandleGetStarted( |
| 94 | parent_view_->IsOnboardingViewStartedFromNudge()); |
Peter Kasting | 5aacfd49 | 2020-10-31 03:33:14 | [diff] [blame] | 95 | } |
| 96 | |
Bartek Nowierski | deb7584 | 2023-12-27 02:32:42 | [diff] [blame] | 97 | raw_ptr<phonehub::OnboardingUiTracker> onboarding_ui_tracker_ = nullptr; |
| 98 | raw_ptr<OnboardingView> parent_view_ = nullptr; |
Tim Song | 5a9883f5 | 2020-11-04 19:40:03 | [diff] [blame] | 99 | const OnboardingView::OnboardingFlow onboarding_flow_; |
Meilin Wang | d626fde | 2020-10-23 17:53:36 | [diff] [blame] | 100 | }; |
| 101 | |
David Yeung | adb2744 | 2023-11-14 22:49:51 | [diff] [blame] | 102 | BEGIN_METADATA(OnboardingMainView) |
| 103 | END_METADATA |
| 104 | |
Meilin Wang | d626fde | 2020-10-23 17:53:36 | [diff] [blame] | 105 | // OnboardingView ------------------------------------------------------------- |
Meilin Wang | 98efd1be | 2020-10-01 22:25:35 | [diff] [blame] | 106 | OnboardingView::OnboardingView( |
Henrique Ferreiro | 91fb61df | 2021-11-12 15:51:03 | [diff] [blame] | 107 | phonehub::OnboardingUiTracker* onboarding_ui_tracker, |
Meilin Wang | 6531973 | 2020-11-06 20:03:18 | [diff] [blame] | 108 | Delegate* delegate, |
Tim Song | 5a9883f5 | 2020-11-04 19:40:03 | [diff] [blame] | 109 | OnboardingFlow onboarding_flow) |
Meilin Wang | 6531973 | 2020-11-06 20:03:18 | [diff] [blame] | 110 | : onboarding_ui_tracker_(onboarding_ui_tracker), delegate_(delegate) { |
Meilin Wang | 98efd1be | 2020-10-01 22:25:35 | [diff] [blame] | 111 | SetID(PhoneHubViewID::kOnboardingView); |
Meilin Wang | 418ae71 | 2020-09-17 05:50:03 | [diff] [blame] | 112 | |
Meilin Wang | 418ae71 | 2020-09-17 05:50:03 | [diff] [blame] | 113 | SetLayoutManager(std::make_unique<views::FillLayout>()); |
Tim Song | 5a9883f5 | 2020-11-04 19:40:03 | [diff] [blame] | 114 | main_view_ = AddChildView(std::make_unique<OnboardingMainView>( |
| 115 | onboarding_ui_tracker_, this, onboarding_flow)); |
Tim Song | 8530370 | 2020-10-16 04:57:00 | [diff] [blame] | 116 | |
Tim Song | a6682b15 | 2020-11-03 21:24:24 | [diff] [blame] | 117 | LogInterstitialScreenEvent(InterstitialScreenEvent::kShown); |
Meilin Wang | 418ae71 | 2020-09-17 05:50:03 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | OnboardingView::~OnboardingView() = default; |
| 121 | |
Meilin Wang | d626fde | 2020-10-23 17:53:36 | [diff] [blame] | 122 | void OnboardingView::OnBubbleClose() { |
| 123 | main_view_->OnBubbleClose(); |
| 124 | } |
| 125 | |
Tim Song | 947932a | 2020-10-31 00:38:45 | [diff] [blame] | 126 | Screen OnboardingView::GetScreenForMetrics() const { |
| 127 | return main_view_->GetScreenForMetrics(); |
| 128 | } |
| 129 | |
Pu Shi | 0efed35f | 2023-08-07 19:21:24 | [diff] [blame] | 130 | bool OnboardingView::IsOnboardingViewStartedFromNudge() { |
| 131 | if (!delegate_) { |
| 132 | return false; |
| 133 | } |
| 134 | |
| 135 | return delegate_->IsPhoneHubIconClickedWhenNudgeVisible(); |
| 136 | } |
| 137 | |
Allen Bauer | b74ca11 | 2024-02-09 18:29:53 | [diff] [blame] | 138 | BEGIN_METADATA(OnboardingView) |
Meilin Wang | 418ae71 | 2020-09-17 05:50:03 | [diff] [blame] | 139 | END_METADATA |
| 140 | |
| 141 | } // namespace ash |