use of android.graphics.ColorFilter in project Lightning-Browser by anthonycr.
the class ThemeUtils method getThemedBitmap.
/**
* 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;
}
use of android.graphics.ColorFilter in project devbricks by dailystudio.
the class GifImageView method setViewAttributes.
@SuppressLint("NewApi")
private void setViewAttributes(Context context, AttributeSet attrs, int defStyle) {
/**
* Starting from HONEYCOMB have to turn off HW acceleration to draw
* Movie on Canvas.
*/
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
setLayerType(View.LAYER_TYPE_SOFTWARE, null);
}
final TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.GifMovieView, defStyle, 0);
if (array.hasValue(R.styleable.GifMovieView_tintColor)) {
mTintColor = array.getColor(R.styleable.GifMovieView_tintColor, ColorHelper.getColorResource(getContext(), R.color.android_blue));
mHasTintColor = true;
}
mMovieResourceId = array.getResourceId(R.styleable.GifMovieView_gif, -1);
mPaused = array.getBoolean(R.styleable.GifMovieView_paused, false);
mFillCanvas = array.getBoolean(R.styleable.GifMovieView_fill, false);
array.recycle();
if (mMovieResourceId != -1) {
mMovie = Movie.decodeStream(getResources().openRawResource(mMovieResourceId));
}
if (mHasTintColor) {
mTintPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
ColorFilter filter = new PorterDuffColorFilter(mTintColor, PorterDuff.Mode.SRC_ATOP);
mTintPaint.setColorFilter(filter);
}
}
use of android.graphics.ColorFilter in project GzuClassSchedule by mnnyang.
the class WheelView method setBackgroundDrawable.
@Override
public void setBackgroundDrawable(Drawable background) {
if (viewWidth == 0) {
viewWidth = ((Activity) context).getWindowManager().getDefaultDisplay().getWidth();
Log.d(TAG, "viewWidth: " + viewWidth);
}
if (null == paint) {
paint = new Paint();
paint.setColor(ColorUtil.getColor(context, R.attr.colorPrimary));
paint.setStrokeWidth(dip2px(1f));
}
background = new Drawable() {
@Override
public void draw(Canvas canvas) {
canvas.drawLine(viewWidth * 1 / 6, obtainSelectedAreaBorder()[0], viewWidth * 5 / 6, obtainSelectedAreaBorder()[0], paint);
canvas.drawLine(viewWidth * 1 / 6, obtainSelectedAreaBorder()[1], viewWidth * 5 / 6, obtainSelectedAreaBorder()[1], paint);
}
@Override
public void setAlpha(int alpha) {
}
@Override
public void setColorFilter(ColorFilter cf) {
}
@SuppressLint("WrongConstant")
@Override
public int getOpacity() {
return 0;
}
};
super.setBackgroundDrawable(background);
}
use of android.graphics.ColorFilter in project android_packages_apps_Dialer by LineageOS.
the class PseudoEmergencyAnimator method start.
public void start() {
if (mPseudoEmergencyColorAnimator == null) {
Integer colorFrom = Color.BLUE;
Integer colorTo = Color.RED;
mPseudoEmergencyColorAnimator = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo);
mPseudoEmergencyColorAnimator.addUpdateListener(new AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animator) {
try {
int color = (int) animator.getAnimatedValue();
ColorFilter colorFilter = new LightingColorFilter(Color.BLACK, color);
View floatingActionButtonContainer = getView().findViewById(R.id.floating_action_button);
if (floatingActionButtonContainer != null) {
floatingActionButtonContainer.getBackground().setColorFilter(colorFilter);
}
} catch (Exception e) {
animator.cancel();
}
}
});
mPseudoEmergencyColorAnimator.addListener(new AnimatorListener() {
@Override
public void onAnimationCancel(Animator animation) {
}
@Override
public void onAnimationRepeat(Animator animation) {
try {
vibrate(VIBRATE_LENGTH_MILLIS);
} catch (Exception e) {
animation.cancel();
}
}
@Override
public void onAnimationStart(Animator animation) {
}
@Override
public void onAnimationEnd(Animator animation) {
try {
View floatingActionButtonContainer = getView().findViewById(R.id.floating_action_button);
if (floatingActionButtonContainer != null) {
floatingActionButtonContainer.getBackground().clearColorFilter();
}
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
try {
vibrate(VIBRATE_LENGTH_MILLIS);
} catch (Exception e) {
// ignored
}
}
}, ITERATION_LENGTH_MILLIS);
} catch (Exception e) {
animation.cancel();
}
}
});
mPseudoEmergencyColorAnimator.setDuration(VIBRATE_LENGTH_MILLIS);
mPseudoEmergencyColorAnimator.setRepeatMode(ValueAnimator.REVERSE);
mPseudoEmergencyColorAnimator.setRepeatCount(ANIMATION_ITERATION_COUNT);
}
if (!mPseudoEmergencyColorAnimator.isStarted()) {
mPseudoEmergencyColorAnimator.start();
}
}
use of android.graphics.ColorFilter in project PhoneProfiles by henrichg.
the class BitmapManipulator method recolorBitmap.
static Bitmap recolorBitmap(Bitmap bitmap, int color) {
if (bitmap == null)
return null;
Bitmap colorBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), bitmap.getConfig());
// Config.ARGB_8888);
Canvas canvas = new Canvas(colorBitmap);
Paint paint = new Paint();
Matrix matrix = new Matrix();
ColorFilter filter = new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_ATOP);
paint.setColorFilter(filter);
canvas.drawBitmap(bitmap, matrix, paint);
return colorBitmap;
}
Aggregations