Added Compatibility class level 28
This commit is contained in:
parent
1e6fb279c0
commit
601259f15e
4 changed files with 113 additions and 4 deletions
|
@ -0,0 +1,101 @@
|
|||
package org.linphone.compatibility;
|
||||
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.Notification;
|
||||
import android.app.PendingIntent;
|
||||
import android.app.Person;
|
||||
import android.app.RemoteInput;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Bitmap;
|
||||
|
||||
import org.linphone.R;
|
||||
import org.linphone.notifications.Notifiable;
|
||||
import org.linphone.notifications.NotifiableMessage;
|
||||
import org.linphone.notifications.NotificationBroadcastReceiver;
|
||||
|
||||
import static org.linphone.compatibility.Compatibility.INTENT_ANSWER_CALL_NOTIF_ACTION;
|
||||
import static org.linphone.compatibility.Compatibility.INTENT_CALL_ID;
|
||||
import static org.linphone.compatibility.Compatibility.INTENT_HANGUP_CALL_NOTIF_ACTION;
|
||||
import static org.linphone.compatibility.Compatibility.INTENT_LOCAL_IDENTITY;
|
||||
import static org.linphone.compatibility.Compatibility.INTENT_NOTIF_ID;
|
||||
import static org.linphone.compatibility.Compatibility.INTENT_REPLY_NOTIF_ACTION;
|
||||
import static org.linphone.compatibility.Compatibility.KEY_TEXT_REPLY;
|
||||
|
||||
/*
|
||||
ApiTwentyEightPlus.java
|
||||
Copyright (C) 2017 Belledonne Communications, Grenoble, France
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
@TargetApi(28)
|
||||
public class ApiTwentyEightPlus {
|
||||
|
||||
public static Notification createRepliedNotification(Context context, String reply) {
|
||||
return new Notification.Builder(context)
|
||||
.setSmallIcon(R.drawable.topbar_chat_notification)
|
||||
.setContentText(context.getString(R.string.notification_replied_label).replace("%s", reply))
|
||||
.build();
|
||||
}
|
||||
|
||||
public static Notification createMessageNotification(Context context, Notifiable notif, Bitmap contactIcon, PendingIntent intent) {
|
||||
String replyLabel = context.getResources().getString(R.string.notification_reply_label);
|
||||
RemoteInput remoteInput = new RemoteInput.Builder(KEY_TEXT_REPLY).setLabel(replyLabel).build();
|
||||
|
||||
Intent replyIntent = new Intent(context, NotificationBroadcastReceiver.class);
|
||||
replyIntent.setAction(INTENT_REPLY_NOTIF_ACTION);
|
||||
replyIntent.putExtra(INTENT_NOTIF_ID, notif.getNotificationId());
|
||||
replyIntent.putExtra(INTENT_LOCAL_IDENTITY, notif.getLocalIdentity());
|
||||
|
||||
PendingIntent replyPendingIntent = PendingIntent.getBroadcast(context,
|
||||
notif.getNotificationId(), replyIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
|
||||
Notification.Action action = new Notification.Action.Builder(R.drawable.chat_send_over,
|
||||
context.getString(R.string.notification_reply_label), replyPendingIntent)
|
||||
.addRemoteInput(remoteInput)
|
||||
.setAllowGeneratedReplies(true)
|
||||
.build();
|
||||
|
||||
Person me = new Person.Builder().setName(notif.getMyself()).build();
|
||||
Notification.MessagingStyle style = new Notification.MessagingStyle(me);
|
||||
for (NotifiableMessage message : notif.getMessages()) {
|
||||
Person user = new Person.Builder().setName(message.getSender()).build();
|
||||
style.addMessage(message.getMessage(), message.getTime(), user);
|
||||
}
|
||||
if (notif.isGroup()) {
|
||||
style.setConversationTitle(notif.getGroupTitle());
|
||||
}
|
||||
style.setGroupConversation(notif.isGroup());
|
||||
|
||||
return new Notification.Builder(context)
|
||||
.setSmallIcon(R.drawable.topbar_chat_notification)
|
||||
.setAutoCancel(true)
|
||||
.setContentIntent(intent)
|
||||
.setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE)
|
||||
.setLargeIcon(contactIcon)
|
||||
.setCategory(Notification.CATEGORY_MESSAGE)
|
||||
.setVisibility(Notification.VISIBILITY_PRIVATE)
|
||||
.setPriority(Notification.PRIORITY_HIGH)
|
||||
.setNumber(notif.getMessages().size())
|
||||
.setWhen(System.currentTimeMillis())
|
||||
.setShowWhen(true)
|
||||
.setColor(context.getColor(R.color.notification_color_led))
|
||||
.setStyle(style)
|
||||
.addAction(action)
|
||||
.build();
|
||||
}
|
||||
}
|
|
@ -73,7 +73,9 @@ public class ApiTwentyFourPlus {
|
|||
for (NotifiableMessage message : notif.getMessages()) {
|
||||
style.addMessage(message.getMessage(), message.getTime(), message.getSender());
|
||||
}
|
||||
style.setConversationTitle(notif.getGroupTitle());
|
||||
if (notif.isGroup()) {
|
||||
style.setConversationTitle(notif.getGroupTitle());
|
||||
}
|
||||
|
||||
return new Notification.Builder(context)
|
||||
.setSmallIcon(R.drawable.topbar_chat_notification)
|
||||
|
|
|
@ -106,7 +106,9 @@ public class ApiTwentySixPlus {
|
|||
for (NotifiableMessage message : notif.getMessages()) {
|
||||
style.addMessage(message.getMessage(), message.getTime(), message.getSender());
|
||||
}
|
||||
style.setConversationTitle(notif.getGroupTitle());
|
||||
if (notif.isGroup()) {
|
||||
style.setConversationTitle(notif.getGroupTitle());
|
||||
}
|
||||
|
||||
return new Notification.Builder(context, context.getString(R.string.notification_channel_id))
|
||||
.setSmallIcon(R.drawable.topbar_chat_notification)
|
||||
|
|
|
@ -62,7 +62,9 @@ public class Compatibility {
|
|||
}
|
||||
|
||||
public static Notification createMessageNotification(Context context, Notifiable notif, String msgSender, String msg, Bitmap contactIcon, PendingIntent intent) {
|
||||
if (Version.sdkAboveOrEqual(Version.API26_O_80)) {
|
||||
if (Version.sdkAboveOrEqual(28)) {
|
||||
return ApiTwentyEightPlus.createMessageNotification(context, notif, contactIcon, intent);
|
||||
} else if (Version.sdkAboveOrEqual(Version.API26_O_80)) {
|
||||
return ApiTwentySixPlus.createMessageNotification(context, notif, contactIcon, intent);
|
||||
} else if (Version.sdkAboveOrEqual(Version.API24_NOUGAT_70)) {
|
||||
return ApiTwentyFourPlus.createMessageNotification(context, notif, contactIcon, intent);
|
||||
|
@ -71,7 +73,9 @@ public class Compatibility {
|
|||
}
|
||||
|
||||
public static Notification createRepliedNotification(Context context, String reply) {
|
||||
if (Version.sdkAboveOrEqual(Version.API26_O_80)) {
|
||||
if (Version.sdkAboveOrEqual(28)) {
|
||||
return ApiTwentyEightPlus.createRepliedNotification(context, reply);
|
||||
} else if (Version.sdkAboveOrEqual(Version.API26_O_80)) {
|
||||
return ApiTwentySixPlus.createRepliedNotification(context, reply);
|
||||
} else if (Version.sdkAboveOrEqual(Version.API24_NOUGAT_70)) {
|
||||
return ApiTwentyFourPlus.createRepliedNotification(context, reply);
|
||||
|
|
Loading…
Reference in a new issue