Example usage for android.graphics Rect height

List of usage examples for android.graphics Rect height

Introduction

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

Prototype

public final int height() 

Source Link

Usage

From source file:de.vanita5.twittnuker.util.Utils.java

public static void showMenuItemToast(final View v, final CharSequence text) {
    final int[] screenPos = new int[2];
    final Rect displayFrame = new Rect();
    v.getLocationOnScreen(screenPos);/*  www .ja  v  a  2 s  .  c o m*/
    v.getWindowVisibleDisplayFrame(displayFrame);
    final int height = v.getHeight();
    final int midy = screenPos[1] + height / 2;
    showMenuItemToast(v, text, midy >= displayFrame.height());
}

From source file:net.robotmedia.acv.ui.widget.OcrLayout.java

/** Capture screen to the lastCapture bitmap. */
private boolean captureScreen(Rect curCaptureBox) {
    View v = this.comicView;

    if ((v != null) && (curCaptureBox != null) && (curCaptureBox.width() > 0) && (curCaptureBox.height() > 0)) {
        this.clipOffset = new Point(0, 0);

        try {//from w  w w  .  j a v a 2  s.  com
            // Only create the bitmap that contains the entire screen once
            if (this.lastScreenshot == null) {
                this.lastScreenshot = Bitmap.createBitmap(v.getWidth(), v.getHeight(), Bitmap.Config.ARGB_8888);
                this.captureCanvas = new Canvas(this.lastScreenshot);
            }

            // If user adjusted capture box since this routine was called, stop here
            if (isCaptureBoxBeingAdjusted() || !isCaptureBoxEqual(this.captureBox, curCaptureBox)) {
                return false;
            }

            v.layout(0, 0, v.getWidth(), v.getHeight());

            // Draw the comic view to the lastScreenshot bitmap
            v.draw(this.captureCanvas);

            // If user adjusted capture box since this routine was called, stop here
            if (isCaptureBoxBeingAdjusted() || !isCaptureBoxEqual(this.captureBox, curCaptureBox)) {
                return false;
            }

            // Get bitmap that contains only the capture box area
            Bitmap captureBmp = Bitmap.createBitmap(this.lastScreenshot, curCaptureBox.left, curCaptureBox.top,
                    curCaptureBox.width(), curCaptureBox.height());

            // If user adjusted capture box since this routine was called, stop here
            if (isCaptureBoxBeingAdjusted() || !isCaptureBoxEqual(this.captureBox, curCaptureBox)) {
                return false;
            }

            // Create a Leptonica Pix object from the captured image
            this.lastCapture = ReadFile.readBitmap(captureBmp);

            // If user adjusted capture box since this routine was called, stop here
            if (isCaptureBoxBeingAdjusted() || !isCaptureBoxEqual(this.captureBox, curCaptureBox)) {
                return false;
            }

            // Convert to grayscale
            this.lastCapture = Convert.convertTo8(this.lastCapture);

            if (this.lastCapture == null) {
                return false;
            }

            // If user adjusted capture box since this routine was called, stop here
            if (isCaptureBoxBeingAdjusted() || !isCaptureBoxEqual(this.captureBox, curCaptureBox)) {
                return false;
            }

            Pix tempOtsu = Binarize.otsuAdaptiveThreshold(this.lastCapture, 2000, 2000, 0, 0, 0.0f);

            if (tempOtsu == null) {
                return false;
            }

            // If user adjusted capture box since this routine was called, stop here
            if (isCaptureBoxBeingAdjusted() || !isCaptureBoxEqual(this.captureBox, curCaptureBox)) {
                tempOtsu.recycle();
                return false;
            }

            /* Get the average intensity of the border pixels */
            float aveBorderBrightness = LeptUtils.getAveBorderBrightness(tempOtsu);
            tempOtsu.recycle();

            // If background is dark
            if (aveBorderBrightness <= 0.5f) {
                // Negate image
                boolean invertStatus = this.lastCapture.invert();

                if (!invertStatus) {
                    return false;
                }
            }

            // If user adjusted capture box since this routine was called, stop here
            if (isCaptureBoxBeingAdjusted() || !isCaptureBoxEqual(this.captureBox, curCaptureBox)) {
                return false;
            }

            // Scale the image
            this.lastCapture = Scale.scale(this.lastCapture, this.getIdealPreProcessingScaleFactor());

            if (this.lastCapture == null) {
                return false;
            }

            // If user adjusted capture box since this routine was called, stop here
            if (isCaptureBoxBeingAdjusted() || !isCaptureBoxEqual(this.captureBox, curCaptureBox)) {
                return false;
            }

            // Apply unsharp mask
            this.lastCapture = Enhance.unsharpMasking(this.lastCapture, 5, 2.5f);

            if (this.lastCapture == null) {
                return false;
            }

            // If user adjusted capture box since this routine was called, stop here
            if (isCaptureBoxBeingAdjusted() || !isCaptureBoxEqual(this.captureBox, curCaptureBox)) {
                return false;
            }

            // Binarize
            this.lastCapture = Binarize.otsuAdaptiveThreshold(this.lastCapture, 2000, 2000, 0, 0, 0.0f);

            if (this.lastCapture == null) {
                return false;
            }

            // If user adjusted capture box since this routine was called, stop here
            if (isCaptureBoxBeingAdjusted() || !isCaptureBoxEqual(this.captureBox, curCaptureBox)) {
                return false;
            }

            // Remove furigana
            if (this.isOrientationVertical(this.captureBox)) {
                Furigana.eraseFuriganaVerticalText(this.lastCapture, this.getIdealPreProcessingScaleFactor());
            } else {
                Furigana.eraseFuriganaHorizontalText(this.lastCapture, this.getIdealPreProcessingScaleFactor());
            }

            // If user adjusted capture box since this routine was called, stop here
            if (isCaptureBoxBeingAdjusted() || !isCaptureBoxEqual(this.captureBox, curCaptureBox)) {
                return false;
            }

            // Clip foreground and add border
            if (this.isTriggerCapture || this.ocrSettingsForceBorder) {
                // Are there any foreground pixels to clip to?
                boolean canClip = Clip.testClipToForeground(this.lastCapture);

                if (canClip) {
                    // Get the top-left point of the foreground clip (will be used to offset bounding boxes)
                    this.clipOffset = LeptUtils.getForegroundClipOffset(this.lastCapture);

                    // If user adjusted capture box since this routine was called, stop here
                    if (isCaptureBoxBeingAdjusted() || !isCaptureBoxEqual(this.captureBox, curCaptureBox)) {
                        return false;
                    }

                    // Remove all existing white border pixels
                    this.lastCapture = Clip.clipToForeground(this.lastCapture);

                    if (this.lastCapture == null) {
                        return false;
                    }
                }

                // If user adjusted capture box since this routine was called, stop here
                if (isCaptureBoxBeingAdjusted() || !isCaptureBoxEqual(this.captureBox, curCaptureBox)) {
                    return false;
                }

                // Add an external white border
                this.lastCapture = Pix.addBlackOrWhiteBorder(this.lastCapture, 2, 2, 2, 2, false);
                this.clipOffset.x -= 2;
                this.clipOffset.y -= 2;

                this.isTriggerCapture = false;
            }

            // If user adjusted capture box since this routine was called, stop here
            if (isCaptureBoxBeingAdjusted() || !isCaptureBoxEqual(this.captureBox, curCaptureBox)) {
                return false;
            }
        } catch (Exception e) {
            // If we're here, it's probably an out-of-memory exception
            Log.e(LOG_TAG, "Exception in captureScreen()! " + e);
            return false;
        }
    } else {
        return false;
    }

    return true;
}

From source file:com.klinker.android.launcher.launcher3.Workspace.java

/**
 * Draw the View v into the given Canvas.
 *
 * @param v the view to draw/*www .  ja  v a 2 s  . c o m*/
 * @param destCanvas the canvas to draw on
 * @param padding the horizontal and vertical padding to use when drawing
 */
private static void drawDragView(View v, Canvas destCanvas, int padding) {
    final Rect clipRect = sTempRect;
    v.getDrawingRect(clipRect);

    boolean textVisible = false;

    destCanvas.save();
    if (v instanceof TextView) {
        Drawable d = getTextViewIcon((TextView) v);
        Rect bounds = getDrawableBounds(d);
        clipRect.set(0, 0, bounds.width() + padding, bounds.height() + padding);
        destCanvas.translate(padding / 2 - bounds.left, padding / 2 - bounds.top);
        d.draw(destCanvas);
    } else {
        if (v instanceof FolderIcon) {
            // For FolderIcons the text can bleed into the icon area, and so we need to
            // hide the text completely (which can't be achieved by clipping).
            if (((FolderIcon) v).getTextVisible()) {
                ((FolderIcon) v).setTextVisible(false);
                textVisible = true;
            }
        }
        destCanvas.translate(-v.getScrollX() + padding / 2, -v.getScrollY() + padding / 2);
        destCanvas.clipRect(clipRect, Op.REPLACE);
        v.draw(destCanvas);

        // Restore text visibility of FolderIcon if necessary
        if (textVisible) {
            ((FolderIcon) v).setTextVisible(true);
        }
    }
    destCanvas.restore();
}

From source file:com.breakout.main.GameState.java

/**
 * Renders debug features./*from  w w  w.  jav a 2s  .c om*/
 * <p>
 * This function is allowed to violate the "don't allocate objects" rule.
 */
void drawDebugStuff() {

    // Draw a red outline rectangle around the ball.  This shows the area that was
    // examined for collisions during the "coarse" pass.
    OutlineAlignedRect.prepareToDraw();
    mDebugCollisionRect.draw();
    OutlineAlignedRect.finishedDrawing();

    // Draw the entire message texture so we can see what it looks like.
    if (true) {
        int textureWidth = mTextRes.getTextureWidth();
        int textureHeight = mTextRes.getTextureHeight();
        float scale = (ARENA_WIDTH * STATUS_MESSAGE_WIDTH_PERC) / textureWidth;

        // Draw an orange rect around the texture.
        OutlineAlignedRect outline = new OutlineAlignedRect();
        outline.setPosition(ARENA_WIDTH / 2, ARENA_HEIGHT / 2);
        outline.setScale(textureWidth * scale + 2, textureHeight * scale + 2);
        outline.setColor(1.0f, 0.65f, 0.0f);
        OutlineAlignedRect.prepareToDraw();
        outline.draw();
        OutlineAlignedRect.finishedDrawing();

        // Draw the full texture.  Note you can set the background to opaque white in
        // TextResources to see what the drop shadow looks like.
        Rect boundsRect = new Rect(0, 0, textureWidth, textureHeight);
        TexturedAlignedRect msgBox = mGameStatusMessages;
        msgBox.setTextureCoords(boundsRect);
        msgBox.setScale(textureWidth * scale, textureHeight * scale);
        TexturedAlignedRect.prepareToDraw();
        msgBox.draw();
        TexturedAlignedRect.finishedDrawing();

        // Draw a rectangle around each individual text item.  We draw a different one each
        // time to get a flicker effect, so it doesn't fully obscure the text.
        if (true) {
            outline.setColor(1.0f, 1.0f, 1.0f);
            int stringNum = mDebugFramedString;
            mDebugFramedString = (mDebugFramedString + 1) % TextResources.getNumStrings();
            boundsRect = mTextRes.getTextureRect(stringNum);
            // The bounds rect is in bitmap coordinates, with (0,0) in the top left.  Translate
            // it to an offset from the center of the bitmap, and find the center of the rect.
            float boundsCenterX = boundsRect.exactCenterX() - (textureWidth / 2);
            float boundsCenterY = boundsRect.exactCenterY() - (textureHeight / 2);
            // Now scale it to arena coordinates, using the same scale factor we used to
            // draw the texture with all the messages, and translate it to the center of
            // the arena.  We need to invert Y to match GL conventions.
            boundsCenterX = ARENA_WIDTH / 2 + (boundsCenterX * scale);
            boundsCenterY = ARENA_HEIGHT / 2 - (boundsCenterY * scale);
            // Set the values and draw the rect.
            outline.setPosition(boundsCenterX, boundsCenterY);
            outline.setScale(boundsRect.width() * scale, boundsRect.height() * scale);
            OutlineAlignedRect.prepareToDraw();
            outline.draw();
            OutlineAlignedRect.finishedDrawing();
        }
    }
}

From source file:com.android.launcher3.CellLayout.java

private boolean addViewsToTempLocation(ArrayList<View> views, Rect rectOccupiedByPotentialDrop, int[] direction,
        View dragView, ItemConfiguration currentState) {
    if (views.size() == 0)
        return true;

    boolean success = false;
    Rect boundingRect = null;
    // We construct a rect which represents the entire group of views passed in
    for (View v : views) {
        CellAndSpan c = currentState.map.get(v);
        if (boundingRect == null) {
            boundingRect = new Rect(c.x, c.y, c.x + c.spanX, c.y + c.spanY);
        } else {// w  w  w. ja  va 2s .c o  m
            boundingRect.union(c.x, c.y, c.x + c.spanX, c.y + c.spanY);
        }
    }

    // Mark the occupied state as false for the group of views we want to move.
    for (View v : views) {
        CellAndSpan c = currentState.map.get(v);
        markCellsForView(c.x, c.y, c.spanX, c.spanY, mTmpOccupied, false);
    }

    boolean[][] blockOccupied = new boolean[boundingRect.width()][boundingRect.height()];
    int top = boundingRect.top;
    int left = boundingRect.left;
    // We mark more precisely which parts of the bounding rect are truly occupied, allowing
    // for interlocking.
    for (View v : views) {
        CellAndSpan c = currentState.map.get(v);
        markCellsForView(c.x - left, c.y - top, c.spanX, c.spanY, blockOccupied, true);
    }

    markCellsForRect(rectOccupiedByPotentialDrop, mTmpOccupied, true);

    findNearestArea(boundingRect.left, boundingRect.top, boundingRect.width(), boundingRect.height(), direction,
            mTmpOccupied, blockOccupied, mTempLocation);

    // If we successfuly found a location by pushing the block of views, we commit it
    if (mTempLocation[0] >= 0 && mTempLocation[1] >= 0) {
        int deltaX = mTempLocation[0] - boundingRect.left;
        int deltaY = mTempLocation[1] - boundingRect.top;
        for (View v : views) {
            CellAndSpan c = currentState.map.get(v);
            c.x += deltaX;
            c.y += deltaY;
        }
        success = true;
    }

    // In either case, we set the occupied array as marked for the location of the views
    for (View v : views) {
        CellAndSpan c = currentState.map.get(v);
        markCellsForView(c.x, c.y, c.spanX, c.spanY, mTmpOccupied, true);
    }
    return success;
}

From source file:com.google.zxing.client.android.ViewfinderView.java

@SuppressLint("DrawAllocation")
@Override//w w w .j  av  a 2s . com
public void onDraw(Canvas canvas) {
    if (cameraManager == null) {
        return; // not ready yet, early draw before done configuring
    }
    Rect frame = cameraManager.getFramingRect();
    Rect previewFrame = cameraManager.getFramingRectInPreview();
    if (frame == null || previewFrame == null) {
        return;
    }
    int width = canvas.getWidth();
    int height = canvas.getHeight();

    // Draw the exterior (i.e. outside the framing rect) darkened
    paint.setColor(resultBitmap != null ? resultColor : maskColor);
    canvas.drawRect(0, 0, width, frame.top, paint);
    canvas.drawRect(0, frame.top, frame.left, frame.bottom, paint);
    canvas.drawRect(frame.right, frame.top, width, frame.bottom, paint);
    canvas.drawRect(0, frame.bottom, width, height, paint);

    ///
    // 
    paint.setColor(getResources().getColor(R.color.encode_view));
    int w = 16;
    int h = 2;
    int margin = 2;
    // 
    canvas.drawRect(frame.left - margin - h, frame.top - margin - h, frame.left - margin + w - h,
            frame.top - margin + h - h, paint);
    canvas.drawRect(frame.left - margin - h, frame.top - margin - h, frame.left - margin + h - h,
            frame.top - margin + w - h, paint);
    // ?
    canvas.drawRect(frame.right + margin - w + h, frame.top - margin - h, frame.right + margin + h,
            frame.top - margin + h - h, paint);
    canvas.drawRect(frame.right + margin - h + h, frame.top - margin - h, frame.right + margin + h,
            frame.top - margin + w - h, paint);
    // 
    canvas.drawRect(frame.left - margin - h, frame.bottom + margin - h + h, frame.left - margin + w - h,
            frame.bottom + margin + h, paint);
    canvas.drawRect(frame.left - margin - h, frame.bottom + margin - w + h, frame.left - margin + h - h,
            frame.bottom + margin + h, paint);
    // ?
    canvas.drawRect(frame.right + margin - w + h, frame.bottom + margin - h + h, frame.right + margin + h,
            frame.bottom + margin + h, paint);
    canvas.drawRect(frame.right + margin - h + h, frame.bottom + margin - w + h, frame.right + margin + h,
            frame.bottom + margin + h, paint);
    ///?
    drawLineRound(canvas, frame, paint);
    if (statusText != null) {
        RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) statusText.getLayoutParams();
        lp.topMargin = frame.top - statusText.getMeasuredHeight() - 28;
        statusText.setLayoutParams(lp);
        statusText.setVisibility(View.VISIBLE);
    }
    if (resultBitmap != null) {
        // Draw the opaque result bitmap over the scanning rectangle
        if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            paint.setAlpha(CURRENT_POINT_OPACITY);
        }
        canvas.drawBitmap(resultBitmap, null, frame, paint);
    } else {
        // ??
        if ((i += 5) < frame.bottom - frame.top) {
            /* ?? */
            mRect.set(frame.left, frame.top + i - 1, frame.right, frame.top + i + 1);
            lineDrawable.setBounds(mRect);
            lineDrawable.draw(canvas);
            // 
            invalidate();
        } else {
            i = 0;
        }

        float scaleX = frame.width() / (float) previewFrame.width();
        float scaleY = frame.height() / (float) previewFrame.height();

        List<ResultPoint> currentPossible = possibleResultPoints;
        List<ResultPoint> currentLast = lastPossibleResultPoints;
        int frameLeft = frame.left;
        int frameTop = frame.top;
        if (currentPossible.isEmpty()) {
            lastPossibleResultPoints = null;
        } else {
            possibleResultPoints = new ArrayList<>(5);
            lastPossibleResultPoints = currentPossible;
            if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
                paint.setAlpha(CURRENT_POINT_OPACITY);
            }
            paint.setColor(resultPointColor);
            synchronized (currentPossible) {
                for (ResultPoint point : currentPossible) {
                    canvas.drawCircle(frameLeft + (int) (point.getX() * scaleX),
                            frameTop + (int) (point.getY() * scaleY), POINT_SIZE, paint);
                }
            }
        }
        if (currentLast != null) {
            if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
                paint.setAlpha(CURRENT_POINT_OPACITY / 2);
            }
            paint.setColor(resultPointColor);
            synchronized (currentLast) {
                float radius = POINT_SIZE / 2.0f;
                for (ResultPoint point : currentLast) {
                    canvas.drawCircle(frameLeft + (int) (point.getX() * scaleX),
                            frameTop + (int) (point.getY() * scaleY), radius, paint);
                }
            }
        }

        // Request another update at the animation interval, but only repaint the laser line,
        // not the entire viewfinder mask.
        postInvalidateDelayed(ANIMATION_DELAY, frame.left - POINT_SIZE, frame.top - POINT_SIZE,
                frame.right + POINT_SIZE, frame.bottom + POINT_SIZE);
    }
}

From source file:com.android.launcher2.Workspace.java

public int[] estimateItemSize(int hSpan, int vSpan, ItemInfo itemInfo, boolean springLoaded) {
    int[] size = new int[2];
    if (getChildCount() > 0) {
        CellLayout cl = (CellLayout) mLauncher.getWorkspace().getChildAt(0);
        Rect r = estimateItemPosition(cl, itemInfo, 0, 0, hSpan, vSpan);
        size[0] = r.width();/*from  w  ww .  jav a  2  s .  c  o m*/
        size[1] = r.height();
        if (springLoaded) {
            size[0] *= mSpringLoadedShrinkFactor;
            size[1] *= mSpringLoadedShrinkFactor;
        }
        return size;
    } else {
        size[0] = Integer.MAX_VALUE;
        size[1] = Integer.MAX_VALUE;
        return size;
    }
}

From source file:com.huewu.pla.lib.internal.PLAListView.java

@Override
public boolean requestChildRectangleOnScreen(final View child, final Rect rect, final boolean immediate) {

    final int rectTopWithinChild = rect.top;

    // offset so rect is in coordinates of the this view
    rect.offset(child.getLeft(), child.getTop());
    rect.offset(-child.getScrollX(), -child.getScrollY());

    final int height = getHeight();
    int listUnfadedTop = getScrollY();
    int listUnfadedBottom = listUnfadedTop + height;
    final int fadingEdge = getVerticalFadingEdgeLength();

    if (showingTopFadingEdge()) {
        // leave room for top fading edge as long as rect isn't at very top
        if (rectTopWithinChild > fadingEdge) {
            listUnfadedTop += fadingEdge;
        }//from   w  ww  . ja v  a 2 s. c  om
    }

    final int childCount = getChildCount();
    final int bottomOfBottomChild = getChildAt(childCount - 1).getBottom();

    if (showingBottomFadingEdge()) {
        // leave room for bottom fading edge as long as rect isn't at very
        // bottom
        if (rect.bottom < bottomOfBottomChild - fadingEdge) {
            listUnfadedBottom -= fadingEdge;
        }
    }

    int scrollYDelta = 0;

    if (rect.bottom > listUnfadedBottom && rect.top > listUnfadedTop) {
        // need to MOVE DOWN to get it in view: move down just enough so
        // that the entire rectangle is in view (or at least the first
        // screen size chunk).

        if (rect.height() > height) {
            // just enough to get screen size chunk on
            scrollYDelta += rect.top - listUnfadedTop;
        } else {
            // get entire rect at bottom of screen
            scrollYDelta += rect.bottom - listUnfadedBottom;
        }

        // make sure we aren't scrolling beyond the end of our children
        final int distanceToBottom = bottomOfBottomChild - listUnfadedBottom;
        scrollYDelta = Math.min(scrollYDelta, distanceToBottom);
    } else if (rect.top < listUnfadedTop && rect.bottom < listUnfadedBottom) {
        // need to MOVE UP to get it in view: move up just enough so that
        // entire rectangle is in view (or at least the first screen
        // size chunk of it).

        if (rect.height() > height) {
            // screen size chunk
            scrollYDelta -= listUnfadedBottom - rect.bottom;
        } else {
            // entire rect at top
            scrollYDelta -= listUnfadedTop - rect.top;
        }

        // make sure we aren't scrolling any further than the top our
        // children
        final int top = getChildAt(0).getTop();
        final int deltaToTop = top - listUnfadedTop;
        scrollYDelta = Math.max(scrollYDelta, deltaToTop);
    }

    final boolean scroll = scrollYDelta != 0;
    if (scroll) {
        scrollListItemsBy(-scrollYDelta);
        positionSelector(child);
        mSelectedTop = child.getTop();
        invalidate();
    }
    return scroll;
}

From source file:com.waz.zclient.pages.main.participants.dialog.ParticipantsDialogFragment.java

private void setDialogPosition(Rect rect, int posX, int posY, int dialogWidth, int dialogHeight) {
    if (getControllerFactory().getConversationScreenController()
            .getPopoverLaunchMode() == DialogLaunchMode.COMMON_USER) {
        dialogTranslationX = posX + (rect.width() - dialogWidth) / 2;
        marker.setVisibility(View.VISIBLE);
    } else if (getControllerFactory().getConversationScreenController()
            .getPopoverLaunchMode() == DialogLaunchMode.CONVERSATION_TOOLBAR) {
        int screenWidth = ViewUtils.getRealDisplayWidth(getActivity());
        dialogTranslationX = screenWidth / 2 - dialogWidth / 2;
        marker.setVisibility(View.INVISIBLE);
    } else {/*ww w .  ja  v  a  2 s .  c  o m*/
        dialogTranslationX = getResources()
                .getDimensionPixelSize(R.dimen.framework__participants_dialog__pos_x);
        marker.setVisibility(View.VISIBLE);
    }

    int markerHeight = marker.getMeasuredHeight() / 2; // because we draw on our own
    int markerWidth = marker.getMeasuredWidth();

    markerTranslationX = posX + (rect.width() - markerWidth) / 2;

    int displayHeight;
    int displayWidth;

    boolean forceRight = getControllerFactory().getConversationScreenController()
            .getPopoverLaunchMode() == DialogLaunchMode.SEARCH
            || getControllerFactory().getConversationScreenController()
                    .getPopoverLaunchMode() == DialogLaunchMode.CONVERSATION_MENU;

    if (ViewUtils.isInPortrait(getActivity())) {
        displayHeight = ViewUtils.getOrientationIndependentDisplayHeight(getActivity());
        displayWidth = ViewUtils.getOrientationIndependentDisplayWidth(getActivity());
    } else {
        displayHeight = ViewUtils.getOrientationIndependentDisplayWidth(getActivity());
        displayWidth = ViewUtils.getOrientationIndependentDisplayHeight(getActivity());
    }

    final int screenBottom = displayHeight - participantDialogPadding
            - ViewUtils.getStatusBarHeight(getActivity());
    final int screenRight = displayWidth - participantDialogPadding;
    final int screenLeft = participantDialogPadding;

    if ((posY - dialogHeight - markerHeight) >= participantDialogPadding && !forceRight) {
        // put above
        markerTranslationY = posY - markerHeight;
        dialogTranslationY = markerTranslationY - dialogHeight;
        marker.setRotation(0f);
        if (dialogTranslationX + dialogWidth > screenRight) {
            // too far right
            dialogTranslationX = screenRight - dialogWidth;
        } else if (dialogTranslationX < participantDialogPadding) {
            // too far left
            dialogTranslationX = participantDialogPadding;
        }
        selfGravity = Gravity.TOP;
    } else if (posY + rect.height() + dialogHeight + markerHeight < screenBottom && !forceRight) {
        // put below
        markerTranslationY = posY + rect.height() - markerHeight;
        dialogTranslationY = markerTranslationY + 2 * markerHeight; // 2 * because we draw on our own
        marker.setRotation(180f);
        if (dialogTranslationX + dialogWidth > screenRight) {
            // too far right
            dialogTranslationX = screenRight - dialogWidth;
        } else if (dialogTranslationX < participantDialogPadding) {
            // too far left
            dialogTranslationX = participantDialogPadding;
        }
        selfGravity = Gravity.BOTTOM;
    } else if (posX + rect.width() + markerWidth + dialogWidth <= displayWidth - participantDialogPadding
            || forceRight) {
        int tmp = markerHeight;
        //noinspection SuspiciousNameCombination
        markerHeight = markerWidth;
        markerWidth = tmp;

        // centered
        markerTranslationX = posX + rect.width() - markerWidth;
        dialogTranslationX = markerTranslationX + 2 * markerWidth; // 2 * because we draw on our own

        markerTranslationY = (posY + rect.centerY()) - (markerHeight / 2);
        dialogTranslationY = (posY + rect.centerY()) - (dialogHeight / 2);
        marker.setRotation(90f);

        if (dialogTranslationY < participantDialogPadding) {
            // too high
            dialogTranslationY = participantDialogPadding;
        } else if (posY + dialogHeight > screenBottom) {
            // too low
            dialogTranslationY = displayHeight - participantDialogPadding - dialogHeight
                    - ViewUtils.getStatusBarHeight(getActivity());
        }

        // too far right
        if (dialogTranslationX + dialogWidth > screenRight) {
            dialogTranslationX = screenRight - dialogWidth;
            markerTranslationX = dialogTranslationX - 2 * markerWidth; // 2 * because we draw on our own
        }
        selfGravity = Gravity.RIGHT;
    } else {
        int tmp = markerHeight;
        //noinspection SuspiciousNameCombination
        markerHeight = markerWidth;
        markerWidth = tmp;

        // centered
        markerTranslationX = posX - markerWidth;
        dialogTranslationX = markerTranslationX - dialogWidth;

        markerTranslationY = (posY + rect.centerY()) - (markerHeight / 2);
        dialogTranslationY = (posY + rect.centerY()) - (dialogHeight / 2);
        marker.setRotation(270f);

        if (dialogTranslationY < participantDialogPadding) {
            // too high
            dialogTranslationY = participantDialogPadding;
        } else if (posY + dialogHeight > screenBottom) {
            // too low
            dialogTranslationY = displayHeight - participantDialogPadding - dialogHeight
                    - ViewUtils.getStatusBarHeight(getActivity());
        }

        // too far left
        if (dialogTranslationX < screenLeft) {
            dialogTranslationX = screenLeft;
            markerTranslationX = dialogTranslationX + dialogWidth;
        }

        selfGravity = Gravity.LEFT;
    }

    dialogFrameLayout.setTranslationX(dialogTranslationX);
    dialogFrameLayout.setTranslationY(dialogTranslationY);

    marker.setTranslationX(markerTranslationX);
    marker.setTranslationY(markerTranslationY);
}

From source file:com.huewu.pla.lib.internal.PLA_ListView.java

@Override
public boolean requestChildRectangleOnScreen(View child, Rect rect, boolean immediate) {

    int rectTopWithinChild = rect.top;

    // offset so rect is in coordinates of the this view
    rect.offset(child.getLeft(), child.getTop());
    rect.offset(-child.getScrollX(), -child.getScrollY());

    final int height = getHeight();
    int listUnfadedTop = getScrollY();
    int listUnfadedBottom = listUnfadedTop + height;
    final int fadingEdge = getVerticalFadingEdgeLength();

    if (showingTopFadingEdge()) {
        // leave room for top fading edge as long as rect isn't at very top
        if (rectTopWithinChild > fadingEdge) {
            listUnfadedTop += fadingEdge;
        }// ww w .j av  a2s . com
    }

    int childCount = getChildCount();
    int bottomOfBottomChild = getChildAt(childCount - 1).getBottom();

    if (showingBottomFadingEdge()) {
        // leave room for bottom fading edge as long as rect isn't at very
        // bottom
        if (rect.bottom < (bottomOfBottomChild - fadingEdge)) {
            listUnfadedBottom -= fadingEdge;
        }
    }

    int scrollYDelta = 0;

    if (rect.bottom > listUnfadedBottom && rect.top > listUnfadedTop) {
        // need to MOVE DOWN to get it in view: move down just enough so
        // that the entire rectangle is in view (or at least the first
        // screen size chunk).

        if (rect.height() > height) {
            // just enough to get screen size chunk on
            scrollYDelta += (rect.top - listUnfadedTop);
        } else {
            // get entire rect at bottom of screen
            scrollYDelta += (rect.bottom - listUnfadedBottom);
        }

        // make sure we aren't scrolling beyond the end of our children
        int distanceToBottom = bottomOfBottomChild - listUnfadedBottom;
        scrollYDelta = Math.min(scrollYDelta, distanceToBottom);
    } else if (rect.top < listUnfadedTop && rect.bottom < listUnfadedBottom) {
        // need to MOVE UP to get it in view: move up just enough so that
        // entire rectangle is in view (or at least the first screen
        // size chunk of it).

        if (rect.height() > height) {
            // screen size chunk
            scrollYDelta -= (listUnfadedBottom - rect.bottom);
        } else {
            // entire rect at top
            scrollYDelta -= (listUnfadedTop - rect.top);
        }

        // make sure we aren't scrolling any further than the top our
        // children
        int top = getChildAt(0).getTop();
        int deltaToTop = top - listUnfadedTop;
        scrollYDelta = Math.max(scrollYDelta, deltaToTop);
    }

    final boolean scroll = scrollYDelta != 0;
    if (scroll) {
        scrollListItemsBy(-scrollYDelta);
        positionSelector(child);
        mSelectedTop = child.getTop();
        invalidate();
    }
    return scroll;
}