session-android/src/org/thoughtcrime/securesms/components/SquareFrameLayout.java

47 lines
1.4 KiB
Java
Raw Normal View History

package org.thoughtcrime.securesms.components;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.BitmapFactory;
import android.os.Build.VERSION_CODES;
import android.util.AttributeSet;
import android.widget.FrameLayout;
2019-07-24 02:30:23 +00:00
import network.loki.messenger.R;
public class SquareFrameLayout extends FrameLayout {
private final boolean squareHeight;
@SuppressWarnings("unused")
public SquareFrameLayout(Context context) {
this(context, null);
}
@SuppressWarnings("unused")
public SquareFrameLayout(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
@TargetApi(VERSION_CODES.HONEYCOMB) @SuppressWarnings("unused")
public SquareFrameLayout(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
if (attrs != null) {
TypedArray typedArray = context.getTheme().obtainStyledAttributes(attrs, R.styleable.SquareFrameLayout, 0, 0);
this.squareHeight = typedArray.getBoolean(R.styleable.SquareFrameLayout_square_height, false);
typedArray.recycle();
} else {
this.squareHeight = false;
}
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
//noinspection SuspiciousNameCombination
if (squareHeight) super.onMeasure(heightMeasureSpec, heightMeasureSpec);
else super.onMeasure(widthMeasureSpec, widthMeasureSpec);
}
}