| Index: chrome/android/java/src/org/chromium/chrome/browser/suggestions/Tile.java
|
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/ntp/MostVisitedItem.java b/chrome/android/java/src/org/chromium/chrome/browser/suggestions/Tile.java
|
| similarity index 30%
|
| rename from chrome/android/java/src/org/chromium/chrome/browser/ntp/MostVisitedItem.java
|
| rename to chrome/android/java/src/org/chromium/chrome/browser/suggestions/Tile.java
|
| index 06824fb4fcfb7391c78f2fca0ac1877c9599db73..508fd4bfa1c8d7ed72b2b4449b6fef63038713aa 100644
|
| --- a/chrome/android/java/src/org/chromium/chrome/browser/ntp/MostVisitedItem.java
|
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/suggestions/Tile.java
|
| @@ -2,95 +2,56 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -package org.chromium.chrome.browser.ntp;
|
| +package org.chromium.chrome.browser.suggestions;
|
|
|
| -import android.view.ContextMenu;
|
| -import android.view.ContextMenu.ContextMenuInfo;
|
| -import android.view.View;
|
| -import android.view.View.OnClickListener;
|
| -import android.view.View.OnCreateContextMenuListener;
|
| +import android.graphics.drawable.Drawable;
|
| +import android.support.annotation.Nullable;
|
|
|
| -import org.chromium.chrome.browser.ntp.ContextMenuManager.ContextMenuItemId;
|
| -import org.chromium.chrome.browser.ntp.NewTabPageView.NewTabPageManager;
|
| -import org.chromium.ui.mojom.WindowOpenDisposition;
|
| +import org.chromium.chrome.browser.ntp.MostVisitedTileType;
|
|
|
| /**
|
| - * Displays the title, thumbnail, and favicon of a most visited page. The item can be clicked, or
|
| - * long-pressed to trigger a context menu with options to "open in new tab", "open in incognito
|
| - * tab", or "remove".
|
| + * Holds the details of a site tile.
|
| */
|
| -public class MostVisitedItem implements OnCreateContextMenuListener, OnClickListener {
|
| - /**
|
| - * Interface for an object that handles callbacks from a MostVisitedItem.
|
| - */
|
| - public interface MostVisitedItemManager {
|
| - void removeMostVisitedItem(MostVisitedItem item);
|
| -
|
| - void openMostVisitedItem(int windowDisposition, MostVisitedItem item);
|
| - }
|
| -
|
| - private NewTabPageManager mManager;
|
| - private String mTitle;
|
| - private String mUrl;
|
| - private String mWhitelistIconPath;
|
| - private boolean mOfflineAvailable;
|
| +public class Tile {
|
| + private final String mTitle;
|
| + private final String mUrl;
|
| + private final String mWhitelistIconPath;
|
| + private final boolean mOfflineAvailable;
|
| private int mIndex;
|
| - private int mTileType;
|
| - private int mSource;
|
| - private View mView;
|
| + private int mTileType = MostVisitedTileType.NONE;
|
| + private final int mSource;
|
| +
|
| + @Nullable
|
| + private Drawable mIcon;
|
|
|
| /**
|
| - * Constructs a MostVisitedItem with the given manager, title, URL, whitelist icon path, index,
|
| - * and view.
|
| - *
|
| - * @param manager The NewTabPageManager used to handle clicks and context menu events.
|
| * @param title The title of the page.
|
| * @param url The URL of the page.
|
| - * @param whitelistIconPath The path to the icon image file, if this is a whitelisted most
|
| - * visited item. Empty otherwise.
|
| + * @param whitelistIconPath The path to the icon image file, if this is a whitelisted tile.
|
| + * Empty otherwise.
|
| * @param offlineAvailable Whether there is an offline copy of the URL available.
|
| - * @param index The index of this item in the list of most visited items.
|
| - * @param source The {@code MostVisitedSource} that generated this item.
|
| + * @param index The index of this tile in the list of tiles.
|
| + * @param source The {@code MostVisitedSource} that generated this tile.
|
| */
|
| - public MostVisitedItem(NewTabPageManager manager, String title, String url,
|
| - String whitelistIconPath, boolean offlineAvailable, int index, int source) {
|
| - mManager = manager;
|
| + public Tile(String title, String url, String whitelistIconPath, boolean offlineAvailable,
|
| + int index, int source) {
|
| mTitle = title;
|
| mUrl = url;
|
| mWhitelistIconPath = whitelistIconPath;
|
| mOfflineAvailable = offlineAvailable;
|
| mIndex = index;
|
| - mTileType = MostVisitedTileType.NONE;
|
| mSource = source;
|
| }
|
|
|
| /**
|
| - * Sets the view that will display this item. MostVisitedItem will handle clicks on the view.
|
| - * This should be called exactly once.
|
| - */
|
| - public void initView(View view) {
|
| - assert mView == null;
|
| - mView = view;
|
| - mView.setOnClickListener(this);
|
| - mView.setOnCreateContextMenuListener(this);
|
| - }
|
| -
|
| - /**
|
| - * @return The view representing this item.
|
| - */
|
| - public View getView() {
|
| - return mView;
|
| - }
|
| -
|
| - /**
|
| - * @return The URL of this most visited item.
|
| + * @return The URL of this tile.
|
| */
|
| public String getUrl() {
|
| return mUrl;
|
| }
|
|
|
| /**
|
| - * @return The title of this most visited item.
|
| + * @return The title of this tile.
|
| */
|
| public String getTitle() {
|
| return mTitle;
|
| @@ -104,28 +65,28 @@ public class MostVisitedItem implements OnCreateContextMenuListener, OnClickList
|
| }
|
|
|
| /**
|
| - * @return Whether this item is available offline.
|
| + * @return Whether this tile is available offline.
|
| */
|
| public boolean isOfflineAvailable() {
|
| return mOfflineAvailable;
|
| }
|
|
|
| /**
|
| - * @return The index of this MostVisitedItem in the list of MostVisitedItems.
|
| + * @return The index of this tile in the list of tiles.
|
| */
|
| public int getIndex() {
|
| return mIndex;
|
| }
|
|
|
| /**
|
| - * Updates this item's index in the list of most visited items.
|
| + * Updates this tile's index in the list of tiles.
|
| */
|
| public void setIndex(int index) {
|
| mIndex = index;
|
| }
|
|
|
| /**
|
| - * @return The visual type of this most visited item. Valid values are listed in
|
| + * @return The visual type of this tile. Valid values are listed in
|
| * {@link MostVisitedTileType}.
|
| */
|
| public int getTileType() {
|
| @@ -133,7 +94,7 @@ public class MostVisitedItem implements OnCreateContextMenuListener, OnClickList
|
| }
|
|
|
| /**
|
| - * Sets the visual type of this most visited item. Valid values are listed in
|
| + * Sets the visual type of this tile. Valid values are listed in
|
| * {@link MostVisitedTileType}.
|
| */
|
| public void setTileType(int type) {
|
| @@ -141,44 +102,25 @@ public class MostVisitedItem implements OnCreateContextMenuListener, OnClickList
|
| }
|
|
|
| /**
|
| - * @return The source of this item. Used for metrics tracking. Valid values are listed in
|
| + * @return The source of this tile. Used for metrics tracking. Valid values are listed in
|
| * {@code MostVisitedSource}.
|
| */
|
| public int getSource() {
|
| return mSource;
|
| }
|
|
|
| - @Override
|
| - public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
|
| - mManager.getContextMenuManager().createContextMenu(
|
| - menu, v, new ContextMenuManager.Delegate() {
|
| - @Override
|
| - public void openItem(int windowDisposition) {
|
| - mManager.openMostVisitedItem(windowDisposition, MostVisitedItem.this);
|
| - }
|
| -
|
| - @Override
|
| - public void removeItem() {
|
| - mManager.removeMostVisitedItem(MostVisitedItem.this);
|
| - }
|
| -
|
| - @Override
|
| - public String getUrl() {
|
| - return MostVisitedItem.this.getUrl();
|
| - }
|
| -
|
| - @Override
|
| - public boolean isItemSupported(@ContextMenuItemId int menuItemId) {
|
| - return true;
|
| - }
|
| -
|
| - @Override
|
| - public void onContextMenuCreated() {}
|
| - });
|
| + /**
|
| + * @return The icon, may be null.
|
| + */
|
| + @Nullable
|
| + public Drawable getIcon() {
|
| + return mIcon;
|
| }
|
|
|
| - @Override
|
| - public void onClick(View v) {
|
| - mManager.openMostVisitedItem(WindowOpenDisposition.CURRENT_TAB, MostVisitedItem.this);
|
| + /**
|
| + * Updates the icon drawable.
|
| + */
|
| + public void setIcon(@Nullable Drawable icon) {
|
| + mIcon = icon;
|
| }
|
| }
|
|
|