2018-11-08 23:33:37 -08:00
|
|
|
package org.thoughtcrime.securesms.components;
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.res.TypedArray;
|
|
|
|
import android.support.annotation.Nullable;
|
|
|
|
import android.util.AttributeSet;
|
|
|
|
import android.widget.ScrollView;
|
|
|
|
|
2019-07-24 12:30:23 +10:00
|
|
|
import network.loki.messenger.R;
|
2018-11-08 23:33:37 -08:00
|
|
|
|
|
|
|
public class MaxHeightScrollView extends ScrollView {
|
|
|
|
|
|
|
|
private int maxHeight = -1;
|
|
|
|
|
|
|
|
public MaxHeightScrollView(Context context) {
|
|
|
|
super(context);
|
|
|
|
initialize(null);
|
|
|
|
}
|
|
|
|
|
|
|
|
public MaxHeightScrollView(Context context, AttributeSet attrs) {
|
|
|
|
super(context, attrs);
|
|
|
|
initialize(attrs);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void initialize(@Nullable AttributeSet attrs) {
|
|
|
|
if (attrs != null) {
|
|
|
|
TypedArray typedArray = getContext().getTheme().obtainStyledAttributes(attrs, R.styleable.MaxHeightScrollView, 0, 0);
|
|
|
|
|
|
|
|
maxHeight = typedArray.getDimensionPixelOffset(R.styleable.MaxHeightScrollView_scrollView_maxHeight, -1);
|
|
|
|
|
|
|
|
typedArray.recycle();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
|
|
|
if (maxHeight >= 0) {
|
|
|
|
heightMeasureSpec = MeasureSpec.makeMeasureSpec(maxHeight, MeasureSpec.AT_MOST);
|
|
|
|
}
|
|
|
|
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
|
|
|
}
|
|
|
|
}
|