コード例 #1
0
ファイル: LetterListView.java プロジェクト: yqfs/AGOCAL
 @Override
 public boolean dispatchTouchEvent(MotionEvent event) {
   final int action = event.getAction();
   final float y = event.getY();
   final int oldChoose = choose;
   final OnTouchingLetterChangedListener listener = onTouchingLetterChangedListener;
   final int c = (int) (y / getHeight() * b.length);
   switch (action) {
     case MotionEvent.ACTION_DOWN:
       showBkg = true;
       if (oldChoose != c && listener != null) {
         if (c >= 0 && c < b.length) {
           listener.onTouchingLetterChanged(b[c]);
           choose = c;
           invalidate();
         }
       }
       break;
     case MotionEvent.ACTION_MOVE:
       if (oldChoose != c && listener != null) {
         if (c >= 0 && c < b.length) {
           listener.onTouchingLetterChanged(b[c]);
           choose = c;
           invalidate();
         }
       }
       break;
     case MotionEvent.ACTION_UP:
       showBkg = false;
       choose = -1;
       invalidate();
       break;
   }
   return true;
 }
コード例 #2
0
  @SuppressWarnings("deprecation")
  @Override
  public boolean dispatchTouchEvent(MotionEvent event) {
    final int action = event.getAction();
    final float y = event.getY(); // 点击y坐标
    final int oldChoose = choose;
    final OnTouchingLetterChangedListener listener = onTouchingLetterChangedListener;
    final int c = (int) (y / getHeight() * b.length); // 点击y坐标所占总高度的比例*b数组的长度就等于点击b中的个数.

    switch (action) {
      case MotionEvent.ACTION_UP:
        setBackgroundDrawable(new ColorDrawable(0x00000000));
        choose = -1; //
        invalidate();
        if (mTextDialog != null) {
          mTextDialog.setVisibility(View.INVISIBLE);
        }
        break;

      default:
        // 设置右侧字母列表[A,B,C,D,E....]的背景颜色
        setBackgroundResource(R.drawable.letter_sort_background);
        if (oldChoose != c) {
          if (c >= 0 && c < b.length) {
            if (listener != null) {
              listener.onTouchingLetterChanged(b[c]);
            }
            if (mTextDialog != null) {
              mTextDialog.setText(b[c]);
              mTextDialog.setVisibility(View.VISIBLE);
            }

            choose = c;
            invalidate();
          }
        }

        break;
    }
    return true;
  }
コード例 #3
0
  @Override
  public boolean dispatchTouchEvent(MotionEvent event) {
    final int action = event.getAction();
    float y = event.getY();
    final int oldChoose = choose;
    final OnTouchingLetterChangedListener listener = onTouchingLetterChangedListener;
    final int c = (int) (y / getHeight() * b.length);
    switch (action) {
      case MotionEvent.ACTION_UP:
        setBackgroundDrawable(new ColorDrawable(0x00000000));
        choose = -1; //
        invalidate();
        if (mTextDialog != null) {
          mTextDialog.setVisibility(View.INVISIBLE);
        }
        break;

      default:
        setBackgroundResource(R.drawable.scrollbar_bg);
        if (oldChoose != c) {
          if (c >= 0 && c < b.length) {
            if (listener != null) {
              listener.onTouchingLetterChanged(b[c]);
            }
            if (mTextDialog != null) {
              mTextDialog.setText(b[c]);
              mTextDialog.setVisibility(View.VISIBLE);
            }
            choose = c;
            invalidate();
          }
        }
        break;
    }
    return true;
  }