Peeyush Agarwal | e2c893f | 2016-12-15 15:09:58 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License |
| 15 | */ |
| 16 | |
| 17 | package com.android.systemui.statusbar; |
| 18 | |
| 19 | import android.content.Context; |
| 20 | import android.util.AttributeSet; |
| 21 | import android.view.View; |
| 22 | import android.widget.ImageView; |
| 23 | import android.widget.RelativeLayout; |
| 24 | import android.widget.TextView; |
| 25 | |
| 26 | import com.android.systemui.R; |
| 27 | |
| 28 | /** |
| 29 | * Layout used for displaying keyboard shortcut items inside an alert dialog. |
| 30 | * The layout sets the maxWidth of shortcuts keyword textview to 70% of available space. |
| 31 | */ |
| 32 | public class KeyboardShortcutAppItemLayout extends RelativeLayout { |
| 33 | |
| 34 | private static final double MAX_WIDTH_PERCENT_FOR_KEYWORDS = 0.70; |
| 35 | |
| 36 | public KeyboardShortcutAppItemLayout(Context context) { |
| 37 | super(context); |
| 38 | } |
| 39 | |
| 40 | public KeyboardShortcutAppItemLayout(Context context, AttributeSet attrs) { |
| 41 | super(context, attrs); |
| 42 | } |
| 43 | |
| 44 | @Override |
| 45 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
| 46 | if (MeasureSpec.getMode(widthMeasureSpec) == MeasureSpec.EXACTLY) { |
Alan Viverette | 51efddb | 2017-04-05 10:00:01 -0400 | [diff] [blame] | 47 | ImageView shortcutIcon = findViewById(R.id.keyboard_shortcuts_icon); |
| 48 | TextView shortcutKeyword = findViewById(R.id.keyboard_shortcuts_keyword); |
Peeyush Agarwal | e2c893f | 2016-12-15 15:09:58 +0000 | [diff] [blame] | 49 | int totalMeasuredWidth = MeasureSpec.getSize(widthMeasureSpec); |
| 50 | int totalPadding = getPaddingLeft() + getPaddingRight(); |
| 51 | int availableWidth = totalMeasuredWidth - totalPadding; |
| 52 | if (shortcutIcon.getVisibility() == View.VISIBLE) { |
| 53 | availableWidth = availableWidth - shortcutIcon.getMeasuredWidth(); |
| 54 | } |
| 55 | shortcutKeyword.setMaxWidth((int) |
| 56 | Math.round(availableWidth * MAX_WIDTH_PERCENT_FOR_KEYWORDS)); |
| 57 | } |
| 58 | super.onMeasure(widthMeasureSpec, heightMeasureSpec); |
| 59 | } |
| 60 | } |