WIP - implement navigation drawer (slide-in menu)
This commit is contained in:
parent
6477dd5656
commit
1ca1401cca
Binary file not shown.
BIN
mobile/res/drawable-hdpi/drawer_shadow.9.png
Normal file
BIN
mobile/res/drawable-hdpi/drawer_shadow.9.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 171 B |
BIN
mobile/res/drawable-hdpi/ic_drawer.png
Normal file
BIN
mobile/res/drawable-hdpi/ic_drawer.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.8 KiB |
BIN
mobile/res/drawable-mdpi/drawer_shadow.9.png
Normal file
BIN
mobile/res/drawable-mdpi/drawer_shadow.9.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 158 B |
BIN
mobile/res/drawable-mdpi/ic_drawer.png
Normal file
BIN
mobile/res/drawable-mdpi/ic_drawer.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.8 KiB |
BIN
mobile/res/drawable-xhdpi/drawer_shadow.9.png
Normal file
BIN
mobile/res/drawable-xhdpi/drawer_shadow.9.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 182 B |
BIN
mobile/res/drawable-xhdpi/ic_drawer.png
Normal file
BIN
mobile/res/drawable-xhdpi/ic_drawer.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.0 KiB |
@ -1,18 +1,33 @@
|
|||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_width="fill_parent"
|
android:id="@+id/drawer_layout"
|
||||||
android:layout_height="fill_parent"
|
android:layout_width="match_parent"
|
||||||
android:orientation="vertical">
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
<com.cradle.iitc_mobile.IITC_WebView
|
<com.cradle.iitc_mobile.IITC_WebView
|
||||||
android:id="@+id/iitc_webview"
|
android:id="@+id/iitc_webview"
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="fill_parent" />
|
android:layout_height="match_parent"/>
|
||||||
<ImageView android:id="@+id/imageLoading"
|
|
||||||
android:layout_height="fill_parent"
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:paddingTop="20dp"
|
|
||||||
android:paddingBottom="20dp"
|
|
||||||
android:background="@android:color/darker_gray"
|
|
||||||
android:src="@drawable/iitc" />
|
|
||||||
|
|
||||||
</LinearLayout>
|
<ImageView
|
||||||
|
android:id="@+id/imageLoading"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:background="@android:color/darker_gray"
|
||||||
|
android:paddingBottom="20dp"
|
||||||
|
android:paddingTop="20dp"
|
||||||
|
android:src="@drawable/iitc"/>
|
||||||
|
|
||||||
|
<!-- The navigation drawer -->
|
||||||
|
<!-- TODO: change color/width? -->
|
||||||
|
|
||||||
|
<ListView
|
||||||
|
android:id="@+id/left_drawer"
|
||||||
|
android:layout_width="240dp"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_gravity="start"
|
||||||
|
android:background="#111"
|
||||||
|
android:choiceMode="singleChoice"
|
||||||
|
android:divider="@android:color/transparent"
|
||||||
|
android:dividerHeight="0dp"/>
|
||||||
|
|
||||||
|
</android.support.v4.widget.DrawerLayout>
|
@ -7,6 +7,8 @@
|
|||||||
<string name="activity_share">Share using…</string>
|
<string name="activity_share">Share using…</string>
|
||||||
<string name="activity_share_to_clipboard">Copy to clipboard</string>
|
<string name="activity_share_to_clipboard">Copy to clipboard</string>
|
||||||
<string name="action_settings">Settings</string>
|
<string name="action_settings">Settings</string>
|
||||||
|
<string name="drawer_open">Show navigation menu</string>
|
||||||
|
<string name="drawer_close">Hide navigation menu</string>
|
||||||
<string name="reload">Reload IITC</string>
|
<string name="reload">Reload IITC</string>
|
||||||
<string name="version">Print Version</string>
|
<string name="version">Print Version</string>
|
||||||
<string name="toggle_fullscreen">Toggle fullscreen</string>
|
<string name="toggle_fullscreen">Toggle fullscreen</string>
|
||||||
|
@ -18,12 +18,14 @@ import android.widget.AdapterView;
|
|||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import com.cradle.iitc_mobile.IITC_NavigationHelper.Pane;
|
||||||
import com.cradle.iitc_mobile.share.ShareActivity;
|
import com.cradle.iitc_mobile.share.ShareActivity;
|
||||||
|
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
// provide communication between IITC script and android app
|
// provide communication between IITC script and android app
|
||||||
public class IITC_JSInterface {
|
public class IITC_JSInterface {
|
||||||
@ -102,14 +104,14 @@ public class IITC_JSInterface {
|
|||||||
iitcm.runOnUiThread(new Runnable() {
|
iitcm.runOnUiThread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
IITC_NavigationHelper navigation = iitcm.getNavigationHelper();
|
Pane pane;
|
||||||
Integer button = IITC_Mobile.PANES.get(id);
|
try {
|
||||||
|
pane = Pane.valueOf(id.toUpperCase(Locale.getDefault()));
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
pane = Pane.MAP;
|
||||||
|
}
|
||||||
|
|
||||||
if (button == null)
|
iitcm.setCurrentPane(pane);
|
||||||
button = android.R.id.home;
|
|
||||||
|
|
||||||
navigation.switchTo(button);
|
|
||||||
iitcm.backStackUpdate(button);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -17,8 +17,8 @@ import android.net.Uri;
|
|||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
|
import android.support.v4.widget.DrawerLayout;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.util.SparseArray;
|
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@ -27,19 +27,25 @@ import android.view.WindowManager;
|
|||||||
import android.webkit.CookieManager;
|
import android.webkit.CookieManager;
|
||||||
import android.webkit.WebSettings;
|
import android.webkit.WebSettings;
|
||||||
import android.webkit.WebView;
|
import android.webkit.WebView;
|
||||||
|
import android.widget.ListView;
|
||||||
import android.widget.SearchView;
|
import android.widget.SearchView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import com.cradle.iitc_mobile.IITC_NavigationHelper.Pane;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.Locale;
|
||||||
|
import java.util.Stack;
|
||||||
|
|
||||||
public class IITC_Mobile extends Activity {
|
public class IITC_Mobile extends Activity {
|
||||||
|
|
||||||
private static final int REQUEST_LOGIN = 1;
|
private static final int REQUEST_LOGIN = 1;
|
||||||
|
|
||||||
private IITC_WebView mIitcWebView;
|
private IITC_WebView mIitcWebView;
|
||||||
|
private DrawerLayout mDrawerLayout;
|
||||||
|
private ListView mDrawerList;
|
||||||
private OnSharedPreferenceChangeListener mSharedPrefChangeListener;
|
private OnSharedPreferenceChangeListener mSharedPrefChangeListener;
|
||||||
private final String mIntelUrl = "https://www.ingress.com/intel";
|
private final String mIntelUrl = "https://www.ingress.com/intel";
|
||||||
private boolean mIsLocEnabled = false;
|
private boolean mIsLocEnabled = false;
|
||||||
@ -57,32 +63,11 @@ public class IITC_Mobile extends Activity {
|
|||||||
private IITC_NavigationHelper mNavigationHelper;
|
private IITC_NavigationHelper mNavigationHelper;
|
||||||
|
|
||||||
// Used for custom back stack handling
|
// Used for custom back stack handling
|
||||||
private final ArrayList<Integer> mBackStack = new ArrayList<Integer>();
|
private final Stack<Pane> mBackStack = new Stack<IITC_NavigationHelper.Pane>();
|
||||||
private boolean mBackStackPush = true;
|
private boolean mBackStackPush = true;
|
||||||
private int mCurrentPane = android.R.id.home;
|
private Pane mCurrentPane = Pane.MAP;
|
||||||
private boolean mBackButtonPressed = false;
|
private boolean mBackButtonPressed = false;
|
||||||
|
|
||||||
public static final SparseArray<String> PANE_TITLES = new SparseArray<String>();
|
|
||||||
public static final HashMap<String, Integer> PANES = new HashMap<String, Integer>();
|
|
||||||
|
|
||||||
static {
|
|
||||||
PANES.put("map", android.R.id.home);
|
|
||||||
PANES.put("info", R.id.menu_info);
|
|
||||||
PANES.put("full", R.id.menu_full);
|
|
||||||
PANES.put("compact", R.id.menu_compact);
|
|
||||||
PANES.put("public", R.id.menu_public);
|
|
||||||
PANES.put("faction", R.id.menu_faction);
|
|
||||||
PANES.put("debug", R.id.menu_debug);
|
|
||||||
|
|
||||||
// No need to declare android.R.id.home - that title is default
|
|
||||||
PANE_TITLES.append(R.id.menu_info, "Info");
|
|
||||||
PANE_TITLES.append(R.id.menu_full, "Full");
|
|
||||||
PANE_TITLES.append(R.id.menu_compact, "Compact");
|
|
||||||
PANE_TITLES.append(R.id.menu_public, "Public");
|
|
||||||
PANE_TITLES.append(R.id.menu_faction, "Faction");
|
|
||||||
PANE_TITLES.append(R.id.menu_debug, "Debug");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
@ -92,9 +77,11 @@ public class IITC_Mobile extends Activity {
|
|||||||
|
|
||||||
setContentView(R.layout.activity_main);
|
setContentView(R.layout.activity_main);
|
||||||
mIitcWebView = (IITC_WebView) findViewById(R.id.iitc_webview);
|
mIitcWebView = (IITC_WebView) findViewById(R.id.iitc_webview);
|
||||||
|
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
|
||||||
|
mDrawerList = (ListView) findViewById(R.id.left_drawer);
|
||||||
|
|
||||||
// pass ActionBar to helper because we deprecated getActionBar
|
// pass ActionBar to helper because we deprecated getActionBar
|
||||||
mNavigationHelper = new IITC_NavigationHelper(this, super.getActionBar());
|
mNavigationHelper = new IITC_NavigationHelper(this, super.getActionBar(), mDrawerList, mDrawerLayout);
|
||||||
|
|
||||||
// do something if user changed something in the settings
|
// do something if user changed something in the settings
|
||||||
mSharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
|
mSharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
@ -224,8 +211,8 @@ public class IITC_Mobile extends Activity {
|
|||||||
(SearchView) mSearchMenuItem.getActionView();
|
(SearchView) mSearchMenuItem.getActionView();
|
||||||
searchView.setQuery(query, false);
|
searchView.setQuery(query, false);
|
||||||
searchView.clearFocus();
|
searchView.clearFocus();
|
||||||
mNavigationHelper.switchTo(android.R.id.home);
|
|
||||||
backStackUpdate(android.R.id.home);
|
switchToPane(Pane.MAP);
|
||||||
mIitcWebView.loadUrl("javascript:search('" + query + "');");
|
mIitcWebView.loadUrl("javascript:search('" + query + "');");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -318,11 +305,19 @@ public class IITC_Mobile extends Activity {
|
|||||||
public void onConfigurationChanged(Configuration newConfig) {
|
public void onConfigurationChanged(Configuration newConfig) {
|
||||||
super.onConfigurationChanged(newConfig);
|
super.onConfigurationChanged(newConfig);
|
||||||
|
|
||||||
|
mNavigationHelper.onConfigurationChanged(newConfig);
|
||||||
|
|
||||||
Log.d("iitcm", "configuration changed...restoring...reset idleTimer");
|
Log.d("iitcm", "configuration changed...restoring...reset idleTimer");
|
||||||
mIitcWebView.loadUrl("javascript: window.idleTime = 0");
|
mIitcWebView.loadUrl("javascript: window.idleTime = 0");
|
||||||
mIitcWebView.loadUrl("javascript: window.renderUpdateStatus()");
|
mIitcWebView.loadUrl("javascript: window.renderUpdateStatus()");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPostCreate(Bundle savedInstanceState) {
|
||||||
|
super.onPostCreate(savedInstanceState);
|
||||||
|
mNavigationHelper.onPostCreate(savedInstanceState);
|
||||||
|
}
|
||||||
|
|
||||||
// we want a self defined behavior for the back button
|
// we want a self defined behavior for the back button
|
||||||
@Override
|
@Override
|
||||||
public void onBackPressed() {
|
public void onBackPressed() {
|
||||||
@ -364,31 +359,30 @@ public class IITC_Mobile extends Activity {
|
|||||||
// shouldn't be called when back stack is empty
|
// shouldn't be called when back stack is empty
|
||||||
// catch wrong usage
|
// catch wrong usage
|
||||||
if (mBackStack.isEmpty()) {
|
if (mBackStack.isEmpty()) {
|
||||||
// Empty back stack means we should be at home (ie map) screen
|
mBackStack.push(Pane.MAP);
|
||||||
mNavigationHelper.switchTo(android.R.id.home);
|
|
||||||
mIitcWebView.loadUrl("javascript: window.show('map');");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
int index = mBackStack.size() - 1;
|
|
||||||
int itemId = mBackStack.remove(index);
|
|
||||||
mBackStackPush = false;
|
|
||||||
handleMenuItemSelected(itemId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void backStackUpdate(int itemId) {
|
Pane pane = mBackStack.pop();
|
||||||
|
mBackStackPush = false;
|
||||||
|
switchToPane(pane);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCurrentPane(Pane pane) {
|
||||||
// ensure no double adds
|
// ensure no double adds
|
||||||
if (itemId == mCurrentPane) return;
|
if (pane == mCurrentPane) return;
|
||||||
if (itemId == android.R.id.home) {
|
|
||||||
mBackStack.clear();
|
|
||||||
mBackStackPush = true;
|
|
||||||
} else {
|
|
||||||
if (mBackStackPush)
|
if (mBackStackPush)
|
||||||
mBackStack.add(mCurrentPane);
|
mBackStack.push(mCurrentPane);
|
||||||
else
|
else
|
||||||
mBackStackPush = true;
|
mBackStackPush = true;
|
||||||
|
|
||||||
|
mCurrentPane = pane;
|
||||||
|
mNavigationHelper.switchTo(pane);
|
||||||
}
|
}
|
||||||
|
|
||||||
mCurrentPane = itemId;
|
public void switchToPane(Pane pane) {
|
||||||
|
String name = pane.name().toLowerCase(Locale.getDefault());
|
||||||
|
mIitcWebView.loadUrl("javascript: window.show('" + name + "');");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -411,16 +405,17 @@ public class IITC_Mobile extends Activity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
|
if (mNavigationHelper.onOptionsItemSelected(item))
|
||||||
|
return true;
|
||||||
|
|
||||||
// Handle item selection
|
// Handle item selection
|
||||||
final int itemId = item.getItemId();
|
final int itemId = item.getItemId();
|
||||||
boolean result = handleMenuItemSelected(itemId);
|
|
||||||
return result || super.onOptionsItemSelected(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean handleMenuItemSelected(int itemId) {
|
|
||||||
switch (itemId) {
|
switch (itemId) {
|
||||||
case android.R.id.home:
|
case android.R.id.home:
|
||||||
mIitcWebView.loadUrl("javascript: window.show('map');");
|
mBackStack.clear();
|
||||||
|
mBackStackPush = false;
|
||||||
|
switchToPane(Pane.MAP);
|
||||||
return true;
|
return true;
|
||||||
case R.id.reload_button:
|
case R.id.reload_button:
|
||||||
reloadIITC();
|
reloadIITC();
|
||||||
@ -430,13 +425,13 @@ public class IITC_Mobile extends Activity {
|
|||||||
return true;
|
return true;
|
||||||
case R.id.layer_chooser:
|
case R.id.layer_chooser:
|
||||||
// Force map view to handle potential issue with back stack
|
// Force map view to handle potential issue with back stack
|
||||||
if (!mBackStack.isEmpty() && mCurrentPane != android.R.id.home)
|
if (!mBackStack.isEmpty() && mCurrentPane != Pane.MAP)
|
||||||
mIitcWebView.loadUrl("javascript: window.show('map');");
|
switchToPane(Pane.MAP);
|
||||||
// the getLayers function calls the setLayers method of IITC_JSInterface
|
// the getLayers function calls the setLayers method of IITC_JSInterface
|
||||||
mIitcWebView.loadUrl("javascript: window.layerChooser.getLayers()");
|
mIitcWebView.loadUrl("javascript: window.layerChooser.getLayers()");
|
||||||
return true;
|
return true;
|
||||||
case R.id.locate: // get the users current location and focus it on map
|
case R.id.locate: // get the users current location and focus it on map
|
||||||
mIitcWebView.loadUrl("javascript: window.show('map');");
|
switchToPane(Pane.MAP);
|
||||||
// get location from network by default
|
// get location from network by default
|
||||||
if (!mIsLocEnabled) {
|
if (!mIsLocEnabled) {
|
||||||
mIitcWebView.loadUrl("javascript: " +
|
mIitcWebView.loadUrl("javascript: " +
|
||||||
@ -456,22 +451,22 @@ public class IITC_Mobile extends Activity {
|
|||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
return true;
|
return true;
|
||||||
case R.id.menu_info:
|
case R.id.menu_info:
|
||||||
mIitcWebView.loadUrl("javascript: window.show('info');");
|
switchToPane(Pane.INFO);
|
||||||
return true;
|
return true;
|
||||||
case R.id.menu_full:
|
case R.id.menu_full:
|
||||||
mIitcWebView.loadUrl("javascript: window.show('full');");
|
switchToPane(Pane.FULL);
|
||||||
return true;
|
return true;
|
||||||
case R.id.menu_compact:
|
case R.id.menu_compact:
|
||||||
mIitcWebView.loadUrl("javascript: window.show('compact');");
|
switchToPane(Pane.COMPACT);
|
||||||
return true;
|
return true;
|
||||||
case R.id.menu_public:
|
case R.id.menu_public:
|
||||||
mIitcWebView.loadUrl("javascript: window.show('public');");
|
switchToPane(Pane.PUBLIC);
|
||||||
return true;
|
return true;
|
||||||
case R.id.menu_faction:
|
case R.id.menu_faction:
|
||||||
mIitcWebView.loadUrl("javascript: window.show('faction');");
|
switchToPane(Pane.FACTION);
|
||||||
return true;
|
return true;
|
||||||
case R.id.menu_debug:
|
case R.id.menu_debug:
|
||||||
mIitcWebView.loadUrl("javascript: window.show('debug')");
|
switchToPane(Pane.DEBUG);
|
||||||
return true;
|
return true;
|
||||||
case R.id.menu_clear_cookies:
|
case R.id.menu_clear_cookies:
|
||||||
CookieManager cm = CookieManager.getInstance();
|
CookieManager cm = CookieManager.getInstance();
|
||||||
@ -485,8 +480,9 @@ public class IITC_Mobile extends Activity {
|
|||||||
public void reloadIITC() {
|
public void reloadIITC() {
|
||||||
mNavigationHelper.reset();
|
mNavigationHelper.reset();
|
||||||
mBackStack.clear();
|
mBackStack.clear();
|
||||||
|
mBackStackPush = true;
|
||||||
// iitc starts on map after reload
|
// iitc starts on map after reload
|
||||||
mCurrentPane = android.R.id.home;
|
mCurrentPane = Pane.MAP;
|
||||||
loadUrl(mIntelUrl);
|
loadUrl(mIntelUrl);
|
||||||
mReloadNeeded = false;
|
mReloadNeeded = false;
|
||||||
}
|
}
|
||||||
|
@ -3,11 +3,20 @@ package com.cradle.iitc_mobile;
|
|||||||
import android.app.ActionBar;
|
import android.app.ActionBar;
|
||||||
import android.app.ActionBar.OnNavigationListener;
|
import android.app.ActionBar.OnNavigationListener;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
import android.os.Bundle;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
|
import android.support.v4.app.ActionBarDrawerToggle;
|
||||||
|
import android.support.v4.widget.DrawerLayout;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.AdapterView;
|
||||||
|
import android.widget.AdapterView.OnItemClickListener;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
|
import android.widget.ListView;
|
||||||
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
public class IITC_NavigationHelper implements OnNavigationListener {
|
public class IITC_NavigationHelper extends ActionBarDrawerToggle implements OnNavigationListener, OnItemClickListener {
|
||||||
// Show/hide the up arrow on the very left
|
// Show/hide the up arrow on the very left
|
||||||
// getActionBar().setDisplayHomeAsUpEnabled(enabled);
|
// getActionBar().setDisplayHomeAsUpEnabled(enabled);
|
||||||
|
|
||||||
@ -20,6 +29,60 @@ public class IITC_NavigationHelper implements OnNavigationListener {
|
|||||||
// Makes the icon/title clickable
|
// Makes the icon/title clickable
|
||||||
// getActionBar().setHomeButtonEnabled(enabled);
|
// getActionBar().setHomeButtonEnabled(enabled);
|
||||||
|
|
||||||
|
public static enum Pane {
|
||||||
|
MAP, INFO, FULL, COMPACT, PUBLIC, FACTION, DEBUG
|
||||||
|
};
|
||||||
|
|
||||||
|
public String getPaneTitle(Pane pane)
|
||||||
|
{
|
||||||
|
switch (pane) {
|
||||||
|
case INFO:
|
||||||
|
return "Info";
|
||||||
|
case FULL:
|
||||||
|
return "Full";
|
||||||
|
case COMPACT:
|
||||||
|
return "Compact";
|
||||||
|
case PUBLIC:
|
||||||
|
return "Public";
|
||||||
|
case FACTION:
|
||||||
|
return "Faction";
|
||||||
|
case DEBUG:
|
||||||
|
return "Debug";
|
||||||
|
default:
|
||||||
|
return mIitc.getString(R.string.app_name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class NavigationAdapter extends ArrayAdapter<Pane> {
|
||||||
|
public NavigationAdapter() {
|
||||||
|
super(mIitc, android.R.layout.simple_list_item_1);
|
||||||
|
|
||||||
|
addAll(Pane.values());
|
||||||
|
// TODO: remove debug according to preferences
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public View getView(int position, View convertView, ViewGroup parent) {
|
||||||
|
/*
|
||||||
|
* LayoutInflater inflater = ((Activity) getContext()).getLayoutInflater();
|
||||||
|
* TextView view = (TextView) inflater.inflate(android.R.layout.simple_list_item_1, parent, false);
|
||||||
|
*
|
||||||
|
* ActivityInfo info = getItem(position).activityInfo;
|
||||||
|
* CharSequence label = info.loadLabel(mPackageManager);
|
||||||
|
* Drawable icon = info.loadIcon(mPackageManager);
|
||||||
|
*
|
||||||
|
* view.setText(label);
|
||||||
|
* view.setCompoundDrawablePadding((int) getResources().getDimension(R.dimen.icon_margin));
|
||||||
|
* view.setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null);
|
||||||
|
*
|
||||||
|
* return view;
|
||||||
|
*/
|
||||||
|
TextView view = (TextView) super.getView(position, convertView, parent);
|
||||||
|
view.setText(getPaneTitle(getItem(position)));
|
||||||
|
return view;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private class HighlighterAdapter extends ArrayAdapter<String> {
|
private class HighlighterAdapter extends ArrayAdapter<String> {
|
||||||
public HighlighterAdapter() {
|
public HighlighterAdapter() {
|
||||||
super(mIitc, android.R.layout.simple_list_item_1);
|
super(mIitc, android.R.layout.simple_list_item_1);
|
||||||
@ -43,43 +106,61 @@ public class IITC_NavigationHelper implements OnNavigationListener {
|
|||||||
private ActionBar mActionBar;
|
private ActionBar mActionBar;
|
||||||
private SharedPreferences mPrefs;
|
private SharedPreferences mPrefs;
|
||||||
private HighlighterAdapter mHighlighters;
|
private HighlighterAdapter mHighlighters;
|
||||||
|
private NavigationAdapter mNavigationAdapter;
|
||||||
|
private DrawerLayout mDrawerLayout;
|
||||||
|
private ListView mDrawerList;
|
||||||
|
|
||||||
private String mActiveHighlighter = null;
|
private String mActiveHighlighter = null;
|
||||||
private boolean mDesktopMode = false;
|
private boolean mDesktopMode = false;
|
||||||
private boolean mFullscreen = false;
|
private boolean mFullscreen = false;
|
||||||
private boolean mHideInFullscreen = false;
|
private boolean mHideInFullscreen = false;
|
||||||
private int mPane = android.R.id.home;
|
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) {
|
|
||||||
mIitc = activity;
|
mIitc = activity;
|
||||||
mActionBar = bar;
|
mActionBar = bar;
|
||||||
|
mDrawerList = drawerList;
|
||||||
|
mDrawerLayout = drawerLayout;
|
||||||
|
|
||||||
mPrefs = PreferenceManager.getDefaultSharedPreferences(activity);
|
mPrefs = PreferenceManager.getDefaultSharedPreferences(activity);
|
||||||
mHighlighters = new HighlighterAdapter();
|
mHighlighters = new HighlighterAdapter();
|
||||||
|
|
||||||
mActionBar.setDisplayShowHomeEnabled(true); // show icon
|
mActionBar.setDisplayShowHomeEnabled(true); // show icon
|
||||||
mActionBar.setListNavigationCallbacks(mHighlighters, this);
|
mActionBar.setListNavigationCallbacks(mHighlighters, this);
|
||||||
|
|
||||||
|
mNavigationAdapter = new NavigationAdapter();
|
||||||
|
mDrawerList.setAdapter(mNavigationAdapter);
|
||||||
|
mDrawerList.setOnItemClickListener(this);
|
||||||
|
mDrawerLayout.setDrawerListener(this);
|
||||||
|
|
||||||
onPrefChanged(); // also calls updateActionBar()
|
onPrefChanged(); // also calls updateActionBar()
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateActionBar() {
|
private void updateActionBar() {
|
||||||
|
// TODO setDisplayHomeAsUpEnabled should always be true on mobile mode
|
||||||
|
// TODO hide draw list in desktop mode
|
||||||
boolean showHighlighter = true;
|
boolean showHighlighter = true;
|
||||||
|
|
||||||
if (mDesktopMode) {
|
if (mDesktopMode) {
|
||||||
mActionBar.setDisplayHomeAsUpEnabled(false); // Hide "up" indicator
|
mActionBar.setDisplayHomeAsUpEnabled(false); // Hide "up" indicator
|
||||||
mActionBar.setHomeButtonEnabled(false); // Make icon unclickable
|
mActionBar.setHomeButtonEnabled(false); // Make icon unclickable
|
||||||
mActionBar.setTitle(mIitc.getString(R.string.app_name));
|
mActionBar.setTitle(mIitc.getString(R.string.app_name));
|
||||||
|
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
|
||||||
|
setDrawerIndicatorEnabled(false);
|
||||||
} else {
|
} else {
|
||||||
if (mPane != android.R.id.home) {
|
|
||||||
mActionBar.setDisplayHomeAsUpEnabled(true); // Show "up" indicator
|
mActionBar.setDisplayHomeAsUpEnabled(true); // Show "up" indicator
|
||||||
mActionBar.setHomeButtonEnabled(true);// Make icon clickable
|
mActionBar.setHomeButtonEnabled(true);// Make icon clickable
|
||||||
|
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
|
||||||
|
if (mPane != Pane.MAP) {
|
||||||
showHighlighter = false;
|
showHighlighter = false;
|
||||||
|
setDrawerIndicatorEnabled(false);
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
mActionBar.setDisplayHomeAsUpEnabled(false); // Hide "up" indicator
|
setDrawerIndicatorEnabled(true);
|
||||||
mActionBar.setHomeButtonEnabled(false); // Make icon unclickable
|
|
||||||
}
|
mActionBar.setTitle(getPaneTitle(mPane));
|
||||||
mActionBar.setTitle(IITC_Mobile.PANE_TITLES.get(mPane, mIitc.getString(R.string.app_name)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mHighlighters.getCount() < 2) // there should always be "No Highlights"
|
if (mHighlighters.getCount() < 2) // there should always be "No Highlights"
|
||||||
@ -116,6 +197,7 @@ public class IITC_NavigationHelper implements OnNavigationListener {
|
|||||||
public boolean onNavigationItemSelected(int position, long itemId) {
|
public boolean onNavigationItemSelected(int position, long itemId) {
|
||||||
String name = mHighlighters.getItem(position);
|
String name = mHighlighters.getItem(position);
|
||||||
mIitc.getWebView().loadUrl("javascript: window.changePortalHighlights('" + name + "')");
|
mIitc.getWebView().loadUrl("javascript: window.changePortalHighlights('" + name + "')");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -127,7 +209,7 @@ public class IITC_NavigationHelper implements OnNavigationListener {
|
|||||||
|
|
||||||
public void reset() {
|
public void reset() {
|
||||||
mHighlighters.clear();
|
mHighlighters.clear();
|
||||||
mPane = android.R.id.home;
|
mPane = Pane.MAP;
|
||||||
updateActionBar();
|
updateActionBar();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -151,8 +233,33 @@ public class IITC_NavigationHelper implements OnNavigationListener {
|
|||||||
updateActionBar();
|
updateActionBar();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void switchTo(int button) {
|
public void switchTo(Pane pane) {
|
||||||
mPane = button;
|
mPane = pane;
|
||||||
|
|
||||||
updateActionBar();
|
updateActionBar();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||||
|
Pane item = mNavigationAdapter.getItem(position);
|
||||||
|
mIitc.switchToPane(item);
|
||||||
|
mDrawerLayout.closeDrawer(mDrawerList);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDrawerOpened(View drawerView) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
super.onDrawerOpened(drawerView);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDrawerClosed(View drawerView) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
super.onDrawerClosed(drawerView);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onPostCreate(Bundle savedInstanceState) {
|
||||||
|
// Sync the toggle state after onRestoreInstanceState has occurred.
|
||||||
|
syncState();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user