diff options
| author | 2016-03-18 14:16:36 +0000 | |
|---|---|---|
| committer | 2016-03-18 14:16:38 +0000 | |
| commit | b45e24f7958cf7df136ea4d6bf41f0299e667cff (patch) | |
| tree | c7be2957f6c5c7cd0b58ae9372c3d63b55b02cef | |
| parent | 2c83702aa218cbcc51d8726575c78691fc57a53b (diff) | |
| parent | 844927d62d49a674891cae5490427d1ba6692f96 (diff) | |
Merge "Keyboard shortcuts: new layout for keys container" into nyc-dev
8 files changed, 198 insertions, 17 deletions
diff --git a/packages/SystemUI/res/layout/keyboard_shortcut_app_item.xml b/packages/SystemUI/res/layout/keyboard_shortcut_app_item.xml index 5a6553ff90db..9c2c0ab9faa3 100644 --- a/packages/SystemUI/res/layout/keyboard_shortcut_app_item.xml +++ b/packages/SystemUI/res/layout/keyboard_shortcut_app_item.xml @@ -27,29 +27,19 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingEnd="12dp" - android:background="@android:color/white" - android:textColor="#D9000000" + android:textColor="@color/ksh_keyword_color" android:textSize="16sp" android:maxLines="5" android:singleLine="false" android:scrollHorizontally="false" - android:layout_alignParentStart="true" - android:minWidth="100dp" - android:maxWidth="260dp"/> - <!--TODO: introduce and use a layout that allows wrapping and right align --> - <LinearLayout + android:layout_alignParentStart="true"/> + <com.android.systemui.statusbar.KeyboardShortcutKeysLayout android:id="@+id/keyboard_shortcuts_item_container" android:layout_toEndOf="@+id/keyboard_shortcuts_keyword" android:orientation="horizontal" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:background="@android:color/white" android:layout_alignParentEnd="true" - android:gravity="end" android:textSize="14sp" - android:paddingStart="0dp" - android:paddingEnd="0dp" - android:scrollHorizontally="false" - android:minWidth="100dp" - android:maxWidth="260dp"/> + android:scrollHorizontally="false"/> </RelativeLayout> diff --git a/packages/SystemUI/res/layout/keyboard_shortcuts_category_title.xml b/packages/SystemUI/res/layout/keyboard_shortcuts_category_title.xml index 80a478a6d3d8..6cb8470eaf21 100644 --- a/packages/SystemUI/res/layout/keyboard_shortcuts_category_title.xml +++ b/packages/SystemUI/res/layout/keyboard_shortcuts_category_title.xml @@ -22,4 +22,4 @@ android:paddingStart="24dp" android:paddingTop="20dp" android:paddingEnd="24dp" - android:paddingBottom="13dp" /> + android:paddingBottom="13dp"/> diff --git a/packages/SystemUI/res/layout/keyboard_shortcuts_view.xml b/packages/SystemUI/res/layout/keyboard_shortcuts_view.xml index f73ee1532ba3..7aba1cf6e0dc 100644 --- a/packages/SystemUI/res/layout/keyboard_shortcuts_view.xml +++ b/packages/SystemUI/res/layout/keyboard_shortcuts_view.xml @@ -17,7 +17,7 @@ <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" - android:layout_width="488dp" + android:layout_width="@dimen/ksh_layout_width" android:layout_height="wrap_content"> <LinearLayout android:layout_width="match_parent" diff --git a/packages/SystemUI/res/values-sw600dp/dimens.xml b/packages/SystemUI/res/values-sw600dp/dimens.xml index a2fa3b976922..66963c43e8dc 100644 --- a/packages/SystemUI/res/values-sw600dp/dimens.xml +++ b/packages/SystemUI/res/values-sw600dp/dimens.xml @@ -104,4 +104,7 @@ <!-- The side padding for the task stack. --> <dimen name="recents_stack_left_right_padding">64dp</dimen> + + <!-- Keyboard shortcuts helper --> + <dimen name="ksh_layout_width">488dp</dimen> </resources> diff --git a/packages/SystemUI/res/values/colors.xml b/packages/SystemUI/res/values/colors.xml index eeed0cf62287..a3f8b8551def 100644 --- a/packages/SystemUI/res/values/colors.xml +++ b/packages/SystemUI/res/values/colors.xml @@ -167,6 +167,7 @@ <!-- Keyboard shortcuts colors --> <color name="ksh_system_group_color">#ff00bcd4</color> <color name="ksh_application_group_color">#fff44336</color> + <color name="ksh_keyword_color">#d9000000</color> <!-- Background color of edit overflow --> <color name="qs_edit_overflow_bg">#455A64</color> diff --git a/packages/SystemUI/res/values/dimens.xml b/packages/SystemUI/res/values/dimens.xml index 6a9f45606bab..8b433f984d65 100644 --- a/packages/SystemUI/res/values/dimens.xml +++ b/packages/SystemUI/res/values/dimens.xml @@ -639,4 +639,7 @@ <dimen name="battery_detail_graph_space_top">27dp</dimen> <dimen name="battery_detail_graph_space_bottom">27dp</dimen> + + <!-- Keyboard shortcuts helper --> + <dimen name="ksh_layout_width">@dimen/match_parent</dimen> </resources> diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/KeyboardShortcutKeysLayout.java b/packages/SystemUI/src/com/android/systemui/statusbar/KeyboardShortcutKeysLayout.java new file mode 100644 index 000000000000..ba3e774ea2b7 --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/statusbar/KeyboardShortcutKeysLayout.java @@ -0,0 +1,183 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +package com.android.systemui.statusbar; + +import android.content.Context; +import android.util.AttributeSet; +import android.util.DisplayMetrics; +import android.util.TypedValue; +import android.view.View; +import android.view.ViewGroup; + +/** + * Layout used as a container for keyboard shortcut keys. It's children are wrapped and right + * aligned. + */ +public final class KeyboardShortcutKeysLayout extends ViewGroup { + private int mLineHeight; + + public KeyboardShortcutKeysLayout(Context context) { + super(context); + } + + public KeyboardShortcutKeysLayout(Context context, AttributeSet attrs) { + super(context, attrs); + } + + @Override + protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { + int width = MeasureSpec.getSize(widthMeasureSpec) - getPaddingLeft() - getPaddingRight(); + int childCount = getChildCount(); + int height = MeasureSpec.getSize(heightMeasureSpec) - getPaddingTop() - getPaddingBottom(); + int lineHeight = 0; + int xPos = getPaddingLeft(); + int yPos = getPaddingTop(); + + int childHeightMeasureSpec; + if (MeasureSpec.getMode(heightMeasureSpec) == MeasureSpec.AT_MOST) { + childHeightMeasureSpec = MeasureSpec.makeMeasureSpec(height, MeasureSpec.AT_MOST); + } else { + childHeightMeasureSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED); + } + + for (int i = 0; i < childCount; i++) { + View child = getChildAt(i); + if (child.getVisibility() != GONE) { + LayoutParams layoutParams = (LayoutParams) child.getLayoutParams(); + child.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.AT_MOST), + childHeightMeasureSpec); + int childWidth = child.getMeasuredWidth(); + lineHeight = Math.max(lineHeight, + child.getMeasuredHeight() + layoutParams.mVerticalSpacing); + + if (xPos + childWidth > width) { + xPos = getPaddingLeft(); + yPos += lineHeight; + } + xPos += childWidth + layoutParams.mHorizontalSpacing; + } + } + this.mLineHeight = lineHeight; + + if (MeasureSpec.getMode(heightMeasureSpec) == MeasureSpec.UNSPECIFIED) { + height = yPos + lineHeight; + } else if (MeasureSpec.getMode(heightMeasureSpec) == MeasureSpec.AT_MOST) { + if (yPos + lineHeight < height) { + height = yPos + lineHeight; + } + } + setMeasuredDimension(width, height); + } + + @Override + protected LayoutParams generateDefaultLayoutParams() { + int spacing = getHorizontalVerticalSpacing(); + return new LayoutParams(spacing, spacing); + } + + @Override + protected LayoutParams generateLayoutParams(ViewGroup.LayoutParams layoutParams) { + int spacing = getHorizontalVerticalSpacing(); + return new LayoutParams(spacing, spacing, layoutParams); + } + + @Override + protected boolean checkLayoutParams(ViewGroup.LayoutParams p) { + return (p instanceof LayoutParams); + } + + @Override + protected void onLayout(boolean changed, int l, int t, int r, int b) { + int childCount = getChildCount(); + int fullRowWidth = r - l; + int xPos = getPaddingLeft(); + int yPos = getPaddingTop(); + int lastHorizontalSpacing = 0; + // The index of the child which starts the current row. + int rowStartIdx = 0; + + // Go through all the children. + for (int i = 0; i < childCount; i++) { + View currentChild = getChildAt(i); + if (currentChild.getVisibility() != GONE) { + int currentChildWidth = currentChild.getMeasuredWidth(); + LayoutParams lp = (LayoutParams) currentChild.getLayoutParams(); + + // If the current child does not fit on this row. + if (xPos + currentChildWidth > fullRowWidth) { + // 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(); + yPos += mLineHeight; + rowStartIdx = i; + } + + xPos += currentChildWidth + lp.mHorizontalSpacing; + lastHorizontalSpacing = lp.mHorizontalSpacing; + } + } + + // Lay out the children on the last row. + if (rowStartIdx < childCount) { + layoutChildrenOnRow(rowStartIdx, childCount, fullRowWidth, xPos, yPos, + lastHorizontalSpacing); + } + } + + private int getHorizontalVerticalSpacing() { + DisplayMetrics displayMetrics = getResources().getDisplayMetrics(); + return (int) TypedValue.applyDimension( + TypedValue.COMPLEX_UNIT_DIP, 4, displayMetrics); + } + + private void layoutChildrenOnRow(int startIndex, int endIndex, int fullRowWidth, int xPos, + int yPos, int lastHorizontalSpacing) { + int freeSpace = fullRowWidth - xPos + lastHorizontalSpacing; + xPos = getPaddingLeft() + freeSpace; + + for (int j = startIndex; j < endIndex; ++j) { + View currentChild = getChildAt(j); + currentChild.layout( + xPos, + yPos, + xPos + currentChild.getMeasuredWidth(), + yPos + currentChild.getMeasuredHeight()); + xPos += currentChild.getMeasuredWidth() + + ((LayoutParams) currentChild.getLayoutParams()).mHorizontalSpacing; + } + } + + public static class LayoutParams extends ViewGroup.LayoutParams { + public final int mHorizontalSpacing; + public final int mVerticalSpacing; + + public LayoutParams(int horizontalSpacing, int verticalSpacing, + ViewGroup.LayoutParams viewGroupLayout) { + super(viewGroupLayout); + this.mHorizontalSpacing = horizontalSpacing; + this.mVerticalSpacing = verticalSpacing; + } + + public LayoutParams(int mHorizontalSpacing, int verticalSpacing) { + super(0, 0); + this.mHorizontalSpacing = mHorizontalSpacing; + this.mVerticalSpacing = verticalSpacing; + } + } +} diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/KeyboardShortcuts.java b/packages/SystemUI/src/com/android/systemui/statusbar/KeyboardShortcuts.java index 0b7bfa8871ee..60c2fa61830c 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/KeyboardShortcuts.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/KeyboardShortcuts.java @@ -29,6 +29,7 @@ import android.view.KeyboardShortcutGroup; import android.view.KeyboardShortcutInfo; import android.view.LayoutInflater; import android.view.View; +import android.view.ViewGroup; import android.view.Window; import android.view.WindowManager.KeyboardShortcutsReceiver; import android.widget.LinearLayout; @@ -153,7 +154,7 @@ public class KeyboardShortcuts { .findViewById(R.id.keyboard_shortcuts_keyword); textView.setText(info.getLabel()); - LinearLayout shortcutItemsContainer = (LinearLayout) shortcutView + ViewGroup shortcutItemsContainer = (ViewGroup) shortcutView .findViewById(R.id.keyboard_shortcuts_item_container); List<String> shortcutKeys = getHumanReadableShortcutKeys(info); final int shortcutKeysSize = shortcutKeys.size(); |