Example usage for android.graphics Rect centerX

List of usage examples for android.graphics Rect centerX

Introduction

In this page you can find the example usage for android.graphics Rect centerX.

Prototype

public final int centerX() 

Source Link

Usage

From source file:com.waz.zclient.pages.main.profile.camera.CameraFragment.java

@Override
public void onFocus(Rect focusArea) {
    focusView.setColor(getControllerFactory().getAccentColorController().getColor());
    int x = focusArea.centerX();
    int y = focusArea.centerY();
    focusView.setX(x - focusView.getWidth() / 2);
    focusView.setY(y - focusView.getHeight() / 2);
    focusView.showFocusView();/* w w  w  . j a va  2 s  . c o m*/
}

From source file:android.support.transition.SidePropagation.java

@Override
public long getStartDelay(ViewGroup sceneRoot, Transition transition, TransitionValues startValues,
        TransitionValues endValues) {//  w  w  w  . j a  va2  s.  c o  m
    if (startValues == null && endValues == null) {
        return 0;
    }
    int directionMultiplier = 1;
    Rect epicenter = transition.getEpicenter();
    TransitionValues positionValues;
    if (endValues == null || getViewVisibility(startValues) == View.VISIBLE) {
        positionValues = startValues;
        directionMultiplier = -1;
    } else {
        positionValues = endValues;
    }

    int viewCenterX = getViewX(positionValues);
    int viewCenterY = getViewY(positionValues);

    int[] loc = new int[2];
    sceneRoot.getLocationOnScreen(loc);
    int left = loc[0] + Math.round(sceneRoot.getTranslationX());
    int top = loc[1] + Math.round(sceneRoot.getTranslationY());
    int right = left + sceneRoot.getWidth();
    int bottom = top + sceneRoot.getHeight();

    int epicenterX;
    int epicenterY;
    if (epicenter != null) {
        epicenterX = epicenter.centerX();
        epicenterY = epicenter.centerY();
    } else {
        epicenterX = (left + right) / 2;
        epicenterY = (top + bottom) / 2;
    }

    float distance = distance(sceneRoot, viewCenterX, viewCenterY, epicenterX, epicenterY, left, top, right,
            bottom);
    float maxDistance = getMaxDistance(sceneRoot);
    float distanceFraction = distance / maxDistance;

    long duration = transition.getDuration();
    if (duration < 0) {
        duration = 300;
    }

    return Math.round(duration * directionMultiplier / mPropagationSpeed * distanceFraction);
}

From source file:com.acious.android.paginationseekbar.PaginationSeekBar.java

private void updateThumbPos(int posX) {
    int thumbWidth = mThumb.getIntrinsicWidth();
    int halfThumb = thumbWidth / 2;
    int start;//  w w w. j  av  a2  s  . c o m
    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);
}

From source file:com.astir_trotter.atcustom.ui.iconics.core.IconicsDrawable.java

/**
 * Set the icon offset//from www . ja v  a  2s . co m
 *
 * @param viewBounds
 */
private void offsetIcon(Rect viewBounds) {
    float startX = viewBounds.centerX() - (mPathBounds.width() / 2);
    float offsetX = startX - mPathBounds.left;

    float startY = viewBounds.centerY() - (mPathBounds.height() / 2);
    float offsetY = startY - (mPathBounds.top);

    mPath.offset(offsetX + mIconOffsetX, offsetY + mIconOffsetY);
}

From source file:com.ibm.mil.readyapps.physio.fragments.PainLocationFragment.java

/**
 * Pulls the bitmap image of the body part out of its RelativeLayout, colors it appropriatly,
 * and then tells the zoomLayout where it needs to zoom to. Also swaps the FRONT/BACK buttons
 * for the ADD/DELETE buttons./*  ww  w.ja v  a 2  s. com*/
 *
 * @param image the body part the touch occured in.
 */
private void zoomOnImage(RelativeLayout image) {

    Bitmap bitm = ((BitmapDrawable) image.getBackground()).getBitmap();

    Bitmap temp = bitm.copy(bitm.getConfig(), true);
    int[] pixels = new int[temp.getHeight() * temp.getWidth()];

    temp.getPixels(pixels, 0, temp.getWidth(), 0, 0, temp.getWidth(), temp.getHeight());

    for (int i = 0; i < temp.getHeight() * temp.getWidth(); i++) {

        if (pixels[i] != 0) {

            int r, g, b;

            if (!blue) {
                r = Color.red(pixels[i]) + 100;
                if (r > 255) {
                    r = 255;
                }
                g = Color.green(pixels[i]) - 50;
                b = Color.blue(pixels[i]) - 50;
            } else {
                r = Color.red(pixels[i]) - 30;
                g = Color.green(pixels[i]) + 15;
                b = Color.blue(pixels[i]) + 100;
                if (b > 255) {
                    b = 255;
                }

            }
            pixels[i] = Color.argb(Color.alpha(pixels[i]), r, g, b);
        }
    }

    temp.setPixels(pixels, 0, temp.getWidth(), 0, 0, temp.getWidth(), temp.getHeight());
    image.setBackground(new BitmapDrawable(getResources(), temp));

    Rect rect = new Rect();
    image.getGlobalVisibleRect(rect);

    zoomLayout.zoomToRect(rect, 0, getYOffset());
    current = image;
    zoomed = true;
    swapButtons();

    placePointer(rect.centerX(), rect.centerY());

}

From source file:com.android.deskclock.timer.TimerFullScreenFragment.java

private Animator getRevealAnimator(View source, int revealColor) {
    final ViewGroup containerView = (ViewGroup) source.getRootView().findViewById(android.R.id.content);

    final Rect sourceBounds = new Rect(0, 0, source.getHeight(), source.getWidth());
    containerView.offsetDescendantRectToMyCoords(source, sourceBounds);

    final int centerX = sourceBounds.centerX();
    final int centerY = sourceBounds.centerY();

    final int xMax = Math.max(centerX, containerView.getWidth() - centerX);
    final int yMax = Math.max(centerY, containerView.getHeight() - centerY);

    final float startRadius = Math.max(sourceBounds.width(), sourceBounds.height()) / 2.0f;
    final float endRadius = (float) Math.sqrt(xMax * xMax + yMax * yMax);

    final CircleView revealView = new CircleView(source.getContext()).setCenterX(centerX).setCenterY(centerY)
            .setFillColor(revealColor);//  www . ja va  2 s  .  co  m
    containerView.addView(revealView);

    final Animator revealAnimator = ObjectAnimator.ofFloat(revealView, CircleView.RADIUS, startRadius,
            endRadius);
    revealAnimator.setInterpolator(PathInterpolatorCompat.create(0.0f, 0.0f, 0.2f, 1.0f));

    final ValueAnimator fadeAnimator = ObjectAnimator.ofFloat(revealView, View.ALPHA, 0.0f);
    fadeAnimator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            containerView.removeView(revealView);
        }
    });

    final AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.setDuration(TimerFragment.ANIMATION_TIME_MILLIS);
    animatorSet.playSequentially(revealAnimator, fadeAnimator);

    return revealAnimator;
}

From source file:com.ucmap.dingdinghelper.services.DingDingHelperAccessibilityService.java

private void finishSignIn() {
    AccessibilityNodeInfo mAccessibilityNodeInfo = this.getRootInActiveWindow();
    if (mAccessibilityNodeInfo == null) {
        return;//from  w w w. j  av  a  2 s.  com
    }
    AccessibilityNodeInfo mNodeInfos = recurseFindByText("?", mAccessibilityNodeInfo);//??? 
    if (mNodeInfos == null) {
        backHomePager();
        handleHomeInsensitiveCallback(tag_callback_time);
        return;
    }
    AccessibilityNodeInfo mInfo = mNodeInfos;
    Rect mRect = new Rect();
    mInfo.getBoundsInScreen(mRect);

    doShellCmdInputTap(mRect.centerX(), mRect.centerY());//adb? ??root

    backHomePager();
}

From source file:net.qiujuer.genius.ui.widget.GeniusAbsSeekBar.java

private void updateThumbPosForScale(float scale) {
    // SeekBar/*from   w w w  .  ja  v a2s  .co m*/
    if (scale == -1) {
        scale = (mValue - mMin) / (float) (mMax - mMin);
    }
    mSeekBarDrawable.setHotScale(scale);

    // Indicator Move
    final Rect finalBounds = mTempRect;
    mSeekBarDrawable.copyTouchBounds(finalBounds);
    if (!isInEditMode()) {
        mIndicator.move(finalBounds.centerX());
    }

    // Ripple
    mRipple.setBounds(finalBounds.left, finalBounds.top, finalBounds.right, finalBounds.bottom);

    // Invalidate
    mSeekBarDrawable.copyBounds(mInvalidateRect);
    invalidate(mInvalidateRect);
}

From source file:com.ucmap.dingdinghelper.services.DingDingHelperAccessibilityService.java

private void handleIt(AccessibilityNodeInfo info) {

    if (!isCut) {
        isCut = true;/*from   w w  w .  j  a  va  2  s. co  m*/
        //            Toast.makeText(App.mContext, "??", Toast.LENGTH_SHORT).show();
    }
    Rect mRect = new Rect();
    info.getBoundsInScreen(mRect);
    ShellUtils.CommandResult mCommandResult = doShellCmdInputTap(mRect.centerX(), mRect.centerY());
    if (mCommandResult.result == 0) {
        STATE = STATE_CHECKED_IN;
    }

}

From source file:com.ucmap.dingdinghelper.services.DingDingHelperAccessibilityService.java

private void handleGoToWork(AccessibilityNodeInfo info) {
    if (isGo) {//  w  ww  .j ava  2  s.c om
        isGo = false;
        //            Toast.makeText(App.mContext, "???? ... ", Toast.LENGTH_SHORT).show();
        Rect mRect = new Rect();
        info.getBoundsInScreen(mRect);
        ShellUtils.CommandResult mCommandResult = doShellCmdInputTap(mRect.centerX(), mRect.centerY());
        if (mCommandResult.result == 0) {
            STATE = STATE_CHECKED_IN;
        }
    }
}