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