コード例 #1
0
		// Called when the user clicks the send button.
		private void sendMessage()
		{
			//checkMessage
			mMsgEditText.Enabled = false;
			string msgStr = mMsgEditText.Text.ToString();
			if (msgStr.Length > 0)
			{

				if (msgStr.Length > maxTextLength)
				{
					showError();
				}
				else
				{
					ChatMessage myMsg = new ChatMessage(senderId, senderAlias, msgStr, ChatMessage.MessageStatus.SENT_MESSAGE);
					bool msgError = onMessageReadyToSend(myMsg);

					if (msgError)
					{
						Log.d(LOG_TAG, "Error to send the message");
						showError();

					}
					else
					{
						mMsgEditText.Enabled = true;
						mMsgEditText.Focusable = true;
						mMsgEditText.Text = "";
						mMsgCharsView.TextColor = Resources.getColor(R.color.info);
						mListView.smoothScrollToPosition(mMessageAdapter.Count);

						//add the message to the component
						addMessage(myMsg);
					}

				}

			}
			else
			{
				mMsgEditText.Enabled = true;
			}
		}
コード例 #2
0
		/// <summary>
		/// Called when a message in the TextChatFragment is ready to send. A message is
		/// ready to send when the user clicks the Send button in the TextChatFragment
		/// user interface.
		/// 
		/// If you subclass the TextChatFragment class and implement this method,
		/// you do not need to set a TextChatListener.
		/// </summary>
		protected internal virtual bool onMessageReadyToSend(ChatMessage msg)
		{
			if (this.textChatListener != null)
			{
				Log.d(LOG_TAG, "onMessageReadyToSend");
				return this.textChatListener.onMessageReadyToSend(msg);
			}
			return false;
		}
コード例 #3
0
		/// <summary>
		/// Add a message to the TextChatListener received message list.
		/// </summary>
		public virtual void addMessage(ChatMessage msg)
		{
			Log.i(LOG_TAG, "New message " + msg.Text + " is ready to be added.");

			if (msg != null)
			{

				//check the origin of the message
				if (msg.SenderId != this.senderId)
				{
					msg.Status = ChatMessage.MessageStatus.RECEIVED_MESSAGE;
				}

				bool visible = NewMessageVisible;
				mMsgNotificationView.TextColor = Resources.getColor(R.color.text);
				mMsgNotificationView.Text = "New messages";
				showMsgNotification(visible);

				//generate message timestamp
				DateTime date = DateTime.Now;
				if (msg.Timestamp == 0)
				{
					msg.Timestamp = date.Ticks;
				}

				mMessageAdapter.add(msg);
			}
		}