Search in sources :

Example 1 with Step4

use of com.example.alphatour.wizardpercorso.Step4 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;
        }
    });
}
Also used : RequiresApi(androidx.annotation.RequiresApi) Context(android.content.Context) LinearLayout(android.widget.LinearLayout) Bundle(android.os.Bundle) MapZoneAndObject(com.example.alphatour.oggetti.MapZoneAndObject) ReviewZoneSelected(com.example.alphatour.wizardpercorso.ReviewZoneSelected) PackageManager(android.content.pm.PackageManager) NonNull(androidx.annotation.NonNull) Environment(android.os.Environment) Uri(android.net.Uri) Dialog(android.app.Dialog) Intent(android.content.Intent) TransitionManager(android.transition.TransitionManager) AppCompatActivity(androidx.appcompat.app.AppCompatActivity) MenuItem(android.view.MenuItem) IntegerIdProvider(org.jgrapht.nio.IntegerIdProvider) ArrayList(java.util.ArrayList) ClipData(android.content.ClipData) Manifest(android.Manifest) Toast(android.widget.Toast) FloatingActionButton(com.google.android.material.floatingactionbutton.FloatingActionButton) Menu(android.view.Menu) JSONExporter(org.jgrapht.nio.json.JSONExporter) View(android.view.View) Button(android.widget.Button) Build(android.os.Build) Step2(com.example.alphatour.wizardpercorso.Step2) ContextCompat(androidx.core.content.ContextCompat) Step4(com.example.alphatour.wizardpercorso.Step4) CardView(androidx.cardview.widget.CardView) DefaultEdge(org.jgrapht.graph.DefaultEdge) BottomAppBar(com.google.android.material.bottomappbar.BottomAppBar) ActivityCompat(androidx.core.app.ActivityCompat) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) ViewGroup(android.view.ViewGroup) File(java.io.File) FileNotFoundException(java.io.FileNotFoundException) Objects(java.util.Objects) List(java.util.List) TextView(android.widget.TextView) PercorsoWizard(com.example.alphatour.wizardpercorso.PercorsoWizard) ConstraintLayout(androidx.constraintlayout.widget.ConstraintLayout) FileProvider(androidx.core.content.FileProvider) ZoneChoosed(com.example.alphatour.oggetti.ZoneChoosed) Graph(org.jgrapht.Graph) Toolbar(androidx.appcompat.widget.Toolbar) AutoTransition(android.transition.AutoTransition) Context(android.content.Context) FileNotFoundException(java.io.FileNotFoundException) MenuItem(android.view.MenuItem) Intent(android.content.Intent) IOException(java.io.IOException) View(android.view.View) CardView(androidx.cardview.widget.CardView) TextView(android.widget.TextView) Uri(android.net.Uri) IntegerIdProvider(org.jgrapht.nio.IntegerIdProvider) Graph(org.jgrapht.Graph) FileOutputStream(java.io.FileOutputStream) JSONExporter(org.jgrapht.nio.json.JSONExporter) File(java.io.File) Toolbar(androidx.appcompat.widget.Toolbar)

Aggregations

Manifest (android.Manifest)1 Dialog (android.app.Dialog)1 ClipData (android.content.ClipData)1 Context (android.content.Context)1 Intent (android.content.Intent)1 PackageManager (android.content.pm.PackageManager)1 Uri (android.net.Uri)1 Build (android.os.Build)1 Bundle (android.os.Bundle)1 Environment (android.os.Environment)1 AutoTransition (android.transition.AutoTransition)1 TransitionManager (android.transition.TransitionManager)1 Menu (android.view.Menu)1 MenuItem (android.view.MenuItem)1 View (android.view.View)1 ViewGroup (android.view.ViewGroup)1 Button (android.widget.Button)1 LinearLayout (android.widget.LinearLayout)1 TextView (android.widget.TextView)1 Toast (android.widget.Toast)1