Example usage for android.graphics.drawable ScaleDrawable getDrawable

List of usage examples for android.graphics.drawable ScaleDrawable getDrawable

Introduction

In this page you can find the example usage for android.graphics.drawable ScaleDrawable getDrawable.

Prototype

@Nullable
public Drawable getDrawable() 

Source Link

Usage

From source file:com.ceino.chaperonandroid.activities.LicenseActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ChaperOnApplication.get(this).inject(this);
    chaperOnConnection = new ChaperOnConnection(this);
    overridePendingTransition(R.anim.animation, R.anim.animation2);
    setContentView(R.layout.activity_licenseverify);
    ButterKnife.inject(this);
    toastHandler = new ToastHandler(this);
    Intent intent = getIntent();/*from  ww w  .  ja v  a2  s  .c o  m*/
    phone = intent.getStringExtra("phone");
    email = intent.getStringExtra("email");
    password = intent.getStringExtra("pwd");
    firstname = intent.getStringExtra("fname");
    username = intent.getStringExtra("uname");
    imagePath = intent.getStringExtra("imgpath");
    street = intent.getStringExtra("street");
    apartment = intent.getStringExtra("aptno");
    city = intent.getStringExtra("city");
    postal = intent.getStringExtra("postal");
    country = intent.getStringExtra("country");
    lastname = intent.getStringExtra("lname");
    description = intent.getStringExtra("desc");
    rideType = intent.getIntExtra("ridetype", 0);
    lattitude = intent.getDoubleExtra("lat", 0);
    longtitude = intent.getDoubleExtra("long", 0);

    Drawable drawable = getResources().getDrawable(R.drawable.hash);
    drawable.setBounds(0, 0, (int) (drawable.getIntrinsicWidth() * 0.4),
            (int) (drawable.getIntrinsicHeight() * 0.4));
    ScaleDrawable sd = new ScaleDrawable(drawable, 0, 1f, 1f);

    emptySeats.setCompoundDrawablePadding(15);
    emptySeats.setCompoundDrawables(sd.getDrawable(), null, null, null);

    imgBack.setOnClickListener(this);
    imgLicense.setOnClickListener(this);
    saveAllbtn.setOnClickListener(this);
}

From source file:org.ciasaboark.tacere.manager.NotificationManagerWrapper.java

private Bitmap combineDrawablesToBitmap(final Drawable backgroundImage, final BitmapDrawable overlayImage,
        int width, int height) {

    Bitmap canvasBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    // Create a canvas, that will draw on to canvasBitmap.
    Canvas imageCanvas = new Canvas(canvasBitmap);

    // Draw the image to our canvas
    backgroundImage.setBounds(0, 0, width, height);
    backgroundImage.draw(imageCanvas);/*from  www  .j a v a  2 s . com*/
    overlayImage.setBounds(0, 0, (int) (overlayImage.getIntrinsicWidth() * 0.5),
            (int) (overlayImage.getIntrinsicHeight() * 0.5));
    final int scaleWidth = 24;
    final int scaleHeight = 24;
    final float scaleWidthPercent = ((float) scaleWidth) / overlayImage.getIntrinsicWidth();
    final float scaleHeightPercent = ((float) scaleHeight) / overlayImage.getIntrinsicHeight();
    ScaleDrawable scaleDrawable = new ScaleDrawable(overlayImage, 0, scaleWidthPercent, scaleHeightPercent);
    Drawable scaledOverlay = scaleDrawable.getDrawable();
    scaledOverlay.setBounds(0, 0, width, height);
    scaledOverlay.draw(imageCanvas);

    // Combine background and text to a LayerDrawable
    LayerDrawable layerDrawable = new LayerDrawable(
            new Drawable[] { backgroundImage, new BitmapDrawable(canvasBitmap) });
    Bitmap newBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    layerDrawable.setBounds(0, 0, width, height);
    layerDrawable.draw(new Canvas(newBitmap));
    return newBitmap;
}

From source file:com.landenlabs.all_UiDemo.frag.ImageScalesFrag.java

private void setScaledVector(ImageView imageView, int imageRes) {

    Drawable rawDrawable;/*  ww  w.ja  v  a  2 s.co m*/
    if (Build.VERSION.SDK_INT >= 21) {
        rawDrawable = getResources().getDrawable(imageRes, getTheme());
    } else {
        rawDrawable = getResources().getDrawable(imageRes);
    }

    Drawable drawable = rawDrawable.mutate();
    /*
    int pad = 50;
    drawable.setBounds(0, pad, drawable.getIntrinsicWidth(),
        drawable.getIntrinsicHeight());
    */

    // ScaleDrawable does nothing !!!!
    if (false) {
        ScaleDrawable scaleDrawable = new ScaleDrawable(rawDrawable, Gravity.TOP | Gravity.LEFT, 2.0f, 0.8f);
        scaleDrawable.setLevel(8000);
        drawable = scaleDrawable.getDrawable();
    }

    if (false) {
        int tintColor = 0x80ff0000;
        ColorStateList colorStateList = new ColorStateList(new int[][] { new int[] {} },
                new int[] { tintColor });

        drawable = DrawableCompat.wrap(drawable.mutate());
        DrawableCompat.setTintList(drawable, colorStateList);
        DrawableCompat.setTintMode(drawable, PorterDuff.Mode.MULTIPLY);
    }

    //imageView.setScaleType(ImageView.ScaleType.CENTER);
    imageView.setImageDrawable(drawable);
    // imageView.setImageDrawable(null);
    // imageView.setBackgroundDrawable(drawable);
}

From source file:co.ceryle.segmentedbutton.SegmentedButton.java

/**
 * @param scale sets button's drawable size. It multiplies drawable's width and height with the given variable.
 *///from w w  w  .  ja v a  2  s  .  c  om
public void scaleDrawable(double scale) {
    Drawable[] drawables = getCompoundDrawables();

    for (int i = 0; i < drawables.length; i++) {
        if (drawables[i] != null) {
            if (drawables[i] instanceof ScaleDrawable) {
                drawables[i].setLevel(1);
            }
            ScaleDrawable sd = new ScaleDrawable(drawables[i], 0, drawables[i].getIntrinsicWidth(),
                    drawables[i].getIntrinsicHeight());
            drawables[i].setBounds(0, 0, (int) (drawables[i].getIntrinsicWidth() * scale),
                    (int) (drawables[i].getIntrinsicHeight() * scale));

            setDrawable(sd.getDrawable(), i);
        }
    }
}