Java Code Examples for android.graphics.BlurMaskFilter#Blur

The following examples show how to use android.graphics.BlurMaskFilter#Blur . 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 check out the related API usage on the sidebar.
Example 1
Source File: BlurMaskFilterActivity.java    From android-graphics-demo with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_blur_mask_filter);

  LinearLayout container = (LinearLayout) findViewById(R.id.container);
  for (BlurMaskFilter.Blur style : BlurMaskFilter.Blur.values()) {
    TextView textView = new TextView(this);
    textView.setTextAppearance(this, R.style.TextAppearance_Huge_Green);
    applyFilter(textView, style);

    LinearLayout.LayoutParams params =  new LinearLayout.LayoutParams(
        ViewGroup.LayoutParams.WRAP_CONTENT,
        ViewGroup.LayoutParams.WRAP_CONTENT);
    params.gravity = Gravity.CENTER;
    container.addView(textView, params);
  }
}
 
Example 2
Source File: Spans.java    From spanner with Apache License 2.0 5 votes vote down vote up
/**
 * @see BlurMaskFilter#BlurMaskFilter(float, BlurMaskFilter.Blur)
 */
public static Span blur(final float radius, @NonNull final BlurMaskFilter.Blur style) {
    return new Span(new SpanBuilder() {
        @Override
        public Object build() {
            return new MaskFilterSpan(new BlurMaskFilter(radius, style));
        }
    });
}
 
Example 3
Source File: TextDecorator.java    From text-decorator with Apache License 2.0 5 votes vote down vote up
public TextDecorator blur(final float radius, final BlurMaskFilter.Blur style, final String... texts) {
  int index;

  for (String text : texts) {
    if (content.contains(text)) {
      index = content.indexOf(text);
      decoratedContent.setSpan(new MaskFilterSpan(new BlurMaskFilter(radius, style)), index, index + text.length(), flags);
    }
  }

  return this;
}
 
Example 4
Source File: TickerView.java    From ticker with Apache License 2.0 5 votes vote down vote up
/**
 * Exposing method to add or remove blur mask filter to ticker text.
 *
 * @param style Blur mask filter type
 * @param radius Density of filter
 */
public void setBlurMaskFilter(BlurMaskFilter.Blur style, float radius) {
    if (style != null && radius > 0f) {
        BlurMaskFilter filter = new BlurMaskFilter(radius, style);
        textPaint.setMaskFilter(filter);
    } else {
        setLayerType(View.LAYER_TYPE_SOFTWARE, null);
        textPaint.setMaskFilter(null);
    }
}
 
Example 5
Source File: BlurMaskFilterActivity.java    From android-graphics-demo with Apache License 2.0 5 votes vote down vote up
private void applyFilter(
    TextView textView, BlurMaskFilter.Blur style) {
  if (Build.VERSION.SDK_INT >= 11) {
    ViewUtil.setSoftwareLayerType(textView);
  }
  textView.setText(style.name());
  BlurMaskFilter filter = new BlurMaskFilter(textView.getTextSize() / 10, style);
  textView.getPaint().setMaskFilter(filter);
}
 
Example 6
Source File: TextDecorator.java    From text-decorator with Apache License 2.0 4 votes vote down vote up
public TextDecorator blur(final float radius, final BlurMaskFilter.Blur style, final int start, final int end) {
  checkIndexOutOfBoundsException(start, end);
  decoratedContent.setSpan(new MaskFilterSpan(new BlurMaskFilter(radius, style)), start, end, flags);

  return this;
}
 
Example 7
Source File: SpanOptions.java    From AndroidSpan with Apache License 2.0 4 votes vote down vote up
/**
 * @param density
 * @param style   BlurMaskFilter.Blur.NORMAL
 * @return
 */
public SpanOptions addMaskFilterSpan(float density, BlurMaskFilter.Blur style) {
    MaskFilterSpan span = new MaskFilterSpan(new BlurMaskFilter(density, style));
    listSpan.add(span);
    return this;
}
 
Example 8
Source File: SpannableStringUtils.java    From AndroidWallet with GNU General Public License v3.0 3 votes vote down vote up
/**
 * 设置模糊
 * <p>尚存bug,其他地方存在相同的字体的话,相同字体出现在之前的话那么就不会模糊,出现在之后的话那会一起模糊</p>
 * <p>推荐还是把所有字体都模糊这样使用</p>
 *
 * @param radius 模糊半径(需大于0)
 * @param style  模糊样式<ul>
 *               <li>{@link BlurMaskFilter.Blur#NORMAL}</li>
 *               <li>{@link BlurMaskFilter.Blur#SOLID}</li>
 *               <li>{@link BlurMaskFilter.Blur#OUTER}</li>
 *               <li>{@link BlurMaskFilter.Blur#INNER}</li>
 *               </ul>
 * @return {@link Builder}
 */
public Builder setBlur(float radius, BlurMaskFilter.Blur style) {
    this.blurRadius = radius;
    this.style = style;
    this.isBlur = true;
    return this;
}
 
Example 9
Source File: SpannableStringUtils.java    From DevUtils with Apache License 2.0 3 votes vote down vote up
/**
 * 设置模糊
 * @param radius 模糊程度
 * @param style  模糊样式
 *               <ul>
 *               <li>{@link BlurMaskFilter.Blur#NORMAL}</li>
 *               <li>{@link BlurMaskFilter.Blur#SOLID}</li>
 *               <li>{@link BlurMaskFilter.Blur#OUTER}</li>
 *               <li>{@link BlurMaskFilter.Blur#INNER}</li>
 *               </ul>
 * @return {@link SpannableStringUtils}
 */
public SpannableStringUtils setBlur(@FloatRange(from = 0, fromInclusive = false) final float radius,
                                    final BlurMaskFilter.Blur style) {
    this.blurRadius = radius;
    this.style = style;
    return this;
}
 
Example 10
Source File: SpannableStringUtils.java    From Android-UtilCode with Apache License 2.0 3 votes vote down vote up
/**
 * 设置模糊
 * <p>尚存bug,其他地方存在相同的字体的话,相同字体出现在之前的话那么就不会模糊,出现在之后的话那会一起模糊</p>
 * <p>推荐还是把所有字体都模糊这样使用</p>
 *
 * @param radius 模糊半径(需大于0)
 * @param style  模糊样式<ul>
 *               <li>{@link BlurMaskFilter.Blur#NORMAL}</li>
 *               <li>{@link BlurMaskFilter.Blur#SOLID}</li>
 *               <li>{@link BlurMaskFilter.Blur#OUTER}</li>
 *               <li>{@link BlurMaskFilter.Blur#INNER}</li>
 *               </ul>
 * @return {@link Builder}
 */
public Builder setBlur(float radius, BlurMaskFilter.Blur style) {
    this.blurRadius = radius;
    this.style = style;
    this.isBlur = true;
    return this;
}
 
Example 11
Source File: AndroidSpan.java    From AndroidSpan with Apache License 2.0 2 votes vote down vote up
/**
 * 模糊效果
 *
 * @param text
 * @param density
 * @param style   BlurMaskFilter.Blur.NORMAL
 * @return
 */
public AndroidSpan drawMaskFilterSpan(String text, float density, BlurMaskFilter.Blur style) {
    MaskFilterSpan span = new MaskFilterSpan(new BlurMaskFilter(density, style));
    drawSpan(text, span);
    return this;
}