1 package com
.actionbarsherlock
.internal
.widget
;
3 import android
.content
.Context
;
4 import android
.content
.res
.TypedArray
;
5 import android
.os
.Build
;
6 import android
.util
.AttributeSet
;
7 import android
.widget
.TextView
;
9 import java
.util
.Locale
;
11 public class CapitalizingTextView
extends TextView
{
12 private static final boolean SANS_ICE_CREAM
= Build
.VERSION
.SDK_INT
< Build
.VERSION_CODES
.ICE_CREAM_SANDWICH
;
13 private static final boolean IS_GINGERBREAD
= Build
.VERSION
.SDK_INT
>= Build
.VERSION_CODES
.GINGERBREAD
;
15 private static final int[] R_styleable_TextView
= new int[] {
16 android
.R
.attr
.textAllCaps
18 private static final int R_styleable_TextView_textAllCaps
= 0;
20 private boolean mAllCaps
;
22 public CapitalizingTextView(Context context
, AttributeSet attrs
) {
23 this(context
, attrs
, 0);
26 public CapitalizingTextView(Context context
, AttributeSet attrs
, int defStyle
) {
27 super(context
, attrs
, defStyle
);
29 TypedArray a
= context
.obtainStyledAttributes(attrs
, R_styleable_TextView
, defStyle
, 0);
30 mAllCaps
= a
.getBoolean(R_styleable_TextView_textAllCaps
, true
);
34 public void setTextCompat(CharSequence text
) {
35 if (SANS_ICE_CREAM
&& mAllCaps
&& text
!= null
) {
38 setText(text
.toString().toUpperCase(Locale
.ROOT
));
39 } catch (NoSuchFieldError e
) {
40 //Some manufacturer broke Locale.ROOT. See #572.
41 setText(text
.toString().toUpperCase());
44 setText(text
.toString().toUpperCase());