Java Code Examples for android.graphics.drawable.Drawable#getMinimumWidth()

The following examples show how to use android.graphics.drawable.Drawable#getMinimumWidth() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SelectDrawableAdapter.java    From LoopBanner with Apache License 2.0 6 votes vote down vote up
private LinearLayout.LayoutParams generateLayoutParams(Drawable drawable, int size, int margin) {
    if (mLayoutParams == null) {
        final int minimumWidth = drawable.getMinimumWidth();
        final int minimumHeight = drawable.getMinimumHeight();
        LinearLayout.LayoutParams layoutParams;
        if (minimumWidth == 0 || minimumHeight == 0) {
            layoutParams = new LinearLayout.LayoutParams(size, size);
        } else {
            layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
                    LinearLayout.LayoutParams.WRAP_CONTENT);
        }
        layoutParams.leftMargin = margin;
        mLayoutParams = layoutParams;
    }
    return mLayoutParams;
}
 
Example 2
Source File: DrawableContainerCompat.java    From MaterialProgressBar with Apache License 2.0 6 votes vote down vote up
protected void computeConstantSize() {
    mCheckedConstantSize = true;
    createAllFutures();
    final int count = mNumChildren;
    final Drawable[] drawables = mDrawables;
    mConstantWidth = mConstantHeight = -1;
    mConstantMinimumWidth = mConstantMinimumHeight = 0;
    for (int i = 0; i < count; i++) {
        final Drawable dr = drawables[i];
        int s = dr.getIntrinsicWidth();
        if (s > mConstantWidth) mConstantWidth = s;
        s = dr.getIntrinsicHeight();
        if (s > mConstantHeight) mConstantHeight = s;
        s = dr.getMinimumWidth();
        if (s > mConstantMinimumWidth) mConstantMinimumWidth = s;
        s = dr.getMinimumHeight();
        if (s > mConstantMinimumHeight) mConstantMinimumHeight = s;
    }
}
 
Example 3
Source File: CustomPullDownRefreshListView.java    From NewXmPluginSDK with Apache License 2.0 6 votes vote down vote up
public void setHeaderBackground(Drawable drawable) {
    if (mBkgImgView != null) {
        mBkgImgView.setImageDrawable(drawable);
        int width = drawable.getMinimumWidth();
        int height = drawable.getMinimumHeight();
        if (width <= 0) {
            return;
        }
        DisplayMetrics dm = new DisplayMetrics();
        ((Activity) getContext()).getWindowManager().getDefaultDisplay().getMetrics(dm);
        int viewHeight = (height * dm.widthPixels) / width;
        ViewGroup.LayoutParams lp = mBkgImgView.getLayoutParams();
        lp.height = viewHeight;
        mMaxHeaderHeight = viewHeight;
        mBkgImgView.setLayoutParams(lp);
    }
}
 
Example 4
Source File: HListView.java    From Klyph with MIT License 6 votes vote down vote up
void drawOverscrollFooter( Canvas canvas, Drawable drawable, Rect bounds ) {
	final int width = drawable.getMinimumWidth();

	canvas.save();
	canvas.clipRect( bounds );

	final int span = bounds.right - bounds.left;
	if ( span < width ) {
		bounds.right = bounds.left + width;
	}

	drawable.setBounds( bounds );
	drawable.draw( canvas );

	canvas.restore();
}
 
Example 5
Source File: GestureImageView.java    From ViewPagerTabIndicator with Artistic License 2.0 6 votes vote down vote up
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    int width = MeasureSpec.getSize(widthMeasureSpec);
    int height = MeasureSpec.getSize(heightMeasureSpec);
    viewSize = new PointF(width, height);

    //��ȡ��ǰDrawable�Ĵ�С
    Drawable drawable = getDrawable();
    if (drawable == null) {
        Log.e("no drawable", "drawable is nullPtr");
    } else {
        imageSize = new PointF(drawable.getMinimumWidth(), drawable.getMinimumHeight());
    }

    FitCenter();
}
 
Example 6
Source File: PXButtonDrawable.java    From pixate-freestyle-android with Apache License 2.0 6 votes vote down vote up
/**
 * Set tint color on a given {@link Button}. This method will set an
 * instance of this {@link PXButtonDrawable} as the {@link Button}s
 * background drawable.
 * 
 * @param button A {@link Button}. In case the button does not have a
 *            {@link PXButtonDrawable} as a background, this method will
 *            attach one and theme it.
 * @param color
 */
@SuppressWarnings("deprecation")
public static void setTintColor(Button button, int color) {
    Drawable drawable = button.getBackground();
    if (drawable instanceof PXButtonDrawable) {
        setTintColor(button, (PXButtonDrawable) drawable, color);
    } else {
        Drawable prevDrawable = button.getBackground();
        PXButtonDrawable pxDrawable;
        if (prevDrawable != null) {
            pxDrawable = new PXButtonDrawable(prevDrawable.getMinimumHeight(),
                    prevDrawable.getMinimumWidth());
        } else {
            // TODO: API 16 supports getMinimunHeight and getMinimumWidth
            pxDrawable = new PXButtonDrawable(button.getHeight(), button.getWidth());
        }
        button.setBackgroundDrawable(pxDrawable);
        setTintColor(button, pxDrawable, color);
    }
}
 
Example 7
Source File: HListView.java    From Klyph with MIT License 6 votes vote down vote up
void drawOverscrollHeader( Canvas canvas, Drawable drawable, Rect bounds ) {
	final int width = drawable.getMinimumWidth();

	canvas.save();
	canvas.clipRect( bounds );

	final int span = bounds.right - bounds.left;
	if ( span < width ) {
		bounds.left = bounds.right - width;
	}

	drawable.setBounds( bounds );
	drawable.draw( canvas );

	canvas.restore();
}
 
Example 8
Source File: GAccount.java    From GoogleNavigationDrawer with Apache License 2.0 5 votes vote down vote up
private Bitmap convertToBitmap(Drawable drawable) {
    Bitmap mutableBitmap;
    if(drawable.getMinimumHeight() == 0 || drawable.getMinimumWidth() == 0)
        mutableBitmap = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
    else
        mutableBitmap = Bitmap.createBitmap(drawable.getMinimumWidth(), drawable.getMinimumHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(mutableBitmap);
    drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
    drawable.draw(canvas);

    return mutableBitmap;
}
 
Example 9
Source File: GridDrawable.java    From ProjectX with Apache License 2.0 5 votes vote down vote up
@Override
public int getMinimumWidth() {
    if (mColumnCount <= 0)
        return -1;
    final Drawable drawable = getWrappedDrawable();
    if (drawable == null)
        return -1;
    final int itemWidth = drawable.getMinimumWidth();
    return Math.round(mColumnCount * itemWidth + mHorizontalSpacing * (mColumnCount - 1));
}
 
Example 10
Source File: XulCommonDrawable.java    From starcor.xul with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public int getWidth() {
	Drawable drawable = _drawable;
	if (drawable == null) {
		return 0;
	}
	return drawable.getMinimumWidth();
}
 
Example 11
Source File: PreventFragment.java    From prevent with Do What The F*ck You Want To Public License 5 votes vote down vote up
private void setHeaderIcon(ContextMenu menu, Drawable icon) {
    int width = getHeaderIconWidth();
    if (icon.getMinimumWidth() <= width) {
        menu.setHeaderIcon(icon);
    } else if (icon instanceof BitmapDrawable) {
        Bitmap bitmap = Bitmap.createScaledBitmap(((BitmapDrawable) icon).getBitmap(), width, width, false);
        menu.setHeaderIcon(new BitmapDrawable(getResources(), bitmap));
    }
}
 
Example 12
Source File: HListView.java    From letv with Apache License 2.0 5 votes vote down vote up
void drawOverscrollFooter(Canvas canvas, Drawable drawable, Rect bounds) {
    int width = drawable.getMinimumWidth();
    canvas.save();
    canvas.clipRect(bounds);
    if (bounds.right - bounds.left < width) {
        bounds.right = bounds.left + width;
    }
    drawable.setBounds(bounds);
    drawable.draw(canvas);
    canvas.restore();
}
 
Example 13
Source File: HListView.java    From letv with Apache License 2.0 5 votes vote down vote up
void drawOverscrollHeader(Canvas canvas, Drawable drawable, Rect bounds) {
    int width = drawable.getMinimumWidth();
    canvas.save();
    canvas.clipRect(bounds);
    if (bounds.right - bounds.left < width) {
        bounds.left = bounds.right - width;
    }
    drawable.setBounds(bounds);
    drawable.draw(canvas);
    canvas.restore();
}
 
Example 14
Source File: FlexboxHelper.java    From Collection-Android with MIT License 5 votes vote down vote up
/**
 * Compound buttons (ex. {{@link android.widget.CheckBox}}, {@link android.widget.ToggleButton})
 * have a button drawable with minimum height and width specified for them.
 * To align the behavior with CSS Flexbox we want to respect these minimum measurement to avoid
 * these drawables from being cut off during calculation. When the compound button has a minimum
 * width or height already specified we will not make any change since we assume those were
 * voluntarily set by the user.
 *
 * @param compoundButton the compound button that need to be evaluated
 */
private void evaluateMinimumSizeForCompoundButton(CompoundButton compoundButton) {
    FlexItem flexItem = (FlexItem) compoundButton.getLayoutParams();
    int minWidth = flexItem.getMinWidth();
    int minHeight = flexItem.getMinHeight();

    Drawable drawable = CompoundButtonCompat.getButtonDrawable(compoundButton);
    int drawableMinWidth = drawable == null ? 0 : drawable.getMinimumWidth();
    int drawableMinHeight = drawable == null ? 0 : drawable.getMinimumHeight();
    flexItem.setMinWidth(minWidth == NOT_SET ? drawableMinWidth : minWidth);
    flexItem.setMinHeight(minHeight == NOT_SET ? drawableMinHeight : minHeight);
}
 
Example 15
Source File: LockscreenAppBar.java    From GravityBox with Apache License 2.0 4 votes vote down vote up
private Drawable createBadgeDrawable(Drawable d, int count) {
    if (d == null) return null;

    NumberFormat f = NumberFormat.getIntegerInstance();
    String countStr = count > 99 ? "99+" : f.format(count);

    Bitmap b = Utils.drawableToBitmap(d);
    b = b.copy(Bitmap.Config.ARGB_8888, true);
    Canvas c = new Canvas(b);

    Paint p = new Paint();
    p.setTextAlign(Paint.Align.CENTER);
    p.setColor(Color.WHITE);
    p.setAntiAlias(true);
    p.setTextSize(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 10,
            mResources.getDisplayMetrics()));

    Drawable bg = mGbResources.getDrawable(R.drawable.ic_notification_overlay, null);

    final int w = b.getWidth();
    final int h = b.getHeight();
    final Rect r = new Rect();
    p.getTextBounds(countStr, 0, countStr.length(), r);
    final int tw = r.right - r.left;
    final int th = r.bottom - r.top;
    bg.getPadding(r);
    int dw = r.left + tw + r.right;
    if (dw < bg.getMinimumWidth()) {
        dw = bg.getMinimumWidth();
    }
    int x = w-r.right-((dw-r.right-r.left)/2);
    int dh = r.top + th + r.bottom;
    if (dh < bg.getMinimumHeight()) {
        dh = bg.getMinimumHeight();
    }
    if (dw < dh) dw = dh;
    int y = h-r.bottom-((dh-r.top-th-r.bottom)/2);
    bg.setBounds(w-dw, h-dh, w, h);

    bg.draw(c);
    c.drawText(countStr, x, y, p);

    return new BitmapDrawable(mResources, b);
}
 
Example 16
Source File: PreviewTimeBar.java    From PreviewSeekBar with Apache License 2.0 4 votes vote down vote up
public PreviewTimeBar(Context context, AttributeSet attrs) {
    super(context, attrs);
    TypedArray typedArray = context.getTheme().obtainStyledAttributes(attrs,
            com.google.android.exoplayer2.ui.R.styleable.DefaultTimeBar, 0, 0);
    scrubberColor = typedArray.getInt(
            com.google.android.exoplayer2.ui.R.styleable.DefaultTimeBar_scrubber_color,
            DEFAULT_SCRUBBER_COLOR);

    final Drawable scrubberDrawable = typedArray.getDrawable(
            com.google.android.exoplayer2.ui.R.styleable.DefaultTimeBar_scrubber_drawable);

    final int scrubberEnabledSize = typedArray.getDimensionPixelSize(
            com.google.android.exoplayer2.ui.R.styleable.DefaultTimeBar_scrubber_enabled_size,
            dpToPx(context.getResources().getDisplayMetrics(),
                    DEFAULT_SCRUBBER_ENABLED_SIZE_DP));

    final int scrubberDisabledSize = typedArray.getDimensionPixelSize(
            com.google.android.exoplayer2.ui.R.styleable.DefaultTimeBar_scrubber_disabled_size,
            dpToPx(context.getResources().getDisplayMetrics(),
                    DEFAULT_SCRUBBER_DISABLED_SIZE_DP));

    final int scrubberDraggedSize = typedArray.getDimensionPixelSize(
            com.google.android.exoplayer2.ui.R.styleable.DefaultTimeBar_scrubber_dragged_size,
            dpToPx(context.getResources().getDisplayMetrics(),
                    DEFAULT_SCRUBBER_DRAGGED_SIZE_DP));

    // Calculate the scrubber padding based on the maximum size the scrubber can have
    if (scrubberDrawable != null) {
        scrubberPadding = (scrubberDrawable.getMinimumWidth() + 1) / 2;
    } else {
        scrubberPadding =
                (Math.max(scrubberDisabledSize,
                        Math.max(scrubberEnabledSize, scrubberDraggedSize)) + 1) / 2;
    }

    typedArray.recycle();

    typedArray = context.getTheme().obtainStyledAttributes(
            attrs, R.styleable.PreviewTimeBar, 0, 0);

    previewId = typedArray.getResourceId(
            R.styleable.PreviewTimeBar_previewFrameLayout, View.NO_ID);

    delegate = new PreviewDelegate(this);
    delegate.setPreviewEnabled(isEnabled());
    delegate.setAnimationEnabled(typedArray.getBoolean(
            R.styleable.PreviewTimeBar_previewAnimationEnabled, true));
    delegate.setPreviewEnabled(typedArray.getBoolean(
            R.styleable.PreviewTimeBar_previewEnabled, true));
    delegate.setAutoHidePreview(typedArray.getBoolean(
            R.styleable.PreviewTimeBar_previewAutoHide, true));

    typedArray.recycle();

    addListener(new TimeBarDefaultOnScrubListener());
}
 
Example 17
Source File: PhotoView.java    From SprintNBA with Apache License 2.0 4 votes vote down vote up
private static int getDrawableWidth(Drawable d) {
    int width = d.getIntrinsicWidth();
    if (width <= 0) width = d.getMinimumWidth();
    if (width <= 0) width = d.getBounds().width();
    return width;
}
 
Example 18
Source File: CropImageView.java    From YImagePicker with Apache License 2.0 4 votes vote down vote up
private boolean hasSize(Drawable d) {
    return (d.getIntrinsicHeight() > 0 && d.getIntrinsicWidth() > 0)
            || (d.getMinimumWidth() > 0 && d.getMinimumHeight() > 0)
            || (d.getBounds().width() > 0 && d.getBounds().height() > 0);
}
 
Example 19
Source File: CropImageView.java    From YImagePicker with Apache License 2.0 4 votes vote down vote up
private static int getDrawableWidth(Drawable d) {
    int width = d.getIntrinsicWidth();
    if (width <= 0) width = d.getMinimumWidth();
    if (width <= 0) width = d.getBounds().width();
    return width;
}
 
Example 20
Source File: CropImageView.java    From YImagePicker with Apache License 2.0 4 votes vote down vote up
private boolean hasSize(Drawable d) {
    return (d.getIntrinsicHeight() > 0 && d.getIntrinsicWidth() > 0)
            || (d.getMinimumWidth() > 0 && d.getMinimumHeight() > 0)
            || (d.getBounds().width() > 0 && d.getBounds().height() > 0);
}