1 /*
2  * Copyright (C) 2006 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package android.text.style;
18 
19 import android.graphics.MaskFilter;
20 import android.text.TextPaint;
21 /**
22  * Span that allows setting a {@link MaskFilter} to the text it's attached to.
23  * <p>
24  * For example, to blur a text, a {@link android.graphics.BlurMaskFilter} can be used:
25  * <pre>
26  * MaskFilter blurMask = new BlurMaskFilter(5f, BlurMaskFilter.Blur.NORMAL);
27  * SpannableString string = new SpannableString("Text with blur mask");
28  * string.setSpan(new MaskFilterSpan(blurMask), 10, 15, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
29  * </pre>
30  * <img src="{@docRoot}reference/android/images/text/style/maskfilterspan.png" />
31  * <figcaption>Text blurred with the <code>MaskFilterSpan</code>.</figcaption>
32  */
33 public class MaskFilterSpan extends CharacterStyle implements UpdateAppearance {
34 
35     private MaskFilter mFilter;
36 
37     /**
38      * Creates a {@link MaskFilterSpan} from a {@link MaskFilter}.
39      *
40      * @param filter the filter to be applied to the <code>TextPaint</code>
41      */
MaskFilterSpan(MaskFilter filter)42     public MaskFilterSpan(MaskFilter filter) {
43         mFilter = filter;
44     }
45 
46     /**
47      * Return the mask filter for this span.
48      *
49      * @return the mask filter for this span
50      */
getMaskFilter()51     public MaskFilter getMaskFilter() {
52         return mFilter;
53     }
54 
55     @Override
updateDrawState(TextPaint ds)56     public void updateDrawState(TextPaint ds) {
57         ds.setMaskFilter(mFilter);
58     }
59 
60     @Override
toString()61     public String toString() {
62         return "MaskFilterSpan{filter=" + getMaskFilter() + '}';
63     }
64 }
65