• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2008 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.os.Parcel;
20 import android.text.ParcelableSpan;
21 import android.text.TextPaint;
22 import android.text.TextUtils;
23 
24 public class AbsoluteSizeSpan extends MetricAffectingSpan implements ParcelableSpan {
25 
26     private final int mSize;
27     private boolean mDip;
28 
29     /**
30      * Set the text size to <code>size</code> physical pixels.
31      */
AbsoluteSizeSpan(int size)32     public AbsoluteSizeSpan(int size) {
33         mSize = size;
34     }
35 
36     /**
37      * Set the text size to <code>size</code> physical pixels,
38      * or to <code>size</code> device-independent pixels if
39      * <code>dip</code> is true.
40      */
AbsoluteSizeSpan(int size, boolean dip)41     public AbsoluteSizeSpan(int size, boolean dip) {
42         mSize = size;
43         mDip = dip;
44     }
45 
AbsoluteSizeSpan(Parcel src)46     public AbsoluteSizeSpan(Parcel src) {
47         mSize = src.readInt();
48         mDip = src.readInt() != 0;
49     }
50 
getSpanTypeId()51     public int getSpanTypeId() {
52         return getSpanTypeIdInternal();
53     }
54 
55     /** @hide */
getSpanTypeIdInternal()56     public int getSpanTypeIdInternal() {
57         return TextUtils.ABSOLUTE_SIZE_SPAN;
58     }
59 
describeContents()60     public int describeContents() {
61         return 0;
62     }
63 
writeToParcel(Parcel dest, int flags)64     public void writeToParcel(Parcel dest, int flags) {
65         writeToParcelInternal(dest, flags);
66     }
67 
68     /** @hide */
writeToParcelInternal(Parcel dest, int flags)69     public void writeToParcelInternal(Parcel dest, int flags) {
70         dest.writeInt(mSize);
71         dest.writeInt(mDip ? 1 : 0);
72     }
73 
getSize()74     public int getSize() {
75         return mSize;
76     }
77 
getDip()78     public boolean getDip() {
79         return mDip;
80     }
81 
82     @Override
updateDrawState(TextPaint ds)83     public void updateDrawState(TextPaint ds) {
84         if (mDip) {
85             ds.setTextSize(mSize * ds.density);
86         } else {
87             ds.setTextSize(mSize);
88         }
89     }
90 
91     @Override
updateMeasureState(TextPaint ds)92     public void updateMeasureState(TextPaint ds) {
93         if (mDip) {
94             ds.setTextSize(mSize * ds.density);
95         } else {
96             ds.setTextSize(mSize);
97         }
98     }
99 }
100