public static ColorStateList ResolveActionTextColorStateList(Context context, int colorAttr, ColorStateList fallback) { TypedArray a = context.Theme.ObtainStyledAttributes(new int[] { colorAttr }); try { TypedValue value = a.PeekValue(0); if (value == null) { return(fallback); } if (value.Type >= DataType.FirstColorInt && value.Type <= DataType.LastColorInt) { return(GetActionTextStateList(context, new Color(value.Data))); } else { ColorStateList stateList = a.GetColorStateList(0); if (stateList != null) { return(stateList); } else { return(fallback); } } } finally { a.Recycle(); } }
public Marker(Context context, IAttributeSet attrs, int defStyleAttr, String maxValue, int thumbSize, int separation) : base(context, attrs, defStyleAttr) { Visibility = ViewStates.Visible; DisplayMetrics displayMetrics = context.Resources.DisplayMetrics; TypedArray a = context.ObtainStyledAttributes(attrs, Resource.Styleable.DiscreteSeekBar, Resource.Attribute.discreteSeekBarStyle, Resource.Style.Widget_DiscreteSeekBar); int padding = (int)(PADDING_DP * displayMetrics.Density) * 2; int textAppearanceId = a.GetResourceId(Resource.Styleable.DiscreteSeekBar_dsb_indicatorTextAppearance, Resource.Style.Widget_DiscreteIndicatorTextAppearance); 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.Gravity = GravityFlags.Center; mNumber.Text = maxValue; mNumber.SetMaxLines(1); mNumber.SetSingleLine(true); SeekBarCompat.SetTextDirection(mNumber, (int)TextDirectionLocale); mNumber.Visibility = ViewStates.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 = separation; ColorStateList color = a.GetColorStateList(Resource.Styleable.DiscreteSeekBar_dsb_indicatorColor); mMarkerDrawable = new MarkerDrawable(color, thumbSize); mMarkerDrawable.SetCallback(this); mMarkerDrawable.SetMarkerListener(this); mMarkerDrawable.SetExternalOffset(padding); //Elevation for anroid 5+ float elevation = a.GetDimension(Resource.Styleable.DiscreteSeekBar_dsb_indicatorElevation, ELEVATION_DP * displayMetrics.Density); ViewCompat.SetElevation(this, elevation); if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop) { SeekBarCompat.SetOutlineProvider(this, mMarkerDrawable); } a.Recycle(); }
private void InitalizeAttributes(IAttributeSet attrs, int defStyle) { TypedArray a = Context.ObtainStyledAttributes(attrs, Resource.Styleable.PullToRefresharpWrapper, defStyle, 0); header_res_id = a.GetResourceId(Resource.Styleable.PullToRefresharpWrapper_headerId, 0); content_view_res_id = a.GetResourceId(Resource.Styleable.PullToRefresharpWrapper_contentViewId, 0); pulldown_progress_indicator_res_id = a.GetResourceId(Resource.Styleable.PullToRefresharpWrapper_pullDownProgressIndicatorId, 0); pull_to_refresh_string_id = a.GetResourceId(Resource.Styleable.PullToRefresharpWrapper_pullToRefreshText, Resource.String.ptrsharp_pull_to_refresh); release_to_refresh_string_id = a.GetResourceId(Resource.Styleable.PullToRefresharpWrapper_releaseToRefreshText, Resource.String.ptrsharp_release_to_refresh); refreshing_string_id = a.GetResourceId(Resource.Styleable.PullToRefresharpWrapper_refreshingText, Resource.String.ptrsharp_refreshing); header_background_res_id = a.GetResourceId(Resource.Styleable.PullToRefresharpWrapper_ptrHeaderBackground, 0); header_text_color = a.GetColorStateList(Resource.Styleable.PullToRefresharpWrapper_headerTextColor); pulldown_icon_drawable_res_id = a.GetResourceId(Resource.Styleable.PullToRefresharpWrapper_headerIconDrawable, 0); pulldown_tension_factor = a.GetFloat(Resource.Styleable.PullToRefresharpWrapper_pullDownTension, 0.5f); SnapbackDuration = a.GetInt(Resource.Styleable.PullToRefresharpWrapper_snapbackDuration, 400); IsPullEnabled = a.GetBoolean(Resource.Styleable.PullToRefresharpWrapper_pullEnabled, true); fastscroll_thumb_width = a.GetDimensionPixelSize(Resource.Styleable.PullToRefresharpWrapper_fastScrollThumbWidth, -1); if (fastscroll_thumb_width < 0) { fastscroll_thumb_width = Resources.GetDimensionPixelSize(Resource.Dimension.fastscroll_thumb_width); } // Enforce the constraint that both or none of the attributes headerId and viewId are set if (header_res_id > 0 && content_view_res_id == 0 || content_view_res_id > 0 && header_res_id == 0) { throw new ArgumentException("Both headerId and contentViewId must be either set or not set, setting just one is not supported"); } a.Recycle(); }
public void ApplyStylableAttributes(Context context, TypedArray a, int[] styleableRes) { if (styleableRes == Resource.Styleable.CircularEventGauge) { // Background Gauge Attributes bool ringColorsSet = false; Color startColor = Color.DarkGray; Color endColor = Color.White; if (a.HasValue(Resource.Styleable.CircularEventGauge_ringStartColor)) { startColor = a.GetColor(Resource.Styleable.CircularEventGauge_ringStartColor, Color.DarkGray); ringColorsSet = true; } if (a.HasValue(Resource.Styleable.CircularEventGauge_ringEndColor)) { endColor = a.GetColor(Resource.Styleable.CircularEventGauge_ringEndColor, Color.White); ringColorsSet = true; } if (ringColorsSet) { RingColors = new ShadingColorPair(startColor, endColor); } if (a.HasValue(Resource.Styleable.CircularEventGauge_centerTint)) { var csl = a.GetColorStateList(Resource.Styleable.CircularEventGauge_centerTint); if (csl != null) { CenterTint = csl; } } if (a.HasValue(Resource.Styleable.CircularEventGauge_centerSrc)) { CenterDrawable = a.GetDrawable(Resource.Styleable.CircularEventGauge_centerSrc); } if (a.HasValue(Resource.Styleable.CircularEventGauge_ringGap)) { RingGapPx = a.GetDimensionPixelSize(Resource.Styleable.CircularEventGauge_ringGap, RingThicknessPx); } // Count Atttributes bool fontPropertiesSet = false; Typeface typeface = null; string familyName = null; string styleName = null; if (a.HasValue(Resource.Styleable.CircularEventGauge_countTypeface)) { typeface = (Typeface)a.GetInt(Resource.Styleable.CircularEventGauge_countTypeface, 0); fontPropertiesSet = true; } if (a.HasValue(Resource.Styleable.CircularEventGauge_countTextStyle)) { styleName = a.GetString(Resource.Styleable.CircularEventGauge_countTextStyle); fontPropertiesSet = true; } if (a.HasValue(Resource.Styleable.CircularEventGauge_countFontFamily)) { Typeface tf = null; // Try to resolve as a font resource try { var resId = a.GetResourceId(Resource.Styleable.CircularEventGauge_countFontFamily, 0); tf = ResourcesCompat.GetFont(Context, resId); } catch (Exception ex) { } if (tf == null) { // Try to resolve as a font asset or system font familyName = a.GetString(Resource.Styleable.CircularEventGauge_countFontFamily); } else { typeface = tf; } fontPropertiesSet = true; } if (fontPropertiesSet) { var typefaceAndStyle = GetTypefaceFromAttrs(typeface, familyName, styleName); if (typefaceAndStyle?.Item1 != null && typefaceAndStyle?.Item1 == null) { CountTypeface = typefaceAndStyle.Item1; } else if (typefaceAndStyle?.Item1 != null && typefaceAndStyle?.Item1 != null) { SetCountTypeface(typefaceAndStyle.Item1, (TypefaceStyle)typefaceAndStyle.Item2); } } if (a.HasValue(Resource.Styleable.CircularEventGauge_countColor)) { var csl = a.GetColorStateList(Resource.Styleable.CircularEventGauge_countColor); if (csl != null) { CountColors = csl; } } if (a.HasValue(Resource.Styleable.CircularEventGauge_countAutosize)) { CountAutoSize = a.GetBoolean(Resource.Styleable.CircularEventGauge_countAutosize, true); } if (a.HasValue(Resource.Styleable.CircularEventGauge_countTextSize)) { CountTextSizePx = a.GetDimensionPixelSize(Resource.Styleable.CircularEventGauge_countTextSize, PixelSizeConverter.SpToPx(20)); } if (a.HasValue(Resource.Styleable.CircularEventGauge_countAllCaps)) { CountAllCaps = a.GetBoolean(Resource.Styleable.CircularEventGauge_countAllCaps, true); } if (a.HasValue(Resource.Styleable.CircularEventGauge_countText)) { CountText = a.GetString(Resource.Styleable.CircularEventGauge_countText); } // Label Atttributes fontPropertiesSet = false; typeface = null; familyName = null; styleName = null; if (a.HasValue(Resource.Styleable.CircularEventGauge_labelTypeface)) { typeface = (Typeface)a.GetInt(Resource.Styleable.CircularEventGauge_labelTypeface, 0); fontPropertiesSet = true; } if (a.HasValue(Resource.Styleable.CircularEventGauge_labelTextStyle)) { styleName = a.GetString(Resource.Styleable.CircularEventGauge_labelTextStyle); fontPropertiesSet = true; } if (a.HasValue(Resource.Styleable.CircularEventGauge_labelFontFamily)) { Typeface tf = null; // Try to resolve as a font resource try { var resId = a.GetResourceId(Resource.Styleable.CircularEventGauge_labelFontFamily, 0); tf = ResourcesCompat.GetFont(Context, resId); } catch (Exception ex) { } if (tf == null) { // Try to resolve as a font asset or system font familyName = a.GetString(Resource.Styleable.CircularEventGauge_labelFontFamily); } else { typeface = tf; } fontPropertiesSet = true; } if (fontPropertiesSet) { var typefaceAndStyle = GetTypefaceFromAttrs(typeface, familyName, styleName); if (typefaceAndStyle?.Item1 != null && typefaceAndStyle?.Item1 == null) { LabelTypeface = typefaceAndStyle.Item1; } else if (typefaceAndStyle?.Item1 != null && typefaceAndStyle?.Item1 != null) { SetLabelTypeface(typefaceAndStyle.Item1, (TypefaceStyle)typefaceAndStyle.Item2); } } if (a.HasValue(Resource.Styleable.CircularEventGauge_labelColor)) { var csl = a.GetColorStateList(Resource.Styleable.CircularEventGauge_labelColor); if (csl != null) { LabelColors = csl; } } if (a.HasValue(Resource.Styleable.CircularEventGauge_labelTextSize)) { LabelTextSizePx = a.GetDimensionPixelSize(Resource.Styleable.CircularEventGauge_labelTextSize, PixelSizeConverter.SpToPx(10)); } if (a.HasValue(Resource.Styleable.CircularEventGauge_labelAllCaps)) { LabelAllCaps = a.GetBoolean(Resource.Styleable.CircularEventGauge_labelAllCaps, true); } if (a.HasValue(Resource.Styleable.CircularEventGauge_labelText)) { LabelText = a.GetString(Resource.Styleable.CircularEventGauge_labelText); } // Icon attributes if (a.HasValue(Resource.Styleable.CircularEventGauge_iconSrc)) { IconDrawable = a.GetDrawable(Resource.Styleable.CircularEventGauge_iconSrc); } if (a.HasValue(Resource.Styleable.CircularEventGauge_iconSize)) { IconSizePx = a.GetDimensionPixelSize(Resource.Styleable.CircularEventGauge_iconSize, PixelSizeConverter.SpToPx(18)); } if (a.HasValue(Resource.Styleable.CircularEventGauge_iconTint)) { var csl = a.GetColorStateList(Resource.Styleable.CircularEventGauge_iconTint); if (csl != null) { IconTint = csl; } } if (a.HasValue(Resource.Styleable.CircularEventGauge_iconTintMode)) { var mode = a.GetInt(Resource.Styleable.CircularEventGauge_iconTintMode, -1); if (mode != -1) { IconTintMode = (PorterDuff.Mode)mode; } } // Other Attributes if (a.HasValue(Resource.Styleable.CircularEventGauge_count)) { var count = a.GetInt(Resource.Styleable.CircularEventGauge_count, -1); if (count > -1) { EventCount = count; } } if (a.HasValue(Resource.Styleable.CircularEventGauge_active)) { Active = a.GetBoolean(Resource.Styleable.CircularEventGauge_active, true); } CreateGuage(); } }
public DiscreteSeekBar(Context context, IAttributeSet attrs, int defStyleAttr) : base(context, attrs, defStyleAttr) { mShowIndicatorRunnable = new Runnable(Run); mFloaterListener = this; Focusable = true; SetWillNotDraw(false); mTouchSlop = ViewConfiguration.Get(context).ScaledWindowTouchSlop; float density = context.Resources.DisplayMetrics.Density; TypedArray a = context.ObtainStyledAttributes(attrs, Resource.Styleable.DiscreteSeekBar, defStyleAttr, Resource.Style.Widget_DiscreteSeekBar); int max = 100; int min = 0; int value = 0; mMirrorForRtl = a.GetBoolean(Resource.Styleable.DiscreteSeekBar_dsb_mirrorForRtl, mMirrorForRtl); mAllowTrackClick = a.GetBoolean(Resource.Styleable.DiscreteSeekBar_dsb_allowTrackClickToDrag, mAllowTrackClick); mIndicatorPopupEnabled = a.GetBoolean(Resource.Styleable.DiscreteSeekBar_dsb_indicatorPopupEnabled, mIndicatorPopupEnabled); mTrackHeight = a.GetDimensionPixelSize(Resource.Styleable.DiscreteSeekBar_dsb_trackHeight, (int)(1 * density)); mScrubberHeight = a.GetDimensionPixelSize(Resource.Styleable.DiscreteSeekBar_dsb_scrubberHeight, (int)(4 * density)); int thumbSize = a.GetDimensionPixelSize(Resource.Styleable.DiscreteSeekBar_dsb_thumbSize, (int)(density * ThumbDrawable.DEFAULT_SIZE_DP)); int separation = a.GetDimensionPixelSize(Resource.Styleable.DiscreteSeekBar_dsb_indicatorSeparation, (int)(SEPARATION_DP * density)); //Extra pixels for a minimum touch area of 32dp int touchBounds = (int)(density * 32); mAddedTouchBounds = System.Math.Max(0, (touchBounds - thumbSize) / 2); int indexMax = Resource.Styleable.DiscreteSeekBar_dsb_max; int indexMin = Resource.Styleable.DiscreteSeekBar_dsb_min; int indexValue = Resource.Styleable.DiscreteSeekBar_dsb_value; TypedValue @out = new TypedValue(); //Not sure why, but we wanted to be able to use dimensions here... if (a.GetValue(indexMax, @out)) { if (@out.Type == DataType.Dimension) { max = a.GetDimensionPixelSize(indexMax, max); } else { max = a.GetInteger(indexMax, max); } } if (a.GetValue(indexMin, @out)) { if (@out.Type == DataType.Dimension) { min = a.GetDimensionPixelSize(indexMin, min); } else { min = a.GetInteger(indexMin, min); } } if (a.GetValue(indexValue, @out)) { if (@out.Type == DataType.Dimension) { value = a.GetDimensionPixelSize(indexValue, value); } else { value = a.GetInteger(indexValue, value); } } mMin = min; mMax = Math.Max(min + 1, max); mValue = Math.Max(min, Math.Min(max, value)); UpdateKeyboardRange(); mIndicatorFormatter = a.GetString(Resource.Styleable.DiscreteSeekBar_dsb_indicatorFormatter); ColorStateList trackColor = a.GetColorStateList(Resource.Styleable.DiscreteSeekBar_dsb_trackColor); ColorStateList progressColor = a.GetColorStateList(Resource.Styleable.DiscreteSeekBar_dsb_progressColor); ColorStateList rippleColor = a.GetColorStateList(Resource.Styleable.DiscreteSeekBar_dsb_rippleColor); bool editMode = IsInEditMode; if (editMode || rippleColor == null) { rippleColor = new ColorStateList(new int[][] { new int[] { } }, new int[] { Color.DarkGray }); } if (editMode || trackColor == null) { trackColor = new ColorStateList(new int[][] { new int[] { } }, new int[] { Color.Gray }); } if (editMode || progressColor == null) { progressColor = new ColorStateList(new int[][] { new int[] { } }, new int[] { DEFAULT_THUMB_COLOR }); } mRipple = SeekBarCompat.GetRipple(rippleColor); if (isLollipopOrGreater) { SeekBarCompat.SetBackground(this, mRipple); } else { mRipple.SetCallback(this); } TrackRectDrawable shapeDrawable = new TrackRectDrawable(trackColor); mTrack = shapeDrawable; mTrack.SetCallback(this); shapeDrawable = new TrackRectDrawable(progressColor); mScrubber = shapeDrawable; mScrubber.SetCallback(this); mThumb = new ThumbDrawable(progressColor, thumbSize); mThumb.SetCallback(this); mThumb.SetBounds(0, 0, mThumb.IntrinsicWidth, mThumb.IntrinsicHeight); if (!editMode) { mIndicator = new PopupIndicator(context, attrs, defStyleAttr, ConvertValueToMessage(mMax), thumbSize, thumbSize + mAddedTouchBounds + separation); mIndicator.SetListener(mFloaterListener); } a.Recycle(); SetNumericTransformer(new DefaultNumericTransformer()); }
public LoadingLayout(Context context, Mode mode, PtrOrientation scrollDirection, TypedArray attrs) : base(context) { //base(context); mMode = mode; mScrollDirection = scrollDirection; switch (scrollDirection) { case PtrOrientation.HORIZONTAL: LayoutInflater.From(context).Inflate(Resource.Layout.pull_to_refresh_header_horizontal, this); break; case PtrOrientation.VERTICAL: default: LayoutInflater.From(context).Inflate(Resource.Layout.pull_to_refresh_header_vertical, this); break; } mInnerLayout = (FrameLayout)FindViewById(Resource.Id.fl_inner); mHeaderText = (TextView)mInnerLayout.FindViewById(Resource.Id.pull_to_refresh_text); mHeaderProgress = (ProgressBar)mInnerLayout.FindViewById(Resource.Id.pull_to_refresh_progress); mSubHeaderText = (TextView)mInnerLayout.FindViewById(Resource.Id.pull_to_refresh_sub_text); mHeaderImage = (ImageView)mInnerLayout.FindViewById(Resource.Id.pull_to_refresh_image); FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams)mInnerLayout.LayoutParameters; switch (mode) { case Mode.PULL_FROM_END: lp.Gravity = scrollDirection == PtrOrientation.VERTICAL ? GravityFlags.Top : GravityFlags.Left; // Load in labels mPullLabel = context.GetString(Resource.String.pull_to_refresh_from_bottom_pull_label); mRefreshingLabel = context.GetString(Resource.String.pull_to_refresh_from_bottom_refreshing_label); mReleaseLabel = context.GetString(Resource.String.pull_to_refresh_from_bottom_release_label); break; case Mode.PULL_FROM_START: default: lp.Gravity = scrollDirection == PtrOrientation.VERTICAL ? GravityFlags.Bottom : GravityFlags.Right; // Load in labels mPullLabel = context.GetString(Resource.String.pull_to_refresh_pull_label); mRefreshingLabel = context.GetString(Resource.String.pull_to_refresh_refreshing_label); mReleaseLabel = context.GetString(Resource.String.pull_to_refresh_release_label); break; } if (attrs.HasValue(Resource.Styleable.PullToRefresh_ptrHeaderBackground)) { Drawable background = attrs.GetDrawable(Resource.Styleable.PullToRefresh_ptrHeaderBackground); if (null != background) { ViewCompat.setBackground(this, background); } } if (attrs.HasValue(Resource.Styleable.PullToRefresh_ptrHeaderTextAppearance)) { TypedValue styleID = new TypedValue(); attrs.GetValue(Resource.Styleable.PullToRefresh_ptrHeaderTextAppearance, styleID); setTextAppearance(styleID.Data); } if (attrs.HasValue(Resource.Styleable.PullToRefresh_ptrSubHeaderTextAppearance)) { TypedValue styleID = new TypedValue(); attrs.GetValue(Resource.Styleable.PullToRefresh_ptrSubHeaderTextAppearance, styleID); setSubTextAppearance(styleID.Data); } // Text Color attrs need to be set after TextAppearance attrs if (attrs.HasValue(Resource.Styleable.PullToRefresh_ptrHeaderTextColor)) { ColorStateList colors = attrs.GetColorStateList(Resource.Styleable.PullToRefresh_ptrHeaderTextColor); if (null != colors) { setTextColor(colors); } } if (attrs.HasValue(Resource.Styleable.PullToRefresh_ptrHeaderSubTextColor)) { ColorStateList colors = attrs.GetColorStateList(Resource.Styleable.PullToRefresh_ptrHeaderSubTextColor); if (null != colors) { setSubTextColor(colors); } } // Try and get defined drawable from Attrs Drawable imageDrawable = null; if (attrs.HasValue(Resource.Styleable.PullToRefresh_ptrDrawable)) { imageDrawable = attrs.GetDrawable(Resource.Styleable.PullToRefresh_ptrDrawable); } // Check Specific Drawable from Attrs, these overrite the generic // drawable attr above switch (mode) { case Mode.PULL_FROM_START: default: if (attrs.HasValue(Resource.Styleable.PullToRefresh_ptrDrawableStart)) { imageDrawable = attrs.GetDrawable(Resource.Styleable.PullToRefresh_ptrDrawableStart); } else if (attrs.HasValue(Resource.Styleable.PullToRefresh_ptrDrawableTop)) { Utils.warnDeprecation("ptrDrawableTop", "ptrDrawableStart"); imageDrawable = attrs.GetDrawable(Resource.Styleable.PullToRefresh_ptrDrawableTop); } break; case Mode.PULL_FROM_END: if (attrs.HasValue(Resource.Styleable.PullToRefresh_ptrDrawableEnd)) { imageDrawable = attrs.GetDrawable(Resource.Styleable.PullToRefresh_ptrDrawableEnd); } else if (attrs.HasValue(Resource.Styleable.PullToRefresh_ptrDrawableBottom)) { Utils.warnDeprecation("ptrDrawableBottom", "ptrDrawableEnd"); imageDrawable = attrs.GetDrawable(Resource.Styleable.PullToRefresh_ptrDrawableBottom); } break; } // If we don't have a user defined drawable, load the default if (null == imageDrawable) { imageDrawable = context.Resources.GetDrawable(getDefaultDrawableResId()); } // Set Drawable, and save width/height setLoadingDrawable(imageDrawable); reset(); }
public ColorStateList GetColorStateList(int index) { return(_array.GetColorStateList(index)); }
//JAVA TO C# CONVERTER WARNING: 'final' parameters are not available in .NET: //ORIGINAL LINE: public LoadingLayout(android.content.Context context, final PullToRefresh.PullMode mode, final PullToRefresh.ScrollOrientation scrollDirection, android.content.res.TypedArray attrs) public LoadingLayout(Context context, PullMode mode, ScrollOrientation scrollDirection, TypedArray attrs) : base(context) { mMode = mode; mScrollDirection = scrollDirection; switch (scrollDirection) { case ScrollOrientation.HORIZONTAL: LayoutInflater.From(context).Inflate(Resource.Layout.pull_to_refresh_header_horizontal, this); break; case ScrollOrientation.VERTICAL: default: LayoutInflater.From(context).Inflate(Resource.Layout.pull_to_refresh_header_vertical, this); break; } mInnerLayout = (FrameLayout)FindViewById(Resource.Id.fl_inner); mHeaderText = (TextView)mInnerLayout.FindViewById(Resource.Id.pull_to_refresh_text); mHeaderProgress = (ProgressBar)mInnerLayout.FindViewById(Resource.Id.pull_to_refresh_progress); mSubHeaderText = (TextView)mInnerLayout.FindViewById(Resource.Id.pull_to_refresh_sub_text); mHeaderImage = (ImageView)mInnerLayout.FindViewById(Resource.Id.pull_to_refresh_image); LayoutParams lp = (LayoutParams)mInnerLayout.LayoutParameters; switch (mode) { case PullMode.PULL_FROM_END: lp.Gravity = scrollDirection == ScrollOrientation.VERTICAL ? GravityFlags.Top : GravityFlags.Left; // Load in labels mPullLabel = context.GetString(Resource.String.pull_to_refresh_pull_label); mRefreshingLabel = context.GetString(Resource.String.pull_to_refresh_refreshing_label); mReleaseLabel = context.GetString(Resource.String.pull_to_refresh_release_label); break; case PullMode.PULL_FROM_START: default: lp.Gravity = scrollDirection == ScrollOrientation.VERTICAL ? GravityFlags.Bottom : GravityFlags.Right; // Load in labels mPullLabel = context.GetString(Resource.String.pull_to_refresh_pull_label); mRefreshingLabel = context.GetString(Resource.String.pull_to_refresh_refreshing_label); mReleaseLabel = context.GetString(Resource.String.pull_to_refresh_release_label); break; } if (attrs.HasValue(Resource.Styleable.PullToRefresh_ptrHeaderBackground)) { Drawable background = attrs.GetDrawable(Resource.Styleable.PullToRefresh_ptrHeaderBackground); if (null != background) { ViewCompat.setBackground(this, background); } } if (attrs.HasValue(Resource.Styleable.PullToRefresh_ptrHeaderTextAppearance)) { TypedValue styleID = new TypedValue(); attrs.GetValue(Resource.Styleable.PullToRefresh_ptrHeaderTextAppearance, styleID); TextAppearance = styleID.Data; } if (attrs.HasValue(Resource.Styleable.PullToRefresh_ptrSubHeaderTextAppearance)) { TypedValue styleID = new TypedValue(); attrs.GetValue(Resource.Styleable.PullToRefresh_ptrSubHeaderTextAppearance, styleID); SubTextAppearance = styleID.Data; } // Text Color attrs need to be set after TextAppearance attrs if (attrs.HasValue(Resource.Styleable.PullToRefresh_ptrHeaderTextColor)) { ColorStateList colors = attrs.GetColorStateList(Resource.Styleable.PullToRefresh_ptrHeaderTextColor); if (null != colors) { TextColor = colors; } } if (attrs.HasValue(Resource.Styleable.PullToRefresh_ptrHeaderSubTextColor)) { ColorStateList colors = attrs.GetColorStateList(Resource.Styleable.PullToRefresh_ptrHeaderSubTextColor); if (null != colors) { SubTextColor = colors; } } // Try and get defined drawable from Attrs Drawable imageDrawable = null; if (attrs.HasValue(Resource.Styleable.PullToRefresh_ptrDrawable)) { imageDrawable = attrs.GetDrawable(Resource.Styleable.PullToRefresh_ptrDrawable); } // Check Specific Drawable from Attrs, these overrite the generic // drawable attr above switch (mode) { case PullMode.PULL_FROM_START: default: if (attrs.HasValue(Resource.Styleable.PullToRefresh_ptrDrawableStart)) { imageDrawable = attrs.GetDrawable(Resource.Styleable.PullToRefresh_ptrDrawableStart); } else if (attrs.HasValue(Resource.Styleable.PullToRefresh_ptrDrawableTop)) { Utils.warnDeprecation("ptrDrawableTop", "ptrDrawableStart"); imageDrawable = attrs.GetDrawable(Resource.Styleable.PullToRefresh_ptrDrawableTop); } break; case PullMode.PULL_FROM_END: if (attrs.HasValue(Resource.Styleable.PullToRefresh_ptrDrawableEnd)) { imageDrawable = attrs.GetDrawable(Resource.Styleable.PullToRefresh_ptrDrawableEnd); } else if (attrs.HasValue(Resource.Styleable.PullToRefresh_ptrDrawableBottom)) { Utils.warnDeprecation("ptrDrawableBottom", "ptrDrawableEnd"); imageDrawable = attrs.GetDrawable(Resource.Styleable.PullToRefresh_ptrDrawableBottom); } break; } // If we don't have a user defined drawable, load the default if (null == imageDrawable) { imageDrawable = context.Resources.GetDrawable(DefaultDrawableResId); } // Set Drawable, and save width/height LoadingDrawable = imageDrawable; reset(); }
protected void Initialize(Context context) { _context = context; //Used to load and scale resource items _resources = context.Resources; //Definition of this drawables size _textBounds = new Rect(); //Paint to use for the text _textPaint = new TextPaint(PaintFlags.AntiAlias); _textPaint.Density = _resources.DisplayMetrics.Density; _textPaint.Dither = true; int textSize = 15; ColorStateList textColor = null; TypefaceStyle styleIndex = TypefaceStyle.Normal; int typefaceIndex = -1; //Set default parameters from the current theme TypedArray a = context.Theme.ObtainStyledAttributes(_themeAttributes); int appearanceId = a.GetResourceId(0, -1); a.Recycle(); TypedArray ap = null; if (appearanceId != -1) { ap = context.ObtainStyledAttributes(appearanceId, _appearanceAttributes); } if (ap != null) { for (int i = 0; i < ap.IndexCount; i++) { int attr = ap.GetIndex(i); switch (attr) { case 0: //Text Size textSize = a.GetDimensionPixelSize(attr, textSize); break; case 1: //Typeface typefaceIndex = a.GetInt(attr, typefaceIndex); break; case 2: //Text Style styleIndex = (TypefaceStyle)a.GetInt(attr, (int)styleIndex); break; case 3: //Text Color textColor = a.GetColorStateList(attr); break; default: break; } } ap.Recycle(); } this.SetTextColor(textColor != null ? textColor : ColorStateList.ValueOf(Color.Black)); this.SetRawTextSize(textSize); Typeface tf = null; switch (typefaceIndex) { case SANS: tf = Typeface.SansSerif; break; case SERIF: tf = Typeface.Serif; break; case MONOSPACE: tf = Typeface.Monospace; break; } this.SetTypeface(tf, styleIndex); }