public CircleImageView(Context context, IAttributeSet attrs, int defStyle) : base(context, attrs, defStyle) { // init paint paint = new Paint(); paint.AntiAlias = true; paintBorder = new Paint(); paintBorder.AntiAlias = true; // load the styled attributes and set their properties TypedArray attributes = context.ObtainStyledAttributes(attrs, Resource.Styleable.CircularImageView, defStyle, 0); if (attributes.GetBoolean(Resource.Styleable.CircularImageView_border, true)) { int defaultBorderSize = (int)(4 * context.Resources.DisplayMetrics.Density+ 0.5f); BorderWidth = attributes.GetDimensionPixelOffset(Resource.Styleable.CircularImageView_border_width, defaultBorderSize); BorderColor = attributes.GetColor(Resource.Styleable.CircularImageView_border_color, Color.White); } if (attributes.GetBoolean(Resource.Styleable.CircularImageView_shadow, false)) { addShadow(); } }
public LinePageIndicator(Context context, IAttributeSet attrs, int defStyle) : base(context, attrs, defStyle) { if(IsInEditMode) return; var res = Resources; //Load defaults from resources var defaultSelectedColor = res.GetColor(Resource.Color.default_line_indicator_selected_color); var defaultUnselectedColor = res.GetColor(Resource.Color.default_line_indicator_unselected_color); var defaultLineWidth = res.GetDimension(Resource.Dimension.default_line_indicator_line_width); var defaultGapWidth = res.GetDimension(Resource.Dimension.default_line_indicator_gap_width); var defaultStrokeWidth = res.GetDimension(Resource.Dimension.default_line_indicator_stroke_width); var defaultCentered = res.GetBoolean(Resource.Boolean.default_line_indicator_centered); //Retrive styles attributes var a = context.ObtainStyledAttributes(attrs, Resource.Styleable.LinePageIndicator, defStyle, 0); _centered = a.GetBoolean(Resource.Styleable.LinePageIndicator_centered, defaultCentered); _lineWidth = a.GetDimension(Resource.Styleable.LinePageIndicator_lineWidth, defaultLineWidth); _gapWidth = a.GetDimension(Resource.Styleable.LinePageIndicator_gapWidth, defaultGapWidth); StrokeWidth = a.GetDimension(Resource.Styleable.LinePageIndicator_strokeWidth, defaultStrokeWidth); _paintUnSelected.Color = a.GetColor(Resource.Styleable.LinePageIndicator_unselectedColor, defaultUnselectedColor); _paintSelected.Color = a.GetColor(Resource.Styleable.LinePageIndicator_selectedColor, defaultSelectedColor); var background = a.GetDrawable(Resource.Styleable.LinePageIndicator_android_background); if (null != background) Background = background; a.Recycle(); var configuration = ViewConfiguration.Get(context); _touchSlop = ViewConfigurationCompat.GetScaledPagingTouchSlop(configuration); }
//applies font from XML public static void ApplyCustomFont(TextView view, Context context, IAttributeSet attrs) { TypedArray attributeArray = context.ObtainStyledAttributes (attrs, Resource.Styleable.CustomFont); string fontName = attributeArray.GetString (Resource.Styleable.CustomFont_font); int textStyle = attrs.GetAttributeIntValue (ANDROID_SCHEMA, "textStyle", 0); Typeface customFont = SelectTypeface (context, fontName); switch (textStyle) { case 1: view.SetTypeface (customFont, TypefaceStyle.Bold); break; case 2: view.SetTypeface (customFont, TypefaceStyle.Italic); break; case 3: view.SetTypeface (customFont, TypefaceStyle.BoldItalic); break; default: view.SetTypeface (customFont, TypefaceStyle.Normal); break; } attributeArray.Recycle (); }
public MvxImageView(Context context, IAttributeSet attrs) : base(context, attrs) { if (!Mvx.TryResolve(out _imageHelper)) { MvxTrace.Error( "No IMvxImageHelper registered - you must provide an image helper before you can use a MvxImageView"); } else { _imageHelper.ImageChanged += ImageHelperOnImageChanged; } var typedArray = context.ObtainStyledAttributes(attrs, MvxAndroidBindingResource.Instance .ImageViewStylableGroupId); int numStyles = typedArray.IndexCount; for (var i = 0; i < numStyles; ++i) { int attributeId = typedArray.GetIndex(i); if (attributeId == MvxAndroidBindingResource.Instance.SourceBindId) { ImageUrl = typedArray.GetString(attributeId); } } typedArray.Recycle(); }
public MvxHorizontalGridView(Context context, IAttributeSet attrs, int defStyle, IMvxRecyclerAdapter adapter) : base(context, attrs, defStyle) { // Note: Any calling derived class passing a null adapter is responsible for setting // it's own itemTemplateId if (adapter == null) return; var itemTemplateId = MvxAttributeHelpers.ReadListItemTemplateId(context, attrs); adapter.ItemTemplateId = itemTemplateId; Adapter = adapter; var typedArray = context.ObtainStyledAttributes(attrs, Resource.Styleable.MvxHorizontalGridView); try { FocusFirstChildOnLaidOut = typedArray.GetBoolean(Resource.Styleable.MvxHorizontalGridView_FocusFirstChildOnLaidOut, false); if (FocusFirstChildOnLaidOut) { SetOnChildLaidOutListener(new MvxFocusFirstChildOnChildLaidOutListener()); } } finally { typedArray.Recycle(); } // We need this listener to get information about the currently _selected_ item // Overriding setter of base.SelectedPosition is not enough! OnChildViewHolderSelectedListener = new MvxOnChildViewHolderSelectedListener(); SetOnChildViewHolderSelectedListener(OnChildViewHolderSelectedListener); }
/// <summary> /// Parses the binding attributes into MvxViewBindingTag. /// </summary> /// <returns>The tag with parsed values, null if no binding attributes found.</returns> protected MvxViewBindingTag ParseAttributes (Context context, IAttributeSet attrs) { var res = MvxAndroidBindingResource.Instance; IEnumerable<MvxBindingDescription> descriptions = null; using (var typedArray = context.ObtainStyledAttributes( attrs, res.BindingStylableGroupId)) { int numStyles = typedArray.IndexCount; for (var i = 0; i < numStyles; ++i) { var attributeId = typedArray.GetIndex (i); if (attributeId == res.BindingBindId) { try { var bindingText = typedArray.GetString (attributeId); descriptions = this.GetService<IMvxBindingDescriptionParser> ().Parse (bindingText); } catch (Exception exception) { MvxBindingTrace.Trace ( MvxTraceLevel.Error, "Exception thrown during the parsing the bindings {0}", exception.ToLongString ()); throw; } } } typedArray.Recycle (); } if (descriptions != null) { return new MvxViewBindingTag (descriptions); } return null; }
public RoundedImageView(Context context, IAttributeSet attrs, int defStyle) : base(context, attrs, defStyle) { TypedArray a = context.ObtainStyledAttributes(attrs, Resource.Styleable.RoundedImageView, defStyle, 0); int index = a.GetInt(Resource.Styleable.RoundedImageView_android_scaleType, -1); SetScaleType(index >= 0 ? ScaleTypes[index] : ScaleType.FitCenter); _cornerRadius = a.GetDimensionPixelSize(Resource.Styleable.RoundedImageView_corner_radius, -1); _borderWidth = a.GetDimensionPixelSize(Resource.Styleable.RoundedImageView_border_width, -1); // don't allow negative values for radius and border if (_cornerRadius < 0) { _cornerRadius = DefaultRadius; } if (_borderWidth < 0) { _borderWidth = DefaultBorderWidth; } _borderColor = a.GetColorStateList(Resource.Styleable.RoundedImageView_border_color) ?? ColorStateList.ValueOf(Color.Black); _mutateBackground = a.GetBoolean(Resource.Styleable.RoundedImageView_mutate_background, false); _isOval = a.GetBoolean(Resource.Styleable.RoundedImageView_oval, false); UpdateDrawableAttrs(); UpdateBackgroundDrawableAttrs(true); a.Recycle(); }
public AnimatedPathView (Context context, IAttributeSet attrs, int defStyle) : base (context, attrs, defStyle) { mStrokePaint.SetStyle (Paint.Style.Stroke); mFillPaint.SetStyle (Paint.Style.Fill); TypedArray a = context.ObtainStyledAttributes (attrs, Resource.Styleable.AnimatedPathView, defStyle, 0); try { if(a != null) { mStrokePaint.StrokeWidth = a.GetDimensionPixelSize (Resource.Styleable.AnimatedPathView_strokeWidth,1); mStrokePaint.Color = a.GetColor (Resource.Styleable.AnimatedPathView_strokeColor, unchecked((int)0xff000000)); svg = new SvgHelper (mStrokePaint); mFillPaint.Color = a.GetColor (Resource.Styleable.AnimatedPathView_fillColor, unchecked((int)0xff000000)); phase = a.GetFloat (Resource.Styleable.AnimatedPathView_phase, 0.0f); duration = a.GetInt (Resource.Styleable.AnimatedPathView_duration, 4000); fillDuration = a.GetInt (Resource.Styleable.AnimatedPathView_fillDuration, 4000); fillOffset = a.GetInt (Resource.Styleable.AnimatedPathView_fillOffset, 2000); fadeFactor = a.GetFloat (Resource.Styleable.AnimatedPathView_fadeFactor, 10.0f); svgResource = a.GetResourceId (Resource.Styleable.AnimatedPathView_svgPath, 0); } } finally { if (a != null) a.Recycle (); } }
public DividerItemDecoration (Context context, int orientation) { var a = context.ObtainStyledAttributes (Attrs); divider = a.GetDrawable (0); a.Recycle(); Orientation = orientation; }
public GridView(Context context, IAttributeSet attrs, int defStyle) : base(context, attrs, defStyle) { var a = context.ObtainStyledAttributes(attrs, Resource.Styleable.GridView, defStyle, 0); int markupId = a.GetResourceId(Resource.Styleable.GridView_grid_markup, DefaultGridMarkupValue); if(markupId != DefaultGridMarkupValue) { ParseMarkupXml(markupId); } else { _rowDefinitions.Add(new GridDefinition()); _columnDefinitions.Add(new GridDefinition()); } foreach(var row in _rowDefinitions) { var rowInfo = new GridDefinitionMeasureInfo(row); _rowsInfo.Add(row, rowInfo); if(row.Length.IsStar) { _heightStarSum += row.Length.Value; } } foreach(var column in _columnDefinitions) { var columnInfo = new GridDefinitionMeasureInfo(column); _columnsInfo.Add(column, columnInfo); if(column.Length.IsStar) { _widthStarSum += column.Length.Value; } } }
private void Init(Android.Content.Context context, IAttributeSet attrs) { TypedArray typedArray = context.ObtainStyledAttributes(attrs, Resource.Styleable.LoadingView); loadText = typedArray.GetString(Resource.Styleable.LoadingView_loadingText); typedArray.Recycle(); }
public CirclePageIndicator(Context context, IAttributeSet attrs, int defStyle) : base(context, attrs, defStyle) { //Load defaults from resources var res = Resources; int defaultPageColor = res.GetColor(Resource.Color.default_circle_indicator_page_color); int defaultFillColor = res.GetColor(Resource.Color.default_circle_indicator_fill_color); int defaultOrientation = res.GetInteger(Resource.Integer.default_circle_indicator_orientation); int defaultStrokeColor = res.GetColor(Resource.Color.default_circle_indicator_stroke_color); float defaultStrokeWidth = res.GetDimension(Resource.Dimension.default_circle_indicator_stroke_width); float defaultRadius = res.GetDimension(Resource.Dimension.default_circle_indicator_radius); bool defaultCentered = res.GetBoolean(Resource.Boolean.default_circle_indicator_centered); bool defaultSnap = res.GetBoolean(Resource.Boolean.default_circle_indicator_snap); //Retrieve styles attributes var a = context.ObtainStyledAttributes(attrs, Resource.Styleable.CirclePageIndicator, defStyle, Resource.Style.Widget_CirclePageIndicator); mCentered = a.GetBoolean(Resource.Styleable.CirclePageIndicator_vpiCentered, defaultCentered); mOrientation = a.GetInt(Resource.Styleable.CirclePageIndicator_vpiOrientation, defaultOrientation); mPaintPageFill = new Paint(PaintFlags.AntiAlias); mPaintPageFill.SetStyle(Paint.Style.Fill); mPaintPageFill.Color = a.GetColor(Resource.Styleable.CirclePageIndicator_vpiPageColor, defaultPageColor); mPaintStroke = new Paint(PaintFlags.AntiAlias); mPaintStroke.SetStyle(Paint.Style.Stroke); mPaintFill = new Paint(PaintFlags.AntiAlias); mPaintFill.SetStyle(Paint.Style.Fill); mSnap = a.GetBoolean(Resource.Styleable.CirclePageIndicator_vpiSnap, defaultSnap); mRadius = a.GetDimension(Resource.Styleable.CirclePageIndicator_vpiRadius, defaultRadius); mPaintFill.Color = a.GetColor(Resource.Styleable.CirclePageIndicator_vpiFillColor, defaultFillColor); mPaintStroke.Color = a.GetColor(Resource.Styleable.CirclePageIndicator_vpiStrokeColor, defaultStrokeColor); mPaintStroke.StrokeWidth = a.GetDimension(Resource.Styleable.CirclePageIndicator_vpiStrokeWidth, defaultStrokeWidth); a.Recycle(); }
private static string ReadRecyclerViewItemTemplateSelectorClassName(Context context, IAttributeSet attrs) { TryInitializeBindingResourcePaths(); TypedArray typedArray = null; string className = string.Empty; try { typedArray = context.ObtainStyledAttributes(attrs, MvxRecyclerViewItemTemplateSelectorGroupId); int numberOfStyles = typedArray.IndexCount; for (int i = 0; i < numberOfStyles; ++i) { var attributeId = typedArray.GetIndex(i); if (attributeId == MvxRecyclerViewItemTemplateSelector) className = typedArray.GetString(attributeId); } } finally { typedArray?.Recycle(); } if (string.IsNullOrEmpty(className)) return typeof (SingleItemDefaultTemplateSelector).FullName; return className; }
public SearchToolbar(Context context, IAttributeSet attrs, int defStyleAttr) : base(context, attrs, defStyleAttr) { binding = SearchToolbarBinding.Inflate(LayoutInflater.From(context), Resource.Layout.toolbar_search, this, true); if (!IsInEditMode) { var a = context.ObtainStyledAttributes(attrs, Resource.Styleable.SearchToolbar); try { var focus = a.GetBoolean(Resource.Styleable.SearchToolbar_searchFocus, false); var hintResId = a.GetResourceId(Resource.Styleable.SearchToolbar_searchHint, Resource.String.search_hint); SetHint(hintResId); if (focus) { binding.editSearch.RequestFocus(); } else { ClearFocus(); } ToggleCloseButtonVisible(false); InitView(); } finally { a.Recycle(); } } }
public BezelImageView(Context context, IAttributeSet attrs, int defStyle) : base(context, attrs, defStyle) { // Attribute initialization var a = context.ObtainStyledAttributes(attrs, Resource.Styleable.BezelImageView, defStyle, 0); mMaskDrawable = a.GetDrawable(Resource.Styleable.BezelImageView_maskDrawable); if (mMaskDrawable == null) { mMaskDrawable = Resources.GetDrawable(Resource.Drawable.bezel_mask); } mMaskDrawable.Callback = this; mBorderDrawable = a.GetDrawable(Resource.Styleable.BezelImageView_borderDrawable); if (mBorderDrawable == null) { mBorderDrawable = Resources.GetDrawable(Resource.Drawable.bezel_border); } mBorderDrawable.Callback = this; a.Recycle(); // Other initialization mMaskedPaint = new Paint(); mMaskedPaint.SetXfermode(new PorterDuffXfermode(PorterDuff.Mode.SrcAtop)); mCopyPaint = new Paint(); }
private void Init(Android.Content.Context context, IAttributeSet attrs, int p) { TypedArray a = context.ObtainStyledAttributes(attrs, Resource.Styleable.CircleProgressBar, p, 0); float density = context.Resources.DisplayMetrics.Density; mBackGroundColor = a.GetColor(Resource.Styleable.CircleProgressBar_mlpb_background_color, DEFAULT_CIRCLE_BG_LIGHT); mProgressColor = a.GetColor(Resource.Styleable.CircleProgressBar_mlpb_progress_color, DEFAULT_CIRCLE_BG_LIGHT); mInnerRadius = a.GetDimensionPixelOffset(Resource.Styleable.CircleProgressBar_mlpb_inner_radius, -1); mProgressStokeWidth = a.GetDimensionPixelOffset(Resource.Styleable.CircleProgressBar_mlpb_progress_stoke_width, (int)(STROKE_WIDTH_LARGE * density)); mArrowWidth = a.GetDimensionPixelOffset(Resource.Styleable.CircleProgressBar_mlpb_arrow_width, -1); mArrowHeight = a.GetDimensionPixelOffset(Resource.Styleable.CircleProgressBar_mlpb_arrow_height, -1); mTextSize = a.GetDimensionPixelOffset(Resource.Styleable.CircleProgressBar_mlpb_progress_text_size, (int)(DEFAULT_TEXT_SIZE * density)); mTextColor = a.GetColor(Resource.Styleable.CircleProgressBar_mlpb_progress_text_color, Color.Black); mShowArrow = a.GetBoolean(Resource.Styleable.CircleProgressBar_mlpb_show_arrow, false); mCircleBackgroundEnabled = a.GetBoolean(Resource.Styleable.CircleProgressBar_mlpb_enable_circle_background, true); mProgress = a.GetInt(Resource.Styleable.CircleProgressBar_mlpb_progress, 0); mMax = a.GetInt(Resource.Styleable.CircleProgressBar_mlpb_max, 100); int textVisible = a.GetInt(Resource.Styleable.CircleProgressBar_mlpb_progress_text_visibility, 1); if (textVisible != 1) { mIfDrawText = true; } mTextPaint = new Paint(); mTextPaint.SetStyle(Paint.Style.Fill); mTextPaint.Color = mTextColor; mTextPaint.TextSize = mTextSize; mTextPaint.AntiAlias = true; a.Recycle(); mProgressDrawable = new MaterialProgressDrawale(Context, this); base.SetImageDrawable(mProgressDrawable); }
public SwipeLayout(Context context, IAttributeSet attrs, int defStyle) : base(context, attrs, defStyle) { IsSwipeEnabled = true; gestureDetector = new GestureDetector (Context, new SwipeDetector (this)); mDragHelperCallback = new SwipeLayoutDragHelperCallback (this); mDragHelper = ViewDragHelper.Create(this, mDragHelperCallback); mTouchSlop = ViewConfiguration.Get(context).ScaledTouchSlop; TypedArray a = context.ObtainStyledAttributes(attrs, Resource.Styleable.SwipeLayout); int dragEdgeChoices = a.GetInt(Resource.Styleable.SwipeLayout_drag_edge, DRAG_RIGHT); mEdgeSwipesOffset[(int)DragEdge.Left] = a.GetDimension(Resource.Styleable.SwipeLayout_leftEdgeSwipeOffset, 0); mEdgeSwipesOffset[(int)DragEdge.Right] = a.GetDimension(Resource.Styleable.SwipeLayout_rightEdgeSwipeOffset, 0); mEdgeSwipesOffset[(int)DragEdge.Top] = a.GetDimension(Resource.Styleable.SwipeLayout_topEdgeSwipeOffset, 0); mEdgeSwipesOffset[(int)DragEdge.Bottom] = a.GetDimension(Resource.Styleable.SwipeLayout_bottomEdgeSwipeOffset, 0); ClickToClose = a.GetBoolean(Resource.Styleable.SwipeLayout_clickToClose, ClickToClose); if ((dragEdgeChoices & DRAG_LEFT) == DRAG_LEFT) { mDragEdges.Add(DragEdge.Left, null); } if ((dragEdgeChoices & DRAG_TOP) == DRAG_TOP) { mDragEdges.Add(DragEdge.Top, null); } if ((dragEdgeChoices & DRAG_RIGHT) == DRAG_RIGHT) { mDragEdges.Add(DragEdge.Right, null); } if ((dragEdgeChoices & DRAG_BOTTOM) == DRAG_BOTTOM) { mDragEdges.Add(DragEdge.Bottom, null); } int ordinal = a.GetInt(Resource.Styleable.SwipeLayout_show_mode, (int)ShowMode.PullOut); mShowMode = (ShowMode)System.Enum.ToObject(typeof(ShowMode), ordinal); a.Recycle(); }
public static int GetAccentColor(Context context) { var typedValue = new TypedValue(); TypedArray a = context.ObtainStyledAttributes(typedValue.Data, new int[] { Resource.Attribute.colorAccent }); int color = a.GetColor(0, 0); a.Recycle(); return color; }
public IcsLinearLayout(Context context, int themeAttr) : base(context) { var a = context.ObtainStyledAttributes(null, Ll, themeAttr, 0); DividerDrawable = a.GetDrawable(LlDivider); _dividerPadding = a.GetDimensionPixelSize(LlDividerPadding, 0); _showDividers = a.GetInteger(LlShowDivider, (int)ShowDividers.None); }
public BlocksLayout(Context context, IAttributeSet attrs, int defStyle) : base(context, attrs, defStyle) { var a = context.ObtainStyledAttributes(attrs, Resource.Styleable.BlocksLayout, defStyle, 0); mColumns = a.GetInt(Resource.Styleable.TimeRulerView_headerWidth, mColumns); a.Recycle(); }
// Default constructor override public AutoScaleToWidthTextView(Context context, IAttributeSet attrs, int defStyle) : base(context, attrs, defStyle) { _textSize = TextSize; TypedArray typeArray = context.ObtainStyledAttributes(attrs, Resource.Styleable.AutoScaleToWidthTextView, 0, 0); _maxTextSize = typeArray.GetDimension(Resource.Styleable.AutoScaleToWidthTextView_maxTextSize, 1000); }
public SlidingUpPanelLayout(Context context, IAttributeSet attrs, int defStyle) : base(context, attrs, defStyle) { // not really relevan in Xamarin.Android but keeping for a possible // future update which will render layouts in the Designer. if (IsInEditMode) return; if (attrs != null) { var defAttrs = context.ObtainStyledAttributes(attrs, DefaultAttrs); if (defAttrs.Length() > 0) { var gravity = defAttrs.GetInt(0, (int)GravityFlags.NoGravity); var gravityFlag = (GravityFlags) gravity; if (gravityFlag != GravityFlags.Top && gravityFlag != GravityFlags.Bottom) throw new ArgumentException("gravity must be set to either top or bottom"); _isSlidingUp = gravityFlag == GravityFlags.Bottom; } defAttrs.Recycle(); var ta = context.ObtainStyledAttributes(attrs, Resource.Styleable.SlidingUpPanelLayout); if (ta.Length() > 0) { _panelHeight = ta.GetDimensionPixelSize(Resource.Styleable.SlidingUpPanelLayout_collapsedHeight, -1); _shadowHeight = ta.GetDimensionPixelSize(Resource.Styleable.SlidingUpPanelLayout_shadowHeight, -1); _minFlingVelocity = ta.GetInt(Resource.Styleable.SlidingUpPanelLayout_flingVelocity, DefaultMinFlingVelocity); _coveredFadeColor = ta.GetColor(Resource.Styleable.SlidingUpPanelLayout_fadeColor, DefaultFadeColor); _dragViewResId = ta.GetResourceId(Resource.Styleable.SlidingUpPanelLayout_dragView, -1); OverlayContent = ta.GetBoolean(Resource.Styleable.SlidingUpPanelLayout_overlay, DefaultOverlayFlag); } ta.Recycle(); } var density = context.Resources.DisplayMetrics.Density; if (_panelHeight == -1) _panelHeight = (int) (DefaultPanelHeight * density + 0.5f); if (_shadowHeight == -1) _shadowHeight = (int) (DefaultShadowHeight * density + 0.5f); SetWillNotDraw(false); _dragHelper = ViewDragHelper.Create(this, 0.5f, new DragHelperCallback(this)); _dragHelper.MinVelocity = _minFlingVelocity * density; _canSlide = true; SlidingEnabled = true; var vc = ViewConfiguration.Get(context); _scrollTouchSlop = vc.ScaledTouchSlop; }
public IcsLinearLayout(Context context, IAttributeSet attrs) : base(context, attrs) { var a = context.ObtainStyledAttributes(null, LinearLayoutResources, attrs.StyleAttribute, 0); SetDividerDrawable(a.GetDrawable((int)EAttributeIndex.Divider)); dividerPadding = a.GetDimensionPixelSize((int)EAttributeIndex.DividerPadding, 0); showDividers = a.GetInteger((int)EAttributeIndex.ShowDivider, (int)ShowDividers.None); a.Recycle(); }
protected virtual void initAttributes (Context context, IAttributeSet attrs) { if (attrs != null) { TypedArray a = context.ObtainStyledAttributes (attrs, Resource.Styleable.Fontable); int fontTypo = a.GetInteger (Resource.Styleable.Fontable_font, 0); setCustomFont (fontTypo); a.Recycle (); } }
public MyEditText(Context context, IAttributeSet attrs, int defStyle) : base(context, attrs, defStyle) { var a = context.ObtainStyledAttributes(attrs, Resource.Styleable.CustomFonts); var customFont = a.GetString(Resource.Styleable.CustomFonts_customFont); SetCustomFont(customFont); a.Recycle(); }
public IcsLinearLayout(Context context, int themeAttr) : base(context) { TypedArray a = context.ObtainStyledAttributes(null, LL, themeAttr, 0); setDividerDrawable(a.GetDrawable(IcsLinearLayout.LL_DIVIDER)); mDividerPadding = a.GetDimensionPixelSize(LL_DIVIDER_PADDING, 0); mShowDividers =(ShowDividers) a.GetInteger(LL_SHOW_DIVIDER, (int)ShowDividers.None); a.Recycle(); }
public MvxCircleImageView(Context context, IAttributeSet attrs, int defStyle) : base (context, attrs) { TypedArray a = context.ObtainStyledAttributes(attrs, Resource.Styleable.CircleImageView, defStyle, 0); _borderWidth = a.GetDimensionPixelSize (Resource.Styleable.CircleImageView_border_width, DEFAULT_BORDER_WIDTH); mBorderColor = a.GetColor (Resource.Styleable.CircleImageView_border_color, DEFAULT_BORDER_COLOR); a.Recycle (); Init(); }
public CirclePageIndicator (Context context, IAttributeSet attrs, int defStyle) : base(context, attrs, defStyle) { //Load defaults from resources var res = Resources; int defaultPageColor = res.GetColor (Resource.Color.default_circle_indicator_page_color); int defaultFillColor = res.GetColor (Resource.Color.default_circle_indicator_fill_color); int defaultOrientation = res.GetInteger (Resource.Integer.default_circle_indicator_orientation); int defaultStrokeColor = res.GetColor (Resource.Color.default_circle_indicator_stroke_color); float defaultStrokeWidth = res.GetDimension (Resource.Dimension.default_circle_indicator_stroke_width); float defaultRadius = res.GetDimension (Resource.Dimension.default_circle_indicator_radius); bool defaultCentered = res.GetBoolean (Resource.Boolean.default_circle_indicator_centered); bool defaultSnap = res.GetBoolean (Resource.Boolean.default_circle_indicator_snap); //Retrieve styles attributes try { var a = context.ObtainStyledAttributes (attrs, Resource.Styleable.CirclePageIndicator, defStyle, Resource.Style.Widget_CirclePageIndicator); mCentered = a.GetBoolean (Resource.Styleable.CirclePageIndicator_centered, defaultCentered); mOrientation = a.GetInt (Resource.Styleable.CirclePageIndicator_orientation, defaultOrientation); mPaintPageFill = new Paint (PaintFlags.AntiAlias); mPaintPageFill.SetStyle (Paint.Style.Fill); mPaintPageFill.Color = a.GetColor (Resource.Styleable.CirclePageIndicator_pageColor, defaultPageColor); mPaintStroke = new Paint (PaintFlags.AntiAlias); mPaintStroke.SetStyle (Paint.Style.Stroke); mPaintStroke.Color = a.GetColor (Resource.Styleable.CirclePageIndicator_strokeColor, defaultStrokeColor); mPaintStroke.StrokeWidth = a.GetDimension (Resource.Styleable.CirclePageIndicator_strokeWidth, defaultStrokeWidth); mPaintFill = new Paint (PaintFlags.AntiAlias); mPaintFill.SetStyle (Paint.Style.Fill); mPaintFill.Color = a.GetColor (Resource.Styleable.CirclePageIndicator_fillColor, defaultFillColor); mRadius = a.GetDimension (Resource.Styleable.CirclePageIndicator_radius, defaultRadius); mSnap = a.GetBoolean (Resource.Styleable.CirclePageIndicator_snap, defaultSnap); a.Recycle (); } catch { mCentered = defaultCentered; mOrientation = defaultOrientation; mPaintPageFill = new Paint (PaintFlags.AntiAlias); mPaintPageFill.SetStyle (Paint.Style.Fill); mPaintPageFill.Color = new Color(0,0,0,0); mPaintStroke = new Paint (PaintFlags.AntiAlias); mPaintStroke.SetStyle (Paint.Style.Stroke); mPaintStroke.Color = new Color(127,127,127); mPaintStroke.StrokeWidth = defaultStrokeWidth; mPaintFill = new Paint (PaintFlags.AntiAlias); mPaintFill.SetStyle (Paint.Style.Fill); mPaintFill.Color = new Color(255,173,58); mRadius = defaultRadius; mSnap = defaultSnap; } var configuration = ViewConfiguration.Get (context); mTouchSlop = Android.Support.V4.View.ViewConfigurationCompat.GetScaledPagingTouchSlop (configuration); }
private void Init(Context context, IAttributeSet attrs) { Android.Content.Res.TypedArray attributes = context.ObtainStyledAttributes(attrs, Resource.Styleable.BorderedImageView, 0, 0); var color = attributes.GetColor(Resource.Styleable.BorderedImageView_bordered_color, Color.White); mBorderPaint = new Paint(); mBorderPaint.AntiAlias = true; mBorderPaint.SetStyle(Paint.Style.Stroke); mBorderPaint.Color = color; mBorderPaint.StrokeWidth = ImageLoading.Sample.MainActivity.DimensionHelper.DpToPx(STROKE_WIDTH_DP); }
protected override void initAttributes (Context context, IAttributeSet attrs) { if (attrs != null) { TypedArray a = context.ObtainStyledAttributes (attrs, Resource.Styleable.Keymaster); var labelKey = a.GetString (Resource.Styleable.Keymaster_keyName); if (!string.IsNullOrEmpty (labelKey)) SetMatrixString (VinzClortho.Instance.Get (labelKey)); a.Recycle (); } base.initAttributes (context, attrs); }
public CircleImageView(Context context, IAttributeSet attrs, int defStyle):base(context,attrs,defStyle) { TypedArray a = context.ObtainStyledAttributes(attrs, Resource.Styleable.CircleImageView, defStyle, 0); mBorderWidth = a.GetDimensionPixelSize(Resource.Styleable.CircleImageView_civ_border_width,DEFAULT_BORDER_WIDTH); mBorderColor = a.GetColor(Resource.Styleable.CircleImageView_civ_border_overlay, DEFAULT_BORDER_COLOR);//使用这个不报错 mBorderOverlay = a.GetBoolean(Resource.Styleable.CircleImageView_civ_border_overlay, DEFAULT_BORDER_OVERLAY); mFillColor = a.GetColor(Resource.Styleable.CircleImageView_civ_border_overlay, DEFAULT_FILL_COLOR);//使用这个不报错 a.Recycle (); init (); }
public SmoothProgressBar(Context context, IAttributeSet attrs, int defStyle) : base(context, attrs, defStyle) { var res = context.Resources; var a = context.ObtainStyledAttributes(attrs, Resource.Styleable.SmoothProgressBar, defStyle, 0); var color = a.GetColor(Resource.Styleable.SmoothProgressBar_spb_color, res.GetColor(Resource.Color.spb_default_color)); var sectionsCount = a.GetInteger(Resource.Styleable.SmoothProgressBar_spb_sections_count, res.GetInteger(Resource.Integer.spb_default_sections_count)); var separatorLength = a.GetDimensionPixelSize(Resource.Styleable.SmoothProgressBar_spb_stroke_separator_length, res.GetDimensionPixelSize(Resource.Dimension.spb_default_stroke_separator_length)); var strokeWidth = a.GetDimension(Resource.Styleable.SmoothProgressBar_spb_stroke_width, res.GetDimension(Resource.Dimension.spb_default_stroke_width)); var speed = a.GetFloat(Resource.Styleable.SmoothProgressBar_spb_speed, float.Parse(res.GetString(Resource.String.spb_default_speed), CultureInfo.InvariantCulture)); var reversed = a.GetBoolean(Resource.Styleable.SmoothProgressBar_spb_reversed, res.GetBoolean(Resource.Boolean.spb_default_reversed)); var mirrorMode = a.GetBoolean(Resource.Styleable.SmoothProgressBar_spb_mirror_mode, res.GetBoolean(Resource.Boolean.spb_default_mirror_mode)); var colorsId = a.GetResourceId(Resource.Styleable.SmoothProgressBar_spb_colors, 0); var idInterpolator = a.GetResourceId(Resource.Styleable.SmoothProgressBar_android_interpolator, 0); a.Recycle(); if (idInterpolator > 0) SetInterpolator(context, idInterpolator); Color[] colors = null; if (colorsId != 0) colors = IntsToColors(res.GetIntArray(colorsId)); var builder = new SmoothProgressDrawable.Builder(context) .Speed(speed) .SectionsCount(sectionsCount) .SeparatorLength(separatorLength) .StrokeWidth(strokeWidth) .Reversed(reversed) .MirrorMode(mirrorMode); if (Interpolator != null) builder.Interpolator(Interpolator); if (colors != null && colors.Length > 0) builder.Colors(colors); else builder.Color(color); IndeterminateDrawable = builder.Build(); }
public static int[] ReadAttributeValue(Android.Content.Context context, IAttributeSet attrs, int[] groupId, int[] requiredAttributeId) { var typedArray = context.ObtainStyledAttributes(attrs, groupId); try { var attributes = Enumerable .Range(0, typedArray.IndexCount) .Select(i => (int?)typedArray.GetIndex(i)) .ToArray(); var q = from reqId in requiredAttributeId let foundAttributeId = attributes.FirstOrDefault(a => a == reqId) select foundAttributeId != null?typedArray.GetResourceId(foundAttributeId.Value, 0) : 0; return(q.ToArray()); } finally { typedArray.Recycle(); } }
public static bool ReadBooleanValue(Android.Content.Context context, IAttributeSet attrs, int[] groupId, int requiredAttributeId) { var typedArray = context.ObtainStyledAttributes(attrs, groupId); try { var numStyles = typedArray.IndexCount; for (var i = 0; i < numStyles; ++i) { var attributeId = typedArray.GetIndex(i); if (attributeId == requiredAttributeId) { return(typedArray.GetBoolean(i, false)); } } return(false); } finally { typedArray.Recycle(); } }