@Override
  public boolean onTouchEvent(MotionEvent event) {
    final int y = (int) event.getY();
    mBounceHack = false;

    switch (event.getAction()) {
      case MotionEvent.ACTION_UP:
        if (!isVerticalScrollBarEnabled()) {
          setVerticalScrollBarEnabled(true);
        }
        if (getFirstVisiblePosition() == 0 && mRefreshState != REFRESHING) {
          if ((mRefreshView.getBottom() >= mRefreshViewHeight || mRefreshView.getTop() >= 0)
              && mRefreshState == RELEASE_TO_REFRESH) {
            // Initiate the refresh
            mRefreshState = REFRESHING;
            prepareForRefresh();
            onRefresh();
          } else if (mRefreshView.getBottom() < mRefreshViewHeight || mRefreshView.getTop() <= 0) {
            // Abort refresh and scroll down below the refresh view
            resetHeader();
            setSelection(1);
          }
        }
        break;
      case MotionEvent.ACTION_DOWN:
        mLastMotionY = y;
        break;
      case MotionEvent.ACTION_MOVE:
        applyHeaderPadding(event);
        break;
    }
    return super.onTouchEvent(event);
  }
Example #2
0
  /**
   * 初始化摄像头
   *
   * @param surfaceHolder
   */
  private void initCamera(SurfaceHolder surfaceHolder) {
    try {
      CameraManager.get().openDriver(surfaceHolder);

      Point point = CameraManager.get().getCameraResolution();

      int x = mCropLayout.getLeft() * point.y / mContainer.getWidth();
      int y = mCropLayout.getTop() * point.x / mContainer.getHeight();

      int cropWidth = mCropLayout.getWidth() * point.y / mContainer.getWidth();
      int cropHeight = mCropLayout.getHeight() * point.x / mContainer.getHeight();

      setX(x);
      setY(y);
      setCropWidth(cropWidth);
      setCropHeight(cropHeight);
      // 设置是否需要截图
      // setNeedCapture(true);

    } catch (IOException | RuntimeException ioe) {
      return;
    }
    if (handler == null) {
      handler = new CaptureActivityHandler(CaptureActivity.this);
    }
  }
 // 监听滚动Y值变化,通过addView和removeView来实现悬停效果
 @Override
 public void onScroll(int scrollY) {
   // TODO Auto-generated method stub
   int mBuyLayout2ParentTop = Math.max(scrollY, mBuyLayout.getTop());
   mTopBuyLayout.layout(
       0,
       mBuyLayout2ParentTop,
       mTopBuyLayout.getWidth(),
       mBuyLayout2ParentTop + mTopBuyLayout.getHeight());
 }
  @Override
  public void onWindowFocusChanged(boolean hasFocus) {
    if (firstQuestion == true) {

      // Layout Variables
      glLeft = gridLayout.getLeft();
      Log.i("rlLeft", Integer.toString(glLeft));
      glTop = gridLayout.getTop();
      Log.i("rlTop", Integer.toString(glTop));
      glWidth = gridLayout.getWidth();
      Log.i("rlWidth", Float.toString(glWidth));
      glHeight = gridLayout.getHeight();
      Log.i("rlHeight", Float.toString(glHeight));

      glv.initGrid(glWidth, glHeight);

      setLinePositions(glv);

      // Init Skills Layout
      // Layout Variables
      slLeft = skillsLayout.getLeft();
      // Log.i("rlLeft", Integer.toString(glLeft));
      slTop = skillsLayout.getTop();
      // Log.i("rlTop", Integer.toString(glTop));
      slWidth = skillsLayout.getWidth();
      // Log.i("rlWidth", Float.toString(glWidth));
      slHeight = skillsLayout.getHeight();
      // Log.i("rlHeight", Float.toString(glHeight));

      coordNumbersX.bringToFront();
      coordNumbersY.bringToFront();
      brackets.bringToFront();

      initQuestion();
    }
  }
  @Override
  public void onScroll(
      AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
    // When the refresh view is completely visible, change the text to say
    // "Release to refresh..." and flip the arrow drawable.
    if (refreshOn) {

      if (mCurrentScrollState == SCROLL_STATE_TOUCH_SCROLL && mRefreshState != REFRESHING) {
        if (firstVisibleItem == 0) {
          mRefreshViewImage.setVisibility(View.VISIBLE);
          if ((mRefreshView.getBottom() >= mRefreshViewHeight + 20 || mRefreshView.getTop() >= 0)
              && mRefreshState != RELEASE_TO_REFRESH) {
            mRefreshViewText.setText("Release to refresh...");
            mRefreshViewImage.clearAnimation();
            mRefreshViewImage.startAnimation(mFlipAnimation);
            mRefreshState = RELEASE_TO_REFRESH;
          } else if (mRefreshView.getBottom() < mRefreshViewHeight + 20
              && mRefreshState != PULL_TO_REFRESH) {
            mRefreshViewText.setText("Pull to refresh...");
            if (mRefreshState != TAP_TO_REFRESH) {
              mRefreshViewImage.clearAnimation();
              mRefreshViewImage.startAnimation(mReverseFlipAnimation);
            }
            mRefreshState = PULL_TO_REFRESH;
          }
        } else {
          mRefreshViewImage.setVisibility(View.GONE);
          resetHeader();
        }
      } else if (mCurrentScrollState == SCROLL_STATE_FLING
          && firstVisibleItem == 0
          && mRefreshState != REFRESHING) {
        setSelection(1);
        mBounceHack = true;
      } else if (mBounceHack && mCurrentScrollState == SCROLL_STATE_FLING) {
        setSelection(1);
      }
    }

    if (mOnScrollListener != null) {
      mOnScrollListener.onScroll(view, firstVisibleItem, visibleItemCount, totalItemCount);
    }
  }