[Libreoffice-commits] core.git: android/source
Libreoffice Gerrit user
logerrit at kemper.freedesktop.org
Tue Jul 31 11:38:50 UTC 2018
android/source/res/menu/main.xml | 14 +
android/source/res/values/strings.xml | 7
android/source/src/java/org/libreoffice/DocumentPartView.java | 4
android/source/src/java/org/libreoffice/InvalidationHandler.java | 23 ++
android/source/src/java/org/libreoffice/LOEvent.java | 8
android/source/src/java/org/libreoffice/LOKitTileProvider.java | 86 ++++++++++
android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java | 29 +++
android/source/src/java/org/libreoffice/TileProvider.java | 5
android/source/src/java/org/libreoffice/ToolbarController.java | 9 +
9 files changed, 182 insertions(+), 3 deletions(-)
New commits:
commit 7a0e523b8875539491ce1cd1975f5c8f243d4c83
Author: Mert Tumer <merttumer at outlook.com>
AuthorDate: Mon Jul 30 05:55:12 2018 -0700
Commit: Tomaž Vajngerl <quikee at gmail.com>
CommitDate: Tue Jul 31 13:38:26 2018 +0200
Rename/Delete worksheets and slides option on Android Viewer
Change-Id: I57f379f0283ecc1a456e44f9fefcfd3b3e56a46c
Signed-off-by: Mert Tumer <merttumer at outlook.com>
Reviewed-on: https://gerrit.libreoffice.org/58327
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>
diff --git a/android/source/res/menu/main.xml b/android/source/res/menu/main.xml
index 764e6e7f97c8..ba807dfd53b3 100644
--- a/android/source/res/menu/main.xml
+++ b/android/source/res/menu/main.xml
@@ -49,6 +49,20 @@
android:title="@string/action_add_worksheet"
android:orderInCategory="100"
android:visible="false" />
+ <item android:id="@+id/action_rename_worksheet"
+ android:title="@string/action_rename_worksheet"
+ android:orderInCategory="100"
+ android:visible="false" />
+
+ <item android:id="@+id/action_delete_worksheet"
+ android:title="@string/action_delete_worksheet"
+ android:orderInCategory="100"
+ android:visible="false"/>
+
+ <item android:id="@+id/action_delete_slide"
+ android:title="@string/action_delete_slide"
+ android:orderInCategory="100"
+ android:visible="false"/>
</group>
<group android:id="@+id/group_edit_clipboard"
diff --git a/android/source/res/values/strings.xml b/android/source/res/values/strings.xml
index b476ac38682e..da23400202d6 100644
--- a/android/source/res/values/strings.xml
+++ b/android/source/res/values/strings.xml
@@ -185,7 +185,12 @@
<string name="insert_table">Insert table</string>
<string name="select_insert_options">Select insert options:</string>
<string name="select_delete_options">Select delete options:</string>
-
+ <string name="action_rename_worksheet">Rename worksheet</string>
+ <string name="action_delete_worksheet">Delete worksheet</string>
+ <string name="action_delete_slide">Delete slide</string>
+ <string name="name_already_used">Given name is already being used.</string>
+ <string name="part_name_changed">Part name has been changed.</string>
+ <string name="part_deleted">Part has been deleted.</string>
<string-array name="insertrowscolumns">
<item>Insert Rows Before</item>
<item>Insert Rows After</item>
diff --git a/android/source/src/java/org/libreoffice/DocumentPartView.java b/android/source/src/java/org/libreoffice/DocumentPartView.java
index 5f72305673c5..f1ce71900d96 100644
--- a/android/source/src/java/org/libreoffice/DocumentPartView.java
+++ b/android/source/src/java/org/libreoffice/DocumentPartView.java
@@ -9,8 +9,8 @@
package org.libreoffice;
public class DocumentPartView {
- public final int partIndex;
- public final String partName;
+ public int partIndex;
+ public String partName;
public DocumentPartView(int partIndex, String partName) {
this.partIndex = partIndex;
diff --git a/android/source/src/java/org/libreoffice/InvalidationHandler.java b/android/source/src/java/org/libreoffice/InvalidationHandler.java
index 25771afdcde3..0f72e7272004 100644
--- a/android/source/src/java/org/libreoffice/InvalidationHandler.java
+++ b/android/source/src/java/org/libreoffice/InvalidationHandler.java
@@ -6,6 +6,7 @@ import android.graphics.RectF;
import android.net.Uri;
import android.util.Log;
import android.widget.EditText;
+import android.widget.Toast;
import org.json.JSONArray;
import org.json.JSONException;
@@ -131,6 +132,28 @@ public class InvalidationHandler implements Document.MessageCallback, Office.Mes
if (payloadObject.getString("success").equals("true")) {
mContext.saveFilesToCloud();
}
+ }else if(payloadObject.getString("commandName").equals(".uno:Name")){
+ //success returns false even though its true for some reason,
+ LOKitShell.getMainHandler().post(new Runnable() {
+ @Override
+ public void run() {
+ mContext.getTileProvider().resetParts();
+ mContext.getDocumentPartViewListAdapter().notifyDataSetChanged();
+ LibreOfficeMainActivity.setDocumentChanged(true);
+ Toast.makeText(mContext, mContext.getString(R.string.part_name_changed), Toast.LENGTH_SHORT).show();
+ }
+ });
+ } else if(payloadObject.getString("commandName").equals(".uno:Remove") ||
+ payloadObject.getString("commandName").equals(".uno:DeletePage") ) {
+ LOKitShell.getMainHandler().post(new Runnable() {
+ @Override
+ public void run() {
+ mContext.getTileProvider().resetParts();
+ mContext.getDocumentPartViewListAdapter().notifyDataSetChanged();
+ LibreOfficeMainActivity.setDocumentChanged(true);
+ Toast.makeText(mContext, mContext.getString(R.string.part_deleted), Toast.LENGTH_SHORT).show();
+ }
+ });
}
}catch(JSONException e){
e.printStackTrace();
diff --git a/android/source/src/java/org/libreoffice/LOEvent.java b/android/source/src/java/org/libreoffice/LOEvent.java
index 7e15dea2b988..4db48a5bbd6d 100644
--- a/android/source/src/java/org/libreoffice/LOEvent.java
+++ b/android/source/src/java/org/libreoffice/LOEvent.java
@@ -89,6 +89,14 @@ public class LOEvent implements Comparable<LOEvent> {
mNotify = notify;
}
+ public LOEvent(int type, String someString, String value, boolean notify) {
+ mType = type;
+ mTypeString = "String";
+ mString = someString;
+ mValue = value;
+ mNotify = notify;
+ }
+
public LOEvent(int type, String key, String value) {
mType = type;
mTypeString = "key / value";
diff --git a/android/source/src/java/org/libreoffice/LOKitTileProvider.java b/android/source/src/java/org/libreoffice/LOKitTileProvider.java
index e5c32dee64ed..3672cdeb0bc2 100644
--- a/android/source/src/java/org/libreoffice/LOKitTileProvider.java
+++ b/android/source/src/java/org/libreoffice/LOKitTileProvider.java
@@ -12,6 +12,7 @@ import android.graphics.Bitmap;
import android.graphics.PointF;
import android.util.Log;
import android.view.KeyEvent;
+import android.widget.Toast;
import org.json.JSONException;
import org.json.JSONObject;
@@ -125,9 +126,12 @@ class LOKitTileProvider implements TileProvider {
if (mDocument.getDocumentType() == Document.DOCTYPE_PRESENTATION) {
mContext.getToolbarController().showItem(R.id.action_presentation);
mContext.getToolbarController().showItem(R.id.action_add_slide);
+ mContext.getToolbarController().showItem(R.id.action_delete_slide);
}
if (mDocument.getDocumentType() == Document.DOCTYPE_SPREADSHEET) {
mContext.getToolbarController().showItem(R.id.action_add_worksheet);
+ mContext.getToolbarController().showItem(R.id.action_rename_worksheet);
+ mContext.getToolbarController().showItem(R.id.action_delete_worksheet);
}
// Writer documents always have one part, so hide the navigation drawer.
@@ -205,6 +209,80 @@ class LOKitTileProvider implements TileProvider {
mContext.getDocumentPartView().add(partView);
}
+ public void resetParts(){
+ int parts = mDocument.getParts();
+ mContext.getDocumentPartView().clear();
+ if (mDocument.getDocumentType() != Document.DOCTYPE_TEXT) {
+ for (int i = 0; i < parts; i++) {
+ String partName = mDocument.getPartName(i);
+
+ if (partName.isEmpty()) {
+ partName = getGenericPartName(i);
+ }
+ Log.i(LOGTAG, "resetParts: " + partName);
+ mDocument.setPart(i);
+ resetDocumentSize();
+ final DocumentPartView partView = new DocumentPartView(i, partName);
+ mContext.getDocumentPartView().add(partView);
+ }
+ }
+ } public void renamePart(String partName) {
+ try{
+ for(int i=0; i<mDocument.getParts(); i++){
+ if(mContext.getDocumentPartView().get(i).partName.equals(partName)){
+ //part name must be unique
+ Toast.makeText(mContext, mContext.getString(R.string.name_already_used), Toast.LENGTH_SHORT).show();
+ return;
+ }
+ }
+ if(isSpreadsheet() == false) {
+ //document must be spreadsheet
+ return;
+ }
+ JSONObject parameter = new JSONObject();
+ JSONObject name = new JSONObject();
+ JSONObject index = new JSONObject();
+ name.put("type", "string");
+ name.put("value", partName);
+ index.put("type","long");
+ index.put("value", getCurrentPartNumber()+1);
+ parameter.put("Name", name);
+ parameter.put("Index", index);
+ LOKitShell.sendEvent(new LOEvent(LOEvent.UNO_COMMAND_NOTIFY, ".uno:Name", parameter.toString(),true));
+ }catch (JSONException e){
+ e.printStackTrace();
+ }
+ }
+
+ public void removePart() {
+ try{
+ if(isSpreadsheet() == false && isPresentation() == false) {
+ //document must be spreadsheet or presentation
+ return;
+ }
+
+ if(isPresentation()){
+ LOKitShell.sendEvent(new LOEvent(LOEvent.UNO_COMMAND_NOTIFY, ".uno:DeletePage", true));
+ return;
+ }
+
+ if(getPartsCount() < 2){
+ return;
+ }
+
+ JSONObject parameter = new JSONObject();
+ JSONObject index = new JSONObject();
+ index.put("type","long");
+ index.put("value", getCurrentPartNumber()+1);
+ parameter.put("Index", index);
+ LOKitShell.sendEvent(new LOEvent(LOEvent.UNO_COMMAND_NOTIFY, ".uno:Remove", parameter.toString(),true));
+ }catch (JSONException e){
+ e.printStackTrace();
+ }
+ }
+
+
+
@Override
public void saveDocumentAs(String filePath, String format) {
final String newFilePath = "file://" + filePath;
@@ -509,6 +587,14 @@ class LOKitTileProvider implements TileProvider {
}
/**
+ * @see TileProvider#isPresentation()
+ */
+ @Override
+ public boolean isPresentation(){
+ return mDocument != null && mDocument.getDocumentType() == Document.DOCTYPE_PRESENTATION;
+ }
+
+ /**
* Returns the Unicode character generated by this event or 0.
*/
private int getCharCode(KeyEvent keyEvent) {
diff --git a/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java b/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java
index e6fbf26c20f3..f92c8bcf977d 100644
--- a/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java
+++ b/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java
@@ -22,11 +22,13 @@ import android.support.design.widget.Snackbar;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
+import android.text.InputType;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
+import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TabHost;
@@ -743,6 +745,33 @@ public class LibreOfficeMainActivity extends AppCompatActivity implements Settin
setDocumentChanged(true);
}
+ public void renamePart(){
+ AlertDialog.Builder builder = new AlertDialog.Builder(this);
+ builder.setTitle("Enter a part name");
+ final EditText input = new EditText(this);
+ input.setInputType(InputType.TYPE_CLASS_TEXT);
+ builder.setView(input);
+
+ builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ mTileProvider.renamePart( input.getText().toString());
+ }
+ });
+ builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ dialog.cancel();
+ }
+ });
+
+ builder.show();
+ }
+
+ public void deletePart() {
+ mTileProvider.removePart();
+ }
+
public void showSettings() {
startActivity(new Intent(getApplicationContext(), SettingsActivity.class));
}
diff --git a/android/source/src/java/org/libreoffice/TileProvider.java b/android/source/src/java/org/libreoffice/TileProvider.java
index 3b6f22873466..ef8ab62bde3c 100644
--- a/android/source/src/java/org/libreoffice/TileProvider.java
+++ b/android/source/src/java/org/libreoffice/TileProvider.java
@@ -82,6 +82,11 @@ public interface TileProvider {
boolean isSpreadsheet();
/**
+ * Returns true if the current open document is a presentation
+ */
+ boolean isPresentation();
+
+ /**
* Trigger a key event.
*
* @param keyEvent - contains information about key event
diff --git a/android/source/src/java/org/libreoffice/ToolbarController.java b/android/source/src/java/org/libreoffice/ToolbarController.java
index 204664d80004..d34a3447ec1c 100644
--- a/android/source/src/java/org/libreoffice/ToolbarController.java
+++ b/android/source/src/java/org/libreoffice/ToolbarController.java
@@ -192,6 +192,15 @@ public class ToolbarController implements Toolbar.OnMenuItemClickListener {
case R.id.action_add_worksheet:
mContext.addPart();
return true;
+ case R.id.action_rename_worksheet:
+ mContext.renamePart();
+ return true;
+ case R.id.action_delete_worksheet:
+ mContext.deletePart();
+ return true;
+ case R.id.action_delete_slide:
+ mContext.deletePart();
+ return true;
case R.id.action_back:
hideClipboardActions();
return true;
More information about the Libreoffice-commits
mailing list