Tuesday, September 22, 2009

How to Import Cards from the SD Card

One of the key features of A++ Flash Cards is the ability to upload flash cards to a phone in a quick and simple manner. This feature saves users a lot of time because they can create cards on their computer's keyboard rather than the on their phone's. This feature is also useful because it allows users to pull flash cards from other flash card websites, such as flashcardexchange.com or flashcardmachine, removing the need to type out any cards at all.

Here is how the 'Import Set from xml File' feature works:

(What you will need)

First, users need a mini-sd card for their phone with a mini-sd adapter for their computer, in order to transfer the files.
Second, users need a text editor, like Microsoft Word, or Notepad++ (no affiliation), so that they can edit and format the file that will be in imported. Whichever editor is used, it needs to be able to do a few things:
  1. It needs to be able to read xml files. Most editors can do this.
  2. It needs to preserve line breaks in the file. If the editor converts an xml file into one long sentence, then the importer will get confused and give strange results.
  3. The editor needs to allow UTF-8 encoding. You will need to encode your files in UTF-8 format before they are uploaded to the phone, otherwise special characters and fonts from other languages, like Japanese or Mandarin, will show up on the card as little boxes or question marks. Notepad++ makes this easy.
Once a user has an editor that can do all of these things and an SD card and an adapter, importing cards to A++ Flash Cards is easy.

As an example, let's say I want to learn how to count in Japanese, and I want to learn how to write the numbers out in in their Kanji characters. I know I can make cards with Kanji, because Android can handle Japanese fonts. Note that the Android Operating System does not currently support Hebrew or Arabic fonts, and so neither can A++ Flash Cards, unfortunately.

(How to Prepare the xml file)

There are many sites out there that have flash cards already made, so if you haven't read it already, please read my post on How to Get Flash Cards from the Web.

If you would like a set of cards to practice with, you can use my set for Counting to 10 in Japanese.

Assuming you have the xml/html code with the cards you want in your editor already, the next step is to make sure the code is in the right format. First, check that any special characters you want to show up in the cards is showing up in the editor. If you see question marks or little boxes where the special characters should be, you need to highlight the code and convert it to UTF-8 encoding. Once you can see the characters as they should be in the editor, it means that if Android supports those fonts, then so will A++ Flash Cards.

The next step is to do any necessary tweaking to the code, so that A++ Flash Cards' importer knows where the card information is in the code. The importer can handle card information in two different formats. The first format is the one that A++ Flash Cards exports sets of cards in.



As the picture to the left shows, one way the importer looks for cards is where the card is contained between <tr> </tr> tags, and individual card information is contained within <td> </td> tags. If the file to the left was uploaded to the phone, the importer would see three cards, all with the same content: The front of the card would be 'front', the Back would be 'back', and the Extra part would be 'extra'. As a side note, since the content is identical in all three cards, the importer would only create one card in this case.

Another acceptable format is demonstrated in the picture below. This is source code from one of the many popular flash card sites on the web. Again, this format works because individual cards are contained within <tr> and </tr> tags, while card information is separated between <td> and </td> tags. Note that the <tr> and </tr> tags are not on the same line - the importer would skip the card information in the middle if they were on the same line. Also, the importer knows to skip the first set of <td> </td> tags, because there is no card information in between them, but it knows not to skip the following three sets of <td> </td> tags.

The importer can also handle a combination of the two formats. In the picture to the right, the xml file has one card in the first format, and a second card in the second format. This is perfectly acceptable, because the <tr> </tr> tags are on different lines and contain individual card information, and the card information is separated by <td> </td> tags.

One way to get the hang of formatting files so you can import them is to first create some cards on the phone, and then export the set as an xml file (when exporting, the phone will overwrite the file importexport.xml in the folder 'A++ Flash Cards' on the SD card) and then edit that file with the new content you want uploaded.

Once the all the card information is in an acceptable format, copy and paste the formatted text into the file importexport.xml. Remember, make sure the special characters are encoded as UTF-8 and the formatting did not change. Save the file as importexport.xml back into the 'A++ Flash Cards' folder on your SD card, and then remove the SD card from your computer and put it back in your Android phone. Then, if you have not done so already, from the main page create the new set that you want to import your cards into. In this case, I would create a set called 'Japanese Numbers'. Then long press the set 'Japanese Numbers' until the options menu pops up, and then select 'Import Set from xml file'.

After a moment, the cards will have been uploaded, and you can check whether the cards were imported correctly by either clicking the set name, which will take you to viewing mode, or by long pressing the set name and selecting 'View or Edit Cards in Set'. You will immediately see whether the cards were encoded properly and whether the file was properly formatted.

Note that importing a set overwrites all previous cards in the set, so before importing, take precautions and back up your cards in the set by first exporting them and then copying and renaming the file they're in. Remember, the importer and exporter both use the file importexport.xml to import and export cards, so if you want to back up and save sets of cards, export them and then copy and rename the file so it will not be touched by the importer or exporter later.

To get the hang of importing and exporting, first make a small set of cards and export the set to importexport.xml. Then alter the file, such as by adding or removing some cards, and then import the file back to the set and see the changes in the card set.

Feel free to leave feedback on how to make this feature more user friendly, and expect updates to it down the road. Good Luck!

1 comment:

  1. Hey, there is a problem with your import method... if the file is not indented as you expect, it does not works... too bad... :( Anyway... when it works, it is nice. :)

    ReplyDelete