List of usage examples for android.content.res TypedArray getInt
public int getInt(@StyleableRes int index, int defValue)
From source file:com.justwayward.reader.view.RVPIndicator.java
public RVPIndicator(Context context, AttributeSet attrs) { super(context, attrs); // /*from w ww . j a v a2s . co m*/ TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.RVPIndicator); mTabVisibleCount = a.getInt(R.styleable.RVPIndicator_item_count, D_TAB_COUNT); mTextColorNormal = a.getColor(R.styleable.RVPIndicator_text_color_normal, D_TEXT_COLOR_NORMAL); mTextColorHighlight = a.getColor(R.styleable.RVPIndicator_text_color_hightlight, D_TEXT_COLOR_HIGHLIGHT); mTextSize = a.getDimensionPixelSize(R.styleable.RVPIndicator_text_size, 16); mIndicatorColor = a.getColor(R.styleable.RVPIndicator_indicator_color, D_INDICATOR_COLOR); mIndicatorStyle = a.getInt(R.styleable.RVPIndicator_indicator_style, STYLE_LINE); Drawable drawable = a.getDrawable(R.styleable.RVPIndicator_indicator_src); if (drawable != null) { if (drawable instanceof BitmapDrawable) { mBitmap = ((BitmapDrawable) drawable).getBitmap(); } else if (drawable instanceof NinePatchDrawable) { // .9? Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); drawable.draw(canvas); mBitmap = bitmap; } } else { mBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.heart_love); } a.recycle(); /** * */ mPaint = new Paint(); mPaint.setAntiAlias(true); mPaint.setColor(mIndicatorColor); mPaint.setStyle(Style.FILL); }
From source file:com.auth0.android.lock.views.ValidatedInputView.java
private void init(AttributeSet attrs) { inflate(getContext(), R.layout.com_auth0_lock_validated_input_view, this); rootView = (LinearLayout) findViewById(R.id.com_auth0_lock_container); errorDescription = (TextView) findViewById(R.id.errorDescription); icon = (ImageView) findViewById(R.id.com_auth0_lock_icon); input = (EditText) findViewById(R.id.com_auth0_lock_input); createBackground();//from ww w . jav a 2 s .c o m if (attrs == null || isInEditMode()) { return; } TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.Lock_ValidatedInput); //noinspection WrongConstant dataType = a.getInt(R.styleable.Lock_ValidatedInput_Auth0_InputDataType, 0); a.recycle(); setupInputValidation(); updateBorder(true); }
From source file:alexander.martinz.libs.materialpreferences.MaterialEditTextPreference.java
@Override protected TypedArray parseAttrs(Context context, AttributeSet attrs) { final TypedArray a = super.parseAttrs(context, attrs); if (a == null) { Log.e(this.getClass().getSimpleName(), "Could not obtain typed array!"); return null; }/*from ww w . j a v a2 s.c o m*/ mDefaultValue = a.getString(R.styleable.MaterialPreference_prefDefaultValue); mValue = mDefaultValue; mPrefTextColor = a.getResourceId(R.styleable.MaterialPreference_prefTextColor, -1); mPrefTextSize = a.getInt(R.styleable.MaterialPreference_prefTextSize, -1); mPrefTextMaxLength = a.getInt(R.styleable.MaterialPreference_prefTextMaxLength, 25); return a; }
From source file:com.github.ppamorim.library.DraggerView.java
private void initializeAttributes(AttributeSet attrs) { TypedArray attributes = getContext().obtainStyledAttributes(attrs, R.styleable.dragger_layout); this.dragLimit = attributes.getFloat(R.styleable.dragger_layout_drag_limit, DEFAULT_DRAG_LIMIT); this.dragPosition = DraggerPosition.getDragPosition( attributes.getInt(R.styleable.dragger_layout_drag_position, DEFAULT_DRAG_POSITION)); this.attributes = attributes; }
From source file:com.freegeek.android.materialbanner.MaterialBanner.java
private void init(Context context, AttributeSet attrs) { TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.MaterialBanner); mIndicatorMargin = (int) a.getDimension(R.styleable.MaterialBanner_indicatorMargin, dip2Pix(context, 10)); mIndicatorGravity = IndicatorGravity.valueOf(a.getInt(R.styleable.MaterialBanner_indicatorGravity, 0)); mIndicatorInside = a.getBoolean(R.styleable.MaterialBanner_indicatorInside, true); mMatch = a.getBoolean(R.styleable.MaterialBanner_match, false); a.recycle();//from w w w .ja va2 s. com View view = LayoutInflater.from(context).inflate(R.layout.material_banner, this, true); mCardView = (CardView) view.findViewById(R.id.card_view); mViewPager = (MaterialViewPager) view.findViewById(R.id.view_pager); mCardContainer = (FrameLayout) view.findViewById(R.id.container); mCardContainer = (FrameLayout) view.findViewById(R.id.card_container); mIndicatorContainer = (FrameLayout) view.findViewById(R.id.indicator_container); mIndicatorParams = new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); mIndicatorParams.gravity = Gravity.CENTER; mCardParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT); mCardParams.gravity = Gravity.TOP; //set Z value. bring indicator view to front,view.bringToFront does't work on 6.0 ViewCompat.setZ(mCardView, 1); ViewCompat.setZ(mViewPager, 2); ViewCompat.setZ(mCardContainer, 1); ViewCompat.setZ(mIndicatorContainer, 2); updateMargin(); setMatch(mMatch); adSwitchTask = new AdSwitchTask(this); }
From source file:com.fortysevendeg.android.swipelistview.SwipeListView.java
/** * Init ListView//w w w. ja v a2 s.co 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 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); swipeFrontView = styled.getResourceId(R.styleable.SwipeListView_swipeFrontView, 0); swipeBackView = styled.getResourceId(R.styleable.SwipeListView_swipeBackView, 0); } if (swipeFrontView == 0 || swipeBackView == 0) { throw new RuntimeException("Missed attribute swipeFrontView or swipeBackView"); } 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); setOnTouchListener(touchListener); setOnScrollListener(touchListener.makeScrollListener()); }
From source file:com.amitupadhyay.aboutexample.ui.widget.FabOverlapTextView.java
private void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { paint = new TextPaint(Paint.ANTI_ALIAS_FLAG); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.FabOverlapTextView); float defaultTextSize = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, DEFAULT_TEXT_SIZE_SP, getResources().getDisplayMetrics()); setFabOverlapGravity(a.getInt(R.styleable.FabOverlapTextView_fabGravity, Gravity.BOTTOM | Gravity.RIGHT)); setFabOverlapHeight(a.getDimensionPixelSize(R.styleable.FabOverlapTextView_fabOverlayHeight, 0)); setFabOverlapWidth(a.getDimensionPixelSize(R.styleable.FabOverlapTextView_fabOverlayWidth, 0)); if (a.hasValue(R.styleable.FabOverlapTextView_android_textAppearance)) { final int textAppearance = a.getResourceId(R.styleable.FabOverlapTextView_android_textAppearance, android.R.style.TextAppearance); TypedArray atp = getContext().obtainStyledAttributes(textAppearance, R.styleable.FontTextAppearance); paint.setColor(atp.getColor(R.styleable.FontTextAppearance_android_textColor, Color.BLACK)); paint.setTextSize(atp.getDimensionPixelSize(R.styleable.FontTextAppearance_android_textSize, (int) defaultTextSize)); if (atp.hasValue(R.styleable.FontTextAppearance_font)) { paint.setTypeface(FontUtil.get(getContext(), atp.getString(R.styleable.FontTextAppearance_font))); }/*from www .j a v a 2 s . c o m*/ atp.recycle(); } if (a.hasValue(R.styleable.FabOverlapTextView_font)) { setFont(a.getString(R.styleable.FabOverlapTextView_font)); } if (a.hasValue(R.styleable.FabOverlapTextView_android_textColor)) { setTextColor(a.getColor(R.styleable.FabOverlapTextView_android_textColor, 0)); } if (a.hasValue(R.styleable.FabOverlapTextView_android_textSize)) { setTextSize(a.getDimensionPixelSize(R.styleable.FabOverlapTextView_android_textSize, (int) defaultTextSize)); } lineHeightHint = a.getDimensionPixelSize(R.styleable.FabOverlapTextView_lineHeightHint, 0); unalignedTopPadding = getPaddingTop(); unalignedBottomPadding = getPaddingBottom(); breakStrategy = a.getInt(R.styleable.FabOverlapTextView_android_breakStrategy, Layout.BREAK_STRATEGY_BALANCED); a.recycle(); }
From source file:com.bilibili.magicasakura.widgets.AppCompatCompoundDrawableHelper.java
@SuppressWarnings("ResourceType") @Override/*from ww w .ja va 2 s .c om*/ void loadFromAttribute(AttributeSet attrs, int defStyleAttr) { Context context = mView.getContext(); TypedArray a = context.obtainStyledAttributes(attrs, ATTR, defStyleAttr, 0); for (int tintIndex = 0; tintIndex < 4; tintIndex++) { int modeIndex = tintIndex + 4; mCompoundDrawableResIds[tintIndex] = a.getResourceId(tintIndex, 0); mCompoundDrawableTintResIds[tintIndex] = a.getResourceId(tintIndex, 0); if (a.hasValue(modeIndex)) { mCompoundDrawableTintModes[tintIndex] = DrawableUtils.parseTintMode(a.getInt(modeIndex, 0), null); } } mCompoundDrawableResIds[0] = ThemeUtils.getThemeAttrId(context, attrs, android.R.attr.drawableLeft); mCompoundDrawableResIds[1] = ThemeUtils.getThemeAttrId(context, attrs, android.R.attr.drawableTop); mCompoundDrawableResIds[2] = ThemeUtils.getThemeAttrId(context, attrs, android.R.attr.drawableRight); mCompoundDrawableResIds[3] = ThemeUtils.getThemeAttrId(context, attrs, android.R.attr.drawableBottom); a.recycle(); setCompoundDrawablesWithIntrinsicBounds(getCompoundDrawableByPosition(0), getCompoundDrawableByPosition(1), getCompoundDrawableByPosition(2), getCompoundDrawableByPosition(3)); }
From source file:cn.com.hgh.view.SlideSwitch.java
public SlideSwitch(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); listener = null;// w w w.j av a 2 s .c o m paint = new Paint(); paint.setAntiAlias(true); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.slideswitch); color_theme = a.getColor(R.styleable.slideswitch_themeColor, DEFAULT_COLOR_THEME); isOpen = a.getBoolean(R.styleable.slideswitch_isOpen, false); shape = a.getInt(R.styleable.slideswitch_shape1, SHAPE_RECT); a.recycle(); }
From source file:com.github.andrewlord1990.materialandroid.component.grid.GridItemView.java
private void loadIcon(TypedArray typedAttrs) { Drawable icon = typedAttrs.getDrawable(R.styleable.MDGridItemView_md_grid_icon); setIcon(icon);/*from ww w . j a v a 2 s .c o m*/ @IconGravity int iconGravity = typedAttrs.getInt(R.styleable.MDGridItemView_md_grid_icon_gravity, ICON_GRAVITY_START); this.iconGravity = iconGravity; }