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:aierjun.com.aierjunlibrary.widget.tablayout.PagerSlidingTabStrip.java

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

    setFillViewport(true);/*  w  w w .  ja  v  a2 s  .  c o  m*/
    setWillNotDraw(false);

    tabsContainer = new LinearLayout(context);
    tabsContainer.setOrientation(LinearLayout.HORIZONTAL);
    tabsContainer.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
    addView(tabsContainer);

    DisplayMetrics dm = getResources().getDisplayMetrics();

    scrollOffset = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, scrollOffset, dm);
    indicatorHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, indicatorHeight, dm);
    underlineHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, underlineHeight, dm);
    dividerPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dividerPadding, dm);
    tabPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, tabPadding, dm);
    dividerWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dividerWidth, dm);
    tabTextSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, tabTextSize, dm);

    // get system attrs (android:textSize and android:textColor)
    TypedArray a = context.obtainStyledAttributes(attrs, ATTRS);

    tabTextSize = a.getDimensionPixelSize(0, tabTextSize);
    tabTextColor = a.getColor(1, tabTextColor);

    tabBackgroundDrawable = createColorStateListDrawable(Color.TRANSPARENT,
            getResources().getColor(android.R.color.transparent));

    a.recycle();
    a = context.obtainStyledAttributes(attrs, R.styleable.PagerSlidingTabStrip);
    indicatorColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsIndicatorColor, indicatorColor);
    underlineColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsUnderlineColor, underlineColor);
    dividerColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsDividerColor, dividerColor);
    indicatorHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsIndicatorHeight,
            indicatorHeight);
    underlineHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsUnderlineHeight,
            underlineHeight);
    dividerPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsDividerPadding,
            dividerPadding);
    tabPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsTabPaddingLeftRight, tabPadding);
    if (a.hasValue(R.styleable.PagerSlidingTabStrip_pstsTabBackground))
        tabBackgroundDrawable = a.getDrawable(R.styleable.PagerSlidingTabStrip_pstsTabBackground);
    shouldExpand = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsShouldExpand, shouldExpand);
    scrollOffset = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsScrollOffset, scrollOffset);
    textAllCaps = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsTextAllCaps, textAllCaps);
    tabchecktextcolor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsTabCheckTextColor, tabchecktextcolor);

    a.recycle();

    rectPaint = new Paint();
    rectPaint.setAntiAlias(true);
    rectPaint.setStyle(Style.FILL);

    dividerPaint = new Paint();
    dividerPaint.setAntiAlias(true);
    dividerPaint.setStrokeWidth(dividerWidth);

    defaultTabLayoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.MATCH_PARENT);
    expandedTabLayoutParams = new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 1.0f);

    if (locale == null) {
        locale = getResources().getConfiguration().locale;
    }
}

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

/**
 * Default constructor for inflating BottomSheetBehaviors from layout.
 *
 * @param context The {@link Context}.//from w  ww.  j a  va  2  s  .  co m
 * @param attrs The {@link AttributeSet}.
 */
public BottomSheetBehavior(Context context, AttributeSet attrs) {
    super(context, attrs);
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.BottomSheetBehavior_Params);
    setPeekHeight(a.getDimensionPixelSize(R.styleable.BottomSheetBehavior_Params_behavior_peekHeight_ox, 0));
    setHideable(a.getBoolean(R.styleable.BottomSheetBehavior_Params_behavior_hideable_ox, false));
    a.recycle();
    ViewConfiguration configuration = ViewConfiguration.get(context);
    mMaximumVelocity = configuration.getScaledMaximumFlingVelocity();
}

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

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

    final TypedArray a = context.obtainStyledAttributes(attrs,
            android.support.v7.preference.R.styleable.MultiSelectListPreference, defStyleAttr, defStyleRes);

    mEntries = TypedArrayUtils.getTextArray(a,
            android.support.v7.preference.R.styleable.MultiSelectListPreference_entries,
            android.support.v7.preference.R.styleable.MultiSelectListPreference_android_entries);

    mEntryValues = TypedArrayUtils.getTextArray(a,
            android.support.v7.preference.R.styleable.MultiSelectListPreference_entryValues,
            android.support.v7.preference.R.styleable.MultiSelectListPreference_android_entryValues);

    a.recycle();
}

From source file:ccv.checkhelzio.nuevaagendacucsh.transitions.FabTransition.java

public FabTransition(Context context, AttributeSet attrs) {
    super(context, attrs);
    TypedArray a = null;
    try {/*from  w  ww.  ja  va2  s  .  c om*/
        a = context.obtainStyledAttributes(attrs, R.styleable.FabTransition);
        if (!a.hasValue(R.styleable.FabTransition_fabColor) || !a.hasValue(R.styleable.FabTransition_fabIcon)) {
            throw new IllegalArgumentException("Must provide both color & icon.");
        }
        color = a.getColor(R.styleable.FabTransition_fabColor, Color.TRANSPARENT);
        icon = a.getResourceId(R.styleable.FabTransition_fabIcon, 0);
        setPathMotion(new GravityArcMotion());
        if (getDuration() < 0) {
            setDuration(DEFAULT_DURATION);
        }
    } finally {
        if (a != null) {
            a.recycle();
        }
    }
}

From source file:com.ichi2.anki.widgets.DeckAdapter.java

public DeckAdapter(LayoutInflater layoutInflater, Context context) {
    mLayoutInflater = layoutInflater;/*w  w w .j  av  a  2 s  .c om*/
    mDeckList = new ArrayList<>();
    // Get the colors from the theme attributes
    int[] attrs = new int[] { R.attr.zeroCountColor, R.attr.newCountColor, R.attr.learnCountColor,
            R.attr.reviewCountColor, R.attr.currentDeckBackground, android.R.attr.textColor,
            R.attr.dynDeckColor, R.attr.expandRef, R.attr.collapseRef };
    TypedArray ta = context.obtainStyledAttributes(attrs);
    Resources res = context.getResources();
    mZeroCountColor = ta.getColor(0, res.getColor(R.color.zero_count));
    mNewCountColor = ta.getColor(1, res.getColor(R.color.new_count));
    mLearnCountColor = ta.getColor(2, res.getColor(R.color.learn_count));
    mReviewCountColor = ta.getColor(3, res.getColor(R.color.review_count));
    mRowCurrentDrawable = ta.getResourceId(4, 0);
    mDeckNameDefaultColor = ta.getColor(5, res.getColor(R.color.black));
    mDeckNameDynColor = ta.getColor(6, res.getColor(R.color.deckadapter_deck_name_dyn));
    mExpandImage = ta.getDrawable(7);
    mCollapseImage = ta.getDrawable(8);
    ta.recycle();
}

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

private Typeface readFontFamilyTypeface(int resId) {
    final TypedArray a = mView.getContext().obtainStyledAttributes(resId,
            new int[] { android.R.attr.fontFamily });
    try {/* w  ww  .j a v  a 2  s  .  c o m*/
        final String family = a.getString(0);
        if (family != null) {
            return Typeface.create(family, Typeface.NORMAL);
        }
    } finally {
        a.recycle();
    }
    return null;
}

From source file:android.support.graphics.drawable.AnimatorInflaterCompat.java

private static PropertyValuesHolder[] loadValues(Context context, Resources res, Theme theme,
        XmlPullParser parser, AttributeSet attrs) throws XmlPullParserException, IOException {
    ArrayList<PropertyValuesHolder> values = null;

    int type;// www . j  ava  2  s .  co m
    while ((type = parser.getEventType()) != XmlPullParser.END_TAG && type != XmlPullParser.END_DOCUMENT) {

        if (type != XmlPullParser.START_TAG) {
            parser.next();
            continue;
        }

        String name = parser.getName();

        if (name.equals("propertyValuesHolder")) {
            TypedArray a = TypedArrayUtils.obtainAttributes(res, theme, attrs,
                    AndroidResources.STYLEABLE_PROPERTY_VALUES_HOLDER);

            String propertyName = TypedArrayUtils.getNamedString(a, parser, "propertyName",
                    AndroidResources.STYLEABLE_PROPERTY_VALUES_HOLDER_PROPERTY_NAME);
            int valueType = TypedArrayUtils.getNamedInt(a, parser, "valueType",
                    AndroidResources.STYLEABLE_PROPERTY_VALUES_HOLDER_VALUE_TYPE, VALUE_TYPE_UNDEFINED);

            PropertyValuesHolder pvh = loadPvh(context, res, theme, parser, propertyName, valueType);
            if (pvh == null) {
                pvh = getPVH(a, valueType, AndroidResources.STYLEABLE_PROPERTY_VALUES_HOLDER_VALUE_FROM,
                        AndroidResources.STYLEABLE_PROPERTY_VALUES_HOLDER_VALUE_TO, propertyName);
            }
            if (pvh != null) {
                if (values == null) {
                    values = new ArrayList<PropertyValuesHolder>();
                }
                values.add(pvh);
            }
            a.recycle();
        }

        parser.next();
    }

    PropertyValuesHolder[] valuesArray = null;
    if (values != null) {
        int count = values.size();
        valuesArray = new PropertyValuesHolder[count];
        for (int i = 0; i < count; ++i) {
            valuesArray[i] = values.get(i);
        }
    }
    return valuesArray;
}

From source file:android.support.v7.internal.widget.ActionBarOverlayLayout.java

private void init(Context context) {
    TypedArray ta = getContext().getTheme().obtainStyledAttributes(ATTRS);
    mActionBarHeight = ta.getDimensionPixelSize(0, 0);
    mWindowContentOverlay = ta.getDrawable(1);
    setWillNotDraw(mWindowContentOverlay == null);
    ta.recycle();

    mIgnoreWindowContentOverlay = context.getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.KITKAT;

    mFlingEstimator = ScrollerCompat.create(context);
}

From source file:android.support.v7.widget.AppCompatTextViewAutoSizeHelper.java

void loadFromAttributes(AttributeSet attrs, int defStyleAttr) {
    float autoSizeMinTextSizeInPx = UNSET_AUTO_SIZE_UNIFORM_CONFIGURATION_VALUE;
    float autoSizeMaxTextSizeInPx = UNSET_AUTO_SIZE_UNIFORM_CONFIGURATION_VALUE;
    float autoSizeStepGranularityInPx = UNSET_AUTO_SIZE_UNIFORM_CONFIGURATION_VALUE;

    TypedArray a = mContext.obtainStyledAttributes(attrs, R.styleable.AppCompatTextView, defStyleAttr, 0);
    if (a.hasValue(R.styleable.AppCompatTextView_autoSizeTextType)) {
        mAutoSizeTextType = a.getInt(R.styleable.AppCompatTextView_autoSizeTextType,
                TextViewCompat.AUTO_SIZE_TEXT_TYPE_NONE);
    }/*w  w  w. j  a  v a 2  s . c o m*/
    if (a.hasValue(R.styleable.AppCompatTextView_autoSizeStepGranularity)) {
        autoSizeStepGranularityInPx = a.getDimension(R.styleable.AppCompatTextView_autoSizeStepGranularity,
                UNSET_AUTO_SIZE_UNIFORM_CONFIGURATION_VALUE);
    }
    if (a.hasValue(R.styleable.AppCompatTextView_autoSizeMinTextSize)) {
        autoSizeMinTextSizeInPx = a.getDimension(R.styleable.AppCompatTextView_autoSizeMinTextSize,
                UNSET_AUTO_SIZE_UNIFORM_CONFIGURATION_VALUE);
    }
    if (a.hasValue(R.styleable.AppCompatTextView_autoSizeMaxTextSize)) {
        autoSizeMaxTextSizeInPx = a.getDimension(R.styleable.AppCompatTextView_autoSizeMaxTextSize,
                UNSET_AUTO_SIZE_UNIFORM_CONFIGURATION_VALUE);
    }
    if (a.hasValue(R.styleable.AppCompatTextView_autoSizePresetSizes)) {
        final int autoSizeStepSizeArrayResId = a
                .getResourceId(R.styleable.AppCompatTextView_autoSizePresetSizes, 0);
        if (autoSizeStepSizeArrayResId > 0) {
            final TypedArray autoSizePreDefTextSizes = a.getResources()
                    .obtainTypedArray(autoSizeStepSizeArrayResId);
            setupAutoSizeUniformPresetSizes(autoSizePreDefTextSizes);
            autoSizePreDefTextSizes.recycle();
        }
    }
    a.recycle();

    if (supportsAutoSizeText()) {
        if (mAutoSizeTextType == TextViewCompat.AUTO_SIZE_TEXT_TYPE_UNIFORM) {
            // If uniform auto-size has been specified but preset values have not been set then
            // replace the auto-size configuration values that have not been specified with the
            // defaults.
            if (!mHasPresetAutoSizeValues) {
                final DisplayMetrics displayMetrics = mContext.getResources().getDisplayMetrics();

                if (autoSizeMinTextSizeInPx == UNSET_AUTO_SIZE_UNIFORM_CONFIGURATION_VALUE) {
                    autoSizeMinTextSizeInPx = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP,
                            DEFAULT_AUTO_SIZE_MIN_TEXT_SIZE_IN_SP, displayMetrics);
                }

                if (autoSizeMaxTextSizeInPx == UNSET_AUTO_SIZE_UNIFORM_CONFIGURATION_VALUE) {
                    autoSizeMaxTextSizeInPx = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP,
                            DEFAULT_AUTO_SIZE_MAX_TEXT_SIZE_IN_SP, displayMetrics);
                }

                if (autoSizeStepGranularityInPx == UNSET_AUTO_SIZE_UNIFORM_CONFIGURATION_VALUE) {
                    autoSizeStepGranularityInPx = DEFAULT_AUTO_SIZE_GRANULARITY_IN_PX;
                }

                validateAndSetAutoSizeTextTypeUniformConfiguration(autoSizeMinTextSizeInPx,
                        autoSizeMaxTextSizeInPx, autoSizeStepGranularityInPx);
            }

            setupAutoSizeText();
        }
    } else {
        mAutoSizeTextType = TextViewCompat.AUTO_SIZE_TEXT_TYPE_NONE;
    }
}

From source file:com.albedinsky.android.setting.SettingSelectionDialogPreference.java

/**
 * Called from one of constructors of this setting preference to perform its initialization.
 * <p>//from ww w.j  a v a 2  s .  c  o m
 * Initialization is done via parsing of the specified <var>attrs</var> set and obtaining for
 * this preference specific data from it that can be used to configure this new preference instance.
 * The specified <var>defStyleAttr</var> and <var>defStyleRes</var> are used to obtain default
 * data from the current theme provided by the specified <var>context</var>.
 */
private void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    final TypedArray typedArray = context.obtainStyledAttributes(attrs,
            R.styleable.Ui_Settings_SelectionDialogPreference, defStyleAttr, defStyleRes);
    setEntries(typedArray.getTextArray(R.styleable.Ui_Settings_SelectionDialogPreference_android_entries));
    setEntryValues(
            typedArray.getTextArray(R.styleable.Ui_Settings_SelectionDialogPreference_android_entryValues));
    typedArray.recycle();
    this.mSummaryTextBuilder = new DefaultSummaryTextBuilder(SUMMARY_ENTRIES_SEPARATOR);
}