Goal
The goal is to build a basic conversion app.
Rather than dump everything onto one screen, I wanted to use two different screens. The first screen is where the user enters a planet and both an age and a weight to convert. On the second screen, the user enters a second planet and receives as output a new age and weight that is the conversion of the previous age and weight from the first planet in terms of the second.
Implementation
I created two Activites for both the screens. I was going to use radio buttons to allow the user to select planets as mentioned in the project specs and as others have done, but upon reading the Android documentation, I opted to use a Spinner instead. In both screens, when items from the spinner are selected, an ImageView at the top of the screen (in portrait mode) is set to a picture of the planet that the user had just selected.
Once the user enters an age and weight in the EditTexts, selects a planet from the Spinner, and hits the "Continue" button below, they are taken to the next screen. I wired the continue button to start a new Activity and stuffed the user inputs--age and planet--into the Bundle of the Intent that signals for the second Activity. So now that the new Activity has access to this information when created (OnCreate), all the user must do is select another planet in the same fashion from another Spinner. And when he or she hits the "Convert" button below, an empty TextView at the bottom gets its text set to an informative output which was calculated using simple conversions--namely, converting the input age and weight in the associated planet from the first activity to an equivalent unit in terms of Earth and then using this Earth-standardized age and weight along with the input planet in this Activity to compute the resulting age and weight in terms of this planet.
Screenshots
This is a simple example of the app being used. I realize that Hackster happens to have a white background which makes all my initial snapshot screens (where the user is to select a planet and enter an age and weight) borderless as they have been set to a background color of white. However, the second screen (where the user enters the second planet and performs the conversion) has the regular background and is visible.
Video
Some Improvements/Last minute edits
I have made a few improvements to the application that has been described thus far, and the source code below reflects these changes:
First, I set the inputType of the editText for the weight user input in the landscape layout of the first Activity to numbers only--something I had forgotten to do for just the landscape layout.
Second, and again in the landscape layout but this time for the second screen, I noticed that for certain conversions the result text overflowed out of the screen. To fix this I lowered that textView's layout_marginTop. Now everything fits.
Third, I set all the image sizes to by the same dimention, so that toggling images does not distract the user so much. Previous, the elements in the screen would shift all over the place due to changing sizes.
Fourth, I have allowed the user to dynamically alter the background color to match the planet selected. These colors are very un-elegantly hardcoded and copy-pasted in, but they reflect the spirit of the planet. For example, selecting Mars turns the screen red.
Unfinished Work (as of 11:56 pm)
-Adding the days extra credit
-Truncating the results to a given number of decimal places
-Using Fragments instead of Activities
-Taking screen shots of the new app
-Edge cases: not entering anything for the age or weight fields causes the application to crash. (A default value could have been initialized or the offending user could have been given a warning on, say a DialogFragment)
But...
Due to time constraints, all I have time for before midnight is to show one video of the final version of my app. The source code below, however, reflects this current version.
But...
There is always time to give credit to sources:
-http://www.onlineconversion.com/weight_on_other_planets.htm
Comments