Show portal highlighters in action bar

This commit is contained in:
fkloft 2013-09-18 16:43:12 +02:00
parent 6290ef56aa
commit daaef1575e
3 changed files with 104 additions and 13 deletions

View File

@ -11,14 +11,26 @@ window.addPortalHighlighter = function(name, callback) {
_highlighters = {};
}
_highlighters[name] = callback;
if (typeof android !== 'undefined' && android && android.addPortalHighlighter)
android.addPortalHighlighter(name);
if(localStorage.portal_highlighter === undefined) {
_current_highlighter = name;
if (typeof android !== 'undefined' && android && android.setActiveHighlighter)
android.setActiveHighlighter(name);
localStorage.portal_highlighter = name;
}
portalHighlighterControl();
}
window.portalHighlighterControl = function() {
if (typeof android !== 'undefined' && android && android.addPortalHighlighter) {
$('#portal_highlight_select').remove();
return;
}
if(_highlighters !== null) {
if($('#portal_highlight_select').length === 0) {
$("body").append("<select id='portal_highlight_select'></select>");
@ -46,6 +58,8 @@ window.portalHighlighterControl = function() {
window.changePortalHighlights = function(name) {
_current_highlighter = name;
if (typeof android !== 'undefined' && android && android.setActiveHighlighter)
android.setActiveHighlighter(name);
resetHighlightedPortals();
localStorage.portal_highlighter = name;
}

View File

@ -1,11 +1,13 @@
package com.cradle.iitc_mobile;
import android.app.ActionBar;
import android.app.ActionBar.OnNavigationListener;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.widget.ArrayAdapter;
import android.widget.Toast;
public class ActionBarHelper {
public class ActionBarHelper implements OnNavigationListener {
/*
* Show/hide the up arrow on the left end
* getActionBar().setDisplayHomeAsUpEnabled(enabled);
@ -20,10 +22,31 @@ public class ActionBarHelper {
* getActionBar().setHomeButtonEnabled(enabled);
*/
private ActionBar mActionBar;
private IITC_Mobile mIitc;
private SharedPreferences mPrefs;
private class HighlighterAdapter extends ArrayAdapter<String> {
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);
}
@Override
public void clear() {
super.clear();
add("No Highlights");// Probably must be the same as window._no_highlighter
}
}
private IITC_Mobile mIitc;
private ActionBar mActionBar;
private SharedPreferences mPrefs;
private HighlighterAdapter mHighlighters;
private String mActiveHighlighter = null;
private boolean mDesktopMode = false;
private boolean mFullscreen = false;
private boolean mHideInFullscreen = false;
@ -33,58 +56,90 @@ public class ActionBarHelper {
mIitc = activity;
mActionBar = bar;
mPrefs = PreferenceManager.getDefaultSharedPreferences(activity);
mHighlighters = new HighlighterAdapter();
mActionBar.setDisplayShowHomeEnabled(true); // show icon
mActionBar.setListNavigationCallbacks(mHighlighters, this);
onPrefChanged(); // also calls updateActionBar()
}
private void updateActionBar() {
boolean showHighlighter = true;
if (mDesktopMode) {
mActionBar.setDisplayHomeAsUpEnabled(false); // Hide "up" indicator
mActionBar.setHomeButtonEnabled(false); // Make icon unclickable
mActionBar.setTitle(mIitc.getString(R.string.app_name));
} else {
if (mPane != android.R.id.home)
{
if (mPane != android.R.id.home) {
mActionBar.setDisplayHomeAsUpEnabled(true); // Show "up" indicator
mActionBar.setHomeButtonEnabled(true);// Make icon clickable
showHighlighter = false;
}
else
{
else {
mActionBar.setDisplayHomeAsUpEnabled(false); // Hide "up" indicator
mActionBar.setHomeButtonEnabled(false); // Make icon unclickable
}
mActionBar.setTitle(IITC_Mobile.PANE_TITLES.get(mPane, mIitc.getString(R.string.app_name)));
}
if (mHighlighters.getCount() < 2) // there should always be "No Highlights"
showHighlighter = false;
if (showHighlighter) {
mActionBar.setDisplayShowTitleEnabled(false); // Hide title
mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
} else {
mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
mActionBar.setDisplayShowTitleEnabled(true); // Show title
}
if (mFullscreen && mHideInFullscreen)
mActionBar.hide();
else
mActionBar.show();
}
@Deprecated
public void goHome() {
switchTo(android.R.id.home);
public void addPortalHighlighter(String name) {
mHighlighters.add(name);
if (name.equals(mActiveHighlighter))
setActiveHighlighter(name);
updateActionBar();
}
public boolean hideInFullscreen() {
return mHideInFullscreen;
}
@Override
public boolean onNavigationItemSelected(int position, long itemId) {
String name = mHighlighters.getItem(position);
mIitc.getWebView().loadUrl("javascript: window.changePortalHighlights('" + name + "')");
return true;
}
public void onPrefChanged() {
mDesktopMode = mPrefs.getBoolean("pref_force_desktop", false);
mHideInFullscreen = mPrefs.getBoolean("pref_fullscreen_actionbar", false);
updateActionBar();
}
public void reset()
{
public void reset() {
mHighlighters.clear();
mPane = android.R.id.home;
updateActionBar();
}
public void setActiveHighlighter(String name) {
int position = mHighlighters.getPosition(name);
if (position >= 0)
mActionBar.setSelectedNavigationItem(position);
mActiveHighlighter = name;
}
public void setFullscreen(boolean fullscreen) {
mFullscreen = fullscreen;
if (mFullscreen && mHideInFullscreen) {

View File

@ -230,6 +230,28 @@ public class IITC_JSInterface {
showMultiSelection();
}
@JavascriptInterface
public void addPortalHighlighter(final String name) {
final IITC_Mobile iitc = ((IITC_Mobile) mContext);
iitc.runOnUiThread(new Runnable() {
@Override
public void run() {
iitc.getActionBarHelper().addPortalHighlighter(name);
}
});
}
@JavascriptInterface
public void setActiveHighlighter(final String name) {
final IITC_Mobile iitc = ((IITC_Mobile) mContext);
iitc.runOnUiThread(new Runnable() {
@Override
public void run() {
iitc.getActionBarHelper().setActiveHighlighter(name);
}
});
}
// show all overlay layers in a multi selection list dialog
private void showMultiSelection() {
// build the layer chooser dialog