Replace Pane enum with class
This commit is contained in:
@ -13,8 +13,6 @@ import android.widget.Toast;
|
|||||||
import com.cradle.iitc_mobile.IITC_NavigationHelper.Pane;
|
import com.cradle.iitc_mobile.IITC_NavigationHelper.Pane;
|
||||||
import com.cradle.iitc_mobile.share.ShareActivity;
|
import com.cradle.iitc_mobile.share.ShareActivity;
|
||||||
|
|
||||||
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 {
|
||||||
// context of main activity
|
// context of main activity
|
||||||
@ -96,7 +94,7 @@ public class IITC_JSInterface {
|
|||||||
public void run() {
|
public void run() {
|
||||||
Pane pane;
|
Pane pane;
|
||||||
try {
|
try {
|
||||||
pane = Pane.valueOf(id.toUpperCase(Locale.getDefault()));
|
pane = mIitc.getNavigationHelper().getPane(id);
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
pane = Pane.MAP;
|
pane = Pane.MAP;
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,6 @@ import android.widget.ArrayAdapter;
|
|||||||
import android.widget.CheckedTextView;
|
import android.widget.CheckedTextView;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
import android.widget.Spinner;
|
import android.widget.Spinner;
|
||||||
import android.widget.TextView;
|
|
||||||
|
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
|
@ -35,7 +35,6 @@ import com.cradle.iitc_mobile.IITC_NavigationHelper.Pane;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.Stack;
|
import java.util.Stack;
|
||||||
|
|
||||||
public class IITC_Mobile extends Activity implements OnSharedPreferenceChangeListener, LocationListener {
|
public class IITC_Mobile extends Activity implements OnSharedPreferenceChangeListener, LocationListener {
|
||||||
@ -412,8 +411,7 @@ public class IITC_Mobile extends Activity implements OnSharedPreferenceChangeLis
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void switchToPane(Pane pane) {
|
public void switchToPane(Pane pane) {
|
||||||
String name = pane.name().toLowerCase(Locale.getDefault());
|
mIitcWebView.loadUrl("javascript: window.show('" + pane.name + "');");
|
||||||
mIitcWebView.loadUrl("javascript: window.show('" + name + "');");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -34,69 +34,6 @@ public class IITC_NavigationHelper extends ActionBarDrawerToggle implements OnIt
|
|||||||
// Makes the icon/title clickable
|
// Makes the icon/title clickable
|
||||||
// getActionBar().setHomeButtonEnabled(enabled);
|
// getActionBar().setHomeButtonEnabled(enabled);
|
||||||
|
|
||||||
private class NavigationAdapter extends ArrayAdapter<Pane> {
|
|
||||||
public NavigationAdapter() {
|
|
||||||
super(mIitc, R.layout.list_item_selectable);
|
|
||||||
|
|
||||||
add(Pane.MAP);
|
|
||||||
add(Pane.INFO);
|
|
||||||
add(Pane.FULL);
|
|
||||||
add(Pane.COMPACT);
|
|
||||||
add(Pane.PUBLIC);
|
|
||||||
add(Pane.FACTION);
|
|
||||||
|
|
||||||
if (mPrefs.getBoolean("pref_advanced_menu", false)) {
|
|
||||||
add(Pane.DEBUG);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public View getView(int position, View convertView, ViewGroup parent) {
|
|
||||||
TextView view = (TextView) super.getView(position, convertView, parent);
|
|
||||||
Pane item = getItem(position);
|
|
||||||
if (item == Pane.MAP) {
|
|
||||||
view.setText("Map");
|
|
||||||
} else {
|
|
||||||
view.setText(getPaneTitle(item));
|
|
||||||
}
|
|
||||||
|
|
||||||
int icon = 0;
|
|
||||||
switch (item) {
|
|
||||||
case MAP:
|
|
||||||
icon = R.drawable.location_map;
|
|
||||||
break;
|
|
||||||
case INFO:
|
|
||||||
icon = R.drawable.action_about;
|
|
||||||
break;
|
|
||||||
case FULL:
|
|
||||||
icon = R.drawable.collections_view_as_list;
|
|
||||||
break;
|
|
||||||
case COMPACT:
|
|
||||||
icon = R.drawable.collections_view_as_list_compact;
|
|
||||||
break;
|
|
||||||
case PUBLIC:
|
|
||||||
icon = R.drawable.social_group;
|
|
||||||
break;
|
|
||||||
case FACTION:
|
|
||||||
icon = R.drawable.social_cc_bcc;
|
|
||||||
break;
|
|
||||||
case DEBUG:
|
|
||||||
icon = R.drawable.ic_debug;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (icon != 0) {
|
|
||||||
view.setCompoundDrawablesWithIntrinsicBounds(icon, 0, 0, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
return view;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static enum Pane {
|
|
||||||
COMPACT, DEBUG, FACTION, FULL, INFO, MAP, PUBLIC
|
|
||||||
}
|
|
||||||
|
|
||||||
public static final int NOTICE_DRAWERS = 1 << 0;
|
public static final int NOTICE_DRAWERS = 1 << 0;
|
||||||
public static final int NOTICE_INFO = 1 << 1;
|
public static final int NOTICE_INFO = 1 << 1;
|
||||||
// next one would be 1<<2; (this results in 1,2,4,8,...)
|
// next one would be 1<<2; (this results in 1,2,4,8,...)
|
||||||
@ -140,9 +77,7 @@ public class IITC_NavigationHelper extends ActionBarDrawerToggle implements OnIt
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void showNotice(final int which) {
|
private void showNotice(final int which) {
|
||||||
if ((mPrefs.getInt("pref_messages", 0) & which) != 0) {
|
if ((mPrefs.getInt("pref_messages", 0) & which) != 0) return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
String text;
|
String text;
|
||||||
switch (which) {
|
switch (which) {
|
||||||
@ -185,10 +120,12 @@ public class IITC_NavigationHelper extends ActionBarDrawerToggle implements OnIt
|
|||||||
dialog.show();
|
dialog.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateActionBar() {
|
private void updateViews() {
|
||||||
int position = mNavigationAdapter.getPosition(mPane);
|
int position = mNavigationAdapter.getPosition(mPane);
|
||||||
if (position >= 0 && position < mNavigationAdapter.getCount()) {
|
if (position >= 0 && position < mNavigationAdapter.getCount()) {
|
||||||
mDrawerLeft.setItemChecked(position, true);
|
mDrawerLeft.setItemChecked(position, true);
|
||||||
|
} else {
|
||||||
|
mDrawerLeft.setItemChecked(mDrawerLeft.getCheckedItemPosition(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mDesktopMode) {
|
if (mDesktopMode) {
|
||||||
@ -219,7 +156,7 @@ public class IITC_NavigationHelper extends ActionBarDrawerToggle implements OnIt
|
|||||||
if (mDrawerLayout.isDrawerOpen(mDrawerLeft)) {
|
if (mDrawerLayout.isDrawerOpen(mDrawerLeft)) {
|
||||||
mActionBar.setTitle(mIitc.getString(R.string.app_name));
|
mActionBar.setTitle(mIitc.getString(R.string.app_name));
|
||||||
} else {
|
} else {
|
||||||
mActionBar.setTitle(getPaneTitle(mPane));
|
mActionBar.setTitle(mPane.label);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -235,23 +172,17 @@ public class IITC_NavigationHelper extends ActionBarDrawerToggle implements OnIt
|
|||||||
mDrawerLayout.closeDrawers();
|
mDrawerLayout.closeDrawers();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getPaneTitle(Pane pane) {
|
public Pane getPane(String id) {
|
||||||
switch (pane) {
|
for (int i = 0; i < mNavigationAdapter.getCount(); i++) {
|
||||||
case INFO:
|
Pane pane = mNavigationAdapter.getItem(i);
|
||||||
return "Info";
|
if (pane.name.equals(id))
|
||||||
case FULL:
|
return pane;
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
throw new IllegalArgumentException("Unknown pane: " + id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void hideActionBar() {
|
||||||
|
mActionBar.hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isDrawerOpened() {
|
public boolean isDrawerOpened() {
|
||||||
@ -268,7 +199,7 @@ public class IITC_NavigationHelper extends ActionBarDrawerToggle implements OnIt
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
mIitc.invalidateOptionsMenu();
|
mIitc.invalidateOptionsMenu();
|
||||||
updateActionBar();
|
updateViews();
|
||||||
}
|
}
|
||||||
}, 200);
|
}, 200);
|
||||||
}
|
}
|
||||||
@ -278,7 +209,7 @@ public class IITC_NavigationHelper extends ActionBarDrawerToggle implements OnIt
|
|||||||
super.onDrawerOpened(drawerView);
|
super.onDrawerOpened(drawerView);
|
||||||
mIitc.getWebView().onWindowFocusChanged(false);
|
mIitc.getWebView().onWindowFocusChanged(false);
|
||||||
mIitc.invalidateOptionsMenu();
|
mIitc.invalidateOptionsMenu();
|
||||||
updateActionBar();
|
updateViews();
|
||||||
mDrawerLayout.closeDrawer(drawerView.equals(mDrawerLeft) ? mDrawerRight : mDrawerLeft);
|
mDrawerLayout.closeDrawer(drawerView.equals(mDrawerLeft) ? mDrawerRight : mDrawerLeft);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -310,7 +241,7 @@ public class IITC_NavigationHelper extends ActionBarDrawerToggle implements OnIt
|
|||||||
|
|
||||||
public void onPrefChanged() {
|
public void onPrefChanged() {
|
||||||
mDesktopMode = mPrefs.getBoolean("pref_force_desktop", false);
|
mDesktopMode = mPrefs.getBoolean("pref_force_desktop", false);
|
||||||
updateActionBar();
|
updateViews();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void openRightDrawer() {
|
public void openRightDrawer() {
|
||||||
@ -321,37 +252,100 @@ public class IITC_NavigationHelper extends ActionBarDrawerToggle implements OnIt
|
|||||||
|
|
||||||
public void reset() {
|
public void reset() {
|
||||||
mPane = Pane.MAP;
|
mPane = Pane.MAP;
|
||||||
updateActionBar();
|
mNavigationAdapter.reset();
|
||||||
|
updateViews();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDebugMode(boolean enabled) {
|
public void setDebugMode(boolean enabled) {
|
||||||
mNavigationAdapter.remove(Pane.DEBUG); // avoid duplicates
|
mNavigationAdapter.reset();
|
||||||
if (enabled) {
|
|
||||||
mNavigationAdapter.add(Pane.DEBUG);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setHighlighter(String name) {
|
public void setHighlighter(String name) {
|
||||||
mHighlighter = name;
|
mHighlighter = name;
|
||||||
updateActionBar();
|
updateViews();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLoadingState(boolean isLoading) {
|
public void setLoadingState(boolean isLoading) {
|
||||||
mIsLoading = isLoading;
|
mIsLoading = isLoading;
|
||||||
updateActionBar();
|
updateViews();
|
||||||
}
|
|
||||||
|
|
||||||
public void switchTo(Pane pane) {
|
|
||||||
mPane = pane;
|
|
||||||
|
|
||||||
updateActionBar();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showActionBar() {
|
public void showActionBar() {
|
||||||
mActionBar.show();
|
mActionBar.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void hideActionBar() {
|
public void switchTo(Pane pane) {
|
||||||
mActionBar.hide();
|
mPane = pane;
|
||||||
|
|
||||||
|
updateViews();
|
||||||
|
}
|
||||||
|
|
||||||
|
private class NavigationAdapter extends ArrayAdapter<Pane> {
|
||||||
|
public NavigationAdapter() {
|
||||||
|
super(mIitc, R.layout.list_item_selectable);
|
||||||
|
|
||||||
|
reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public View getView(int position, View convertView, ViewGroup parent) {
|
||||||
|
TextView view = (TextView) super.getView(position, convertView, parent);
|
||||||
|
Pane item = getItem(position);
|
||||||
|
view.setText(item.label);
|
||||||
|
|
||||||
|
if (item.icon != 0) {
|
||||||
|
view.setCompoundDrawablesWithIntrinsicBounds(item.icon, 0, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
return view;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void reset() {
|
||||||
|
clear();
|
||||||
|
|
||||||
|
add(Pane.INFO);
|
||||||
|
add(Pane.FULL);
|
||||||
|
add(Pane.COMPACT);
|
||||||
|
add(Pane.PUBLIC);
|
||||||
|
add(Pane.FACTION);
|
||||||
|
|
||||||
|
if (mPrefs.getBoolean("pref_advanced_menu", false)) {
|
||||||
|
add(Pane.DEBUG);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Pane {
|
||||||
|
public static final Pane COMPACT = new Pane("compact", "Compact", R.drawable.collections_view_as_list_compact);
|
||||||
|
public static final Pane DEBUG = new Pane("debug", "Debug", R.drawable.ic_debug);
|
||||||
|
public static final Pane FACTION = new Pane("faction", "Faction", R.drawable.social_cc_bcc);
|
||||||
|
public static final Pane FULL = new Pane("full", "Full", R.drawable.collections_view_as_list);
|
||||||
|
public static final Pane INFO = new Pane("info", "Info", R.drawable.action_about);
|
||||||
|
public static final Pane MAP = new Pane("map", "IITC Mobile", R.drawable.location_map);
|
||||||
|
public static final Pane PUBLIC = new Pane("public", "Public", R.drawable.social_group);
|
||||||
|
|
||||||
|
private int icon;
|
||||||
|
public String label;
|
||||||
|
public String name;
|
||||||
|
|
||||||
|
public Pane(String name, String label, int icon) {
|
||||||
|
this.name = name;
|
||||||
|
this.label = label;
|
||||||
|
this.icon = icon;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (o == null) return false;
|
||||||
|
if (o.getClass() != getClass()) return false;
|
||||||
|
|
||||||
|
Pane pane = (Pane) o;
|
||||||
|
return name.equals(pane.name);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return name.hashCode();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user