Java Code Examples for android.graphics.ColorFilter

The following examples show how to use android.graphics.ColorFilter. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: arcusandroid   Source File: ArcusProductFragment.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * convert the current screen color to grey
 * @param apply apply grey scale or not
 */
private void applyGreyScale(final boolean apply){

    ColorMatrix cm = new ColorMatrix();
    cm.setSaturation(0f);
    final ColorFilter filter = new ColorMatrixColorFilter(cm);

    if (apply) {
        if (deviceImage != null) this.deviceImage.setColorFilter(filter);
        if (this.leftNav != null) this.leftNav.setColorFilter(null);
        if (this.rightNav != null) this.rightNav.setColorFilter(null);
        if (this.bottomView != null && !isBottomViewAlerting) this.bottomView.getBackground().setColorFilter(filter);
    } else {
        if (deviceImage != null) this.deviceImage.setColorFilter(null);
        if (this.leftNav != null) this.leftNav.setColorFilter(null);
        if (this.rightNav != null) this.rightNav.setColorFilter(null);
        if (this.bottomView != null && !isBottomViewAlerting) this.bottomView.getBackground().setColorFilter(null);
    }
}
 
Example 2
Source Project: arcusandroid   Source File: HaloFragment.java    License: Apache License 2.0 6 votes vote down vote up
@Override protected ColorFilter getOnlineColorFilter() {
    if (haloModel == null || mView == null) {
        return null;
    }

    View colorOverlayView = mView.findViewById(R.id.color_overlay);
    if (colorOverlayView == null) {
        return null;
    }

    boolean applyFilter = haloModel.isOnline() && isVisible();
    colorOverlayView.setVisibility(applyFilter ? View.VISIBLE : View.GONE);

    if(applyFilter) {
        float [] colorHSV = new float[]{ haloModel.getHue(), (haloModel.getSaturation() / 100f), 1f};
        colorOverlayView.setBackgroundColor(Color.HSVToColor(25, colorHSV));

        ColorMatrix cm = new ColorMatrix();
        cm.setSaturation(0f);
        return new ColorMatrixColorFilter(cm);
    }

    return null;
}
 
Example 3
Source Project: arcusandroid   Source File: HueFallbackFragment.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void updateBackground(boolean isConnected) {
    try {
        ColorMatrix cm = new ColorMatrix();
        cm.setSaturation(0f);
        final ColorFilter filter = new ColorMatrixColorFilter(cm);
        final View bgView = ImageManager.getWallpaperView();
        if (bgView != null) {
            final Drawable bgDrawable = bgView.getBackground();
            if (bgDrawable != null) {
                bgDrawable.setColorFilter(filter);
            }
        }
    }catch (Exception e){
        logger.error("Can't change background color filter: {}", e);
    }
}
 
Example 4
Source Project: arcusandroid   Source File: DimmerFragment.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected ColorFilter getOnlineColorFilter() {
    View colorOverlayView = mView.findViewById(R.id.color_overlay);
    if(getDeviceModel() != null && isVisible() && Light.COLORMODE_COLOR.equals(getDeviceModel().get(Light.ATTR_COLORMODE)) && !DeviceConnection.STATE_OFFLINE.equals(getDeviceModel().get(DeviceConnection.ATTR_STATE))) {
        int colorOverlay = getColorFilterValue();
        if(colorOverlay != 0) {
            colorOverlayView.setVisibility(View.VISIBLE);
            colorOverlayView.setBackgroundColor(colorOverlay);
            //colorOverlayView.getBackground().setColorFilter(new PorterDuffColorFilter(colorOverlay, PorterDuff.Mode.SRC_OVER));
        }
        ColorMatrix cm = new ColorMatrix();
        cm.setSaturation(0f);
        return new ColorMatrixColorFilter(cm);
    }
    else {
        colorOverlayView.setVisibility(View.GONE);
    }
    return null;
}
 
Example 5
Source Project: arcusandroid   Source File: BaseFragment.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * update background color based on the current device connectivity
 */
public void updateBackground(boolean isConnected) {
    try {
        ColorMatrix cm = new ColorMatrix();
        cm.setSaturation(0f);
        final ColorFilter filter = new ColorMatrixColorFilter(cm);
        final ColorFilter filterOnline = getOnlineColorFilter();
        final View bgView = ImageManager.getWallpaperView();
        if (bgView != null) {
            final Drawable bgDrawable = bgView.getBackground();
            if (bgDrawable != null) {
                bgDrawable.setColorFilter(isConnected ? filterOnline : filter);
            }
        }
        if(this instanceof ArcusProductFragment) {
            final ArcusProductFragment fragment = (ArcusProductFragment) this;
            fragment.setEnabled(isConnected);
        }
        if(callback != null) {
            callback.backgroundUpdated();
        }
    }catch (Exception e){
        logger.error("Can't change background color filter: {}", e);
    }
}
 
Example 6
Source Project: android_9.0.0_r45   Source File: ScrollBarDrawable.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void setColorFilter(ColorFilter colorFilter) {
    mColorFilter = colorFilter;
    mHasSetColorFilter = true;

    if (mVerticalTrack != null) {
        mVerticalTrack.setColorFilter(colorFilter);
    }
    if (mVerticalThumb != null) {
        mVerticalThumb.setColorFilter(colorFilter);
    }
    if (mHorizontalTrack != null) {
        mHorizontalTrack.setColorFilter(colorFilter);
    }
    if (mHorizontalThumb != null) {
        mHorizontalThumb.setColorFilter(colorFilter);
    }
}
 
Example 7
Source Project: SmartLoadingView   Source File: CircleImageView.java    License: MIT License 5 votes vote down vote up
@Override
public void setColorFilter(ColorFilter cf) {
    if (cf == mColorFilter) {
        return;
    }

    mColorFilter = cf;
    mBitmapPaint.setColorFilter(mColorFilter);
    invalidate();
}
 
Example 8
Source Project: android_9.0.0_r45   Source File: ImageView.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Apply an arbitrary colorfilter to the image.
 *
 * @param cf the colorfilter to apply (may be null)
 *
 * @see #getColorFilter()
 */
public void setColorFilter(ColorFilter cf) {
    if (mColorFilter != cf) {
        mColorFilter = cf;
        mHasColorFilter = true;
        mColorMod = true;
        applyColorMod();
        invalidate();
    }
}
 
Example 9
Source Project: candybar   Source File: RoundedBitmapDisplayer.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void setColorFilter(ColorFilter cf) {
    paint.setColorFilter(cf);
}
 
Example 10
Source Project: Folivora   Source File: WindmillDrawable.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void setColorFilter(@Nullable ColorFilter colorFilter) {
  mPaint.setColorFilter(colorFilter);
}
 
Example 11
Source Project: mollyim-android   Source File: ContactChip.java    License: GNU General Public License v3.0 4 votes vote down vote up
@Override
public void setColorFilter(@Nullable ColorFilter colorFilter) {
}
 
Example 12
private ColorFilter getIconTintFilter() {
  return new PorterDuffColorFilter(ThemeUtil.getThemedColor(getContext(), R.attr.icon_tint), PorterDuff.Mode.SRC_IN);
}
 
Example 13
@Override
public void setColorFilter(ColorFilter cf) { }
 
Example 14
@Override
public void setDrawable(final String url,
                        final DrawableTarget drawableTarget,
                        final DrawableStrategy drawableStrategy) {
  WXSDKManager.getInstance().postOnUiThread(new Runnable() {
    @Override
    public void run() {
      String temp = url;
      if (url.startsWith("//")) {
        temp = "http:" + url;
      }

      /** This is a hack for picasso, as Picasso hold weakReference to Target.
       * http://stackoverflow.com/questions/24180805/onbitmaploaded-of-target-object-not-called-on-first-load
       */
      class PlaceHolderDrawableTarget extends Drawable implements Target {

        @Override
        public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
          BitmapDrawable bitmapDrawable = new BitmapDrawable(mContext.getResources(), bitmap);
          bitmapDrawable.setGravity(Gravity.FILL);
          drawableTarget.setDrawable(bitmapDrawable, true);
        }

        @Override
        public void onBitmapFailed(Drawable errorDrawable) {

        }

        @Override
        public void onPrepareLoad(Drawable placeHolderDrawable) {
          drawableTarget.setDrawable(this, true);
        }

        @Override
        public void draw(Canvas canvas) {

        }

        @Override
        public void setAlpha(int alpha) {

        }

        @Override
        public void setColorFilter(ColorFilter colorFilter) {

        }

        @Override
        public int getOpacity() {
          return PixelFormat.UNKNOWN;
        }
      }
      Picasso.
              with(mContext).
              load(temp).
              resize(drawableStrategy.width, drawableStrategy.height).
              onlyScaleDown().
              into(new PlaceHolderDrawableTarget());
    }
  }, 0);

}
 
Example 15
@Override
public void setColorFilter(ColorFilter colorFilter) {
    paint.setColorFilter(colorFilter);
}
 
Example 16
Source Project: arcusandroid   Source File: HueFallbackFragment.java    License: Apache License 2.0 4 votes vote down vote up
@Override
protected ColorFilter getOnlineColorFilter() {
    ColorMatrix cm = new ColorMatrix();
    cm.setSaturation(0f);
    return new ColorMatrixColorFilter(cm);
}
 
Example 17
Source Project: arcusandroid   Source File: BaseFragment.java    License: Apache License 2.0 4 votes vote down vote up
protected ColorFilter getOnlineColorFilter() {
    return null;
}
 
Example 18
Source Project: arcusandroid   Source File: ComboSeekBarSlider.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void setColorFilter(ColorFilter cf) {
}
 
Example 19
Source Project: arcusandroid   Source File: ComboSeekBarThumb.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void setColorFilter(ColorFilter cf) {
}
 
Example 20
Source Project: SegmentedButton   Source File: BadgeDrawable.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void setColorFilter(ColorFilter cf) {
    paint.setColorFilter(cf);
}
 
Example 21
Source Project: tysq-android   Source File: WheelDrawable.java    License: GNU General Public License v3.0 4 votes vote down vote up
@Override
public void setColorFilter(ColorFilter colorFilter) {
}
 
Example 22
Source Project: fastedit   Source File: EditBar.java    License: Apache License 2.0 4 votes vote down vote up
public EditBar(FastEdit fastEdit) {
    super(fastEdit.getContext());
    this.fastEdit = fastEdit;
    this.context = fastEdit.getContext();
    contentView = LayoutInflater.from(context).inflate(R.layout.fe_layout_edit, null);
    setContentView(contentView);
    contentView.measure(fastEdit.getWidth(), fastEdit.getHeight());
    setWidth(contentView.getMeasuredWidth());
    setHeight(contentView.getMeasuredHeight());
    initView();
    setOutsideTouchable(true);
    paint = new Paint();
    setBackgroundDrawable(null);
    contentView.setBackgroundDrawable(new Drawable() {
        @Override
        public void draw(Canvas canvas) {
            int shadowWidth = contentView.getPaddingTop();
            paint.setColor(0x33000000);
            paint.setMaskFilter(new BlurMaskFilter(shadowWidth, BlurMaskFilter.Blur.OUTER));
            canvas.drawRoundRect(shadowWidth,
                    shadowWidth,
                    getWidth() - shadowWidth,
                    getHeight() - shadowWidth,
                    shadowWidth, shadowWidth,
                    paint);
            paint.reset();
            paint.setColor(Color.WHITE);
            canvas.drawRoundRect(shadowWidth,
                    shadowWidth,
                    getWidth() - shadowWidth,
                    getHeight() - shadowWidth,
                    shadowWidth, shadowWidth,
                    paint);
        }

        @Override
        public void setAlpha(int alpha) {

        }

        @Override
        public void setColorFilter(ColorFilter colorFilter) {

        }


        @Override
        public int getOpacity() {
            return 0;
        }
    });

}
 
Example 23
Source Project: fastedit   Source File: SelectBar.java    License: Apache License 2.0 4 votes vote down vote up
public SelectBar(FastEdit fastEdit) {
    super(fastEdit.getContext());
    this.fastEdit = fastEdit;
    this.context = fastEdit.getContext();
    contentView = LayoutInflater.from(context).inflate(R.layout.fe_layout_select, null);
    setContentView(contentView);
    contentView.measure(fastEdit.getWidth(), fastEdit.getHeight());
    setWidth(contentView.getMeasuredWidth());
    setHeight(contentView.getMeasuredHeight());
    initView();
    paint = new Paint();
    setBackgroundDrawable(null);
    contentView.setBackgroundDrawable(new Drawable() {
        @Override
        public void draw(Canvas canvas) {
            int shadowWidth = contentView.getPaddingTop();
            paint.setColor(0x33000000);
            paint.setMaskFilter(new BlurMaskFilter(shadowWidth, BlurMaskFilter.Blur.OUTER));
            canvas.drawRoundRect(shadowWidth,
                    shadowWidth,
                    getWidth() - shadowWidth,
                    getHeight() - shadowWidth,
                    shadowWidth, shadowWidth,
                    paint);
            paint.reset();
            paint.setColor(Color.WHITE);
            canvas.drawRoundRect(shadowWidth,
                    shadowWidth,
                    getWidth() - shadowWidth,
                    getHeight() - shadowWidth,
                    shadowWidth, shadowWidth,
                    paint);
        }

        @Override
        public void setAlpha(int alpha) {

        }

        @Override
        public void setColorFilter(ColorFilter colorFilter) {

        }


        @Override
        public int getOpacity() {
            return 0;
        }
    });

}
 
Example 24
@Override
public void setColorFilter(ColorFilter cf)
{
    emptyDrawable.setColorFilter(cf);
    fullDrawable.setColorFilter(cf);
}
 
Example 25
Source Project: giffun   Source File: GifDrawable.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void setColorFilter(ColorFilter colorFilter) {
    paint.setColorFilter(colorFilter);
}
 
Example 26
Source Project: giffun   Source File: GlideBitmapDrawable.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void setColorFilter(ColorFilter colorFilter) {
    state.setColorFilter(colorFilter);
    invalidateSelf();
}
 
Example 27
Source Project: giffun   Source File: GlideBitmapDrawable.java    License: Apache License 2.0 4 votes vote down vote up
void setColorFilter(ColorFilter colorFilter) {
    mutatePaint();
    paint.setColorFilter(colorFilter);
}
 
Example 28
Source Project: animation-samples   Source File: TextResize.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void setColorFilter(ColorFilter colorFilter) {
    paint.setColorFilter(colorFilter);
}
 
Example 29
Source Project: EasyPhotos   Source File: FastBitmapDrawable.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void setColorFilter(ColorFilter cf) {
    mPaint.setColorFilter(cf);
}
 
Example 30
Source Project: bcm-android   Source File: EmojiProvider.java    License: GNU General Public License v3.0 4 votes vote down vote up
@Override
public void setColorFilter(ColorFilter cf) { }