summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java35
-rw-r--r--android/source/src/java/org/libreoffice/ToolbarController.java17
-rw-r--r--android/source/src/java/org/libreoffice/ui/FileUtilities.java5
-rw-r--r--android/source/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java51
4 files changed, 32 insertions, 76 deletions
diff --git a/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java b/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java
index 1812ad253744..066c05dc9662 100644
--- a/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java
+++ b/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java
@@ -169,24 +169,12 @@ public class LibreOfficeMainActivity extends AppCompatActivity implements Settin
mDocumentOverlay = new DocumentOverlay(this, layerView);
mbISReadOnlyMode = !isExperimentalMode();
- boolean isNewDocument = false;
mDocumentUri = getIntent().getData();
if (mDocumentUri != null) {
if (mDocumentUri.getScheme().equals(ContentResolver.SCHEME_CONTENT)
|| mDocumentUri.getScheme().equals(ContentResolver.SCHEME_ANDROID_RESOURCE)) {
- final boolean isReadOnlyDoc;
- if (getIntent().getStringExtra(LibreOfficeUIActivity.NEW_DOC_TYPE_KEY) != null) {
- // New document type string is not null, meaning we want to open a new document
- String newDocumentType = getIntent().getStringExtra(LibreOfficeUIActivity.NEW_DOC_TYPE_KEY);
- // create a temporary local file, will be copied to the actual URI when saving
- loadNewDocument(newDocumentType);
- isNewDocument = true;
- isReadOnlyDoc = false;
- } else {
- isReadOnlyDoc = (getIntent().getFlags() & Intent.FLAG_GRANT_WRITE_URI_PERMISSION) == 0;
- }
-
+ final boolean isReadOnlyDoc = (getIntent().getFlags() & Intent.FLAG_GRANT_WRITE_URI_PERMISSION) == 0;
mbISReadOnlyMode = !isExperimentalMode() || isReadOnlyDoc;
Log.d(LOGTAG, "SCHEME_CONTENT: getPath(): " + mDocumentUri.getPath());
@@ -198,12 +186,6 @@ public class LibreOfficeMainActivity extends AppCompatActivity implements Settin
Log.d(LOGTAG, "SCHEME_FILE: getPath(): " + mDocumentUri.getPath());
toolbarTop.setTitle(mDocumentUri.getLastPathSegment());
}
- } else {
- Log.e(LOGTAG, "No document specified. This should never happen.");
- return;
- }
-
- if (!isNewDocument) {
// create a temporary local copy to work with
boolean copyOK = copyFileToTemp() && mTempFile != null;
if (!copyOK) {
@@ -212,6 +194,15 @@ public class LibreOfficeMainActivity extends AppCompatActivity implements Settin
return;
}
LOKitShell.sendLoadEvent(mTempFile.getPath());
+ } else if (getIntent().getStringExtra(LibreOfficeUIActivity.NEW_DOC_TYPE_KEY) != null) {
+ // New document type string is not null, meaning we want to open a new document
+ String newDocumentType = getIntent().getStringExtra(LibreOfficeUIActivity.NEW_DOC_TYPE_KEY);
+ // create a temporary local file, will be copied to the actual URI when saving
+ loadNewDocument(newDocumentType);
+ toolbarTop.setTitle(getString(R.string.default_document_name));
+ } else {
+ Log.e(LOGTAG, "No document specified. This should never happen.");
+ return;
}
mDrawerLayout = findViewById(R.id.drawer_layout);
@@ -339,6 +330,8 @@ public class LibreOfficeMainActivity extends AppCompatActivity implements Settin
String displayName = FileUtilities.retrieveDisplayNameForDocumentUri(getContentResolver(), mDocumentUri);
toolbarTop.setTitle(displayName);
+ // make sure that "Save" menu item is enabled
+ getToolbarController().setupToolbars();
}
public void exportToPDF() {
@@ -880,6 +873,10 @@ public class LibreOfficeMainActivity extends AppCompatActivity implements Settin
return mbISReadOnlyMode;
}
+ public boolean hasLocationForSave() {
+ return mDocumentUri != null;
+ }
+
public static void setDocumentChanged (boolean changed) {
isDocumentChanged = changed;
}
diff --git a/android/source/src/java/org/libreoffice/ToolbarController.java b/android/source/src/java/org/libreoffice/ToolbarController.java
index 1384339f8c30..d4985aee180e 100644
--- a/android/source/src/java/org/libreoffice/ToolbarController.java
+++ b/android/source/src/java/org/libreoffice/ToolbarController.java
@@ -45,12 +45,12 @@ public class ToolbarController implements Toolbar.OnMenuItemClickListener {
clipboardManager = (ClipboardManager)mContext.getSystemService(Context.CLIPBOARD_SERVICE);
}
- public void disableMenuItem(final int menuItemId, final boolean disabled) {
+ private void enableMenuItem(final int menuItemId, final boolean enabled) {
LOKitShell.getMainHandler().post(new Runnable() {
public void run() {
MenuItem menuItem = mMainMenu.findItem(menuItemId);
if (menuItem != null) {
- menuItem.setEnabled(!disabled);
+ menuItem.setEnabled(enabled);
} else {
Log.e(LOGTAG, "MenuItem not found.");
}
@@ -245,11 +245,14 @@ public class ToolbarController implements Toolbar.OnMenuItemClickListener {
}
void setupToolbars() {
- // show message in case experimental mode is enabled (i.e. editing is supported in general),
- // but current document is readonly
- if (LibreOfficeMainActivity.isExperimentalMode() && LibreOfficeMainActivity.isReadOnlyMode()) {
- disableMenuItem(R.id.action_save, true);
- Toast.makeText(mContext, mContext.getString(R.string.temp_file_saving_disabled), Toast.LENGTH_LONG).show();
+ if (LibreOfficeMainActivity.isExperimentalMode()) {
+ boolean enableSaveEntry = !LibreOfficeMainActivity.isReadOnlyMode() && mContext.hasLocationForSave();
+ enableMenuItem(R.id.action_save, enableSaveEntry);
+ if (LibreOfficeMainActivity.isReadOnlyMode()) {
+ // show message in case experimental mode is enabled (i.e. editing is supported in general),
+ // but current document is readonly
+ Toast.makeText(mContext, mContext.getString(R.string.temp_file_saving_disabled), Toast.LENGTH_LONG).show();
+ }
}
mMainMenu.findItem(R.id.action_parts).setVisible(mContext.isDrawerEnabled());
}
diff --git a/android/source/src/java/org/libreoffice/ui/FileUtilities.java b/android/source/src/java/org/libreoffice/ui/FileUtilities.java
index 660fbc0e4528..0d51dd55e1e5 100644
--- a/android/source/src/java/org/libreoffice/ui/FileUtilities.java
+++ b/android/source/src/java/org/libreoffice/ui/FileUtilities.java
@@ -33,11 +33,6 @@ public class FileUtilities {
static final int UNKNOWN = 10;
- public static final String DEFAULT_WRITER_EXTENSION = ".odt";
- public static final String DEFAULT_IMPRESS_EXTENSION = ".odp";
- public static final String DEFAULT_SPREADSHEET_EXTENSION = ".ods";
- public static final String DEFAULT_DRAWING_EXTENSION = ".odg";
-
public static final String MIMETYPE_OPENDOCUMENT_TEXT = "application/vnd.oasis.opendocument.text";
public static final String MIMETYPE_OPENDOCUMENT_SPREADSHEET = "application/vnd.oasis.opendocument.spreadsheet";
public static final String MIMETYPE_OPENDOCUMENT_PRESENTATION = "application/vnd.oasis.opendocument.presentation";
diff --git a/android/source/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java b/android/source/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java
index 9f1cd7a9089d..110123f54acf 100644
--- a/android/source/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java
+++ b/android/source/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java
@@ -23,7 +23,6 @@ import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.preference.PreferenceManager;
-import android.support.annotation.NonNull;
import android.support.design.widget.FloatingActionButton;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
@@ -66,9 +65,7 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings
INVALID
}
- private String LOGTAG = LibreOfficeUIActivity.class.getSimpleName();
-
- private DocumentType newDocType = DocumentType.INVALID;
+ private static final String LOGTAG = LibreOfficeUIActivity.class.getSimpleName();
public static final String EXPLORER_PREFS_KEY = "EXPLORER_PREFS";
private static final String RECENT_DOCUMENTS_KEY = "RECENT_DOCUMENT_URIS";
@@ -123,7 +120,6 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings
};
private static final int REQUEST_CODE_OPEN_FILECHOOSER = 12345;
- private static final int REQUEST_CODE_CREATE_NEW_DOCUMENT = 12346;
private static final int PERMISSION_WRITE_EXTERNAL_STORAGE = 0;
@@ -257,10 +253,6 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings
if (requestCode == REQUEST_CODE_OPEN_FILECHOOSER && resultCode == RESULT_OK) {
final Uri fileUri = data.getData();
openDocument(fileUri);
- } else if (requestCode == REQUEST_CODE_CREATE_NEW_DOCUMENT && resultCode == RESULT_OK) {
- // "forward" to LibreOfficeMainActivity to create + open the file
- final Uri fileUri = data.getData();
- loadNewDocument(newDocType, fileUri);
}
}
@@ -295,33 +287,7 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings
startActivity(intent);
}
- private void createNewFileDialog() {
- final String extension;
- if (newDocType == DocumentType.WRITER) {
- extension = FileUtilities.DEFAULT_WRITER_EXTENSION;
- } else if (newDocType == DocumentType.CALC) {
- extension = FileUtilities.DEFAULT_SPREADSHEET_EXTENSION;
- } else if (newDocType == DocumentType.IMPRESS) {
- extension = FileUtilities.DEFAULT_IMPRESS_EXTENSION;
- } else if (newDocType == DocumentType.DRAW) {
- extension = FileUtilities.DEFAULT_DRAWING_EXTENSION;
- } else {
- Log.e(LOGTAG, "Invalid document type passed.");
- return;
- }
-
- String defaultFileName = getString(R.string.default_document_name) + extension;
- String mimeType = FileUtilities.getMimeType(defaultFileName);
-
- Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT);
- intent.addCategory(Intent.CATEGORY_OPENABLE);
- intent.setType(mimeType);
- intent.putExtra(Intent.EXTRA_TITLE, defaultFileName);
-
- startActivityForResult(intent, REQUEST_CODE_CREATE_NEW_DOCUMENT);
- }
-
- private void loadNewDocument(DocumentType docType, Uri newFileUri) {
+ private void loadNewDocument(DocumentType docType) {
final String newDocumentType;
if (docType == DocumentType.WRITER) {
newDocumentType = NEW_WRITER_STRING_KEY;
@@ -338,7 +304,6 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings
Intent intent = new Intent(LibreOfficeUIActivity.this, LibreOfficeMainActivity.class);
intent.putExtra(NEW_DOC_TYPE_KEY, newDocumentType);
- intent.setData(newFileUri);
startActivity(intent);
}
@@ -493,20 +458,16 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings
showSystemFilePickerAndOpenFile();
break;
case R.id.newWriterFAB:
- newDocType = DocumentType.WRITER;
- createNewFileDialog();
+ loadNewDocument(DocumentType.WRITER);
break;
case R.id.newImpressFAB:
- newDocType = DocumentType.IMPRESS;
- createNewFileDialog();
+ loadNewDocument(DocumentType.IMPRESS);
break;
case R.id.newCalcFAB:
- newDocType = DocumentType.CALC;
- createNewFileDialog();
+ loadNewDocument(DocumentType.CALC);
break;
case R.id.newDrawFAB:
- newDocType = DocumentType.DRAW;
- createNewFileDialog();
+ loadNewDocument(DocumentType.DRAW);
break;
}
}