From fcf25c8da5ff74ecc02e9c8025aadaada3494006 Mon Sep 17 00:00:00 2001 From: Pierre Date: Wed, 25 Apr 2018 17:27:19 +0200 Subject: [PATCH] Pressing return key when typing a message in the conversation system request the message to be sent. --- .../ui/fragments/ConversationFragment.java | 31 +++++++++++++++++++ .../main/res/layout/fragment_conversation.xml | 1 + 2 files changed, 32 insertions(+) diff --git a/app/src/main/java/org/communiquons/android/comunic/client/ui/fragments/ConversationFragment.java b/app/src/main/java/org/communiquons/android/comunic/client/ui/fragments/ConversationFragment.java index 0f098a5..2152d5a 100644 --- a/app/src/main/java/org/communiquons/android/comunic/client/ui/fragments/ConversationFragment.java +++ b/app/src/main/java/org/communiquons/android/comunic/client/ui/fragments/ConversationFragment.java @@ -13,9 +13,11 @@ import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.util.ArrayMap; import android.util.Log; +import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.view.inputmethod.EditorInfo; import android.widget.EditText; import android.widget.ImageButton; import android.widget.ListView; @@ -246,6 +248,35 @@ public class ConversationFragment extends Fragment } }); + //Make message input act like send button on enter key press + new_message_content.setOnKeyListener(new View.OnKeyListener() { + @Override + public boolean onKey(View v, int keyCode, KeyEvent event) { + + if(event.getAction() == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_ENTER) { + send_message(); + return false; + } + + + return false; + } + }); + /*setOnEditorActionListener(new TextView.OnEditorActionListener() { + @Override + public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { + + if(event != null){ + if(event.getKeyCode() == KeyEvent.KEYCODE_ENTER && + //actionId == EditorInfo.IME_NULL && + event.getAction() == KeyEvent.ACTION_DOWN) + send_message(); + } + + return false; + } + });*/ + //Make pick image button lives pick_image_button.setOnClickListener(new View.OnClickListener() { @Override diff --git a/app/src/main/res/layout/fragment_conversation.xml b/app/src/main/res/layout/fragment_conversation.xml index a83d675..e1e323f 100644 --- a/app/src/main/res/layout/fragment_conversation.xml +++ b/app/src/main/res/layout/fragment_conversation.xml @@ -42,6 +42,7 @@ android:layout_width="0dp" android:layout_weight="1" android:layout_height="wrap_content" + android:inputType="text" android:hint="@string/fragment_conversation_new_message_placeholder"/>