From d976f9151af53319819c6adb77bc819c460c1bb5 Mon Sep 17 00:00:00 2001 From: aleksandar-stefanovic Date: Thu, 29 Dec 2016 20:29:41 +0100 Subject: Updated toolbar spinner to newer implementation Lowered all-caps navigation labels to something more professional. Added a Spinner to the Toolbar in XML. Reworked many lines of LibreOfficeUIActivity to remove possible NPE's, and also removed redundant lines, which were mostly deprecated, as well as switching to a newer implementation of a toolbar-spinner navigation pattern. There are more deprecated methods, but I wanted them in a separate commit. Change-Id: I15d5365ed7c00880873bf7874bc794008436bb99 Reviewed-on: https://gerrit.libreoffice.org/32497 Reviewed-by: jan iversen Tested-by: jan iversen --- android/source/res/layout/toolbar.xml | 7 ++++ android/source/res/values/arrays.xml | 10 ++--- .../org/libreoffice/ui/LibreOfficeUIActivity.java | 46 +++++++++++++--------- 3 files changed, 40 insertions(+), 23 deletions(-) (limited to 'android') diff --git a/android/source/res/layout/toolbar.xml b/android/source/res/layout/toolbar.xml index 42136ce68ffc..bbeb62a7629c 100644 --- a/android/source/res/layout/toolbar.xml +++ b/android/source/res/layout/toolbar.xml @@ -4,11 +4,18 @@ android:id="@+id/toolbar" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="wrap_content" android:elevation="3dp" android:background="@color/toolbar_background" app:theme="@style/LibreOfficeTheme.Toolbar" + tools:theme="@style/LibreOfficeTheme.Toolbar" app:popupTheme="@style/LibreOfficeTheme"> + + diff --git a/android/source/res/values/arrays.xml b/android/source/res/values/arrays.xml index 28849afb5395..0467baae1b2a 100644 --- a/android/source/res/values/arrays.xml +++ b/android/source/res/values/arrays.xml @@ -33,11 +33,11 @@ - EVERYTHING - DOCUMENTS - SPREADSHEETS - PRESENTATIONS - DRAWINGS + Everything + Documents + Spreadsheets + Presentations + Drawings diff --git a/android/source/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java b/android/source/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java index 148a98cbafec..d0681bd51773 100644 --- a/android/source/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java +++ b/android/source/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java @@ -24,6 +24,7 @@ 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.Toolbar; import android.util.Log; import android.view.ContextMenu; @@ -66,7 +67,7 @@ import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; -public class LibreOfficeUIActivity extends AppCompatActivity implements ActionBar.OnNavigationListener { +public class LibreOfficeUIActivity extends AppCompatActivity { private String LOGTAG = LibreOfficeUIActivity.class.getSimpleName(); private SharedPreferences prefs; private int filterMode = FileUtilities.ALL; @@ -128,19 +129,34 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements ActionBa Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); ActionBar actionBar = getSupportActionBar(); - actionBar.setDisplayShowTitleEnabled(false); //This should show current directory if anything - actionBar.setDisplayHomeAsUpEnabled(true); - //make the navigation spinner - Context context = actionBar.getThemedContext(); - ArrayAdapter list = ArrayAdapter.createFromResource(context, R.array.file_view_modes, android.R.layout.simple_spinner_item); - list.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + if (actionBar != null) { + actionBar.setDisplayShowTitleEnabled(false); + actionBar.setDisplayHomeAsUpEnabled(true); + + //make the navigation spinner + Context context = actionBar.getThemedContext(); + AppCompatSpinner toolbarSpinner = (AppCompatSpinner) findViewById(R.id.toolbar_spinner); + ArrayAdapter spinnerAdapter = ArrayAdapter.createFromResource(context, R.array.file_view_modes, android.R.layout.simple_spinner_item); + spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + toolbarSpinner.setAdapter(spinnerAdapter); + toolbarSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + @Override + public void onItemSelected(AdapterView adapterView, View view, int pos, long id) { + filterMode = pos -1; //bit of a hack, I know. -1 is ALL 0 Docs etc + openDirectory(currentDirectory);// Uses filter mode + } - actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); - actionBar.setListNavigationCallbacks(list, this); + @Override + public void onNothingSelected(AdapterView adapterView) { + filterMode = FileUtilities.ALL; + openDirectory(currentDirectory); + } + }); + } - LinearLayout content = (LinearLayout) findViewById(R.id.browser_main_content); + LinearLayout content = (LinearLayout) findViewById(R.id.browser_main_content); if (viewMode == GRID_VIEW) { // code to make a grid view getLayoutInflater().inflate(R.layout.file_grid, content); @@ -151,13 +167,13 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements ActionBa open(position); } }); - actionBar.setSelectedNavigationItem(filterMode + 1);//This triggers the listener which modifies the view. + openDirectory(currentDirectory); registerForContextMenu(gv); } else { getLayoutInflater().inflate(R.layout.file_list, content); lv = (ListView)findViewById(R.id.file_explorer_list_view); lv.setClickable(true); - actionBar.setSelectedNavigationItem(filterMode + 1); + openDirectory(currentDirectory); registerForContextMenu(lv); } @@ -678,12 +694,6 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements ActionBa Log.d(LOGTAG, "onDestroy"); } - public boolean onNavigationItemSelected(int itemPosition, long itemId) { - filterMode = itemPosition -1; //bit of a hack, I know. -1 is ALL 0 Docs etc - openDirectory(currentDirectory);// Uses filter mode - return true; - } - private int dpToPx(int dp){ final float scale = getApplicationContext().getResources().getDisplayMetrics().density; return (int) (dp * scale + 0.5f); -- cgit