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.graphics.drawable.LayerDrawable; | |
13 import android.support.annotation.IdRes; | |
12 import android.text.TextUtils; | 14 import android.text.TextUtils; |
13 import android.view.LayoutInflater; | 15 import android.view.LayoutInflater; |
14 import android.view.MenuItem; | 16 import android.view.MenuItem; |
15 import android.view.View; | 17 import android.view.View; |
16 import android.view.View.OnClickListener; | 18 import android.view.View.OnClickListener; |
17 import android.view.ViewGroup; | 19 import android.view.ViewGroup; |
18 import android.widget.BaseAdapter; | 20 import android.widget.BaseAdapter; |
19 import android.widget.ImageView; | 21 import android.widget.ImageView; |
20 import android.widget.ListView; | 22 import android.widget.ListView; |
21 import android.widget.TextView; | 23 import android.widget.TextView; |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
90 private static final int ENTER_ITEM_DURATION_MS = 350; | 92 private static final int ENTER_ITEM_DURATION_MS = 350; |
91 private static final int ENTER_ITEM_BASE_DELAY_MS = 80; | 93 private static final int ENTER_ITEM_BASE_DELAY_MS = 80; |
92 private static final int ENTER_ITEM_ADDL_DELAY_MS = 30; | 94 private static final int ENTER_ITEM_ADDL_DELAY_MS = 30; |
93 private static final float ENTER_STANDARD_ITEM_OFFSET_Y_DP = -10.f; | 95 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; | 96 private static final float ENTER_STANDARD_ITEM_OFFSET_X_DP = 10.f; |
95 | 97 |
96 private final AppMenu mAppMenu; | 98 private final AppMenu mAppMenu; |
97 private final LayoutInflater mInflater; | 99 private final LayoutInflater mInflater; |
98 private final List<MenuItem> mMenuItems; | 100 private final List<MenuItem> mMenuItems; |
99 private final int mNumMenuItems; | 101 private final int mNumMenuItems; |
102 @IdRes | |
103 private final int mHighlightedItemId; | |
104 private final int mHighlightedColor; | |
100 private final float mDpToPx; | 105 private final float mDpToPx; |
101 | 106 |
102 public AppMenuAdapter(AppMenu appMenu, List<MenuItem> menuItems, LayoutInfla ter inflater) { | 107 // Cached drawables to avoid animation glitches if views get rebuilt. |
108 private Drawable mCachedHighlightIconDrawable; | |
109 private Drawable mCachedHighlightRowDrawable; | |
110 | |
111 public AppMenuAdapter(AppMenu appMenu, List<MenuItem> menuItems, LayoutInfla ter inflater, | |
112 @IdRes int highlightedItemId) { | |
103 mAppMenu = appMenu; | 113 mAppMenu = appMenu; |
104 mMenuItems = menuItems; | 114 mMenuItems = menuItems; |
105 mInflater = inflater; | 115 mInflater = inflater; |
116 mHighlightedItemId = highlightedItemId; | |
117 mHighlightedColor = ApiCompatibilityUtils.getColor( | |
118 mInflater.getContext().getResources(), R.color.google_blue_500); | |
106 mNumMenuItems = menuItems.size(); | 119 mNumMenuItems = menuItems.size(); |
107 mDpToPx = inflater.getContext().getResources().getDisplayMetrics().densi ty; | 120 mDpToPx = inflater.getContext().getResources().getDisplayMetrics().densi ty; |
108 } | 121 } |
109 | 122 |
110 @Override | 123 @Override |
111 public int getCount() { | 124 public int getCount() { |
112 return mNumMenuItems; | 125 return mNumMenuItems; |
113 } | 126 } |
114 | 127 |
115 @Override | 128 @Override |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
154 final MenuItem item = getItem(position); | 167 final MenuItem item = getItem(position); |
155 switch (getItemViewType(position)) { | 168 switch (getItemViewType(position)) { |
156 case STANDARD_MENU_ITEM: { | 169 case STANDARD_MENU_ITEM: { |
157 StandardMenuItemViewHolder holder = null; | 170 StandardMenuItemViewHolder holder = null; |
158 if (convertView == null | 171 if (convertView == null |
159 || !(convertView.getTag() instanceof StandardMenuItemVie wHolder)) { | 172 || !(convertView.getTag() instanceof StandardMenuItemVie wHolder)) { |
160 holder = new StandardMenuItemViewHolder(); | 173 holder = new StandardMenuItemViewHolder(); |
161 convertView = mInflater.inflate(R.layout.menu_item, parent, false); | 174 convertView = mInflater.inflate(R.layout.menu_item, parent, false); |
162 holder.text = (TextView) convertView.findViewById(R.id.menu_ item_text); | 175 holder.text = (TextView) convertView.findViewById(R.id.menu_ item_text); |
163 holder.image = (AppMenuItemIcon) convertView.findViewById(R. id.menu_item_icon); | 176 holder.image = (AppMenuItemIcon) convertView.findViewById(R. id.menu_item_icon); |
177 holder.background = convertView.getBackground(); | |
164 convertView.setTag(holder); | 178 convertView.setTag(holder); |
165 convertView.setTag(R.id.menu_item_enter_anim_id, | 179 convertView.setTag(R.id.menu_item_enter_anim_id, |
166 buildStandardItemEnterAnimator(convertView, position )); | 180 buildStandardItemEnterAnimator(convertView, position )); |
167 } else { | 181 } else { |
168 holder = (StandardMenuItemViewHolder) convertView.getTag(); | 182 holder = (StandardMenuItemViewHolder) convertView.getTag(); |
169 } | 183 } |
170 | 184 |
171 setupStandardMenuItemViewHolder(holder, convertView, item); | 185 setupStandardMenuItemViewHolder(holder, convertView, item); |
172 break; | 186 break; |
173 } | 187 } |
174 case UPDATE_MENU_ITEM: { | 188 case UPDATE_MENU_ITEM: { |
175 CustomMenuItemViewHolder holder = null; | 189 CustomMenuItemViewHolder holder = null; |
176 if (convertView == null | 190 if (convertView == null |
177 || !(convertView.getTag() instanceof CustomMenuItemViewH older)) { | 191 || !(convertView.getTag() instanceof CustomMenuItemViewH older)) { |
178 holder = new CustomMenuItemViewHolder(); | 192 holder = new CustomMenuItemViewHolder(); |
179 convertView = mInflater.inflate(R.layout.update_menu_item, p arent, false); | 193 convertView = mInflater.inflate(R.layout.update_menu_item, p arent, false); |
180 holder.text = (TextView) convertView.findViewById(R.id.menu_ item_text); | 194 holder.text = (TextView) convertView.findViewById(R.id.menu_ item_text); |
181 holder.image = (AppMenuItemIcon) convertView.findViewById(R. id.menu_item_icon); | 195 holder.image = (AppMenuItemIcon) convertView.findViewById(R. id.menu_item_icon); |
182 holder.summary = (TextView) convertView.findViewById(R.id.me nu_item_summary); | 196 holder.summary = (TextView) convertView.findViewById(R.id.me nu_item_summary); |
197 holder.background = convertView.getBackground(); | |
183 convertView.setTag(holder); | 198 convertView.setTag(holder); |
184 convertView.setTag(R.id.menu_item_enter_anim_id, | 199 convertView.setTag(R.id.menu_item_enter_anim_id, |
185 buildStandardItemEnterAnimator(convertView, position )); | 200 buildStandardItemEnterAnimator(convertView, position )); |
186 } else { | 201 } else { |
187 holder = (CustomMenuItemViewHolder) convertView.getTag(); | 202 holder = (CustomMenuItemViewHolder) convertView.getTag(); |
188 } | 203 } |
189 | 204 |
190 setupStandardMenuItemViewHolder(holder, convertView, item); | 205 setupStandardMenuItemViewHolder(holder, convertView, item); |
191 String summary = UpdateMenuItemHelper.getInstance().getMenuItemS ummaryText( | 206 String summary = UpdateMenuItemHelper.getInstance().getMenuItemS ummaryText( |
192 mInflater.getContext()); | 207 mInflater.getContext()); |
(...skipping 17 matching lines...) Expand all Loading... | |
210 convertView = createMenuItemRow(convertView, parent, item, 5); | 225 convertView = createMenuItemRow(convertView, parent, item, 5); |
211 break; | 226 break; |
212 } | 227 } |
213 case TITLE_BUTTON_MENU_ITEM: { | 228 case TITLE_BUTTON_MENU_ITEM: { |
214 TitleButtonMenuItemViewHolder holder = null; | 229 TitleButtonMenuItemViewHolder holder = null; |
215 if (convertView == null | 230 if (convertView == null |
216 || !(convertView.getTag() instanceof TitleButtonMenuItem ViewHolder)) { | 231 || !(convertView.getTag() instanceof TitleButtonMenuItem ViewHolder)) { |
217 holder = new TitleButtonMenuItemViewHolder(); | 232 holder = new TitleButtonMenuItemViewHolder(); |
218 convertView = mInflater.inflate(R.layout.title_button_menu_i tem, parent, false); | 233 convertView = mInflater.inflate(R.layout.title_button_menu_i tem, parent, false); |
219 holder.title = (TextView) convertView.findViewById(R.id.titl e); | 234 holder.title = (TextView) convertView.findViewById(R.id.titl e); |
220 holder.button = (TintedImageButton) convertView.findViewById (R.id.button); | 235 holder.background = convertView.getBackground(); |
236 holder.button.view = (TintedImageButton) convertView.findVie wById(R.id.button); | |
237 holder.button.background = holder.button.view.getBackground( ); | |
221 | 238 |
222 View animatedView = convertView; | 239 View animatedView = convertView; |
223 | 240 |
224 convertView.setTag(holder); | 241 convertView.setTag(holder); |
225 convertView.setTag(R.id.menu_item_enter_anim_id, | 242 convertView.setTag(R.id.menu_item_enter_anim_id, |
226 buildStandardItemEnterAnimator(animatedView, positio n)); | 243 buildStandardItemEnterAnimator(animatedView, positio n)); |
227 } else { | 244 } else { |
228 holder = (TitleButtonMenuItemViewHolder) convertView.getTag( ); | 245 holder = (TitleButtonMenuItemViewHolder) convertView.getTag( ); |
229 } | 246 } |
230 final MenuItem titleItem = item.hasSubMenu() ? item.getSubMenu() .getItem(0) : item; | 247 final MenuItem titleItem = item.hasSubMenu() ? item.getSubMenu() .getItem(0) : item; |
231 holder.title.setText(titleItem.getTitle()); | 248 holder.title.setText(titleItem.getTitle()); |
232 holder.title.setEnabled(titleItem.isEnabled()); | 249 holder.title.setEnabled(titleItem.isEnabled()); |
233 holder.title.setFocusable(titleItem.isEnabled()); | 250 holder.title.setFocusable(titleItem.isEnabled()); |
234 holder.title.setOnClickListener(new OnClickListener() { | 251 holder.title.setOnClickListener(new OnClickListener() { |
235 @Override | 252 @Override |
236 public void onClick(View v) { | 253 public void onClick(View v) { |
237 mAppMenu.onItemClick(titleItem); | 254 mAppMenu.onItemClick(titleItem); |
238 } | 255 } |
239 }); | 256 }); |
240 | 257 |
241 if (item.getSubMenu().getItem(1).getIcon() != null) { | 258 if (item.getSubMenu().getItem(1).getIcon() != null) { |
242 holder.button.setVisibility(View.VISIBLE); | 259 holder.button.view.setVisibility(View.VISIBLE); |
243 setupImageButton(holder.button, item.getSubMenu().getItem(1) ); | 260 setupImageButton(holder.button, item.getSubMenu().getItem(1) ); |
244 } else { | 261 } else { |
245 holder.button.setVisibility(View.GONE); | 262 holder.button.view.setVisibility(View.GONE); |
246 } | 263 } |
247 convertView.setFocusable(false); | 264 convertView.setFocusable(false); |
248 convertView.setEnabled(false); | 265 convertView.setEnabled(false); |
249 break; | 266 break; |
250 } | 267 } |
251 default: | 268 default: |
252 assert false : "Unexpected MenuItem type"; | 269 assert false : "Unexpected MenuItem type"; |
253 } | 270 } |
271 | |
272 checkRowHighlight(item.getItemId(), convertView); | |
273 | |
254 return convertView; | 274 return convertView; |
255 } | 275 } |
256 | 276 |
257 private void setupImageButton(TintedImageButton button, final MenuItem item) { | 277 private void setupImageButton(RowItemButton button, final MenuItem item) { |
258 // Store and recover the level of image as button.setimageDrawable | 278 // Store and recover the level of image as button.setimageDrawable |
259 // resets drawable to default level. | 279 // resets drawable to default level. |
280 TintedImageButton view = button.view; | |
281 | |
260 int currentLevel = item.getIcon().getLevel(); | 282 int currentLevel = item.getIcon().getLevel(); |
261 button.setImageDrawable(item.getIcon()); | 283 view.setImageDrawable(item.getIcon()); |
262 item.getIcon().setLevel(currentLevel); | 284 item.getIcon().setLevel(currentLevel); |
263 if (item.isChecked()) { | 285 if (item.isChecked()) { |
264 button.setTint(ApiCompatibilityUtils.getColorStateList( | 286 view.setTint(ApiCompatibilityUtils.getColorStateList( |
265 button.getResources(), R.color.blue_mode_tint)); | 287 view.getResources(), R.color.blue_mode_tint)); |
266 } | 288 } |
267 button.setEnabled(item.isEnabled()); | 289 view.setEnabled(item.isEnabled()); |
268 button.setFocusable(item.isEnabled()); | 290 view.setFocusable(item.isEnabled()); |
269 button.setContentDescription(item.getTitleCondensed()); | 291 view.setContentDescription(item.getTitleCondensed()); |
270 | 292 |
271 button.setOnClickListener(new OnClickListener() { | 293 view.setOnClickListener(new OnClickListener() { |
272 @Override | 294 @Override |
273 public void onClick(View v) { | 295 public void onClick(View v) { |
274 mAppMenu.onItemClick(item); | 296 mAppMenu.onItemClick(item); |
275 } | 297 } |
276 }); | 298 }); |
277 | 299 |
300 checkItemHighlight(item.getItemId(), view, button.background, true); | |
301 | |
278 // Menu items may be hidden by command line flags before they get to thi s point. | 302 // 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); | 303 view.setVisibility(item.isVisible() ? View.VISIBLE : View.GONE); |
280 } | 304 } |
281 | 305 |
282 private void setupStandardMenuItemViewHolder(StandardMenuItemViewHolder hold er, | 306 private void setupStandardMenuItemViewHolder(StandardMenuItemViewHolder hold er, |
283 View convertView, final MenuItem item) { | 307 View convertView, final MenuItem item) { |
284 // Set up the icon. | 308 // Set up the icon. |
285 Drawable icon = item.getIcon(); | 309 Drawable icon = item.getIcon(); |
286 holder.image.setImageDrawable(icon); | 310 holder.image.setImageDrawable(icon); |
287 holder.image.setVisibility(icon == null ? View.GONE : View.VISIBLE); | 311 holder.image.setVisibility(icon == null ? View.GONE : View.VISIBLE); |
288 holder.image.setChecked(item.isChecked()); | 312 holder.image.setChecked(item.isChecked()); |
289 holder.text.setText(item.getTitle()); | 313 holder.text.setText(item.getTitle()); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
329 view.setAlpha(0.f); | 353 view.setAlpha(0.f); |
330 } | 354 } |
331 }); | 355 }); |
332 return animation; | 356 return animation; |
333 } | 357 } |
334 | 358 |
335 /** | 359 /** |
336 * This builds an {@link Animator} for the enter animation of icon row menu items. This means | 360 * 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. | 361 * it will animate the alpha from 0 to 1 and translate the views from 10dp t o 0dp on the x axis. |
338 * | 362 * |
339 * @param views The list if icons in the menu item that should be ani mated. | 363 * @param buttons The list of icons in the menu item that should be animated . |
340 * @return The {@link Animator}. | 364 * @return The {@link Animator}. |
341 */ | 365 */ |
342 private Animator buildIconItemEnterAnimator(final ImageView[] views) { | 366 private Animator buildIconItemEnterAnimator(final RowItemButton[] buttons) { |
343 final boolean rtl = LocalizationUtils.isLayoutRtl(); | 367 final boolean rtl = LocalizationUtils.isLayoutRtl(); |
344 final float offsetXPx = ENTER_STANDARD_ITEM_OFFSET_X_DP * mDpToPx * (rtl ? -1.f : 1.f); | 368 final float offsetXPx = ENTER_STANDARD_ITEM_OFFSET_X_DP * mDpToPx * (rtl ? -1.f : 1.f); |
345 final int maxViewsToAnimate = views.length; | 369 final int maxViewsToAnimate = buttons.length; |
346 | 370 |
347 AnimatorSet animation = new AnimatorSet(); | 371 AnimatorSet animation = new AnimatorSet(); |
348 AnimatorSet.Builder builder = null; | 372 AnimatorSet.Builder builder = null; |
349 for (int i = 0; i < maxViewsToAnimate; i++) { | 373 for (int i = 0; i < maxViewsToAnimate; i++) { |
350 final int startDelay = ENTER_ITEM_ADDL_DELAY_MS * i; | 374 final int startDelay = ENTER_ITEM_ADDL_DELAY_MS * i; |
351 | 375 |
352 Animator alpha = ObjectAnimator.ofFloat(views[i], View.ALPHA, 0.f, 1 .f); | 376 ImageView view = buttons[i].view; |
353 Animator translate = ObjectAnimator.ofFloat(views[i], View.TRANSLATI ON_X, offsetXPx, 0); | 377 Animator alpha = ObjectAnimator.ofFloat(view, View.ALPHA, 0.f, 1.f); |
378 Animator translate = ObjectAnimator.ofFloat(view, View.TRANSLATION_X , offsetXPx, 0); | |
354 alpha.setStartDelay(startDelay); | 379 alpha.setStartDelay(startDelay); |
355 translate.setStartDelay(startDelay); | 380 translate.setStartDelay(startDelay); |
356 alpha.setDuration(ENTER_ITEM_DURATION_MS); | 381 alpha.setDuration(ENTER_ITEM_DURATION_MS); |
357 translate.setDuration(ENTER_ITEM_DURATION_MS); | 382 translate.setDuration(ENTER_ITEM_DURATION_MS); |
358 | 383 |
359 if (builder == null) { | 384 if (builder == null) { |
360 builder = animation.play(alpha); | 385 builder = animation.play(alpha); |
361 } else { | 386 } else { |
362 builder.with(alpha); | 387 builder.with(alpha); |
363 } | 388 } |
364 builder.with(translate); | 389 builder.with(translate); |
365 } | 390 } |
366 animation.setStartDelay(ENTER_ITEM_BASE_DELAY_MS); | 391 animation.setStartDelay(ENTER_ITEM_BASE_DELAY_MS); |
367 animation.setInterpolator(BakedBezierInterpolator.FADE_IN_CURVE); | 392 animation.setInterpolator(BakedBezierInterpolator.FADE_IN_CURVE); |
368 | 393 |
369 animation.addListener(new AnimatorListenerAdapter() { | 394 animation.addListener(new AnimatorListenerAdapter() { |
370 @Override | 395 @Override |
371 public void onAnimationStart(Animator animation) { | 396 public void onAnimationStart(Animator animation) { |
372 for (int i = 0; i < maxViewsToAnimate; i++) { | 397 for (int i = 0; i < maxViewsToAnimate; i++) { |
373 views[i].setAlpha(0.f); | 398 buttons[i].view.setAlpha(0.f); |
374 } | 399 } |
375 } | 400 } |
376 }); | 401 }); |
377 return animation; | 402 return animation; |
378 } | 403 } |
379 | 404 |
380 private View createMenuItemRow( | 405 private View createMenuItemRow( |
381 View convertView, ViewGroup parent, MenuItem item, int numItems) { | 406 View convertView, ViewGroup parent, MenuItem item, int numItems) { |
382 RowItemViewHolder holder = null; | 407 RowItemViewHolder holder = null; |
383 if (convertView == null | 408 if (convertView == null |
384 || !(convertView.getTag() instanceof RowItemViewHolder) | 409 || !(convertView.getTag() instanceof RowItemViewHolder) |
385 || ((RowItemViewHolder) convertView.getTag()).buttons.length != numItems) { | 410 || ((RowItemViewHolder) convertView.getTag()).buttons.length != numItems) { |
386 holder = new RowItemViewHolder(numItems); | 411 holder = new RowItemViewHolder(numItems); |
387 convertView = mInflater.inflate(R.layout.icon_row_menu_item, parent, false); | 412 convertView = mInflater.inflate(R.layout.icon_row_menu_item, parent, false); |
413 holder.background = convertView.getBackground(); | |
388 | 414 |
389 // Save references to all the buttons. | 415 // Save references to all the buttons. |
390 for (int i = 0; i < numItems; i++) { | 416 for (int i = 0; i < numItems; i++) { |
391 holder.buttons[i] = | 417 TintedImageButton view = |
392 (TintedImageButton) convertView.findViewById(BUTTON_IDS[ i]); | 418 (TintedImageButton) convertView.findViewById(BUTTON_IDS[ i]); |
419 holder.buttons[i].view = view; | |
420 holder.buttons[i].background = view.getBackground(); | |
393 } | 421 } |
394 | 422 |
395 // Remove unused menu items. | 423 // Remove unused menu items. |
396 for (int j = numItems; j < 5; j++) { | 424 for (int j = numItems; j < 5; j++) { |
397 ((ViewGroup) convertView).removeView(convertView.findViewById(BU TTON_IDS[j])); | 425 ((ViewGroup) convertView).removeView(convertView.findViewById(BU TTON_IDS[j])); |
398 } | 426 } |
399 | 427 |
400 convertView.setTag(holder); | 428 convertView.setTag(holder); |
401 convertView.setTag(R.id.menu_item_enter_anim_id, | 429 convertView.setTag(R.id.menu_item_enter_anim_id, |
402 buildIconItemEnterAnimator(holder.buttons)); | 430 buildIconItemEnterAnimator(holder.buttons)); |
403 } else { | 431 } else { |
404 holder = (RowItemViewHolder) convertView.getTag(); | 432 holder = (RowItemViewHolder) convertView.getTag(); |
405 } | 433 } |
406 | 434 |
407 for (int i = 0; i < numItems; i++) { | 435 for (int i = 0; i < numItems; i++) { |
408 setupImageButton(holder.buttons[i], item.getSubMenu().getItem(i)); | 436 setupImageButton(holder.buttons[i], item.getSubMenu().getItem(i)); |
409 } | 437 } |
410 convertView.setFocusable(false); | 438 convertView.setFocusable(false); |
411 convertView.setEnabled(false); | 439 convertView.setEnabled(false); |
412 return convertView; | 440 return convertView; |
413 } | 441 } |
414 | 442 |
415 static class StandardMenuItemViewHolder { | 443 private void checkRowHighlight(int itemId, View view) { |
444 if (mHighlightedItemId == 0) return; | |
445 | |
446 Object tag = view.getTag(); | |
447 if (tag == null || !(tag instanceof MenuItemViewHolder)) return; | |
Ted C
2017/03/31 19:01:47
when isn't the tag a MenuItemViewHolder? It seems
| |
448 | |
449 Drawable background = ((MenuItemViewHolder) tag).background; | |
450 | |
451 checkItemHighlight(itemId, view, background, false); | |
452 } | |
453 | |
454 private void checkItemHighlight( | |
455 int itemId, View view, Drawable viewBackground, boolean isIcon) { | |
456 if (mHighlightedItemId == 0) return; | |
457 | |
458 if (mHighlightedItemId == itemId) { | |
459 view.setBackground(new LayerDrawable( | |
460 new Drawable[] {getHighlightDrawable(isIcon), viewBackground })); | |
461 } else { | |
462 view.setBackground(viewBackground); | |
463 } | |
464 } | |
465 | |
466 private Drawable getHighlightDrawable(boolean isIcon) { | |
467 if (isIcon) { | |
468 if (mCachedHighlightIconDrawable == null) { | |
469 mCachedHighlightIconDrawable = new IconHighlightDrawable(mHighli ghtedColor); | |
470 } | |
471 return mCachedHighlightIconDrawable; | |
472 } else { | |
473 if (mCachedHighlightRowDrawable == null) { | |
474 mCachedHighlightRowDrawable = new RowHighlightDrawable(mHighligh tedColor); | |
475 } | |
476 return mCachedHighlightRowDrawable; | |
477 } | |
478 } | |
479 | |
480 static class MenuItemViewHolder { public Drawable background; } | |
481 | |
482 static class StandardMenuItemViewHolder extends MenuItemViewHolder { | |
416 public TextView text; | 483 public TextView text; |
417 public AppMenuItemIcon image; | 484 public AppMenuItemIcon image; |
418 } | 485 } |
419 | 486 |
420 static class CustomMenuItemViewHolder extends StandardMenuItemViewHolder { | 487 static class CustomMenuItemViewHolder extends StandardMenuItemViewHolder { |
421 public TextView summary; | 488 public TextView summary; |
422 } | 489 } |
423 | 490 |
424 private static class RowItemViewHolder { | 491 static class RowItemButton { |
425 public TintedImageButton[] buttons; | 492 public TintedImageButton view; |
493 public Drawable background; | |
494 } | |
495 | |
496 private static class RowItemViewHolder extends MenuItemViewHolder { | |
497 public RowItemButton[] buttons; | |
426 | 498 |
427 RowItemViewHolder(int numButtons) { | 499 RowItemViewHolder(int numButtons) { |
428 buttons = new TintedImageButton[numButtons]; | 500 buttons = new RowItemButton[numButtons]; |
501 for (int i = 0; i < numButtons; i++) { | |
502 buttons[i] = new RowItemButton(); | |
503 } | |
429 } | 504 } |
430 } | 505 } |
431 | 506 |
432 static class TitleButtonMenuItemViewHolder { | 507 static class TitleButtonMenuItemViewHolder extends MenuItemViewHolder { |
433 public TextView title; | 508 public TextView title; |
434 public TintedImageButton button; | 509 public RowItemButton button = new RowItemButton(); |
435 } | 510 } |
436 } | 511 } |
OLD | NEW |