类android.graphics.drawable.VectorDrawable源码实例Demo

下面列出了怎么用android.graphics.drawable.VectorDrawable的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: memetastic   文件: ContextUtils.java
/**
 * Get a {@link Bitmap} out of a {@link Drawable}
 */
public Bitmap drawableToBitmap(Drawable drawable) {
    Bitmap bitmap = null;
    if (drawable instanceof VectorDrawableCompat
            || (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && drawable instanceof VectorDrawable)
            || ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && drawable instanceof AdaptiveIconDrawable))) {

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
            drawable = (DrawableCompat.wrap(drawable)).mutate();
        }

        bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(),
                drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(bitmap);
        drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
        drawable.draw(canvas);
    } else if (drawable instanceof BitmapDrawable) {
        bitmap = ((BitmapDrawable) drawable).getBitmap();
    }
    return bitmap;
}
 
源代码2 项目: openlauncher   文件: ContextUtils.java
/**
 * Get a {@link Bitmap} out of a {@link Drawable}
 */
public Bitmap drawableToBitmap(Drawable drawable) {
    Bitmap bitmap = null;
    if (drawable instanceof VectorDrawableCompat
            || (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && drawable instanceof VectorDrawable)
            || ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && drawable instanceof AdaptiveIconDrawable))) {

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
            drawable = (DrawableCompat.wrap(drawable)).mutate();
        }

        bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(),
                drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(bitmap);
        drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
        drawable.draw(canvas);
    } else if (drawable instanceof BitmapDrawable) {
        bitmap = ((BitmapDrawable) drawable).getBitmap();
    }
    return bitmap;
}
 
源代码3 项目: Stringlate   文件: ContextUtils.java
/**
 * Get a {@link Bitmap} out of a {@link Drawable}
 */
public Bitmap drawableToBitmap(Drawable drawable) {
    Bitmap bitmap = null;
    if (drawable instanceof VectorDrawableCompat
            || (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && drawable instanceof VectorDrawable)
            || ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && drawable instanceof AdaptiveIconDrawable))) {

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
            drawable = (DrawableCompat.wrap(drawable)).mutate();
        }

        bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(),
                drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(bitmap);
        drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
        drawable.draw(canvas);
    } else if (drawable instanceof BitmapDrawable) {
        bitmap = ((BitmapDrawable) drawable).getBitmap();
    }
    return bitmap;
}
 
源代码4 项目: kimai-android   文件: ContextUtils.java
/**
 * Get a {@link Bitmap} out of a {@link Drawable}
 */
public Bitmap drawableToBitmap(Drawable drawable) {
    Bitmap bitmap = null;
    if (drawable instanceof VectorDrawableCompat
            || (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && drawable instanceof VectorDrawable)
            || ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && drawable instanceof AdaptiveIconDrawable))) {

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
            drawable = (DrawableCompat.wrap(drawable)).mutate();
        }

        bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(),
                drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(bitmap);
        drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
        drawable.draw(canvas);
    } else if (drawable instanceof BitmapDrawable) {
        bitmap = ((BitmapDrawable) drawable).getBitmap();
    }
    return bitmap;
}
 
源代码5 项目: SegmentedButton   文件: SegmentedButton.java
private Drawable readCompatDrawable(Context context, int drawableResId)
{
    Drawable drawable = AppCompatResources.getDrawable(context, drawableResId);

    // API 28 has a bug with vector drawables where the selected tint color is always applied to the drawable
    // To prevent this, the vector drawable is converted to a bitmap
    if ((VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP && drawable instanceof VectorDrawable)
        || drawable instanceof VectorDrawableCompat)
    {
        Bitmap bitmap = getBitmapFromVectorDrawable(drawable);
        return new BitmapDrawable(context.getResources(), bitmap);
    }
    else
        return drawable;
}
 
源代码6 项目: Twire   文件: RoundedImageView.java
@Override
protected void onDraw(Canvas canvas) {

    Drawable drawable = getDrawable();

    if (drawable == null) {
        return;
    }

    if (getWidth() == 0 || getHeight() == 0) {
        return;
    }

    Bitmap b = null;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP
            && drawable instanceof VectorDrawable) {
        drawable.draw(canvas);
        b = Bitmap.createBitmap(canvas.getWidth(), canvas.getHeight(), Bitmap.Config.ARGB_8888);
        Canvas c = new Canvas();
        c.setBitmap(b);
        drawable.draw(c);
    } else if (drawable instanceof BitmapDrawable) {
        b = ((BitmapDrawable) drawable).getBitmap();
    } else if (drawable instanceof LayerDrawable) {
        LayerDrawable layerDrawable = (LayerDrawable) drawable;
        b = Bitmap.createBitmap(canvas.getWidth(), canvas.getHeight(), Bitmap.Config.ARGB_8888);
        layerDrawable.draw(new Canvas(b));
    }
    Bitmap bitmap = b.copy(Bitmap.Config.ARGB_8888, true);
    int w = getWidth(), h = getHeight();

    Bitmap roundBitmap = getCroppedBitmap(bitmap, w);
    canvas.drawBitmap(roundBitmap, 0, 0, null);
}
 
源代码7 项目: VectorChildFinder   文件: VectorDrawableCompat.java
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
@Override
public Drawable newDrawable() {
    VectorDrawableCompat drawableCompat = new VectorDrawableCompat();
    drawableCompat.mDelegateDrawable = (VectorDrawable) mDelegateState.newDrawable();
    return drawableCompat;
}
 
源代码8 项目: VectorChildFinder   文件: VectorDrawableCompat.java
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
@Override
public Drawable newDrawable(Resources res) {
    VectorDrawableCompat drawableCompat = new VectorDrawableCompat();
    drawableCompat.mDelegateDrawable = (VectorDrawable) mDelegateState.newDrawable(res);
    return drawableCompat;
}
 
源代码9 项目: VectorChildFinder   文件: VectorDrawableCompat.java
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
@Override
public Drawable newDrawable(Resources res, Resources.Theme theme) {
    VectorDrawableCompat drawableCompat = new VectorDrawableCompat();
    drawableCompat.mDelegateDrawable =
            (VectorDrawable) mDelegateState.newDrawable(res, theme);
    return drawableCompat;
}
 
源代码10 项目: fingen   文件: AmountColorizer.java
public Drawable getTransactionIcon(int transactionType) {
    switch (transactionType) {
        case Transaction.TRANSACTION_TYPE_INCOME:
            return iconIncome;
        case Transaction.TRANSACTION_TYPE_EXPENSE:
            return iconExpense;
        case Transaction.TRANSACTION_TYPE_TRANSFER:
            return iconTransfer;
        default:
            return new VectorDrawable();
    }
}
 
public void setRightIcon(int drawableID, int clear_btn_width, int alpha) {
        this.rightIconSize = (short) clear_btn_width;

        iconPaint.setAlpha(alpha);
        Drawable drawable = ContextCompat.getDrawable(getContext(), drawableID);
//        Drawable drawable = VectorDrawableCompat.create(getResources(),drawableID,null) ;

        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true;
        Bitmap sampleBitmap = createBitmap(drawable, getResources(), drawableID, options);
        int sampleSize = 1;
        int width = options.outWidth;
        int height = options.outHeight;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && drawable instanceof VectorDrawable) {
            width = drawable.getIntrinsicWidth();
            height = drawable.getIntrinsicHeight();
        }
        bitmap_height = (short) (height * clear_btn_width / width);
        int destinationHeight = bitmap_height;
        if (height > destinationHeight || width > clear_btn_width) {
            int halfHeight = height >> 1;
            int halfWidth = width >> 1;
            while ((halfHeight / sampleSize) > destinationHeight && (halfWidth / sampleSize) > clear_btn_width) {
                sampleSize *= 2;
            }
        }
        if (sampleBitmap != null)
            sampleBitmap.recycle();
        options.inSampleSize = sampleSize;
        options.inJustDecodeBounds = false;
        Bitmap oldBitmap = createBitmap(drawable, getResources(), drawableID, options);
        width = oldBitmap.getWidth();
        height = oldBitmap.getHeight();
        Matrix matrix = new Matrix();
        float scaleX = ((float) clear_btn_width / width);
        float scaleY = ((float) destinationHeight / height);
        matrix.postScale(scaleX, scaleY);
        rightIconBitmap = new SoftReference<>(
                Bitmap.createBitmap(oldBitmap, 0, 0, width, height, matrix, true)).get();
    }
 
private Bitmap createBitmap(Drawable drawable, Resources resources, int drawableId, BitmapFactory.Options options) {
    if (drawable instanceof BitmapDrawable) {
        return getBitmap(resources, drawableId, options);
    } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && drawable instanceof VectorDrawable) {
        return getVectorBitmap((VectorDrawable) drawable);
    } else {
        throw new IllegalArgumentException("unsupported drawable type");
    }
}
 
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private Bitmap getVectorBitmap(VectorDrawable vectorDrawable) {
    Bitmap bitmap = Bitmap.createBitmap(vectorDrawable.getIntrinsicWidth(),
            vectorDrawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    vectorDrawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
    vectorDrawable.draw(canvas);
    return bitmap;
}
 
源代码14 项目: xmrwallet   文件: Helper.java
static public Bitmap getBitmap(Context context, int drawableId) {
    Drawable drawable = ContextCompat.getDrawable(context, drawableId);
    if (drawable instanceof BitmapDrawable) {
        return BitmapFactory.decodeResource(context.getResources(), drawableId);
    } else if (drawable instanceof VectorDrawable) {
        return getBitmap((VectorDrawable) drawable);
    } else {
        throw new IllegalArgumentException("unsupported drawable type");
    }
}
 
源代码15 项目: xmrwallet   文件: Helper.java
static private Bitmap getBitmap(VectorDrawable vectorDrawable) {
    Bitmap bitmap = Bitmap.createBitmap(vectorDrawable.getIntrinsicWidth(),
            vectorDrawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    vectorDrawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
    vectorDrawable.draw(canvas);
    return bitmap;
}
 
源代码16 项目: OpenHub   文件: ViewUtils.java
private static Bitmap getBitmapFromResource(VectorDrawable vectorDrawable) {
    Bitmap bitmap = Bitmap.createBitmap(vectorDrawable.getIntrinsicWidth(),
            vectorDrawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    vectorDrawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
    vectorDrawable.draw(canvas);
    return bitmap;
}
 
源代码17 项目: OpenHub   文件: ViewUtils.java
/**
 * Get bitmap from resource
 */
public static Bitmap getBitmapFromResource(Context context, int drawableId) {
    Drawable drawable = ContextCompat.getDrawable(context, drawableId);
    if (drawable instanceof BitmapDrawable) {
        return BitmapFactory.decodeResource(context.getResources(), drawableId);
    } else if (drawable instanceof VectorDrawable) {
        return getBitmapFromResource((VectorDrawable) drawable);
    } else {
        throw new IllegalArgumentException("unsupported drawable type");
    }
}
 
源代码18 项目: Pocket-Plays-for-Twitch   文件: RoundedImageView.java
@Override
protected void onDraw(Canvas canvas) {

	Drawable drawable = getDrawable();

	if (drawable == null) {
		return;
	}

	if (getWidth() == 0 || getHeight() == 0) {
		return;
	}

	Bitmap b = null;
	if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP
			&& drawable instanceof VectorDrawable) {
		((VectorDrawable) drawable).draw(canvas);
		b = Bitmap.createBitmap(canvas.getWidth(), canvas.getHeight(), Bitmap.Config.ARGB_8888);
		Canvas c = new Canvas();
		c.setBitmap(b);
		drawable.draw(c);
	} else if (drawable instanceof BitmapDrawable){
		b = ((BitmapDrawable) drawable).getBitmap();
	} else if (drawable instanceof LayerDrawable) {
		LayerDrawable layerDrawable = (LayerDrawable) drawable;
		b = Bitmap.createBitmap(canvas.getWidth(), canvas.getHeight(), Bitmap.Config.ARGB_8888);
		layerDrawable.draw(new Canvas(b));
	}
	Bitmap bitmap = b.copy(Bitmap.Config.ARGB_8888, true);
	int w = getWidth(), h = getHeight();

	Bitmap roundBitmap =  getCroppedBitmap(bitmap, w);
	canvas.drawBitmap(roundBitmap, 0,0, null);
}
 
源代码19 项目: MangoBloggerAndroidApp   文件: Utils.java
public static Bitmap getBitmap(Drawable drawable, int width, int height) {
    if (drawable instanceof BitmapDrawable) {
        return ((BitmapDrawable) drawable).getBitmap();
    } else if (drawable instanceof VectorDrawableCompat) {
        return getBitmap((VectorDrawableCompat) drawable, width, height);
    } else if (drawable instanceof VectorDrawable) {
        return getBitmap((VectorDrawable) drawable, width, height);
    } else {
        throw new IllegalArgumentException("Unsupported drawable type");
    }
}
 
源代码20 项目: MangoBloggerAndroidApp   文件: Utils.java
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private static Bitmap getBitmap(VectorDrawable vectorDrawable, int width, int height) {
    Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    vectorDrawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
    vectorDrawable.draw(canvas);
    return bitmap;
}
 
源代码21 项目: ForPDA   文件: App.java
public static Drawable getVecDrawable(Context context, @DrawableRes int id) {
    Drawable drawable = AppCompatResources.getDrawable(context, id);
    if (!(drawable instanceof VectorDrawableCompat || drawable instanceof VectorDrawable)) {
        throw new RuntimeException();
    }
    return drawable;
}
 
源代码22 项目: RxGpsService   文件: BitmapHelper.java
public Bitmap getBitmap(Context context, int drawableId) {
    Drawable drawable = ContextCompat.getDrawable(context, drawableId);
    if (drawable instanceof BitmapDrawable) {
        return ((BitmapDrawable) drawable).getBitmap();
    } else if (drawable instanceof VectorDrawable) {
        return getBitmap((VectorDrawable) drawable);
    } else {
        throw new IllegalArgumentException("unsupported drawable type");
    }
}
 
源代码23 项目: RxGpsService   文件: BitmapHelper.java
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private Bitmap getBitmap(VectorDrawable vectorDrawable) {
    Bitmap bitmap = Bitmap.createBitmap(vectorDrawable.getIntrinsicWidth(), vectorDrawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    vectorDrawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
    vectorDrawable.draw(canvas);
    return bitmap;
}
 
源代码24 项目: droidkaigi2016   文件: ResourceUtil.java
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private static Bitmap getBitmap(VectorDrawable vectorDrawable) {
    Bitmap bitmap = Bitmap.createBitmap(vectorDrawable.getIntrinsicWidth(),
            vectorDrawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    vectorDrawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
    vectorDrawable.draw(canvas);
    return bitmap;
}
 
源代码25 项目: droidkaigi2016   文件: ResourceUtil.java
public static Bitmap getBitmap(Context context, @DrawableRes int drawableResId) {
    Drawable drawable = ContextCompat.getDrawable(context, drawableResId);
    if (drawable instanceof BitmapDrawable) {
        return ((BitmapDrawable) drawable).getBitmap();
    } else if (drawable instanceof VectorDrawableCompat) {
        return getBitmap((VectorDrawableCompat) drawable);
    } else if (drawable instanceof VectorDrawable) {
        return getBitmap((VectorDrawable) drawable);
    } else {
        throw new IllegalArgumentException("Unsupported drawable type");
    }
}
 
源代码26 项目: TSnackBar   文件: TSnackbar.java
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private static Bitmap getBitmap(VectorDrawable vectorDrawable) {
    Bitmap bitmap = Bitmap.createBitmap(vectorDrawable.getIntrinsicWidth(),
            vectorDrawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    vectorDrawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
    vectorDrawable.draw(canvas);
    return bitmap;
}
 
源代码27 项目: TSnackBar   文件: TSnackbar.java
private static Bitmap getBitmap(Drawable drawable) {
    if (drawable instanceof BitmapDrawable) {
        return ((BitmapDrawable) drawable).getBitmap();
    } else if (drawable instanceof VectorDrawable) {
        return getBitmap((VectorDrawable) drawable);
    } else {
        throw new IllegalArgumentException("unsupported drawable type");
    }
}
 
源代码28 项目: droidkaigi2016   文件: ResourceUtil.java
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private static Bitmap getBitmap(VectorDrawable vectorDrawable) {
    Bitmap bitmap = Bitmap.createBitmap(vectorDrawable.getIntrinsicWidth(),
            vectorDrawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    vectorDrawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
    vectorDrawable.draw(canvas);
    return bitmap;
}
 
源代码29 项目: droidkaigi2016   文件: ResourceUtil.java
public static Bitmap getBitmap(Context context, @DrawableRes int drawableResId) {
    Drawable drawable = ContextCompat.getDrawable(context, drawableResId);
    if (drawable instanceof BitmapDrawable) {
        return ((BitmapDrawable) drawable).getBitmap();
    } else if (drawable instanceof VectorDrawableCompat) {
        return getBitmap((VectorDrawableCompat) drawable);
    } else if (drawable instanceof VectorDrawable) {
        return getBitmap((VectorDrawable) drawable);
    } else {
        throw new IllegalArgumentException("Unsupported drawable type");
    }
}
 
 类方法
 同包方法