Back to project page OpenHSK.
The source code is released under:
This work is licensed under a Creative Commons Attribution 3.0 Unported License. Original author of word lists: http://lingomi.com/ Original author of definitions: http://cc-cedict.org Original autho...
If you think the Android project OpenHSK listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package edu.openhsk.service; //from w ww . j ava 2 s . c o m import java.util.List; import java.util.Random; import android.util.Log; import edu.openhsk.models.QuizHanzi; import edu.openhsk.repository.DatabaseMetadata; public class QuizService { private static final String LOG_TAG = QuizService.class.getSimpleName(); public int chooseCorrectAnswer(List<QuizHanzi> quizWordList) { //randomizes index and answer if (quizWordList != null && quizWordList.size() == 4) { int randInt = -1; randInt = new Random(System.currentTimeMillis()).nextInt(4); int idOfAnswer = quizWordList.get(randInt).getId(); Log.d(LOG_TAG, "Index of answer: " + randInt + " Id of answer: " + idOfAnswer); return idOfAnswer; } else { throw new RuntimeException("List is null or has invalid number of elements"); } } public String getFilePathByWordList(int wordListId) { String filePath = ""; if (wordListId == DatabaseMetadata.WORD_LIST_ID_HSK1) { filePath = "hsk1_sounds/"; } else if (wordListId == DatabaseMetadata.WORD_LIST_ID_HSK2) { filePath = "hsk2_sounds/"; } return filePath; } public static int getCachedHighestId(int[] shuffledIds) { int max = -1; for (int i : shuffledIds) { if (i > max) max = i; } return max; } public static int[] unmarshallWordIds(String marshalledWordIds) { String[] splitWordIdStrings = marshalledWordIds.split(","); int[] wordIds = new int[splitWordIdStrings.length]; for (int i = 0; i < splitWordIdStrings.length; i++) { wordIds[i] = Integer.parseInt(splitWordIdStrings[i]); } return wordIds; } public static String marshallWordIds(int... wordIds) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < wordIds.length; i++) { if (i != 0) { sb.append(","); } sb.append(wordIds[i]); } return sb.toString(); } }