Ejemplo n.º 1
0
  @Override
  public Rect[] getOperatorBoundingBoxes() {
    // Get the sizes
    final Rect childRect = getChild(0).getBoundingBox();
    final int parentheseWidth = (int) (childRect.height() * PARENTHESES_RATIO);
    Rect textBounding = sizeAddPadding(getSize(findTextSize()));

    // Make sure everything is aligned nicely
    final int childCenterY = getChild(0).getCenter().y;
    final int childTop = Math.max(textBounding.centerY() - childCenterY, 0);
    textBounding.offsetTo(0, Math.max(childCenterY - textBounding.centerY(), 0));

    // Return the bounding boxes
    return new Rect[] {
      textBounding,
      new Rect(
          textBounding.width(),
          childTop,
          textBounding.width() + parentheseWidth,
          childTop + childRect.height()),
      new Rect(
          textBounding.width() + parentheseWidth + childRect.width(),
          childTop,
          textBounding.width() + childRect.width() + 2 * parentheseWidth,
          childTop + childRect.height())
    };
  }
  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();
  }
Ejemplo n.º 3
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);
    }
  }
  @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();
  }
Ejemplo n.º 5
0
 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);
 }
Ejemplo n.º 6
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();
  }
Ejemplo n.º 7
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;
  }
Ejemplo n.º 8
0
  private void drawMovRect(Canvas canvas) {

    canvas.drawRect(movRect, dragging);
    canvas.drawText(
        selNum + "",
        movRect.centerX(),
        movRect.centerY() + textOffsetY - cellLength / 2,
        number_fixed);
  }
  private void drawGradient(Canvas canvas) {
    float xSectionWidth = 1f / mSectionsCount;
    int currentIndexColor = mColorsIndex;

    mLinearGradientPositions[0] = 0f;
    mLinearGradientPositions[mLinearGradientPositions.length - 1] = 1f;
    int firstColorIndex = currentIndexColor - 1;
    if (firstColorIndex < 0) firstColorIndex += mColors.length;

    mLinearGradientColors[0] = mColors[firstColorIndex];

    for (int i = 0; i < mSectionsCount; ++i) {

      float position = mInterpolator.getInterpolation(i * xSectionWidth + mCurrentOffset);
      mLinearGradientPositions[i + 1] = position;
      mLinearGradientColors[i + 1] = mColors[currentIndexColor];

      currentIndexColor = (currentIndexColor + 1) % mColors.length;
    }
    mLinearGradientColors[mLinearGradientColors.length - 1] = mColors[currentIndexColor];

    float left =
        mReversed
            ? (mMirrorMode ? Math.abs(mBounds.left - mBounds.right) / 2 : mBounds.left)
            : mBounds.left;
    float right =
        mMirrorMode
            ? (mReversed ? mBounds.left : Math.abs(mBounds.left - mBounds.right) / 2)
            : mBounds.right;
    float top = mBounds.centerY() - mStrokeWidth / 2;
    float bottom = mBounds.centerY() + mStrokeWidth / 2;
    LinearGradient linearGradient =
        new LinearGradient(
            left,
            top,
            right,
            bottom,
            mLinearGradientColors,
            mLinearGradientPositions,
            mMirrorMode ? Shader.TileMode.MIRROR : Shader.TileMode.CLAMP);

    mPaint.setShader(linearGradient);
  }
 @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);
 }
Ejemplo n.º 11
0
  private void initializePaddles() {
    // Order from top to bottom; Red, Green, Orange, Cyan, Yellow, Blue

    Rect redTouch = new Rect(0, 0, getWidth(), getHeight() / 8);
    Rect blueTouch = new Rect(0, 7 * getHeight() / 8, getWidth(), getHeight());
    Rect greenTouch = new Rect(0, 4 * getHeight() / 16, getWidth(), (getHeight() / 16) * 5);
    Rect orangeTouch = new Rect(0, 6 * getHeight() / 16, getWidth(), (getHeight() / 16) * 7);
    Rect yellowTouch = new Rect(0, 11 * getHeight() / 16, getWidth(), (getHeight() / 4) * 3);
    Rect cyanTouch = new Rect(0, 9 * getHeight() / 16, getWidth(), (getHeight() / 16) * 10);

    mRed = new Paddle(Color.RED, redTouch.bottom + PADDING);
    mBlue = new Paddle(Color.BLUE, blueTouch.top - PADDING - Paddle.PADDLE_THICKNESS);
    mGreen = new Paddle(Color.GREEN, greenTouch.centerY() + PADDING);
    mYellow = new Paddle(Color.YELLOW, yellowTouch.centerY() + PADDING);
    mOrange = new Paddle(Color.rgb(255, 128, 0), orangeTouch.centerY() + PADDING);
    mCyan = new Paddle(Color.rgb(0, 255, 255), cyanTouch.centerY() + PADDING);

    mRed.setTouchbox(redTouch);
    mBlue.setTouchbox(blueTouch);
    mGreen.setTouchbox(greenTouch);
    mYellow.setTouchbox(yellowTouch);
    mOrange.setTouchbox(orangeTouch);
    mCyan.setTouchbox(cyanTouch);

    mRed.setHandicap(mCpuHandicap);
    mBlue.setHandicap(mCpuHandicap);
    mGreen.setHandicap(mCpuHandicap);
    mYellow.setHandicap(mCpuHandicap);
    mOrange.setHandicap(mCpuHandicap);
    mCyan.setHandicap(mCpuHandicap);

    mRed.player = mRedPlayer;
    mBlue.player = mBluePlayer;

    mRed.setSlave(mOrange);
    mBlue.setSlave(mCyan);
    mOrange.setSlave(mYellow);
    mCyan.setSlave(mGreen);

    mRed.setLives(STARTING_LIVES + mLivesModifier);
    mBlue.setLives(STARTING_LIVES + mLivesModifier);
  }
Ejemplo n.º 12
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;
  }
Ejemplo n.º 14
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);
     }
   }
 }
Ejemplo n.º 16
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);
 }
Ejemplo n.º 17
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);
    }
  }
  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());
  }
Ejemplo n.º 19
0
  @Override
  public void onSideSwitch(SwitchCompat v) {
    Rect rect = new Rect();
    v.getGlobalVisibleRect(rect);
    final int cy = rect.centerY() - getStatusBarHeight();
    final int halfThumbWidth = v.getThumbDrawable().getIntrinsicWidth() / 2;
    final int cx;

    if (this instanceof BrightSideFragment && v.isChecked()) {
      cx = rect.right - halfThumbWidth;
      postGoToSide(cy, cx, "dark");
    } else if (!v.isChecked()) {
      cx = rect.left + halfThumbWidth;
      postGoToSide(cy, cx, "bright");
    }
  }
Ejemplo n.º 20
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);
    }
  }
Ejemplo n.º 21
0
  @Override
  public Rect getChildBoundingBox(int index) throws IndexOutOfBoundsException {
    // Make sure the child index is valid
    checkChildIndex(index);

    // Gets the needed sizes and centres
    final Rect childRect = getChild(index).getBoundingBox();
    final int parentheseWidth = (int) (childRect.height() * PARENTHESES_RATIO);
    Rect textBounding = sizeAddPadding(getSize(findTextSize()));

    // Align the child's vertical centre with the text's vertical centre
    // also offset it horizontally to place it behind the opening bracket
    childRect.offsetTo(
        textBounding.width() + parentheseWidth,
        Math.max(textBounding.centerY() - getChild(index).getCenter().y, 0));

    // Return the result
    return childRect;
  }
        @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;
        }
Ejemplo n.º 23
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);
  }
Ejemplo n.º 24
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);
    }
  }
  @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);
    }
  }
Ejemplo n.º 26
0
 @Override
 public boolean onTouchEvent(MotionEvent event) {
   int action = event.getAction();
   float newX = event.getX(), newY = event.getY();
   switch (action) {
     case MotionEvent.ACTION_DOWN:
       if (ballRect.contains((int) newX, (int) newY)) {
         initX = newX;
         initY = newY;
         move = true;
       } else {
         move = false;
       }
       break;
     case MotionEvent.ACTION_MOVE:
       if (move) {
         ballRect.offset((int) (newX - initX), (int) (newY - initY));
         initX = newX;
         initY = newY;
         if ((!rect.contains(ballRect) && !rect2.contains(ballRect))
             && !conRect.contains(ballRect)) {
           move = false;
           ballRect.offsetTo(ballRectX, ballRectY);
           Toast.makeText(mContext, "out of bounds", Toast.LENGTH_SHORT).show();
         } else if (ballRect.contains(goal.centerX(), goal.centerY())) {
           ballRect.offset(-30, 0);
           Toast.makeText(mContext, "Congratulations\n Get UP!", Toast.LENGTH_SHORT).show();
           AlarmDialog.vibrator.cancel();
           ((Activity) getContext()).finish();
         }
       }
       break;
     case MotionEvent.ACTION_UP:
       ballRect.offsetTo(ballRectX, ballRectY);
       break;
   }
   return (true);
 }
Ejemplo n.º 27
0
  @Override
  public void draw(Canvas canvas) {
    Rect bounds = getBounds();
    int cellSize = Math.min(bounds.height(), bounds.width());
    float x0 = bounds.left;
    float y0 = bounds.top;
    float x1 = bounds.right;
    float y1 = bounds.bottom;
    float xM = bounds.centerX();
    float yM = bounds.centerY();
    float border = cellSize / 8;
    paint.setStyle(Paint.Style.STROKE);
    paint.setStrokeWidth(border / 2);

    switch (kind) {
      case BRANCH_ALL:
      case BRANCH_LEFT:
      case BRANCH_LEFT_AND_RIGTH:
      case BRANCH_RIGHT:
        if (kind == Kind.BRANCH_ALL
            || kind == Kind.BRANCH_LEFT
            || kind == Kind.BRANCH_LEFT_AND_RIGTH) {
          canvas.drawLine(xM, y0 + border, x0 + border, yM, paint);
        }
        if (kind == Kind.BRANCH_ALL || kind == Kind.BRANCH_LEFT || kind == Kind.BRANCH_RIGHT) {
          canvas.drawLine(xM, y0 + border, xM, y1 - border, paint);
        }
        if (kind == Kind.BRANCH_ALL
            || kind == Kind.BRANCH_RIGHT
            || kind == Kind.BRANCH_LEFT_AND_RIGTH) {
          canvas.drawLine(xM, y0 + border, x1 - border, yM, paint);
        }
        break;

      case CLASSIFIER:
        {
          int color = paint.getColor();
          paint.setColor(Colors.GRAY[1]);
          paint.setStyle(Paint.Style.FILL);
          canvas.drawCircle(bounds.centerX(), bounds.centerY(), cellSize / 2, paint);

          paint.setColor(color);
          paint.setStyle(Paint.Style.STROKE);
          canvas.drawCircle(bounds.centerX(), bounds.centerY(), cellSize / 2, paint);
          break;
        }
      case MODULE:
        rect.set(bounds);
        rect.bottom = x0 + 1.5f * border;
        rect.right = bounds.centerX();
        paint.setStyle(Paint.Style.FILL_AND_STROKE);
        canvas.drawRoundRect(rect, border / 2, border / 2, paint);
        rect.top = rect.centerY();
        canvas.drawRect(rect, paint);
        rect.set(bounds);
        rect.top += 1.5 * border;
        rect.bottom -= 1 * border;
        paint.setStyle(Paint.Style.STROKE);
        canvas.drawRoundRect(rect, border, border, paint);
        break;
      case CONTINUOUS_OPERATION:
        paint.setUnderlineText(true);
        // Fallthrough intended
      case OPERATION:
        rect.set(bounds);
        rect.top += border;
        rect.bottom -= border;
        canvas.drawRoundRect(rect, border, border, paint);
        // canvas.drawRect(rect, paint);
        break;
      case PROPERTY:
        path.rewind();
        path.moveTo(x0 + border, y0 + border);
        path.lineTo(x1, y0 + border);
        path.lineTo(x1 - border, y1 - border);
        path.lineTo(x0, y1 - border);
        path.close();
        canvas.drawPath(path, paint);
        break;
      case SOUND:
        path.rewind();
        path.moveTo(x1 - border, y0 + border);
        path.lineTo(x1 - border, y1 - border);
        path.lineTo(xM, yM + 1.5f * border);
        path.lineTo(xM, yM - 1.5f * border);
        path.close();
        canvas.drawPath(path, paint);
        rect.left = x0 + border;
        rect.right = xM - 1.5f * border;
        rect.top = yM - 1.5f * border;
        rect.bottom = yM + 1.5f * border;
        canvas.drawRect(rect, paint);
        return;

      case TUTORIAL:
        path.rewind();
        path.moveTo(x1 - 2 * border, y0 + 4 * border);
        path.lineTo(x1 - 2 * border, y1 - 2 * border);
        path.lineTo(xM, y1 - border);
        path.lineTo(x0 + 2 * border, y1 - 2 * border);
        path.lineTo(x0 + 2 * border, y0 + 4 * border);
        canvas.drawPath(path, paint);

        path.rewind();
        path.moveTo(xM, y0 + border);
        path.lineTo(x1, y0 + 3 * border);
        path.lineTo(xM, y0 + 5 * border);
        path.lineTo(x0, y0 + 3 * border);
        path.close();
        canvas.drawPath(path, paint);
        canvas.drawLine(x1, y0 + 3 * border, x1, yM + (text == null ? 2 : 1) * border, paint);
        break;
    }

    if (text != null) {
      paint.setStyle(Paint.Style.FILL);
      if (kind == Kind.TUTORIAL) {
        paint.setTextSize(cellSize * 0.33f);
        paint.setTextAlign(Paint.Align.RIGHT);
        TextHelper.drawText(
            context,
            canvas,
            text,
            bounds.right,
            bounds.bottom,
            paint,
            TextHelper.VerticalAlign.BOTTOM);
      } else {
        paint.setTextSize(cellSize * (kind == Kind.CLASSIFIER ? 0.66f : 0.5f));
        //      canvas.drawText(text, bounds.centerX(), bounds.bottom - cellSize * (kind ==
        // Kind.CLASSIFIER ? 0.25f : 0.33f), paint);
        TextHelper.drawText(
            context,
            canvas,
            text,
            bounds.centerX(),
            bounds.centerY(),
            paint,
            TextHelper.VerticalAlign.CENTER);
      }
    } /*else {
            paint.setStyle(Paint.Style.FILL);
            rect.set(bounds);
            rect.inset(border, border);
            rect.top += border;
            paint.setColor(Colors.GRAY[0]);
            canvas.drawRect(rect, paint);
            paint.setColor(Colors.GRAY[3]);
            paint.setStrokeWidth(cellSize / 16);
            paint.setStyle(Paint.Style.STROKE);
            canvas.drawRect(rect, paint);

            path.rewind();
            path.moveTo(x0 + border, y0 + 2 * border);
            path.lineTo(x0 + 2 * border, y0 + border);
            path.lineTo(x1 - 2 * border, y0 + border);
            path.lineTo(x1 - border, y0 + 2 * border);

      //      path.lineTo(x1 - border, y1 - 2 * border);
        //    path.lineTo(xM, y1);
          //  path.lineTo(x0 + border, y1 - 2 * border);
      //      path.close();
            //paint.setColor(Color.BLACK);
            canvas.drawPath(path, paint);
      //      canvas.drawPath(path, paint);
      //      canvas.drawLine(x0 + border, y0 + 2 * border, xM, y0 + 4 * border, paint);
        //    canvas.drawLine(x1 - border, y0 + 2 * border, xM, y0 + 4 * border, paint);
          //  canvas.drawLine(xM, y1, xM, y0 + 4* border, paint);
          }
      */
  }
Ejemplo n.º 28
0
 /** draw self */
 protected void draw(Canvas canvas) {
   canvas.drawText(
       String.valueOf(mDayOfMonth), mBound.centerX() - dx, mBound.centerY() + dy, mPaint);
 }
Ejemplo n.º 29
0
  private float getMaxRadius(float x, float y, Rect bounds) {
    float x1 = x < bounds.centerX() ? bounds.right : bounds.left;
    float y1 = y < bounds.centerY() ? bounds.bottom : bounds.top;

    return (float) Math.sqrt(Math.pow(x1 - x, 2) + Math.pow(y1 - y, 2));
  }
Ejemplo n.º 30
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 {
    try {
      final Hashtable<String, Object> params = command.params();
      AndroidElement el = null;
      int clickX = -1;
      int clickY = -1;

      boolean isElement = false;
      // 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) {
      }

      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);
      }

      final Object paramDuration = params.get("duration");
      int duration = 2000; // two seconds
      if (paramDuration != null) {
        duration = Integer.parseInt(paramDuration.toString());
      }

      Logger.debug(
          "longClick using element? "
              + isElement
              + " x: "
              + clickX
              + ", y: "
              + clickY
              + ", duration: "
              + duration);
      if (correctLongClick(clickX, clickY, duration)) {
        return getSuccessResult(true);
      }

      // if correctLongClick failed and we have an element
      // then uiautomator's longClick is used as a fallback.
      if (isElement) {
        Logger.debug("Falling back to broken longClick");

        final boolean res = el.longClick();
        return getSuccessResult(res);
      }
    } 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 long click");
  }