|
34 | 34 | import android.widget.ImageButton; |
35 | 35 |
|
36 | 36 | import java.util.ArrayList; |
| 37 | +import java.util.Collections; |
| 38 | +import java.util.Comparator; |
37 | 39 |
|
38 | 40 | /** |
39 | 41 | * MenuPresenter for building action menus as seen in the action bar and action modes. |
@@ -351,7 +353,27 @@ public boolean isOverflowReserved() { |
351 | 353 | } |
352 | 354 |
|
353 | 355 | public boolean flagActionItems() { |
354 | | - final ArrayList<MenuItemImpl> visibleItems = mMenu.getVisibleItems(); |
| 356 | + // Items must be sorted always in base to his showAsAction type |
| 357 | + // always -> ifRoom -> Others |
| 358 | + // Create an internal sorted array based in this priority (items must keep |
| 359 | + // his original order) |
| 360 | + final ArrayList<MenuItemImpl> visibleItems = |
| 361 | + new ArrayList<MenuItemImpl>(mMenu.getVisibleItems()); |
| 362 | + Collections.sort(visibleItems, new Comparator<MenuItemImpl>() { |
| 363 | + @Override |
| 364 | + public int compare(MenuItemImpl lhs, MenuItemImpl rhs) { |
| 365 | + boolean lhsRequires = lhs.requiresActionButton(); |
| 366 | + boolean lhsRequest = lhs.requestsActionButton(); |
| 367 | + boolean rhsRequires = rhs.requiresActionButton(); |
| 368 | + boolean rhsRequest = rhs.requestsActionButton(); |
| 369 | + if (lhsRequires && rhsRequires) return 0; |
| 370 | + if (lhsRequires) return -1; |
| 371 | + if (rhsRequires) return 1; |
| 372 | + if (lhsRequest && rhsRequest) return 0; |
| 373 | + if (lhsRequest) return -1; |
| 374 | + return 1; |
| 375 | + } |
| 376 | + }); |
355 | 377 | final int itemsSize = visibleItems.size(); |
356 | 378 | int maxActions = mMaxItems; |
357 | 379 | int widthLimit = mActionItemWidthLimit; |
|
0 commit comments