/** * This is a wrapper on top of built in {@link Drawable#getPadding(Rect)} which overrides * default return value. The reason why we need this - is because on pre-L devices LayerDrawable * always returns "true" even if drawable doesn't have padding (see https://goo.gl/gExcMQ). * Since we heavily rely on correctness of this information, we need to check padding manually */ private static boolean getDrawablePadding(Drawable drawable, Rect outRect) { drawable.getPadding(outRect); return outRect.bottom != 0 || outRect.top != 0 || outRect.left != 0 || outRect.right != 0; }
@Override public boolean getPadding(Rect padding) { return mDrawable != null && mDrawable.getPadding(padding); }
@Override public boolean getPadding(@NonNull Rect padding) { return wrapped.getPadding(padding); }
@Override public boolean getPadding(Rect padding) { return mDrawable.getPadding(padding); }
@Override public boolean getPadding(Rect padding) { return mDrawable.getPadding(padding); }
@Override public boolean getPadding(Rect padding) { return mMask.getPadding(padding); } }
/** * Refreshes the cached padding values for the specified child. * * @return true if the child's padding has changed */ private boolean refreshChildPadding(int i, ChildDrawable r) { if (r.mDrawable != null) { final Rect rect = mTmpRect; r.mDrawable.getPadding(rect); if (rect.left != mPaddingL[i] || rect.top != mPaddingT[i] || rect.right != mPaddingR[i] || rect.bottom != mPaddingB[i]) { mPaddingL[i] = rect.left; mPaddingT[i] = rect.top; mPaddingR[i] = rect.right; mPaddingB[i] = rect.bottom; return true; } } return false; }
@Override public boolean getPadding(Rect padding) { boolean hasPadding = mDrawable != null && mDrawable.getPadding(padding); if(hasPadding){ padding.left += mPaddingLeft; padding.top += mPaddingTop; padding.right += mPaddingRight; padding.bottom += mPaddingBottom; } else{ padding.set(mPaddingLeft, mPaddingTop, mPaddingRight, mPaddingBottom); hasPadding = mPaddingLeft != 0 || mPaddingTop != 0 || mPaddingRight != 0 || mPaddingBottom != 0; } return hasPadding; }
public boolean getPadding(@NonNull Rect padding) { return this.mDrawable.getPadding(padding); }
@Override public void setSelector(Drawable sel) { mSelector = sel != null ? new GateKeeperDrawable(sel) : null; super.setSelector(mSelector); final Rect padding = new Rect(); if (sel != null) { sel.getPadding(padding); } mSelectionLeftPadding = padding.left; mSelectionTopPadding = padding.top; mSelectionRightPadding = padding.right; mSelectionBottomPadding = padding.bottom; } @Override
@Override public boolean getPadding(@NonNull Rect padding) { final Rect r = mDrawableContainerState.getConstantPadding(); boolean result; if (r != null) { padding.set(r); result = (r.left | r.top | r.bottom | r.right) != 0; } else { if (mCurrDrawable != null) { result = mCurrDrawable.getPadding(padding); } else { result = super.getPadding(padding); } } if (needsMirroring()) { final int left = padding.left; final int right = padding.right; padding.left = right; padding.right = left; } return result; }
/** * @return The constant padding */ public final Rect getConstantPadding() { if (mVariablePadding) { return null; } if ((mConstantPadding != null) || mCheckedPadding) { return mConstantPadding; } createAllFutures(); Rect r = null; final Rect t = new Rect(); final int count = mNumChildren; final Drawable[] drawables = mDrawables; for (int i = 0; i < count; i++) { if (drawables[i].getPadding(t)) { if (r == null) r = new Rect(0, 0, 0, 0); if (t.left > r.left) r.left = t.left; if (t.top > r.top) r.top = t.top; if (t.right > r.right) r.right = t.right; if (t.bottom > r.bottom) r.bottom = t.bottom; } } mCheckedPadding = true; return (mConstantPadding = r); }
/** * Sets the width of the popup window by the size of its content. The final width may be * larger to accommodate styled window dressing. * * @param width Desired width of content in pixels. */ public void setContentWidth(int width) { Drawable popupBackground = mPopup.getBackground(); if (popupBackground != null) { popupBackground.getPadding(mTempRect); mDropDownWidth = mTempRect.left + mTempRect.right + width; } else { setWidth(width); } }
background.getPadding(mTempRect); width += mTempRect.left + mTempRect.right;
/** * Set the background to a given Drawable, or remove the background. * * @param background the Drawable to use as the background, or null to remove the background. */ @SuppressWarnings("deprecation") // View#setBackgroundDrawable is compatible with pre-API level 16 (Jelly Bean). public void setBackground(Drawable background) { mContainer.setBackgroundDrawable(background); // Force setting of padding. // setBackgroundDrawable does not call setPadding if the background has 0 padding. if (background != null) { Rect rect = new Rect(); background.getPadding(rect); mContainer.setPadding(rect.left, rect.top, rect.right, rect.bottom); } else { mContainer.setPadding(0, 0, 0, 0); } }
public void setSelector(Drawable sel) { if (mSelector != null) { mSelector.setCallback(null); unscheduleDrawable(mSelector); } mSelector = sel; Rect padding = new Rect(); sel.getPadding(padding); mSelectionLeftPadding = padding.left; mSelectionTopPadding = padding.top; mSelectionRightPadding = padding.right; mSelectionBottomPadding = padding.bottom; sel.setCallback(this); sel.setState(getDrawableState()); }
@Override public void onGlobalLayout() { ListView lv = mReplacementPopup.getListView(); ViewTreeObserver observer = lv.getViewTreeObserver(); if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) observer.removeOnGlobalLayoutListener(this); else observer.removeGlobalOnLayoutListener(this); View v = lv.getChildAt(0); v.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); mReplacementPopup.setContentWidth(v.getMeasuredWidth()); int[] popupLocation = new int[2]; lv.getLocationOnScreen(popupLocation); int[] inputLocation = new int[2]; mInputView.getLocationOnScreen(inputLocation); Drawable background = mReplacementPopup.getPopup().getBackground(); Rect backgroundPadding = new Rect(); int verticalOffset; int horizontalOffset = inputLocation[0] + (int)mSelectedSpan.mX - (popupLocation[0] + backgroundPadding.left); if(background != null) background.getPadding(backgroundPadding); if(inputLocation[1] < popupLocation[1]) //popup show at bottom verticalOffset = inputLocation[1] + mSelectedSpan.mY - (popupLocation[1] + backgroundPadding.top); else verticalOffset = inputLocation[1] + mSelectedSpan.mY + mSpanHeight - (popupLocation[1] + lv.getHeight() - backgroundPadding.bottom); mReplacementPopup.setVerticalOffset(verticalOffset); mReplacementPopup.setHorizontalOffset(horizontalOffset); mReplacementPopup.show(); } });
int hOffset = 0; if (background != null) { background.getPadding(mTempRect); hOffset = mIsRtl ? mTempRect.right : -mTempRect.left; } else
if (background == null || !background.getPadding(sBackgroundPaddingRect)) { editText.setPadding(0, 0, 0, 0);
if (background != null) { Rect rect = new Rect(); background.getPadding(rect); Reference.release(c.getAndroidContext(), background, backgroundRef);