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

brainbreaker gautamprajapati06 at gmail.com
Mon Feb 27 14:08:59 UTC 2017


 android/source/AndroidManifest.xml                                                         |    2 
 android/source/res/values/strings.xml                                                      |    4 -
 android/source/src/java/org/libreoffice/storage/IDocumentProvider.java                     |    7 +
 android/source/src/java/org/libreoffice/storage/external/ExtsdDocumentsProvider.java       |    5 +
 android/source/src/java/org/libreoffice/storage/external/LegacyExtSDDocumentsProvider.java |    6 +
 android/source/src/java/org/libreoffice/storage/external/OTGDocumentsProvider.java         |    7 +
 android/source/src/java/org/libreoffice/storage/local/LocalDocumentsProvider.java          |    5 +
 android/source/src/java/org/libreoffice/storage/owncloud/OwnCloudProvider.java             |    5 +
 android/source/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java                      |   39 ++++++++++
 9 files changed, 78 insertions(+), 2 deletions(-)

New commits:
commit 5ada20b3588f76cad5b7f39442147fca3d63bec7
Author: brainbreaker <gautamprajapati06 at gmail.com>
Date:   Sun Feb 26 02:27:43 2017 +0530

    Improve the Document Provider UX
    
    This commit improves the user experience of different
    Document Providers in the app.
    In case ext sd card is not present, the option is disabled
    in Navigation Menu.
    If the device does not support USB OTG,
    the option is disabled.
    LibreOfficeUIActivity registers a broadcast receiver
    in onCreate which detects if a USB device is connected
    and directs the user to Settings page to configure it.
    In case of errors in configuration in any case,
    user is directed to Settings activity after appropriate toast.
    
    Change-Id: I680f78a679e2071ce8330c8168d7aa4e95041723
    Reviewed-on: https://gerrit.libreoffice.org/34650
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Aleksandar Stefanović <theonewithideas at gmail.com>

diff --git a/android/source/AndroidManifest.xml b/android/source/AndroidManifest.xml
index 7e35208..601f478 100644
--- a/android/source/AndroidManifest.xml
+++ b/android/source/AndroidManifest.xml
@@ -4,6 +4,8 @@
 
     <!-- App requires OpenGL ES 2.0 -->
     <uses-feature android:glEsVersion="0x00020000" android:required="true" />
+    <!-- App wants to know if device supports USB host capability(not mandatory) -->
+    <uses-feature android:name="android.hardware.usb.host" android:required="false"/>
     <uses-sdk android:minSdkVersion="14" android:targetSdkVersion="21"/>
     <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
     <uses-permission android:name="android.permission.INTERNET" />
diff --git a/android/source/res/values/strings.xml b/android/source/res/values/strings.xml
index ff4a183..9832d8b 100644
--- a/android/source/res/values/strings.xml
+++ b/android/source/res/values/strings.xml
@@ -65,12 +65,13 @@
     <string name="external_sd_file_system">External SD</string>
     <string name="otg_file_system">OTG device (experimental)</string>
     <string name="owncloud">Remote server</string>
+    <string name="usb_connected_configure">USB connected, configure your device.</string>
 
     <string name="owncloud_wrong_connection">Cannot connect to ownCloud server. Check your configuration.</string>
     <string name="owncloud_unauthorized">Cannot log into ownCloud server. Check your configuration.</string>
     <string name="owncloud_unspecified_error">Unspecified error connecting to ownCloud server. Check your configuration and/or try later.</string>
 
-    <string name="ext_document_provider_error">Invalid root file. Check your configuration.</string>
+    <string name="ext_document_provider_error">Invalid root file. Check your sd card configuration.</string>
     <string name="legacy_extsd_missing_error">Invalid root file. Check your external sd card and/or configuration.</string>
     <string name="otg_missing_error">Invalid root file. Check your OTG device and/or configuration.</string>
 
@@ -118,5 +119,4 @@
     <string name="no_save_document">NO</string>
 
 
-
 </resources>
diff --git a/android/source/src/java/org/libreoffice/storage/IDocumentProvider.java b/android/source/src/java/org/libreoffice/storage/IDocumentProvider.java
index edb026f..2b0460a 100644
--- a/android/source/src/java/org/libreoffice/storage/IDocumentProvider.java
+++ b/android/source/src/java/org/libreoffice/storage/IDocumentProvider.java
@@ -54,4 +54,11 @@ public interface IDocumentProvider {
      * @return Unique ID for a document provider instance.
      */
     int getId();
+
+    /**
+     * Checks if the Document Provider is available or not.
+     *
+     * @return A boolean value based on provider availability.
+     */
+    boolean checkProviderAvailability();
 }
diff --git a/android/source/src/java/org/libreoffice/storage/external/ExtsdDocumentsProvider.java b/android/source/src/java/org/libreoffice/storage/external/ExtsdDocumentsProvider.java
index abbfca9..4ce77f0 100644
--- a/android/source/src/java/org/libreoffice/storage/external/ExtsdDocumentsProvider.java
+++ b/android/source/src/java/org/libreoffice/storage/external/ExtsdDocumentsProvider.java
@@ -148,6 +148,11 @@ public class ExtsdDocumentsProvider implements IExternalDocumentProvider,
     }
 
     @Override
+    public boolean checkProviderAvailability() {
+        return Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED) && Environment.isExternalStorageRemovable();
+    }
+
+    @Override
     public void onSharedPreferenceChanged(SharedPreferences preferences, String key) {
         if (key.equals(DocumentProviderSettingsActivity.KEY_PREF_EXTERNAL_SD_PATH_URI)) {
             rootPathURI = preferences.getString(key, "");
diff --git a/android/source/src/java/org/libreoffice/storage/external/LegacyExtSDDocumentsProvider.java b/android/source/src/java/org/libreoffice/storage/external/LegacyExtSDDocumentsProvider.java
index 0ded177..1ac3440 100644
--- a/android/source/src/java/org/libreoffice/storage/external/LegacyExtSDDocumentsProvider.java
+++ b/android/source/src/java/org/libreoffice/storage/external/LegacyExtSDDocumentsProvider.java
@@ -2,6 +2,7 @@ package org.libreoffice.storage.external;
 
 import android.content.Context;
 import android.content.SharedPreferences;
+import android.os.Environment;
 import android.preference.PreferenceManager;
 import android.text.TextUtils;
 import android.util.Log;
@@ -88,6 +89,11 @@ public class LegacyExtSDDocumentsProvider implements IExternalDocumentProvider,
     }
 
     @Override
+    public boolean checkProviderAvailability() {
+        return Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED) && Environment.isExternalStorageRemovable();
+    }
+
+    @Override
     public void onSharedPreferenceChanged(SharedPreferences preferences, String key) {
         if (key.equals(DocumentProviderSettingsActivity.KEY_PREF_EXTERNAL_SD_PATH_URI)) {
             rootPathURI = preferences.getString(key, "");
diff --git a/android/source/src/java/org/libreoffice/storage/external/OTGDocumentsProvider.java b/android/source/src/java/org/libreoffice/storage/external/OTGDocumentsProvider.java
index 556e6f6..0f9ee30 100644
--- a/android/source/src/java/org/libreoffice/storage/external/OTGDocumentsProvider.java
+++ b/android/source/src/java/org/libreoffice/storage/external/OTGDocumentsProvider.java
@@ -2,6 +2,7 @@ package org.libreoffice.storage.external;
 
 import android.content.Context;
 import android.content.SharedPreferences;
+import android.content.pm.PackageManager;
 import android.preference.PreferenceManager;
 
 import org.libreoffice.R;
@@ -80,4 +81,10 @@ public class OTGDocumentsProvider implements IExternalDocumentProvider,
     public String guessRootURI() {
         return "";
     }
+
+    @Override
+    public boolean checkProviderAvailability() {
+        // check if system supports USB Host
+        return context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_USB_HOST);
+    }
 }
diff --git a/android/source/src/java/org/libreoffice/storage/local/LocalDocumentsProvider.java b/android/source/src/java/org/libreoffice/storage/local/LocalDocumentsProvider.java
index a1a84e8..42c2533 100644
--- a/android/source/src/java/org/libreoffice/storage/local/LocalDocumentsProvider.java
+++ b/android/source/src/java/org/libreoffice/storage/local/LocalDocumentsProvider.java
@@ -48,4 +48,9 @@ public class LocalDocumentsProvider implements IDocumentProvider {
     public int getId() {
         return id;
     }
+
+    @Override
+    public boolean checkProviderAvailability() {
+        return true;
+    }
 }
diff --git a/android/source/src/java/org/libreoffice/storage/owncloud/OwnCloudProvider.java b/android/source/src/java/org/libreoffice/storage/owncloud/OwnCloudProvider.java
index c037941..e10c88b 100644
--- a/android/source/src/java/org/libreoffice/storage/owncloud/OwnCloudProvider.java
+++ b/android/source/src/java/org/libreoffice/storage/owncloud/OwnCloudProvider.java
@@ -177,4 +177,9 @@ public class OwnCloudProvider implements IDocumentProvider,
     public int getId() {
         return id;
     }
+
+    @Override
+    public boolean checkProviderAvailability() {
+        return true;
+    }
 }
diff --git a/android/source/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java b/android/source/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java
index 8655e5c..40726c3 100644
--- a/android/source/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java
+++ b/android/source/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java
@@ -10,13 +10,16 @@
 package org.libreoffice.ui;
 
 import android.app.Activity;
+import android.content.BroadcastReceiver;
 import android.content.ComponentName;
 import android.content.Context;
 import android.content.Intent;
+import android.content.IntentFilter;
 import android.content.SharedPreferences;
 import android.content.pm.ShortcutInfo;
 import android.content.pm.ShortcutManager;
 import android.graphics.drawable.Icon;
+import android.hardware.usb.UsbManager;
 import android.net.Uri;
 import android.os.AsyncTask;
 import android.os.Bundle;
@@ -65,6 +68,7 @@ import java.net.URI;
 import java.net.URISyntaxException;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Date;
 import java.util.HashSet;
 import java.util.List;
@@ -116,6 +120,11 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings
         PreferenceManager.setDefaultValues(this, R.xml.documentprovider_preferences, false);
         readPreferences();
         SettingsListenerModel.getInstance().setListener(this);
+        // Registering the USB detect broadcast receiver
+        IntentFilter filter = new IntentFilter();
+        filter.addAction(UsbManager.ACTION_USB_DEVICE_ATTACHED);
+        filter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED);
+        registerReceiver(mUSBReceiver, filter);
         // init UI and populate with contents from the provider
         switchToDocumentProvider(documentProviderFactory.getDefaultProvider());
         createUI();
@@ -161,6 +170,19 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings
         drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
         navigationDrawer = (NavigationView) findViewById(R.id.navigation_drawer);
 
+        final ArrayList<CharSequence> providerNames = new ArrayList<CharSequence>(
+                Arrays.asList(documentProviderFactory.getNames())
+        );
+
+        // Loop through the document providers menu items and check if they are available or not
+        for (int index = 0; index < providerNames.size(); index++) {
+            MenuItem item = navigationDrawer.getMenu().getItem(index);
+            boolean isDocumentProviderAvailable = checkDocumentProviderAvailability(documentProviderFactory.getProvider(index));
+            if (!isDocumentProviderAvailable){
+                item.setEnabled(false);
+            }
+        }
+
         final Context context = this; //needed for anonymous method below
         navigationDrawer.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
             @Override
@@ -225,6 +247,10 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings
         drawerToggle.syncState();
     }
 
+    private boolean checkDocumentProviderAvailability(IDocumentProvider provider) {
+        return provider.checkProviderAvailability();
+    }
+
     @Override
     protected void onPostCreate(Bundle savedInstanceState) {
         super.onPostCreate(savedInstanceState);
@@ -326,6 +352,7 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings
                                     Toast.LENGTH_SHORT).show();
                         }
                     });
+                    startActivity(new Intent(activity, DocumentProviderSettingsActivity.class));
                     Log.e(LOGTAG, e.getMessage(), e.getCause());
                 }
                 return null;
@@ -719,6 +746,18 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings
         Log.d(LOGTAG, currentDirectory.toString() + Integer.toString(filterMode) + Integer.toString(viewMode));
     }
 
+    private final BroadcastReceiver mUSBReceiver = new BroadcastReceiver() {
+        public void onReceive(Context context, Intent intent) {
+            String action = intent.getAction();
+            if (UsbManager.ACTION_USB_DEVICE_ATTACHED.equals(action)) {
+                Toast.makeText(context, R.string.usb_connected_configure, Toast.LENGTH_SHORT).show();
+                startActivity(new Intent(context, DocumentProviderSettingsActivity.class));
+                Log.d(LOGTAG, "USB device attached");
+            } else if (UsbManager.ACTION_USB_DEVICE_DETACHED.equals(action)) {
+                Log.d(LOGTAG, "USB device detached");
+            }
+        }
+    };
     @Override
     protected void onPause() {
         super.onPause();


More information about the Libreoffice-commits mailing list