351 lines
11 KiB
Java
351 lines
11 KiB
Java
package com.ubt.jimu.controller.component;
|
|
|
|
import android.content.Context;
|
|
import android.graphics.Bitmap;
|
|
import android.graphics.BitmapFactory;
|
|
import android.graphics.Canvas;
|
|
import android.graphics.Paint;
|
|
import android.graphics.Rect;
|
|
import android.graphics.RectF;
|
|
import android.util.AttributeSet;
|
|
import android.view.View;
|
|
import com.ubt.jimu.R;
|
|
import com.ubt.jimu.controller.component.MenuItemView;
|
|
import com.ubt.jimu.controller.data.widget.ItemBaseData;
|
|
import com.ubt.jimu.controller.util.SvgUtils;
|
|
import com.ubt.jimu.utils.ScreenUtil;
|
|
import com.ubtrobot.log.ALog;
|
|
|
|
/* loaded from: classes.dex */
|
|
public class DragShadowView extends View {
|
|
private RectF a;
|
|
private RectF b;
|
|
private RectF c;
|
|
private Context d;
|
|
private Bitmap e;
|
|
private Bitmap f;
|
|
private float g;
|
|
private float h;
|
|
private float i;
|
|
private float j;
|
|
private Paint k;
|
|
private Paint l;
|
|
private Paint m;
|
|
private RectF n;
|
|
private DeleteView o;
|
|
private MenuItemView.MenuItemType p;
|
|
private float q;
|
|
public int r;
|
|
public int s;
|
|
private boolean t;
|
|
private Bitmap u;
|
|
private float v;
|
|
private ItemBaseData x;
|
|
private DragShadowState y;
|
|
|
|
/* renamed from: com.ubt.jimu.controller.component.DragShadowView$1, reason: invalid class name */
|
|
static /* synthetic */ class AnonymousClass1 {
|
|
static final /* synthetic */ int[] a = new int[DragShadowState.values().length];
|
|
|
|
static {
|
|
try {
|
|
a[DragShadowState.DRAG_STATE.ordinal()] = 1;
|
|
} catch (NoSuchFieldError unused) {
|
|
}
|
|
try {
|
|
a[DragShadowState.OVERLAP_STATE.ordinal()] = 2;
|
|
} catch (NoSuchFieldError unused2) {
|
|
}
|
|
try {
|
|
a[DragShadowState.DELETE_STATE.ordinal()] = 3;
|
|
} catch (NoSuchFieldError unused3) {
|
|
}
|
|
}
|
|
}
|
|
|
|
public enum DragShadowState {
|
|
NONE_STATE,
|
|
DRAG_STATE,
|
|
OVERLAP_STATE,
|
|
DELETE_STATE
|
|
}
|
|
|
|
public DragShadowView(Context context) {
|
|
super(context);
|
|
this.g = 0.0f;
|
|
this.h = 0.0f;
|
|
this.i = 0.0f;
|
|
this.j = 0.0f;
|
|
this.t = false;
|
|
this.y = DragShadowState.NONE_STATE;
|
|
this.d = context;
|
|
c();
|
|
}
|
|
|
|
private void a(Canvas canvas) {
|
|
if (!this.t || this.c.width() <= 0.0f) {
|
|
return;
|
|
}
|
|
Bitmap bitmap = this.u;
|
|
RectF rectF = this.c;
|
|
float f = rectF.left;
|
|
float f2 = rectF.bottom;
|
|
float f3 = this.v;
|
|
canvas.drawBitmap(bitmap, (Rect) null, new RectF(f, f2 - f3, f3 + f, f2), this.m);
|
|
canvas.save();
|
|
RectF rectF2 = this.c;
|
|
float f4 = rectF2.left;
|
|
float f5 = this.v;
|
|
canvas.rotate(90.0f, f4 + (f5 / 2.0f), rectF2.top + (f5 / 2.0f));
|
|
Bitmap bitmap2 = this.u;
|
|
RectF rectF3 = this.c;
|
|
float f6 = rectF3.left;
|
|
float f7 = rectF3.top;
|
|
float f8 = this.v;
|
|
canvas.drawBitmap(bitmap2, (Rect) null, new RectF(f6, f7, f6 + f8, f8 + f7), this.m);
|
|
canvas.restore();
|
|
canvas.save();
|
|
RectF rectF4 = this.c;
|
|
float f9 = rectF4.right;
|
|
float f10 = this.v;
|
|
canvas.rotate(180.0f, f9 - (f10 / 2.0f), rectF4.top + (f10 / 2.0f));
|
|
Bitmap bitmap3 = this.u;
|
|
RectF rectF5 = this.c;
|
|
float f11 = rectF5.right;
|
|
float f12 = this.v;
|
|
float f13 = rectF5.top;
|
|
canvas.drawBitmap(bitmap3, (Rect) null, new RectF(f11 - f12, f13, f11, f12 + f13), this.m);
|
|
canvas.restore();
|
|
canvas.save();
|
|
RectF rectF6 = this.c;
|
|
float f14 = rectF6.right;
|
|
float f15 = this.v;
|
|
canvas.rotate(270.0f, f14 - (f15 / 2.0f), rectF6.bottom - (f15 / 2.0f));
|
|
Bitmap bitmap4 = this.u;
|
|
RectF rectF7 = this.c;
|
|
float f16 = rectF7.right;
|
|
float f17 = this.v;
|
|
float f18 = rectF7.bottom;
|
|
canvas.drawBitmap(bitmap4, (Rect) null, new RectF(f16 - f17, f18 - f17, f16, f18), this.m);
|
|
canvas.restore();
|
|
}
|
|
|
|
private void c() {
|
|
this.k = new Paint();
|
|
this.k.setFlags(3);
|
|
this.l = new Paint();
|
|
this.l.setFlags(3);
|
|
this.l.setColor(this.d.getResources().getColor(R.color.color_00C4C9));
|
|
this.m = new Paint();
|
|
this.m.setFlags(3);
|
|
this.u = BitmapFactory.decodeResource(getResources(), R.drawable.ic_adsorb_corner);
|
|
this.a = new RectF();
|
|
this.b = new RectF();
|
|
this.c = new RectF();
|
|
this.q = this.d.getResources().getDimension(R.dimen.shadow_radian);
|
|
this.r = ScreenUtil.b(this.d);
|
|
this.s = ScreenUtil.a(this.d);
|
|
this.v = getContext().getResources().getDimension(R.dimen.grid_view_width);
|
|
}
|
|
|
|
private RectF getDeleteViewRectF() {
|
|
return this.n;
|
|
}
|
|
|
|
public DragShadowView b(float f, float f2) {
|
|
this.i = f;
|
|
this.j = f2;
|
|
return this;
|
|
}
|
|
|
|
public DragShadowView d(float f, float f2) {
|
|
this.g = f;
|
|
this.h = f2;
|
|
if (this.p == MenuItemView.MenuItemType.WIDGET_ITEM) {
|
|
this.i = f;
|
|
this.j = f2;
|
|
}
|
|
return this;
|
|
}
|
|
|
|
public float getBgHeight() {
|
|
return this.j;
|
|
}
|
|
|
|
public float getBgWidth() {
|
|
return this.i;
|
|
}
|
|
|
|
public MenuItemView.MenuItemType getMenuItemType() {
|
|
return this.p;
|
|
}
|
|
|
|
@Override // android.view.View
|
|
protected void onDraw(Canvas canvas) {
|
|
if (this.e == null) {
|
|
super.onDraw(canvas);
|
|
return;
|
|
}
|
|
if (this.p == null) {
|
|
super.onDraw(canvas);
|
|
return;
|
|
}
|
|
super.onDraw(canvas);
|
|
RectF rectF = this.b;
|
|
float f = this.q;
|
|
canvas.drawRoundRect(rectF, f, f, this.l);
|
|
a(canvas);
|
|
if (this.p == MenuItemView.MenuItemType.ACTION_ITEM) {
|
|
canvas.drawBitmap(this.f, (Rect) null, this.b, this.k);
|
|
}
|
|
canvas.drawBitmap(this.e, (Rect) null, this.a, this.k);
|
|
}
|
|
|
|
public void setDragShadowState(DragShadowState dragShadowState) {
|
|
int color;
|
|
if (dragShadowState.equals(this.y)) {
|
|
invalidate();
|
|
return;
|
|
}
|
|
int i = AnonymousClass1.a[dragShadowState.ordinal()];
|
|
if (i == 1) {
|
|
color = this.d.getResources().getColor(R.color.bg_9900C4C9);
|
|
this.t = true;
|
|
if (this.o != null && this.x != null) {
|
|
String format = String.format(this.d.getResources().getString(R.string.control_remove_widget_here), b(this.x));
|
|
this.o.setOverlapState(false);
|
|
this.o.a(format);
|
|
}
|
|
} else if (i == 2) {
|
|
color = this.d.getResources().getColor(R.color.bg_99B8BEC1);
|
|
this.t = false;
|
|
if (this.o != null && this.x != null) {
|
|
String format2 = String.format(this.d.getResources().getString(R.string.control_remove_widget_here), b(this.x));
|
|
this.o.setOverlapState(false);
|
|
this.o.a(format2);
|
|
}
|
|
} else if (i != 3) {
|
|
ALog.a("Not Support set this state", new Object[0]);
|
|
color = 0;
|
|
} else {
|
|
this.t = false;
|
|
color = this.d.getResources().getColor(R.color.color_FF4979);
|
|
if (this.o != null && this.x != null) {
|
|
String format3 = String.format(this.d.getResources().getString(R.string.control_remove_widget), b(this.x));
|
|
this.o.setOverlapState(true);
|
|
this.o.a(format3);
|
|
}
|
|
}
|
|
this.l.setColor(color);
|
|
invalidate();
|
|
}
|
|
|
|
private String b(ItemBaseData itemBaseData) {
|
|
return itemBaseData != null ? itemBaseData.getWidgetInfo(this.d) : "";
|
|
}
|
|
|
|
public void b() {
|
|
this.a.set(0.0f, 0.0f, 0.0f, 0.0f);
|
|
this.b.set(0.0f, 0.0f, 0.0f, 0.0f);
|
|
this.c.set(0.0f, 0.0f, 0.0f, 0.0f);
|
|
DeleteView deleteView = this.o;
|
|
if (deleteView != null) {
|
|
deleteView.f();
|
|
}
|
|
invalidate();
|
|
}
|
|
|
|
public DragShadowView(Context context, AttributeSet attributeSet) {
|
|
super(context, attributeSet);
|
|
this.g = 0.0f;
|
|
this.h = 0.0f;
|
|
this.i = 0.0f;
|
|
this.j = 0.0f;
|
|
this.t = false;
|
|
this.y = DragShadowState.NONE_STATE;
|
|
this.d = context;
|
|
c();
|
|
}
|
|
|
|
public float b(float f) {
|
|
float f2 = this.j;
|
|
if (f - (f2 / 2.0f) <= 0.0f) {
|
|
return f2 / 2.0f;
|
|
}
|
|
float f3 = (f2 / 2.0f) + f;
|
|
int i = this.s;
|
|
return f3 >= ((float) i) ? i - (f2 / 2.0f) : f;
|
|
}
|
|
|
|
public DragShadowView a(MenuItemView.MenuItemType menuItemType) {
|
|
this.p = menuItemType;
|
|
return this;
|
|
}
|
|
|
|
public DragShadowView a(ItemBaseData itemBaseData) {
|
|
this.x = itemBaseData;
|
|
return this;
|
|
}
|
|
|
|
public void c(float f, float f2) {
|
|
float a = a(f);
|
|
float b = b(f2);
|
|
RectF rectF = this.a;
|
|
float f3 = this.g;
|
|
float f4 = this.h;
|
|
rectF.set(a - (f3 / 2.0f), b - (f4 / 2.0f), (f3 / 2.0f) + a, (f4 / 2.0f) + b);
|
|
RectF rectF2 = this.b;
|
|
float f5 = this.i;
|
|
float f6 = this.j;
|
|
rectF2.set(a - (f5 / 2.0f), b - (f6 / 2.0f), a + (f5 / 2.0f), b + (f6 / 2.0f));
|
|
}
|
|
|
|
public DragShadowView a(int i) {
|
|
MenuItemView.MenuItemType menuItemType = this.p;
|
|
if (menuItemType != null) {
|
|
if (menuItemType == MenuItemView.MenuItemType.WIDGET_ITEM) {
|
|
this.e = BitmapFactory.decodeResource(this.d.getResources(), i);
|
|
return this;
|
|
}
|
|
this.e = SvgUtils.a(this.d).a(i, (int) this.g, (int) this.h);
|
|
if (this.p == MenuItemView.MenuItemType.ACTION_ITEM) {
|
|
this.f = BitmapFactory.decodeResource(this.d.getResources(), R.mipmap.btn_shadow);
|
|
}
|
|
return this;
|
|
}
|
|
throw new RuntimeException("必须先调用 setMenuItemType() 函数设置item类型");
|
|
}
|
|
|
|
public void a(float f, float f2) {
|
|
RectF rectF = this.c;
|
|
float f3 = this.i;
|
|
float f4 = this.j;
|
|
rectF.set(f - (f3 / 2.0f), f2 - (f4 / 2.0f), f + (f3 / 2.0f), f2 + (f4 / 2.0f));
|
|
}
|
|
|
|
public boolean a() {
|
|
RectF deleteViewRectF = getDeleteViewRectF();
|
|
if (deleteViewRectF == null) {
|
|
return false;
|
|
}
|
|
return RectF.intersects(deleteViewRectF, this.b);
|
|
}
|
|
|
|
public void a(DeleteView deleteView) {
|
|
this.o = deleteView;
|
|
if (this.o != null) {
|
|
this.n = deleteView.getDeleteViewRectF();
|
|
}
|
|
}
|
|
|
|
public float a(float f) {
|
|
float f2 = this.i;
|
|
if (f - (f2 / 2.0f) <= 0.0f) {
|
|
return f2 / 2.0f;
|
|
}
|
|
float f3 = (f2 / 2.0f) + f;
|
|
int i = this.r;
|
|
return f3 >= ((float) i) ? i - (f2 / 2.0f) : f;
|
|
}
|
|
}
|