Search in sources :

Example 1 with ZoneChoosed

use of com.example.alphatour.oggetti.ZoneChoosed 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)

Example 2 with ZoneChoosed

use of com.example.alphatour.oggetti.ZoneChoosed in project AlphaTour by Frank99DG.

the class Step4 method savePathLocal.

public long savePathLocal(Path path) {
    long newRowId = -1;
    AlphaTourDbHelper dbAlpha = new AlphaTourDbHelper(getContext());
    SQLiteDatabase db = dbAlpha.getWritableDatabase();
    ContentValues values = new ContentValues();
    values.put(AlphaTourContract.AlphaTourEntry.NAME_COLUMN_PATH_NAME, path.getName());
    values.put(AlphaTourContract.AlphaTourEntry.NAME_COLUMN_PATH_DESCRIPTION, path.getDescription());
    values.put(AlphaTourContract.AlphaTourEntry.NAME_COLUMN_PATH_LOAD, "false");
    newRowId = db.insert(AlphaTourContract.AlphaTourEntry.NAME_TABLE_PATH, AlphaTourContract.AlphaTourEntry.COLUMN_NAME_NULLABLE, values);
    SQLiteDatabase db1 = dbAlpha.getWritableDatabase();
    ContentValues values1 = new ContentValues();
    for (i = 0; i < path.getZonePath().size(); i++) {
        ZoneChoosed zoneChoosed = path.getZonePath().get(i);
        for (int j = 0; j < zoneChoosed.getObjectChoosed().size(); j++) {
            values1.put(AlphaTourContract.AlphaTourEntry.NAME_COLUMN_PATH_CONTAINS_ID_PATH, getIdPath(path.getName()));
            values1.put(AlphaTourContract.AlphaTourEntry.NAME_COLUMN_PATH_CONTAINS_ZONE, zoneChoosed.getName());
            values1.put(AlphaTourContract.AlphaTourEntry.NAME_COLUMN_PATH_CONTAINS_OBJECT, zoneChoosed.getObjectChoosed().get(j));
            values1.put(AlphaTourContract.AlphaTourEntry.NAME_COLUMN_PATH_CONTAINS_LOAD, "false");
            newRowId = db1.insert(AlphaTourContract.AlphaTourEntry.NAME_TABLE_PATH_CONTAINS, AlphaTourContract.AlphaTourEntry.COLUMN_NAME_NULLABLE, values1);
        }
    }
    return newRowId;
}
Also used : ContentValues(android.content.ContentValues) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) ZoneChoosed(com.example.alphatour.oggetti.ZoneChoosed) AlphaTourDbHelper(com.example.alphatour.dblite.AlphaTourDbHelper)

Example 3 with ZoneChoosed

use of com.example.alphatour.oggetti.ZoneChoosed in project AlphaTour by Frank99DG.

the class Step4 method savePath.

private void savePath() {
    progressBar.setVisibility(View.VISIBLE);
    List<MapZoneAndObject> zoneAndObjectList = zoneAndObjectList_;
    MapZoneAndObject mapZoneAndOb = zoneAndObjectList.get(0);
    Path path = new Path();
    path.setName(mapZoneAndOb.getName());
    path.setDescription(mapZoneAndOb.getDescription());
    path.setIdUser(user.getUid());
    for (int i = 0; i < zoneAndObjectList_.size(); i++) {
        MapZoneAndObject mapZoneAndObject = zoneAndObjectList.get(i);
        // String delete = "delete";
        // if(!mapZoneAndObject.getZone().matches(delete)) {
        ZoneChoosed zoneChoosed = new ZoneChoosed();
        zoneChoosed.setName(mapZoneAndObject.getZone());
        List<String> obj = mapZoneAndObject.getListObj();
        for (int j = 0; j < obj.size(); j++) {
            zoneChoosed.setObjectChoosed(obj.get(j));
        }
        graph.addVertex(zoneChoosed);
        zoneChooseds.add(zoneChoosed);
        if (i >= 1) {
            graph.addEdge(zoneChooseds.get(i - 1), zoneChooseds.get(i));
        }
        path.setZonePath(zoneChoosed);
    // }
    }
    if (receiver.isConnected()) {
        savePathRemote(path);
        savePathLocal(path);
    } else {
        savePathRemote(path);
        savePathLocal(path);
        moveToCreateJsonActivity();
        progressBar.setVisibility(View.GONE);
    }
}
Also used : Path(com.example.alphatour.oggetti.Path) ZoneChoosed(com.example.alphatour.oggetti.ZoneChoosed) MapZoneAndObject(com.example.alphatour.oggetti.MapZoneAndObject)

Example 4 with ZoneChoosed

use of com.example.alphatour.oggetti.ZoneChoosed in project AlphaTour by Frank99DG.

the class Step5 method savePath.

private void savePath() {
    progressBar.setVisibility(View.VISIBLE);
    List<MapZoneAndObject> zoneAndObjectList = zoneAndObjectList_;
    MapZoneAndObject mapZoneAndOb = zoneAndObjectList.get(0);
    Path path = new Path();
    path.setName(mapZoneAndOb.getName());
    path.setDescription(mapZoneAndOb.getDescription());
    path.setIdUser(user.getUid());
    for (int i = 0; i < zoneAndObjectList_.size(); i++) {
        MapZoneAndObject mapZoneAndObject = zoneAndObjectList.get(i);
        // String delete = "delete";
        // if(!mapZoneAndObject.getZone().matches(delete)) {
        ZoneChoosed zoneChoosed = new ZoneChoosed();
        zoneChoosed.setName(mapZoneAndObject.getZone());
        List<String> obj = mapZoneAndObject.getListObj();
        for (int j = 0; j < obj.size(); j++) {
            zoneChoosed.setObjectChoosed(obj.get(j));
        }
        graph.addVertex(zoneChoosed);
        zoneChooseds.add(zoneChoosed);
        if (i >= 1) {
            graph.addEdge(zoneChooseds.get(i - 1), zoneChooseds.get(i));
        }
        path.setZonePath(zoneChoosed);
    // }
    }
}
Also used : Path(com.example.alphatour.oggetti.Path) ZoneChoosed(com.example.alphatour.oggetti.ZoneChoosed) MapZoneAndObject(com.example.alphatour.oggetti.MapZoneAndObject)

Aggregations

ZoneChoosed (com.example.alphatour.oggetti.ZoneChoosed)4 MapZoneAndObject (com.example.alphatour.oggetti.MapZoneAndObject)3 Path (com.example.alphatour.oggetti.Path)2 Manifest (android.Manifest)1 Dialog (android.app.Dialog)1 ClipData (android.content.ClipData)1 ContentValues (android.content.ContentValues)1 Context (android.content.Context)1 Intent (android.content.Intent)1 PackageManager (android.content.pm.PackageManager)1 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)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