336 lines
12 KiB
Java
336 lines
12 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.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.SliderConfig;
|
|
import com.ubt.jimu.controller.data.widget.SliderWidgetData;
|
|
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.LogUtils;
|
|
import com.ubt.jimu.utils.SystemUtils;
|
|
|
|
/* loaded from: classes.dex */
|
|
public class VSliderView extends SuperControlView<SliderWidgetData> {
|
|
private Paint B;
|
|
private Context C;
|
|
private Bitmap D;
|
|
private Bitmap E;
|
|
private RectF F;
|
|
private float G;
|
|
private float H;
|
|
private float I;
|
|
private RectF J;
|
|
private float K;
|
|
private float L;
|
|
private float M;
|
|
private long N;
|
|
private CommandSendManager O;
|
|
private float P;
|
|
private float Q;
|
|
private float R;
|
|
private float S;
|
|
|
|
public VSliderView(Context context, float f, float f2) {
|
|
super(context);
|
|
this.N = System.currentTimeMillis();
|
|
this.C = context;
|
|
this.G = f;
|
|
this.H = f2;
|
|
f();
|
|
h();
|
|
g();
|
|
this.O = new CommandSendManager();
|
|
}
|
|
|
|
private void b(float f, float f2) {
|
|
this.F.offsetTo(f, f2);
|
|
this.j.offsetTo(f, f2);
|
|
this.J.offsetTo(this.F.centerX() - (this.I / 2.0f), this.F.centerY() - (this.I / 2.0f));
|
|
}
|
|
|
|
private void f() {
|
|
this.B = new Paint();
|
|
this.B.setFlags(3);
|
|
}
|
|
|
|
private void g() {
|
|
this.m = this.C.getResources().getDimension(R.dimen.grid_view_width) * 8.0f;
|
|
this.D.getWidth();
|
|
this.D.getHeight();
|
|
float f = this.m;
|
|
this.l = f / 2.0f;
|
|
this.K = this.l / 2.0f;
|
|
this.L = f / 2.0f;
|
|
this.I = this.C.getResources().getDimension(R.dimen.controlBallWidthOrHeight);
|
|
float f2 = this.H;
|
|
float f3 = this.m;
|
|
float f4 = f2 + (f3 / 2.0f);
|
|
int i = this.s;
|
|
if (f4 >= i) {
|
|
this.H = i - (f3 / 2.0f);
|
|
}
|
|
float f5 = this.G;
|
|
float f6 = this.l;
|
|
if (f5 - (f6 / 2.0f) <= 0.0f) {
|
|
this.G = f6 / 2.0f;
|
|
} else {
|
|
float f7 = f5 + (f6 / 2.0f);
|
|
int i2 = this.r;
|
|
if (f7 >= i2) {
|
|
this.G = i2 - (f6 / 2.0f);
|
|
}
|
|
}
|
|
float f8 = this.G;
|
|
float f9 = this.l;
|
|
float f10 = this.H;
|
|
float f11 = this.m;
|
|
this.F = new RectF(f8 - (f9 / 2.0f), f10 - (f11 / 2.0f), (f9 / 2.0f) + f8, (f11 / 2.0f) + f10);
|
|
float centerX = this.F.centerX();
|
|
float centerY = this.F.centerY();
|
|
float f12 = this.I;
|
|
this.J = new RectF(centerX - (f12 / 2.0f), centerY - (f12 / 2.0f), centerX + (f12 / 2.0f), centerY + (f12 / 2.0f));
|
|
}
|
|
|
|
private void h() {
|
|
this.D = BitmapFactory.decodeResource(this.C.getResources(), R.mipmap.bg_v_slider);
|
|
this.E = BitmapFactory.decodeResource(this.C.getResources(), R.mipmap.slider_ball);
|
|
}
|
|
|
|
public boolean a(RectF rectF) {
|
|
RectF deleteViewRectF = getDeleteViewRectF();
|
|
if (deleteViewRectF == null) {
|
|
return false;
|
|
}
|
|
return RectF.intersects(deleteViewRectF, rectF);
|
|
}
|
|
|
|
@Override // com.ubt.jimu.controller.view.control.SuperControlView
|
|
public float[] getViewCenterXY() {
|
|
return new float[]{this.F.centerX(), this.F.centerY()};
|
|
}
|
|
|
|
@Override // com.ubt.jimu.controller.view.control.SuperControlView, android.view.View
|
|
protected void onDraw(Canvas canvas) {
|
|
super.onDraw(canvas);
|
|
canvas.drawBitmap(this.D, (Rect) null, this.F, this.B);
|
|
canvas.drawBitmap(this.E, (Rect) null, this.J, this.B);
|
|
}
|
|
|
|
@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.I;
|
|
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) {
|
|
this.O.a((CommandSendManager) getData());
|
|
this.O.a();
|
|
ControlTouchEvent controlTouchEvent = this.i;
|
|
if (controlTouchEvent != null) {
|
|
controlTouchEvent.a((SuperControlView) this);
|
|
}
|
|
}
|
|
}
|
|
return super.onTouchEvent(motionEvent);
|
|
}
|
|
float centerX2 = this.F.centerX();
|
|
float centerY2 = this.F.centerY();
|
|
float f8 = this.K;
|
|
float f9 = centerX2 - f8;
|
|
float f10 = centerX2 + f8;
|
|
float f11 = this.L;
|
|
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;
|
|
b(motionEvent);
|
|
}
|
|
return true;
|
|
}
|
|
if (action != 2) {
|
|
if (action == 3 && !this.f) {
|
|
this.f = true;
|
|
b(motionEvent);
|
|
}
|
|
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)) {
|
|
b(false);
|
|
if (this.e != null && getData() != null) {
|
|
this.e.setOverlapState(true);
|
|
this.e.a(String.format(this.C.getResources().getString(R.string.control_remove_widget), getData().getWidgetInfo(this.C)));
|
|
}
|
|
this.b.setColor(this.C.getResources().getColor(R.color.color_FF4979));
|
|
if (!this.n) {
|
|
SystemUtils.b(this.C);
|
|
this.n = true;
|
|
}
|
|
} else {
|
|
if (this.e != null && getData() != null) {
|
|
this.e.setOverlapState(false);
|
|
this.e.a(String.format(this.C.getResources().getString(R.string.control_remove_widget_here), getData().getWidgetInfo(this.C)));
|
|
}
|
|
RectF rectF = this.F;
|
|
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.C.getResources().getColor(R.color.bg_99B8BEC1));
|
|
} else {
|
|
b(true);
|
|
this.b.setColor(this.C.getResources().getColor(this.a));
|
|
}
|
|
this.n = false;
|
|
}
|
|
}
|
|
} else {
|
|
float y = motionEvent.getY();
|
|
float centerX3 = this.F.centerX();
|
|
float centerY3 = this.F.centerY();
|
|
float f16 = this.L;
|
|
float f17 = this.I;
|
|
float f18 = (centerY3 - f16) + (f17 / 2.0f);
|
|
float f19 = (centerY3 + f16) - (f17 / 2.0f);
|
|
if (y < f18) {
|
|
y = f18;
|
|
}
|
|
if (y > f19) {
|
|
y = f19;
|
|
}
|
|
RectF rectF2 = this.J;
|
|
float f20 = this.I;
|
|
rectF2.offsetTo(centerX3 - (f20 / 2.0f), y - (f20 / 2.0f));
|
|
this.M = this.J.centerX() - this.F.centerX();
|
|
if (System.currentTimeMillis() - this.N > 200) {
|
|
this.N = System.currentTimeMillis();
|
|
}
|
|
a(motionEvent);
|
|
}
|
|
invalidate();
|
|
return true;
|
|
}
|
|
|
|
public void setUpdateCommandParameterListener(CommandSendManager.VSliderViewCommandSendListener vSliderViewCommandSendListener) {
|
|
this.O.a(vSliderViewCommandSendListener);
|
|
}
|
|
|
|
public void a(MotionEvent motionEvent) {
|
|
float[] viewCenterXY = getViewCenterXY();
|
|
if (viewCenterXY == null || viewCenterXY.length < 2) {
|
|
return;
|
|
}
|
|
float y = motionEvent.getY() - viewCenterXY[1];
|
|
float f = viewCenterXY[1];
|
|
float f2 = this.L;
|
|
float f3 = this.I;
|
|
float f4 = (((viewCenterXY[1] + f2) - (f3 / 2.0f)) - ((f - f2) + (f3 / 2.0f))) / 2.0f;
|
|
float f5 = -f4;
|
|
if (y <= f5) {
|
|
y = f5;
|
|
} else if (y >= f4) {
|
|
y = f4;
|
|
}
|
|
this.O.a(-((y / f4) * 100.0f));
|
|
if (motionEvent.getAction() == 1 || motionEvent.getAction() == 3) {
|
|
this.O.b();
|
|
}
|
|
}
|
|
|
|
private void b(MotionEvent motionEvent) {
|
|
SliderWidgetData data;
|
|
SliderConfig config;
|
|
if (b()) {
|
|
boolean a = a(this.j);
|
|
LogUtils.c("isDelete:");
|
|
if (a) {
|
|
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.F;
|
|
PointF a2 = a(rectF.left, rectF.top);
|
|
this.k.offsetTo(a2.x, a2.y);
|
|
if (this.i.c((SuperControlView) this)) {
|
|
b(this.o, this.p);
|
|
this.b.setColor(this.C.getResources().getColor(this.a));
|
|
} else {
|
|
b(a2.x, a2.y);
|
|
this.i.a(this, this.F.centerX(), this.F.centerY());
|
|
}
|
|
this.i.c((View) this);
|
|
if (System.currentTimeMillis() - this.t < 350) {
|
|
this.i.a(this, getData());
|
|
}
|
|
}
|
|
b(false);
|
|
} else {
|
|
ControlTouchEvent controlTouchEvent = this.i;
|
|
if (controlTouchEvent != null) {
|
|
controlTouchEvent.b((SuperControlView) this);
|
|
}
|
|
float centerX = this.F.centerX();
|
|
float centerY = this.F.centerY();
|
|
RectF rectF2 = this.J;
|
|
float f = centerX + this.M;
|
|
float f2 = this.I;
|
|
rectF2.offsetTo(f - (f2 / 2.0f), centerY - (f2 / 2.0f));
|
|
a(motionEvent);
|
|
}
|
|
invalidate();
|
|
}
|
|
}
|