@Override protected void onLayout(boolean changed, int l, int t, int r, int b) { View view = resolveView(); if (view != null) { int width = getMeasuredWidth(); int height = getMeasuredHeight(); @Px int leftLineWidth = leftBorder == BorderMode.LINE ? 1 : leftPageBorder.getIntrinsicWidth(); @Px int rightLineWidth = rightBorder == BorderMode.HIDDEN ? 0 : rightPageBorder.getIntrinsicWidth(); int headerFooterHeight = 0; view.layout(leftLineWidth, headerFooterHeight, width - rightLineWidth, height - headerFooterHeight); super.onLayout(changed, l, t, r, b); } }
@Override public void scrollTo(@Px int x, @Px int y) { if (y < mMinPosition) { goStartEdgeEffect(y); y = mMinPosition; } if (y > mMaxPosition) { goEndEdgeEffect(y); y = mMaxPosition; } if (y != getScrollY()) { super.scrollTo(x, y); } mCurrentScale = scrollYtoScale(y); if (mRulerCallback != null) { mRulerCallback.onScaleChanging(Math.round(mCurrentScale)); } }
@Override public void scrollTo(@Px int x, @Px int y) { if (x < mMinPosition) { goStartEdgeEffect(x); x = mMinPosition; } if (x > mMaxPosition) { goEndEdgeEffect(x); x = mMaxPosition; } if (x != getScrollX()) { super.scrollTo(x, y); } mCurrentScale = scrollXtoScale(x); if (mRulerCallback != null) { mRulerCallback.onScaleChanging(Math.round(mCurrentScale)); } }
/** * Resize the image to the specified size in pixels. * Use 0 as desired dimension to resize keeping aspect ratio. */ public Builder resize(@Px int targetWidth, @Px int targetHeight) { if (targetWidth < 0) { throw new IllegalArgumentException("Width must be positive number or 0."); } if (targetHeight < 0) { throw new IllegalArgumentException("Height must be positive number or 0."); } if (targetHeight == 0 && targetWidth == 0) { throw new IllegalArgumentException("At least one dimension has to be positive number."); } this.targetWidth = targetWidth; this.targetHeight = targetHeight; return this; }
/** * Sets the radius of the progress arc. * * @param radius The desired radius. * @see #getProgressRadius() */ public void setProgressRadius(@Px int radius) { if (mProgressRadius != radius) { this.mProgressRadius = radius; this.handleDrawablesSizeChange(); } }
/** * @param value The elevation (in px) with which the toolbar starts * @return Own object */ public WaterfallToolbar setInitialElevationPx(@Px @NonNull final Integer value) { mInitialElevation = value; // gotta update elevation in case this value have // been set in a running and visible activity if (mIsSetup) adjustCardElevation(); return this; }
/** * @param value The elevation (in px) the toolbar gets when it reaches final scroll elevation * @return Own object */ public WaterfallToolbar setFinalElevationPx(@Px @NonNull final Integer value) { mFinalElevation = value; // gotta update elevation in case this value have // been set in a running and visible activity if (mIsSetup) adjustCardElevation(); return this; }
/** * Sets the top and bottom padding to the given View, keeping the horizontal padding values as the were. * * @param view Which view to set the padding to, must not be {@code null} * @param padding The vertical padding value */ public static void setPaddingVertical(@NonNull final View view, @Px final int padding) { final int paddingStart = Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 ? view.getPaddingStart() : view.getPaddingLeft(); final int paddingEnd = Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 ? view.getPaddingEnd() : view.getPaddingRight(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { view.setPaddingRelative(paddingStart, padding, paddingEnd, padding); } else { view.setPadding(paddingStart, padding, paddingEnd, padding); } }
/** * Sets the left/start and right/end padding to the given View, keeping the vertical padding values as the were. * * @param view Which view to set the padding to, must not be {@code null} * @param padding The horizontal padding value */ public static void setPaddingHorizontal(@NonNull final View view, @Px final int padding) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { view.setPaddingRelative(padding, view.getPaddingTop(), padding, view.getPaddingBottom()); } else { view.setPadding(padding, view.getPaddingTop(), padding, view.getPaddingBottom()); } }
/** * Converts a {@link Drawable} into a {@link Bitmap}. Includes an optimization in case the {@link Drawable} in question is already a * {@link BitmapDrawable}. * * @param drawable A Drawable instance to convert * @param width The width of the new Bitmap * @param height The height of the new Bitmap * @return A new {@link Bitmap} instance constraint to width and height dimensions supplied, never {@code null} */ @NonNull @SuppressWarnings("unused") public static Bitmap drawableToBitmap(@NonNull final Drawable drawable, @Px final int width, @Px final int height) { final Bitmap result = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); final Canvas canvas = new Canvas(result); drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); drawable.draw(canvas); return result; }
@Override public void setPadding(@Px int left, @Px int top, @Px int right, @Px int bottom) { if (mPager != null) { mPager.setPadding(left, top, right, bottom); } else { // Pass to ourselves. We will remove it in the constructor. super.setPadding(left, top, right, bottom); } }
@Override public void setPadding(@Px int left, @Px int top, @Px int right, @Px int bottom) { left += mShadowRadius; top += mShadowRadius; right += mShadowRadius; bottom += mShadowRadius; super.setPadding(left, top, right, bottom); }
@Override public void scrollTo(@Px int x, @Px int y) { int offset = Math.min(maxScrollY, edgeScroll ? y : Math.max(0, y)); boolean layout = false; if (getScrollY() != offset) { layout = true; } super.scrollTo(0, offset); if (layout) { requestLayout(); } if (mOnScrollListener != null) { mOnScrollListener.onScrollTo(offset); } }
@Override public void scrollTo(@Px int x, @Px int y) { int offset = Math.min(maxScrollY, Math.max(0, y)); boolean layout = false; if (getScrollY() != offset) { layout = true; } super.scrollTo(0, offset); if (layout) { requestLayout(); } if (mOnScrollListener != null) { mOnScrollListener.onScrollTo(offset); } }
@Px static int getDimension(Context context, TypedArray array, @StyleableRes int attr, @DimenRes int defaultDimenRes) { return array.getDimensionPixelOffset( attr, context.getResources().getDimensionPixelSize(defaultDimenRes)); }
@Override public void layout(@Px int l, @Px int t, @Px int r, @Px int b) { TEST_STATS.layoutStart(); for (int i = 0; i < Const.LOOP_COUNT; i++) { // TODO for test super.layout(l, t, r, b); } TEST_STATS.layoutEnd(); }
@Override public void scrollBy(@Px int x, @Px int y) { int targetY = getScrollY() + y; if (targetY >= mMaxScrollY) { targetY = mMaxScrollY; } else if (targetY <= 0) { targetY = 0; } super.scrollBy(x, targetY - getScrollY()); }
@Override public void scrollTo(@Px int x, @Px int y) { if (y >= mMaxScrollY) { y = mMaxScrollY; } else if (y <= 0) { y = 0; } if (mOnCollapsingListener != null) { float progress = 1.0f - (float) y / (float) mMaxScrollY; if (BuildConfig.DEBUG) Log.d(TAG, "collapsing progress = " + progress); mOnCollapsingListener.onCollapsing(progress); } mCurrentScrollY = y; super.scrollTo(x, y); }
/** * 设置文本大小,像素 * @param size 文本大小 */ public void setTextSize(@Px int size) { if(size <= 0) { return; } this.textSize = size; for(TextView tv : list) { tv.setTextSize(textSize); } }
@Override public void scrollTo(@Px int x, @Px int y) { if (maxShowLine > 0) { return; } super.scrollTo(x, y); }
@Contract(pure = true) @Px static int px(@Dimension(unit = Dimension.DP) int dp) { float dpi = Resources.getSystem().getDisplayMetrics().density; dpi = dpi > 100/*120, 160, 213, 240, 320, 480 or 640 dpi*/ ? dpi / 160f : dpi; dpi = dpi == 0 ? 1f : dpi; return (int) (dp * dpi); }
@Override public void scrollTo(@Px int x, @Px int y) { super.scrollTo(x, y); }
public void setTickStrokeWidth(@Px int strokeWidth) { mTickView.setStrokeWidth(strokeWidth); }
void setFrameThickness(@Px int thickness) { mFramePaint.setStrokeWidth(thickness); if (Utils.isLaidOut(this)) { invalidate(); } }
void setFrameCornersSize(@Px int size) { mFrameCornerSize = size; if (Utils.isLaidOut(this)) { invalidate(); } }
public static Node absoluteSize(@Px Integer size, Object... nodes) { return new SpanNode(new AbsoluteSizeSpan(size), nodes); }
public static Node absoluteSize(@Px Integer size, Boolean dip, Object... nodes) { return new SpanNode(new AbsoluteSizeSpan(size, dip), nodes); }
public static Node bullet(@Px Integer gapWidth, Object... nodes) { return new SpanNode(new BulletSpan(gapWidth), nodes); }
public static Node drawableMargin(Drawable drawable, @Px Integer padding, Object... nodes) { return new SpanNode(new DrawableMarginSpan(drawable, padding), nodes); }
public static Node iconMargin(Bitmap bitmap, @Px Integer padding, Object... nodes) { return new SpanNode(new IconMarginSpan(bitmap, padding), nodes); }
@TargetApi(Build.VERSION_CODES.LOLLIPOP) @Override public void setElevation(@Px float elevation) { super.setElevation(elevation); mRoundingElevation = elevation; }
/** * Invokes {@link SillyAndroid#setPadding(View, int, int, int, int)} with the same arguments. */ protected final void setPadding(@NonNull final View view, @Px final int start, @Px final int top, @Px final int end, @Px final int bottom) { SillyAndroid.setPadding(view, start, top, end, bottom); }
/** * Invokes the {@link SillyAndroid#setPaddingVertical(View, int)} with the same arguments. */ protected final void setPaddingVertical(@NonNull final View view, @Px final int padding) { SillyAndroid.setPaddingVertical(view, padding); }
/** * Invokes the {@link SillyAndroid#setPaddingHorizontal(View, int)} with the same arguments. */ protected final void setPaddingHorizontal(@NonNull final View view, @Px final int padding) { SillyAndroid.setPaddingHorizontal(view, padding); }
/** * Invokes {@link SillyAndroid#setPadding(View, int)} with the same arguments. */ protected final void setPadding(@NonNull final View view, @Px final int padding) { SillyAndroid.setPadding(view, padding); }