summaryrefslogtreecommitdiff
path: root/android
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.com>2015-11-13 11:01:37 +0100
committerTomaž Vajngerl <tomaz.vajngerl@collabora.com>2015-11-13 11:40:33 +0100
commit6636476cf06ccabc81fcc951f842a34a7f4b5840 (patch)
tree8cb6e4f4269e8aa538d832946410f3bd73b61674 /android
parent319623a3345b5cb11f0d42c6e7781734ff1a3a40 (diff)
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
Diffstat (limited to 'android')
-rw-r--r--android/source/res/drawable-xxxhdpi/ic_search_black_24dp.pngbin0 -> 868 bytes
-rw-r--r--android/source/res/drawable-xxxhdpi/ic_search_direction_down_black_24dp.pngbin0 -> 256 bytes
-rw-r--r--android/source/res/drawable-xxxhdpi/ic_search_direction_up_black_24dp.pngbin0 -> 261 bytes
-rw-r--r--android/source/res/drawable/ic_search.xml5
-rw-r--r--android/source/res/drawable/ic_search_direction_down.xml5
-rw-r--r--android/source/res/drawable/ic_search_direction_up.xml5
-rw-r--r--android/source/res/layout/toolbar_bottom.xml39
-rw-r--r--android/source/res/menu/main.xml6
-rw-r--r--android/source/res/values/strings.xml1
-rw-r--r--android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java31
-rw-r--r--android/source/src/java/org/libreoffice/SearchController.java70
-rw-r--r--android/source/src/java/org/libreoffice/ToolbarController.java3
-rw-r--r--android/source/src/java/org/libreoffice/UnitConverter.java12
-rw-r--r--android/source/src/java/org/libreoffice/overlay/DocumentOverlay.java4
-rw-r--r--android/source/src/java/org/libreoffice/overlay/DocumentOverlayView.java4
15 files changed, 185 insertions, 0 deletions
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
--- /dev/null
+++ b/android/source/res/drawable-xxxhdpi/ic_search_black_24dp.png
Binary files 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
--- /dev/null
+++ b/android/source/res/drawable-xxxhdpi/ic_search_direction_down_black_24dp.png
Binary files 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
--- /dev/null
+++ b/android/source/res/drawable-xxxhdpi/ic_search_direction_up_black_24dp.png
Binary files 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 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
+ android:src="@drawable/ic_search_black_24dp"
+ android:tint="@color/toolbar_forgeround"/> \ 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 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
+ android:src="@drawable/ic_search_direction_down_black_24dp"
+ android:tint="@color/toolbar_forgeround"/> \ 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 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
+ android:src="@drawable/ic_search_direction_up_black_24dp"
+ android:tint="@color/toolbar_forgeround"/> \ 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"/>
+
+
+ </LinearLayout>
+
+ <LinearLayout
+ android:id="@+id/search_toolbar"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:orientation="vertical">
+
+ <LinearLayout
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:orientation="horizontal">
+
+ <EditText
+ android:id="@+id/search_string"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:layout_weight="0.2"/>
+
+ <ImageButton
+ android:id="@+id/button_search_up"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:layout_weight="0.6"
+ android:background="@drawable/image_button_background"
+ android:padding="10dp"
+ android:src="@drawable/ic_search_direction_down"/>
+
+ <ImageButton
+ android:id="@+id/button_search_down"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:layout_weight="0.6"
+ android:background="@drawable/image_button_background"
+ android:padding="10dp"
+ android:src="@drawable/ic_search_direction_up"/>
+ </LinearLayout>
</LinearLayout>
</LinearLayout>
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"/>
+ <item android:id="@+id/action_search"
+ android:title="@string/action_search"
+ android:icon="@drawable/ic_search"
+ android:orderInCategory="100"
+ app:showAsAction="always"/>
+
<item android:id="@+id/action_save"
android:title="@string/action_save"
android:orderInCategory="100" />
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 @@
<string name="action_keyboard">Show keyboard</string>
<string name="action_save">Save</string>
<string name="action_fromat">Enable Format</string>
+ <string name="action_search">Search</string>
<!-- Feedback messages -->
<string name="message_saved">Save complete</string>
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: */