1d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd/* 2d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * Copyright (C) 2015 The Android Open Source Project 3d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * 4d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * Licensed under the Apache License, Version 2.0 (the "License"); 5d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * you may not use this file except in compliance with the License. 6d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * You may obtain a copy of the License at 7d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * 8d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * http://www.apache.org/licenses/LICENSE-2.0 9d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * 10d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * Unless required by applicable law or agreed to in writing, software 11d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * distributed under the License is distributed on an "AS IS" BASIS, 12d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * See the License for the specific language governing permissions and 14d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * limitations under the License. 15d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd */ 16d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddpackage com.android.messaging.ui; 17d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 18d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport android.content.Context; 19d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport android.content.res.TypedArray; 20d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport android.util.AttributeSet; 21d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport android.widget.ScrollView; 22d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 23d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddimport com.android.messaging.R; 24d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 25d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd/** 26d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * A ScrollView that limits the maximum height that it can take. This is to work around android 27d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd * layout's limitation of not having android:maxHeight. 28d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd */ 29d3b009ae55651f1e60950342468e3c37fdeb0796Mike Doddpublic class MaxHeightScrollView extends ScrollView { 30d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd private static final int NO_MAX_HEIGHT = -1; 31d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 32d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd private final int mMaxHeight; 33d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 34d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd public MaxHeightScrollView(final Context context, final AttributeSet attrs) { 35d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd super(context, attrs); 36d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd final TypedArray attr = context.obtainStyledAttributes(attrs, 37d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd R.styleable.MaxHeightScrollView, 0, 0); 38d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd mMaxHeight = attr.getDimensionPixelSize(R.styleable.MaxHeightScrollView_android_maxHeight, 39d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd NO_MAX_HEIGHT); 40d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd attr.recycle(); 41d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 42d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd 43d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd @Override 44d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd protected void onMeasure(final int widthMeasureSpec, final int heightMeasureSpec) { 45d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd super.onMeasure(widthMeasureSpec, heightMeasureSpec); 46d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd if (mMaxHeight != NO_MAX_HEIGHT) { 47d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd setMeasuredDimension(getMeasuredWidth(), Math.min(getMeasuredHeight(), mMaxHeight)); 48d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 49d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd } 50d3b009ae55651f1e60950342468e3c37fdeb0796Mike Dodd}