From a927163e253e3c6a3e3aa8b853023f3c4ba18116 Mon Sep 17 00:00:00 2001 From: Maurits Dijkstra Date: Sun, 1 Jan 2017 18:43:50 +0100 Subject: [PATCH 1/4] Made the auto-correct and auto-capitalization flags of the main text input field configurable. --- .../WeechatAndroid/fragments/BufferFragment.java | 13 +++++++++++++ .../com/ubergeek42/WeechatAndroid/service/P.java | 7 ++++++- .../ubergeek42/WeechatAndroid/utils/Constants.java | 2 ++ .../src/main/res/layout/chatview_main.xml | 2 +- weechat-android/src/main/res/values/strings.xml | 4 +++- weechat-android/src/main/res/xml/preferences.xml | 4 +++- 6 files changed, 28 insertions(+), 4 deletions(-) diff --git a/weechat-android/src/main/java/com/ubergeek42/WeechatAndroid/fragments/BufferFragment.java b/weechat-android/src/main/java/com/ubergeek42/WeechatAndroid/fragments/BufferFragment.java index 4b849e213..c65f9bf3c 100644 --- a/weechat-android/src/main/java/com/ubergeek42/WeechatAndroid/fragments/BufferFragment.java +++ b/weechat-android/src/main/java/com/ubergeek42/WeechatAndroid/fragments/BufferFragment.java @@ -11,6 +11,7 @@ import android.content.Context; import android.os.Bundle; import android.text.Editable; +import android.text.InputType; import android.text.TextWatcher; import android.view.KeyEvent; import android.view.LayoutInflater; @@ -35,6 +36,7 @@ import com.ubergeek42.WeechatAndroid.relay.BufferList; import com.ubergeek42.WeechatAndroid.relay.Line; import com.ubergeek42.WeechatAndroid.service.P; +import com.ubergeek42.WeechatAndroid.utils.ActionEditText; import com.ubergeek42.WeechatAndroid.utils.CopyPaste; import com.ubergeek42.weechat.ColorScheme; @@ -138,6 +140,17 @@ public void onStart() { started = true; uiSend.setVisibility(P.showSend ? View.VISIBLE : View.GONE); uiTab.setVisibility(P.showTab ? View.VISIBLE : View.GONE); + int inputType = InputType.TYPE_CLASS_TEXT; + + if(P.enableAutoCorrect) { + inputType |= InputType.TYPE_TEXT_FLAG_AUTO_CORRECT; + } else { + inputType |= InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS; + } + if(P.enableAutoCapitalize) { + inputType |= InputType.TYPE_TEXT_FLAG_CAP_SENTENCES; + } + uiInput.setInputType(inputType); uiLines.setBackgroundColor(0xFF000000 | ColorScheme.get().defaul[ColorScheme.OPT_BG]); EventBus.getDefault().registerSticky(this); } diff --git a/weechat-android/src/main/java/com/ubergeek42/WeechatAndroid/service/P.java b/weechat-android/src/main/java/com/ubergeek42/WeechatAndroid/service/P.java index dfe6be4fb..86b84affe 100644 --- a/weechat-android/src/main/java/com/ubergeek42/WeechatAndroid/service/P.java +++ b/weechat-android/src/main/java/com/ubergeek42/WeechatAndroid/service/P.java @@ -71,7 +71,8 @@ public static void init(@NonNull Context context) { public static boolean notificationEnable, notificationTicker, notificationLight, notificationVibrate; public static String notificationSound; - public static boolean showSend, showTab, hotlistSync, volumeBtnSize; + public static boolean showSend, showTab, enableAutoCapitalize, enableAutoCorrect, hotlistSync; + public static boolean volumeBtnSize; public static String bufferFont; public static boolean showBufferFilter; @@ -104,6 +105,8 @@ public static void loadUIPreferences() { // buffer fragment showSend = p.getBoolean(PREF_SHOW_SEND, PREF_SHOW_SEND_D); showTab = p.getBoolean(PREF_SHOW_TAB, PREF_SHOW_TAB_D); + enableAutoCapitalize = p.getBoolean(PREF_ENABLE_AUTO_CAPITALIZE, PREF_ENABLE_AUTO_CAPITALIZE_D); + enableAutoCorrect = p.getBoolean(PREF_ENABLE_AUTO_CORRECT, PREF_ENABLE_AUTO_CORRECT_D); hotlistSync = p.getBoolean(PREF_HOTLIST_SYNC, PREF_HOTLIST_SYNC_D); volumeBtnSize = p.getBoolean(PREF_VOLUME_BTN_SIZE, PREF_VOLUME_BTN_SIZE_D); @@ -223,6 +226,8 @@ public static void loadConnectionPreferences() { // buffer fragment case PREF_SHOW_SEND: showSend = p.getBoolean(key, PREF_SHOW_SEND_D); break; case PREF_SHOW_TAB: showTab = p.getBoolean(key, PREF_SHOW_TAB_D); break; + case PREF_ENABLE_AUTO_CAPITALIZE: enableAutoCapitalize = p.getBoolean(key, PREF_ENABLE_AUTO_CAPITALIZE_D); break; + case PREF_ENABLE_AUTO_CORRECT: enableAutoCorrect = p.getBoolean(key, PREF_ENABLE_AUTO_CORRECT_D); break; case PREF_HOTLIST_SYNC: hotlistSync = p.getBoolean(key, PREF_HOTLIST_SYNC_D); break; case PREF_VOLUME_BTN_SIZE: volumeBtnSize = p.getBoolean(key, PREF_VOLUME_BTN_SIZE_D); break; diff --git a/weechat-android/src/main/java/com/ubergeek42/WeechatAndroid/utils/Constants.java b/weechat-android/src/main/java/com/ubergeek42/WeechatAndroid/utils/Constants.java index b4b12aa52..ef0bf2883 100644 --- a/weechat-android/src/main/java/com/ubergeek42/WeechatAndroid/utils/Constants.java +++ b/weechat-android/src/main/java/com/ubergeek42/WeechatAndroid/utils/Constants.java @@ -66,6 +66,8 @@ public class Constants { // buttons public final static String PREF_SHOW_SEND = "sendbtn_show"; final public static boolean PREF_SHOW_SEND_D = true; public final static String PREF_SHOW_TAB = "tabbtn_show"; final public static boolean PREF_SHOW_TAB_D = true; + public final static String PREF_ENABLE_AUTO_CORRECT = "autocorrect_input"; final public static boolean PREF_ENABLE_AUTO_CORRECT_D = true; + public final static String PREF_ENABLE_AUTO_CAPITALIZE = "autocapitalize_input"; final public static boolean PREF_ENABLE_AUTO_CAPITALIZE_D = true; public final static String PREF_VOLUME_BTN_SIZE = "volumebtn_size"; final public static boolean PREF_VOLUME_BTN_SIZE_D = true; // notifications diff --git a/weechat-android/src/main/res/layout/chatview_main.xml b/weechat-android/src/main/res/layout/chatview_main.xml index 6d6747d3c..3224975b5 100644 --- a/weechat-android/src/main/res/layout/chatview_main.xml +++ b/weechat-android/src/main/res/layout/chatview_main.xml @@ -19,7 +19,7 @@ android:layout_weight="1.0" android:layout_width="0dp" android:layout_height="wrap_content" - android:inputType="textCapSentences|textMultiLine|textAutoCorrect" + android:inputType="textMultiLine" android:imeOptions="flagNoFullscreen|flagNoExtractUi|actionSend" android:maxLines="4" android:minLines="1" diff --git a/weechat-android/src/main/res/values/strings.xml b/weechat-android/src/main/res/values/strings.xml index e6ea3afc5..3b066e44f 100644 --- a/weechat-android/src/main/res/values/strings.xml +++ b/weechat-android/src/main/res/values/strings.xml @@ -234,9 +234,11 @@ - Buttons + Buttons & input Show tab button Show send button + Enable keyboard auto-capitalization + Enable keyboard auto-correct Volume buttons change text size If set, volume buttons will change text size instead of volume diff --git a/weechat-android/src/main/res/xml/preferences.xml b/weechat-android/src/main/res/xml/preferences.xml index 7cb996b10..4a72c8849 100644 --- a/weechat-android/src/main/res/xml/preferences.xml +++ b/weechat-android/src/main/res/xml/preferences.xml @@ -74,7 +74,9 @@ - + + + From 6443e2ccfadb781abdbe4bcfd2aee3d941c6f629 Mon Sep 17 00:00:00 2001 From: Maurits Dijkstra Date: Tue, 3 Jan 2017 23:12:40 +0100 Subject: [PATCH 2/4] Re-enable the multi line input type flag on the EditText as it is required to show multi line pastes properly. Some keyboards (SwiftKey) refuse to disable auto-capitalization if the multi line flag is also set, but this should be considered a bug in those keyboards. --- .../com/ubergeek42/WeechatAndroid/fragments/BufferFragment.java | 2 +- weechat-android/src/main/res/layout/chatview_main.xml | 1 - weechat-android/src/main/res/values/strings.xml | 1 + weechat-android/src/main/res/xml/preferences.xml | 2 +- 4 files changed, 3 insertions(+), 3 deletions(-) diff --git a/weechat-android/src/main/java/com/ubergeek42/WeechatAndroid/fragments/BufferFragment.java b/weechat-android/src/main/java/com/ubergeek42/WeechatAndroid/fragments/BufferFragment.java index c65f9bf3c..31db251d8 100644 --- a/weechat-android/src/main/java/com/ubergeek42/WeechatAndroid/fragments/BufferFragment.java +++ b/weechat-android/src/main/java/com/ubergeek42/WeechatAndroid/fragments/BufferFragment.java @@ -140,7 +140,7 @@ public void onStart() { started = true; uiSend.setVisibility(P.showSend ? View.VISIBLE : View.GONE); uiTab.setVisibility(P.showTab ? View.VISIBLE : View.GONE); - int inputType = InputType.TYPE_CLASS_TEXT; + int inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_MULTI_LINE; if(P.enableAutoCorrect) { inputType |= InputType.TYPE_TEXT_FLAG_AUTO_CORRECT; diff --git a/weechat-android/src/main/res/layout/chatview_main.xml b/weechat-android/src/main/res/layout/chatview_main.xml index 3224975b5..0f45e0e6f 100644 --- a/weechat-android/src/main/res/layout/chatview_main.xml +++ b/weechat-android/src/main/res/layout/chatview_main.xml @@ -19,7 +19,6 @@ android:layout_weight="1.0" android:layout_width="0dp" android:layout_height="wrap_content" - android:inputType="textMultiLine" android:imeOptions="flagNoFullscreen|flagNoExtractUi|actionSend" android:maxLines="4" android:minLines="1" diff --git a/weechat-android/src/main/res/values/strings.xml b/weechat-android/src/main/res/values/strings.xml index 3b066e44f..3742e05cb 100644 --- a/weechat-android/src/main/res/values/strings.xml +++ b/weechat-android/src/main/res/values/strings.xml @@ -238,6 +238,7 @@ Show tab button Show send button Enable keyboard auto-capitalization + Some keyboards (such as SwiftKey) will refuse to disable auto-capitalization. Enable keyboard auto-correct Volume buttons change text size If set, volume buttons will change text size instead of volume diff --git a/weechat-android/src/main/res/xml/preferences.xml b/weechat-android/src/main/res/xml/preferences.xml index 4a72c8849..e342d0622 100644 --- a/weechat-android/src/main/res/xml/preferences.xml +++ b/weechat-android/src/main/res/xml/preferences.xml @@ -75,7 +75,7 @@ - + From 1b32c12848d8664d65764e3afd239c25422ac1bb Mon Sep 17 00:00:00 2001 From: Maurits Dijkstra Date: Tue, 3 Jan 2017 23:37:21 +0100 Subject: [PATCH 3/4] Found a workaround for the SwiftKey multi line bug/feature by simply not sending the multi line flag to the IME. --- .../fragments/BufferFragment.java | 22 +++++++++---------- .../WeechatAndroid/utils/ActionEditText.java | 2 ++ .../src/main/res/values/strings.xml | 1 - .../src/main/res/xml/preferences.xml | 2 +- 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/weechat-android/src/main/java/com/ubergeek42/WeechatAndroid/fragments/BufferFragment.java b/weechat-android/src/main/java/com/ubergeek42/WeechatAndroid/fragments/BufferFragment.java index 31db251d8..ad667534e 100644 --- a/weechat-android/src/main/java/com/ubergeek42/WeechatAndroid/fragments/BufferFragment.java +++ b/weechat-android/src/main/java/com/ubergeek42/WeechatAndroid/fragments/BufferFragment.java @@ -1,15 +1,10 @@ package com.ubergeek42.WeechatAndroid.fragments; -import java.util.Vector; - import android.annotation.SuppressLint; -import android.support.annotation.NonNull; -import android.support.v4.app.Fragment; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import android.content.Context; import android.os.Bundle; +import android.support.annotation.NonNull; +import android.support.v4.app.Fragment; import android.text.Editable; import android.text.InputType; import android.text.TextWatcher; @@ -27,24 +22,29 @@ import android.widget.TextView; import android.widget.Toast; -import com.ubergeek42.WeechatAndroid.adapters.ChatLinesAdapter; import com.ubergeek42.WeechatAndroid.R; import com.ubergeek42.WeechatAndroid.WeechatActivity; +import com.ubergeek42.WeechatAndroid.adapters.ChatLinesAdapter; import com.ubergeek42.WeechatAndroid.relay.Buffer; import com.ubergeek42.WeechatAndroid.relay.Buffer.LINES; import com.ubergeek42.WeechatAndroid.relay.BufferEye; import com.ubergeek42.WeechatAndroid.relay.BufferList; import com.ubergeek42.WeechatAndroid.relay.Line; import com.ubergeek42.WeechatAndroid.service.P; -import com.ubergeek42.WeechatAndroid.utils.ActionEditText; import com.ubergeek42.WeechatAndroid.utils.CopyPaste; import com.ubergeek42.weechat.ColorScheme; -import static com.ubergeek42.WeechatAndroid.service.Events.*; -import static com.ubergeek42.WeechatAndroid.service.RelayService.STATE.*; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Vector; import de.greenrobot.event.EventBus; +import static com.ubergeek42.WeechatAndroid.service.Events.SendMessageEvent; +import static com.ubergeek42.WeechatAndroid.service.Events.StateChangedEvent; +import static com.ubergeek42.WeechatAndroid.service.RelayService.STATE.LISTED; + public class BufferFragment extends Fragment implements BufferEye, OnKeyListener, OnClickListener, TextWatcher, TextView.OnEditorActionListener { diff --git a/weechat-android/src/main/java/com/ubergeek42/WeechatAndroid/utils/ActionEditText.java b/weechat-android/src/main/java/com/ubergeek42/WeechatAndroid/utils/ActionEditText.java index 133f14311..16ddde055 100644 --- a/weechat-android/src/main/java/com/ubergeek42/WeechatAndroid/utils/ActionEditText.java +++ b/weechat-android/src/main/java/com/ubergeek42/WeechatAndroid/utils/ActionEditText.java @@ -2,6 +2,7 @@ import android.content.Context; import android.support.v7.widget.AppCompatEditText; +import android.text.InputType; import android.util.AttributeSet; import android.view.inputmethod.EditorInfo; import android.view.inputmethod.InputConnection; @@ -23,6 +24,7 @@ public ActionEditText(Context context, AttributeSet attrs, int defStyle) { public InputConnection onCreateInputConnection(EditorInfo outAttrs) { InputConnection conn = super.onCreateInputConnection(outAttrs); outAttrs.imeOptions &= ~EditorInfo.IME_FLAG_NO_ENTER_ACTION; + outAttrs.inputType &= ~InputType.TYPE_TEXT_FLAG_MULTI_LINE; return conn; } } diff --git a/weechat-android/src/main/res/values/strings.xml b/weechat-android/src/main/res/values/strings.xml index 3742e05cb..3b066e44f 100644 --- a/weechat-android/src/main/res/values/strings.xml +++ b/weechat-android/src/main/res/values/strings.xml @@ -238,7 +238,6 @@ Show tab button Show send button Enable keyboard auto-capitalization - Some keyboards (such as SwiftKey) will refuse to disable auto-capitalization. Enable keyboard auto-correct Volume buttons change text size If set, volume buttons will change text size instead of volume diff --git a/weechat-android/src/main/res/xml/preferences.xml b/weechat-android/src/main/res/xml/preferences.xml index e342d0622..4a72c8849 100644 --- a/weechat-android/src/main/res/xml/preferences.xml +++ b/weechat-android/src/main/res/xml/preferences.xml @@ -75,7 +75,7 @@ - + From 5454a9fc43416b68b8544465e62ef7b2dc8ddfbc Mon Sep 17 00:00:00 2001 From: Maurits Dijkstra Date: Wed, 4 Jan 2017 11:24:02 +0100 Subject: [PATCH 4/4] Correct indentation in the preferences XML. --- weechat-android/src/main/res/xml/preferences.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/weechat-android/src/main/res/xml/preferences.xml b/weechat-android/src/main/res/xml/preferences.xml index 4a72c8849..07e01c1bb 100644 --- a/weechat-android/src/main/res/xml/preferences.xml +++ b/weechat-android/src/main/res/xml/preferences.xml @@ -74,9 +74,9 @@ - - - + + +