• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2015 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.support.v7.widget;
18 
19 import android.content.Context;
20 import android.support.v7.appcompat.R;
21 import android.util.AttributeSet;
22 import android.widget.TextView;
23 
24 /**
25  * A {@link TextView} which supports compatible features on older version of the platform,
26  * including:
27  * <ul>
28  *     <li>Supports {@link R.attr#textAllCaps} style attribute which works back to
29  *     {@link android.os.Build.VERSION_CODES#ECLAIR_MR1 Eclair MR1}.</li>
30  * </ul>
31  *
32  * <p>This will automatically be used when you use {@link TextView} in your layouts.
33  * You should only need to manually use this class when writing custom views.</p>
34  */
35 public class AppCompatTextView extends TextView {
36 
37     private AppCompatTextHelper mTextHelper;
38 
AppCompatTextView(Context context)39     public AppCompatTextView(Context context) {
40         this(context, null);
41     }
42 
AppCompatTextView(Context context, AttributeSet attrs)43     public AppCompatTextView(Context context, AttributeSet attrs) {
44         this(context, attrs, android.R.attr.textViewStyle);
45     }
46 
AppCompatTextView(Context context, AttributeSet attrs, int defStyleAttr)47     public AppCompatTextView(Context context, AttributeSet attrs, int defStyleAttr) {
48         super(context, attrs, defStyleAttr);
49 
50         mTextHelper = new AppCompatTextHelper(this);
51         mTextHelper.loadFromAttributes(attrs, defStyleAttr);
52     }
53 
54     @Override
setTextAppearance(Context context, int resId)55     public void setTextAppearance(Context context, int resId) {
56         super.setTextAppearance(context, resId);
57         if (mTextHelper != null) {
58             mTextHelper.onSetTextAppearance(context, resId);
59         }
60     }
61 }
62