| 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.suggestions; | 5 package org.chromium.chrome.browser.suggestions; |
| 6 | 6 |
| 7 import android.content.Context; | 7 import android.content.Context; |
| 8 import android.content.res.Resources; |
| 8 import android.util.AttributeSet; | 9 import android.util.AttributeSet; |
| 10 import android.view.View; |
| 9 import android.widget.FrameLayout; | 11 import android.widget.FrameLayout; |
| 10 import android.widget.ImageView; | 12 import android.widget.ImageView; |
| 11 import android.widget.TextView; | 13 import android.widget.TextView; |
| 12 | 14 |
| 13 import org.chromium.chrome.R; | 15 import org.chromium.chrome.R; |
| 14 import org.chromium.chrome.browser.ntp.TitleUtil; | 16 import org.chromium.chrome.browser.ntp.TitleUtil; |
| 15 | 17 |
| 16 /** | 18 /** |
| 17 * The view for a site suggestion tile. Displays the title of the site beneath a
large icon. If a | 19 * The view for a site suggestion tile. Displays the title of the site beneath a
large icon. If a |
| 18 * large icon isn't available, displays a rounded rectangle with a single letter
in its place. | 20 * large icon isn't available, displays a rounded rectangle with a single letter
in its place. |
| (...skipping 20 matching lines...) Expand all Loading... |
| 39 mTitleView = (TextView) findViewById(R.id.tile_view_title); | 41 mTitleView = (TextView) findViewById(R.id.tile_view_title); |
| 40 mIconView = (ImageView) findViewById(R.id.tile_view_icon); | 42 mIconView = (ImageView) findViewById(R.id.tile_view_icon); |
| 41 mBadgeView = (ImageView) findViewById(R.id.offline_badge); | 43 mBadgeView = (ImageView) findViewById(R.id.offline_badge); |
| 42 } | 44 } |
| 43 | 45 |
| 44 /** | 46 /** |
| 45 * Initializes the view using the data held by {@code tile}. This should be
called immediately | 47 * Initializes the view using the data held by {@code tile}. This should be
called immediately |
| 46 * after inflation. | 48 * after inflation. |
| 47 * @param tile The tile that holds the data to populate this view. | 49 * @param tile The tile that holds the data to populate this view. |
| 48 * @param titleLines The number of text lines to use for the tile title. | 50 * @param titleLines The number of text lines to use for the tile title. |
| 51 * @param condensed Whether to use a condensed layout. |
| 49 */ | 52 */ |
| 50 public void initialize(Tile tile, int titleLines) { | 53 public void initialize(Tile tile, int titleLines, boolean condensed) { |
| 51 mTitleView.setLines(titleLines); | 54 mTitleView.setLines(titleLines); |
| 52 mUrl = tile.getUrl(); | 55 mUrl = tile.getUrl(); |
| 56 |
| 57 // TODO(mvanouwerkerk): Move this code to xml - https://crbug.com/695817
. |
| 58 if (condensed) { |
| 59 Resources res = getResources(); |
| 60 |
| 61 setPadding(0, 0, 0, 0); |
| 62 LayoutParams tileParams = (LayoutParams) getLayoutParams(); |
| 63 tileParams.width = res.getDimensionPixelOffset(R.dimen.tile_view_wid
th_condensed); |
| 64 setLayoutParams(tileParams); |
| 65 |
| 66 LayoutParams iconParams = (LayoutParams) mIconView.getLayoutParams()
; |
| 67 iconParams.setMargins(0, |
| 68 res.getDimensionPixelOffset(R.dimen.tile_view_icon_margin_to
p_condensed), 0, 0); |
| 69 mIconView.setLayoutParams(iconParams); |
| 70 |
| 71 View highlightView = findViewById(R.id.tile_view_highlight); |
| 72 LayoutParams highlightParams = (LayoutParams) highlightView.getLayou
tParams(); |
| 73 highlightParams.setMargins(0, |
| 74 res.getDimensionPixelOffset(R.dimen.tile_view_icon_margin_to
p_condensed), 0, 0); |
| 75 highlightView.setLayoutParams(highlightParams); |
| 76 |
| 77 LayoutParams titleParams = (LayoutParams) mTitleView.getLayoutParams
(); |
| 78 titleParams.setMargins(0, |
| 79 res.getDimensionPixelOffset(R.dimen.tile_view_title_margin_t
op_condensed), 0, |
| 80 0); |
| 81 mTitleView.setLayoutParams(titleParams); |
| 82 } |
| 83 |
| 53 renderTile(tile); | 84 renderTile(tile); |
| 54 } | 85 } |
| 55 | 86 |
| 56 /** @return The url associated to this view. */ | 87 /** @return The url associated with this view. */ |
| 57 public String getUrl() { | 88 public String getUrl() { |
| 58 return mUrl; | 89 return mUrl; |
| 59 } | 90 } |
| 60 | 91 |
| 61 /** | 92 /** |
| 62 * Renders the icon held by the {@link Tile} or clears it from the view if t
he icon is null. | 93 * Renders the icon held by the {@link Tile} or clears it from the view if t
he icon is null. |
| 63 */ | 94 */ |
| 64 public void renderIcon(Tile tile) { | 95 public void renderIcon(Tile tile) { |
| 65 mIconView.setImageDrawable(tile.getIcon()); | 96 mIconView.setImageDrawable(tile.getIcon()); |
| 66 } | 97 } |
| (...skipping 19 matching lines...) Expand all Loading... |
| 86 | 117 |
| 87 private void renderTile(Tile tile) { | 118 private void renderTile(Tile tile) { |
| 88 // A TileView should not be reused across tiles having different urls, a
s registered | 119 // A TileView should not be reused across tiles having different urls, a
s registered |
| 89 // callbacks and handlers use it to look up the data and notify the rest
of the system. | 120 // callbacks and handlers use it to look up the data and notify the rest
of the system. |
| 90 assert mUrl.equals(tile.getUrl()); | 121 assert mUrl.equals(tile.getUrl()); |
| 91 mTitleView.setText(TitleUtil.getTitleForDisplay(tile.getTitle(), tile.ge
tUrl())); | 122 mTitleView.setText(TitleUtil.getTitleForDisplay(tile.getTitle(), tile.ge
tUrl())); |
| 92 renderOfflineBadge(tile); | 123 renderOfflineBadge(tile); |
| 93 renderIcon(tile); | 124 renderIcon(tile); |
| 94 } | 125 } |
| 95 } | 126 } |
| OLD | NEW |