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:chao.widget.tablayout.TabLayout.java

static void checkAppCompatTheme(Context context) {
    TypedArray a = context.obtainStyledAttributes(APPCOMPAT_CHECK_ATTRS);
    final boolean failed = !a.hasValue(0);
    if (a != null) {
        a.recycle();
    }//from  www  .j  a v a2 s .  c o m
    if (failed) {
        throw new IllegalArgumentException(
                "You need to use a Theme.AppCompat theme " + "(or descendant) with the design library.");
    }
}

From source file:android.hqs.view.pager.indicator.UnderlinePageIndicator.java

/**
 * ?/* www . j av  a2s . co m*/
 * @param context
 * @param attrs
 * @param defStyle
 */
@SuppressWarnings("deprecation")
public UnderlinePageIndicator(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    if (isInEditMode())
        return;

    final Resources res = getResources();

    //Load defaults from resources
    final boolean defaultFades = res.getBoolean(R.bool.default_underline_indicator_fades);
    final int defaultFadeDelay = res.getInteger(R.integer.default_underline_indicator_fade_delay);
    final int defaultFadeLength = res.getInteger(R.integer.default_underline_indicator_fade_length);
    final int defaultSelectedColor = res.getColor(R.color.default_underline_indicator_selected_color);

    //Retrieve styles attributes
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.UnderlinePageIndicator, defStyle, 0);

    setFades(a.getBoolean(R.styleable.UnderlinePageIndicator_fades, defaultFades));
    setSelectedColor(a.getColor(R.styleable.UnderlinePageIndicator_selectedColor, defaultSelectedColor));
    setFadeDelay(a.getInteger(R.styleable.UnderlinePageIndicator_fadeDelay, defaultFadeDelay));
    setFadeLength(a.getInteger(R.styleable.UnderlinePageIndicator_fadeLength, defaultFadeLength));

    Drawable background = a.getDrawable(R.styleable.UnderlinePageIndicator_android_background);
    if (background != null) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            setBackground(background);
        } else {
            setBackgroundDrawable(background);
        }
    }

    a.recycle();

    final ViewConfiguration configuration = ViewConfiguration.get(context);
    mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration);
}

From source file:ch.berta.fabio.fabprogress.FabProgress.java

private void init(@NonNull Context context, @NonNull AttributeSet attrs, int defStyleAttr) {
    mArcWidth = getResources().getDimensionPixelSize(R.dimen.fp_progress_arc_stroke_width);
    mFabIcon = getDrawable();// w  w w  .j  a  v a  2  s .  c o m
    mAccentColor = fetchAccentColor();

    TypedArray attr = context.obtainStyledAttributes(attrs, R.styleable.FabProgress, defStyleAttr, 0);
    try {
        mArcColor = attr.getColor(R.styleable.FabProgress_fp_arcColor,
                ContextCompat.getColor(context, R.color.green_500));
        mUseRoundedStroke = attr.getBoolean(R.styleable.FabProgress_fp_roundedStroke, false);
        mCompleteIcon = attr.getDrawable(R.styleable.FabProgress_fp_finalIcon);
        if (mCompleteIcon == null) {
            mCompleteIcon = ContextCompat.getDrawable(getContext(), R.drawable.ic_done_white_24dp);
        }
        mIsReusable = attr.getBoolean(R.styleable.FabProgress_fp_reusable, false);
    } finally {
        attr.recycle();
    }

    if (!Utils.isRunningLollipopAndHigher()) {
        setFakeShadowPadding(context, attrs, defStyleAttr);
    }

    setupPaint();
    setupAnimations();
}

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

/**
 * Construct a new SwitchPreference with the given style options.
 *
 * @param context The Context that will style this preference
 * @param attrs Style attributes that differ from the default
 * @param defStyleAttr An attribute in the current theme that contains a
 *        reference to a style resource that supplies default values for
 *        the view. Can be 0 to not look for defaults.
 * @param defStyleRes A resource identifier of a style resource that
 *        supplies default values for the view, used only if
 *        defStyleAttr is 0 or can not be found in the theme. Can be 0
 *        to not look for defaults./*from  w  ww .j ava 2s .c  om*/
 */
public SwitchPreferenceCompat(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    super(context, attrs, defStyleAttr, defStyleRes);

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SwitchPreferenceCompat, defStyleAttr,
            defStyleRes);

    setSummaryOn(TypedArrayUtils.getString(a, R.styleable.SwitchPreferenceCompat_summaryOn,
            R.styleable.SwitchPreferenceCompat_android_summaryOn));

    setSummaryOff(TypedArrayUtils.getString(a, R.styleable.SwitchPreferenceCompat_summaryOff,
            R.styleable.SwitchPreferenceCompat_android_summaryOff));

    setSwitchTextOn(TypedArrayUtils.getString(a, R.styleable.SwitchPreferenceCompat_switchTextOn,
            R.styleable.SwitchPreferenceCompat_android_switchTextOn));

    setSwitchTextOff(TypedArrayUtils.getString(a, R.styleable.SwitchPreferenceCompat_switchTextOff,
            R.styleable.SwitchPreferenceCompat_android_switchTextOff));

    setDisableDependentsState(
            TypedArrayUtils.getBoolean(a, R.styleable.SwitchPreferenceCompat_disableDependentsState,
                    R.styleable.SwitchPreferenceCompat_android_disableDependentsState, false));

    a.recycle();
}

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

public void setCollapsedSubAppearance(int resId) {
    TypedArray a = mView.getContext().obtainStyledAttributes(resId, R.styleable.TextAppearance);
    if (a.hasValue(R.styleable.TextAppearance_android_textColor)) {
        mCollapsedSubColor = a.getColor(R.styleable.TextAppearance_android_textColor, mCollapsedSubColor);
    }/*  w w  w .  j  a  va  2 s .  co  m*/
    if (a.hasValue(R.styleable.TextAppearance_android_textSize)) {
        mCollapsedSubSize = a.getDimensionPixelSize(R.styleable.TextAppearance_android_textSize,
                (int) mCollapsedSubSize);
    }
    a.recycle();
}

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

public void setCollapsedSubAppearance(int resId) {
    TypedArray a = mView.getContext().obtainStyledAttributes(resId, R.styleable.TextAppearance);
    if (a.hasValue(R.styleable.TextAppearance_android_textColor)) {
        mCollapsedSubColor = a.getColorStateList(R.styleable.TextAppearance_android_textColor);
    }//  w  ww  .  j  a v  a 2s  .  c  o  m
    if (a.hasValue(R.styleable.TextAppearance_android_textSize)) {
        mCollapsedSubSize = a.getDimensionPixelSize(R.styleable.TextAppearance_android_textSize,
                (int) mCollapsedSubSize);
    }
    a.recycle();
}

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

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

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

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

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

    a.recycle();

    // Need to theme the inflater to pick up the preferenceFragmentListStyle
    final TypedValue tv = new TypedValue();
    getActivity().getTheme().resolveAttribute(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");
    }//from  w ww.  j  av a2  s .  c o  m

    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:at.linuxtage.companion.widgets.SlidingTabLayout.java

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

    // Disable the Scroll Bar
    setHorizontalScrollBarEnabled(false);
    // Make sure that the Tab Strips fills this View
    setFillViewport(true);/*from   ww w .  java  2s .c  o m*/

    mTabStrip = new SlidingTabStrip(context);
    addView(mTabStrip, LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SlidingTabLayout, defStyle,
            R.style.SlidingTabLayout);

    mTabStrip.setSelectedIndicatorHeight(
            a.getDimensionPixelSize(R.styleable.SlidingTabLayout_indicatorHeight, 0));
    mTabStrip.setSelectedIndicatorColor(a.getColor(R.styleable.SlidingTabLayout_indicatorColor, 0));
    mTextColor = a.getColorStateList(R.styleable.SlidingTabLayout_textColor);
    if ((mTextColor != null) && a.hasValue(R.styleable.SlidingTabLayout_selectedTextColor)) {
        setTabTextColors(mTextColor.getDefaultColor(),
                a.getColor(R.styleable.SlidingTabLayout_selectedTextColor, 0));
    }
    setContentInsetStart(a.getDimensionPixelSize(R.styleable.SlidingTabLayout_contentInsetStart, 0));
    setDistributeEvenly(a.getBoolean(R.styleable.SlidingTabLayout_distributeEvenly, false));

    a.recycle();
}

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

/**
 */// www . j av a 2 s  . c  o  m
@Override
@SuppressWarnings("ResourceType")
protected void onConfigureDialogOptions(@NonNull SelectionDialog.SelectionOptions options,
        @NonNull Context context, @Nullable AttributeSet attrs, @AttrRes int defStyleAttr,
        @StyleRes int defStyleRes) {
    super.onConfigureDialogOptions(options, context, attrs, defStyleAttr, defStyleRes);
    final TypedArray typedArray = context.obtainStyledAttributes(attrs,
            R.styleable.Ui_Settings_SelectionDialogPreference, defStyleAttr, defStyleRes);
    for (int i = 0; i < typedArray.getIndexCount(); i++) {
        final int index = typedArray.getIndex(i);
        if (index == R.styleable.Ui_Settings_SelectionDialogPreference_dialogSelectionMode) {
            options.selectionMode(typedArray.getInt(index, options.selectionMode()));
        } else if (index == R.styleable.Ui_Settings_SelectionDialogPreference_dialogEmptySelectionAllowed) {
            options.emptySelectionAllowed(typedArray.getBoolean(index, options.shouldAllowEmptySelection()));
        }
    }
    typedArray.recycle();
}

From source file:com.roselism.bottomsheet.BottomSheet.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    init(getContext());/*from w w  w. j  ava2  s  .c  o  m*/

    WindowManager.LayoutParams params = getWindow().getAttributes();
    params.height = ViewGroup.LayoutParams.WRAP_CONTENT;
    params.gravity = Gravity.BOTTOM;

    TypedArray a = getContext().obtainStyledAttributes(new int[] { android.R.attr.layout_width });
    try {
        params.width = a.getLayoutDimension(0, ViewGroup.LayoutParams.MATCH_PARENT);
    } finally {
        a.recycle();
    }
    super.setOnDismissListener(new OnDismissListener() {
        @Override
        public void onDismiss(DialogInterface dialog) {
            if (dismissListener != null) {
                dismissListener.onDismiss(dialog);
            }
            if (limit != Integer.MAX_VALUE) {
                showShortItems();
            }
        }
    });
    getWindow().setAttributes(params);
}