Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(256)

Side by Side Diff: chrome/android/java_staging/src/org/chromium/chrome/browser/ntp/MostVisitedItem.java

Issue 1141283003: Upstream oodles of Chrome for Android code into Chromium. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: final patch? Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 package org.chromium.chrome.browser.ntp;
6
7 import android.view.ContextMenu;
8 import android.view.ContextMenu.ContextMenuInfo;
9 import android.view.MenuItem;
10 import android.view.MenuItem.OnMenuItemClickListener;
11 import android.view.View;
12 import android.view.View.OnClickListener;
13 import android.view.View.OnCreateContextMenuListener;
14
15 /**
16 * Displays the title, thumbnail, and favicon of a most visited page. The item c an be clicked, or
17 * long-pressed to trigger a context menu with options to "open in new tab", "op en in incognito
18 * tab", or "remove".
19 */
20 public class MostVisitedItem implements OnCreateContextMenuListener,
21 MenuItem.OnMenuItemClickListener, OnClickListener {
22
23 private MostVisitedItemManager mManager;
24 private String mTitle;
25 private String mUrl;
26 private int mIndex;
27 private View mView;
28
29 /**
30 * Interface for an object that handles callbacks from a MostVisitedItem.
31 */
32 public interface MostVisitedItemManager {
33 /**
34 * Navigates to a most visited page in the existing tab.
35 * @param item The most visited item to open.
36 */
37 void open(MostVisitedItem item);
38
39 /**
40 * Allows the manager to add context menu items for a given MostVisitedI tem.
41 * @param menu The context menu that should be used to add menu items.
42 * @param listener Listener that should get the callbacks for context me nu selections.
43 */
44 void onCreateContextMenu(ContextMenu menu, OnMenuItemClickListener liste ner);
45
46 /**
47 * Handles context menu item clicks.
48 * @param menuId Id of the menu item that was selected.
49 * @param item MostVisitedItem that triggered the context menu.
50 * @return Whether a menu item was selected successfully.
51 */
52 boolean onMenuItemClick(int menuId, MostVisitedItem item);
53 }
54
55 /**
56 * Constructs a MostVisitedItem with the given manager, title, URL, index, a nd view.
57 *
58 * @param manager The NewTabPageManager used to handle clicks and context me nu events.
59 * @param title The title of the page.
60 * @param url The URL of the page.
61 * @param index The index of this item in the list of most visited items.
62 * @param view The View that will display the item. The MostVisitedItem will handle clicks
63 * on this view.
64 */
65 public MostVisitedItem(MostVisitedItemManager manager, String title, String url, int index,
66 View view) {
67 mManager = manager;
68 mTitle = title;
69 mUrl = url;
70 mIndex = index;
71 mView = view;
72 mView.setOnClickListener(this);
73 mView.setOnCreateContextMenuListener(this);
74 }
75
76 /**
77 * @return The view representing this item.
78 */
79 public View getView() {
80 return mView;
81 }
82
83 /**
84 * @return The URL of this most visited item.
85 */
86 public String getUrl() {
87 return mUrl;
88 }
89
90 /**
91 * @return The title of this most visited item.
92 */
93 public String getTitle() {
94 return mTitle;
95 }
96
97 /**
98 * @return The index of this MostVisitedItem in the list of MostVisitedItems .
99 */
100 public int getIndex() {
101 return mIndex;
102 }
103
104 /**
105 * Updates this item's index in the list of most visited items.
106 */
107 public void setIndex(int index) {
108 mIndex = index;
109 }
110
111 @Override
112 public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo me nuInfo) {
113 mManager.onCreateContextMenu(menu, this);
114 }
115
116 @Override
117 public boolean onMenuItemClick(MenuItem item) {
118 return mManager.onMenuItemClick(item.getItemId(), this);
119 }
120
121 @Override
122 public void onClick(View v) {
123 mManager.open(this);
124 }
125 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698