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

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/appmenu/AppMenuAdapter.java

Issue 2779543005: Add support for highlighting menu items (Closed)
Patch Set: Moved PulseDrawable Created 3 years, 8 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 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.content.res.Resources;
11 import android.graphics.drawable.Drawable; 12 import android.graphics.drawable.Drawable;
13 import android.graphics.drawable.LayerDrawable;
14 import android.support.annotation.IdRes;
12 import android.text.TextUtils; 15 import android.text.TextUtils;
13 import android.view.LayoutInflater; 16 import android.view.LayoutInflater;
14 import android.view.MenuItem; 17 import android.view.MenuItem;
15 import android.view.View; 18 import android.view.View;
16 import android.view.View.OnClickListener; 19 import android.view.View.OnClickListener;
17 import android.view.ViewGroup; 20 import android.view.ViewGroup;
18 import android.widget.BaseAdapter; 21 import android.widget.BaseAdapter;
19 import android.widget.ImageView; 22 import android.widget.ImageView;
20 import android.widget.ListView; 23 import android.widget.ListView;
21 import android.widget.TextView; 24 import android.widget.TextView;
22 25
23 import org.chromium.base.ApiCompatibilityUtils; 26 import org.chromium.base.ApiCompatibilityUtils;
27 import org.chromium.base.ContextUtils;
24 import org.chromium.chrome.R; 28 import org.chromium.chrome.R;
25 import org.chromium.chrome.browser.omaha.UpdateMenuItemHelper; 29 import org.chromium.chrome.browser.omaha.UpdateMenuItemHelper;
30 import org.chromium.chrome.browser.widget.PulseDrawable;
26 import org.chromium.chrome.browser.widget.TintedImageButton; 31 import org.chromium.chrome.browser.widget.TintedImageButton;
27 import org.chromium.ui.base.LocalizationUtils; 32 import org.chromium.ui.base.LocalizationUtils;
28 import org.chromium.ui.interpolators.BakedBezierInterpolator; 33 import org.chromium.ui.interpolators.BakedBezierInterpolator;
29 34
30 import java.util.List; 35 import java.util.List;
31 36
32 /** 37 /**
33 * ListAdapter to customize the view of items in the list. 38 * ListAdapter to customize the view of items in the list.
34 * 39 *
35 * The icon row in the menu is a special case of a MenuItem that displays multip le buttons in a row. 40 * The icon row in the menu is a special case of a MenuItem that displays multip le buttons in a row.
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 private static final int ENTER_ITEM_DURATION_MS = 350; 95 private static final int ENTER_ITEM_DURATION_MS = 350;
91 private static final int ENTER_ITEM_BASE_DELAY_MS = 80; 96 private static final int ENTER_ITEM_BASE_DELAY_MS = 80;
92 private static final int ENTER_ITEM_ADDL_DELAY_MS = 30; 97 private static final int ENTER_ITEM_ADDL_DELAY_MS = 30;
93 private static final float ENTER_STANDARD_ITEM_OFFSET_Y_DP = -10.f; 98 private static final float ENTER_STANDARD_ITEM_OFFSET_Y_DP = -10.f;
94 private static final float ENTER_STANDARD_ITEM_OFFSET_X_DP = 10.f; 99 private static final float ENTER_STANDARD_ITEM_OFFSET_X_DP = 10.f;
95 100
96 private final AppMenu mAppMenu; 101 private final AppMenu mAppMenu;
97 private final LayoutInflater mInflater; 102 private final LayoutInflater mInflater;
98 private final List<MenuItem> mMenuItems; 103 private final List<MenuItem> mMenuItems;
99 private final int mNumMenuItems; 104 private final int mNumMenuItems;
105 @IdRes
106 private final int mHighlightedItemId;
100 private final float mDpToPx; 107 private final float mDpToPx;
101 108
102 public AppMenuAdapter(AppMenu appMenu, List<MenuItem> menuItems, LayoutInfla ter inflater) { 109 // Use a single PulseDrawable to spawn the other drawables so that the Const antState gets
110 // shared. This allows the animation to stay in step even as the views are recycled and the
111 // background gets changed. This Drawable isn't just used directly because Drawables need to
112 // have a single owner or the internals of View can modify it's state as it gets cleared later.
113 private PulseDrawable mHighlightDrawableSource;
114
115 public AppMenuAdapter(AppMenu appMenu, List<MenuItem> menuItems, LayoutInfla ter inflater,
116 @IdRes int highlightedItemId) {
103 mAppMenu = appMenu; 117 mAppMenu = appMenu;
104 mMenuItems = menuItems; 118 mMenuItems = menuItems;
105 mInflater = inflater; 119 mInflater = inflater;
120 mHighlightedItemId = highlightedItemId;
106 mNumMenuItems = menuItems.size(); 121 mNumMenuItems = menuItems.size();
107 mDpToPx = inflater.getContext().getResources().getDisplayMetrics().densi ty; 122 mDpToPx = inflater.getContext().getResources().getDisplayMetrics().densi ty;
108 } 123 }
109 124
110 @Override 125 @Override
111 public int getCount() { 126 public int getCount() {
112 return mNumMenuItems; 127 return mNumMenuItems;
113 } 128 }
114 129
115 @Override 130 @Override
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 StandardMenuItemViewHolder holder = null; 172 StandardMenuItemViewHolder holder = null;
158 if (convertView == null 173 if (convertView == null
159 || !(convertView.getTag() instanceof StandardMenuItemVie wHolder)) { 174 || !(convertView.getTag() instanceof StandardMenuItemVie wHolder)) {
160 holder = new StandardMenuItemViewHolder(); 175 holder = new StandardMenuItemViewHolder();
161 convertView = mInflater.inflate(R.layout.menu_item, parent, false); 176 convertView = mInflater.inflate(R.layout.menu_item, parent, false);
162 holder.text = (TextView) convertView.findViewById(R.id.menu_ item_text); 177 holder.text = (TextView) convertView.findViewById(R.id.menu_ item_text);
163 holder.image = (AppMenuItemIcon) convertView.findViewById(R. id.menu_item_icon); 178 holder.image = (AppMenuItemIcon) convertView.findViewById(R. id.menu_item_icon);
164 convertView.setTag(holder); 179 convertView.setTag(holder);
165 convertView.setTag(R.id.menu_item_enter_anim_id, 180 convertView.setTag(R.id.menu_item_enter_anim_id,
166 buildStandardItemEnterAnimator(convertView, position )); 181 buildStandardItemEnterAnimator(convertView, position ));
182 convertView.setTag(
183 R.id.menu_item_original_background, convertView.getB ackground());
167 } else { 184 } else {
168 holder = (StandardMenuItemViewHolder) convertView.getTag(); 185 holder = (StandardMenuItemViewHolder) convertView.getTag();
169 } 186 }
170 187
171 setupStandardMenuItemViewHolder(holder, convertView, item); 188 setupStandardMenuItemViewHolder(holder, convertView, item);
172 break; 189 break;
173 } 190 }
174 case UPDATE_MENU_ITEM: { 191 case UPDATE_MENU_ITEM: {
175 CustomMenuItemViewHolder holder = null; 192 CustomMenuItemViewHolder holder = null;
176 if (convertView == null 193 if (convertView == null
177 || !(convertView.getTag() instanceof CustomMenuItemViewH older)) { 194 || !(convertView.getTag() instanceof CustomMenuItemViewH older)) {
178 holder = new CustomMenuItemViewHolder(); 195 holder = new CustomMenuItemViewHolder();
179 convertView = mInflater.inflate(R.layout.update_menu_item, p arent, false); 196 convertView = mInflater.inflate(R.layout.update_menu_item, p arent, false);
180 holder.text = (TextView) convertView.findViewById(R.id.menu_ item_text); 197 holder.text = (TextView) convertView.findViewById(R.id.menu_ item_text);
181 holder.image = (AppMenuItemIcon) convertView.findViewById(R. id.menu_item_icon); 198 holder.image = (AppMenuItemIcon) convertView.findViewById(R. id.menu_item_icon);
182 holder.summary = (TextView) convertView.findViewById(R.id.me nu_item_summary); 199 holder.summary = (TextView) convertView.findViewById(R.id.me nu_item_summary);
183 convertView.setTag(holder); 200 convertView.setTag(holder);
184 convertView.setTag(R.id.menu_item_enter_anim_id, 201 convertView.setTag(R.id.menu_item_enter_anim_id,
185 buildStandardItemEnterAnimator(convertView, position )); 202 buildStandardItemEnterAnimator(convertView, position ));
203 convertView.setTag(
204 R.id.menu_item_original_background, convertView.getB ackground());
186 } else { 205 } else {
187 holder = (CustomMenuItemViewHolder) convertView.getTag(); 206 holder = (CustomMenuItemViewHolder) convertView.getTag();
188 } 207 }
189 208
190 setupStandardMenuItemViewHolder(holder, convertView, item); 209 setupStandardMenuItemViewHolder(holder, convertView, item);
191 String summary = UpdateMenuItemHelper.getInstance().getMenuItemS ummaryText( 210 String summary = UpdateMenuItemHelper.getInstance().getMenuItemS ummaryText(
192 mInflater.getContext()); 211 mInflater.getContext());
193 if (TextUtils.isEmpty(summary)) { 212 if (TextUtils.isEmpty(summary)) {
194 holder.summary.setVisibility(View.GONE); 213 holder.summary.setVisibility(View.GONE);
195 } else { 214 } else {
(...skipping 15 matching lines...) Expand all
211 break; 230 break;
212 } 231 }
213 case TITLE_BUTTON_MENU_ITEM: { 232 case TITLE_BUTTON_MENU_ITEM: {
214 TitleButtonMenuItemViewHolder holder = null; 233 TitleButtonMenuItemViewHolder holder = null;
215 if (convertView == null 234 if (convertView == null
216 || !(convertView.getTag() instanceof TitleButtonMenuItem ViewHolder)) { 235 || !(convertView.getTag() instanceof TitleButtonMenuItem ViewHolder)) {
217 holder = new TitleButtonMenuItemViewHolder(); 236 holder = new TitleButtonMenuItemViewHolder();
218 convertView = mInflater.inflate(R.layout.title_button_menu_i tem, parent, false); 237 convertView = mInflater.inflate(R.layout.title_button_menu_i tem, parent, false);
219 holder.title = (TextView) convertView.findViewById(R.id.titl e); 238 holder.title = (TextView) convertView.findViewById(R.id.titl e);
220 holder.button = (TintedImageButton) convertView.findViewById (R.id.button); 239 holder.button = (TintedImageButton) convertView.findViewById (R.id.button);
221 240 holder.button.setTag(
241 R.id.menu_item_original_background, holder.button.ge tBackground());
222 View animatedView = convertView; 242 View animatedView = convertView;
223 243
224 convertView.setTag(holder); 244 convertView.setTag(holder);
225 convertView.setTag(R.id.menu_item_enter_anim_id, 245 convertView.setTag(R.id.menu_item_enter_anim_id,
226 buildStandardItemEnterAnimator(animatedView, positio n)); 246 buildStandardItemEnterAnimator(animatedView, positio n));
247 convertView.setTag(
248 R.id.menu_item_original_background, convertView.getB ackground());
227 } else { 249 } else {
228 holder = (TitleButtonMenuItemViewHolder) convertView.getTag( ); 250 holder = (TitleButtonMenuItemViewHolder) convertView.getTag( );
229 } 251 }
230 final MenuItem titleItem = item.hasSubMenu() ? item.getSubMenu() .getItem(0) : item; 252 final MenuItem titleItem = item.hasSubMenu() ? item.getSubMenu() .getItem(0) : item;
231 holder.title.setText(titleItem.getTitle()); 253 holder.title.setText(titleItem.getTitle());
232 holder.title.setEnabled(titleItem.isEnabled()); 254 holder.title.setEnabled(titleItem.isEnabled());
233 holder.title.setFocusable(titleItem.isEnabled()); 255 holder.title.setFocusable(titleItem.isEnabled());
234 holder.title.setOnClickListener(new OnClickListener() { 256 holder.title.setOnClickListener(new OnClickListener() {
235 @Override 257 @Override
236 public void onClick(View v) { 258 public void onClick(View v) {
237 mAppMenu.onItemClick(titleItem); 259 mAppMenu.onItemClick(titleItem);
238 } 260 }
239 }); 261 });
240 262
241 if (item.getSubMenu().getItem(1).getIcon() != null) { 263 if (item.getSubMenu().getItem(1).getIcon() != null) {
242 holder.button.setVisibility(View.VISIBLE); 264 holder.button.setVisibility(View.VISIBLE);
243 setupImageButton(holder.button, item.getSubMenu().getItem(1) ); 265 setupImageButton(holder.button, item.getSubMenu().getItem(1) );
244 } else { 266 } else {
245 holder.button.setVisibility(View.GONE); 267 holder.button.setVisibility(View.GONE);
246 } 268 }
247 convertView.setFocusable(false); 269 convertView.setFocusable(false);
248 convertView.setEnabled(false); 270 convertView.setEnabled(false);
249 break; 271 break;
250 } 272 }
251 default: 273 default:
252 assert false : "Unexpected MenuItem type"; 274 assert false : "Unexpected MenuItem type";
253 } 275 }
276
277 highlightItemIfNecessary(convertView, false, item.getItemId());
278
254 return convertView; 279 return convertView;
255 } 280 }
256 281
257 private void setupImageButton(TintedImageButton button, final MenuItem item) { 282 private void setupImageButton(TintedImageButton button, final MenuItem item) {
258 // Store and recover the level of image as button.setimageDrawable 283 // Store and recover the level of image as button.setimageDrawable
259 // resets drawable to default level. 284 // resets drawable to default level.
260 int currentLevel = item.getIcon().getLevel(); 285 int currentLevel = item.getIcon().getLevel();
261 button.setImageDrawable(item.getIcon()); 286 button.setImageDrawable(item.getIcon());
262 item.getIcon().setLevel(currentLevel); 287 item.getIcon().setLevel(currentLevel);
263 if (item.isChecked()) { 288 if (item.isChecked()) {
264 button.setTint(ApiCompatibilityUtils.getColorStateList( 289 button.setTint(ApiCompatibilityUtils.getColorStateList(
265 button.getResources(), R.color.blue_mode_tint)); 290 button.getResources(), R.color.blue_mode_tint));
266 } 291 }
267 button.setEnabled(item.isEnabled()); 292 button.setEnabled(item.isEnabled());
268 button.setFocusable(item.isEnabled()); 293 button.setFocusable(item.isEnabled());
269 button.setContentDescription(item.getTitleCondensed()); 294 button.setContentDescription(item.getTitleCondensed());
270 295
271 button.setOnClickListener(new OnClickListener() { 296 button.setOnClickListener(new OnClickListener() {
272 @Override 297 @Override
273 public void onClick(View v) { 298 public void onClick(View v) {
274 mAppMenu.onItemClick(item); 299 mAppMenu.onItemClick(item);
275 } 300 }
276 }); 301 });
277 302
303 highlightItemIfNecessary(button, true, item.getItemId());
304
278 // Menu items may be hidden by command line flags before they get to thi s point. 305 // Menu items may be hidden by command line flags before they get to thi s point.
279 button.setVisibility(item.isVisible() ? View.VISIBLE : View.GONE); 306 button.setVisibility(item.isVisible() ? View.VISIBLE : View.GONE);
280 } 307 }
281 308
282 private void setupStandardMenuItemViewHolder(StandardMenuItemViewHolder hold er, 309 private void setupStandardMenuItemViewHolder(StandardMenuItemViewHolder hold er,
283 View convertView, final MenuItem item) { 310 View convertView, final MenuItem item) {
284 // Set up the icon. 311 // Set up the icon.
285 Drawable icon = item.getIcon(); 312 Drawable icon = item.getIcon();
286 holder.image.setImageDrawable(icon); 313 holder.image.setImageDrawable(icon);
287 holder.image.setVisibility(icon == null ? View.GONE : View.VISIBLE); 314 holder.image.setVisibility(icon == null ? View.GONE : View.VISIBLE);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 view.setAlpha(0.f); 356 view.setAlpha(0.f);
330 } 357 }
331 }); 358 });
332 return animation; 359 return animation;
333 } 360 }
334 361
335 /** 362 /**
336 * This builds an {@link Animator} for the enter animation of icon row menu items. This means 363 * This builds an {@link Animator} for the enter animation of icon row menu items. This means
337 * it will animate the alpha from 0 to 1 and translate the views from 10dp t o 0dp on the x axis. 364 * it will animate the alpha from 0 to 1 and translate the views from 10dp t o 0dp on the x axis.
338 * 365 *
339 * @param views The list if icons in the menu item that should be ani mated. 366 * @param buttons The list of icons in the menu item that should be animated .
340 * @return The {@link Animator}. 367 * @return The {@link Animator}.
341 */ 368 */
342 private Animator buildIconItemEnterAnimator(final ImageView[] views) { 369 private Animator buildIconItemEnterAnimator(final ImageView[] buttons) {
343 final boolean rtl = LocalizationUtils.isLayoutRtl(); 370 final boolean rtl = LocalizationUtils.isLayoutRtl();
344 final float offsetXPx = ENTER_STANDARD_ITEM_OFFSET_X_DP * mDpToPx * (rtl ? -1.f : 1.f); 371 final float offsetXPx = ENTER_STANDARD_ITEM_OFFSET_X_DP * mDpToPx * (rtl ? -1.f : 1.f);
345 final int maxViewsToAnimate = views.length; 372 final int maxViewsToAnimate = buttons.length;
346 373
347 AnimatorSet animation = new AnimatorSet(); 374 AnimatorSet animation = new AnimatorSet();
348 AnimatorSet.Builder builder = null; 375 AnimatorSet.Builder builder = null;
349 for (int i = 0; i < maxViewsToAnimate; i++) { 376 for (int i = 0; i < maxViewsToAnimate; i++) {
350 final int startDelay = ENTER_ITEM_ADDL_DELAY_MS * i; 377 final int startDelay = ENTER_ITEM_ADDL_DELAY_MS * i;
351 378
352 Animator alpha = ObjectAnimator.ofFloat(views[i], View.ALPHA, 0.f, 1 .f); 379 ImageView view = buttons[i];
353 Animator translate = ObjectAnimator.ofFloat(views[i], View.TRANSLATI ON_X, offsetXPx, 0); 380 Animator alpha = ObjectAnimator.ofFloat(view, View.ALPHA, 0.f, 1.f);
381 Animator translate = ObjectAnimator.ofFloat(view, View.TRANSLATION_X , offsetXPx, 0);
354 alpha.setStartDelay(startDelay); 382 alpha.setStartDelay(startDelay);
355 translate.setStartDelay(startDelay); 383 translate.setStartDelay(startDelay);
356 alpha.setDuration(ENTER_ITEM_DURATION_MS); 384 alpha.setDuration(ENTER_ITEM_DURATION_MS);
357 translate.setDuration(ENTER_ITEM_DURATION_MS); 385 translate.setDuration(ENTER_ITEM_DURATION_MS);
358 386
359 if (builder == null) { 387 if (builder == null) {
360 builder = animation.play(alpha); 388 builder = animation.play(alpha);
361 } else { 389 } else {
362 builder.with(alpha); 390 builder.with(alpha);
363 } 391 }
364 builder.with(translate); 392 builder.with(translate);
365 } 393 }
366 animation.setStartDelay(ENTER_ITEM_BASE_DELAY_MS); 394 animation.setStartDelay(ENTER_ITEM_BASE_DELAY_MS);
367 animation.setInterpolator(BakedBezierInterpolator.FADE_IN_CURVE); 395 animation.setInterpolator(BakedBezierInterpolator.FADE_IN_CURVE);
368 396
369 animation.addListener(new AnimatorListenerAdapter() { 397 animation.addListener(new AnimatorListenerAdapter() {
370 @Override 398 @Override
371 public void onAnimationStart(Animator animation) { 399 public void onAnimationStart(Animator animation) {
372 for (int i = 0; i < maxViewsToAnimate; i++) { 400 for (int i = 0; i < maxViewsToAnimate; i++) {
373 views[i].setAlpha(0.f); 401 buttons[i].setAlpha(0.f);
374 } 402 }
375 } 403 }
376 }); 404 });
377 return animation; 405 return animation;
378 } 406 }
379 407
380 private View createMenuItemRow( 408 private View createMenuItemRow(
381 View convertView, ViewGroup parent, MenuItem item, int numItems) { 409 View convertView, ViewGroup parent, MenuItem item, int numItems) {
382 RowItemViewHolder holder = null; 410 RowItemViewHolder holder = null;
383 if (convertView == null 411 if (convertView == null
384 || !(convertView.getTag() instanceof RowItemViewHolder) 412 || !(convertView.getTag() instanceof RowItemViewHolder)
385 || ((RowItemViewHolder) convertView.getTag()).buttons.length != numItems) { 413 || ((RowItemViewHolder) convertView.getTag()).buttons.length != numItems) {
386 holder = new RowItemViewHolder(numItems); 414 holder = new RowItemViewHolder(numItems);
387 convertView = mInflater.inflate(R.layout.icon_row_menu_item, parent, false); 415 convertView = mInflater.inflate(R.layout.icon_row_menu_item, parent, false);
416 convertView.setTag(R.id.menu_item_original_background, convertView.g etBackground());
388 417
389 // Save references to all the buttons. 418 // Save references to all the buttons.
390 for (int i = 0; i < numItems; i++) { 419 for (int i = 0; i < numItems; i++) {
391 holder.buttons[i] = 420 TintedImageButton view =
392 (TintedImageButton) convertView.findViewById(BUTTON_IDS[ i]); 421 (TintedImageButton) convertView.findViewById(BUTTON_IDS[ i]);
422 holder.buttons[i] = view;
423 holder.buttons[i].setTag(
424 R.id.menu_item_original_background, holder.buttons[i].ge tBackground());
393 } 425 }
394 426
395 // Remove unused menu items. 427 // Remove unused menu items.
396 for (int j = numItems; j < 5; j++) { 428 for (int j = numItems; j < 5; j++) {
397 ((ViewGroup) convertView).removeView(convertView.findViewById(BU TTON_IDS[j])); 429 ((ViewGroup) convertView).removeView(convertView.findViewById(BU TTON_IDS[j]));
398 } 430 }
399 431
400 convertView.setTag(holder); 432 convertView.setTag(holder);
401 convertView.setTag(R.id.menu_item_enter_anim_id, 433 convertView.setTag(R.id.menu_item_enter_anim_id,
402 buildIconItemEnterAnimator(holder.buttons)); 434 buildIconItemEnterAnimator(holder.buttons));
403 } else { 435 } else {
404 holder = (RowItemViewHolder) convertView.getTag(); 436 holder = (RowItemViewHolder) convertView.getTag();
405 } 437 }
406 438
407 for (int i = 0; i < numItems; i++) { 439 for (int i = 0; i < numItems; i++) {
408 setupImageButton(holder.buttons[i], item.getSubMenu().getItem(i)); 440 setupImageButton(holder.buttons[i], item.getSubMenu().getItem(i));
409 } 441 }
410 convertView.setFocusable(false); 442 convertView.setFocusable(false);
411 convertView.setEnabled(false); 443 convertView.setEnabled(false);
412 return convertView; 444 return convertView;
413 } 445 }
414 446
447 private void highlightItemIfNecessary(View view, boolean isIcon, int itemId) {
448 Drawable background = (Drawable) view.getTag(R.id.menu_item_original_bac kground);
449 if (background == null) return;
450
451 if (itemId != mHighlightedItemId) {
452 view.setBackground(background);
453 return;
454 }
455
456 if (mHighlightDrawableSource == null) {
457 mHighlightDrawableSource =
458 isIcon ? PulseDrawable.createCircle() : PulseDrawable.create Highlight();
459 }
460
461 Resources resources = ContextUtils.getApplicationContext().getResources( );
462
463 PulseDrawable pulse =
464 (PulseDrawable) mHighlightDrawableSource.getConstantState().newD rawable(resources);
465 if (background.getConstantState() != null) {
466 background = background.getConstantState().newDrawable(resources);
467 }
468
469 LayerDrawable drawable = new LayerDrawable(new Drawable[] {pulse, backgr ound});
470 view.setBackground(drawable);
471 pulse.start();
472 }
473
415 static class StandardMenuItemViewHolder { 474 static class StandardMenuItemViewHolder {
416 public TextView text; 475 public TextView text;
417 public AppMenuItemIcon image; 476 public AppMenuItemIcon image;
418 } 477 }
419 478
420 static class CustomMenuItemViewHolder extends StandardMenuItemViewHolder { 479 static class CustomMenuItemViewHolder extends StandardMenuItemViewHolder {
421 public TextView summary; 480 public TextView summary;
422 } 481 }
423 482
424 private static class RowItemViewHolder { 483 private static class RowItemViewHolder {
425 public TintedImageButton[] buttons; 484 public TintedImageButton[] buttons;
426 485
427 RowItemViewHolder(int numButtons) { 486 RowItemViewHolder(int numButtons) {
428 buttons = new TintedImageButton[numButtons]; 487 buttons = new TintedImageButton[numButtons];
429 } 488 }
430 } 489 }
431 490
432 static class TitleButtonMenuItemViewHolder { 491 static class TitleButtonMenuItemViewHolder {
433 public TextView title; 492 public TextView title;
434 public TintedImageButton button; 493 public TintedImageButton button;
435 } 494 }
436 } 495 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698