コード例 #1
0
  @SuppressLint("NewApi")
  private boolean IndicatorTouchEvent(final MotionEvent event) {
    switch (event.getActionMasked()) {
      case MotionEvent.ACTION_DOWN:
        if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
          // mScrollIndicator.findViewById(ID_PIN).setVisibility(View.VISIBLE);
          // mScrollIndicatorText.setVisibility(View.VISIBLE);
          toggleVisibilityCompat(false);
        } else mScrollIndicator.startAnimation(mFadeIn);
        mScrollIndicator.setPadding(0, 0, getWidth(), 0);
        scroll(event.getY());
        mScrolling = true;
        return true;
      case MotionEvent.ACTION_MOVE:
        scroll(event.getY());
        return true;
      case MotionEvent.ACTION_UP:
        if (mType == TYPE_INDICATOR_WITH_HANDLE || mType == TYPE_POPUP_WITH_HANDLE)
          mHandlebar.setSelected(false);

        if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
          mScrolling = false;
          toggleVisibilityCompat(true);
        } else mScrollIndicator.startAnimation(mFadeOut);
        return true;
      default:
        break;
    }
    return false;
  }
コード例 #2
0
  @SuppressLint("NewApi")
  private void scroll(final float height) {
    if (mType == TYPE_INDICATOR || mType == TYPE_INDICATOR_WITH_HANDLE) {
      float move = height - (mScrollIndicator.getHeight() / 2);

      if (move < 0) move = 0;
      else if (move > getHeight() - mScrollIndicator.getHeight())
        move = getHeight() - mScrollIndicator.getHeight();

      if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB)
        mScrollIndicator.startAnimation(moveCompat(move));
      else mScrollIndicator.setTranslationY(move);
    }

    if (mType == TYPE_INDICATOR_WITH_HANDLE || mType == TYPE_POPUP_WITH_HANDLE) {
      mHandlebar.setSelected(true);
      moveHandlebar(height - (mHandlebar.getHeight() / 2));
    }

    int postition = (int) ((height / getHeight()) * mItemCount);
    if (mList instanceof ExpandableListView) {
      final int grouppos =
          ExpandableListView.getPackedPositionGroup(
              ((ExpandableListView) mList).getExpandableListPosition(postition));
      if (grouppos != -1) mGroupPosition = grouppos;
    }

    if (postition < 0) postition = 0;
    else if (postition >= mItemCount) postition = mItemCount - 1;
    mScrollIndicatorText.setText(mScrollable.getIndicatorForPosition(postition, mGroupPosition));
    mList.setSelection(mScrollable.getScrollPosition(postition, mGroupPosition));
  }
コード例 #3
0
 private void toggleVisibilityCompat(final boolean visible) {
   if (mScrollIndicatorText != null) {
     mScrollIndicatorText.startAnimation(visible ? mFadeOut : mFadeIn);
   }
   if (mScrollIndicator != null) {
     mScrollIndicator.startAnimation(visible ? mFadeOut : mFadeIn);
   }
 }
コード例 #4
0
 private void hideIndicatorCompat() {
   if (mScrollIndicatorText != null) {
     mScrollIndicatorText.setVisibility(View.INVISIBLE);
     mScrollIndicatorText.startAnimation(mFadeOut);
   }
   if (mScrollIndicator != null) {
     mScrollIndicator.findViewById(ID_PIN).setVisibility(View.INVISIBLE);
     mScrollIndicator.startAnimation(mFadeOut);
   }
 }
コード例 #5
0
  @Override
  public boolean onTouchEvent(MotionEvent event) {
    if (mList.getAdapter() == null) return false;
    mItemCount = mList.getAdapter().getCount();
    if (mItemCount == 0) return false;

    if (event.getActionMasked() == MotionEvent.ACTION_CANCEL) {
      if (mType == TYPE_POPUP || mType == TYPE_POPUP_WITH_HANDLE) {
        if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
          mScrolling = false;
          mScrollIndicatorText.setVisibility(View.GONE);
        } else mScrollIndicatorText.startAnimation(mFadeOut);
      } else {
        if (mType == TYPE_INDICATOR_WITH_HANDLE || mType == TYPE_POPUP_WITH_HANDLE)
          mHandlebar.setSelected(false);

        if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
          mScrolling = false;
          toggleVisibilityCompat(true);
        } else mScrollIndicator.startAnimation(mFadeOut);
      }
    }

    switch (mType) {
      case TYPE_POPUP:
        return PopupTouchEvent(event);
      case TYPE_POPUP_WITH_HANDLE:
        return PopupTouchEvent(event);
      case TYPE_INDICATOR:
        return IndicatorTouchEvent(event);
      case TYPE_INDICATOR_WITH_HANDLE:
        return IndicatorTouchEvent(event);
      default:
        break;
    }
    return false;
  }