Android Drawable - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android Drawable class.

This code example shows how to use the following methods:getIntrinsicHeight, getIntrinsicWidth, setBounds
 
    final int width = bounds.width();
    final int height = bounds.height();
    final float ratio = (float) width / height;
 
    final int drawableWidth = drawable.getIntrinsicWidth();
    final int drawableHeight = drawable.getIntrinsicHeight();
    final float drawableRatio = (float) drawableWidth / drawableHeight;
 
    if (drawableRatio < ratio) {
      final float scale = (float) height / drawableHeight;
      final int scaledDrawableWidth = (int) (drawableWidth * scale);
      final int drawableLeft = bounds.left - (scaledDrawableWidth - width) / 2;
      final int drawableRight = drawableLeft + scaledDrawableWidth;
      drawable.setBounds(drawableLeft, bounds.top, drawableRight, bounds.bottom);
    } else { 
      final float scale = (float) width / drawableWidth;
      final int scaledDrawableHeight = (int) (drawableHeight * scale);
      final int drawableTop = bounds.top - (scaledDrawableHeight - height) / 2;
      final int drawableBottom = drawableTop + scaledDrawableHeight;

9
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:draw, getBounds, getIntrinsicHeight, getIntrinsicWidth, setBounds
            Bitmap bitmap = bitmapDrawable.getBitmap();
            if (bitmap.getDensity() == Bitmap.DENSITY_NONE) {
                bitmapDrawable.setTargetDensity(mDisplayMetrics);
            } 
        } 
        int sourceWidth = icon.getIntrinsicWidth();
        int sourceHeight = icon.getIntrinsicHeight();
 
        if (sourceWidth > 0 && sourceHeight > 0) {
            // There are intrinsic sizes. 
            if (width < sourceWidth || height < sourceHeight) {
                // It's too big, scale it down. 
                final float ratio = (float) sourceWidth / sourceHeight;
                if (sourceWidth > sourceHeight) {
                    height = (int) (width / ratio);
                } else if (sourceHeight > sourceWidth) {
                    width = (int) (height * ratio);
                } 
            } else if (sourceWidth < width && sourceHeight < height) {
                // It's small, use the size they gave us. 

9
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getIntrinsicHeight, getIntrinsicWidth
        if (divider == mDivider) {
            return; 
        } 
        mDivider = divider;
        if (divider != null) {
            mDividerWidth = divider.getIntrinsicWidth();
            mDividerHeight = divider.getIntrinsicHeight();
        } else { 
            mDividerWidth = 0;
            mDividerHeight = 0;
        } 
        setWillNotDraw(divider == null);
        requestLayout();
    } 
 
    @Override 
    protected void measureChildWithMargins(View child, int parentWidthMeasureSpec, int widthUsed, int parentHeightMeasureSpec, int heightUsed) {
        final int index = indexOfChild(child);
        final int orientation = getOrientation();
        final LayoutParams params = (LayoutParams) child.getLayoutParams();
9
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getIntrinsicHeight, getIntrinsicWidth, getPaint, setBounds
 
    public DrawableHolder(BitmapDrawable drawable, float x, float y) {
        mDrawable = drawable;
        mX = x;
        mY = y;
        mDrawable.getPaint().setAntiAlias(true); // Force AA
        mDrawable.setBounds(0, 0, mDrawable.getIntrinsicWidth(), mDrawable.getIntrinsicHeight());
    } 
 
    /** 
     * 
     * Adds an animation that interpolates given property from its current value 
     * to the given value. 
     * 
     * @param duration the duration, in ms. 
     * @param delay the delay to start the animation, in ms. 
     * @param property the property to animate 
     * @param toValue the target value 
     * @param replace if true, replace the current animation with this one. 
     */ 
8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:draw, setAlpha, setBounds
 
	@Override 
	public void draw(Canvas canvas)
	{ 
		if (background != null) {
			background.setBounds((int) innerRect.left, (int) innerRect.top, (int) innerRect.right, (int) innerRect.bottom);
		} 
 
		canvas.save();
 
		if (background != null) {
			if (alpha > NOT_SET) {
				background.setAlpha(alpha);
			} 
			background.draw(canvas);
		} 
 
		canvas.restore();
	} 
 
8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:draw, getIntrinsicHeight, getIntrinsicWidth, setBounds, setState
	@Override 
	protected void onDraw(Canvas canvas) {
		super.onDraw(canvas);
 
		if (image != null) {
			image.setState(getDrawableState());
 
			// scale image to fit inside button 
 
			int imgHeight = image.getIntrinsicHeight();
			int imgWidth = image.getIntrinsicWidth();
			int btnWidth = getWidth();
			int btnHeight = getHeight();
			float scale;
 
			if (imgWidth <= btnWidth && imgHeight <= btnHeight) {
                scale = 1.0f;
            } else { 
                scale = Math.min((float) btnWidth / (float) imgWidth,
                        (float) btnHeight / (float) imgHeight);

8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:draw, getBounds, getIntrinsicHeight, getIntrinsicWidth, getOpacity
            Bitmap bitmap = bitmapDrawable.getBitmap();
            if (bitmap.getDensity() == Bitmap.DENSITY_NONE) {
                bitmapDrawable.setTargetDensity(context.getResources().getDisplayMetrics());
            } 
        } 
        int iconWidth = icon.getIntrinsicWidth();
        int iconHeight = icon.getIntrinsicHeight();
 
        if (width > 0 && height > 0) {
            if (width < iconWidth || height < iconHeight || scale != 1.0f) {
                final float ratio = (float) iconWidth / iconHeight;
 
                if (iconWidth > iconHeight) {
                    height = (int) (width / ratio);
                } else if (iconHeight > iconWidth) {
                    width = (int) (height * ratio);
                } 
 
                final Bitmap.Config c = icon.getOpacity() != PixelFormat.OPAQUE ?
                            Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565;

8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:draw, getIntrinsicHeight, getIntrinsicWidth, setBounds
            final int h = getHeight();
 
            frameBounds.set(0, 0, w, h);
            mFrame.setBounds(frameBounds);
            if (mOverlay != null) {
                mOverlay.setBounds(w - mOverlay.getIntrinsicWidth(),
                        h - mOverlay.getIntrinsicHeight(), w, h);
            } 
        } 
 
        mFrame.draw(canvas);
        if (mOverlay != null) {
            mOverlay.draw(canvas);
        } 
    } 
 
 
    @Override 
    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
        super.onSizeChanged(w, h, oldw, oldh);
8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getIntrinsicHeight, getIntrinsicWidth, setBounds
        mPaint.setAntiAlias(true);
        mPaint.setDither(true);
 
        mDrawable = drawable;
        if (mDrawable != null) {
            drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
        } 
    } 
 
    public void setCenter(float x, float y) {
        mCenterX = x;
        mCenterY = y;
    } 
 
    public void makePointCloud(float innerRadius, float outerRadius) {
        if (innerRadius == 0) {
            Log.w(TAG, "Must specify an inner radius");
            return; 
        } 
        mOuterRadius = outerRadius;
8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:restore, restoreToCount, save, scale, translate
8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java

Related Android Drawable Questions & Answers:

Other Android Drawable Examples

45:	
46:	  class MyDragListener implements OnDragListener {
47:	    Drawable enterShape = getResources().getDrawable(R.drawable.shape_droptarget);
48:	    Drawable normalShape = getResources().getDrawable(R.drawable.shape);
49:	
-
46:	  class MyDragListener implements OnDragListener {
47:	    Drawable enterShape = getResources().getDrawable(R.drawable.shape_droptarget);
48:	    Drawable normalShape = getResources().getDrawable(R.drawable.shape);
49:	
50:	    @Override

Read More

15:		   private Context context;
16:		   
17:		   public AddItemizedOverlay(Drawable defaultMarker) {
18:		        super(boundCenterBottom(defaultMarker));
19:		   }
-
19:		   }
20:		   
21:		   public AddItemizedOverlay(Drawable defaultMarker, Context context) {
22:		        this(defaultMarker);
23:		        this.context = context;

Read More

1:	Drawable drawable = this.getResources().getDrawable(R.drawable.mark_red);
2:	AddItemizedOverlay itemizedOverlay = 
3:	new AddItemizedOverlay(drawable, this);

Read More

22:	       private Context context;
23:	 
24:	       public AddItemizedOverlay(Drawable defaultMarker) {
25:	            super(boundCenterBottom(defaultMarker));
26:	       }
-
26:	       }
27:	 
28:	       public AddItemizedOverlay(Drawable defaultMarker, Context context) {
29:	            this(defaultMarker);
30:	            this.context = context;

Read More

See Code Examples for Android Drawable Methods: