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

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/contextmenu/TabularContextMenuUi.java

Issue 2868403003: added scale animation for context menu (Closed)
Patch Set: periods Created 3 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
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.ActionBar.LayoutParams;
7 import android.app.Activity; 8 import android.app.Activity;
8 import android.app.Dialog; 9 import android.app.Dialog;
9 import android.content.DialogInterface; 10 import android.content.DialogInterface;
10 import android.content.res.Resources; 11 import android.content.res.Resources;
11 import android.graphics.Bitmap; 12 import android.graphics.Bitmap;
12 import android.graphics.Canvas; 13 import android.graphics.Canvas;
14 import android.graphics.Color;
15 import android.graphics.Rect;
13 import android.graphics.Shader; 16 import android.graphics.Shader;
14 import android.graphics.drawable.BitmapDrawable; 17 import android.graphics.drawable.BitmapDrawable;
18 import android.graphics.drawable.ColorDrawable;
15 import android.graphics.drawable.Drawable; 19 import android.graphics.drawable.Drawable;
16 import android.support.design.widget.TabLayout; 20 import android.support.design.widget.TabLayout;
17 import android.support.v4.view.ViewPager; 21 import android.support.v4.view.ViewPager;
22 import android.support.v4.view.animation.LinearOutSlowInInterpolator;
18 import android.support.v7.app.AlertDialog; 23 import android.support.v7.app.AlertDialog;
19 import android.text.TextUtils; 24 import android.text.TextUtils;
20 import android.util.Pair; 25 import android.util.Pair;
26 import android.view.Gravity;
21 import android.view.LayoutInflater; 27 import android.view.LayoutInflater;
22 import android.view.View; 28 import android.view.View;
29 import android.view.View.OnClickListener;
30 import android.view.View.OnLayoutChangeListener;
23 import android.view.ViewGroup; 31 import android.view.ViewGroup;
32 import android.view.Window;
33 import android.view.animation.Animation;
34 import android.view.animation.Animation.AnimationListener;
35 import android.view.animation.ScaleAnimation;
24 import android.widget.AdapterView; 36 import android.widget.AdapterView;
25 import android.widget.BaseAdapter; 37 import android.widget.BaseAdapter;
38 import android.widget.FrameLayout;
26 import android.widget.ImageView; 39 import android.widget.ImageView;
27 import android.widget.ListView; 40 import android.widget.ListView;
28 import android.widget.TextView; 41 import android.widget.TextView;
29 42
30 import org.chromium.base.ApiCompatibilityUtils; 43 import org.chromium.base.ApiCompatibilityUtils;
31 import org.chromium.base.Callback; 44 import org.chromium.base.Callback;
32 import org.chromium.base.VisibleForTesting; 45 import org.chromium.base.VisibleForTesting;
33 import org.chromium.chrome.R; 46 import org.chromium.chrome.R;
47 import org.chromium.chrome.browser.widget.AlwaysDismissedDialog;
48 import org.chromium.content.browser.ContentViewCore;
34 49
35 import java.util.ArrayList; 50 import java.util.ArrayList;
36 import java.util.List; 51 import java.util.List;
37 52
38 /** 53 /**
39 * A custom dialog that separates each group into separate tabs. It uses a dialo g instead. 54 * A custom dialog that separates each group into separate tabs. It uses a dialo g instead.
40 */ 55 */
41 public class TabularContextMenuUi implements ContextMenuUi, AdapterView.OnItemCl ickListener { 56 public class TabularContextMenuUi implements ContextMenuUi, AdapterView.OnItemCl ickListener {
42 private Dialog mDialog; 57 private Dialog mDialog;
43 private Callback<Integer> mCallback; 58 private Callback<Integer> mCallback;
44 private int mMenuItemHeight; 59 private int mMenuItemHeight;
45 private ImageView mHeaderImageView; 60 private ImageView mHeaderImageView;
46 private Runnable mOnShareItemClicked; 61 private Runnable mOnShareItemClicked;
62 private View mPagerView;
63
64 private float mContextMenuSourceX;
65 private float mContextMenuSourceY;
66 private int mContextMenuYLocationOnScreen;
67 private ContentViewCore mContentViewCore;
68
69 private static final double MAX_PROPORTION = 0.75;
Theresa 2017/05/23 01:58:08 nit: MAX_WIDTH_PROPORTION
Daniel Park 2017/05/24 16:44:31 Done.
70 private static final int ANIMATION_IN_DURATION = 250;
71 private static final int ANIMATION_OUT_DURATION = (int) (ANIMATION_IN_DURATI ON * 0.6);
47 72
48 public TabularContextMenuUi(Runnable onShareItemClicked) { 73 public TabularContextMenuUi(Runnable onShareItemClicked) {
49 mOnShareItemClicked = onShareItemClicked; 74 mOnShareItemClicked = onShareItemClicked;
50 } 75 }
51 76
52 @Override 77 @Override
53 public void displayMenu(Activity activity, ContextMenuParams params, 78 public void displayMenu(final Activity activity, ContextMenuParams params,
54 List<Pair<Integer, List<ContextMenuItem>>> items, Callback<Integer> onItemClicked, 79 List<Pair<Integer, List<ContextMenuItem>>> items, Callback<Integer> onItemClicked,
55 final Runnable onMenuShown, final Runnable onMenuClosed) { 80 final Runnable onMenuShown, final Runnable onMenuClosed) {
56 mCallback = onItemClicked; 81 mCallback = onItemClicked;
57 mDialog = createDialog(activity, params, items); 82 mDialog = createDialog(activity, params, items);
58 83
59 mDialog.getWindow().setBackgroundDrawable(ApiCompatibilityUtils.getDrawa ble(
60 activity.getResources(), R.drawable.white_with_rounded_corners)) ;
61
62 mDialog.setOnShowListener(new DialogInterface.OnShowListener() { 84 mDialog.setOnShowListener(new DialogInterface.OnShowListener() {
63 @Override 85 @Override
64 public void onShow(DialogInterface dialogInterface) { 86 public void onShow(DialogInterface dialogInterface) {
65 onMenuShown.run(); 87 onMenuShown.run();
66 } 88 }
67 }); 89 });
68 90
69 mDialog.setOnDismissListener(new DialogInterface.OnDismissListener() { 91 mDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
70 @Override 92 @Override
71 public void onDismiss(DialogInterface dialogInterface) { 93 public void onDismiss(DialogInterface dialogInterface) {
72 onMenuClosed.run(); 94 onMenuClosed.run();
73 } 95 }
74 }); 96 });
75 97
98 Window dialogWindow = mDialog.getWindow();
99 dialogWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)) ;
100 dialogWindow.setLayout(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PAR ENT);
101
102 float density = Resources.getSystem().getDisplayMetrics().density;
103 final float touchPointX = params.getX() * density;
104 final float touchPointY = params.getY() * density;
105
106 mPagerView.setVisibility(View.INVISIBLE);
107 mPagerView.addOnLayoutChangeListener(new OnLayoutChangeListener() {
108
109 @Override
110 public void onLayoutChange(View v, int left, int top, int right, int bottom,
111 int oldLeft, int oldTop, int oldRight, int oldBottom) {
112 ViewGroup group = (ViewGroup) v;
113 for (int i = 0; i < group.getChildCount(); i++) {
114 if (group.getChildAt(i).getHeight() == 0
115 && group.getChildAt(i).getVisibility() == View.VISIB LE) {
116 return;
Theresa 2017/05/23 01:58:08 nit: Add a comment about why we're returning early
Daniel Park 2017/05/24 16:44:31 Done.
117 }
118 }
119 initializeAnimationAndRevealView(touchPointX, touchPointY, activ ity);
120 mPagerView.removeOnLayoutChangeListener(this);
121 }
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 AlwaysDismissedDialog(activity, R.style.Dialog WhenLarge);
90 dialog.setContentView(createPagerView(activity, params, itemGroups)); 139
140 dialog.findViewById(android.R.id.content).setOnClickListener(new OnClick Listener() {
Theresa 2017/05/23 01:58:08 The dialog can also be dismissed by a tap on the b
Daniel Park 2017/05/24 16:44:31 Done.
141 @Override
142 public void onClick(View v) {
143 int[] outLocation = new int[2];
144 mPagerView.getLocationOnScreen(outLocation);
145 mContextMenuSourceY =
146 mContextMenuSourceY + (mContextMenuYLocationOnScreen - o utLocation[1]);
147 Animation exitAnimation = getScaleAnimation(false);
148 exitAnimation.setAnimationListener(new AnimationListener() {
149
150 @Override
151 public void onAnimationStart(Animation animation) {}
152
153 @Override
154 public void onAnimationRepeat(Animation animation) {}
155
156 @Override
157 public void onAnimationEnd(Animation animation) {
158 dialog.dismiss();
159 }
160 });
161 mPagerView.startAnimation(exitAnimation);
162 dialog.findViewById(android.R.id.content).setOnClickListener(nul l);
163 }
164 });
165
166 Resources resources = activity.getResources();
167
168 FrameLayout mFullContainer = new FrameLayout(activity);
169 mFullContainer.setBackgroundColor(
170 ApiCompatibilityUtils.getColor(resources, R.color.modal_dialog_s crim_color));
171
172 int contextMenuWidth =
173 (int) Math.min(resources.getDisplayMetrics().widthPixels * MAX_P ROPORTION,
174 resources.getDimensionPixelSize(R.dimen.context_menu_max _width_in_dp));
175
176 FrameLayout.LayoutParams layoutParams =
177 new FrameLayout.LayoutParams(contextMenuWidth, LayoutParams.MATC H_PARENT);
178 layoutParams.gravity = Gravity.CENTER;
179
180 mPagerView = createPagerView(activity, params, itemGroups);
181
182 mFullContainer.addView(mPagerView, layoutParams);
183 dialog.addContentView(mFullContainer,
184 new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_P ARENT));
185
91 return dialog; 186 return dialog;
92 } 187 }
93 188
94 /** 189 /**
95 * Creates a ViewPageAdapter based off the given list of views. 190 * Creates a ViewPageAdapter based off the given list of views.
96 * @param activity Used to inflate the new ViewPager 191 *
192 * @param activity Used to inflate the new ViewPager.
97 * @param params Used to get the header text. 193 * @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 194 * @param itemGroups The list of views to put into the ViewPager. The string is the title of the
99 * tab 195 * tab.
100 * @return Returns a complete tabular context menu view. 196 * @return Returns a complete tabular context menu view.
101 */ 197 */
102 @VisibleForTesting 198 @VisibleForTesting
103 View createPagerView(Activity activity, ContextMenuParams params, 199 View createPagerView(Activity activity, ContextMenuParams params,
104 List<Pair<Integer, List<ContextMenuItem>>> itemGroups) { 200 List<Pair<Integer, List<ContextMenuItem>>> itemGroups) {
105 View view = LayoutInflater.from(activity).inflate(R.layout.tabular_conte xt_menu, null); 201 View view = LayoutInflater.from(activity).inflate(R.layout.tabular_conte xt_menu, null);
Theresa 2017/05/23 01:58:08 Can tabular_context_menu be updated to include the
Daniel Park 2017/05/24 16:44:31 Done.
106 202
107 List<Pair<String, ViewGroup>> viewGroups = new ArrayList<>(); 203 List<Pair<String, ViewGroup>> viewGroups = new ArrayList<>();
108 int maxCount = 0; 204 int maxCount = 0;
109 for (int i = 0; i < itemGroups.size(); i++) { 205 for (int i = 0; i < itemGroups.size(); i++) {
110 Pair<Integer, List<ContextMenuItem>> itemGroup = itemGroups.get(i); 206 Pair<Integer, List<ContextMenuItem>> itemGroup = itemGroups.get(i);
111 maxCount = Math.max(maxCount, itemGroup.second.size()); 207 maxCount = Math.max(maxCount, itemGroup.second.size());
112 } 208 }
113 for (int i = 0; i < itemGroups.size(); i++) { 209 for (int i = 0; i < itemGroups.size(); i++) {
114 Pair<Integer, List<ContextMenuItem>> itemGroup = itemGroups.get(i); 210 Pair<Integer, List<ContextMenuItem>> itemGroup = itemGroups.get(i);
115 // TODO(tedchoc): Pass the ContextMenuGroup identifier to determine if it's an image. 211 // TODO(tedchoc): Pass the ContextMenuGroup identifier to determine if it's an image.
116 boolean isImageTab = itemGroup.first == R.string.contextmenu_image_t itle; 212 boolean isImageTab = itemGroup.first == R.string.contextmenu_image_t itle;
117 viewGroups.add(new Pair<>(activity.getString(itemGroup.first), 213 viewGroups.add(new Pair<>(activity.getString(itemGroup.first),
118 createContextMenuPageUi( 214 createContextMenuPageUi(
119 activity, params, itemGroup.second, isImageTab, maxC ount))); 215 activity, params, itemGroup.second, isImageTab, maxC ount)));
120 } 216 }
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 217
128 TabularContextMenuViewPager pager = 218 TabularContextMenuViewPager pager =
129 (TabularContextMenuViewPager) view.findViewById(R.id.custom_page r); 219 (TabularContextMenuViewPager) view.findViewById(R.id.custom_page r);
130 pager.setAdapter(new TabularContextMenuPagerAdapter(viewGroups)); 220 pager.setAdapter(new TabularContextMenuPagerAdapter(viewGroups));
131
132 TabLayout tabLayout = (TabLayout) view.findViewById(R.id.tab_layout); 221 TabLayout tabLayout = (TabLayout) view.findViewById(R.id.tab_layout);
133 if (itemGroups.size() <= 1) { 222 if (itemGroups.size() <= 1) {
134 tabLayout.setVisibility(View.GONE); 223 tabLayout.setVisibility(View.GONE);
135 } else { 224 } else {
225 tabLayout.setBackgroundResource(R.drawable.grey_with_top_rounded_cor ners);
136 tabLayout.setupWithViewPager((ViewPager) view.findViewById(R.id.cust om_pager)); 226 tabLayout.setupWithViewPager((ViewPager) view.findViewById(R.id.cust om_pager));
137 } 227 }
138 228
139 return view; 229 return view;
140 } 230 }
141 231
142 /** 232 /**
143 * Creates the view of a context menu. Based off the Context Type, it'll adj ust the list of 233 * 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. 234 * items and display only the ones that'll be on that specific group.
235 *
145 * @param activity Used to get the resources of an item. 236 * @param activity Used to get the resources of an item.
146 * @param params used to create the header text. 237 * @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. 238 * @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 . 239 * @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 240 * @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 241 * or any other views calculated in the context menu. Used to est imate the size of
151 * of the list. 242 * the list.
152 * @return Returns a filled LinearLayout with all the context menu items. 243 * @return Returns a filled LinearLayout with all the context menu items.
153 */ 244 */
154 @VisibleForTesting 245 @VisibleForTesting
155 ViewGroup createContextMenuPageUi(Activity activity, ContextMenuParams param s, 246 ViewGroup createContextMenuPageUi(Activity activity, ContextMenuParams param s,
156 List<ContextMenuItem> items, boolean isImage, int maxCount) { 247 List<ContextMenuItem> items, boolean isImage, int maxCount) {
157 ViewGroup baseLayout = (ViewGroup) LayoutInflater.from(activity).inflate ( 248 ViewGroup baseLayout = (ViewGroup) LayoutInflater.from(activity).inflate (
158 R.layout.tabular_context_menu_page, null); 249 R.layout.tabular_context_menu_page, null);
159 ListView listView = (ListView) baseLayout.findViewById(R.id.selectable_i tems); 250 ListView listView = (ListView) baseLayout.findViewById(R.id.selectable_i tems);
160 251
161 displayHeaderIfVisibleItems(params, baseLayout); 252 displayHeaderIfVisibleItems(params, baseLayout);
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 BitmapDrawable bm = new BitmapDrawable(resources, bitmap); 329 BitmapDrawable bm = new BitmapDrawable(resources, bitmap);
239 bm.setTileModeXY(Shader.TileMode.REPEAT, Shader.TileMode.REPEAT); 330 bm.setTileModeXY(Shader.TileMode.REPEAT, Shader.TileMode.REPEAT);
240 imageView.setVisibility(View.VISIBLE); 331 imageView.setVisibility(View.VISIBLE);
241 imageView.setBackground(bm); 332 imageView.setBackground(bm);
242 } 333 }
243 334
244 /** 335 /**
245 * To save time measuring the height, this method gets an item if the height has not been 336 * 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 337 * 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. 338 * height too small as the ListView will scroll through the other values.
339 *
248 * @param listView The ListView to measure the surrounding padding. 340 * @param listView The ListView to measure the surrounding padding.
249 * @param listAdapter The adapter which contains the items within the list. 341 * @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 342 * @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. 343 * of the ListView based off the an item.
252 */ 344 */
253 private int measureApproximateListViewHeight( 345 private int measureApproximateListViewHeight(
254 ListView listView, BaseAdapter listAdapter, int maxCount) { 346 ListView listView, BaseAdapter listAdapter, int maxCount) {
255 int totalHeight = listView.getPaddingTop() + listView.getPaddingBottom() ; 347 int totalHeight = listView.getPaddingTop() + listView.getPaddingBottom() ;
256 if (mMenuItemHeight == 0 && !listAdapter.isEmpty()) { 348 if (mMenuItemHeight == 0 && !listAdapter.isEmpty()) {
257 View view = listAdapter.getView(0, null, listView); 349 View view = listAdapter.getView(0, null, listView);
258 view.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UN SPECIFIED), 350 view.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UN SPECIFIED),
259 View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECI FIED)); 351 View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECI FIED));
260 mMenuItemHeight = view.getMeasuredHeight(); 352 mMenuItemHeight = view.getMeasuredHeight();
261 } 353 }
262 return totalHeight + mMenuItemHeight * maxCount; 354 return totalHeight + mMenuItemHeight * maxCount;
263 } 355 }
264 356
265 /** 357 /**
266 * When an thumbnail is retrieved for the header of an image, this will set the header to 358 * @param touchPointX The x-coordinate of the pixel where the touch was regi stered.
Theresa 2017/05/23 01:58:07 nit: I think this would read better as "The x-coor
Daniel Park 2017/05/24 16:44:32 Done.
267 * that particular bitmap. 359 * @param touchPointY The y-coordinate of the pixel where the touch was regi stered.
360 * @param activity Activity to get the offsets.
Theresa 2017/05/23 01:58:08 Elaborate on what "offsets" means.
Daniel Park 2017/05/24 16:44:32 Done.
361 */
362 private void initializeAnimationAndRevealView(
363 final float touchPointX, final float touchPointY, Activity activity) {
364 mPagerView.setVisibility(View.VISIBLE);
365
366 int[] locationOnScreen = new int[2];
367 mPagerView.getLocationOnScreen(locationOnScreen);
368
369 mContextMenuYLocationOnScreen = locationOnScreen[1];
370 mPagerView.startAnimation(initAnimations(
371 touchPointX, touchPointY, locationOnScreen[0], locationOnScreen[ 1], activity));
372 mPagerView.getLocationOnScreen(locationOnScreen);
Theresa 2017/05/23 01:58:08 Why is getLocationOnScreen() called again here?
Daniel Park 2017/05/24 16:44:31 Done.
Daniel Park 2017/05/24 16:44:31 it was for debugging purposes that i forgot to tak
373 }
374
375 /**
376 * @param startX The starting x-coordinate of the translation animation.
377 * @param startY The starting y-coordinate of the translation animation.
378 * @param viewLocationX The x-coordinate of the top left corner of the view relative to the
379 * device.
380 * @param viewLocationY The y-coordinate of the top left corner of the view relative to the
381 * device.
382 * @param activity
Theresa 2017/05/23 01:58:08 activity needs a description
Daniel Park 2017/05/24 16:44:31 Done.
383 * @return Returns the animation set containing the scale & translation anim ations with the
384 * pivots set relative to the view because 0, 0 is relative to the v iew, not the device
Theresa 2017/05/23 01:58:08 nit: because 0,0.... belongs in an in-line comment
Daniel Park 2017/05/24 16:44:31 Done.
385 * window.
386 */
387 protected Animation initAnimations(final float touchPointX, final float touc hPointY,
Theresa 2017/05/23 01:58:07 nit: can this method be private?
Daniel Park 2017/05/24 16:44:32 Done.
388 int viewLocationX, int viewLocationY, Activity activity) {
389 Rect rectangle = new Rect();
390 Window window = activity.getWindow();
391 window.getDecorView().getWindowVisibleDisplayFrame(rectangle);
392
393 // yOffset represents how many pixels are taken up by anything above the content window
394 // e.g. toolbar & tab strip.
395 float yOffset =
396 rectangle.top + mContentViewCore.getRenderCoordinates().getConte ntOffsetYPix();
397
398 // xOffset represents how many pixels are taken up by anything to the le ft of the content
399 // window e.g. navigation bar of the Nexus 6P when in landscape mode wit h usb port to the
400 // left.
401 float xOffset = rectangle.left;
402
403 /**
404 * Touch points & view locations are relative to the content window i.e . 0, 0 represents
405 * the top left corner of the content window, but animation requires co ordinates relative
406 * to the context menu. These operations are to transform the content w indow coordinates
407 * to what they would be if they were relative to the the context menu.
408 */
409 mContextMenuSourceX = touchPointX - viewLocationX + xOffset;
410 mContextMenuSourceY = touchPointY - viewLocationY + yOffset;
411 return getScaleAnimation(true);
412 }
413
414 /**
415 * When an thumbnail is retrieved for the header of an image, this will set the header to that
416 * particular bitmap.
268 */ 417 */
269 public void onImageThumbnailRetrieved(Bitmap bitmap) { 418 public void onImageThumbnailRetrieved(Bitmap bitmap) {
270 if (mHeaderImageView != null) { 419 if (mHeaderImageView != null) {
271 mHeaderImageView.setImageBitmap(bitmap); 420 mHeaderImageView.setImageBitmap(bitmap);
272 } 421 }
273 } 422 }
274 423
275 @Override 424 @Override
276 public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) { 425 public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
277 mDialog.dismiss(); 426 mDialog.dismiss();
278 mCallback.onResult((int) id); 427 mCallback.onResult((int) id);
279 } 428 }
429
430 /**
431 * Gives this class access to the content view core to allow access to the t otal size of the
432 * toolbar and tab strip.
433 */
434 public void setContentViewCore(ContentViewCore contentViewCore) {
435 mContentViewCore = contentViewCore;
436 }
437
438 private Animation getScaleAnimation(boolean comingIn) {
439 float fromX = comingIn ? 0f : 1f;
440 float toX = comingIn ? 1f : 0f;
441 float fromY = fromX;
442 float toY = toX;
443
444 ScaleAnimation scaleAnimation = new ScaleAnimation(fromX, toX, fromY, to Y,
445 Animation.ABSOLUTE, mContextMenuSourceX, Animation.ABSOLUTE, mCo ntextMenuSourceY);
446
447 long duration = comingIn ? ANIMATION_IN_DURATION : ANIMATION_OUT_DURATIO N;
448 scaleAnimation.setDuration(duration);
449 scaleAnimation.setInterpolator(new LinearOutSlowInInterpolator());
450 return scaleAnimation;
451 }
280 } 452 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698