2015-06-27 03:14:51 +00:00
|
|
|
package org.thoughtcrime.securesms.components;
|
|
|
|
|
|
|
|
import android.annotation.TargetApi;
|
|
|
|
import android.content.Context;
|
2016-11-26 06:37:23 +00:00
|
|
|
import android.content.res.TypedArray;
|
|
|
|
import android.graphics.BitmapFactory;
|
2015-06-27 03:14:51 +00:00
|
|
|
import android.os.Build.VERSION_CODES;
|
|
|
|
import android.util.AttributeSet;
|
|
|
|
import android.widget.FrameLayout;
|
|
|
|
|
2016-11-26 06:37:23 +00:00
|
|
|
import org.thoughtcrime.securesms.R;
|
|
|
|
|
2015-06-27 03:14:51 +00:00
|
|
|
public class SquareFrameLayout extends FrameLayout {
|
2016-11-26 06:37:23 +00:00
|
|
|
|
|
|
|
private final boolean squareHeight;
|
|
|
|
|
2015-06-27 03:14:51 +00:00
|
|
|
@SuppressWarnings("unused")
|
|
|
|
public SquareFrameLayout(Context context) {
|
2016-11-26 06:37:23 +00:00
|
|
|
this(context, null);
|
2015-06-27 03:14:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@SuppressWarnings("unused")
|
|
|
|
public SquareFrameLayout(Context context, AttributeSet attrs) {
|
2016-11-26 06:37:23 +00:00
|
|
|
this(context, attrs, 0);
|
2015-06-27 03:14:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@TargetApi(VERSION_CODES.HONEYCOMB) @SuppressWarnings("unused")
|
|
|
|
public SquareFrameLayout(Context context, AttributeSet attrs, int defStyleAttr) {
|
|
|
|
super(context, attrs, defStyleAttr);
|
|
|
|
|
2016-11-26 06:37:23 +00:00
|
|
|
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;
|
|
|
|
}
|
2015-06-27 03:14:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
|
|
|
//noinspection SuspiciousNameCombination
|
2016-11-26 06:37:23 +00:00
|
|
|
if (squareHeight) super.onMeasure(heightMeasureSpec, heightMeasureSpec);
|
|
|
|
else super.onMeasure(widthMeasureSpec, widthMeasureSpec);
|
2015-06-27 03:14:51 +00:00
|
|
|
}
|
|
|
|
}
|