List of usage examples for android.graphics Rect centerX
public final int centerX()
From source file:net.qiujuer.genius.ui.widget.GeniusAbsSeekBar.java
private void startDragging(MotionEvent ev, boolean ignoreTrackIfInScrollContainer) { final Rect bounds = mTempRect; mSeekBarDrawable.copyTouchBounds(bounds); //Grow the current thumb rect for a bigger touch area boolean isDragging = (bounds.contains((int) ev.getX(), (int) ev.getY())); if (!isDragging && mAllowTrackClick && !ignoreTrackIfInScrollContainer) { //If the user clicked outside the thumb, we compute the current position //and force an immediate drag to it. isDragging = true;// w ww.jav a 2 s. c o m mDragOffset = bounds.width() / 2; updateDragging(ev); //As the thumb may have moved, get the bounds again mSeekBarDrawable.setHotScale(mSeekBarDrawable.getHotScale()); } if (isDragging) { onStartTrackingTouch(); setHotspot(ev.getX(), ev.getY()); mDragOffset = (int) (ev.getX() - bounds.centerX()); } }
From source file:com.irccloud.android.DrawerArrowDrawable.java
@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 ? 0 : -180, isRtl ? 180 : 0, mProgress); final float topBottomBarOffset = lerp(mBarGap + mBarThickness, 0, mProgress); mPath.rewind();// w ww . j av a 2s . c om 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(); }
From source file:com.stanleyidesis.quotograph.ui.activity.LWQSettingsActivity.java
Animator animateFABActions(final boolean dismiss) { fabBackground.setVisibility(View.VISIBLE); Animator backgroundAnimator;// w w w .j a va 2 s .co m if (Build.VERSION.SDK_INT >= 21) { Rect fabRect = new Rect(); fabAdd.getGlobalVisibleRect(fabRect); final Point realScreenSize = UIUtils.getRealScreenSize(); int radius = Math.max(realScreenSize.x, realScreenSize.y); backgroundAnimator = ViewAnimationUtils.createCircularReveal(fabBackground, fabRect.centerX(), fabRect.centerY(), dismiss ? radius : 0, dismiss ? 0 : radius); } else { backgroundAnimator = ObjectAnimator.ofFloat(fabBackground, "alpha", dismiss ? 1f : 0f, dismiss ? 0f : 1f); } backgroundAnimator.setDuration(300).setInterpolator(new AccelerateDecelerateInterpolator()); backgroundAnimator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { if (dismiss) { fabBackground.setVisibility(View.GONE); // Tell them to swipe again for settings! showTutorialTip(TutorialTooltips.SWIPE_AGAIN); } else { // Tell them about search! showTutorialTip(TutorialTooltips.SEARCH); } } }); final long shortDelay = 50; final long longDelay = 100; final Animator createAnimator = animateFAB(fabCreate, dismiss); final Animator searchAnimator = animateFAB(fabSearch, dismiss); createAnimator.setStartDelay(dismiss ? longDelay : shortDelay); searchAnimator.setStartDelay(dismiss ? shortDelay : longDelay); AnimatorSet allAnimations = new AnimatorSet(); allAnimations.playTogether(backgroundAnimator, createAnimator, searchAnimator); return allAnimations; }
From source file:com.brian.common.view.DrawerArrowDrawable.java
@Override public void draw(Canvas canvas) { if (mIsCirculate) { if (mProgress >= .995) { flipped = true;// w w w. j a va 2 s . c o m } else if (mProgress <= .005) { flipped = false; } if (flipped) { canvas.save(); canvas.scale(1f, -1f, getIntrinsicWidth() / 2, getIntrinsicHeight() / 2); } } Rect bounds = getBounds(); final boolean flipToPointRight; switch (mDirection) { case ARROW_DIRECTION_LEFT: flipToPointRight = false; break; case ARROW_DIRECTION_RIGHT: flipToPointRight = true; break; default: flipToPointRight = false; break; } // Interpolated widths of arrow bars float arrowHeadBarLength = (float) Math.sqrt(mArrowHeadLength * mArrowHeadLength * 2); arrowHeadBarLength = lerp(mBarLength, arrowHeadBarLength, mProgress); final float arrowShaftLength = lerp(mBarLength, mArrowShaftLength, mProgress); // Interpolated size of middle bar final float arrowShaftCut = Math.round(lerp(0, mMaxCutForBarSize, 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(flipToPointRight ? 0 : -180, flipToPointRight ? 180 : 0, mProgress); final float arrowWidth = Math.round(arrowHeadBarLength * Math.cos(rotation)); final float arrowHeight = Math.round(arrowHeadBarLength * Math.sin(rotation)); mPath.rewind(); final float topBottomBarOffset = lerp(mBarGap + mPaint.getStrokeWidth(), -mMaxCutForBarSize, mProgress); final float arrowEdge = -arrowShaftLength / 2; // draw middle bar mPath.moveTo(arrowEdge + arrowShaftCut, 0); mPath.rLineTo(arrowShaftLength - arrowShaftCut * 2, 0); // bottom bar mPath.moveTo(arrowEdge, topBottomBarOffset); mPath.rLineTo(arrowWidth, arrowHeight); // top bar mPath.moveTo(arrowEdge, -topBottomBarOffset); mPath.rLineTo(arrowWidth, -arrowHeight); 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. final float barThickness = mPaint.getStrokeWidth(); final int remainingSpace = (int) (bounds.height() - barThickness * 3 - mBarGap * 2); float yOffset = (remainingSpace / 4) * 2; // making sure it is a multiple of 2. yOffset += barThickness * 1.5 + mBarGap; canvas.translate(bounds.centerX(), yOffset); if (mSpin) { canvas.rotate(canvasRotate * ((mVerticalMirror ^ flipToPointRight) ? -1 : 1)); } else if (flipToPointRight) { canvas.rotate(180); } canvas.drawPath(mPath, mPaint); canvas.restore(); }
From source file:radialdemo.RadialMenuWidget.java
@Override protected void onDraw(Canvas c) { Paint paint = new Paint(); paint.setAntiAlias(true);/*from w ww . j av a 2 s .c o m*/ paint.setStrokeWidth(3); // draws a dot at the source of the press if (showSource == true) { paint.setColor(outlineColor); paint.setAlpha(outlineAlpha); paint.setStyle(Paint.Style.STROKE); c.drawCircle(xSource, ySource, cRadius / 10, paint); paint.setColor(selectedColor); paint.setAlpha(selectedAlpha); paint.setStyle(Paint.Style.FILL); c.drawCircle(xSource, ySource, cRadius / 10, paint); } //inner for (int i = 0; i < Wedges.length; i++) { RadialMenuWedge f = Wedges[i]; paint.setColor(outlineColor); paint.setAlpha(outlineAlpha); paint.setStyle(Paint.Style.STROKE); c.drawPath(f, paint); if (f == enabled && Wedge2Shown == true) { paint.setColor(wedge2Color); paint.setAlpha(wedge2Alpha); paint.setStyle(Paint.Style.FILL); c.drawPath(f, paint); } else if (f != enabled && Wedge2Shown == true) { paint.setColor(disabledColor); paint.setAlpha(disabledAlpha); paint.setStyle(Paint.Style.FILL); c.drawPath(f, paint); } else if (f == enabled && Wedge2Shown == false) { paint.setColor(wedge2Color); paint.setAlpha(wedge2Alpha); paint.setStyle(Paint.Style.FILL); c.drawPath(f, paint); } else if (f == selected) { paint.setColor(wedge2Color); paint.setAlpha(wedge2Alpha); paint.setStyle(Paint.Style.FILL); c.drawPath(f, paint); } else { paint.setColor(defaultColor); paint.setAlpha(defaultAlpha); paint.setStyle(Paint.Style.FILL); c.drawPath(f, paint); } //button content Rect rf = iconRect[i]; if ((menuEntries.get(i).getIcon() != 0) && (menuEntries.get(i).getLabel() != null)) { // This will look for a "new line" and split into multiple lines String menuItemName = menuEntries.get(i).getLabel(); String[] stringArray = menuItemName.split("\n"); paint.setColor(textColor); if (f != enabled && Wedge2Shown == true) { paint.setAlpha(disabledAlpha); } else { paint.setAlpha(textAlpha); } paint.setStyle(Paint.Style.FILL); paint.setTextSize(textSize); Rect rect = new Rect(); float textHeight = 0; for (int j = 0; j < stringArray.length; j++) { paint.getTextBounds(stringArray[j], 0, stringArray[j].length(), rect); textHeight = textHeight + (rect.height() + 3); } Rect rf2 = new Rect(); rf2.set(rf.left, rf.top - ((int) textHeight / 2), rf.right, rf.bottom - ((int) textHeight / 2)); float textBottom = rf2.bottom; for (int j = 0; j < stringArray.length; j++) { paint.getTextBounds(stringArray[j], 0, stringArray[j].length(), rect); float textLeft = rf.centerX() - rect.width() / 2; textBottom = textBottom + (rect.height() + 3); c.drawText(stringArray[j], textLeft - rect.left, textBottom - rect.bottom, paint); } // Puts in the Icon Drawable drawable = getResources().getDrawable(menuEntries.get(i).getIcon()); drawable.setBounds(rf2); if (f != enabled && Wedge2Shown == true) { drawable.setAlpha(disabledAlpha); } else { drawable.setAlpha(pictureAlpha); } drawable.draw(c); // Icon Only } else if (menuEntries.get(i).getIcon() != 0) { // Puts in the Icon Drawable drawable = getResources().getDrawable(menuEntries.get(i).getIcon()); drawable.setBounds(rf); if (f != enabled && Wedge2Shown == true) { drawable.setAlpha(disabledAlpha); } else { drawable.setAlpha(pictureAlpha); } drawable.draw(c); // Text Only } else { // Puts in the Text if no Icon paint.setColor(textColor); if (f != enabled && Wedge2Shown == true) { paint.setAlpha(disabledAlpha); } else { paint.setAlpha(textAlpha); } paint.setStyle(Paint.Style.FILL); paint.setTextSize(textSize + 10); // This will look for a "new line" and split into multiple lines String menuItemName = menuEntries.get(i).getLabel(); String[] stringArray = menuItemName.split("\n"); // gets total height Rect rect = new Rect(); float textHeight = 0; for (int j = 0; j < stringArray.length; j++) { paint.getTextBounds(stringArray[j], 0, stringArray[j].length(), rect); textHeight = textHeight + (rect.height() + 3); } float textBottom = rf.centerY() - (textHeight / 2); for (int j = 0; j < stringArray.length; j++) { paint.getTextBounds(stringArray[j], 0, stringArray[j].length(), rect); float textLeft = rf.centerX() - rect.width() / 2; textBottom = textBottom + (rect.height() + 3); c.drawText(stringArray[j], textLeft - rect.left, textBottom - rect.bottom, paint); } } } // Animate the outer ring in/out if (animateOuterIn == true) { animateOuterWedges(ANIMATE_IN); } else if (animateOuterOut == true) { animateOuterWedges(ANIMATE_OUT); } //outer if (Wedge2Shown == true) { for (int i = 0; i < Wedges2.length; i++) { RadialMenuWedge f = Wedges2[i]; paint.setColor(outlineColor); paint.setAlpha(20); paint.setStyle(Paint.Style.STROKE); c.drawPath(f, paint); if (f == selected2) { paint.setColor(selectedColor); paint.setAlpha(selectedAlpha); paint.setStyle(Paint.Style.FILL); c.drawPath(f, paint); } else { paint.setColor(wedge2Color); paint.setAlpha(wedge2Alpha); paint.setStyle(Paint.Style.FILL); c.drawPath(f, paint); } Rect rf = iconRect2[i]; if ((wedge2Data.getChildren().get(i).getIcon() != 0) && (wedge2Data.getChildren().get(i).getLabel() != null)) { // This will look for a "new line" and split into multiple // lines String menuItemName = wedge2Data.getChildren().get(i).getLabel(); String[] stringArray = menuItemName.split("\n"); paint.setColor(textColor); paint.setAlpha(textAlpha); paint.setStyle(Paint.Style.FILL); paint.setTextSize(animateTextSize); Rect rect = new Rect(); float textHeight = 0; for (int j = 0; j < stringArray.length; j++) { paint.getTextBounds(stringArray[j], 0, stringArray[j].length(), rect); textHeight = textHeight + (rect.height() + 3); } Rect rf2 = new Rect(); rf2.set(rf.left, rf.top - ((int) textHeight / 2), rf.right, rf.bottom - ((int) textHeight / 2)); float textBottom = rf2.bottom; for (int j = 0; j < stringArray.length; j++) { paint.getTextBounds(stringArray[j], 0, stringArray[j].length(), rect); float textLeft = rf.centerX() - rect.width() / 2; textBottom = textBottom + (rect.height() + 3); c.drawText(stringArray[j], textLeft - rect.left, textBottom - rect.bottom, paint); } // Puts in the Icon Drawable drawable = getResources().getDrawable(wedge2Data.getChildren().get(i).getIcon()); drawable.setBounds(rf2); drawable.setAlpha(pictureAlpha); drawable.draw(c); // Icon Only } else if (wedge2Data.getChildren().get(i).getIcon() != 0) { // Puts in the Icon Drawable drawable = getResources().getDrawable(wedge2Data.getChildren().get(i).getIcon()); drawable.setBounds(rf); drawable.setAlpha(pictureAlpha); drawable.draw(c); // Text Only } else { // Puts in the Text if no Icon paint.setColor(textColor); paint.setAlpha(textAlpha); paint.setStyle(Paint.Style.FILL); paint.setTextSize(animateTextSize); // This will look for a "new line" and split into multiple // lines String menuItemName = wedge2Data.getChildren().get(i).getLabel(); String[] stringArray = menuItemName.split("\n"); // gets total height Rect rect = new Rect(); float textHeight = 0; for (int j = 0; j < stringArray.length; j++) { paint.getTextBounds(stringArray[j], 0, stringArray[j].length(), rect); textHeight = textHeight + (rect.height() + 3); } float textBottom = rf.centerY() - (textHeight / 2); for (int j = 0; j < stringArray.length; j++) { paint.getTextBounds(stringArray[j], 0, stringArray[j].length(), rect); float textLeft = rf.centerX() - rect.width() / 2; textBottom = textBottom + (rect.height() + 3); c.drawText(stringArray[j], textLeft - rect.left, textBottom - rect.bottom, paint); } } } } //Check if the user has given input for centre circle if (centerCircle != null) { // Draws the Middle Circle paint.setColor(outlineColor); paint.setAlpha(outlineAlpha); paint.setStyle(Paint.Style.STROKE); c.drawCircle(xPosition, yPosition, cRadius, paint); if (inCircle == true) { paint.setColor(selectedColor); paint.setAlpha(selectedAlpha); paint.setStyle(Paint.Style.FILL); c.drawCircle(xPosition, yPosition, cRadius, paint); helper.onCloseAnimation(this, xPosition, yPosition, xSource, ySource); } else { paint.setColor(defaultColor); paint.setAlpha(defaultAlpha); paint.setStyle(Paint.Style.FILL); c.drawCircle(xPosition, yPosition, cRadius, paint); } // Draw the circle picture if ((centerCircle.getIcon() != 0) && (centerCircle.getLabel() != null)) { // This will look for a "new line" and split into multiple lines String menuItemName = centerCircle.getLabel(); String[] stringArray = menuItemName.split("\n"); paint.setColor(textColor); paint.setAlpha(textAlpha); paint.setStyle(Paint.Style.FILL); paint.setTextSize(textSize); Rect rectText = new Rect(); Rect rectIcon = new Rect(); Drawable drawable = getResources().getDrawable(centerCircle.getIcon()); int h = getIconSize(drawable.getIntrinsicHeight(), MinIconSize, MaxIconSize); int w = getIconSize(drawable.getIntrinsicWidth(), MinIconSize, MaxIconSize); rectIcon.set(xPosition - w / 2, yPosition - h / 2, xPosition + w / 2, yPosition + h / 2); float textHeight = 0; for (int j = 0; j < stringArray.length; j++) { paint.getTextBounds(stringArray[j], 0, stringArray[j].length(), rectText); textHeight = textHeight + (rectText.height() + 3); } rectIcon.set(rectIcon.left, rectIcon.top - ((int) textHeight / 2), rectIcon.right, rectIcon.bottom - ((int) textHeight / 2)); float textBottom = rectIcon.bottom; for (int j = 0; j < stringArray.length; j++) { paint.getTextBounds(stringArray[j], 0, stringArray[j].length(), rectText); float textLeft = xPosition - rectText.width() / 2; textBottom = textBottom + (rectText.height() + 3); c.drawText(stringArray[j], textLeft - rectText.left, textBottom - rectText.bottom, paint); } // Puts in the Icon drawable.setBounds(rectIcon); drawable.setAlpha(pictureAlpha); drawable.draw(c); // Icon Only } else if (centerCircle.getIcon() != 0) { Rect rect = new Rect(); Drawable drawable = getResources().getDrawable(centerCircle.getIcon()); int h = getIconSize(drawable.getIntrinsicHeight(), MinIconSize, MaxIconSize); int w = getIconSize(drawable.getIntrinsicWidth(), MinIconSize, MaxIconSize); rect.set(xPosition - w / 2, yPosition - h / 2, xPosition + w / 2, yPosition + h / 2); drawable.setBounds(rect); drawable.setAlpha(pictureAlpha); drawable.draw(c); // Text Only } else { // Puts in the Text if no Icon paint.setColor(textColor); paint.setAlpha(textAlpha); paint.setStyle(Paint.Style.FILL); paint.setTextSize(textSize); // This will look for a "new line" and split into multiple lines String menuItemName = centerCircle.getLabel(); String[] stringArray = menuItemName.split("\n"); // gets total height Rect rect = new Rect(); float textHeight = 0; for (int j = 0; j < stringArray.length; j++) { paint.getTextBounds(stringArray[j], 0, stringArray[j].length(), rect); textHeight = textHeight + (rect.height() + 3); } float textBottom = yPosition - (textHeight / 2); for (int j = 0; j < stringArray.length; j++) { paint.getTextBounds(stringArray[j], 0, stringArray[j].length(), rect); float textLeft = xPosition - rect.width() / 2; textBottom = textBottom + (rect.height() + 3); c.drawText(stringArray[j], textLeft - rect.left, textBottom - rect.bottom, paint); } } } // Draws Text in TextBox if (headerString != null) { paint.setTextSize(headerTextSize); paint.getTextBounds(headerString, 0, headerString.length(), this.textRect); if (HeaderBoxBounded == false) { determineHeaderBox(); HeaderBoxBounded = true; } paint.setColor(outlineColor); paint.setAlpha(outlineAlpha); paint.setStyle(Paint.Style.STROKE); c.drawRoundRect(this.textBoxRect, scalePX(5), scalePX(5), paint); paint.setColor(headerBackgroundColor); paint.setAlpha(headerBackgroundAlpha); paint.setStyle(Paint.Style.FILL); c.drawRoundRect(this.textBoxRect, scalePX(5), scalePX(5), paint); paint.setColor(headerTextColor); paint.setAlpha(headerTextAlpha); paint.setStyle(Paint.Style.FILL); paint.setTextSize(headerTextSize); c.drawText(headerString, headerTextLeft, headerTextBottom, paint); } }
From source file:android.support.v7.graphics.drawable.DrawerArrowDrawable.java
@Override public void draw(Canvas canvas) { Rect bounds = getBounds(); final boolean flipToPointRight; switch (mDirection) { case ARROW_DIRECTION_LEFT: flipToPointRight = false;/*w w w . j av a2s. c o m*/ break; case ARROW_DIRECTION_RIGHT: flipToPointRight = true; break; case ARROW_DIRECTION_END: flipToPointRight = DrawableCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_LTR; break; case ARROW_DIRECTION_START: default: flipToPointRight = DrawableCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_RTL; break; } // Interpolated widths of arrow bars float arrowHeadBarLength = (float) Math.sqrt(mArrowHeadLength * mArrowHeadLength * 2); arrowHeadBarLength = lerp(mBarLength, arrowHeadBarLength, mProgress); final float arrowShaftLength = lerp(mBarLength, mArrowShaftLength, mProgress); // Interpolated size of middle bar final float arrowShaftCut = Math.round(lerp(0, mMaxCutForBarSize, 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(flipToPointRight ? 0 : -180, flipToPointRight ? 180 : 0, mProgress); final float arrowWidth = Math.round(arrowHeadBarLength * Math.cos(rotation)); final float arrowHeight = Math.round(arrowHeadBarLength * Math.sin(rotation)); mPath.rewind(); final float topBottomBarOffset = lerp(mBarGap + mPaint.getStrokeWidth(), -mMaxCutForBarSize, mProgress); final float arrowEdge = -arrowShaftLength / 2; // draw middle bar mPath.moveTo(arrowEdge + arrowShaftCut, 0); mPath.rLineTo(arrowShaftLength - arrowShaftCut * 2, 0); // bottom bar mPath.moveTo(arrowEdge, topBottomBarOffset); mPath.rLineTo(arrowWidth, arrowHeight); // top bar mPath.moveTo(arrowEdge, -topBottomBarOffset); mPath.rLineTo(arrowWidth, -arrowHeight); 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. final float barThickness = mPaint.getStrokeWidth(); final int remainingSpace = (int) (bounds.height() - barThickness * 3 - mBarGap * 2); float yOffset = (remainingSpace / 4) * 2; // making sure it is a multiple of 2. yOffset += barThickness * 1.5 + mBarGap; canvas.translate(bounds.centerX(), yOffset); if (mSpin) { canvas.rotate(canvasRotate * ((mVerticalMirror ^ flipToPointRight) ? -1 : 1)); } else if (flipToPointRight) { canvas.rotate(180); } canvas.drawPath(mPath, mPaint); canvas.restore(); }
From source file:com.commonsware.cwac.crossport.v7.graphics.drawable.DrawerArrowDrawable.java
@Override public void draw(Canvas canvas) { Rect bounds = getBounds(); final boolean flipToPointRight; switch (mDirection) { case ARROW_DIRECTION_LEFT: flipToPointRight = false;//from w ww . j ava 2 s . c o m break; case ARROW_DIRECTION_RIGHT: flipToPointRight = true; break; case ARROW_DIRECTION_END: flipToPointRight = DrawableCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_LTR; break; case ARROW_DIRECTION_START: default: flipToPointRight = DrawableCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_RTL; break; } // Interpolated widths of arrow bars float arrowHeadBarLength = (float) Math.sqrt(mArrowHeadLength * mArrowHeadLength * 2); arrowHeadBarLength = lerp(mBarLength, arrowHeadBarLength, mProgress); final float arrowShaftLength = lerp(mBarLength, mArrowShaftLength, mProgress); // Interpolated size of middle bar final float arrowShaftCut = Math.round(lerp(0, mMaxCutForBarSize, 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(flipToPointRight ? 0 : -180, flipToPointRight ? 180 : 0, mProgress); final float arrowWidth = Math.round(arrowHeadBarLength * Math.cos(rotation)); final float arrowHeight = Math.round(arrowHeadBarLength * Math.sin(rotation)); mPath.rewind(); final float topBottomBarOffset = lerp(mBarGap + mPaint.getStrokeWidth(), -mMaxCutForBarSize, mProgress); final float arrowEdge = -arrowShaftLength / 2; // draw middle bar mPath.moveTo(arrowEdge + arrowShaftCut, 0); mPath.rLineTo(arrowShaftLength - arrowShaftCut * 2, 0); // bottom bar mPath.moveTo(arrowEdge, topBottomBarOffset); mPath.rLineTo(arrowWidth, arrowHeight); // top bar mPath.moveTo(arrowEdge, -topBottomBarOffset); mPath.rLineTo(arrowWidth, -arrowHeight); 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. final float barThickness = mPaint.getStrokeWidth(); final int remainingSpace = (int) (bounds.height() - barThickness * 3 - mBarGap * 2); float yOffset = (remainingSpace / 4) * 2; // making sure it is a multiple of 2. yOffset += barThickness * 1.5f + mBarGap; canvas.translate(bounds.centerX(), yOffset); if (mSpin) { canvas.rotate(canvasRotate * ((mVerticalMirror ^ flipToPointRight) ? -1 : 1)); } else if (flipToPointRight) { canvas.rotate(180); } canvas.drawPath(mPath, mPaint); canvas.restore(); }
From source file:com.android.launcher3.CellLayout.java
private void getDirectionVectorForDrop(int dragViewCenterX, int dragViewCenterY, int spanX, int spanY, View dragView, int[] resultDirection) { int[] targetDestination = new int[2]; findNearestArea(dragViewCenterX, dragViewCenterY, spanX, spanY, targetDestination); Rect dragRect = new Rect(); regionToRect(targetDestination[0], targetDestination[1], spanX, spanY, dragRect); dragRect.offset(dragViewCenterX - dragRect.centerX(), dragViewCenterY - dragRect.centerY()); Rect dropRegionRect = new Rect(); getViewsIntersectingRegion(targetDestination[0], targetDestination[1], spanX, spanY, dragView, dropRegionRect, mIntersectingViews); int dropRegionSpanX = dropRegionRect.width(); int dropRegionSpanY = dropRegionRect.height(); regionToRect(dropRegionRect.left, dropRegionRect.top, dropRegionRect.width(), dropRegionRect.height(), dropRegionRect);/*from ww w .ja v a 2 s. c o m*/ int deltaX = (dropRegionRect.centerX() - dragViewCenterX) / spanX; int deltaY = (dropRegionRect.centerY() - dragViewCenterY) / spanY; if (dropRegionSpanX == mCountX || spanX == mCountX) { deltaX = 0; } if (dropRegionSpanY == mCountY || spanY == mCountY) { deltaY = 0; } if (deltaX == 0 && deltaY == 0) { // No idea what to do, give a random direction. resultDirection[0] = 1; resultDirection[1] = 0; } else { computeDirectionVector(deltaX, deltaY, resultDirection); } }
From source file:com.albedinsky.android.ui.widget.SeekBarWidget.java
/** * Draws discrete indicator of this SeekBarWidget at its current position updated by * {@link #updateDiscreteIndicatorPosition(int, int)} according to the current progress. * * @param canvas Canvas on which to draw discrete indicator's drawable. *//*from www.j ava 2s . com*/ private void drawDiscreteIndicator(Canvas canvas) { if (mDiscreteIndicatorHeight == 0) { return; } // todo: draw according to LTR/RTL layout direction. mDiscreteIndicator.draw(canvas); // Draw current progress over indicator's graphics. final Rect indicatorBounds = mDiscreteIndicator.getBounds(); final Paint textPaint = DISCRETE_INDICATOR_TEXT_INFO.paint; textPaint.getTextBounds("0", 0, 1, mRect); final float textSize = mRect.height(); final Rect textPadding = DISCRETE_INDICATOR_TEXT_INFO.padding; final int absoluteTextGravity = WidgetGravity.getAbsoluteGravity(DISCRETE_INDICATOR_TEXT_INFO.gravity, ViewCompat.getLayoutDirection(this)); final float textX, textY; // Resolve horizontal text position according to the requested gravity. switch (absoluteTextGravity & Gravity.HORIZONTAL_GRAVITY_MASK) { case Gravity.CENTER_HORIZONTAL: textPaint.setTextAlign(Paint.Align.CENTER); textX = indicatorBounds.centerX(); break; case Gravity.RIGHT: textPaint.setTextAlign(Paint.Align.RIGHT); textX = indicatorBounds.right - textPadding.right; break; case Gravity.LEFT: default: textPaint.setTextAlign(Paint.Align.LEFT); textX = indicatorBounds.left + textPadding.left; break; } // Resolve vertical text position according to the requested gravity. switch (absoluteTextGravity & Gravity.VERTICAL_GRAVITY_MASK) { case Gravity.CENTER_VERTICAL: textY = indicatorBounds.centerY() + textSize / 2f; break; case Gravity.BOTTOM: textY = indicatorBounds.bottom - textPadding.bottom; break; case Gravity.TOP: default: textY = indicatorBounds.top + textSize + textPadding.top; break; } canvas.drawText(Integer.toString(getProgress()), textX, textY, textPaint); }