Android BitmapDrawable - 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 BitmapDrawable class.

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
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getIntrinsicHeight, getIntrinsicWidth, setTargetDensity
This code example shows how to use the following methods:draw, setAlpha
        if (placeholder != null) {
          placeholder.draw(canvas);
        } 
 
        int alpha = (int) (0xFF * normalized);
        image.setAlpha(alpha);
        image.draw(canvas);
        image.setAlpha(0xFF);
        invalidateSelf();
      } 
    } 
 
    if (debugging) {
      drawDebugIndicator(canvas);
    } 
  } 
 
  @Override public int getIntrinsicWidth() { 
    return image.getIntrinsicWidth();
  } 
8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:
 
  @Test 
  public void queryActivityIcons__Match() throws Exception { 
    Intent i = new Intent();
    i.setComponent(new ComponentName(TEST_PACKAGE_NAME, ""));
    Drawable d = new BitmapDrawable();
 
    rpm.addActivityIcon(i, d);
 
    assertThat(rpm.getActivityIcon(i)).isSameAs(d);
    assertThat(rpm.getActivityIcon(i.getComponent())).isSameAs(d);
  } 
 
  @Test 
  public void hasSystemFeature() throws Exception { 
    // uninitialized 
    assertThat(rpm.hasSystemFeature(PackageManager.FEATURE_CAMERA)).isFalse();
 
    // positive 
    rpm.setSystemFeature(PackageManager.FEATURE_CAMERA, true);
8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getIntrinsicHeight, getIntrinsicWidth
    } 
 
    @Test 
    public void constructor_shouldSetTheIntrinsicWidthAndHeightToTheWidthAndHeightOfTheBitmap() throws Exception { 
        Bitmap bitmap = Bitmap.createBitmap(5, 10, Bitmap.Config.ARGB_8888);
        BitmapDrawable drawable = new BitmapDrawable(Robolectric.application.getResources(), bitmap);
        assertEquals(5, drawable.getIntrinsicWidth());
        assertEquals(10, drawable.getIntrinsicHeight());
    } 
 
    @Test 
    public void constructor_shouldAcceptNullBitmap() throws Exception { 
        BitmapDrawable drawable = new BitmapDrawable(Robolectric.application.getResources(), (Bitmap) null);
        assertNotNull(drawable);
    } 
} 
8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:
    } 
 
    @Test 
    public void queryActivityIcons__Match() throws Exception { 
        Intent i = rpm.getLaunchIntentForPackage(TEST_PACKAGE_NAME);
        Drawable d = new BitmapDrawable();
 
        rpm.addActivityIcon(i, d);
 
        assertThat(rpm.getActivityIcon(i)).isSameAs(d);
        assertThat(rpm.getActivityIcon(i.getComponent())).isSameAs(d);
    } 
 
    @Test 
    public void hasSystemFeature() throws Exception { 
        // uninitialized 
        assertThat(rpm.hasSystemFeature(PackageManager.FEATURE_CAMERA)).isFalse();
 
        // positive 
        rpm.setSystemFeature(PackageManager.FEATURE_CAMERA, true);
8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:
		this.background = new PaintDrawable(backgroundColor);
	} 
 
	public void setBackgroundImage(Bitmap backgroundImage) {
		releaseDelegate(); 
		this.background = new BitmapDrawable(backgroundImage);
	} 
 
	public void setBackgroundDrawable(Drawable drawable) {
		releaseDelegate(); 
		this.background = drawable;
		onStateChange(getState());
	} 
 
	@Override 
	public void setAlpha(int alpha)
	{ 
		super.setAlpha(alpha);
		this.alpha = alpha;
	} 
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:
	public ProfileNameBannerContainer2(final Context context, final AttributeSet attrs, final int defStyle) { 
		super(context, attrs, defStyle); 
	} 
 
	public void setBanner(final Bitmap banner) { 
		setBackgroundDrawable(banner != null ? new BitmapDrawable(getResources(), banner) : null); 
	} 
 
	@Override 
	protected void onMeasure(final int widthMeasureSpec, final int heightMeasureSpec) { 
		final int parentWidth = MeasureSpec.getSize(widthMeasureSpec); 
		setMeasuredDimension(parentWidth, parentWidth / 2); 
		final ViewGroup.LayoutParams lp = getLayoutParams(); 
		lp.width = parentWidth; 
		lp.height = parentWidth / 2; 
		setLayoutParams(lp); 
		super.onMeasure(widthMeasureSpec, heightMeasureSpec); 
	} 
} 
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getBitmap, setTargetDensity
            painter.setIntrinsicWidth(width);
            painter.setIntrinsicHeight(height);
        } else if (icon instanceof BitmapDrawable) {
            // Ensure the bitmap has a density. 
            BitmapDrawable bitmapDrawable = (BitmapDrawable) icon;
            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);
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getBitmap
     
    @Override 
    public void drawBitmap(String name, float xc, float yc, float w, float h,
                           float angle) {
        final Drawable drawable = mCache != null ? mCache.getImage(mView, name)
                : name == null ? new BitmapDrawable(mView.getResources(), getHandleBitmap(3)) : null;
         
        if (drawable != null) {
            Matrix mat = new Matrix();
            int width = ImageCache.getWidth(drawable);
            int height = ImageCache.getHeight(drawable);
             
            mat.postTranslate(-0.5f * width, -0.5f * height);
            mat.postRotate(-angle * 180.f / 3.1415926f); // degree to radian
            mat.postScale(w / width, h / height);
            mat.postTranslate(xc, yc);
             
            try { 
                BitmapDrawable b = (BitmapDrawable)drawable;
                mCanvas.drawBitmap(b.getBitmap(), mat, null);

7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java

Related Android BitmapDrawable Questions & Answers:

See Code Examples for Android BitmapDrawable Methods: