1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
ash / system / phonehub / app_stream_launcher_list_item.cc [blame]
// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/system/phonehub/app_stream_launcher_list_item.h"
#include "ash/strings/grit/ash_strings.h"
#include "ash/style/style_util.h"
#include "ash/style/typography.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/metadata/metadata_impl_macros.h"
#include "ui/chromeos/styles/cros_tokens_color_mappings.h"
#include "ui/color/color_id.h"
#include "ui/gfx/image/image.h"
#include "ui/gfx/image/image_skia_operations.h"
#include "ui/views/controls/focus_ring.h"
#include "ui/views/controls/highlight_path_generator.h"
namespace ash {
namespace {
constexpr int kEcheAppLIstItemIconSize = 32;
constexpr double kAlphaValueForInhibitedIconOpacity = 0.38;
} // namespace
AppStreamLauncherListItem::AppStreamLauncherListItem(
PressedCallback callback,
const phonehub::Notification::AppMetadata& app_metadata)
: LabelButton(std::move(callback), app_metadata.visible_app_name) {
TypographyProvider::Get()->StyleLabel(ash::TypographyToken::kCrosBody2,
*label());
gfx::ImageSkia resized_app_icon =
gfx::ImageSkiaOperations::CreateResizedImage(
app_metadata.color_icon.AsImageSkia(),
skia::ImageOperations::RESIZE_BEST,
gfx::Size(kEcheAppLIstItemIconSize, kEcheAppLIstItemIconSize));
SetImageModel(STATE_NORMAL, ui::ImageModel::FromImageSkia(resized_app_icon));
// Fade the image in order to make it look like grayed out.
SetImageModel(views::Button::ButtonState::STATE_DISABLED,
ui::ImageModel::FromImageSkia(
gfx::ImageSkiaOperations::CreateTransparentImage(
resized_app_icon, kAlphaValueForInhibitedIconOpacity)));
ash::StyleUtil::SetUpInkDropForButton(this, gfx::Insets(),
/*highlight_on_hover=*/false,
/*highlight_on_focus=*/true);
views::FocusRing::Get(this)->SetColorId(
static_cast<ui::ColorId>(cros_tokens::kCrosSysFocusRing));
views::InstallRectHighlightPathGenerator(this);
SetTooltipText(GetAppAccessibleName(app_metadata));
SetEnabled(app_metadata.app_streamability_status ==
phonehub::proto::AppStreamabilityStatus::STREAMABLE);
}
AppStreamLauncherListItem::~AppStreamLauncherListItem() = default;
std::u16string AppStreamLauncherListItem::GetAppAccessibleName(
const phonehub::Notification::AppMetadata& app_metadata) {
switch (app_metadata.app_streamability_status) {
case phonehub::proto::STREAMABLE:
return app_metadata.visible_app_name;
case phonehub::proto::BLOCKED_BY_APP:
return l10n_util::GetStringUTF16(
IDS_ASH_PHONE_HUB_STREAM_NOT_SUPPORTED_BY_APP);
case phonehub::proto::BLOCK_LISTED:
default:
return l10n_util::GetStringUTF16(IDS_ASH_PHONE_HUB_STREAM_NOT_SUPPORTED);
}
}
BEGIN_METADATA(AppStreamLauncherListItem)
END_METADATA
} // namespace ash