Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(943)

Unified Diff: ui/message_center/views/notification_header_view.cc

Issue 2972493002: Implement time stamp in new-style notification. (Closed)
Patch Set: Fix UI strings. Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/message_center/views/notification_header_view.h ('k') | ui/message_center/views/notification_view_md.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/message_center/views/notification_header_view.cc
diff --git a/ui/message_center/views/notification_header_view.cc b/ui/message_center/views/notification_header_view.cc
index 8ce5827264a9184e91a7f5021eb499e4e2a8facd..4699b4faf45cd88cd49a893bc29f890841938f21 100644
--- a/ui/message_center/views/notification_header_view.cc
+++ b/ui/message_center/views/notification_header_view.cc
@@ -6,6 +6,7 @@
#include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h"
+#include "base/time/time.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/gfx/color_palette.h"
#include "ui/gfx/font_list.h"
@@ -34,7 +35,7 @@ constexpr gfx::Insets kHeaderPadding(0, 12, 0, 2);
constexpr int kHeaderHorizontalSpacing = 2;
constexpr int kAppInfoConatainerTopPadding = 12;
// Bullet character. The divider symbol between different parts of the header.
-constexpr base::char16 kNotificationHeaderDividerSymbol = 0x2022;
+constexpr wchar_t kNotificationHeaderDivider[] = L" \u2022 ";
// Base ink drop color of action buttons.
const SkColor kInkDropBaseColor = SkColorSetRGB(0x0, 0x0, 0x0);
@@ -43,6 +44,13 @@ constexpr float kInkDropRippleVisibleOpacity = 0.08f;
// Highlight (hover) ink drop opacity of action buttons.
constexpr float kInkDropHighlightVisibleOpacity = 0.08f;
+// base::TimeBase has similar constants, but some of them are missing.
+constexpr int64_t kMinuteInMillis = 60LL * 1000LL;
+constexpr int64_t kHourInMillis = 60LL * kMinuteInMillis;
+constexpr int64_t kDayInMillis = 24LL * kHourInMillis;
+// In Android, DateUtils.YEAR_IN_MILLIS is 364 days.
+constexpr int64_t kYearInMillis = 364LL * kDayInMillis;
+
// ExpandButtton forwards all mouse and key events to NotificationHeaderView,
// but takes tab focus for accessibility purpose.
class ExpandButton : public views::ImageView {
@@ -83,6 +91,35 @@ void ExpandButton::OnBlur() {
SchedulePaint();
}
+// Do relative time string formatting that is similar to
+// com.java.android.widget.DateTimeView.updateRelativeTime.
+// Chromium has its own base::TimeFormat::Simple(), but none of the formats
+// supported by the function is similar to Android's one.
+base::string16 FormatToRelativeTime(base::Time past) {
+ base::Time now = base::Time::Now();
+ int64_t duration = (now - past).InMilliseconds();
+ if (duration < kMinuteInMillis) {
+ return l10n_util::GetStringUTF16(
+ IDS_MESSAGE_NOTIFICATION_NOW_STRING_SHORTEST);
+ } else if (duration < kHourInMillis) {
+ int count = static_cast<int>(duration / kMinuteInMillis);
+ return l10n_util::GetPluralStringFUTF16(
+ IDS_MESSAGE_NOTIFICATION_DURATION_MINUTES_SHORTEST, count);
+ } else if (duration < kDayInMillis) {
+ int count = static_cast<int>(duration / kHourInMillis);
+ return l10n_util::GetPluralStringFUTF16(
+ IDS_MESSAGE_NOTIFICATION_DURATION_HOURS_SHORTEST, count);
+ } else if (duration < kYearInMillis) {
+ int count = static_cast<int>(duration / kDayInMillis);
+ return l10n_util::GetPluralStringFUTF16(
+ IDS_MESSAGE_NOTIFICATION_DURATION_DAYS_SHORTEST, count);
+ } else {
+ int count = static_cast<int>(duration / kYearInMillis);
+ return l10n_util::GetPluralStringFUTF16(
+ IDS_MESSAGE_NOTIFICATION_DURATION_YEARS_SHORTEST, count);
+ }
+}
+
} // namespace
NotificationHeaderView::NotificationHeaderView(views::ButtonListener* listener)
@@ -125,9 +162,7 @@ NotificationHeaderView::NotificationHeaderView(views::ButtonListener* listener)
// Summary text divider
summary_text_divider_ =
- new views::Label(base::ASCIIToUTF16(" ") +
- base::string16(1, kNotificationHeaderDividerSymbol) +
- base::ASCIIToUTF16(" "));
+ new views::Label(base::WideToUTF16(kNotificationHeaderDivider));
summary_text_divider_->SetFontList(font_list);
summary_text_divider_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
summary_text_divider_->SetVisible(false);
@@ -140,6 +175,21 @@ NotificationHeaderView::NotificationHeaderView(views::ButtonListener* listener)
summary_text_view_->SetVisible(false);
app_info_container->AddChildView(summary_text_view_);
+ // Timestamp divider
+ timestamp_divider_ =
+ new views::Label(base::WideToUTF16(kNotificationHeaderDivider));
+ timestamp_divider_->SetFontList(font_list);
+ timestamp_divider_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
+ timestamp_divider_->SetVisible(false);
+ app_info_container->AddChildView(timestamp_divider_);
+
+ // Timestamp view
+ timestamp_view_ = new views::Label(base::string16());
+ timestamp_view_->SetFontList(font_list);
+ timestamp_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
+ timestamp_view_->SetVisible(false);
+ app_info_container->AddChildView(timestamp_view_);
+
// Expand button view
expand_button_ = new ExpandButton();
app_info_container->AddChildView(expand_button_);
@@ -205,6 +255,17 @@ void NotificationHeaderView::ClearOverflowIndicator() {
UpdateSummaryTextVisibility();
}
+void NotificationHeaderView::SetTimestamp(base::Time past) {
+ timestamp_view_->SetText(FormatToRelativeTime(past));
+ has_timestamp_ = true;
+ UpdateSummaryTextVisibility();
+}
+
+void NotificationHeaderView::ClearTimestamp() {
+ has_timestamp_ = false;
+ UpdateSummaryTextVisibility();
+}
+
void NotificationHeaderView::SetExpandButtonEnabled(bool enabled) {
// SetInkDropMode iff. the visibility changed.
// Otherwise, the ink drop animation cannot finish.
@@ -290,6 +351,8 @@ void NotificationHeaderView::UpdateSummaryTextVisibility() {
const bool visible = has_progress_ || has_overflow_indicator_;
summary_text_divider_->SetVisible(visible);
summary_text_view_->SetVisible(visible);
+ timestamp_divider_->SetVisible(!has_progress_ && has_timestamp_);
+ timestamp_view_->SetVisible(!has_progress_ && has_timestamp_);
Layout();
}
« no previous file with comments | « ui/message_center/views/notification_header_view.h ('k') | ui/message_center/views/notification_view_md.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698