Initial commit
This commit is contained in:
140
sources/com/ubtech/view/widget/ULinearLayout.java
Normal file
140
sources/com/ubtech/view/widget/ULinearLayout.java
Normal file
@@ -0,0 +1,140 @@
|
||||
package com.ubtech.view.widget;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
import com.ubtech.R$styleable;
|
||||
import com.ubtech.utils.DensityUtils;
|
||||
|
||||
/* loaded from: classes2.dex */
|
||||
public class ULinearLayout extends LinearLayout {
|
||||
private int a;
|
||||
private float b;
|
||||
|
||||
public static class LayoutParams extends LinearLayout.LayoutParams {
|
||||
private float a;
|
||||
private float b;
|
||||
private float c;
|
||||
private float d;
|
||||
private float e;
|
||||
private float f;
|
||||
|
||||
public LayoutParams(Context context, AttributeSet attributeSet) {
|
||||
super(context, attributeSet);
|
||||
TypedArray obtainStyledAttributes = context.obtainStyledAttributes(attributeSet, R$styleable.u_layout, 0, 0);
|
||||
this.a = obtainStyledAttributes.getFloat(R$styleable.u_layout_height_percent, 0.0f);
|
||||
this.b = obtainStyledAttributes.getFloat(R$styleable.u_layout_width_percent, 0.0f);
|
||||
this.c = obtainStyledAttributes.getFloat(R$styleable.u_layout_margin_left_percent, 0.0f);
|
||||
this.d = obtainStyledAttributes.getFloat(R$styleable.u_layout_margin_top_percent, 0.0f);
|
||||
this.e = obtainStyledAttributes.getFloat(R$styleable.u_layout_margin_right_percent, 0.0f);
|
||||
this.f = obtainStyledAttributes.getFloat(R$styleable.u_layout_margin_bottom_percent, 0.0f);
|
||||
obtainStyledAttributes.recycle();
|
||||
}
|
||||
|
||||
public float a() {
|
||||
return this.f;
|
||||
}
|
||||
|
||||
public float b() {
|
||||
return this.a;
|
||||
}
|
||||
|
||||
public float c() {
|
||||
return this.c;
|
||||
}
|
||||
|
||||
public float d() {
|
||||
return this.e;
|
||||
}
|
||||
|
||||
public float e() {
|
||||
return this.d;
|
||||
}
|
||||
|
||||
public float f() {
|
||||
return this.b;
|
||||
}
|
||||
}
|
||||
|
||||
public ULinearLayout(Context context) {
|
||||
this(context, null);
|
||||
}
|
||||
|
||||
private void a(Context context, AttributeSet attributeSet) {
|
||||
DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
|
||||
this.a = Math.min(displayMetrics.widthPixels, displayMetrics.heightPixels);
|
||||
this.b = this.a / (DensityUtils.a(context, 720) * 1.0f);
|
||||
}
|
||||
|
||||
@Override // android.view.ViewGroup
|
||||
public void addView(View view, int i, ViewGroup.LayoutParams layoutParams) {
|
||||
super.addView(view, i, layoutParams);
|
||||
if (view instanceof TextView) {
|
||||
TextView textView = (TextView) view;
|
||||
textView.setTextSize(0, textView.getTextSize() * this.b);
|
||||
}
|
||||
}
|
||||
|
||||
@Override // android.widget.LinearLayout, android.view.View
|
||||
protected void onMeasure(int i, int i2) {
|
||||
float f;
|
||||
float f2;
|
||||
float f3;
|
||||
float f4;
|
||||
float f5;
|
||||
float f6;
|
||||
for (int i3 = 0; i3 < getChildCount(); i3++) {
|
||||
LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) getChildAt(i3).getLayoutParams();
|
||||
if (layoutParams instanceof LayoutParams) {
|
||||
LayoutParams layoutParams2 = (LayoutParams) layoutParams;
|
||||
f2 = layoutParams2.f();
|
||||
f3 = layoutParams2.b();
|
||||
f4 = layoutParams2.c();
|
||||
f5 = layoutParams2.e();
|
||||
f6 = layoutParams2.d();
|
||||
f = layoutParams2.a();
|
||||
} else {
|
||||
f = 0.0f;
|
||||
f2 = 0.0f;
|
||||
f3 = 0.0f;
|
||||
f4 = 0.0f;
|
||||
f5 = 0.0f;
|
||||
f6 = 0.0f;
|
||||
}
|
||||
if (f3 != 0.0f) {
|
||||
layoutParams.height = (int) Math.ceil(this.a * f3);
|
||||
}
|
||||
if (f2 != 0.0f) {
|
||||
layoutParams.width = (int) Math.ceil(layoutParams.height * f2);
|
||||
}
|
||||
if (f4 != 0.0f) {
|
||||
layoutParams.leftMargin = (int) Math.ceil(this.a * f4);
|
||||
}
|
||||
if (f5 != 0.0f) {
|
||||
layoutParams.topMargin = (int) Math.ceil(this.a * f5);
|
||||
}
|
||||
if (f6 != 0.0f) {
|
||||
layoutParams.rightMargin = (int) Math.ceil(this.a * f6);
|
||||
}
|
||||
if (f != 0.0f) {
|
||||
layoutParams.bottomMargin = (int) Math.ceil(this.a * f);
|
||||
}
|
||||
}
|
||||
super.onMeasure(i, i2);
|
||||
}
|
||||
|
||||
public ULinearLayout(Context context, AttributeSet attributeSet) {
|
||||
super(context, attributeSet);
|
||||
a(context, attributeSet);
|
||||
}
|
||||
|
||||
@Override // android.widget.LinearLayout, android.view.ViewGroup
|
||||
public LinearLayout.LayoutParams generateLayoutParams(AttributeSet attributeSet) {
|
||||
return new LayoutParams(getContext(), attributeSet);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user