@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);
  }
  public void hideMenu(View view) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
      final int cx = (settingsMenuButton.getLeft() + settingsMenuButton.getRight()) / 2;
      final int cy =
          ((settingsMenuButton.getTop() + settingsMenuButton.getBottom()) / 2)
              - settingsMenu.getTop();

      Log.i("", "Circle center " + cx + ", " + cy + " width " + bottomView.getWidth());

      final Animator anim =
          ViewAnimationUtils.createCircularReveal(settingsMenu, cx, cy, bottomView.getWidth(), 0);

      anim.addListener(
          new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
              super.onAnimationEnd(animation);
              settingsMenu.setVisibility(View.INVISIBLE);
              settingsMenuButton.setVisibility(View.VISIBLE);
            }
          });

      anim.start();
    } else {
      settingsMenuButton.setVisibility(View.VISIBLE);
      settingsMenu.setVisibility(View.INVISIBLE);
    }
  }
  @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);
  }
示例#5
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;
    }
  }
示例#6
0
  private void fillToGalleryRightLtr() {
    final int itemSpacing = mSpacing;
    final int galleryRight = getRight() - getLeft() - getPaddingRight();
    final int numChildren = getChildCount();
    final int numItems = mItemCount;

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

    if (prevIterationView != null) {
      curPosition = mFirstPosition + numChildren;
      curLeftEdge = prevIterationView.getRight() + itemSpacing;
    } else {
      mFirstPosition = curPosition = mItemCount - 1;
      curLeftEdge = getPaddingLeft();
      mShouldStopFling = true;
    }

    while (curLeftEdge < galleryRight && curPosition < numItems) {
      prevIterationView =
          makeAndAddView(curPosition, curPosition - mSelectedPosition, curLeftEdge, true);

      // Set state for next iteration
      curLeftEdge = prevIterationView.getRight() + itemSpacing;
      curPosition++;
    }
  }
示例#7
0
  private void fillToGalleryRightRtl() {
    final int itemSpacing = mSpacing;
    final int GalleryRight = getRight() - getLeft() - getPaddingRight();

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

    if (prevIterationView != null) {
      curPosition = mFirstPosition - 1;
      curLeftEdge = prevIterationView.getRight() + itemSpacing;
    } else {
      curPosition = 0;
      curLeftEdge = getPaddingLeft();
      mShouldStopFling = true;
    }

    while (curLeftEdge < GalleryRight && curPosition >= 0) {
      prevIterationView =
          makeAndAddView(curPosition, curPosition - mSelectedPosition, curLeftEdge, true);

      // Remember some state
      mFirstPosition = curPosition;

      // Set state for next iteration
      curLeftEdge = prevIterationView.getRight() + itemSpacing;
      curPosition--;
    }
  }
  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;
  }
  @Override
  protected Rect getDividerBound(int position, RecyclerView parent, View child) {
    Rect bounds = new Rect(0, 0, 0, 0);
    int transitionX = (int) ViewCompat.getTranslationX(child);
    int transitionY = (int) ViewCompat.getTranslationY(child);
    RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
    bounds.top =
        parent.getPaddingTop() + mMarginProvider.dividerTopMargin(position, parent) + transitionY;
    bounds.bottom =
        parent.getHeight()
            - parent.getPaddingBottom()
            - mMarginProvider.dividerBottomMargin(position, parent)
            + transitionY;

    int dividerSize = getDividerSize(position, parent);
    if (mDividerType == DividerType.DRAWABLE) {
      bounds.left = child.getRight() + params.leftMargin + transitionX;
      bounds.right = bounds.left + dividerSize;
    } else {
      bounds.left = child.getRight() + params.leftMargin + dividerSize / 2 + transitionX;
      bounds.right = bounds.left;
    }

    return bounds;
  }
  @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 fillToGalleryRight() {
    int itemSpacing = 0;
    int galleryRight = getScreenScrollPositionX(mCurrentScreen + 3);
    int numChildren = getChildCount();
    int numItems = mItemCount;

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

    if (prevIterationView != null) {
      curPosition = mFirstPosition + numChildren;
      curLeftEdge = prevIterationView.getRight() + itemSpacing;
    } else {
      mFirstPosition = curPosition = mItemCount - 1;
      curLeftEdge = getPaddingLeft();
    }

    while (curLeftEdge < galleryRight && curPosition < numItems) {
      prevIterationView =
          makeAndAddView(curPosition, curPosition - mCurrentScreen, curLeftEdge, true);

      // Set state for next iteration
      curLeftEdge = prevIterationView.getRight() + itemSpacing;
      curPosition++;
    }
  }
示例#12
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);
      }
    }
  }
  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);
    }
  }
 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;
     }
   }
 }
示例#15
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;
    }
  }
  @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);
    }
  }
    @Override
    public boolean onTouch(View v, MotionEvent event) {
      switch (event.getAction()) {
        case MotionEvent.ACTION_DOWN:
          return true;
        case MotionEvent.ACTION_UP:
          if (event.getRawX()
              >= (v.getRight() - ((TextView) v).getCompoundDrawables()[2].getBounds().width())) {
            // 响应右侧图标点击事件
            Intent intent = new Intent(context, TerminalSubmitActivity.class);
            intent.putExtra("operate", "modify");
            intent.putExtra("terminalid", ((String) v.getTag()).split(",")[0]);
            ((Activity) context).startActivityForResult(intent, 0);
          } else {
            // 响应自己的点击事件
            if (!v.performClick()) {
              // 响应ListView点击事件
              int position = Integer.parseInt(((String) v.getTag()).split(",")[1]) + 1;
              listView.performItemClick(
                  listView.getChildAt(position - listView.getFirstVisiblePosition()),
                  position,
                  listView.getItemIdAtPosition(position));
            }
          }
      }

      return false;
    }
    /**
     * This method takes layout manager and finds the right center element of it
     *
     * @param layoutManager
     * @return View
     */
    private View findCenterView(LinearLayoutManager layoutManager) {

      int minDistance = 0;
      View view, returnView = null;
      boolean notFound = true;

      for (int i = layoutManager.findFirstVisibleItemPosition();
          i <= layoutManager.findLastVisibleItemPosition() && notFound;
          i++) {

        view = layoutManager.findViewByPosition(i);

        int center = (view.getLeft() + view.getRight()) / 2;

        int leastDifference = Math.abs(mCenterPivot - center);

        if (leastDifference <= minDistance || i == layoutManager.findFirstVisibleItemPosition()) {
          minDistance = leastDifference;
          returnView = view;
        } else {
          notFound = false;
        }
      }
      return returnView;
    }
 @Override
 public boolean onSingleTapConfirmed(MotionEvent e) {
   Rect viewRect = new Rect();
   for (int i = 0; i < getChildCount(); i++) {
     View child = getChildAt(i);
     int left = child.getLeft();
     int right = child.getRight();
     int top = child.getTop();
     int bottom = child.getBottom();
     viewRect.set(left, top, right, bottom);
     if (viewRect.contains((int) e.getX(), (int) e.getY())) {
       if (mOnItemClicked != null) {
         mOnItemClicked.onItemClick(
             HorizontalListView.this,
             child,
             mLeftViewIndex + 1 + i,
             mAdapter.getItemId(mLeftViewIndex + 1 + i));
       }
       if (mOnItemSelected != null) {
         mOnItemSelected.onItemSelected(
             HorizontalListView.this,
             child,
             mLeftViewIndex + 1 + i,
             mAdapter.getItemId(mLeftViewIndex + 1 + i));
       }
       break;
     }
   }
   return true;
 }
 public void setShadowVisible(boolean visible) {
   initShadow(visible);
   if (mPinnedSection != null) {
     View v = mPinnedSection.view;
     invalidate(v.getLeft(), v.getTop(), v.getRight(), v.getBottom() + mShadowHeight);
   }
 }
  private void captureValues(TransitionValues transitionValues) {
    final View view = transitionValues.view;
    if (view == null || view.getWidth() <= 0 || view.getHeight() <= 0) return;

    transitionValues.values.put(
        PROP_BOUNDS, new Rect(view.getLeft(), view.getTop(), view.getRight(), view.getBottom()));
  }
  private void drawDividersHorizontal(Canvas canvas) {
    final int count = getChildCount();
    for (int i = 0; i < count; i++) {
      final View child = getChildAt(i);

      if (child != null && child.getVisibility() != GONE) {
        if (hasDividerBeforeChildAt(i)) {
          final LayoutParams lp = (LayoutParams) child.getLayoutParams();
          final int left = child.getLeft() - lp.leftMargin /* - mDividerWidth*/;
          drawVerticalDivider(canvas, left);
        }
      }
    }

    if (hasDividerBeforeChildAt(count)) {
      final View child = getChildAt(count - 1);
      int right = 0;
      if (child == null) {
        right = getWidth() - getPaddingRight() - mDividerWidth;
      } else {
        // final LayoutParams lp = (LayoutParams) child.getLayoutParams();
        right = child.getRight() /* + lp.rightMargin*/;
      }
      drawVerticalDivider(canvas, right);
    }
  }
  private void updateSubviewClipStatus(View subview) {
    if (!mRemoveClippedSubviews || getParent() == null) {
      return;
    }

    Assertions.assertNotNull(mClippingRect);
    Assertions.assertNotNull(mAllChildren);

    // do fast check whether intersect state changed
    sHelperRect.set(subview.getLeft(), subview.getTop(), subview.getRight(), subview.getBottom());
    boolean intersects =
        mClippingRect.intersects(
            sHelperRect.left, sHelperRect.top, sHelperRect.right, sHelperRect.bottom);

    // If it was intersecting before, should be attached to the parent
    boolean oldIntersects = (subview.getParent() != null);

    if (intersects != oldIntersects) {
      int clippedSoFar = 0;
      for (int i = 0; i < mAllChildrenCount; i++) {
        if (mAllChildren[i] == subview) {
          updateSubviewClipStatus(mClippingRect, i, clippedSoFar);
          break;
        }
        if (mAllChildren[i].getParent() == null) {
          clippedSoFar++;
        }
      }
    }
  }
示例#24
0
  @Override
  public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
    layout.onPageScrolled(position, positionOffset, positionOffsetPixels);

    final View selectedTitle = layout.getChildAt(position);
    if (selectedTitle == null) {
      return;
    }

    final int selectedTitleOffset = (int) (positionOffset * selectedTitle.getWidth());

    int titleLeft = selectedTitle.getLeft() + selectedTitleOffset;
    if (position > 0) {
      titleLeft -= titleOffset;
    }

    int titleRight = selectedTitle.getRight() + selectedTitleOffset;
    if (position < layout.getChildCount() - 1) {
      titleRight += titleOffset;
    }

    final int scrollX = getScrollX();
    if (titleLeft < scrollX) {
      // Tab strip overflows to the left.
      scrollTo(titleLeft, 0);
    } else if (titleRight > scrollX + getWidth()) {
      // Tab strip overflows to the right.
      scrollTo(titleRight - getWidth(), 0);
    }
  }
  @Override
  protected void dispatchDraw(Canvas canvas) {
    final long drawingTime = getDrawingTime();
    final View handle = mHandle;
    final boolean isVertical = mVertical;

    drawChild(canvas, handle, drawingTime);

    if (mTracking || mAnimating) {
      final Bitmap cache = mContent.getDrawingCache();
      if (cache != null) {
        if (isVertical) {
          canvas.drawBitmap(cache, 0, handle.getBottom(), null);
        } else {
          canvas.drawBitmap(cache, handle.getRight(), 0, null);
        }
      } else {
        canvas.save();
        canvas.translate(
            isVertical ? 0 : handle.getLeft() - mTopOffset,
            isVertical ? handle.getTop() - mTopOffset : 0);
        drawChild(canvas, mContent, drawingTime);
        canvas.restore();
      }
    } else if (mExpanded) {
      drawChild(canvas, mContent, drawingTime);
    }
  }
  /**
   * Tests scrollability within child views of v given a delta of dx.
   *
   * @param v View to test for horizontal scrollability
   * @param checkV Whether the view should be checked for draggability
   * @param dx Delta scrolled in pixels
   * @param x X coordinate of the active touch point
   * @param y Y coordinate of the active touch point
   * @return true if child views of v can be scrolled by delta of dx.
   */
  protected boolean canChildScrollVertically(View v, boolean checkV, int dx, int x, int y) {
    if (v instanceof ViewGroup) {
      final ViewGroup group = (ViewGroup) v;

      final int count = group.getChildCount();
      // Count backwards - let topmost views consume scroll distance first.
      for (int i = count - 1; i >= 0; i--) {
        final View child = group.getChildAt(i);

        final int childLeft = child.getLeft() + supportGetTranslationX(child);
        final int childRight = child.getRight() + supportGetTranslationX(child);
        final int childTop = child.getTop() + supportGetTranslationY(child);
        final int childBottom = child.getBottom() + supportGetTranslationY(child);

        if (x >= childLeft
            && x < childRight
            && y >= childTop
            && y < childBottom
            && canChildScrollVertically(child, true, dx, x - childLeft, y - childTop)) {
          return true;
        }
      }
    }

    return checkV && mOnInterceptMoveEventListener.isViewDraggable(v, dx, x, y);
  }
示例#27
0
  // Layout showing effect(using CircularReveal)
  private void showLayout(int viewId, int viewId2) {
    final View myView = findViewById(viewId);
    View myView2 = findViewById(viewId2);

    if (android.os.Build.VERSION.SDK_INT > 20) {

      int finalRadius = Math.max(myView.getWidth(), myView.getHeight());

      int cx = (myView2.getLeft() + myView2.getRight()) / 2;
      int cy = (myView2.getTop() + myView2.getBottom()) / 2;

      Animator anim = ViewAnimationUtils.createCircularReveal(myView, cx, cy, 0, finalRadius);
      anim.setDuration(500);

      anim.addListener(
          new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
              super.onAnimationEnd(animation);
              if (gameStatus == GAME_GOGAME) {
                gameStatus = GAME_WAITING;
              }
            }
          });

      myView.setVisibility(View.VISIBLE);
      myView.setAlpha(1);
      anim.start();
    } else {
      myView.setVisibility(View.VISIBLE);
      if (gameStatus == GAME_GOGAME) {
        gameStatus = GAME_WAITING;
      }
    }
  }
示例#28
0
 public final void onDraw$13fcd2ff(Canvas paramCanvas, RecyclerView paramRecyclerView) {
   this.mCardStackBoundsRect.setEmpty();
   int i = paramRecyclerView.getChildCount();
   for (int j = 0; j < i; j++) {
     View localView = paramRecyclerView.getChildAt(j);
     if ((localView instanceof CardSection)) {
       boolean bool = localView instanceof DetailsPeekingSection;
       int k = 0;
       if (bool) {
         k = ((DetailsPeekingSection) localView).getTopPeekAmount();
       }
       this.mCardStackBoundsRect.union(
           localView.getLeft(),
           k + localView.getTop(),
           localView.getRight(),
           localView.getBottom());
     }
   }
   if (this.mCardStackBoundsRect.isEmpty()) {
     return;
   }
   Rect localRect1 = this.mCardStackBoundsRect;
   localRect1.left -= this.mVerticalPadding;
   Rect localRect2 = this.mCardStackBoundsRect;
   localRect2.top -= this.mVerticalPadding;
   Rect localRect3 = this.mCardStackBoundsRect;
   localRect3.right += this.mVerticalPadding;
   Rect localRect4 = this.mCardStackBoundsRect;
   localRect4.bottom += this.mVerticalPadding;
   this.mCardDrawable.setBounds(this.mCardStackBoundsRect);
   this.mCardDrawable.draw(paramCanvas);
 }
示例#29
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;
 }
  private View findCenterView(LinearLayoutManager lm) {

    int minDistance = 0;
    View view = null;
    View returnView = null;
    boolean notFound = true;

    for (int i = lm.findFirstVisibleItemPosition();
        i <= lm.findLastVisibleItemPosition() && notFound;
        i++) {

      view = lm.findViewByPosition(i);

      int center =
          lm.getOrientation() == LinearLayoutManager.HORIZONTAL
              ? (view.getLeft() + view.getRight()) / 2
              : (view.getTop() + view.getBottom()) / 2;
      int leastDifference = Math.abs(mCenterPivot - center);

      if (leastDifference <= minDistance || i == lm.findFirstVisibleItemPosition()) {
        minDistance = leastDifference;
        returnView = view;
        setCenterView(returnView);
      } else {
        notFound = false;
      }
    }
    return returnView;
  }