Introduce a second drawer with map settings

This commit is contained in:
fkloft
2013-09-23 18:35:10 +02:00
parent e06f8f87d9
commit f560ff369f
10 changed files with 421 additions and 373 deletions

View File

@ -1,7 +1,6 @@
package com.cradle.iitc_mobile;
import android.app.ActionBar;
import android.app.ActionBar.OnNavigationListener;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
@ -16,9 +15,7 @@ import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import java.util.Comparator;
public class IITC_NavigationHelper extends ActionBarDrawerToggle implements OnNavigationListener, OnItemClickListener {
public class IITC_NavigationHelper extends ActionBarDrawerToggle implements OnItemClickListener {
// Show/hide the up arrow on the very left
// getActionBar().setDisplayHomeAsUpEnabled(enabled);
@ -31,42 +28,6 @@ public class IITC_NavigationHelper extends ActionBarDrawerToggle implements OnNa
// Makes the icon/title clickable
// getActionBar().setHomeButtonEnabled(enabled);
private class HighlighterAdapter extends ArrayAdapter<String> {
// Move "No Highlights" on top. Sort the rest alphabetically
private class HighlighterComparator implements Comparator<String> {
@Override
public int compare(String lhs, String rhs) {
if (lhs.equals("No Highlights"))
return -1000;
else if (rhs.equals("No Highlights"))
return 1000;
else
return lhs.compareTo(rhs);
}
}
private HighlighterComparator mComparator = new HighlighterComparator();
public HighlighterAdapter() {
super(mIitc, android.R.layout.simple_list_item_1);
clear();
}
@Override
public void add(String object) {
super.remove(object); // to avoid duplicates
super.add(object);
super.sort(mComparator);
}
@Override
public void clear() {
super.clear();
add("No Highlights");// Probably must be the same as window._no_highlighter
}
};
private class NavigationAdapter extends ArrayAdapter<Pane> {
public NavigationAdapter() {
super(mIitc, R.layout.list_item_selectable);
@ -122,12 +83,11 @@ public class IITC_NavigationHelper extends ActionBarDrawerToggle implements OnNa
private IITC_Mobile mIitc;
private ActionBar mActionBar;
private SharedPreferences mPrefs;
private HighlighterAdapter mHighlighters;
private NavigationAdapter mNavigationAdapter;
private DrawerLayout mDrawerLayout;
private ListView mDrawerList;
private ListView mDrawerLeft;
private View mDrawerRight;
private String mActiveHighlighter = null;
private boolean mDesktopMode = false;
private boolean mDrawerOpened;
private boolean mFullscreen = false;
@ -135,35 +95,33 @@ public class IITC_NavigationHelper extends ActionBarDrawerToggle implements OnNa
private boolean mHideInFullscreen = false;
private Pane mPane = Pane.MAP;
public IITC_NavigationHelper(IITC_Mobile activity, ActionBar bar, ListView drawerList, DrawerLayout drawerLayout) {
super(activity, drawerLayout, R.drawable.ic_drawer, R.string.drawer_open, R.string.drawer_close);
public IITC_NavigationHelper(IITC_Mobile activity, ActionBar bar) {
super(activity, (DrawerLayout) activity.findViewById(R.id.drawer_layout),
R.drawable.ic_drawer, R.string.drawer_open, R.string.drawer_close);
mIitc = activity;
mActionBar = bar;
mDrawerList = drawerList;
mDrawerLayout = drawerLayout;
mDrawerLeft = (ListView) activity.findViewById(R.id.left_drawer);
mDrawerRight = activity.findViewById(R.id.right_drawer);
mDrawerLayout = (DrawerLayout) activity.findViewById(R.id.drawer_layout);
mPrefs = PreferenceManager.getDefaultSharedPreferences(activity);
mHighlighters = new HighlighterAdapter();
mActionBar.setDisplayShowHomeEnabled(true); // show icon
mActionBar.setListNavigationCallbacks(mHighlighters, this);
mNavigationAdapter = new NavigationAdapter();
mDrawerList.setAdapter(mNavigationAdapter);
mDrawerList.setOnItemClickListener(this);
mDrawerList.setItemChecked(0, true);
mDrawerLeft.setAdapter(mNavigationAdapter);
mDrawerLeft.setOnItemClickListener(this);
mDrawerLeft.setItemChecked(0, true);
mDrawerLayout.setDrawerListener(this);
onPrefChanged(); // also calls updateActionBar()
}
private void updateActionBar() {
boolean showHighlighter = true;
int position = mNavigationAdapter.getPosition(mPane);
if (position >= 0 && position < mNavigationAdapter.getCount())
mDrawerList.setItemChecked(position, true);
mDrawerLeft.setItemChecked(position, true);
if (mDesktopMode) {
mActionBar.setDisplayHomeAsUpEnabled(false); // Hide "up" indicator
@ -188,42 +146,16 @@ public class IITC_NavigationHelper extends ActionBarDrawerToggle implements OnNa
setDrawerIndicatorEnabled(true);
}
if (mPane != Pane.MAP)
showHighlighter = false;
mActionBar.setTitle(getPaneTitle(mPane));
}
if (mHighlighters.getCount() < 2) // there should always be "No Highlights"
showHighlighter = false;
if (mDrawerOpened)
showHighlighter = false;
if (showHighlighter) {
mActionBar.setDisplayShowTitleEnabled(false); // Hide title
mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
setActiveHighlighter(mActiveHighlighter);
} else {
mActionBar.setDisplayShowTitleEnabled(true); // Show title
mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
}
if (mFullscreen && mHideInFullscreen)
mActionBar.hide();
else
mActionBar.show();
}
public void addPortalHighlighter(String name) {
mHighlighters.add(name);
if (name.equals(mActiveHighlighter))
setActiveHighlighter(name);
updateActionBar();
}
public void closeDrawer() {
public void closeDrawers() {
mDrawerLayout.closeDrawers();
}
@ -275,15 +207,7 @@ public class IITC_NavigationHelper extends ActionBarDrawerToggle implements OnNa
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Pane item = mNavigationAdapter.getItem(position);
mIitc.switchToPane(item);
mDrawerLayout.closeDrawer(mDrawerList);
}
@Override
public boolean onNavigationItemSelected(int position, long itemId) {
String name = mHighlighters.getItem(position);
mIitc.getWebView().loadUrl("javascript: window.changePortalHighlights('" + name + "')");
return true;
mDrawerLayout.closeDrawer(mDrawerLeft);
}
public void onPostCreate(Bundle savedInstanceState) {
@ -298,21 +222,11 @@ public class IITC_NavigationHelper extends ActionBarDrawerToggle implements OnNa
}
public void reset() {
mHighlighters.clear();
// TODO mHighlighters.clear();
mPane = Pane.MAP;
updateActionBar();
}
public void setActiveHighlighter(String name) {
mActiveHighlighter = name;
if (mActionBar.getNavigationMode() == ActionBar.NAVIGATION_MODE_LIST) {
int position = mHighlighters.getPosition(mActiveHighlighter);
if (position >= 0 && position < mActionBar.getNavigationItemCount())
mActionBar.setSelectedNavigationItem(position);
}
}
public void setDebugMode(boolean enabled) {
mNavigationAdapter.remove(Pane.DEBUG); // avoid duplicates
if (enabled)
@ -339,4 +253,9 @@ public class IITC_NavigationHelper extends ActionBarDrawerToggle implements OnNa
updateActionBar();
}
public void openRightDrawer() {
// TODO should close left drawer
mDrawerLayout.openDrawer(mDrawerRight);
}
}