<commit_before>/*
 * Copyright (C) 2014 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 androidx.appcompat.app;

import android.content.Context;
import android.content.ContextWrapper;
import android.content.res.TypedArray;
import android.os.Build;
import android.util.AttributeSet;
import android.util.Log;
import android.view.InflateException;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.R;
import androidx.appcompat.view.ContextThemeWrapper;
import androidx.appcompat.widget.AppCompatAutoCompleteTextView;
import androidx.appcompat.widget.AppCompatButton;
import androidx.appcompat.widget.AppCompatCheckBox;
import androidx.appcompat.widget.AppCompatCheckedTextView;
import androidx.appcompat.widget.AppCompatEditText;
import androidx.appcompat.widget.AppCompatImageButton;
import androidx.appcompat.widget.AppCompatImageView;
import androidx.appcompat.widget.AppCompatMultiAutoCompleteTextView;
import androidx.appcompat.widget.AppCompatRadioButton;
import androidx.appcompat.widget.AppCompatRatingBar;
import androidx.appcompat.widget.AppCompatSeekBar;
import androidx.appcompat.widget.AppCompatSpinner;
import androidx.appcompat.widget.AppCompatTextView;
import androidx.appcompat.widget.AppCompatToggleButton;
import androidx.appcompat.widget.TintContextWrapper;
import androidx.collection.SimpleArrayMap;
import androidx.core.view.ViewCompat;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * This class is used by AppCompat to automatically "substitute" all usages of core Android
 * widgets inflated from layout files by the AppCompat extensions of those widgets.
 *
 * <p>This class two main responsibilities: the first is to 'inject' our tinted views in place of
 * the framework versions in layout inflation; the second is backport the {@code android:theme}
 * functionality for any inflated widgets. This include theme inheritance from its parent.</p>
 *
 * <p>In order to provide your own extensions, follow these steps:
 *    <ul>
 *        <li>Extend this class, or the relevant subclass if you're using the Material
 *        components library</li>
 *        <li>Override one or more of the <code>createXYZ</code> methods</li>
 *        <li>Add the <code>viewInflaterClass</code> attribute on your application theme. The
 *        value of the attribute should be the fully-qualified class name of your custom inflater
 *        class.</li>
 *    </ul>
 * </p>
 */
public class AppCompatViewInflater {

    private static final Class<?>[] sConstructorSignature = new Class<?>[]{
            Context.class, AttributeSet.class};
    private static final int[] sOnClickAttrs = new int[]{android.R.attr.onClick};
    private static final int[] sAccessibilityHeading =
            new int[]{android.R.attr.accessibilityHeading};
    private static final int[] sAccessibilityPaneTitle =
            new int[]{android.R.attr.accessibilityPaneTitle};
    private static final int[] sScreenReaderFocusable =
            new int[]{android.R.attr.screenReaderFocusable};

    private static final String[] sClassPrefixList = {
            "android.widget.",
            "android.view.",
            "android.webkit."
    };

    private static final String LOG_TAG = "AppCompatViewInflater";

    private static final SimpleArrayMap<String, Constructor<? extends View>> sConstructorMap =
            new SimpleArrayMap<>();

    private final Object[] mConstructorArgs = new Object[2];

    /**
     * Creates AppCompat version of the views.
     */
    @Nullable
    public final View createView(@Nullable View parent, @NonNull final String name,
            @NonNull Context context,
            @NonNull AttributeSet attrs, boolean inheritContext,
            boolean readAndroidTheme, boolean readAppTheme, boolean wrapContext) {
        final Context originalContext = context;

        // We can emulate Lollipop's android:theme attribute propagating down the view hierarchy
        // by using the parent's context
        if (inheritContext && parent != null) {
            context = parent.getContext();
        }
        if (readAndroidTheme || readAppTheme) {
            // We then apply the theme on the context, if specified
            context = themifyContext(context, attrs, readAndroidTheme, readAppTheme);
        }
        if (wrapContext) {
            context = TintContextWrapper.wrap(context);
        }

        View view = null;

        // We need to 'inject' our tint aware Views in place of the standard framework versions
        switch (name) {
            case "TextView":<commit_msg>Document new createView method<commit_after>/*
 * Copyright (C) 2014 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 androidx.appcompat.app;

import android.content.Context;
import android.content.ContextWrapper;
import android.content.res.TypedArray;
import android.os.Build;
import android.util.AttributeSet;
import android.util.Log;
import android.view.InflateException;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.R;
import androidx.appcompat.view.ContextThemeWrapper;
import androidx.appcompat.widget.AppCompatAutoCompleteTextView;
import androidx.appcompat.widget.AppCompatButton;
import androidx.appcompat.widget.AppCompatCheckBox;
import androidx.appcompat.widget.AppCompatCheckedTextView;
import androidx.appcompat.widget.AppCompatEditText;
import androidx.appcompat.widget.AppCompatImageButton;
import androidx.appcompat.widget.AppCompatImageView;
import androidx.appcompat.widget.AppCompatMultiAutoCompleteTextView;
import androidx.appcompat.widget.AppCompatRadioButton;
import androidx.appcompat.widget.AppCompatRatingBar;
import androidx.appcompat.widget.AppCompatSeekBar;
import androidx.appcompat.widget.AppCompatSpinner;
import androidx.appcompat.widget.AppCompatTextView;
import androidx.appcompat.widget.AppCompatToggleButton;
import androidx.appcompat.widget.TintContextWrapper;
import androidx.collection.SimpleArrayMap;
import androidx.core.view.ViewCompat;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * This class is used by AppCompat to automatically "substitute" all usages of core Android
 * widgets inflated from layout files by the AppCompat extensions of those widgets.
 *
 * <p>This class two main responsibilities: the first is to 'inject' our tinted views in place of
 * the framework versions in layout inflation; the second is backport the {@code android:theme}
 * functionality for any inflated widgets. This include theme inheritance from its parent.</p>
 *
 * <p>In order to provide your own extensions, follow these steps:
 *    <ul>
 *        <li>Extend this class, or the relevant subclass if you're using the Material
 *        components library</li>
 *        <li>Override one or more of the <code>createXYZ</code> methods</li>
 *        <li>Add the <code>viewInflaterClass</code> attribute on your application theme. The
 *        value of the attribute should be the fully-qualified class name of your custom inflater
 *        class.</li>
 *    </ul>
 * </p>
 */
public class AppCompatViewInflater {

    private static final Class<?>[] sConstructorSignature = new Class<?>[]{
            Context.class, AttributeSet.class};
    private static final int[] sOnClickAttrs = new int[]{android.R.attr.onClick};
    private static final int[] sAccessibilityHeading =
            new int[]{android.R.attr.accessibilityHeading};
    private static final int[] sAccessibilityPaneTitle =
            new int[]{android.R.attr.accessibilityPaneTitle};
    private static final int[] sScreenReaderFocusable =
            new int[]{android.R.attr.screenReaderFocusable};

    private static final String[] sClassPrefixList = {
            "android.widget.",
            "android.view.",
            "android.webkit."
    };

    private static final String LOG_TAG = "AppCompatViewInflater";

    private static final SimpleArrayMap<String, Constructor<? extends View>> sConstructorMap =
            new SimpleArrayMap<>();

    private final Object[] mConstructorArgs = new Object[2];

    /**
     * Creates an AppCompat-compatible widget by automatically "substituting" all usages of core
     * Android widgets with the AppCompat extensions of those widgets.
     * <p>
     * Most developers should not call this method directly. Instead, use the layout inflater
     * provided by {@link AppCompatActivity#getLayoutInflater()} or call
     * {@link AppCompatDelegate#createView(View, String, Context, AttributeSet)}.
     *
     * @param parent the hierarchical parent of the view, if any
     * @param name class name of the view, must be a simple class name like {@code TextView} for
     *             core Android widgets
     * @param context context against which the view should be constructed, may be wrapped for
     *                theming purposes or fully replaced if {@code inheritContext} is {@code true}
     * @param attrs attribute set to pass to the view constructor
     * @param inheritContext {@code true} to construct the view against the {@code parent} view's
     *                       context instead of {@code context}, or {@code false} to use
     *                       {@code context}
     * @param readAndroidTheme {@code true} to parse {@code android:theme} from {@code attrs} and
     *                         wrap the view's construction context if necessary
     * @param readAppTheme {@code true} to parse {@code app:theme} from {@code attrs} and wrap the
     *                     view's construction context if necessary
     * @param wrapContext {@code true} to wrap the view's construction context to provide
     *                    additional resource system feature backports
     * @return an AppCompat-compatible widget
     */
    @Nullable
    public final View createView(@Nullable View parent, @NonNull final String name,
            @NonNull Context context,
            @NonNull AttributeSet attrs, boolean inheritContext,
            boolean readAndroidTheme, boolean readAppTheme, boolean wrapContext) {
        final Context originalContext = context;

        // We can emulate Lollipop's android:theme attribute propagating down the view hierarchy
        // by using the parent's context
        if (inheritContext && parent != null) {
            context = parent.getContext();
        }
        if (readAndroidTheme || readAppTheme) {
            // We then apply the theme on the context, if specified
            context = themifyContext(context, attrs, readAndroidTheme, readAppTheme);
        }
        if (wrapContext) {
            context = TintContextWrapper.wrap(context);
        }

        View view = null;

        // We need to 'inject' our tint aware Views in place of the standard framework versions
        switch (name) {
            case "TextView":
{'fraction_non_alphanumeric': 0.08040863404185203, 'fraction_numerical': 0.0014829461196243204, 'mean_word_length': 3.5059391239792133, 'pattern_counts': {'":': 2, '<': 46, '<?xml version=': 0, '>': 46, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4445208', 'n_tokens_mistral': 3044, 'n_tokens_neox': 3010, 'n_words': 1090}