本文整理汇总了Java中me.leolin.shortcutbadger.ShortcutBadger类的典型用法代码示例。如果您正苦于以下问题:Java ShortcutBadger类的具体用法?Java ShortcutBadger怎么用?Java ShortcutBadger使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ShortcutBadger类属于me.leolin.shortcutbadger包,在下文中一共展示了ShortcutBadger类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setBadgeNumber
import me.leolin.shortcutbadger.ShortcutBadger; //导入依赖的package包/类
public void setBadgeNumber(final CallbackContext callbackContext, final int number) {
mFirebase.cordova.getThreadPool().execute(new Runnable() {
public void run() {
try {
Log.i(TAG, "Setting badge number " + number);
Context context = mFirebase.cordova.getActivity();
SharedPreferences.Editor editor = context.getSharedPreferences(KEY, Context.MODE_PRIVATE).edit();
editor.putInt(KEY, number);
editor.apply();
ShortcutBadger.applyCount(context, number);
callbackContext.success();
} catch (Exception e) {
Log.e(TAG, "Error setting badge number " + number);
callbackContext.error(e.getMessage());
}
}
});
}
示例2: updateBadgerCount
import me.leolin.shortcutbadger.ShortcutBadger; //导入依赖的package包/类
public static void updateBadgerCount(final int unreadCount) {
if (handler == null) {
handler = Handlers.sharedInstance().newHandler("Badger");
}
handler.removeCallbacksAndMessages(null);
handler.postDelayed(new Runnable() {
@Override
public void run() {
int badgerCount = unreadCount;
if (badgerCount < 0) {
badgerCount = 0;
} else if (badgerCount > 999) {
badgerCount = 999;
}
boolean res = ShortcutBadger.applyCount(NimUIKit.getContext(), badgerCount);
Log.i(TAG, "update badger count " + (res ? "success" : "failed"));
}
}, 200);
}
示例3: updateUnreadCountBadge
import me.leolin.shortcutbadger.ShortcutBadger; //导入依赖的package包/类
public synchronized void updateUnreadCountBadge() {
new Thread(new Runnable() {
@Override
public void run() {
int count = unreadCount();
if (unreadCount != count) {
Log.d(Config.LOGTAG, "update unread count to " + count);
if (count > 0) {
ShortcutBadger.applyCount(getApplicationContext(), count);
} else {
ShortcutBadger.removeCount(getApplicationContext());
}
unreadCount = count;
}
}
}).start();
}
示例4: markAndroidNotificationBundledDetailRead
import me.leolin.shortcutbadger.ShortcutBadger; //导入依赖的package包/类
/**
* 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);
}
}
示例5: onResume
import me.leolin.shortcutbadger.ShortcutBadger; //导入依赖的package包/类
@Override
protected void onResume() {
super.onResume();
/** Register for broadcast action if you need to be notified when Countly message received */
messageReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Message message = intent.getParcelableExtra(CountlyMessaging.BROADCAST_RECEIVER_ACTION_MESSAGE);
Log.i("CountlyActivity", "Got a message with data: " + message.getData());
//Badge related things
Bundle data = message.getData();
String badgeString = data.getString("badge");
try {
if(badgeString != null) {
int badgeCount = Integer.parseInt(badgeString);
boolean succeded = ShortcutBadger.applyCount(getApplicationContext(), badgeCount);
if (!succeded) {
Toast.makeText(getApplicationContext(), "Unable to put badge", Toast.LENGTH_SHORT).show();
}
}
} catch (NumberFormatException exception) {
Toast.makeText(getApplicationContext(), "Unable to parse given badge number", Toast.LENGTH_SHORT).show();
}
}
};
IntentFilter filter = new IntentFilter();
filter.addAction(CountlyMessaging.getBroadcastAction(getApplicationContext()));
registerReceiver(messageReceiver, filter);
}
示例6: updateBadge
import me.leolin.shortcutbadger.ShortcutBadger; //导入依赖的package包/类
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("MessageNotifier", t);
}
}
示例7: tryAutomaticBadge
import me.leolin.shortcutbadger.ShortcutBadger; //导入依赖的package包/类
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);
}
示例8: updateUnreadCountBadge
import me.leolin.shortcutbadger.ShortcutBadger; //导入依赖的package包/类
public synchronized void updateUnreadCountBadge() {
int count = unreadCount();
if (unreadCount != count) {
Log.d(Config.LOGTAG, "update unread count to " + count);
if (count > 0) {
ShortcutBadger.applyCount(getApplicationContext(), count);
} else {
ShortcutBadger.removeCount(getApplicationContext());
}
unreadCount = count;
}
}
示例9: setBadgeCount
import me.leolin.shortcutbadger.ShortcutBadger; //导入依赖的package包/类
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);
}
}
示例10: Click
import me.leolin.shortcutbadger.ShortcutBadger; //导入依赖的package包/类
@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)) {
T.showSToast(this, "success");
} else {
T.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;
}
}
示例11: updateUnreadCountBadge
import me.leolin.shortcutbadger.ShortcutBadger; //导入依赖的package包/类
public synchronized void updateUnreadCountBadge() {
int count = unreadCount();
if (unreadCount != count) {
Log.d(Config.LOGTAG, "update unread count to " + count);
if (count > 0) {
ShortcutBadger.with(getApplicationContext()).count(count);
} else {
ShortcutBadger.with(getApplicationContext()).remove();
}
unreadCount = count;
}
}
示例12: updateBadge
import me.leolin.shortcutbadger.ShortcutBadger; //导入依赖的package包/类
private static void updateBadge(Context context, int count) {
try {
ShortcutBadger.setBadge(context, count);
} catch (Throwable t) {
// NOTE :: I don't totally trust this thing, so I'm catching
// everything.
Log.w("MessageNotifier", t);
}
}
示例13: allUserMessageAlreadyRead
import me.leolin.shortcutbadger.ShortcutBadger; //导入依赖的package包/类
/**
* user read all user message in other device so should clear unread indicator from all user message
*
* @param userId
*/
private void allUserMessageAlreadyRead(String userId) {
Realm realm = Realm.getDefaultInstance();
RealmResults<MessageModelRealm> unreadMessageForIterating = realm.where(MessageModelRealm.class).equalTo("withUserId", userId).equalTo("youAreFirst", true).equalTo("isSendReadSignal", false).findAll();
ArrayList<String> listOfMessageId = new ArrayList<>();
for (int i = 0; i < unreadMessageForIterating.size(); i++) {
listOfMessageId.add(unreadMessageForIterating.get(i).getMessageId());
}
if (listOfMessageId.size() > 0) {
realm.beginTransaction();
for (int i = 0; i < listOfMessageId.size(); i++) {
MessageModelRealm messageModelRealm = realm.where(MessageModelRealm.class).equalTo("messageId", listOfMessageId.get(i)).findFirst();
if (messageModelRealm != null) {
messageModelRealm.setIsSendReadSignal(true);
}
}
realm.commitTransaction();
}
//clear notification and badger number for this user
UserMessageNotificationRealmModel notificationRealmModelByUserId = realm.where(UserMessageNotificationRealmModel.class).equalTo("fromUserId", userId).findFirst();
if (notificationRealmModelByUserId != null) {
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(TApplication.applicationContext);
notificationManager.cancel(notificationRealmModelByUserId.getNotificationId());
realm.beginTransaction();
notificationRealmModelByUserId.setNumberOfNotification(0);
notificationRealmModelByUserId.setNotificationBody("");
realm.commitTransaction();
}
mAppPreferenceTools.setApplicationBadgerNumber(0);
ShortcutBadger.with(TApplication.applicationContext).count(0);
realm.close();
//set signal for update from DB
Intent messageIntent = new Intent(Constants.ACTION_TO_DO_FOR_MESSAGE_UPDATE_INTENT_FILTER);
messageIntent.putExtra(Constants.ACTION_TO_DO_PARAM, Constants.UPDATE_FROM_DB);
mLocalBroadcastManager.sendBroadcast(messageIntent);
}
示例14: onHandleIntent
import me.leolin.shortcutbadger.ShortcutBadger; //导入依赖的package包/类
@Override
protected void onHandleIntent(Intent intent) {
if (UNREAD_COUNT_UPDATED.equals(intent.getAction())) {
ShortcutBadger.with(getApplicationContext()).count(SmsHelper.getUnreadMessageCount(this));
WidgetProvider.notifyDatasetChanged(this);
}
}
示例15: logout
import me.leolin.shortcutbadger.ShortcutBadger; //导入依赖的package包/类
/**
* Logout the current user.
* @param activity the caller activity
*/
public static void logout(Activity activity) {
stopEventStream(activity);
try {
ShortcutBadger.setBadge(activity, 0);
} catch (Exception e) {
}
// warn that the user logs out
Collection<MXSession> sessions = Matrix.getMXSessions(activity);
for(MXSession session : sessions) {
// Publish to the server that we're now offline
MyPresenceManager.getInstance(activity, session).advertiseOffline();
MyPresenceManager.remove(session);
}
// clear the preferences
PreferenceManager.getDefaultSharedPreferences(activity).edit().clear().commit();
// reset the GCM
Matrix.getInstance(activity).getSharedGcmRegistrationManager().reset();
// clear credentials
Matrix.getInstance(activity).clearSessions(activity, true);
// ensure that corrupted values are cleared
Matrix.getInstance(activity).getLoginStorage().clear();
// reset the contacts
PIDsRetriever.getIntance().reset();
ContactsManager.reset();
MXMediasCache.clearThumbnailsCache(activity);
// go to login page
activity.startActivity(new Intent(activity, LoginActivity.class));
activity.finish();
}