Updated target version and added categories to notifications
This commit is contained in:
parent
540a1c6fb4
commit
c5fce75e94
4 changed files with 124 additions and 5 deletions
|
@ -2,7 +2,7 @@
|
|||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="org.linphone"
|
||||
android:versionCode="2302" android:installLocation="auto">
|
||||
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="19"/>
|
||||
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="22"/>
|
||||
|
||||
<!-- Permissions for Push Notification -->
|
||||
<permission android:name="org.linphone.permission.C2D_MESSAGE" android:protectionLevel="signature" /> <!-- Change package ! -->
|
||||
|
|
113
src/org/linphone/compatibility/ApiTwentyOnePlus.java
Normal file
113
src/org/linphone/compatibility/ApiTwentyOnePlus.java
Normal file
|
@ -0,0 +1,113 @@
|
|||
package org.linphone.compatibility;
|
||||
|
||||
import org.linphone.R;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.Notification;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.view.ViewTreeObserver;
|
||||
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
|
||||
/*
|
||||
ApiTwentyOnePlus.java
|
||||
Copyright (C) 2012 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
/**
|
||||
* @author Sylvain Berfini
|
||||
*/
|
||||
@TargetApi(21)
|
||||
public class ApiTwentyOnePlus {
|
||||
|
||||
public static Notification createMessageNotification(Context context,
|
||||
int msgCount, String msgSender, String msg, Bitmap contactIcon,
|
||||
PendingIntent intent) {
|
||||
String title;
|
||||
if (msgCount == 1) {
|
||||
title = msgSender;
|
||||
} else {
|
||||
title = context.getString(R.string.unread_messages).replace("%i", String.valueOf(msgCount));
|
||||
}
|
||||
|
||||
Notification notif = new Notification.Builder(context)
|
||||
.setContentTitle(title)
|
||||
.setContentText(msg)
|
||||
.setSmallIcon(R.drawable.chat_icon_over)
|
||||
.setAutoCancel(true)
|
||||
.setContentIntent(intent)
|
||||
.setDefaults(
|
||||
Notification.DEFAULT_LIGHTS
|
||||
| Notification.DEFAULT_SOUND
|
||||
| Notification.DEFAULT_VIBRATE)
|
||||
.setWhen(System.currentTimeMillis())
|
||||
.setLargeIcon(contactIcon)
|
||||
.setCategory(Notification.CATEGORY_MESSAGE)
|
||||
.build();
|
||||
|
||||
return notif;
|
||||
}
|
||||
|
||||
public static Notification createInCallNotification(Context context,
|
||||
String title, String msg, int iconID, Bitmap contactIcon,
|
||||
String contactName, PendingIntent intent) {
|
||||
|
||||
Notification notif = new Notification.Builder(context).setContentTitle(contactName)
|
||||
.setContentText(msg).setSmallIcon(iconID)
|
||||
.setAutoCancel(false)
|
||||
.setContentIntent(intent)
|
||||
.setWhen(System.currentTimeMillis())
|
||||
.setLargeIcon(contactIcon)
|
||||
.setCategory(Notification.CATEGORY_CALL)
|
||||
.build();
|
||||
notif.flags |= Notification.FLAG_ONGOING_EVENT;
|
||||
|
||||
return notif;
|
||||
}
|
||||
|
||||
public static Notification createNotification(Context context, String title, String message, int icon, int level, Bitmap largeIcon, PendingIntent intent, boolean isOngoingEvent) {
|
||||
Notification notif;
|
||||
|
||||
if (largeIcon != null) {
|
||||
notif = new Notification.Builder(context)
|
||||
.setContentTitle(title)
|
||||
.setContentText(message)
|
||||
.setSmallIcon(icon, level)
|
||||
.setLargeIcon(largeIcon)
|
||||
.setContentIntent(intent)
|
||||
.setWhen(System.currentTimeMillis())
|
||||
.build();
|
||||
} else {
|
||||
notif = new Notification.Builder(context)
|
||||
.setContentTitle(title)
|
||||
.setContentText(message)
|
||||
.setSmallIcon(icon, level)
|
||||
.setContentIntent(intent)
|
||||
.setWhen(System.currentTimeMillis())
|
||||
.setCategory(Notification.CATEGORY_SERVICE)
|
||||
.build();
|
||||
}
|
||||
if (isOngoingEvent) {
|
||||
notif.flags |= Notification.FLAG_ONGOING_EVENT;
|
||||
}
|
||||
|
||||
return notif;
|
||||
}
|
||||
|
||||
public static void removeGlobalLayoutListener(ViewTreeObserver viewTreeObserver, OnGlobalLayoutListener keyboardListener) {
|
||||
viewTreeObserver.removeOnGlobalLayoutListener(keyboardListener);
|
||||
}
|
||||
}
|
|
@ -162,7 +162,9 @@ public class Compatibility {
|
|||
title = "%i unread messages".replace("%i", String.valueOf(msgCount));
|
||||
}
|
||||
|
||||
if (Version.sdkAboveOrEqual(Version.API16_JELLY_BEAN_41)) {
|
||||
if (Version.sdkAboveOrEqual(Version.API21_LOLLIPOP_50)) {
|
||||
return ApiTwentyOnePlus.createMessageNotification(context, msgCount, msgSender, msg, contactIcon, intent);
|
||||
} else if (Version.sdkAboveOrEqual(Version.API16_JELLY_BEAN_41)) {
|
||||
notif = ApiSixteenPlus.createMessageNotification(context, msgCount, msgSender, msg, contactIcon, intent);
|
||||
} else if (Version.sdkAboveOrEqual(Version.API11_HONEYCOMB_30)) {
|
||||
notif = ApiElevenPlus.createMessageNotification(context, msgCount, msgSender, msg, contactIcon, intent);
|
||||
|
@ -175,7 +177,9 @@ public class Compatibility {
|
|||
public static Notification createInCallNotification(Context context, String title, String msg, int iconID, Bitmap contactIcon, String contactName, PendingIntent intent) {
|
||||
Notification notif = null;
|
||||
|
||||
if (Version.sdkAboveOrEqual(Version.API16_JELLY_BEAN_41)) {
|
||||
if (Version.sdkAboveOrEqual(Version.API21_LOLLIPOP_50)) {
|
||||
return ApiTwentyOnePlus.createInCallNotification(context, title, msg, iconID, contactIcon, contactName, intent);
|
||||
} else if (Version.sdkAboveOrEqual(Version.API16_JELLY_BEAN_41)) {
|
||||
notif = ApiSixteenPlus.createInCallNotification(context, title, msg, iconID, contactIcon, contactName, intent);
|
||||
} else if (Version.sdkAboveOrEqual(Version.API11_HONEYCOMB_30)) {
|
||||
notif = ApiElevenPlus.createInCallNotification(context, title, msg, iconID, contactIcon, contactName, intent);
|
||||
|
@ -186,7 +190,9 @@ public class Compatibility {
|
|||
}
|
||||
|
||||
public static Notification createNotification(Context context, String title, String message, int icon, int iconLevel, Bitmap largeIcon, PendingIntent intent, boolean isOngoingEvent) {
|
||||
if (Version.sdkAboveOrEqual(Version.API16_JELLY_BEAN_41)) {
|
||||
if (Version.sdkAboveOrEqual(Version.API21_LOLLIPOP_50)) {
|
||||
return ApiTwentyOnePlus.createNotification(context, title, message, icon, iconLevel, largeIcon, intent, isOngoingEvent);
|
||||
} else if (Version.sdkAboveOrEqual(Version.API16_JELLY_BEAN_41)) {
|
||||
return ApiSixteenPlus.createNotification(context, title, message, icon, iconLevel, largeIcon, intent, isOngoingEvent);
|
||||
} else if (Version.sdkAboveOrEqual(Version.API11_HONEYCOMB_30)) {
|
||||
return ApiElevenPlus.createNotification(context, title, message, icon, iconLevel, largeIcon, intent, isOngoingEvent);
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit ef7677a88d7aaef4168f884eeaca85af2994ecd9
|
||||
Subproject commit da924cdecea09a8a3e308b32c81e641aa5402d23
|
Loading…
Reference in a new issue