2011-07-07 66 views
0

在我的應用我有,我繪製canvas.and路徑也是我把所有的路徑爲ArrayList<Path>.
畫,我只是發送ArrayList<Path>另一個類之後的活動獲取XY座標在不同的畫布上繪製相同的路徑。機器人從路徑

於是就有的,而不是直接使用這條道路我想每個路徑轉換爲X,Y座標和我能夠得出所有的路徑。
我該怎麼做?我的代碼

一部分是低於,

private ArrayList<Path> _graphics = new ArrayList<Path>(); 
public boolean onTouchEvent(MotionEvent event) { 
     synchronized (_thread.getSurfaceHolder()) { 

      if (event.getAction() == MotionEvent.ACTION_DOWN) { 
       System.out.println("i'm in ACTION_DOWN "); 
       path = new Path(); 
       path.moveTo(event.getX(), event.getY()); 
       path.lineTo(event.getX(), event.getY()); 

      //_graphics.add(path); 


       path.addCircle(event.getX(), event.getY(), 2, 
         Path.Direction.CCW); 

      } 
      else if (event.getAction() == MotionEvent.ACTION_MOVE) { 

       System.out.println("i'm in ACTION_MOVE "); 
       path.lineTo(event.getX(), event.getY()); 
       path.moveTo(event.getX(), event.getY()); 
       _graphics.add(path); 

      } 
      else if (event.getAction() == MotionEvent.ACTION_UP) { 

       System.out.println("i'm in ACTION_UP "); 
       path.lineTo(event.getX(), event.getY()); 

      } 

      return true; 
      } 
    } 


    public void onDraw(Canvas canvas) { 
     canvas.drawColor(Color.WHITE); 
     if (onSelect == true) { 
      onSelect = false; 
      _graphics.clear(); 
     } 
     for (Path path : _graphics) { 
      canvas.drawPath(path, mPaint); 
      } 
     } 

_graphicsArrayList<Path>

另一個問題是我也想通過Socket通過這個Arraylist<path>,對於我有這個路徑轉換爲byte[]是否可以轉換爲字節[]?

謝謝

回答

1

我知道這不正是你尋找的,但這應該幫助。它會顯示x和y。

package com.mike.touch; 

import android.app.Activity; 
import android.os.Bundle; 
import android.view.MotionEvent; 
import android.widget.TextView; 

public class TouchActivity extends Activity { 
    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     TextView tv = new TextView(this); 
     tv.setText("touch screen"); 
     setContentView(tv); 
    } 
    @Override 
    public boolean onTouchEvent(MotionEvent event){ 
     TextView tv = new TextView(this); 
     tv.setText("x="+event.getX()+"  y="+event.getY()); 
     setContentView(tv); 

     return super.onTouchEvent(event); 
    } 
}