diff options
| author | 2015-09-24 20:59:44 +0000 | |
|---|---|---|
| committer | 2015-09-24 20:59:44 +0000 | |
| commit | 8f3976c8756e85864f49c5fde2f9ff1bbe53d30d (patch) | |
| tree | c223b73a33812b960f1bace87d1b7368dd4c2108 | |
| parent | d75247cf7fa0ddf4975cc2957fefdf081854cd56 (diff) | |
| parent | 734320d06be5ad6365e6997b4ddbcbdb2778809c (diff) | |
Merge "Cascading submenus: Fix a few small issues."
| -rw-r--r-- | core/java/android/widget/MenuPopupWindow.java | 6 | ||||
| -rw-r--r-- | core/java/com/android/internal/view/menu/CascadingMenuPopup.java | 39 |
2 files changed, 30 insertions, 15 deletions
diff --git a/core/java/android/widget/MenuPopupWindow.java b/core/java/android/widget/MenuPopupWindow.java index ba77b1b53079..eac3a0b51758 100644 --- a/core/java/android/widget/MenuPopupWindow.java +++ b/core/java/android/widget/MenuPopupWindow.java @@ -124,8 +124,8 @@ public class MenuPopupWindow extends ListPopupWindow implements MenuItemHoverLis } return true; } else if (selectedItem != null && keyCode == mRetreatKey) { - setSelectedPositionInt(-1); - setNextSelectedPositionInt(-1); + setSelectedPositionInt(INVALID_POSITION); + setNextSelectedPositionInt(INVALID_POSITION); ((MenuAdapter) getAdapter()).getAdapterMenu().close(); return true; @@ -159,6 +159,4 @@ public class MenuPopupWindow extends ListPopupWindow implements MenuItemHoverLis return superVal; } } - - }
\ No newline at end of file diff --git a/core/java/com/android/internal/view/menu/CascadingMenuPopup.java b/core/java/com/android/internal/view/menu/CascadingMenuPopup.java index 415f32528914..aa7b34bb9999 100644 --- a/core/java/com/android/internal/view/menu/CascadingMenuPopup.java +++ b/core/java/com/android/internal/view/menu/CascadingMenuPopup.java @@ -153,8 +153,6 @@ final class CascadingMenuPopup extends MenuPopup implements AdapterView.OnItemCl (MenuDropDownListView) mListViews.get(menuIndex + 1); final MenuAdapter nextAdapter = (MenuAdapter) nextView.getAdapter(); - view.clearSelection(); - mSubMenuHoverHandler.removeCallbacksAndMessages(null); mSubMenuHoverHandler.postDelayed(new Runnable() { @Override @@ -162,9 +160,14 @@ final class CascadingMenuPopup extends MenuPopup implements AdapterView.OnItemCl // Make sure the menu wasn't already closed by something else and that // it wasn't re-hovered by the user since this was scheduled. int nextMenuIndex = mListViews.indexOf(nextView); + if (nextMenuIndex != -1 && nextView.getSelectedView() == null) { // Disable exit animation, to prevent overlapping fading out submenus. - mPopupWindows.get(nextMenuIndex).setExitTransition(null); + for (int i = nextMenuIndex; i < mPopupWindows.size(); i++) { + final MenuPopupWindow popupWindow = mPopupWindows.get(i); + popupWindow.setExitTransition(null); + popupWindow.setAnimationStyle(0); + } nextAdapter.getAdapterMenu().close(); } } @@ -178,8 +181,9 @@ final class CascadingMenuPopup extends MenuPopup implements AdapterView.OnItemCl private View mShownAnchorView; private List<DropDownListView> mListViews; private List<MenuPopupWindow> mPopupWindows; + private int mLastPosition; + private List<Integer> mPositions; private List<int[]> mOffsets; - private int mPreferredPosition; private boolean mForceShowIcon; private Callback mPresenterCallback; private ViewTreeObserver mTreeObserver; @@ -203,14 +207,14 @@ final class CascadingMenuPopup extends MenuPopup implements AdapterView.OnItemCl final Resources res = context.getResources(); final Configuration config = res.getConfiguration(); mLayoutDirection = config.getLayoutDirection(); - mPreferredPosition = mLayoutDirection == View.LAYOUT_DIRECTION_RTL ? HORIZ_POSITION_LEFT : - HORIZ_POSITION_RIGHT; + mLastPosition = getInitialMenuPosition(); mMenuMaxWidth = Math.max(res.getDisplayMetrics().widthPixels / 2, res.getDimensionPixelSize(com.android.internal.R.dimen.config_prefDialogWidth)); mPopupWindows = new ArrayList<MenuPopupWindow>(); mListViews = new ArrayList<DropDownListView>(); mOffsets = new ArrayList<int[]>(); + mPositions = new ArrayList<Integer>(); mSubMenuHoverHandler = new Handler(); } @@ -286,6 +290,16 @@ final class CascadingMenuPopup extends MenuPopup implements AdapterView.OnItemCl } /** + * Determines the proper initial menu position for the current LTR/RTL configuration. + * @return The initial position. + */ + @HorizPosition + private int getInitialMenuPosition() { + return mLayoutDirection == View.LAYOUT_DIRECTION_RTL ? HORIZ_POSITION_LEFT : + HORIZ_POSITION_RIGHT; + } + + /** * Determines whether the next submenu (of the given width) should display on the right or on * the left of the most recent menu. * @@ -302,7 +316,7 @@ final class CascadingMenuPopup extends MenuPopup implements AdapterView.OnItemCl final Rect displayFrame = new Rect(); mShownAnchorView.getWindowVisibleDisplayFrame(displayFrame); - if (mPreferredPosition == HORIZ_POSITION_RIGHT) { + if (mLastPosition == HORIZ_POSITION_RIGHT) { final int right = screenLocation[0] + lastListView.getWidth() + nextMenuWidth; if (right > displayFrame.right) { return HORIZ_POSITION_LEFT; @@ -342,7 +356,7 @@ final class CascadingMenuPopup extends MenuPopup implements AdapterView.OnItemCl ListView lastListView = mListViews.get(mListViews.size() - 1); @HorizPosition int nextMenuPosition = getNextMenuPosition(menuWidth); boolean showOnRight = nextMenuPosition == HORIZ_POSITION_RIGHT; - mPreferredPosition = nextMenuPosition; + mLastPosition = nextMenuPosition; int[] lastLocation = new int[2]; lastListView.getLocationOnScreen(lastLocation); @@ -384,6 +398,7 @@ final class CascadingMenuPopup extends MenuPopup implements AdapterView.OnItemCl int[] offsets = {x, y}; mOffsets.add(offsets); + mPositions.add(mLastPosition); } /** @@ -479,9 +494,11 @@ final class CascadingMenuPopup extends MenuPopup implements AdapterView.OnItemCl mListViews.subList(menuIndex, mListViews.size()).clear(); mOffsets.subList(menuIndex, mOffsets.size()).clear(); - // If there's still a menu open, refocus the new leaf [sub]menu. - if (mListViews.size() > 0) { - mListViews.get(mListViews.size() - 1).requestFocus(); + mPositions.subList(menuIndex, mPositions.size()).clear(); + if (mPositions.size() > 0) { + mLastPosition = mPositions.get(mPositions.size() - 1); + } else { + mLastPosition = getInitialMenuPosition(); } } |