Skip to content

Commit

Permalink
Nearby Share Feature Tile
Browse files Browse the repository at this point in the history
Add Nearby Share feature tile for the CrOS revamped Quick Settings
which toggles Nearby Share high visibility, which means the device is
visible to everyone.

- Updated button icon, title label and sub-label text.
- Excluded `OnLabelPressed` action which opens Nearby Share settings on
its own without enabling the "Visible to everyone" feature.
- Tile is shown only if Nearby Share is enabled from the settings app.

screenshots:
Off - https://screenshot.googleplex.com/ARLeZzdJmvZpkuu.png
On  - https://screenshot.googleplex.com/7o4MK3Rn264N7tQ.png

b: 262925705
Change-Id: I86f5c8ebf443806fe9dbc7f98520ca827ecb6597
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4153330
Reviewed-by: Jiaming Cheng <jiamingc@chromium.org>
Reviewed-by: Ryan Hansberry <hansberry@chromium.org>
Commit-Queue: Kevin Radtke <kradtke@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1096454}
  • Loading branch information
Kevin Radtke authored and Chromium LUCI CQ committed Jan 24, 2023
1 parent 4815f3f commit 2c83630
Show file tree
Hide file tree
Showing 16 changed files with 315 additions and 56 deletions.
9 changes: 9 additions & 0 deletions ash/ash_strings.grd
Expand Up @@ -423,12 +423,21 @@ Style notes:
<message name="IDS_ASH_STATUS_TRAY_NEARBY_SHARE_BUTTON_LABEL" desc="The shorter label used for the button in the status tray to toggle Nearby Share high visibility mode, which makes the device visible to all nearby devices for file sharing.">
Nearby visibility
</message>
<message name="IDS_ASH_STATUS_TRAY_NEARBY_SHARE_TILE_LABEL" desc="The shorter label used for the feature tile in the status tray to toggle Nearby Share high visibility mode, which makes the device visible to all nearby devices for file sharing.">
Nearby Share
</message>
<message name="IDS_ASH_STATUS_TRAY_NEARBY_SHARE_OFF_STATE" desc="Sub-label for the Nearby Share system tray button." meaning="Nearby Share high visibility mode is currently inactive. [CHAR_LIMIT=14]">
Off
</message>
<message name="IDS_ASH_STATUS_TRAY_NEARBY_SHARE_ON_STATE" desc="Sub-label for the Nearby Share system tray button." meaning="Nearby Share high visibility mode is currently active with the displayed time remaining. [CHAR_LIMIT=14]">
On, <ph name="REMAINING_TIME">$1<ex>40 sec</ex></ph>
</message>
<message name="IDS_ASH_STATUS_TRAY_NEARBY_SHARE_TILE_OFF_STATE" desc="Sub-label for the Nearby Share system tray feature tile when off." meaning="Nearby Share high visibility mode is currently inactive. [CHAR_LIMIT=14]">
Everyone, off
</message>
<message name="IDS_ASH_STATUS_TRAY_NEARBY_SHARE_TILE_ON_STATE" desc="Sub-label for the Nearby Share system tray feature tile when on." meaning="Nearby Share high visibility mode is currently active with the displayed time remaining. [CHAR_LIMIT=14]">
Everyone, <ph name="REMAINING_TIME">$1<ex>40 sec</ex></ph>
</message>
<message name="IDS_ASH_STATUS_TRAY_NEARBY_SHARE_REMAINING_MINUTES" desc="A short string showing the nearest number of whole minutes until Nearby Share high visibility turns off. To be used with IDS_ASH_STATUS_TRAY_NEARBY_SHARE_ON_STATE. [CHAR_LIMIT=7]">
<ph name="MINUTES">$1<ex>2</ex></ph> min
</message>
Expand Down
@@ -0,0 +1 @@
7b5be464228da5f62bcf2df39c75a3261521bfaa
@@ -0,0 +1 @@
f4c5b8e433cb87bda458420db9c978d6c876f283
@@ -0,0 +1 @@
1a468f62ed719c2ca269fb136f12ce44026e9f56
3 changes: 3 additions & 0 deletions ash/public/cpp/nearby_share_delegate.h
Expand Up @@ -21,6 +21,9 @@ class ASH_PUBLIC_EXPORT NearbyShareDelegate {
public:
virtual ~NearbyShareDelegate() = default;

// Used to determine if NearbyShare has been enabled in the settings app.
virtual bool IsEnabled() = 0;

// Used by the pod button to determine whether it should be visible.
virtual bool IsPodButtonVisible() = 0;

Expand Down
4 changes: 4 additions & 0 deletions ash/public/cpp/test/test_nearby_share_delegate.cc
Expand Up @@ -12,6 +12,10 @@ TestNearbyShareDelegate::TestNearbyShareDelegate() = default;

TestNearbyShareDelegate::~TestNearbyShareDelegate() = default;

bool TestNearbyShareDelegate::IsEnabled() {
return is_enabled_;
}

bool TestNearbyShareDelegate::IsPodButtonVisible() {
return is_pod_button_visible_;
}
Expand Down
4 changes: 4 additions & 0 deletions ash/public/cpp/test/test_nearby_share_delegate.h
Expand Up @@ -25,6 +25,7 @@ class ASH_PUBLIC_EXPORT TestNearbyShareDelegate : public NearbyShareDelegate {
TestNearbyShareDelegate& operator=(TestNearbyShareDelegate&) = delete;

// NearbyShareDelegate
bool IsEnabled() override;
bool IsPodButtonVisible() override;
bool IsHighVisibilityOn() override;
bool IsEnableHighVisibilityRequestActive() const override;
Expand All @@ -33,6 +34,8 @@ class ASH_PUBLIC_EXPORT TestNearbyShareDelegate : public NearbyShareDelegate {
void DisableHighVisibility() override;
void ShowNearbyShareSettings() const override;

void set_is_enabled(bool enabled) { is_enabled_ = enabled; }

void set_is_pod_button_visible(bool visible) {
is_pod_button_visible_ = visible;
}
Expand All @@ -52,6 +55,7 @@ class ASH_PUBLIC_EXPORT TestNearbyShareDelegate : public NearbyShareDelegate {
std::vector<Method>& method_calls() { return method_calls_; }

private:
bool is_enabled_ = true;
bool is_pod_button_visible_ = false;
bool is_enable_high_visibility_request_active_ = false;
bool is_high_visibility_on_ = false;
Expand Down
2 changes: 2 additions & 0 deletions ash/resources/vector_icons/BUILD.gn
Expand Up @@ -258,6 +258,8 @@ aggregate_vector_icons("ash_vector_icons") {
"privacy_screen.icon",
"quick_settings_left_arrow.icon",
"quick_settings_managed.icon",
"quick_settings_nearby_share_off.icon",
"quick_settings_nearby_share_on.icon",
"quick_settings_right_arrow.icon",
"remove_outline.icon",
"reorder.icon",
Expand Down
68 changes: 68 additions & 0 deletions ash/resources/vector_icons/quick_settings_nearby_share_off.icon
@@ -0,0 +1,68 @@
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

CANVAS_DIMENSIONS, 20,
MOVE_TO, 1, 3.5f,
LINE_TO, 2.24f, 2.26f,
LINE_TO, 17.09f, 17.11f,
LINE_TO, 15.85f, 18.35f,
LINE_TO, 1, 3.5f,
CLOSE,
NEW_PATH,
MOVE_TO, 7, 7.03f,
CUBIC_TO, 6.82f, 7.17f, 6.65f, 7.33f, 6.48f, 7.5f,
LINE_TO, 2.24f, 11.84f,
CUBIC_TO, 1.87f, 12.23f, 1.87f, 12.86f, 2.26f, 13.24f,
CUBIC_TO, 2.65f, 13.61f, 3.28f, 13.61f, 3.66f, 13.22f,
LINE_TO, 5.65f, 11.17f,
LINE_TO, 7.89f, 8.88f,
CUBIC_TO, 8.05f, 8.71f, 8.23f, 8.57f, 8.42f, 8.45f,
LINE_TO, 7, 7.03f,
CLOSE,
NEW_PATH,
MOVE_TO, 11.25f, 11.27f,
CUBIC_TO, 10.87f, 11.45f, 10.45f, 11.54f, 10.02f, 11.54f,
CUBIC_TO, 9.29f, 11.54f, 8.62f, 11.28f, 8.09f, 10.81f,
LINE_TO, 6.72f, 12.22f,
CUBIC_TO, 7.63f, 13.05f, 8.78f, 13.51f, 10.02f, 13.51f,
CUBIC_TO, 10.98f, 13.51f, 11.91f, 13.24f, 12.7f, 12.72f,
LINE_TO, 11.25f, 11.27f,
CLOSE,
NEW_PATH,
MOVE_TO, 14, 11.56f,
LINE_TO, 12.61f, 10.16f,
LINE_TO, 14.38f, 8.35f,
LINE_TO, 16.38f, 6.3f,
CUBIC_TO, 16.75f, 5.91f, 17.38f, 5.91f, 17.77f, 6.28f,
CUBIC_TO, 17.97f, 6.48f, 18.06f, 6.74f, 18.06f, 6.99f,
CUBIC_TO, 18.06f, 7.24f, 17.97f, 7.49f, 17.79f, 7.68f,
LINE_TO, 15.76f, 9.76f,
LINE_TO, 14.38f, 11.17f,
LINE_TO, 14, 11.56f,
CLOSE,
NEW_PATH,
MOVE_TO, 10.47f, 8.02f,
LINE_TO, 8.65f, 6.2f,
CUBIC_TO, 9.08f, 6.07f, 9.54f, 6.01f, 10.02f, 6.01f,
CUBIC_TO, 11.25f, 6.01f, 12.41f, 6.47f, 13.31f, 7.3f,
LINE_TO, 11.94f, 8.71f,
CUBIC_TO, 11.51f, 8.34f, 11.01f, 8.1f, 10.47f, 8.02f,
CLOSE,
NEW_PATH,
MOVE_TO, 2.26f, 6.28f,
CUBIC_TO, 1.87f, 6.66f, 1.86f, 7.28f, 2.24f, 7.68f,
LINE_TO, 3.24f, 8.71f,
LINE_TO, 4.61f, 7.29f,
LINE_TO, 3.66f, 6.3f,
CUBIC_TO, 3.28f, 5.91f, 2.66f, 5.9f, 2.26f, 6.28f,
CLOSE,
NEW_PATH,
MOVE_TO, 18.06f, 12.53f,
CUBIC_TO, 18.06f, 12.29f, 17.97f, 12.03f, 17.79f, 11.84f,
LINE_TO, 16.8f, 10.83f,
LINE_TO, 15.43f, 12.25f,
LINE_TO, 16.38f, 13.23f,
CUBIC_TO, 16.75f, 13.62f, 17.37f, 13.63f, 17.77f, 13.24f,
CUBIC_TO, 17.97f, 13.05f, 18.06f, 12.79f, 18.06f, 12.53f,
CLOSE
50 changes: 50 additions & 0 deletions ash/resources/vector_icons/quick_settings_nearby_share_on.icon
@@ -0,0 +1,50 @@
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

CANVAS_DIMENSIONS, 20,
MOVE_TO, 2.24f, 7.68f,
CUBIC_TO, 1.86f, 7.28f, 1.87f, 6.66f, 2.26f, 6.28f,
CUBIC_TO, 2.66f, 5.9f, 3.28f, 5.91f, 3.66f, 6.3f,
LINE_TO, 4.61f, 7.29f,
LINE_TO, 3.24f, 8.71f,
LINE_TO, 2.24f, 7.68f,
CLOSE,
NEW_PATH,
MOVE_TO, 14.38f, 11.17f,
LINE_TO, 13.55f, 12.02f,
CUBIC_TO, 12.61f, 12.99f, 11.36f, 13.51f, 10.02f, 13.51f,
CUBIC_TO, 8.78f, 13.51f, 7.63f, 13.05f, 6.72f, 12.22f,
LINE_TO, 8.09f, 10.81f,
CUBIC_TO, 8.62f, 11.28f, 9.29f, 11.54f, 10.02f, 11.54f,
CUBIC_TO, 10.83f, 11.54f, 11.58f, 11.22f, 12.14f, 10.64f,
LINE_TO, 14.38f, 8.35f,
LINE_TO, 16.38f, 6.3f,
CUBIC_TO, 16.75f, 5.91f, 17.38f, 5.91f, 17.77f, 6.28f,
CUBIC_TO, 17.97f, 6.48f, 18.06f, 6.74f, 18.06f, 6.99f,
CUBIC_TO, 18.06f, 7.24f, 17.97f, 7.49f, 17.79f, 7.68f,
LINE_TO, 15.76f, 9.76f,
LINE_TO, 14.38f, 11.17f,
CLOSE,
NEW_PATH,
MOVE_TO, 6.48f, 7.5f,
CUBIC_TO, 7.42f, 6.53f, 8.67f, 6.01f, 10.02f, 6.01f,
CUBIC_TO, 11.25f, 6.01f, 12.41f, 6.47f, 13.31f, 7.3f,
LINE_TO, 11.94f, 8.71f,
CUBIC_TO, 11.4f, 8.24f, 10.74f, 7.98f, 10.02f, 7.98f,
CUBIC_TO, 9.21f, 7.98f, 8.46f, 8.3f, 7.89f, 8.88f,
LINE_TO, 5.65f, 11.17f,
LINE_TO, 3.66f, 13.22f,
CUBIC_TO, 3.28f, 13.61f, 2.65f, 13.61f, 2.26f, 13.24f,
CUBIC_TO, 1.87f, 12.86f, 1.87f, 12.23f, 2.24f, 11.84f,
LINE_TO, 6.48f, 7.5f,
CLOSE,
NEW_PATH,
MOVE_TO, 17.79f, 11.84f,
CUBIC_TO, 17.97f, 12.03f, 18.06f, 12.29f, 18.06f, 12.53f,
CUBIC_TO, 18.06f, 12.79f, 17.97f, 13.05f, 17.77f, 13.24f,
CUBIC_TO, 17.37f, 13.63f, 16.75f, 13.62f, 16.38f, 13.23f,
LINE_TO, 15.43f, 12.25f,
LINE_TO, 16.8f, 10.83f,
LINE_TO, 17.79f, 11.84f,
CLOSE
66 changes: 58 additions & 8 deletions ash/system/nearby_share/nearby_share_feature_pod_controller.cc
Expand Up @@ -12,6 +12,7 @@
#include "ash/strings/grit/ash_strings.h"
#include "ash/system/model/system_tray_model.h"
#include "ash/system/unified/feature_pod_button.h"
#include "ash/system/unified/feature_tile.h"
#include "ash/system/unified/quick_settings_metrics_util.h"
#include "ash/system/unified/unified_system_tray_controller.h"
#include "base/functional/bind.h"
Expand Down Expand Up @@ -86,6 +87,35 @@ FeaturePodButton* NearbyShareFeaturePodController::CreateButton() {
return button_;
}

std::unique_ptr<FeatureTile> NearbyShareFeaturePodController::CreateTile(
bool compact) {
DCHECK(features::IsQsRevampEnabled());
auto tile = std::make_unique<FeatureTile>(
base::BindRepeating(&FeaturePodControllerBase::OnIconPressed,
weak_ptr_factory_.GetWeakPtr()));
tile_ = tile.get();

SessionControllerImpl* session_controller =
Shell::Get()->session_controller();
const bool visible = nearby_share_delegate_->IsPodButtonVisible() &&
session_controller->IsActiveUserSessionStarted() &&
session_controller->IsUserPrimary() &&
!session_controller->IsUserSessionBlocked() &&
nearby_share_delegate_->IsEnabled();
tile_->SetVisible(visible);
if (visible) {
TrackVisibilityUMA();
}

tile_->SetLabel(
l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_NEARBY_SHARE_TILE_LABEL));
tile_->SetTooltipText(l10n_util::GetStringUTF16(
IDS_ASH_STATUS_TRAY_NEARBY_SHARE_TOGGLE_TOOLTIP));
bool enabled = nearby_share_delegate_->IsHighVisibilityOn();
OnHighVisibilityEnabledChanged(enabled);
return tile;
}

QsFeatureCatalogName NearbyShareFeaturePodController::GetCatalogName() {
return QsFeatureCatalogName::kNearbyShare;
}
Expand Down Expand Up @@ -117,17 +147,37 @@ void NearbyShareFeaturePodController::OnHighVisibilityEnabledChanged(
}

void NearbyShareFeaturePodController::UpdateButton(bool enabled) {
button_->SetToggled(enabled);
button_->SetVectorIcon(enabled ? kUnifiedMenuNearbyShareVisibleIcon
: kUnifiedMenuNearbyShareNotVisibleIcon);
bool is_qs_revamp_enabled = features::IsQsRevampEnabled();

if (is_qs_revamp_enabled) {
tile_->SetToggled(enabled);
tile_->SetVectorIcon(enabled ? kQuickSettingsNearbyShareOnIcon
: kQuickSettingsNearbyShareOffIcon);

} else {
button_->SetToggled(enabled);
button_->SetVectorIcon(enabled ? kUnifiedMenuNearbyShareVisibleIcon
: kUnifiedMenuNearbyShareNotVisibleIcon);
}

if (enabled) {
button_->SetSubLabel(l10n_util::GetStringFUTF16(
IDS_ASH_STATUS_TRAY_NEARBY_SHARE_ON_STATE,
RemainingTimeString(RemainingHighVisibilityTime())));
if (is_qs_revamp_enabled) {
tile_->SetSubLabel(l10n_util::GetStringFUTF16(
IDS_ASH_STATUS_TRAY_NEARBY_SHARE_TILE_ON_STATE,
RemainingTimeString(RemainingHighVisibilityTime())));
} else {
button_->SetSubLabel(l10n_util::GetStringFUTF16(
IDS_ASH_STATUS_TRAY_NEARBY_SHARE_ON_STATE,
RemainingTimeString(RemainingHighVisibilityTime())));
}
} else {
button_->SetSubLabel(
l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_NEARBY_SHARE_OFF_STATE));
if (is_qs_revamp_enabled) {
tile_->SetSubLabel(l10n_util::GetStringUTF16(
IDS_ASH_STATUS_TRAY_NEARBY_SHARE_TILE_OFF_STATE));
} else {
button_->SetSubLabel(l10n_util::GetStringUTF16(
IDS_ASH_STATUS_TRAY_NEARBY_SHARE_OFF_STATE));
}
}
}

Expand Down
5 changes: 5 additions & 0 deletions ash/system/nearby_share/nearby_share_feature_pod_controller.h
Expand Up @@ -9,6 +9,7 @@
#include "ash/constants/quick_settings_catalogs.h"
#include "ash/system/nearby_share/nearby_share_controller_impl.h"
#include "ash/system/unified/feature_pod_controller_base.h"
#include "base/memory/weak_ptr.h"
#include "base/time/time.h"
#include "base/timer/timer.h"

Expand All @@ -33,6 +34,7 @@ class ASH_EXPORT NearbyShareFeaturePodController

// FeaturePodControllerBase:
FeaturePodButton* CreateButton() override;
std::unique_ptr<FeatureTile> CreateTile(bool compact = false) override;
QsFeatureCatalogName GetCatalogName() override;
void OnIconPressed() override;
void OnLabelPressed() override;
Expand All @@ -54,6 +56,9 @@ class ASH_EXPORT NearbyShareFeaturePodController
NearbyShareDelegate* const nearby_share_delegate_;
NearbyShareControllerImpl* const nearby_share_controller_;
FeaturePodButton* button_ = nullptr;
FeatureTile* tile_ = nullptr;

base::WeakPtrFactory<NearbyShareFeaturePodController> weak_ptr_factory_{this};
};

} // namespace ash
Expand Down

0 comments on commit 2c83630

Please sign in to comment.