72 lines
2.5 KiB
Java
72 lines
2.5 KiB
Java
package com.twitter.sdk.android.tweetui.internal;
|
|
|
|
import android.content.Context;
|
|
import android.content.res.TypedArray;
|
|
import android.util.AttributeSet;
|
|
import android.view.View;
|
|
import android.widget.FrameLayout;
|
|
import com.twitter.sdk.android.tweetui.R$styleable;
|
|
|
|
/* loaded from: classes.dex */
|
|
public class AspectRatioFrameLayout extends FrameLayout {
|
|
protected double a;
|
|
private int b;
|
|
|
|
public AspectRatioFrameLayout(Context context) {
|
|
this(context, null);
|
|
}
|
|
|
|
private void a(int i) {
|
|
TypedArray obtainStyledAttributes = getContext().getTheme().obtainStyledAttributes(i, R$styleable.AspectRatioFrameLayout);
|
|
try {
|
|
this.a = obtainStyledAttributes.getFloat(R$styleable.AspectRatioFrameLayout_tw__frame_layout_aspect_ratio, 1.0f);
|
|
this.b = obtainStyledAttributes.getInt(R$styleable.AspectRatioFrameLayout_tw__frame_layout_dimension_to_adjust, 0);
|
|
} finally {
|
|
obtainStyledAttributes.recycle();
|
|
}
|
|
}
|
|
|
|
@Override // android.widget.FrameLayout, android.view.View
|
|
protected void onMeasure(int i, int i2) {
|
|
int measuredHeight;
|
|
int i3;
|
|
int i4;
|
|
int measuredWidth;
|
|
int paddingLeft = getPaddingLeft() + getPaddingRight();
|
|
int paddingBottom = getPaddingBottom() + getPaddingTop();
|
|
if (this.b == 0) {
|
|
if (View.MeasureSpec.getMode(i) == 1073741824) {
|
|
measuredWidth = View.MeasureSpec.getSize(i);
|
|
} else {
|
|
super.onMeasure(i, i2);
|
|
measuredWidth = getMeasuredWidth();
|
|
}
|
|
i4 = measuredWidth - paddingLeft;
|
|
i3 = (int) (i4 / this.a);
|
|
} else {
|
|
if (View.MeasureSpec.getMode(i2) == 1073741824) {
|
|
measuredHeight = View.MeasureSpec.getSize(i2);
|
|
} else {
|
|
super.onMeasure(i, i2);
|
|
measuredHeight = getMeasuredHeight();
|
|
}
|
|
i3 = measuredHeight - paddingBottom;
|
|
i4 = (int) (i3 * this.a);
|
|
}
|
|
super.onMeasure(View.MeasureSpec.makeMeasureSpec(i4 + paddingLeft, 1073741824), View.MeasureSpec.makeMeasureSpec(i3 + paddingBottom, 1073741824));
|
|
}
|
|
|
|
public void setAspectRatio(double d) {
|
|
this.a = d;
|
|
}
|
|
|
|
public AspectRatioFrameLayout(Context context, AttributeSet attributeSet) {
|
|
this(context, attributeSet, 0);
|
|
}
|
|
|
|
public AspectRatioFrameLayout(Context context, AttributeSet attributeSet, int i) {
|
|
super(context, attributeSet, i);
|
|
a(i);
|
|
}
|
|
}
|