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.Resources; | 8 import android.content.res.Resources; |
9 import android.graphics.Bitmap; | 9 import android.graphics.Bitmap; |
10 import android.graphics.drawable.BitmapDrawable; | 10 import android.graphics.drawable.BitmapDrawable; |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
178 : R.dimen.snippets_publisher_margin_top_with_article _snippet); | 178 : R.dimen.snippets_publisher_margin_top_with_article _snippet); |
179 | 179 |
180 params.setMargins(params.leftMargin, | 180 params.setMargins(params.leftMargin, |
181 topMargin, | 181 topMargin, |
182 params.rightMargin, | 182 params.rightMargin, |
183 params.bottomMargin); | 183 params.bottomMargin); |
184 | 184 |
185 mPublisherBar.setLayoutParams(params); | 185 mPublisherBar.setLayoutParams(params); |
186 } | 186 } |
187 | 187 |
188 public String getAttributionString(SnippetArticle article) { | |
Michael van Ouwerkerk
2016/12/22 10:55:28
Can this method be private?
vitaliii
2016/12/22 12:39:01
Done.
private static
| |
189 if (article.mPublishTimestampMilliseconds == 0) return article.mPublishe r; | |
190 | |
191 // DateUtils.getRelativeTimeSpanString(...) calls through to TimeZone.ge tDefault(). If this | |
192 // has never been called before it loads the current time zone from disk . In most likelihood | |
193 // this will have been called previously and the current time zone will have been cached, | |
194 // but in some cases (eg instrumentation tests) it will cause a strict m ode violation. | |
195 StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); | |
196 long time = SystemClock.elapsedRealtime(); | |
197 CharSequence relativeTimeSpan; | |
198 try { | |
199 relativeTimeSpan = | |
200 DateUtils.getRelativeTimeSpanString(mArticle.mPublishTimesta mpMilliseconds, | |
201 System.currentTimeMillis(), DateUtils.MINUTE_IN_MILL IS); | |
202 } finally { | |
203 StrictMode.setThreadPolicy(oldPolicy); | |
204 } | |
205 | |
206 RecordHistogram.recordTimesHistogram("Android.StrictMode.SnippetUIBuildT ime", | |
Michael van Ouwerkerk
2016/12/22 10:55:28
Moving this histogram recording further down may a
vitaliii
2016/12/22 12:39:01
Done.
| |
207 SystemClock.elapsedRealtime() - time, TimeUnit.MILLISECONDS); | |
208 | |
209 // We format the publisher here so that having a publisher name in an RT L language | |
210 // doesn't mess up the formatting on an LTR device and vice versa. | |
211 return String.format(PUBLISHER_FORMAT_STRING, | |
212 BidiFormatter.getInstance().unicodeWrap(mArticle.mPublisher), re lativeTimeSpan); | |
213 } | |
214 | |
188 public void onBindViewHolder(SnippetArticle article, SuggestionsCategoryInfo categoryInfo) { | 215 public void onBindViewHolder(SnippetArticle article, SuggestionsCategoryInfo categoryInfo) { |
189 super.onBindViewHolder(); | 216 super.onBindViewHolder(); |
190 | 217 |
191 // No longer listen for offline status changes to the old article. | 218 // No longer listen for offline status changes to the old article. |
192 if (mArticle != null) mArticle.setOfflineStatusChangeRunnable(null); | 219 if (mArticle != null) mArticle.setOfflineStatusChangeRunnable(null); |
193 | 220 |
194 mArticle = article; | 221 mArticle = article; |
195 mCategoryInfo = categoryInfo; | 222 mCategoryInfo = categoryInfo; |
196 updateLayout(); | 223 updateLayout(); |
197 | 224 |
198 mHeadlineTextView.setText(mArticle.mTitle); | 225 mHeadlineTextView.setText(mArticle.mTitle); |
199 | 226 mPublisherTextView.setText(getAttributionString(mArticle)); |
200 // DateUtils.getRelativeTimeSpanString(...) calls through to TimeZone.ge tDefault(). If this | |
201 // has never been called before it loads the current time zone from disk . In most likelihood | |
202 // this will have been called previously and the current time zone will have been cached, | |
203 // but in some cases (eg instrumentation tests) it will cause a strict m ode violation. | |
204 StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); | |
205 try { | |
206 long time = SystemClock.elapsedRealtime(); | |
207 CharSequence relativeTimeSpan = DateUtils.getRelativeTimeSpanString( | |
208 mArticle.mPublishTimestampMilliseconds, System.currentTimeMi llis(), | |
209 DateUtils.MINUTE_IN_MILLIS); | |
210 RecordHistogram.recordTimesHistogram("Android.StrictMode.SnippetUIBu ildTime", | |
211 SystemClock.elapsedRealtime() - time, TimeUnit.MILLISECONDS) ; | |
212 | |
213 // We format the publisher here so that having a publisher name in a n RTL language | |
214 // doesn't mess up the formatting on an LTR device and vice versa. | |
215 String publisherAttribution = String.format(PUBLISHER_FORMAT_STRING, | |
216 BidiFormatter.getInstance().unicodeWrap(mArticle.mPublisher) , relativeTimeSpan); | |
217 mPublisherTextView.setText(publisherAttribution); | |
218 } finally { | |
219 StrictMode.setThreadPolicy(oldPolicy); | |
220 } | |
221 | 227 |
222 // The favicon of the publisher should match the TextView height. | 228 // The favicon of the publisher should match the TextView height. |
223 int widthSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED); | 229 int widthSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED); |
224 int heightSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED) ; | 230 int heightSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED) ; |
225 mPublisherTextView.measure(widthSpec, heightSpec); | 231 mPublisherTextView.measure(widthSpec, heightSpec); |
226 mPublisherFaviconSizePx = mPublisherTextView.getMeasuredHeight(); | 232 mPublisherFaviconSizePx = mPublisherTextView.getMeasuredHeight(); |
227 | 233 |
228 mArticleSnippetTextView.setText(mArticle.mPreviewText); | 234 mArticleSnippetTextView.setText(mArticle.mPreviewText); |
229 | 235 |
230 // If there's still a pending thumbnail fetch, cancel it. | 236 // If there's still a pending thumbnail fetch, cancel it. |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
387 ApiCompatibilityUtils.setCompoundDrawablesRelative( | 393 ApiCompatibilityUtils.setCompoundDrawablesRelative( |
388 mPublisherTextView, drawable, null, null, null); | 394 mPublisherTextView, drawable, null, null, null); |
389 mPublisherTextView.setVisibility(View.VISIBLE); | 395 mPublisherTextView.setVisibility(View.VISIBLE); |
390 } | 396 } |
391 | 397 |
392 @Override | 398 @Override |
393 public boolean isDismissable() { | 399 public boolean isDismissable() { |
394 return !isPeeking(); | 400 return !isPeeking(); |
395 } | 401 } |
396 } | 402 } |
OLD | NEW |