コード例 #1
0
  // Info retrieval
  private void GetInfo() {
    // Search mode
    if (m_info == null && m_word_search != null) m_info = m_word_search.Word();

    // View mode
    if (m_info == null && m_id >= 0 && m_section != null) {
      WordTrain entry = m_section.WordEntry(m_id);
      m_info = entry.Info();
      m_color_exists = true;
      m_color_level = entry.Score();
    }
  }
コード例 #2
0
  // Touch
  @Override
  public boolean onTouch(View view, MotionEvent event) {
    int eventCase = event.getAction() & MotionEvent.ACTION_MASK;
    if (eventCase == MotionEvent.ACTION_DOWN) {
      // keep track of where on the button we originally pressed in order
      // to tell if we've swiped
      touchX = event.getX();
    } else {
      if (eventCase == MotionEvent.ACTION_CANCEL) {
        return true;
      }

      float distanceFromTouchX = Math.abs(touchX - event.getX());

      // if we release our click without swiping much
      if (eventCase == MotionEvent.ACTION_UP) {
        if (distanceFromTouchX < DRAG_THRESHOLD_X) {
          onClick(view);
          view.performClick();
          return true;
        } else {
          return true;
        }
      }
      // if we swipe our a certain amount either left or right
      else if (eventCase == MotionEvent.ACTION_MOVE) {
        if (distanceFromTouchX > DRAG_THRESHOLD_X) {
          WordTrain entry = m_section.WordEntry(m_id);

          // if swipe right
          if (touchX < event.getX()) {
            entry.SetScore(DataTrainWord.TRAIN_LEVELS - 1);
          } else { // swipe left
            entry.SetScore(0);
          }

          // update the color on the view
          m_color_level = entry.Score();
          TextView view_score = (TextView) view.findViewById(R.id.score);
          updateViewColor(view_score);

          view.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
          return true;
        }
      }
    }
    return true;
  }