147 lines
5.4 KiB
Java
147 lines
5.4 KiB
Java
package com.ubt.jimu.widgets.screenAdaptive;
|
|
|
|
import android.content.Context;
|
|
import android.util.AttributeSet;
|
|
import android.util.DisplayMetrics;
|
|
import android.util.Log;
|
|
import android.view.MotionEvent;
|
|
import android.view.View;
|
|
import android.view.ViewGroup;
|
|
import android.widget.FrameLayout;
|
|
import android.widget.RelativeLayout;
|
|
import android.widget.TextView;
|
|
import com.ubt.jimu.utils.LogUtils;
|
|
|
|
/* loaded from: classes2.dex */
|
|
public class XRelativeLayout extends RelativeLayout {
|
|
private Context a;
|
|
private float b;
|
|
private int c;
|
|
private float d;
|
|
private float e;
|
|
private float f;
|
|
private float g;
|
|
protected boolean h;
|
|
|
|
class AutoLayoutParams extends RelativeLayout.LayoutParams {
|
|
public AutoLayoutParams(XRelativeLayout xRelativeLayout, Context context, AttributeSet attributeSet) {
|
|
super(context, attributeSet);
|
|
}
|
|
}
|
|
|
|
public XRelativeLayout(Context context, AttributeSet attributeSet) {
|
|
super(context, attributeSet);
|
|
this.h = false;
|
|
this.a = context;
|
|
a(context);
|
|
}
|
|
|
|
private void a(Context context) {
|
|
DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
|
|
this.b = displayMetrics.density;
|
|
this.c = displayMetrics.densityDpi;
|
|
this.d = displayMetrics.heightPixels;
|
|
this.e = displayMetrics.widthPixels;
|
|
float f = this.e;
|
|
float f2 = this.d;
|
|
if (f < f2) {
|
|
this.e = f2;
|
|
this.d = f;
|
|
}
|
|
this.f = this.e / 1024.0f;
|
|
this.g = this.d / 768.0f;
|
|
LogUtils.c("Density is " + this.b + " densityDpi is " + this.c + " height: " + this.d + " width: " + this.e);
|
|
}
|
|
|
|
@Override // android.view.ViewGroup
|
|
public void addView(View view, int i, ViewGroup.LayoutParams layoutParams) {
|
|
if (view instanceof TextView) {
|
|
TextView textView = (TextView) view;
|
|
textView.setTextSize(0, textView.getTextSize() * this.g);
|
|
}
|
|
int paddingBottom = view.getPaddingBottom();
|
|
int paddingTop = view.getPaddingTop();
|
|
int paddingLeft = view.getPaddingLeft();
|
|
int paddingRight = view.getPaddingRight();
|
|
if (paddingBottom != 0 || paddingTop != 0 || paddingLeft != 0 || paddingRight != 0) {
|
|
view.setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom);
|
|
}
|
|
if (layoutParams instanceof RelativeLayout.LayoutParams) {
|
|
RelativeLayout.LayoutParams layoutParams2 = (RelativeLayout.LayoutParams) layoutParams;
|
|
float f = layoutParams2.width;
|
|
float f2 = layoutParams2.height;
|
|
int i2 = layoutParams2.topMargin;
|
|
int i3 = layoutParams2.leftMargin;
|
|
int i4 = layoutParams2.bottomMargin;
|
|
int i5 = layoutParams2.rightMargin;
|
|
if (i2 != 0) {
|
|
layoutParams2.topMargin = (int) ((i2 * this.g) + 0.5d);
|
|
}
|
|
if (i4 != 0) {
|
|
layoutParams2.bottomMargin = (int) ((i4 * this.g) + 0.5d);
|
|
}
|
|
if (i3 != 0) {
|
|
layoutParams2.leftMargin = (int) ((i3 * this.f) + 0.5d);
|
|
}
|
|
if (i5 != 0) {
|
|
layoutParams2.rightMargin = (int) ((i5 * this.f) + 0.5d);
|
|
}
|
|
int i6 = (int) ((this.g * f2) + 0.5d);
|
|
if (f2 > 0.0f) {
|
|
layoutParams2.height = i6;
|
|
}
|
|
float f3 = f / f2;
|
|
int i7 = (int) ((i6 * f3) + 0.5d);
|
|
if (f > 0.0f) {
|
|
layoutParams2.width = i7;
|
|
}
|
|
Log.e("XRelativeLayout Test", "childWidth=" + f + "--childHeight" + f2 + "--adapterHeight=" + i6 + "--adapterWidth=" + i7 + "aspectRatio=" + f3 + "--heightRatio=" + this.g + "---widthRatio=" + this.f);
|
|
}
|
|
super.addView(view, i, layoutParams);
|
|
}
|
|
|
|
@Override // android.view.ViewGroup, android.view.View
|
|
public boolean dispatchTouchEvent(MotionEvent motionEvent) {
|
|
boolean z = this.h;
|
|
return z ? z : super.dispatchTouchEvent(motionEvent);
|
|
}
|
|
|
|
@Override // android.view.ViewGroup
|
|
public boolean onInterceptTouchEvent(MotionEvent motionEvent) {
|
|
LogUtils.d("isIntercept==" + this.h + "ev==" + getId());
|
|
boolean z = this.h;
|
|
return z ? z : super.onInterceptTouchEvent(motionEvent);
|
|
}
|
|
|
|
@Override // android.widget.RelativeLayout, android.view.ViewGroup, android.view.View
|
|
protected void onLayout(boolean z, int i, int i2, int i3, int i4) {
|
|
super.onLayout(z, i, i2, i3, i4);
|
|
LogUtils.d("l==" + i + "t==" + i2 + "r==" + i3 + "b==" + i4);
|
|
}
|
|
|
|
@Override // android.widget.RelativeLayout, android.view.View
|
|
protected void onMeasure(int i, int i2) {
|
|
if (getLayoutParams() instanceof FrameLayout.LayoutParams) {
|
|
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) getLayoutParams();
|
|
int i3 = layoutParams.width;
|
|
int i4 = layoutParams.height;
|
|
}
|
|
super.onMeasure(i, i2);
|
|
}
|
|
|
|
@Override // android.view.View
|
|
public boolean onTouchEvent(MotionEvent motionEvent) {
|
|
return super.onTouchEvent(motionEvent);
|
|
}
|
|
|
|
public void setIntercept(boolean z) {
|
|
LogUtils.d("setIntercept==" + z);
|
|
this.h = z;
|
|
}
|
|
|
|
@Override // android.widget.RelativeLayout, android.view.ViewGroup
|
|
public RelativeLayout.LayoutParams generateLayoutParams(AttributeSet attributeSet) {
|
|
return new AutoLayoutParams(this, this.a, attributeSet);
|
|
}
|
|
}
|