Chromium Code Reviews| 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; |
| 9 import android.view.View; | 10 import android.view.View; |
| 10 import android.widget.FrameLayout; | 11 import android.widget.FrameLayout; |
| 11 import android.widget.ImageView; | 12 import android.widget.ImageView; |
| 12 import android.widget.TextView; | 13 import android.widget.TextView; |
| 13 | 14 |
| 14 import org.chromium.chrome.R; | 15 import org.chromium.chrome.R; |
| 15 import org.chromium.chrome.browser.ntp.TitleUtil; | 16 import org.chromium.chrome.browser.ntp.TitleUtil; |
| 16 | 17 |
| 17 /** | 18 /** |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 29 */ | 30 */ |
| 30 public TileView(Context context, AttributeSet attrs) { | 31 public TileView(Context context, AttributeSet attrs) { |
| 31 super(context, attrs); | 32 super(context, attrs); |
| 32 } | 33 } |
| 33 | 34 |
| 34 /** | 35 /** |
| 35 * Initializes the view using the data held by {@code tile}. This should be called immediately | 36 * Initializes the view using the data held by {@code tile}. This should be called immediately |
| 36 * after inflation. | 37 * after inflation. |
| 37 * @param tile The tile that holds the data to populate this view. | 38 * @param tile The tile that holds the data to populate this view. |
| 38 * @param titleLines The number of text lines to use for the tile title. | 39 * @param titleLines The number of text lines to use for the tile title. |
| 40 * @param condensed Whether to use a condensed layout. | |
| 39 */ | 41 */ |
| 40 public void initialize(Tile tile, int titleLines) { | 42 public void initialize(Tile tile, int titleLines, boolean condensed) { |
| 41 mTile = tile; | 43 mTile = tile; |
| 42 TextView titleView = (TextView) findViewById(R.id.tile_view_title); | 44 TextView titleView = (TextView) findViewById(R.id.tile_view_title); |
| 43 titleView.setLines(titleLines); | 45 titleView.setLines(titleLines); |
| 44 titleView.setText(TitleUtil.getTitleForDisplay(mTile.getTitle(), mTile.g etUrl())); | 46 titleView.setText(TitleUtil.getTitleForDisplay(mTile.getTitle(), mTile.g etUrl())); |
| 45 renderIcon(); | 47 renderIcon(); |
| 46 findViewById(R.id.offline_badge) | 48 findViewById(R.id.offline_badge) |
| 47 .setVisibility(mTile.isOfflineAvailable() ? View.VISIBLE : View. GONE); | 49 .setVisibility(mTile.isOfflineAvailable() ? View.VISIBLE : View. GONE); |
| 50 | |
| 51 if (!condensed) return; | |
| 52 | |
| 53 Resources res = getResources(); | |
| 54 | |
| 55 setPadding(0, 0, 0, 0); | |
|
dgn
2017/02/23 15:17:44
it would be nice to have a todo with a bug to move
Michael van Ouwerkerk
2017/02/24 11:31:19
Done.
| |
| 56 LayoutParams tileParams = (LayoutParams) getLayoutParams(); | |
| 57 tileParams.width = res.getDimensionPixelOffset(R.dimen.tile_view_width_c ondensed); | |
| 58 setLayoutParams(tileParams); | |
| 59 | |
| 60 View iconView = findViewById(R.id.tile_view_icon); | |
| 61 LayoutParams iconParams = (LayoutParams) iconView.getLayoutParams(); | |
| 62 iconParams.setMargins( | |
|
dgn
2017/02/23 15:17:44
is it only the padding that gets reset when the im
Michael van Ouwerkerk
2017/02/24 11:31:19
I haven't seen any problems with this. Looking at
| |
| 63 0, res.getDimensionPixelOffset(R.dimen.tile_view_icon_margin_top _condensed), 0, 0); | |
| 64 iconView.setLayoutParams(iconParams); | |
| 65 | |
| 66 View highlightView = findViewById(R.id.tile_view_highlight); | |
| 67 LayoutParams highlightParams = (LayoutParams) highlightView.getLayoutPar ams(); | |
| 68 highlightParams.setMargins( | |
| 69 0, res.getDimensionPixelOffset(R.dimen.tile_view_icon_margin_top _condensed), 0, 0); | |
| 70 highlightView.setLayoutParams(highlightParams); | |
| 71 | |
| 72 LayoutParams titleParams = (LayoutParams) titleView.getLayoutParams(); | |
| 73 titleParams.setMargins( | |
| 74 0, res.getDimensionPixelOffset(R.dimen.tile_view_title_margin_to p_condensed), 0, 0); | |
| 75 titleView.setLayoutParams(titleParams); | |
| 48 } | 76 } |
| 49 | 77 |
| 50 /** | 78 /** |
| 51 * @return The tile that holds the data to populate this view. | 79 * @return The tile that holds the data to populate this view. |
| 52 */ | 80 */ |
| 53 public Tile getTile() { | 81 public Tile getTile() { |
| 54 return mTile; | 82 return mTile; |
| 55 } | 83 } |
| 56 | 84 |
| 57 /** | 85 /** |
| 58 * Renders the icon held by the {@link Tile} or clears it from the view if t he icon is null. | 86 * Renders the icon held by the {@link Tile} or clears it from the view if t he icon is null. |
| 59 */ | 87 */ |
| 60 public void renderIcon() { | 88 public void renderIcon() { |
| 61 ((ImageView) findViewById(R.id.tile_view_icon)).setImageDrawable(mTile.g etIcon()); | 89 ((ImageView) findViewById(R.id.tile_view_icon)).setImageDrawable(mTile.g etIcon()); |
| 62 } | 90 } |
| 63 } | 91 } |
| OLD | NEW |