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