Messaging: Toggable keyboard emoticons access

 * Allows keyboards to always display the line return key

Change-Id: I9ecb19733f707d35771255018afebf0b5cda5e6d
Signed-off-by: AdrianDC <radian.dc@gmail.com>
diff --git a/res/values-ldrtl/styles.xml b/res/values-ldrtl/styles.xml
index de4d9e8..1d33e26 100644
--- a/res/values-ldrtl/styles.xml
+++ b/res/values-ldrtl/styles.xml
@@ -38,7 +38,7 @@
         <item name="android:background">@null</item>
         <item name="android:scrollHorizontally">false</item>
         <item name="android:textCursorDrawable">@null</item>
-        <item name="android:inputType">textShortMessage|textAutoCorrect|textCapSentences|textMultiLine</item>
+        <item name="android:inputType">textAutoCorrect|textCapSentences|textMultiLine</item>
     </style>
 
     <style name="ConversationComposeSubjectText" parent="ConversationComposeSendText">
diff --git a/res/values/cm_strings.xml b/res/values/cm_strings.xml
index 1e1ee52..15110df 100644
--- a/res/values/cm_strings.xml
+++ b/res/values/cm_strings.xml
@@ -18,4 +18,8 @@
     <!-- Swipe to delete conversation -->
     <string name="swipe_to_delete_conversation_pref_title">Swipe to delete</string>
     <string name="swipe_to_delete_conversation_pref_summary">Swipe to the right to delete a conversation</string>
+
+    <!-- Show emoticons -->
+    <string name="show_emoticons_pref_title">Emoticons access</string>
+    <string name="show_emoticons_pref_summary">Show the emoticons key on the keyboard</string>
 </resources>
diff --git a/res/values/lineage_constants.xml b/res/values/lineage_constants.xml
index 1975b6a..cf2793b 100644
--- a/res/values/lineage_constants.xml
+++ b/res/values/lineage_constants.xml
@@ -21,4 +21,8 @@
 
     <!-- This should really go into a config xml, but whoever wrote this app is an idiot, so follow their pattern -->
     <bool name="swipe_right_deletes_conversation_default" translatable="false">false</bool>
+
+    <!-- Preference keys for user-visible settings -->
+    <!-- Application-wide settings -->
+    <bool name="show_emoticons_pref_default" translatable="false">true</bool>
 </resources>
diff --git a/res/values/styles.xml b/res/values/styles.xml
index 6f9be47..f3e7623 100644
--- a/res/values/styles.xml
+++ b/res/values/styles.xml
@@ -142,7 +142,7 @@
         <item name="android:background">@null</item>
         <item name="android:scrollHorizontally">false</item>
         <item name="android:textCursorDrawable">@null</item>
-        <item name="android:inputType">textShortMessage|textAutoCorrect|textCapSentences|textMultiLine</item>
+        <item name="android:inputType">textAutoCorrect|textCapSentences|textMultiLine</item>
     </style>
 
     <style name="ConversationComposeSubjectText" parent="ConversationComposeSendText">
diff --git a/res/xml-v21/preferences_application.xml b/res/xml-v21/preferences_application.xml
index ab9206a..c403c06 100644
--- a/res/xml-v21/preferences_application.xml
+++ b/res/xml-v21/preferences_application.xml
@@ -67,6 +67,13 @@
         android:dependency="@string/notifications_enabled_pref_key" />
 
     <SwitchPreference
+        android:key="pref_show_emoticons"
+        android:title="@string/show_emoticons_pref_title"
+        android:persistent="true"
+        android:defaultValue="@bool/show_emoticons_pref_default"
+        android:summary="@string/show_emoticons_pref_summary" />
+
+    <SwitchPreference
         android:key="@string/swipe_right_deletes_conversation_key"
         android:title="@string/swipe_to_delete_conversation_pref_title"
         android:summary="@string/swipe_to_delete_conversation_pref_summary"
diff --git a/res/xml-v23/preferences_application.xml b/res/xml-v23/preferences_application.xml
index 0f106c7..d9cc151 100644
--- a/res/xml-v23/preferences_application.xml
+++ b/res/xml-v23/preferences_application.xml
@@ -68,6 +68,13 @@
         android:dependency="@string/notifications_enabled_pref_key" />
 
     <SwitchPreference
+        android:key="pref_show_emoticons"
+        android:title="@string/show_emoticons_pref_title"
+        android:persistent="true"
+        android:defaultValue="@bool/show_emoticons_pref_default"
+        android:summary="@string/show_emoticons_pref_summary" />
+
+    <SwitchPreference
         android:key="@string/swipe_right_deletes_conversation_key"
         android:title="@string/swipe_to_delete_conversation_pref_title"
         android:summary="@string/swipe_to_delete_conversation_pref_summary"
diff --git a/res/xml/preferences_application.xml b/res/xml/preferences_application.xml
index 4c67407..03b868b 100644
--- a/res/xml/preferences_application.xml
+++ b/res/xml/preferences_application.xml
@@ -66,6 +66,13 @@
         android:persistent="true"
         android:dependency="@string/notifications_enabled_pref_key" />
 
+    <CheckBoxPreference
+        android:key="pref_show_emoticons"
+        android:title="@string/show_emoticons_pref_title"
+        android:persistent="true"
+        android:defaultValue="@bool/show_emoticons_pref_default"
+        android:summary="@string/show_emoticons_pref_summary" />
+
     <SwitchPreference
         android:key="@string/swipe_right_deletes_conversation_key"
         android:title="@string/swipe_to_delete_conversation_pref_title"
diff --git a/src/com/android/messaging/ui/conversation/ComposeMessageView.java b/src/com/android/messaging/ui/conversation/ComposeMessageView.java
index c35927e..02be2de 100644
--- a/src/com/android/messaging/ui/conversation/ComposeMessageView.java
+++ b/src/com/android/messaging/ui/conversation/ComposeMessageView.java
@@ -25,6 +25,7 @@
 import android.text.Html;
 import android.text.InputFilter;
 import android.text.InputFilter.LengthFilter;
+import android.text.InputType;
 import android.text.TextUtils;
 import android.text.TextWatcher;
 import android.text.format.Formatter;
@@ -72,6 +73,8 @@
 import com.android.messaging.util.UiUtils;
 import com.android.messaging.util.UriUtil;
 
+import org.lineageos.messaging.util.PrefsUtils;
+
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
@@ -217,6 +220,14 @@
                 new LengthFilter(MmsConfig.get(ParticipantData.DEFAULT_SELF_SUB_ID)
                         .getMaxTextLimit()) });
 
+        if (PrefsUtils.isShowEmoticonsEnabled()) {
+            mComposeEditText.setInputType(mComposeEditText.getInputType()
+                    | InputType.TYPE_TEXT_VARIATION_SHORT_MESSAGE);
+        } else {
+            mComposeEditText.setInputType(mComposeEditText.getInputType()
+                    & ~InputType.TYPE_TEXT_VARIATION_SHORT_MESSAGE);
+        }
+
         mSelfSendIcon = (SimIconView) findViewById(R.id.self_send_icon);
         mSelfSendIcon.setOnClickListener(new OnClickListener() {
             @Override
diff --git a/src/org/lineageos/messaging/util/PrefsUtils.java b/src/org/lineageos/messaging/util/PrefsUtils.java
index fa08af4..ad0bc13 100644
--- a/src/org/lineageos/messaging/util/PrefsUtils.java
+++ b/src/org/lineageos/messaging/util/PrefsUtils.java
@@ -22,6 +22,8 @@
 import com.android.messaging.util.BuglePrefs;
 
 public class PrefsUtils {
+    public static final String SHOW_EMOTICONS_ENABLED = "pref_show_emoticons";
+
     private PrefsUtils() {
         //Don't instantiate
     }
@@ -39,4 +41,12 @@
                 R.bool.swipe_right_deletes_conversation_default);
         return prefs.getBoolean(prefKey, defaultValue);
     }
+
+    public static boolean isShowEmoticonsEnabled() {
+        final BuglePrefs prefs = BuglePrefs.getApplicationPrefs();
+        final Context context = Factory.get().getApplicationContext();
+        final boolean defaultValue = context.getResources().getBoolean(
+                R.bool.show_emoticons_pref_default);
+        return prefs.getBoolean(SHOW_EMOTICONS_ENABLED, defaultValue);
+    }
 }