Search in sources :

Example 1 with Exporter

use of org.hwyl.sexytopo.control.io.translation.Exporter in project sexytopo by richsmith.

the class SexyTopoActivity method exportSurvey.

public void exportSurvey() {
    // public due to stupid Reflection requirements
    final Survey survey = getSurvey();
    AlertDialog.Builder builderSingle = new AlertDialog.Builder(this);
    builderSingle.setTitle(getString(R.string.select_export_type));
    final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(this, android.R.layout.select_dialog_item);
    final Map<String, Exporter> nameToExporter = new HashMap<>();
    for (Exporter exporter : SelectableExporters.EXPORTERS) {
        String name = exporter.getExportTypeName(this);
        arrayAdapter.add(name);
        nameToExporter.put(name, exporter);
    }
    builderSingle.setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });
    builderSingle.setAdapter(arrayAdapter, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            String name = arrayAdapter.getItem(which);
            Exporter selectedExporter = nameToExporter.get(name);
            try {
                selectedExporter.export(SexyTopoActivity.this, survey);
                showSimpleToast(survey.getName() + " " + getString(R.string.export_successful));
            } catch (Exception exception) {
                showException(exception);
            }
        }
    });
    builderSingle.show();
}
Also used : AlertDialog(android.app.AlertDialog) HashMap(java.util.HashMap) DialogInterface(android.content.DialogInterface) Exporter(org.hwyl.sexytopo.control.io.translation.Exporter) Survey(org.hwyl.sexytopo.model.survey.Survey) ArrayAdapter(android.widget.ArrayAdapter)

Aggregations

AlertDialog (android.app.AlertDialog)1 DialogInterface (android.content.DialogInterface)1 ArrayAdapter (android.widget.ArrayAdapter)1 HashMap (java.util.HashMap)1 Exporter (org.hwyl.sexytopo.control.io.translation.Exporter)1 Survey (org.hwyl.sexytopo.model.survey.Survey)1