List of usage examples for android.content.res TypedArray getInt
public int getInt(@StyleableRes int index, int defValue)
From source file:com.gj.administrator.gjerp.view.CircleIndicator.java
private void handleTypedArray(Context context, AttributeSet attrs) { if (attrs == null) return;// ww w . java2 s. com TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.CircleIndicator); mIndicatorRadius = typedArray.getDimensionPixelSize(R.styleable.CircleIndicator_ci_radius, DEFAULT_INDICATOR_RADIUS); mIndicatorMargin = typedArray.getDimensionPixelSize(R.styleable.CircleIndicator_ci_margin, DEFAULT_INDICATOR_MARGIN); mIndicatorBackground = typedArray.getColor(R.styleable.CircleIndicator_ci_background, DEFAULT_INDICATOR_BACKGROUND); mIndicatorSelectedBackground = typedArray.getColor(R.styleable.CircleIndicator_ci_selected_background, DEFAULT_INDICATOR_SELECTED_BACKGROUND); int gravity = typedArray.getInt(R.styleable.CircleIndicator_ci_gravity, DEFAULT_INDICATOR_LAYOUT_GRAVITY); mIndicatorLayoutGravity = Gravity.values()[gravity]; int mode = typedArray.getInt(R.styleable.CircleIndicator_ci_mode, DEFAULT_INDICATOR_MODE); mIndicatorMode = Mode.values()[mode]; typedArray.recycle(); }
From source file:com.layer_net.stepindicator.StepIndicator.java
private void initAttributes(Context context, AttributeSet attributeSet) { TypedArray attr = context.obtainStyledAttributes(attributeSet, R.styleable.StepIndicator, 0, 0); if (attr == null) { return;//from ww w . java 2 s.c om } try { radius = (int) attr.getDimension(R.styleable.StepIndicator_siRadius, dp2px(DEFAULT_STEP_RADIUS)); strokeWidth = (int) attr.getDimension(R.styleable.StepIndicator_siStrokeWidth, dp2px(DEFAULT_STOKE_WIDTH)); lineWidth = (int) attr.getDimension(R.styleable.StepIndicator_siLineWidth, radius * 80 / 100); stepsCount = attr.getInt(R.styleable.StepIndicator_siStepCount, DEFAULT_STEP_COUNT); stepColor = attr.getColor(R.styleable.StepIndicator_siStepColor, ContextCompat.getColor(context, DEFAULT_STEP_COLOR)); currentColor = attr.getColor(R.styleable.StepIndicator_siCurrentStepColor, ContextCompat.getColor(context, DEFAULT_CURRENT_STEP_COLOR)); backgroundColor = attr.getColor(R.styleable.StepIndicator_siBackgroundColor, ContextCompat.getColor(context, DEFAULT_BACKGROUND_COLOR)); textColor = attr.getColor(R.styleable.StepIndicator_siTextColor, ContextCompat.getColor(context, DEFAULT_TEXT_COLOR)); secondaryTextColor = attr.getColor(R.styleable.StepIndicator_siSecondaryTextColor, ContextCompat.getColor(context, DEFAULT_SECONDARY_TEXT_COLOR)); } finally { attr.recycle(); } }
From source file:com.coolerfall.uiart.PagerSlidingTabStrip.java
public PagerSlidingTabStrip(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); setFillViewport(true);/*from w w w.ja v a2s. c o m*/ setWillNotDraw(false); mTabsContainer = new LinearLayout(context); mTabsContainer.setOrientation(LinearLayout.HORIZONTAL); mTabsContainer.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); addView(mTabsContainer); /* default attrs */ DisplayMetrics dm = getResources().getDisplayMetrics(); mIndicatorHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mIndicatorHeight, dm); mUnderlineHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mUnderlineHeight, dm); mTabTextSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, mTabTextSize, dm); mNumTextSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, mNumTextSize, dm); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PagerSlidingTabStrip); /* get system attrs */ mTabTextSize = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_android_textSize, mTabTextSize); mTabTextColor = a.getColor(R.styleable.PagerSlidingTabStrip_android_textColor, mTabTextColor); mTabTypefaceStyle = a.getInt(R.styleable.PagerSlidingTabStrip_android_textStyle, mTabTypefaceStyle); /* get custom attrs */ mIndicatorColor = a.getColor(R.styleable.PagerSlidingTabStrip_indicatorColor, mIndicatorColor); mUnderlineColor = a.getColor(R.styleable.PagerSlidingTabStrip_underLineColor, mUnderlineColor); mIndicatorHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_indicatorHeight, mIndicatorHeight); mUnderlineHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_underLineHeight, mUnderlineHeight); mTabPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_tabsPadding, mTabPadding); mFixed = a.getBoolean(R.styleable.PagerSlidingTabStrip_fixed, mFixed); /* if use expand layout, the tab padding should be 0 */ if (mFixed) { mTabPadding = 0; } a.recycle(); /* create a new paint to draw ui */ mRectPaint = new Paint(); mRectPaint.setAntiAlias(true); mRectPaint.setStyle(Style.FILL); mDefaultTabLayoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); mFixedTabLayoutParams = new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 1.0f); mNumLayoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); mNumLayoutParams.setMargins(mNumPadding, 0, 0, 0); }
From source file:android.support.v7ox.widget.AppCompatSpinner.java
/** * Constructs a new spinner with the given context's theme, the supplied * attribute set, default styles, popup mode (one of {@link #MODE_DIALOG} * or {@link #MODE_DROPDOWN}), and the context against which the popup * should be inflated.// ww w.j a v a 2 s.c o m * * @param context The context against which the view is inflated, which * provides access to the current theme, resources, etc. * @param attrs The attributes of the XML tag that is inflating the view. * @param defStyleAttr An attribute in the current theme that contains a * reference to a style resource that supplies default * values for the view. Can be 0 to not look for * defaults. * @param mode Constant describing how the user will select choices from * the spinner. * @param popupTheme The theme against which the dialog or dropdown popup * should be inflated. May be {@code null} to use the * view theme. If set, this will override any value * specified by * {@link R.styleable#Spinner_popupTheme}. * @see #MODE_DIALOG * @see #MODE_DROPDOWN */ public AppCompatSpinner(Context context, AttributeSet attrs, int defStyleAttr, int mode, Resources.Theme popupTheme) { super(context, attrs, defStyleAttr); TintTypedArray a = TintTypedArray.obtainStyledAttributes(context, attrs, R.styleable.Spinner, defStyleAttr, 0); mDrawableManager = AppCompatDrawableManager.get(); mBackgroundTintHelper = new AppCompatBackgroundHelper(this, mDrawableManager); if (popupTheme != null) { mPopupContext = new ContextThemeWrapper(context, popupTheme); } else { final int popupThemeResId = a.getResourceId(R.styleable.Spinner_popupTheme, 0); if (popupThemeResId != 0) { mPopupContext = new ContextThemeWrapper(context, popupThemeResId); } else { // If we're running on a < M device, we'll use the current context and still handle // any dropdown popup mPopupContext = !IS_AT_LEAST_M ? context : null; } } if (mPopupContext != null) { if (mode == MODE_THEME) { if (Build.VERSION.SDK_INT >= 11) { // If we're running on API v11+ we will try and read android:spinnerMode TypedArray aa = null; try { aa = context.obtainStyledAttributes(attrs, ATTRS_ANDROID_SPINNERMODE, defStyleAttr, 0); if (aa.hasValue(0)) { mode = aa.getInt(0, MODE_DIALOG); } } catch (Exception e) { Log.i(TAG, "Could not read android:spinnerMode", e); } finally { if (aa != null) { aa.recycle(); } } } else { // Else, we use a default mode of dropdown mode = MODE_DROPDOWN; } } if (mode == MODE_DROPDOWN) { final DropdownPopup popup = new DropdownPopup(mPopupContext, attrs, defStyleAttr); final TintTypedArray pa = TintTypedArray.obtainStyledAttributes(mPopupContext, attrs, R.styleable.Spinner, defStyleAttr, 0); mDropDownWidth = pa.getLayoutDimension(R.styleable.Spinner_android_dropDownWidth, LayoutParams.WRAP_CONTENT); popup.setPromptText(a.getString(R.styleable.Spinner_android_prompt)); pa.recycle(); mPopup = popup; mForwardingListener = new ListPopupWindow.ForwardingListener(this) { @Override public ListPopupWindow getPopup() { return popup; } @Override public boolean onForwardingStarted() { if (!mPopup.isShowing()) { mPopup.show(); } return true; } }; } } final CharSequence[] entries = a.getTextArray(R.styleable.Spinner_android_entries); if (entries != null) { final ArrayAdapter<CharSequence> adapter = new ArrayAdapter<>(context, R.layout.support_simple_spinner_dropdown_item, entries); adapter.setDropDownViewResource(R.layout.support_simple_spinner_dropdown_item); setAdapter(adapter); } a.recycle(); mPopupSet = true; // Base constructors can call setAdapter before we initialize mPopup. // Finish setting things up if this happened. if (mTempAdapter != null) { setAdapter(mTempAdapter); mTempAdapter = null; } mBackgroundTintHelper.loadFromAttributes(attrs, defStyleAttr); }
From source file:com.edgar.banner.BannerPagerView.java
private void init(AttributeSet attrs, int defStyle) { Context context = getContext(); Resources resource = context.getResources(); LayoutInflater.from(getContext()).inflate(R.layout.banner_layout, this, true); mViewPage = (LoopViewPager) findViewById(R.id.carouse_viewpager); setBannerScroller(new BannerScroller(getContext())); mViewPage.setOverScrollMode(View.OVER_SCROLL_NEVER); mViewPage.setOnPageChangeListener(mCarousePageListener); mBannerPageAdapter = new DefaultBannerPageViewAdapter(); mIndicatorParams.gravity = Gravity.BOTTOM; mPointPadding = resource.getDimensionPixelOffset(R.dimen.point_margin); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.BannerPagerView, defStyle, 0); int N = a.getIndexCount(); for (int i = 0; i < N; i++) { int attr = a.getIndex(i); if (attr == R.styleable.BannerPagerView_bannerAnimation) { int transformerType = a.getInt(attr, 0); setBannerPageTransformer(true, TransformerType.convert(transformerType)); } else if (attr == R.styleable.BannerPagerView_enableAutoPlayer) { setEnableAutoPlay(a.getBoolean(attr, false)); } else if (attr == R.styleable.BannerPagerView_indicatorStyle) { mIndicatorStyle = a.getInt(attr, IndicatorStyle.CIRCLE_INDICATOR); } else if (attr == R.styleable.BannerPagerView_indicatorLayout) { int resId = a.getResourceId(attr, 0); if (resId != 0) { View indicatorView = LayoutInflater.from(context).inflate(resId, this, false); if (!(indicatorView instanceof BannerIndicator)) { throw new IllegalArgumentException("Your indicator must implements BannerIndicator."); }// w ww .jav a 2 s.c om mIndicatorView = indicatorView; mBannerIndicator = (BannerIndicator) indicatorView; addView(mIndicatorView); } } else if (attr == R.styleable.BannerPagerView_unSelectDrawable) { mUnSelectedDrawable = a.getDrawable(attr); } else if (attr == R.styleable.BannerPagerView_selectedDrawable) { mSelectedDrawable = a.getDrawable(attr); } else if (attr == R.styleable.BannerPagerView_indicatorGravity) { mIndicatorGravity = a.getInt(attr, Gravity.CENTER); } else if (attr == R.styleable.BannerPagerView_pointPadding) { mPointPadding = a.getDimensionPixelOffset(attr, mPointPadding); } else if (attr == R.styleable.BannerPagerView_indicatorBackground) { mIndicatorBackground = a.getDrawable(attr); } } if (mUnSelectedDrawable == null) { mUnSelectedDrawable = ContextCompat.getDrawable(context, R.drawable.def_circle_normal_background); } if (mSelectedDrawable == null) { mSelectedDrawable = ContextCompat.getDrawable(context, R.drawable.def_circle_selected_background); } if (mIndicatorBackground == null) { mIndicatorBackground = new ColorDrawable(resource.getColor(R.color.indicator_background)); } if (mBannerIndicator == null) { setIndicatorStyle(mIndicatorStyle); } a.recycle(); }
From source file:android.support.v7.widget.AppCompatSpinner.java
/** * Constructs a new spinner with the given context's theme, the supplied * attribute set, default styles, popup mode (one of {@link #MODE_DIALOG} * or {@link #MODE_DROPDOWN}), and the context against which the popup * should be inflated./*www. ja v a 2 s . co m*/ * * @param context The context against which the view is inflated, which * provides access to the current theme, resources, etc. * @param attrs The attributes of the XML tag that is inflating the view. * @param defStyleAttr An attribute in the current theme that contains a * reference to a style resource that supplies default * values for the view. Can be 0 to not look for * defaults. * @param mode Constant describing how the user will select choices from * the spinner. * @param popupTheme The theme against which the dialog or dropdown popup * should be inflated. May be {@code null} to use the * view theme. If set, this will override any value * specified by * {@link R.styleable#Spinner_popupTheme}. * @see #MODE_DIALOG * @see #MODE_DROPDOWN */ public AppCompatSpinner(Context context, AttributeSet attrs, int defStyleAttr, int mode, Resources.Theme popupTheme) { super(context, attrs, defStyleAttr); TintTypedArray a = TintTypedArray.obtainStyledAttributes(context, attrs, R.styleable.Spinner, defStyleAttr, 0); mDrawableManager = AppCompatDrawableManager.get(); mBackgroundTintHelper = new AppCompatBackgroundHelper(this, mDrawableManager); if (popupTheme != null) { mPopupContext = new ContextThemeWrapper(context, popupTheme); } else { final int popupThemeResId = a.getResourceId(R.styleable.Spinner_popupTheme, 0); if (popupThemeResId != 0) { mPopupContext = new ContextThemeWrapper(context, popupThemeResId); } else { // If we're running on a < M device, we'll use the current context and still handle // any dropdown popup mPopupContext = !IS_AT_LEAST_M ? context : null; } } if (mPopupContext != null) { if (mode == MODE_THEME) { if (Build.VERSION.SDK_INT >= 11) { // If we're running on API v11+ we will try and read android:spinnerMode TypedArray aa = null; try { aa = context.obtainStyledAttributes(attrs, ATTRS_ANDROID_SPINNERMODE, defStyleAttr, 0); if (aa.hasValue(0)) { mode = aa.getInt(0, MODE_DIALOG); } } catch (Exception e) { Log.i(TAG, "Could not read android:spinnerMode", e); } finally { if (aa != null) { aa.recycle(); } } } else { // Else, we use a default mode of dropdown mode = MODE_DROPDOWN; } } if (mode == MODE_DROPDOWN) { final DropdownPopup popup = new DropdownPopup(mPopupContext, attrs, defStyleAttr); final TintTypedArray pa = TintTypedArray.obtainStyledAttributes(mPopupContext, attrs, R.styleable.Spinner, defStyleAttr, 0); mDropDownWidth = pa.getLayoutDimension(R.styleable.Spinner_android_dropDownWidth, LayoutParams.WRAP_CONTENT); popup.setBackgroundDrawable(pa.getDrawable(R.styleable.Spinner_android_popupBackground)); popup.setPromptText(a.getString(R.styleable.Spinner_android_prompt)); pa.recycle(); mPopup = popup; mForwardingListener = new ForwardingListener(this) { @Override public ShowableListMenu getPopup() { return popup; } @Override public boolean onForwardingStarted() { if (!mPopup.isShowing()) { mPopup.show(); } return true; } }; } } final CharSequence[] entries = a.getTextArray(R.styleable.Spinner_android_entries); if (entries != null) { final ArrayAdapter<CharSequence> adapter = new ArrayAdapter<>(context, android.R.layout.simple_spinner_item, entries); adapter.setDropDownViewResource(R.layout.support_simple_spinner_dropdown_item); setAdapter(adapter); } a.recycle(); mPopupSet = true; // Base constructors can call setAdapter before we initialize mPopup. // Finish setting things up if this happened. if (mTempAdapter != null) { setAdapter(mTempAdapter); mTempAdapter = null; } mBackgroundTintHelper.loadFromAttributes(attrs, defStyleAttr); }
From source file:android.support.v7ox.widget.AppCompatBackgroundHelper.java
void loadFromAttributes(AttributeSet attrs, int defStyleAttr) { TypedArray a = mView.getContext().obtainStyledAttributes(attrs, R.styleable.ViewBackgroundHelper, defStyleAttr, 0);//from w w w . jav a 2 s. co m try { if (a.hasValue(R.styleable.ViewBackgroundHelper_android_background)) { ColorStateList tint = mDrawableManager.getTintList(mView.getContext(), a.getResourceId(R.styleable.ViewBackgroundHelper_android_background, -1)); if (tint != null) { setInternalBackgroundTint(tint); } } if (a.hasValue(R.styleable.ViewBackgroundHelper_backgroundTint_ox)) { ViewCompat.setBackgroundTintList(mView, a.getColorStateList(R.styleable.ViewBackgroundHelper_backgroundTint_ox)); } if (a.hasValue(R.styleable.ViewBackgroundHelper_backgroundTintMode_ox)) { ViewCompat.setBackgroundTintMode(mView, DrawableUtils .parseTintMode(a.getInt(R.styleable.ViewBackgroundHelper_backgroundTintMode_ox, -1), null)); } } finally { 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"); }// w w w .ja va 2 s. c o m 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:com.ionesmile.variousdemo.view.SlidingLayer.java
/** * Constructor for the sliding layer.<br> * By default this panel will/* w w w .j a v a 2 s .com*/ * <ol> * <li>{@link #setStickTo(int)} with param {@link #STICK_TO_AUTO}</li> * <li>Use no shadow drawable. (i.e. with width of 0)</li> * <li>Close when the panel is tapped</li> * <li>Open when the offset is tapped, but will have an offset of 0</li> * </ol> * @param context a reference to an existing context * @param attrs attribute set constructed from attributes set in android .xml file * @param defStyle style res id */ public SlidingLayer(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); // Style final TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.SlidingLayer); // Set the side of the screen setStickTo(ta.getInt(R.styleable.SlidingLayer_stickTo, STICK_TO_AUTO)); // Sets the ability to close the layer by tapping in any empty space closeOnTapEnabled = ta.getBoolean(R.styleable.SlidingLayer_closeOnTapEnabled, true); // Sets the ability to open the layout by tapping on any of the exposed closed layer openOnTapEnabled = ta.getBoolean(R.styleable.SlidingLayer_openOnTapEnabled, true); // How much of the view sticks out when closed setOffsetWidth(ta.getDimensionPixelOffset(R.styleable.SlidingLayer_offsetWidth, 0)); ta.recycle(); init(); }
From source file:android.support.design.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); mBackgroundTintMode = ViewUtils//from w w w . j av a 2 s . c om .parseTintMode(a.getInt(R.styleable.FloatingActionButton_backgroundTintMode, -1), null); mRippleColor = a.getColor(R.styleable.FloatingActionButton_rippleColor, 0); mSize = a.getInt(R.styleable.FloatingActionButton_fabSize, SIZE_AUTO); 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); mImageHelper.loadFromAttributes(attrs, defStyleAttr); mMaxImageSize = (int) getResources().getDimension(R.dimen.design_fab_image_size); getImpl().setBackgroundDrawable(mBackgroundTint, mBackgroundTintMode, mRippleColor, mBorderWidth); getImpl().setElevation(elevation); getImpl().setPressedTranslationZ(pressedTranslationZ); }