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:arun.com.chromer.settings.widgets.AppPreferenceCardView.java

private void init(AttributeSet attrs, int defStyle) {
    // Load attributes
    final TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.AppPreferenceCardView, defStyle,
            0);/*ww  w  . j  a  v  a2  s.c  o m*/
    if (!a.hasValue(R.styleable.AppPreferenceCardView_preferenceType)) {
        throw new IllegalArgumentException("Must specify app:preferenceType in xml");
    }

    preferenceType = a.getInt(R.styleable.AppPreferenceCardView_preferenceType, 0);
    setInitialValues();
    a.recycle();
    addView(LayoutInflater.from(getContext()).inflate(R.layout.widget_app_preference_cardview_content, this,
            false));
    unbinder = ButterKnife.bind(this);
}

From source file:cn.picksomething.slidingtabindicator.SlidingTabLayout.java

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

    TypedArray typedArray = getContext().obtainStyledAttributes(attrs, R.styleable.SlidingTabLayout);
    mTextFocusColor = typedArray.getColor(R.styleable.SlidingTabLayout_textSelectedColor, Color.WHITE);
    mTextDefaultColor = typedArray.getColor(R.styleable.SlidingTabLayout_textDefaultColor, Color.WHITE);
    typedArray.recycle();

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

    mTitleOffset = (int) (TITLE_OFFSET_DIPS * getResources().getDisplayMetrics().density);

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

From source file:com.fastbootmobile.encore.app.adapters.PlaylistListAdapter.java

@Override
public void onBindViewHolder(final ViewHolder holder, int position) {
    final int itemViewType = getItemViewType(position);

    if (itemViewType == VIEW_TYPE_HEADER) {
        SpecialViewHolder specialHolder = (SpecialViewHolder) holder;
        specialHolder.cardFavorites.setOnClickListener(new View.OnClickListener() {
            @Override/*  w ww . j  a v  a2  s .com*/
            public void onClick(View v) {
                Context ctx = v.getContext();
                Intent intent = PlaylistActivity.craftIntent(ctx, AutoPlaylistHelper.REF_SPECIAL_FAVORITES,
                        null);
                ctx.startActivity(intent);
            }
        });

        specialHolder.cardMostPlayed.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Context ctx = v.getContext();
                Intent intent = PlaylistActivity.craftIntent(ctx, AutoPlaylistHelper.REF_SPECIAL_MOST_PLAYED,
                        null);
                ctx.startActivity(intent);
            }
        });
    } else if (itemViewType == VIEW_TYPE_REGULAR) {
        final Playlist item = mPlaylists.get(position - 1);
        holder.tvPlaylistName.setText(item.getName());
        holder.ivCover.loadArtForPlaylist(item);

        if (item.isLoaded() || item.getSongsCount() > 0) {
            ProviderConnection provider = PluginsLookup.getDefault().getProvider(item.getProvider());
            if (provider != null) {
                holder.tvPlaylistDesc
                        .setText(String.format("%s / %s",
                                holder.tvPlaylistDesc.getContext().getResources().getQuantityString(
                                        R.plurals.xx_songs, item.getSongsCount(), item.getSongsCount()),
                                provider.getProviderName()));
            }

            holder.ivOfflineStatus.setVisibility(View.VISIBLE);

            switch (item.getOfflineStatus()) {
            case BoundEntity.OFFLINE_STATUS_NO:
                holder.ivOfflineStatus.setVisibility(View.GONE);
                break;

            case BoundEntity.OFFLINE_STATUS_DOWNLOADING:
                holder.ivOfflineStatus.setImageResource(R.drawable.ic_sync_in_progress);
                break;

            case BoundEntity.OFFLINE_STATUS_ERROR:
                holder.ivOfflineStatus.setImageResource(R.drawable.ic_sync_problem);
                break;

            case BoundEntity.OFFLINE_STATUS_PENDING:
                holder.ivOfflineStatus.setImageResource(R.drawable.ic_track_download_pending);
                break;

            case BoundEntity.OFFLINE_STATUS_READY:
                holder.ivOfflineStatus.setImageResource(R.drawable.ic_track_downloaded);
                break;
            }
        } else {
            holder.tvPlaylistDesc.setText(null);
            holder.ivOfflineStatus.setVisibility(View.GONE);
        }

        final int dragState = holder.getDragStateFlags();

        if (((dragState & RecyclerViewDragDropManager.STATE_FLAG_IS_UPDATED) != 0)) {
            int bgColor = 0;

            if ((dragState & RecyclerViewDragDropManager.STATE_FLAG_IS_ACTIVE) != 0) {
                bgColor = 0xFFDDDDDD;
            } else if ((dragState & RecyclerViewDragDropManager.STATE_FLAG_DRAGGING) != 0) {
                bgColor = 0xFFAAAAAA;
            }

            if (bgColor != 0) {
                holder.container.setBackgroundColor(bgColor);
            } else {
                int[] attrs = new int[] { android.R.attr.selectableItemBackground /* index 0 */ };
                TypedArray ta = holder.container.getContext().obtainStyledAttributes(attrs);
                Drawable drawableFromTheme = ta.getDrawable(0 /* index */);
                ta.recycle();
                holder.container.setBackground(drawableFromTheme);
            }
        }

        holder.container.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Context ctx = v.getContext();
                Intent intent = PlaylistActivity.craftIntent(ctx, item,
                        ((MaterialTransitionDrawable) holder.ivCover.getDrawable()).getFinalDrawable()
                                .getBitmap());

                if (Utils.hasLollipop()) {
                    ActivityOptions opt = ActivityOptions.makeSceneTransitionAnimation((Activity) ctx,
                            holder.ivCover, "itemImage");
                    ctx.startActivity(intent, opt.toBundle());
                } else {
                    ctx.startActivity(intent);
                }
            }
        });
    }
}

From source file:am.widget.tabstrip.TabStripViewGroup.java

private void initView(Context context, @Nullable AttributeSet attrs) {
    final TypedArray custom = context.obtainStyledAttributes(attrs, R.styleable.TabStripViewGroup);
    mHelper.set(custom.getResourceId(R.styleable.TabStripViewGroup_tsgViewPager, NO_ID),
            custom.getBoolean(R.styleable.TabStripViewGroup_tsgAutoFindViewPager, true),
            custom.getBoolean(R.styleable.TabStripViewGroup_tsgClickSmoothScroll, false));
    custom.recycle();
}

From source file:bigshots.people_helping_people.scroll_iew_lib.PagerSlidingTabStrip.java

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

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

    a.recycle();

    // get custom attrs

    indicatorColor = getResources().getColor(R.color.current_charity_color);
    underlineColor = indicatorColor;
    dividerColor = 0xffffffff;
    tabBackgroundResId = 0x00000000;

    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:com.manning.androidhacks.hack003.view.CascadeLayout.java

public CascadeLayout(Context context, AttributeSet attrs) {
    super(context, attrs);

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

    try {//w  ww.  j  a va  2  s . c  o m
        mHorizontalSpacing = a.getDimensionPixelSize(R.styleable.CascadeLayout_horizontal_spacing,
                getResources().getDimensionPixelSize(R.dimen.cascade_horizontal_spacing));

        mVerticalSpacing = a.getDimensionPixelSize(R.styleable.CascadeLayout_vertical_spacing,
                getResources().getDimensionPixelSize(R.dimen.cascade_vertical_spacing));
    } finally {
        a.recycle();
    }

}

From source file:app.newbee.lib.swipeback.SwipeBackLayout.java

public void attachToActivity(Activity activity) {
    mActivity = activity;//from www.j  a v a2  s  . c o m
    TypedArray a = activity.getTheme().obtainStyledAttributes(new int[] { android.R.attr.windowBackground });
    int background = a.getResourceId(0, 0);
    a.recycle();

    ViewGroup decor = (ViewGroup) activity.getWindow().getDecorView().findViewById(Window.ID_ANDROID_CONTENT);
    ViewGroup decorChild = (ViewGroup) decor.getChildAt(0);
    decorChild.setBackgroundResource(background);
    decor.removeView(decorChild);
    addView(decorChild);
    setContentView(decorChild);
    decor.addView(this);
}

From source file:ar.rulosoft.custompref.SeekBarCustomPreference.java

private void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CustomDialogPref, defStyleAttr,
            defStyleRes);//from ww  w  .j  a  v  a2s  .  co m
    setMax(a.getInt(R.styleable.CustomDialogPref_val_max, mPreferredMax));
    setMin(a.getInt(R.styleable.CustomDialogPref_val_min, mPreferredMin));
    a.recycle();
    setLayoutResource(R.layout.preference_seekbar_widget_layout);
}

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

public PatternPathMotion(Context context, AttributeSet attrs) {
    TypedArray a = context.obtainStyledAttributes(attrs, Styleable.PATTERN_PATH_MOTION);
    try {/*  w  w  w  . jav a  2s.com*/
        String pathData = TypedArrayUtils.getNamedString(a, (XmlPullParser) attrs, "patternPathData",
                Styleable.PatternPathMotion.PATTERN_PATH_DATA);
        if (pathData == null) {
            throw new RuntimeException("pathData must be supplied for patternPathMotion");
        }
        Path pattern = PathParser.createPathFromPathData(pathData);
        setPatternPath(pattern);
    } finally {
        a.recycle();
    }
}

From source file:cn.finalteam.galleryfinal.widget.FloatingActionButton.java

void init(Context context, AttributeSet attributeSet) {
    TypedArray attr = context.obtainStyledAttributes(attributeSet, R.styleable.GFFloatingActionButton, 0, 0);
    mColorNormal = attr.getColor(R.styleable.GFFloatingActionButton_fabColorNormal, Color.BLACK);
    mColorPressed = attr.getColor(R.styleable.GFFloatingActionButton_fabColorPressed, Color.BLACK);
    mIcon = attr.getResourceId(R.styleable.GFFloatingActionButton_fabIcon, 0);
    mTitle = attr.getString(R.styleable.GFFloatingActionButton_fabTitle);
    attr.recycle();

    updateCircleSize();// w  w w . jav a  2 s  .  c o m
    mShadowRadius = getDimension(R.dimen.fab_shadow_radius);
    mShadowOffset = getDimension(R.dimen.fab_shadow_offset);
    updateDrawableSize();

    updateBackground();
}