diff options
author | brainbreaker <gautamprajapati06@gmail.com> | 2017-02-26 02:27:43 +0530 |
---|---|---|
committer | Aleksandar Stefanović <theonewithideas@gmail.com> | 2017-02-27 14:08:32 +0000 |
commit | 5ada20b3588f76cad5b7f39442147fca3d63bec7 (patch) | |
tree | 622dbcd10408b344be078b08aec7559c3f6afc1c /android | |
parent | 87847bb8b87b80f338bc010d413ce2c9f912e6ec (diff) |
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@libreoffice.org>
Reviewed-by: Aleksandar Stefanović <theonewithideas@gmail.com>
Diffstat (limited to 'android')
9 files changed, 78 insertions, 2 deletions
diff --git a/android/source/AndroidManifest.xml b/android/source/AndroidManifest.xml index 7e352088ecde..601f478ae352 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 ff4a183a98a8..9832d8b72eb2 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 edb026ff9433..2b0460a8ee6e 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 abbfca9c6221..4ce77f0e1916 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 0ded17764cce..1ac34405b361 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 556e6f6f6de4..0f9ee30ea28b 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 a1a84e8af55b..42c253322ce7 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 c037941b69ea..e10c88bee93a 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 8655e5c763fd..40726c3e6caf 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(); |