Fix notification background color
This commit is contained in:
parent
d734e93ed2
commit
182ecba4b7
1 changed files with 150 additions and 156 deletions
|
@ -36,176 +36,170 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
@TargetApi(26)
|
@TargetApi(26)
|
||||||
public class ApiTwentySixPlus {
|
public class ApiTwentySixPlus {
|
||||||
|
|
||||||
public static void CreateChannel(Context context) {
|
public static void CreateChannel(Context context) {
|
||||||
NotificationManager notificationManager =
|
NotificationManager notificationManager =
|
||||||
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||||
// Create service/call notification channel
|
// Create service/call notification channel
|
||||||
String id = context.getString(R.string.notification_service_channel_id);
|
String id = context.getString(R.string.notification_service_channel_id);
|
||||||
CharSequence name = context.getString(R.string.content_title_notification_service);
|
CharSequence name = context.getString(R.string.content_title_notification_service);
|
||||||
String description = context.getString(R.string.content_title_notification_service);
|
String description = context.getString(R.string.content_title_notification_service);
|
||||||
int importance = NotificationManager.IMPORTANCE_NONE;
|
int importance = NotificationManager.IMPORTANCE_NONE;
|
||||||
NotificationChannel mChannel = new NotificationChannel(id, name, importance);
|
NotificationChannel mChannel = new NotificationChannel(id, name, importance);
|
||||||
mChannel.setDescription(description);
|
mChannel.setDescription(description);
|
||||||
mChannel.enableVibration(false);
|
mChannel.enableVibration(false);
|
||||||
mChannel.enableLights(false);
|
mChannel.enableLights(false);
|
||||||
notificationManager.createNotificationChannel(mChannel);
|
notificationManager.createNotificationChannel(mChannel);
|
||||||
// Create message notification channel
|
// Create message notification channel
|
||||||
id = context.getString(R.string.notification_channel_id);
|
id = context.getString(R.string.notification_channel_id);
|
||||||
name = context.getString(R.string.content_title_notification);
|
name = context.getString(R.string.content_title_notification);
|
||||||
description = context.getString(R.string.content_title_notification);
|
description = context.getString(R.string.content_title_notification);
|
||||||
importance = NotificationManager.IMPORTANCE_HIGH;
|
importance = NotificationManager.IMPORTANCE_HIGH;
|
||||||
mChannel = new NotificationChannel(id, name, importance);
|
mChannel = new NotificationChannel(id, name, importance);
|
||||||
mChannel.setDescription(description);
|
mChannel.setDescription(description);
|
||||||
mChannel.enableLights(true);
|
mChannel.setLightColor(context.getColor(R.color.notification_color_led));
|
||||||
mChannel.setLightColor(context.getColor(R.color.notification_color_led));
|
mChannel.enableLights(true);
|
||||||
mChannel.enableLights(true);
|
notificationManager.createNotificationChannel(mChannel);
|
||||||
notificationManager.createNotificationChannel(mChannel);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public static Notification createMessageNotification(Context context,
|
public static Notification createMessageNotification(Context context,
|
||||||
int msgCount, String msgSender, String msg, Bitmap contactIcon,
|
int msgCount, String msgSender, String msg, Bitmap contactIcon,
|
||||||
PendingIntent intent) {
|
PendingIntent intent) {
|
||||||
String title;
|
String title;
|
||||||
if (msgCount == 1) {
|
if (msgCount == 1) {
|
||||||
title = msgSender;
|
title = msgSender;
|
||||||
} else {
|
} else {
|
||||||
title = context.getString(R.string.unread_messages).replace("%i", String.valueOf(msgCount));
|
title = context.getString(R.string.unread_messages).replace("%i", String.valueOf(msgCount));
|
||||||
}
|
}
|
||||||
|
|
||||||
Notification notif = null;
|
Notification notif = null;
|
||||||
notif = new Notification.Builder(context, context.getString(R.string.notification_channel_id))
|
notif = new Notification.Builder(context, context.getString(R.string.notification_channel_id))
|
||||||
.setContentTitle(title)
|
.setContentTitle(title)
|
||||||
.setContentText(msg)
|
.setContentText(msg)
|
||||||
.setSmallIcon(R.drawable.topbar_chat_notification)
|
.setSmallIcon(R.drawable.topbar_chat_notification)
|
||||||
.setAutoCancel(true)
|
.setAutoCancel(true)
|
||||||
.setContentIntent(intent)
|
.setContentIntent(intent)
|
||||||
.setDefaults(Notification.DEFAULT_SOUND
|
.setDefaults(Notification.DEFAULT_SOUND
|
||||||
| Notification.DEFAULT_VIBRATE)
|
| Notification.DEFAULT_VIBRATE)
|
||||||
.setLargeIcon(contactIcon)
|
.setLargeIcon(contactIcon)
|
||||||
.setCategory(Notification.CATEGORY_MESSAGE)
|
.setCategory(Notification.CATEGORY_MESSAGE)
|
||||||
.setVisibility(Notification.VISIBILITY_PRIVATE)
|
.setVisibility(Notification.VISIBILITY_PRIVATE)
|
||||||
.setPriority(Notification.PRIORITY_HIGH)
|
.setPriority(Notification.PRIORITY_HIGH)
|
||||||
.setNumber(msgCount)
|
.setNumber(msgCount)
|
||||||
.setWhen(System.currentTimeMillis())
|
.setWhen(System.currentTimeMillis())
|
||||||
.setShowWhen(true)
|
.setShowWhen(true)
|
||||||
.setColorized(true)
|
.setColor(context.getColor(R.color.notification_color_led))
|
||||||
.setColor(context.getColor(R.color.notification_color_led))
|
.build();
|
||||||
.build();
|
|
||||||
|
|
||||||
return notif;
|
return notif;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Notification createInCallNotification(Context context,
|
public static Notification createInCallNotification(Context context,
|
||||||
String title, String msg, int iconID, Bitmap contactIcon,
|
String title, String msg, int iconID, Bitmap contactIcon,
|
||||||
String contactName, PendingIntent intent) {
|
String contactName, PendingIntent intent) {
|
||||||
|
|
||||||
Notification notif = new Notification.Builder(context, context.getString(R.string.notification_service_channel_id))
|
Notification notif = new Notification.Builder(context, context.getString(R.string.notification_service_channel_id))
|
||||||
.setContentTitle(contactName)
|
.setContentTitle(contactName)
|
||||||
.setContentText(msg)
|
.setContentText(msg)
|
||||||
.setSmallIcon(iconID)
|
.setSmallIcon(iconID)
|
||||||
.setAutoCancel(false)
|
.setAutoCancel(false)
|
||||||
.setContentIntent(intent)
|
.setContentIntent(intent)
|
||||||
.setLargeIcon(contactIcon)
|
.setLargeIcon(contactIcon)
|
||||||
.setCategory(Notification.CATEGORY_CALL)
|
.setCategory(Notification.CATEGORY_CALL)
|
||||||
.setVisibility(Notification.VISIBILITY_PUBLIC)
|
.setVisibility(Notification.VISIBILITY_PUBLIC)
|
||||||
.setPriority(Notification.PRIORITY_HIGH)
|
.setPriority(Notification.PRIORITY_HIGH)
|
||||||
.setWhen(System.currentTimeMillis())
|
.setWhen(System.currentTimeMillis())
|
||||||
.setShowWhen(true)
|
.setShowWhen(true)
|
||||||
.setColorized(true)
|
.setColor(context.getColor(R.color.notification_color_led))
|
||||||
.setColor(context.getColor(R.color.notification_color_led))
|
.build();
|
||||||
.build();
|
|
||||||
|
|
||||||
return notif;
|
return notif;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Notification createNotification(Context context, String title, String message, int icon, int level, Bitmap largeIcon, PendingIntent intent, boolean isOngoingEvent, int priority) {
|
public static Notification createNotification(Context context, String title, String message, int icon, int level, Bitmap largeIcon, PendingIntent intent, boolean isOngoingEvent,int priority) {
|
||||||
Notification notif;
|
Notification notif;
|
||||||
|
|
||||||
if (largeIcon != null) {
|
if (largeIcon != null) {
|
||||||
notif = new Notification.Builder(context, context.getString(R.string.notification_service_channel_id))
|
notif = new Notification.Builder(context, context.getString(R.string.notification_service_channel_id))
|
||||||
.setContentTitle(title)
|
.setContentTitle(title)
|
||||||
.setContentText(message)
|
.setContentText(message)
|
||||||
.setSmallIcon(icon, level)
|
.setSmallIcon(icon, level)
|
||||||
.setLargeIcon(largeIcon)
|
.setLargeIcon(largeIcon)
|
||||||
.setContentIntent(intent)
|
.setContentIntent(intent)
|
||||||
.setCategory(Notification.CATEGORY_SERVICE)
|
.setCategory(Notification.CATEGORY_SERVICE)
|
||||||
.setVisibility(Notification.VISIBILITY_SECRET)
|
.setVisibility(Notification.VISIBILITY_SECRET)
|
||||||
.setPriority(priority)
|
.setPriority(priority)
|
||||||
.setWhen(System.currentTimeMillis())
|
.setWhen(System.currentTimeMillis())
|
||||||
.setShowWhen(true)
|
.setShowWhen(true)
|
||||||
.setColorized(true)
|
.setColor(context.getColor(R.color.notification_color_led))
|
||||||
.setColor(context.getColor(R.color.notification_color_led))
|
.build();
|
||||||
.build();
|
} else {
|
||||||
} else {
|
notif = new Notification.Builder(context, context.getString(R.string.notification_service_channel_id))
|
||||||
notif = new Notification.Builder(context, context.getString(R.string.notification_service_channel_id))
|
.setContentTitle(title)
|
||||||
.setContentTitle(title)
|
.setContentText(message)
|
||||||
.setContentText(message)
|
.setSmallIcon(icon, level)
|
||||||
.setSmallIcon(icon, level)
|
.setContentIntent(intent)
|
||||||
.setContentIntent(intent)
|
.setCategory(Notification.CATEGORY_SERVICE)
|
||||||
.setCategory(Notification.CATEGORY_SERVICE)
|
.setVisibility(Notification.VISIBILITY_SECRET)
|
||||||
.setVisibility(Notification.VISIBILITY_SECRET)
|
.setPriority(priority)
|
||||||
.setPriority(priority)
|
.setWhen(System.currentTimeMillis())
|
||||||
.setWhen(System.currentTimeMillis())
|
.setShowWhen(true)
|
||||||
.setShowWhen(true)
|
.setColor(context.getColor(R.color.notification_color_led))
|
||||||
.setColorized(true)
|
.build();
|
||||||
.setColor(context.getColor(R.color.notification_color_led))
|
}
|
||||||
.build();
|
|
||||||
}
|
|
||||||
|
|
||||||
return notif;
|
return notif;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void removeGlobalLayoutListener(ViewTreeObserver viewTreeObserver, ViewTreeObserver.OnGlobalLayoutListener keyboardListener) {
|
public static void removeGlobalLayoutListener(ViewTreeObserver viewTreeObserver, ViewTreeObserver.OnGlobalLayoutListener keyboardListener) {
|
||||||
viewTreeObserver.removeOnGlobalLayoutListener(keyboardListener);
|
viewTreeObserver.removeOnGlobalLayoutListener(keyboardListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Notification createMissedCallNotification(Context context, String title, String text, PendingIntent intent) {
|
public static Notification createMissedCallNotification(Context context, String title, String text, PendingIntent intent) {
|
||||||
Notification notif = new Notification.Builder(context, context.getString(R.string.notification_channel_id))
|
Notification notif = new Notification.Builder(context, context.getString(R.string.notification_channel_id))
|
||||||
.setContentTitle(title)
|
.setContentTitle(title)
|
||||||
.setContentText(text)
|
.setContentText(text)
|
||||||
.setSmallIcon(R.drawable.call_status_missed)
|
.setSmallIcon(R.drawable.call_status_missed)
|
||||||
.setAutoCancel(true)
|
.setAutoCancel(true)
|
||||||
.setContentIntent(intent)
|
.setContentIntent(intent)
|
||||||
.setDefaults(Notification.DEFAULT_SOUND
|
.setDefaults(Notification.DEFAULT_SOUND
|
||||||
| Notification.DEFAULT_VIBRATE)
|
| Notification.DEFAULT_VIBRATE)
|
||||||
.setCategory(Notification.CATEGORY_MESSAGE)
|
.setCategory(Notification.CATEGORY_MESSAGE)
|
||||||
.setVisibility(Notification.VISIBILITY_PRIVATE)
|
.setVisibility(Notification.VISIBILITY_PRIVATE)
|
||||||
.setPriority(Notification.PRIORITY_HIGH)
|
.setPriority(Notification.PRIORITY_HIGH)
|
||||||
.setWhen(System.currentTimeMillis())
|
.setWhen(System.currentTimeMillis())
|
||||||
.setShowWhen(true)
|
.setShowWhen(true)
|
||||||
.setColorized(true)
|
.setColor(context.getColor(R.color.notification_color_led))
|
||||||
.setColor(context.getColor(R.color.notification_color_led))
|
.build();
|
||||||
.build();
|
|
||||||
|
|
||||||
return notif;
|
return notif;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Notification createSimpleNotification(Context context, String title, String text, PendingIntent intent) {
|
public static Notification createSimpleNotification(Context context, String title, String text, PendingIntent intent) {
|
||||||
Notification notif = new Notification.Builder(context, context.getString(R.string.notification_channel_id))
|
Notification notif = new Notification.Builder(context, context.getString(R.string.notification_channel_id))
|
||||||
.setContentTitle(title)
|
.setContentTitle(title)
|
||||||
.setContentText(text)
|
.setContentText(text)
|
||||||
.setSmallIcon(R.drawable.linphone_logo)
|
.setSmallIcon(R.drawable.linphone_logo)
|
||||||
.setAutoCancel(true)
|
.setAutoCancel(true)
|
||||||
.setContentIntent(intent)
|
.setContentIntent(intent)
|
||||||
.setDefaults(Notification.DEFAULT_SOUND
|
.setDefaults(Notification.DEFAULT_SOUND
|
||||||
| Notification.DEFAULT_VIBRATE)
|
| Notification.DEFAULT_VIBRATE)
|
||||||
.setCategory(Notification.CATEGORY_MESSAGE)
|
.setCategory(Notification.CATEGORY_MESSAGE)
|
||||||
.setVisibility(Notification.VISIBILITY_PRIVATE)
|
.setVisibility(Notification.VISIBILITY_PRIVATE)
|
||||||
.setPriority(Notification.PRIORITY_HIGH)
|
.setPriority(Notification.PRIORITY_HIGH)
|
||||||
.setWhen(System.currentTimeMillis())
|
.setWhen(System.currentTimeMillis())
|
||||||
.setShowWhen(true)
|
.setShowWhen(true)
|
||||||
.setColorized(true)
|
.setColorized(true)
|
||||||
.setColor(context.getColor(R.color.notification_color_led))
|
.setColor(context.getColor(R.color.notification_color_led))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
return notif;
|
return notif;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void startService(Context context, Intent intent) {
|
public static void startService(Context context, Intent intent) {
|
||||||
context.startForegroundService(intent);
|
context.startForegroundService(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setFragmentTransactionReorderingAllowed(FragmentTransaction transaction, boolean allowed) {
|
public static void setFragmentTransactionReorderingAllowed(FragmentTransaction transaction, boolean allowed) {
|
||||||
transaction.setReorderingAllowed(allowed);
|
transaction.setReorderingAllowed(allowed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue