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:am.widget.scalerecyclerview.ScaleRecyclerView.java

private void initView(Context context, @Nullable AttributeSet attrs) {
    final TypedArray custom = context.obtainStyledAttributes(attrs, R.styleable.ScaleRecyclerView);
    mScaleEnable = custom.getBoolean(R.styleable.ScaleRecyclerView_srvScaleEnable, false);
    mScale = custom.getFloat(R.styleable.ScaleRecyclerView_srvScale, 1);
    mMinScale = custom.getFloat(R.styleable.ScaleRecyclerView_srvMinScale, 0.000000001f);
    mMaxScale = custom.getFloat(R.styleable.ScaleRecyclerView_srvMaxScale, 6);
    custom.recycle();
    mGestureDetector = new GestureDetectorCompat(context, new DoubleTapListener());
    mScaleGestureDetector = new ScaleGestureDetector(context, new ScaleListener());
}

From source file:androidx.mediarouter.app.MediaRouteButton.java

public MediaRouteButton(Context context, AttributeSet attrs, int defStyleAttr) {
    super(MediaRouterThemeHelper.createThemedButtonContext(context), attrs, defStyleAttr);
    context = getContext();/*from   ww  w.j  ava 2 s  .co  m*/

    mRouter = MediaRouter.getInstance(context);
    mCallback = new MediaRouterCallback();

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.MediaRouteButton, defStyleAttr, 0);
    mButtonTint = a.getColorStateList(R.styleable.MediaRouteButton_mediaRouteButtonTint);
    mMinWidth = a.getDimensionPixelSize(R.styleable.MediaRouteButton_android_minWidth, 0);
    mMinHeight = a.getDimensionPixelSize(R.styleable.MediaRouteButton_android_minHeight, 0);
    int remoteIndicatorResId = a.getResourceId(R.styleable.MediaRouteButton_externalRouteEnabledDrawable, 0);
    a.recycle();

    if (remoteIndicatorResId != 0) {
        Drawable.ConstantState remoteIndicatorState = sRemoteIndicatorCache.get(remoteIndicatorResId);
        if (remoteIndicatorState != null) {
            setRemoteIndicatorDrawable(remoteIndicatorState.newDrawable());
        } else {
            mRemoteIndicatorLoader = new RemoteIndicatorLoader(remoteIndicatorResId);
            mRemoteIndicatorLoader.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        }
    }

    updateContentDescription();
    setClickable(true);
}

From source file:com.eutectoid.dosomething.picker.PlacePickerFragment.java

@Override
public void onInflate(Activity activity, AttributeSet attrs, Bundle savedInstanceState) {
    super.onInflate(activity, attrs, savedInstanceState);
    TypedArray a = activity.obtainStyledAttributes(attrs, R.styleable.picker_place_picker_fragment);

    setRadiusInMeters(a.getInt(R.styleable.picker_place_picker_fragment_radius_in_meters, radiusInMeters));
    setResultsLimit(a.getInt(R.styleable.picker_place_picker_fragment_results_limit, resultsLimit));
    if (a.hasValue(R.styleable.picker_place_picker_fragment_results_limit)) {
        setSearchText(a.getString(R.styleable.picker_place_picker_fragment_search_text));
    }//from  w  w w  .ja va 2 s  .  c  o m
    showSearchBox = a.getBoolean(R.styleable.picker_place_picker_fragment_show_search_box, showSearchBox);

    a.recycle();
}

From source file:app.viewpagerindicator.UnderlinePageIndicator.java

public UnderlinePageIndicator(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    if (isInEditMode())
        return;/* w  w  w.  j a v  a2s .c  o m*/

    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) {
        setBackgroundDrawable(background);
    }

    a.recycle();

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

From source file:anabolicandroids.chanobol.util.swipebottom.SwipeRefreshLayoutBottom.java

/**
 * Constructor that is called when inflating SwipeRefreshLayout from XML.
 *
 * @param context//from   w w  w .  j  ava 2 s  . co m
 * @param attrs
 */
public SwipeRefreshLayoutBottom(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:ch.berta.fabio.fabprogress.FabProgress.java

/**
 * We are using private resources here in order to get the fab size. This is hacky but the
 * alternative would be that the user needs to specify the fab size two times in the XML.
 * TODO: only needed as long as we support api <21, because of the space the shadow drawable takes up
 *
 * @param context      the context to obtain the style attributes
 * @param attrs        the attribute set
 * @param defStyleAttr the style attr//ww  w  . j a v a 2 s . c o m
 */
@SuppressLint("PrivateResource")
private void setFakeShadowPadding(@NonNull Context context, @NonNull AttributeSet attrs, int defStyleAttr) {
    TypedArray attrFab = context.obtainStyledAttributes(attrs, R.styleable.FloatingActionButton, defStyleAttr,
            0);
    try {
        final Resources res = getResources();
        int size = attrFab.getInt(R.styleable.FloatingActionButton_fabSize, SIZE_NORMAL);
        if (size == SIZE_MINI) {
            mFabSize = res.getDimensionPixelSize(R.dimen.fp_fab_size_mini);
        } else {
            mFabSize = res.getDimensionPixelSize(R.dimen.fp_fab_size_normal);
        }
    } finally {
        attrFab.recycle();
    }

    final int maxContentSize = (int) getResources().getDimension(R.dimen.fp_fab_content_size);
    final int contentPadding = (mFabSize - maxContentSize) / 2;
    mShadowPadding.left = getPaddingLeft() - contentPadding;
    mShadowPadding.top = getPaddingTop() - contentPadding;
    mShadowPadding.right = getPaddingEnd() - contentPadding;
    mShadowPadding.bottom = getPaddingBottom() - contentPadding;
}

From source file:cn.com.elex.social_life.support.view.indicator.UnderlinePageIndicator.java

public UnderlinePageIndicator(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    if (isInEditMode())
        return;//w  ww. java  2s .  c o  m

    final Resources res = getResources();

    //Load defaults from resources
    final boolean defaultFades = res
            .getBoolean(cn.com.elex.social_life.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(cn.com.elex.social_life.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) {
        setBackgroundDrawable(background);
    }

    a.recycle();

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

From source file:banner.edgar.com.banner.UnderlinePageIndicator.java

public UnderlinePageIndicator(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    if (isInEditMode())
        return;//w  w w . j av a 2s .  co m

    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) {
        setBackgroundDrawable(background);
    }

    a.recycle();

}

From source file:cn.smilecity.viewpagerindicator.UnderlinePageIndicator.java

public UnderlinePageIndicator(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    if (isInEditMode())
        return;/*from ww w  .  j  a  va2  s  .c  o  m*/

    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.bg_title);

    // 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) {
        setBackgroundDrawable(background);
    }

    a.recycle();

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

From source file:android.view.SpringIndicator.java

private void initAttrs(final AttributeSet attrs) {
    textColorId = R.color.springIndicator_default_text_color;
    selectedTextColorId = R.color.springIndicator_default_text_color_selected;
    indicatorColorId = R.color.springIndicator_default_indicator_bg;
    textSize = getResources().getDimension(R.dimen.springIndicator_default_text_size);
    radiusMax = getResources().getDimension(R.dimen.springIndicator_default_radius_max);
    radiusMin = getResources().getDimension(R.dimen.springIndicator_default_radius_min);

    final TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.SpringIndicator);
    textColorId = a.getResourceId(R.styleable.SpringIndicator_textColor, textColorId);
    selectedTextColorId = a.getResourceId(R.styleable.SpringIndicator_selectedTextColor, selectedTextColorId);
    textSize = a.getDimension(R.styleable.SpringIndicator_textSize, textSize);
    textBgResId = a.getResourceId(R.styleable.SpringIndicator_textBackground, 0);
    indicatorColorId = a.getResourceId(R.styleable.SpringIndicator_indicatorColor, indicatorColorId);
    indicatorColorsId = a.getResourceId(R.styleable.SpringIndicator_indicatorColors, 0);
    radiusMax = a.getDimension(R.styleable.SpringIndicator_maxRadius, radiusMax);
    radiusMin = a.getDimension(R.styleable.SpringIndicator_minRadius, radiusMin);
    a.recycle();

    if (indicatorColorsId != 0)
        indicatorColorArray = getResources().getIntArray(indicatorColorsId);
    radiusOffset = radiusMax - radiusMin;
}