我的情况很简单。我有一个移动穿戴应用程序。我的移动应用程序是“绘图”应用程序。它连接到具有磁性铅笔的硬件。在硬件上绘图会向我的应用程序发送三个功能-touchStart,touchMove,touchStop。我可以以合理的速度在移动应用程序上绘制路径。但是,如果我通过SendMessage将这3次触摸检测发送到我的手表,则图像绘制缓慢。我正在尝试加快速度,以便像移动设备一样实时绘制图形。
这是我的手表应用程序的Paint类的代码:
class SimpleDrawingView extends View {
// setup initial color
private final int paintColor = Color.WHITE;
// defines paint and canvas
private Paint drawPaint;
// Store circles to draw each time the user touches down
public int xwidth, xheight;
private Path bPath = new Path();
private Path path = new Path();
public SimpleDrawingView(Context context, AttributeSet attrs) {
super(context, attrs);
setFocusable(true);
setFocusableInTouchMode(true);
setupPaint();
}
public Path redraw() {
Matrix m = new Matrix();
RectF innerBounds = new RectF();
bPath = new Path(path);
bPath.computeBounds(innerBounds, true);
int width = getWidth();
int height = getHeight();
RectF intoBounds = new RectF(0, 0, width, height);
m.setRectToRect(innerBounds, intoBounds, Matrix.ScaleToFit.CENTER);
bPath.transform(m);
return bPath;
}
// Draw each circle onto the view
@Override
protected void onDraw(Canvas canvas) {
Log.d("MEx", " drawing ");
redraw();
canvas.drawPath(path, drawPaint);
}
public void actionDown(Point a)
{
path.moveTo(a.x, a.y);
invalidate();
}
public void clear()
{
path.reset();
invalidate();
}
public void actionEnd(Point a)
{
// path.lineTo(a.x, a.y);
}
public void actionMove(Point a)
{
path.lineTo(a.x, a.y);
invalidate();
}
// Append new circle each time user presses on screen
private void setupPaint() {
// Setup paint with color and stroke styles
drawPaint = new Paint();
drawPaint.setColor(paintColor);
drawPaint.setAntiAlias(true);
drawPaint.setStrokeWidth(23);
drawPaint.setStyle(Paint.Style.STROKE);
drawPaint.setStrokeJoin(Paint.Join.ROUND);
drawPaint.setStrokeCap(Paint.Cap.ROUND);
}
}
这是我的邮件接收者:
public class Receiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
for(String s : intent.getExtras().keySet()) {
String first = intent.getExtras().get(s).toString();
String label, x, y;
if (first.contains("charge+")) {
textLabel.setText(first.split("7")[1]);
} else if (first.contains("battery+")) {
String color = first.substring(8);
Log.d("TESTTWO", color + " <- ");
switch(color)
{
case "RED":
dotView.setImageResource(R.drawable.red);
textLabel.setText("");
break;
case "GREEN":
dotView.setImageResource(R.drawable.green);
textLabel.setTextColor(Color.GREEN);
break;
case "YELLOW":
textLabel.setTextColor(Color.YELLOW);
dotView.setImageResource(R.drawable.yellow);
break;
}
} else {
label = first.substring(0, 1);
String[] toSplit;
toSplit = first.substring(2).split(",");
Point point = new Point(Integer.parseInt(toSplit[0]), Integer.parseInt(toSplit[1]));
switch (label) {
case "S":
imageView.actionDown(point);
break;
case "M":
imageView.actionMove(point);
break;
case "E":
imageView.actionEnd(point);
break;
}
}
}
}
}
点以以下任一格式发送到我的手表
S-x,y √ E-x,y
S =开始,M =移动,E =结束。
如果有人可以帮助我优化此功能,那就太好了!
我也尝试将数据作为资产发送,这甚至更慢。