1 /* 2 * Copyright 2018 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 androidx.browser.browseractions; 18 19 import static androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP; 20 21 import android.content.Context; 22 import android.util.AttributeSet; 23 import android.widget.LinearLayout; 24 25 import androidx.annotation.RestrictTo; 26 import androidx.browser.R; 27 28 /** 29 * The class responsible for deciding the size of Browser Actions context menu. 30 */ 31 /** @hide */ 32 @RestrictTo(LIBRARY_GROUP) 33 public class BrowserActionsFallbackMenuView extends LinearLayout { 34 private final int mBrowserActionsMenuMinPaddingPx; 35 private final int mBrowserActionsMenuMaxWidthPx; 36 37 public BrowserActionsFallbackMenuView(Context context, AttributeSet attrs) { 38 super(context, attrs); 39 mBrowserActionsMenuMinPaddingPx = getResources().getDimensionPixelOffset( 40 R.dimen.browser_actions_context_menu_min_padding); 41 mBrowserActionsMenuMaxWidthPx = getResources().getDimensionPixelOffset( 42 R.dimen.browser_actions_context_menu_max_width); 43 } 44 45 @Override 46 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 47 int appWindowWidthPx = getResources().getDisplayMetrics().widthPixels; 48 int contextMenuWidth = Math.min(appWindowWidthPx - 2 * mBrowserActionsMenuMinPaddingPx, 49 mBrowserActionsMenuMaxWidthPx); 50 widthMeasureSpec = MeasureSpec.makeMeasureSpec(contextMenuWidth, MeasureSpec.EXACTLY); 51 super.onMeasure(widthMeasureSpec, heightMeasureSpec); 52 } 53 } 54