@Override
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {

    // TODO: handle vertical labels
    if (isEnabled() && mLabelLayout != null) {
      final int sweepHeight = mSweep.getIntrinsicHeight();
      final int templateHeight = mLabelLayout.getHeight();

      mSweepOffset.x = 0;
      mSweepOffset.y = 0;
      mSweepOffset.y = (int) ((templateHeight / 2) - getTargetInset());
      setMeasuredDimension(mSweep.getIntrinsicWidth(), Math.max(sweepHeight, templateHeight));

    } else {
      mSweepOffset.x = 0;
      mSweepOffset.y = 0;
      setMeasuredDimension(mSweep.getIntrinsicWidth(), mSweep.getIntrinsicHeight());
    }

    if (mFollowAxis == VERTICAL) {
      final int targetHeight =
          mSweep.getIntrinsicHeight() - mSweepPadding.top - mSweepPadding.bottom;
      mMargins.top = -(mSweepPadding.top + (targetHeight / 2));
      mMargins.bottom = 0;
      mMargins.left = -mSweepPadding.left;
      mMargins.right = mSweepPadding.right;
    } else {
      final int targetWidth = mSweep.getIntrinsicWidth() - mSweepPadding.left - mSweepPadding.right;
      mMargins.left = -(mSweepPadding.left + (targetWidth / 2));
      mMargins.right = 0;
      mMargins.top = -mSweepPadding.top;
      mMargins.bottom = mSweepPadding.bottom;
    }

    mContentOffset.set(0, 0, 0, 0);

    // make touch target area larger
    final int widthBefore = getMeasuredWidth();
    final int heightBefore = getMeasuredHeight();
    if (mFollowAxis == HORIZONTAL) {
      final int widthAfter = widthBefore * 3;
      setMeasuredDimension(widthAfter, heightBefore);
      mContentOffset.left = (widthAfter - widthBefore) / 2;

      final int offset = mSweepPadding.bottom * 2;
      mContentOffset.bottom -= offset;
      mMargins.bottom += offset;
    } else {
      final int heightAfter = heightBefore * 2;
      setMeasuredDimension(widthBefore, heightAfter);
      mContentOffset.offset(0, (heightAfter - heightBefore) / 2);

      final int offset = mSweepPadding.right * 2;
      mContentOffset.right -= offset;
      mMargins.right += offset;
    }

    mSweepOffset.offset(mContentOffset.left, mContentOffset.top);
    mMargins.offset(-mSweepOffset.x, -mSweepOffset.y);
  }
  public void drawScaledImage(
      Image Image,
      int x,
      int y,
      int width,
      int height, /* int srcX,int srcY, int srcWidth, int srcHeight,*/
      float scale /*,int originX, int originY*/) {
    /*srcRect.left=srcX;
    srcRect.top=srcY;
    srcRect.right=srcX+srcWidth;
    srcRect.bottom=srcY+srcHeight;*/

    srcRect.left = 0;
    srcRect.top = 0;
    srcRect.right = Image.getWidth();
    srcRect.bottom = Image.getHeight();

    dstRect.left = (int) (x);
    dstRect.top = (int) (((y)));
    dstRect.right = (int) (((x + (width * scale))));
    dstRect.bottom = (int) (((y + (height * scale))));
    /*
    dstRect.left= (int) (originX+((x-originX)*scale));
    dstRect.top=(int) (originY+((y-originY)*scale));
    dstRect.right=(int) (originX+((x+width-originX)*scale));
    dstRect.bottom=(int) (originY+((y+height-originY)*scale));*/

    canvas.drawBitmap(((AndroidImage) Image).bitmap, srcRect, dstRect, null);
  }
 /**
  * Handles scrolling in response to a "home/end" shortcut press. This method will scroll the view
  * to the top or bottom and give the focus to the topmost/bottommost component in the new visible
  * area. If no component is a good candidate for focus, this scrollview reclaims the focus.
  *
  * @param direction the scroll direction: {@link android.view.View#FOCUS_UP} to go the top of the
  *     view or {@link android.view.View#FOCUS_DOWN} to go the bottom
  * @return true if the key event is consumed by this method, false otherwise
  */
 public boolean fullScroll(int direction, boolean horizontal) {
   if (!horizontal) {
     boolean down = direction == View.FOCUS_DOWN;
     int height = getHeight();
     mTempRect.top = 0;
     mTempRect.bottom = height;
     if (down) {
       int count = getChildCount();
       if (count > 0) {
         View view = getChildAt(count - 1);
         mTempRect.bottom = view.getBottom();
         mTempRect.top = mTempRect.bottom - height;
       }
     }
     return scrollAndFocus(direction, mTempRect.top, mTempRect.bottom, 0, 0, 0);
   } else {
     boolean right = direction == View.FOCUS_DOWN;
     int width = getWidth();
     mTempRect.left = 0;
     mTempRect.right = width;
     if (right) {
       int count = getChildCount();
       if (count > 0) {
         View view = getChildAt(count - 1);
         mTempRect.right = view.getBottom();
         mTempRect.left = mTempRect.right - width;
       }
     }
     return scrollAndFocus(0, 0, 0, direction, mTempRect.top, mTempRect.bottom);
   }
 }
    @Override
    public void getItemOffsets(
        Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
      int position = parent.getChildAdapterPosition(view); // item position
      int column = position % spanCount; // item column

      if (includeEdge) {
        outRect.left =
            spacing
                - column * spacing / spanCount; // spacing - column * ((1f / spanCount) * spacing)
        outRect.right =
            (column + 1) * spacing / spanCount; // (column + 1) * ((1f / spanCount) * spacing)

        if (position < spanCount) { // top edge
          outRect.top = spacing;
        }
        outRect.bottom = spacing; // item bottom
      } else {
        outRect.left = column * spacing / spanCount; // column * ((1f / spanCount) * spacing)
        outRect.right =
            spacing
                - (column + 1)
                    * spacing
                    / spanCount; // spacing - (column + 1) * ((1f /    spanCount) * spacing)
        if (position >= spanCount) {
          outRect.top = spacing; // item top
        }
      }
    }
  public void calculateTapAreaByTopLeft(
      int focusWidth,
      int focusHeight,
      float areaMultiple,
      int top,
      int left,
      int previewWidth,
      int previewHeight,
      Rect rect) {
    int areaWidth = (int) (focusWidth * areaMultiple);
    int areaHeight = (int) (focusHeight * areaMultiple);

    int right = Util.clamp(left + areaWidth, areaWidth, previewWidth);
    int bottom = Util.clamp(top + areaHeight, areaHeight, previewHeight);

    RectF rectF = new RectF(left, top, right, bottom);
    mMatrix.mapRect(rectF);
    Util.rectFToRect(rectF, rect);

    if (rect.left < -1000) rect.left = -1000;
    if (rect.left > 1000) rect.left = 1000;

    if (rect.right < -1000) rect.right = -1000;
    if (rect.right > 1000) rect.right = 1000;

    if (rect.top < -1000) rect.top = -1000;
    if (rect.top > 1000) rect.top = 1000;

    if (rect.bottom < -1000) rect.bottom = -1000;
    if (rect.bottom > 1000) rect.bottom = 1000;
  }
Beispiel #6
0
 private void computeDirtyRect(int d) {
   dirtyRectTop = dirtyRectLeft = Integer.MAX_VALUE;
   dirtyRectBottom = dirtyRectRight = -1;
   int i = 0;
   for (int row = 0; row < trsScreenRows; row++) {
     for (int col = 0; col < trsScreenCols / d; col++) {
       if (lastScreenBuffer[i] != screenBuffer[i]) {
         if (dirtyRectTop > row) {
           dirtyRectTop = row;
         }
         if (dirtyRectBottom < row) {
           dirtyRectBottom = row;
         }
         if (dirtyRectLeft > col) {
           dirtyRectLeft = col;
         }
         if (dirtyRectRight < col) {
           dirtyRectRight = col;
         }
         lastScreenBuffer[i] = screenBuffer[i];
       }
       i += d;
     }
   }
   if (dirtyRectBottom == -1) {
     return;
   }
   clipRect.left = adjustedClipRect.left = trsCharWidth * dirtyRectLeft * d;
   clipRect.right = adjustedClipRect.right = trsCharWidth * (dirtyRectRight + 1) * d;
   clipRect.top = adjustedClipRect.top = trsCharHeight * dirtyRectTop;
   clipRect.bottom = adjustedClipRect.bottom = trsCharHeight * (dirtyRectBottom + 1);
 }
  BorderCropDrawable(
      Drawable child, boolean cropLeft, boolean cropTop, boolean cropRight, boolean cropBottom) {
    mChild = child;

    mBoundsShift = new Rect();
    mPadding = new Rect();
    mChild.getPadding(mPadding);

    if (cropLeft) {
      mBoundsShift.left = -mPadding.left;
      mPadding.left = 0;
    }
    if (cropTop) {
      mBoundsShift.top = -mPadding.top;
      mPadding.top = 0;
    }
    if (cropRight) {
      mBoundsShift.right = mPadding.right;
      mPadding.right = 0;
    }
    if (cropBottom) {
      mBoundsShift.bottom = mPadding.bottom;
      mPadding.bottom = 0;
    }
  }
Beispiel #8
0
  public void drawData() {
    Paint paint = new Paint();
    paint.setTextSize((int) (30 * UIDefaultData.f_y_scales));
    paint.setFakeBoldText(true);
    paint.setColor(Color.BLACK);
    canvas.drawText(
        GameInfo.money + "", 180 * UIDefaultData.f_x_scales, 600 * UIDefaultData.f_y_scales, paint);
    paint.setColor(Color.WHITE);
    paint.setTextSize((int) (25 * UIDefaultData.f_y_scales));
    canvas.drawText(
        GameInfo.level + "", 395 * UIDefaultData.f_x_scales, 45 * UIDefaultData.f_y_scales, paint);

    int real_wid = (int) (UIDefaultData.container_bmp.getBitmap("OUR_HEALTH").getWidth() * 0.75125);
    rec_our.right = wid - (int) (real_wid * (1 - GameInfo.getPercent(1)));
    rec_enemy.right = wid - (int) (real_wid * (1 - GameInfo.getPercent(2)));
    rec_dst_our.right = right_our - (int) (real_wid * (1 - GameInfo.getPercent(1)));
    rec_dst_enemy.right = right_enemy - (int) (real_wid * (1 - GameInfo.getPercent(2)));
    canvas.drawBitmap(
        UIDefaultData.container_bmp.getBitmap("our_hp").getBitmap(), rec_our, rec_dst_our, null);
    canvas.drawBitmap(
        UIDefaultData.container_bmp.getBitmap("enemy_hp").getBitmap(),
        rec_enemy,
        rec_dst_enemy,
        null);
  }
Beispiel #9
0
  @Override
  public void getItemOffsets(
      Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
    int position = parent.getChildAdapterPosition(view);
    outRect.left = mSpace;
    outRect.right = mSpace;
    outRect.top = 0;
    outRect.bottom = mSpace;

    if (parent.getLayoutManager() instanceof StaggeredGridLayoutManager) {
      outRect.left = 0;
      outRect.right = 0;
      outRect.top = 0;
      outRect.bottom = 0;
      if (position < ((StaggeredGridLayoutManager) parent.getLayoutManager()).getSpanCount()) {
        // 利用item的margin配合RecyclerView的margin值使得间隔相等,这里只需设第一行item的相对顶部的高度
        outRect.top = mSpace;
      }
    } else if (parent.getLayoutManager() instanceof GridLayoutManager) {
      if (position < ((GridLayoutManager) parent.getLayoutManager()).getSpanCount()) {
        // 保证第一行有相对顶部有高度
        outRect.top = mSpace;
      }
    } else if (parent.getLayoutManager() instanceof LinearLayoutManager) {
      if (position == 0) {
        // 保证第一行有相对顶部有高度
        outRect.top = mSpace;
      }
    }
  }
  @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) {
    mPaint.setAntiAlias(true);
    mPaint.setStrokeWidth(mCircleWidth);
    mPaint.setStrokeCap(Paint.Cap.ROUND);
    mPaint.setStyle(Paint.Style.STROKE);
    int center = getWidth() / 2;
    int radius = center - mCircleWidth / 2;
    drawOval(canvas, center, radius);

    int relRadius = radius - mCircleWidth / 2;
    mRect.left = (int) (relRadius - Math.sqrt(2) * 1.0f / 2 * relRadius) + mCircleWidth;
    mRect.top = (int) (relRadius - Math.sqrt(2) * 1.0f / 2 * relRadius) + mCircleWidth;
    mRect.bottom = (int) (mRect.left + Math.sqrt(2) * relRadius);
    mRect.right = (int) (mRect.left + Math.sqrt(2) * relRadius);

    /** 如果图片比较小,那么根据图片的尺寸放置到正中心 */
    if (mImage.getWidth() < Math.sqrt(2) * relRadius) {
      mRect.left =
          (int) (mRect.left + Math.sqrt(2) * relRadius * 1.0f / 2 - mImage.getWidth() * 1.0f / 2);
      mRect.top =
          (int) (mRect.top + Math.sqrt(2) * relRadius * 1.0f / 2 - mImage.getHeight() * 1.0f / 2);
      mRect.right = (int) (mRect.left + mImage.getWidth());
      mRect.bottom = (int) (mRect.top + mImage.getHeight());
    }

    // 绘图
    canvas.drawBitmap(mImage, null, mRect, mPaint);
  }
Beispiel #12
0
  private void update() {
    mPlayedBar.set(mProgressBar);

    if (mTotalTime > 0) {
      mPlayedBar.right =
          mPlayedBar.left + (int) ((mProgressBar.width() * (long) mCurrentTime) / mTotalTime);
      /*
       *  M: if duration is not accurate, here just adjust playedBar
       *  we also show the accurate position text to final user.
       */
      if (mPlayedBar.right > mProgressBar.right) {
        mPlayedBar.right = mProgressBar.right;
      }
    } else {
      mPlayedBar.right = mProgressBar.left;
    }

    if (!mScrubbing) {
      mScrubberLeft = mPlayedBar.right - mScrubber.getWidth() / 2;
    }
    // update text bounds when layout changed or time changed
    updateBounds();
    mInfoExt.updateVisibleText(this, mProgressBar, mTimeBounds);
    invalidate();
  }
Beispiel #13
0
  @Override
  public void setParameter(ZDepthParam param, int left, int top, int right, int bottom) {
    mRectTopShadow.left = left;
    mRectTopShadow.top = (int) (top + param.mOffsetYTopShadowPx);
    mRectTopShadow.right = right;
    mRectTopShadow.bottom = (int) (bottom + param.mOffsetYTopShadowPx);

    mRectBottomShadow.left = left;
    mRectBottomShadow.top = (int) (top + param.mOffsetYBottomShadowPx);
    mRectBottomShadow.right = right;
    mRectBottomShadow.bottom = (int) (bottom + param.mOffsetYBottomShadowPx);

    mTopShadow.getPaint().setColor(Color.argb(param.mAlphaTopShadow, 0, 0, 0));
    if (0 < param.mBlurTopShadowPx) {
      mTopShadow
          .getPaint()
          .setMaskFilter(new BlurMaskFilter(param.mBlurTopShadowPx, BlurMaskFilter.Blur.NORMAL));
    } else {
      mTopShadow.getPaint().setMaskFilter(null);
    }

    mBottomShadow.getPaint().setColor(Color.argb(param.mAlphaBottomShadow, 0, 0, 0));
    if (0 < param.mBlurBottomShadowPx) {
      mBottomShadow
          .getPaint()
          .setMaskFilter(new BlurMaskFilter(param.mBlurBottomShadowPx, BlurMaskFilter.Blur.NORMAL));
    } else {
      mBottomShadow.getPaint().setMaskFilter(null);
    }
  }
  @Override
  public void draw(Canvas c, Layer l) {
    if (layer == l && alpha > 0) {
      paint.setAlpha(alpha);
      int width = numbers.getMinimumWidth() / 10;

      location.top = top;
      location.bottom = top + getPrologHeight();
      location.left = left + (getWidth() - prolog.getMinimumWidth()) / 2;
      location.right = location.left + prolog.getMinimumWidth();
      c.drawBitmap(prolog.getBitmap(), null, location, paint);

      source.top = 0;
      source.bottom = numbers.getIntrinsicHeight();
      location.top = top + numbers_offset;
      location.bottom = top + getTotalHeight();
      for (int i = digits - 1, n = number > 0 ? number : 0; i >= 0; --i, n = n / 10) {
        location.left = left + (getWidth() - width * digits) / 2 + i * width;
        location.right = location.left + width;
        source.left = (n % 10) * width;
        source.right = source.left + width;
        c.drawBitmap(numbers.getBitmap(), source, location, paint);
      }
    }
  }
Beispiel #15
0
  /**
   * 获取扫描框相对于预览界面的矩形
   *
   * @param cameraPreviewSize 相机预览分辨率
   * @return 扫描框相对的预览界面的矩形
   */
  public Rect getRectInPreview(Camera.Size cameraPreviewSize) {
    if (rectInPreview == null) {
      // 在相对于屏幕的矩形的基础上创建相对于预览界面的矩形,然后在修改其各项属性
      rectInPreview = new Rect(getRectInScreen());

      // 获取屏幕分辨率
      WindowManager windowManager =
          (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
      Display display = windowManager.getDefaultDisplay();

      // 如果是横屏
      if (getContext().getResources().getConfiguration().orientation
          == Configuration.ORIENTATION_LANDSCAPE) {
        rectInPreview.left = rectInPreview.left * cameraPreviewSize.width / display.getWidth();
        rectInPreview.right = rectInPreview.right * cameraPreviewSize.width / display.getWidth();
        rectInPreview.top = rectInPreview.top * cameraPreviewSize.height / display.getHeight();
        rectInPreview.bottom =
            rectInPreview.bottom * cameraPreviewSize.height / display.getHeight();
      } else {
        rectInPreview.left = rectInPreview.left * cameraPreviewSize.height / display.getWidth();
        rectInPreview.right = rectInPreview.right * cameraPreviewSize.height / display.getWidth();
        rectInPreview.top = rectInPreview.top * cameraPreviewSize.width / display.getHeight();
        rectInPreview.bottom = rectInPreview.bottom * cameraPreviewSize.width / display.getHeight();
      }
    }

    return rectInPreview;
  }
  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);
    }
  }
  /**
   * Computes the offsets based on the vertical and horizontal spacing values. The spacing
   * computation has to ensure that the lane sizes are the same after applying the offsets. This
   * means we have to shift the spacing unevenly across items depending on their position in the
   * layout.
   */
  public void getItemOffsets(Rect outRect, int itemPosition, RecyclerView parent) {
    final BaseLayoutManager lm = (BaseLayoutManager) parent.getLayoutManager();

    lm.getLaneForPosition(mTempLaneInfo, itemPosition, TwoWayLayoutManager.Direction.END);
    final int lane = mTempLaneInfo.startLane;
    final int laneSpan = lm.getLaneSpanForPosition(itemPosition);
    final int laneCount = lm.getLanes().getCount();
    final int itemCount = parent.getAdapter().getItemCount();

    final boolean isVertical = lm.isVertical();

    final boolean firstLane = (lane == 0);
    final boolean secondLane = isSecondLane(lm, itemPosition, lane);

    final boolean lastLane = (lane + laneSpan == laneCount);
    final boolean beforeLastLane = (lane + laneSpan == laneCount - 1);

    final int laneSpacing = (isVertical ? mHorizontalSpacing : mVerticalSpacing);

    final int laneOffsetStart;
    final int laneOffsetEnd;

    if (firstLane) {
      laneOffsetStart = 0;
    } else if (lastLane && !secondLane) {
      laneOffsetStart = (int) (laneSpacing * 0.75);
    } else if (secondLane && !lastLane) {
      laneOffsetStart = (int) (laneSpacing * 0.25);
    } else {
      laneOffsetStart = (int) (laneSpacing * 0.5);
    }

    if (lastLane) {
      laneOffsetEnd = 0;
    } else if (firstLane && !beforeLastLane) {
      laneOffsetEnd = (int) (laneSpacing * 0.75);
    } else if (beforeLastLane && !firstLane) {
      laneOffsetEnd = (int) (laneSpacing * 0.25);
    } else {
      laneOffsetEnd = (int) (laneSpacing * 0.5);
    }

    final boolean isFirstInLane = isFirstChildInLane(lm, itemPosition);
    final boolean isLastInLane =
        !mAddSpacingAtEnd && isLastChildInLane(lm, itemPosition, itemCount);

    if (isVertical) {
      outRect.left = laneOffsetStart;
      outRect.top = (isFirstInLane ? 0 : mVerticalSpacing / 2);
      outRect.right = laneOffsetEnd;
      outRect.bottom = (isLastInLane ? 0 : mVerticalSpacing / 2);
    } else {
      outRect.left = (isFirstInLane ? 0 : mHorizontalSpacing / 2);
      outRect.top = laneOffsetStart;
      outRect.right = (isLastInLane ? 0 : mHorizontalSpacing / 2);
      outRect.bottom = laneOffsetEnd;
    }
  }
  public void drawImage(
      Image Image, int x, int y, int srcX, int srcY, int srcWidth, int srcHeight) {
    srcRect.left = srcX;
    srcRect.top = srcY;
    srcRect.right = srcX + srcWidth;
    srcRect.bottom = srcY + srcHeight;

    dstRect.left = x;
    dstRect.top = y;
    dstRect.right = x + srcWidth;
    dstRect.bottom = y + srcHeight;

    canvas.drawBitmap(((AndroidImage) Image).bitmap, srcRect, dstRect, null);
  }
  @Override
  public void drawPixmap(
      Pixmap pixmap, int x, int y, int srcX, int srcY, int srcWidth, int srcHeight) {
    srcRect.left = srcX;
    srcRect.top = srcY;
    srcRect.right = srcX + srcWidth - 1;
    srcRect.bottom = srcY + srcHeight - 1;

    dstRect.left = x;
    dstRect.top = y;
    dstRect.right = x + srcWidth - 1;
    dstRect.bottom = y + srcHeight - 1;

    canvas.drawBitmap(((AndroidPixmap) pixmap).bitmap, srcRect, dstRect, null);
  }
Beispiel #20
0
  private void update() {
    playedBar.set(progressBar);

    if (totalTime > 0) {
      playedBar.right =
          playedBar.left + (int) ((progressBar.width() * (long) currentTime) / totalTime);
    } else {
      playedBar.right = progressBar.left;
    }

    if (!scrubbing) {
      scrubberLeft = playedBar.right - scrubber.getWidth() / 2;
    }
    invalidate();
  }
  /**
   * Calculate the bounds for a view's title
   *
   * @param index
   * @param paint
   * @return
   */
  private Rect calcBounds(int index, Paint paint) {
    // Calculate the text bounds
    Rect bounds = new Rect();
    CharSequence title = getTitle(index);
    bounds.right = (int) paint.measureText(title, 0, title.length());
    bounds.bottom = (int) (paint.descent() - paint.ascent());

    Drawable icon = getIcon(index);
    if (icon != null) {
      Rect iconBounds = icon.getBounds();
      bounds.right += iconBounds.width() + mIconPadding;
    }

    return bounds;
  }
Beispiel #22
0
 public static Bitmap maskBitmap(Bitmap bitmap, Bitmap mask, int width, int height) {
   if (null == bitmap || mask == null) {
     return null;
   }
   // 定义期望大小的bitmap
   Xfermode mode = new PorterDuffXfermode(Mode.SRC_IN);
   Bitmap dstBmp = Bitmap.createBitmap(width, height, Config.ARGB_8888);
   // 定义一个画布
   Canvas canvas = new Canvas(dstBmp);
   // 创建一个取消锯齿画笔
   Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
   // 定义需要绘制的某图片上的那一部分矩形空间
   Rect src = new Rect(0, 0, mask.getWidth(), mask.getHeight());
   // 定义需要将上面的矩形绘制成新的矩形大小
   Rect dst = new Rect(0, 0, width, height);
   // 将蒙版图片绘制成imageview本身的大小,这样从大小才会和UE标注的一样大
   canvas.drawBitmap(mask, src, dst, paint);
   // 设置两张图片的相交模式
   // 至于这个函数介绍参考网址:http://blog.csdn.net/wm111/article/details/7299294
   paint.setXfermode(mode);
   // 将src修改为需要添加mask的bitmap大小,因为是要将此bitmap整个添加上蒙版
   src.right = bitmap.getWidth();
   src.bottom = bitmap.getHeight();
   // 在已经绘制的mask上叠加bitmap
   canvas.drawBitmap(bitmap, src, dst, paint);
   return dstBmp;
 }
 @Override
 public boolean onLoadInt(int command_, int intData_) {
   try {
     switch (command_) {
       case FILECOMMAND_RELATIVEIMAGESTATEBITMAPRECTLEFT:
         _BitmapRect.left = intData_;
         break;
       case FILECOMMAND_RELATIVEIMAGESTATEBITMAPRECTTOP:
         _BitmapRect.top = intData_;
         break;
       case FILECOMMAND_RELATIVEIMAGESTATEBITMAPRECTRIGHT:
         _BitmapRect.right = intData_;
         break;
       case FILECOMMAND_RELATIVEIMAGESTATEBITMAPRECTBOTTOM:
         _BitmapRect.bottom = intData_;
         break;
         //                    case FILECOMMAND_RELATIVEIMAGESTATEPOSLEFT:
         //                        _PositionRect.left = intData_;
         //                        break;
         //                    case FILECOMMAND_RELATIVEIMAGESTATEPOSTOP:
         //                        _PositionRect.top = intData_;
         //                        break;
         //                    case FILECOMMAND_RELATIVEIMAGESTATEPOSRIGHT:
         //                        _PositionRect.right = intData_;
         //                        break;
         //                    case FILECOMMAND_RELATIVEIMAGESTATEPOSBOTTOM:
         //                        _PositionRect.bottom = intData_;
         //                        break;
     }
   } catch (Exception e) {
     return false;
   }
   return true;
 }
Beispiel #24
0
  /**
   * This will generate a bitmap with the pattern as big as the rectangle we were allow to draw on.
   * We do this to chache the bitmap so we don't need to recreate it each time draw() is called
   * since it takes a few milliseconds.
   */
  private void generatePatternBitmap() {

    if (getBounds().width() <= 0 || getBounds().height() <= 0) {
      return;
    }

    mBitmap = Bitmap.createBitmap(getBounds().width(), getBounds().height(), Config.ARGB_8888);
    Canvas canvas = new Canvas(mBitmap);

    Rect r = new Rect();
    boolean verticalStartWhite = true;
    for (int i = 0; i <= numRectanglesVertical; i++) {

      boolean isWhite = verticalStartWhite;
      for (int j = 0; j <= numRectanglesHorizontal; j++) {

        r.top = i * mRectangleSize;
        r.left = j * mRectangleSize;
        r.bottom = r.top + mRectangleSize;
        r.right = r.left + mRectangleSize;

        canvas.drawRect(r, isWhite ? mPaintWhite : mPaintGray);

        isWhite = !isWhite;
      }

      verticalStartWhite = !verticalStartWhite;
    }
  }
Beispiel #25
0
 public void move(int x, int y) {
   mDest.left = x - widthHalf;
   mDest.right = x + widthHalf;
   mDest.top = y - 2 * heightHalf;
   mDest.bottom = y;
   invalidate();
 }
 private void initialize(Context context, AttributeSet attrs, int defStyleAttr) {
   TypedArray a =
       context.obtainStyledAttributes(
           attrs, R.styleable.CardView, defStyleAttr, R.style.CardView_Light);
   int backgroundColor = a.getColor(R.styleable.CardView_cardBackgroundColor, 0);
   float radius = a.getDimension(R.styleable.CardView_cardCornerRadius, 0);
   float elevation = a.getDimension(R.styleable.CardView_cardElevation, 0);
   float maxElevation = a.getDimension(R.styleable.CardView_cardMaxElevation, 0);
   mCompatPadding = a.getBoolean(R.styleable.CardView_cardUseCompatPadding, false);
   mPreventCornerOverlap = a.getBoolean(R.styleable.CardView_cardPreventCornerOverlap, true);
   int defaultPadding = a.getDimensionPixelSize(R.styleable.CardView_contentPadding, 0);
   mContentPadding.left =
       a.getDimensionPixelSize(R.styleable.CardView_contentPaddingLeft, defaultPadding);
   mContentPadding.top =
       a.getDimensionPixelSize(R.styleable.CardView_contentPaddingTop, defaultPadding);
   mContentPadding.right =
       a.getDimensionPixelSize(R.styleable.CardView_contentPaddingRight, defaultPadding);
   mContentPadding.bottom =
       a.getDimensionPixelSize(R.styleable.CardView_contentPaddingBottom, defaultPadding);
   if (elevation > maxElevation) {
     maxElevation = elevation;
   }
   a.recycle();
   IMPL.initialize(this, context, backgroundColor, radius, elevation, maxElevation);
 }
  @Override
  public void getItemOffsets(
      Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
    super.getItemOffsets(outRect, view, parent, state);
    if (mDivider == null) {
      return;
    }

    int position = parent.getChildAdapterPosition(view);
    if (position == RecyclerView.NO_POSITION || (position == 0 && !mShowFirstDivider)) {
      return;
    }

    if (mOrientation == -1) getOrientation(parent);

    if (mOrientation == LinearLayoutManager.VERTICAL) {
      outRect.top = mDivider.getIntrinsicHeight();
      if (mShowLastDivider && position == (state.getItemCount() - 1)) {
        outRect.bottom = outRect.top;
      }
    } else {
      outRect.left = mDivider.getIntrinsicWidth();
      if (mShowLastDivider && position == (state.getItemCount() - 1)) {
        outRect.right = outRect.left;
      }
    }
  }
    public void onClick(View v) {
      try {
        String pos = (String) v.getTag();
        Intent intent = new Intent(LauncherIntent.Action.ACTION_VIEW_CLICK);
        intent.setComponent(mAppWidgetProvider);
        intent
            .putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId)
            .putExtra(LauncherIntent.Extra.EXTRA_APPWIDGET_ID, mAppWidgetId);
        intent.putExtra(LauncherIntent.Extra.EXTRA_VIEW_ID, v.getId());
        intent.putExtra(LauncherIntent.Extra.Scroll.EXTRA_LISTVIEW_ID, mListViewId);
        intent.putExtra(LauncherIntent.Extra.Scroll.EXTRA_ITEM_POS, pos);

        Rect srcRect = new Rect();
        final int[] location = new int[2];
        v.getLocationOnScreen(location);
        srcRect.left = location[0];
        srcRect.top = location[1];
        srcRect.right = srcRect.left + v.getWidth();
        srcRect.bottom = srcRect.top + v.getHeight();
        intent.putExtra(LauncherIntent.Extra.Scroll.EXTRA_SOURCE_BOUNDS, srcRect);

        v.getContext().sendBroadcast(intent);
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  /** Measures and layouts the scrollbar and decorations. */
  public void updatePopAlphabetLayout() {
    // Prevent re-entry when RTL properties change as a side-effect of
    // resolving padding.
    if (mUpdatingLayout) {
      return;
    }

    mUpdatingLayout = true;

    updateContainerRect();

    final Rect bounds = mTempBounds;
    measurePreview(mPrimaryText, bounds);
    applyLayout(mPrimaryText, bounds);
    measurePreview(mSecondaryText, bounds);
    applyLayout(mSecondaryText, bounds);

    if (mPreviewImage != null) {
      // Apply preview image padding.
      bounds.left -= mPreviewImage.getPaddingLeft();
      bounds.top -= mPreviewImage.getPaddingTop();
      bounds.right += mPreviewImage.getPaddingRight();
      bounds.bottom += mPreviewImage.getPaddingBottom();
      applyLayout(mPreviewImage, bounds);
    }
  }
Beispiel #30
0
    // 새로운 도형을 목록에 추가한다.
    void AddNewShape() {
      Shape shape = new Shape();
      int idx;
      boolean bFindIntersect;
      Rect rt = new Rect();

      // 기존 도형과 겹치지 않는 새 위치를 찾는다.
      for (; ; ) {
        // 크기는 32, 48, 64 중 하나 선택
        int Size = 32 + 16 * Rnd.nextInt(3);

        // 위치는 난수로 선택
        rt.left = Rnd.nextInt(getWidth());
        rt.top = Rnd.nextInt(getHeight());
        rt.right = rt.left + Size;
        rt.bottom = rt.top + Size;

        // 화면을 벗어나면 안된다.
        if (rt.right > getWidth() || rt.bottom > getHeight()) {
          continue;
        }

        // 기존 도형 순회하며 겹치는지 조사한다.
        bFindIntersect = false;
        for (idx = 0; idx < arShape.size(); idx++) {
          if (rt.intersect(arShape.get(idx).rt) == true) {
            bFindIntersect = true;
          }
        }

        // 겹치지 않을 때 확정한다. 겹치면 계속 새 위치 선정한다.
        if (bFindIntersect == false) {
          break;
        }
      }

      // 새 도형 정보 작성. 모양, 색상 등을 난수 선택한다.
      shape.what = Rnd.nextInt(3);

      switch (Rnd.nextInt(5)) {
        case 0:
          shape.color = Color.WHITE;
          break;
        case 1:
          shape.color = Color.RED;
          break;
        case 2:
          shape.color = Color.GREEN;
          break;
        case 3:
          shape.color = Color.BLUE;
          break;
        case 4:
          shape.color = Color.YELLOW;
          break;
      }

      shape.rt = rt;
      arShape.add(shape);
    }