我有一个颜色选择器调色板类,我希望在客户端通过单独的java文件中的蓝牙类更改颜色(OnTouch)时发送颜色信息。蓝牙片段正在完美地工作和连接。问题是write方法在它的类中工作,但是当我初始化它并尝试在调色板类中使用它时,它会在测试中崩溃。 蓝牙类中的工作write()方法:
BluetoothFragment rat = new BluetoothFragment();
public boolean onTouchEvent(MotionEvent event) {
int action = event.getAction();
switch (action) {
case MotionEvent.ACTION_DOWN:
case MotionEvent.ACTION_MOVE:
int x = (int) event.getX();
int y = (int) event.getY();
int cx = x - getWidth() / 2;
int cy = y - getHeight() / 2;
double d = Math.sqrt(cx * cx + cy * cy);
if (d <= colorWheelRadius) {
colorHSV[0] = (float) (Math.toDegrees(Math.atan2(cy, cx)) + 180f);
colorHSV[1] = Math.max(0f, Math.min(1f, (float) (d / colorWheelRadius)));
invalidate();
} else if (x >= getWidth() / 2 && d >= innerWheelRadius) {
colorHSV[2] = (float) Math.max(0, Math.min(1, Math.atan2(cy, cx) / Math.PI + 0.5f));
invalidate();
}
return true;
}
rat.write(getColor());
return super.onTouchEvent(event);
}
我试图在调色板类(ColorPicker.java)中使用该方法:
mvn dependency:tree