Example usage for android.graphics BlurMaskFilter BlurMaskFilter

List of usage examples for android.graphics BlurMaskFilter BlurMaskFilter

Introduction

In this page you can find the example usage for android.graphics BlurMaskFilter BlurMaskFilter.

Prototype

public BlurMaskFilter(float radius, Blur style) 

Source Link

Document

Create a blur maskfilter.

Usage

From source file:com.breel.wearables.shadowclock.graphics.ShapeShadow.java

public void setupBlur(float _amout) {
    blurMaskFilter = new BlurMaskFilter(_amout * mDensity, BlurMaskFilter.Blur.NORMAL);
    shadowPathPaint.setMaskFilter(blurMaskFilter);
}

From source file:org.florescu.android.rangeseekbar.RangeSeekBar.java

private void init(Context context, AttributeSet attrs) {
    float barHeight;
    int thumbNormal = R.drawable.seek_thumb;
    int thumbPressed = R.drawable.seek_thumb_pressed;
    int thumbDisabled = R.drawable.seek_thumb_disabled;
    int thumbShadowColor;
    int defaultShadowColor = Color.argb(75, 0, 0, 0);
    int defaultShadowYOffset = PixelUtil.dpToPx(context, 2);
    int defaultShadowXOffset = PixelUtil.dpToPx(context, 0);
    int defaultShadowBlur = PixelUtil.dpToPx(context, 2);

    offset = PixelUtil.dpToPx(context, TEXT_LATERAL_PADDING_IN_DP);
    textSeperation = PixelUtil.dpToPx(context, DEFAULT_TEXT_SEPERATION_IN_DP);
    step = DEFAULT_STEP;//from   w  w w .  j a v a2s .c om
    snapTolerance = DEFAULT_SNAP_TOLERANCE_PERCENT / 100;
    minimumDistance = DEFAULT_MINIMUM_DISTANCE;
    increments = DEFAULT_INCREMENTS;
    incrementRanges = DEFAULT_INCREMENT_RANGES;

    if (attrs == null) {
        rangeType = DEFAULT_RANGE_TYPE;
        setRangeToDefaultValues();
        mInternalPad = PixelUtil.dpToPx(context, INITIAL_PADDING_IN_DP);
        barHeight = PixelUtil.dpToPx(context, LINE_HEIGHT_IN_DP);
        mActiveColor = ACTIVE_COLOR;
        mDefaultColor = Color.parseColor("#e5e8eb");
        mAlwaysActive = true;
        mShowTextAboveThumbs = true;
        mTextAboveThumbsColor = Color.WHITE;
        thumbShadowColor = defaultShadowColor;
        mThumbShadowXOffset = defaultShadowXOffset;
        mThumbShadowYOffset = defaultShadowYOffset;
        mThumbShadowBlur = defaultShadowBlur;
        mActivateOnDefaultValues = true;
    } else {
        TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.RangeSeekBar, 0, 0);
        try {
            switch (a.getInt(R.styleable.RangeSeekBar_rangeType, 0)) {
            case 0:
                rangeType = RangeType.LINEAR;
                break;
            case 1:
                rangeType = RangeType.PREDEFINED;
                break;
            case 2:
                rangeType = RangeType.CUBIC;
                break;
            default:
                rangeType = RangeType.LINEAR;
            }
            setRangeValues(
                    extractNumericValueFromAttributes(a, R.styleable.RangeSeekBar_absoluteMinValue,
                            DEFAULT_MINIMUM),
                    extractNumericValueFromAttributes(a, R.styleable.RangeSeekBar_absoluteMaxValue,
                            DEFAULT_MAXIMUM));
            mShowTextAboveThumbs = a.getBoolean(R.styleable.RangeSeekBar_valuesAboveThumbs, true);
            mTextAboveThumbsColor = a.getColor(R.styleable.RangeSeekBar_textAboveThumbsColor, Color.WHITE);
            mSingleThumb = a.getBoolean(R.styleable.RangeSeekBar_singleThumb, false);
            mShowLabels = a.getBoolean(R.styleable.RangeSeekBar_showLabels, true);
            mInternalPad = PixelUtil.dpToPx(context,
                    a.getInt(R.styleable.RangeSeekBar_internalPadding, INITIAL_PADDING_IN_DP));
            barHeight = PixelUtil.dpToPx(context,
                    a.getInt(R.styleable.RangeSeekBar_barHeight, LINE_HEIGHT_IN_DP));
            mActiveColor = a.getColor(R.styleable.RangeSeekBar_activeColor, ACTIVE_COLOR);
            mDefaultColor = a.getColor(R.styleable.RangeSeekBar_defaultColor, Color.parseColor("#e5e8eb"));
            mAlwaysActive = a.getBoolean(R.styleable.RangeSeekBar_alwaysActive, true);
            customMinValueLabel = a.getString(R.styleable.RangeSeekBar_minValueLabel);
            customMaxValueLabel = a.getString(R.styleable.RangeSeekBar_maxValueLabel);

            Drawable normalDrawable = a.getDrawable(R.styleable.RangeSeekBar_thumbNormal);
            if (normalDrawable != null) {
                thumbImage = BitmapUtil.drawableToBitmap(normalDrawable);
            }
            Drawable disabledDrawable = a.getDrawable(R.styleable.RangeSeekBar_thumbDisabled);
            if (disabledDrawable != null) {
                thumbDisabledImage = BitmapUtil.drawableToBitmap(disabledDrawable);
            }
            Drawable pressedDrawable = a.getDrawable(R.styleable.RangeSeekBar_thumbPressed);
            if (pressedDrawable != null) {
                thumbPressedImage = BitmapUtil.drawableToBitmap(pressedDrawable);
            }
            mThumbShadow = a.getBoolean(R.styleable.RangeSeekBar_thumbShadow, false);
            thumbShadowColor = a.getColor(R.styleable.RangeSeekBar_thumbShadowColor, defaultShadowColor);
            mThumbShadowXOffset = a.getDimensionPixelSize(R.styleable.RangeSeekBar_thumbShadowXOffset,
                    defaultShadowXOffset);
            mThumbShadowYOffset = a.getDimensionPixelSize(R.styleable.RangeSeekBar_thumbShadowYOffset,
                    defaultShadowYOffset);
            mThumbShadowBlur = a.getDimensionPixelSize(R.styleable.RangeSeekBar_thumbShadowBlur,
                    defaultShadowBlur);

            mActivateOnDefaultValues = a.getBoolean(R.styleable.RangeSeekBar_activateOnDefaultValues, true);
        } finally {
            a.recycle();
        }
    }

    Resources resources = getResources();
    int px = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 18, resources.getDisplayMetrics());

    if (thumbImage == null) {
        thumbImage = Bitmap.createBitmap(px, px, Bitmap.Config.ARGB_8888);
        Drawable thumbDrawableNormal = getResources().getDrawable(thumbNormal);
        thumbDrawableNormal.setBounds(0, 0, px, px);
        thumbDrawableNormal.draw(new Canvas(thumbImage));
    }
    if (thumbPressedImage == null) {
        Drawable thumbDrawablePressed = getResources().getDrawable(thumbPressed);
        thumbDrawablePressed.setBounds(0, 0, px, px);
        thumbPressedImage = Bitmap.createBitmap(px, px, Bitmap.Config.ARGB_8888);
        thumbDrawablePressed.draw(new Canvas(thumbPressedImage));
    }
    if (thumbDisabledImage == null) {
        Drawable thumbDrawableDisabled = getResources().getDrawable(thumbDisabled);
        thumbDrawableDisabled.setBounds(0, 0, px, px);
        thumbDisabledImage = Bitmap.createBitmap(px, px, Bitmap.Config.ARGB_8888);
        thumbDrawableDisabled.draw(new Canvas(thumbDisabledImage));
    }

    mThumbHalfWidth = 0.5f * thumbImage.getWidth();
    mThumbHalfHeight = 0.5f * thumbImage.getHeight();

    setValuePrimAndNumberType();

    mTextSize = PixelUtil.spToPx(context, DEFAULT_TEXT_SIZE_IN_SP);
    mDistanceToTop = PixelUtil.dpToPx(context, DEFAULT_TEXT_DISTANCE_TO_TOP_IN_DP);
    mTextOffset = !mShowTextAboveThumbs ? 0
            : this.mTextSize + PixelUtil.dpToPx(context, DEFAULT_TEXT_DISTANCE_TO_BUTTON_IN_DP)
                    + this.mDistanceToTop;

    mRect = new RectF(padding, mTextOffset + mThumbHalfHeight - barHeight / 2, getWidth() - padding,
            mTextOffset + mThumbHalfHeight + barHeight / 2);

    // make RangeSeekBar focusable. This solves focus handling issues in case EditText widgets are being used along with the RangeSeekBar within ScrollViews.
    setFocusable(true);
    setFocusableInTouchMode(true);
    mScaledTouchSlop = ViewConfiguration.get(getContext()).getScaledTouchSlop();

    if (mThumbShadow) {
        // We need to remove hardware acceleration in order to blur the shadow
        setLayerType(LAYER_TYPE_SOFTWARE, null);
        shadowPaint.setColor(thumbShadowColor);
        shadowPaint.setMaskFilter(new BlurMaskFilter(mThumbShadowBlur, BlurMaskFilter.Blur.NORMAL));
        mThumbShadowPath = new Path();
        mThumbShadowPath.addCircle(0, 0, mThumbHalfHeight, Path.Direction.CW);
    }
}

From source file:org.catrobat.catroid.ui.fragment.AddBrickFragment.java

public ImageView getGlowingBorder(Bitmap bitmap) {
    ImageView imageView = new ImageView(getActivity());
    imageView.setBackgroundColor(Color.TRANSPARENT);
    imageView.setId(R.id.drag_and_drop_list_view_image_view);

    Bitmap glowingBitmap = Bitmap.createBitmap(bitmap.getWidth() + 30, bitmap.getHeight() + 30,
            Bitmap.Config.ARGB_8888);//from ww w.jav a2 s. c om
    Canvas glowingCanvas = new Canvas(glowingBitmap);
    Bitmap alpha = bitmap.extractAlpha();
    Paint paintBlur = new Paint();
    paintBlur.setColor(Color.WHITE);
    glowingCanvas.drawBitmap(alpha, 15, 15, paintBlur);
    BlurMaskFilter blurMaskFilter = new BlurMaskFilter(15.0f, BlurMaskFilter.Blur.OUTER);
    paintBlur.setMaskFilter(blurMaskFilter);
    glowingCanvas.drawBitmap(alpha, 15, 15, paintBlur);
    paintBlur.setMaskFilter(null);
    glowingCanvas.drawBitmap(bitmap, 15, 15, paintBlur);

    imageView.setImageBitmap(glowingBitmap);

    return imageView;
}

From source file:hku.fyp14017.blencode.ui.fragment.AddBrickFragment.java

public ImageView getGlowingBorder(Bitmap bitmap) {
    ImageView imageView = new ImageView(getActivity());
    imageView.setBackgroundColor(Color.TRANSPARENT);
    imageView.setId(hku.fyp14017.blencode.R.id.drag_and_drop_list_view_image_view);

    Bitmap glowingBitmap = Bitmap.createBitmap(bitmap.getWidth() + 30, bitmap.getHeight() + 30,
            Bitmap.Config.ARGB_8888);/*www  .ja  v  a 2s .  c o m*/
    Canvas glowingCanvas = new Canvas(glowingBitmap);
    Bitmap alpha = bitmap.extractAlpha();
    Paint paintBlur = new Paint();
    paintBlur.setColor(Color.WHITE);
    glowingCanvas.drawBitmap(alpha, 15, 15, paintBlur);
    BlurMaskFilter blurMaskFilter = new BlurMaskFilter(15.0f, BlurMaskFilter.Blur.OUTER);
    paintBlur.setMaskFilter(blurMaskFilter);
    glowingCanvas.drawBitmap(alpha, 15, 15, paintBlur);
    paintBlur.setMaskFilter(null);
    glowingCanvas.drawBitmap(bitmap, 15, 15, paintBlur);

    imageView.setImageBitmap(glowingBitmap);

    return imageView;
}

From source file:com.waz.zclient.views.images.CircularSeekBar.java

/**
 * Initializes the {@code Paint} objects with the appropriate styles.
 *///from  w  w w . j a  v a  2 s.  co  m
protected void initPaints() {
    circlePaint = new Paint();
    circlePaint.setAntiAlias(true);
    circlePaint.setDither(true);
    circlePaint.setColor(circleColor);
    circlePaint.setStrokeWidth(circleStrokeWidth);
    circlePaint.setStyle(Paint.Style.STROKE);
    circlePaint.setStrokeJoin(Paint.Join.ROUND);
    circlePaint.setStrokeCap(Paint.Cap.ROUND);

    circleFillPaint = new Paint();
    circleFillPaint.setAntiAlias(true);
    circleFillPaint.setDither(true);
    circleFillPaint.setColor(circleFillColor);
    circleFillPaint.setStyle(Paint.Style.FILL);

    circleProgressPaint = new Paint();
    circleProgressPaint.setAntiAlias(true);
    circleProgressPaint.setDither(true);
    circleProgressPaint.setColor(circleProgressColor);
    circleProgressPaint.setStrokeWidth(circleStrokeWidth);
    circleProgressPaint.setStyle(Paint.Style.STROKE);
    circleProgressGlowPaint = new Paint();
    circleProgressGlowPaint.set(circleProgressPaint);
    if (!isInEditMode()) {
        circleProgressGlowPaint
                .setMaskFilter(new BlurMaskFilter((5f * dpToPxScale), BlurMaskFilter.Blur.NORMAL));
    }

    pointerPaint = new Paint();
    pointerPaint.setAntiAlias(true);
    pointerPaint.setDither(true);
    pointerPaint.setStyle(Paint.Style.FILL);
    pointerPaint.setColor(pointerColor);
    pointerPaint.setStrokeWidth(pointerRadius);

    pointerHaloPaint = new Paint();
    pointerHaloPaint.set(pointerPaint);
    pointerHaloPaint.setColor(pointerHaloColor);
    pointerHaloPaint.setAlpha(pointerAlpha);
    pointerHaloPaint.setStrokeWidth(pointerRadius + pointerHaloWidth);

    pointerHaloBorderPaint = new Paint();
    pointerHaloBorderPaint.set(pointerPaint);
    pointerHaloBorderPaint.setStrokeWidth(pointerHaloBorderWidth);
    pointerHaloBorderPaint.setStyle(Paint.Style.STROKE);
}

From source file:com.owen.view.views.PieChart.java

/**
 * Initialize the control. This code is in a separate method so that it can be
 * called from both constructors./*  www.ja  va 2s  .co  m*/
 */
private void init() {
    // Force the background to software rendering because otherwise the Blur
    // filter won't work.
    setLayerToSW(this);

    // Set up the paint for the label text
    mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mTextPaint.setColor(mTextColor);
    if (mTextHeight == 0) {
        mTextHeight = mTextPaint.getTextSize();
    } else {
        mTextPaint.setTextSize(mTextHeight);
    }

    // Set up the paint for the pie slices
    mPiePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mPiePaint.setStyle(Paint.Style.FILL);
    mPiePaint.setTextSize(mTextHeight);

    // Set up the paint for the shadow
    mShadowPaint = new Paint(0);
    mShadowPaint.setColor(0xff101010);
    mShadowPaint.setMaskFilter(new BlurMaskFilter(8, BlurMaskFilter.Blur.NORMAL));

    // Add a child view to draw the pie. Putting this in a child view
    // makes it possible to draw it on a separate hardware layer that rotates
    // independently
    mPieView = new PieView(getContext());
    addView(mPieView);
    mPieView.rotateTo(mPieRotation);

    // The pointer doesn't need hardware acceleration, but in order to show up
    // in front of the pie it also needs to be on a separate view.
    mPointerView = new PointerView(getContext());
    addView(mPointerView);

    // Set up an animator to animate the PieRotation property. This is used to
    // correct the pie's orientation after the user lets go of it.
    if (Build.VERSION.SDK_INT >= 11) {
        mAutoCenterAnimator = ObjectAnimator.ofInt(PieChart.this, "PieRotation", 0);

        // Add a listener to hook the onAnimationEnd event so that we can do
        // some cleanup when the pie stops moving.
        mAutoCenterAnimator.addListener(new Animator.AnimatorListener() {
            public void onAnimationStart(Animator animator) {
            }

            public void onAnimationEnd(Animator animator) {
                mPieView.decelerate();
            }

            public void onAnimationCancel(Animator animator) {
            }

            public void onAnimationRepeat(Animator animator) {
            }
        });
    }

    // Create a Scroller to handle the fling gesture.
    if (Build.VERSION.SDK_INT < 11) {
        mScroller = new Scroller(getContext());
    } else {
        mScroller = new Scroller(getContext(), null, true);
    }
    // The scroller doesn't have any built-in animation functions--it just supplies
    // values when we ask it to. So we have to have a way to call it every frame
    // until the fling ends. This code (ab)uses a ValueAnimator object to generate
    // a callback on every animation frame. We don't use the animated value at all.
    if (Build.VERSION.SDK_INT >= 11) {
        mScrollAnimator = ValueAnimator.ofFloat(0, 1);
        mScrollAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            public void onAnimationUpdate(ValueAnimator valueAnimator) {
                tickScrollAnimation();
            }
        });
    }

    // Create a gesture detector to handle onTouch messages
    mDetector = new GestureDetector(PieChart.this.getContext(), new GestureListener());

    // Turn off long press--this control doesn't use it, and if long press is enabled,
    // you can't scroll for a bit, pause, then scroll some more (the pause is interpreted
    // as a long press, apparently)
    mDetector.setIsLongpressEnabled(false);

    // In edit mode it's nice to have some demo data, so add that here.
    if (this.isInEditMode()) {
        Resources res = getResources();
        addItem("Annabelle", 3, ContextCompat.getColor(getContext(), R.color.bluegrass));
        addItem("Brunhilde", 4, ContextCompat.getColor(getContext(), R.color.chartreuse));
        addItem("Carolina", 2, ContextCompat.getColor(getContext(), R.color.emerald));
        addItem("Dahlia", 3, ContextCompat.getColor(getContext(), R.color.seafoam));
        addItem("Ekaterina", 1, ContextCompat.getColor(getContext(), R.color.slate));
    }

}

From source file:Steps.StepsFragment.java

private void setBackgroundGlow(ImageView imgview, int imageicon, int r, int g, int b) {
    // An added margin to the initial image
    int margin = 50;
    int halfMargin = margin / 2;
    // the glow radius
    int glowRadius = 90;

    // the glow color
    int glowColor = Color.rgb(r, g, b);

    // The original image to use reduced(re-sampled)
    Bitmap src = SampleImage.decodeSampledBitmapFromResource(getResources(), imageicon, 250, 250);

    // extract the alpha from the source image
    Bitmap alpha = src.extractAlpha();//from   w ww.jav a  2s. c  om

    // The output bitmap (with the icon + glow)
    Bitmap bmp = Bitmap.createBitmap(src.getWidth() + margin, src.getHeight() + margin,
            Bitmap.Config.ARGB_8888);

    // The canvas to paint on the image
    Canvas canvas = new Canvas(bmp);

    Paint paint = new Paint();
    paint.setColor(glowColor);

    // outer glow
    paint.setMaskFilter(new BlurMaskFilter(glowRadius, BlurMaskFilter.Blur.OUTER));//For Inner glow set Blur.INNER
    canvas.drawBitmap(alpha, halfMargin, halfMargin, paint);

    // original icon
    canvas.drawBitmap(src, halfMargin, halfMargin, null);

    imgview.setImageBitmap(bmp);

}