Commit 900f4106 authored by Cathy Li's avatar Cathy Li Committed by Commit Bot

[Explore sites]: Fix crash caused by race condition between when explore sites...

[Explore sites]: Fix crash caused by race condition between when explore sites section parent is added to the view and when we grab the width of the parent.

Change-Id: Ia9244aa14424a7661befb4802c2f9536edeb2baf
Reviewed-on: https://chromium-review.googlesource.com/1112723Reviewed-by: default avatarDmitry Titov <dimich@chromium.org>
Commit-Queue: Cathy Li <chili@chromium.org>
Cr-Commit-Position: refs/heads/master@{#569854}
parent 44982312
......@@ -49,11 +49,12 @@ public class ExploreSitesCategoryTileView extends LinearLayout {
mIconView = findViewById(R.id.explore_sites_category_tile_icon);
}
public void initialize(ExploreSitesCategoryTile category, int widthPx, int heightPx) {
public void initialize(ExploreSitesCategoryTile category, int widthPx) {
mCategoryData = category;
mIconWidthPx = widthPx;
mIconHeightPx = heightPx;
mIconGenerator = new RoundedIconGenerator(widthPx, heightPx,
mIconWidthPx =
widthPx - (2 * mResources.getDimensionPixelSize(R.dimen.explore_sites_padding));
mIconHeightPx = mIconWidthPx * 2 / 3;
mIconGenerator = new RoundedIconGenerator(mIconWidthPx, mIconHeightPx,
mResources.getDimensionPixelSize(R.dimen.explore_sites_radius),
ApiCompatibilityUtils.getColor(
mResources, R.color.default_favicon_background_color),
......
......@@ -4,9 +4,12 @@
package org.chromium.chrome.browser.explore_sites;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Point;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.LinearLayout;
import org.chromium.chrome.R;
......@@ -51,13 +54,11 @@ public class ExploreSitesSection {
private void initializeTiles(List<ExploreSitesCategoryTile> tileList) {
if (tileList == null) return;
int parentWidth = mExploreSection.getWidth();
int tileWidth = (parentWidth
- (mExploreSection.getResources().getDimensionPixelSize(
R.dimen.explore_sites_padding)
* 2))
/ MAX_TILES;
int tileHeight = tileWidth / 3 * 2;
Point screenSize = new Point();
((WindowManager) mExploreSection.getContext().getSystemService(Context.WINDOW_SERVICE))
.getDefaultDisplay()
.getSize(screenSize);
int tileWidth = screenSize.x / MAX_TILES;
int tileCount = 0;
for (final ExploreSitesCategoryTile tile : tileList) {
......@@ -69,7 +70,8 @@ public class ExploreSitesSection {
(ExploreSitesCategoryTileView) LayoutInflater.from(mExploreSection.getContext())
.inflate(R.layout.explore_sites_category_tile_view, mCategorySection,
false);
tileView.initialize(tile, tileWidth, tileHeight);
tileView.initialize(tile, tileWidth);
mCategorySection.addView(tileView);
tileView.setOnClickListener(
(View v)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment