OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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.contextmenu; | 5 package org.chromium.chrome.browser.contextmenu; |
6 | 6 |
7 import android.app.Activity; | 7 import android.app.Activity; |
8 import android.app.Dialog; | 8 import android.app.Dialog; |
9 import android.content.DialogInterface; | 9 import android.content.DialogInterface; |
10 import android.content.res.Resources; | 10 import android.content.res.Resources; |
(...skipping 27 matching lines...) Expand all Loading... |
38 /** | 38 /** |
39 * A custom dialog that separates each group into separate tabs. It uses a dialo
g instead. | 39 * A custom dialog that separates each group into separate tabs. It uses a dialo
g instead. |
40 */ | 40 */ |
41 public class TabularContextMenuUi implements ContextMenuUi, AdapterView.OnItemCl
ickListener { | 41 public class TabularContextMenuUi implements ContextMenuUi, AdapterView.OnItemCl
ickListener { |
42 private Dialog mDialog; | 42 private Dialog mDialog; |
43 private Callback<Integer> mCallback; | 43 private Callback<Integer> mCallback; |
44 private int mMenuItemHeight; | 44 private int mMenuItemHeight; |
45 private ContextMenuHelper mContextMenuHelper; | 45 private ContextMenuHelper mContextMenuHelper; |
46 | 46 |
47 /** | 47 /** |
48 * A context menu that sperates types by tabs. | 48 * A context menu that separates types by tabs. |
49 * @param contextMenuHelper The {@link ContextMenuHelper} is used to retriev
e the thumbnail | 49 * @param contextMenuHelper The {@link ContextMenuHelper} is used to retriev
e the thumbnail |
50 * natively from the Context Menu Helper. | 50 * natively from the Context Menu Helper. |
51 */ | 51 */ |
52 TabularContextMenuUi(ContextMenuHelper contextMenuHelper) { | 52 TabularContextMenuUi(ContextMenuHelper contextMenuHelper) { |
53 mContextMenuHelper = contextMenuHelper; | 53 mContextMenuHelper = contextMenuHelper; |
54 } | 54 } |
55 | 55 |
56 @Override | 56 @Override |
57 public void displayMenu(Activity activity, ContextMenuParams params, | 57 public void displayMenu(Activity activity, ContextMenuParams params, |
58 List<Pair<Integer, List<ContextMenuItem>>> items, Callback<Integer>
onItemClicked, | 58 List<Pair<Integer, List<ContextMenuItem>>> items, Callback<Integer>
onItemClicked, |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 ListView listView = (ListView) baseLayout.findViewById(R.id.selectable_i
tems); | 110 ListView listView = (ListView) baseLayout.findViewById(R.id.selectable_i
tems); |
111 | 111 |
112 if (isImage) { | 112 if (isImage) { |
113 displayImageHeader(baseLayout, params, activity.getResources()); | 113 displayImageHeader(baseLayout, params, activity.getResources()); |
114 } else { | 114 } else { |
115 displayHeaderIfVisibleItems(params, baseLayout); | 115 displayHeaderIfVisibleItems(params, baseLayout); |
116 } | 116 } |
117 | 117 |
118 // Set the list adapter and get the height to display it appropriately i
n a dialog. | 118 // Set the list adapter and get the height to display it appropriately i
n a dialog. |
119 TabularContextMenuListAdapter listAdapter = | 119 TabularContextMenuListAdapter listAdapter = |
120 new TabularContextMenuListAdapter(items, activity); | 120 new TabularContextMenuListAdapter(items, activity, mContextMenuH
elper); |
121 ViewGroup.LayoutParams layoutParams = listView.getLayoutParams(); | 121 ViewGroup.LayoutParams layoutParams = listView.getLayoutParams(); |
122 layoutParams.height = measureApproximateListViewHeight(listView, listAda
pter, maxCount); | 122 layoutParams.height = measureApproximateListViewHeight(listView, listAda
pter, maxCount); |
123 listView.setLayoutParams(layoutParams); | 123 listView.setLayoutParams(layoutParams); |
124 listView.setAdapter(listAdapter); | 124 listView.setAdapter(listAdapter); |
125 listView.setOnItemClickListener(this); | 125 listView.setOnItemClickListener(this); |
126 | 126 |
127 return baseLayout; | 127 return baseLayout; |
128 } | 128 } |
129 | 129 |
130 private void displayHeaderIfVisibleItems(ContextMenuParams params, ViewGroup
baseLayout) { | 130 private void displayHeaderIfVisibleItems(ContextMenuParams params, ViewGroup
baseLayout) { |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 | 237 |
238 return view; | 238 return view; |
239 } | 239 } |
240 | 240 |
241 @Override | 241 @Override |
242 public void onItemClick(AdapterView<?> adapterView, View view, int position,
long id) { | 242 public void onItemClick(AdapterView<?> adapterView, View view, int position,
long id) { |
243 mDialog.dismiss(); | 243 mDialog.dismiss(); |
244 mCallback.onResult((int) id); | 244 mCallback.onResult((int) id); |
245 } | 245 } |
246 } | 246 } |
OLD | NEW |