From 6636476cf06ccabc81fcc951f842a34a7f4b5840 Mon Sep 17 00:00:00 2001 From: Tomaž Vajngerl Date: Fri, 13 Nov 2015 11:01:37 +0100 Subject: android: Add string searching + search toolbar LOKit supports searching, but this was not implemented yet in the Android GUI. This adds a bottom search toolbar where you can type a search string + up/down search handles to search for the string from the current cursor position. Change-Id: Ia7461d2c6399c23201d2ea81f0b44c38533939a1 --- .../res/drawable-xxxhdpi/ic_search_black_24dp.png | Bin 0 -> 868 bytes .../ic_search_direction_down_black_24dp.png | Bin 0 -> 256 bytes .../ic_search_direction_up_black_24dp.png | Bin 0 -> 261 bytes android/source/res/drawable/ic_search.xml | 5 ++ .../res/drawable/ic_search_direction_down.xml | 5 ++ .../source/res/drawable/ic_search_direction_up.xml | 5 ++ android/source/res/layout/toolbar_bottom.xml | 39 ++++++++++++ android/source/res/menu/main.xml | 6 ++ android/source/res/values/strings.xml | 1 + .../org/libreoffice/LibreOfficeMainActivity.java | 31 +++++++++ .../src/java/org/libreoffice/SearchController.java | 70 +++++++++++++++++++++ .../java/org/libreoffice/ToolbarController.java | 3 + .../src/java/org/libreoffice/UnitConverter.java | 12 ++++ .../org/libreoffice/overlay/DocumentOverlay.java | 4 ++ .../libreoffice/overlay/DocumentOverlayView.java | 4 ++ 15 files changed, 185 insertions(+) create mode 100644 android/source/res/drawable-xxxhdpi/ic_search_black_24dp.png create mode 100644 android/source/res/drawable-xxxhdpi/ic_search_direction_down_black_24dp.png create mode 100644 android/source/res/drawable-xxxhdpi/ic_search_direction_up_black_24dp.png create mode 100644 android/source/res/drawable/ic_search.xml create mode 100644 android/source/res/drawable/ic_search_direction_down.xml create mode 100644 android/source/res/drawable/ic_search_direction_up.xml create mode 100644 android/source/src/java/org/libreoffice/SearchController.java create mode 100644 android/source/src/java/org/libreoffice/UnitConverter.java (limited to 'android') diff --git a/android/source/res/drawable-xxxhdpi/ic_search_black_24dp.png b/android/source/res/drawable-xxxhdpi/ic_search_black_24dp.png new file mode 100644 index 000000000000..21be572990b5 Binary files /dev/null and b/android/source/res/drawable-xxxhdpi/ic_search_black_24dp.png differ diff --git a/android/source/res/drawable-xxxhdpi/ic_search_direction_down_black_24dp.png b/android/source/res/drawable-xxxhdpi/ic_search_direction_down_black_24dp.png new file mode 100644 index 000000000000..ad852e3e6f76 Binary files /dev/null and b/android/source/res/drawable-xxxhdpi/ic_search_direction_down_black_24dp.png differ diff --git a/android/source/res/drawable-xxxhdpi/ic_search_direction_up_black_24dp.png b/android/source/res/drawable-xxxhdpi/ic_search_direction_up_black_24dp.png new file mode 100644 index 000000000000..99c6e3e1c202 Binary files /dev/null and b/android/source/res/drawable-xxxhdpi/ic_search_direction_up_black_24dp.png differ diff --git a/android/source/res/drawable/ic_search.xml b/android/source/res/drawable/ic_search.xml new file mode 100644 index 000000000000..9dd529cb9dde --- /dev/null +++ b/android/source/res/drawable/ic_search.xml @@ -0,0 +1,5 @@ + + + \ No newline at end of file diff --git a/android/source/res/drawable/ic_search_direction_down.xml b/android/source/res/drawable/ic_search_direction_down.xml new file mode 100644 index 000000000000..92cecedf4494 --- /dev/null +++ b/android/source/res/drawable/ic_search_direction_down.xml @@ -0,0 +1,5 @@ + + + \ No newline at end of file diff --git a/android/source/res/drawable/ic_search_direction_up.xml b/android/source/res/drawable/ic_search_direction_up.xml new file mode 100644 index 000000000000..a6370607da3b --- /dev/null +++ b/android/source/res/drawable/ic_search_direction_up.xml @@ -0,0 +1,5 @@ + + + \ No newline at end of file diff --git a/android/source/res/layout/toolbar_bottom.xml b/android/source/res/layout/toolbar_bottom.xml index 7b4d01be2a03..9de4906fe0e5 100644 --- a/android/source/res/layout/toolbar_bottom.xml +++ b/android/source/res/layout/toolbar_bottom.xml @@ -130,6 +130,45 @@ android:layout_height="wrap_content" android:layout_weight="1" android:minHeight="50dip"/> + + + + + + + + + + + + + + diff --git a/android/source/res/menu/main.xml b/android/source/res/menu/main.xml index b80cae9db8e8..d000be8fe69c 100644 --- a/android/source/res/menu/main.xml +++ b/android/source/res/menu/main.xml @@ -19,6 +19,12 @@ android:orderInCategory="100" app:showAsAction="always"/> + + diff --git a/android/source/res/values/strings.xml b/android/source/res/values/strings.xml index ed8529fca699..9340b3283be6 100644 --- a/android/source/res/values/strings.xml +++ b/android/source/res/values/strings.xml @@ -65,6 +65,7 @@ Show keyboard Save Enable Format + Search Save complete diff --git a/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java b/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java index 9c47ffe92be9..7027e37d33bf 100644 --- a/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java +++ b/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java @@ -9,6 +9,7 @@ import android.content.Intent; import android.content.SharedPreferences; import android.content.res.AssetFileDescriptor; import android.content.res.AssetManager; +import android.graphics.RectF; import android.os.AsyncTask; import android.os.Bundle; import android.os.Handler; @@ -77,6 +78,7 @@ public class LibreOfficeMainActivity extends AppCompatActivity { private FormattingController mFormattingController; private ToolbarController mToolbarController; private FontController mFontController; + private SearchController mSearchController; public LibreOfficeMainActivity() { mAbout = new LOAbout(this, false); @@ -127,6 +129,7 @@ public class LibreOfficeMainActivity extends AppCompatActivity { }); mFontController = new FontController(this); + mSearchController = new SearchController(this); if (getIntent().getData() != null) { if (getIntent().getData().getScheme().equals(ContentResolver.SCHEME_CONTENT)) { @@ -181,6 +184,10 @@ public class LibreOfficeMainActivity extends AppCompatActivity { mToolbarController.setupToolbars(); } + public RectF getCurrentCursorPosition() { + return mDocumentOverlay.getCurrentCursorPosition(); + } + private boolean copyFileToTemp() { ContentResolver contentResolver = getContentResolver(); FileChannel inputChannel = null; @@ -430,6 +437,7 @@ public class LibreOfficeMainActivity extends AppCompatActivity { public void run() { findViewById(R.id.toolbar_bottom).setVisibility(View.GONE); findViewById(R.id.formatting_toolbar).setVisibility(View.GONE); + findViewById(R.id.search_toolbar).setVisibility(View.GONE); } }); } @@ -440,6 +448,7 @@ public class LibreOfficeMainActivity extends AppCompatActivity { public void run() { showBottomToolbar(); findViewById(R.id.formatting_toolbar).setVisibility(View.VISIBLE); + findViewById(R.id.search_toolbar).setVisibility(View.GONE); hideSoftKeyboardDirect(); } }); @@ -455,6 +464,28 @@ public class LibreOfficeMainActivity extends AppCompatActivity { }); } + public void showSearchToolbar() { + LOKitShell.getMainHandler().post(new Runnable() { + @Override + public void run() { + showBottomToolbar(); + findViewById(R.id.formatting_toolbar).setVisibility(View.GONE); + findViewById(R.id.search_toolbar).setVisibility(View.VISIBLE); + hideSoftKeyboardDirect(); + } + }); + } + + public void hideSearchToolbar() { + LOKitShell.getMainHandler().post(new Runnable() { + @Override + public void run() { + hideBottomToolbar(); + findViewById(R.id.search_toolbar).setVisibility(View.GONE); + } + }); + } + public void showProgressSpinner() { findViewById(R.id.loadingPanel).setVisibility(View.VISIBLE); } diff --git a/android/source/src/java/org/libreoffice/SearchController.java b/android/source/src/java/org/libreoffice/SearchController.java new file mode 100644 index 000000000000..026a75327101 --- /dev/null +++ b/android/source/src/java/org/libreoffice/SearchController.java @@ -0,0 +1,70 @@ +package org.libreoffice; + +import android.view.View; +import android.widget.EditText; +import android.widget.ImageButton; + +import org.json.JSONException; +import org.json.JSONObject; + +public class SearchController implements View.OnClickListener { + private LibreOfficeMainActivity mActivity; + + private enum SearchDriection { + UP, DOWN + }; + + public SearchController(LibreOfficeMainActivity activity) { + mActivity = activity; + + ((ImageButton) activity.findViewById(R.id.button_search_up)).setOnClickListener(this); + ((ImageButton) activity.findViewById(R.id.button_search_down)).setOnClickListener(this); + } + + private void search(String searchString, SearchDriection direction, float x, float y) { + try { + JSONObject rootJson = new JSONObject(); + + addProperty(rootJson, "SearchItem.SearchString", "string", searchString); + addProperty(rootJson, "SearchItem.Backward", "boolean", direction == SearchDriection.DOWN ? "true" : "false"); + addProperty(rootJson, "SearchItem.SearchStartPointX", "long", String.valueOf((long) UnitConverter.pixelToTwip(x, LOKitShell.getDpi()))); + addProperty(rootJson, "SearchItem.SearchStartPointY", "long", String.valueOf((long) UnitConverter.pixelToTwip(y, LOKitShell.getDpi()))); + addProperty(rootJson, "SearchItem.Command", "long", String.valueOf(0)); // search all == 1 + + LOKitShell.sendEvent(new LOEvent(LOEvent.UNO_COMMAND, ".uno:ExecuteSearch", rootJson.toString())); + + } catch (JSONException e) { + e.printStackTrace(); + } + } + + private void addProperty(JSONObject json, String parentValue, String type, String value) throws JSONException { + JSONObject child = new JSONObject(); + child.put("type", type); + child.put("value", value); + json.put(parentValue, child); + } + + @Override + public void onClick(View view) { + ImageButton button = (ImageButton) view; + + SearchDriection direction = SearchDriection.DOWN; + switch(button.getId()) { + case R.id.button_search_down: + direction = SearchDriection.DOWN; + break; + case R.id.button_search_up: + direction = SearchDriection.UP; + break; + default: + break; + } + + 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); + } +} diff --git a/android/source/src/java/org/libreoffice/ToolbarController.java b/android/source/src/java/org/libreoffice/ToolbarController.java index 08e981c42ece..a03abc653d39 100644 --- a/android/source/src/java/org/libreoffice/ToolbarController.java +++ b/android/source/src/java/org/libreoffice/ToolbarController.java @@ -126,6 +126,9 @@ public class ToolbarController implements Toolbar.OnMenuItemClickListener { case R.id.action_settings: mContext.showSettings(); return true; + case R.id.action_search: + mContext.showSearchToolbar(); + return true; } return false; } diff --git a/android/source/src/java/org/libreoffice/UnitConverter.java b/android/source/src/java/org/libreoffice/UnitConverter.java new file mode 100644 index 000000000000..e0dcfb86b93f --- /dev/null +++ b/android/source/src/java/org/libreoffice/UnitConverter.java @@ -0,0 +1,12 @@ +package org.libreoffice; + + +public class UnitConverter { + public static float twipToPixel(float input, float dpi) { + return input / 1440.0f * dpi; + } + + public static float pixelToTwip(float input, float dpi) { + return (input / dpi) * 1440.0f; + } +} diff --git a/android/source/src/java/org/libreoffice/overlay/DocumentOverlay.java b/android/source/src/java/org/libreoffice/overlay/DocumentOverlay.java index 40e4eaadc99e..f2c4c8f47725 100644 --- a/android/source/src/java/org/libreoffice/overlay/DocumentOverlay.java +++ b/android/source/src/java/org/libreoffice/overlay/DocumentOverlay.java @@ -205,6 +205,10 @@ public class DocumentOverlay { } }); } + + public RectF getCurrentCursorPosition() { + return mDocumentOverlayView.getCurrentCursorPosition(); + } } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/android/source/src/java/org/libreoffice/overlay/DocumentOverlayView.java b/android/source/src/java/org/libreoffice/overlay/DocumentOverlayView.java index 8d199e4775f7..ce600dc984ae 100644 --- a/android/source/src/java/org/libreoffice/overlay/DocumentOverlayView.java +++ b/android/source/src/java/org/libreoffice/overlay/DocumentOverlayView.java @@ -384,6 +384,10 @@ public class DocumentOverlayView extends View implements View.OnTouchListener { } return null; } + + public RectF getCurrentCursorPosition() { + return mCursor.mPosition; + } } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit v1.2.3