コード例 #1
0
    @Override
    public void onViewPositionChanged(View changedView, int left, int top, int dx, int dy) {
      LogUtil.i(
          TAG,
          "onViewPositionChanged:" + "left:" + left + ",top:" + top + ",dx:" + dx + ",dy:" + dy);
      mTop = top;
      mDragOffset = (float) top / mDragRange;

      LogUtil.i(TAG, "onViewPositionChanged:" + "mDragOffset:" + mDragOffset);
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        mBgView.setAlpha(mDragOffset);
      }
      if (!isUnderEnterprise) {
        if (Constants.hasEnterpriseAccountLoggedIn()) {
          ImageLoader.getInstance()
              .displayImage(
                  Constants.userInfo.getEnterprise().getLogo(),
                  mHeaderView,
                  DisplayImageOptionsUtil.flagDisplayOpts);
          mBgView.setVisibility(View.GONE);
        } else {
          if (mDragOffset < 1) {
            mHeaderView.setImageResource(R.drawable.flag);
            mBgView.setVisibility(View.GONE);
          } else {
            mHeaderView.setImageResource(R.drawable.flag_up);
            mBgView.setVisibility(View.VISIBLE);
          }
        }
      } else {
        mHeaderView.setImageResource(R.drawable.flag);
        mBgView.setVisibility(View.GONE);
      }
      requestLayout();
    }
コード例 #2
0
  @Override
  public boolean onTouchEvent(MotionEvent event) {
    mDragHelper.processTouchEvent(event);

    final int action = event.getAction();
    final float x = event.getX();
    final float y = event.getY();

    // 触摸点是否落在HeaderView上
    boolean isHeaderViewUnder = mDragHelper.isViewUnder(mHeaderView, (int) x, (int) y);

    switch (action & MotionEventCompat.ACTION_MASK) {
      case MotionEvent.ACTION_DOWN:
        {
          mInitialMotionX = x;
          mInitialMotionY = y;
          break;
        }
      case MotionEvent.ACTION_UP:
        {
          final float dx = x - mInitialMotionX;
          final float dy = y - mInitialMotionY;
          final float slop = mDragHelper.getTouchSlop();

          LogUtil.i(TAG, "dx * dx + dy * dy = " + dx * dx + dy * dy);
          LogUtil.i(TAG, "slop * slop = " + slop * slop);
          LogUtil.i(TAG, "mDragOffset:" + mDragOffset);
          if (dx * dx + dy * dy < slop * slop && isHeaderViewUnder) {
            if (Constants.hasEnterpriseAccountLoggedIn()) {
              if (onFlagAreaExpandLis != null) {
                onFlagAreaExpandLis.onSAASCMSSwitch();
              }
            } else {
              if (mDragOffset == 0) {
                minimize();
              } else {
                maximize();
              }
            }
          } else {
            if (Constants.hasEnterpriseAccountLoggedIn()) {
              if (onFlagAreaExpandLis != null) {
                onFlagAreaExpandLis.onSAASCMSSwitch();
              }
            }
          }
          break;
        }
    }

    return isHeaderViewUnder && isViewHit(mHeaderView, (int) x, (int) y)
        || isViewHit(mContentView, (int) x, (int) y);
  }
コード例 #3
0
 @Override
 protected void onLayout(boolean changed, int l, int t, int r, int b) {
   mBgView.layout(l, t, r, b);
   int dragViewHeight = mHeaderView.getMeasuredHeight();
   int dragViewWidth = mHeaderView.getMeasuredWidth();
   mDragRange = mContentView.getMeasuredHeight(); // parentViewHeight -
   // dragViewHeight;
   if (Constants.hasEnterpriseAccountLoggedIn()) {
     mTop = 0;
   }
   LogUtil.d(
       TAG,
       "onLayout:"
           + "changed:"
           + changed
           + ",l:"
           + l
           + ",t:"
           + t
           + ",r:"
           + r
           + ",b:"
           + b
           + ",mDragRange"
           + mDragRange
           + ",mtop----"
           + mTop
           + " drageViewWidth----"
           + dragViewWidth
           + " dragViewHeight----"
           + dragViewHeight);
   mContentView.layout(0, 0, r, mTop);
   mHeaderView.layout(
       20, mTop + mHeaderView.getPaddingTop(), 20 + dragViewWidth, mTop + dragViewHeight);
 }
コード例 #4
0
  @Override
  protected void onFinishInflate() {
    LogUtil.d(TAG, "onFInishInflate");
    mHeaderView = (ImageView) findViewById(R.id.view_header);
    mContentView = findViewById(R.id.view_content);
    mBgView = new View(getContext());
    mBgView.setBackgroundResource(R.color.translucent);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
      mBgView.setAlpha(0.0f);
    }
    mBgView.setVisibility(View.GONE);
    mBgView.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            maximize();
          }
        });
    addView(mBgView, 0);

    if (isUnderEnterprise) {
      mHeaderView.setImageResource(R.drawable.flag);
    }
  }
コード例 #5
0
    @Override
    public void onViewReleased(View releasedChild, float xvel, float yvel) {
      LogUtil.i(TAG, "onViewReleased:" + "xvel:" + xvel + ",yvel:" + yvel);
      // yvel Fling产生的值,yvel > 0 则是快速往下Fling || yvel < 0 则是快速往上Fling

      int top = getPaddingTop();
      if (yvel > 0 || (yvel == 0 && mDragOffset > 0.4f) /* 后面这个小括号里判断处理拖动之后停下来但是未松手的情况 */) {
        top += mDragRange;
      }
      if (Constants.hasEnterpriseAccountLoggedIn()) {
        top = 0;
      }
      mDragHelper.settleCapturedViewAt(releasedChild.getLeft(), top);
      invalidate();
    }
コード例 #6
0
 public void onResume(boolean isUnderEnterprise) {
   this.isUnderEnterprise = isUnderEnterprise;
   if (isUnderEnterprise) {
     mHeaderView.setImageResource(R.drawable.flag);
   } else {
     if (Constants.hasEnterpriseAccountLoggedIn()) {
       LogUtil.e(TAG, "-------------------login--------------->>>>");
       ImageLoader.getInstance()
           .displayImage(
               Constants.userInfo.getEnterprise().getLogo(),
               mHeaderView,
               DisplayImageOptionsUtil.flagDisplayOpts);
     } else {
       mHeaderView.setImageResource(R.drawable.flag);
     }
   }
 }
コード例 #7
0
  @Override
  public boolean onInterceptTouchEvent(MotionEvent ev) {
    final int action = MotionEventCompat.getActionMasked(ev);

    if (action != MotionEvent.ACTION_DOWN) {
      mDragHelper.cancel();
      return super.onInterceptTouchEvent(ev);
    }

    if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) {
      mDragHelper.cancel();
      return false;
    }

    final float x = ev.getX();
    final float y = ev.getY();
    boolean interceptTap = false;

    switch (action) {
      case MotionEvent.ACTION_DOWN:
        mInitialMotionX = x;
        mInitialMotionY = y;
        interceptTap = mDragHelper.isViewUnder(mHeaderView, (int) x, (int) y);
        break;

      case MotionEvent.ACTION_MOVE:
        final float adx = Math.abs(x - mInitialMotionX);
        final float ady = Math.abs(y - mInitialMotionY);
        final int slop = mDragHelper.getTouchSlop();
        LogUtil.d(TAG, "adx:" + adx + " ady:" + ady + " slop:" + slop);
        if (ady > slop && adx > ady) {
          mDragHelper.cancel();
          return false;
        }
        break;
    }

    return mDragHelper.shouldInterceptTouchEvent(ev) || interceptTap;
  }