• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 @android.ravenwood.annotation.RavenwoodKeepWholeClass
34 public class MaskFilterSpan extends CharacterStyle implements UpdateAppearance {
35 
36     private MaskFilter mFilter;
37 
38     /**
39      * Creates a {@link MaskFilterSpan} from a {@link MaskFilter}.
40      *
41      * @param filter the filter to be applied to the <code>TextPaint</code>
42      */
MaskFilterSpan(MaskFilter filter)43     public MaskFilterSpan(MaskFilter filter) {
44         mFilter = filter;
45     }
46 
47     /**
48      * Return the mask filter for this span.
49      *
50      * @return the mask filter for this span
51      */
getMaskFilter()52     public MaskFilter getMaskFilter() {
53         return mFilter;
54     }
55 
56     @Override
updateDrawState(TextPaint ds)57     public void updateDrawState(TextPaint ds) {
58         ds.setMaskFilter(mFilter);
59     }
60 
61     @Override
toString()62     public String toString() {
63         return "MaskFilterSpan{filter=" + getMaskFilter() + '}';
64     }
65 }
66