package com.ubt.jimu.controller.component; import android.animation.ValueAnimator; import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.PointF; import android.graphics.Rect; import android.graphics.RectF; import android.text.TextUtils; import android.util.Log; import android.view.MotionEvent; import android.view.View; import com.ubt.jimu.R; import com.ubt.jimu.controller.data.widget.ActionWidgetData; import com.ubt.jimu.controller.util.SvgUtils; import com.ubt.jimu.controller.view.control.ControlTouchEvent; import com.ubt.jimu.controller.view.control.OnControllerClickListener; import com.ubt.jimu.controller.view.control.SuperControlView; import com.ubt.jimu.utils.LocaleUtils; import com.ubt.jimu.utils.LogUtils; import com.ubt.jimu.utils.SystemUtils; import com.ubtrobot.log.ALog; /* loaded from: classes.dex */ public class ActionView extends SuperControlView { private Context B; private float C; private float D; private Paint E; private Paint F; private Paint G; private RectF H; private RectF I; private RectF J; private RectF K; private Bitmap L; private Bitmap M; private String N; private Bitmap O; private Bitmap P; private Bitmap Q; private Bitmap R; private float S; private float T; private float U; private float V; private float W; private float a0; private ValueAnimator b0; private float c0; private float d0; private int e0; private float f0; private float g0; private long h0; private long i0; public ActionView(Context context, int i, float f, float f2) { super(context); this.a0 = -360.0f; this.B = context; this.C = f; this.D = f2; this.e0 = i; j(); i(); } private void b(float f, float f2) { this.H.offsetTo(f, f2); this.j.offsetTo(f, f2); float centerX = this.H.centerX(); float centerY = this.H.centerY(); RectF rectF = this.I; float f3 = this.f0; rectF.offsetTo(centerX - (f3 / 2.0f), centerY - (f3 / 2.0f)); this.K.offsetTo(centerX - this.V, centerY - this.W); } private void g() { OnControllerClickListener onControllerClickListener = getOnControllerClickListener(); if (onControllerClickListener == null || b()) { return; } if (this.z == 0) { long j = this.h0; if (j - this.t > 500 || j - this.i0 < 500) { return; } } float centerY = this.H.centerY(); float centerX = this.H.centerX(); float f = this.c0; float f2 = this.l; if (f < centerX - (f2 / 2.0f) || f > centerX + (f2 / 2.0f)) { return; } float f3 = this.d0; float f4 = this.m; if (f3 < centerY - (f4 / 2.0f) || f3 > centerY + (f4 / 2.0f)) { return; } onControllerClickListener.a(getData(), this); this.i0 = System.currentTimeMillis(); } private void h() { if (this.e0 == 0) { this.e0 = R.drawable.icon_loudly; } SvgUtils a = SvgUtils.a(this.B); int i = this.e0; float f = this.f0; this.L = a.a(i, (int) f, (int) f); } private void i() { this.l = this.B.getResources().getDimension(R.dimen.grid_view_width) * 4.0f; this.m = this.l; float f = this.D; float f2 = this.m; float f3 = f + (f2 / 2.0f); int i = this.s; if (f3 >= i) { this.D = i - (f2 / 2.0f); } float f4 = this.C; float f5 = this.m; if (f4 - (f5 / 2.0f) <= 0.0f) { this.C = f5 / 2.0f; } else { float f6 = f4 + (f5 / 2.0f); int i2 = this.r; if (f6 >= i2) { this.C = i2 - (f5 / 2.0f); } } this.U = this.B.getResources().getDimension(R.dimen.control_action_width); this.f0 = this.B.getResources().getDimension(R.dimen.control_action_width); this.g0 = this.B.getResources().getDimension(R.dimen.control_action_text_width); h(); this.O = BitmapFactory.decodeResource(this.B.getResources(), R.mipmap.btn_shadow); this.R = BitmapFactory.decodeResource(this.B.getResources(), R.mipmap.text_background_normal); this.Q = BitmapFactory.decodeResource(this.B.getResources(), R.mipmap.text_background_pressed); this.P = this.R; this.E = new Paint(); this.E.setFlags(3); this.F = new Paint(); this.G = new Paint(); this.F.setAntiAlias(true); this.F.setColor(this.B.getResources().getColor(R.color.bg_C9EBFE)); this.G.setColor(this.B.getResources().getColor(R.color.bg_FFFFFF)); float f7 = this.C; float f8 = this.l; float f9 = this.D; float f10 = this.m; this.j = new RectF(f7 - (f8 / 2.0f), f9 - (f10 / 2.0f), f7 + (f8 / 2.0f), f9 + (f10 / 2.0f)); float f11 = this.C; float f12 = this.l; float f13 = this.D; float f14 = this.m; this.H = new RectF(f11 - (f12 / 2.0f), f13 - (f14 / 2.0f), f11 + (f12 / 2.0f), f13 + (f14 / 2.0f)); this.V = this.B.getResources().getDimension(R.dimen.control_action_text_x_offset); this.W = this.B.getResources().getDimension(R.dimen.control_action_text_y_offset); float[] viewCenterXY = getViewCenterXY(); this.K = new RectF(viewCenterXY[0] - this.V, viewCenterXY[1] - this.W, this.C + (this.l / 2.0f), this.D + (this.m / 2.0f)); this.J = new RectF(); float f15 = this.C; float f16 = this.f0; float f17 = this.D; this.I = new RectF(f15 - (f16 / 2.0f), f17 - (f16 / 2.0f), f15 + (f16 / 2.0f), f17 + (f16 / 2.0f)); } private void j() { } public void a(int i) { this.e0 = i; h(); invalidate(); } public void f() { ALog.a("Test").d("Text:" + this.N); this.N = null; this.M = null; invalidate(); } public String getText() { return this.N; } @Override // com.ubt.jimu.controller.view.control.SuperControlView public float[] getViewCenterXY() { return new float[]{this.H.centerX(), this.H.centerY()}; } @Override // com.ubt.jimu.controller.view.control.SuperControlView, android.view.View protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (b()) { canvas.drawBitmap(this.O, (Rect) null, this.H, this.E); canvas.drawBitmap(this.L, (Rect) null, this.I, this.E); return; } if (getState() == 0) { a(); canvas.drawBitmap(this.O, (Rect) null, this.H, this.E); canvas.drawArc(this.J, 270.0f, this.a0, true, this.F); a(canvas); canvas.drawBitmap(this.L, (Rect) null, this.I, this.E); return; } if (c()) { e(); } canvas.drawBitmap(this.O, (Rect) null, this.H, this.E); a(canvas); canvas.drawBitmap(this.L, (Rect) null, this.I, this.E); } @Override // android.view.View public boolean onTouchEvent(MotionEvent motionEvent) { int actionMasked = motionEvent.getActionMasked(); if (actionMasked == 0) { this.t = System.currentTimeMillis(); this.c0 = motionEvent.getX(); this.d0 = motionEvent.getY(); d(); float centerX = this.H.centerX(); float centerY = this.H.centerY(); float f = this.c0; float f2 = this.l; if (f >= centerX - (f2 / 2.0f) && f <= (f2 / 2.0f) + centerX) { float f3 = this.d0; float f4 = this.m; if (f3 >= centerY - (f4 / 2.0f) && f3 <= (f4 / 2.0f) + centerY) { this.f = false; setPressed(true); if (b()) { float centerX2 = this.j.centerX(); float centerY2 = this.j.centerY(); this.S = centerX2 - this.c0; this.T = centerY2 - this.d0; bringToFront(); ControlTouchEvent controlTouchEvent = this.i; if (controlTouchEvent != null) { controlTouchEvent.a((View) this); } } else if (getState() == 0) { ValueAnimator valueAnimator = this.b0; if (valueAnimator != null) { valueAnimator.cancel(); } this.a0 = -360.0f; RectF rectF = this.J; float f5 = this.U; rectF.set(centerX - (f5 / 2.0f), centerY - (f5 / 2.0f), centerX + (f5 / 2.0f), centerY + (f5 / 2.0f)); this.P = this.Q; this.H.set(0.0f, 0.0f, 0.0f, 0.0f); ControlTouchEvent controlTouchEvent2 = this.i; if (controlTouchEvent2 != null) { controlTouchEvent2.a((SuperControlView) this); this.i.a(getData()); } invalidate(); } return true; } } return super.onTouchEvent(motionEvent); } if (actionMasked == 1) { setPressed(false); if (!this.f) { LogUtils.c("MotionEvent: 抬起"); this.f = true; a(SuperControlView.MotionEventState.STATE_UP); } invalidate(); return true; } if (actionMasked != 2) { if (actionMasked != 3) { return super.onTouchEvent(motionEvent); } if (!this.f) { LogUtils.c("MotionEvent:取消"); this.f = true; a(SuperControlView.MotionEventState.STATE_CANCEL); } return true; } if (b()) { float x = motionEvent.getX(); float y = motionEvent.getY(); b(super.a(motionEvent, this.S), super.b(motionEvent, this.T)); boolean a = a(this.j); if (this.i != null) { if (Math.abs(this.c0 - x) <= 20.0f && Math.abs(this.d0 - y) <= 20.0f) { return true; } this.i.b((View) this); if (a) { if (this.e != null && getData() != null) { this.e.setOverlapState(true); this.e.a(String.format(getResources().getString(R.string.control_remove_widget), getData().getWidgetInfo(this.B))); } b(false); this.b.setColor(this.B.getResources().getColor(R.color.color_FF4979)); if (!this.n) { SystemUtils.b(this.B); this.n = true; } } else { if (this.e != null && getData() != null) { this.e.setOverlapState(false); this.e.a(String.format(getResources().getString(R.string.control_remove_widget_here), getData().getShowName(LocaleUtils.b()))); } RectF rectF2 = this.H; PointF a2 = a(rectF2.left, rectF2.top); this.k.offsetTo(a2.x, a2.y); if (this.i.c((SuperControlView) this)) { b(false); this.b.setColor(this.B.getResources().getColor(R.color.bg_99B8BEC1)); } else { b(true); this.b.setColor(this.B.getResources().getColor(this.a)); } this.n = false; } } invalidate(); } return true; } /* JADX WARN: Can't fix incorrect switch cases order, some code will duplicate */ public Bitmap a(String str) { char c; switch (str.hashCode()) { case -1721778389: if (str.equals("DPAD_UP")) { c = '\b'; break; } c = 65535; break; case -1067127502: if (str.equals("DPAD_DOWN")) { c = '\t'; break; } c = 65535; break; case -1066899305: if (str.equals("DPAD_LEFT")) { c = '\n'; break; } c = 65535; break; case 65: if (str.equals("A")) { c = 0; break; } c = 65535; break; case 66: if (str.equals("B")) { c = 1; break; } c = 65535; break; case 88: if (str.equals("X")) { c = 2; break; } c = 65535; break; case 89: if (str.equals("Y")) { c = 3; break; } c = 65535; break; case 2405: if (str.equals("L1")) { c = 4; break; } c = 65535; break; case 2406: if (str.equals("L2")) { c = 5; break; } c = 65535; break; case 2591: if (str.equals("R1")) { c = 6; break; } c = 65535; break; case 2592: if (str.equals("R2")) { c = 7; break; } c = 65535; break; case 1291520876: if (str.equals("DPAD_RIGHT")) { c = 11; break; } c = 65535; break; default: c = 65535; break; } int i = R.drawable.ic_text_x; switch (c) { case 0: i = R.drawable.ic_text_a; break; case 1: i = R.drawable.ic_text_b; break; case 2: break; case 3: i = R.drawable.ic_text_y; break; case 4: i = R.drawable.ic_text_l1; break; case 5: i = R.drawable.ic_text_l2; break; case 6: i = R.drawable.ic_text_r1; break; case 7: i = R.drawable.ic_text_r2; break; case '\b': i = R.drawable.ic_text_direction_up; break; case '\t': i = R.drawable.ic_text_direction_down; break; case '\n': i = R.drawable.ic_text_direction_left; break; case 11: i = R.drawable.ic_text_direction_right; break; default: Log.e("ActionView", "Invalid text, use defaut text X"); break; } if (i == 0) { return null; } SvgUtils a = SvgUtils.a(this.B); float f = this.g0; return a.a(i, (int) f, (int) f); } private void a(Canvas canvas) { if (this.M != null) { canvas.drawBitmap(this.P, (Rect) null, this.K, this.E); canvas.drawBitmap(this.M, (Rect) null, new RectF(this.K.centerX() - (this.g0 / 2.0f), this.K.centerY() - (this.g0 / 2.0f), this.K.centerX() + (this.g0 / 2.0f), this.K.centerY() + (this.g0 / 2.0f)), this.E); } } public void b(String str) { ALog.a("Test").d("Text:" + str); this.N = str; if (TextUtils.isEmpty(str)) { f(); } this.M = a(str); invalidate(); } private void a(SuperControlView.MotionEventState motionEventState) { ActionWidgetData data; this.h0 = System.currentTimeMillis(); if (b()) { this.S = 0.0f; this.T = 0.0f; if (a(this.j)) { if (this.i != null && (data = getData()) != null) { this.i.a(this, data.getActionID()); this.i.c((View) this); } invalidate(); return; } if (this.i != null) { RectF rectF = this.H; PointF a = a(rectF.left, rectF.top); this.k.offsetTo(a.x, a.y); if (this.i.c((SuperControlView) this)) { b(this.o, this.p); this.b.setColor(this.B.getResources().getColor(this.a)); } else { b(a.x, a.y); this.i.a(this, this.j.centerX(), this.j.centerY()); } this.i.c((View) this); if (System.currentTimeMillis() - this.t < 300) { this.i.a(this, getData()); } } b(false); return; } float centerX = this.I.centerX(); float centerY = this.I.centerY(); RectF rectF2 = this.H; float f = this.l; float f2 = this.m; rectF2.set(centerX - (f / 2.0f), centerY - (f2 / 2.0f), centerX + (f / 2.0f), centerY + (f2 / 2.0f)); this.J.set(0.0f, 0.0f, 0.0f, 0.0f); this.P = this.R; int i = this.z; if (i != 0) { if (i != 2) { return; } setSelect(true); g(); return; } g(); ControlTouchEvent controlTouchEvent = this.i; if (controlTouchEvent != null) { controlTouchEvent.b((SuperControlView) this); this.i.a(getData(), motionEventState); } } public boolean a(RectF rectF) { RectF deleteViewRectF = getDeleteViewRectF(); if (deleteViewRectF == null) { return false; } return RectF.intersects(deleteViewRectF, rectF); } }