1 package com
.actionbarsherlock
.internal
.widget
;
3 import java
.util
.Locale
;
4 import android
.content
.Context
;
5 import android
.content
.res
.TypedArray
;
6 import android
.os
.Build
;
7 import android
.util
.AttributeSet
;
8 import android
.widget
.Button
;
10 public class CapitalizingButton
extends Button
{
11 private static final boolean SANS_ICE_CREAM
= Build
.VERSION
.SDK_INT
< Build
.VERSION_CODES
.ICE_CREAM_SANDWICH
;
12 private static final boolean IS_GINGERBREAD
= Build
.VERSION
.SDK_INT
>= Build
.VERSION_CODES
.GINGERBREAD
;
14 private static final int[] R_styleable_Button
= new int[] {
15 android
.R
.attr
.textAllCaps
17 private static final int R_styleable_Button_textAllCaps
= 0;
19 private boolean mAllCaps
;
21 public CapitalizingButton(Context context
, AttributeSet attrs
) {
22 super(context
, attrs
);
24 TypedArray a
= context
.obtainStyledAttributes(attrs
, R_styleable_Button
);
25 mAllCaps
= a
.getBoolean(R_styleable_Button_textAllCaps
, true
);
29 public void setTextCompat(CharSequence text
) {
30 if (SANS_ICE_CREAM
&& mAllCaps
&& text
!= null
) {
32 setText(text
.toString().toUpperCase(Locale
.ROOT
));
34 setText(text
.toString().toUpperCase());