From 2298bb199c7ac4b00dcf5d5677bad0c268c488e0 Mon Sep 17 00:00:00 2001 From: Andrei Stingaceanu Date: Mon, 21 Mar 2016 11:51:58 +0000 Subject: [PATCH] Keyboard shortcuts: RTL for KeyboardShortcutKeysLayout Introduced RTL support for the KeyboardShortcutKeysLayout and with another minor change to the dialog layout achived full RTL support for the keyboard shortcuts UI. Bug: 22776761 Bug: 27674152 Change-Id: I14e38dc4533208f6fd982a53a1d0305e003d926b --- .../keyboard_shortcuts_category_title.xml | 2 +- .../statusbar/KeyboardShortcutKeysLayout.java | 52 +++++++++++++++---- 2 files changed, 43 insertions(+), 11 deletions(-) diff --git a/packages/SystemUI/res/layout/keyboard_shortcuts_category_title.xml b/packages/SystemUI/res/layout/keyboard_shortcuts_category_title.xml index 6cb8470eaf212..381fb165df10d 100644 --- a/packages/SystemUI/res/layout/keyboard_shortcuts_category_title.xml +++ b/packages/SystemUI/res/layout/keyboard_shortcuts_category_title.xml @@ -16,7 +16,7 @@ ~ limitations under the License --> fullRowWidth) { + boolean childDoesNotFitOnRow = isRTL() + ? xPos - getPaddingLeft() - currentChildWidth < 0 + : xPos + currentChildWidth > fullRowWidth; + + if (childDoesNotFitOnRow) { // Layout all the children on this row but the current one. layoutChildrenOnRow(rowStartIdx, i, fullRowWidth, xPos, yPos, lastHorizontalSpacing); // Update the positions for starting on the new row. - xPos = getPaddingLeft(); + xPos = isRTL() + ? fullRowWidth - getPaddingRight() + : getPaddingLeft(); yPos += mLineHeight; rowStartIdx = i; } - xPos += currentChildWidth + lp.mHorizontalSpacing; + xPos = isRTL() + ? xPos - currentChildWidth - lp.mHorizontalSpacing + : xPos + currentChildWidth + lp.mHorizontalSpacing; lastHorizontalSpacing = lp.mHorizontalSpacing; } } @@ -148,21 +160,41 @@ public final class KeyboardShortcutKeysLayout extends ViewGroup { private void layoutChildrenOnRow(int startIndex, int endIndex, int fullRowWidth, int xPos, int yPos, int lastHorizontalSpacing) { - int freeSpace = fullRowWidth - xPos + lastHorizontalSpacing; - xPos = getPaddingLeft() + freeSpace; + if (!isRTL()) { + xPos = getPaddingLeft() + fullRowWidth - xPos + lastHorizontalSpacing; + } for (int j = startIndex; j < endIndex; ++j) { View currentChild = getChildAt(j); + int currentChildWidth = currentChild.getMeasuredWidth(); + LayoutParams lp = (LayoutParams) currentChild.getLayoutParams(); + if (isRTL() && j == startIndex) { + xPos = fullRowWidth - xPos - getPaddingRight() - currentChildWidth + - lp.mHorizontalSpacing; + } + currentChild.layout( xPos, yPos, - xPos + currentChild.getMeasuredWidth(), + xPos + currentChildWidth, yPos + currentChild.getMeasuredHeight()); - xPos += currentChild.getMeasuredWidth() - + ((LayoutParams) currentChild.getLayoutParams()).mHorizontalSpacing; + + if (isRTL()) { + int nextChildWidth = j < endIndex - 1 + ? getChildAt(j + 1).getMeasuredWidth() + : 0; + xPos -= nextChildWidth + lp.mHorizontalSpacing; + } else { + xPos += currentChildWidth + lp.mHorizontalSpacing; + } } } + private boolean isRTL() { + return mContext.getResources().getConfiguration().getLayoutDirection() + == View.LAYOUT_DIRECTION_RTL; + } + public static class LayoutParams extends ViewGroup.LayoutParams { public final int mHorizontalSpacing; public final int mVerticalSpacing;