From aeba903c99be4ac31eccbae6280054a8ca1d312e Mon Sep 17 00:00:00 2001 From: alexrainman Date: Sun, 5 Jul 2015 14:26:35 -0500 Subject: [PATCH 1/4] Xamarin Android update. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Launcher’s badge providers added. --- Badge.userprefs | 8 ++ Badge/Badge.Plugin.Abstractions/IBadge.cs | 3 +- .../Badge.Plugin.Android.csproj | 25 +++- .../BadgeImplementation.cs | 62 ++++---- .../BadgeProviderFactory.cs | 77 ++++++++++ Badge/Badge.Plugin.Android/Badges.cs | 64 +++++++++ .../BadgesNotSupportedException.cs | 45 ++++++ .../HomePackageIdentify.cs | 31 ++++ .../Providers/AdwBadgeProvider.cs | 27 ++++ .../Providers/ApexBadgeProvider.cs | 29 ++++ .../Providers/AsusBadgeProvider.cs | 29 ++++ .../Providers/BadgeProvider.cs | 68 +++++++++ .../Providers/DefaultBadgeProvider.cs | 29 ++++ .../Providers/HtcBadgeProvider.cs | 53 +++++++ .../Providers/LGBadgeProvider.cs | 45 ++++++ .../Providers/NovaBadgeProvider.cs | 39 ++++++ .../Providers/NullBadgeProvider.cs | 39 ++++++ .../Providers/SamsungBadgeProvider.cs | 132 ++++++++++++++++++ .../Providers/SolidBadgeProvider.cs | 29 ++++ .../Providers/SonyBadgeProvider.cs | 48 +++++++ .../Providers/XiaomiBadgeProvider.cs | 38 +++++ Badge/Badge.Plugin.iOS/BadgeImplementation.cs | 3 +- 22 files changed, 886 insertions(+), 37 deletions(-) create mode 100644 Badge.userprefs mode change 100644 => 100755 Badge/Badge.Plugin.Abstractions/IBadge.cs mode change 100644 => 100755 Badge/Badge.Plugin.Android/BadgeImplementation.cs create mode 100755 Badge/Badge.Plugin.Android/BadgeProviderFactory.cs create mode 100755 Badge/Badge.Plugin.Android/Badges.cs create mode 100755 Badge/Badge.Plugin.Android/BadgesNotSupportedException.cs create mode 100755 Badge/Badge.Plugin.Android/HomePackageIdentify.cs create mode 100644 Badge/Badge.Plugin.Android/Providers/AdwBadgeProvider.cs create mode 100644 Badge/Badge.Plugin.Android/Providers/ApexBadgeProvider.cs create mode 100644 Badge/Badge.Plugin.Android/Providers/AsusBadgeProvider.cs create mode 100755 Badge/Badge.Plugin.Android/Providers/BadgeProvider.cs create mode 100644 Badge/Badge.Plugin.Android/Providers/DefaultBadgeProvider.cs create mode 100755 Badge/Badge.Plugin.Android/Providers/HtcBadgeProvider.cs create mode 100755 Badge/Badge.Plugin.Android/Providers/LGBadgeProvider.cs create mode 100644 Badge/Badge.Plugin.Android/Providers/NovaBadgeProvider.cs create mode 100755 Badge/Badge.Plugin.Android/Providers/NullBadgeProvider.cs create mode 100755 Badge/Badge.Plugin.Android/Providers/SamsungBadgeProvider.cs create mode 100644 Badge/Badge.Plugin.Android/Providers/SolidBadgeProvider.cs create mode 100755 Badge/Badge.Plugin.Android/Providers/SonyBadgeProvider.cs create mode 100644 Badge/Badge.Plugin.Android/Providers/XiaomiBadgeProvider.cs mode change 100644 => 100755 Badge/Badge.Plugin.iOS/BadgeImplementation.cs diff --git a/Badge.userprefs b/Badge.userprefs new file mode 100644 index 0000000..a62ab3c --- /dev/null +++ b/Badge.userprefs @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/Badge/Badge.Plugin.Abstractions/IBadge.cs b/Badge/Badge.Plugin.Abstractions/IBadge.cs old mode 100644 new mode 100755 index 833e8e3..206a076 --- a/Badge/Badge.Plugin.Abstractions/IBadge.cs +++ b/Badge/Badge.Plugin.Abstractions/IBadge.cs @@ -14,7 +14,6 @@ public interface IBadge /// Sets the badge. /// /// The badge number. - /// The title. Used only by Android - void SetBadge(int badgeNumber, string title = null); + void SetBadge(int badgeNumber); } } diff --git a/Badge/Badge.Plugin.Android/Badge.Plugin.Android.csproj b/Badge/Badge.Plugin.Android/Badge.Plugin.Android.csproj index 631dd4e..1abb100 100644 --- a/Badge/Badge.Plugin.Android/Badge.Plugin.Android.csproj +++ b/Badge/Badge.Plugin.Android/Badge.Plugin.Android.csproj @@ -3,8 +3,6 @@ Debug AnyCPU - 8.0.30703 - 2.0 {56A56F17-7DE1-4CA1-9617-BF32E971AC84} {EFBA0AD7-5A72-4C68-AF49-83D382785DCF};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} Library @@ -16,6 +14,7 @@ Off True True + v5.0 true @@ -50,13 +49,30 @@ + + + + + + + + + + + + + + + + + - {6edb0588-ffc5-4ef5-8a99-9e241d0f878d} + {6EDB0588-FFC5-4EF5-8A99-9E241D0F878D} Badge.Plugin.Abstractions @@ -68,4 +84,7 @@ --> + + + \ No newline at end of file diff --git a/Badge/Badge.Plugin.Android/BadgeImplementation.cs b/Badge/Badge.Plugin.Android/BadgeImplementation.cs old mode 100644 new mode 100755 index 0c5c7c0..a48623f --- a/Badge/Badge.Plugin.Android/BadgeImplementation.cs +++ b/Badge/Badge.Plugin.Android/BadgeImplementation.cs @@ -1,8 +1,35 @@ -using Android; + +using System; using Android.App; -using Android.Content; using Badge.Plugin.Abstractions; +/* + + + + + + + + + + + + + + + + + + + + + + + + +*/ + namespace Badge.Plugin { /// @@ -10,19 +37,13 @@ namespace Badge.Plugin /// public class BadgeImplementation : IBadge { - private const int BadgeNotificationId = int.MinValue; - /// /// Sets the badge. /// /// The badge number. - /// The title. Used only by Android - public void SetBadge(int badgeNumber, string title = null) + public void SetBadge(int badgeNumber) { - var notificationManager = getNotificationManager(); - var notification = createNativeNotification(badgeNumber, title ?? string.Format("{0} new messages", badgeNumber)); - - notificationManager.Notify(BadgeNotificationId, notification); + Badges.SetBadge(Application.Context, badgeNumber); } /// @@ -30,26 +51,7 @@ public void SetBadge(int badgeNumber, string title = null) /// public void ClearBadge() { - var notificationManager = getNotificationManager(); - notificationManager.Cancel(BadgeNotificationId); - } - - private NotificationManager getNotificationManager() - { - var notificationManager = Application.Context.GetSystemService(Context.NotificationService) as NotificationManager; - return notificationManager; - } - - private Notification createNativeNotification(int badgeNumber, string title) - { - var builder = new Notification.Builder(Application.Context) - .SetContentTitle(title) - .SetTicker(title) - .SetNumber(badgeNumber) - .SetSmallIcon(Resource.Drawable.IcDialogEmail); - - var nativeNotification = builder.Build(); - return nativeNotification; + Badges.RemoveBadge(Application.Context); } } } \ No newline at end of file diff --git a/Badge/Badge.Plugin.Android/BadgeProviderFactory.cs b/Badge/Badge.Plugin.Android/BadgeProviderFactory.cs new file mode 100755 index 0000000..c16a553 --- /dev/null +++ b/Badge/Badge.Plugin.Android/BadgeProviderFactory.cs @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2014 Arturo Gutiérrez Díaz-Guerra. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +using Android.Content; +using System.Collections.Generic; +using System; + +namespace Badge.Plugin +{ + /** + * Factory created to provide BadgeProvider implementations depending what launcher is being executed + * + * @author Arturo Gutiérrez Díaz-Guerra + */ + public class BadgeProviderFactory { + + readonly Context context; + Dictionary providers; + + /// + /// Badge provider factory constructor + /// + public BadgeProviderFactory(Context context) { + this.context = context; + providers = new Dictionary(); + + /* from https://github.com/arturogutierrez/Badges */ + providers.Add("com.sec.android.app.launcher", new SamsungBadgeProvider(context)); + providers.Add("com.sec.android.app.twlauncher", new SamsungBadgeProvider(context)); + providers.Add("com.lge.launcher", new LGBadgeProvider(context)); + providers.Add("com.lge.launcher2", new LGBadgeProvider(context)); + providers.Add("com.sonyericsson.home", new SonyBadgeProvider(context)); + providers.Add("com.htc.launcher", new HtcBadgeProvider(context)); + + /* from https://github.com/leolin310148/ShortcutBadger */ + providers.Add("org.adw.launcher", new AdwBadgeProvider(context)); + providers.Add("org.adwfreak.launcher", new AdwBadgeProvider(context)); + providers.Add("com.anddoes.launcher", new ApexBadgeProvider(context)); + providers.Add("com.asus.launcher", new AsusBadgeProvider(context)); + providers.Add("com.teslacoilsw.launcher", new NovaBadgeProvider(context)); + providers.Add("com.majeur.launcher", new SolidBadgeProvider(context)); + providers.Add("com.miui.home", new XiaomiBadgeProvider(context)); + providers.Add("com.miui.miuilite", new XiaomiBadgeProvider(context)); + providers.Add("com.miui.miuihome", new XiaomiBadgeProvider(context)); + providers.Add("com.miui.miuihome2", new XiaomiBadgeProvider(context)); + providers.Add("com.miui.mihome", new XiaomiBadgeProvider(context)); + providers.Add("com.miui.mihome2", new XiaomiBadgeProvider(context)); + } + + /// + /// Get badge provider + /// + public BadgeProvider GetBadgeProvider() { + string currentPackage = GetHomePackage(); + + return providers.ContainsKey (currentPackage) ? providers [currentPackage] : new DefaultBadgeProvider (context); //new NullBadgeProvider (); + } + + private string GetHomePackage() { + var identify = new HomePackageIdentify(); + return identify.GetHomePackage(context); + } + } +} \ No newline at end of file diff --git a/Badge/Badge.Plugin.Android/Badges.cs b/Badge/Badge.Plugin.Android/Badges.cs new file mode 100755 index 0000000..1b199db --- /dev/null +++ b/Badge/Badge.Plugin.Android/Badges.cs @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2014 Arturo Gutiérrez Díaz-Guerra. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +using Android.Content; +using Java.Lang; + +namespace Badge.Plugin +{ + + /** + * Helper to set badge count on current application icon on any supported launchers. + * + * @author Arturo Gutiérrez Díaz-Guerra + */ + public static class Badges { + + /** + * Set badge count on app icon + * + * @param context context activity + * @param count should be >= 0, passing count as 0 the badge will be removed. + * @throws BadgesNotSupportedException when the current launcher is not supported by Badges + */ + public static void SetBadge(Context context, int count) { + + if (context == null) { + throw new BadgesNotSupportedException(); + } + + var badgeFactory = new BadgeProviderFactory(context); + var badgeProvider = badgeFactory.GetBadgeProvider(); + + try { + badgeProvider.SetBadge(count); + } catch (UnsupportedOperationException e) { + throw new BadgesNotSupportedException(); + } + } + + /** + * Remove current badge count + * + * @param context context activity + * @throws BadgesNotSupportedException when the current launcher is not supported by Badges + */ + + public static void RemoveBadge(Context context) { + Badges.SetBadge(context, 0); + } + } +} diff --git a/Badge/Badge.Plugin.Android/BadgesNotSupportedException.cs b/Badge/Badge.Plugin.Android/BadgesNotSupportedException.cs new file mode 100755 index 0000000..7f39cc1 --- /dev/null +++ b/Badge/Badge.Plugin.Android/BadgesNotSupportedException.cs @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2014 Arturo Gutiérrez Díaz-Guerra. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +using System; + +namespace Badge.Plugin +{ + + /** + * Exception to tell the current launcher is not supported by Badges library. + * + * @author Arturo Gutiérrez Díaz-Guerra + */ + public class BadgesNotSupportedException : Exception { + + /// + /// Current home launcher is not supported by Badges library + /// + public BadgesNotSupportedException() + : base("Current home launcher is not supported by Badges library") + { + } + + /// + /// The home launcher package is not supported by Badges library + /// + public BadgesNotSupportedException(String homePackage) + : base(string.Format("The home launcher with package {0} is not supported by Badges library", homePackage)) + { + } + } + +} \ No newline at end of file diff --git a/Badge/Badge.Plugin.Android/HomePackageIdentify.cs b/Badge/Badge.Plugin.Android/HomePackageIdentify.cs new file mode 100755 index 0000000..9604a52 --- /dev/null +++ b/Badge/Badge.Plugin.Android/HomePackageIdentify.cs @@ -0,0 +1,31 @@ + +using Android.Content; +using Android.Content.PM; + +namespace Badge.Plugin +{ + /** + * Helper to identify the package of current home launcher running + * + * Created by Arturo Gutiérrez on 19/12/14. + */ + public class HomePackageIdentify { + + /// + /// Get home package + /// + public string GetHomePackage(Context context) { + + var intent = new Intent(Intent.ActionMain); + intent.AddCategory(Intent.CategoryHome); + + ResolveInfo resolveInfo = context.PackageManager.ResolveActivity(intent, PackageInfoFlags.MatchDefaultOnly); + + if (resolveInfo != null && resolveInfo.ActivityInfo != null && resolveInfo.ActivityInfo.PackageName != null) { + return resolveInfo.ActivityInfo.PackageName; + } + + return context.PackageName; + } + } +} \ No newline at end of file diff --git a/Badge/Badge.Plugin.Android/Providers/AdwBadgeProvider.cs b/Badge/Badge.Plugin.Android/Providers/AdwBadgeProvider.cs new file mode 100644 index 0000000..aa7d007 --- /dev/null +++ b/Badge/Badge.Plugin.Android/Providers/AdwBadgeProvider.cs @@ -0,0 +1,27 @@ + +using Android.Content; + +namespace Badge.Plugin +{ + /** + * @author Gernot Pansy + */ + class AdwBadgeProvider : BadgeProvider { + + public AdwBadgeProvider(Context context) + : base(context) + { + } + + public override void SetBadge(int count) { + var intent = new Intent("org.adw.launcher.counter.SEND"); + intent.PutExtra("PNAME", GetPackageName()); + intent.PutExtra("COUNT", count); + mContext.SendBroadcast(intent); + } + + public override void RemoveBadge() { + SetBadge(0); + } + } +} \ No newline at end of file diff --git a/Badge/Badge.Plugin.Android/Providers/ApexBadgeProvider.cs b/Badge/Badge.Plugin.Android/Providers/ApexBadgeProvider.cs new file mode 100644 index 0000000..957e74c --- /dev/null +++ b/Badge/Badge.Plugin.Android/Providers/ApexBadgeProvider.cs @@ -0,0 +1,29 @@ + +using Android.Content; + +namespace Badge.Plugin +{ + /** + * @author Gernot Pansy + */ + class ApexBadgeProvider : BadgeProvider { + + public ApexBadgeProvider(Context context) + : base(context) + { + } + + public override void SetBadge(int count) { + var intent = new Intent("com.anddoes.launcher.COUNTER_CHANGED"); + intent.PutExtra("package", GetPackageName()); + intent.PutExtra("count", count); + intent.PutExtra("class", GetMainActivityClassName()); + mContext.SendBroadcast(intent); + } + + public override void RemoveBadge() { + SetBadge(0); + } + } +} + diff --git a/Badge/Badge.Plugin.Android/Providers/AsusBadgeProvider.cs b/Badge/Badge.Plugin.Android/Providers/AsusBadgeProvider.cs new file mode 100644 index 0000000..68211d2 --- /dev/null +++ b/Badge/Badge.Plugin.Android/Providers/AsusBadgeProvider.cs @@ -0,0 +1,29 @@ +using Android.Content; + +namespace Badge.Plugin +{ + /** + * @author leolin + */ + class AsusBadgeProvider : BadgeProvider { + + public AsusBadgeProvider(Context context) + : base(context) + { + } + + public override void SetBadge(int count) { + var intent = new Intent("android.intent.action.BADGE_COUNT_UPDATE"); + intent.PutExtra("badge_count", count); + intent.PutExtra("badge_count_package_name", GetPackageName()); + intent.PutExtra("badge_count_class_name", GetMainActivityClassName()); + intent.PutExtra("badge_vip_count", 0); + mContext.SendBroadcast(intent); + } + + public override void RemoveBadge() { + SetBadge(0); + } + } +} + diff --git a/Badge/Badge.Plugin.Android/Providers/BadgeProvider.cs b/Badge/Badge.Plugin.Android/Providers/BadgeProvider.cs new file mode 100755 index 0000000..b6d6faf --- /dev/null +++ b/Badge/Badge.Plugin.Android/Providers/BadgeProvider.cs @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2014 Arturo Gutiérrez Díaz-Guerra. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +using Android.Content; + +namespace Badge.Plugin +{ + /** + * Abstract class created to be implemented by different classes to provide badge change support on + * different launchers. + * + * @author Arturo Gutiérrez Díaz-Guerra + */ + + public class BadgeProvider { + + /// + /// Badge provider context + /// + protected Context mContext; + + /// + /// Badge provider constructor + /// + public BadgeProvider(Context context) { + mContext = context; + } + + /// + /// Virtual set badge + /// + public virtual void SetBadge(int count){ + } + + /// + /// Virtual remove badge + /// + public virtual void RemoveBadge(){ + } + + /// + /// Get package name + /// + protected string GetPackageName() { + return mContext.PackageName; + } + + /// + /// Get main activity class name + /// + protected string GetMainActivityClassName() { + return mContext.PackageManager.GetLaunchIntentForPackage(GetPackageName()).Component.ClassName; + } + } +} \ No newline at end of file diff --git a/Badge/Badge.Plugin.Android/Providers/DefaultBadgeProvider.cs b/Badge/Badge.Plugin.Android/Providers/DefaultBadgeProvider.cs new file mode 100644 index 0000000..413c654 --- /dev/null +++ b/Badge/Badge.Plugin.Android/Providers/DefaultBadgeProvider.cs @@ -0,0 +1,29 @@ +using System; +using Android.Content; + +namespace Badge.Plugin +{ + /** + * @author leolin + */ + class DefaultBadgeProvider : BadgeProvider { + + public DefaultBadgeProvider(Context context) + : base(context) + { + } + + public override void SetBadge(int count) { + var intent = new Intent("android.intent.action.BADGE_COUNT_UPDATE"); + intent.PutExtra("badge_count", count); + intent.PutExtra("badge_count_package_name", GetPackageName()); + intent.PutExtra("badge_count_class_name", GetMainActivityClassName()); + mContext.SendBroadcast(intent); + } + + public override void RemoveBadge() { + SetBadge(0); + } + } +} + diff --git a/Badge/Badge.Plugin.Android/Providers/HtcBadgeProvider.cs b/Badge/Badge.Plugin.Android/Providers/HtcBadgeProvider.cs new file mode 100755 index 0000000..4f2daed --- /dev/null +++ b/Badge/Badge.Plugin.Android/Providers/HtcBadgeProvider.cs @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2014 Arturo Gutiérrez Díaz-Guerra. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +//import android.content.ComponentName; +//import android.content.Context; +//import android.content.Intent; +using Android.Content; + +namespace Badge.Plugin +{ + /** + * BadgeProvider implementation to support badges on HTC devices. + * + * @author Arturo Gutiérrez Díaz-Guerra + */ + class HtcBadgeProvider : BadgeProvider { + + public HtcBadgeProvider(Context context) + : base(context) + { + } + + public override void SetBadge(int count) { + var intent = new Intent("com.htc.launcher.action.UPDATE_SHORTCUT"); + intent.PutExtra("packagename", GetPackageName()); + intent.PutExtra("count", count); + mContext.SendBroadcast (intent); + + var setNotificationIntent = new Intent("com.htc.launcher.action.SET_NOTIFICATION"); + var componentName = new ComponentName(GetPackageName(), GetMainActivityClassName()); + setNotificationIntent.PutExtra("com.htc.launcher.extra.COMPONENT", componentName.FlattenToShortString()); + setNotificationIntent.PutExtra("com.htc.launcher.extra.COUNT", count); + mContext.SendBroadcast(setNotificationIntent); + } + + public override void RemoveBadge() { + SetBadge(0); + } + } +} \ No newline at end of file diff --git a/Badge/Badge.Plugin.Android/Providers/LGBadgeProvider.cs b/Badge/Badge.Plugin.Android/Providers/LGBadgeProvider.cs new file mode 100755 index 0000000..ef9a6b9 --- /dev/null +++ b/Badge/Badge.Plugin.Android/Providers/LGBadgeProvider.cs @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2014 Arturo Gutiérrez Díaz-Guerra. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +using Android.Content; + +namespace Badge.Plugin +{ + /** + * BadgeProvider implementation to support badges on LG devices. + * + * @author Arturo Gutiérrez Díaz-Guerra + */ + class LGBadgeProvider : BadgeProvider { + + public LGBadgeProvider(Context context) + : base(context) + { + } + + public override void SetBadge(int count) { + var intent = new Intent("android.intent.action.BADGE_COUNT_UPDATE"); + intent.PutExtra("badge_count_package_name", GetPackageName()); + intent.PutExtra("badge_count_class_name", GetMainActivityClassName()); + intent.PutExtra("badge_count", count); + + mContext.SendBroadcast(intent); + } + + public override void RemoveBadge() { + SetBadge(0); + } + } +} diff --git a/Badge/Badge.Plugin.Android/Providers/NovaBadgeProvider.cs b/Badge/Badge.Plugin.Android/Providers/NovaBadgeProvider.cs new file mode 100644 index 0000000..3483993 --- /dev/null +++ b/Badge/Badge.Plugin.Android/Providers/NovaBadgeProvider.cs @@ -0,0 +1,39 @@ +using System; +using Android.Content; + +namespace Badge.Plugin +{ + /** + * Shortcut Badger support for Nova Launcher. + * TeslaUnread must be installed. + * User: Gernot Pansy + * Date: 2014/11/03 + * Time: 7:15 + */ + class NovaBadgeProvider : BadgeProvider { + + public NovaBadgeProvider(Context context) + : base(context) + { + } + + public override void SetBadge(int count) { + try { + var contentValues = new ContentValues(); + contentValues.Put("tag", GetPackageName() + "/" + GetMainActivityClassName()); + contentValues.Put("count", count); + mContext.ContentResolver.Insert(Android.Net.Uri.Parse("content://com.teslacoilsw.notifier/unread_count"), contentValues); + } catch (Java.Lang.IllegalArgumentException ex) { + /* Fine, TeslaUnread is not installed. */ + } catch (Exception ex) { + /* Some other error, possibly because the format of the ContentValues are incorrect. */ + throw new BadgesNotSupportedException(ex.Message); + } + } + + public override void RemoveBadge() { + SetBadge(0); + } + } +} + diff --git a/Badge/Badge.Plugin.Android/Providers/NullBadgeProvider.cs b/Badge/Badge.Plugin.Android/Providers/NullBadgeProvider.cs new file mode 100755 index 0000000..51d686c --- /dev/null +++ b/Badge/Badge.Plugin.Android/Providers/NullBadgeProvider.cs @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2014 Arturo Gutiérrez Díaz-Guerra. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +using Java.Lang; + +namespace Badge.Plugin +{ + /** + * NullObject implementation for BadgeProvider. + * + * @author Arturo Gutiérrez Díaz-Guerra + */ + class NullBadgeProvider : BadgeProvider { + + public NullBadgeProvider() : base(null) { + } + + public override void SetBadge(int count){ + throw new UnsupportedOperationException(); + } + + public override void RemoveBadge() { + throw new UnsupportedOperationException(); + } + } +} \ No newline at end of file diff --git a/Badge/Badge.Plugin.Android/Providers/SamsungBadgeProvider.cs b/Badge/Badge.Plugin.Android/Providers/SamsungBadgeProvider.cs new file mode 100755 index 0000000..f15c98f --- /dev/null +++ b/Badge/Badge.Plugin.Android/Providers/SamsungBadgeProvider.cs @@ -0,0 +1,132 @@ +/* + * Copyright (C) 2014 Arturo Gutiérrez Díaz-Guerra. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +using Android.Content; +using System; + +namespace Badge.Plugin +{ + /** + * BadgeProvider implementation to support badges on Samsung devices (WITH FIXES). + * + * @author Arturo Gutiérrez Díaz-Guerra + */ + class SamsungBadgeProvider : BadgeProvider { + + static Android.Net.Uri CONTENT_URI = Android.Net.Uri.Parse("content://com.sec.badge/apps"); + //const string COLUMN_ID = "_id"; + //const string COLUMN_PACKAGE = "package"; + //const string COLUMN_CLASS = "class"; + //const string COLUMN_BADGE_COUNT = "badgecount"; + + public SamsungBadgeProvider(Context context) : base(context){ + } + + public override void SetBadge(int count) { + try { + + /*ContentResolver contentResolver = mContext.ContentResolver; + var cursor = contentResolver.Query(CONTENT_URI, new string[]{ COLUMN_ID }, COLUMN_PACKAGE + "=?", new string[]{ GetPackageName() }, null); + + if (cursor == null || !cursor.MoveToFirst()) { + var contentValues = new ContentValues(); + contentValues.Put(COLUMN_PACKAGE, GetPackageName()); + contentValues.Put(COLUMN_CLASS, GetMainActivityClassName()); + contentValues.Put(COLUMN_BADGE_COUNT, count); + contentResolver.Insert(CONTENT_URI, contentValues); + } else { + int idColumnIndex = cursor.GetColumnIndex(COLUMN_ID); + + var contentValues = new ContentValues(); + contentValues.Put(COLUMN_BADGE_COUNT, count); + contentResolver.Update(CONTENT_URI, contentValues, COLUMN_ID + "=?", new string[]{ cursor.GetInt(idColumnIndex).ToString() }); + }*/ + + var cv = new ContentValues(); + cv.Put("package", GetPackageName()); + cv.Put("class", GetMainActivityClassName()); + cv.Put("badgecount", count); // integer count you want to display + + ContentResolver contentResolver = mContext.ContentResolver; + + int updated = contentResolver.Update(CONTENT_URI, cv, "package=?", new string[] { GetPackageName() }); + + if (updated == 0) + contentResolver.Insert(CONTENT_URI, cv); + + } catch (Exception e) { + // Some Samsung devices are throwing SecurityException or RuntimeException when + // trying to set the badge saying the app needs permission which are already added, + // this try/catch protect us from these "crappy phones" :) + throw new Java.Lang.UnsupportedOperationException(); + } + } + + public override void RemoveBadge() { + SetBadge(0); + } + + /*const string CONTENT_URI = "content://com.sec.badge/apps?notify=true"; + static string[] CONTENT_PROJECTION = new string[]{ "_id","class" }; + + public SamsungBadgeProvider(Context context) : base(context){ + } + + public override void SetBadge(int count) { + Android.Net.Uri mUri = Android.Net.Uri.Parse(CONTENT_URI); + ContentResolver contentResolver = mContext.ContentResolver; + try { + var cursor = contentResolver.Query(mUri, CONTENT_PROJECTION, "package=?", new string[]{ GetPackageName() }, null); + if (cursor != null) { + string entryActivityName = GetMainActivityClassName(); + bool entryActivityExist = false; + while (cursor.MoveToNext()) { + int id = cursor.GetInt(0); + ContentValues contentValues = GetContentValues(count, false); + contentResolver.Update(mUri, contentValues, "_id=?", new String[]{ id.ToString() }); + entryActivityExist |= entryActivityName.Equals (cursor.GetString (cursor.GetColumnIndex ("class"))); + } + + if (!entryActivityExist) { + ContentValues contentValues = GetContentValues(count, true); + contentResolver.Insert(mUri, contentValues); + } + } + } catch (Exception e) { + // Some Samsung devices are throwing SecurityException or RuntimeException when + // trying to set the badge saying the app needs permission which are already added, + // this try/catch protect us from these "crappy phones" :) + throw new Java.Lang.UnsupportedOperationException(); + } + } + + public override void RemoveBadge() { + SetBadge(0); + } + + ContentValues GetContentValues(int count, bool isInsert) { + var contentValues = new ContentValues(); + if (isInsert) { + contentValues.Put("package", GetPackageName()); + contentValues.Put("class", GetMainActivityClassName()); + } + + contentValues.Put("badgecount", count); + + return contentValues; + }*/ + } +} \ No newline at end of file diff --git a/Badge/Badge.Plugin.Android/Providers/SolidBadgeProvider.cs b/Badge/Badge.Plugin.Android/Providers/SolidBadgeProvider.cs new file mode 100644 index 0000000..c79d22d --- /dev/null +++ b/Badge/Badge.Plugin.Android/Providers/SolidBadgeProvider.cs @@ -0,0 +1,29 @@ + +using Android.Content; + +namespace Badge.Plugin +{ + /** + * @author MajeurAndroid + */ + class SolidBadgeProvider : BadgeProvider { + + public SolidBadgeProvider(Context context) + : base(context) + { + } + + public override void SetBadge(int count) { + var intent = new Intent("com.majeur.launcher.intent.action.UPDATE_BADGE"); + intent.PutExtra("com.majeur.launcher.intent.extra.BADGE_PACKAGE", GetPackageName()); + intent.PutExtra("com.majeur.launcher.intent.extra.BADGE_COUNT", count); + intent.PutExtra("com.majeur.launcher.intent.extra.BADGE_CLASS", GetMainActivityClassName()); + mContext.SendBroadcast(intent); + } + + public override void RemoveBadge() { + SetBadge(0); + } + } +} + diff --git a/Badge/Badge.Plugin.Android/Providers/SonyBadgeProvider.cs b/Badge/Badge.Plugin.Android/Providers/SonyBadgeProvider.cs new file mode 100755 index 0000000..b7860b7 --- /dev/null +++ b/Badge/Badge.Plugin.Android/Providers/SonyBadgeProvider.cs @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2014 Arturo Gutiérrez Díaz-Guerra. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +using Android.Content; + +namespace Badge.Plugin +{ + /** + * BadgeProvider implementation to support badges on Sony devices. + * + * @author Arturo Gutiérrez Díaz-Guerra + */ + class SonyBadgeProvider : BadgeProvider { + + public SonyBadgeProvider(Context context) + : base(context) + { + } + + public override void SetBadge(int count) { + var intent = new Intent(); + + intent.SetAction("com.sonyericsson.home.action.UPDATE_BADGE"); + intent.PutExtra("com.sonyericsson.home.intent.extra.badge.PACKAGE_NAME", GetPackageName()); + intent.PutExtra("com.sonyericsson.home.intent.extra.badge.ACTIVITY_NAME", GetMainActivityClassName()); + intent.PutExtra("com.sonyericsson.home.intent.extra.badge.SHOW_MESSAGE", count > 0); + intent.PutExtra("com.sonyericsson.home.intent.extra.badge.MESSAGE", count.ToString()); + + mContext.SendBroadcast(intent); + } + + public override void RemoveBadge() { + SetBadge(0); + } + } +} \ No newline at end of file diff --git a/Badge/Badge.Plugin.Android/Providers/XiaomiBadgeProvider.cs b/Badge/Badge.Plugin.Android/Providers/XiaomiBadgeProvider.cs new file mode 100644 index 0000000..e76125e --- /dev/null +++ b/Badge/Badge.Plugin.Android/Providers/XiaomiBadgeProvider.cs @@ -0,0 +1,38 @@ + +using Android.Content; +using Java.Lang; +using Java.Lang.Reflect; + +namespace Badge.Plugin +{ + /** + * @author leolin + */ + class XiaomiBadgeProvider : BadgeProvider { + + public XiaomiBadgeProvider(Context context) + : base(context) + { + } + + public override void SetBadge(int count) { + try { + Class miuiNotificationClass = Class.ForName("android.app.MiuiNotification"); + Java.Lang.Object miuiNotification = miuiNotificationClass.NewInstance(); + Field field = miuiNotification.Class.GetDeclaredField("messageCount"); + field.Accessible = true; + field.Set(miuiNotification, count == 0 ? "" : count.ToString()); + } catch (System.Exception e) { + var localIntent = new Intent("android.intent.action.APPLICATION_MESSAGE_UPDATE"); + localIntent.PutExtra("android.intent.extra.update_application_component_name", GetPackageName() + "/" + GetMainActivityClassName()); + localIntent.PutExtra("android.intent.extra.update_application_message_text", count == 0 ? "" : count.ToString()); + mContext.SendBroadcast(localIntent); + } + } + + public override void RemoveBadge() { + SetBadge(0); + } + } +} + diff --git a/Badge/Badge.Plugin.iOS/BadgeImplementation.cs b/Badge/Badge.Plugin.iOS/BadgeImplementation.cs old mode 100644 new mode 100755 index 38e7501..757879c --- a/Badge/Badge.Plugin.iOS/BadgeImplementation.cs +++ b/Badge/Badge.Plugin.iOS/BadgeImplementation.cs @@ -24,8 +24,7 @@ public void ClearBadge() /// Sets the badge. /// /// The badge number. - /// The title. Used only by Android - public void SetBadge(int badgeNumber, string title = null) + public void SetBadge(int badgeNumber) { UIApplication.SharedApplication.ApplicationIconBadgeNumber = badgeNumber; } From d31d37c663743b635c12ac3f87d8320303af734a Mon Sep 17 00:00:00 2001 From: alexrainman Date: Sun, 5 Jul 2015 14:30:48 -0500 Subject: [PATCH 2/4] Credit Ported by Alex Rainman --- Badge/Badge.Plugin.Android/BadgeProviderFactory.cs | 2 ++ Badge/Badge.Plugin.Android/Badges.cs | 2 ++ Badge/Badge.Plugin.Android/BadgesNotSupportedException.cs | 2 ++ Badge/Badge.Plugin.Android/HomePackageIdentify.cs | 2 ++ Badge/Badge.Plugin.Android/Providers/AdwBadgeProvider.cs | 2 ++ Badge/Badge.Plugin.Android/Providers/ApexBadgeProvider.cs | 2 ++ Badge/Badge.Plugin.Android/Providers/AsusBadgeProvider.cs | 2 ++ Badge/Badge.Plugin.Android/Providers/BadgeProvider.cs | 2 ++ Badge/Badge.Plugin.Android/Providers/DefaultBadgeProvider.cs | 2 ++ Badge/Badge.Plugin.Android/Providers/HtcBadgeProvider.cs | 2 ++ Badge/Badge.Plugin.Android/Providers/LGBadgeProvider.cs | 2 ++ Badge/Badge.Plugin.Android/Providers/NovaBadgeProvider.cs | 2 ++ Badge/Badge.Plugin.Android/Providers/NullBadgeProvider.cs | 4 +++- Badge/Badge.Plugin.Android/Providers/SamsungBadgeProvider.cs | 2 ++ Badge/Badge.Plugin.Android/Providers/SolidBadgeProvider.cs | 2 ++ Badge/Badge.Plugin.Android/Providers/SonyBadgeProvider.cs | 2 ++ Badge/Badge.Plugin.Android/Providers/XiaomiBadgeProvider.cs | 4 +++- 17 files changed, 36 insertions(+), 2 deletions(-) diff --git a/Badge/Badge.Plugin.Android/BadgeProviderFactory.cs b/Badge/Badge.Plugin.Android/BadgeProviderFactory.cs index c16a553..8b628d9 100755 --- a/Badge/Badge.Plugin.Android/BadgeProviderFactory.cs +++ b/Badge/Badge.Plugin.Android/BadgeProviderFactory.cs @@ -24,6 +24,8 @@ namespace Badge.Plugin * Factory created to provide BadgeProvider implementations depending what launcher is being executed * * @author Arturo Gutiérrez Díaz-Guerra + * + * ported to C# by Alex Rainman */ public class BadgeProviderFactory { diff --git a/Badge/Badge.Plugin.Android/Badges.cs b/Badge/Badge.Plugin.Android/Badges.cs index 1b199db..914e880 100755 --- a/Badge/Badge.Plugin.Android/Badges.cs +++ b/Badge/Badge.Plugin.Android/Badges.cs @@ -24,6 +24,8 @@ namespace Badge.Plugin * Helper to set badge count on current application icon on any supported launchers. * * @author Arturo Gutiérrez Díaz-Guerra + * + * ported to C# by Alex Rainman */ public static class Badges { diff --git a/Badge/Badge.Plugin.Android/BadgesNotSupportedException.cs b/Badge/Badge.Plugin.Android/BadgesNotSupportedException.cs index 7f39cc1..ac7b97e 100755 --- a/Badge/Badge.Plugin.Android/BadgesNotSupportedException.cs +++ b/Badge/Badge.Plugin.Android/BadgesNotSupportedException.cs @@ -22,6 +22,8 @@ namespace Badge.Plugin * Exception to tell the current launcher is not supported by Badges library. * * @author Arturo Gutiérrez Díaz-Guerra + * + * ported to C# by Alex Rainman */ public class BadgesNotSupportedException : Exception { diff --git a/Badge/Badge.Plugin.Android/HomePackageIdentify.cs b/Badge/Badge.Plugin.Android/HomePackageIdentify.cs index 9604a52..d94574f 100755 --- a/Badge/Badge.Plugin.Android/HomePackageIdentify.cs +++ b/Badge/Badge.Plugin.Android/HomePackageIdentify.cs @@ -8,6 +8,8 @@ namespace Badge.Plugin * Helper to identify the package of current home launcher running * * Created by Arturo Gutiérrez on 19/12/14. + * + * ported to C# by Alex Rainman */ public class HomePackageIdentify { diff --git a/Badge/Badge.Plugin.Android/Providers/AdwBadgeProvider.cs b/Badge/Badge.Plugin.Android/Providers/AdwBadgeProvider.cs index aa7d007..beac194 100644 --- a/Badge/Badge.Plugin.Android/Providers/AdwBadgeProvider.cs +++ b/Badge/Badge.Plugin.Android/Providers/AdwBadgeProvider.cs @@ -5,6 +5,8 @@ namespace Badge.Plugin { /** * @author Gernot Pansy + * + * ported to C# by Alex Rainman */ class AdwBadgeProvider : BadgeProvider { diff --git a/Badge/Badge.Plugin.Android/Providers/ApexBadgeProvider.cs b/Badge/Badge.Plugin.Android/Providers/ApexBadgeProvider.cs index 957e74c..0958998 100644 --- a/Badge/Badge.Plugin.Android/Providers/ApexBadgeProvider.cs +++ b/Badge/Badge.Plugin.Android/Providers/ApexBadgeProvider.cs @@ -5,6 +5,8 @@ namespace Badge.Plugin { /** * @author Gernot Pansy + * + * ported to C# by Alex Rainman */ class ApexBadgeProvider : BadgeProvider { diff --git a/Badge/Badge.Plugin.Android/Providers/AsusBadgeProvider.cs b/Badge/Badge.Plugin.Android/Providers/AsusBadgeProvider.cs index 68211d2..4c5b3d7 100644 --- a/Badge/Badge.Plugin.Android/Providers/AsusBadgeProvider.cs +++ b/Badge/Badge.Plugin.Android/Providers/AsusBadgeProvider.cs @@ -4,6 +4,8 @@ namespace Badge.Plugin { /** * @author leolin + * + * ported to C# by Alex Rainman */ class AsusBadgeProvider : BadgeProvider { diff --git a/Badge/Badge.Plugin.Android/Providers/BadgeProvider.cs b/Badge/Badge.Plugin.Android/Providers/BadgeProvider.cs index b6d6faf..9d9c1fb 100755 --- a/Badge/Badge.Plugin.Android/Providers/BadgeProvider.cs +++ b/Badge/Badge.Plugin.Android/Providers/BadgeProvider.cs @@ -23,6 +23,8 @@ namespace Badge.Plugin * different launchers. * * @author Arturo Gutiérrez Díaz-Guerra + * + * ported to C# by Alex Rainman */ public class BadgeProvider { diff --git a/Badge/Badge.Plugin.Android/Providers/DefaultBadgeProvider.cs b/Badge/Badge.Plugin.Android/Providers/DefaultBadgeProvider.cs index 413c654..e3821e2 100644 --- a/Badge/Badge.Plugin.Android/Providers/DefaultBadgeProvider.cs +++ b/Badge/Badge.Plugin.Android/Providers/DefaultBadgeProvider.cs @@ -5,6 +5,8 @@ namespace Badge.Plugin { /** * @author leolin + * + * ported to C# by Alex Rainman */ class DefaultBadgeProvider : BadgeProvider { diff --git a/Badge/Badge.Plugin.Android/Providers/HtcBadgeProvider.cs b/Badge/Badge.Plugin.Android/Providers/HtcBadgeProvider.cs index 4f2daed..6e7f792 100755 --- a/Badge/Badge.Plugin.Android/Providers/HtcBadgeProvider.cs +++ b/Badge/Badge.Plugin.Android/Providers/HtcBadgeProvider.cs @@ -25,6 +25,8 @@ namespace Badge.Plugin * BadgeProvider implementation to support badges on HTC devices. * * @author Arturo Gutiérrez Díaz-Guerra + * + * ported to C# by Alex Rainman */ class HtcBadgeProvider : BadgeProvider { diff --git a/Badge/Badge.Plugin.Android/Providers/LGBadgeProvider.cs b/Badge/Badge.Plugin.Android/Providers/LGBadgeProvider.cs index ef9a6b9..769fc7d 100755 --- a/Badge/Badge.Plugin.Android/Providers/LGBadgeProvider.cs +++ b/Badge/Badge.Plugin.Android/Providers/LGBadgeProvider.cs @@ -21,6 +21,8 @@ namespace Badge.Plugin * BadgeProvider implementation to support badges on LG devices. * * @author Arturo Gutiérrez Díaz-Guerra + * + * ported to C# by Alex Rainman */ class LGBadgeProvider : BadgeProvider { diff --git a/Badge/Badge.Plugin.Android/Providers/NovaBadgeProvider.cs b/Badge/Badge.Plugin.Android/Providers/NovaBadgeProvider.cs index 3483993..9c1ef8a 100644 --- a/Badge/Badge.Plugin.Android/Providers/NovaBadgeProvider.cs +++ b/Badge/Badge.Plugin.Android/Providers/NovaBadgeProvider.cs @@ -9,6 +9,8 @@ namespace Badge.Plugin * User: Gernot Pansy * Date: 2014/11/03 * Time: 7:15 + * + * ported to C# by Alex Rainman */ class NovaBadgeProvider : BadgeProvider { diff --git a/Badge/Badge.Plugin.Android/Providers/NullBadgeProvider.cs b/Badge/Badge.Plugin.Android/Providers/NullBadgeProvider.cs index 51d686c..a047b1c 100755 --- a/Badge/Badge.Plugin.Android/Providers/NullBadgeProvider.cs +++ b/Badge/Badge.Plugin.Android/Providers/NullBadgeProvider.cs @@ -19,9 +19,11 @@ namespace Badge.Plugin { /** - * NullObject implementation for BadgeProvider. + * NullObject implementation for BadgeProvider (not used, replaced by DefaultBadgeProvider). * * @author Arturo Gutiérrez Díaz-Guerra + * + * ported to C# by Alex Rainman */ class NullBadgeProvider : BadgeProvider { diff --git a/Badge/Badge.Plugin.Android/Providers/SamsungBadgeProvider.cs b/Badge/Badge.Plugin.Android/Providers/SamsungBadgeProvider.cs index f15c98f..85e924d 100755 --- a/Badge/Badge.Plugin.Android/Providers/SamsungBadgeProvider.cs +++ b/Badge/Badge.Plugin.Android/Providers/SamsungBadgeProvider.cs @@ -23,6 +23,8 @@ namespace Badge.Plugin * BadgeProvider implementation to support badges on Samsung devices (WITH FIXES). * * @author Arturo Gutiérrez Díaz-Guerra + * + * ported to C# and fixed by Alex Rainman */ class SamsungBadgeProvider : BadgeProvider { diff --git a/Badge/Badge.Plugin.Android/Providers/SolidBadgeProvider.cs b/Badge/Badge.Plugin.Android/Providers/SolidBadgeProvider.cs index c79d22d..8ae7f5e 100644 --- a/Badge/Badge.Plugin.Android/Providers/SolidBadgeProvider.cs +++ b/Badge/Badge.Plugin.Android/Providers/SolidBadgeProvider.cs @@ -5,6 +5,8 @@ namespace Badge.Plugin { /** * @author MajeurAndroid + * + * ported to C# by Alex Rainman */ class SolidBadgeProvider : BadgeProvider { diff --git a/Badge/Badge.Plugin.Android/Providers/SonyBadgeProvider.cs b/Badge/Badge.Plugin.Android/Providers/SonyBadgeProvider.cs index b7860b7..c88d637 100755 --- a/Badge/Badge.Plugin.Android/Providers/SonyBadgeProvider.cs +++ b/Badge/Badge.Plugin.Android/Providers/SonyBadgeProvider.cs @@ -21,6 +21,8 @@ namespace Badge.Plugin * BadgeProvider implementation to support badges on Sony devices. * * @author Arturo Gutiérrez Díaz-Guerra + * + * ported to C# by Alex Rainman */ class SonyBadgeProvider : BadgeProvider { diff --git a/Badge/Badge.Plugin.Android/Providers/XiaomiBadgeProvider.cs b/Badge/Badge.Plugin.Android/Providers/XiaomiBadgeProvider.cs index e76125e..3fcc87e 100644 --- a/Badge/Badge.Plugin.Android/Providers/XiaomiBadgeProvider.cs +++ b/Badge/Badge.Plugin.Android/Providers/XiaomiBadgeProvider.cs @@ -7,6 +7,8 @@ namespace Badge.Plugin { /** * @author leolin + * + * ported to C# by Alex Rainman */ class XiaomiBadgeProvider : BadgeProvider { @@ -18,7 +20,7 @@ public XiaomiBadgeProvider(Context context) public override void SetBadge(int count) { try { Class miuiNotificationClass = Class.ForName("android.app.MiuiNotification"); - Java.Lang.Object miuiNotification = miuiNotificationClass.NewInstance(); + Object miuiNotification = miuiNotificationClass.NewInstance(); Field field = miuiNotification.Class.GetDeclaredField("messageCount"); field.Accessible = true; field.Set(miuiNotification, count == 0 ? "" : count.ToString()); From 05fe05bf90c318206fcdec697093df60cfde54e7 Mon Sep 17 00:00:00 2001 From: alexrainman Date: Sun, 5 Jul 2015 14:38:15 -0500 Subject: [PATCH 3/4] Update README.md --- README.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/README.md b/README.md index 4cc423d..7f7cd7a 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,29 @@ Simple cross platform plugin to work with application badge * Windows Phone 8.1 RT * Windows Store 8.0+ +**Xamarin.Android Fix** + +Android doesn't supports app icon badge by default but third party manufacturers launchers do. + +Now the plugin support these: + +* Samsung +* HTC +* LG +* Sony +* Xiaomi +* Adw +* Apex +* Asus +* Nova +* Solid +* Default (because some launchers use android.intent.action.BADGE_COUNT_UPDATE to update count) + +Thanks to: + +https://github.com/arturogutierrez/Badges +https://github.com/leolin310148/ShortcutBadger + ### API Usage Call **CrossBadge.Current** from any project or PCL to gain access to APIs. From 630b85e2708a5a16873d9386c098799ad68b14e9 Mon Sep 17 00:00:00 2001 From: alexrainman Date: Sun, 5 Jul 2015 14:38:46 -0500 Subject: [PATCH 4/4] Update README.md --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 7f7cd7a..096b5a3 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,9 @@ Now the plugin support these: Thanks to: https://github.com/arturogutierrez/Badges + +and + https://github.com/leolin310148/ShortcutBadger ### API Usage