Every activity available in our app has its own class implemented by us (with the exception of the image capture activity which is provided by the android system). We used anonymous classes for all the lists except for the new game player list because this one was more complicated, requiring more buttons and needing to keep track of reference across items instead of simply starting activities with indexes. Any activity that modifies the database extends DatabaseStoreOnStopActivity
instead of Activity
. This custom class overrides the onStop()
method to store the database. This ensures that no data is lost even if the app is exited during Live Mode or another editing activity.
With the exception of LiveMode
and NewGame
, all the activities did not require custom views or other classes . Live Mode required the following user-defined objects:
DialogFragment
class for the "tink or sink" pop-up with the intention of rotating it according the which player caused it. GestureDetector
class to recognize different actions, each of which was attached to a player's text viewAt the core of our program is the class BeerDieDatabase
. This class is a singleton which can be accessed from anywhere in the project by providing a context. The entire database is stored on the device's hard drive and is can be re-stored with a call to BeerDieDatabase.store()
. The database maintains the following:
Player
classGame
class is comparable by the last time it was played, making Collections.sort()
applicableIt is easy to add tables, games, and players to the database from the various activities that do so. Any activity that requires a game reference does not need to get the reference from an intent, it simply gets a reference to the most recent game (as the activity that started it will reorder the games before starting the activity). There is also a provided reset database option (for which there is a shortcut in the main activity) that deletes the table image files and creates a new database, relying on garbage collection to get rid of the old references in the prior database instance.
BeerDieDatabase
uses a class called ImageSaver
to obtain file references to the table images and was found on stackoverflow.com.