OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.chrome.browser.ntp.snippets; | 5 package org.chromium.chrome.browser.ntp.snippets; |
6 | 6 |
7 import android.annotation.SuppressLint; | 7 import android.annotation.SuppressLint; |
8 import android.content.res.ColorStateList; | 8 import android.content.res.ColorStateList; |
9 import android.graphics.Bitmap; | 9 import android.graphics.Bitmap; |
10 import android.graphics.drawable.BitmapDrawable; | 10 import android.graphics.drawable.BitmapDrawable; |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 private void updateLayout() { | 247 private void updateLayout() { |
248 final int horizontalStyle = mUiConfig.getCurrentDisplayStyle().horizonta
l; | 248 final int horizontalStyle = mUiConfig.getCurrentDisplayStyle().horizonta
l; |
249 final int verticalStyle = mUiConfig.getCurrentDisplayStyle().vertical; | 249 final int verticalStyle = mUiConfig.getCurrentDisplayStyle().vertical; |
250 final int layout = mCategoryInfo.getCardLayout(); | 250 final int layout = mCategoryInfo.getCardLayout(); |
251 | 251 |
252 boolean showHeadline = shouldShowHeadline(); | 252 boolean showHeadline = shouldShowHeadline(); |
253 boolean showDescription = shouldShowDescription(horizontalStyle, vertica
lStyle, layout); | 253 boolean showDescription = shouldShowDescription(horizontalStyle, vertica
lStyle, layout); |
254 boolean showThumbnail = shouldShowThumbnail(horizontalStyle, verticalSty
le, layout); | 254 boolean showThumbnail = shouldShowThumbnail(horizontalStyle, verticalSty
le, layout); |
255 | 255 |
256 mHeadlineTextView.setVisibility(showHeadline ? View.VISIBLE : View.GONE)
; | 256 mHeadlineTextView.setVisibility(showHeadline ? View.VISIBLE : View.GONE)
; |
| 257 mHeadlineTextView.setMaxLines(getHeaderMaxLines(horizontalStyle, vertica
lStyle, layout)); |
257 mArticleSnippetTextView.setVisibility(showDescription ? View.VISIBLE : V
iew.GONE); | 258 mArticleSnippetTextView.setVisibility(showDescription ? View.VISIBLE : V
iew.GONE); |
258 mThumbnailView.setVisibility(showThumbnail ? View.VISIBLE : View.GONE); | 259 mThumbnailView.setVisibility(showThumbnail ? View.VISIBLE : View.GONE); |
259 | 260 |
260 ViewGroup.MarginLayoutParams publisherBarParams = | 261 ViewGroup.MarginLayoutParams publisherBarParams = |
261 (ViewGroup.MarginLayoutParams) mPublisherBar.getLayoutParams(); | 262 (ViewGroup.MarginLayoutParams) mPublisherBar.getLayoutParams(); |
262 | 263 |
263 if (showDescription) { | 264 if (showDescription) { |
264 publisherBarParams.topMargin = mPublisherBar.getResources().getDimen
sionPixelSize( | 265 publisherBarParams.topMargin = mPublisherBar.getResources().getDimen
sionPixelSize( |
265 R.dimen.snippets_publisher_margin_top_with_article_snippet); | 266 R.dimen.snippets_publisher_margin_top_with_article_snippet); |
266 } else if (showHeadline) { | 267 } else if (showHeadline) { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 return ChromeFeatureList.isEnabled(ChromeFeatureList.CONTENT_SUGGESTIONS
_SHOW_SUMMARY); | 300 return ChromeFeatureList.isEnabled(ChromeFeatureList.CONTENT_SUGGESTIONS
_SHOW_SUMMARY); |
300 } | 301 } |
301 | 302 |
302 private boolean shouldShowThumbnail(int horizontalStyle, int verticalStyle,
int layout) { | 303 private boolean shouldShowThumbnail(int horizontalStyle, int verticalStyle,
int layout) { |
303 // Minimal cards don't have a thumbnail | 304 // Minimal cards don't have a thumbnail |
304 if (layout == ContentSuggestionsCardLayout.MINIMAL_CARD) return false; | 305 if (layout == ContentSuggestionsCardLayout.MINIMAL_CARD) return false; |
305 | 306 |
306 return true; | 307 return true; |
307 } | 308 } |
308 | 309 |
| 310 /** |
| 311 * If no summary (no description) is shown, allow more lines for the header
(title). |
| 312 * @return The maximum number of header text lines. |
| 313 */ |
| 314 private int getHeaderMaxLines(int horizontalStyle, int verticalStyle, int la
yout) { |
| 315 return shouldShowDescription(horizontalStyle, verticalStyle, layout) ? 2
: 3; |
| 316 } |
| 317 |
309 private static String getPublisherString(SnippetArticle article) { | 318 private static String getPublisherString(SnippetArticle article) { |
310 // We format the publisher here so that having a publisher name in an RT
L language | 319 // We format the publisher here so that having a publisher name in an RT
L language |
311 // doesn't mess up the formatting on an LTR device and vice versa. | 320 // doesn't mess up the formatting on an LTR device and vice versa. |
312 return BidiFormatter.getInstance().unicodeWrap(article.mPublisher); | 321 return BidiFormatter.getInstance().unicodeWrap(article.mPublisher); |
313 } | 322 } |
314 | 323 |
315 private static String getArticleAge(SnippetArticle article) { | 324 private static String getArticleAge(SnippetArticle article) { |
316 if (article.mPublishTimestampMilliseconds == 0) return ""; | 325 if (article.mPublishTimestampMilliseconds == 0) return ""; |
317 | 326 |
318 // DateUtils.getRelativeTimeSpanString(...) calls through to TimeZone.ge
tDefault(). If this | 327 // DateUtils.getRelativeTimeSpanString(...) calls through to TimeZone.ge
tDefault(). If this |
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
632 * Callback to refresh the offline badge visibility. | 641 * Callback to refresh the offline badge visibility. |
633 */ | 642 */ |
634 public static class RefreshOfflineBadgeVisibilityCallback extends PartialBin
dCallback { | 643 public static class RefreshOfflineBadgeVisibilityCallback extends PartialBin
dCallback { |
635 @Override | 644 @Override |
636 public void onResult(NewTabPageViewHolder holder) { | 645 public void onResult(NewTabPageViewHolder holder) { |
637 assert holder instanceof SnippetArticleViewHolder; | 646 assert holder instanceof SnippetArticleViewHolder; |
638 ((SnippetArticleViewHolder) holder).refreshOfflineBadgeVisibility(); | 647 ((SnippetArticleViewHolder) holder).refreshOfflineBadgeVisibility(); |
639 } | 648 } |
640 } | 649 } |
641 } | 650 } |
OLD | NEW |