Merge "Keyboard shortcuts: new layout for keys container" into nyc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
b45e24f795
@@ -27,29 +27,19 @@
|
|||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:paddingEnd="12dp"
|
android:paddingEnd="12dp"
|
||||||
android:background="@android:color/white"
|
android:textColor="@color/ksh_keyword_color"
|
||||||
android:textColor="#D9000000"
|
|
||||||
android:textSize="16sp"
|
android:textSize="16sp"
|
||||||
android:maxLines="5"
|
android:maxLines="5"
|
||||||
android:singleLine="false"
|
android:singleLine="false"
|
||||||
android:scrollHorizontally="false"
|
android:scrollHorizontally="false"
|
||||||
android:layout_alignParentStart="true"
|
android:layout_alignParentStart="true"/>
|
||||||
android:minWidth="100dp"
|
<com.android.systemui.statusbar.KeyboardShortcutKeysLayout
|
||||||
android:maxWidth="260dp"/>
|
|
||||||
<!--TODO: introduce and use a layout that allows wrapping and right align -->
|
|
||||||
<LinearLayout
|
|
||||||
android:id="@+id/keyboard_shortcuts_item_container"
|
android:id="@+id/keyboard_shortcuts_item_container"
|
||||||
android:layout_toEndOf="@+id/keyboard_shortcuts_keyword"
|
android:layout_toEndOf="@+id/keyboard_shortcuts_keyword"
|
||||||
android:orientation="horizontal"
|
android:orientation="horizontal"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:background="@android:color/white"
|
|
||||||
android:layout_alignParentEnd="true"
|
android:layout_alignParentEnd="true"
|
||||||
android:gravity="end"
|
|
||||||
android:textSize="14sp"
|
android:textSize="14sp"
|
||||||
android:paddingStart="0dp"
|
android:scrollHorizontally="false"/>
|
||||||
android:paddingEnd="0dp"
|
|
||||||
android:scrollHorizontally="false"
|
|
||||||
android:minWidth="100dp"
|
|
||||||
android:maxWidth="260dp"/>
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
|||||||
@@ -22,4 +22,4 @@
|
|||||||
android:paddingStart="24dp"
|
android:paddingStart="24dp"
|
||||||
android:paddingTop="20dp"
|
android:paddingTop="20dp"
|
||||||
android:paddingEnd="24dp"
|
android:paddingEnd="24dp"
|
||||||
android:paddingBottom="13dp" />
|
android:paddingBottom="13dp"/>
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
<FrameLayout
|
<FrameLayout
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
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">
|
android:layout_height="wrap_content">
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
|||||||
@@ -104,4 +104,7 @@
|
|||||||
|
|
||||||
<!-- The side padding for the task stack. -->
|
<!-- The side padding for the task stack. -->
|
||||||
<dimen name="recents_stack_left_right_padding">64dp</dimen>
|
<dimen name="recents_stack_left_right_padding">64dp</dimen>
|
||||||
|
|
||||||
|
<!-- Keyboard shortcuts helper -->
|
||||||
|
<dimen name="ksh_layout_width">488dp</dimen>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -167,6 +167,7 @@
|
|||||||
<!-- Keyboard shortcuts colors -->
|
<!-- Keyboard shortcuts colors -->
|
||||||
<color name="ksh_system_group_color">#ff00bcd4</color>
|
<color name="ksh_system_group_color">#ff00bcd4</color>
|
||||||
<color name="ksh_application_group_color">#fff44336</color>
|
<color name="ksh_application_group_color">#fff44336</color>
|
||||||
|
<color name="ksh_keyword_color">#d9000000</color>
|
||||||
|
|
||||||
<!-- Background color of edit overflow -->
|
<!-- Background color of edit overflow -->
|
||||||
<color name="qs_edit_overflow_bg">#455A64</color>
|
<color name="qs_edit_overflow_bg">#455A64</color>
|
||||||
|
|||||||
@@ -639,4 +639,7 @@
|
|||||||
|
|
||||||
<dimen name="battery_detail_graph_space_top">27dp</dimen>
|
<dimen name="battery_detail_graph_space_top">27dp</dimen>
|
||||||
<dimen name="battery_detail_graph_space_bottom">27dp</dimen>
|
<dimen name="battery_detail_graph_space_bottom">27dp</dimen>
|
||||||
|
|
||||||
|
<!-- Keyboard shortcuts helper -->
|
||||||
|
<dimen name="ksh_layout_width">@dimen/match_parent</dimen>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -29,6 +29,7 @@ import android.view.KeyboardShortcutGroup;
|
|||||||
import android.view.KeyboardShortcutInfo;
|
import android.view.KeyboardShortcutInfo;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
import android.view.Window;
|
import android.view.Window;
|
||||||
import android.view.WindowManager.KeyboardShortcutsReceiver;
|
import android.view.WindowManager.KeyboardShortcutsReceiver;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
@@ -153,7 +154,7 @@ public class KeyboardShortcuts {
|
|||||||
.findViewById(R.id.keyboard_shortcuts_keyword);
|
.findViewById(R.id.keyboard_shortcuts_keyword);
|
||||||
textView.setText(info.getLabel());
|
textView.setText(info.getLabel());
|
||||||
|
|
||||||
LinearLayout shortcutItemsContainer = (LinearLayout) shortcutView
|
ViewGroup shortcutItemsContainer = (ViewGroup) shortcutView
|
||||||
.findViewById(R.id.keyboard_shortcuts_item_container);
|
.findViewById(R.id.keyboard_shortcuts_item_container);
|
||||||
List<String> shortcutKeys = getHumanReadableShortcutKeys(info);
|
List<String> shortcutKeys = getHumanReadableShortcutKeys(info);
|
||||||
final int shortcutKeysSize = shortcutKeys.size();
|
final int shortcutKeysSize = shortcutKeys.size();
|
||||||
|
|||||||
Reference in New Issue
Block a user