示例#1
0
  protected void onDrawCell(Canvas canvas, Cell cell) {
    if (cell.text == null && cell.bgColor == null && cell.rtDrawable == null)
      return; // 如果无内容,且无背景色不进行绘制
    Rect rect = this.getCellRectInView(cell);
    if (cell.bgColor != null) {

      canvas.drawColor(cell.bgColor);
    }

    if (cell.ballColor != null) {
      painter.setColor(cell.ballColor);
      canvas.drawCircle(rect.centerX(), rect.centerY(), rect.height() / 2 - 1 * dp, painter);
    }
    if (cell.textColor != null) painter.setColor(cell.textColor);
    if (cell.text != null) {
      if (cell.textSize > 0) painter.setTextSize(cell.textSize);
      else painter.setTextSize(this.textSize);
      painter.setTextAlign(cell.aligin);
      int cx = rect.centerX();
      if (cell.aligin == Align.LEFT) cx = rect.left;
      else if (cell.aligin == Align.RIGHT) cx = rect.right;
      int cy = rect.centerY() + (int) (painter.getTextSize() * 2 / 5 + 0.5f);
      if (cell.fixedTextX) cx -= offX;
      if (cell.fixedTextY) cy -= offY;

      canvas.drawText(cell.text, cx, cy, painter);
    }
    if (cell.rtDrawable != null) {
      int minWidth = cell.rtDrawable.getMinimumWidth();
      if (minWidth > rect.width() / 2) minWidth = rect.width() / 2;
      cell.rtDrawable.setBounds(
          new Rect(rect.right - minWidth, rect.top, rect.right, rect.top + minWidth));
      cell.rtDrawable.draw(canvas);
    }
  }
  private void doSelectionHandleTestUrlLaunched(TestPageType pageType) throws Throwable {
    clickNodeToShowSelectionHandles(pageType.nodeId);
    assertWaitForSelectionEditableEquals(pageType.selectionShouldBeEditable);

    HandleView startHandle = getStartHandle();
    HandleView endHandle = getEndHandle();

    Rect nodeWindowBounds = getNodeBoundsPix(pageType.nodeId);

    int leftX = (nodeWindowBounds.left + nodeWindowBounds.centerX()) / 2;
    int centerX = nodeWindowBounds.centerX();
    int rightX = (nodeWindowBounds.right + nodeWindowBounds.centerX()) / 2;

    int topY = (nodeWindowBounds.top + nodeWindowBounds.centerY()) / 2;
    int centerY = nodeWindowBounds.centerY();
    int bottomY = (nodeWindowBounds.bottom + nodeWindowBounds.centerY()) / 2;

    // Drag start handle up and to the left. The selection start should decrease.
    dragHandleAndCheckSelectionChange(startHandle, leftX, topY, -1, 0);
    // Drag end handle down and to the right. The selection end should increase.
    dragHandleAndCheckSelectionChange(endHandle, rightX, bottomY, 0, 1);
    // Drag start handle back to the middle. The selection start should increase.
    dragHandleAndCheckSelectionChange(startHandle, centerX, centerY, 1, 0);
    // Drag end handle up and to the left past the start handle. Both selection start and end
    // should decrease.
    dragHandleAndCheckSelectionChange(endHandle, leftX, topY, -1, -1);
    // Drag start handle down and to the right past the end handle. Both selection start and end
    // should increase.
    dragHandleAndCheckSelectionChange(startHandle, rightX, bottomY, 1, 1);

    clickToDismissHandles();
  }
示例#3
0
    public void move(int s) {
      int dx = (int) Math.abs(mRect.centerX() - destination);

      if (destination < mRect.centerX()) {
        mRect.offset((dx > s) ? -s : -dx, 0);
        slaveMover(s, dx, s, dx);

      } else if (destination > mRect.centerX()) {
        mRect.offset((dx > s) ? s : dx, 0);
        slaveMover(s, dx, -s, -dx);
      }
    }
  /**
   * Actual internal method to show this dialog. Called only by {@link #considerShowing()} when all
   * data requirements have been met.
   */
  private void showInternal() {
    mDecor = mWindow.getDecorView();
    mDecor.getViewTreeObserver().addOnGlobalLayoutListener(this);
    WindowManager.LayoutParams l = mWindow.getAttributes();

    l.width = mScreenWidth + mShadowHoriz + mShadowHoriz;
    l.height = WindowManager.LayoutParams.WRAP_CONTENT;

    // Force layout measuring pass so we have baseline numbers
    mDecor.measure(l.width, l.height);
    final int blockHeight = mDecor.getMeasuredHeight();

    l.gravity = Gravity.TOP | Gravity.LEFT;
    l.x = -mShadowHoriz;

    if (mAnchor.top > blockHeight) {
      // Show downwards callout when enough room, aligning bottom block
      // edge with top of anchor area, and adjusting to inset arrow.
      showArrow(R.id.arrow_down, mAnchor.centerX());
      l.y = mAnchor.top - blockHeight + mShadowVert;
      l.windowAnimations = R.style.QuickContactAboveAnimation;

    } else {
      // Otherwise show upwards callout, aligning block top with bottom of
      // anchor area, and adjusting to inset arrow.
      showArrow(R.id.arrow_up, mAnchor.centerX());
      l.y = mAnchor.bottom - mShadowVert;
      l.windowAnimations = R.style.QuickContactBelowAnimation;
    }

    l.flags =
        WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
            | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;

    mRequestedY = l.y;
    mWindowManager.addView(mDecor, l);
    mShowing = true;
    mQuerying = false;
    mDismissed = false;

    mTrack.startAnimation(mTrackAnim);

    if (TRACE_LAUNCH) {
      android.os.Debug.stopMethodTracing();
      Log.d(
          TAG,
          "Window recycled " + mWindowRecycled + " times, chiclets " + mActionRecycled + " times");
    }
  }
  @Override
  public void draw(Canvas canvas) {
    Rect bounds = getBounds();
    final boolean isRtl = isLayoutRtl();
    // Interpolated widths of arrow bars
    final float arrowSize = lerp(mBarSize, mTopBottomArrowSize, mProgress);
    final float middleBarSize = lerp(mBarSize, mMiddleArrowSize, mProgress);
    // Interpolated size of middle bar
    final float middleBarCut = lerp(0, mBarThickness / 2, mProgress);
    // The rotation of the top and bottom bars (that make the arrow head)
    final float rotation = lerp(0, ARROW_HEAD_ANGLE, mProgress);

    // The whole canvas rotates as the transition happens
    final float canvasRotate = lerp(isRtl ? 180 : 0, isRtl ? 0 : 180, mProgress);
    final float topBottomBarOffset = lerp(mBarGap + mBarThickness, 0, mProgress);
    mPath.rewind();

    final float arrowEdge = -middleBarSize / 2;
    // draw middle bar
    mPath.moveTo(arrowEdge + middleBarCut, 0);
    mPath.rLineTo(middleBarSize - middleBarCut, 0);

    final float arrowWidth = Math.round(arrowSize * Math.cos(rotation));
    final float arrowHeight = Math.round(arrowSize * Math.sin(rotation));

    // top bar
    mPath.moveTo(arrowEdge, topBottomBarOffset);
    mPath.rLineTo(arrowWidth, arrowHeight);

    // bottom bar
    mPath.moveTo(arrowEdge, -topBottomBarOffset);
    mPath.rLineTo(arrowWidth, -arrowHeight);
    mPath.moveTo(0, 0);
    mPath.close();

    canvas.save();
    // Rotate the whole canvas if spinning, if not, rotate it 180 to get
    // the arrow pointing the other way for RTL.
    if (mSpin) {
      canvas.rotate(
          canvasRotate * ((mVerticalMirror ^ isRtl) ? -1 : 1), bounds.centerX(), bounds.centerY());
    } else if (isRtl) {
      canvas.rotate(-180, bounds.centerX(), bounds.centerY());
    }
    canvas.translate(bounds.centerX(), bounds.centerY());
    canvas.drawPath(mPath, mPaint);

    canvas.restore();
  }
  private void updateThumbPos(int posX) {
    int thumbWidth = mThumb.getIntrinsicWidth();
    int halfThumb = thumbWidth / 2;
    int start;
    if (isRtl()) {
      start = getWidth() - getPaddingRight() - mAddedTouchBounds;
      posX = start - posX - thumbWidth;
    } else {
      start = getPaddingLeft() + mAddedTouchBounds;
      posX = start + posX;
    }
    mThumb.copyBounds(mInvalidateRect);
    mThumb.setBounds(posX, mInvalidateRect.top, posX + thumbWidth, mInvalidateRect.bottom);
    if (isRtl()) {
      mScrubber.getBounds().right = start - halfThumb;
      mScrubber.getBounds().left = posX + halfThumb;
    } else {
      mScrubber.getBounds().left = start + halfThumb;
      mScrubber.getBounds().right = posX + halfThumb;
    }
    final Rect finalBounds = mTempRect;
    mThumb.copyBounds(finalBounds);
    if (!isInEditMode()) {
      mIndicator.move(finalBounds.centerX());
    }

    mInvalidateRect.inset(-mAddedTouchBounds, -mAddedTouchBounds);
    finalBounds.inset(-mAddedTouchBounds, -mAddedTouchBounds);
    mInvalidateRect.union(finalBounds);
    SeekBarCompat.setHotspotBounds(
        mRipple, finalBounds.left, finalBounds.top, finalBounds.right, finalBounds.bottom);
    invalidate(mInvalidateRect);
  }
 public static void scaleRectAboutCenter(Rect r, float scale) {
   int cx = r.centerX();
   int cy = r.centerY();
   r.offset(-cx, -cy);
   Utilities.scaleRect(r, scale);
   r.offset(cx, cy);
 }
示例#8
0
  public void onDrawRectText(Canvas canvas, Rect rect) {

    Rect textBounds = new Rect();

    paint = new Paint();
    paint.setStrokeWidth(textSize);
    paint.setTextSize(textSize);
    paint.setColor(textColor);
    paint.setTextAlign(Paint.Align.CENTER);
    paint.getTextBounds(text, 0, text.length(), textBounds);

    canvas.drawText(text, rect.centerX(), rect.centerY() - textBounds.exactCenterY(), paint);

    this.rect = rect;
    this.x = rect.centerX();
    this.y = rect.centerY() - textBounds.exactCenterY();
  }
示例#9
0
  /** Show popup mWindow */
  public void show(View anchor) {
    preShow();

    int[] location = new int[2];

    mDidAction = false;

    anchor.getLocationOnScreen(location);

    Rect anchorRect =
        new Rect(
            location[0],
            location[1],
            location[0] + anchor.getWidth(),
            location[1] + anchor.getHeight());

    // mRootView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
    // LayoutParams.WRAP_CONTENT));
    mRootView.measure(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

    int rootWidth = mRootView.getMeasuredWidth();
    int rootHeight = mRootView.getMeasuredHeight();

    int screenWidth = mWindowManager.getDefaultDisplay().getWidth();
    // int screenHeight 	= mWindowManager.getDefaultDisplay().getHeight();

    // int xPos 			= (screenWidth - rootWidth) / 2;
    int xPos = anchorRect.left;
    int yPos = anchorRect.top - rootHeight;

    boolean onTop = true;

    // display on bottom
    if (rootHeight > anchor.getTop()) {
      yPos = anchorRect.bottom;
      onTop = false;
    }

    showArrow(((onTop) ? R.id.arrow_down : R.id.arrow_up), anchorRect.centerX());

    setAnimationStyle(screenWidth, anchorRect.centerX(), onTop);

    mWindow.showAtLocation(anchor, Gravity.NO_GRAVITY, xPos, yPos);

    if (mAnimateTrack) mTrack.startAnimation(mTrackAnim);
  }
示例#10
0
  // Determines which edges are hit by touching at (x, y).
  public int getHit(float x, float y) {

    Rect r = computeLayout();
    final float hysteresis = 20F;
    int retval = GROW_NONE;

    if (mCircle) {
      float distX = x - r.centerX();
      float distY = y - r.centerY();
      int distanceFromCenter = (int) Math.sqrt(distX * distX + distY * distY);
      int radius = mDrawRect.width() / 2;
      int delta = distanceFromCenter - radius;
      if (Math.abs(delta) <= hysteresis) {
        if (Math.abs(distY) > Math.abs(distX)) {
          if (distY < 0) {
            retval = GROW_TOP_EDGE;
          } else {
            retval = GROW_BOTTOM_EDGE;
          }
        } else {
          if (distX < 0) {
            retval = GROW_LEFT_EDGE;
          } else {
            retval = GROW_RIGHT_EDGE;
          }
        }
      } else if (distanceFromCenter < radius) {
        retval = MOVE;
      } else {
        retval = GROW_NONE;
      }
    } else {
      // verticalCheck makes sure the position is between the top and
      // the bottom edge (with some tolerance). Similar for horizCheck.
      boolean verticalCheck = (y >= r.top - hysteresis) && (y < r.bottom + hysteresis);
      boolean horizCheck = (x >= r.left - hysteresis) && (x < r.right + hysteresis);

      // Check whether the position is near some edge(s).
      if ((Math.abs(r.left - x) < hysteresis) && verticalCheck) {
        retval |= GROW_LEFT_EDGE;
      }
      if ((Math.abs(r.right - x) < hysteresis) && verticalCheck) {
        retval |= GROW_RIGHT_EDGE;
      }
      if ((Math.abs(r.top - y) < hysteresis) && horizCheck) {
        retval |= GROW_TOP_EDGE;
      }
      if ((Math.abs(r.bottom - y) < hysteresis) && horizCheck) {
        retval |= GROW_BOTTOM_EDGE;
      }

      // Not near any edge but inside the rectangle: move.
      if (retval == GROW_NONE && r.contains((int) x, (int) y)) {
        retval = MOVE;
      }
    }
    return retval;
  }
示例#11
0
  private void drawMovRect(Canvas canvas) {

    canvas.drawRect(movRect, dragging);
    canvas.drawText(
        selNum + "",
        movRect.centerX(),
        movRect.centerY() + textOffsetY - cellLength / 2,
        number_fixed);
  }
示例#12
0
  @Override
  protected synchronized void onDraw(Canvas canvas) {
    if ((mThumb != null) && (mDots.size() > 1)) {
      if (isSelected) {
        for (Dot dot : mDots) {
          if (dot.isSelected) {
            Rect bounds = mThumb.copyBounds();
            bounds.right = dot.mX;
            bounds.left = dot.mX;
            mThumb.setBounds(bounds);
            break;
          }
        }
      } else {
        int intervalWidth = mDots.get(1).mX - mDots.get(0).mX;
        Rect bounds = mThumb.copyBounds();
        // find nearest dot
        if ((mDots.get(mDots.size() - 1).mX - bounds.centerX()) < 0) {
          bounds.right = mDots.get(mDots.size() - 1).mX;
          bounds.left = mDots.get(mDots.size() - 1).mX;
          mThumb.setBounds(bounds);

          for (Dot dot : mDots) {
            dot.isSelected = false;
          }
          mDots.get(mDots.size() - 1).isSelected = true;
          handleClick(mDots.get(mDots.size() - 1));
        } else {
          for (int i = 0; i < mDots.size(); i++) {
            if (Math.abs(mDots.get(i).mX - bounds.centerX()) <= (intervalWidth / 2)) {
              bounds.right = mDots.get(i).mX;
              bounds.left = mDots.get(i).mX;
              mThumb.setBounds(bounds);
              mDots.get(i).isSelected = true;
              handleClick(mDots.get(i));
            } else {
              mDots.get(i).isSelected = false;
            }
          }
        }
      }
    }
    super.onDraw(canvas);
  }
 @Override
 protected synchronized void onDraw(Canvas canvas) {
   // First draw the regular progress bar, then custom draw our text
   super.onDraw(canvas);
   Rect bounds = new Rect();
   textPaint.getTextBounds(text, 0, text.length(), bounds);
   int x = getWidth() / 2 - bounds.centerX();
   int y = getHeight() / 2 - bounds.centerY();
   canvas.drawText(text, x, y, textPaint);
 }
示例#14
0
  /**
   * @param command The {@link AndroidCommand}
   * @return {@link AndroidCommandResult}
   * @throws JSONException
   * @see
   *     io.appium.android.bootstrap.CommandHandler#execute(io.appium.android.bootstrap.AndroidCommand)
   */
  @Override
  public AndroidCommandResult execute(final AndroidCommand command) throws JSONException {
    initalize();
    try {
      params = command.params();

      // isElementCommand doesn't check to see if we actually have an element
      // so getElement is used instead.
      try {
        if (command.getElement() != null) {
          isElement = true;
        }
      } catch (final Exception e) {
        isElement = false;
      }

      if (isElement) {
        // extract x and y from the element.
        el = command.getElement();

        final Rect bounds = el.getVisibleBounds();
        clickX = bounds.centerX();
        clickY = bounds.centerY();
      } else { // no element so extract x and y from params
        final Object paramX = params.get("x");
        final Object paramY = params.get("y");
        double targetX = 0.5;
        double targetY = 0.5;
        if (paramX != null) {
          targetX = Double.parseDouble(paramX.toString());
        }

        if (paramY != null) {
          targetY = Double.parseDouble(paramY.toString());
        }

        final ArrayList<Integer> posVals = absPosFromCoords(new Double[] {targetX, targetY});
        clickX = posVals.get(0);
        clickY = posVals.get(1);
      }

      if (executeTouchEvent()) {
        return getSuccessResult(true);
      }

    } catch (final UiObjectNotFoundException e) {
      return new AndroidCommandResult(WDStatus.NO_SUCH_ELEMENT, e.getMessage());
    } catch (final ElementNotInHashException e) {
      return new AndroidCommandResult(WDStatus.NO_SUCH_ELEMENT, e.getMessage());
    } catch (final Exception e) {
      return getErrorResult(e.getMessage());
    }
    return getErrorResult("Failed to execute touch event");
  }
  public int addBand(Rect rect) {
    mBands.add(0, mCurrentBand = new Band(rect.centerX(), rect.centerY()));
    mCurrentBand.mask = false;
    int x = (mCurrentBand.xPos1 + mCurrentBand.xPos2) / 2;
    int y = (mCurrentBand.yPos1 + mCurrentBand.yPos2) / 2;
    double addDelta = ADD_MIN_DIST * Math.max(rect.width(), rect.height());
    boolean moved = true;
    int count = 0;
    int toMove = mBands.indexOf(mCurrentBand);

    while (moved) {
      moved = false;
      count++;
      if (count > 14) {
        break;
      }

      for (Band point : mBands) {
        if (point.mask) {
          break;
        }
      }

      for (Band point : mBands) {
        if (point.mask) {
          break;
        }
        int index = mBands.indexOf(point);

        if (toMove != index) {
          double dist = Math.hypot(point.xPos1 - x, point.yPos1 - y);
          if (dist < addDelta) {
            moved = true;
            mCurrentBand.xPos1 += addDelta;
            mCurrentBand.yPos1 += addDelta;
            mCurrentBand.xPos2 += addDelta;
            mCurrentBand.yPos2 += addDelta;
            x = (mCurrentBand.xPos1 + mCurrentBand.xPos2) / 2;
            y = (mCurrentBand.yPos1 + mCurrentBand.yPos2) / 2;

            if (mCurrentBand.yPos1 > rect.bottom) {
              mCurrentBand.yPos1 = (int) (rect.top + addDelta);
            }
            if (mCurrentBand.xPos1 > rect.right) {
              mCurrentBand.xPos1 = (int) (rect.left + addDelta);
            }
          }
        }
      }
    }
    trimVector();
    return 0;
  }
  @Override
  public void draw(Canvas canvas) {
    final Rect bounds = getBounds();

    // Calculations on the different components sizes
    int size = Math.min(bounds.height(), bounds.width());
    float outerRadius = (size / 2) - (ringWidth / 2);
    float innerRadius = outerRadius - ringWidth / 2; // * circleScale;
    float offsetX = (bounds.width() - outerRadius * 2) / 2;
    float offsetY = (bounds.height() - outerRadius * 2) / 2;

    // Outline Circle
    paint.setStyle(Paint.Style.STROKE);
    paint.setStrokeWidth(ringWidth / 2);
    paint.setColor(outlineColor);
    canvas.drawCircle(bounds.centerX(), bounds.centerY(), outerRadius, paint);

    // Inner circle
    paint.setStyle(Paint.Style.FILL);
    paint.setColor(centerColor);
    canvas.drawCircle(bounds.centerX(), bounds.centerY(), innerRadius, paint);

    int halfRingWidth = ringWidth / 2;
    float arcX0 = offsetX + halfRingWidth;
    float arcY0 = offsetY + halfRingWidth;
    float arcX = offsetX + outerRadius * 2 - halfRingWidth;
    float arcY = offsetY + outerRadius * 2 - halfRingWidth;

    // Outer Circle
    paint.setColor(ringColor);
    paint.setStyle(Paint.Style.STROKE);
    paint.setStrokeWidth(ringWidth);
    paint.setStrokeCap(Paint.Cap.ROUND);
    arcElements.set(arcX0, arcY0, arcX, arcY);
    if (indeterminate) {
      canvas.drawArc(arcElements, progress, 90, false, paint);
    } else {
      canvas.drawArc(arcElements, 89, progress, false, paint);
    }
  }
 @Override
 public void doDraw(Canvas canvas, Paint paint) {
   Rect bounds = getBounds();
   int size = Math.min(bounds.width(), bounds.height());
   float scale = mCurrentScale;
   int rippleColor = mRippleColor;
   int bgColor = mRippleBgColor;
   float radius = (size / 2);
   float radiusAnimated = radius * scale;
   if (scale > INACTIVE_SCALE) {
     if (bgColor != 0) {
       paint.setColor(bgColor);
       paint.setAlpha(decreasedAlpha(Color.alpha(bgColor)));
       canvas.drawCircle(bounds.centerX(), bounds.centerY(), radius, paint);
     }
     if (rippleColor != 0) {
       paint.setColor(rippleColor);
       paint.setAlpha(modulateAlpha(Color.alpha(rippleColor)));
       canvas.drawCircle(bounds.centerX(), bounds.centerY(), radiusAnimated, paint);
     }
   }
 }
示例#18
0
  @Override
  public void onMeasureLayout(Rect anchorRect, View contentView) {
    int anchorX = anchorRect.centerX();
    int dyTop = anchorRect.top;
    int dyBottom = getScreenHeight() - anchorRect.bottom;

    RelativeLayout.LayoutParams params =
        new RelativeLayout.LayoutParams(
            getScreenWidth() / 2, RelativeLayout.LayoutParams.WRAP_CONTENT);
    getListView().setLayoutParams(params);
    boolean isOnAnchorTop = (dyTop > dyBottom);
    int rootHeight = contentView.getMeasuredHeight();
    int popupY = (isOnAnchorTop) ? anchorRect.top - rootHeight : anchorRect.bottom + 5;

    int popupX = anchorRect.centerX();
    if (anchorX < getScreenWidth() / 4) {
      popupX = 5;
    } else if (anchorX > 3 * getScreenWidth() / 4) {
      popupX = getScreenWidth() - anchorRect.width() - 5;
    }
    setWidgetPosition(popupX, popupY, isOnAnchorTop);
  }
示例#19
0
 @Override
 public void onDraw(Canvas canvas) {
   mPaint.setStrokeWidth(mInnerStroke);
   canvas.drawCircle(mCenterX, mCenterY, mMinCircle, mPaint);
   canvas.drawCircle(mCenterX, mCenterY, mMaxCircle, mPaint);
   canvas.drawLine(mCenterX - mMinCircle, mCenterY, mCenterX - mMaxCircle - 4, mCenterY, mPaint);
   mPaint.setStrokeWidth(mOuterStroke);
   canvas.drawCircle((float) mCenterX, (float) mCenterY, (float) mCircleSize, mPaint);
   String txt = mZoomSig + "." + mZoomFraction + "x";
   mTextPaint.getTextBounds(txt, 0, txt.length(), mTextBounds);
   canvas.drawText(
       txt, mCenterX - mTextBounds.centerX(), mCenterY - mTextBounds.centerY(), mTextPaint);
 }
示例#20
0
  private void centerAboutIcon() {
    DragLayer.LayoutParams lp = (DragLayer.LayoutParams) getLayoutParams();

    int width = getPaddingLeft() + getPaddingRight() + mContent.getDesiredWidth();
    int height =
        getPaddingTop() + getPaddingBottom() + mContent.getDesiredHeight() + mFolderNameHeight;
    DragLayer parent = (DragLayer) mLauncher.findViewById(R.id.drag_layer);

    parent.getDescendantRectRelativeToSelf(mFolderIcon, mTempRect);

    int centerX = mTempRect.centerX();
    int centerY = mTempRect.centerY();
    int centeredLeft = centerX - width / 2;
    int centeredTop = centerY - height / 2;

    // We first fetch the currently visible CellLayoutChildren
    CellLayout currentPage = mLauncher.getWorkspace().getCurrentDropLayout();
    CellLayoutChildren boundingLayout = currentPage.getChildrenLayout();
    Rect bounds = new Rect();
    parent.getDescendantRectRelativeToSelf(boundingLayout, bounds);

    // We need to bound the folder to the currently visible CellLayoutChildren
    int left = Math.min(Math.max(bounds.left, centeredLeft), bounds.left + bounds.width() - width);
    int top = Math.min(Math.max(bounds.top, centeredTop), bounds.top + bounds.height() - height);
    // If the folder doesn't fit within the bounds, center it about the desired bounds
    if (width >= bounds.width()) {
      left = bounds.left + (bounds.width() - width) / 2;
    }
    if (height >= bounds.height()) {
      top = bounds.top + (bounds.height() - height) / 2;
    }

    int folderPivotX = width / 2 + (centeredLeft - left);
    int folderPivotY = height / 2 + (centeredTop - top);
    setPivotX(folderPivotX);
    setPivotY(folderPivotY);
    int folderIconPivotX = (int) (mFolderIcon.getMeasuredWidth() * (1.0f * folderPivotX / width));
    int folderIconPivotY = (int) (mFolderIcon.getMeasuredHeight() * (1.0f * folderPivotY / height));
    mFolderIcon.setPivotX(folderIconPivotX);
    mFolderIcon.setPivotY(folderIconPivotY);

    if (mMode == PARTIAL_GROW) {
      lp.width = width;
      lp.height = height;
      lp.x = left;
      lp.y = top;
    } else {
      mNewSize.set(left, top, left + width, top + height);
    }
  }
 /** Refreshes {@link #mCoordinates} with values based on {@link #mContentRect}. */
 private void refreshCoordinates() {
   int x = mContentRect.centerX() - mPopup.getWidth() / 2;
   int y;
   if (mContentRect.top > mPopup.getHeight()) {
     y = mContentRect.top - mPopup.getHeight();
     mOverflowDirection = FloatingToolbarPopup.OVERFLOW_DIRECTION_UP;
   } else if (mContentRect.top > mPopup.getToolbarHeightWithVerticalMargin()) {
     y = mContentRect.top - mPopup.getToolbarHeightWithVerticalMargin();
     mOverflowDirection = FloatingToolbarPopup.OVERFLOW_DIRECTION_DOWN;
   } else {
     y = mContentRect.bottom;
     mOverflowDirection = FloatingToolbarPopup.OVERFLOW_DIRECTION_DOWN;
   }
   mCoordinates.set(x, y);
 }
  private void clickNodeToShowSelectionHandles(String nodeId) throws Throwable {
    Rect nodeWindowBounds = getNodeBoundsPix(nodeId);

    TouchCommon touchCommon = new TouchCommon(this);
    int centerX = nodeWindowBounds.centerX();
    int centerY = nodeWindowBounds.centerY();
    touchCommon.longPressView(getContentViewCore().getContainerView(), centerX, centerY);

    assertWaitForHandlesShowingEquals(true);
    assertWaitForHandleViewStopped(getStartHandle());

    // No words wrap in the sample text so handles should be at the same y
    // position.
    assertEquals(getStartHandle().getPositionY(), getEndHandle().getPositionY());
  }
示例#23
0
 public void showIndicator(View parent, Rect touchBounds) {
   if (this.isShowing()) {
     this.mPopupView.mMarker.animateOpen();
   } else {
     IBinder windowToken = parent.getWindowToken();
     if (windowToken != null) {
       LayoutParams p = this.createPopupLayout(windowToken);
       p.gravity = 8388659;
       this.updateLayoutParamsForPosiion(parent, p, touchBounds.bottom);
       this.mShowing = true;
       this.translateViewIntoPosition(touchBounds.centerX());
       this.invokePopup(p);
     }
   }
 }
示例#24
0
  /**
   * This is meant to be a "pure" tile drawing function that doesn't take into account
   * osmdroid-specific characteristics (like osmdroid's canvas's having 0,0 as the center rather
   * than the upper-left corner). Once the tile is ready to be drawn, it is passed to
   * onTileReadyToDraw where custom manipulations can be made before drawing the tile.
   */
  public void drawTiles(
      final Canvas c,
      final Projection projection,
      final int zoomLevel,
      final int tileSizePx,
      final Rect viewPort) {

    mProjection = projection;
    mTileLooper.loop(c, zoomLevel, tileSizePx, viewPort);

    // draw a cross at center in debug mode
    if (DEBUGMODE) {
      // final GeoPoint center = osmv.getMapCenter();
      final Point centerPoint = new Point(viewPort.centerX(), viewPort.centerY());
      c.drawLine(centerPoint.x, centerPoint.y - 9, centerPoint.x, centerPoint.y + 9, mDebugPaint);
      c.drawLine(centerPoint.x - 9, centerPoint.y, centerPoint.x + 9, centerPoint.y, mDebugPaint);
    }
  }
  public void showIndicator(View parent, Rect touchBounds) {
    if (isShowing()) {
      mPopupView.mMarker.animateOpen();
      return;
    }

    IBinder windowToken = parent.getWindowToken();
    if (windowToken != null) {
      WindowManager.LayoutParams p = createPopupLayout(windowToken);

      p.gravity = Gravity.TOP | GravityCompat.START;
      updateLayoutParamsForPosiion(parent, p, touchBounds.bottom);
      mShowing = true;

      translateViewIntoPosition(touchBounds.centerX());
      invokePopup(p);
    }
  }
示例#26
0
  private void showArrow() {
    final View contentView = getContentView();
    final int arrowId = mIsOnTop ? R.id.gdi_arrow_down : R.id.gdi_arrow_up;
    final View arrow = contentView.findViewById(arrowId);
    final View arrowUp = contentView.findViewById(R.id.gdi_arrow_up);
    final View arrowDown = contentView.findViewById(R.id.gdi_arrow_down);

    if (arrowId == R.id.gdi_arrow_up) {
      arrowUp.setVisibility(View.VISIBLE);
      arrowDown.setVisibility(View.INVISIBLE);
    } else if (arrowId == R.id.gdi_arrow_down) {
      arrowUp.setVisibility(View.INVISIBLE);
      arrowDown.setVisibility(View.VISIBLE);
    }

    ViewGroup.MarginLayoutParams param = (ViewGroup.MarginLayoutParams) arrow.getLayoutParams();
    param.leftMargin = mRect.centerX() - (arrow.getMeasuredWidth()) / 2;
  }
        @Override
        public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {

          mScroller.fling(
              mRect.centerX(),
              mRect.centerY(),
              Math.round(velocityX),
              Math.round(velocityY),
              0,
              getWidth() - SIZE,
              0,
              getHeight() - SIZE,
              SIZE / 2,
              SIZE / 2);

          ViewCompat.postInvalidateOnAnimation(ScrollerView.this);

          return true;
        }
示例#28
0
  private void drawBackspace(
      Canvas canvas, Keyboard.Key key, String color, String strokeColor, String textColor) {
    int fontValue = 140;
    int maxTextSize = (int) getDensityPixels(fontValue);
    Rect keyRectangle = new Rect(key.x, key.y, key.x + key.width, key.y + key.height);

    if (mPaint == null) {
      mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    }

    mPaint.setStyle(Paint.Style.FILL);
    mPaint.setColor(Color.parseColor(color));
    canvas.drawRect(keyRectangle, mPaint);

    mPaint.setColor(Color.parseColor(strokeColor));
    mPaint.setStyle(Paint.Style.STROKE);
    mPaint.setStrokeWidth(getDensityPixels(5));
    canvas.drawRect(keyRectangle, mPaint);

    mPaint.setColor(Color.parseColor(textColor));
    mPaint.setTextAlign(Paint.Align.CENTER);
    mPaint.setTextSize(maxTextSize);
    mPaint.setStyle(Paint.Style.FILL);

    Rect bounds = new Rect();
    mPaint.getTextBounds(key.label.toString(), 0, key.label.length(), bounds);

    while (bounds.height() > (keyRectangle.height() / 10) * 6
        || bounds.width() >= (keyRectangle.width() / 10) * 9) {
      fontValue -= 1;
      mPaint.setTextSize(getDensityPixels(fontValue));
      mPaint.getTextBounds(key.label.toString(), 0, key.label.length(), bounds);
    }

    canvas.drawText(
        key.label.toString(),
        keyRectangle.centerX(),
        keyRectangle.centerY() - bounds.exactCenterY(),
        mPaint);
  }
  @Override
  protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    if (location == null
        || foregroundBounds == null
        || backgroundBounds == null
        || accuracyAnimator == null) {
      // Not ready yet
      return;
    }

    // Draw circle
    float metersPerPixel = (float) projection.getMetersPerPixelAtLatitude(location.getLatitude());
    float accuracyPixels = (Float) accuracyAnimator.getAnimatedValue() / metersPerPixel;
    float maxRadius = getWidth() / 2;
    canvas.drawCircle(
        foregroundBounds.centerX(),
        foregroundBounds.centerY(),
        accuracyPixels <= maxRadius ? accuracyPixels : maxRadius,
        accuracyPaint);

    // Draw shadow
    if (backgroundDrawable != null) {
      backgroundDrawable.draw(canvas);
    }

    // Draw foreground
    if (myBearingTrackingMode == MyBearingTracking.NONE) {
      if (foregroundDrawable != null) {
        foregroundDrawable.draw(canvas);
      }
    } else if (foregroundBearingDrawable != null && foregroundBounds != null) {
      getRotateDrawable(
              foregroundBearingDrawable,
              myBearingTrackingMode == MyBearingTracking.COMPASS ? compassDirection : gpsDirection)
          .draw(canvas);
    }
  }
示例#30
0
  public void draw(Canvas canvas, Context context) {
    for (MapCell cell : mMapCells) {
      ShapeDrawable cellShape = new ShapeDrawable(new RectShape());
      Rect cellBounds = cell.getBounds();
      cellShape.setBounds(
          cellBounds.left + mOriginX,
          cellBounds.top + mOriginY,
          cellBounds.right + mOriginX,
          cellBounds.bottom + mOriginY);
      cellShape.getPaint().setColor(ContextCompat.getColor(context, R.color.colorDarkerForeground));
      cellShape.draw(canvas);

      Paint textPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
      textPaint.setColor(ContextCompat.getColor(context, R.color.colorPrimary));
      textPaint.setTextSize((float) (14 * 3.5));
      canvas.drawText(
          cell.getName(),
          cellBounds.centerX() + mOriginX,
          cellBounds.centerY() + mOriginY,
          textPaint);
    }
  }