private Drawable CreateUserIconDrawable() { int dp16 = PixelSizeConverter.DpToPx(16); int dp12 = PixelSizeConverter.DpToPx(12); int dp4 = PixelSizeConverter.DpToPx(4); var fillColor = new Color(ResourcesCompat.GetColor(_layout.Resources, Resource.Color.user_location, null)); var ringColor = new Color(ResourcesCompat.GetColor(_layout.Resources, Resource.Color.user_location_stroke, null)); var pointColor = new Color(ResourcesCompat.GetColor(_layout.Resources, Resource.Color.user_location_center, null)); LayerDrawable drw = new LayerDrawable(new Drawable[] { CircleDrawable(ringColor, dp16), CircleDrawable(fillColor, dp12), CircleDrawable(pointColor, dp4) }); drw.SetLayerSize(0, dp16, dp16); drw.SetLayerSize(1, dp12, dp12); drw.SetLayerSize(2, dp4, dp4); drw.SetLayerGravity(0, GravityFlags.Center); drw.SetLayerGravity(1, GravityFlags.Center); drw.SetLayerGravity(2, GravityFlags.Center); return(drw); }
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 static void SendLocalNotification(Context ctx, string notificationChannelId, string title, int smallIconResId, Color smallIconColor, string notificationCatagory, int notificationVisibility, int notificationId = 0, string notificationTag = "Edison", PendingIntent pendingIntent = null, bool autoCancel = true, string summaryContent = null, int contentIconResId = 0, int color = -1, NotificationCompat.Style style = null, string groupKey = null) { var notificationManager = NotificationManager.FromContext(ctx); var channel = notificationManager.GetNotificationChannel(notificationChannelId); if (channel == null) { return; } //Map channel importance (Android 8+) to notification importance (android 7) int priority = NotificationCompat.PriorityDefault; switch (channel.Importance) { case NotificationImportance.Max: priority = NotificationCompat.PriorityMax; break; case NotificationImportance.High: priority = NotificationCompat.PriorityHigh; break; case NotificationImportance.Low: priority = NotificationCompat.PriorityLow; break; case NotificationImportance.Min: priority = NotificationCompat.PriorityMin; break; default: priority = NotificationCompat.PriorityDefault; break; } // ensure visibility is valid if (notificationVisibility > NotificationCompat.VisibilityPublic || notificationVisibility < NotificationCompat.VisibilitySecret) { notificationVisibility = NotificationCompat.VisibilityPrivate; } var notificationBuilder = new NotificationCompat.Builder(ctx, notificationChannelId) .SetContentTitle(title) .SetSmallIcon(smallIconResId) .SetColor(smallIconColor) .SetPriority(priority) .SetCategory(notificationCatagory) .SetVisibility(notificationVisibility) .SetAutoCancel(autoCancel); if (!string.IsNullOrWhiteSpace(summaryContent)) { notificationBuilder.SetContentText(summaryContent); } if (pendingIntent != null) { notificationBuilder.SetContentIntent(pendingIntent); } Bitmap icon = null; if (contentIconResId != 0) { if (color != -1) { Color col = new Color(color); if (contentIconResId != 0) { // build circular icon Drawable iconDrawable = Drawables.CircularIcon(ctx, contentIconResId, Color.White, col, PixelSizeConverter.DpToPx(15), PixelSizeConverter.DpToPx(140)); // try to get bitmap icon = iconDrawable.ToBitmap(); } } else { // try to get bitmap icon = BitmapFactory.DecodeResource(ctx.Resources, contentIconResId); } if (icon != null) { notificationBuilder.SetLargeIcon(icon); } } if (style != null) { notificationBuilder.SetStyle(style); } if (Build.VERSION.SdkInt >= BuildVersionCodes.N && !string.IsNullOrWhiteSpace(groupKey)) { notificationBuilder.SetGroup(groupKey); } notificationManager.Notify(notificationTag, notificationId, notificationBuilder.Build()); icon?.Dispose(); }
public static void SendLocalEdisonNotification(Context ctx, string notificationChannelId, string title, int smallIconResId, Color smallIconColor, string notificationCatagory, int notificationVisibility, int notificationId, string notificationTag, PendingIntent pendingIntent, bool autoCancel, string summaryTitle, string messageText, int contentIconResId, Color contentIconBackgroundColor, int collapsedLayoutResId, int expandedLayoutResId, int headsupLayoutResId, int largeIconResId, int titleResId, int responseTitleResId, int messageTextResId, int emergencyButtonResId, int activityButtonResId, int safeButtonResId, PendingIntent emergencyIntent, PendingIntent activityIntent, PendingIntent safeIntent, string groupKey = null) { var notificationManager = NotificationManager.FromContext(ctx); var channel = notificationManager.GetNotificationChannel(notificationChannelId); if (channel == null) { return; } //Map channel importance (Android 8+) to notification importance (android 7) int priority = MapToPriority(channel.Importance); // ensure visibility is valid if (notificationVisibility > NotificationCompat.VisibilityPublic || notificationVisibility < NotificationCompat.VisibilitySecret) { notificationVisibility = NotificationCompat.VisibilityPrivate; } var notificationBuilder = new NotificationCompat.Builder(ctx, notificationChannelId) .SetContentTitle(title) .SetSmallIcon(smallIconResId) .SetColor(smallIconColor) .SetPriority(priority) .SetCategory(notificationCatagory) .SetVisibility(notificationVisibility) .SetAutoCancel(autoCancel); SpannableStringBuilder sb = null; if (!string.IsNullOrWhiteSpace(summaryTitle)) { sb = new SpannableStringBuilder(summaryTitle); sb.SetSpan(new StyleSpan(TypefaceStyle.Bold), 0, summaryTitle.Length, SpanTypes.ExclusiveExclusive); notificationBuilder.SetContentText(sb); if (!string.IsNullOrWhiteSpace(messageText)) { sb = new SpannableStringBuilder(summaryTitle); sb.Append("\n"); sb.Append(messageText); sb.SetSpan(new StyleSpan(TypefaceStyle.Bold), 0, summaryTitle.Length, SpanTypes.ExclusiveExclusive); notificationBuilder.SetStyle(new NotificationCompat.BigTextStyle().BigText(sb)); } } else { if (!string.IsNullOrWhiteSpace(messageText)) { notificationBuilder.SetContentText(messageText); if (!string.IsNullOrWhiteSpace(messageText)) { notificationBuilder.SetStyle(new NotificationCompat.BigTextStyle().BigText(messageText)); } } } if (pendingIntent != null) { notificationBuilder.SetContentIntent(pendingIntent); } Bitmap icon = null; if (contentIconResId != 0) { // build circular icon Drawable iconDrawable = Drawables.CircularIcon(ctx, contentIconResId, Color.White, contentIconBackgroundColor, PixelSizeConverter.DpToPx(15), PixelSizeConverter.DpToPx(140)); // try to get bitmap icon = iconDrawable.ToBitmap(); // Don't set the large icon otherwise it takes up the right hand side of the entire notification. Instead will set in the custom view // if (icon != null) // notificationBuilder.SetLargeIcon(icon); } if (Build.VERSION.SdkInt >= BuildVersionCodes.N && !string.IsNullOrWhiteSpace(groupKey)) { notificationBuilder.SetGroup(groupKey); } notificationBuilder.SetStyle(new NotificationCompat.DecoratedCustomViewStyle()); RemoteViews collapsedContent = new RemoteViews(ctx.PackageName, collapsedLayoutResId); if (!string.IsNullOrWhiteSpace(title)) { var titleText = title; if (!string.IsNullOrWhiteSpace(summaryTitle)) { titleText = titleText + ": " + summaryTitle; } collapsedContent.SetTextViewText(titleResId, titleText); } else if (!string.IsNullOrWhiteSpace(summaryTitle)) { collapsedContent.SetTextViewText(titleResId, summaryTitle); } if (icon != null) { collapsedContent.SetImageViewBitmap(largeIconResId, icon); } collapsedContent.SetOnClickPendingIntent(emergencyButtonResId, emergencyIntent); collapsedContent.SetOnClickPendingIntent(activityButtonResId, activityIntent); collapsedContent.SetOnClickPendingIntent(safeButtonResId, safeIntent); notificationBuilder.SetCustomContentView(collapsedContent); RemoteViews headsupContent = new RemoteViews(ctx.PackageName, headsupLayoutResId); if (!string.IsNullOrWhiteSpace(title)) { var titleText = title; if (!string.IsNullOrWhiteSpace(summaryTitle)) { titleText = titleText + ": " + summaryTitle; } headsupContent.SetTextViewText(titleResId, titleText); } else if (!string.IsNullOrWhiteSpace(summaryTitle)) { headsupContent.SetTextViewText(titleResId, summaryTitle); } if (icon != null) { headsupContent.SetImageViewBitmap(largeIconResId, icon); } headsupContent.SetOnClickPendingIntent(emergencyButtonResId, emergencyIntent); headsupContent.SetOnClickPendingIntent(activityButtonResId, activityIntent); headsupContent.SetOnClickPendingIntent(safeButtonResId, safeIntent); notificationBuilder.SetCustomHeadsUpContentView(headsupContent); RemoteViews expandedContent = new RemoteViews(ctx.PackageName, expandedLayoutResId); if (!string.IsNullOrWhiteSpace(title)) { expandedContent.SetTextViewText(titleResId, title); } if (!string.IsNullOrWhiteSpace(summaryTitle)) { expandedContent.SetTextViewText(responseTitleResId, summaryTitle); } if (icon != null) { expandedContent.SetImageViewBitmap(largeIconResId, icon); } if (messageText != null) { expandedContent.SetTextViewText(messageTextResId, messageText); } expandedContent.SetOnClickPendingIntent(emergencyButtonResId, emergencyIntent); expandedContent.SetOnClickPendingIntent(activityButtonResId, activityIntent); expandedContent.SetOnClickPendingIntent(safeButtonResId, safeIntent); notificationBuilder.SetCustomBigContentView(expandedContent); notificationManager.Notify(notificationTag, notificationId, notificationBuilder.Build()); icon?.Dispose(); }
public static void SendLocalNotification(Context ctx, string notificationChannelId, string title, int smallIconResId, Color smallIconColor, string notificationCatagory, int notificationVisibility, int notificationId, string notificationTag, PendingIntent pendingIntent, bool autoCancel, string summaryTitle, string summaryContent, int contentIconResId, Color contentIconBackgroundColor, string groupKey = null, List <NotificationCompat.Action> actions = null) { var notificationManager = NotificationManager.FromContext(ctx); var channel = notificationManager.GetNotificationChannel(notificationChannelId); if (channel == null) { return; } //Map channel importance (Android 8+) to notification importance (android 7) int priority = MapToPriority(channel.Importance); // ensure visibility is valid if (notificationVisibility > NotificationCompat.VisibilityPublic || notificationVisibility < NotificationCompat.VisibilitySecret) { notificationVisibility = NotificationCompat.VisibilityPrivate; } var notificationBuilder = new NotificationCompat.Builder(ctx, notificationChannelId) .SetContentTitle(title) .SetSmallIcon(smallIconResId) .SetColor(smallIconColor) .SetPriority(priority) .SetCategory(notificationCatagory) .SetVisibility(notificationVisibility) .SetAutoCancel(autoCancel); if (!string.IsNullOrWhiteSpace(summaryTitle)) { SpannableStringBuilder sb = new SpannableStringBuilder(summaryTitle); sb.SetSpan(new StyleSpan(TypefaceStyle.Bold), 0, summaryTitle.Length, SpanTypes.ExclusiveExclusive); notificationBuilder.SetContentText(sb); var content = summaryContent; if (!string.IsNullOrWhiteSpace(content)) { sb = new SpannableStringBuilder(summaryTitle); sb.Append("\n"); sb.Append(summaryContent); sb.SetSpan(new StyleSpan(TypefaceStyle.Bold), 0, summaryTitle.Length, SpanTypes.ExclusiveExclusive); notificationBuilder.SetStyle(new NotificationCompat.BigTextStyle().BigText(sb)); } } else { if (!string.IsNullOrWhiteSpace(summaryContent)) { notificationBuilder.SetContentText(summaryContent); if (!string.IsNullOrWhiteSpace(summaryContent)) { notificationBuilder.SetStyle(new NotificationCompat.BigTextStyle().BigText(summaryContent)); } } } if (pendingIntent != null) { notificationBuilder.SetContentIntent(pendingIntent); } Bitmap icon = null; if (contentIconResId != 0) { // build circular icon Drawable iconDrawable = Drawables.CircularIcon(ctx, contentIconResId, Color.White, contentIconBackgroundColor, PixelSizeConverter.DpToPx(15), PixelSizeConverter.DpToPx(140)); // try to get bitmap icon = iconDrawable.ToBitmap(); if (icon != null) { notificationBuilder.SetLargeIcon(icon); } } if (Build.VERSION.SdkInt >= BuildVersionCodes.N && !string.IsNullOrWhiteSpace(groupKey)) { notificationBuilder.SetGroup(groupKey); } if (actions != null && actions.Count > 0) { foreach (var action in actions) { notificationBuilder.AddAction(action); } } notificationManager.Notify(notificationTag, notificationId, notificationBuilder.Build()); icon?.Dispose(); }
public override bool OnDependentViewChanged(CoordinatorLayout parent, Java.Lang.Object jChild, View dependency) { if (dependency is T view) { var child = jChild.JavaCast <View>(); if (_dependsOnView) { //TODO this 4dp margin is actual shadow layout height, which is 4 dp in bottomBar library ver. 2.0.2 float transitionY = view.TranslationY - view.Height + (State != StateExpanded ? PixelSizeConverter.DpToPx(4) : 0); child.TranslationY = System.Math.Min(transitionY, 0); } if (view.TranslationY >= view.Height) { _dependsOnView = false; view.Visibility = ViewStates.Gone; } if (State != StateExpanded) { _dependsOnView = true; view.Visibility = ViewStates.Visible; } return(false); } return(base.OnDependentViewChanged(parent, jChild, dependency)); }