[Libreoffice-commits] core.git: android/source

brainbreaker gautamprajapati06 at gmail.com
Tue Apr 18 12:14:38 UTC 2017


 android/source/res/values/strings.xml                                 |   16 -
 android/source/src/java/org/libreoffice/LOKitTileProvider.java        |    4 
 android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java  |  125 +++-------
 android/source/src/java/org/libreoffice/ui/FileUtilities.java         |    5 
 android/source/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java |   49 +++
 5 files changed, 97 insertions(+), 102 deletions(-)

New commits:
commit d70636a3145c72fe7f34c0a73f3784f99dc329ee
Author: brainbreaker <gautamprajapati06 at gmail.com>
Date:   Thu Apr 6 15:00:33 2017 +0530

    Discard StorageAccessFramework for creating new documents
    
    This commit adds the ability to create a new document using
    existing file system browsing in the app.
    Usage of StorageAccessFramework to create new document
    has been ditched as it is not backward compatible.
    
    Change-Id: I852c3de337613cb01e689d532476d2c5f932c1b3
    Reviewed-on: https://gerrit.libreoffice.org/36195
    Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>
    Tested-by: Tomaž Vajngerl <quikee at gmail.com>

diff --git a/android/source/res/values/strings.xml b/android/source/res/values/strings.xml
index a554c84b4aef..4495ca584927 100644
--- a/android/source/res/values/strings.xml
+++ b/android/source/res/values/strings.xml
@@ -16,9 +16,11 @@
     <string name="about_moreinfo">More Info</string>
     <string name="back_again_to_quit">Press back again to quit</string>
 
+    <string name="new_write">New Write</string>
     <string name="new_impress">New Impress</string>
     <string name="new_spreadsheet">New Sheet</string>
     <string name="new_draw">New Draw</string>
+    <string name="default_document_name">untitled</string>
 
     <string name="browser_app_name">LibreOffice Browser</string>
     <string name="menu_search">Search</string>
@@ -94,7 +96,8 @@
     <string name="message_saved">Save complete</string>
     <string name="message_saving">Saving the document…</string>
     <string name="message_save_incomplete">Save incomplete. Were there any changes?</string>
-    <string name="new_file_created">File created in Documents folder</string>
+    <string name="create_new_file_success">"Created new file - "</string>
+    <string name="create_new_file_error">Unable to create new file, please check entered file name.</string>
 
     <!-- Document provider settings -->
     <string name="storage_provider_settings">Storage provider settings</string>
@@ -118,15 +121,14 @@
     <string name="directory_browser_label">Choose Directory</string>
     <string name="bad_directory">Invalid directory path</string>
 
-    <!-- Closing alert dialog strings -->
+    <!-- Save Alert dialog strings -->
     <string name="save_alert_dialog_title">Save the document before closing?</string>
     <string name="save_document">SAVE</string>
-    <string name="cancel_save_document">CANCEL</string>
+    <string name="action_cancel">Cancel</string>
     <string name="no_save_document">NO</string>
-    <string name="new_write">New Write</string>
-
-    <string name="save_as_success">Saved file -</string>
-    <string name="save_as_error">Unable to create new file, please check entered file name.</string>
 
+    <!-- Create New Document Dialog Strings -->
+    <string name="create_new_document_title">Enter file name</string>
+    <string name="action_create">CREATE</string>
 
 </resources>
diff --git a/android/source/src/java/org/libreoffice/LOKitTileProvider.java b/android/source/src/java/org/libreoffice/LOKitTileProvider.java
index 1996a1b5bedd..29def6e97794 100644
--- a/android/source/src/java/org/libreoffice/LOKitTileProvider.java
+++ b/android/source/src/java/org/libreoffice/LOKitTileProvider.java
@@ -142,7 +142,7 @@ class LOKitTileProvider implements TileProvider {
                 @Override
                 public void run() {
                     // There was some error
-                    mContext.showSaveStatusToast(true);
+                    mContext.showSaveStatusMessage(true);
                 }
             });
         }
@@ -150,7 +150,7 @@ class LOKitTileProvider implements TileProvider {
             @Override
             public void run() {
                 // There was no error
-                mContext.showSaveStatusToast(false);
+                mContext.showSaveStatusMessage(false);
             }
         });
     }
diff --git a/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java b/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java
index 3e41a7dda98f..267fce39315e 100755
--- a/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java
+++ b/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java
@@ -10,12 +10,11 @@ import android.content.SharedPreferences;
 import android.content.res.AssetFileDescriptor;
 import android.content.res.AssetManager;
 import android.graphics.RectF;
-import android.net.Uri;
 import android.os.AsyncTask;
 import android.os.Bundle;
-import android.os.Environment;
 import android.os.Handler;
 import android.preference.PreferenceManager;
+import android.support.design.widget.Snackbar;
 import android.support.v4.widget.DrawerLayout;
 import android.support.v7.app.AppCompatActivity;
 import android.support.v7.widget.Toolbar;
@@ -76,16 +75,12 @@ public class LibreOfficeMainActivity extends AppCompatActivity {
     private DocumentPartViewListAdapter mDocumentPartViewListAdapter;
     private int partIndex=-1;
     private File mInputFile;
-    private String newFileName = "untitled";
-    private String newFilePath = "/storage/emulated/0/Documents/";
     private DocumentOverlay mDocumentOverlay;
     private File mTempFile = null;
-    private String newDocumentType = null;
     private FormattingController mFormattingController;
     private ToolbarController mToolbarController;
     private FontController mFontController;
     private SearchController mSearchController;
-    private static final int PICKFOLDER_RESULT_CODE = 1;
 
     public GeckoLayerClient getLayerClient() {
         return mLayerClient;
@@ -134,20 +129,35 @@ public class LibreOfficeMainActivity extends AppCompatActivity {
         mFontController = new FontController(this);
         mSearchController = new SearchController(this);
 
-        // New document type string is not null, it means we want to open a new document
+        loKitThread = new LOKitThread(this);
+        loKitThread.start();
+
+        mLayerClient = new GeckoLayerClient(this);
+        LayerView layerView = (LayerView) findViewById(R.id.layer_view);
+        mLayerClient.setView(layerView);
+        layerView.setInputConnectionHandler(new LOKitInputConnectionHandler());
+        mLayerClient.notifyReady();
+
+        layerView.setOnKeyListener(new View.OnKeyListener() {
+            @Override
+            public boolean onKey(View view, int i, KeyEvent keyEvent) {
+                if(keyEvent.getKeyCode() != KeyEvent.KEYCODE_BACK){
+                    isDocumentChanged=true;
+                }
+                return false;
+            }
+        });
+
+        // create TextCursorLayer
+        mDocumentOverlay = new DocumentOverlay(this, layerView);
+
+        // New document type string is not null, meaning we want to open a new document
         if (getIntent().getStringExtra(LibreOfficeUIActivity.NEW_DOC_TYPE_KEY) != null) {
-            newDocumentType = getIntent().getStringExtra(LibreOfficeUIActivity.NEW_DOC_TYPE_KEY);
-            if (newDocumentType.matches(LibreOfficeUIActivity.NEW_WRITER_STRING_KEY))
-                newFileName = newFileName + ".odt";
-            else if (newDocumentType.matches(LibreOfficeUIActivity.NEW_IMPRESS_STRING_KEY))
-                newFileName = newFileName + ".odp";
-            else if (newDocumentType.matches(LibreOfficeUIActivity.NEW_CALC_STRING_KEY))
-                newFileName = newFileName + ".ods";
-            else
-                newFileName = newFileName + ".odg";
-            // We want to create a new Document, create an alert dialogue to name the new file.
-            openSelectPathIntent();
-            isNewDocument = true;
+            String newDocumentType = getIntent().getStringExtra(LibreOfficeUIActivity.NEW_DOC_TYPE_KEY);
+            String newFilePath = getIntent().getStringExtra(LibreOfficeUIActivity.NEW_FILE_PATH_KEY);
+
+            // Load the new document
+            loadNewDocument(newFilePath, newDocumentType);
         }
 
         if (getIntent().getData() != null) {
@@ -170,10 +180,10 @@ public class LibreOfficeMainActivity extends AppCompatActivity {
                 documentUri = (URI) getIntent().getSerializableExtra(
                         "org.libreoffice.document_uri");
             }
-        } else if (isNewDocument){
-            toolbarTop.setTitle(newFileName);
         } else {
-            mInputFile = new File(DEFAULT_DOC_PATH);
+            if (!isNewDocument) {
+                mInputFile = new File(DEFAULT_DOC_PATH);
+            }
         }
 
         mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
@@ -186,28 +196,6 @@ public class LibreOfficeMainActivity extends AppCompatActivity {
             mDrawerList.setOnItemClickListener(new DocumentPartClickListener());
         }
 
-        loKitThread = new LOKitThread(this);
-        loKitThread.start();
-
-        mLayerClient = new GeckoLayerClient(this);
-        LayerView layerView = (LayerView) findViewById(R.id.layer_view);
-        mLayerClient.setView(layerView);
-        layerView.setInputConnectionHandler(new LOKitInputConnectionHandler());
-        mLayerClient.notifyReady();
-
-        layerView.setOnKeyListener(new View.OnKeyListener() {
-            @Override
-            public boolean onKey(View view, int i, KeyEvent keyEvent) {
-                if(keyEvent.getKeyCode() != KeyEvent.KEYCODE_BACK){
-                    isDocumentChanged=true;
-                }
-                return false;
-            }
-        });
-
-        // create TextCursorLayer
-        mDocumentOverlay = new DocumentOverlay(this, layerView);
-
         mToolbarController.setupToolbars();
 
         TabHost host = (TabHost) findViewById(R.id.toolbarTabHost);
@@ -229,40 +217,12 @@ public class LibreOfficeMainActivity extends AppCompatActivity {
         host.addTab(spec);
     }
 
-    private void openSelectPathIntent() {
-        Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT)
-                           .addCategory(Intent.CATEGORY_OPENABLE)
-                           .setType("*/*")
-                           .putExtra(Intent.EXTRA_TITLE, newFileName);
-        startActivityForResult(intent, PICKFOLDER_RESULT_CODE);
-    }
-
-    @Override
-    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
-        switch(requestCode){
-            case PICKFOLDER_RESULT_CODE:
-                if(resultCode==RESULT_OK){
-                    Uri fileURI = data.getData();
-                    newFilePath = fileURI.getPath();
-                    if (newFilePath.contains("primary")) {
-                        /* When file is being saved in primary storage folder other than Documents home.
-                         *  newFilePath content is similar to this - /document/primary:Downloads/untitled1.odt */
-                        newFilePath = Environment.getExternalStorageDirectory().getPath() + "/" + newFilePath.split(":")[1];
-                    } else if (newFilePath.contains("home")) {
-                        /* When file is being saved in documents folder itself i.e. Document home.
-                         *  newFilePath content is similar to this - /document/home:untitled1.odt */
-                        newFilePath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS) + "/" + newFilePath.split(":")[1];
-                    } else {
-                        newFilePath = Environment.getExternalStorageDirectory().getPath() + "/";
-                    }
-                    Log.d("newFilePath", newFilePath);
-                }
-                // Now set the input file variable to new file created
-                mInputFile = new File(newFilePath);
-                // and load the new document
-                LOKitShell.sendNewDocumentLoadEvent(newFilePath, newDocumentType);
-                break;
-        }
+    // Loads a new Document
+    private void loadNewDocument(String newFilePath, String newDocumentType) {
+        mInputFile = new File(newFilePath);
+        LOKitShell.sendNewDocumentLoadEvent(newFilePath, newDocumentType);
+        isNewDocument = true;
+        toolbarTop.setTitle(mInputFile.getName());
     }
 
     public RectF getCurrentCursorPosition() {
@@ -475,7 +435,7 @@ public class LibreOfficeMainActivity extends AppCompatActivity {
         AlertDialog.Builder builder = new AlertDialog.Builder(this);
         builder.setMessage(R.string.save_alert_dialog_title)
                 .setPositiveButton(R.string.save_document, dialogClickListener)
-                .setNegativeButton(R.string.cancel_save_document, dialogClickListener)
+                .setNegativeButton(R.string.action_cancel, dialogClickListener)
                 .setNeutralButton(R.string.no_save_document, dialogClickListener)
                 .show();
 
@@ -770,12 +730,11 @@ public class LibreOfficeMainActivity extends AppCompatActivity {
     }
 
     // This method is used in LOKitTileProvider.java to show status of new file creation.
-    public void showSaveStatusToast(boolean error) {
+    public void showSaveStatusMessage(boolean error) {
         if (!error)
-            Toast.makeText(this, getString(R.string.save_as_success) + newFilePath, Toast.LENGTH_SHORT).show();
+            Snackbar.make(mDrawerLayout, getString(R.string.create_new_file_success) + mInputFile.getName(), Snackbar.LENGTH_LONG).show();
         else
-            Toast.makeText(this, R.string.save_as_error, Toast.LENGTH_SHORT).show();
-    }
+            Snackbar.make(mDrawerLayout, getString(R.string.create_new_file_error) + mInputFile.getName(), Snackbar.LENGTH_LONG).show();    }
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/android/source/src/java/org/libreoffice/ui/FileUtilities.java b/android/source/src/java/org/libreoffice/ui/FileUtilities.java
index c98a505dff91..422b1e9971cd 100644
--- a/android/source/src/java/org/libreoffice/ui/FileUtilities.java
+++ b/android/source/src/java/org/libreoffice/ui/FileUtilities.java
@@ -46,6 +46,11 @@ public class FileUtilities {
     /** Smallest Files First */
     static final int SORT_SMALLEST = 5;
 
+    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";
+
     private static final Map<String, Integer> mExtnMap = new HashMap<String, Integer>();
     private static final Map<String, String> extensionToMimeTypeMap = new HashMap<String, String>();
     static {
diff --git a/android/source/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java b/android/source/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java
index 06d6daba90e3..5b20c7d98fef 100644
--- a/android/source/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java
+++ b/android/source/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java
@@ -10,9 +10,11 @@
 package org.libreoffice.ui;
 
 import android.app.Activity;
+import android.app.AlertDialog;
 import android.content.BroadcastReceiver;
 import android.content.ComponentName;
 import android.content.Context;
+import android.content.DialogInterface;
 import android.content.Intent;
 import android.content.IntentFilter;
 import android.content.SharedPreferences;
@@ -23,7 +25,6 @@ import android.hardware.usb.UsbManager;
 import android.net.Uri;
 import android.os.AsyncTask;
 import android.os.Bundle;
-import android.os.Environment;
 import android.os.Handler;
 import android.preference.PreferenceManager;
 import android.support.annotation.NonNull;
@@ -39,6 +40,7 @@ import android.support.v7.widget.GridLayoutManager;
 import android.support.v7.widget.LinearLayoutManager;
 import android.support.v7.widget.RecyclerView;
 import android.support.v7.widget.Toolbar;
+import android.text.InputType;
 import android.util.Log;
 import android.view.ContextMenu;
 import android.view.ContextMenu.ContextMenuInfo;
@@ -53,6 +55,7 @@ import android.view.ViewGroup;
 import android.view.animation.Animation;
 import android.view.animation.AnimationUtils;
 import android.view.animation.OvershootInterpolator;
+import android.widget.EditText;
 import android.widget.ImageView;
 import android.widget.LinearLayout;
 import android.widget.TextView;
@@ -67,12 +70,10 @@ import org.libreoffice.storage.DocumentProviderFactory;
 import org.libreoffice.storage.DocumentProviderSettingsActivity;
 import org.libreoffice.storage.IDocumentProvider;
 import org.libreoffice.storage.IFile;
-import org.libreoffice.storage.local.LocalFile;
 
 import java.io.File;
 import java.io.FileFilter;
 import java.io.FilenameFilter;
-import java.io.IOException;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.text.SimpleDateFormat;
@@ -107,6 +108,7 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings
     public static final String SORT_MODE_KEY = "SORT_MODE";
     private static final String RECENT_DOCUMENTS_KEY = "RECENT_DOCUMENTS";
 
+    public static final String NEW_FILE_PATH_KEY = "NEW_FILE_PATH_KEY";
     public static final String NEW_DOC_TYPE_KEY = "NEW_DOC_TYPE_KEY";
     public static final String NEW_WRITER_STRING_KEY = "private:factory/swriter";
     public static final String NEW_IMPRESS_STRING_KEY = "private:factory/simpress";
@@ -547,10 +549,37 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings
         }.execute(document);
     }
 
-    // For opening a new Document
-    private void open(String newDocumentType) {
-        Intent intent = new Intent(this, LibreOfficeMainActivity.class);
+    // Opens an Input dialog to get the name of new file
+    private void createNewFileInputDialog(final String defaultFileName, final String newDocumentType) {
+        AlertDialog.Builder builder = new AlertDialog.Builder(this);
+        builder.setTitle(R.string.create_new_document_title);
+        final EditText input = new EditText(this);
+        input.setInputType(InputType.TYPE_CLASS_TEXT);
+        input.setText(defaultFileName);
+        builder.setView(input);
+
+        builder.setPositiveButton(R.string.action_create, new DialogInterface.OnClickListener() {
+            @Override
+            public void onClick(DialogInterface dialog, int which) {
+                final String newFilePath = currentDirectory.getUri().getPath() + input.getText().toString();
+                loadNewDocument(newDocumentType, newFilePath);
+            }
+        });
+
+        builder.setNegativeButton(R.string.action_cancel, new DialogInterface.OnClickListener() {
+            @Override
+            public void onClick(DialogInterface dialog, int which) {
+                dialog.cancel();
+            }
+        });
+
+        builder.show();
+    }
+
+    private void loadNewDocument(String newDocumentType, String newFilePath) {
+        Intent intent = new Intent(LibreOfficeUIActivity.this, LibreOfficeMainActivity.class);
         intent.putExtra(NEW_DOC_TYPE_KEY, newDocumentType);
+        intent.putExtra(NEW_FILE_PATH_KEY, newFilePath);
         startActivity(intent);
     }
 
@@ -990,16 +1019,16 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings
                 }
                 break;
             case R.id.newWriterFAB:
-                open(NEW_WRITER_STRING_KEY);
+                createNewFileInputDialog(getString(R.string.default_document_name) + FileUtilities.DEFAULT_WRITER_EXTENSION, NEW_WRITER_STRING_KEY);
                 break;
             case R.id.newImpressFAB:
-                open(NEW_IMPRESS_STRING_KEY);
+                createNewFileInputDialog(getString(R.string.default_document_name) + FileUtilities.DEFAULT_IMPRESS_EXTENSION, NEW_IMPRESS_STRING_KEY);
                 break;
             case R.id.newCalcFAB:
-                open(NEW_CALC_STRING_KEY);
+                createNewFileInputDialog(getString(R.string.default_document_name) + FileUtilities.DEFAULT_SPREADSHEET_EXTENSION, NEW_CALC_STRING_KEY);
                 break;
             case R.id.newDrawFAB:
-                open(NEW_DRAW_STRING_KEY);
+                createNewFileInputDialog(getString(R.string.default_document_name) + FileUtilities.DEFAULT_DRAWING_EXTENSION, NEW_DRAW_STRING_KEY);
                 break;
         }
     }


More information about the Libreoffice-commits mailing list