diff options
| author | 2016-12-15 15:09:58 +0000 | |
|---|---|---|
| committer | 2016-12-20 17:53:20 +0000 | |
| commit | e2c893fc2d26fd2a3c1accb8fc78dddc8022e1bf (patch) | |
| tree | c8f1fcbf08f7f69034c22d133d55310fe59cd556 | |
| parent | 0de5d03c9d6cca001706e93f5e35a95f6320b77b (diff) | |
Fix keyboard shortcut display layout
The keyboard_shortcuts_keyword TextView in keyboard_shortcut_app_item
layout was wrap_content making it take all the space in case the text is
too long. The TextView is now rendered indide a KeyboardShortcutsLayout
which extends the RelativeLayout and sets the maxWidth of
keyboard_shortcuts_keyword TextView to 70% when onMeasure is called with
EXACT MeasureSpec.
Bug: 32980732
Fixes: 32980732
Test: Manual
Change-Id: I1250802af0a4ad011e842318384ca6fe5686989c
| -rw-r--r-- | packages/SystemUI/res/layout/keyboard_shortcut_app_item.xml | 6 | ||||
| -rw-r--r-- | packages/SystemUI/src/com/android/systemui/statusbar/KeyboardShortcutAppItemLayout.java | 60 |
2 files changed, 64 insertions, 2 deletions
diff --git a/packages/SystemUI/res/layout/keyboard_shortcut_app_item.xml b/packages/SystemUI/res/layout/keyboard_shortcut_app_item.xml index 69e52c53808d..d49aff9abc01 100644 --- a/packages/SystemUI/res/layout/keyboard_shortcut_app_item.xml +++ b/packages/SystemUI/res/layout/keyboard_shortcut_app_item.xml @@ -14,7 +14,8 @@ ~ See the License for the specific language governing permissions and ~ limitations under the License --> -<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" +<com.android.systemui.statusbar.KeyboardShortcutAppItemLayout + xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="wrap_content" @@ -37,6 +38,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingEnd="12dp" + android:paddingBottom="4dp" android:textColor="@color/ksh_keyword_color" android:textSize="16sp" android:maxLines="5" @@ -55,4 +57,4 @@ android:scrollHorizontally="false" android:layout_centerVertical="true" android:focusable="true"/> -</RelativeLayout> +</com.android.systemui.statusbar.KeyboardShortcutAppItemLayout> diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/KeyboardShortcutAppItemLayout.java b/packages/SystemUI/src/com/android/systemui/statusbar/KeyboardShortcutAppItemLayout.java new file mode 100644 index 000000000000..507b66524c0b --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/statusbar/KeyboardShortcutAppItemLayout.java @@ -0,0 +1,60 @@ +/* + * 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.view.View; +import android.widget.ImageView; +import android.widget.RelativeLayout; +import android.widget.TextView; + +import com.android.systemui.R; + +/** + * Layout used for displaying keyboard shortcut items inside an alert dialog. + * The layout sets the maxWidth of shortcuts keyword textview to 70% of available space. + */ +public class KeyboardShortcutAppItemLayout extends RelativeLayout { + + private static final double MAX_WIDTH_PERCENT_FOR_KEYWORDS = 0.70; + + public KeyboardShortcutAppItemLayout(Context context) { + super(context); + } + + public KeyboardShortcutAppItemLayout(Context context, AttributeSet attrs) { + super(context, attrs); + } + + @Override + protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { + if (MeasureSpec.getMode(widthMeasureSpec) == MeasureSpec.EXACTLY) { + ImageView shortcutIcon = (ImageView) findViewById(R.id.keyboard_shortcuts_icon); + TextView shortcutKeyword = (TextView) findViewById(R.id.keyboard_shortcuts_keyword); + int totalMeasuredWidth = MeasureSpec.getSize(widthMeasureSpec); + int totalPadding = getPaddingLeft() + getPaddingRight(); + int availableWidth = totalMeasuredWidth - totalPadding; + if (shortcutIcon.getVisibility() == View.VISIBLE) { + availableWidth = availableWidth - shortcutIcon.getMeasuredWidth(); + } + shortcutKeyword.setMaxWidth((int) + Math.round(availableWidth * MAX_WIDTH_PERCENT_FOR_KEYWORDS)); + } + super.onMeasure(widthMeasureSpec, heightMeasureSpec); + } +} |