0

I am a beginner in Android development. I am trying to study the use of Graphstream (https://graphstream-project.org) in an android app. I have created a basic activity with a drawer layout which includes a navigationview and frame layout where I intend to display the graph.
I have tried to use the code samples from here - https://github.com/graphstream/gs-ui-android-test/blob/master/app/src/main/java/ui/graphstream/org/gs_ui_androidtest/Activity_withXML.java

This is my code:-

public class MainActivity extends AppCompatActivity {



@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    ...
    Graph graph = new SingleGraph("Tutorial 1");

    graph.setAttribute("ui.stylesheet", "" +
            "graph { padding: 0px; fill-color: #EEE; }"+
            "edge { text-size: 48; size: 5;}"+
            "node { text-size: 48; fill-color: white; size: 40px, 40px; padding: 15px, 15px; stroke-mode: plain; stroke-color: #555; shape: box; }"
            + "node#B {shape: circle;}"
    );

    graph.setAttribute("ui.antialias");

    graph.setStrict(false);
    graph.setAutoCreate( true );
    Edge e = graph.addEdge( "AB", "B", "A", true);
    e.setAttribute("weight", 5.0);
    e = graph.addEdge( "BC", "B", "C", true);

    Node b = graph.getNode("B");
    b.setAttribute("label", "B");

    e.setAttribute("weight", 1.0);
    e = graph.addEdge( "CA", "C", "A", true);
    e.setAttribute("weight", 2.0);
    e = graph.addEdge( "BF", "F", "B", true);
    e.setAttribute("weight", 1.0);
    e = graph.addEdge( "CE", "E", "C", true);
    e.setAttribute("weight", 8.0);
    e = graph.addEdge( "EF", "E", "F", true);
    e.setAttribute("weight", 1.0);

    for(int i = 0 ; i < graph.getNodeCount() ; i++){
        graph.getNode(i).setAttribute("ui.label", graph.getNode(i).getId());
    }

    for(int i = 0 ; i < graph.getEdgeCount() ; i++){
        graph.getEdge(i).setAttribute("ui.label", "Poids = "+(graph.getEdge(i).getAttribute("weight")));
    }

    display(savedInstanceState, graph, true);
}

public void display(Bundle savedInstanceState, Graph graph, boolean autoLayout) {
    if (savedInstanceState == null) {
        FragmentManager fm = getSupportFragmentManager();
        DefaultFragment fragment = (DefaultFragment) fm.findFragmentByTag("fragment_tag");

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

        FragmentTransaction ft = fm.beginTransaction() ;
        ft.add(R.id.content_frame, fragment).commit();
    }
}

However, I am only getting a blank white screen in the frame. The app is not crashing. Can someone explain what I am doing wrong?
This is what I see in logcat errors (red lines) in Android Studio:-

11928-11928/com.testapp.graphstream.myflavor E/Debug: DefaultFragment : onAttach
11928-11928/com.testapp.graphstream.myflavor E/Debug: DefaultFragment : onCreate
11928-11928/com.testapp.graphstream.myflavor E/Debug: Tutorial 1
11928-11928/com.testapp.graphstream.myflavor E/Debug: DefaultFragment : onCreateView
11928-11928/com.testapp.graphstream.myflavor E/Debug: DefaultFragment : onAttach
11928-11928/com.testapp.graphstream.myflavor E/Debug: DefaultFragment : onCreate
11928-11928/com.testapp.graphstream.myflavor E/Debug: DefaultFragment : onCreateView

I am also not sure if I am missing some entire steps in the implementation of Graphstream. Some of the examples on github show the use of a 'algorithm generator', some other examples show the use of 'viewerpipe' under protected void onStart() - like the code on this page -> https://github.com/graphstream/gs-ui-android-test/blob/master/app/src/main/java/ui/graphstream/org/gs_ui_androidtestFull/Activity_LayoutTest.java
I am confused about their use cases.

So I will be grateful if someone can also point to any resources where there are detailed tutorials of graphstream specifically for android. The website and code samples on github are not much descriptive in aspects related to android (or forgive me for being a noob).
Thanks

Jemshid
  • 15
  • 4
  • Can you show your Activity's layout ? (activity_main.xml) – Artem Viter Jun 07 '21 at 15:56
  • Sorry for the delay in reply. I was offline for few days. The issue was related to my layout which was bit complex. I have got a working example as posted below (accepted answer) from where I will try to move up. – Jemshid Jun 11 '21 at 10:00

1 Answers1

1

tes. I guess your layout file is the cause. You can use my example code of using GraphView here

Catur Ananta
  • 92
  • 12
  • Thank you for the working example. Issue was related to my complex layout which I am yet to pin point. I will use your example to move ahead. – Jemshid Jun 11 '21 at 10:01