389 lines
14 KiB
Java
389 lines
14 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.util.Log;
|
||
import android.view.MotionEvent;
|
||
import android.view.View;
|
||
import com.ubt.jimu.R;
|
||
import com.ubt.jimu.controller.data.config.JockstickConfig;
|
||
import com.ubt.jimu.controller.data.widget.JockstickData;
|
||
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.LogUtils;
|
||
import com.ubt.jimu.utils.SystemUtils;
|
||
|
||
/* loaded from: classes.dex */
|
||
public class SteeringWheelView extends SuperControlView<JockstickData> {
|
||
private OnSlideListener B;
|
||
private float C;
|
||
private float D;
|
||
private Context E;
|
||
private int F;
|
||
private float G;
|
||
private float H;
|
||
private float I;
|
||
private Paint J;
|
||
private RectF K;
|
||
private RectF L;
|
||
private Paint M;
|
||
private Bitmap N;
|
||
private Bitmap O;
|
||
private float P;
|
||
private long Q;
|
||
private float R;
|
||
private float S;
|
||
private float T;
|
||
private float U;
|
||
|
||
public interface OnSlideListener {
|
||
void a(float f, float f2, float f3, JockstickData jockstickData);
|
||
|
||
void a(JockstickData jockstickData);
|
||
|
||
void a(JockstickData jockstickData, SuperControlView.MotionEventState motionEventState);
|
||
}
|
||
|
||
public SteeringWheelView(Context context, float f, float f2) {
|
||
super(context);
|
||
this.F = R.color.color_4D00C4C9;
|
||
this.H = 0.0f;
|
||
this.I = 0.0f;
|
||
this.Q = System.currentTimeMillis();
|
||
this.E = context;
|
||
this.H = f;
|
||
this.I = f2;
|
||
h();
|
||
g();
|
||
}
|
||
|
||
private void a(SuperControlView.MotionEventState motionEventState) {
|
||
JockstickConfig config;
|
||
if (b()) {
|
||
this.R = 0.0f;
|
||
this.S = 0.0f;
|
||
if (a(this.j) && this.i != null && (config = getData().getConfig()) != null) {
|
||
this.i.a(this, config.getConfigID());
|
||
}
|
||
if (this.i != null) {
|
||
RectF rectF = this.K;
|
||
PointF a = a(rectF.left, rectF.top);
|
||
this.k.offsetTo(a.x, a.y);
|
||
boolean c = this.i.c((SuperControlView) this);
|
||
Log.e("Test", "isOverlap:" + c);
|
||
if (c) {
|
||
b(this.o, this.p);
|
||
this.b.setColor(this.E.getResources().getColor(this.F));
|
||
} else {
|
||
b(a.x, a.y);
|
||
this.i.a(this, this.K.centerX(), this.K.centerY());
|
||
}
|
||
this.i.c((View) this);
|
||
if (System.currentTimeMillis() - this.t < 350) {
|
||
this.i.a(this, getData());
|
||
}
|
||
}
|
||
b(false);
|
||
} else {
|
||
float centerX = this.K.centerX();
|
||
float centerY = this.K.centerY();
|
||
float f = this.G;
|
||
this.L.offsetTo(centerX - (f / 2.0f), centerY - (f / 2.0f));
|
||
int state = getState();
|
||
if (state == 0) {
|
||
b(motionEventState);
|
||
} else if (state == 2) {
|
||
setSelect(true);
|
||
this.b.setColor(this.E.getResources().getColor(this.F));
|
||
f();
|
||
}
|
||
ControlTouchEvent controlTouchEvent = this.i;
|
||
if (controlTouchEvent != null) {
|
||
controlTouchEvent.b((SuperControlView) this);
|
||
}
|
||
}
|
||
invalidate();
|
||
}
|
||
|
||
private void b(SuperControlView.MotionEventState motionEventState) {
|
||
OnSlideListener onSlideListener = this.B;
|
||
if (onSlideListener != null) {
|
||
onSlideListener.a(getData(), motionEventState);
|
||
}
|
||
}
|
||
|
||
private void c(float f, float f2) {
|
||
double d;
|
||
double d2;
|
||
OnSlideListener onSlideListener;
|
||
float centerX = this.K.centerX();
|
||
float centerY = this.K.centerY();
|
||
double d3 = f - centerX;
|
||
double d4 = centerY - f2;
|
||
double sqrt = Math.sqrt((d3 * d3) + (d4 * d4));
|
||
float f3 = this.P;
|
||
if (sqrt > f3) {
|
||
double d5 = ((f3 / sqrt) * d3) + centerX;
|
||
float f4 = this.G;
|
||
d = d5 - (f4 / 2.0f);
|
||
d2 = (((f3 / sqrt) * (f2 - centerY)) + centerY) - (f4 / 2.0f);
|
||
} else {
|
||
float f5 = this.G;
|
||
d = f - (f5 / 2.0f);
|
||
d2 = f2 - (f5 / 2.0f);
|
||
}
|
||
this.L.offsetTo((float) d, (float) d2);
|
||
if (getState() == 0) {
|
||
boolean z = Math.abs(d3 - ((double) this.T)) < ((double) getMinXOffset()) || Math.abs(d4 - ((double) this.U)) < ((double) getMinYOffset());
|
||
if ((System.currentTimeMillis() - this.Q > 200 || z) && (onSlideListener = this.B) != null) {
|
||
onSlideListener.a((float) d3, (float) d4, this.P, getData());
|
||
this.Q = System.currentTimeMillis();
|
||
}
|
||
}
|
||
}
|
||
|
||
private void f() {
|
||
OnControllerClickListener onControllerClickListener = getOnControllerClickListener();
|
||
if (onControllerClickListener == null) {
|
||
return;
|
||
}
|
||
onControllerClickListener.a(null, this);
|
||
}
|
||
|
||
private void g() {
|
||
this.l = this.E.getResources().getDimension(R.dimen.grid_view_width) * 8.0f;
|
||
this.m = this.l;
|
||
float f = this.I;
|
||
float f2 = this.m;
|
||
float f3 = f + (f2 / 2.0f);
|
||
int i = this.s;
|
||
if (f3 >= i) {
|
||
this.I = i - (f2 / 2.0f);
|
||
}
|
||
float f4 = this.H;
|
||
float f5 = this.m;
|
||
if (f4 - (f5 / 2.0f) <= 0.0f) {
|
||
this.H = f5 / 2.0f;
|
||
} else {
|
||
float f6 = f4 + (f5 / 2.0f);
|
||
int i2 = this.r;
|
||
if (f6 >= i2) {
|
||
this.H = i2 - (f5 / 2.0f);
|
||
}
|
||
}
|
||
this.G = this.E.getResources().getDimension(R.dimen.wheel_control_ball);
|
||
this.J = new Paint();
|
||
this.J.setFlags(3);
|
||
float f7 = this.H;
|
||
float f8 = this.l;
|
||
float f9 = this.I;
|
||
float f10 = this.m;
|
||
this.K = new RectF(f7 - (f8 / 2.0f), f9 - (f10 / 2.0f), f7 + (f8 / 2.0f), f9 + (f10 / 2.0f));
|
||
this.M = new Paint();
|
||
this.M.setAntiAlias(true);
|
||
this.M.setFilterBitmap(true);
|
||
this.N = BitmapFactory.decodeResource(this.E.getResources(), R.mipmap.jockstick);
|
||
this.O = BitmapFactory.decodeResource(this.E.getResources(), R.mipmap.steering_wheel_thumb);
|
||
float centerX = this.K.centerX();
|
||
float centerY = this.K.centerY();
|
||
float f11 = this.G;
|
||
this.L = new RectF(centerX - (f11 / 2.0f), centerY - (f11 / 2.0f), centerX + (f11 / 2.0f), centerY + (f11 / 2.0f));
|
||
this.P = this.l / 2.0f;
|
||
}
|
||
|
||
private float getMinXOffset() {
|
||
return this.l / 20.0f;
|
||
}
|
||
|
||
private float getMinYOffset() {
|
||
return this.l / 20.0f;
|
||
}
|
||
|
||
private void h() {
|
||
}
|
||
|
||
@Override // com.ubt.jimu.controller.view.control.SuperControlView
|
||
public float[] getViewCenterXY() {
|
||
return new float[]{this.K.centerX(), this.K.centerY()};
|
||
}
|
||
|
||
@Override // com.ubt.jimu.controller.view.control.SuperControlView, android.view.View
|
||
protected void onDraw(Canvas canvas) {
|
||
if (getState() == 2) {
|
||
if (c()) {
|
||
e();
|
||
} else {
|
||
a();
|
||
}
|
||
}
|
||
super.onDraw(canvas);
|
||
canvas.drawBitmap(this.N, (Rect) null, this.K, this.M);
|
||
canvas.drawBitmap(this.O, (Rect) null, this.L, this.M);
|
||
}
|
||
|
||
@Override // android.view.View
|
||
public boolean onTouchEvent(MotionEvent motionEvent) {
|
||
OnSlideListener onSlideListener;
|
||
int action = motionEvent.getAction();
|
||
if (action == 0) {
|
||
LogUtils.c("MotionEvent.ACTION_DOWN:");
|
||
this.t = System.currentTimeMillis();
|
||
this.C = motionEvent.getX();
|
||
this.D = motionEvent.getY();
|
||
super.d();
|
||
this.f = false;
|
||
setPressed(true);
|
||
if (!b()) {
|
||
float centerX = this.K.centerX();
|
||
float centerY = this.K.centerY();
|
||
float f = this.C;
|
||
float f2 = this.l;
|
||
if (f >= centerX - (f2 / 2.0f)) {
|
||
float f3 = this.D;
|
||
if (f3 >= centerY - (f2 / 2.0f) && f <= centerX + (f2 / 2.0f) && f3 <= centerY + (f2 / 2.0f)) {
|
||
ControlTouchEvent controlTouchEvent = this.i;
|
||
if (controlTouchEvent != null) {
|
||
controlTouchEvent.a((SuperControlView) this);
|
||
}
|
||
if (getState() == 0 && (onSlideListener = this.B) != null) {
|
||
onSlideListener.a(getData());
|
||
}
|
||
}
|
||
}
|
||
return super.onTouchEvent(motionEvent);
|
||
}
|
||
float centerX2 = this.K.centerX();
|
||
float centerY2 = this.K.centerY();
|
||
float f4 = this.l;
|
||
float f5 = centerX2 - (f4 / 2.0f);
|
||
float f6 = this.m;
|
||
float f7 = centerY2 - (f6 / 2.0f);
|
||
float f8 = centerX2 + (f4 / 2.0f);
|
||
float f9 = centerY2 + (f6 / 2.0f);
|
||
float f10 = this.C;
|
||
if (f10 >= f5 && f10 <= f8) {
|
||
float f11 = this.D;
|
||
if (f11 >= f7 && f11 <= f9) {
|
||
this.R = super.a(f10);
|
||
this.S = super.b(this.D);
|
||
bringToFront();
|
||
ControlTouchEvent controlTouchEvent2 = this.i;
|
||
if (controlTouchEvent2 != null) {
|
||
controlTouchEvent2.a((View) this);
|
||
}
|
||
invalidate();
|
||
}
|
||
}
|
||
return super.onTouchEvent(motionEvent);
|
||
}
|
||
if (action == 1) {
|
||
setPressed(false);
|
||
if (!this.f) {
|
||
this.f = true;
|
||
a(SuperControlView.MotionEventState.STATE_UP);
|
||
LogUtils.c("方向盘:ACTION_UP");
|
||
}
|
||
return true;
|
||
}
|
||
if (action != 2) {
|
||
if (action != 3) {
|
||
return super.onTouchEvent(motionEvent);
|
||
}
|
||
if (!this.f) {
|
||
LogUtils.c("方向盘:ACTION_CANCEL");
|
||
this.f = true;
|
||
a(SuperControlView.MotionEventState.STATE_CANCEL);
|
||
}
|
||
return true;
|
||
}
|
||
setPressed(true);
|
||
this.f = false;
|
||
LogUtils.c("MotionEvent.ACTION_MOVE:");
|
||
if (b()) {
|
||
a(motionEvent);
|
||
if (this.i != null) {
|
||
float abs = Math.abs(motionEvent.getX() - this.C);
|
||
float abs2 = Math.abs(motionEvent.getY() - this.D);
|
||
if (abs <= 10.0f && abs2 <= 10.0f) {
|
||
return true;
|
||
}
|
||
this.i.b((View) this);
|
||
if (a(this.j)) {
|
||
b(false);
|
||
this.b.setColor(this.E.getResources().getColor(R.color.color_FF4979));
|
||
if (this.e != null && getData() != null) {
|
||
this.e.setOverlapState(true);
|
||
this.e.a(String.format(this.E.getResources().getString(R.string.control_remove_widget), getData().getWidgetInfo(this.E)));
|
||
}
|
||
if (!this.n) {
|
||
SystemUtils.b(this.E);
|
||
this.n = true;
|
||
}
|
||
} else {
|
||
if (this.e != null && getData() != null) {
|
||
this.e.setOverlapState(false);
|
||
this.e.a(String.format(this.E.getResources().getString(R.string.control_remove_widget_here), getData().getWidgetInfo(this.E)));
|
||
}
|
||
RectF rectF = this.K;
|
||
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.E.getResources().getColor(R.color.bg_99B8BEC1));
|
||
} else {
|
||
b(true);
|
||
this.b.setColor(this.E.getResources().getColor(this.F));
|
||
}
|
||
this.n = false;
|
||
}
|
||
}
|
||
} else {
|
||
c(motionEvent.getX(), motionEvent.getY());
|
||
}
|
||
invalidate();
|
||
return true;
|
||
}
|
||
|
||
public void setOnSlideListener(OnSlideListener onSlideListener) {
|
||
this.B = onSlideListener;
|
||
}
|
||
|
||
@Override // com.ubt.jimu.controller.view.control.SuperControlView
|
||
public void setSelect(boolean z) {
|
||
super.setSelect(z);
|
||
}
|
||
|
||
public void setSteeringWheelBackgroundStartX(float f) {
|
||
this.H = f;
|
||
}
|
||
|
||
public void setSteeringWheelBackgroundStartY(float f) {
|
||
this.I = f;
|
||
}
|
||
|
||
private void b(float f, float f2) {
|
||
this.K.offsetTo(f, f2);
|
||
this.j.offsetTo(f, f2);
|
||
this.L.offsetTo(this.K.centerX() - (this.G / 2.0f), this.K.centerY() - (this.G / 2.0f));
|
||
}
|
||
|
||
private void a(MotionEvent motionEvent) {
|
||
b(super.a(motionEvent, this.R), super.b(motionEvent, this.S));
|
||
}
|
||
|
||
public boolean a(RectF rectF) {
|
||
RectF deleteViewRectF = getDeleteViewRectF();
|
||
if (deleteViewRectF == null) {
|
||
return false;
|
||
}
|
||
return RectF.intersects(deleteViewRectF, rectF);
|
||
}
|
||
}
|