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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 public TabularContextMenuUi(Runnable onShareItemClicked) { | 48 public TabularContextMenuUi(Runnable onShareItemClicked) { |
49 mOnShareItemClicked = onShareItemClicked; | 49 mOnShareItemClicked = onShareItemClicked; |
50 } | 50 } |
51 | 51 |
52 @Override | 52 @Override |
53 public void displayMenu(Activity activity, ContextMenuParams params, | 53 public void displayMenu(Activity activity, ContextMenuParams params, |
54 List<Pair<Integer, List<ContextMenuItem>>> items, Callback<Integer>
onItemClicked, | 54 List<Pair<Integer, List<ContextMenuItem>>> items, Callback<Integer>
onItemClicked, |
55 final Runnable onMenuShown, final Runnable onMenuClosed) { | 55 final Runnable onMenuShown, final Runnable onMenuClosed) { |
56 mCallback = onItemClicked; | 56 mCallback = onItemClicked; |
57 mDialog = createDialog(activity, params, items); | 57 mDialog = createDialog(activity, params, items); |
| 58 |
58 mDialog.getWindow().setBackgroundDrawable(ApiCompatibilityUtils.getDrawa
ble( | 59 mDialog.getWindow().setBackgroundDrawable(ApiCompatibilityUtils.getDrawa
ble( |
59 activity.getResources(), R.drawable.bg_find_toolbar_popup)); | 60 activity.getResources(), R.drawable.white_with_rounded_corners))
; |
60 | 61 |
61 mDialog.setOnShowListener(new DialogInterface.OnShowListener() { | 62 mDialog.setOnShowListener(new DialogInterface.OnShowListener() { |
62 @Override | 63 @Override |
63 public void onShow(DialogInterface dialogInterface) { | 64 public void onShow(DialogInterface dialogInterface) { |
64 onMenuShown.run(); | 65 onMenuShown.run(); |
65 } | 66 } |
66 }); | 67 }); |
67 | 68 |
68 mDialog.setOnDismissListener(new DialogInterface.OnDismissListener() { | 69 mDialog.setOnDismissListener(new DialogInterface.OnDismissListener() { |
69 @Override | 70 @Override |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 maxCount = Math.max(maxCount, itemGroup.second.size()); | 111 maxCount = Math.max(maxCount, itemGroup.second.size()); |
111 } | 112 } |
112 for (int i = 0; i < itemGroups.size(); i++) { | 113 for (int i = 0; i < itemGroups.size(); i++) { |
113 Pair<Integer, List<ContextMenuItem>> itemGroup = itemGroups.get(i); | 114 Pair<Integer, List<ContextMenuItem>> itemGroup = itemGroups.get(i); |
114 // TODO(tedchoc): Pass the ContextMenuGroup identifier to determine
if it's an image. | 115 // TODO(tedchoc): Pass the ContextMenuGroup identifier to determine
if it's an image. |
115 boolean isImageTab = itemGroup.first == R.string.contextmenu_image_t
itle; | 116 boolean isImageTab = itemGroup.first == R.string.contextmenu_image_t
itle; |
116 viewGroups.add(new Pair<>(activity.getString(itemGroup.first), | 117 viewGroups.add(new Pair<>(activity.getString(itemGroup.first), |
117 createContextMenuPageUi( | 118 createContextMenuPageUi( |
118 activity, params, itemGroup.second, isImageTab, maxC
ount))); | 119 activity, params, itemGroup.second, isImageTab, maxC
ount))); |
119 } | 120 } |
| 121 if (itemGroups.size() == 1) { |
| 122 viewGroups.get(0) |
| 123 .second.getChildAt(0) |
| 124 .findViewById(R.id.context_header_layout) |
| 125 .setBackgroundResource(R.color.google_grey_100); |
| 126 } |
| 127 |
120 TabularContextMenuViewPager pager = | 128 TabularContextMenuViewPager pager = |
121 (TabularContextMenuViewPager) view.findViewById(R.id.custom_page
r); | 129 (TabularContextMenuViewPager) view.findViewById(R.id.custom_page
r); |
122 pager.setAdapter(new TabularContextMenuPagerAdapter(viewGroups)); | 130 pager.setAdapter(new TabularContextMenuPagerAdapter(viewGroups)); |
123 | 131 |
124 TabLayout tabLayout = (TabLayout) view.findViewById(R.id.tab_layout); | 132 TabLayout tabLayout = (TabLayout) view.findViewById(R.id.tab_layout); |
125 if (itemGroups.size() <= 1) { | 133 if (itemGroups.size() <= 1) { |
126 tabLayout.setVisibility(View.GONE); | 134 tabLayout.setVisibility(View.GONE); |
127 } else { | 135 } else { |
128 tabLayout.setupWithViewPager((ViewPager) view.findViewById(R.id.cust
om_pager)); | 136 tabLayout.setupWithViewPager((ViewPager) view.findViewById(R.id.cust
om_pager)); |
129 } | 137 } |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 mHeaderImageView.setImageBitmap(bitmap); | 264 mHeaderImageView.setImageBitmap(bitmap); |
257 } | 265 } |
258 } | 266 } |
259 | 267 |
260 @Override | 268 @Override |
261 public void onItemClick(AdapterView<?> adapterView, View view, int position,
long id) { | 269 public void onItemClick(AdapterView<?> adapterView, View view, int position,
long id) { |
262 mDialog.dismiss(); | 270 mDialog.dismiss(); |
263 mCallback.onResult((int) id); | 271 mCallback.onResult((int) id); |
264 } | 272 } |
265 } | 273 } |
OLD | NEW |