[Libreoffice-commits] online.git: android/app

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Fri Apr 12 08:31:57 UTC 2019


 android/app/src/main/java/org/libreoffice/androidapp/ui/LibreOfficeUIActivity.java |   29 +++++++---
 android/app/src/main/res/values/strings.xml                                        |    2 
 2 files changed, 24 insertions(+), 7 deletions(-)

New commits:
commit caeda968b3e20e9b0a27fdaa12eed8868c735d62
Author:     kaishu-sahu <kaishusahu101 at gmail.com>
AuthorDate: Thu Apr 11 22:05:15 2019 +0530
Commit:     Jan Holesovsky <kendy at collabora.com>
CommitDate: Fri Apr 12 10:31:39 2019 +0200

    android: convert the remaining explicit intents to implicit intents.
    
    Change-Id: I0d9ff0a9726f751041d8ee6bdf3c1cd90e95baf4
    Reviewed-on: https://gerrit.libreoffice.org/70604
    Reviewed-by: Jan Holesovsky <kendy at collabora.com>
    Tested-by: Jan Holesovsky <kendy at collabora.com>

diff --git a/android/app/src/main/java/org/libreoffice/androidapp/ui/LibreOfficeUIActivity.java b/android/app/src/main/java/org/libreoffice/androidapp/ui/LibreOfficeUIActivity.java
index 1e7bb63b2..f2dd9c608 100644
--- a/android/app/src/main/java/org/libreoffice/androidapp/ui/LibreOfficeUIActivity.java
+++ b/android/app/src/main/java/org/libreoffice/androidapp/ui/LibreOfficeUIActivity.java
@@ -614,7 +614,7 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements /*Settin
 
         //warning text to notify the user that such a file already exists
         final TextView warningText = new TextView(this);
-        warningText.setText("A file with this name already exits, and it will be overwritten.");
+        warningText.setText(getString(R.string.file_exists_warning));
         layout.addView(warningText);
         //check if the file exists when showing the create dialog
         File tempFile = new File(currentDirectory.getUri().getPath() + input.getText().toString());
@@ -626,10 +626,21 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements /*Settin
             @Override
             public void onClick(DialogInterface dialog, int which) {
                 final String path = currentDirectory.getUri().getPath() + input.getText().toString();
-                createNewFile(path, extension);
-                Intent intent = new Intent(getBaseContext(), MainActivity.class);
-                intent.putExtra("URI", path);
-                startActivity(intent);
+                Uri newDocUri = createNewFile(path, extension);
+                if (newDocUri != null) {
+                    Intent i = new Intent(Intent.ACTION_VIEW, newDocUri);
+                    String packageName = getApplicationContext().getPackageName();
+                    ComponentName componentName = new ComponentName(packageName,
+                            MainActivity.class.getName());
+                    i.setComponent(componentName);
+                    i.putExtra("org.libreoffice.document_provider_id",
+                            documentProvider.getId());
+                    i.putExtra("org.libreoffice.document_uri",
+                            newDocUri);
+                    startActivity(i);
+                } else {
+                    Toast.makeText(LibreOfficeUIActivity.this, getString(R.string.file_creation_failed), Toast.LENGTH_SHORT).show();
+                }
             }
         });
 
@@ -661,11 +672,13 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements /*Settin
      * Creates a new file at the specified path, by copying an empty template to that location.
      * @param path the complete path (including the file name) where the file will be created
      * @param extension is required to know what template should be used when creating the document
+     *
+     * @return Uri of newFile if newFile is successfully created else null
      */
-    private void createNewFile(final String path, final String extension) {
+    private Uri createNewFile(final String path, final String extension) {
         InputStream templateFileStream = null;
         //create a new file where the template will be written
-        File newFile = new File(path );
+        File newFile = new File(path);
         OutputStream newFileStream = null;
         try {
             //read the template and copy it to the new file
@@ -678,6 +691,7 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements /*Settin
             }
         } catch (IOException e) {
             e.printStackTrace();
+            return null;
         } finally {
             try {
                 //close the streams
@@ -687,6 +701,7 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements /*Settin
                 e.printStackTrace();
             }
         }
+        return Uri.fromFile(newFile);
     }
 
 
diff --git a/android/app/src/main/res/values/strings.xml b/android/app/src/main/res/values/strings.xml
index 5b0c83ea9..2eba35f54 100644
--- a/android/app/src/main/res/values/strings.xml
+++ b/android/app/src/main/res/values/strings.xml
@@ -8,6 +8,8 @@
     <string name="no_recent_items">No recent items</string>
     <string name="no_items">No items</string>
     <string name="temp_file_saving_disabled">This file is read-only, saving is disabled.</string>
+    <string name="file_exists_warning">A file with this name already exists, and it will be overwritten.</string>
+    <string name="file_creation_failed">File creation failed</string>
 
     <string name="about_license">Show License</string>
     <string name="about_notice">Show Notice</string>


More information about the Libreoffice-commits mailing list