如何使用api Graphstream在Android Studio中通过触摸创建节点?

时间:2019-03-23 20:11:31

标签: java android graphstream

当我在屏幕上单击以创建节点时,我正在尝试获取它,但是通过Viwerpipe,我唯一能做的就是删除已经创建的节点。

    public class Activity_TestManySprite extends Activity implements ViewerListener {

    private static final int CONTENT_VIEW_ID = 10101010;
    private DefaultFragment fragment ;
    private Graph graph ;
    protected boolean loop = true;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        FrameLayout frame = new FrameLayout(this);
        frame.setId(CONTENT_VIEW_ID);
        setContentView(frame, new FrameLayout.LayoutParams(
        FrameLayout.LayoutParams.MATCH_PARENT, 
        FrameLayout.LayoutParams.MATCH_PARENT));

        graph = new MultiGraph("TestSize");
        graph.setAttribute("ui.antialias");

        display(savedInstanceState, graph, true);
    }

    @Override
    protected void onStart() {
        super.onStart();

        ViewerPipe pipe = fragment.getViewer().newViewerPipe();

        pipe.addAttributeSink( graph );
        pipe.addViewerListener( this );
        pipe.pump();

        graph.setAttribute( "ui.stylesheet", styleSheet );
        graph.setAttribute( "ui.antialias" );
    }

    public void display(Bundle savedInstanceState, Graph graph, boolean autoLayout) {
        if (savedInstanceState == null) {
        FragmentManager fm = getFragmentManager();

        fragment = (DefaultFragment)fm.findFragmentByTag("fragment_tag");
        if (null == fragment) {
        fragment = new DefaultFragment();
        fragment.init(graph, autoLayout);
        }

        FragmentTransaction ft = fm.beginTransaction() ;
        ft.add(CONTENT_VIEW_ID, fragment).commit();
        }
    }

    public void buttonPushed( String id ) {
        graph.removeNode(id);
    }

    public void buttonReleased(String id) {
    }    

    public void mouseOver(String id) {
    }

    public void mouseLeft(String id) {
    }

    public void viewClosed(String viewName) {
    }
}

我在很多地方搜索过,但是我找不到如何使用触摸屏执行此操作的过程,通常我会发现该链接说它很有用,但我听不懂:我在很多地方搜索过,但是找不到要使用触摸屏执行此操作,通常会发现此链接说它有用,但我无法理解:https://github.com/graphstream/gs-ui-android-test/tree/master/app/src / main / java / ui / graphstream / org / gs_ui_androidtestFull

1 个答案:

答案 0 :(得分:0)

您应该可以用DefaultView类的addListener()方法自己替换onTouchListener。

fragment.getViewer().getDefaultView().addListener("OnTouchListener", myListener);