Commits

Luke Plant committed db715d9

Made 'preferences' menu item only available when a LearnScripture page is loaded

  • Participants
  • Parent commits 0acb7b1

Comments (0)

Files changed (1)

File src/net/learnscripture/webviewapp/Dashboard.java

 	public String BASE_URL = "http://learnscripture.net/";
 	public String DASHBOARD_URL = BASE_URL + "dashboard/";
 
+	public boolean enablePreferencesMenu = false;
+
 	@SuppressLint("SetJavaScriptEnabled") @Override
 	protected void onCreate(Bundle savedInstanceState) {
 		super.onCreate(savedInstanceState);
 		engine.setWebViewClient(new FixedWebViewClient() {
 			public void onPageStarted(WebView view, String url, Bitmap favicon)
 			{
+				enablePreferencesMenu  = false;
 				progressBar.setVisibility(View.VISIBLE);
 			}
 
 			}
 		});
 		engine.getSettings().setJavaScriptEnabled(true);
+		engine.addJavascriptInterface(new IJavascriptHandler(this), "androidlearnscripture");
 		engine.loadUrl(BASE_URL);
 	}
 
 	}
 
 	@Override
+	public boolean onPrepareOptionsMenu(Menu menu) {
+		MenuItem prefs = menu.findItem(R.id.preferences_menuitem);
+		if (prefs != null) {
+			prefs.setVisible(enablePreferencesMenu);
+		}
+		super.onPrepareOptionsMenu(menu);
+		return true;
+	}
+
+	@Override
 	public boolean onOptionsItemSelected(MenuItem item) {
 		// Handle item selection
 		switch (item.getItemId()) {
 		}
 	}
 
+	final class IJavascriptHandler {
+		private Dashboard activity;
+
+		IJavascriptHandler(Dashboard activity) {
+			this.activity = activity;
+		}
+
+		public void setEnablePreferencesMenu() {
+			// this is called from JS with passed value
+			activity.enablePreferencesMenu = true;
+		}
+	}
+
 }