Java 类android.graphics.PorterDuffColorFilter 实例源码

项目:airgram    文件:DrawerProfileCell.java   
@Override
protected void onDraw(Canvas canvas) {
    int pic=SkinMan.currentSkin.actionPicture();
    Drawable backgroundDrawable = pic!=0 ? ContextCompat.getDrawable(getContext(), pic) : ApplicationLoader.getCachedWallpaper();
    int color = ApplicationLoader.getServiceMessageColor();
    if (currentColor != color) {
        currentColor = color;
        shadowView.getDrawable().setColorFilter(new PorterDuffColorFilter(color | 0xff000000, PorterDuff.Mode.MULTIPLY));
    }

    if (ApplicationLoader.isCustomTheme() || pic !=0 && backgroundDrawable != null) {
        phoneTextView.setTextColor(0xffffffff);
        shadowView.setVisibility(VISIBLE);
        if (backgroundDrawable instanceof ColorDrawable) {
            backgroundDrawable.setBounds(0, 0, getMeasuredWidth(), getMeasuredHeight());
            backgroundDrawable.draw(canvas);
        } else if (backgroundDrawable instanceof BitmapDrawable) {
            Bitmap bitmap = ((BitmapDrawable) backgroundDrawable).getBitmap();
            float scaleX = (float) getMeasuredWidth() / (float) bitmap.getWidth();
            float scaleY = (float) getMeasuredHeight() / (float) bitmap.getHeight();
            float scale = scaleX < scaleY ? scaleY : scaleX;
            int width = (int) (getMeasuredWidth() / scale);
            int height = (int) (getMeasuredHeight() / scale);
            int x = (bitmap.getWidth() - width) / 2;
            int y = (bitmap.getHeight() - height) / 2;
            srcRect.set(x, y, x + width, y + height);
            destRect.set(0, 0, getMeasuredWidth(), getMeasuredHeight());
            canvas.drawBitmap(bitmap, srcRect, destRect, paint);
        }
    } else {
        shadowView.setVisibility(INVISIBLE);
        phoneTextView.setTextColor(0xffc2e5ff);
        super.onDraw(canvas);
    }
}
项目:WechatChatroomHelper    文件:BGASwipeBackLayout2.java   
private void dimChildView(View v, float mag, int fadeColor) {
    final LayoutParams lp = (LayoutParams) v.getLayoutParams();

    if (mag > 0 && fadeColor != 0) {
        final int baseAlpha = (fadeColor & 0xff000000) >>> 24;
        int imag = (int) (baseAlpha * mag);
        int color = imag << 24 | (fadeColor & 0xffffff);
        if (lp.dimPaint == null) {
            lp.dimPaint = new Paint();
        }
        lp.dimPaint.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_OVER));
        if (ViewCompat.getLayerType(v) != ViewCompat.LAYER_TYPE_HARDWARE) {
            ViewCompat.setLayerType(v, ViewCompat.LAYER_TYPE_HARDWARE, lp.dimPaint);
        }
        invalidateChildRegion(v);
    } else if (ViewCompat.getLayerType(v) != ViewCompat.LAYER_TYPE_NONE) {
        if (lp.dimPaint != null) {
            lp.dimPaint.setColorFilter(null);
        }
        final DisableLayerRunnable dlr = new DisableLayerRunnable(v);
        mPostedRunnables.add(dlr);
        ViewCompat.postOnAnimation(this, dlr);
    }
}
项目:HoldingButton    文件:HoldingDrawable.java   
public void setIcon(Bitmap bitmap) {
    if (bitmap != null) {
        mIconWidth = bitmap.getWidth();
        mIconHeight = bitmap.getHeight();
        mIconShader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
        mIconShader.setLocalMatrix(mIconMatrix);
        mIconPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        mIconPaint.setShader(mIconShader);
        mIconPaint.setColorFilter(new PorterDuffColorFilter(Color.WHITE, PorterDuff.Mode.SRC_IN));

        invalidateSelf();
    } else {
        mIconWidth = 0;
        mIconHeight = 0;
        mIconShader = null;
        mIconMatrix = null;
        mIconPaint = null;
    }
}
项目:android_ui    文件:TintLayerDrawable.java   
/**
 * Updates tint of a layer with the specified <var>layerId</var> of the wrapped drawable
 * depends on the specified <var>stateSet</var>.
 *
 * @param layerId  Id of the desired layer of which tint to update.
 * @param stateSet State set to properly resolve tint color.
 * @return {@code True} if tint has ben updated, {@code false} otherwise.
 */
private boolean updateDrawableLayerTint(int layerId, int[] stateSet) {
    if ((mPrivateFlags & PFLAG_HAS_COLOR_FILTER) == 0) {
        final Drawable drawable = ((LayerDrawable) mDrawable).findDrawableByLayerId(layerId);
        if (drawable == null) {
            return false;
        }

        final DrawableLayerTint layerTint = mDrawableLayerTints != null ? mDrawableLayerTints.get(layerId) : null;
        if (layerTint != null && layerTint.tintList != null && layerTint.tintMode != null) {
            final int tintColor = layerTint.tintList.getColorForState(stateSet, layerTint.currentTint);

            if (tintColor != layerTint.currentTint || (mPrivateFlags & PFLAG_TINT_COLOR_CACHING_ENABLED) == 0) {
                drawable.setColorFilter(new PorterDuffColorFilter(tintColor, layerTint.tintMode));
                layerTint.currentTint = tintColor;
            }
        } else {
            drawable.clearColorFilter();
        }
        return true;
    }
    return false;
}
项目:android_ui    文件:TintDrawable.java   
/**
 * Updates tint of the wrapped drawable depends on the specified <var>stateSet</var>.
 *
 * @param stateSet State set to properly resolve tint color.
 * @return {@code True} if tint has ben updated, {@code false} otherwise.
 */
private boolean updateTint(int[] stateSet) {
    if ((mPrivateFlags & PFLAG_HAS_COLOR_FILTER) == 0) {
        if (mTintList != null && mTintMode != null) {
            final int tintColor = mTintList.getColorForState(stateSet, mCurrentTint);
            if (tintColor != mCurrentTint || (mPrivateFlags & PFLAG_TINT_COLOR_CACHING_ENABLED) == 0) {
                super.setColorFilter(new PorterDuffColorFilter(tintColor, mTintMode));
                this.mCurrentTint = tintColor;
            }
        } else {
            super.clearColorFilter();
        }
    }
    return false;
}
项目:react-native-andorid-shadow    文件:ShadowParentView.java   
private void decodeShadowBounds() {
    if (hasShadowColor) {
        shadowDrawable.setColorFilter(new PorterDuffColorFilter(shadowColor, PorterDuff.Mode.SRC_IN));
    }
    Rect pad = new Rect();
    shadowDrawable.getPadding(pad);

    View view = getChildAt(0);
    Rect bounds = new Rect(view.getLeft()-pad.left, view.getTop()-pad.top,
            view.getRight()+pad.right, view.getBottom()+pad.bottom);

    shadowPadding = Math.max(Math.max(pad.left,pad.top),Math.max(pad.right,pad.bottom));

    shadowDrawable.setBounds(bounds);
}
项目:PeSanKita-android    文件:ScribbleToolbar.java   
private void setBrushSelected(boolean enabled) {
  if (enabled) {

    this.textView.setBackground(null);
    this.textView.setColorFilter(new PorterDuffColorFilter(foregroundUnselectedTint, PorterDuff.Mode.MULTIPLY));

    this.brushView.setBackground(background);
    this.brushView.setColorFilter(new PorterDuffColorFilter(foregroundSelectedTint, PorterDuff.Mode.MULTIPLY));

    this.stickerView.setBackground(null);
    this.stickerView.setColorFilter(new PorterDuffColorFilter(foregroundUnselectedTint, PorterDuff.Mode.MULTIPLY));

    this.separatorView.setVisibility(View.VISIBLE);
    this.undoView.setVisibility(View.VISIBLE);
    this.deleteView.setVisibility(View.GONE);

    this.selected = Selected.BRUSH;
  } else {
    this.brushView.setBackground(null);
    this.brushView.setColorFilter(new PorterDuffColorFilter(foregroundUnselectedTint, PorterDuff.Mode.MULTIPLY));
    this.separatorView.setVisibility(View.GONE);
    this.undoView.setVisibility(View.GONE);

    this.selected = Selected.NONE;
  }
}
项目:PeSanKita-android    文件:ScribbleToolbar.java   
public void setTextSelected(boolean enabled) {
  if (enabled) {
    this.brushView.setBackground(null);
    this.brushView.setColorFilter(new PorterDuffColorFilter(foregroundUnselectedTint, PorterDuff.Mode.MULTIPLY));

    this.textView.setBackground(background);
    this.textView.setColorFilter(new PorterDuffColorFilter(foregroundSelectedTint, PorterDuff.Mode.MULTIPLY));

    this.stickerView.setBackground(null);
    this.stickerView.setColorFilter(new PorterDuffColorFilter(foregroundUnselectedTint, PorterDuff.Mode.MULTIPLY));

    this.separatorView.setVisibility(View.VISIBLE);
    this.undoView.setVisibility(View.GONE);
    this.deleteView.setVisibility(View.VISIBLE);

    this.selected = Selected.TEXT;
  } else {
    this.textView.setBackground(null);
    this.textView.setColorFilter(new PorterDuffColorFilter(foregroundUnselectedTint, PorterDuff.Mode.MULTIPLY));

    this.separatorView.setVisibility(View.GONE);
    this.deleteView.setVisibility(View.GONE);

    this.selected = Selected.NONE;
  }
}
项目:PeSanKita-android    文件:ScribbleToolbar.java   
public void setStickerSelected(boolean enabled) {
  if (enabled) {
    this.brushView.setBackground(null);
    this.brushView.setColorFilter(new PorterDuffColorFilter(foregroundUnselectedTint, PorterDuff.Mode.MULTIPLY));

    this.textView.setBackground(null);
    this.textView.setColorFilter(new PorterDuffColorFilter(foregroundUnselectedTint, PorterDuff.Mode.MULTIPLY));

    this.separatorView.setVisibility(View.VISIBLE);
    this.undoView.setVisibility(View.GONE);
    this.deleteView.setVisibility(View.VISIBLE);

    this.selected = Selected.STICKER;
  } else {
    this.separatorView.setVisibility(View.GONE);
    this.deleteView.setVisibility(View.GONE);

    this.selected = Selected.NONE;
  }
}
项目:AppFirCloud    文件:ResideLayout.java   
private void dimChildView(View v, float mag, int fadeColor) {
    final LayoutParams lp = (LayoutParams) v.getLayoutParams();

    if (mag > 0 && fadeColor != 0) {
        final int baseAlpha = (fadeColor & 0xff000000) >>> 24;
        int imag = (int) (baseAlpha * mag);
        int color = imag << 24 | (fadeColor & 0xffffff);
        if (lp.dimPaint == null) {
            lp.dimPaint = new Paint();
        }
        lp.dimPaint.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_OVER));
        if (ViewCompat.getLayerType(v) != ViewCompat.LAYER_TYPE_HARDWARE) {
            ViewCompat.setLayerType(v, ViewCompat.LAYER_TYPE_HARDWARE, lp.dimPaint);
        }
        invalidateChildRegion(v);
    } else if (ViewCompat.getLayerType(v) != ViewCompat.LAYER_TYPE_NONE) {
        if (lp.dimPaint != null) {
            lp.dimPaint.setColorFilter(null);
        }
        final DisableLayerRunnable dlr = new DisableLayerRunnable(v);
        mPostedRunnables.add(dlr);
        ViewCompat.postOnAnimation(this, dlr);
    }
}
项目:airgram    文件:DrawerActionCell.java   
public void setTextAndIcon(String text, int resId) {
    try {
        textView.setText(text);
        Drawable d= ContextCompat.getDrawable(getContext(), resId);
        d.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_ATOP));
        textView.setCompoundDrawablesWithIntrinsicBounds(d, null, null, null);
    } catch (Throwable e) {
        FileLog.e("tmessages", e);
    }
}
项目:airgram    文件:Switch.java   
@Override
public void setChecked(boolean checked) {
    super.setChecked(checked);

    checked = isChecked();

    if (attachedToWindow && wasLayout) {
        animateThumbToCheckedState(checked);
    } else {
        cancelPositionAnimator();
        setThumbPosition(checked ? 1 : 0);
    }

    if (mTrackDrawable != null) {
        mTrackDrawable.setColorFilter(new PorterDuffColorFilter(checked ? 0xffa0d6fa : 0xffc7c7c7, PorterDuff.Mode.MULTIPLY));
    }
    if (mThumbDrawable != null) {
        mThumbDrawable.setColorFilter(new PorterDuffColorFilter(checked ? 0xff45abef : 0xffededed, PorterDuff.Mode.MULTIPLY));
    }
}
项目:RX_Demo    文件:ResideLayout.java   
private void dimChildView(View v, float mag, int fadeColor) {
    final LayoutParams lp = (LayoutParams) v.getLayoutParams();

    if (mag > 0 && fadeColor != 0) {
        final int baseAlpha = (fadeColor & 0xff000000) >>> 24;
        int imag = (int) (baseAlpha * mag);
        int color = imag << 24 | (fadeColor & 0xffffff);
        if (lp.dimPaint == null) {
            lp.dimPaint = new Paint();
        }
        lp.dimPaint.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_OVER));
        if (ViewCompat.getLayerType(v) != ViewCompat.LAYER_TYPE_HARDWARE) {
            ViewCompat.setLayerType(v, ViewCompat.LAYER_TYPE_HARDWARE, lp.dimPaint);
        }
        invalidateChildRegion(v);
    } else if (ViewCompat.getLayerType(v) != ViewCompat.LAYER_TYPE_NONE) {
        if (lp.dimPaint != null) {
            lp.dimPaint.setColorFilter(null);
        }
        final DisableLayerRunnable dlr = new DisableLayerRunnable(v);
        mPostedRunnables.add(dlr);
        ViewCompat.postOnAnimation(this, dlr);
    }
}
项目:argus-android    文件:BaseFragment.java   
private void applyTheme(final View view) {
    ArgusTheme theme = Argus.getInstance().getArgusTheme();
    if (theme.getLogo() != 0) {
        ImageView iv = (ImageView) view.findViewById(R.id.iv_logo);
        if (iv != null) {
            iv.setImageResource(theme.getLogo());
        }
    }

    PorterDuffColorFilter filter = new PorterDuffColorFilter(
            ViewUtils.fetchAccentColor(getContext()), PorterDuff.Mode.MULTIPLY);
    ContextCompat.getDrawable(getContext(), R.drawable.email_icon).setColorFilter(filter);
    ContextCompat.getDrawable(getContext(), R.drawable.password_icon).setColorFilter(filter);
    ContextCompat.getDrawable(getContext(), R.drawable.icn_show_pwd).setColorFilter(filter);
    ContextCompat.getDrawable(getContext(), R.drawable.ic_hide_pwd).setColorFilter(filter);
}
项目:Picasso-transformations    文件:ColorFilterTransformation.java   
@Override public Bitmap transform(Bitmap source) {

    int width = source.getWidth();
    int height = source.getHeight();

    Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);

    Canvas canvas = new Canvas(bitmap);
    Paint paint = new Paint();
    paint.setAntiAlias(true);
    paint.setColorFilter(new PorterDuffColorFilter(mColor, PorterDuff.Mode.SRC_ATOP));
    canvas.drawBitmap(source, 0, 0, paint);
    source.recycle();

    return bitmap;
  }
项目:Hello-Music-droid    文件:Timber6.java   
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(
            R.layout.fragment_timber6, container, false);

    setMusicStateListener();
    setSongDetails(rootView);

    initGestures(rootView.findViewById(R.id.album_art));

    ((SeekBar) rootView.findViewById(R.id.song_progress)).getProgressDrawable().setColorFilter(new PorterDuffColorFilter(Color.WHITE, PorterDuff.Mode.MULTIPLY));
    ((SeekBar) rootView.findViewById(R.id.song_progress)).getThumb().setColorFilter(new PorterDuffColorFilter(Color.WHITE, PorterDuff.Mode.SRC_ATOP));

    nextSong = (TextView) rootView.findViewById(R.id.title_next);
    nextArt = (CircleImageView) rootView.findViewById(R.id.album_art_next);

    rootView.findViewById(R.id.nextView).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            MusicPlayer.setQueuePosition(MusicPlayer.getQueuePosition() + 1);
        }
    });

    return rootView;
}
项目:Cable-Android    文件:ScribbleToolbar.java   
public void setStickerSelected(boolean enabled) {
  if (enabled) {
    this.brushView.setBackground(null);
    this.brushView.setColorFilter(new PorterDuffColorFilter(foregroundUnselectedTint, PorterDuff.Mode.MULTIPLY));

    this.textView.setBackground(null);
    this.textView.setColorFilter(new PorterDuffColorFilter(foregroundUnselectedTint, PorterDuff.Mode.MULTIPLY));

    this.separatorView.setVisibility(View.VISIBLE);
    this.undoView.setVisibility(View.GONE);
    this.deleteView.setVisibility(View.VISIBLE);

    this.selected = Selected.STICKER;
  } else {
    this.separatorView.setVisibility(View.GONE);
    this.deleteView.setVisibility(View.GONE);

    this.selected = Selected.NONE;
  }
}
项目:silly-android    文件:ColoringTest.java   
/**
 * Tests the {@link Coloring#colorVectorDrawable(VectorDrawable, int)} method.
 * <p>
 * Unfortunately {@link VectorDrawable#setColorFilter(int, PorterDuff.Mode)} is not mocked in Android JAR yet.
 */
@Test
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public final void testColorVectorDrawable() {
    try {
        final VectorDrawable vectorDrawable = new VectorDrawable();
        assertNotNull("VectorDrawable is null", vectorDrawable);
        final VectorDrawable colored = Coloring.colorVectorDrawable(vectorDrawable, Color.RED);
        final PorterDuff.Mode mode = PorterDuff.Mode.SRC_ATOP;
        assertEquals("Vector color filter does not match", new PorterDuffColorFilter(Color.RED, mode), colored.getColorFilter());
    } catch (RuntimeException e) {
        boolean knownIssue = e.getMessage().contains("not mocked");
        if (!knownIssue) {
            e.printStackTrace();
        }
        assertTrue("Unknown error: " + e.getMessage(), knownIssue);
    }
}
项目:WechatChatroomHelper    文件:BGASwipeBackLayout.java   
private void dimChildView(View v, float mag, int fadeColor) {
    final LayoutParams lp = (LayoutParams) v.getLayoutParams();

    if (mag > 0 && fadeColor != 0) {
        final int baseAlpha = (fadeColor & 0xff000000) >>> 24;
        int imag = (int) (baseAlpha * mag);
        int color = imag << 24 | (fadeColor & 0xffffff);
        if (lp.dimPaint == null) {
            lp.dimPaint = new Paint();
        }
        lp.dimPaint.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_OVER));
        if (ViewCompat.getLayerType(v) != ViewCompat.LAYER_TYPE_HARDWARE) {
            ViewCompat.setLayerType(v, ViewCompat.LAYER_TYPE_HARDWARE, lp.dimPaint);
        }
        invalidateChildRegion(v);
    } else if (ViewCompat.getLayerType(v) != ViewCompat.LAYER_TYPE_NONE) {
        if (lp.dimPaint != null) {
            lp.dimPaint.setColorFilter(null);
        }
        final DisableLayerRunnable dlr = new DisableLayerRunnable(v);
        mPostedRunnables.add(dlr);
        ViewCompat.postOnAnimation(this, dlr);
    }
}
项目:letv    文件:SlidingPaneLayout.java   
private void dimChildView(View v, float mag, int fadeColor) {
    LayoutParams lp = (LayoutParams) v.getLayoutParams();
    if (mag > 0.0f && fadeColor != 0) {
        int color = (((int) (((float) ((-16777216 & fadeColor) >>> 24)) * mag)) << 24) | (ViewCompat.MEASURED_SIZE_MASK & fadeColor);
        if (lp.dimPaint == null) {
            lp.dimPaint = new Paint();
        }
        lp.dimPaint.setColorFilter(new PorterDuffColorFilter(color, Mode.SRC_OVER));
        if (ViewCompat.getLayerType(v) != 2) {
            ViewCompat.setLayerType(v, 2, lp.dimPaint);
        }
        invalidateChildRegion(v);
    } else if (ViewCompat.getLayerType(v) != 0) {
        if (lp.dimPaint != null) {
            lp.dimPaint.setColorFilter(null);
        }
        DisableLayerRunnable dlr = new DisableLayerRunnable(v);
        this.mPostedRunnables.add(dlr);
        ViewCompat.postOnAnimation(this, dlr);
    }
}
项目:Glide-transformations    文件:ColorFilterTransformation.java   
@Override
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
  Bitmap source = resource.get();

  int width = source.getWidth();
  int height = source.getHeight();

  Bitmap.Config config =
      source.getConfig() != null ? source.getConfig() : Bitmap.Config.ARGB_8888;
  Bitmap bitmap = mBitmapPool.get(width, height, config);
  if (bitmap == null) {
    bitmap = Bitmap.createBitmap(width, height, config);
  }

  Canvas canvas = new Canvas(bitmap);
  Paint paint = new Paint();
  paint.setAntiAlias(true);
  paint.setColorFilter(new PorterDuffColorFilter(mColor, PorterDuff.Mode.SRC_ATOP));
  canvas.drawBitmap(source, 0, 0, paint);

  return BitmapResource.obtain(bitmap, mBitmapPool);
}
项目:PasscodeView    文件:BoxFingerprint.java   
@SuppressWarnings("deprecation")
@Override
void draw(@NonNull Canvas canvas) {
    if (isFingerPrintBoxVisible) {
        //Show fingerprint icon
        Drawable d = getContext().getResources().getDrawable(R.drawable.ic_fingerprint);
        d.setBounds((int) (mBounds.exactCenterX() - mBounds.height() / 4),
                mBounds.top + 15,
                (int) (mBounds.exactCenterX() + mBounds.height() / 4),
                mBounds.top + mBounds.height() / 2 + 15);
        d.setColorFilter(new PorterDuffColorFilter(mStatusTextPaint.getColor(), PorterDuff.Mode.SRC_ATOP));
        d.draw(canvas);

        //Show finger print text
        canvas.drawText(mCurrentStatusText,
                mBounds.exactCenterX(),
                (float) (mBounds.top + (mBounds.height() / 1.3) - ((mStatusTextPaint.descent() + mStatusTextPaint.ascent()) / 2)),
                mStatusTextPaint);
    }
}
项目:IdeaTrackerPlus    文件:ToolbarColorizeHelper.java   
/**
 * It's important to set overflowDescription atribute in styles, so we can grab the reference
 * to the overflow icon. Check: res/values/styles.xml
 *
 * @param activity
 * @param colorFilter
 */
private static void setOverflowButtonColor(final Activity activity, final PorterDuffColorFilter colorFilter) {
    final String overflowDescription = activity.getString(R.string.abc_action_menu_overflow_description);
    final ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView();
    final ViewTreeObserver viewTreeObserver = decorView.getViewTreeObserver();
    viewTreeObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            final ArrayList<View> outViews = new ArrayList<View>();
            decorView.findViewsWithText(outViews, overflowDescription,
                    View.FIND_VIEWS_WITH_CONTENT_DESCRIPTION);
            if (outViews.isEmpty()) {
                return;
            }
            AppCompatImageView overflow = (AppCompatImageView) outViews.get(0);
            overflow.setColorFilter(colorFilter);
            removeOnGlobalLayoutListener(decorView, this);
        }
    });
}
项目:PlusGram    文件:Slate.java   
public void setPenColor(int color) {
            mPenColor = color;
            if (color == 0) {
                // eraser: DST_OUT
                mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OUT));
                mPaint.setColor(Color.BLACK);
            } else {
                mPaint.setXfermode(null);

                //mPaint.setColor(color); 
                mPaint.setColor(Color.BLACK); // or collor? or color & (mInkDensity << 24)?
                mPaint.setAlpha(mInkDensity);

//                mPaint.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_IN));
                mPaint.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_ATOP));
            }
        }
项目:PlusGram    文件:ToolButton.java   
@Override
public void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    if (mPaint == null) return;

    float x = 0.5f * getWidth();
    float y = 0.5f * getHeight();
    float r = Math.min(getWidth() - getPaddingLeft() - getPaddingRight(),
            getHeight() - getPaddingTop() - getPaddingBottom()) * 0.5f;


    int color = mFgColor.getColorForState(getDrawableState(), mFgColor.getDefaultColor());
    mPaint.setColor(color);
    mPaint.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_ATOP)); // SRC_IN ??
    tmpRF.set(x - r, y - r, x + r, y + r);

    canvas.drawBitmap(icon, frame, tmpRF, mPaint);
}
项目:Xndroid    文件:ThemeUtils.java   
/**
 * Gets the icon with an applied color filter
 * for the correct theme.
 *
 * @param context the context to use.
 * @param res     the drawable resource to use.
 * @param dark    true for icon suitable for use with a dark theme,
 *                false for icon suitable for use with a light theme.
 * @return a themed icon.
 */
@NonNull
public static Bitmap getThemedBitmap(@NonNull Context context, @DrawableRes int res, boolean dark) {
    int color = dark ? getIconDarkThemeColor(context) : getIconLightThemeColor(context);

    Bitmap sourceBitmap = getBitmapFromVectorDrawable(context, res);
    Bitmap resultBitmap = Bitmap.createBitmap(sourceBitmap.getWidth(), sourceBitmap.getHeight(),
        Bitmap.Config.ARGB_8888);
    Paint p = new Paint();
    ColorFilter filter = new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_IN);
    p.setColorFilter(filter);
    Canvas canvas = new Canvas(resultBitmap);
    canvas.drawBitmap(sourceBitmap, 0, 0, p);
    sourceBitmap.recycle();
    return resultBitmap;
}
项目:RetroMusicPlayer    文件:ToolbarColorizeHelper.java   
/**
 * It's important to set overflowDescription atribute in styles, so we can grab the reference
 * to the overflow icon. Check: res/values/styles.xml
 *
 * @param activity
 * @param colorFilter
 */
private static void setOverflowButtonColor(final Activity activity, final PorterDuffColorFilter colorFilter) {
    final String overflowDescription = activity.getString(R.string.abc_action_menu_overflow_description);
    final ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView();
    final ViewTreeObserver viewTreeObserver = decorView.getViewTreeObserver();
    viewTreeObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            final ArrayList<View> outViews = new ArrayList<View>();
            decorView.findViewsWithText(outViews, overflowDescription,
                    View.FIND_VIEWS_WITH_CONTENT_DESCRIPTION);
            if (outViews.isEmpty()) {
                return;
            }
            final ActionMenuView overflowViewParent = (ActionMenuView) outViews.get(0).getParent();
            overflowViewParent.getOverflowIcon().setColorFilter(colorFilter);
            removeOnGlobalLayoutListener(decorView, this);
        }
    });
}
项目:Cable-Android    文件:ScribbleToolbar.java   
public void setTextSelected(boolean enabled) {
  if (enabled) {
    this.brushView.setBackground(null);
    this.brushView.setColorFilter(new PorterDuffColorFilter(foregroundUnselectedTint, PorterDuff.Mode.MULTIPLY));

    this.textView.setBackground(background);
    this.textView.setColorFilter(new PorterDuffColorFilter(foregroundSelectedTint, PorterDuff.Mode.MULTIPLY));

    this.stickerView.setBackground(null);
    this.stickerView.setColorFilter(new PorterDuffColorFilter(foregroundUnselectedTint, PorterDuff.Mode.MULTIPLY));

    this.separatorView.setVisibility(View.VISIBLE);
    this.undoView.setVisibility(View.GONE);
    this.deleteView.setVisibility(View.VISIBLE);

    this.selected = Selected.TEXT;
  } else {
    this.textView.setBackground(null);
    this.textView.setColorFilter(new PorterDuffColorFilter(foregroundUnselectedTint, PorterDuff.Mode.MULTIPLY));

    this.separatorView.setVisibility(View.GONE);
    this.deleteView.setVisibility(View.GONE);

    this.selected = Selected.NONE;
  }
}
项目:Assertive-Touch    文件:ATButton.java   
public void setBackgroundColor(int color) {

        Drawable mDrawable = mApp.getResources().getDrawable(R.drawable.circle_button);
        mDrawable.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_IN));

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
            quickActionButton.setBackgroundDrawable(mDrawable);
        } else {
            quickActionButton.setBackground(mDrawable);
        }
    }
项目:GitHub    文件:Blur.java   
public static Bitmap of(Context context, Bitmap source, BlurFactor factor) {
  int width = factor.width / factor.sampling;
  int height = factor.height / factor.sampling;

  if (Helper.hasZero(width, height)) {
    return null;
  }

  Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);

  Canvas canvas = new Canvas(bitmap);
  canvas.scale(1 / (float) factor.sampling, 1 / (float) factor.sampling);
  Paint paint = new Paint();
  paint.setFlags(Paint.FILTER_BITMAP_FLAG | Paint.ANTI_ALIAS_FLAG);
  PorterDuffColorFilter filter =
      new PorterDuffColorFilter(factor.color, PorterDuff.Mode.SRC_ATOP);
  paint.setColorFilter(filter);
  canvas.drawBitmap(source, 0, 0, paint);

  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
    try {
      bitmap = Blur.rs(context, bitmap, factor.radius);
    } catch (RSRuntimeException e) {
      bitmap = Blur.stack(bitmap, factor.radius, true);
    }
  } else {
    bitmap = Blur.stack(bitmap, factor.radius, true);
  }

  if (factor.sampling == BlurFactor.DEFAULT_SAMPLING) {
    return bitmap;
  } else {
    Bitmap scaled = Bitmap.createScaledBitmap(bitmap, factor.width, factor.height, true);
    bitmap.recycle();
    return scaled;
  }
}
项目:Cable-Android    文件:ConversationUpdateItem.java   
private void setTimerRecord(final MessageRecord messageRecord) {
  if (messageRecord.getExpiresIn() > 0) {
    icon.setImageResource(R.drawable.ic_timer_white_24dp);
    icon.setColorFilter(new PorterDuffColorFilter(Color.parseColor("#757575"), PorterDuff.Mode.MULTIPLY));
  } else {
    icon.setImageResource(R.drawable.ic_timer_off_white_24dp);
    icon.setColorFilter(new PorterDuffColorFilter(Color.parseColor("#757575"), PorterDuff.Mode.MULTIPLY));
  }

  body.setText(messageRecord.getDisplayBody());
  date.setVisibility(View.GONE);
}
项目:GitHub    文件:ImageUtils.java   
/**
 * 快速模糊图片
 * <p>先缩小原图,对小图进行模糊,再放大回原先尺寸</p>
 *
 * @param src     源图片
 * @param scale   缩放比例(0...1)
 * @param radius  模糊半径(0...25)
 * @param recycle 是否回收
 * @return 模糊后的图片
 */
public static Bitmap fastBlur(final Bitmap src,
                              @FloatRange(from = 0, to = 1, fromInclusive = false) final float scale,
                              @FloatRange(from = 0, to = 25, fromInclusive = false) final float radius,
                              final boolean recycle) {
    if (isEmptyBitmap(src)) return null;
    int width = src.getWidth();
    int height = src.getHeight();
    Matrix matrix = new Matrix();
    matrix.setScale(scale, scale);
    Bitmap scaleBitmap = Bitmap.createBitmap(src, 0, 0, src.getWidth(), src.getHeight(), matrix, true);
    Paint paint = new Paint(Paint.FILTER_BITMAP_FLAG | Paint.ANTI_ALIAS_FLAG);
    Canvas canvas = new Canvas();
    PorterDuffColorFilter filter = new PorterDuffColorFilter(
            Color.TRANSPARENT, PorterDuff.Mode.SRC_ATOP);
    paint.setColorFilter(filter);
    canvas.scale(scale, scale);
    canvas.drawBitmap(scaleBitmap, 0, 0, paint);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        scaleBitmap = renderScriptBlur(scaleBitmap, radius, recycle);
    } else {
        scaleBitmap = stackBlur(scaleBitmap, (int) radius, recycle);
    }
    if (scale == 1) return scaleBitmap;
    Bitmap ret = Bitmap.createScaledBitmap(scaleBitmap, width, height, true);
    if (scaleBitmap != null && !scaleBitmap.isRecycled()) scaleBitmap.recycle();
    if (recycle && !src.isRecycled()) src.recycle();
    return ret;
}
项目:GitHub    文件:ToastUtils.java   
private static void setBgAndGravity() {
    View toastView = sToast.getView();
    if (bgResource != -1) {
        toastView.setBackgroundResource(bgResource);
    } else if (bgColor != COLOR_DEFAULT) {
        Drawable background = toastView.getBackground();
        background.setColorFilter(new PorterDuffColorFilter(bgColor, PorterDuff.Mode.SRC_IN));
    }
    sToast.setGravity(gravity, xOffset, yOffset);
}
项目:Android-UtilCode    文件:ImageUtils.java   
/**
 * 快速模糊图片
 * <p>先缩小原图,对小图进行模糊,再放大回原先尺寸</p>
 *
 * @param src     源图片
 * @param scale   缩放比例(0...1)
 * @param radius  模糊半径(0...25)
 * @param recycle 是否回收
 * @return 模糊后的图片
 */
public static Bitmap fastBlur(Bitmap src,
                              @FloatRange(from = 0, to = 1, fromInclusive = false) float scale,
                              @FloatRange(from = 0, to = 25, fromInclusive = false) float radius,
                              boolean recycle) {
    if (isEmptyBitmap(src)) return null;
    int width = src.getWidth();
    int height = src.getHeight();
    int scaleWidth = (int) (width * scale + 0.5f);
    int scaleHeight = (int) (height * scale + 0.5f);
    if (scaleWidth == 0 || scaleHeight == 0) return null;
    Bitmap scaleBitmap = Bitmap.createScaledBitmap(src, scaleWidth, scaleHeight, true);
    Paint paint = new Paint(Paint.FILTER_BITMAP_FLAG | Paint.ANTI_ALIAS_FLAG);
    Canvas canvas = new Canvas();
    PorterDuffColorFilter filter = new PorterDuffColorFilter(
            Color.TRANSPARENT, PorterDuff.Mode.SRC_ATOP);
    paint.setColorFilter(filter);
    canvas.scale(scale, scale);
    canvas.drawBitmap(scaleBitmap, 0, 0, paint);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        scaleBitmap = renderScriptBlur(scaleBitmap, radius);
    } else {
        scaleBitmap = stackBlur(scaleBitmap, (int) radius, recycle);
    }
    if (scale == 1) return scaleBitmap;
    Bitmap ret = Bitmap.createScaledBitmap(scaleBitmap, width, height, true);
    if (scaleBitmap != null && !scaleBitmap.isRecycled()) scaleBitmap.recycle();
    if (recycle && !src.isRecycled()) src.recycle();
    return ret;
}
项目:PeSanKita-android    文件:ConversationUpdateItem.java   
private void setTimerRecord(final MessageRecord messageRecord) {
  if (messageRecord.getExpiresIn() > 0) {
    icon.setImageResource(R.drawable.ic_timer_white_24dp);
    icon.setColorFilter(new PorterDuffColorFilter(Color.parseColor("#757575"), PorterDuff.Mode.MULTIPLY));
  } else {
    icon.setImageResource(R.drawable.ic_timer_off_white_24dp);
    icon.setColorFilter(new PorterDuffColorFilter(Color.parseColor("#757575"), PorterDuff.Mode.MULTIPLY));
  }

  body.setText(messageRecord.getDisplayBody());
  date.setVisibility(View.GONE);
}
项目:ePills    文件:AddPillSetTime.java   
/**
 * Selects the Day on position 'index'.
 * @param index
 * @param dayLayout
 * @param check: True if checkDays() should be called.
 */
private void activateDay(int index, LinearLayout dayLayout, boolean check) {
    weekdaysSelection[index] = true;

    dayLayout.setTag(true);
    Drawable bg = ContextCompat.getDrawable(getBaseContext(), R.drawable.circle_step);
    int colorPrimary = ContextCompat.getColor(getBaseContext(), R.color.accent);
    bg.setColorFilter(new PorterDuffColorFilter(colorPrimary, PorterDuff.Mode.SRC_IN));
    dayLayout.setBackground(bg);
    TextView day = (TextView) dayLayout.findViewById(R.id.day);
    day.setTextColor(ContextCompat.getColor(getBaseContext(),R.color.md_white_1000));
    if(check) {
        checkDays();
    }
}
项目:PeSanKita-android    文件:HourglassView.java   
public HourglassView(Context context, AttributeSet attrs, int defStyleAttr) {
  super(context, attrs, defStyleAttr);

  if (attrs != null) {
    TypedArray typedArray = context.getTheme().obtainStyledAttributes(attrs, R.styleable.HourglassView, 0, 0);
    this.empty = BitmapFactory.decodeResource(getResources(), typedArray.getResourceId(R.styleable.HourglassView_empty, 0));
    this.full  = BitmapFactory.decodeResource(getResources(), typedArray.getResourceId(R.styleable.HourglassView_full, 0));
    this.tint  = typedArray.getColor(R.styleable.HourglassView_tint, 0);
    this.percentage = typedArray.getInt(R.styleable.HourglassView_percentage, 50);
    this.offset = typedArray.getInt(R.styleable.HourglassView_offset, 0);
    typedArray.recycle();
  }

  this.backgroundPaint = new Paint();
  this.foregroundPaint = new Paint();
  this.progressPaint   = new Paint();

  this.backgroundPaint.setColorFilter(new PorterDuffColorFilter(tint, PorterDuff.Mode.MULTIPLY));
  this.foregroundPaint.setColorFilter(new PorterDuffColorFilter(tint, PorterDuff.Mode.MULTIPLY));

  this.progressPaint.setColor(getResources().getColor(R.color.black));
  this.progressPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));

  if (android.os.Build.VERSION.SDK_INT >= 11)
  {
    setLayerType(View.LAYER_TYPE_SOFTWARE, null);
  }
}
项目:Hitalk    文件:BGAQRCodeUtil.java   
public static Bitmap makeTintBitmap(Bitmap inputBitmap, int tintColor) {
    if (inputBitmap == null) {
        return null;
    }

    Bitmap outputBitmap = Bitmap.createBitmap(inputBitmap.getWidth(), inputBitmap.getHeight(), inputBitmap.getConfig());
    Canvas canvas = new Canvas(outputBitmap);
    Paint paint = new Paint();
    paint.setColorFilter(new PorterDuffColorFilter(tintColor, PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(inputBitmap, 0, 0, paint);
    return outputBitmap;
}
项目:qmui    文件:QMUIRadiusImageView.java   
public void setSelectedMaskColor(@ColorInt int selectedMaskColor) {
    if (mSelectedMaskColor != selectedMaskColor) {
        mSelectedMaskColor = selectedMaskColor;
        if (mSelectedMaskColor != Color.TRANSPARENT) {
            mSelectedColorFilter = new PorterDuffColorFilter(mSelectedMaskColor, PorterDuff.Mode.DARKEN);
        } else {
            mSelectedColorFilter = null;
        }
        if (mIsSelected) {
            invalidate();
        }
    }
    mSelectedMaskColor = selectedMaskColor;
}
项目:MediaNotification    文件:ImageUtils.java   
public static Bitmap setBitmapColor(Bitmap bitmap, int color) {
    Bitmap result = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth() - 1, bitmap.getHeight() - 1);
    Paint paint = new Paint();
    paint.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_ATOP));

    Canvas canvas = new Canvas(result);
    canvas.drawBitmap(result, 0, 0, paint);

    return result;
}