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 <jani@documentfoundation.org>
Tested-by: jan iversen <jani@documentfoundation.org>
This commit is contained in:
aleksandar-stefanovic
2016-12-29 20:29:41 +01:00
committed by jan iversen
parent 11e443bfe1
commit d976f9151a
3 changed files with 40 additions and 23 deletions

View File

@@ -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">
<android.support.v7.widget.AppCompatSpinner
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/toolbar_spinner"/>
</android.support.v7.widget.Toolbar>

View File

@@ -33,11 +33,11 @@
<!-- Preference Name Arrays
This has to be in sync with FileUtilities.java. -->
<string-array name="file_view_modes">
<item >EVERYTHING</item>
<item >DOCUMENTS</item>
<item>SPREADSHEETS</item>
<item >PRESENTATIONS</item>
<item>DRAWINGS</item>
<item>Everything</item>
<item>Documents</item>
<item>Spreadsheets</item>
<item>Presentations</item>
<item>Drawings</item>
</string-array>
<string-array name="FilterTypeNames">

View File

@@ -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<CharSequence> 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<CharSequence> 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
}
@Override
public void onNothingSelected(AdapterView<?> adapterView) {
filterMode = FileUtilities.ALL;
openDirectory(currentDirectory);
}
});
}
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
actionBar.setListNavigationCallbacks(list, this);
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);