Kaydet (Commit) 5ada20b3 authored tarafından brainbreaker's avatar brainbreaker Kaydeden (comit) Aleksandar Stefanović

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/34650Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarAleksandar Stefanović <theonewithideas@gmail.com>
üst 87847bb8
......@@ -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" />
......
......@@ -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>
......@@ -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();
}
......@@ -147,6 +147,11 @@ public class ExtsdDocumentsProvider implements IExternalDocumentProvider,
return id;
}
@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)) {
......
......@@ -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;
......@@ -87,6 +88,11 @@ public class LegacyExtSDDocumentsProvider implements IExternalDocumentProvider,
return id;
}
@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)) {
......
......@@ -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);
}
}
......@@ -48,4 +48,9 @@ public class LocalDocumentsProvider implements IDocumentProvider {
public int getId() {
return id;
}
@Override
public boolean checkProviderAvailability() {
return true;
}
}
......@@ -177,4 +177,9 @@ public class OwnCloudProvider implements IDocumentProvider,
public int getId() {
return id;
}
@Override
public boolean checkProviderAvailability() {
return true;
}
}
......@@ -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();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment