Example usage for android.content.res TypedArray recycle

List of usage examples for android.content.res TypedArray recycle

Introduction

In this page you can find the example usage for android.content.res TypedArray recycle.

Prototype

public void recycle() 

Source Link

Document

Recycles the TypedArray, to be re-used by a later caller.

Usage

From source file:android.support.design.widget.BottomSheetBehavior.java

/**
 * Default constructor for inflating BottomSheetBehaviors from layout.
 *
 * @param context The {@link Context}.//from  ww  w . ja v a 2 s . c  o  m
 * @param attrs   The {@link AttributeSet}.
 */
public BottomSheetBehavior(Context context, AttributeSet attrs) {
    super(context, attrs);
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.BottomSheetBehavior_Layout);
    TypedValue value = a.peekValue(R.styleable.BottomSheetBehavior_Layout_behavior_peekHeight);
    if (value != null && value.data == PEEK_HEIGHT_AUTO) {
        setPeekHeight(value.data);
    } else {
        setPeekHeight(a.getDimensionPixelSize(R.styleable.BottomSheetBehavior_Layout_behavior_peekHeight,
                PEEK_HEIGHT_AUTO));
    }
    setHideable(a.getBoolean(R.styleable.BottomSheetBehavior_Layout_behavior_hideable, false));
    setSkipCollapsed(a.getBoolean(R.styleable.BottomSheetBehavior_Layout_behavior_skipCollapsed, false));
    a.recycle();
    ViewConfiguration configuration = ViewConfiguration.get(context);
    mMaximumVelocity = configuration.getScaledMaximumFlingVelocity();
}

From source file:android.support.v14.preference.PreferenceFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    TypedArray a = mStyledContext.obtainStyledAttributes(null, R.styleable.PreferenceFragment,
            TypedArrayUtils.getAttr(mStyledContext,
                    android.support.v7.preference.R.attr.preferenceFragmentStyle,
                    AndroidResources.ANDROID_R_PREFERENCE_FRAGMENT_STYLE),
            0);//from   ww w  .ja v  a2s .c  o  m

    mLayoutResId = a.getResourceId(R.styleable.PreferenceFragment_android_layout, mLayoutResId);

    final Drawable divider = a.getDrawable(R.styleable.PreferenceFragment_android_divider);
    final int dividerHeight = a.getDimensionPixelSize(R.styleable.PreferenceFragment_android_dividerHeight, -1);

    a.recycle();

    // Need to theme the inflater to pick up the preferenceFragmentListStyle
    final TypedValue tv = new TypedValue();
    getActivity().getTheme().resolveAttribute(android.support.v7.preference.R.attr.preferenceTheme, tv, true);
    final int theme = tv.resourceId;

    final Context themedContext = new ContextThemeWrapper(inflater.getContext(), theme);
    final LayoutInflater themedInflater = inflater.cloneInContext(themedContext);

    final View view = themedInflater.inflate(mLayoutResId, container, false);

    final View rawListContainer = view.findViewById(AndroidResources.ANDROID_R_LIST_CONTAINER);
    if (!(rawListContainer instanceof ViewGroup)) {
        throw new RuntimeException("Content has view with id attribute "
                + "'android.R.id.list_container' that is not a ViewGroup class");
    }

    final ViewGroup listContainer = (ViewGroup) rawListContainer;

    final RecyclerView listView = onCreateRecyclerView(themedInflater, listContainer, savedInstanceState);
    if (listView == null) {
        throw new RuntimeException("Could not create RecyclerView");
    }

    mList = listView;

    listView.addItemDecoration(mDividerDecoration);
    setDivider(divider);
    if (dividerHeight != -1) {
        setDividerHeight(dividerHeight);
    }

    listContainer.addView(mList);
    mHandler.post(mRequestFocus);

    return view;
}

From source file:ca.uwaterloo.sh6choi.czshopper.ui.FloatLabelLayout.java

public FloatLabelLayout(Context context, AttributeSet attrs) {
    super(context, attrs);
    setOrientation(VERTICAL);/*from ww w.  j a  v a2 s .co m*/

    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.FloatLabelLayout);

    int leftPadding = a.getDimensionPixelSize(R.styleable.FloatLabelLayout_floatLabelPaddingLeft,
            dipsToPix(DEFAULT_LABEL_PADDING_LEFT));
    int topPadding = a.getDimensionPixelSize(R.styleable.FloatLabelLayout_floatLabelPaddingTop,
            dipsToPix(DEFAULT_LABEL_PADDING_TOP));
    int rightPadding = a.getDimensionPixelSize(R.styleable.FloatLabelLayout_floatLabelPaddingRight,
            dipsToPix(DEFAULT_LABEL_PADDING_RIGHT));
    int bottomPadding = a.getDimensionPixelSize(R.styleable.FloatLabelLayout_floatLabelPaddingBottom,
            dipsToPix(DEFAULT_LABEL_PADDING_BOTTOM));
    mHint = a.getText(R.styleable.FloatLabelLayout_floatLabelHint);

    mLabel = new TextView(context);
    mLabel.setPadding(leftPadding, topPadding, rightPadding, bottomPadding);
    mLabel.setVisibility(INVISIBLE);
    mLabel.setText(mHint);
    ViewCompat.setPivotX(mLabel, 0f);
    ViewCompat.setPivotY(mLabel, 0f);

    mLabel.setTextAppearance(context, a.getResourceId(R.styleable.FloatLabelLayout_floatLabelTextAppearance,
            android.R.style.TextAppearance_Small));
    a.recycle();

    addView(mLabel, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

    mInterpolator = AnimationUtils.loadInterpolator(context,
            Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ? android.R.interpolator.fast_out_slow_in
                    : android.R.anim.decelerate_interpolator);
}

From source file:android.support.v7.preference.PreferenceController.java

@Override
@NonNull//from   www . j  av a2  s  .c  o m
public View onCreateView(@NonNull LayoutInflater inflater, @NonNull ViewGroup container,
        @Nullable Bundle savedInstanceState) {
    mInitDone = false;
    mHavePrefs = false;

    final TypedValue tv = new TypedValue();
    getActivity().getTheme().resolveAttribute(R.attr.preferenceTheme, tv, true);
    final int theme = tv.resourceId;
    if (theme == 0) {
        throw new IllegalStateException("Must specify preferenceTheme in theme");
    }
    mStyledContext = new ContextThemeWrapper(getActivity(), theme);

    mPreferenceManager = new PreferenceManager(mStyledContext);
    final String rootKey = getArgs().getString(ARG_PREFERENCE_ROOT);
    onCreatePreferences(savedInstanceState, rootKey);

    TypedArray a = mStyledContext.obtainStyledAttributes(null, R.styleable.PreferenceFragmentCompat,
            R.attr.preferenceFragmentCompatStyle, 0);

    mLayoutResId = a.getResourceId(R.styleable.PreferenceFragmentCompat_android_layout, mLayoutResId);

    mDividerDecoration = new DividerDecoration();
    final Drawable divider = a.getDrawable(R.styleable.PreferenceFragmentCompat_android_divider);
    final int dividerHeight = a
            .getDimensionPixelSize(R.styleable.PreferenceFragmentCompat_android_dividerHeight, -1);
    final boolean allowDividerAfterLastItem = a
            .getBoolean(R.styleable.PreferenceFragmentCompat_allowDividerAfterLastItem, true);

    a.recycle();

    final Context themedContext = new ContextThemeWrapper(inflater.getContext(), theme);
    final LayoutInflater themedInflater = inflater.cloneInContext(themedContext);

    final View view = themedInflater.inflate(mLayoutResId, container, false);

    final View rawListContainer = view.findViewById(AndroidResources.ANDROID_R_LIST_CONTAINER);
    if (!(rawListContainer instanceof ViewGroup)) {
        throw new RuntimeException("Content has view with id attribute "
                + "'android.R.id.list_container' that is not a ViewGroup class");
    }

    final ViewGroup listContainer = (ViewGroup) rawListContainer;

    final RecyclerView listView = onCreateRecyclerView(themedInflater, listContainer, savedInstanceState);
    if (listView == null) {
        throw new RuntimeException("Could not create RecyclerView");
    }

    mList = listView;

    listView.addItemDecoration(mDividerDecoration);
    setDivider(divider);
    if (dividerHeight != -1) {
        setDividerHeight(dividerHeight);
    }
    mDividerDecoration.setAllowDividerAfterLastItem(allowDividerAfterLastItem);

    listContainer.addView(mList);
    mHandler.post(mRequestFocus);

    onViewCreated(view, savedInstanceState);

    return view;
}

From source file:com.advaitaworld.widgets.FloatLabelLayout.java

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

    setOrientation(VERTICAL);//  w  w w.  j  a va  2s  .  c o m

    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.FloatLabelLayout);

    int leftPadding = a.getDimensionPixelSize(R.styleable.FloatLabelLayout_floatLabelPaddingLeft,
            dipsToPix(DEFAULT_LABEL_PADDING_LEFT));
    int topPadding = a.getDimensionPixelSize(R.styleable.FloatLabelLayout_floatLabelPaddingTop,
            dipsToPix(DEFAULT_LABEL_PADDING_TOP));
    int rightPadding = a.getDimensionPixelSize(R.styleable.FloatLabelLayout_floatLabelPaddingRight,
            dipsToPix(DEFAULT_LABEL_PADDING_RIGHT));
    int bottomPadding = a.getDimensionPixelSize(R.styleable.FloatLabelLayout_floatLabelPaddingBottom,
            dipsToPix(DEFAULT_LABEL_PADDING_BOTTOM));
    mHint = a.getText(R.styleable.FloatLabelLayout_floatLabelHint);

    mLabel = new TextView(context);
    mLabel.setPadding(leftPadding, topPadding, rightPadding, bottomPadding);
    mLabel.setVisibility(INVISIBLE);
    mLabel.setText(mHint);
    ViewCompat.setPivotX(mLabel, 0f);
    ViewCompat.setPivotY(mLabel, 0f);

    mLabel.setTextAppearance(context, a.getResourceId(R.styleable.FloatLabelLayout_floatLabelTextAppearance,
            android.R.style.TextAppearance_Small));
    a.recycle();

    addView(mLabel, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

    mInterpolator = AnimationUtils.loadInterpolator(context,
            Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ? android.R.interpolator.fast_out_slow_in
                    : android.R.anim.decelerate_interpolator);
}

From source file:android.support.designox.widget.CollapsingTextHelper.java

void setExpandedTextAppearance(int resId) {
    TypedArray a = mView.getContext().obtainStyledAttributes(resId, R.styleable.TextAppearance);
    if (a.hasValue(R.styleable.TextAppearance_android_textColor)) {
        mExpandedTextColor = a.getColor(R.styleable.TextAppearance_android_textColor, mExpandedTextColor);
    }//from w w w  . jav a 2  s .c o  m
    if (a.hasValue(R.styleable.TextAppearance_android_textSize)) {
        mExpandedTextSize = a.getDimensionPixelSize(R.styleable.TextAppearance_android_textSize,
                (int) mExpandedTextSize);
    }
    mExpandedShadowColor = a.getInt(R.styleable.TextAppearance_android_shadowColor, 0);
    mExpandedShadowDx = a.getFloat(R.styleable.TextAppearance_android_shadowDx, 0);
    mExpandedShadowDy = a.getFloat(R.styleable.TextAppearance_android_shadowDy, 0);
    mExpandedShadowRadius = a.getFloat(R.styleable.TextAppearance_android_shadowRadius, 0);
    a.recycle();

    if (Build.VERSION.SDK_INT >= 16) {
        mExpandedTypeface = readFontFamilyTypeface(resId);
    }

    recalculate();
}

From source file:ch.heigvd.wordhunt.Interaction.FloatLabelLayout.java

public void init(Context context, AttributeSet attrs) {

    setOrientation(VERTICAL);/*from   ww w . ja v  a2  s .c  o  m*/

    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.FloatLabelLayout);

    int leftPadding = a.getDimensionPixelSize(R.styleable.FloatLabelLayout_floatLabelPaddingLeft,
            dipsToPix(DEFAULT_LABEL_PADDING_LEFT));
    int topPadding = a.getDimensionPixelSize(R.styleable.FloatLabelLayout_floatLabelPaddingTop,
            dipsToPix(DEFAULT_LABEL_PADDING_TOP));
    int rightPadding = a.getDimensionPixelSize(R.styleable.FloatLabelLayout_floatLabelPaddingRight,
            dipsToPix(DEFAULT_LABEL_PADDING_RIGHT));
    int bottomPadding = a.getDimensionPixelSize(R.styleable.FloatLabelLayout_floatLabelPaddingBottom,
            dipsToPix(DEFAULT_LABEL_PADDING_BOTTOM));
    mHint = a.getText(R.styleable.FloatLabelLayout_floatLabelHint);

    mLabel = new TextView(context);
    mLabel.setPadding(leftPadding, topPadding, rightPadding, bottomPadding);
    mLabel.setVisibility(INVISIBLE);
    mLabel.setText(mHint);
    ViewCompat.setPivotX(mLabel, 0f);
    ViewCompat.setPivotY(mLabel, 0f);

    mLabel.setTextAppearance(context, a.getResourceId(R.styleable.FloatLabelLayout_floatLabelTextAppearance,
            android.R.style.TextAppearance_Small));
    a.recycle();

    addView(mLabel, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

    mInterpolator = AnimationUtils.loadInterpolator(context,
            Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ? android.R.interpolator.fast_out_slow_in
                    : android.R.anim.decelerate_interpolator);
}

From source file:com.seatgeek.placesautocompletedemo.MainFragment.java

/**
 * chooses a random color from array.xml
 *//*  w w  w .ja va  2s. c om*/
private int getRandomMaterialColor(String typeColor) {
    int returnColor = Color.GRAY;
    int arrayId = getResources().getIdentifier("mdcolor_" + typeColor, "array", getContext().getPackageName());

    if (arrayId != 0) {
        TypedArray colors = getResources().obtainTypedArray(arrayId);
        int index = (int) (Math.random() * colors.length());
        returnColor = colors.getColor(index, Color.GRAY);
        colors.recycle();
    }
    return returnColor;
}

From source file:android.support.designox.widget.CollapsingTextHelper.java

void setCollapsedTextAppearance(int resId) {
    TypedArray a = mView.getContext().obtainStyledAttributes(resId, R.styleable.TextAppearance);
    if (a.hasValue(R.styleable.TextAppearance_android_textColor)) {
        mCollapsedTextColor = a.getColor(R.styleable.TextAppearance_android_textColor, mCollapsedTextColor);
    }/*from   ww  w. j a v  a 2s  .  co m*/
    if (a.hasValue(R.styleable.TextAppearance_android_textSize)) {
        mCollapsedTextSize = a.getDimensionPixelSize(R.styleable.TextAppearance_android_textSize,
                (int) mCollapsedTextSize);
    }
    mCollapsedShadowColor = a.getInt(R.styleable.TextAppearance_android_shadowColor, 0);
    mCollapsedShadowDx = a.getFloat(R.styleable.TextAppearance_android_shadowDx, 0);
    mCollapsedShadowDy = a.getFloat(R.styleable.TextAppearance_android_shadowDy, 0);
    mCollapsedShadowRadius = a.getFloat(R.styleable.TextAppearance_android_shadowRadius, 0);
    a.recycle();

    if (Build.VERSION.SDK_INT >= 16) {
        mCollapsedTypeface = readFontFamilyTypeface(resId);
    }

    recalculate();
}

From source file:android.support.wear.widget.CircularProgressLayout.java

public CircularProgressLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    super(context, attrs, defStyleAttr, defStyleRes);

    mProgressDrawable = new CircularProgressDrawable(context);
    mProgressDrawable.setProgressRotation(DEFAULT_ROTATION);
    mProgressDrawable.setStrokeCap(Paint.Cap.BUTT);
    setBackground(mProgressDrawable);//from  ww w.j  av  a2  s. co m

    // If a child view is added, make it center aligned so it fits in the progress drawable.
    setOnHierarchyChangeListener(new OnHierarchyChangeListener() {
        @Override
        public void onChildViewAdded(View parent, View child) {
            // Ensure that child view is aligned in center
            LayoutParams params = (LayoutParams) child.getLayoutParams();
            params.gravity = Gravity.CENTER;
            child.setLayoutParams(params);
        }

        @Override
        public void onChildViewRemoved(View parent, View child) {

        }
    });

    mController = new CircularProgressLayoutController(this);

    Resources r = context.getResources();
    TypedArray a = r.obtainAttributes(attrs, R.styleable.CircularProgressLayout);

    if (a.getType(R.styleable.CircularProgressLayout_colorSchemeColors) == TypedValue.TYPE_REFERENCE
            || !a.hasValue(R.styleable.CircularProgressLayout_colorSchemeColors)) {
        int arrayResId = a.getResourceId(R.styleable.CircularProgressLayout_colorSchemeColors,
                R.array.circular_progress_layout_color_scheme_colors);
        setColorSchemeColors(getColorListFromResources(r, arrayResId));
    } else {
        setColorSchemeColors(a.getColor(R.styleable.CircularProgressLayout_colorSchemeColors, Color.BLACK));
    }

    setStrokeWidth(a.getDimensionPixelSize(R.styleable.CircularProgressLayout_strokeWidth,
            r.getDimensionPixelSize(R.dimen.circular_progress_layout_stroke_width)));

    setBackgroundColor(a.getColor(R.styleable.CircularProgressLayout_backgroundColor,
            ContextCompat.getColor(context, R.color.circular_progress_layout_background_color)));

    setIndeterminate(a.getBoolean(R.styleable.CircularProgressLayout_indeterminate, false));

    a.recycle();
}