@Override
  public void onChildDrawOver(
      Canvas c,
      RecyclerView recyclerView,
      RecyclerView.ViewHolder viewHolder,
      float dX,
      float dY,
      int actionState,
      boolean isCurrentlyActive) {
    super.onChildDrawOver(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);

    if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE) {
      View itemView = viewHolder.itemView;

      c.save();
      if (dX > 0) {
        c.clipRect(
            itemView.getLeft(), itemView.getTop(), itemView.getLeft() + dX, itemView.getBottom());
        c.translate(itemView.getLeft(), itemView.getTop());
      } else {
        c.clipRect(
            itemView.getRight() + dX, itemView.getTop(), itemView.getRight(), itemView.getBottom());
        c.translate(itemView.getRight() + dX, itemView.getTop());
      }

      mAdapter.onItemSwiping(c, viewHolder, dX, dY, isCurrentlyActive);
      c.restore();
    }
  }
  void getLayoutCache() {
    final RelativeLayout parent = (RelativeLayout) findViewById(R.id.parent);
    View view1 = (View) parent.findViewById(R.id.view1);
    View view2 = (View) parent.findViewById(R.id.view2);
    View view3 = (View) parent.findViewById(R.id.view3);
    View view4 = (View) parent.findViewById(R.id.view4);
    View view5 = (View) parent.findViewById(R.id.view5);
    View view12 = (View) parent.findViewById(R.id.view12);

    String firstColumn = view2.getLeft() + "," + view2.getRight();
    layoutCache.put(firstColumn, new HashMap<String, Integer>());
    String secondColumn = view1.getLeft() + "," + view1.getRight();
    layoutCache.put(secondColumn, new HashMap<String, Integer>());
    String thirdColumn = view4.getLeft() + "," + view4.getRight();
    layoutCache.put(thirdColumn, new HashMap<String, Integer>());
    String firstRow = view3.getTop() + "," + view3.getBottom();
    layoutCache.get(firstColumn).put(firstRow, 1);
    layoutCache.get(secondColumn).put(firstRow, 2);
    layoutCache.get(thirdColumn).put(firstRow, 3);
    String secondRow = view5.getTop() + "," + view5.getBottom();
    layoutCache.get(firstColumn).put(secondRow, 4);
    layoutCache.get(secondColumn).put(secondRow, 5);
    layoutCache.get(thirdColumn).put(secondRow, 6);
    String thirdRow = view12.getTop() + "," + view12.getBottom();
    layoutCache.get(firstColumn).put(thirdRow, 7);
    layoutCache.get(secondColumn).put(thirdRow, 8);
    layoutCache.get(thirdColumn).put(thirdRow, 9);
  }
  private void startAnimation(final boolean isLeft, final boolean isOpen, boolean staticDuration) {
    mToOpen = isOpen;
    int total;
    if (isLeft) {
      mTargetView = mLeftDrawer;
      mStartLeft = mLeftDrawer.getLeft();
      total = mLeftDrawer.getWidth();
      mEndLeft = mToOpen ? 0 : -total;
    } else {
      mTargetView = mRightDrawer;
      mStartLeft = mRightDrawer.getLeft();
      total = mRightDrawer.getWidth();
      mEndLeft = mToOpen ? getWidth() - total : getWidth();
    }

    if (mStartLeft == mEndLeft) {
      // No need to animate
      updateDrawerSlide(mTargetView, mToOpen ? 1.0f : 0.0f);
      updateDrawerState(mTargetView, mToOpen ? STATE_OPEN : STATE_CLOSED);
      if (mToOpen) dispatchOnDrawerOpened(mTargetView);
      else dispatchOnDrawerClosed(mTargetView);
      return;
    }

    mAnimator.setDuration(
        staticDuration ? ANIMATE_TIME : ANIMATE_TIME * Math.abs(mStartLeft - mEndLeft) / total);

    mAnimator.start();
  }
Example #4
0
  public void commOnTouchEvent(MotionEvent ev) {
    int action = ev.getAction();
    switch (action) {
      case MotionEvent.ACTION_DOWN:
        y = ev.getY();
        break;
      case MotionEvent.ACTION_UP:
        if (isNeedAnimation()) {
          animation();
        }
        break;
      case MotionEvent.ACTION_MOVE:
        final float preY = y;
        float nowY = ev.getY();
        int deltaY = (int) (preY - nowY) / size;

        y = nowY;
        if (isNeedMove()) {
          if (normal.isEmpty()) {
            normal.set(inner.getLeft(), inner.getTop(), inner.getRight(), inner.getBottom());
            return;
          }
          int yy = inner.getTop() - deltaY;

          inner.layout(inner.getLeft(), yy, inner.getRight(), inner.getBottom() - deltaY);
        }
        break;
      default:
        break;
    }
  }
  @Override
  protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    if (isInEditMode() || tabCount == 0) {
      return;
    }

    final int height = getHeight();

    // draw underline
    rectPaint.setColor(underlineColor);
    canvas.drawRect(0, height - underlineHeight, tabsContainer.getWidth(), height, rectPaint);

    // default: line below current tab
    View currentTab = tabsContainer.getChildAt(currentPosition);
    float lineLeft = currentTab.getLeft();
    float lineRight = currentTab.getRight();

    // if there is an offset, start interpolating left and right coordinates between current and
    // next tab
    if (currentPositionOffset > 0f && currentPosition < tabCount - 1) {

      View nextTab = tabsContainer.getChildAt(currentPosition + 1);
      final float nextTabLeft = nextTab.getLeft();
      final float nextTabRight = nextTab.getRight();

      lineLeft = (currentPositionOffset * nextTabLeft + (1f - currentPositionOffset) * lineLeft);
      lineRight = (currentPositionOffset * nextTabRight + (1f - currentPositionOffset) * lineRight);
    }

    // draw indicator line
    rectPaint.setColor(indicatorColor);
    canvas.drawRect(lineLeft, height - indicatorHeight, lineRight, height, rectPaint);
  }
    @Override
    public int clampViewPositionHorizontal(View child, int left, int dx) {

      if (!mIntercepted) return child.getLeft();

      if (child == mContentView || child == mShadow) {
        if (mLeftState == STATE_CLOSED && mRightState == STATE_CLOSED) {
          if (dx > 0 && mLeftDrawer != null && mLeftLockMode == LOCK_MODE_UNLOCKED) {
            slideLeftDrawer(dx);
            updateDrawerState(mLeftDrawer, STATE_SLIDING);
          } else if (dx < 0 && mRightDrawer != null && mRightLockMode == LOCK_MODE_UNLOCKED) {
            slideRightDrawer(dx);
            updateDrawerState(mRightDrawer, STATE_SLIDING);
          }
        } else if (mLeftState != STATE_CLOSED) {
          slideLeftDrawer(dx);
          updateDrawerState(mLeftDrawer, STATE_SLIDING);
        } else if (mRightState != STATE_CLOSED) {
          slideRightDrawer(dx);
          updateDrawerState(mRightDrawer, STATE_SLIDING);
        }
        return child.getLeft();

      } else if (child == mLeftDrawer) {
        updateDrawerState(mLeftDrawer, STATE_SLIDING);
        return child.getLeft() + getActualDxLeft(dx);

      } else if (child == mRightDrawer) {
        updateDrawerState(mRightDrawer, STATE_SLIDING);
        return child.getLeft() + getActualDxRight(dx);

      } else {
        return child.getLeft();
      }
    }
Example #7
0
  @Override
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    int count = getChildCount();

    int start = 0;
    int currentLineWidth = 0;
    int currentLineHeight = 0;

    int totalHeight = 0;
    int totalWeight = 0;

    for (int i = 0; i < count; i++) {
      final View child = getChildAt(i);
      measureChildWithMargins(child, widthMeasureSpec, 0, heightMeasureSpec, 0);
      final LayoutParams lp = (LayoutParams) child.getLayoutParams();
      if (i == 0) { // first one
        start = child.getLeft();
        currentLineWidth = child.getMeasuredWidth() + lp.leftMargin + lp.rightMargin;
        currentLineHeight = child.getMeasuredHeight() + lp.topMargin + lp.bottomMargin;
      }
      if (child.getLeft() != start) { // not the last
        currentLineHeight =
            Math.max(currentLineHeight, child.getMeasuredHeight() + lp.topMargin + lp.bottomMargin);
        currentLineWidth += child.getMeasuredWidth() + lp.leftMargin + lp.rightMargin;
      } else { // the last one
        totalHeight += currentLineHeight;
        totalWeight = Math.max(currentLineWidth, totalWeight);
        currentLineWidth = child.getMeasuredWidth() + lp.leftMargin + lp.rightMargin;
        currentLineHeight = child.getMeasuredHeight() + lp.topMargin + lp.bottomMargin;
      }
    }
    setMeasuredDimension(
        resolveSize(totalWeight, widthMeasureSpec), resolveSize(totalHeight, heightMeasureSpec));
  }
    @Override
    public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
      super.onScrolled(recyclerView, dx, dy);

      int childCount = recyclerView.getChildCount();
      int width = recyclerView.getChildAt(0).getWidth();
      int padding = (recyclerView.getWidth() - width) / 2;

      for (int i = 0; i < childCount; i++) {
        View view = recyclerView.getChildAt(i);

        float ratio = 0;

        if (view.getLeft() <= padding) {
          if (view.getLeft() >= padding - view.getWidth()) {
            ratio = (padding - view.getLeft()) * 1f / view.getWidth();
          } else {
            ratio = 1;
          }
          view.setScaleY(1 - ratio * 0.5f);
          view.setScaleX(1 - ratio * 0.5f);

        } else {

          if (view.getLeft() <= recyclerView.getWidth() - padding) {
            ratio = (recyclerView.getWidth() - padding - view.getLeft()) * 1f / view.getWidth();
          }
          view.setScaleY(0.5f + ratio * 0.5f);
          view.setScaleX(0.5f + ratio * 0.5f);
        }
      }
    }
Example #9
0
  private void fillToGalleryLeftLtr() {
    final int itemSpacing = mSpacing;
    final int galleryLeft = getPaddingLeft();

    // Set state for initial iteration
    View prevIterationView = getChildAt(0);
    int curPosition;
    int curRightEdge;

    if (prevIterationView != null) {
      curPosition = mFirstPosition - 1;
      curRightEdge = prevIterationView.getLeft() - itemSpacing;
    } else {
      // No children available!
      curPosition = 0;
      curRightEdge = getRight() - getLeft() - getPaddingRight();
      mShouldStopFling = true;
    }

    while (curRightEdge > galleryLeft && curPosition >= 0) {
      prevIterationView =
          makeAndAddView(curPosition, curPosition - mSelectedPosition, curRightEdge, false);

      // Remember some state
      mFirstPosition = curPosition;

      // Set state for next iteration
      curRightEdge = prevIterationView.getLeft() - itemSpacing;
      curPosition--;
    }
  }
  private void fillToGalleryLeft() {
    int itemSpacing = 0;
    int galleryLeft = getScreenScrollPositionX(mCurrentScreen - 3);

    // Set state for initial iteration
    View prevIterationView = getChildAt(0);
    int curPosition;
    int curRightEdge;

    if (prevIterationView != null) {
      curPosition = mFirstPosition - 1;
      curRightEdge = prevIterationView.getLeft() - itemSpacing;
    } else {
      // No children available!
      curPosition = 0;
      curRightEdge = getRight() - getLeft() - getPaddingRight();
    }

    while (curRightEdge > galleryLeft && curPosition >= 0) {
      prevIterationView =
          makeAndAddView(curPosition, curPosition - mCurrentScreen, curRightEdge, false);

      // Remember some state
      mFirstPosition = curPosition;

      // Set state for next iteration
      curRightEdge = prevIterationView.getLeft() - itemSpacing;
      curPosition--;
    }
  }
Example #11
0
  public boolean arrowScroll(int direction) {
    View currentFocused = findFocus();
    if (currentFocused == this) currentFocused = null;

    boolean handled = false;

    View nextFocused = FocusFinder.getInstance().findNextFocus(this, currentFocused, direction);
    if (nextFocused != null && nextFocused != currentFocused) {
      if (direction == View.FOCUS_LEFT) {
        handled = nextFocused.requestFocus();
      } else if (direction == View.FOCUS_RIGHT) {
        // If there is nothing to the right, or this is causing us to
        // jump to the left, then what we really want to do is page right.
        if (currentFocused != null && nextFocused.getLeft() <= currentFocused.getLeft()) {
          handled = pageRight();
        } else {
          handled = nextFocused.requestFocus();
        }
      }
    } else if (direction == FOCUS_LEFT || direction == FOCUS_BACKWARD) {
      // Trying to move left and nothing there; try to page.
      handled = pageLeft();
    } else if (direction == FOCUS_RIGHT || direction == FOCUS_FORWARD) {
      // Trying to move right and nothing there; try to page.
      handled = pageRight();
    }
    if (handled) {
      playSoundEffect(SoundEffectConstants.getContantForFocusDirection(direction));
    }
    return handled;
  }
  private int getTouchZone(MotionEvent event) {
    if (mTouchZonesAccurate) {
      int x = (int) event.getX();
      if (x < mLeftZoneEdge && mDisplayedPage > 0) {
        return LEFT_ZONE;
      } else if (x > mLeftZoneEdge && x < mRightZoneEdge) {
        return MIDDLE_ZONE;
      } else if (x > mRightZoneEdge && mDisplayedPage < getChildCount() - 1) {
        return RIGHT_ZONE;
      }
    } else {
      View middleChild = getChildAt(mDisplayedPage);
      int mLeft = middleChild.getLeft();
      int mRight = middleChild.getRight();

      View leftChild = getChildAt(mDisplayedPage - 1);
      int lRight = leftChild != null ? leftChild.getRight() : -1;

      View rightChild = getChildAt(mDisplayedPage + 1);
      int rLeft = rightChild != null ? rightChild.getLeft() : -1;

      mLeftZoneEdge = lRight < 0 ? 0 : lRight + ((mLeft - lRight) / 2);
      mRightZoneEdge = rLeft < 0 ? getWidth() : rLeft - ((rLeft - mRight) / 2);
      mTouchZonesAccurate = true;
      return getTouchZone(event);
    }
    return MIDDLE_ZONE;
  }
Example #13
0
  private void fillToGalleryLeftRtl() {
    final int itemSpacing = mSpacing;
    final int galleryLeft = getPaddingLeft();
    final int numChildren = getChildCount();

    // Set state for initial iteration
    View prevIterationView = getChildAt(numChildren - 1);
    int curPosition;
    int curRightEdge;

    if (prevIterationView != null) {
      curPosition = mFirstPosition + numChildren;
      curRightEdge = prevIterationView.getLeft() - itemSpacing;
    } else {
      // No children available!
      mFirstPosition = curPosition = mItemCount - 1;
      curRightEdge = getRight() - getLeft() - getPaddingRight();
      mShouldStopFling = true;
    }

    while (curRightEdge > galleryLeft && curPosition < mItemCount) {
      prevIterationView =
          makeAndAddView(curPosition, curPosition - mSelectedPosition, curRightEdge, false);

      // Set state for next iteration
      curRightEdge = prevIterationView.getLeft() - itemSpacing;
      curPosition++;
    }
  }
  @Override
  protected void onDraw(Canvas canvas) {
    final int height = getHeight();
    final int childCount = getChildCount();
    final SlidingTabLayout.TabColorizer tabColorizer =
        mCustomTabColorizer != null ? mCustomTabColorizer : mDefaultTabColorizer;

    // Thick colored underline below the current selection
    if (childCount > 0) {
      View selectedTitle = getChildAt(mSelectedPosition);
      int left = selectedTitle.getLeft();
      int right = selectedTitle.getRight();
      int color = tabColorizer.getIndicatorColor(mSelectedPosition);

      if (mSelectionOffset > 0f && mSelectedPosition < (getChildCount() - 1)) {
        int nextColor = tabColorizer.getIndicatorColor(mSelectedPosition + 1);
        if (color != nextColor) {
          color = blendColors(nextColor, color, mSelectionOffset);
        }

        // Draw the selection partway between the tabs
        View nextTitle = getChildAt(mSelectedPosition + 1);
        left = (int) (mSelectionOffset * nextTitle.getLeft() + (1.0f - mSelectionOffset) * left);
        right = (int) (mSelectionOffset * nextTitle.getRight() + (1.0f - mSelectionOffset) * right);
      }

      mSelectedIndicatorPaint.setColor(color);

      canvas.drawRect(
          left, height - mSelectedIndicatorThickness, right, height, mSelectedIndicatorPaint);
    }

    // Thin underline along the entire bottom edge
    canvas.drawRect(0, height - mBottomBorderThickness, getWidth(), height, mBottomBorderPaint);
  }
  private void trySlideAttachmentView(final ViewWrapper viewWrapper) {
    if (!(viewWrapper.attachment instanceof MediaPickerMessagePartData)) {
      return;
    }
    final View view = viewWrapper.view;

    final int xOffset = viewWrapper.prevLeft - view.getLeft();
    final int yOffset = viewWrapper.prevTop - view.getTop();
    final float scaleX = viewWrapper.prevWidth / (float) view.getWidth();
    final float scaleY = viewWrapper.prevHeight / (float) view.getHeight();

    if (xOffset == 0 && yOffset == 0 && scaleX == 1 && scaleY == 1) {
      // Layout hasn't changed
      return;
    }

    final AnimationSet animationSet = new AnimationSet(true /* shareInterpolator */);
    animationSet.addAnimation(new TranslateAnimation(xOffset, 0, yOffset, 0));
    animationSet.addAnimation(new ScaleAnimation(scaleX, 1, scaleY, 1));
    animationSet.setDuration(UiUtils.MEDIAPICKER_TRANSITION_DURATION);
    animationSet.setInterpolator(UiUtils.DEFAULT_INTERPOLATOR);
    view.startAnimation(animationSet);
    view.invalidate();
    viewWrapper.prevLeft = view.getLeft();
    viewWrapper.prevTop = view.getTop();
    viewWrapper.prevWidth = view.getWidth();
    viewWrapper.prevHeight = view.getHeight();
  }
  private void calcIndicatorRect() {
    View currentTabView = mTabsContainer.getChildAt(this.mCurrentTab);
    float left = currentTabView.getLeft();
    float right = currentTabView.getRight();

    // for mIndicatorWidthEqualTitle
    if (mIndicatorStyle == STYLE_NORMAL && mIndicatorWidthEqualTitle) {
      TextView tab_title = (TextView) currentTabView.findViewById(R.id.tv_tab_title);
      mTextPaint.setTextSize(mTextsize);
      float textWidth = mTextPaint.measureText(tab_title.getText().toString());
      margin = (right - left - textWidth) / 2;
    }

    if (this.mCurrentTab < mTabCount - 1) {
      View nextTabView = mTabsContainer.getChildAt(this.mCurrentTab + 1);
      float nextTabLeft = nextTabView.getLeft();
      float nextTabRight = nextTabView.getRight();

      left = left + mCurrentPositionOffset * (nextTabLeft - left);
      right = right + mCurrentPositionOffset * (nextTabRight - right);

      // for mIndicatorWidthEqualTitle
      if (mIndicatorStyle == STYLE_NORMAL && mIndicatorWidthEqualTitle) {
        TextView next_tab_title = (TextView) nextTabView.findViewById(R.id.tv_tab_title);
        mTextPaint.setTextSize(mTextsize);
        float nextTextWidth = mTextPaint.measureText(next_tab_title.getText().toString());
        float nextMargin = (nextTabRight - nextTabLeft - nextTextWidth) / 2;
        margin = margin + mCurrentPositionOffset * (nextMargin - margin);
      }
    }

    mIndicatorRect.left = (int) left;
    mIndicatorRect.right = (int) right;
    // for mIndicatorWidthEqualTitle
    if (mIndicatorStyle == STYLE_NORMAL && mIndicatorWidthEqualTitle) {
      mIndicatorRect.left = (int) (left + margin - 1);
      mIndicatorRect.right = (int) (right - margin - 1);
    }

    mTabRect.left = (int) left;
    mTabRect.right = (int) right;

    if (mIndicatorWidth < 0) { // indicatorWidth小于0时,原jpardogo's PagerSlidingTabStrip

    } else { // indicatorWidth大于0时,圆角矩形以及三角形
      float indicatorLeft =
          currentTabView.getLeft() + (currentTabView.getWidth() - mIndicatorWidth) / 2;

      if (this.mCurrentTab < mTabCount - 1) {
        View nextTab = mTabsContainer.getChildAt(this.mCurrentTab + 1);
        indicatorLeft =
            indicatorLeft
                + mCurrentPositionOffset * (currentTabView.getWidth() / 2 + nextTab.getWidth() / 2);
      }

      mIndicatorRect.left = (int) indicatorLeft;
      mIndicatorRect.right = (int) (mIndicatorRect.left + mIndicatorWidth);
    }
  }
Example #17
0
  private void drawDebugInfo(Canvas canvas, View child) {
    if (!debugDraw) {
      return;
    }

    Paint childPaint = this.createPaint(0xffffff00);
    Paint layoutPaint = this.createPaint(0xff00ff00);
    Paint newLinePaint = this.createPaint(0xffff0000);

    LayoutParams lp = (LayoutParams) child.getLayoutParams();

    if (lp.horizontalSpacing > 0) {
      float x = child.getRight();
      float y = child.getTop() + child.getHeight() / 2.0f;
      canvas.drawLine(x, y, x + lp.horizontalSpacing, y, childPaint);
      canvas.drawLine(
          x + lp.horizontalSpacing - 4.0f, y - 4.0f, x + lp.horizontalSpacing, y, childPaint);
      canvas.drawLine(
          x + lp.horizontalSpacing - 4.0f, y + 4.0f, x + lp.horizontalSpacing, y, childPaint);
    } else if (this.horizontalSpacing > 0) {
      float x = child.getRight();
      float y = child.getTop() + child.getHeight() / 2.0f;
      canvas.drawLine(x, y, x + this.horizontalSpacing, y, layoutPaint);
      canvas.drawLine(
          x + this.horizontalSpacing - 4.0f, y - 4.0f, x + this.horizontalSpacing, y, layoutPaint);
      canvas.drawLine(
          x + this.horizontalSpacing - 4.0f, y + 4.0f, x + this.horizontalSpacing, y, layoutPaint);
    }

    if (lp.verticalSpacing > 0) {
      float x = child.getLeft() + child.getWidth() / 2.0f;
      float y = child.getBottom();
      canvas.drawLine(x, y, x, y + lp.verticalSpacing, childPaint);
      canvas.drawLine(
          x - 4.0f, y + lp.verticalSpacing - 4.0f, x, y + lp.verticalSpacing, childPaint);
      canvas.drawLine(
          x + 4.0f, y + lp.verticalSpacing - 4.0f, x, y + lp.verticalSpacing, childPaint);
    } else if (this.verticalSpacing > 0) {
      float x = child.getLeft() + child.getWidth() / 2.0f;
      float y = child.getBottom();
      canvas.drawLine(x, y, x, y + this.verticalSpacing, layoutPaint);
      canvas.drawLine(
          x - 4.0f, y + this.verticalSpacing - 4.0f, x, y + this.verticalSpacing, layoutPaint);
      canvas.drawLine(
          x + 4.0f, y + this.verticalSpacing - 4.0f, x, y + this.verticalSpacing, layoutPaint);
    }

    if (lp.newLine) {
      if (orientation == HORIZONTAL) {
        float x = child.getLeft();
        float y = child.getTop() + child.getHeight() / 2.0f;
        canvas.drawLine(x, y - 6.0f, x, y + 6.0f, newLinePaint);
      } else {
        float x = child.getLeft() + child.getWidth() / 2.0f;
        float y = child.getTop();
        canvas.drawLine(x - 6.0f, y, x + 6.0f, y, newLinePaint);
      }
    }
  }
Example #18
0
 public int getAbsRightBound(View content) {
   if (mMode == SlidingMenu.LEFT) {
     return content.getLeft();
   } else if (mMode == SlidingMenu.RIGHT || mMode == SlidingMenu.LEFT_RIGHT) {
     return content.getLeft() + getBehindWidth();
   }
   return 0;
 }
 public void smoothOpenMenu() {
   state = STATE_OPEN;
   if (mSwipeDirection == SwipeMenuRecyclerView.DIRECTION_LEFT) {
     mOpenScroller.startScroll(-mContentView.getLeft(), 0, mMenuView.getWidth(), 0, animDuration);
   } else {
     mOpenScroller.startScroll(mContentView.getLeft(), 0, mMenuView.getWidth(), 0, animDuration);
   }
   postInvalidate();
 }
 void drawDividersHorizontal(Canvas paramCanvas)
 {
   int k = getVirtualChildCount();
   boolean bool = ViewUtils.isLayoutRtl(this);
   int i = 0;
   View localView;
   LinearLayoutCompat.LayoutParams localLayoutParams;
   if (i < k)
   {
     localView = getVirtualChildAt(i);
     if ((localView != null) && (localView.getVisibility() != 8) && (hasDividerBeforeChildAt(i)))
     {
       localLayoutParams = (LinearLayoutCompat.LayoutParams)localView.getLayoutParams();
       if (!bool) {
         break label92;
       }
       j = localView.getRight();
     }
     label92:
     for (int j = rightMargin + j;; j = localView.getLeft() - leftMargin - mDividerWidth)
     {
       drawVerticalDivider(paramCanvas, j);
       i += 1;
       break;
     }
   }
   if (hasDividerBeforeChildAt(k))
   {
     localView = getVirtualChildAt(k - 1);
     if (localView != null) {
       break label171;
     }
     if (!bool) {
       break label153;
     }
     i = getPaddingLeft();
   }
   for (;;)
   {
     drawVerticalDivider(paramCanvas, i);
     return;
     label153:
     i = getWidth() - getPaddingRight() - mDividerWidth;
     continue;
     label171:
     localLayoutParams = (LinearLayoutCompat.LayoutParams)localView.getLayoutParams();
     if (bool)
     {
       i = localView.getLeft() - leftMargin - mDividerWidth;
     }
     else
     {
       i = localView.getRight();
       i = rightMargin + i;
     }
   }
 }
 private Rect getScrollBounds(View v) {
   // There can be scroll amounts not yet accounted for in
   // onLayout, so add mXScroll and mYScroll to the current
   // positions when calculating the bounds.
   return getScrollBounds(
       v.getLeft() + mXScroll,
       v.getTop() + mYScroll,
       v.getLeft() + v.getMeasuredWidth() + mXScroll,
       v.getTop() + v.getMeasuredHeight() + mYScroll);
 }
Example #22
0
 @Override
 protected void dispatchDraw(Canvas canvas) {
   super.dispatchDraw(canvas);
   View localView1 = getChildAt(0);
   int column = getWidth() / localView1.getWidth();
   int childCount = getChildCount();
   Paint localPaint;
   localPaint = new Paint();
   localPaint.setStyle(Paint.Style.STROKE);
   localPaint.setColor(getContext().getResources().getColor(R.color.grid_line));
   for (int i = 0; i < childCount; i++) {
     View cellView = getChildAt(i);
     if ((i + 1) % column == 0) {
       canvas.drawLine(
           cellView.getLeft(),
           cellView.getBottom(),
           cellView.getRight(),
           cellView.getBottom(),
           localPaint);
     } else if ((i + 1) > (childCount - (childCount % column))) {
       canvas.drawLine(
           cellView.getRight(),
           cellView.getTop(),
           cellView.getRight(),
           cellView.getBottom(),
           localPaint);
     } else {
       canvas.drawLine(
           cellView.getRight(),
           cellView.getTop(),
           cellView.getRight(),
           cellView.getBottom(),
           localPaint);
       canvas.drawLine(
           cellView.getLeft(),
           cellView.getBottom(),
           cellView.getRight(),
           cellView.getBottom(),
           localPaint);
     }
   }
   if (childCount % column != 0) {
     for (int j = 0; j < (column - childCount % column); j++) {
       View lastView = getChildAt(childCount - 1);
       canvas.drawLine(
           lastView.getRight() + lastView.getWidth() * j,
           lastView.getTop(),
           lastView.getRight() + lastView.getWidth() * j,
           lastView.getBottom(),
           localPaint);
     }
   }
 }
Example #23
0
  public void commOnTouchEvent(MotionEvent ev) {
    int action = ev.getAction();
    switch (action) {
      case MotionEvent.ACTION_DOWN:
        y = ev.getY();
        break;
      case MotionEvent.ACTION_UP:
        if (isNeedAnimation()) {
          animation();
        }

        // 加入额外代码
        if (mAutoScrollViewPager != null) {
          mAutoScrollViewPager.startAutoScroll();
        }

        y = DEFAULT_POSITION;
        break;

        /**
         * 排除第一次移动计算,因为第一次无法得知y左边,在MotionEvent.ACTION_DOWN中获取不到,
         * 因为此时是MyScrollView的Tocuh时间传递到了ListView的孩子item上面。所以从第二次开始计算
         * 然而我们也要进行初始化,就是第一次移动的时候让滑动距离归零,之后记录准确了就正常执行
         */
      case MotionEvent.ACTION_MOVE:
        float preY = y;
        float nowY = ev.getY();
        if (isDefaultPosition(y)) {
          preY = nowY;
        }
        int deltaY = (int) (preY - nowY);
        scrollBy(0, deltaY);
        y = nowY;
        // 当滚动到最上或者最下时就不会再滚动,这时移动布局
        if (isNeedMove()) {
          if (normal.isEmpty()) {
            // 保存正常的布局位置
            normal.set(inner.getLeft(), inner.getTop(), inner.getRight(), inner.getBottom());
          }
          // 移动布局
          inner.layout(
              inner.getLeft(),
              inner.getTop() - deltaY / 2,
              inner.getRight(),
              inner.getBottom() - deltaY / 2);
        }
        break;

      default:
        break;
    }
  }
Example #24
0
 protected Rect getRelativePosition(View child) {
   View t = child;
   Rect r = new Rect(t.getLeft(), t.getTop(), 0, 0);
   while (t.getParent() != null && t != getRootView()) {
     t = (View) t.getParent();
     if (t == this) break;
     r.left += t.getLeft();
     r.top += t.getTop();
   }
   r.right = r.left + child.getMeasuredWidth();
   r.bottom = r.top + child.getMeasuredHeight();
   return r;
 }
Example #25
0
        @Override
        public void onViewReleased(View releasedChild, float xvel, float yvel) {
          super.onViewReleased(releasedChild, xvel, yvel);
          Log.d(VIEW_LOG_TAG, "xvel " + xvel + "," + " yvel " + yvel);
          // use settleCaptureViewAt() method
          //            if (yvel > 0) {
          //                mViewDragHelper.settleCapturedViewAt(releasedChild.getLeft(),
          // getHeight() - releasedChild.getHeight() - getPaddingBottom());
          //            } else {
          //                mViewDragHelper.settleCapturedViewAt(releasedChild.getLeft(),
          // getPaddingTop());
          //            }
          //            invalidate();

          // or use smoothSlideViewTo method
          //            int half = (getHeight() - getPaddingTop() - getPaddingBottom()) / 2;
          //            int current = (releasedChild.getTop() + releasedChild.getBottom()) / 2;
          //            boolean settled;
          //            if (current >= half) {
          //                settled = mViewDragHelper.smoothSlideViewTo(releasedChild,
          // releasedChild.getLeft(),
          //                        getHeight() + childOffset - releasedChild.getHeight() -
          // getPaddingBottom());
          //            } else {
          //                settled = mViewDragHelper
          //                        .smoothSlideViewTo(releasedChild, releasedChild.getLeft(),
          // getPaddingTop());
          //            }
          //            if (settled) {
          //                invalidate();
          //            }
          boolean settled;
          if (yvel > 0) {
            // 往下拖,直接吸到底部
            settled =
                mViewDragHelper.smoothSlideViewTo(
                    releasedChild,
                    releasedChild.getLeft(),
                    getHeight() + childOffset - releasedChild.getHeight() - getPaddingBottom());
          } else {
            // 往上托,全部露出
            settled =
                mViewDragHelper.smoothSlideViewTo(
                    releasedChild,
                    releasedChild.getLeft(),
                    getHeight() - releasedChild.getHeight() - getPaddingBottom());
          }
          if (settled) {
            invalidate();
          }
        }
Example #26
0
  private static void updateForView(final RFBClient client, View view) {
    view.setDrawingCacheEnabled(true);
    // view.destroyDrawingCache();
    //		view.buildLayer();

    //		Bitmap bm = Bitmap.createBitmap( view.getMeasuredWidth(), view.getMeasuredHeight(),
    // Bitmap.Config.ARGB_8888);
    //		Canvas c = new Canvas(bm);
    //		view.invalidate();
    //		view.forceLayout();
    //		view.layout(0, 0, view.getLayoutParams().width, view.getLayoutParams().height);
    //		view.draw(c);
    //
    // view.getDrawingCache();
    Bitmap cache = view.getDrawingCache();
    //		Canvas renderC = new Canvas(cache);
    // view.destroyDrawingCache();
    //		view.layout(0, 0, cache.getWidth(), cache.getHeight());
    //		view.draw(renderC);
    // view.buildDrawingCache(false);

    int[] location = new int[2];
    view.getLocationOnScreen(location);
    int[] pixels = new int[cache.getWidth() * cache.getHeight()];
    cache.getPixels(
        pixels,
        0,
        cache.getWidth(),
        view.getLeft(),
        view.getTop(),
        cache.getWidth(),
        cache.getHeight());
    Rect rect =
        Rect.encode(
            client.getPreferredEncoding(),
            pixels,
            client.getPixelFormat(),
            cache.getWidth(),
            view.getLeft(),
            view.getTop(),
            cache.getWidth(),
            cache.getHeight());
    rect.transform(location[0], location[1]);
    Rect[] rects = {rect};

    try {
      client.writeFrameBufferUpdate(rects);
    } catch (IOException e) {
      Log.e("RemoteDisplay", "error while sending update rect", e);
    }
  }
  private void drawScrim(Canvas canvas, View child) {
    final int baseAlpha = (mScrimColor & 0xff000000) >>> 24;
    final int alpha = (int) (baseAlpha * mScrimOpacity);
    final int color = alpha << 24 | (mScrimColor & 0xffffff);

    if ((mTrackingEdge & EDGE_LEFT) != 0) {
      canvas.clipRect(0, 0, child.getLeft(), getHeight());
    } else if ((mTrackingEdge & EDGE_RIGHT) != 0) {
      canvas.clipRect(child.getRight(), 0, getRight(), getHeight());
    } else if ((mTrackingEdge & EDGE_BOTTOM) != 0) {
      canvas.clipRect(child.getLeft(), child.getBottom(), getRight(), getHeight());
    }
    canvas.drawColor(color);
  }
  @Override
  protected void onDraw(Canvas canvas) {
    final int height = getHeight();
    final int childCount = getChildCount();
    final int dividerHeightPx = (int) (Math.min(Math.max(0f, mDividerHeight), 1f) * height);
    final SlidingTabLayout.TabColorizer tabColorizer =
        mCustomTabColorizer != null ? mCustomTabColorizer : mDefaultTabColorizer;

    // Thick colored underline below the current selection
    if (childCount > 0) {
      View selectedTitle = getChildAt(mSelectedPosition);
      int left = selectedTitle.getLeft();
      int right = selectedTitle.getRight();
      int color = tabColorizer.getIndicatorColor(mSelectedPosition);

      if (mSelectionOffset > 0f && mSelectedPosition < (getChildCount() - 1)) {
        int nextColor = tabColorizer.getIndicatorColor(mSelectedPosition + 1);
        if (color != nextColor) {
          color = blendColors(nextColor, color, mSelectionOffset);
        }

        // Draw the selection partway between the tabs
        View nextTitle = getChildAt(mSelectedPosition + 1);
        left = (int) (mSelectionOffset * nextTitle.getLeft() + (1.0f - mSelectionOffset) * left);
        right = (int) (mSelectionOffset * nextTitle.getRight() + (1.0f - mSelectionOffset) * right);
      }

      mSelectedIndicatorPaint.setColor(color);

      canvas.drawRect(
          left, height - mSelectedIndicatorThickness, right, height, mSelectedIndicatorPaint);
    }

    // Thin underline along the entire bottom edge
    canvas.drawRect(0, height - mBottomBorderThickness, getWidth(), height, mBottomBorderPaint);

    // Vertical separators between the titles
    int separatorTop = (height - dividerHeightPx) / 2;
    for (int i = 0; i < childCount - 1; i++) {
      View child = getChildAt(i);
      mDividerPaint.setColor(tabColorizer.getDividerColor(i));
      canvas.drawLine(
          child.getRight(),
          separatorTop,
          child.getRight(),
          separatorTop + dividerHeightPx,
          mDividerPaint);
    }
  }
Example #29
0
  private void blur(Bitmap bg, View view) {
    long startMs = System.currentTimeMillis();

    float radius = 20;
    Bitmap overlay =
        Bitmap.createBitmap(
            view.getMeasuredWidth() / scaleFactor,
            view.getMeasuredHeight() / scaleFactor,
            Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(overlay);
    canvas.translate(-view.getLeft() / scaleFactor, -view.getTop() / scaleFactor);
    // scale参数为float类型
    canvas.scale(1.0f / scaleFactor, 1.0f / scaleFactor);
    // 开启双缓冲
    Paint paint = new Paint();
    paint.setFlags(Paint.FILTER_BITMAP_FLAG);

    canvas.drawBitmap(bg, 0, 0, paint);
    // Bitmap result = blurBitmap(overlay, 2);
    Bitmap result = blurBitmapStack(overlay, 2);
    view.setBackground(new BitmapDrawable(result));
    long endMs = System.currentTimeMillis();
    String time = (endMs - startMs) + "ms";
    Toast.makeText(this, time, Toast.LENGTH_SHORT).show();
  }
Example #30
0
 private Bitmap makeBitmapMask(final View view) {
   if (view != null) {
     Drawable d = view.getBackground();
     float scaleFactor = 0.5f;
     int width = (int) (getMeasuredWidth() * scaleFactor);
     int height = (int) (getMeasuredHeight() * scaleFactor);
     if (d != null && width > 0 && height > 0) {
       d.setBounds(
           (int) (view.getLeft() * scaleFactor),
           (int) (view.getTop() * scaleFactor),
           (int) (view.getRight() * scaleFactor),
           (int) (view.getBottom() * scaleFactor));
       Bitmap mask = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
       Canvas canvas = new Canvas(mask);
       d.draw(canvas);
       return mask;
     } else {
       log(
           "Can't create a mask with height 0 or width 0. Or the layout has no children and is wrap content");
       return null;
     }
   } else {
     log("No bitmap mask loaded, view will NOT be masked !");
   }
   return null;
 }