java类android.graphics.PorterDuff的实例源码

ToolbarMenuItem.java 文件源码 项目:https-github.com-hyb1996-NoRootScriptDroid 阅读 18 收藏 0 点赞 0 评论 0
public static Drawable convertDrawableToGrayScale(Drawable drawable, int color) {
    if (drawable == null || drawable.getConstantState() == null)
        return null;
    Drawable res = drawable.getConstantState().newDrawable().mutate();
    res.setColorFilter(color, PorterDuff.Mode.SRC_IN);
    return res;
}
ClipView.java 文件源码 项目:YiZhi 阅读 20 收藏 0 点赞 0 评论 0
public ClipView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    //去锯齿
    paint.setAntiAlias(true);
    borderPaint.setStyle(Paint.Style.STROKE);
    borderPaint.setColor(Color.WHITE);
    borderPaint.setStrokeWidth(clipBorderWidth);
    borderPaint.setAntiAlias(true);
    xfermode = new PorterDuffXfermode(PorterDuff.Mode.DST_OUT);
}
SunriseSunset.java 文件源码 项目:OneWeather 阅读 21 收藏 0 点赞 0 评论 0
private void init(AttributeSet attrs) {
    if(attrs != null){
        TypedArray typedArray = mContext.obtainStyledAttributes(attrs,R.styleable.SunriseSunset);
        lineColor = typedArray.getColor(R.styleable.SunriseSunset_lineColor, Color.WHITE);
        sunColor = typedArray.getColor(R.styleable.SunriseSunset_sunColor,Color.YELLOW);
        timeTextColor = typedArray.getColor(R.styleable.SunriseSunset_timeTextColor,Color.GRAY);
        timeTextSize = typedArray.getDimension(R.styleable.SunriseSunset_timeTextSize,40);
        typedArray.recycle();
    }
    mCenterPoint = new Point();
    mArcPaint = new Paint();
    mArcPaint.setAntiAlias(true);
    mArcPaint.setColor(lineColor);
    mArcPaint.setStyle(Paint.Style.STROKE);
    mArcPaint.setStrokeWidth(3);
    mArcPaint.setPathEffect(new DashPathEffect(new float[]{20,15},20));
    mArcPaint.setStrokeCap(Paint.Cap.ROUND);
    mRectF = new RectF();


    mSunPaint = new Paint();
    mSunPaint.setAntiAlias(true);
    mSunPaint.setColor(sunColor);
    mSunPaint.setStyle(Paint.Style.STROKE);
    mSunPaint.setStrokeWidth(3);
    mSunPaint.setPathEffect(new DashPathEffect(new float[]{20,15},20));
    mSunriseBitmap = BitmapFactory.decodeResource(getResources(),R.drawable.ic_sunrise);
    mSunsetBitmap = BitmapFactory.decodeResource(getResources(),R.drawable.ic_sunset);
    mSunPaint.setColorFilter( new PorterDuffColorFilter(sunColor, PorterDuff.Mode.SRC_ATOP)) ;//设置后bitmap才会填充颜色

    mTimePaint = new Paint();
    mTimePaint.setColor(timeTextColor);
    mTimePaint.setTextSize(timeTextSize);
    mTimePaint.setTextAlign(Paint.Align.CENTER);



}
ThemeUtils.java 文件源码 项目:Mix 阅读 35 收藏 0 点赞 0 评论 0
public static Drawable tintDrawable(Drawable drawable, @ColorInt int color, PorterDuff.Mode mode) {
    if (drawable == null) return null;
    Drawable wrapper = DrawableCompat.wrap(drawable.mutate());
    DrawableCompat.setTint(wrapper, color);
    DrawableCompat.setTintMode(drawable, mode);
    return wrapper;
}
NoInternetDialog.java 文件源码 项目:NoInternetDialog 阅读 28 收藏 0 点赞 0 评论 0
private void initButtonStyle() {
    wifiOn.getBackground().mutate().setColorFilter(buttonColor, PorterDuff.Mode.SRC_IN);
    mobileOn.getBackground().mutate().setColorFilter(buttonColor, PorterDuff.Mode.SRC_IN);
    airplaneOff.getBackground().mutate().setColorFilter(buttonColor, PorterDuff.Mode.SRC_IN);

    wifiOn.setTextColor(buttonTextColor);
    mobileOn.setTextColor(buttonTextColor);
    airplaneOff.setTextColor(buttonTextColor);

    Drawable wifi = ContextCompat.getDrawable(getContext(), R.drawable.ic_wifi_white);
    Drawable mobileData = ContextCompat.getDrawable(getContext(), R.drawable.ic_4g_white);
    Drawable airplane = ContextCompat.getDrawable(getContext(), R.drawable.ic_airplane_off);

    wifi.mutate().setColorFilter(buttonIconsColor, PorterDuff.Mode.SRC_ATOP);
    mobileData.mutate().setColorFilter(buttonIconsColor, PorterDuff.Mode.SRC_ATOP);
    airplane.mutate().setColorFilter(buttonIconsColor, PorterDuff.Mode.SRC_ATOP);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        wifiOn.setCompoundDrawablesRelativeWithIntrinsicBounds(wifi, null, null, null);
        mobileOn.setCompoundDrawablesRelativeWithIntrinsicBounds(mobileData, null, null, null);
        airplaneOff.setCompoundDrawablesRelativeWithIntrinsicBounds(airplane, null, null, null);
    } else {
        wifiOn.setCompoundDrawablesWithIntrinsicBounds(wifi, null, null, null);
        mobileOn.setCompoundDrawablesWithIntrinsicBounds(mobileData, null, null, null);
        airplaneOff.setCompoundDrawablesWithIntrinsicBounds(airplane, null, null, null);
    }
}
Slate.java 文件源码 项目:PlusGram 阅读 23 收藏 0 点赞 0 评论 0
public void clear() {
    if (mTiledCanvas != null) {
        commitStroke();
        mTiledCanvas.drawColor(0x00000000, PorterDuff.Mode.SRC);
        invalidate();
    } else if (mPendingPaintBitmap != null) { // FIXME for tiling
        mPendingPaintBitmap.recycle();
        mPendingPaintBitmap = null;
    }
    mEmpty = true;

    // reset the zoom when clearing
    resetZoom();
}
PendingAppWidgetHostView.java 文件源码 项目:FlickLauncher 阅读 25 收藏 0 点赞 0 评论 0
private void updateSettingColor() {
    int color = Utilities.findDominantColorByHue(mIcon, 20);
    // Make the dominant color bright.
    float[] hsv = new float[3];
    Color.colorToHSV(color, hsv);
    hsv[1] = Math.min(hsv[1], MIN_SATUNATION);
    hsv[2] = 1;
    color = Color.HSVToColor(hsv);

    mSettingIconDrawable.setColorFilter(color,  PorterDuff.Mode.SRC_IN);
}
BindingUtils.java 文件源码 项目:GitHub 阅读 41 收藏 0 点赞 0 评论 0
@BindingAdapter({"roundImageUrl"})
public static void loadRoundImg(ImageView v, String url) {
    v.setColorFilter(v.getContext().getResources().getColor(SpUtil.isNight() ? R.color.CoverColor : R.color.colorWhite), PorterDuff.Mode.MULTIPLY);
    Glide.with(v.getContext())
            .load(getFuckUrl(url))
            .diskCacheStrategy(DiskCacheStrategy.ALL)
            .transform(new GlideCircleTransform(v.getContext()))
            .error(R.mipmap.ic_launcher)
            .into(v);
}
ViewfinderView.java 文件源码 项目:zxing_qrcode_demo 阅读 35 收藏 0 点赞 0 评论 0
/**
 * 绘制有四个圆角的取景框边框
 *
 * @return
 */
private void drawRoundRectForeground(Canvas canvas, Rect frame) {
    paint.setColor(Color.TRANSPARENT);
    paint.setStyle(Paint.Style.FILL);
    paint.setAlpha(60);

    //set mode为clear
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OUT));

    canvas.drawRoundRect(new RectF(frame.left, frame.top, frame.right, frame.bottom + scanLineHeight), radius, radius, paint);
    paint.setXfermode(null);
}
ResourceLoader.java 文件源码 项目:airgram 阅读 30 收藏 0 点赞 0 评论 0
public static void fantasyChanged(boolean fantasy){
    Context c= ApplicationLoader.applicationContext;
    loadRecources(c);

    if(fantasy){
        checkDrawableF.setColorFilter(0xff68a7ad, PorterDuff.Mode.SRC_ATOP);
        halfCheckDrawableF.setColorFilter(0xff68a7ad, PorterDuff.Mode.SRC_ATOP);
        clockDrawableF.setColorFilter(0xff68a7ad, PorterDuff.Mode.SRC_ATOP);
        viewsOutCountDrawableF.setColorFilter(0xff68a7ad, PorterDuff.Mode.SRC_ATOP);
        viewsCountDrawableF.setColorFilter(0xffb5a564, PorterDuff.Mode.SRC_ATOP);
        broadcastDrawableF.setColorFilter(0xff68a7ad, PorterDuff.Mode.SRC_ATOP);
        docMenuDrawableF[0].setColorFilter(ChatBaseColors.timeInF, PorterDuff.Mode.SRC_ATOP);
        docMenuDrawableF[1].setColorFilter(ChatBaseColors.timeOutF, PorterDuff.Mode.SRC_ATOP);
        docMenuDrawableF[2].setColorFilter(ChatBaseColors.timeInSelectedF, PorterDuff.Mode.SRC_ATOP);
    }else {
        checkDrawableF.clearColorFilter();
        halfCheckDrawableF.clearColorFilter();
        clockDrawableF.clearColorFilter();
        viewsOutCountDrawableF.clearColorFilter();
        viewsCountDrawableF.clearColorFilter();
        broadcastDrawableF.clearColorFilter();
        docMenuDrawableF[0].clearColorFilter();
        docMenuDrawableF[1].clearColorFilter();
        docMenuDrawableF[2].clearColorFilter();
    }

}


问题


面经


文章

微信
公众号

扫码关注公众号