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; | |
9 import android.content.DialogInterface; | 8 import android.content.DialogInterface; |
10 import android.content.res.Resources; | 9 import android.content.res.Resources; |
11 import android.graphics.Bitmap; | 10 import android.graphics.Bitmap; |
12 import android.graphics.Canvas; | 11 import android.graphics.Canvas; |
12 import android.graphics.Color; | |
13 import android.graphics.Rect; | |
13 import android.graphics.Shader; | 14 import android.graphics.Shader; |
14 import android.graphics.drawable.BitmapDrawable; | 15 import android.graphics.drawable.BitmapDrawable; |
16 import android.graphics.drawable.ColorDrawable; | |
15 import android.graphics.drawable.Drawable; | 17 import android.graphics.drawable.Drawable; |
16 import android.support.design.widget.TabLayout; | 18 import android.support.design.widget.TabLayout; |
17 import android.support.v4.view.ViewPager; | |
18 import android.support.v7.app.AlertDialog; | 19 import android.support.v7.app.AlertDialog; |
19 import android.text.TextUtils; | 20 import android.text.TextUtils; |
20 import android.util.Pair; | 21 import android.util.Pair; |
21 import android.view.LayoutInflater; | 22 import android.view.LayoutInflater; |
22 import android.view.View; | 23 import android.view.View; |
24 import android.view.View.OnLayoutChangeListener; | |
23 import android.view.ViewGroup; | 25 import android.view.ViewGroup; |
26 import android.view.ViewGroup.LayoutParams; | |
27 import android.view.Window; | |
28 import android.view.animation.Animation; | |
24 import android.widget.AdapterView; | 29 import android.widget.AdapterView; |
25 import android.widget.BaseAdapter; | 30 import android.widget.BaseAdapter; |
26 import android.widget.ImageView; | 31 import android.widget.ImageView; |
27 import android.widget.ListView; | 32 import android.widget.ListView; |
28 import android.widget.TextView; | 33 import android.widget.TextView; |
29 | 34 |
30 import org.chromium.base.ApiCompatibilityUtils; | 35 import org.chromium.base.ApiCompatibilityUtils; |
31 import org.chromium.base.Callback; | 36 import org.chromium.base.Callback; |
32 import org.chromium.base.VisibleForTesting; | 37 import org.chromium.base.VisibleForTesting; |
33 import org.chromium.chrome.R; | 38 import org.chromium.chrome.R; |
39 import org.chromium.chrome.browser.widget.ContextMenuDialog; | |
40 import org.chromium.content.browser.RenderCoordinates; | |
34 | 41 |
35 import java.util.ArrayList; | 42 import java.util.ArrayList; |
36 import java.util.List; | 43 import java.util.List; |
37 | 44 |
38 /** | 45 /** |
39 * A custom dialog that separates each group into separate tabs. It uses a dialo g instead. | 46 * A custom dialog that separates each group into separate tabs. It uses a dialo g instead. |
40 */ | 47 */ |
41 public class TabularContextMenuUi implements ContextMenuUi, AdapterView.OnItemCl ickListener { | 48 public class TabularContextMenuUi implements ContextMenuUi, AdapterView.OnItemCl ickListener { |
42 private Dialog mDialog; | 49 private ContextMenuDialog mContextMenuDialog; |
43 private Callback<Integer> mCallback; | 50 private Callback<Integer> mCallback; |
44 private int mMenuItemHeight; | 51 private int mMenuItemHeight; |
45 private ImageView mHeaderImageView; | 52 private ImageView mHeaderImageView; |
46 private Runnable mOnShareItemClicked; | 53 private Runnable mOnShareItemClicked; |
54 private View mPagerView; | |
55 | |
56 private float mContextMenuSourceX; | |
57 private float mContextMenuSourceY; | |
58 private int mContextMenuFirstLocationY; | |
59 private RenderCoordinates mRenderCoordinates; | |
60 | |
61 private static final double MAX_WIDTH_PROPORTION = 0.75; | |
Theresa
2017/05/24 20:16:33
nit: private static final variables should go abov
Daniel Park
2017/05/24 22:34:31
Done.
| |
47 | 62 |
48 public TabularContextMenuUi(Runnable onShareItemClicked) { | 63 public TabularContextMenuUi(Runnable onShareItemClicked) { |
49 mOnShareItemClicked = onShareItemClicked; | 64 mOnShareItemClicked = onShareItemClicked; |
50 } | 65 } |
51 | 66 |
52 @Override | 67 @Override |
53 public void displayMenu(Activity activity, ContextMenuParams params, | 68 public void displayMenu(final Activity activity, ContextMenuParams params, |
54 List<Pair<Integer, List<ContextMenuItem>>> items, Callback<Integer> onItemClicked, | 69 List<Pair<Integer, List<ContextMenuItem>>> items, Callback<Integer> onItemClicked, |
55 final Runnable onMenuShown, final Runnable onMenuClosed) { | 70 final Runnable onMenuShown, final Runnable onMenuClosed) { |
56 mCallback = onItemClicked; | 71 mCallback = onItemClicked; |
57 mDialog = createDialog(activity, params, items); | 72 mContextMenuDialog = createContextMenuDialog(activity, params, items); |
58 | 73 |
59 mDialog.getWindow().setBackgroundDrawable(ApiCompatibilityUtils.getDrawa ble( | 74 mContextMenuDialog.setOnShowListener(new DialogInterface.OnShowListener( ) { |
60 activity.getResources(), R.drawable.white_with_rounded_corners)) ; | |
61 | |
62 mDialog.setOnShowListener(new DialogInterface.OnShowListener() { | |
63 @Override | 75 @Override |
64 public void onShow(DialogInterface dialogInterface) { | 76 public void onShow(DialogInterface dialogInterface) { |
65 onMenuShown.run(); | 77 onMenuShown.run(); |
66 } | 78 } |
67 }); | 79 }); |
68 | 80 |
69 mDialog.setOnDismissListener(new DialogInterface.OnDismissListener() { | 81 mContextMenuDialog.setOnDismissListener(new DialogInterface.OnDismissLis tener() { |
70 @Override | 82 @Override |
71 public void onDismiss(DialogInterface dialogInterface) { | 83 public void onDismiss(DialogInterface dialogInterface) { |
72 onMenuClosed.run(); | 84 onMenuClosed.run(); |
73 } | 85 } |
74 }); | 86 }); |
75 | 87 |
76 mDialog.show(); | 88 Window dialogWindow = mContextMenuDialog.getWindow(); |
89 dialogWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)) ; | |
90 dialogWindow.setLayout(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PAR ENT); | |
91 | |
92 float density = Resources.getSystem().getDisplayMetrics().density; | |
93 final float touchPointX = params.getTriggeringTouchX() * density; | |
94 final float touchPointY = params.getTriggeringTouchY() * density; | |
95 | |
96 mPagerView.setVisibility(View.INVISIBLE); | |
97 mPagerView.addOnLayoutChangeListener(new OnLayoutChangeListener() { | |
98 | |
99 @Override | |
100 public void onLayoutChange(View v, int left, int top, int right, int bottom, | |
101 int oldLeft, int oldTop, int oldRight, int oldBottom) { | |
102 ViewGroup group = (ViewGroup) v; | |
103 for (int i = 0; i < group.getChildCount(); i++) { | |
104 if (group.getChildAt(i).getHeight() == 0 | |
105 && group.getChildAt(i).getVisibility() == View.VISIB LE) { | |
106 // Return early because not all the views have been meas ured, so animations | |
107 // pivots will be off. | |
108 return; | |
109 } | |
110 } | |
111 revealViewAndStartEnterAnimation(touchPointX, touchPointY, activ ity); | |
112 mPagerView.removeOnLayoutChangeListener(this); | |
113 mContextMenuDialog.setExitAnimationParameters(mPagerView, mConte xtMenuSourceX, | |
114 mContextMenuSourceY, mContextMenuFirstLocationY); | |
115 } | |
116 }); | |
117 mContextMenuDialog.show(); | |
77 } | 118 } |
78 | 119 |
79 /** | 120 /** |
80 * Returns the fully complete dialog based off the params and the itemGroups . | 121 * Returns the fully complete dialog based off the params and the itemGroups . |
122 * | |
81 * @param activity Used to inflate the dialog. | 123 * @param activity Used to inflate the dialog. |
82 * @param params Used to get the header title. | 124 * @param params Used to get the header title. |
83 * @param itemGroups If there is more than one group it will create a paged view. | 125 * @param itemGroups If there is more than one group it will create a paged view. |
84 * @return Returns a final dialog that does not have a background can be dis played using | 126 * @return Returns a final dialog that does not have a background can be dis played using |
85 * {@link AlertDialog#show()}. | 127 * {@link AlertDialog#show()}. |
86 */ | 128 */ |
87 private Dialog createDialog(Activity activity, ContextMenuParams params, | 129 private ContextMenuDialog createContextMenuDialog(Activity activity, Context MenuParams params, |
88 List<Pair<Integer, List<ContextMenuItem>>> itemGroups) { | 130 List<Pair<Integer, List<ContextMenuItem>>> itemGroups) { |
89 Dialog dialog = new Dialog(activity); | 131 final ContextMenuDialog dialog = new ContextMenuDialog(activity, R.style .DialogWhenLarge); |
90 dialog.setContentView(createPagerView(activity, params, itemGroups)); | 132 |
133 View view = LayoutInflater.from(activity).inflate(R.layout.tabular_conte xt_menu, null); | |
134 | |
135 Resources resources = activity.getResources(); | |
136 | |
137 int contextMenuWidth = | |
138 (int) Math.min(resources.getDisplayMetrics().widthPixels * MAX_W IDTH_PROPORTION, | |
139 resources.getDimensionPixelSize(R.dimen.context_menu_max _width)); | |
140 | |
141 mPagerView = initPagerView(activity, params, itemGroups, | |
142 (TabularContextMenuViewPager) view.findViewById(R.id.custom_page r)); | |
143 mPagerView.getLayoutParams().width = contextMenuWidth; | |
144 | |
145 dialog.addContentView( | |
Theresa
2017/05/24 20:16:33
setContentView() instead of addContentView() since
Daniel Park
2017/05/24 22:34:31
Done.
| |
146 view, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.M ATCH_PARENT)); | |
147 | |
91 return dialog; | 148 return dialog; |
92 } | 149 } |
93 | 150 |
94 /** | 151 /** |
95 * Creates a ViewPageAdapter based off the given list of views. | 152 * Creates a ViewPageAdapter based off the given list of views. |
96 * @param activity Used to inflate the new ViewPager | 153 * |
154 * @param activity Used to inflate the new ViewPager. | |
97 * @param params Used to get the header text. | 155 * @param params Used to get the header text. |
98 * @param itemGroups The list of views to put into the ViewPager. The string is the title of the | 156 * @param itemGroups The list of views to put into the ViewPager. The string is the title of the |
99 * tab | 157 * tab. |
158 * @param viewPager The viewpager to initialize. | |
100 * @return Returns a complete tabular context menu view. | 159 * @return Returns a complete tabular context menu view. |
101 */ | 160 */ |
102 @VisibleForTesting | 161 @VisibleForTesting |
103 View createPagerView(Activity activity, ContextMenuParams params, | 162 View initPagerView(Activity activity, ContextMenuParams params, |
104 List<Pair<Integer, List<ContextMenuItem>>> itemGroups) { | 163 List<Pair<Integer, List<ContextMenuItem>>> itemGroups, |
105 View view = LayoutInflater.from(activity).inflate(R.layout.tabular_conte xt_menu, null); | 164 TabularContextMenuViewPager viewPager) { |
106 | |
107 List<Pair<String, ViewGroup>> viewGroups = new ArrayList<>(); | 165 List<Pair<String, ViewGroup>> viewGroups = new ArrayList<>(); |
108 int maxCount = 0; | 166 int maxCount = 0; |
109 for (int i = 0; i < itemGroups.size(); i++) { | 167 for (int i = 0; i < itemGroups.size(); i++) { |
110 Pair<Integer, List<ContextMenuItem>> itemGroup = itemGroups.get(i); | 168 Pair<Integer, List<ContextMenuItem>> itemGroup = itemGroups.get(i); |
111 maxCount = Math.max(maxCount, itemGroup.second.size()); | 169 maxCount = Math.max(maxCount, itemGroup.second.size()); |
112 } | 170 } |
113 for (int i = 0; i < itemGroups.size(); i++) { | 171 for (int i = 0; i < itemGroups.size(); i++) { |
114 Pair<Integer, List<ContextMenuItem>> itemGroup = itemGroups.get(i); | 172 Pair<Integer, List<ContextMenuItem>> itemGroup = itemGroups.get(i); |
115 // TODO(tedchoc): Pass the ContextMenuGroup identifier to determine if it's an image. | 173 // TODO(tedchoc): Pass the ContextMenuGroup identifier to determine if it's an image. |
116 boolean isImageTab = itemGroup.first == R.string.contextmenu_image_t itle; | 174 boolean isImageTab = itemGroup.first == R.string.contextmenu_image_t itle; |
117 viewGroups.add(new Pair<>(activity.getString(itemGroup.first), | 175 viewGroups.add(new Pair<>(activity.getString(itemGroup.first), |
118 createContextMenuPageUi( | 176 createContextMenuPageUi( |
119 activity, params, itemGroup.second, isImageTab, maxC ount))); | 177 activity, params, itemGroup.second, isImageTab, maxC ount))); |
120 } | 178 } |
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 | 179 |
128 TabularContextMenuViewPager pager = | 180 viewPager.setAdapter(new TabularContextMenuPagerAdapter(viewGroups)); |
129 (TabularContextMenuViewPager) view.findViewById(R.id.custom_page r); | 181 TabLayout tabLayout = (TabLayout) viewPager.findViewById(R.id.tab_layout ); |
130 pager.setAdapter(new TabularContextMenuPagerAdapter(viewGroups)); | |
131 | |
132 TabLayout tabLayout = (TabLayout) view.findViewById(R.id.tab_layout); | |
133 if (itemGroups.size() <= 1) { | 182 if (itemGroups.size() <= 1) { |
134 tabLayout.setVisibility(View.GONE); | 183 tabLayout.setVisibility(View.GONE); |
135 } else { | 184 } else { |
136 tabLayout.setupWithViewPager((ViewPager) view.findViewById(R.id.cust om_pager)); | 185 tabLayout.setBackgroundResource(R.drawable.grey_with_top_rounded_cor ners); |
186 tabLayout.setupWithViewPager(viewPager); | |
137 } | 187 } |
138 | 188 |
139 return view; | 189 return viewPager; |
140 } | 190 } |
141 | 191 |
142 /** | 192 /** |
143 * Creates the view of a context menu. Based off the Context Type, it'll adj ust the list of | 193 * Creates the view of a context menu. Based off the Context Type, it'll adj ust the list of |
144 * items and display only the ones that'll be on that specific group. | 194 * items and display only the ones that'll be on that specific group. |
195 * | |
145 * @param activity Used to get the resources of an item. | 196 * @param activity Used to get the resources of an item. |
146 * @param params used to create the header text. | 197 * @param params used to create the header text. |
147 * @param items A set of Items to display in a context menu. Filtered based off the type. | 198 * @param items A set of Items to display in a context menu. Filtered based off the type. |
148 * @param isImage Whether or not the view should have an image layout or not . | 199 * @param isImage Whether or not the view should have an image layout or not . |
149 * @param maxCount The maximum amount of {@link ContextMenuItem}s that could exist in this view | 200 * @param maxCount The maximum amount of {@link ContextMenuItem}s that could exist in this view |
150 * or any other views calculated in the context menu. Used t o estimate the size | 201 * or any other views calculated in the context menu. Used t o estimate the size |
151 * of the list. | 202 * of the list. |
152 * @return Returns a filled LinearLayout with all the context menu items. | 203 * @return Returns a filled LinearLayout with all the context menu items. |
153 */ | 204 */ |
154 @VisibleForTesting | 205 @VisibleForTesting |
(...skipping 10 matching lines...) Expand all Loading... | |
165 baseLayout.findViewById(R.id.context_header_layout).setVisibility(Vi ew.VISIBLE); | 216 baseLayout.findViewById(R.id.context_header_layout).setVisibility(Vi ew.VISIBLE); |
166 baseLayout.findViewById(R.id.context_divider).setVisibility(View.VIS IBLE); | 217 baseLayout.findViewById(R.id.context_divider).setVisibility(View.VIS IBLE); |
167 displayImageHeader(baseLayout, params, activity.getResources()); | 218 displayImageHeader(baseLayout, params, activity.getResources()); |
168 } | 219 } |
169 | 220 |
170 // Set the list adapter and get the height to display it appropriately i n a dialog. | 221 // Set the list adapter and get the height to display it appropriately i n a dialog. |
171 Runnable onDirectShare = new Runnable() { | 222 Runnable onDirectShare = new Runnable() { |
172 @Override | 223 @Override |
173 public void run() { | 224 public void run() { |
174 mOnShareItemClicked.run(); | 225 mOnShareItemClicked.run(); |
175 mDialog.dismiss(); | 226 mContextMenuDialog.dismiss(); |
176 } | 227 } |
177 }; | 228 }; |
178 TabularContextMenuListAdapter listAdapter = | 229 TabularContextMenuListAdapter listAdapter = |
179 new TabularContextMenuListAdapter(items, activity, onDirectShare ); | 230 new TabularContextMenuListAdapter(items, activity, onDirectShare ); |
180 ViewGroup.LayoutParams layoutParams = listView.getLayoutParams(); | 231 ViewGroup.LayoutParams layoutParams = listView.getLayoutParams(); |
181 layoutParams.height = measureApproximateListViewHeight(listView, listAda pter, maxCount); | 232 layoutParams.height = measureApproximateListViewHeight(listView, listAda pter, maxCount); |
182 listView.setLayoutParams(layoutParams); | 233 listView.setLayoutParams(layoutParams); |
183 listView.setAdapter(listAdapter); | 234 listView.setAdapter(listAdapter); |
184 listView.setOnItemClickListener(this); | 235 listView.setOnItemClickListener(this); |
185 | 236 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
238 BitmapDrawable bm = new BitmapDrawable(resources, bitmap); | 289 BitmapDrawable bm = new BitmapDrawable(resources, bitmap); |
239 bm.setTileModeXY(Shader.TileMode.REPEAT, Shader.TileMode.REPEAT); | 290 bm.setTileModeXY(Shader.TileMode.REPEAT, Shader.TileMode.REPEAT); |
240 imageView.setVisibility(View.VISIBLE); | 291 imageView.setVisibility(View.VISIBLE); |
241 imageView.setBackground(bm); | 292 imageView.setBackground(bm); |
242 } | 293 } |
243 | 294 |
244 /** | 295 /** |
245 * To save time measuring the height, this method gets an item if the height has not been | 296 * To save time measuring the height, this method gets an item if the height has not been |
246 * previous measured and multiplies it by count of the total amount of items . It is fine if the | 297 * previous measured and multiplies it by count of the total amount of items . It is fine if the |
247 * height too small as the ListView will scroll through the other values. | 298 * height too small as the ListView will scroll through the other values. |
299 * | |
248 * @param listView The ListView to measure the surrounding padding. | 300 * @param listView The ListView to measure the surrounding padding. |
249 * @param listAdapter The adapter which contains the items within the list. | 301 * @param listAdapter The adapter which contains the items within the list. |
250 * @return Returns the combined height of the padding of the ListView and th e approximate height | 302 * @return Returns the combined height of the padding of the ListView and th e approximate height |
251 * of the ListView based off the an item. | 303 * of the ListView based off the an item. |
252 */ | 304 */ |
253 private int measureApproximateListViewHeight( | 305 private int measureApproximateListViewHeight( |
254 ListView listView, BaseAdapter listAdapter, int maxCount) { | 306 ListView listView, BaseAdapter listAdapter, int maxCount) { |
255 int totalHeight = listView.getPaddingTop() + listView.getPaddingBottom() ; | 307 int totalHeight = listView.getPaddingTop() + listView.getPaddingBottom() ; |
256 if (mMenuItemHeight == 0 && !listAdapter.isEmpty()) { | 308 if (mMenuItemHeight == 0 && !listAdapter.isEmpty()) { |
257 View view = listAdapter.getView(0, null, listView); | 309 View view = listAdapter.getView(0, null, listView); |
258 view.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UN SPECIFIED), | 310 view.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UN SPECIFIED), |
259 View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECI FIED)); | 311 View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECI FIED)); |
260 mMenuItemHeight = view.getMeasuredHeight(); | 312 mMenuItemHeight = view.getMeasuredHeight(); |
261 } | 313 } |
262 return totalHeight + mMenuItemHeight * maxCount; | 314 return totalHeight + mMenuItemHeight * maxCount; |
263 } | 315 } |
264 | 316 |
265 /** | 317 /** |
266 * When an thumbnail is retrieved for the header of an image, this will set the header to | 318 * @param touchPointX The x-coordinate of the touch that triggered the conte xt menu in pixels. |
267 * that particular bitmap. | 319 * @param touchPointY The y-coordinate of the touch that triggered the conte xt menu in pixels. |
320 * @param activity Activity to determine the number of pixels to the left an d above of the | |
321 * window. | |
322 */ | |
323 private void revealViewAndStartEnterAnimation( | |
324 final float touchPointX, final float touchPointY, Activity activity) { | |
325 mPagerView.setVisibility(View.VISIBLE); | |
326 | |
327 int[] currentLocationOnScreen = new int[2]; | |
328 mPagerView.getLocationOnScreen(currentLocationOnScreen); | |
329 | |
330 mContextMenuFirstLocationY = currentLocationOnScreen[1]; | |
331 mPagerView.startAnimation(initPivotValuesAndGetEnterScaleAnimation(touch PointX, touchPointY, | |
332 currentLocationOnScreen[0], currentLocationOnScreen[1], activity )); | |
333 } | |
334 | |
335 /** | |
336 * @param touchPointX The starting x-coordinate of the translation animation . | |
337 * @param touchPointY The starting y-coordinate of the translation animation . | |
338 * @param viewLocationX The x-coordinate of the top left corner of the view relative to the | |
339 * device. | |
340 * @param viewLocationY The y-coordinate of the top left corner of the view relative to the | |
341 * device. | |
342 * @param activity Activity to determine the number of pixels to the left an d above of the | |
343 * window. | |
Theresa
2017/05/24 20:16:33
nit: align "window" with "Activity"
Daniel Park
2017/05/24 22:34:31
Done.
| |
344 * @return Returns the entering scale animation for the context menu. | |
345 */ | |
346 private Animation initPivotValuesAndGetEnterScaleAnimation(final float touch PointX, | |
Theresa
2017/05/24 20:16:33
nit: this is probably more verbose than needed. I
Daniel Park
2017/05/24 22:34:31
Done.
| |
347 final float touchPointY, int viewLocationX, int viewLocationY, Activ ity activity) { | |
348 Rect rectangle = new Rect(); | |
349 Window window = activity.getWindow(); | |
350 window.getDecorView().getWindowVisibleDisplayFrame(rectangle); | |
351 | |
352 // yOffset represents how many pixels are taken up by anything above the content window | |
353 // e.g. toolbar & tab strip. | |
354 float yOffset = rectangle.top + mRenderCoordinates.getContentOffsetYPix( ); | |
355 | |
356 // xOffset represents how many pixels are taken up by anything to the le ft of the content | |
357 // window e.g. navigation bar of the Nexus 6P when in landscape mode wit h usb port to the | |
358 // left. | |
359 float xOffset = rectangle.left; | |
360 | |
361 /** | |
362 * Touch points & view locations are relative to the content window i.e . 0, 0 represents | |
363 * the top left corner of the content window, but animation requires co ordinates relative | |
364 * to the context menu. These operations are to transform the content w indow coordinates | |
365 * to what they would be if they were relative to the the context menu. | |
366 */ | |
367 mContextMenuSourceX = touchPointX - viewLocationX + xOffset; | |
368 mContextMenuSourceY = touchPointY - viewLocationY + yOffset; | |
369 | |
Theresa
2017/05/24 20:16:33
I was hoping all of this could move to ContextMenu
Daniel Park
2017/05/24 22:34:31
Done.
| |
370 return mContextMenuDialog.getScaleAnimation(true, mContextMenuSourceX, m ContextMenuSourceY); | |
371 } | |
372 | |
373 /** | |
374 * When an thumbnail is retrieved for the header of an image, this will set the header to that | |
375 * particular bitmap. | |
268 */ | 376 */ |
269 public void onImageThumbnailRetrieved(Bitmap bitmap) { | 377 public void onImageThumbnailRetrieved(Bitmap bitmap) { |
270 if (mHeaderImageView != null) { | 378 if (mHeaderImageView != null) { |
271 mHeaderImageView.setImageBitmap(bitmap); | 379 mHeaderImageView.setImageBitmap(bitmap); |
272 } | 380 } |
273 } | 381 } |
274 | 382 |
275 @Override | 383 @Override |
276 public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) { | 384 public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) { |
277 mDialog.dismiss(); | 385 mContextMenuDialog.dismiss(); |
278 mCallback.onResult((int) id); | 386 mCallback.onResult((int) id); |
279 } | 387 } |
388 | |
389 /** | |
390 * Gives this class access to the content view core to allow access to the t otal size of the | |
Theresa
2017/05/24 20:16:33
This comment needs to be updated
Daniel Park
2017/05/24 22:34:31
Done.
| |
391 * toolbar and tab strip. | |
392 */ | |
393 public void setRenderCoordinates(RenderCoordinates renderCoordinates) { | |
394 mRenderCoordinates = renderCoordinates; | |
395 } | |
280 } | 396 } |
OLD | NEW |