/*
 * Copyright (C) 2013 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.support.v7.internal.widget;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Rect;
import android.support.v7.appcompat.R;
import android.support.v7.internal.text.AllCapsTransformationMethod;
import android.text.method.TransformationMethod;
import android.util.AttributeSet;
import android.view.View;
import android.widget.TextView;

import java.util.Locale;

/**
 * @hide
 */
public class CompatTextView extends TextView {

    public CompatTextView(Context context) {
        this(context, null);
    }

    public CompatTextView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public CompatTextView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);

        boolean allCaps = false;

        // First read the TextAppearance style id
        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CompatTextView,
                defStyle, 0);
        final int ap = a.getResourceId(R.styleable.CompatTextView_android_textAppearance, -1);
        a.recycle();

        // Now check TextAppearance's textAllCaps value
        if (ap != -1) {
            TypedArray appearance = context.obtainStyledAttributes(ap,
                    R.styleable.TextAppearance);
            if (appearance.hasValue(R.styleable.TextAppearance_textAllCaps)) {
                setAllCaps(appearance.getBoolean(R.styleable.TextAppearance_textAllCaps, false));
            }
            appearance.recycle();
        }

        // Now read the style's value
        a = context.obtainStyledAttributes(attrs, R.styleable.CompatTextView, defStyle, 0);
        if (a.hasValue(R.styleable.CompatTextView_textAllCaps)) {
            allCaps = a.getBoolean(R.styleable.CompatTextView_textAllCaps, false);
        }
        a.recycle();

        setAllCaps(allCaps);
    }

    public void setAllCaps(boolean allCaps) {
        setTransformationMethod(allCaps ? new AllCapsTransformationMethod(getContext()) : null);
    }

    @Override
    public void setTextAppearance(Context context, int resid) {
        super.setTextAppearance(context, resid);

        TypedArray appearance = context.obtainStyledAttributes(resid, R.styleable.TextAppearance);
        if (appearance.hasValue(R.styleable.TextAppearance_textAllCaps)) {
            setAllCaps(appearance.getBoolean(R.styleable.TextAppearance_textAllCaps, false));
        }
        appearance.recycle();
    }
}

@@ -1412,42 +1412,8 @@
 );%0A%0A
-        boolean allCaps = false;%0A%0A
     
@@ -1848,28 +1848,8 @@
 (ap,
-%0A                   
  R.s
@@ -2322,18 +2322,19 @@
     
-a
+setA
 llCaps
- = 
+(
 a.ge
@@ -2388,16 +2388,17 @@
 , false)
+)
 ;%0A      
@@ -2425,38 +2425,8 @@
 e();
-%0A%0A        setAllCaps(allCaps);
 %0A   

Fix CompatTextView allcaps on L