Java Code Examples for android.graphics.PorterDuffColorFilter

The following are top voted examples for showing how to use android.graphics.PorterDuffColorFilter. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: airgram   File: DrawerProfileCell.java   View source code 7 votes vote down vote up
@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);
    }
}
 
Example 2
Project: WechatChatroomHelper   File: BGASwipeBackLayout2.java   View source code 6 votes vote down vote up
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);
    }
}
 
Example 3
Project: HoldingButton   File: HoldingDrawable.java   View source code 6 votes vote down vote up
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;
    }
}
 
Example 4
Project: android_ui   File: TintLayerDrawable.java   View source code 6 votes vote down vote up
/**
 * 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;
}
 
Example 5
Project: android_ui   File: TintDrawable.java   View source code 6 votes vote down vote up
/**
 * 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;
}
 
Example 6
Project: react-native-andorid-shadow   File: ShadowParentView.java   View source code 6 votes vote down vote up
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);
}
 
Example 7
Project: PeSanKita-android   File: ScribbleToolbar.java   View source code 6 votes vote down vote up
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;
  }
}
 
Example 8
Project: PeSanKita-android   File: ScribbleToolbar.java   View source code 6 votes vote down vote up
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;
  }
}
 
Example 9
Project: PeSanKita-android   File: ScribbleToolbar.java   View source code 6 votes vote down vote up
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;
  }
}
 
Example 10
Project: AppFirCloud   File: ResideLayout.java   View source code 6 votes vote down vote up
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);
    }
}
 
Example 11
Project: airgram   File: DrawerActionCell.java   View source code 6 votes vote down vote up
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);
    }
}
 
Example 12
Project: airgram   File: Switch.java   View source code 6 votes vote down vote up
@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));
    }
}
 
Example 13
Project: RX_Demo   File: ResideLayout.java   View source code 6 votes vote down vote up
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);
    }
}
 
Example 14
Project: argus-android   File: BaseFragment.java   View source code 6 votes vote down vote up
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);
}
 
Example 15
Project: Picasso-transformations   File: ColorFilterTransformation.java   View source code 6 votes vote down vote up
@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;
  }
 
Example 16
Project: Cable-Android   File: ScribbleToolbar.java   View source code 6 votes vote down vote up
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;
  }
}
 
Example 17
Project: silly-android   File: ColoringTest.java   View source code 6 votes vote down vote up
/**
 * 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);
    }
}
 
Example 18
Project: WechatChatroomHelper   File: BGASwipeBackLayout.java   View source code 6 votes vote down vote up
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);
    }
}
 
Example 19
Project: letv   File: SlidingPaneLayout.java   View source code 6 votes vote down vote up
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);
    }
}
 
Example 20
Project: Glide-transformations   File: ColorFilterTransformation.java   View source code 6 votes vote down vote up
@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);
}
 
Example 21
Project: PasscodeView   File: BoxFingerprint.java   View source code 6 votes vote down vote up
@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);
    }
}
 
Example 22
Project: IdeaTrackerPlus   File: ToolbarColorizeHelper.java   View source code 6 votes vote down vote up
/**
 * 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);
        }
    });
}
 
Example 23
Project: PlusGram   File: Slate.java   View source code 6 votes vote down vote up
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));
            }
        }
 
Example 24
Project: PlusGram   File: ToolButton.java   View source code 6 votes vote down vote up
@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);
}
 
Example 25
Project: Xndroid   File: ThemeUtils.java   View source code 6 votes vote down vote up
/**
 * 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;
}
 
Example 26
Project: RetroMusicPlayer   File: ToolbarColorizeHelper.java   View source code 6 votes vote down vote up
/**
 * 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);
        }
    });
}
 
Example 27
Project: Cable-Android   File: ScribbleToolbar.java   View source code 6 votes vote down vote up
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;
  }
}
 
Example 28
Project: GitHub   File: Blur.java   View source code 5 votes vote down vote up
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;
  }
}
 
Example 29
Project: Cable-Android   File: ConversationUpdateItem.java   View source code 5 votes vote down vote up
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);
}
 
Example 30
Project: GitHub   File: ImageUtils.java   View source code 5 votes vote down vote up
/**
 * 快速模糊图片
 * <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;
}
 
Example 31
Project: GitHub   File: ToastUtils.java   View source code 5 votes vote down vote up
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);
}
 
Example 32
Project: Android-UtilCode   File: ImageUtils.java   View source code 5 votes vote down vote up
/**
 * 快速模糊图片
 * <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;
}
 
Example 33
Project: PeSanKita-android   File: ConversationUpdateItem.java   View source code 5 votes vote down vote up
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);
}
 
Example 34
Project: ePills   File: AddPillSetTime.java   View source code 5 votes vote down vote up
/**
 * 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();
    }
}
 
Example 35
Project: PeSanKita-android   File: HourglassView.java   View source code 5 votes vote down vote up
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);
  }
}
 
Example 36
Project: Hitalk   File: BGAQRCodeUtil.java   View source code 5 votes vote down vote up
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;
}
 
Example 37
Project: qmui   File: QMUIRadiusImageView.java   View source code 5 votes vote down vote up
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;
}
 
Example 38
Project: MediaNotification   File: ImageUtils.java   View source code 5 votes vote down vote up
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;
}
 
Example 39
Project: Hello-Music-droid   File: FolderAdapter.java   View source code 5 votes vote down vote up
public void applyTheme(boolean dark) {
    ColorFilter cf = new PorterDuffColorFilter(Color.WHITE, PorterDuff.Mode.SRC_ATOP);
    for (Drawable d : mIcons) {
        if (dark) {
            d.setColorFilter(cf);
        } else {
            d.clearColorFilter();
        }
    }
}
 
Example 40
Project: Hello-Music-droid   File: Timber6.java   View source code 5 votes vote down vote up
@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;
}