Java Code Examples for me.leolin.shortcutbadger.ShortcutBadger#applyCount()

The following examples show how to use me.leolin.shortcutbadger.ShortcutBadger#applyCount() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HelperNotificationAndBadge.java    From iGap-Android with GNU Affero General Public License v3.0 6 votes vote down vote up
public static int[] updateBadgeOnly(Realm realm, long roomId) {
    int unreadMessageCount = 0;
    int chatCount = 0;
    int[] result = new int[2];

    RealmResults<RealmRoom> realmRooms = realm.where(RealmRoom.class).equalTo(RealmRoomFields.KEEP_ROOM, false).
            equalTo(RealmRoomFields.MUTE, false).equalTo(RealmRoomFields.IS_DELETED, false).notEqualTo(RealmRoomFields.ID, roomId).findAll();

    for (RealmRoom realmRoom1 : realmRooms) {
        if (realmRoom1.getUnreadCount() > 0) {
            unreadMessageCount += realmRoom1.getUnreadCount();
            ++chatCount;
        }
    }

    try {
        ShortcutBadger.applyCount(G.context, unreadMessageCount);
    } catch (Exception e) {
        e.printStackTrace();
    }

    result[0] = unreadMessageCount;
    result[1] = chatCount;
    return result;
}
 
Example 2
Source File: AppUtils.java    From iGap-Android with GNU Affero General Public License v3.0 6 votes vote down vote up
public static int[] updateBadgeOnly(Realm realm, long roomId) {
    int unreadMessageCount = 0;
    int chatCount = 0;
    int[] result = new int[2];

    RealmResults<RealmRoom> realmRooms = realm.where(RealmRoom.class).equalTo(RealmRoomFields.KEEP_ROOM, false).
            equalTo(RealmRoomFields.MUTE, false).equalTo(RealmRoomFields.IS_DELETED, false).notEqualTo(RealmRoomFields.ID, roomId).findAll();

    for (RealmRoom realmRoom1 : realmRooms) {
        if (realmRoom1.getUnreadCount() > 0) {
            unreadMessageCount += realmRoom1.getUnreadCount();
            ++chatCount;
        }
    }

    try {
        ShortcutBadger.applyCount(G.context, unreadMessageCount);
    } catch (Exception e) {
        e.printStackTrace();
    }

    result[0] = unreadMessageCount;
    result[1] = chatCount;
    return result;
}
 
Example 3
Source File: UnreadNotificationsService.java    From ghwatch with Apache License 2.0 6 votes vote down vote up
/**
 * Call this when you want to mark android notification issued by this app as read - remove it
 */
public void markAndroidNotificationBundledDetailRead(int androidNotificationIdToCancel) {
  Utils.getNotificationManager(context).cancel(androidNotificationIdToCancel);
  long c = PreferencesUtils.getLong(context, NUM_OF_BUNDLED_ANDROID_NOTIFICATIONS,0);
  if(c>1){
    PreferencesUtils.storeLong(context, NUM_OF_BUNDLED_ANDROID_NOTIFICATIONS, --c);
  } else {
    markAndroidNotificationsRead();
  }

  int bc = PreferencesUtils.getInt(context, NUM_OF_BADGED_ANDROID_NOTIFICATIONS,0);
  if(bc>1){
    PreferencesUtils.storeInt(context, NUM_OF_BADGED_ANDROID_NOTIFICATIONS, --bc);
    ShortcutBadger.applyCount(context, bc);
  } else {
    ShortcutBadger.removeCount(context);
  }

}
 
Example 4
Source File: DefaultMessageNotifier.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
private static void updateBadge(Context context, int count) {
  try {
    if (count == 0) ShortcutBadger.removeCount(context);
    else            ShortcutBadger.applyCount(context, count);
  } catch (Throwable t) {
    // NOTE :: I don't totally trust this thing, so I'm catching
    // everything.
    Log.w(TAG, t);
  }
}
 
Example 5
Source File: ApplicationBadgeHelper.java    From react-native-push-notification-CE with MIT License 5 votes vote down vote up
private void tryAutomaticBadge(Context context, int number) {
    if (null == applyAutomaticBadger) {
        applyAutomaticBadger = ShortcutBadger.applyCount(context, number);
        if (applyAutomaticBadger) {
            FLog.i(LOG_TAG, "First attempt to use automatic badger succeeded; permanently enabling method.");
        } else {
            FLog.i(LOG_TAG, "First attempt to use automatic badger failed; permanently disabling method.");
        }
        return;
    } else if (!applyAutomaticBadger) {
        return;
    }
    ShortcutBadger.applyCount(context, number);
}
 
Example 6
Source File: NotificationManager.java    From weMessage with GNU Affero General Public License v3.0 5 votes vote down vote up
public void addUnreadMessages(String chatId, int amount){
    int unread = 0;

    if (unreadMessages.containsKey(chatId)){
        unread = unreadMessages.get(chatId);
    }

    unreadMessages.put(chatId, unread + amount);

    try {
        ShortcutBadger.applyCount(app, getTotalUnread());
    }catch (Exception ex){
        AppLogger.error("An error occurred while trying to create a badge", ex);
    }
}
 
Example 7
Source File: NotificationManager.java    From weMessage with GNU Affero General Public License v3.0 5 votes vote down vote up
public void subtractUnreadMessages(String chatId){
    unreadMessages.remove(chatId);

    try {
        ShortcutBadger.applyCount(app, getTotalUnread());
    }catch (Exception ex){
        AppLogger.error("An error occurred while trying to create a badge", ex);
    }
}
 
Example 8
Source File: HelperNotificationAndBadge.java    From iGap-Android with GNU Affero General Public License v3.0 5 votes vote down vote up
static void cleanBadge() {
    try {
        ShortcutBadger.applyCount(G.context, 0);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 9
Source File: AppUtils.java    From iGap-Android with GNU Affero General Public License v3.0 5 votes vote down vote up
public static void cleanBadge() {
    try {
        ShortcutBadger.applyCount(G.context, 0);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 10
Source File: BadgeHelper.java    From react-native-fcm with MIT License 5 votes vote down vote up
public void setBadgeCount(int badgeCount) {
    storeBadgeCount(badgeCount);
    if (badgeCount == 0) {
        ShortcutBadger.removeCount(mContext);
        Log.d(TAG, "Remove count");
    } else {
        ShortcutBadger.applyCount(mContext, badgeCount);
        Log.d(TAG, "Apply count: " + badgeCount);
    }
}
 
Example 11
Source File: FirebaseMessagingPlugin.java    From cordova-plugin-firebase-messaging with MIT License 5 votes vote down vote up
@CordovaMethod
private void setBadge(int value, CallbackContext callbackContext) {
    if (value >= 0) {
        Context context = cordova.getActivity().getApplicationContext();
        ShortcutBadger.applyCount(context, value);

        callbackContext.success();
    } else {
        callbackContext.error("Badge value can't be negative");
    }
}
 
Example 12
Source File: InputActivity.java    From AndroidAnimationExercise with Apache License 2.0 5 votes vote down vote up
@OnClick({R.id.set_badge_num, R.id.get, R.id.format, R.id.getMac1, R.id.getMac2, R.id.link})
public void Click(View view) {
    switch (view.getId()) {
        case R.id.set_badge_num:
            int count = 0;
            if (!TextUtils.isEmpty(mInput.getText().toString())) {
                count = Integer.parseInt(mInput.getText().toString());
            }

            if (ShortcutBadger.applyCount(this, count)) {
                TT.showSToast(this, "success");
            } else {
                TT.showSToast(this, "fail");
            }


            break;
        case R.id.get:
            mResult.setText(mInput.getText().toString());
            break;
        case R.id.format:
            String temp = mResult.getText().toString();

            temp = temp.replace("\n", "");

            mResult.setText(temp);
            break;
        case R.id.getMac1:
            getMacAddress1();
            break;
        case R.id.getMac2:
            getMacAddress2();
            break;
        case R.id.link:
            Toast.makeText(this, "link !", Toast.LENGTH_SHORT).show();
            break;
        default:
            break;
    }
}
 
Example 13
Source File: ApplicationBadgeHelper.java    From react-native-push-notification with MIT License 5 votes vote down vote up
private void tryAutomaticBadge(Context context, int number) {
    if (null == applyAutomaticBadger) {
        applyAutomaticBadger = ShortcutBadger.applyCount(context, number);
        if (applyAutomaticBadger) {
            FLog.i(LOG_TAG, "First attempt to use automatic badger succeeded; permanently enabling method.");
        } else {
            FLog.i(LOG_TAG, "First attempt to use automatic badger failed; permanently disabling method.");
        }
        return;
    } else if (!applyAutomaticBadger) {
        return;
    }
    ShortcutBadger.applyCount(context, number);
}
 
Example 14
Source File: UnreadNotificationsService.java    From ghwatch with Apache License 2.0 5 votes vote down vote up
protected void fireAndroidNotification(NotificationStream newStream, NotificationStream oldStream) {
  if (newStream == null || !PreferencesUtils.getBoolean(context, PreferencesUtils.PREF_NOTIFY, true))
    return;

  Log.d(TAG, "fireAndroidNotification count before filter " + newStream.size());
  newStream = filterForAndroidNotification(newStream);
  Log.d(TAG, "fireAndroidNotification count after filter " + newStream.size());
  if (newStream.isNewNotification(oldStream)) {
    ShortcutBadger.applyCount(context, newStream.size());
    PreferencesUtils.storeInt(context, NUM_OF_BADGED_ANDROID_NOTIFICATIONS, newStream.size());

    //TEST with only one notification
    if(false) {
      Notification on = newStream.get(0);
      Notification on2 = newStream.get(1);
      newStream = new NotificationStream();
      newStream.addNotification(on);
      newStream.addNotification(on2);
    }

    if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.N) {
      fireAndroidNotificationInboxStyle(newStream);
    } else {
      fireAndroidNotificationBundledStyle(newStream);
    }
    ActivityTracker.sendEvent(context, ActivityTracker.CAT_NOTIF, "new_notif", "notif count: " + newStream.size(), Long.valueOf(newStream.size()));
  } else if (newStream.isEmpty()) {
    // #54 dismiss previous android notification if no any Github notification is available (as it was read on another device)
    Utils.getNotificationManager(context).cancel(ANDROID_NOTIFICATION_MAIN_ID);
    ShortcutBadger.removeCount(context);
  }
}
 
Example 15
Source File: BadgeModule.java    From react-native-android-badge with MIT License 4 votes vote down vote up
@ReactMethod
public void setBadge(int number) {
  ShortcutBadger.applyCount(getReactApplicationContext(), number);
}