2

最初の電話のユーザーが描いた絵を2番目の電話が描くことができるように、ある電話から別の電話に送信する必要があるパスの配列リストがあります。これで、ある電話から別の電話に文字列メッセージを送信できる関数ができました。パスを文字列に変換し、必要なすべてのデータを取得して他の電話で再作成するにはどうすればよいですか?

4

1 に答える 1

3

DrawEntities (描画するオブジェクト) の配列リストを gson として送信し、それを処理します。

 ArrayList<DrawEntity> pathsToDraw = paintv.getPaths();
                Gson gson = new Gson();
                String json = gson.toJson(pathsToDraw);

パスを取得するために、ペイント ビューで、すべての MOVE モーション イベントでパスの座標の X と Y を保存します。

  private void touch_move(float x, float y) {
    LogService.log(TAG, "touchmove" + y);
    xlist.add(x);
    ylist.add(y);
    float dx, dy;
    dx = Math.abs(x - mX);
    dy = Math.abs(y - mY);
    if ((dx >= 20) || (dy >= 20)) {
        hasmoved = true;
    }
    if (mPath == null) {
        mPath = new Path();
        mPath.moveTo(x, y);
    }
    if ((dx >= TOUCH_TOLERANCE) || (dy >= TOUCH_TOLERANCE)) {
        mPath.quadTo(mX, mY, (x + mX) / 2, (y + mY) / 2);
        mX = x;
        mY = y;
    }
    LogService.log(TAG, "touchmove" + ylist.size());
}

 private void touch_up() {
    LogService.log(TAG, "touch up");
    mPath.lineTo(mX, mY);
    mPath.moveTo(mX, mY);
    DrawEntity draw = new DrawEntity(mPath, paint, stroke, xlist, ylist);
    draw.color = paint.getColor();
    if (hasmoved) {
        pathsToDraw.add(draw);
    }
    LogService.log(TAG, "touch up SIZE: " + pathsToDraw.size());
    xlist = null;
    ylist = null;
}

ご覧のとおり、コンストラクターでこれら 2 つのリスト (x、y) を含む DrawEntity (送信します) を作成します。

于 2013-09-24T09:19:32.567 に答える