[Libreoffice-commits] core.git: android/source
aleksandar-stefanovic
theonewithideas at gmail.com
Sat Feb 25 09:29:42 UTC 2017
android/source/res/menu/navigation_menu.xml | 21 ++
android/source/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java | 85 ++++------
2 files changed, 57 insertions(+), 49 deletions(-)
New commits:
commit e792eb52160a16cff3a04d9713e023230247e7c3
Author: aleksandar-stefanovic <theonewithideas at gmail.com>
Date: Thu Feb 16 20:42:45 2017 +0100
Moved navigation items to XML
I made them add programatically before, because I was unsure
whether the list was dynamic, but when I found out that the five
items on the list are actually static, I realized that it's better
to declare menu items in XML, because of the performance and
readibility.
Change-Id: I044abe356e51b26ac13328fcf451cabc9e70a3ea
Reviewed-on: https://gerrit.libreoffice.org/34342
Tested-by: Jenkins <ci at libreoffice.org>
Reviewed-by: Aleksandar Stefanović <theonewithideas at gmail.com>
diff --git a/android/source/res/menu/navigation_menu.xml b/android/source/res/menu/navigation_menu.xml
index 21f6860..532c9ed 100644
--- a/android/source/res/menu/navigation_menu.xml
+++ b/android/source/res/menu/navigation_menu.xml
@@ -4,7 +4,26 @@
android:checkableBehavior="single"
android:id="@+id/group_providers">
- <!--Items will be added programmatically in LibreOfficeUIActivity.java-->
+ <item android:id="@+id/menu_provider_documents"
+ android:title="@string/local_documents"
+ android:icon="@drawable/ic_insert_drive_file_black_24dp" />
+
+ <item android:id="@+id/menu_provider_filesystem"
+ android:title="@string/local_file_system"
+ android:icon="@drawable/ic_storage_black_24dp"/>
+
+ <item android:id="@+id/menu_provider_extsd"
+ android:title="@string/external_sd_file_system"
+ android:icon="@drawable/ic_sd_card_black_24dp"/>
+
+ <item android:id="@+id/menu_provider_otg"
+ android:title="@string/otg_file_system"
+ android:icon="@drawable/ic_usb_black_24dp"/>
+
+ <item android:id="@+id/menu_provider_owncloud"
+ android:title="@string/owncloud"
+ android:icon="@drawable/ic_cloud_black_24dp"/>
+
</group>
diff --git a/android/source/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java b/android/source/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java
index 3393484..8655e5c 100644
--- a/android/source/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java
+++ b/android/source/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java
@@ -29,7 +29,6 @@ import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
-import android.support.v7.widget.AppCompatSpinner;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
@@ -45,8 +44,6 @@ import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnLongClickListener;
import android.view.ViewGroup;
-import android.widget.AdapterView;
-import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
@@ -68,7 +65,6 @@ 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;
@@ -164,55 +160,48 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings
//Setting up navigation drawer
drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
navigationDrawer = (NavigationView) findViewById(R.id.navigation_drawer);
- /*
- * These are the currently-known document providers (for which icons are assigned).
- * This is to ensure that there is an icon available if the provider is recognized, while
- * the unrecognized ones still appear, but without an icon. If there is a document provider
- * not on this list, it should be added and an icon assigned to it, in the if-else ladder
- * bellow. This is a hacky implementation, maybe we could make something better in the
- * future, i.e. we could move this into the menu file and load it that way.
- */
- final String LOCAL_DOCUMENTS_NAME = "Local documents";
- final String LOCAL_FILE_SYSTEM_NAME = "Local file system";
- final String EXTERNAL_SD_NAME = "External SD";
- final String OTG_FILE_SYSTEM_NAME = "OTG device (experimental)";
- final String OWNCLOUD_NAME = "Remote server";
-
- //Provider names are wrapped as a ArrayList so indexOf(Object) method could be used
- final ArrayList<CharSequence> providerNames = new ArrayList<CharSequence>(
- Arrays.asList(documentProviderFactory.getNames())
- );
- for (CharSequence name : providerNames) {
- int iconRes = 0;
- if (name.equals(LOCAL_DOCUMENTS_NAME)) {
- iconRes = R.drawable.ic_insert_drive_file_black_24dp;
- } else if (name.equals(LOCAL_FILE_SYSTEM_NAME)) {
- iconRes = R.drawable.ic_storage_black_24dp;
- } else if (name.equals(EXTERNAL_SD_NAME)) {
- iconRes = R.drawable.ic_sd_card_black_24dp;
- } else if (name.equals(OTG_FILE_SYSTEM_NAME)) {
- iconRes = R.drawable.ic_usb_black_24dp;
- } else if (name.equals(OWNCLOUD_NAME)) {
- iconRes = R.drawable.ic_cloud_black_24dp;
- }
- MenuItem item = navigationDrawer.getMenu().add(R.id.group_providers, Menu.NONE, Menu.NONE, name)
- .setCheckable(true);
- if (iconRes != 0) {
- item.setIcon(iconRes);
- }
- }
final Context context = this; //needed for anonymous method below
navigationDrawer.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
- if (item.getItemId() == R.id.menu_storage_preferences) {
- startActivity(new Intent(context, DocumentProviderSettingsActivity.class));
- return true;
+
+ switch (item.getItemId()) {
+ case R.id.menu_storage_preferences: {
+ startActivity(new Intent(context, DocumentProviderSettingsActivity.class));
+ return true;
+ }
+
+ case R.id.menu_provider_documents: {
+ switchToDocumentProvider(documentProviderFactory.getProvider(0));
+ return true;
+ }
+
+ case R.id.menu_provider_filesystem: {
+ switchToDocumentProvider(documentProviderFactory.getProvider(1));
+ return true;
+ }
+
+ case R.id.menu_provider_extsd: {
+ switchToDocumentProvider(documentProviderFactory.getProvider(2));
+ return true;
+ }
+
+ case R.id.menu_provider_otg: {
+ switchToDocumentProvider(documentProviderFactory.getProvider(3));
+ return true;
+ }
+
+ case R.id.menu_provider_owncloud: {
+ switchToDocumentProvider(documentProviderFactory.getProvider(4));
+ return true;
+ }
+
+ default:
+ return false;
}
- int position = providerNames.indexOf(item.getTitle());
- switchToDocumentProvider(documentProviderFactory.getProvider(position));
- return true;
+
+
}
});
drawerToggle = new ActionBarDrawerToggle(this, drawerLayout,
@@ -600,7 +589,7 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings
filterMode = FileUtilities.DRAWING;
openDirectory(currentDirectory);
break;
-
+
case R.id.menu_sort_size:
case R.id.menu_sort_az:
case R.id.menu_sort_modified:
More information about the Libreoffice-commits
mailing list