Apply latests notification improvements for other Android versions

This commit is contained in:
Sylvain Berfini 2014-02-06 17:50:44 +01:00
parent f562397686
commit 902d4c7101
4 changed files with 68 additions and 68 deletions

View file

@ -1,55 +0,0 @@
package org.linphone.compatibility;
/*
ApiEighteenPlus.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.
*/
import android.annotation.TargetApi;
import android.app.Notification;
import android.app.PendingIntent;
import android.content.Context;
import android.graphics.Bitmap;
@TargetApi(18)
public class ApiEighteenPlus {
public static Notification createNotification(Context context, String title, String message, int icon, int level, Bitmap largeIcon, PendingIntent intent) {
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())
.build();
}
notif.flags |= Notification.FLAG_ONGOING_EVENT;
return notif;
}
}

View file

@ -51,7 +51,7 @@ public class ApiElevenPlus {
PendingIntent intent) {
String title;
if (msgCount == 1) {
title = "Unread message from %s".replace("%s", msgSender);
title = msgSender;
} else {
title = "%i unread messages"
.replace("%i", String.valueOf(msgCount));
@ -60,6 +60,7 @@ public class ApiElevenPlus {
Notification notif = new Notification.Builder(context)
.setContentTitle(title)
.setContentText(msg)
.setContentIntent(intent)
.setSmallIcon(R.drawable.chat_icon_over)
.setAutoCancel(true)
.setDefaults(
@ -68,7 +69,6 @@ public class ApiElevenPlus {
| Notification.DEFAULT_VIBRATE)
.setWhen(System.currentTimeMillis())
.setLargeIcon(contactIcon).getNotification();
notif.contentIntent = intent;
return notif;
}
@ -81,12 +81,39 @@ public class ApiElevenPlus {
Notification notif = new Notification.Builder(context).setContentTitle(contactName)
.setContentText(msg).setSmallIcon(iconID)
.setAutoCancel(false)
.setContentIntent(intent)
.setWhen(System.currentTimeMillis())
.setLargeIcon(contactIcon).getNotification();
notif.contentIntent = intent;
return notif;
}
@SuppressWarnings("deprecation")
public static Notification createNotification(Context context, String title, String message, int icon, int level, Bitmap largeIcon, PendingIntent intent) {
Notification notif;
if (largeIcon != null) {
notif = new Notification.Builder(context)
.setContentTitle(title)
.setContentText(message)
.setSmallIcon(icon, level)
.setLargeIcon(largeIcon)
.setContentIntent(intent)
.setWhen(System.currentTimeMillis())
.getNotification();
} else {
notif = new Notification.Builder(context)
.setContentTitle(title)
.setContentText(message)
.setSmallIcon(icon, level)
.setContentIntent(intent)
.setWhen(System.currentTimeMillis())
.getNotification();
}
notif.flags |= Notification.FLAG_ONGOING_EVENT;
return notif;
}
public static void copyTextToClipboard(Context context, String msg) {
ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);

View file

@ -74,6 +74,32 @@ public class ApiSixteenPlus {
return notif;
}
public static Notification createNotification(Context context, String title, String message, int icon, int level, Bitmap largeIcon, PendingIntent intent) {
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())
.build();
}
notif.flags |= Notification.FLAG_ONGOING_EVENT;
return notif;
}
public static void removeGlobalLayoutListener(ViewTreeObserver viewTreeObserver, OnGlobalLayoutListener keyboardListener) {
viewTreeObserver.removeOnGlobalLayoutListener(keyboardListener);

View file

@ -134,7 +134,7 @@ public class Compatibility {
title = "%i unread messages".replace("%i", String.valueOf(msgCount));
}
if (Version.sdkAboveOrEqual(16)) {
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);
@ -147,7 +147,7 @@ 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(16)) {
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);
@ -157,6 +157,16 @@ public class Compatibility {
return notif;
}
public static Notification createNotification(Context context, String title, String message, int icon, int iconLevel, Bitmap largeIcon, PendingIntent intent) {
if (Version.sdkAboveOrEqual(Version.API16_JELLY_BEAN_41)) {
return ApiSixteenPlus.createNotification(context, title, message, icon, iconLevel, largeIcon, intent);
} else if (Version.sdkAboveOrEqual(Version.API11_HONEYCOMB_30)) {
return ApiElevenPlus.createNotification(context, title, message, icon, iconLevel, largeIcon, intent);
} else {
return ApiFivePlus.createNotification(context, title, message, icon, iconLevel, intent);
}
}
public static String refreshContactName(ContentResolver cr, String id) {
if (Version.sdkAboveOrEqual(Version.API05_ECLAIR_20)) {
return ApiFivePlus.refreshContactName(cr, id);
@ -266,12 +276,4 @@ public class Compatibility {
ApiFivePlus.setAudioManagerInCallMode(manager);
}
}
public static Notification createNotification(Context context, String title, String message, int icon, int iconLevel, Bitmap largeIcon, PendingIntent intent) {
if (Version.sdkAboveOrEqual(18)) {
return ApiEighteenPlus.createNotification(context, title, message, icon, iconLevel, largeIcon, intent);
} else {
return ApiFivePlus.createNotification(context, title, message, icon, iconLevel, intent);
}
}
}