List of usage examples for android.content.res TypedArray getInt
public int getInt(@StyleableRes int index, int defValue)
From source file:codetail.graphics.drawables.LayerDrawable.java
/** * Initializes the constant state from the values in the typed array. *///from w w w .ja v a 2 s.c o m private void updateStateFromTypedArray(Theme theme, TypedArray a, TypedValue[] extracted) { final LayerState state = mLayerState; // Account for any configuration changes. state.mChangingConfigurations |= TypedArrayCompat.getChangingConfigurations(a); // Extract the theme attributes, if any. state.mThemeAttrs = TypedArrayCompat.extractThemeAttrs(a); mOpacityOverride = a.getInt(R.styleable.LayerDrawable_android_opacity, mOpacityOverride); state.mAutoMirrored = a.getBoolean(R.styleable.LayerDrawable_android_autoMirrored, state.mAutoMirrored); state.mPaddingMode = a.getInteger(R.styleable.LayerDrawable_android_paddingMode, state.mPaddingMode); }
From source file:com.glm.view.SlidingLayer.java
/** * Constructor for the sliding layer.<br> * By default this panel will//from w ww . ja va2 s . c o m * <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); if (isInEditMode()) return; // 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 shadow drawable int shadowRes = ta.getResourceId(R.styleable.SlidingLayer_shadowDrawable, -1); if (shadowRes != -1) { setShadowDrawable(shadowRes); } // Sets the shadow width setShadowWidth((int) ta.getDimension(R.styleable.SlidingLayer_shadowWidth, 0)); // 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:com.grottworkshop.gwsswipelayout.SwipeLayout.java
public SwipeLayout(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); mDragHelper = ViewDragHelper.create(this, mDragHelperCallback); //TODO: should be recycled @SuppressLint("Recycle") TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SwipeLayout); int ordinal = a.getInt(R.styleable.SwipeLayout_drag_edge, DragEdge.Right.ordinal()); mDragEdge = DragEdge.values()[ordinal]; ordinal = a.getInt(R.styleable.SwipeLayout_show_mode, ShowMode.PullOut.ordinal()); mShowMode = ShowMode.values()[ordinal]; }
From source file:com.albedinsky.android.support.ui.widget.ViewPagerWidget.java
/** * Called from the constructor to process tint values for this view. <b>Note</b>, that for * {@link android.os.Build.VERSION_CODES#LOLLIPOP LOLLIPOP} is this call ignored. * * @param context The context passed to constructor. * @param typedArray TypedArray obtained for styleable attributes specific for this view. *//*from www.j ava 2s.c om*/ @SuppressWarnings("All") private void processTintValues(Context context, TypedArray typedArray) { // Do not handle for LOLLIPOP. if (UiConfig.LOLLIPOP) { return; } this.ensureTintInfo(); // Get tint colors. if (typedArray.hasValue(R.styleable.Ui_Widget_TextView_uiBackgroundTint)) { mTintInfo.backgroundTintList = typedArray .getColorStateList(R.styleable.Ui_Widget_TextView_uiBackgroundTint); } // Get tint modes. mTintInfo.backgroundTintMode = TintManager.parseTintMode( typedArray.getInt(R.styleable.Ui_Widget_TextView_uiBackgroundTintMode, 0), mTintInfo.backgroundTintList != null ? PorterDuff.Mode.SRC_IN : null); // If there is no tint mode specified within style/xml do not tint at all. if (mTintInfo.backgroundTintMode == null) { mTintInfo.backgroundTintList = null; } mTintInfo.hasBackgroundTintList = mTintInfo.backgroundTintList != null; mTintInfo.hasBackgroundTinMode = mTintInfo.backgroundTintMode != null; }
From source file:com.facebook.litho.widget.TextSpec.java
private static void resolveStyleAttrsForTypedArray(TypedArray a, Output<TruncateAt> ellipsize, Output<Boolean> shouldIncludeFontPadding, Output<Float> spacingMultiplier, Output<Integer> minLines, Output<Integer> maxLines, Output<Integer> minEms, Output<Integer> maxEms, Output<Integer> minWidth, Output<Integer> maxWidth, Output<Boolean> isSingleLine, Output<CharSequence> text, Output<ColorStateList> textColorStateList, Output<Integer> linkColor, Output<Integer> highlightColor, Output<Integer> textSize, Output<Alignment> textAlignment, Output<Integer> textStyle, Output<Float> shadowRadius, Output<Float> shadowDx, Output<Float> shadowDy, Output<Integer> shadowColor, Output<VerticalGravity> verticalGravity) { int viewTextAlignment = View.TEXT_ALIGNMENT_GRAVITY; int gravity = Gravity.NO_GRAVITY; for (int i = 0, size = a.getIndexCount(); i < size; i++) { final int attr = a.getIndex(i); if (attr == R.styleable.Text_android_text) { text.set(a.getString(attr)); } else if (attr == R.styleable.Text_android_textColor) { textColorStateList.set(a.getColorStateList(attr)); } else if (attr == R.styleable.Text_android_textSize) { textSize.set(a.getDimensionPixelSize(attr, 0)); } else if (attr == R.styleable.Text_android_ellipsize) { final int index = a.getInteger(attr, 0); if (index > 0) { ellipsize.set(TRUNCATE_AT[index - 1]); }/* w w w.ja v a 2 s . com*/ } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 && attr == R.styleable.Text_android_textAlignment) { viewTextAlignment = a.getInt(attr, -1); textAlignment.set(getAlignment(viewTextAlignment, gravity)); } else if (attr == R.styleable.Text_android_gravity) { gravity = a.getInt(attr, -1); textAlignment.set(getAlignment(viewTextAlignment, gravity)); verticalGravity.set(getVerticalGravity(gravity)); } else if (attr == R.styleable.Text_android_includeFontPadding) { shouldIncludeFontPadding.set(a.getBoolean(attr, false)); } else if (attr == R.styleable.Text_android_minLines) { minLines.set(a.getInteger(attr, -1)); } else if (attr == R.styleable.Text_android_maxLines) { maxLines.set(a.getInteger(attr, -1)); } else if (attr == R.styleable.Text_android_singleLine) { isSingleLine.set(a.getBoolean(attr, false)); } else if (attr == R.styleable.Text_android_textColorLink) { linkColor.set(a.getColor(attr, 0)); } else if (attr == R.styleable.Text_android_textColorHighlight) { highlightColor.set(a.getColor(attr, 0)); } else if (attr == R.styleable.Text_android_textStyle) { textStyle.set(a.getInteger(attr, 0)); } else if (attr == R.styleable.Text_android_lineSpacingMultiplier) { spacingMultiplier.set(a.getFloat(attr, 0)); } else if (attr == R.styleable.Text_android_shadowDx) { shadowDx.set(a.getFloat(attr, 0)); } else if (attr == R.styleable.Text_android_shadowDy) { shadowDy.set(a.getFloat(attr, 0)); } else if (attr == R.styleable.Text_android_shadowRadius) { shadowRadius.set(a.getFloat(attr, 0)); } else if (attr == R.styleable.Text_android_shadowColor) { shadowColor.set(a.getColor(attr, 0)); } else if (attr == R.styleable.Text_android_minEms) { minEms.set(a.getInteger(attr, DEFAULT_EMS)); } else if (attr == R.styleable.Text_android_maxEms) { maxEms.set(a.getInteger(attr, DEFAULT_EMS)); } else if (attr == R.styleable.Text_android_minWidth) { minWidth.set(a.getDimensionPixelSize(attr, DEFAULT_MIN_WIDTH)); } else if (attr == R.styleable.Text_android_maxWidth) { maxWidth.set(a.getDimensionPixelSize(attr, DEFAULT_MAX_WIDTH)); } } }
From source file:bk.vinhdo.taxiads.utils.view.SlidingLayer.java
/** * Constructor for the sliding layer.<br> * By default this panel will//from w w w.java 2 s . co m * <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 shadow drawable int shadowRes = ta.getResourceId(R.styleable.SlidingLayer_shadowDrawableSliding, -1); if (shadowRes != -1) { setShadowDrawable(shadowRes); } // Sets the shadow width setShadowWidth((int) ta.getDimension(R.styleable.SlidingLayer_shadowWidthSliding, 0)); // 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:com.mde.potdroid.helpers.ptr.SwipyRefreshLayout.java
/** * Constructor that is called when inflating SwipeRefreshLayout from XML. * * @param context/*w ww . ja v a 2s.c o m*/ * @param attrs */ public SwipyRefreshLayout(Context context, AttributeSet attrs) { super(context, attrs); mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop(); mMediumAnimationDuration = getResources().getInteger(android.R.integer.config_mediumAnimTime); setWillNotDraw(false); mDecelerateInterpolator = new DecelerateInterpolator(DECELERATE_INTERPOLATION_FACTOR); final TypedArray a = context.obtainStyledAttributes(attrs, LAYOUT_ATTRS); setEnabled(a.getBoolean(0, true)); a.recycle(); final TypedArray a2 = context.obtainStyledAttributes(attrs, R.styleable.SwipyRefreshLayout); mAdapterViewId = a2.getResourceId(R.styleable.SwipyRefreshLayout_adapter_view, -1); SwipyRefreshLayoutDirection direction = SwipyRefreshLayoutDirection .getFromInt(a2.getInt(R.styleable.SwipyRefreshLayout_srl_direction, 0)); if (direction != SwipyRefreshLayoutDirection.BOTH) { mDirection = direction; mBothDirection = false; } else { mDirection = SwipyRefreshLayoutDirection.TOP; mBothDirection = true; } a2.recycle(); final DisplayMetrics metrics = getResources().getDisplayMetrics(); mCircleWidth = (int) (CIRCLE_DIAMETER * metrics.density); mCircleHeight = (int) (CIRCLE_DIAMETER * metrics.density); createProgressView(); ViewCompat.setChildrenDrawingOrderEnabled(this, true); // the absolute offset has to take into account that the circle starts at an offset mSpinnerFinalOffset = DEFAULT_CIRCLE_TARGET * metrics.density; }
From source file:com.appsummary.luoxf.myappsummary.navigationtabstrip.NavigationTabStrip.java
public NavigationTabStrip(final Context context, final AttributeSet attrs, final int defStyleAttr) { super(context, attrs, defStyleAttr); //Init NTS/* w w w. ja v a 2s. c o m*/ // Always draw setWillNotDraw(false); // More speed! setLayerType(LAYER_TYPE_HARDWARE, null); final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.NavigationTabStrip); try { setStripColor(typedArray.getColor(R.styleable.NavigationTabStrip_nts_color, DEFAULT_STRIP_COLOR)); setTitleSize(typedArray.getDimension(R.styleable.NavigationTabStrip_nts_size, DEFAULT_TITLE_SIZE)); setStripWeight( typedArray.getDimension(R.styleable.NavigationTabStrip_nts_weight, DEFAULT_STRIP_WEIGHT)); setStripFactor(typedArray.getFloat(R.styleable.NavigationTabStrip_nts_factor, DEFAULT_STRIP_FACTOR)); setStripType(typedArray.getInt(R.styleable.NavigationTabStrip_nts_type, StripType.LINE_INDEX)); setStripGravity( typedArray.getInt(R.styleable.NavigationTabStrip_nts_gravity, StripGravity.BOTTOM_INDEX)); setTypeface(typedArray.getString(R.styleable.NavigationTabStrip_nts_typeface)); setInactiveColor( typedArray.getColor(R.styleable.NavigationTabStrip_nts_inactive_color, DEFAULT_INACTIVE_COLOR)); setActiveColor( typedArray.getColor(R.styleable.NavigationTabStrip_nts_active_color, DEFAULT_ACTIVE_COLOR)); setAnimationDuration(typedArray.getInteger(R.styleable.NavigationTabStrip_nts_animation_duration, DEFAULT_ANIMATION_DURATION)); setCornersRadius(typedArray.getDimension(R.styleable.NavigationTabStrip_nts_corners_radius, DEFAULT_CORNER_RADIUS)); // Get titles String[] titles = null; try { final int titlesResId = typedArray.getResourceId(R.styleable.NavigationTabStrip_nts_titles, 0); titles = titlesResId == 0 ? null : typedArray.getResources().getStringArray(titlesResId); } catch (Exception exception) { titles = null; exception.printStackTrace(); } finally { if (titles == null) { if (isInEditMode()) { titles = new String[new Random().nextInt(5) + 1]; Arrays.fill(titles, PREVIEW_TITLE); } else titles = new String[0]; } setTitles(titles); } // Init animator mAnimator.setFloatValues(MIN_FRACTION, MAX_FRACTION); mAnimator.setInterpolator(new LinearInterpolator()); mAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(final ValueAnimator animation) { updateIndicatorPosition((Float) animation.getAnimatedValue()); } }); } finally { typedArray.recycle(); } }
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;/*from ww w . j ava 2 s .c o 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:com.quran.labs.androidquran.widgets.SlidingUpPanelLayout.java
public SlidingUpPanelLayout(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); if (isInEditMode()) { mShadowDrawable = null;/*w ww.ja v a2 s. c o m*/ mScrollTouchSlop = 0; mDragHelper = null; return; } if (attrs != null) { TypedArray defAttrs = context.obtainStyledAttributes(attrs, DEFAULT_ATTRS); if (defAttrs != null) { int gravity = defAttrs.getInt(0, Gravity.NO_GRAVITY); if (gravity != Gravity.TOP && gravity != Gravity.BOTTOM) { throw new IllegalArgumentException("gravity must be set to either top or bottom"); } mIsSlidingUp = gravity == Gravity.BOTTOM; } defAttrs.recycle(); TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.SlidingUpPanelLayout); if (ta != null) { mPanelHeight = ta.getDimensionPixelSize(R.styleable.SlidingUpPanelLayout_panelHeight, -1); mShadowHeight = ta.getDimensionPixelSize(R.styleable.SlidingUpPanelLayout_shadowHeight, -1); mParallaxOffset = ta.getDimensionPixelSize(R.styleable.SlidingUpPanelLayout_parallaxOffset, -1); mMinFlingVelocity = ta.getInt(R.styleable.SlidingUpPanelLayout_flingVelocity, DEFAULT_MIN_FLING_VELOCITY); mCoveredFadeColor = ta.getColor(R.styleable.SlidingUpPanelLayout_fadeColor, DEFAULT_FADE_COLOR); mDragViewResId = ta.getResourceId(R.styleable.SlidingUpPanelLayout_dragView, -1); mOverlayContent = ta.getBoolean(R.styleable.SlidingUpPanelLayout_overlay, DEFAULT_OVERLAY_FLAG); mArbitraryPositionEnabled = ta.getBoolean(R.styleable.SlidingUpPanelLayout_arbitraryPosition, DEFAULT_ARBITRARY_POS_FLAG); } ta.recycle(); } final float density = context.getResources().getDisplayMetrics().density; if (mPanelHeight == -1) { mPanelHeight = (int) (DEFAULT_PANEL_HEIGHT * density + 0.5f); } if (mShadowHeight == -1) { mShadowHeight = (int) (DEFAULT_SHADOW_HEIGHT * density + 0.5f); } if (mParallaxOffset == -1) { mParallaxOffset = (int) (DEFAULT_PARALLAX_OFFSET * density); } // If the shadow height is zero, don't show the shadow if (mShadowHeight > 0) { if (mIsSlidingUp) { mShadowDrawable = ContextCompat.getDrawable(context, R.drawable.sliding_panel_above_shadow); } else { mShadowDrawable = ContextCompat.getDrawable(context, R.drawable.sliding_panel_below_shadow); } } else { mShadowDrawable = null; } setWillNotDraw(false); mDragHelper = ViewDragHelper.create(this, 1.0f, new DragHelperCallback()); mDragHelper.setMinVelocity(mMinFlingVelocity * density); mCanSlide = true; mIsSlidingEnabled = true; ViewConfiguration vc = ViewConfiguration.get(context); mScrollTouchSlop = vc.getScaledTouchSlop(); }