Kaydet (Commit) bec54f3f authored tarafından Tomaž Vajngerl's avatar Tomaž Vajngerl

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
(cherry picked from commit 6636476c)
üst 5b43e106
<?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
<?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
<?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
......@@ -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>
......
......@@ -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" />
......
......@@ -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>
......
......@@ -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);
}
......
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);
}
}
......@@ -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;
}
......
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;
}
}
......@@ -205,6 +205,10 @@ public class DocumentOverlay {
}
});
}
public RectF getCurrentCursorPosition() {
return mDocumentOverlayView.getCurrentCursorPosition();
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -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: */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment