teaching machines

Weren’t Flashcards the First App?

October 19, 2011 by . Filed under cs491 mobile, fall 2011, postmortems.

So when I saw the first app I thought flashcards would be a really nice project to do. They’re visually simple and the end result would be really practical (my girlfriend manages to write around 1200 flashcards a semester, or 400 index cards cut into thirds). But as I thought about it, there wasn’t a real clean way to do it, since we hadn’t touched databases yet. So I scrapped that and went with a flowchart, but flashcards were still on my mind.

Then the second assignment rolled around and now flashcard were totally doable. So here it is. The app is broken down into four activities. The main activity shows a list of the decks of flashcards that you’ve made, and can launch that deck to view or edit. Decks are also created, renamed, and deleted from here. This list uses a custom adapter, that launches an intent. Android will yell at you if you don’t add the appropriate flag when you do this.

not very interesting flashcard decks

 

this happens when one of the pencils is clicked on

                Intent intent = new Intent(context, DeckEditActivity.class);

// required flag for launching an intent outside
// an activity
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra(“deck_position”, position);
context.startActivity(intent);

 

After you make a new deck or click the pencil (or try to view a deck with no cards) you are taken to the deck editing activity. In here the cards of the deck are displayed in a list. Cards can be added, deleted, or launched into editing from here. Nothing terribly interesting going on, other than the layout the standard adapter that stores the cards is using is a custom one that limits the text to one line. By using the same id that the standard simple list item view uses, I was able to use a custom layout on a stock adapter.

and here’s that layout I was talking about

<?xml version=”1.0″ encoding=”utf-8″?>

<!– notice the id, this allows use of the layout in a
list without a custom adapter –>
<TextView
xmlns:android=”http://schemas.android.com/apk/res/android”
android:id=”@android:id/text1″
android:layout_width=”fill_parent”
android:layout_height=”wrap_content”
android:textAppearance=”?android:attr/textAppearanceLarge”
android:gravity=”center_vertical”
android:paddingLeft=”6dp”
android:singleLine=”true”
android:minHeight=”?android:attr/listPreferredItemHeight”>
</TextView>

 

 

When we click on one of those, or make a new card, we’re brought to the card editing activity. The buttons on the bottom will save, delete, and add a new card. Adding a new card saves the current card, launches a new card editing activity, then finishes the current one. Also, like Dr Johnson’s Rattler, it will nag you if you have unsaved changes.

 

The last activity is launch by clicking on a deck in the main activity, and it the viewing activity. The one has a lot going. One of the things I didn’t think I would need was  a custom ViewFlipper, because ViewFlipper in 2.1 has a bug, for displaying the text of the cards. That text is scrollable if need, though no scrollbar will be shown.

There are two methods of switching between the cards (and sides of cards), the buttons at the bottom, and through gesture recognition. When the view flipper changes between two views (I just alternate between two, but you can use more), the activity applies animations to the entering and leaving views that suggest the direction of the button clicked or gesture performed. The gestures that it recognizes are sliding left or right, a  ‘c’-like motion moving up or down, and a backwards  ‘c’-like motion moving up or down. The latter ones are to tell the activity to flip the flashcard to the other side.