Commits

Luke Plant committed 1037968

Added 'copy page address' menu item

Comments (0)

Files changed (3)

gen/net/learnscripture/webviewapp/R.java

     }
     public static final class id {
         public static final int contact_menuitem=0x7f080006;
+        public static final int copy_url_menuitem=0x7f080007;
         public static final int dashboard_menuitem=0x7f080003;
         public static final int fullscreen_content_controls=0x7f080000;
         public static final int preferences_menuitem=0x7f080005;

res/menu/main_menu.xml

     <item android:id="@+id/refresh_menuitem" android:title="Refresh"></item>
     <item android:id="@+id/preferences_menuitem" android:title="Preferences"></item>
     <item android:id="@+id/contact_menuitem" android:title="Contact"></item>
+    <item android:id="@+id/copy_url_menuitem" android:title="Copy page address"></item>
 </menu>

src/net/learnscripture/webviewapp/Dashboard.java

 import android.net.MailTo;
 import android.net.Uri;
 import android.os.Bundle;
+import android.text.ClipboardManager;
 import android.view.Menu;
 import android.view.MenuInflater;
 import android.view.MenuItem;
 import android.webkit.WebView;
 import android.webkit.WebViewClient;
 import android.widget.ProgressBar;
+import android.widget.Toast;
 
+@SuppressWarnings("deprecation")
 public class Dashboard extends Activity {
 
 	public String BASE_URL = "http://learnscripture.net/";
 			{
 				jsInterface.enablePreferencesMenu  = false;
 				jsInterface.modalIsVisible = false;
+				jsInterface.urlForSharing = null;
 				progressBar.setVisibility(View.VISIBLE);
 			}
 
 		case R.id.contact_menuitem:
 			getEngine().loadUrl(CONTACT_URL);
 			return true;
+		case R.id.copy_url_menuitem:
+			final String url = (jsInterface.urlForSharing != null
+								? jsInterface.urlForSharing
+								: getEngine().getUrl());
+			((ClipboardManager) getSystemService(CLIPBOARD_SERVICE)).setText(url);
+			Toast.makeText(getApplicationContext(), "Page address copied", Toast.LENGTH_SHORT).show();
 		default:
 			return super.onOptionsItemSelected(item);
 		}
 		}
 	}
 
-	// The methods of JavascriptInterface are called from javascript
+	// The methods of JavascriptInterface are called from javascript.
+	// The attributes are accessed from the Dashboard class.
+	// This is deliberately a dumb container class to stop possible
+	// security issues of javascript controlling Java app.
 	final class JavascriptInterface {
 		public boolean enablePreferencesMenu = false;
 		public boolean modalIsVisible = false;
 		public int versionCode = 0;
+		public String urlForSharing = null;
 
 		public void setEnablePreferencesMenu() {
 			enablePreferencesMenu = true;
 		public int getVersionCode() {
 			return versionCode;
 		}
+		
+		public void setUrlForSharing(String url) {
+			urlForSharing = url;
+		}
 	}
 
 }