List of usage examples for android.content.res TypedArray recycle
public void recycle()
From source file:aksha.upcomingdemo.HorizontalListView.java
/** * Parse the XML configuration for this widget * * @param context Context used for extracting attributes * @param attrs The Attribute Set containing the ColumnView attributes *///from ww w .j a v a 2s . c om private void retrieveXmlConfiguration(Context context, AttributeSet attrs) { if (attrs != null) { TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.HorizontalListView); // Get the provided drawable from the XML final Drawable d = a.getDrawable(R.styleable.HorizontalListView_android_divider); if (d != null) { // If a drawable is provided to use as the divider then use its intrinsic width for the divider width setDivider(d); } // If a width is explicitly specified then use that width final int dividerWidth = a.getDimensionPixelSize(R.styleable.HorizontalListView_dividerWidth, 0); if (dividerWidth != 0) { setDividerWidth(dividerWidth); } a.recycle(); } }
From source file:com.abslyon.abetterselection.CoverFlow.CoverFlowView.java
private void initAttributes(Context context, AttributeSet attrs) { TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ImageCoverFlowView); int totalVisibleChildren = a.getInt(R.styleable.ImageCoverFlowView_visibleImage, 2); if (totalVisibleChildren % 2 == 0) { throw new IllegalArgumentException("visible image must be an odd number"); }/*from w ww. ja v a2 s. c om*/ VISIBLE_VIEWS = totalVisibleChildren >> 1; reflectHeightFraction = a.getFraction(R.styleable.ImageCoverFlowView_reflectionHeight, 100, 0, 0.0f); if (reflectHeightFraction > 100) { reflectHeightFraction = 100; } reflectHeightFraction /= 100; reflectGap = a.getDimensionPixelSize(R.styleable.ImageCoverFlowView_reflectionGap, 0); mGravity = CoverFlowGravity.values()[a.getInt(R.styleable.ImageCoverFlowView_coverflowGravity, CoverFlowGravity.CENTER_VERTICAL.ordinal())]; mLayoutMode = CoverFlowLayoutMode.values()[a.getInt(R.styleable.ImageCoverFlowView_coverflowLayoutMode, CoverFlowLayoutMode.WRAP_CONTENT.ordinal())]; a.recycle(); }
From source file:android.support.wear.widget.drawer.PageIndicatorView.java
public PageIndicatorView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); final TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.PageIndicatorView, defStyleAttr, R.style.WsPageIndicatorViewStyle); mDotSpacing = a.getDimensionPixelOffset(R.styleable.PageIndicatorView_wsPageIndicatorDotSpacing, 0); mDotRadius = a.getDimension(R.styleable.PageIndicatorView_wsPageIndicatorDotRadius, 0); mDotRadiusSelected = a.getDimension(R.styleable.PageIndicatorView_wsPageIndicatorDotRadiusSelected, 0); mDotColor = a.getColor(R.styleable.PageIndicatorView_wsPageIndicatorDotColor, 0); mDotColorSelected = a.getColor(R.styleable.PageIndicatorView_wsPageIndicatorDotColorSelected, 0); mDotFadeOutDelay = a.getInt(R.styleable.PageIndicatorView_wsPageIndicatorDotFadeOutDelay, 0); mDotFadeOutDuration = a.getInt(R.styleable.PageIndicatorView_wsPageIndicatorDotFadeOutDuration, 0); mDotFadeInDuration = a.getInt(R.styleable.PageIndicatorView_wsPageIndicatorDotFadeInDuration, 0); mDotFadeWhenIdle = a.getBoolean(R.styleable.PageIndicatorView_wsPageIndicatorDotFadeWhenIdle, false); mDotShadowDx = a.getDimension(R.styleable.PageIndicatorView_wsPageIndicatorDotShadowDx, 0); mDotShadowDy = a.getDimension(R.styleable.PageIndicatorView_wsPageIndicatorDotShadowDy, 0); mDotShadowRadius = a.getDimension(R.styleable.PageIndicatorView_wsPageIndicatorDotShadowRadius, 0); mDotShadowColor = a.getColor(R.styleable.PageIndicatorView_wsPageIndicatorDotShadowColor, 0); a.recycle(); mDotPaint = new Paint(Paint.ANTI_ALIAS_FLAG); mDotPaint.setColor(mDotColor);/*from w ww. j a va2s. c om*/ mDotPaint.setStyle(Style.FILL); mDotPaintSelected = new Paint(Paint.ANTI_ALIAS_FLAG); mDotPaintSelected.setColor(mDotColorSelected); mDotPaintSelected.setStyle(Style.FILL); mDotPaintShadow = new Paint(Paint.ANTI_ALIAS_FLAG); mDotPaintShadowSelected = new Paint(Paint.ANTI_ALIAS_FLAG); mCurrentViewPagerState = ViewPager.SCROLL_STATE_IDLE; if (isInEditMode()) { // When displayed in layout preview: // Simulate 5 positions, currently on the 3rd position. mNumberOfPositions = 5; mSelectedPosition = 2; mDotFadeWhenIdle = false; } if (mDotFadeWhenIdle) { mVisible = false; animate().alpha(0f).setStartDelay(2000).setDuration(mDotFadeOutDuration).start(); } else { animate().cancel(); setAlpha(1.0f); } updateShadows(); }
From source file:cn.fantasee.swipwmenulistview.swipelistview.SwipeListView.java
/** * Init ListView//from ww w. ja va 2 s. c o m * * @param attrs AttributeSet */ private void init(AttributeSet attrs) { int swipeMode = SWIPE_MODE_BOTH; boolean swipeOpenOnLongPress = true; boolean swipeCloseAllItemsWhenMoveList = true; long swipeAnimationTime = 0; float swipeOffsetLeft = 0; float swipeOffsetRight = 0; int swipeDrawableChecked = 0; int swipeDrawableUnchecked = 0; int swipeActionLeft = SWIPE_ACTION_REVEAL; int swipeActionRight = SWIPE_ACTION_REVEAL; if (attrs != null) { TypedArray styled = getContext().obtainStyledAttributes(attrs, R.styleable.SwipeListView); swipeMode = styled.getInt(R.styleable.SwipeListView_swipeMode, SWIPE_MODE_BOTH); swipeActionLeft = styled.getInt(R.styleable.SwipeListView_swipeActionLeft, SWIPE_ACTION_REVEAL); swipeActionRight = styled.getInt(R.styleable.SwipeListView_swipeActionRight, SWIPE_ACTION_REVEAL); swipeOffsetLeft = styled.getDimension(R.styleable.SwipeListView_swipeOffsetLeft, 0); swipeOffsetRight = styled.getDimension(R.styleable.SwipeListView_swipeOffsetRight, 0); swipeOpenOnLongPress = styled.getBoolean(R.styleable.SwipeListView_swipeOpenOnLongPress, true); swipeAnimationTime = styled.getInteger(R.styleable.SwipeListView_swipeAnimationTime, 0); swipeCloseAllItemsWhenMoveList = styled .getBoolean(R.styleable.SwipeListView_swipeCloseAllItemsWhenMoveList, true); swipeDrawableChecked = styled.getResourceId(R.styleable.SwipeListView_swipeDrawableChecked, 0); swipeDrawableUnchecked = styled.getResourceId(R.styleable.SwipeListView_swipeDrawableUnchecked, 0); swipeFrontView = styled.getResourceId(R.styleable.SwipeListView_swipeFrontView, 0); swipeBackView = styled.getResourceId(R.styleable.SwipeListView_swipeBackView, 0); styled.recycle(); } if (swipeFrontView == 0 || swipeBackView == 0) { swipeFrontView = getContext().getResources().getIdentifier(SWIPE_DEFAULT_FRONT_VIEW, "id", getContext().getPackageName()); swipeBackView = getContext().getResources().getIdentifier(SWIPE_DEFAULT_BACK_VIEW, "id", getContext().getPackageName()); if (swipeFrontView == 0 || swipeBackView == 0) { throw new RuntimeException(String.format( "You forgot the attributes swipeFrontView or swipeBackView. You can add this attributes or use '%s' and '%s' identifiers", SWIPE_DEFAULT_FRONT_VIEW, SWIPE_DEFAULT_BACK_VIEW)); } } final ViewConfiguration configuration = ViewConfiguration.get(getContext()); touchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration); touchListener = new SwipeListViewTouchListener(this, swipeFrontView, swipeBackView); if (swipeAnimationTime > 0) { touchListener.setAnimationTime(swipeAnimationTime); } touchListener.setRightOffset(swipeOffsetRight); touchListener.setLeftOffset(swipeOffsetLeft); touchListener.setSwipeActionLeft(swipeActionLeft); touchListener.setSwipeActionRight(swipeActionRight); touchListener.setSwipeMode(swipeMode); touchListener.setSwipeClosesAllItemsWhenListMoves(swipeCloseAllItemsWhenMoveList); touchListener.setSwipeOpenOnLongPress(swipeOpenOnLongPress); touchListener.setSwipeDrawableChecked(swipeDrawableChecked); touchListener.setSwipeDrawableUnchecked(swipeDrawableUnchecked); setOnTouchListener(touchListener); setOnScrollListener(touchListener.makeScrollListener()); }
From source file:android.support.design.widget.AppBarLayout.java
public AppBarLayout(Context context, AttributeSet attrs) { super(context, attrs); setOrientation(VERTICAL);//www .ja va 2 s. c om ThemeUtils.checkAppCompatTheme(context); if (Build.VERSION.SDK_INT >= 21) { // Use the bounds view outline provider so that we cast a shadow, even without a // background ViewUtilsLollipop.setBoundsViewOutlineProvider(this); // If we're running on API 21+, we should reset any state list animator from our // default style ViewUtilsLollipop.setStateListAnimatorFromAttrs(this, attrs, 0, R.style.Widget_Design_AppBarLayout); } final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.AppBarLayout, 0, R.style.Widget_Design_AppBarLayout); ViewCompat.setBackground(this, a.getDrawable(R.styleable.AppBarLayout_android_background)); if (a.hasValue(R.styleable.AppBarLayout_expanded)) { setExpanded(a.getBoolean(R.styleable.AppBarLayout_expanded, false), false, false); } if (Build.VERSION.SDK_INT >= 21 && a.hasValue(R.styleable.AppBarLayout_elevation)) { ViewUtilsLollipop.setDefaultAppBarLayoutStateListAnimator(this, a.getDimensionPixelSize(R.styleable.AppBarLayout_elevation, 0)); } a.recycle(); ViewCompat.setOnApplyWindowInsetsListener(this, new android.support.v4.view.OnApplyWindowInsetsListener() { @Override public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) { return onWindowInsetChanged(insets); } }); }
From source file:com.acbelter.scheduleview.ScheduleView.java
public ScheduleView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs); mClipRect = new Rect(); mClickedViewBounds = new Rect(); mSelectedIds = new HashSet<Long>(); mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); mTopEdgeEffect = new EdgeEffectCompat(context); mBottomEdgeEffect = new EdgeEffectCompat(context); mDataSetObserver = new DataSetObserver() { @Override// ww w. j a va 2 s . co m public void onChanged() { super.onChanged(); removeAllViewsInLayout(); requestLayout(); } @Override public void onInvalidated() { super.onInvalidated(); removeAllViewsInLayout(); requestLayout(); } }; init(context); setVerticalScrollBarEnabled(true); setHorizontalScrollBarEnabled(false); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ScheduleView, defStyle, 0); try { if (a != null) { DisplayMetrics dm = context.getResources().getDisplayMetrics(); mInternalPaddingTop = (int) a.getDimension(R.styleable.ScheduleView_internalPaddingTop, TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, dm)); mInternalPaddingBottom = (int) a.getDimension(R.styleable.ScheduleView_internalPaddingBottom, TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, dm)); mTimeMarksDistance = (int) a.getDimension(R.styleable.ScheduleView_timeMarksDistance, TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 40, dm)); mItemPaddingLeft = (int) a.getDimension(R.styleable.ScheduleView_itemPaddingLeft, TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, dm)); mItemPaddingRight = (int) a.getDimension(R.styleable.ScheduleView_itemPaddingRight, TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, dm)); initializeScrollbars(a); } } finally { if (a != null) { a.recycle(); } } // Draw the background even if no items to display setWillNotDraw(false); mActionModeCallback = new ActionMode.Callback() { @Override public boolean onCreateActionMode(ActionMode mode, Menu menu) { mode.getMenuInflater().inflate(R.menu.menu_context, menu); mIsActionMode = true; return true; } @Override public boolean onPrepareActionMode(ActionMode mode, Menu menu) { return false; } @Override public boolean onActionItemClicked(ActionMode mode, MenuItem item) { if (item.getItemId() == R.id.delete_items) { deleteSelectedItems(); } return false; } @Override public void onDestroyActionMode(ActionMode mode) { clearSelection(); mIsActionMode = false; mActionMode = null; invalidate(); } }; }
From source file:com.adithyaupadhya.uimodule.roundcornerprogressbar.BaseRoundCornerProgressBar.java
private void setupStyleable(Context context, AttributeSet attrs) { TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.RoundCornerProgress); radius = (int) typedArray.getDimension(R.styleable.RoundCornerProgress_rcRadius, dp2px(DEFAULT_PROGRESS_RADIUS)); padding = (int) typedArray.getDimension(R.styleable.RoundCornerProgress_rcBackgroundPadding, dp2px(DEFAULT_BACKGROUND_PADDING)); isReverse = typedArray.getBoolean(R.styleable.RoundCornerProgress_rcReverse, false); max = typedArray.getFloat(R.styleable.RoundCornerProgress_rcMax, DEFAULT_MAX_PROGRESS); progress = typedArray.getFloat(R.styleable.RoundCornerProgress_rcProgress, DEFAULT_PROGRESS); secondaryProgress = typedArray.getFloat(R.styleable.RoundCornerProgress_rcSecondaryProgress, DEFAULT_SECONDARY_PROGRESS); int colorBackgroundDefault = ContextCompat.getColor(context, R.color.round_corner_progress_bar_background_default); colorBackground = typedArray.getColor(R.styleable.RoundCornerProgress_rcBackgroundColor, colorBackgroundDefault);//from w w w .j a v a 2 s. c o m int colorProgressDefault = ContextCompat.getColor(context, R.color.round_corner_progress_bar_progress_default); colorProgress = typedArray.getColor(R.styleable.RoundCornerProgress_rcProgressColor, colorProgressDefault); int colorSecondaryProgressDefault = ContextCompat.getColor(context, R.color.round_corner_progress_bar_secondary_progress_default); colorSecondaryProgress = typedArray.getColor(R.styleable.RoundCornerProgress_rcSecondaryProgressColor, colorSecondaryProgressDefault); typedArray.recycle(); initStyleable(context, attrs); }
From source file:com.achenging.view.SlidingTabLayout.java
public SlidingTabLayout(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); mTabStrip = new SlidingTabStrip(context); int defaultBackgroundColor = mTabStrip.getSolidColor(); // Disable the Scroll Bar setHorizontalScrollBarEnabled(true); // Make sure that the Tab Strips fills this View setFillViewport(true);/* w ww . j a va 2 s . co m*/ //? TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.SlidingTabLayout); // mTabSelectedTextColor = typedArray.getColor(R.styleable.SlidingTabLayout_tabSelectedTextColor, 0); mTabTextColor = typedArray.getColor(R.styleable.SlidingTabLayout_tabTextColor, 0); // int selectedIndicatorThickness = (int) typedArray.getDimension( R.styleable.SlidingTabLayout_tabIndicatorThickness, SELECTED_INDICATOR_THICKNESS_DIPS); // int tabIndicatorColor = typedArray.getColor(R.styleable.SlidingTabLayout_tabIndicatorColor, DEFAULT_SELECTED_INDICATOR_COLOR); //tab int tabDividerThickness = (int) typedArray.getDimension(R.styleable.SlidingTabLayout_dividerThickness, DEFAULT_DIVIDER_THICKNESS_DIPS); //tab int tabDividerColor = typedArray.getColor(R.styleable.SlidingTabLayout_dividerColor, defaultBackgroundColor); //tab?? int tabBottomBorderThickness = (int) typedArray.getDimension( R.styleable.SlidingTabLayout_bottomBorderThickness, DEFAULT_BOTTOM_BORDER_THICKNESS_DIPS); int tabBottomBorderColor = typedArray.getColor(R.styleable.SlidingTabLayout_bottomBorderColor, defaultBackgroundColor); //?tab? boolean showAsDivider = typedArray.getBoolean(R.styleable.SlidingTabLayout_showAsDivider, false); typedArray.recycle(); // // mTitleOffset = (int) (TITLE_OFFSET_DIPS * getResources().getDisplayMetrics().density); mTextPadding = (int) (DEFAULT_TEXT_PADDING * getResources().getDisplayMetrics().density); // setSelectedTitleColors(mTabSelectedTextColor); setUnSelectedTitleColors(mTabTextColor); setDividerColors(tabDividerColor); setSelectedIndicatorColors(tabIndicatorColor); setTabBottomBorderColor(tabBottomBorderColor); setTabDividerColor(tabDividerColor); // setSelectedIndicatorThickness(selectedIndicatorThickness); setTabBottomBorderThickness(tabBottomBorderThickness); setTabDividerThickness(tabDividerThickness); setShowAsDivider(showAsDivider); setShowTabDivider(false); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); params.gravity = Gravity.CENTER; addView(mTabStrip); }
From source file:com.acious.android.paginationseekbar.internal.Marker.java
public Marker(Context context, AttributeSet attrs, int defStyleAttr, String maxValue) { super(context, attrs, defStyleAttr); DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics(); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PaginationSeekBar, R.attr.paginationSeekBarStyle, R.style.DefaultSeekBar); int padding = (int) (PADDING_DP * displayMetrics.density) * 2; int textAppearanceId = a.getResourceId(R.styleable.PaginationSeekBar_psb_indicatorTextAppearance, R.style.DefaultIndicatorTextAppearance); mNumber = new TextView(context); //Add some padding to this textView so the bubble has some space to breath mNumber.setPadding(padding, 0, padding, 0); mNumber.setTextAppearance(context, textAppearanceId); mNumber.setGravity(Gravity.CENTER);/* w ww. j a v a 2 s . c om*/ mNumber.setText(maxValue); mNumber.setMaxLines(1); mNumber.setSingleLine(true); SeekBarCompat.setTextDirection(mNumber, TEXT_DIRECTION_LOCALE); mNumber.setVisibility(View.INVISIBLE); //add some padding for the elevation shadow not to be clipped //I'm sure there are better ways of doing this... setPadding(padding, padding, padding, padding); resetSizes(maxValue); mSeparation = (int) (SEPARATION_DP * displayMetrics.density); int thumbSize = (int) (ThumbDrawable.DEFAULT_SIZE_DP * displayMetrics.density); ColorStateList color = a.getColorStateList(R.styleable.PaginationSeekBar_psb_indicatorColor); mMarkerDrawable = new MarkerDrawable(color, thumbSize); mMarkerDrawable.setCallback(this); mMarkerDrawable.setMarkerListener(this); mMarkerDrawable.setExternalOffset(padding); //Elevation for anroid 5+ float elevation = a.getDimension(R.styleable.PaginationSeekBar_psb_indicatorElevation, ELEVATION_DP * displayMetrics.density); ViewCompat.setElevation(this, elevation); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { SeekBarCompat.setOutlineProvider(this, mMarkerDrawable); } a.recycle(); }
From source file:android.support.v17.leanback.app.BrowseFragment.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); TypedArray ta = getActivity().obtainStyledAttributes(R.styleable.LeanbackTheme); mContainerListMarginStart = (int) ta.getDimension(R.styleable.LeanbackTheme_browseRowsMarginStart, getActivity().getResources().getDimensionPixelSize(R.dimen.lb_browse_rows_margin_start)); mContainerListAlignTop = (int) ta.getDimension(R.styleable.LeanbackTheme_browseRowsMarginTop, getActivity().getResources().getDimensionPixelSize(R.dimen.lb_browse_rows_margin_top)); ta.recycle(); readArguments(getArguments());// w w w . ja va 2 s. com if (mCanShowHeaders) { if (mHeadersBackStackEnabled) { mWithHeadersBackStackName = LB_HEADERS_BACKSTACK + this; mBackStackChangedListener = new BackStackListener(); getFragmentManager().addOnBackStackChangedListener(mBackStackChangedListener); mBackStackChangedListener.load(savedInstanceState); } else { if (savedInstanceState != null) { mShowingHeaders = savedInstanceState.getBoolean(HEADER_SHOW); } } } mScaleFactor = getResources().getFraction(R.fraction.lb_browse_rows_scale, 1, 1); }