Android Open Source - OpenHSK Quiz Service






From Project

Back to project page OpenHSK.

License

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.

Java Source Code

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();
  }
}




Java Source Code List

edu.openhsk.CharacterListActivity.java
edu.openhsk.CharacterViewActivity.java
edu.openhsk.CreateWordActivity.java
edu.openhsk.CreateWordListActivity.java
edu.openhsk.ExamActivity.java
edu.openhsk.ExamResultActivity.java
edu.openhsk.MainActivity.java
edu.openhsk.QuizActivity.java
edu.openhsk.WordListSelectionActivity.java
edu.openhsk.adapters.WordListViewBinder.java
edu.openhsk.adapters.WordViewBinder.java
edu.openhsk.models.ExamResult.java
edu.openhsk.models.Hanzi.java
edu.openhsk.models.QuizHanzi.java
edu.openhsk.models.WordList.java
edu.openhsk.repository.DatabaseHelper.java
edu.openhsk.repository.DatabaseMetadata.java
edu.openhsk.repository.HanziRepository.java
edu.openhsk.repository.HelpfulCursor.java
edu.openhsk.repository.QuizRepository.java
edu.openhsk.repository.SimpleCursorLoader.java
edu.openhsk.repository.WordListRepository.java
edu.openhsk.service.QuizService.java
edu.openhsk.utils.AsyncSoundPlayer.java
edu.openhsk.utils.CSVExporter.java
edu.openhsk.utils.CSVParser.java
edu.openhsk.utils.PinyinReplacer.java
edu.openhsk.utils.SoundManager.java
edu.openhsk.views.BarGraph.java
edu.openhsk.views.Bar.java
edu.openhsk.views.ExamResultPieChart.java