use of org.jgrapht.nio.json.JSONExporter in project AlphaTour by Frank99DG.
the class CreateJsonActivity method bottomAppBarPathClick.
public void bottomAppBarPathClick() {
home_path_button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
moveToDashboard();
finishAffinity();
overridePendingTransition(0, 0);
}
});
bottomAppBarPath.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
switch(item.getItemId()) {
case R.id.download_path:
Graph<ZoneChoosed, DefaultEdge> graph = Step4.getGraph();
JSONExporter<ZoneChoosed, DefaultEdge> exporter = new JSONExporter<>(v -> String.valueOf(v));
exporter.setEdgeIdProvider(new IntegerIdProvider<>(1));
// ByteArrayOutputStream os = new ByteArrayOutputStream();
File file = null;
try {
File fil = new File(Environment.getExternalStorageDirectory().getAbsolutePath(), "Percorso.json");
FileOutputStream fos = new FileOutputStream(fil);
// file = File.createTempFile("Percorso",".json");
exporter.exportGraph(graph, fos);
fos.close();
Toast.makeText(CreateJsonActivity.this, "Saved to " + getFilesDir() + "/" + "Percorso.json", Toast.LENGTH_LONG).show();
} catch (IOException e) {
e.printStackTrace();
}
return true;
case R.id.share_path:
Context context = CreateJsonActivity.this;
String str = "{ \"zona\": \"medioevo\",\n" + " \"oggetto\": \"oggetto1\",\n" + " \"oggetto\": \"oggetto 2\",\n" + " \"zona1\": \"zona2\", \n" + " \"oggetto\": \"oggetto1\", \n" + " \"oggettto\": \"oggetto2\" }";
try {
Graph<ZoneChoosed, DefaultEdge> graphh = Step4.getGraph();
/*Zone zone=new Zone();
Zone zone1=new Zone();
Zone zone2=new Zone();
ElementString elm=new ElementString();
ElementString elm1=new ElementString();
zone.setName("Medioevo");
zone1.setName("Assiri");
zone2.setName("Sumeri");
elm.setIdZone("Medioevo"); elm.setTitle("Oggetto1"); elm.setDescription("descrizione");
elm.setPhoto("link foto"); elm.setQrCode("qr code");
elm1.setIdZone("Assiri"); elm1.setTitle("Oggetto2"); elm1.setDescription("descr");
elm1.setPhoto("link foto oggetto 2"); elm1.setQrCode("qr code oggetto 2");
graph.addVertex(zone);
graph.addVertex(zone1);
graph.addVertex(zone2);
graph.addEdge(zone,zone1);
graph.addEdge(zone,zone2);
graph.addEdge(zone1,zone2);
graph.addEdge(zone2,zone1);*/
JSONExporter<ZoneChoosed, DefaultEdge> exporterr = new JSONExporter<>(v -> String.valueOf(v));
exporterr.setEdgeIdProvider(new IntegerIdProvider<>(1));
// ByteArrayOutputStream os = new ByteArrayOutputStream();
File filee = File.createTempFile("Percorso", ".json");
exporterr.exportGraph(graphh, filee);
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("application/json");
Uri uri = FileProvider.getUriForFile(Objects.requireNonNull(getApplicationContext()), BuildConfig.APPLICATION_ID + ".provider", filee);
intent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(intent);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return true;
}
return false;
}
});
}
use of org.jgrapht.nio.json.JSONExporter in project quarkus-jgrapht by quarkiverse.
the class JgraphtJSONResource method exportGraph.
@GET
@Path("/export")
public String exportGraph() {
Graph<Integer, DefaultEdge> graph = GraphTypeBuilder.directed().edgeClass(DefaultEdge.class).vertexSupplier(SupplierUtil.createIntegerSupplier()).allowingMultipleEdges(false).allowingSelfLoops(false).buildGraph();
graph.addVertex(1);
graph.addVertex(2);
graph.addVertex(3);
graph.addVertex(4);
graph.addEdge(1, 2);
graph.addEdge(2, 3);
graph.addEdge(3, 4);
graph.addEdge(1, 4);
JSONExporter<Integer, DefaultEdge> exporter = new JSONExporter<>(v -> String.valueOf(v));
exporter.setEdgeIdProvider(new IntegerIdProvider<>(1));
StringWriter w = new StringWriter();
exporter.exportGraph(graph, w);
return w.toString();
}
Aggregations