Search in sources :

Example 41 with Rect

use of android.graphics.Rect in project platform_frameworks_base by android.

the class DecorView method updateStatusGuard.

private WindowInsets updateStatusGuard(WindowInsets insets) {
    boolean showStatusGuard = false;
    // Show the status guard when the non-overlay contextual action bar is showing
    if (mPrimaryActionModeView != null) {
        if (mPrimaryActionModeView.getLayoutParams() instanceof MarginLayoutParams) {
            // Insets are magic!
            final MarginLayoutParams mlp = (MarginLayoutParams) mPrimaryActionModeView.getLayoutParams();
            boolean mlpChanged = false;
            if (mPrimaryActionModeView.isShown()) {
                if (mTempRect == null) {
                    mTempRect = new Rect();
                }
                final Rect rect = mTempRect;
                // If the parent doesn't consume the insets, manually
                // apply the default system window insets.
                mWindow.mContentParent.computeSystemWindowInsets(insets, rect);
                final int newMargin = rect.top == 0 ? insets.getSystemWindowInsetTop() : 0;
                if (mlp.topMargin != newMargin) {
                    mlpChanged = true;
                    mlp.topMargin = insets.getSystemWindowInsetTop();
                    if (mStatusGuard == null) {
                        mStatusGuard = new View(mContext);
                        mStatusGuard.setBackgroundColor(mContext.getColor(R.color.input_method_navigation_guard));
                        addView(mStatusGuard, indexOfChild(mStatusColorViewState.view), new LayoutParams(LayoutParams.MATCH_PARENT, mlp.topMargin, Gravity.START | Gravity.TOP));
                    } else {
                        final LayoutParams lp = (LayoutParams) mStatusGuard.getLayoutParams();
                        if (lp.height != mlp.topMargin) {
                            lp.height = mlp.topMargin;
                            mStatusGuard.setLayoutParams(lp);
                        }
                    }
                }
                // The action mode's theme may differ from the app, so
                // always show the status guard above it if we have one.
                showStatusGuard = mStatusGuard != null;
                // We only need to consume the insets if the action
                // mode is overlaid on the app content (e.g. it's
                // sitting in a FrameLayout, see
                // screen_simple_overlay_action_mode.xml).
                final boolean nonOverlay = (mWindow.getLocalFeaturesPrivate() & (1 << Window.FEATURE_ACTION_MODE_OVERLAY)) == 0;
                insets = insets.consumeSystemWindowInsets(false, nonOverlay && showStatusGuard, /* top */
                false, false);
            } else {
                // reset top margin
                if (mlp.topMargin != 0) {
                    mlpChanged = true;
                    mlp.topMargin = 0;
                }
            }
            if (mlpChanged) {
                mPrimaryActionModeView.setLayoutParams(mlp);
            }
        }
    }
    if (mStatusGuard != null) {
        mStatusGuard.setVisibility(showStatusGuard ? View.VISIBLE : View.GONE);
    }
    return insets;
}
Also used : Rect(android.graphics.Rect) View(android.view.View) ActionBarContextView(com.android.internal.widget.ActionBarContextView) DecorCaptionView(com.android.internal.widget.DecorCaptionView) Paint(android.graphics.Paint)

Example 42 with Rect

use of android.graphics.Rect in project platform_frameworks_base by android.

the class DecorView method setFrame.

@Override
protected boolean setFrame(int l, int t, int r, int b) {
    boolean changed = super.setFrame(l, t, r, b);
    if (changed) {
        final Rect drawingBounds = mDrawingBounds;
        getDrawingRect(drawingBounds);
        Drawable fg = getForeground();
        if (fg != null) {
            final Rect frameOffsets = mFrameOffsets;
            drawingBounds.left += frameOffsets.left;
            drawingBounds.top += frameOffsets.top;
            drawingBounds.right -= frameOffsets.right;
            drawingBounds.bottom -= frameOffsets.bottom;
            fg.setBounds(drawingBounds);
            final Rect framePadding = mFramePadding;
            drawingBounds.left += framePadding.left - frameOffsets.left;
            drawingBounds.top += framePadding.top - frameOffsets.top;
            drawingBounds.right -= framePadding.right - frameOffsets.right;
            drawingBounds.bottom -= framePadding.bottom - frameOffsets.bottom;
        }
        Drawable bg = getBackground();
        if (bg != null) {
            bg.setBounds(drawingBounds);
        }
        if (SWEEP_OPEN_MENU) {
            if (mMenuBackground == null && mFeatureId < 0 && mWindow.getAttributes().height == WindowManager.LayoutParams.MATCH_PARENT) {
                mMenuBackground = getContext().getDrawable(R.drawable.menu_background);
            }
            if (mMenuBackground != null) {
                mMenuBackground.setBounds(drawingBounds.left, drawingBounds.bottom - 6, drawingBounds.right, drawingBounds.bottom + 20);
            }
        }
    }
    return changed;
}
Also used : Rect(android.graphics.Rect) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable)

Example 43 with Rect

use of android.graphics.Rect in project platform_frameworks_base by android.

the class ListItemRequestRectAboveThinFirstItemTest method testSecondItemRequestRectAboveTop.

// reproduce bug 998501: when first item fits within fading edge,
// having the second item call requestRectangleOnScreen with a rect above
// the bounds of the list, it was scrolling too far
@MediumTest
public void testSecondItemRequestRectAboveTop() throws Exception {
    sendKeys(KeyEvent.KEYCODE_DPAD_DOWN);
    assertEquals("selected position", 1, mListView.getSelectedItemPosition());
    final View second = mListView.getChildAt(1);
    final Rect rect = new Rect();
    second.getDrawingRect(rect);
    rect.offset(0, -2 * second.getBottom());
    getActivity().requestRectangleOnScreen(1, rect);
    getInstrumentation().waitForIdleSync();
    assertEquals("top of first item", mListView.getListPaddingTop(), mListView.getChildAt(0).getTop());
}
Also used : Rect(android.graphics.Rect) View(android.view.View) ListView(android.widget.ListView) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Example 44 with Rect

use of android.graphics.Rect in project platform_frameworks_base by android.

the class ListItemRequestRectAboveThinFirstItemTest method testSecondToLastItemRequestRectBelowBottom.

// same thing, but at bottom
@LargeTest
public void testSecondToLastItemRequestRectBelowBottom() throws Exception {
    final int secondToLastPos = mListView.getCount() - 2;
    while (mListView.getSelectedItemPosition() < secondToLastPos) {
        sendKeys(KeyEvent.KEYCODE_DPAD_DOWN);
    }
    assertEquals("selected position", secondToLastPos, mListView.getSelectedItemPosition());
    final View secondToLast = mListView.getSelectedView();
    final Rect rect = new Rect();
    secondToLast.getDrawingRect(rect);
    rect.offset(0, 2 * (mListView.getBottom() - secondToLast.getTop()));
    final int secondToLastIndex = mListView.getChildCount() - 2;
    getActivity().requestRectangleOnScreen(secondToLastIndex, rect);
    getInstrumentation().waitForIdleSync();
    int listBottom = mListView.getHeight() - mListView.getPaddingBottom();
    assertEquals("bottom of last item should be at bottom of list", listBottom, mListView.getChildAt(mListView.getChildCount() - 1).getBottom());
}
Also used : Rect(android.graphics.Rect) View(android.view.View) ListView(android.widget.ListView) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 45 with Rect

use of android.graphics.Rect in project platform_frameworks_base by android.

the class NinePatchDrawable method getOutline.

@Override
public void getOutline(@NonNull Outline outline) {
    final Rect bounds = getBounds();
    if (bounds.isEmpty()) {
        return;
    }
    if (mNinePatchState != null && mOutlineInsets != null) {
        final NinePatch.InsetStruct insets = mNinePatchState.mNinePatch.getBitmap().getNinePatchInsets();
        if (insets != null) {
            outline.setRoundRect(bounds.left + mOutlineInsets.left, bounds.top + mOutlineInsets.top, bounds.right - mOutlineInsets.right, bounds.bottom - mOutlineInsets.bottom, mOutlineRadius);
            outline.setAlpha(insets.outlineAlpha * (getAlpha() / 255.0f));
            return;
        }
    }
    super.getOutline(outline);
}
Also used : Rect(android.graphics.Rect) NinePatch(android.graphics.NinePatch)

Aggregations

Rect (android.graphics.Rect)3850 Paint (android.graphics.Paint)794 View (android.view.View)541 Point (android.graphics.Point)472 Bitmap (android.graphics.Bitmap)336 Canvas (android.graphics.Canvas)257 Drawable (android.graphics.drawable.Drawable)204 RectF (android.graphics.RectF)178 Resources (android.content.res.Resources)101 Matrix (android.graphics.Matrix)99 SmallTest (android.test.suitebuilder.annotation.SmallTest)94 TextPaint (android.text.TextPaint)94 ArrayList (java.util.ArrayList)94 RemoteException (android.os.RemoteException)93 ViewGroup (android.view.ViewGroup)92 TextView (android.widget.TextView)92 AccessibilityNodeInfo (android.view.accessibility.AccessibilityNodeInfo)84 BitmapDrawable (android.graphics.drawable.BitmapDrawable)83 SuppressLint (android.annotation.SuppressLint)78 ImageView (android.widget.ImageView)71