private void Init () { SetBackgroundColor (Color.White); SetPadding (0, 0, 0, 0); // Retrieve the drawable resource assigned to the Android.Resource.Attribute.SelectableItemBackground // theme attribute from the current theme. TypedArray a = Context.ObtainStyledAttributes (new[] { Android.Resource.Attribute.SelectableItemBackground }); _foregroundDrawable = a.GetDrawable (0); _foregroundDrawable.SetCallback (this); a.Recycle (); }
private void Initialize(Context context, IAttributeSet attrs, int defStyle) { //set defaults first: var circleColor = Resources.GetColor(Resource.Color.progress_default_circle_color); var progressColor = Resources.GetColor(Resource.Color.progress_default_progress_color); var pinnedDrawable = Resource.Drawable.pin_progress_pinned; var unpinnedDrawable = Resource.Drawable.pin_progress_unpinned; var shadowDrawable = Resource.Drawable.pin_progress_shadow; var indeterminate = false; var indeterminateInterval = Resources.GetInteger(Resource.Integer.progressbutton_indeterminent_interval); var canChecked = false; var canClickable = false; var canFocusable = false; m_InnerSize = Resources.GetDimensionPixelSize(Resource.Dimension.progress_inner_size); if (context != null && attrs != null) { var a = context.ObtainStyledAttributes(attrs, Resource.Styleable.ProgressButton, Resource.Attribute.progressButtonStyle, Resource.Style.ProgressButton_Pin); m_Progress = a.GetInteger(Resource.Styleable.ProgressButton_progress, 0); m_Max = a.GetInteger(Resource.Styleable.ProgressButton_max, 100); circleColor = a.GetColor(Resource.Styleable.ProgressButton_circleColor, circleColor); progressColor = a.GetColor(Resource.Styleable.ProgressButton_progressColor, progressColor); pinnedDrawable = a.GetResourceId(Resource.Styleable.ProgressButton_pinnedDrawable, pinnedDrawable); unpinnedDrawable = a.GetResourceId(Resource.Styleable.ProgressButton_unpinnedDrawable, unpinnedDrawable); shadowDrawable = a.GetResourceId(Resource.Styleable.ProgressButton_shadowDrawable, shadowDrawable); m_InnerSize = a.GetDimensionPixelSize(Resource.Styleable.ProgressButton_innerSize, 0); if(m_InnerSize == 0) m_InnerSize = Resources.GetDimensionPixelSize(Resource.Dimension.progress_inner_size); canChecked = a.GetBoolean(Resource.Styleable.ProgressButton_pinned, canChecked); canClickable = a.GetBoolean(Resource.Styleable.ProgressButton_android_clickable, canClickable); canFocusable = a.GetBoolean(Resource.Styleable.ProgressButton_android_focusable, canFocusable); SetBackgroundDrawable(a.GetDrawable(Resource.Styleable.ProgressButton_android_selectableItemBackground)); indeterminateInterval = a.GetInteger(Resource.Styleable.ProgressButton_indeterminate_interval, indeterminateInterval); indeterminate = a.GetBoolean(Resource.Styleable.ProgressButton_indeterminate, indeterminate); a.Recycle(); } m_PinnedDrawable = Resources.GetDrawable(pinnedDrawable); m_PinnedDrawable.SetCallback(this); m_UnpinnedDrawable = Resources.GetDrawable(unpinnedDrawable); m_UnpinnedDrawable.SetCallback(this); m_ShadowDrawable = Resources.GetDrawable(shadowDrawable); m_ShadowDrawable.SetCallback(this); m_DrawableSize = m_ShadowDrawable.IntrinsicWidth; Checked = canChecked; Clickable = canClickable; Focusable = canFocusable; CirclePaint = new Paint {Color = circleColor, AntiAlias = true}; ProgressPaint = new Paint {Color = progressColor, AntiAlias = true}; m_IndeterminateInterval = indeterminateInterval; Indeterminante = indeterminate; }