Skip to content

Commit

Permalink
[CrOS PhoneHub] Change text color when enable hotspot is connected.
Browse files Browse the repository at this point in the history
Add a function to change sub label's text color in QuickActionItem,
which is used in enable hotspot to change the color to green when
connected.

Bug: 1106937,1126208
Change-Id: Ia892551bd7d60ea1131b6d5c84f60cd6951b8e83
Fixed: 1144843
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2512547
Reviewed-by: Kyle Horimoto <khorimoto@chromium.org>
Reviewed-by: Tim Song <tengs@chromium.org>
Commit-Queue: Andre Le <leandre@chromium.org>
Cr-Commit-Position: refs/heads/master@{#823340}
  • Loading branch information
Andre Le authored and Commit Bot committed Nov 2, 2020
1 parent 476ebf3 commit c439739
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
9 changes: 9 additions & 0 deletions ash/system/phonehub/enable_hotspot_quick_action_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include "ash/resources/vector_icons/vector_icons.h"
#include "ash/strings/grit/ash_strings.h"
#include "ash/style/ash_color_provider.h"
#include "ash/system/phonehub/phone_hub_metrics.h"
#include "ash/system/phonehub/quick_action_item.h"
#include "ui/base/l10n/l10n_util.h"
Expand Down Expand Up @@ -74,26 +75,34 @@ void EnableHotspotQuickActionController::SetState(ActionState state) {
bool icon_enabled;
int state_text_id;
int sub_label_text;
SkColor sub_label_color;
switch (state) {
case ActionState::kOff:
icon_enabled = false;
state_text_id = IDS_ASH_PHONE_HUB_QUICK_ACTIONS_DISABLED_STATE_TOOLTIP;
sub_label_text = IDS_ASH_PHONE_HUB_QUICK_ACTIONS_OFF_STATE;
sub_label_color = AshColorProvider::Get()->GetContentLayerColor(
AshColorProvider::ContentLayerType::kTextColorSecondary);
break;
case ActionState::kConnecting:
icon_enabled = true;
state_text_id = IDS_ASH_PHONE_HUB_QUICK_ACTIONS_CONNECTING_STATE_TOOLTIP;
sub_label_text = IDS_ASH_PHONE_HUB_QUICK_ACTIONS_CONNECTING_STATE;
sub_label_color = AshColorProvider::Get()->GetContentLayerColor(
AshColorProvider::ContentLayerType::kTextColorSecondary);
break;
case ActionState::kConnected:
icon_enabled = true;
state_text_id = IDS_ASH_PHONE_HUB_QUICK_ACTIONS_CONNECTED_STATE_TOOLTIP;
sub_label_text = IDS_ASH_PHONE_HUB_QUICK_ACTIONS_CONNECTED_STATE;
sub_label_color = AshColorProvider::Get()->GetContentLayerColor(
AshColorProvider::ContentLayerType::kTextColorPositive);
break;
}

item_->SetToggled(icon_enabled);
item_->SetSubLabel(l10n_util::GetStringUTF16(sub_label_text));
item_->SetSubLabelColor(sub_label_color);
base::string16 tooltip_state =
l10n_util::GetStringFUTF16(state_text_id, item_->GetItemLabel());
item_->SetIconTooltip(
Expand Down
13 changes: 11 additions & 2 deletions ash/system/phonehub/quick_action_item.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ QuickActionItem::QuickActionItem(Delegate* delegate,
ConfigureLabel(sub_label_, kUnifiedFeaturePodSubLabelLineHeight,
kUnifiedFeaturePodSubLabelFontSize);

sub_label_color_ = AshColorProvider::Get()->GetContentLayerColor(
AshColorProvider::ContentLayerType::kTextColorSecondary);

SetEnabled(true /* enabled */);

SetPaintToLayer();
Expand All @@ -80,6 +83,13 @@ void QuickActionItem::SetSubLabel(const base::string16& sub_label) {
sub_label_->SetText(sub_label);
}

void QuickActionItem::SetSubLabelColor(SkColor color) {
if (sub_label_color_ == color)
return;
sub_label_color_ = color;
sub_label_->SetEnabledColor(sub_label_color_);
}

void QuickActionItem::SetIcon(bool is_on) {
icon_button_->SetVectorIcon(is_on ? icon_on_ : icon_off_);
}
Expand Down Expand Up @@ -120,8 +130,7 @@ void QuickActionItem::SetEnabled(bool enabled) {
} else {
label_->SetEnabledColor(AshColorProvider::Get()->GetContentLayerColor(
AshColorProvider::ContentLayerType::kTextColorPrimary));
sub_label_->SetEnabledColor(AshColorProvider::Get()->GetContentLayerColor(
AshColorProvider::ContentLayerType::kTextColorSecondary));
sub_label_->SetEnabledColor(sub_label_color_);
}
}

Expand Down
6 changes: 6 additions & 0 deletions ash/system/phonehub/quick_action_item.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ class ASH_EXPORT QuickActionItem : public views::View,
// Set the text of sub-label shown below the label.
void SetSubLabel(const base::string16& sub_label);

// Set the color of sub-label shown below the label.
void SetSubLabelColor(SkColor color);

// Set the icon button to be either |icon_on_| or |icon_off_|.
void SetIcon(bool is_on);

Expand Down Expand Up @@ -81,6 +84,9 @@ class ASH_EXPORT QuickActionItem : public views::View,
const gfx::VectorIcon& icon_off_;
views::Label* label_ = nullptr;
views::Label* sub_label_ = nullptr;

// Enabled color of the sub label.
SkColor sub_label_color_;
};

} // namespace ash
Expand Down

0 comments on commit c439739

Please sign in to comment.