Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 66f14602 authored by Flavio Lerda's avatar Flavio Lerda
Browse files

Add action to the voicemail notification.

If there is only one voicemail, add an action to directly play the
voicemail.

Bug: 6288434
Change-Id: I654864d32f7f5fb64c946d23ad95b692aa950246
parent 2d3519b9
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -1573,6 +1573,9 @@
        <item quantity="other"><xliff:g id="count">%1$d</xliff:g> Voicemails</item>
    </plurals>

    <!-- Used in the notification of a new voicemail for the action to play the voicemail. -->
    <string name="notification_action_voicemail_play">Play</string>

    <!-- Used to build a list of names or phone numbers, to indicate the callers who left
         voicemails.
         The first argument may be one or more callers, the most recent ones.
+9 −0
Original line number Diff line number Diff line
@@ -97,6 +97,8 @@ public class CallDetailActivity extends Activity implements ProximitySensorAware
    public static final String EXTRA_VOICEMAIL_URI = "EXTRA_VOICEMAIL_URI";
    /** If we should immediately start playback of the voicemail, this extra will be set to true. */
    public static final String EXTRA_VOICEMAIL_START_PLAYBACK = "EXTRA_VOICEMAIL_START_PLAYBACK";
    /** If the activity was triggered from a notification. */
    public static final String EXTRA_FROM_NOTIFICATION = "EXTRA_FROM_NOTIFICATION";

    private CallTypeHelper mCallTypeHelper;
    private PhoneNumberHelper mPhoneNumberHelper;
@@ -273,6 +275,9 @@ public class CallDetailActivity extends Activity implements ProximitySensorAware
        mContactInfoHelper = new ContactInfoHelper(this, ContactsUtils.getCurrentCountryIso(this));
        configureActionBar();
        optionallyHandleVoicemail();
        if (getIntent().getBooleanExtra(EXTRA_FROM_NOTIFICATION, false)) {
            closeSystemDialogs();
        }
    }

    @Override
@@ -879,6 +884,10 @@ public class CallDetailActivity extends Activity implements ProximitySensorAware
        mPhoneNumberActionMode = startActionMode(new PhoneNumberActionModeCallback(targetView));
    }

    private void closeSystemDialogs() {
        sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS));
    }

    private class PhoneNumberActionModeCallback implements ActionMode.Callback {
        private final View mTargetView;
        private final Drawable mOriginalViewBackground;
+16 −7
Original line number Diff line number Diff line
@@ -152,14 +152,13 @@ public class DefaultVoicemailNotifier implements VoicemailNotifier {
        // TODO: Use the photo of contact if all calls are from the same person.
        final int icon = android.R.drawable.stat_notify_voicemail;

        Notification notification = new Notification.Builder(mContext)
        Notification.Builder notificationBuilder = new Notification.Builder(mContext)
                .setSmallIcon(icon)
                .setContentTitle(title)
                .setContentText(callers)
                .setDefaults(callToNotify != null ? Notification.DEFAULT_ALL : 0)
                .setDeleteIntent(createMarkNewVoicemailsAsOldIntent())
                .setAutoCancel(true)
                .getNotification();
                .setAutoCancel(true);

        // Determine the intent to fire when the notification is clicked on.
        final Intent contentIntent;
@@ -169,19 +168,29 @@ public class DefaultVoicemailNotifier implements VoicemailNotifier {
            contentIntent.setData(newCalls[0].callsUri);
            contentIntent.putExtra(CallDetailActivity.EXTRA_VOICEMAIL_URI,
                    newCalls[0].voicemailUri);
            Intent playIntent = new Intent(mContext, CallDetailActivity.class);
            playIntent.setData(newCalls[0].callsUri);
            playIntent.putExtra(CallDetailActivity.EXTRA_VOICEMAIL_URI,
                    newCalls[0].voicemailUri);
            playIntent.putExtra(CallDetailActivity.EXTRA_VOICEMAIL_START_PLAYBACK, true);
            playIntent.putExtra(CallDetailActivity.EXTRA_FROM_NOTIFICATION, true);
            notificationBuilder.addAction(R.drawable.ic_play_holo_dark,
                    resources.getString(R.string.notification_action_voicemail_play),
                    PendingIntent.getActivity(mContext, 0, playIntent, 0));
        } else {
            // Open the call log.
            contentIntent = new Intent(Intent.ACTION_VIEW, Calls.CONTENT_URI);
        }
        notification.contentIntent = PendingIntent.getActivity(mContext, 0, contentIntent, 0);
        notificationBuilder.setContentIntent(
                PendingIntent.getActivity(mContext, 0, contentIntent, 0));

        // The text to show in the ticker, describing the new event.
        if (callToNotify != null) {
            notification.tickerText = resources.getString(
                    R.string.notification_new_voicemail_ticker, names.get(callToNotify.number));
            notificationBuilder.setTicker(resources.getString(
                    R.string.notification_new_voicemail_ticker, names.get(callToNotify.number)));
        }

        mNotificationManager.notify(NOTIFICATION_TAG, NOTIFICATION_ID, notification);
        mNotificationManager.notify(NOTIFICATION_TAG, NOTIFICATION_ID, notificationBuilder.build());
    }

    /** Creates a pending intent that marks all new voicemails as old. */