add action buttons to the call notification

fixes #4160
Closes #4490
This commit is contained in:
agrajaghh 2015-11-11 15:35:32 +01:00 committed by Moxie Marlinspike
parent 332c722f1d
commit a65ade5366
23 changed files with 75 additions and 28 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 425 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 256 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 457 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 444 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 313 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 197 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 350 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 346 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 557 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 307 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 612 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 536 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 773 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 411 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 863 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 739 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 996 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 460 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@ -313,6 +313,12 @@
<string name="NotificationBarManager_signal_call_in_progress">Signal call in progress</string> <string name="NotificationBarManager_signal_call_in_progress">Signal call in progress</string>
<string name="NotificationBarManager_missed_call_from_s">Missed call from %s</string> <string name="NotificationBarManager_missed_call_from_s">Missed call from %s</string>
<string name="NotificationBarManager_missed_signal_call">Missed Signal call</string> <string name="NotificationBarManager_missed_signal_call">Missed Signal call</string>
<string name="NotificationBarManager__establishing_signal_call">Establishing Signal call</string>
<string name="NotificationBarManager__incoming_signal_call">Incoming Signal call</string>
<string name="NotificationBarManager__deny_call">Deny call</string>
<string name="NotificationBarManager__answer_call">Answer call</string>
<string name="NotificationBarManager__end_call">End call</string>
<string name="NotificationBarManager__cancel_call">Cancel call</string>
<!-- NotificationMmsMessageRecord --> <!-- NotificationMmsMessageRecord -->
<string name="NotificationMmsMessageRecord_multimedia_message">Multimedia message</string> <string name="NotificationMmsMessageRecord_multimedia_message">Multimedia message</string>

View File

@ -61,6 +61,10 @@ public class RedPhone extends Activity {
private static final int STANDARD_DELAY_FINISH = 1000; private static final int STANDARD_DELAY_FINISH = 1000;
public static final int BUSY_SIGNAL_DELAY_FINISH = 5500; public static final int BUSY_SIGNAL_DELAY_FINISH = 5500;
public static final String ANSWER_ACTION = RedPhone.class.getCanonicalName() + ".ANSWER_ACTION";
public static final String DENY_ACTION = RedPhone.class.getCanonicalName() + ".DENY_ACTION";
public static final String END_CALL_ACTION = RedPhone.class.getCanonicalName() + ".END_CALL_ACTION";
private CallScreen callScreen; private CallScreen callScreen;
private BroadcastReceiver bluetoothStateReceiver; private BroadcastReceiver bluetoothStateReceiver;
@ -87,6 +91,16 @@ public class RedPhone extends Activity {
registerBluetoothReceiver(); registerBluetoothReceiver();
} }
@Override
public void onNewIntent(Intent intent){
if (ANSWER_ACTION.equals(intent.getAction())) {
handleAnswerCall();
} else if (DENY_ACTION.equals(intent.getAction())) {
handleDenyCall();
} else if (END_CALL_ACTION.equals(intent.getAction())) {
handleEndCall();
}
}
@Override @Override
public void onPause() { public void onPause() {
@ -151,6 +165,19 @@ public class RedPhone extends Activity {
} }
} }
private void handleEndCall() {
Log.w(TAG, "Hangup pressed, handling termination now...");
Intent intent = new Intent(RedPhone.this, RedPhoneService.class);
intent.setAction(RedPhoneService.ACTION_HANGUP_CALL);
startService(intent);
RedPhoneEvent event = EventBus.getDefault().getStickyEvent(RedPhoneEvent.class);
if (event != null) {
RedPhone.this.handleTerminate(event.getRecipient());
}
}
private void handleIncomingCall(@NonNull RedPhoneEvent event) { private void handleIncomingCall(@NonNull RedPhoneEvent event) {
callScreen.setIncomingCall(event.getRecipient()); callScreen.setIncomingCall(event.getRecipient());
} }
@ -303,16 +330,7 @@ public class RedPhone extends Activity {
private class HangupButtonListener implements CallControls.HangupButtonListener { private class HangupButtonListener implements CallControls.HangupButtonListener {
public void onClick() { public void onClick() {
Log.w(TAG, "Hangup pressed, handling termination now..."); handleEndCall();
Intent intent = new Intent(RedPhone.this, RedPhoneService.class);
intent.setAction(RedPhoneService.ACTION_HANGUP_CALL);
startService(intent);
RedPhoneEvent event = EventBus.getDefault().getStickyEvent(RedPhoneEvent.class);
if (event != null) {
RedPhone.this.handleTerminate(event.getRecipient());
}
} }
} }

View File

@ -204,7 +204,8 @@ public class RedPhoneService extends Service implements CallStateListener, CallS
if (remoteNumber == null || remoteNumber.length() == 0) if (remoteNumber == null || remoteNumber.length() == 0)
return; return;
sendMessage(Type.OUTGOING_CALL, getRecipient(), null); Recipient recipient = getRecipient();
sendMessage(Type.OUTGOING_CALL, recipient, null);
state = STATE_DIALING; state = STATE_DIALING;
lockManager.updatePhoneState(LockManager.PhoneState.INTERACTIVE); lockManager.updatePhoneState(LockManager.PhoneState.INTERACTIVE);
@ -212,7 +213,7 @@ public class RedPhoneService extends Service implements CallStateListener, CallS
remoteNumber, zid); remoteNumber, zid);
this.currentCallManager.start(); this.currentCallManager.start();
NotificationBarManager.setCallInProgress(this); NotificationBarManager.setCallInProgress(this, NotificationBarManager.TYPE_OUTGOING_RINGING, recipient);
DatabaseFactory.getSmsDatabase(this).insertOutgoingCall(remoteNumber); DatabaseFactory.getSmsDatabase(this).insertOutgoingCall(remoteNumber);
} }
@ -389,7 +390,7 @@ public class RedPhoneService extends Service implements CallStateListener, CallS
startCallCardActivity(); startCallCardActivity();
incomingRinger.start(); incomingRinger.start();
NotificationBarManager.setCallInProgress(this); NotificationBarManager.setCallInProgress(this, NotificationBarManager.TYPE_INCOMING_RINGING, getRecipient());
} }
public void notifyBusy() { public void notifyBusy() {
@ -414,7 +415,10 @@ public class RedPhoneService extends Service implements CallStateListener, CallS
outgoingRinger.playComplete(); outgoingRinger.playComplete();
lockManager.updatePhoneState(LockManager.PhoneState.IN_CALL); lockManager.updatePhoneState(LockManager.PhoneState.IN_CALL);
state = STATE_CONNECTED; state = STATE_CONNECTED;
sendMessage(Type.CALL_CONNECTED, getRecipient(), sas.getSasText()); Recipient recipient = getRecipient();
sendMessage(Type.CALL_CONNECTED, recipient, sas.getSasText());
NotificationBarManager.setCallInProgress(this, NotificationBarManager.TYPE_ESTABLISHED, recipient);
} }
public void notifyConnectingtoInitiator() { public void notifyConnectingtoInitiator() {

View File

@ -17,20 +17,15 @@
package org.thoughtcrime.redphone.ui; package org.thoughtcrime.redphone.ui;
import android.app.Notification;
import android.app.NotificationManager; import android.app.NotificationManager;
import android.app.PendingIntent; import android.app.PendingIntent;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.net.Uri;
import android.support.v4.app.NotificationCompat; import android.support.v4.app.NotificationCompat;
import org.thoughtcrime.redphone.RedPhone; import org.thoughtcrime.redphone.RedPhone;
import org.thoughtcrime.securesms.ConversationActivity;
import org.thoughtcrime.securesms.R; import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.database.DatabaseFactory; import org.thoughtcrime.securesms.recipients.Recipient;
import org.thoughtcrime.securesms.recipients.RecipientFactory;
import org.thoughtcrime.securesms.recipients.Recipients;
/** /**
* Manages the state of the RedPhone items in the Android notification bar. * Manages the state of the RedPhone items in the Android notification bar.
@ -44,6 +39,10 @@ public class NotificationBarManager {
private static final int RED_PHONE_NOTIFICATION = 313388; private static final int RED_PHONE_NOTIFICATION = 313388;
private static final int MISSED_CALL_NOTIFICATION = 313389; private static final int MISSED_CALL_NOTIFICATION = 313389;
public static final int TYPE_INCOMING_RINGING = 1;
public static final int TYPE_OUTGOING_RINGING = 2;
public static final int TYPE_ESTABLISHED = 3;
public static void setCallEnded(Context context) { public static void setCallEnded(Context context) {
NotificationManager notificationManager = (NotificationManager)context NotificationManager notificationManager = (NotificationManager)context
.getSystemService(Context.NOTIFICATION_SERVICE); .getSystemService(Context.NOTIFICATION_SERVICE);
@ -51,20 +50,40 @@ public class NotificationBarManager {
notificationManager.cancel(RED_PHONE_NOTIFICATION); notificationManager.cancel(RED_PHONE_NOTIFICATION);
} }
public static void setCallInProgress(Context context) { public static void setCallInProgress(Context context, int type, Recipient recipient) {
NotificationManager notificationManager = (NotificationManager)context NotificationManager notificationManager = (NotificationManager)context
.getSystemService(Context.NOTIFICATION_SERVICE); .getSystemService(Context.NOTIFICATION_SERVICE);
Intent contentIntent = new Intent(context, RedPhone.class); Intent contentIntent = new Intent(context, RedPhone.class);
contentIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); contentIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, contentIntent, 0); PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, contentIntent, 0);
String notificationText = context.getString(R.string.NotificationBarManager_signal_call_in_progress);
Notification notification = new Notification(R.drawable.redphone_stat_sys_phone_call, null,
System.currentTimeMillis());
notification.setLatestEventInfo(context, notificationText, notificationText, pendingIntent); NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
notification.flags = Notification.FLAG_NO_CLEAR; .setSmallIcon(R.drawable.ic_call_secure_white_24dp)
notificationManager.notify(RED_PHONE_NOTIFICATION, notification); .setContentIntent(pendingIntent)
.setOngoing(true)
.setContentTitle(recipient.getName());
if (type == TYPE_INCOMING_RINGING) {
builder.setContentText(context.getString(R.string.NotificationBarManager__incoming_signal_call));
builder.addAction(getNotificationAction(context, RedPhone.DENY_ACTION, R.drawable.ic_close_grey600_32dp, R.string.NotificationBarManager__deny_call));
builder.addAction(getNotificationAction(context, RedPhone.ANSWER_ACTION, R.drawable.ic_phone_grey600_32dp, R.string.NotificationBarManager__answer_call));
} else if (type == TYPE_OUTGOING_RINGING) {
builder.setContentText(context.getString(R.string.NotificationBarManager__establishing_signal_call));
builder.addAction(getNotificationAction(context, RedPhone.END_CALL_ACTION, R.drawable.ic_call_end_grey600_32dp, R.string.NotificationBarManager__cancel_call));
} else {
builder.setContentText(context.getString(R.string.NotificationBarManager_signal_call_in_progress));
builder.addAction(getNotificationAction(context, RedPhone.END_CALL_ACTION, R.drawable.ic_call_end_grey600_32dp, R.string.NotificationBarManager__end_call));
}
notificationManager.notify(RED_PHONE_NOTIFICATION, builder.build());
}
private static NotificationCompat.Action getNotificationAction(Context context, String action, int iconResId, int titleResId) {
Intent intent = new Intent(context, RedPhone.class);
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
intent.setAction(action);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
return new NotificationCompat.Action(iconResId, context.getString(titleResId), pendingIntent);
} }
} }