Skip to content
Snippets Groups Projects
Commit 81ef750e authored by Alexandre Lision's avatar Alexandre Lision
Browse files

* #36834: display missed call notification

parent 269e604e
Branches
Tags
No related merge requests found
...@@ -2,14 +2,14 @@ ...@@ -2,14 +2,14 @@
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"><shape xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true"><shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/darker_gray" /> <solid android:color="@color/transparent_grey" />
<padding android:bottom="10dp" android:left="10dp" android:right="10dp" android:top="10dp" /> <padding android:bottom="10dp" android:left="10dp" android:right="10dp" android:top="10dp" />
<corners android:bottomLeftRadius="5dp" android:bottomRightRadius="5dp" android:topLeftRadius="5dp" android:topRightRadius="5dp" /> <corners android:bottomLeftRadius="5dp" android:bottomRightRadius="5dp" android:topLeftRadius="5dp" android:topRightRadius="5dp" />
</shape></item> </shape></item>
<item android:state_focused="true"><shape xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_focused="true"><shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/light" /> <solid android:color="@color/transparent_grey" />
<padding android:bottom="10dp" android:left="10dp" android:right="10dp" android:top="10dp" /> <padding android:bottom="10dp" android:left="10dp" android:right="10dp" android:top="10dp" />
......
...@@ -11,6 +11,8 @@ ...@@ -11,6 +11,8 @@
android:layout_marginLeft="10dp" android:layout_marginLeft="10dp"
android:layout_marginRight="10dp" android:layout_marginRight="10dp"
android:layout_marginTop="10dp" android:layout_marginTop="10dp"
android:dividerHeight="3dp"
android:divider="@null"
android:clickable="true" /> android:clickable="true" />
<TextView <TextView
......
...@@ -57,7 +57,6 @@ as that of the covered work. ...@@ -57,7 +57,6 @@ as that of the covered work.
<string name="drawer_close">Fermer le tiroir de navigation</string> <string name="drawer_close">Fermer le tiroir de navigation</string>
<!-- Categories --> <!-- Categories -->
<string name="frag_menu_accounts_title">Comptes</string>
<string name="menu_category_settings">Paramètres</string> <string name="menu_category_settings">Paramètres</string>
<string name="menu_category_help">Aide</string> <string name="menu_category_help">Aide</string>
...@@ -102,6 +101,10 @@ as that of the covered work. ...@@ -102,6 +101,10 @@ as that of the covered work.
<!-- FileExplorerDFragement --> <!-- FileExplorerDFragement -->
<string name="file_explorer_title">Sélectionner un fichier</string> <string name="file_explorer_title">Sélectionner un fichier</string>
<!-- Notifications -->
<string name="notif_missed_call_title">Appel manqué</string>
<string name="notif_missed_call_content">From %1$s</string>
<!-- Call Fragment --> <!-- Call Fragment -->
<string name="me">Moi</string> <string name="me">Moi</string>
<string name="action_call_attended_transfer">Transfert</string> <string name="action_call_attended_transfer">Transfert</string>
......
...@@ -65,7 +65,7 @@ as that of the covered work. ...@@ -65,7 +65,7 @@ as that of the covered work.
<string name="menu_item_settings">Settings</string> <string name="menu_item_settings">Settings</string>
<string name="menu_item_settings_interface">Interface</string> <string name="menu_item_settings_interface">Interface</string>
<!-- Dialing Fragmennt --> <!-- Dialing Fragment -->
<string name="dial_action_call">Call</string> <string name="dial_action_call">Call</string>
<string name="dial_error_no_number_dialed">Dial a number</string> <string name="dial_error_no_number_dialed">Dial a number</string>
<string name="dial_hint">Type phone number</string> <string name="dial_hint">Type phone number</string>
...@@ -101,8 +101,9 @@ as that of the covered work. ...@@ -101,8 +101,9 @@ as that of the covered work.
<string name="transfer_no_other_call">No other calls pending</string> <string name="transfer_no_other_call">No other calls pending</string>
<string name="transfer_type_number">Type number to transfer to:</string> <string name="transfer_type_number">Type number to transfer to:</string>
<!-- Menu Fragment --> <!-- Notifications -->
<string name="frag_menu_accounts_title">Accounts</string> <string name="notif_missed_call_title">Missed call</string>
<string name="notif_missed_call_content">De %1$s</string>
<!-- Call Fragment --> <!-- Call Fragment -->
<string name="me">Me</string> <string name="me">Me</string>
......
...@@ -106,9 +106,6 @@ public class AccountsManagementActivity extends Activity implements AccountsMana ...@@ -106,9 +106,6 @@ public class AccountsManagementActivity extends Activity implements AccountsMana
unbindService(mConnection); unbindService(mConnection);
mBound = false; mBound = false;
} }
// stopService(new Intent(this, SipService.class));
// serviceIsOn = false;
super.onDestroy(); super.onDestroy();
} }
......
/*
* Copyright (C) 2004-2013 Savoir-Faire Linux Inc.
*
* Author: Alexandre Lision <alexandre.lision@savoirfairelinux.com>
*
* 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 3 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., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* Additional permission under GNU GPL version 3 section 7:
*
* If you modify this program, or any covered work, by linking or
* combining it with the OpenSSL project's OpenSSL library (or a
* modified version of that library), containing parts covered by the
* terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc.
* grants you additional permission to convey the resulting work.
* Corresponding Source for a non-source form of such a combination
* shall include the source code for the parts of OpenSSL used as well
* as that of the covered work.
*/
package org.sflphone.receivers; package org.sflphone.receivers;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -153,8 +183,11 @@ public class IncomingReceiver extends BroadcastReceiver { ...@@ -153,8 +183,11 @@ public class IncomingReceiver extends BroadcastReceiver {
} }
} else if (newState.equals("HUNGUP")) { } else if (newState.equals("HUNGUP")) {
// Log.e(TAG, "HUNGUP call:" + b.getString("CallID"));
if (callback.getCurrent_calls().get(b.getString("CallID")) != null) { if (callback.getCurrent_calls().get(b.getString("CallID")) != null) {
if(callback.getCurrent_calls().get(b.getString("CallID")).isRinging())
callback.notificationManager.publishMissedCallNotification(callback.getCurrent_calls().get(b.getString("CallID")));
callback.getCurrent_calls().remove(b.getString("CallID")); callback.getCurrent_calls().remove(b.getString("CallID"));
} else { } else {
ArrayList<Conference> it = new ArrayList<Conference>(callback.getCurrent_confs().values()); ArrayList<Conference> it = new ArrayList<Conference>(callback.getCurrent_confs().values());
......
...@@ -33,27 +33,29 @@ ...@@ -33,27 +33,29 @@
package org.sflphone.utils; package org.sflphone.utils;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import org.sflphone.R;
import org.sflphone.client.HomeActivity;
import org.sflphone.model.SipCall; import org.sflphone.model.SipCall;
import android.app.Notification; import android.app.Notification;
import android.app.NotificationManager; import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.ContentValues; import android.content.ContentValues;
import android.content.Context; import android.content.Context;
import android.content.Intent;
import android.graphics.BitmapFactory;
import android.graphics.Typeface; import android.graphics.Typeface;
import android.net.sip.SipProfile; import android.net.sip.SipProfile;
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.NotificationCompat.Builder; import android.support.v4.app.NotificationCompat.Builder;
import android.text.Spannable; import android.text.Spannable;
import android.text.SpannableString; import android.text.SpannableString;
import android.text.TextUtils; import android.text.TextUtils;
import android.text.style.StyleSpan; import android.text.style.StyleSpan;
import android.util.Log; import android.util.Log;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;
public class SipNotifications { public class SipNotifications {
...@@ -86,48 +88,7 @@ public class SipNotifications { ...@@ -86,48 +88,7 @@ public class SipNotifications {
isInit = true; isInit = true;
} }
if( ! Compatibility.isCompatible(9) ) {
searchNotificationPrimaryText(aContext);
}
}
private Integer notificationPrimaryTextColor = null;
private static String TO_SEARCH = "Search";
// Retrieve notification textColor with android < 2.3
@SuppressWarnings("deprecation")
private void searchNotificationPrimaryText(Context aContext) {
try {
Notification ntf = new Notification();
ntf.setLatestEventInfo(aContext, TO_SEARCH, "", null);
LinearLayout group = new LinearLayout(aContext);
ViewGroup event = (ViewGroup) ntf.contentView.apply(aContext, group);
recurseSearchNotificationPrimaryText(event);
group.removeAllViews();
} catch (Exception e) {
Log.e(THIS_FILE, "Can't retrieve the color", e);
}
}
private boolean recurseSearchNotificationPrimaryText(ViewGroup gp) {
final int count = gp.getChildCount();
for (int i = 0; i < count; ++i) {
if (gp.getChildAt(i) instanceof TextView){
final TextView text = (TextView) gp.getChildAt(i);
final String szText = text.getText().toString();
if (TO_SEARCH.equals(szText)) {
notificationPrimaryTextColor = text.getTextColors().getDefaultColor();
return true;
}
} else if (gp.getChildAt(i) instanceof ViewGroup) {
if(recurseSearchNotificationPrimaryText((ViewGroup) gp.getChildAt(i))) {
return true;
}
} }
}
return false;
}
// Foreground api // Foreground api
...@@ -156,8 +117,7 @@ public class SipNotifications { ...@@ -156,8 +117,7 @@ public class SipNotifications {
} }
/** /**
* This is a wrapper around the new startForeground method, using the older * This is a wrapper around the new startForeground method, using the older APIs if it is not available.
* APIs if it is not available.
*/ */
private void startForegroundCompat(int id, Notification notification) { private void startForegroundCompat(int id, Notification notification) {
// If we have the new startForeground API, then use it. // If we have the new startForeground API, then use it.
...@@ -175,8 +135,7 @@ public class SipNotifications { ...@@ -175,8 +135,7 @@ public class SipNotifications {
} }
/** /**
* This is a wrapper around the new stopForeground method, using the older * This is a wrapper around the new stopForeground method, using the older APIs if it is not available.
* APIs if it is not available.
*/ */
private void stopForegroundCompat(int id) { private void stopForegroundCompat(int id) {
// If we have the new stopForeground API, then use it. // If we have the new stopForeground API, then use it.
...@@ -267,7 +226,9 @@ public class SipNotifications { ...@@ -267,7 +226,9 @@ public class SipNotifications {
/** /**
* Format the remote contact name for the call info * Format the remote contact name for the call info
* @param callInfo the callinfo to format *
* @param callInfo
* the callinfo to format
* @return the name to display for the contact * @return the name to display for the contact
*/ */
private String formatRemoteContactString(String remoteContact) { private String formatRemoteContactString(String remoteContact) {
...@@ -278,6 +239,7 @@ public class SipNotifications { ...@@ -278,6 +239,7 @@ public class SipNotifications {
/** /**
* Format the notification title for a call info * Format the notification title for a call info
*
* @param title * @param title
* @param callInfo * @param callInfo
* @return * @return
...@@ -292,10 +254,6 @@ public class SipNotifications { ...@@ -292,10 +254,6 @@ public class SipNotifications {
// TODO // TODO
} }
public void showNotificationForMissedCall(ContentValues callLog) {
//TODO
}
public void showNotificationForVoiceMail(SipProfile acc, int numberOfMessages) { public void showNotificationForVoiceMail(SipProfile acc, int numberOfMessages) {
// TODO // TODO
} }
...@@ -361,4 +319,33 @@ public class SipNotifications { ...@@ -361,4 +319,33 @@ public class SipNotifications {
cancelVoicemails(); cancelVoicemails();
} }
public void publishMissedCallNotification(SipCall sipCall) {
CharSequence tickerText = context.getString(R.string.notif_missed_call_title);
long when = System.currentTimeMillis();
Builder nb = new NotificationCompat.Builder(context);
nb.setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_launcher));
nb.setSmallIcon(R.drawable.ic_action_call);
nb.setTicker(tickerText);
nb.setWhen(when);
nb.setContentTitle(context.getString(R.string.notif_missed_call_title));
nb.setContentText(context.getString(R.string.notif_missed_call_content, sipCall.getContact().getmDisplayName()));
Intent notificationIntent = new Intent(context, HomeActivity.class);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
// notification.setLatestEventInfo(context, contentTitle,
// contentText, contentIntent);
nb.setOnlyAlertOnce(true);
nb.setContentIntent(contentIntent);
Notification notification = nb.build();
// We have to re-write content view because getNotification setLatestEventInfo implicitly
// notification.contentView = contentView;
// startForegroundCompat(CALL_NOTIF_ID, notification);
notificationManager.notify(CALL_NOTIF_ID, notification);
}
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment