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.PointF; import android.graphics.Rect; import android.graphics.RectF; import android.view.MotionEvent; import android.view.View; import com.ubt.jimu.R; import com.ubt.jimu.controller.data.config.HSliderConfig; import com.ubt.jimu.controller.data.widget.HSliderWidgetData; import com.ubt.jimu.controller.manager.CommandSendManager; import com.ubt.jimu.controller.view.control.ControlTouchEvent; import com.ubt.jimu.controller.view.control.SuperControlView; import com.ubt.jimu.utils.SystemUtils; /* loaded from: classes.dex */ public class HSliderView extends SuperControlView { private Context B; private float C; private float D; private float E; private float F; private float G; private float H; private RectF I; private RectF J; private Paint K; private Bitmap L; private Bitmap M; private float N; private CommandSendManager O; private float P; private float Q; private float R; private float S; public HSliderView(Context context, float f, float f2) { super(context); this.C = 0.0f; this.D = 0.0f; System.currentTimeMillis(); this.B = context; this.C = f; this.D = f2; g(); f(); } private void a(float f, float f2, float f3) { this.O.a(((this.J.centerX() - f3) / (f2 - f)) * 100.0f * 2.0f); this.O.a((CommandSendManager) getData()); } private void b(float f, float f2) { this.I.offsetTo(f, f2); this.j.offsetTo(f, f2); this.J.offsetTo(this.I.centerX() - (this.G / 2.0f), this.I.centerY() - (this.G / 2.0f)); } private void f() { this.L = BitmapFactory.decodeResource(this.B.getResources(), R.mipmap.rectangle_hslider); this.M = BitmapFactory.decodeResource(this.B.getResources(), R.mipmap.slider_ball); this.H = this.L.getWidth() / this.L.getHeight(); this.l = this.B.getResources().getDimension(R.dimen.grid_view_width) * 8.0f; this.m = this.l / this.H; 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.l; 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); } } float f7 = this.m; this.G = f7 / 1.8f; this.E = this.l / 2.0f; this.F = f7 / 2.0f; this.K = new Paint(); this.K.setFlags(3); float f8 = this.C; float f9 = this.l; float f10 = this.D; float f11 = this.m; this.I = new RectF(f8 - (f9 / 2.0f), f10 - (f11 / 2.0f), f8 + (f9 / 2.0f), f10 + (f11 / 2.0f)); float centerX = this.I.centerX(); float centerY = this.I.centerY(); float f12 = this.G; this.J = new RectF(centerX - (f12 / 2.0f), centerY - (f12 / 2.0f), centerX + (f12 / 2.0f), centerY + (f12 / 2.0f)); this.O = new CommandSendManager(); } private void g() { } private void h() { HSliderWidgetData data; HSliderConfig config; if (!b()) { this.O.b(); ControlTouchEvent controlTouchEvent = this.i; if (controlTouchEvent != null) { controlTouchEvent.b((SuperControlView) this); } } else { if (a(this.j)) { if (this.i != null && (data = getData()) != null && (config = data.getConfig()) != null) { this.i.a(this, config.getConfigID()); this.i.c((View) this); } invalidate(); return; } if (this.i != null) { RectF rectF = this.I; PointF a = a(rectF.left, rectF.top); this.k.offsetTo(a.x, a.y); if (this.i.c((SuperControlView) this)) { this.J.offsetTo(this.o + this.N, this.p); this.I.offsetTo(this.o, this.p); this.j.offsetTo(this.o, this.p); this.b.setColor(this.B.getResources().getColor(this.a)); } else { b(a.x, a.y); this.i.a(this, this.I.centerX(), this.I.centerY()); } this.i.c((View) this); if (System.currentTimeMillis() - this.t < 350) { this.i.a(this, getData()); } } b(false); } float centerX = this.I.centerX(); float centerY = this.I.centerY(); RectF rectF2 = this.J; float f = centerX + this.N; float f2 = this.G; rectF2.offsetTo(f - (f2 / 2.0f), centerY - (f2 / 2.0f)); invalidate(); } @Override // com.ubt.jimu.controller.view.control.SuperControlView public float[] getViewCenterXY() { return new float[]{this.I.centerX(), this.I.centerY()}; } @Override // com.ubt.jimu.controller.view.control.SuperControlView, android.view.View protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.drawBitmap(this.L, (Rect) null, this.I, this.K); canvas.drawBitmap(this.M, (Rect) null, this.J, this.K); } @Override // android.view.View public boolean onTouchEvent(MotionEvent motionEvent) { int action = motionEvent.getAction(); if (action == 0) { this.t = System.currentTimeMillis(); this.R = motionEvent.getX(); this.S = motionEvent.getY(); super.d(); this.f = false; if (!b()) { float centerX = this.J.centerX(); float centerY = this.J.centerY(); float f = this.G; float f2 = centerX - (f / 2.0f); float f3 = centerX + (f / 2.0f); float f4 = centerY - (f / 2.0f); float f5 = centerY + (f / 2.0f); float f6 = this.R; if (f6 >= f2 && f6 <= f3) { float f7 = this.S; if (f7 >= f4 && f7 <= f5) { ControlTouchEvent controlTouchEvent = this.i; if (controlTouchEvent != null) { controlTouchEvent.a((SuperControlView) this); } this.O.a(); } } return super.onTouchEvent(motionEvent); } float centerX2 = this.I.centerX(); float centerY2 = this.I.centerY(); float f8 = this.E; float f9 = centerX2 - f8; float f10 = centerX2 + f8; float f11 = this.F; float f12 = centerY2 - f11; float f13 = centerY2 + f11; float f14 = this.R; if (f14 >= f9 && f14 <= f10) { float f15 = this.S; if (f15 >= f12 && f15 <= f13) { this.P = super.a(f14); this.Q = super.b(this.S); bringToFront(); ControlTouchEvent controlTouchEvent2 = this.i; if (controlTouchEvent2 != null) { controlTouchEvent2.a((View) this); } } } return super.onTouchEvent(motionEvent); return true; } if (action == 1) { if (!this.f) { this.f = true; h(); } return false; } if (action != 2) { if (action != 3) { return super.onTouchEvent(motionEvent); } if (!this.f) { this.f = true; h(); } return true; } if (b()) { b(super.a(motionEvent, this.P), super.b(motionEvent, this.Q)); if (this.i != null) { float abs = Math.abs(motionEvent.getX() - this.R); float abs2 = Math.abs(motionEvent.getY() - this.S); if (abs <= 10.0f && abs2 <= 10.0f) { return true; } this.i.b((View) this); if (a(this.j)) { this.b.setColor(this.B.getResources().getColor(R.color.color_FF4979)); if (!this.n) { SystemUtils.b(this.B); this.n = true; } b(false); if (this.e != null && getData() != null) { String format = String.format(this.B.getResources().getString(R.string.control_remove_widget), getData().getWidgetInfo(this.B)); this.e.setOverlapState(true); this.e.a(format); } } else { if (this.e != null && getData() != null) { String format2 = String.format(this.B.getResources().getString(R.string.control_remove_widget_here), getData().getWidgetInfo(this.B)); this.e.setOverlapState(false); this.e.a(format2); } RectF rectF = this.I; PointF a = a(rectF.left, rectF.top); this.k.offsetTo(a.x, a.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; } } } else { float x = motionEvent.getX(); float centerX3 = this.I.centerX(); float centerY3 = this.I.centerY(); float f16 = this.E; float f17 = this.G; float f18 = (centerX3 - f16) + (f17 / 2.0f); float f19 = (centerX3 + f16) - (f17 / 2.0f); if (x < f18) { x = f18; } if (x > f19) { x = f19; } RectF rectF2 = this.J; float f20 = this.G; rectF2.offsetTo(x - (f20 / 2.0f), centerY3 - (f20 / 2.0f)); float centerX4 = this.I.centerX(); this.N = this.J.centerX() - centerX4; a(f18, f19, centerX4); } invalidate(); return true; } public void setHSliderViewCommandSendListener(CommandSendManager.HSliderViewCommandSendListener hSliderViewCommandSendListener) { this.O.a(hSliderViewCommandSendListener); } public void setStartX(float f) { this.C = f; } public void setStartY(float f) { this.D = f; } public void setViewHeight(float f) { this.m = f; this.l = f * this.H; this.E = this.l / 2.0f; this.F = this.m / 2.0f; } public void setViewWidth(float f) { this.l = f; this.m = f / this.H; this.E = f / 2.0f; this.F = this.m / 2.0f; } public boolean a(RectF rectF) { RectF deleteViewRectF = getDeleteViewRectF(); if (deleteViewRectF == null) { return false; } return RectF.intersects(deleteViewRectF, rectF); } }