use of androidx.annotation.RequiresApi in project MPAndroidChart by PhilJay.
the class ChartAnimator method animateY.
/**
* Animates values along the Y axis.
*
* @param durationMillis animation duration
* @param easing EasingFunction
*/
@RequiresApi(11)
public void animateY(int durationMillis, EasingFunction easing) {
ObjectAnimator animatorY = yAnimator(durationMillis, easing);
animatorY.addUpdateListener(mListener);
animatorY.start();
}
use of androidx.annotation.RequiresApi in project MPAndroidChart by PhilJay.
the class ChartAnimator method yAnimator.
@RequiresApi(11)
private ObjectAnimator yAnimator(int duration, EasingFunction easing) {
ObjectAnimator animatorY = ObjectAnimator.ofFloat(this, "phaseY", 0f, 1f);
animatorY.setInterpolator(easing);
animatorY.setDuration(duration);
return animatorY;
}
use of androidx.annotation.RequiresApi in project OneSignal-Android-SDK by OneSignal.
the class GenerateNotification method createGrouplessSummaryNotification.
@RequiresApi(api = Build.VERSION_CODES.M)
private static void createGrouplessSummaryNotification(OSNotificationGenerationJob notificationJob, GenerateNotificationOpenIntent intentGenerator, int grouplessNotifCount) {
JSONObject fcmJson = notificationJob.getJsonPayload();
Notification summaryNotification;
SecureRandom random = new SecureRandom();
String group = OneSignalNotificationManager.getGrouplessSummaryKey();
String summaryMessage = grouplessNotifCount + " new messages";
int summaryNotificationId = OneSignalNotificationManager.getGrouplessSummaryId();
PendingIntent summaryContentIntent = intentGenerator.getNewActionPendingIntent(random.nextInt(), createBaseSummaryIntent(summaryNotificationId, intentGenerator, fcmJson, group));
PendingIntent summaryDeleteIntent = getNewDismissActionPendingIntent(random.nextInt(), getNewBaseDismissIntent(0).putExtra("summary", group));
NotificationCompat.Builder summaryBuilder = getBaseOneSignalNotificationBuilder(notificationJob).compatBuilder;
if (notificationJob.getOverriddenSound() != null)
summaryBuilder.setSound(notificationJob.getOverriddenSound());
if (notificationJob.getOverriddenFlags() != null)
summaryBuilder.setDefaults(notificationJob.getOverriddenFlags());
// The summary is designed to fit all notifications.
// Default small and large icons are used instead of the payload options to enforce this.
summaryBuilder.setContentIntent(summaryContentIntent).setDeleteIntent(summaryDeleteIntent).setContentTitle(currentContext.getPackageManager().getApplicationLabel(currentContext.getApplicationInfo())).setContentText(summaryMessage).setNumber(grouplessNotifCount).setSmallIcon(getDefaultSmallIconId()).setLargeIcon(getDefaultLargeIcon()).setOnlyAlertOnce(true).setAutoCancel(false).setGroup(group).setGroupSummary(true);
try {
summaryBuilder.setGroupAlertBehavior(NotificationCompat.GROUP_ALERT_SUMMARY);
} catch (Throwable t) {
// Do nothing in this case... Android support lib 26 isn't in the project
}
NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
inboxStyle.setBigContentTitle(summaryMessage);
summaryBuilder.setStyle(inboxStyle);
summaryNotification = summaryBuilder.build();
NotificationManagerCompat.from(currentContext).notify(summaryNotificationId, summaryNotification);
}
use of androidx.annotation.RequiresApi in project OneSignal-Android-SDK by OneSignal.
the class NotificationChannelManager method createChannel.
// Creates NotificationChannel and NotificationChannelGroup based on a json payload.
// Returns channel id after it is created.
// Language dependent fields will be passed localized
@RequiresApi(api = Build.VERSION_CODES.O)
private static String createChannel(Context context, NotificationManager notificationManager, JSONObject payload) throws JSONException {
// 'chnl' will be a string if coming from FCM and it will be a JSONObject when coming from
// a cold start sync.
Object objChannelPayload = payload.opt("chnl");
JSONObject channelPayload = null;
if (objChannelPayload instanceof String)
channelPayload = new JSONObject((String) objChannelPayload);
else
channelPayload = (JSONObject) objChannelPayload;
String channel_id = channelPayload.optString("id", DEFAULT_CHANNEL_ID);
// Ensure we don't try to use the system reserved id
if (channel_id.equals(NotificationChannel.DEFAULT_CHANNEL_ID))
channel_id = DEFAULT_CHANNEL_ID;
JSONObject payloadWithText = channelPayload;
if (channelPayload.has("langs")) {
JSONObject langList = channelPayload.getJSONObject("langs");
String language = LanguageContext.getInstance().getLanguage();
if (langList.has(language))
payloadWithText = langList.optJSONObject(language);
}
String channel_name = payloadWithText.optString("nm", "Miscellaneous");
int importance = priorityToImportance(payload.optInt("pri", 6));
NotificationChannel channel = new NotificationChannel(channel_id, channel_name, importance);
channel.setDescription(payloadWithText.optString("dscr", null));
if (channelPayload.has("grp_id")) {
String group_id = channelPayload.optString("grp_id");
CharSequence group_name = payloadWithText.optString("grp_nm");
notificationManager.createNotificationChannelGroup(new NotificationChannelGroup(group_id, group_name));
channel.setGroup(group_id);
}
if (payload.has("ledc")) {
String ledc = payload.optString("ledc");
Matcher matcher = hexPattern.matcher(ledc);
BigInteger ledColor;
if (!matcher.matches()) {
OneSignal.Log(OneSignal.LOG_LEVEL.WARN, "OneSignal LED Color Settings: ARGB Hex value incorrect format (E.g: FF9900FF)");
ledc = "FFFFFFFF";
}
try {
ledColor = new BigInteger(ledc, 16);
channel.setLightColor(ledColor.intValue());
} catch (Throwable t) {
OneSignal.Log(OneSignal.LOG_LEVEL.ERROR, "Couldn't convert ARGB Hex value to BigInteger:", t);
}
}
channel.enableLights(payload.optInt("led", 1) == 1);
if (payload.has("vib_pt")) {
long[] vibrationPattern = OSUtils.parseVibrationPattern(payload);
if (vibrationPattern != null)
channel.setVibrationPattern(vibrationPattern);
}
channel.enableVibration(payload.optInt("vib", 1) == 1);
if (payload.has("sound")) {
// Sound will only play if Importance is set to High or Urgent
String sound = payload.optString("sound", null);
Uri uri = OSUtils.getSoundUri(context, sound);
if (uri != null)
channel.setSound(uri, null);
else if ("null".equals(sound) || "nil".equals(sound))
channel.setSound(null, null);
// null = None for a sound.
}
// Setting sound to null makes it 'None' in the Settings.
// Otherwise not calling setSound makes it the default notification sound.
channel.setLockscreenVisibility(payload.optInt("vis", Notification.VISIBILITY_PRIVATE));
channel.setShowBadge(payload.optInt("bdg", 1) == 1);
channel.setBypassDnd(payload.optInt("bdnd", 0) == 1);
OneSignal.onesignalLog(OneSignal.LOG_LEVEL.VERBOSE, "Creating notification channel with channel:\n" + channel.toString());
try {
notificationManager.createNotificationChannel(channel);
} catch (IllegalArgumentException e) {
// TODO: Remove this try-catch once it is figured out which argument is causing Issue #895
// try-catch added to prevent crashing from the illegal argument
// Added logging above this try-catch so we can evaluate the payload of the next victim
// to report a stacktrace
// https://github.com/OneSignal/OneSignal-Android-SDK/issues/895
e.printStackTrace();
}
return channel_id;
}
use of androidx.annotation.RequiresApi in project OneSignal-Android-SDK by OneSignal.
the class NotificationLimitManager method clearOldestOverLimitStandard.
// Cancel the oldest notifications based on what the Android system reports is in the shade.
// This could be any notification, not just a OneSignal notification
@RequiresApi(api = Build.VERSION_CODES.M)
static void clearOldestOverLimitStandard(Context context, int notificationsToMakeRoomFor) throws Throwable {
StatusBarNotification[] activeNotifs = OneSignalNotificationManager.getActiveNotifications(context);
int notificationsToClear = (activeNotifs.length - getMaxNumberOfNotificationsInt()) + notificationsToMakeRoomFor;
// We have enough room in the notification shade, no need to clear any notifications
if (notificationsToClear < 1)
return;
// Create SortedMap so we can sort notifications based on display time
SortedMap<Long, Integer> activeNotifIds = new TreeMap<>();
for (StatusBarNotification activeNotif : activeNotifs) {
if (isGroupSummary(activeNotif))
continue;
activeNotifIds.put(activeNotif.getNotification().when, activeNotif.getId());
}
// Clear the oldest based on the count in notificationsToClear
for (Map.Entry<Long, Integer> mapData : activeNotifIds.entrySet()) {
OneSignal.removeNotification(mapData.getValue());
if (--notificationsToClear <= 0)
break;
}
}
Aggregations