OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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.appmenu; | 5 package org.chromium.chrome.browser.appmenu; |
6 | 6 |
7 import android.animation.Animator; | 7 import android.animation.Animator; |
8 import android.animation.AnimatorListenerAdapter; | 8 import android.animation.AnimatorListenerAdapter; |
9 import android.animation.AnimatorSet; | 9 import android.animation.AnimatorSet; |
10 import android.animation.ObjectAnimator; | 10 import android.animation.ObjectAnimator; |
11 import android.graphics.drawable.Drawable; | 11 import android.graphics.drawable.Drawable; |
12 import android.view.LayoutInflater; | 12 import android.view.LayoutInflater; |
13 import android.view.MenuItem; | 13 import android.view.MenuItem; |
14 import android.view.View; | 14 import android.view.View; |
15 import android.view.View.OnClickListener; | 15 import android.view.View.OnClickListener; |
16 import android.view.ViewGroup; | 16 import android.view.ViewGroup; |
17 import android.widget.BaseAdapter; | 17 import android.widget.BaseAdapter; |
18 import android.widget.ImageButton; | 18 import android.widget.ImageButton; |
19 import android.widget.ImageView; | 19 import android.widget.ImageView; |
20 import android.widget.ImageView.ScaleType; | |
20 import android.widget.ListView; | 21 import android.widget.ListView; |
21 import android.widget.TextView; | 22 import android.widget.TextView; |
22 | 23 |
24 import org.chromium.base.ApiCompatibilityUtils; | |
23 import org.chromium.chrome.R; | 25 import org.chromium.chrome.R; |
26 import org.chromium.ui.base.LocalizationUtils; | |
24 import org.chromium.ui.interpolators.BakedBezierInterpolator; | 27 import org.chromium.ui.interpolators.BakedBezierInterpolator; |
25 | 28 |
26 import java.util.List; | 29 import java.util.List; |
27 | 30 |
28 /** | 31 /** |
29 * ListAdapter to customize the view of items in the list. | 32 * ListAdapter to customize the view of items in the list. |
30 */ | 33 */ |
31 class AppMenuAdapter extends BaseAdapter { | 34 class AppMenuAdapter extends BaseAdapter { |
32 private static final int VIEW_TYPE_COUNT = 4; | 35 private static final int VIEW_TYPE_COUNT = 4; |
33 | 36 |
(...skipping 15 matching lines...) Expand all Loading... | |
49 */ | 52 */ |
50 private static final int FOUR_BUTTON_MENU_ITEM = 3; | 53 private static final int FOUR_BUTTON_MENU_ITEM = 3; |
51 | 54 |
52 /** MenuItem Animation Constants */ | 55 /** MenuItem Animation Constants */ |
53 private static final int ENTER_ITEM_DURATION_MS = 350; | 56 private static final int ENTER_ITEM_DURATION_MS = 350; |
54 private static final int ENTER_ITEM_BASE_DELAY_MS = 80; | 57 private static final int ENTER_ITEM_BASE_DELAY_MS = 80; |
55 private static final int ENTER_ITEM_ADDL_DELAY_MS = 30; | 58 private static final int ENTER_ITEM_ADDL_DELAY_MS = 30; |
56 private static final float ENTER_STANDARD_ITEM_OFFSET_Y_DP = -10.f; | 59 private static final float ENTER_STANDARD_ITEM_OFFSET_Y_DP = -10.f; |
57 private static final float ENTER_STANDARD_ITEM_OFFSET_X_DP = 10.f; | 60 private static final float ENTER_STANDARD_ITEM_OFFSET_X_DP = 10.f; |
58 | 61 |
62 /** Menu Button Layout Constants */ | |
63 private static final float MENU_BUTTON_WIDTH_DP = 59.f; | |
64 private static final float MENU_BUTTON_START_PADDING_DP = 19.f; | |
65 | |
59 private final AppMenu mAppMenu; | 66 private final AppMenu mAppMenu; |
60 private final LayoutInflater mInflater; | 67 private final LayoutInflater mInflater; |
61 private final List<MenuItem> mMenuItems; | 68 private final List<MenuItem> mMenuItems; |
62 private final int mNumMenuItems; | 69 private final int mNumMenuItems; |
63 private final boolean mShowMenuButton; | 70 private final boolean mShowMenuButton; |
64 private final float mDpToPx; | 71 private final float mDpToPx; |
65 | 72 |
66 public AppMenuAdapter(AppMenu appMenu, List<MenuItem> menuItems, LayoutInfla ter inflater, | 73 public AppMenuAdapter(AppMenu appMenu, List<MenuItem> menuItems, LayoutInfla ter inflater, |
67 boolean showMenuButton) { | 74 boolean showMenuButton) { |
68 mAppMenu = appMenu; | 75 mAppMenu = appMenu; |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
204 convertView.setEnabled(false); | 211 convertView.setEnabled(false); |
205 break; | 212 break; |
206 } | 213 } |
207 case TITLE_BUTTON_MENU_ITEM: { | 214 case TITLE_BUTTON_MENU_ITEM: { |
208 TitleButtonMenuItemViewHolder holder = null; | 215 TitleButtonMenuItemViewHolder holder = null; |
209 if (convertView == null) { | 216 if (convertView == null) { |
210 holder = new TitleButtonMenuItemViewHolder(); | 217 holder = new TitleButtonMenuItemViewHolder(); |
211 convertView = mInflater.inflate(R.layout.title_button_menu_i tem, parent, false); | 218 convertView = mInflater.inflate(R.layout.title_button_menu_i tem, parent, false); |
212 holder.title = (TextView) convertView.findViewById(R.id.titl e); | 219 holder.title = (TextView) convertView.findViewById(R.id.titl e); |
213 holder.button = (ImageButton) convertView.findViewById(R.id. button); | 220 holder.button = (ImageButton) convertView.findViewById(R.id. button); |
221 | |
222 View animatedView = hasMenuButton ? holder.title : convertVi ew; | |
223 | |
214 convertView.setTag(holder); | 224 convertView.setTag(holder); |
215 convertView.setTag(R.id.menu_item_enter_anim_id, | 225 convertView.setTag(R.id.menu_item_enter_anim_id, |
216 buildStandardItemEnterAnimator(convertView, position )); | 226 buildStandardItemEnterAnimator(animatedView, positio n)); |
217 } else { | 227 } else { |
218 holder = (TitleButtonMenuItemViewHolder) convertView.getTag( ); | 228 holder = (TitleButtonMenuItemViewHolder) convertView.getTag( ); |
219 } | 229 } |
220 final MenuItem titleItem = item.hasSubMenu() ? item.getSubMenu() .getItem(0) : item; | 230 final MenuItem titleItem = item.hasSubMenu() ? item.getSubMenu() .getItem(0) : item; |
221 holder.title.setText(titleItem.getTitle()); | 231 holder.title.setText(titleItem.getTitle()); |
222 holder.title.setEnabled(titleItem.isEnabled()); | 232 holder.title.setEnabled(titleItem.isEnabled()); |
223 holder.title.setFocusable(titleItem.isEnabled()); | 233 holder.title.setFocusable(titleItem.isEnabled()); |
224 holder.title.setOnClickListener(new OnClickListener() { | 234 holder.title.setOnClickListener(new OnClickListener() { |
225 @Override | 235 @Override |
226 public void onClick(View v) { | 236 public void onClick(View v) { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
268 button.setImageResource(R.drawable.btn_menu_pressed); | 278 button.setImageResource(R.drawable.btn_menu_pressed); |
269 button.setContentDescription(button.getResources().getString(R.string.me nu_dismiss_btn)); | 279 button.setContentDescription(button.getResources().getString(R.string.me nu_dismiss_btn)); |
270 button.setEnabled(true); | 280 button.setEnabled(true); |
271 button.setFocusable(true); | 281 button.setFocusable(true); |
272 button.setOnClickListener(new OnClickListener() { | 282 button.setOnClickListener(new OnClickListener() { |
273 @Override | 283 @Override |
274 public void onClick(View v) { | 284 public void onClick(View v) { |
275 mAppMenu.dismiss(); | 285 mAppMenu.dismiss(); |
276 } | 286 } |
277 }); | 287 }); |
288 | |
289 // Set the button layout to make it properly line up with any underlying menu button | |
290 ApiCompatibilityUtils.setPaddingRelative( | |
aurimas (slooooooooow)
2014/07/25 18:21:03
Do we need to reset these somewhere since we are r
David Trainor- moved to gerrit
2014/07/25 20:01:17
Ah good point!
| |
291 button, (int) (MENU_BUTTON_START_PADDING_DP * mDpToPx), 0, 0, 0) ; | |
292 button.getLayoutParams().width = (int) (MENU_BUTTON_WIDTH_DP * mDpToPx); | |
293 button.setScaleType(ScaleType.CENTER); | |
278 } | 294 } |
279 | 295 |
280 /** | 296 /** |
281 * This builds an {@link Animator} for the enter animation of a standard men u item. This means | 297 * This builds an {@link Animator} for the enter animation of a standard men u item. This means |
282 * it will animate the alpha from 0 to 1 and translate the view from -10dp t o 0dp on the y axis. | 298 * it will animate the alpha from 0 to 1 and translate the view from -10dp t o 0dp on the y axis. |
283 * | 299 * |
284 * @param view The menu item {@link View} to be animated. | 300 * @param view The menu item {@link View} to be animated. |
285 * @param position The position in the menu. This impacts the start delay o f the animation. | 301 * @param position The position in the menu. This impacts the start delay o f the animation. |
286 * @return The {@link Animator}. | 302 * @return The {@link Animator}. |
287 */ | 303 */ |
(...skipping 20 matching lines...) Expand all Loading... | |
308 | 324 |
309 /** | 325 /** |
310 * This builds an {@link Animator} for the enter animation of icon row menu items. This means | 326 * This builds an {@link Animator} for the enter animation of icon row menu items. This means |
311 * it will animate the alpha from 0 to 1 and translate the views from 10dp t o 0dp on the x axis. | 327 * it will animate the alpha from 0 to 1 and translate the views from 10dp t o 0dp on the x axis. |
312 * | 328 * |
313 * @param views The list if icons in the menu item that should be ani mated. | 329 * @param views The list if icons in the menu item that should be ani mated. |
314 * @param skipLastItem Whether or not the last item should be animated or no t. | 330 * @param skipLastItem Whether or not the last item should be animated or no t. |
315 * @return The {@link Animator}. | 331 * @return The {@link Animator}. |
316 */ | 332 */ |
317 private Animator buildIconItemEnterAnimator(final ImageView[] views, boolean skipLastItem) { | 333 private Animator buildIconItemEnterAnimator(final ImageView[] views, boolean skipLastItem) { |
318 final float offsetXPx = ENTER_STANDARD_ITEM_OFFSET_X_DP * mDpToPx; | 334 final boolean rtl = LocalizationUtils.isLayoutRtl(); |
335 final float offsetXPx = ENTER_STANDARD_ITEM_OFFSET_X_DP * mDpToPx * (rtl ? -1.f : 1.f); | |
319 final int maxViewsToAnimate = views.length - (skipLastItem ? 1 : 0); | 336 final int maxViewsToAnimate = views.length - (skipLastItem ? 1 : 0); |
320 | 337 |
321 AnimatorSet animation = new AnimatorSet(); | 338 AnimatorSet animation = new AnimatorSet(); |
322 AnimatorSet.Builder builder = null; | 339 AnimatorSet.Builder builder = null; |
323 for (int i = 0; i < maxViewsToAnimate; i++) { | 340 for (int i = 0; i < maxViewsToAnimate; i++) { |
324 final int startDelay = ENTER_ITEM_ADDL_DELAY_MS * i; | 341 final int startDelay = ENTER_ITEM_ADDL_DELAY_MS * i; |
325 | 342 |
326 Animator alpha = ObjectAnimator.ofFloat(views[i], View.ALPHA, 0.f, 1 .f); | 343 Animator alpha = ObjectAnimator.ofFloat(views[i], View.ALPHA, 0.f, 1 .f); |
327 Animator translate = ObjectAnimator.ofFloat(views[i], View.TRANSLATI ON_X, offsetXPx, 0); | 344 Animator translate = ObjectAnimator.ofFloat(views[i], View.TRANSLATI ON_X, offsetXPx, 0); |
328 alpha.setStartDelay(startDelay); | 345 alpha.setStartDelay(startDelay); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
362 | 379 |
363 static class FourButtonMenuItemViewHolder { | 380 static class FourButtonMenuItemViewHolder { |
364 public ImageButton[] buttons = new ImageButton[4]; | 381 public ImageButton[] buttons = new ImageButton[4]; |
365 } | 382 } |
366 | 383 |
367 static class TitleButtonMenuItemViewHolder { | 384 static class TitleButtonMenuItemViewHolder { |
368 public TextView title; | 385 public TextView title; |
369 public ImageButton button; | 386 public ImageButton button; |
370 } | 387 } |
371 } | 388 } |
OLD | NEW |