List of usage examples for android.content.res TypedArray recycle
public void recycle()
From source file:com.wellsandwhistles.android.redditsp.reddit.prepared.RedditPreparedPost.java
private void colorKarma(Context context) { final int boldCol; final int rrPostSubtitleUpvoteCol; final int rrPostSubtitleDownvoteCol; final TypedArray appearance = context.obtainStyledAttributes(new int[] { R.attr.srPostSubtitleBoldCol, R.attr.srPostSubtitleUpvoteCol, R.attr.srPostSubtitleDownvoteCol }); boldCol = appearance.getColor(0, 255); rrPostSubtitleUpvoteCol = appearance.getColor(1, 255); rrPostSubtitleDownvoteCol = appearance.getColor(2, 255); appearance.recycle(); final BetterSSB karmaSB = new BetterSSB(); final int pointsCol; final int score = computeScore(); if (isUpvoted()) { pointsCol = rrPostSubtitleUpvoteCol; } else if (isDownvoted()) { pointsCol = rrPostSubtitleDownvoteCol; } else {//from www . j ava 2 s. c o m pointsCol = boldCol; } karmaSB.append(String.valueOf(score), BetterSSB.BOLD | BetterSSB.FOREGROUND_COLOR, pointsCol, 0, 1f); postKarma = karmaSB.get(); }
From source file:android.hqs.view.pager.indicator.LinePageIndicator.java
/** * ?//from w ww . j a v a 2s . c o m * @param context * @param attrs * @param defStyle */ @SuppressWarnings("deprecation") public LinePageIndicator(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); if (isInEditMode()) return; final Resources res = getResources(); //Load defaults from resources final int defaultSelectedColor = res.getColor(R.color.default_line_indicator_selected_color); final int defaultUnselectedColor = res.getColor(R.color.default_line_indicator_unselected_color); final float defaultLineWidth = res.getDimension(R.dimen.default_line_indicator_line_width); final float defaultGapWidth = res.getDimension(R.dimen.default_line_indicator_gap_width); final float defaultStrokeWidth = res.getDimension(R.dimen.default_line_indicator_stroke_width); final boolean defaultCentered = res.getBoolean(R.bool.default_line_indicator_centered); //Retrieve styles attributes TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.LinePageIndicator, defStyle, 0); mCentered = a.getBoolean(R.styleable.LinePageIndicator_centered, defaultCentered); mLineWidth = a.getDimension(R.styleable.LinePageIndicator_lineWidth, defaultLineWidth); mGapWidth = a.getDimension(R.styleable.LinePageIndicator_gapWidth, defaultGapWidth); setStrokeWidth(a.getDimension(R.styleable.LinePageIndicator_strokeWidth, defaultStrokeWidth)); mPaintUnselected .setColor(a.getColor(R.styleable.LinePageIndicator_unselectedColor, defaultUnselectedColor)); mPaintSelected.setColor(a.getColor(R.styleable.LinePageIndicator_selectedColor, defaultSelectedColor)); Drawable background = a.getDrawable(R.styleable.LinePageIndicator_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:biz.laenger.android.vpbs.ViewPagerBottomSheetBehavior.java
/** * Default constructor for inflating ViewPagerBottomSheetBehaviors from layout. * * @param context The {@link Context}.//from w w w .j a va 2 s.c o m * @param attrs The {@link AttributeSet}. */ public ViewPagerBottomSheetBehavior(Context context, AttributeSet attrs) { super(context, attrs); scrollableViews = new ArrayList<>(); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.BottomSheetBehavior_Layout); TypedValue value = a.peekValue(R.styleable.BottomSheetBehavior_Layout_behavior_peekHeight); if (value != null && value.data == PEEK_HEIGHT_AUTO) { setPeekHeight(value.data); } else { setPeekHeight(a.getDimensionPixelSize(R.styleable.BottomSheetBehavior_Layout_behavior_peekHeight, PEEK_HEIGHT_AUTO)); } setHideable(a.getBoolean(R.styleable.BottomSheetBehavior_Layout_behavior_hideable, false)); setSkipCollapsed(a.getBoolean(R.styleable.BottomSheetBehavior_Layout_behavior_skipCollapsed, false)); a.recycle(); ViewConfiguration configuration = ViewConfiguration.get(context); mMaximumVelocity = configuration.getScaledMaximumFlingVelocity(); }
From source file:android.support.v17.leanback.app.BackgroundManager.java
private BackgroundManager(Activity activity, boolean isSupportFragmentActivity) { mContext = activity;// w w w . j a va 2 s . co m mService = BackgroundContinuityService.getInstance(); mHeightPx = mContext.getResources().getDisplayMetrics().heightPixels; mWidthPx = mContext.getResources().getDisplayMetrics().widthPixels; mHandler = new Handler(); Interpolator defaultInterpolator = new FastOutLinearInInterpolator(); mAccelerateInterpolator = AnimationUtils.loadInterpolator(mContext, android.R.anim.accelerate_interpolator); mDecelerateInterpolator = AnimationUtils.loadInterpolator(mContext, android.R.anim.decelerate_interpolator); mAnimator = ValueAnimator.ofInt(0, FULL_ALPHA); mAnimator.addListener(mAnimationListener); mAnimator.addUpdateListener(mAnimationUpdateListener); mAnimator.setInterpolator(defaultInterpolator); mDimAnimator = new ValueAnimator(); mDimAnimator.addUpdateListener(mDimUpdateListener); TypedArray ta = activity.getTheme().obtainStyledAttributes(new int[] { android.R.attr.windowBackground }); mThemeDrawableResourceId = ta.getResourceId(0, -1); if (mThemeDrawableResourceId < 0) { if (DEBUG) Log.v(TAG, "BackgroundManager no window background resource!"); } ta.recycle(); if (isSupportFragmentActivity) { createSupportFragment((FragmentActivity) activity); } else { createFragment(activity); } }
From source file:base.PagerSlidingTabStrip.java
public PagerSlidingTabStrip(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); setFillViewport(true);/*from w ww . ja v a 2 s. com*/ 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(TEXT_SIZE_INDEX, tabTextSize); ColorStateList colorStateList = a.getColorStateList(TEXT_COLOR_INDEX); int textPrimaryColor = a.getColor(TEXT_COLOR_PRIMARY, android.R.color.white); if (colorStateList != null) { tabTextColor = colorStateList; } else { tabTextColor = getColorStateList(textPrimaryColor); } underlineColor = textPrimaryColor; dividerColor = textPrimaryColor; indicatorColor = textPrimaryColor; paddingLeft = a.getDimensionPixelSize(PADDING_LEFT_INDEX, paddingLeft); paddingRight = a.getDimensionPixelSize(PADDING_RIGHT_INDEX, paddingRight); a.recycle(); //In case we have the padding they must be equal so we take the biggest if (paddingRight < paddingLeft) { paddingRight = paddingLeft; } if (paddingLeft < paddingRight) { paddingLeft = paddingRight; } // 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); dividerWidth = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsDividerWidth, dividerWidth); 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); isPaddingMiddle = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsPaddingMiddle, isPaddingMiddle); tabTypefaceStyle = a.getInt(R.styleable.PagerSlidingTabStrip_pstsTextStyle, Typeface.BOLD); tabTypefaceSelectedStyle = a.getInt(R.styleable.PagerSlidingTabStrip_pstsTextSelectedStyle, Typeface.BOLD); tabTextAlpha = a.getFloat(R.styleable.PagerSlidingTabStrip_pstsTextAlpha, HALF_TRANSP); tabTextSelectedAlpha = a.getFloat(R.styleable.PagerSlidingTabStrip_pstsTextSelectedAlpha, OPAQUE); 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:android.support.transition.TransitionInflater.java
private void loadTransition(AttributeSet attrs, XmlPullParser parser, ViewGroup sceneRoot, TransitionManager transitionManager) throws Resources.NotFoundException { TypedArray a = mContext.obtainStyledAttributes(attrs, Styleable.TRANSITION_MANAGER); int transitionId = TypedArrayUtils.getNamedResourceId(a, parser, "transition", Styleable.TransitionManager.TRANSITION, -1); int fromId = TypedArrayUtils.getNamedResourceId(a, parser, "fromScene", Styleable.TransitionManager.FROM_SCENE, -1); Scene fromScene = (fromId < 0) ? null : Scene.getSceneForLayout(sceneRoot, fromId, mContext); int toId = TypedArrayUtils.getNamedResourceId(a, parser, "toScene", Styleable.TransitionManager.TO_SCENE, -1);/*from w w w . j a v a 2 s. c om*/ Scene toScene = (toId < 0) ? null : Scene.getSceneForLayout(sceneRoot, toId, mContext); if (transitionId >= 0) { Transition transition = inflateTransition(transitionId); if (transition != null) { if (toScene == null) { throw new RuntimeException("No toScene for transition ID " + transitionId); } if (fromScene == null) { transitionManager.setTransition(toScene, transition); } else { transitionManager.setTransition(fromScene, toScene, transition); } } } a.recycle(); }
From source file:android.support.v7.graphics.drawable.DrawerArrowDrawable.java
/** * @param context used to get the configuration for the drawable from *//*from w ww . jav a 2 s . c o m*/ public DrawerArrowDrawable(Context context) { mPaint.setStyle(Paint.Style.STROKE); mPaint.setStrokeJoin(Paint.Join.MITER); mPaint.setStrokeCap(Paint.Cap.BUTT); mPaint.setAntiAlias(true); final TypedArray a = context.getTheme().obtainStyledAttributes(null, R.styleable.DrawerArrowToggle, R.attr.drawerArrowStyle, R.style.Base_Widget_AppCompat_DrawerArrowToggle); setColor(a.getColor(R.styleable.DrawerArrowToggle_color, 0)); setBarThickness(a.getDimension(R.styleable.DrawerArrowToggle_thickness, 0)); setSpinEnabled(a.getBoolean(R.styleable.DrawerArrowToggle_spinBars, true)); // round this because having this floating may cause bad measurements setGapSize(Math.round(a.getDimension(R.styleable.DrawerArrowToggle_gapBetweenBars, 0))); mSize = a.getDimensionPixelSize(R.styleable.DrawerArrowToggle_drawableSize, 0); // round this because having this floating may cause bad measurements mBarLength = Math.round(a.getDimension(R.styleable.DrawerArrowToggle_barLength, 0)); // round this because having this floating may cause bad measurements mArrowHeadLength = Math.round(a.getDimension(R.styleable.DrawerArrowToggle_arrowHeadLength, 0)); mArrowShaftLength = a.getDimension(R.styleable.DrawerArrowToggle_arrowShaftLength, 0); a.recycle(); }
From source file:android.support.v7.preference.DialogPreference.java
public DialogPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.DialogPreference, defStyleAttr, defStyleRes);// w w w. j av a 2s .c o m mDialogTitle = TypedArrayUtils.getString(a, R.styleable.DialogPreference_dialogTitle, R.styleable.DialogPreference_android_dialogTitle); if (mDialogTitle == null) { // Fall back on the regular title of the preference // (the one that is seen in the list) mDialogTitle = getTitle(); } mDialogMessage = TypedArrayUtils.getString(a, R.styleable.DialogPreference_dialogMessage, R.styleable.DialogPreference_android_dialogMessage); mDialogIcon = TypedArrayUtils.getDrawable(a, R.styleable.DialogPreference_dialogIcon, R.styleable.DialogPreference_android_dialogIcon); mPositiveButtonText = TypedArrayUtils.getString(a, R.styleable.DialogPreference_positiveButtonText, R.styleable.DialogPreference_android_positiveButtonText); mNegativeButtonText = TypedArrayUtils.getString(a, R.styleable.DialogPreference_negativeButtonText, R.styleable.DialogPreference_android_negativeButtonText); mDialogLayoutResId = TypedArrayUtils.getResourceId(a, R.styleable.DialogPreference_dialogLayout, R.styleable.DialogPreference_android_dialogLayout, 0); a.recycle(); }
From source file:android.support.designox.widget.FloatingActionButton.java
public FloatingActionButton(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); ThemeUtils.checkAppCompatTheme(context); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.FloatingActionButton, defStyleAttr, R.style.Widget_Design_FloatingActionButton); mBackgroundTint = a.getColorStateList(R.styleable.FloatingActionButton_backgroundTint_ox); mBackgroundTintMode = parseTintMode(a.getInt(R.styleable.FloatingActionButton_backgroundTintMode_ox, -1), null);/*w w w .j a v a 2s . c o m*/ mRippleColor = a.getColor(R.styleable.FloatingActionButton_rippleColor, 0); mSize = a.getInt(R.styleable.FloatingActionButton_fabSize_ox, SIZE_NORMAL); mBorderWidth = a.getDimensionPixelSize(R.styleable.FloatingActionButton_borderWidth, 0); final float elevation = a.getDimension(R.styleable.FloatingActionButton_elevation, 0f); final float pressedTranslationZ = a.getDimension(R.styleable.FloatingActionButton_pressedTranslationZ, 0f); mCompatPadding = a.getBoolean(R.styleable.FloatingActionButton_useCompatPadding, false); a.recycle(); mImageHelper = new AppCompatImageHelper(this, AppCompatDrawableManager.get()); mImageHelper.loadFromAttributes(attrs, defStyleAttr); final int maxImageSize = (int) getResources().getDimension(R.dimen.design_fab_image_size); mImagePadding = (getSizeDimension() - maxImageSize) / 2; getImpl().setBackgroundDrawable(mBackgroundTint, mBackgroundTintMode, mRippleColor, mBorderWidth); getImpl().setElevation(elevation); getImpl().setPressedTranslationZ(pressedTranslationZ); getImpl().updatePadding(); }
From source file:android.support.v7.app.AlertController.java
public AlertController(Context context, AppCompatDialog di, Window window) { mContext = context;/*from w w w. j a v a 2s.co m*/ mDialog = di; mWindow = window; mHandler = new ButtonHandler(di); final TypedArray a = context.obtainStyledAttributes(null, R.styleable.AlertDialog, R.attr.alertDialogStyle, 0); mAlertDialogLayout = a.getResourceId(R.styleable.AlertDialog_android_layout, 0); mButtonPanelSideLayout = a.getResourceId(R.styleable.AlertDialog_buttonPanelSideLayout, 0); mListLayout = a.getResourceId(R.styleable.AlertDialog_listLayout, 0); mMultiChoiceItemLayout = a.getResourceId(R.styleable.AlertDialog_multiChoiceItemLayout, 0); mSingleChoiceItemLayout = a.getResourceId(R.styleable.AlertDialog_singleChoiceItemLayout, 0); mListItemLayout = a.getResourceId(R.styleable.AlertDialog_listItemLayout, 0); a.recycle(); /* We use a custom title so never request a window title */ di.supportRequestWindowFeature(Window.FEATURE_NO_TITLE); }