projects/syncslides/app/src/main/java/io/v/android/apps/syncslides/DeckChooserFragment.java
/**
     * Import a slide deck from the given (local) folder.
     *
     * The folder must contain a JSON metadata file 'deck.json' with the following format:
     * {
     *     "Title" : "<title>",
     *     "Thumb" : "<filename>,
     *     "Slides" : [
     *          {
     *              "Thumb" : "<thumb_filename1>",
     *              "Image" : "<image_filename1>",
     *              "Note" : "<note1>"
     *          },
     *          {
     *              "Thumb" : "<thumb_filename2>",
     *              "Image" : "<image_filename2>",
     *              "Note" : "<note2>"
     *          },
     *
     *          ...
     *     ]
     * }
     *
     * All the filenames must be local to the given folder.
     */
Import a slide deck from the given (local) folder.



All the filenames must be local to the given folder.
Import a slide deck from the given ( local ) folder . All the filenames must be local to the given folder .
private void importDeck(DocumentFile dir) {
        if (!dir.isDirectory()) {
            toast("Must import from a directory, got: " + dir);
            return;
        }
        DocumentFile metadataFile = dir.findFile("deck.json");
        if (metadataFile == null) {
            toast("Couldn't find deck metadata file 'deck.json'");
            return;
        }
        JSONObject metadata = null;
        try {
            String data = new String(ByteStreams.toByteArray(
                    getActivity().getContentResolver().openInputStream(metadataFile.getUri())),
                    Charsets.UTF_8);
            metadata = new JSONObject(data);
        } catch (FileNotFoundException e) {
            toast("Couldn't open deck metadata file: " + e.getMessage());
            return;
        } catch (IOException e) {
            toast("Couldn't read data from deck metadata file: " + e.getMessage());
            return;
        } catch (JSONException e) {
            toast("Couldn't parse deck metadata: " + e.getMessage());
            return;
        }
        try {
            String id = UUID.randomUUID().toString();
            String title = metadata.getString("Title");
            byte[] thumbData = readImage(dir, metadata.getString("Thumb"));
            Deck deck = DeckFactory.Singleton.get().make(title, thumbData, id);
            Slide[] slides = readSlides(dir, metadata);
            DB.Singleton.get(getActivity().getApplicationContext()).importDeck(deck, slides, null);
        } catch (JSONException e) {
            toast("Invalid format for deck metadata: " + e.getMessage());
            return;
        } catch (IOException e) {
            toast("Error interpreting deck metadata: " + e.getMessage());
            return;
        }
    }
private void importDeck ( DocumentFile dir ) { if ( ! dir . isDirectory ( ) ) { toast ( "Must import from a directory, got: " + dir ) ; return ; } DocumentFile metadataFile = dir . findFile ( "deck.json" ) ; if ( metadataFile == null ) { toast ( "Couldn't find deck metadata file 'deck.json'" ) ; return ; } JSONObject metadata = null ; try { String data = new String ( ByteStreams . toByteArray ( getActivity ( ) . getContentResolver ( ) . openInputStream ( metadataFile . getUri ( ) ) ) , Charsets . UTF_8 ) ; metadata = new JSONObject ( data ) ; } catch ( FileNotFoundException e ) { toast ( "Couldn't open deck metadata file: " + e . getMessage ( ) ) ; return ; } catch ( IOException e ) { toast ( "Couldn't read data from deck metadata file: " + e . getMessage ( ) ) ; return ; } catch ( JSONException e ) { toast ( "Couldn't parse deck metadata: " + e . getMessage ( ) ) ; return ; } try { String id = UUID . randomUUID ( ) . toString ( ) ; String title = metadata . getString ( "Title" ) ; byte [ ] thumbData = readImage ( dir , metadata . getString ( "Thumb" ) ) ; Deck deck = DeckFactory . Singleton . get ( ) . make ( title , thumbData , id ) ; Slide [ ] slides = readSlides ( dir , metadata ) ; DB . Singleton . get ( getActivity ( ) . getApplicationContext ( ) ) . importDeck ( deck , slides , null ) ; } catch ( JSONException e ) { toast ( "Invalid format for deck metadata: " + e . getMessage ( ) ) ; return ; } catch ( IOException e ) { toast ( "Error interpreting deck metadata: " + e . getMessage ( ) ) ; return ; } }
Import a slide deck from the given (local) folder.
Import a slide deck from the given ( local ) folder .
// Read the deck metadata file.