示例#1
0
 private void fillImageDataSolution() {
   boolean wasFilling = mFillingImageData;
   mFillingImageData = true;
   Tongue currentTongue = getCurrentTongue();
   if (currentTongue == null || mDisplayedImageIndex < 0) {
     return;
   }
   SelectedBitmap bitmap = getCurrentBitmap();
   if (bitmap == null) {
     return;
   }
   List<Solution> solutions = bitmap.mBuilder.getSolutions();
   mSolutionWords.setText("");
   if (solutions != null) {
     Solution curr = null;
     for (Solution sol : solutions) {
       if (sol.getTongue().equals(currentTongue)) {
         curr = sol;
         break;
       }
     }
     if (curr != null) {
       StringBuilder words = new StringBuilder();
       List<String> wordsList = curr.getWords();
       for (int i = 0; i < wordsList.size(); i++) {
         words.append(wordsList.get(i));
         if (i < wordsList.size() - 1) {
           words.append(",");
         }
       }
       mSolutionWords.setText(words.toString());
     }
   }
   mFillingImageData = wasFilling;
 }
示例#2
0
  private boolean updateCurrentSolutionWords() {
    Tongue currentTongue = getCurrentTongue();
    SelectedBitmap currentBitmap = getCurrentBitmap();
    if (currentBitmap == null || currentTongue == null) {
      return false;
    }
    String solutionWords = mSolutionWords.getText().toString();
    List<Solution> solutions = currentBitmap.mBuilder.getSolutions();
    int currentSolutionIndex;
    Solution currentSolution = null;
    if (solutions == null) {
      currentSolutionIndex = -1;
    } else {
      for (currentSolutionIndex = 0;
          currentSolutionIndex < solutions.size();
          currentSolutionIndex++) {
        currentSolution = solutions.get(currentSolutionIndex);
        if (currentSolution.getTongue().equals(currentTongue)) {
          break;
        }
        currentSolution = null;
      }
    }
    boolean updateStatus = false;
    if (TextUtils.isEmpty(solutionWords)) {
      if (currentSolution != null) {
        solutions.remove(currentSolutionIndex);
        if (solutions.isEmpty()) {
          currentBitmap.mBuilder.setSolutions(null);
          currentBitmap.mImage = null;
          updateStatus = true;
        }
      }
    } else {
      Solution newSolution = Solution.makeSolution(currentTongue, solutionWords.split(","));
      if (newSolution != null && solutions == null) {
        solutions = new ArrayList<>(mTongues.length);
        updateStatus = true;
      } else if (solutions != null && currentSolution != null) {
        solutions.remove(currentSolutionIndex);
      }
      if (newSolution != null) {
        solutions.add(newSolution);

        currentBitmap.mBuilder.setSolutions(solutions);
        if (currentBitmap.checkedBuild()) {
          updateStatus = true;
        }
      } else if (solutions != null && solutions.isEmpty()) {
        currentBitmap.mBuilder.setSolutions(null);
        currentBitmap.mImage = null;
        updateStatus = true;
      }
    }
    return updateStatus;
  }