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:com.afwsamples.testdpc.common.preference.DpcPreferenceHelper.java

public DpcPreferenceHelper(Context context, Preference preference, AttributeSet attrs) {
    mContext = context;/*from   w  w w  .  ja  v  a  2 s.  c om*/
    mPreference = preference;

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

    mMinSdkVersion = a.getInt(R.styleable.DpcPreference_minSdkVersion, 0);
    if (attrs == null) {
        // Be more lenient when creating the preference from code
        mMinSdkVersion = Build.VERSION_CODES.LOLLIPOP;
    }
    if (mMinSdkVersion == 0) {
        throw new RuntimeException("testdpc:minSdkVersion must be specified.");
    }

    // noinspection ResourceType
    mAdminConstraint = a.getInt(R.styleable.DpcPreference_admin, ADMIN_DEFAULT);
    // noinspection ResourceType
    mUserConstraint = a.getInt(R.styleable.DpcPreference_user, USER_DEFAULT);

    a.recycle();
}

From source file:cn.edu.qzu.face.PagerSlidingTabStrip.java

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

    setFillViewport(true);//ww  w .  j a  va2s .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);

    tabTextColorStateList = a.getColorStateList(1);
    if (tabTextColorStateList == null) {
        tabTextColorStateList = ColorStateList.valueOf(tabTextColor);
    }

    a.recycle();

    // get custom attrs

    //      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);
    //      tabBackgroundResId = a.getResourceId(R.styleable.PagerSlidingTabStrip_pstsTabBackground, tabBackgroundResId);
    //      shouldExpand = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsShouldExpand, shouldExpand);
    //      scrollOffset = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsScrollOffset, scrollOffset);
    //      textAllCaps = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsTextAllCaps, textAllCaps);

    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:co.paulburke.android.textviewpager.TextViewPagerIndicator.java

public TextViewPagerIndicator(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    if (isInEditMode())
        return;//from w w w  .j a v a 2  s  .c  om

    final Resources res = getResources();

    // Load defaults from resources
    final boolean defaultFades = res.getBoolean(R.bool.scroll_indicator_fades);
    final int defaultFadeDelay = res.getInteger(R.integer.scroll_indicator_fade_delay);
    final int defaultFadeLength = res.getInteger(R.integer.scroll_indicator_fade_length);
    final int defaultSelectedColor = res.getColor(R.color.scroll_indicator_selected_color);

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

    setFades(a.getBoolean(R.styleable.TextViewPagerIndicator_fades, defaultFades));
    setSelectedColor(a.getColor(R.styleable.TextViewPagerIndicator_selectedColor, defaultSelectedColor));
    setFadeDelay(a.getInteger(R.styleable.TextViewPagerIndicator_fadeDelay, defaultFadeDelay));
    setFadeLength(a.getInteger(R.styleable.TextViewPagerIndicator_fadeLength, defaultFadeLength));

    Drawable background = a.getDrawable(R.styleable.TextViewPagerIndicator_android_background);
    if (background != null)
        setBackgroundDrawable(background);

    a.recycle();
}

From source file:com.adhere.view.swipe.SwipeRefreshLayout.java

/**
 * Constructor that is called when inflating SwipeRefreshLayout from XML.
 *
 * @param context/*  www. j a v a2 s  . c o  m*/
 * @param attrs
 */
public SwipeRefreshLayout(Context context, AttributeSet attrs) {
    super(context, attrs);

    mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();

    mMediumAnimationDuration = getResources().getInteger(android.R.integer.config_mediumAnimTime);

    setWillNotDraw(false);
    mDecelerateInterpolator = new DecelerateInterpolator(DECELERATE_INTERPOLATION_FACTOR);

    final TypedArray a = context.obtainStyledAttributes(attrs, LAYOUT_ATTRS);
    setEnabled(a.getBoolean(0, true));
    a.recycle();

    final DisplayMetrics metrics = getResources().getDisplayMetrics();
    mCircleWidth = (int) (CIRCLE_DIAMETER * metrics.density);
    mCircleHeight = (int) (CIRCLE_DIAMETER * metrics.density);

    createProgressView();
    ViewCompat.setChildrenDrawingOrderEnabled(this, true);
    // the absolute offset has to take into account that the circle starts at an offset
    mSpinnerFinalOffset = DEFAULT_CIRCLE_TARGET * metrics.density;
    mTotalDragDistance = mSpinnerFinalOffset;
}

From source file:android_network.hetnet.vpn_service.AdapterRule.java

public AdapterRule(Activity context) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);

    this.context = context;
    this.inflater = LayoutInflater.from(context);

    if (prefs.getBoolean("dark_theme", false))
        colorChanged = Color.argb(128, Color.red(Color.DKGRAY), Color.green(Color.DKGRAY),
                Color.blue(Color.DKGRAY));
    else//from w  ww . j  a  v  a  2 s .  co  m
        colorChanged = Color.argb(128, Color.red(Color.LTGRAY), Color.green(Color.LTGRAY),
                Color.blue(Color.LTGRAY));

    TypedArray ta = context.getTheme().obtainStyledAttributes(new int[] { android.R.attr.textColorPrimary });
    try {
        colorText = ta.getColor(0, 0);
    } finally {
        ta.recycle();
    }

    TypedValue tv = new TypedValue();
    context.getTheme().resolveAttribute(R.attr.colorOn, tv, true);
    colorOn = tv.data;
    context.getTheme().resolveAttribute(R.attr.colorOff, tv, true);
    colorOff = tv.data;

    colorGrayed = ContextCompat.getColor(context, R.color.colorGrayed);

    iconSize = Util.dips2pixels(48, context);
}

From source file:cc.wudoumi.framework.views.PagerSlidingTabStrip.java

public PagerSlidingTabStrip(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    tabBackgroundResId = R.drawable.background_tab;
    setFillViewport(true);/*from   w w w . j a va  2s. co 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);
    textColor = a.getColorStateList(1);
    if (textColor == null) {
        textColor = ColorStateList.valueOf(tabTextColor);
    }
    a.recycle();

    // get custom attrs

    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);
    tabBackgroundResId = a.getResourceId(R.styleable.PagerSlidingTabStrip_pstsTabBackground,
            tabBackgroundResId);
    shouldExpand = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsShouldExpand, shouldExpand);
    scrollOffset = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsScrollOffset, scrollOffset);
    textAllCaps = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsTextAllCaps, textAllCaps);

    selecttabTextSize = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsSelectTextSize,
            tabTextSize);
    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;
    }

    tabTextSizeChange = tabTextSize != selecttabTextSize;
}

From source file:com.actionbarsherlock.internal.widget.ActionBarContextView.java

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

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SherlockActionMode, defStyle, 0);
    setBackgroundDrawable(a.getDrawable(R.styleable.SherlockActionMode_background));
    mTitleStyleRes = a.getResourceId(R.styleable.SherlockActionMode_titleTextStyle, 0);
    mSubtitleStyleRes = a.getResourceId(R.styleable.SherlockActionMode_subtitleTextStyle, 0);

    mContentHeight = a.getLayoutDimension(R.styleable.SherlockActionMode_height, 0);

    mSplitBackground = a.getDrawable(R.styleable.SherlockActionMode_backgroundSplit);

    a.recycle();
}

From source file:br.com.leoleal.swipetorefresh.SwipeRefreshLayout.java

/**
 * Constructor that is called when inflating SwipeRefreshLayout from XML.
 *
 * @param context/* www .j a va  2 s . c  o  m*/
 * @param attrs
 */
public SwipeRefreshLayout(Context context, AttributeSet attrs) {
    super(context, attrs);

    mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();

    mMediumAnimationDuration = getResources().getInteger(android.R.integer.config_mediumAnimTime);

    setWillNotDraw(false);
    mDecelerateInterpolator = new DecelerateInterpolator(DECELERATE_INTERPOLATION_FACTOR);

    final TypedArray a = context.obtainStyledAttributes(attrs, LAYOUT_ATTRS);
    setEnabled(a.getBoolean(0, true));
    a.recycle();

    final DisplayMetrics metrics = getResources().getDisplayMetrics();
    mCircleWidth = (int) (CIRCLE_DIAMETER * metrics.density);
    mCircleHeight = (int) (CIRCLE_DIAMETER * metrics.density);

    createProgressView();
    SwipeRefreshLayout.setChildrenDrawingOrderEnabled(this, true);
    // the absolute offset has to take into account that the circle starts at an offset
    mSpinnerFinalOffset = DEFAULT_CIRCLE_TARGET * metrics.density;
    mTotalDragDistance = mSpinnerFinalOffset;
}

From source file:android.support.transition.ArcMotion.java

public ArcMotion(Context context, AttributeSet attrs) {
    super(context, attrs);
    TypedArray a = context.obtainStyledAttributes(attrs, Styleable.ARC_MOTION);
    XmlPullParser parser = (XmlPullParser) attrs;
    float minimumVerticalAngle = TypedArrayUtils.getNamedFloat(a, parser, "minimumVerticalAngle",
            Styleable.ArcMotion.MINIMUM_VERTICAL_ANGLE, DEFAULT_MIN_ANGLE_DEGREES);
    setMinimumVerticalAngle(minimumVerticalAngle);
    float minimumHorizontalAngle = TypedArrayUtils.getNamedFloat(a, parser, "minimumHorizontalAngle",
            Styleable.ArcMotion.MINIMUM_HORIZONTAL_ANGLE, DEFAULT_MIN_ANGLE_DEGREES);
    setMinimumHorizontalAngle(minimumHorizontalAngle);
    float maximumAngle = TypedArrayUtils.getNamedFloat(a, parser, "maximumAngle",
            Styleable.ArcMotion.MAXIMUM_ANGLE, DEFAULT_MAX_ANGLE_DEGREES);
    setMaximumAngle(maximumAngle);//from  w w  w  . j  ava 2s  .c  o m
    a.recycle();
}