Java Code Examples for android.content.res.TypedArray#recycle()

The following examples show how to use android.content.res.TypedArray#recycle() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RuleView.java    From RulerView with Apache License 2.0 6 votes vote down vote up
private void initAttrs(Context context, AttributeSet attrs) {
    TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.RuleView);
    bgColor = ta.getColor(R.styleable.RuleView_zjun_bgColor, Color.parseColor("#f5f8f5"));
    gradationColor = ta.getColor(R.styleable.RuleView_zjun_gradationColor, Color.LTGRAY);
    shortLineWidth = ta.getDimension(R.styleable.RuleView_gv_shortLineWidth, dp2px(1));
    shortGradationLen = ta.getDimension(R.styleable.RuleView_gv_shortGradationLen, dp2px(16));
    longGradationLen = ta.getDimension(R.styleable.RuleView_gv_longGradationLen, shortGradationLen * 2);
    longLineWidth = ta.getDimension(R.styleable.RuleView_gv_longLineWidth, shortLineWidth * 2);
    textColor = ta.getColor(R.styleable.RuleView_zjun_textColor, Color.BLACK);
    textSize = ta.getDimension(R.styleable.RuleView_zjun_textSize, sp2px(14));
    indicatorLineColor = ta.getColor(R.styleable.RuleView_zjun_indicatorLineColor, Color.parseColor("#48b975"));
    indicatorLineWidth = ta.getDimension(R.styleable.RuleView_zjun_indicatorLineWidth, dp2px(3f));
    indicatorLineLen = ta.getDimension(R.styleable.RuleView_gv_indicatorLineLen, dp2px(35f));
    minValue = ta.getFloat(R.styleable.RuleView_gv_minValue, 0f);
    maxValue = ta.getFloat(R.styleable.RuleView_gv_maxValue, 100f);
    currentValue = ta.getFloat(R.styleable.RuleView_gv_currentValue, 50f);
    gradationUnit = ta.getFloat(R.styleable.RuleView_gv_gradationUnit, .1f);
    numberPerCount = ta.getInt(R.styleable.RuleView_gv_numberPerCount, 10);
    gradationGap = ta.getDimension(R.styleable.RuleView_gv_gradationGap, dp2px(10));
    gradationNumberGap = ta.getDimension(R.styleable.RuleView_gv_gradationNumberGap, dp2px(8));
    ta.recycle();
}
 
Example 2
Source File: ActionBarContextView.java    From android-apps with MIT License 6 votes vote down vote up
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();
}
 
Example 3
Source File: FloatingActionsMenu.java    From UltimateAndroid with Apache License 2.0 6 votes vote down vote up
private void init(Context context, AttributeSet attributeSet) {
    mAddButtonPlusColor = getColor(android.R.color.white);
    mAddButtonColorNormal = getColor(android.R.color.holo_blue_dark);
    mAddButtonColorPressed = getColor(android.R.color.holo_blue_light);

    mButtonSpacing = (int) (getResources().getDimension(R.dimen.fab_actions_spacing) - getResources().getDimension(R.dimen.fab_shadow_radius) - getResources().getDimension(R.dimen.fab_shadow_offset));

    if (attributeSet != null) {
        TypedArray attr = context.obtainStyledAttributes(attributeSet, R.styleable.FloatingActionsMenu, 0, 0);
        if (attr != null) {
            try {
                mAddButtonPlusColor = attr.getColor(R.styleable.FloatingActionsMenu_addButtonPlusIconColor, getColor(android.R.color.white));
                mAddButtonColorNormal = attr.getColor(R.styleable.FloatingActionsMenu_addButtonColorNormal, getColor(android.R.color.holo_blue_dark));
                mAddButtonColorPressed = attr.getColor(R.styleable.FloatingActionsMenu_addButtonColorPressed, getColor(android.R.color.holo_blue_light));
                isHorizontal = attr.getBoolean(R.styleable.FloatingActionsMenu_addButtonIsHorizontal, false);
            } finally {
                attr.recycle();
            }
        }
    }

    createAddButton(context);
}
 
Example 4
Source File: BookmarkCard.java    From IslamicLibraryAndroid with GNU General Public License v3.0 6 votes vote down vote up
private void initialize(@NonNull Context context, AttributeSet attrs, int defStyleAttr) {
    View rootView = inflate(getContext(), R.layout.bookmark_card, this);
    TypedArray a = context.getTheme().obtainStyledAttributes(attrs,
            R.styleable.NoteCard,
            defStyleAttr, 0);

    try {
        isShowBook = a.getBoolean(R.styleable.NoteCard_showBook, false);
        isDhowAuthor = a.getBoolean(R.styleable.NoteCard_showAuthor, false);
        isShowCollection = a.getBoolean(R.styleable.NoteCard_showCollection, false);
        isShowCategory = a.getBoolean(R.styleable.NoteCard_showCategory, false);
    } finally {
        a.recycle();
    }
    parentTitleTextView = rootView.findViewById(R.id.toc_card_body);
    bookInfoTextView = rootView.findViewById(R.id.book_info_text_view);
    refreshBookInfo();

    pageNumberTextView = rootView.findViewById(R.id.page_part_number);
    dateTimeTextView = rootView.findViewById(R.id.date_time);
    bookmarkIcon = rootView.findViewById(R.id.bookmark_icon);
}
 
Example 5
Source File: SubtitlePainter.java    From no-player with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("ResourceType")        // We're hacking `spacingMult = styledAttributes.getFloat`
SubtitlePainter(Context context) {
    int[] viewAttr = {android.R.attr.lineSpacingExtra, android.R.attr.lineSpacingMultiplier};
    TypedArray styledAttributes = context.obtainStyledAttributes(null, viewAttr, 0, 0);
    spacingAdd = styledAttributes.getDimensionPixelSize(0, 0);
    spacingMult = styledAttributes.getFloat(1, 1);
    styledAttributes.recycle();

    Resources resources = context.getResources();
    DisplayMetrics displayMetrics = resources.getDisplayMetrics();
    int twoDpInPx = Math.round((TWO_DP * displayMetrics.densityDpi) / DisplayMetrics.DENSITY_DEFAULT);
    cornerRadius = twoDpInPx;
    outlineWidth = twoDpInPx;
    shadowRadius = twoDpInPx;
    shadowOffset = twoDpInPx;

    textPaint = new TextPaint();
    textPaint.setAntiAlias(true);
    textPaint.setSubpixelText(true);

    paint = new Paint();
    paint.setAntiAlias(true);
    paint.setStyle(Style.FILL);
}
 
Example 6
Source File: Building.java    From MultiChoiceAdapter with Apache License 2.0 5 votes vote down vote up
public static ArrayList<Building> createList(Context ctx) {
    Resources res = ctx.getResources();
    String[] names = res.getStringArray(R.array.names);
    String[] heights = res.getStringArray(R.array.heights);
    TypedArray icons = res.obtainTypedArray(R.array.photos);
    ArrayList<Building> items = new ArrayList<Building>(names.length);
    for (int i = 0; i < names.length; ++i) {
        items.add(new Building(names[i], heights[i], icons.getDrawable(i)));
    }
    icons.recycle();
    return items;
}
 
Example 7
Source File: BannerView.java    From YCBanner with Apache License 2.0 5 votes vote down vote up
/**
 * 读取提示形式  和   提示位置   和    播放延迟
 */
private void initView(AttributeSet attrs){
       //这里要做移除,有时在使用中没有手动销毁,所以初始化时要remove
	if(mViewPager!=null){
		removeView(mViewPager);
	}

	//初始化自定义属性
	TypedArray type = getContext().obtainStyledAttributes(attrs, R.styleable.BannerView);
       hintMode = type.getInteger(R.styleable.BannerView_hint_mode, 0);
       gravity = type.getInteger(R.styleable.BannerView_hint_gravity, 1);
	delay = type.getInt(R.styleable.BannerView_play_delay, 0);
	color = type.getColor(R.styleable.BannerView_hint_color, Color.BLACK);
	alpha = type.getInt(R.styleable.BannerView_hint_alpha, 0);
	paddingLeft = (int) type.getDimension(R.styleable.BannerView_hint_paddingLeft, 0);
	paddingRight = (int) type.getDimension(R.styleable.BannerView_hint_paddingRight, 0);
	paddingTop = (int) type.getDimension(R.styleable.BannerView_hint_paddingTop, 0);
	paddingBottom = (int) type.getDimension(R.styleable.BannerView_hint_paddingBottom
               , LibUtils.dip2px(getContext(),4));
       type.recycle();

       //创建ViewPager
	mViewPager = new BannerViewPager(getContext());
	mViewPager.setId(R.id.banner_inner);
	mViewPager.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT
               , LayoutParams.MATCH_PARENT));
	addView(mViewPager);

	if(hintMode== BannerConstant.HintMode.COLOR_POINT_HINT){
           initHint(new ColorPointHintView(getContext(), Color.parseColor("#E3AC42")
                   , Color.parseColor("#88ffffff")));
       }else if(hintMode== BannerConstant.HintMode.TEXT_HINT){
           initHint(new TextHintView(getContext()));
       }else {
           initHint(new ColorPointHintView(getContext(), Color.parseColor("#E3AC42")
                   , Color.parseColor("#88ffffff")));
       }
       initGestureDetector();
}
 
Example 8
Source File: Tools.java    From andOTP with MIT License 5 votes vote down vote up
public static int getThemeColor(Context context, int colorAttr) {
    Resources.Theme theme = context.getTheme();
    TypedArray arr = theme.obtainStyledAttributes(new int[]{colorAttr});

    int colorValue = arr.getColor(0, -1);
    arr.recycle();

    return colorValue;
}
 
Example 9
Source File: PaddedFrameLayout.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Constructor for inflating from XML.
 */
public PaddedFrameLayout(Context context, AttributeSet attrs) {
    super(context, attrs);
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PaddedFrameLayout);
    mMaxChildWidth = a.getDimensionPixelSize(
            R.styleable.PaddedFrameLayout_maxChildWidth, NO_MAX_SIZE);
    mMaxChildHeight = a.getDimensionPixelSize(
            R.styleable.PaddedFrameLayout_maxChildHeight, NO_MAX_SIZE);
    a.recycle();
}
 
Example 10
Source File: AttrUtil.java    From Contacts with MIT License 5 votes vote down vote up
public static Drawable[] getDrawable(Context context, int[] attrs)
{
	TypedArray ta = context.obtainStyledAttributes(attrs);
	Drawable[] drawables = new Drawable[attrs.length];
	
	for (int i = 0; i < attrs.length; i++)
	{
		drawables[i] = ta.getDrawable(i);
	}
	
	ta.recycle();
	
	return drawables;
}
 
Example 11
Source File: EmojiTextView.java    From hipda with GNU General Public License v2.0 5 votes vote down vote up
private void init(@Nullable final AttributeSet attrs) {
    if (attrs == null) {
        emojiSize = (int) getTextSize();
    } else {
        final TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.emoji);

        try {
            emojiSize = (int) a.getDimension(R.styleable.emoji_emojiSize, getTextSize());
        } finally {
            a.recycle();
        }
    }

    setText(getText());
}
 
Example 12
Source File: LearnMorePreference.java    From delion with Apache License 2.0 5 votes vote down vote up
public LearnMorePreference(Context context, AttributeSet attrs) {
    super(context, attrs);
    TypedArray a = context.obtainStyledAttributes(attrs,
            R.styleable.LearnMorePreference, 0, 0);
    mHelpContext = a.getResourceId(R.styleable.LearnMorePreference_helpContext, 0);
    a.recycle();
    setTitle(R.string.learn_more);
}
 
Example 13
Source File: ShareListItem.java    From Silence with GNU General Public License v3.0 5 votes vote down vote up
private void setBackground() {
  int[]      attributes = new int[]{R.attr.conversation_list_item_background_read};
  TypedArray drawables  = context.obtainStyledAttributes(attributes);

  setBackgroundDrawable(drawables.getDrawable(0));

  drawables.recycle();
}
 
Example 14
Source File: ViewPager.java    From GifAssistant with Apache License 2.0 5 votes vote down vote up
public LayoutParams(Context context, AttributeSet attrs) {
    super(context, attrs);

    final TypedArray a = context.obtainStyledAttributes(attrs, LAYOUT_ATTRS);
    gravity = a.getInteger(0, Gravity.TOP);
    a.recycle();
}
 
Example 15
Source File: CollapsingTitleBarLayout.java    From UIWidget with Apache License 2.0 5 votes vote down vote up
public LayoutParams(Context c, AttributeSet attrs) {
    super(c, attrs);

    TypedArray a = c.obtainStyledAttributes(attrs,
            R.styleable.CollapsingTitleBarLayout_Layout);
    mCollapseMode = a.getInt(
            R.styleable.CollapsingTitleBarLayout_Layout_collapsing_layout_collapseMode,
            COLLAPSE_MODE_OFF);
    setParallaxMultiplier(a.getFloat(
            R.styleable.CollapsingTitleBarLayout_Layout_collapsing_layout_collapseParallaxMultiplier,
            DEFAULT_PARALLAX_MULTIPLIER));
    a.recycle();
}
 
Example 16
Source File: DrawableTint.java    From Popeens-DSub with GNU General Public License v3.0 5 votes vote down vote up
public static int getDrawableRes(Context context, @AttrRes int drawableAttr) {
	if(attrMap.containsKey(drawableAttr)) {
		return attrMap.get(drawableAttr);
	} else {
		int[] attrs = new int[]{drawableAttr};
		TypedArray typedArray = context.obtainStyledAttributes(attrs);
		@DrawableRes int drawableRes = typedArray.getResourceId(0, 0);
		typedArray.recycle();
		attrMap.put(drawableAttr, drawableRes);
		return drawableRes;
	}
}
 
Example 17
Source File: PreferenceFrameLayout.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
public PreferenceFrameLayout(
        Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    super(context, attrs, defStyleAttr, defStyleRes);
    final TypedArray a = context.obtainStyledAttributes(attrs,
            com.android.internal.R.styleable.PreferenceFrameLayout, defStyleAttr, defStyleRes);

    float density = context.getResources().getDisplayMetrics().density;
    int defaultBorderTop = (int) (density * DEFAULT_BORDER_TOP + 0.5f);
    int defaultBottomPadding = (int) (density * DEFAULT_BORDER_BOTTOM + 0.5f);
    int defaultLeftPadding = (int) (density * DEFAULT_BORDER_LEFT + 0.5f);
    int defaultRightPadding = (int) (density * DEFAULT_BORDER_RIGHT + 0.5f);

    mBorderTop = a.getDimensionPixelSize(
            com.android.internal.R.styleable.PreferenceFrameLayout_borderTop,
            defaultBorderTop);
    mBorderBottom = a.getDimensionPixelSize(
            com.android.internal.R.styleable.PreferenceFrameLayout_borderBottom,
            defaultBottomPadding);
    mBorderLeft = a.getDimensionPixelSize(
            com.android.internal.R.styleable.PreferenceFrameLayout_borderLeft,
            defaultLeftPadding);
    mBorderRight = a.getDimensionPixelSize(
            com.android.internal.R.styleable.PreferenceFrameLayout_borderRight,
            defaultRightPadding);

    a.recycle();
}
 
Example 18
Source File: StyleUtils.java    From IslamicLibraryAndroid with GNU General Public License v3.0 4 votes vote down vote up
public static void setThemedActionBarDrawable(Context context, ActionBar actionBar) {
    TypedArray a = context.obtainStyledAttributes(null, R.styleable.BooksTheme, 0, 0);
    actionBar.setBackgroundDrawable(a.getDrawable(0));
    a.recycle();
}
 
Example 19
Source File: DividerItemDecoration.java    From AndroidRecyclerViewDemo with Apache License 2.0 4 votes vote down vote up
public DividerItemDecoration(Context context, int orientation) {
    final TypedArray a = context.obtainStyledAttributes(ATTRS);
    mDivider = a.getDrawable(0);
    a.recycle();
    setOrientation(orientation);
}
 
Example 20
Source File: DividerItemDecoration.java    From timecat with Apache License 2.0 4 votes vote down vote up
public DividerItemDecoration(Context context, int orientation) {
    final TypedArray a = context.obtainStyledAttributes(ATTRS);
    mDivider = a.getDrawable(0);
    a.recycle();
    setOrientation(orientation);
}