List of usage examples for android.content.res TypedArray recycle
public void recycle()
From source file:cn.androidy.materialdesignsample.ryanharterviewpager.ViewPager.java
public ViewPager(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ViewPager, defStyle, 0); mOrientation = a.getInt(R.styleable.ViewPager_orientation, ORIENTATION_HORIZONTAL); a.recycle(); initViewPager();//from w w w. jav a2s. c om }
From source file:android.support.designox.widget.CoordinatorLayout.java
public CoordinatorLayout(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); ThemeUtils.checkAppCompatTheme(context); final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CoordinatorLayout, defStyleAttr, R.style.Widget_Design_CoordinatorLayout); final int keylineArrayRes = a.getResourceId(R.styleable.CoordinatorLayout_keylines, 0); if (keylineArrayRes != 0) { final Resources res = context.getResources(); mKeylines = res.getIntArray(keylineArrayRes); final float density = res.getDisplayMetrics().density; final int count = mKeylines.length; for (int i = 0; i < count; i++) { mKeylines[i] *= density;/* w ww .j ava2 s. com*/ } } mStatusBarBackground = a.getDrawable(R.styleable.CoordinatorLayout_statusBarBackground); a.recycle(); if (INSETS_HELPER != null) { INSETS_HELPER.setupForWindowInsets(this, new ApplyInsetsListener()); } super.setOnHierarchyChangeListener(new HierarchyChangeListener()); }
From source file:com.actionbarsherlock.internal.widget.IcsProgressBar.java
/** * @hide/*from w w w. j a v a 2s. co m*/ */ public IcsProgressBar(Context context, AttributeSet attrs, int defStyle, int styleRes) { super(context, attrs, defStyle); mUiThreadId = Thread.currentThread().getId(); initProgressBar(); TypedArray a = context.obtainStyledAttributes(attrs, /*R.styleable.*/ProgressBar, defStyle, styleRes); mNoInvalidate = true; Drawable drawable = a.getDrawable(/*R.styleable.*/ProgressBar_progressDrawable); if (drawable != null) { drawable = tileify(drawable, false); // Calling this method can set mMaxHeight, make sure the corresponding // XML attribute for mMaxHeight is read after calling this method setProgressDrawable(drawable); } mDuration = a.getInt(/*R.styleable.*/ProgressBar_indeterminateDuration, mDuration); mMinWidth = a.getDimensionPixelSize(/*R.styleable.*/ProgressBar_minWidth, mMinWidth); mMaxWidth = a.getDimensionPixelSize(/*R.styleable.*/ProgressBar_maxWidth, mMaxWidth); mMinHeight = a.getDimensionPixelSize(/*R.styleable.*/ProgressBar_minHeight, mMinHeight); mMaxHeight = a.getDimensionPixelSize(/*R.styleable.*/ProgressBar_maxHeight, mMaxHeight); mBehavior = a.getInt(/*R.styleable.*/ProgressBar_indeterminateBehavior, mBehavior); final int resID = a.getResourceId(/*com.android.internal.R.styleable.*/ProgressBar_interpolator, android.R.anim.linear_interpolator); // default to linear interpolator if (resID > 0) { setInterpolator(context, resID); } setMax(a.getInt(/*R.styleable.*/ProgressBar_max, mMax)); setProgress(a.getInt(/*R.styleable.*/ProgressBar_progress, mProgress)); setSecondaryProgress(a.getInt(/*R.styleable.*/ProgressBar_secondaryProgress, mSecondaryProgress)); drawable = a.getDrawable(/*R.styleable.*/ProgressBar_indeterminateDrawable); if (drawable != null) { drawable = tileifyIndeterminate(drawable); setIndeterminateDrawable(drawable); } mOnlyIndeterminate = a.getBoolean(/*R.styleable.*/ProgressBar_indeterminateOnly, mOnlyIndeterminate); mNoInvalidate = false; setIndeterminate( mOnlyIndeterminate || a.getBoolean(/*R.styleable.*/ProgressBar_indeterminate, mIndeterminate)); mAnimationResolution = a.getInteger(/*R.styleable.*/ProgressBar_animationResolution, ANIMATION_RESOLUTION); a.recycle(); mAccessibilityManager = (AccessibilityManager) context.getSystemService(Context.ACCESSIBILITY_SERVICE); }
From source file:com.layer.atlas.AtlasMessagesList.java
public void parseStyle(Context context, AttributeSet attrs, int defStyle) { TypedArray ta = context.getTheme().obtainStyledAttributes(attrs, R.styleable.AtlasMessageList, R.attr.AtlasMessageList, defStyle); this.myTextColor = ta.getColor(R.styleable.AtlasMessageList_myTextColor, context.getResources().getColor(R.color.atlas_text_black)); this.myTextStyle = ta.getInt(R.styleable.AtlasMessageList_myTextStyle, Typeface.NORMAL); String myTextTypefaceName = ta.getString(R.styleable.AtlasMessageList_myTextTypeface); this.myTextTypeface = myTextTypefaceName != null ? Typeface.create(myTextTypefaceName, myTextStyle) : null; //this.myTextSize = ta.getDimension(R.styleable.AtlasMessageList_myTextSize, context.getResources().getDimension(R.dimen.atlas_text_size_general)); this.otherTextColor = ta.getColor(R.styleable.AtlasMessageList_theirTextColor, context.getResources().getColor(R.color.atlas_text_black)); this.otherTextStyle = ta.getInt(R.styleable.AtlasMessageList_theirTextStyle, Typeface.NORMAL); String otherTextTypefaceName = ta.getString(R.styleable.AtlasMessageList_theirTextTypeface); this.otherTextTypeface = otherTextTypefaceName != null ? Typeface.create(otherTextTypefaceName, otherTextStyle) : null;/*w w w. j av a 2s . co m*/ //this.otherTextSize = ta.getDimension(R.styleable.AtlasMessageList_theirTextSize, context.getResources().getDimension(R.dimen.atlas_text_size_general)); this.myBubbleColor = ta.getColor(R.styleable.AtlasMessageList_myBubbleColor, context.getResources().getColor(R.color.atlas_bubble_blue)); this.otherBubbleColor = ta.getColor(R.styleable.AtlasMessageList_theirBubbleColor, context.getResources().getColor(R.color.atlas_background_gray)); this.dateTextColor = ta.getColor(R.styleable.AtlasMessageList_dateTextColor, context.getResources().getColor(R.color.atlas_text_gray)); this.avatarTextColor = ta.getColor(R.styleable.AtlasMessageList_avatarTextColor, context.getResources().getColor(R.color.atlas_text_black)); this.avatarBackgroundColor = ta.getColor(R.styleable.AtlasMessageList_avatarBackgroundColor, context.getResources().getColor(R.color.atlas_background_gray)); ta.recycle(); }
From source file:android.transitions.everywhere.Transition.java
/** * Perform inflation from XML and apply a class-specific base style from a * theme attribute or style resource. This constructor of Transition allows * subclasses to use their own base style when they are inflating. * * @param context The Context the transition is running in, through which it can * access the current theme, resources, etc. * @param attrs The attributes of the XML tag that is inflating the transition. *///from ww w. ja v a 2 s .c om public Transition(Context context, AttributeSet attrs) { TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.Transition); long duration = a.getInt(R.styleable.Transition_duration, -1); if (duration >= 0) { setDuration(duration); } else { duration = a.getInt(R.styleable.Transition_android_duration, -1); if (duration >= 0) { setDuration(duration); } } long startDelay = a.getInt(R.styleable.Transition_startDelay, -1); if (startDelay > 0) { setStartDelay(startDelay); } int resID = a.getResourceId(R.styleable.Transition_interpolator, 0); if (resID > 0) { setInterpolator(AnimationUtils.loadInterpolator(context, resID)); } else { resID = a.getResourceId(R.styleable.Transition_android_interpolator, 0); if (resID > 0) { setInterpolator(AnimationUtils.loadInterpolator(context, resID)); } } String matchOrder = a.getString(R.styleable.Transition_matchOrder); if (matchOrder != null) { setMatchOrder(parseMatchOrder(matchOrder)); } a.recycle(); }
From source file:android.hqs.view.pager.indicator.TitlePageIndicator.java
/** * ?/*w ww . j av a2 s. c o m*/ * @param context * @param attrs * @param defStyle */ @SuppressWarnings("deprecation") public TitlePageIndicator(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); if (isInEditMode()) return; //Load defaults from resources final Resources res = getResources(); final int defaultFooterColor = res.getColor(R.color.default_title_indicator_footer_color); final int defaultSelectedColor = res.getColor(R.color.default_title_indicator_selected_color); final int defaultTextColor = res.getColor(R.color.default_title_indicator_text_color); final float defaultFooterLineHeight = res.getDimension(R.dimen.default_title_indicator_footer_line_height); final int defaultFooterIndicatorStyle = res .getInteger(R.integer.default_title_indicator_footer_indicator_style); final float defaultFooterIndicatorHeight = res .getDimension(R.dimen.default_title_indicator_footer_indicator_height); final float defaultFooterIndicatorUnderlinePadding = res .getDimension(R.dimen.default_title_indicator_footer_indicator_underline_padding); final float defaultFooterPadding = res.getDimension(R.dimen.default_title_indicator_footer_padding); final int defaultLinePosition = res.getInteger(R.integer.default_title_indicator_line_position); final boolean defaultSelectedBold = res.getBoolean(R.bool.default_title_indicator_selected_bold); final float defaultTextSize = res.getDimension(R.dimen.default_title_indicator_text_size); final float defaultTitlePadding = res.getDimension(R.dimen.default_title_indicator_title_padding); final float defaultClipPadding = res.getDimension(R.dimen.default_title_indicator_clip_padding); final float defaultTopPadding = res.getDimension(R.dimen.default_title_indicator_top_padding); //Retrieve styles attributes TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.TitlePageIndicator, defStyle, 0); //Retrieve the colors to be used for this view and apply them. mFooterLineHeight = a.getDimension(R.styleable.TitlePageIndicator_footerLineHeight, defaultFooterLineHeight); mFooterIndicatorStyle = IndicatorStyle.fromValue( a.getInteger(R.styleable.TitlePageIndicator_footerIndicatorStyle, defaultFooterIndicatorStyle)); mFooterIndicatorHeight = a.getDimension(R.styleable.TitlePageIndicator_footerIndicatorHeight, defaultFooterIndicatorHeight); mFooterIndicatorUnderlinePadding = a.getDimension( R.styleable.TitlePageIndicator_footerIndicatorUnderlinePadding, defaultFooterIndicatorUnderlinePadding); mFooterPadding = a.getDimension(R.styleable.TitlePageIndicator_footerPadding, defaultFooterPadding); mLinePosition = LinePosition .fromValue(a.getInteger(R.styleable.TitlePageIndicator_linePosition, defaultLinePosition)); mTopPadding = a.getDimension(R.styleable.TitlePageIndicator_topPadding, defaultTopPadding); mTitlePadding = a.getDimension(R.styleable.TitlePageIndicator_titlePadding, defaultTitlePadding); mClipPadding = a.getDimension(R.styleable.TitlePageIndicator_clipPadding, defaultClipPadding); mColorSelected = a.getColor(R.styleable.TitlePageIndicator_selectedColor, defaultSelectedColor); mColorText = a.getColor(R.styleable.TitlePageIndicator_android_textColor, defaultTextColor); mBoldText = a.getBoolean(R.styleable.TitlePageIndicator_selectedBold, defaultSelectedBold); final float textSize = a.getDimension(R.styleable.TitlePageIndicator_android_textSize, defaultTextSize); final int footerColor = a.getColor(R.styleable.TitlePageIndicator_footerColor, defaultFooterColor); mPaintText.setTextSize(textSize); mPaintText.setAntiAlias(true); mPaintFooterLine.setStyle(Paint.Style.FILL_AND_STROKE); mPaintFooterLine.setStrokeWidth(mFooterLineHeight); mPaintFooterLine.setColor(footerColor); mPaintFooterIndicator.setStyle(Paint.Style.FILL_AND_STROKE); mPaintFooterIndicator.setColor(footerColor); Drawable background = a.getDrawable(R.styleable.TitlePageIndicator_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:android.support.v7.widget.GridLayout.java
/** * {@inheritDoc}/* ww w .java2 s .c o m*/ */ public GridLayout(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); mDefaultGap = context.getResources().getDimensionPixelOffset(R.dimen.default_gap); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.GridLayout); try { setRowCount(a.getInt(ROW_COUNT, DEFAULT_COUNT)); setColumnCount(a.getInt(COLUMN_COUNT, DEFAULT_COUNT)); setOrientation(a.getInt(ORIENTATION, DEFAULT_ORIENTATION)); setUseDefaultMargins(a.getBoolean(USE_DEFAULT_MARGINS, DEFAULT_USE_DEFAULT_MARGINS)); setAlignmentMode(a.getInt(ALIGNMENT_MODE, DEFAULT_ALIGNMENT_MODE)); setRowOrderPreserved(a.getBoolean(ROW_ORDER_PRESERVED, DEFAULT_ORDER_PRESERVED)); setColumnOrderPreserved(a.getBoolean(COLUMN_ORDER_PRESERVED, DEFAULT_ORDER_PRESERVED)); } finally { a.recycle(); } }
From source file:br.liveo.searchliveo.SearchCardLiveo.java
private void initAttribute(Context context, AttributeSet attributeSet, int defStyleAttr) { TypedArray attr = context.obtainStyledAttributes(attributeSet, R.styleable.search_card_liveo, defStyleAttr, 0);/*from ww w .java2 s . co m*/ if (attr != null) { try { if (attr.hasValue(R.styleable.search_card_liveo_search_card_liveo_hint)) { hint(attr.getString(R.styleable.search_card_liveo_search_card_liveo_hint)); } if (attr.hasValue(R.styleable.search_card_liveo_search_card_liveo_text_color)) { mEdtSearch.setTextColor( attr.getColor(R.styleable.search_card_liveo_search_card_liveo_text_color, -1)); } if (attr.hasValue(R.styleable.search_card_liveo_search_card_liveo_hint_color)) { mEdtSearch.setHintTextColor( attr.getColor(R.styleable.search_card_liveo_search_card_liveo_hint_color, -1)); } if (attr.hasValue(R.styleable.search_card_liveo_search_card_liveo_color_icon)) { setColorIcon(attr.getColor(R.styleable.search_card_liveo_search_card_liveo_color_icon, -1)); } if (attr.hasValue(R.styleable.search_card_liveo_search_card_liveo_color_arrow)) { setColorIconArrow( attr.getColor(R.styleable.search_card_liveo_search_card_liveo_color_arrow, -1)); } if (attr.hasValue(R.styleable.search_card_liveo_search_card_liveo_color_voice)) { setColorIconVoice( attr.getColor(R.styleable.search_card_liveo_search_card_liveo_color_voice, -1)); } if (attr.hasValue(R.styleable.search_card_liveo_search_card_liveo_color_close)) { setColorIconClose( attr.getColor(R.styleable.search_card_liveo_search_card_liveo_color_close, -1)); } if (attr.hasValue(R.styleable.search_card_liveo_search_card_liveo_background)) { mCardSearch.setBackgroundColor( attr.getColor(R.styleable.search_card_liveo_search_card_liveo_background, -1)); } if (attr.hasValue(R.styleable.search_card_liveo_search_card_liveo_status_bar_show_color)) { setStatusBarShowColor(attr .getColor(R.styleable.search_card_liveo_search_card_liveo_status_bar_show_color, -1)); } if (attr.hasValue(R.styleable.search_card_liveo_search_card_liveo_status_bar_hide_color)) { setStatusBarHideColor(attr .getColor(R.styleable.search_card_liveo_search_card_liveo_status_bar_hide_color, -1)); } } finally { attr.recycle(); } } }
From source file:cn.njmeter.njmeter.widget.spinner.NiceSpinner.java
private void init(Context context, AttributeSet attrs) { Resources resources = getResources(); TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.NiceSpinner); int defaultPadding = resources.getDimensionPixelSize(R.dimen.one_and_a_half_grid_unit); setGravity(Gravity.CENTER_VERTICAL | Gravity.START); setPadding(resources.getDimensionPixelSize(R.dimen.three_grid_unit), defaultPadding, defaultPadding, defaultPadding);/* w ww. j a v a 2 s. c o m*/ setClickable(true); backgroundSelector = typedArray.getResourceId(R.styleable.NiceSpinner_backgroundSelector, R.drawable.selector); setBackgroundResource(backgroundSelector); textColor = typedArray.getColor(R.styleable.NiceSpinner_textTint, getDefaultTextColor(context)); setTextColor(textColor); listView = new ListView(context); // Set the spinner's id into the listview to make it pretend to be the right parent in // onItemClick listView.setId(getId()); listView.setDivider(new ColorDrawable(Color.GRAY)); listView.setDividerHeight(1); listView.setItemsCanFocus(true); //hide vertical and horizontal scrollbars listView.setVerticalScrollBarEnabled(false); listView.setHorizontalScrollBarEnabled(false); listView.setOverScrollMode(OVER_SCROLL_NEVER); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { selectedIndex = position; if (onItemClickListener != null) { onItemClickListener.onItemClick(parent, view, position, id); } if (onItemSelectedListener != null) { onItemSelectedListener.onItemSelected(parent, view, position, id); } adapter.setSelectedIndex(position); setTextInternal(adapter.getItemInDataset(position).toString()); dismissDropDown(); } }); popupWindow = new PopupWindow(context); popupWindow.setContentView(listView); popupWindow.setOutsideTouchable(true); popupWindow.setFocusable(true); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { popupWindow.setElevation(DEFAULT_ELEVATION); popupWindow.setBackgroundDrawable(ContextCompat.getDrawable(context, R.drawable.spinner_drawable)); } else { popupWindow.setBackgroundDrawable(ContextCompat.getDrawable(context, R.drawable.drop_down_shadow)); } popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() { @Override public void onDismiss() { if (!isArrowHidden) { animateArrow(false); } } }); isArrowHidden = typedArray.getBoolean(R.styleable.NiceSpinner_hideArrow, false); arrowDrawableTint = typedArray.getColor(R.styleable.NiceSpinner_arrowTint, Integer.MAX_VALUE); arrowDrawableResId = typedArray.getResourceId(R.styleable.NiceSpinner_arrowDrawable, R.drawable.arrow); dropDownListPaddingBottom = typedArray .getDimensionPixelSize(R.styleable.NiceSpinner_dropDownListPaddingBottom, 0); typedArray.recycle(); measureDisplayHeight(); }
From source file:android.support.design.widget.CoordinatorLayout.java
public CoordinatorLayout(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); ThemeUtils.checkAppCompatTheme(context); final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CoordinatorLayout, defStyleAttr, R.style.Widget_Design_CoordinatorLayout); final int keylineArrayRes = a.getResourceId(R.styleable.CoordinatorLayout_keylines, 0); if (keylineArrayRes != 0) { final Resources res = context.getResources(); mKeylines = res.getIntArray(keylineArrayRes); final float density = res.getDisplayMetrics().density; final int count = mKeylines.length; for (int i = 0; i < count; i++) { mKeylines[i] *= density;/*w ww .j a va 2 s .com*/ } } mStatusBarBackground = a.getDrawable(R.styleable.CoordinatorLayout_statusBarBackground); a.recycle(); setupForInsets(); super.setOnHierarchyChangeListener(new HierarchyChangeListener()); }