Пример #1
0
 public void OnSharedPreferenceChanged(ISharedPreferences sharedPreferences, string key)
 {
     if (MessageLogger.LOG_KEY == key)
     {
         myFragment.mDataPortView.Text = MessageLogger.GetAllMessages(myFragment.Activity);
     }
 }
        void SendNotificationForConversation(Conversations.Conversation conversation)
        {
            // A pending Intent for reads
            PendingIntent readPendingIntent = PendingIntent.GetBroadcast(ApplicationContext,
                                                                         conversation.ConversationId,
                                                                         GetMessageReadIntent(conversation.ConversationId),
                                                                         PendingIntentFlags.UpdateCurrent);

            // Build a RemoteInput for receiving voice input in a Car Notification
            var remoteInput = new Android.Support.V4.App.RemoteInput.Builder(EXTRA_VOICE_REPLY)
                              .SetLabel(ApplicationContext.GetString(Resource.String.notification_reply))
                              .Build();

            // Building a Pending Intent for the reply action to trigger
            PendingIntent replyIntent = PendingIntent.GetBroadcast(ApplicationContext,
                                                                   conversation.ConversationId,
                                                                   GetMessageReplyIntent(conversation.ConversationId),
                                                                   PendingIntentFlags.UpdateCurrent);

            // Create the UnreadConversation and populate it with the participant name,
            // read and reply intents.
            var unreadConvBuilder =
                new NotificationCompat.CarExtender.UnreadConversation.Builder(conversation.ParticipantName)
                .SetLatestTimestamp(conversation.Timestamp)
                .SetReadPendingIntent(readPendingIntent)
                .SetReplyAction(replyIntent, remoteInput);

            // Note: Add messages from oldest to newest to the UnreadConversation.Builder
            StringBuilder messageForNotification = new StringBuilder();

            for (int i = 0; i < conversation.Messages.Count; i++)
            {
                unreadConvBuilder.AddMessage(conversation.Messages [i]);
                messageForNotification.Append(conversation.Messages [i]);
                if (i != conversation.Messages.Count - 1)
                {
                    messageForNotification.Append(EOL);
                }
            }

            NotificationCompat.Builder builder = new NotificationCompat.Builder(ApplicationContext)
                                                 .SetSmallIcon(Resource.Drawable.notification_icon)
                                                 .SetLargeIcon(BitmapFactory.DecodeResource(
                                                                   ApplicationContext.Resources, Resource.Drawable.android_contact))
                                                 .SetContentText(messageForNotification.ToString())
                                                 .SetWhen(conversation.Timestamp)
                                                 .SetContentTitle(conversation.ParticipantName)
                                                 .SetContentIntent(readPendingIntent)
                                                 .Extend(new NotificationCompat.CarExtender()
                                                         .SetUnreadConversation(unreadConvBuilder.Build())
                                                         .SetColor(ApplicationContext
                                                                   .Resources.GetColor(Resource.Color.default_color_light)));

            MessageLogger.LogMessage(ApplicationContext, "Sending notification "
                                     + conversation.ConversationId + " conversation: " + conversation);

            mNotificationManager.Notify(conversation.ConversationId, builder.Build());
        }
Пример #3
0
        public override void OnReceive(Context context, Intent intent)
        {
            Log.Debug(TAG, "onReceive");
            int conversationId = intent.GetIntExtra(CONVERSATION_ID, -1);

            if (conversationId != -1)
            {
                Log.Debug(TAG, "Conversation " + conversationId + " was read");
                MessageLogger.LogMessage(context, "Conversation " + conversationId + " was read.");
                NotificationManagerCompat.From(context)
                .Cancel(conversationId);
            }
        }
Пример #4
0
 void SendMessage(int howManyConversations, int messagesPerConversation)
 {
     if (mBound)
     {
         Message msg = Message.Obtain(null, MessagingService.MSG_SEND_NOTIFICATION,
                                      howManyConversations, messagesPerConversation);
         try {
             mService.Send(msg);
         } catch (RemoteException e) {
             Log.Error(TAG, "Error sending a message", e);
             MessageLogger.LogMessage(Activity, "Error occurred while sending a message.");
         }
     }
 }
Пример #5
0
 public override void OnReceive(Context context, Intent intent)
 {
     if (MessagingService.REPLY_ACTION.Equals(intent.Action))
     {
         int conversationId = intent.GetIntExtra(MessagingService.CONVERSATION_ID, -1);
         var reply          = GetMessageText(intent);
         if (conversationId != -1)
         {
             Log.Debug(TAG, "Got reply (" + reply + ") for ConversationId " + conversationId);
             MessageLogger.LogMessage(context, "ConversationId: " + conversationId +
                                      " received a reply: [" + reply + "]");
         }
     }
 }
Пример #6
0
 public void OnClick(View v)
 {
     if (v == mSendSingleConversation)
     {
         SendMessage(1, 1);
     }
     else if (v == mSendTwoConversations)
     {
         SendMessage(2, 1);
     }
     else if (v == mSendConversationWithThreeMessages)
     {
         SendMessage(1, 3);
     }
     else if (v == mClearLogButton)
     {
         MessageLogger.Clear(Activity);
         mDataPortView.Text = MessageLogger.GetAllMessages(Activity);
     }
 }
        public override void OnReceive(Context context, Intent intent)
        {
            if (MessagingService.REPLY_ACTION.Equals(intent.Action))
            {
                int conversationId = intent.GetIntExtra(MessagingService.CONVERSATION_ID, -1);
                var reply          = GetMessageText(intent);
                if (conversationId != -1)
                {
                    Log.Debug(TAG, "Got reply (" + reply + ") for ConversationId " + conversationId);
                    MessageLogger.LogMessage(context, "ConversationId: " + conversationId +
                                             " received a reply: [" + reply + "]");

                    using (var notificationManager = NotificationManagerCompat.From(context)) {
                        var notificationBuilder = new NotificationCompat.Builder(context);
                        notificationBuilder.SetSmallIcon(Resource.Drawable.notification_icon);
                        notificationBuilder.SetLargeIcon(BitmapFactory.DecodeResource(context.Resources, Resource.Drawable.android_contact));
                        notificationBuilder.SetContentText(context.GetString(Resource.String.replied));
                        Notification repliedNotification = notificationBuilder.Build();
                        notificationManager.Notify(conversationId, repliedNotification);
                    }
                }
            }
        }
Пример #8
0
 public override void OnResume()
 {
     base.OnResume();
     mDataPortView.Text = MessageLogger.GetAllMessages(Activity);
     MessageLogger.GetPrefs(Activity).RegisterOnSharedPreferenceChangeListener(listener);
 }
Пример #9
0
 public override void OnPause()
 {
     base.OnPause();
     MessageLogger.GetPrefs(Activity).UnregisterOnSharedPreferenceChangeListener(listener);
 }