1 /* 2 * Copyright (C) 2013 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.printspooler; 18 19 import android.content.Context; 20 import android.util.AttributeSet; 21 import android.widget.FrameLayout; 22 23 public class PrintDialogFrame extends FrameLayout { 24 25 public final int mMaxWidth; 26 27 public int mHeight; 28 29 public PrintDialogFrame(Context context, AttributeSet attrs) { 30 super(context, attrs); 31 mMaxWidth = context.getResources().getDimensionPixelSize( 32 R.dimen.print_dialog_frame_max_width_dip); 33 } 34 35 @Override 36 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 37 super.onMeasure(widthMeasureSpec, heightMeasureSpec); 38 39 int measuredWidth = getMeasuredWidth(); 40 final int widthMode = MeasureSpec.getMode(widthMeasureSpec); 41 switch (widthMode) { 42 case MeasureSpec.UNSPECIFIED: { 43 measuredWidth = mMaxWidth; 44 } break; 45 46 case MeasureSpec.AT_MOST: { 47 final int receivedWidth = MeasureSpec.getSize(widthMeasureSpec); 48 measuredWidth = Math.min(mMaxWidth, receivedWidth); 49 } break; 50 } 51 52 mHeight = Math.max(mHeight, getMeasuredHeight()); 53 54 int measuredHeight = getMeasuredHeight(); 55 final int heightMode = MeasureSpec.getMode(heightMeasureSpec); 56 switch (heightMode) { 57 case MeasureSpec.UNSPECIFIED: { 58 measuredHeight = mHeight; 59 } break; 60 61 case MeasureSpec.AT_MOST: { 62 final int receivedHeight = MeasureSpec.getSize(heightMeasureSpec); 63 measuredHeight = Math.min(mHeight, receivedHeight); 64 } break; 65 } 66 67 setMeasuredDimension(measuredWidth, measuredHeight); 68 } 69 } 70