public void SetLabel(string iconStr, string iconFont, float iconSize, string labelStr, string labelFont, float labelSize, uint textColor, uint bgColor, EventHandler onClick) { // don't allow changing WHILE we're animating if (Animating == false) { // setup the banner BannerLayout.SetBackgroundColor(Rock.Mobile.UI.Util.GetUIColor(bgColor)); // setup the icon Icon.Text = iconStr; Icon.SetTypeface(FontManager.Instance.GetFont(iconFont), global::Android.Graphics.TypefaceStyle.Normal); Icon.SetTextSize(ComplexUnitType.Dip, iconSize); Icon.SetTextColor(Rock.Mobile.UI.Util.GetUIColor(textColor)); // setup the label Label.Text = labelStr; Label.SetTypeface(FontManager.Instance.GetFont(labelFont), global::Android.Graphics.TypefaceStyle.Normal); Label.SetTextSize(ComplexUnitType.Dip, labelSize); Label.SetTextColor(Rock.Mobile.UI.Util.GetUIColor(textColor)); if (OnClickAction != null) { OverlayButton.Click -= OnClickAction; } OverlayButton.Click += onClick; OnClickAction = onClick; // resize the button to fit over the full banner int widthMeasureSpec = View.MeasureSpec.MakeMeasureSpec(TextLayout.LayoutParameters.Width, MeasureSpecMode.Unspecified); int heightMeasureSpec = View.MeasureSpec.MakeMeasureSpec(TextLayout.LayoutParameters.Height, MeasureSpecMode.Unspecified); TextLayout.Measure(widthMeasureSpec, heightMeasureSpec); OverlayButton.LayoutParameters.Width = TextLayout.MeasuredWidth; OverlayButton.LayoutParameters.Height = TextLayout.MeasuredHeight; BannerLayout.LayoutParameters.Width = TextLayout.MeasuredWidth; BannerLayout.LayoutParameters.Height = TextLayout.MeasuredHeight; // default it to hidden and offscreen Visibility = ViewStates.Gone; SetX(ScreenWidth); } }
public override bool DispatchTouchEvent(MotionEvent e) { // get the tapped position and the bannerPos's bounding box PointF tappedPos = new PointF(e.GetX( ), e.GetY( )); RectangleF bannerBB = new RectangleF(BannerLayout.GetX( ), BannerLayout.GetY( ), BannerLayout.GetX( ) + BannerLayout.Width, BannerLayout.GetY( ) + BannerLayout.Height); // if they tapped inside the banner, send the click notification if (bannerBB.Contains(tappedPos)) { if (Visibility == ViewStates.Visible) { OnClickAction(null, null); } } // either way dismiss the banner and let the touch input continue Hide( ); return(false); }