Skip to content

Commit 42bcc4b

Browse files
author
michelou
committed
added more examples
1 parent 4079af9 commit 42bcc4b

File tree

71 files changed

+4447
-133
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+4447
-133
lines changed

android-app-dev/TriviaQuiz/src/com/androidbook/triviaquiz/QuizConstants.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ object QuizConstants {
1919

2020
final val GAME_PREFERENCES_PLAYER_ID = "ServerId" // Integer
2121

22-
// XML Tag Names
22+
// XML Tag Names
2323
final val XML_TAG_QUESTION_BLOCK = "questions"
2424
final val XML_TAG_QUESTION = "question"
2525
final val XML_TAG_QUESTION_ATTRIBUTE_NUMBER = "number"
2626
final val XML_TAG_QUESTION_ATTRIBUTE_TEXT = "text"
2727
final val XML_TAG_QUESTION_ATTRIBUTE_IMAGEURL = "imageUrl"
2828
final val QUESTION_BATCH_SIZE = 5 // 15
2929

30-
// Server URLs
30+
// Server URLs
3131
final val TRIVIA_SERVER_BASE = "http://tqs.mamlambo.com/"
3232
final val TRIVIA_SERVER_SCORES = TRIVIA_SERVER_BASE + "scores.jsp"
3333
final val TRIVIA_SERVER_QUESTIONS = TRIVIA_SERVER_BASE + "questions.jsp"

android-app-dev/TriviaQuiz/src/com/androidbook/triviaquiz/QuizGameActivity.scala

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ class QuizGameActivity extends Activity {
9696

9797
/**
9898
* Called when question loading is complete
99-
*
99+
*
100100
* @param startingQuestionNumber
101101
* The first question number that should be available
102102
*/
@@ -133,7 +133,7 @@ class QuizGameActivity extends Activity {
133133
/**
134134
* A switcher factory for use with the question image.
135135
* Creates the next {@code ImageView} object to animate to
136-
*
136+
*
137137
*/
138138
private class MyImageSwitcherFactory extends ViewSwitcher.ViewFactory {
139139
def makeView(): View = {
@@ -148,7 +148,7 @@ class QuizGameActivity extends Activity {
148148
/**
149149
* A switcher factory for use with the question text.
150150
* Creates the next {@code TextView} object to animate to
151-
*
151+
*
152152
*/
153153
private class MyTextSwitcherFactory extends ViewSwitcher.ViewFactory {
154154
def makeView(): View = {
@@ -186,7 +186,6 @@ class QuizGameActivity extends Activity {
186186
editor.commit()
187187

188188
if (!mQuestions.contains(nextQuestionNumber)) {
189-
190189
downloader = new QuizTask()
191190
downloader.execute(TRIVIA_SERVER_QUESTIONS, nextQuestionNumber.asInstanceOf[AnyRef])
192191

@@ -217,7 +216,7 @@ class QuizGameActivity extends Activity {
217216

218217
/**
219218
* Returns a {@code String} representing the text for a particular question number
220-
*
219+
*
221220
* @param questionNumber
222221
* The question number to get the text for
223222
* @return The text of the question, or null if {@code questionNumber} not found
@@ -229,7 +228,7 @@ class QuizGameActivity extends Activity {
229228

230229
/**
231230
* Returns a {@code String} representing the URL to an image for a particular question
232-
*
231+
*
233232
* @param questionNumber
234233
* The question to get the URL for
235234
* @return A {@code String} for the URL or null if none found
@@ -342,7 +341,7 @@ class QuizGameActivity extends Activity {
342341
/**
343342
* Parses the XML questions to {@see mQuestions}. They're preloaded
344343
* into an XmlPullParser (questionBatch)
345-
*
344+
*
346345
* @param questionBatch
347346
* The incoming XmlPullParser
348347
* @throws XmlPullParserException
@@ -377,7 +376,7 @@ class QuizGameActivity extends Activity {
377376

378377
/**
379378
* Loads the XML into the {@see mQuestions} class member variable
380-
*
379+
*
381380
* @param startQuestionNumber
382381
* first question to load
383382
*/

android-app-dev/TriviaQuiz/src/com/androidbook/triviaquiz/QuizHelpActivity.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class QuizHelpActivity extends Activity {
3030

3131
/**
3232
* Converts an input stream to a string
33-
*
33+
*
3434
* @param is
3535
* The {@code InputStream} object to read from
3636
* @return A {@code String} object representing the string for of the input

android-app-dev/TriviaQuiz/src/com/androidbook/triviaquiz/QuizScoresActivity.scala

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ class QuizScoresActivity extends Activity {
3434

3535
// All Scores tab
3636
val allScoresTab = host newTabSpec "allTab"
37-
allScoresTab.setIndicator(getResources.getString(R.string.all_scores), getResources.getDrawable(android.R.drawable.star_on))
37+
allScoresTab.setIndicator(getResources getString R.string.all_scores, getResources getDrawable android.R.drawable.star_on)
3838
allScoresTab setContent R.id.ScrollViewAllScores
3939
host addTab allScoresTab
4040

4141
// Friends Scores tab
4242
val friendScoresTab = host newTabSpec "friendsTab"
43-
friendScoresTab.setIndicator(getResources.getString(R.string.friends_scores), getResources.getDrawable(android.R.drawable.star_on))
43+
friendScoresTab.setIndicator(getResources getString R.string.friends_scores, getResources getDrawable android.R.drawable.star_on)
4444
friendScoresTab setContent R.id.ScrollViewFriendScores
4545
host addTab friendScoresTab
4646

@@ -81,9 +81,8 @@ class QuizScoresActivity extends Activity {
8181
}
8282

8383
/**
84-
*
8584
* Add a header {@code TableRow} to the {@code TableLayout} (styled)
86-
*
85+
*
8786
* @param scoreTable
8887
* the {@code TableLayout} that the header row will be added to
8988
*/
@@ -104,7 +103,7 @@ class QuizScoresActivity extends Activity {
104103
/**
105104
* {@code insertScoreRow()} helper method -- Populate a {@code TableRow}
106105
* with three columns of {@code TextView} data (styled)
107-
*
106+
*
108107
* @param tableRow
109108
* The {@code TableRow} the text is being added to
110109
* @param text
@@ -168,7 +167,6 @@ class QuizScoresActivity extends Activity {
168167
newRow addView noResults
169168
table addView newRow
170169
}
171-
172170
}
173171

174172
override protected def doInBackground(params: AnyRef*): Boolean = {
@@ -189,9 +187,9 @@ class QuizScoresActivity extends Activity {
189187
}
190188

191189
if (scores != null) {
192-
try {
190+
try
193191
processScores(scores)
194-
} catch {
192+
catch {
195193
case e: XmlPullParserException =>
196194
Log.e(DEBUG_TAG, "Pull Parser failure", e)
197195
case e: IOException =>
@@ -203,10 +201,9 @@ class QuizScoresActivity extends Activity {
203201
}
204202

205203
/**
206-
*
207204
* {@code processScores()} helper method -- Inserts a new score
208205
* {@code TableRow} in the {@code TableLayout}
209-
*
206+
*
210207
* @param scoreTable
211208
* The {@code TableLayout} to add the score to
212209
* @param scoreValue
@@ -231,7 +228,7 @@ class QuizScoresActivity extends Activity {
231228

232229
/**
233230
* Churn through an XML score information and populate a {@code TableLayout}
234-
*
231+
*
235232
* @param scores
236233
* A standard {@code XmlPullParser} containing the scores
237234
* @throws XmlPullParserException

android-app-dev/TriviaQuiz/src/com/androidbook/triviaquiz/QuizSettingsActivity.scala

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,7 @@ class QuizSettingsActivity extends Activity {
7878

7979
// if we don't have a serverId yet, we need to get one
8080
val serverId = mGameSettings.getInt(GAME_PREFERENCES_PLAYER_ID, -1)
81-
if (serverId == -1) {
82-
updateServerData()
83-
}
81+
if (serverId == -1) updateServerData()
8482
}
8583

8684
override protected def onPause() {
@@ -109,7 +107,7 @@ class QuizSettingsActivity extends Activity {
109107

110108
/**
111109
* update the server with the latest settings data - everything but the image
112-
*
110+
*
113111
*/
114112
private def updateServerData() {
115113
// make sure we don't collide with another pending update
@@ -123,7 +121,7 @@ class QuizSettingsActivity extends Activity {
123121

124122
/**
125123
* update the server with the latest settings data - everything but the image
126-
*
124+
*
127125
*/
128126
private def doFriendRequest(friendEmail: String) {
129127
// make sure we don't collide with another pending update
@@ -144,9 +142,9 @@ class QuizSettingsActivity extends Activity {
144142
// Took a picture, use the downsized camera image provided by default
145143
val cameraPic = data.getExtras.get("data").asInstanceOf[Bitmap]
146144
if (cameraPic != null) {
147-
try {
145+
try
148146
saveAvatar(cameraPic)
149-
} catch {
147+
catch {
150148
case e: Exception =>
151149
Log.e(DEBUG_TAG, "saveAvatar() with camera image failed.", e)
152150
}
@@ -179,7 +177,7 @@ class QuizSettingsActivity extends Activity {
179177

180178
/**
181179
* Scale a Bitmap, keeping its aspect ratio
182-
*
180+
*
183181
* @param bitmap
184182
* Bitmap to scale
185183
* @param maxSide
@@ -205,16 +203,16 @@ class QuizSettingsActivity extends Activity {
205203

206204
/**
207205
* Save a Bitmap as avatar.jpg
208-
*
206+
*
209207
* @param avatar
210208
* Bitmap to save to file system
211209
*/
212210
private def saveAvatar(avatar: Bitmap) {
213211
val strAvatarFilename = "avatar.jpg"
214-
try {
212+
try
215213
avatar.compress(CompressFormat.JPEG, 100,
216214
openFileOutput(strAvatarFilename, Context.MODE_PRIVATE))
217-
} catch {
215+
catch {
218216
case e: Exception =>
219217
Log.e(DEBUG_TAG, "Avatar compression and save failed.", e)
220218
}
@@ -233,7 +231,7 @@ class QuizSettingsActivity extends Activity {
233231
val avatarButton = findImageButton(R.id.ImageButton_Avatar)
234232
val strAvatarUri = mGameSettings.getString(GAME_PREFERENCES_AVATAR, "android.resource://com.androidbook.triviaquiz/drawable/avatar")
235233
val imageUri = Uri.parse(strAvatarUri)
236-
avatarButton.setImageURI(null); // Workaround for refreshing an ImageButton, which tries to cache the previous image Uri. Passing null effectively resets it.
234+
avatarButton setImageURI null // Workaround for refreshing an ImageButton, which tries to cache the previous image Uri. Passing null effectively resets it.
237235
avatarButton setImageURI imageUri
238236
}
239237

@@ -321,9 +319,8 @@ class QuizSettingsActivity extends Activity {
321319
// Save Email
322320
val emailText = findEditText(R.id.EditText_Email)
323321

324-
if (mGameSettings contains GAME_PREFERENCES_EMAIL) {
322+
if (mGameSettings contains GAME_PREFERENCES_EMAIL)
325323
emailText setText mGameSettings.getString(GAME_PREFERENCES_EMAIL, "")
326-
}
327324

328325
emailText.setOnKeyListener(new View.OnKeyListener() {
329326
def onKey(v: View, keyCode: Int, event: KeyEvent): Boolean = {
@@ -356,11 +353,11 @@ class QuizSettingsActivity extends Activity {
356353

357354
// Handle password setting dialog
358355
val setPassword = findButton(R.id.Button_Password)
359-
setPassword.setOnClickListener(new View.OnClickListener() {
356+
setPassword setOnClickListener new View.OnClickListener() {
360357
def onClick(v: View) {
361358
showDialog(PASSWORD_DIALOG_ID)
362359
}
363-
})
360+
}
364361
}
365362

366363
/**
@@ -369,11 +366,11 @@ class QuizSettingsActivity extends Activity {
369366
private def initFriendEmailEntry() {
370367
// Set button handler to Load friend email entry dialog
371368
val addFriend = findButton(R.id.Button_Friend_Email)
372-
addFriend.setOnClickListener(new View.OnClickListener() {
369+
addFriend setOnClickListener new View.OnClickListener() {
373370
def onClick(v: View) {
374371
showDialog(FRIEND_EMAIL_DIALOG_ID)
375372
}
376-
})
373+
}
377374
}
378375

379376
/**
@@ -409,9 +406,8 @@ class QuizSettingsActivity extends Activity {
409406
adapter setDropDownViewResource android.R.layout.simple_spinner_dropdown_item
410407
spinner setAdapter adapter
411408

412-
if (mGameSettings contains GAME_PREFERENCES_GENDER) {
409+
if (mGameSettings contains GAME_PREFERENCES_GENDER)
413410
spinner.setSelection(mGameSettings.getInt(GAME_PREFERENCES_GENDER, 0))
414-
}
415411

416412
// Handle spinner selections
417413
spinner setOnItemSelectedListener new AdapterView.OnItemSelectedListener() {
@@ -680,7 +676,7 @@ class QuizSettingsActivity extends Activity {
680676
mFavPlaceCoords = new GPSCoords(mGameSettings.getFloat(GAME_PREFERENCES_FAV_PLACE_LAT, 0), mGameSettings.getFloat(GAME_PREFERENCES_FAV_PLACE_LONG, 0))
681677
} else {
682678
// No favorite place set, set coords to current location
683-
strFavPlaceName = getResources.getString(R.string.settings_favplace_currentlocation)
679+
strFavPlaceName = getResources getString R.string.settings_favplace_currentlocation
684680
// We do not name this place ("here"), but use it as a map point.
685681
// User can supply the name if they like
686682
calculateCurrentCoordinates()
@@ -734,7 +730,7 @@ class QuizSettingsActivity extends Activity {
734730

735731
/**
736732
* Helper to format coordinates for screen display
737-
*
733+
*
738734
* @param lat
739735
* @param lon
740736
* @return A string formatted accordingly
@@ -748,7 +744,7 @@ class QuizSettingsActivity extends Activity {
748744
/**
749745
* If location name can't be determined, try to determine location
750746
* based on current coords
751-
*
747+
*
752748
* @param strLocation
753749
* Location or place name to try
754750
*/
@@ -784,9 +780,8 @@ class QuizSettingsActivity extends Activity {
784780
}
785781

786782
/**
787-
*
788783
* Take a description of a location, store the coordinates in mFavPlaceCoords
789-
*
784+
*
790785
* @param strLocation
791786
* The location or placename to look up
792787
* @return true if the address or place was recognized, otherwise false

android-app-dev/TriviaQuiz/src/com/androidbook/triviaquiz/QuizWidgetProvider.scala

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ object QuizWidgetProvider {
6666
remoteView.setTextViewText(R.id.widget_nickname, widgetData.nickname)
6767
remoteView.setTextViewText(R.id.widget_score, "Score: " + widgetData.score)
6868
if (widgetData.avatarUrl.length > 0) {
69-
// remoteView.setImageViewUri(R.id.widget_image, Uri.parse(avatarUrl));
69+
// remoteView.setImageViewUri(R.id.widget_image, Uri.parse(avatarUrl))
7070
var image: URL = null
7171
try {
7272
image = new URL(widgetData.avatarUrl)
@@ -152,13 +152,12 @@ object QuizWidgetProvider {
152152
if (eventType == XmlPullParser.START_TAG) {
153153
val strName = parser.getName
154154

155-
if (strName equals "nickname") {
155+
if (strName equals "nickname")
156156
widgetData.nickname = parser.nextText
157-
} else if (strName equals "score") {
157+
else if (strName equals "score")
158158
widgetData.score = parser.nextText
159-
} else if (strName equals "avatarUrl") {
159+
else if (strName equals "avatarUrl")
160160
widgetData.avatarUrl = parser.nextText
161-
}
162161
}
163162
eventType = parser.next()
164163
} // while
@@ -194,7 +193,7 @@ object QuizWidgetProvider {
194193
/**
195194
* Copy the content of the input stream into the output stream, using
196195
* a temporary byte array buffer whose size is defined by {@link #IO_BUFFER_SIZE}.
197-
*
196+
*
198197
* @param in
199198
* The input stream to copy from.
200199
* @param out

0 commit comments

Comments
 (0)