[Libreoffice-commits] core.git: android/source

Michael Weghorn (via logerrit) logerrit at kemper.freedesktop.org
Fri Mar 6 15:47:13 UTC 2020


 android/source/res/layout/toolbar_bottom.xml                  |    3 +
 android/source/src/java/org/libreoffice/SearchController.java |   19 ++++++++++
 2 files changed, 21 insertions(+), 1 deletion(-)

New commits:
commit 8432df8bd8368b7b3d502e025fdae7d2cad06767
Author:     Michael Weghorn <m.weghorn at posteo.de>
AuthorDate: Fri Mar 6 09:36:04 2020 +0100
Commit:     Michael Weghorn <m.weghorn at posteo.de>
CommitDate: Fri Mar 6 16:46:36 2020 +0100

    android: Make keyboard in search bar show "search button"
    
    ... instead of "Enter" key that inserted a newline when clicked.
    Instead, start a search in downward direction when the search button
    is clicked, which makes using the search feature more intuitive.
    
    I quickly tested with both, Writer and Calc.
    
    Change-Id: Iffc9f6115e558721b34d8fb4ae2ed4a36c4a7aa5
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/90092
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <m.weghorn at posteo.de>

diff --git a/android/source/res/layout/toolbar_bottom.xml b/android/source/res/layout/toolbar_bottom.xml
index 7688dd4f01fc..f4b3f3c5f8cc 100644
--- a/android/source/res/layout/toolbar_bottom.xml
+++ b/android/source/res/layout/toolbar_bottom.xml
@@ -435,7 +435,8 @@
             android:layout_width="match_parent"
             android:layout_height="match_parent"
             android:layout_weight="0.2"
-            android:inputType="" />
+            android:imeOptions="actionSearch"
+            android:inputType="text" />
 
         <ImageButton
             android:id="@+id/button_search_down"
diff --git a/android/source/src/java/org/libreoffice/SearchController.java b/android/source/src/java/org/libreoffice/SearchController.java
index 61f5373c82f0..a9414f7f7a71 100644
--- a/android/source/src/java/org/libreoffice/SearchController.java
+++ b/android/source/src/java/org/libreoffice/SearchController.java
@@ -1,8 +1,11 @@
 package org.libreoffice;
 
+import android.view.KeyEvent;
 import android.view.View;
+import android.view.inputmethod.EditorInfo;
 import android.widget.EditText;
 import android.widget.ImageButton;
+import android.widget.TextView;
 
 import org.json.JSONException;
 import org.json.JSONObject;
@@ -19,6 +22,22 @@ public class SearchController implements View.OnClickListener {
 
         activity.findViewById(R.id.button_search_up).setOnClickListener(this);
         activity.findViewById(R.id.button_search_down).setOnClickListener(this);
+
+        ((EditText) mActivity.findViewById(R.id.search_string)).setOnEditorActionListener(new TextView.OnEditorActionListener() {
+            @Override
+            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
+                if (actionId == EditorInfo.IME_ACTION_SEARCH) {
+                    // search downward when the "search button" on keyboard is pressed,
+                    SearchDirection direction = SearchDirection.DOWN;
+                    String searchText = ((EditText) mActivity.findViewById(R.id.search_string)).getText().toString();
+                    float x = mActivity.getCurrentCursorPosition().centerX();
+                    float y = mActivity.getCurrentCursorPosition().centerY();
+                    search(searchText, direction, x, y);
+                    return true;
+                }
+                return false;
+            }
+        });
     }
 
     private void search(String searchString, SearchDirection direction, float x, float y) {


More information about the Libreoffice-commits mailing list