Commit bc42b9b0 authored by Ahmed Mehfooz's avatar Ahmed Mehfooz Committed by Chromium LUCI CQ

Add stylus battery status behind feature flag

This CL adds a feature flag for stylus battery
status in the stylus tools menu.
Also adds skeleton code to set up the UI to be
hooked up with backend CL in a subsequent CL.

Bug: 1158537
Change-Id: I873c1dac4827a64e0f66a18aa63a4df1e0c44036
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2590366
Commit-Queue: Ahmed Mehfooz <amehfooz@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#837886}
parent 3c6c98f4
......@@ -1171,6 +1171,8 @@ component("ash") {
"system/palette/palette_utils.h",
"system/palette/palette_welcome_bubble.cc",
"system/palette/palette_welcome_bubble.h",
"system/palette/stylus_battery_delegate.cc",
"system/palette/stylus_battery_delegate.h",
"system/palette/tools/capture_region_mode.cc",
"system/palette/tools/capture_region_mode.h",
"system/palette/tools/capture_screen_action.cc",
......
......@@ -1209,6 +1209,15 @@ This file contains the strings for ash.
Silence phone is not available on work profile
</message>
<message name="IDS_ASH_STYLUS_BATTERY_LOW_LABEL">
Low
</message>
<message name="IDS_ASH_STYLUS_BATTERY_MED_LABEL">
Med
</message>
<message name="IDS_ASH_STYLUS_BATTERY_HI_LABEL">
Hi
</message>
<message name="IDS_ASH_STYLUS_TOOLS_CAPTURE_REGION_ACTION" desc="Title of the capture region action in the stylus tools (a pop-up panel next to the status tray). This causes a partial screenshot to be taken (the user selects an area of the screen to take a screenshot of).">
Capture region
</message>
......
f9dfa5adb30c929b0694cbf46ed7893fee05d1fb
\ No newline at end of file
8491abd1aa9f1928d8d1b968e215718da80f9304
\ No newline at end of file
a2bda703b9e32c023a76e2845d05b1c17718630e
\ No newline at end of file
......@@ -131,6 +131,9 @@ const base::Feature kReverseScrollGestures{"EnableReverseScrollGestures",
const base::Feature kFullscreenAlertBubble{"EnableFullscreenBubble",
base::FEATURE_DISABLED_BY_DEFAULT};
const base::Feature kStylusBatteryStatus{"StylusBatteryStatus",
base::FEATURE_DISABLED_BY_DEFAULT};
const base::Feature kSystemTrayMicGainSetting{"SystemTrayMicGainSetting",
base::FEATURE_ENABLED_BY_DEFAULT};
......@@ -290,6 +293,10 @@ bool AreContextualNudgesEnabled() {
return base::FeatureList::IsEnabled(kContextualNudges);
}
bool IsStylusBatteryStatusEnabled() {
return base::FeatureList::IsEnabled(kStylusBatteryStatus);
}
bool IsSystemTrayMicGainSettingEnabled() {
return base::FeatureList::IsEnabled(kSystemTrayMicGainSetting);
}
......
......@@ -178,6 +178,9 @@ ASH_PUBLIC_EXPORT extern const base::Feature kReverseScrollGestures;
// TODO(https://crbug.com/1107185): Remove this after the feature is launched.
ASH_PUBLIC_EXPORT extern const base::Feature kFullscreenAlertBubble;
// Enables battery indicator for styluses in the palette tray
ASH_PUBLIC_EXPORT extern const base::Feature kStylusBatteryStatus;
// Enables sliders for setting mic gain levels in the more audio settings
// section in the system tray.
ASH_PUBLIC_EXPORT extern const base::Feature kSystemTrayMicGainSetting;
......@@ -267,6 +270,8 @@ ASH_PUBLIC_EXPORT bool AreContextualNudgesEnabled();
ASH_PUBLIC_EXPORT bool IsSystemTrayMicGainSettingEnabled();
ASH_PUBLIC_EXPORT bool IsStylusBatteryStatusEnabled();
ASH_PUBLIC_EXPORT bool IsDisplayIdentificationEnabled();
ASH_PUBLIC_EXPORT bool IsWebUITabStripTabDragIntegrationEnabled();
......
......@@ -7,6 +7,7 @@
#include <memory>
#include "ash/accessibility/accessibility_controller_impl.h"
#include "ash/public/cpp/ash_features.h"
#include "ash/public/cpp/ash_pref_names.h"
#include "ash/public/cpp/shelf_config.h"
#include "ash/public/cpp/stylus_utils.h"
......@@ -21,6 +22,7 @@
#include "ash/system/palette/palette_tool_manager.h"
#include "ash/system/palette/palette_utils.h"
#include "ash/system/palette/palette_welcome_bubble.h"
#include "ash/system/palette/stylus_battery_delegate.h"
#include "ash/system/tray/tray_background_view.h"
#include "ash/system/tray/tray_bubble_wrapper.h"
#include "ash/system/tray/tray_container.h"
......@@ -87,6 +89,26 @@ bool ShouldShowOnDisplay(PaletteTray* palette_tray) {
return display.IsInternal();
}
class BatteryView : public views::View {
public:
explicit BatteryView(StylusBatteryDelegate* delegate) {
SetLayoutManager(std::make_unique<views::BoxLayout>(
views::BoxLayout::Orientation::kHorizontal, gfx::Insets(), 4));
icon_ = AddChildView(std::make_unique<views::ImageView>());
icon_->SetImage(delegate->GetBatteryImage());
label_ = AddChildView(std::make_unique<views::Label>(
l10n_util::GetStringUTF16(delegate->GetLabelIdForBatteryLevel())));
label_->SetEnabledColor(delegate->GetColorForBatteryLevel());
TrayPopupUtils::SetLabelFontList(label_,
TrayPopupUtils::FontStyle::kSmallTitle);
}
private:
views::ImageView* icon_ = nullptr;
views::Label* label_ = nullptr;
};
class TitleView : public views::View {
public:
explicit TitleView(PaletteTray* palette_tray) : palette_tray_(palette_tray) {
......@@ -107,6 +129,17 @@ class TitleView : public views::View {
TrayPopupUtils::SetLabelFontList(title_label,
TrayPopupUtils::FontStyle::kPodMenuHeader);
layout_ptr->SetFlexForView(title_label, 1);
if (ash::features::IsStylusBatteryStatusEnabled()) {
AddChildView(std::make_unique<BatteryView>(
palette_tray->stylus_battery_delegate()));
auto* separator = AddChildView(std::make_unique<views::Separator>());
separator->SetPreferredHeight(GetPreferredSize().height());
separator->SetColor(AshColorProvider::Get()->GetContentLayerColor(
AshColorProvider::ContentLayerType::kSeparatorColor));
}
help_button_ = AddChildView(std::make_unique<TopShortcutButton>(
base::BindRepeating(
&TitleView::ButtonPressed, base::Unretained(this),
......
......@@ -11,6 +11,7 @@
#include "ash/public/cpp/session/session_observer.h"
#include "ash/shell_observer.h"
#include "ash/system/palette/palette_tool_manager.h"
#include "ash/system/palette/stylus_battery_delegate.h"
#include "ash/system/tray/tray_background_view.h"
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
......@@ -91,6 +92,10 @@ class ASH_EXPORT PaletteTray : public TrayBackgroundView,
PaletteInvocationMethod method) override;
void RecordPaletteModeCancellation(PaletteModeCancelType type) override;
StylusBatteryDelegate* stylus_battery_delegate() {
return &stylus_battery_delegate_;
}
private:
friend class PaletteTrayTestApi;
......@@ -155,6 +160,8 @@ class ASH_EXPORT PaletteTray : public TrayBackgroundView,
// Number of actions in pen palette bubble.
int num_actions_in_bubble_ = 0;
StylusBatteryDelegate stylus_battery_delegate_;
ScopedSessionObserver scoped_session_observer_;
base::WeakPtrFactory<PaletteTray> weak_factory_{this};
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/system/palette/stylus_battery_delegate.h"
#include "ash/shell.h"
#include "ash/strings/grit/ash_strings.h"
#include "ash/style/ash_color_provider.h"
#include "ash/system/power/power_status.h"
#include "ash/system/tray/tray_constants.h"
#include "base/strings/string16.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/gfx/color_palette.h"
namespace ash {
namespace {
// Battery percentage thresholds to used to label the battery level
// as Hi, Med or Low.
constexpr int kStylusLowBatteryThreshold = 24;
constexpr int kStylusMediumBatteryThreshold = 71;
} // namespace
StylusBatteryDelegate::StylusBatteryDelegate() = default;
SkColor StylusBatteryDelegate::GetColorForBatteryLevel() const {
if (battery_level_ <= kStylusLowBatteryThreshold) {
return AshColorProvider::Get()->GetContentLayerColor(
AshColorProvider::ContentLayerType::kIconColorAlert);
}
return AshColorProvider::Get()->GetContentLayerColor(
AshColorProvider::ContentLayerType::kIconColorPositive);
}
int StylusBatteryDelegate::GetLabelIdForBatteryLevel() const {
if (battery_level_ <= kStylusLowBatteryThreshold) {
return IDS_ASH_STYLUS_BATTERY_LOW_LABEL;
}
if (battery_level_ <= kStylusMediumBatteryThreshold) {
return IDS_ASH_STYLUS_BATTERY_MED_LABEL;
}
return IDS_ASH_STYLUS_BATTERY_HI_LABEL;
}
gfx::ImageSkia StylusBatteryDelegate::GetBatteryImage() const {
PowerStatus::BatteryImageInfo info;
info.charge_percent = battery_level_.value_or(0);
const SkColor icon_fg_color = GetColorForBatteryLevel();
const SkColor icon_bg_color = AshColorProvider::Get()->GetBackgroundColor();
return PowerStatus::GetBatteryImage(info, kUnifiedTrayIconSize, icon_bg_color,
icon_fg_color);
}
} // namespace ash
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ASH_SYSTEM_PALETTE_STYLUS_BATTERY_DELEGATE_H_
#define ASH_SYSTEM_PALETTE_STYLUS_BATTERY_DELEGATE_H_
#include "ash/ash_export.h"
#include "base/scoped_observer.h"
#include "base/strings/string16.h"
#include "ui/gfx/image/image_skia.h"
namespace ash {
class ASH_EXPORT StylusBatteryDelegate {
public:
StylusBatteryDelegate();
StylusBatteryDelegate(const StylusBatteryDelegate& other) = delete;
StylusBatteryDelegate& operator=(const StylusBatteryDelegate& other) = delete;
SkColor GetColorForBatteryLevel() const;
int GetLabelIdForBatteryLevel() const;
gfx::ImageSkia GetBatteryImage() const;
base::Optional<uint8_t> battery_level() const { return battery_level_; }
private:
base::Optional<uint8_t> battery_level_;
// Peripheral battery observer to be added here.
};
} // namespace ash
#endif // ASH_SYSTEM_PALETTE_STYLUS_BATTERY_DELEGATE_H_
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