简体   繁体   中英

how to create a node by touch in android studio with api Graphstream?

I'm trying to get it when I click on the screen to create a node, but through Viwerpipe the only thing I could do was delete a node that was already created.

    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) {
    }
}

I searched in many places but I did not find how to use the touch screen to do this, I usually found this link that said it was useful but I could not understand: I searched in many places but I did not find how to use the touch screen to do this, I usually found this link that said it was useful but I could not understand:https://github.com/graphstream/gs-ui-android-test/tree/master/app/src/main/java/ui/graphstream/org/gs_ui_androidtestFull

您应该能够使用DefaultView类的addListener()方法替换onTouchListener。

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM