Remove copy and paste menu items (they are now handled by SupportActionBar) and creat...
authorSoren Stoutner <soren@stoutner.com>
Sat, 6 Feb 2016 18:37:26 +0000 (11:37 -0700)
committerSoren Stoutner <soren@stoutner.com>
Sat, 6 Feb 2016 18:37:26 +0000 (11:37 -0700)
app/src/main/java/com/stoutner/privacybrowser/MainWebView.java
app/src/main/res/layout/activity_webview.xml
app/src/main/res/layout/url_bar.xml
app/src/main/res/menu/menu_webview.xml
app/src/main/res/values/strings.xml

index 4ca7320a77892bc6c4b686142d24cec4f21ee739..daaa58a809d384b4fb01ae7414d6d38bc271a376 100644 (file)
@@ -398,13 +398,10 @@ public class MainWebView extends AppCompatActivity implements CreateHomeScreenSh
     public boolean onOptionsItemSelected(MenuItem menuItem) {
         int menuItemId = menuItem.getItemId();
 
-        // Some options need to access the clipboard.
-        ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
-
         // Some options need to update the drawable for toggleJavaScript.
         MenuItem toggleJavaScript = mainMenu.findItem(R.id.toggleJavaScript);
 
-        // Sets the commands that relate to the menu entries.
+        // Set the commands that relate to the menu entries.
         switch (menuItemId) {
             case R.id.toggleJavaScript:
                 if (javaScriptEnabled) {
@@ -532,6 +529,24 @@ public class MainWebView extends AppCompatActivity implements CreateHomeScreenSh
                 Toast.makeText(getApplicationContext(), "Cookies deleted", Toast.LENGTH_SHORT).show();
                 return true;
 
+            case R.id.addToHomescreen:
+                // Show the CreateHomeScreenShortcut AlertDialog and name this instance createShortcut.
+                AppCompatDialogFragment shortcutDialog = new CreateHomeScreenShortcut();
+                shortcutDialog.show(getSupportFragmentManager(), "createShortcut");
+
+                //Everything else will be handled by CreateHomeScreenShortcut and the associated listeners below.
+                return true;
+
+            case R.id.downloads:
+                // Launch the system Download Manager.
+                Intent downloadManangerIntent = new Intent(DownloadManager.ACTION_VIEW_DOWNLOADS);
+
+                // Launch as a new task so that Download Manager and Privacy Browser show as separate windows in the recent tasks list.
+                downloadManangerIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+
+                startActivity(downloadManangerIntent);
+                return true;
+
             case R.id.home:
                 mainWebView.loadUrl(homepage);
                 return true;
@@ -548,21 +563,7 @@ public class MainWebView extends AppCompatActivity implements CreateHomeScreenSh
                 mainWebView.goForward();
                 return true;
 
-            case R.id.copyURL:
-                clipboard.setPrimaryClip(ClipData.newPlainText("URL", urlTextBox.getText()));
-                return true;
-
-            case R.id.pasteURL:
-                ClipData.Item clipboardData = clipboard.getPrimaryClip().getItemAt(0);
-                urlTextBox.setText(clipboardData.coerceToText(this));
-                    try {
-                        loadUrlFromTextBox();
-                    } catch (UnsupportedEncodingException e) {
-                        e.printStackTrace();
-                    }
-                return true;
-
-            case R.id.shareURL:
+            case R.id.share:
                 Intent shareIntent = new Intent();
                 shareIntent.setAction(Intent.ACTION_SEND);
                 shareIntent.putExtra(Intent.EXTRA_TEXT, urlTextBox.getText().toString());
@@ -570,24 +571,6 @@ public class MainWebView extends AppCompatActivity implements CreateHomeScreenSh
                 startActivity(Intent.createChooser(shareIntent, "Share URL"));
                 return true;
 
-            case R.id.addToHomescreen:
-                // Show the CreateHomeScreenShortcut AlertDialog and name this instance createShortcut.
-                AppCompatDialogFragment shortcutDialog = new CreateHomeScreenShortcut();
-                shortcutDialog.show(getSupportFragmentManager(), "createShortcut");
-
-                //Everything else will be handled by CreateHomeScreenShortcut and the associated listeners below.
-                return true;
-
-            case R.id.downloads:
-                // Launch the system Download Manager.
-                Intent downloadManangerIntent = new Intent(DownloadManager.ACTION_VIEW_DOWNLOADS);
-
-                // Launch as a new task so that Download Manager and Privacy Browser show as separate windows in the recent tasks list.
-                downloadManangerIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
-
-                startActivity(downloadManangerIntent);
-                return true;
-
             case R.id.settings:
                 // Start the Settings activity.
                 Intent intent = new Intent(this, Settings.class);
index 93cab6545d4c3d507e0009acad00bd703d4279d7..f50c39956a040b144652346e8038e0b82028b638 100644 (file)
   You should have received a copy of the GNU General Public License
   along with Privacy Browser.  If not, see <http://www.gnu.org/licenses/>. -->
 
+<!-- Setting the layout root to be focusableInTouchMode prevents urlTextBox from stealing focus on launch and opening the keyboard. -->
 <RelativeLayout
     android:id="@+id/rootRelativeLayout"
     xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:app="http://schemas.android.com/apk/res-auto"
     android:layout_width="match_parent"
-    android:layout_height="match_parent" >
+    android:layout_height="match_parent"
+    android:focusableInTouchMode="true" >
 
     <android.support.v7.widget.Toolbar
         android:id="@+id/appBar"
index 8ff3f3ed17bb3e8c79a2162027f6410a0b97a78d..e912cf2b62178e680bdf967e5fcf15541d7bc652 100644 (file)
 
         <!-- android:imeOptions="actionGo" sets the keyboard to have a "go" key instead of a "new line" key. -->
         <!-- android:inputType="textUri" disables spell check in the EditText and changes the "go" key from a check mark to an arrow. -->
-        <!-- android:layout_weight="1" makes urlTextBox take up all the remaining space. -->
+        <!-- For some reason, android:layout_weight="1" doesdn't makes urlTextBox take up all the remaining space when it is inside a SupportActionBar.
+            layout_width="2000" is less elegant, but it does the trick. -->
         <EditText
             android:id="@+id/urlTextBox"
-            android:layout_width="0dp"
-            android:layout_weight="1"
+            android:layout_width="2000dp"
             android:layout_height="wrap_content"
             android:imeOptions="actionGo"
             android:inputType="textUri" />
index 29a57e557401a62d506be2cf9d8b9ab14828c853..92bd7c2fe0aeefe26830174e548eb87318c8ffa1 100644 (file)
     <item
         android:id="@+id/toggleJavaScript"
         android:title="@string/javascript"
-        android:orderInCategory="1"
+        android:orderInCategory="10"
         app:showAsAction="always" />
 
     <item
         android:id="@+id/toggleDomStorage"
         android:title="@string/dom_storage"
-        android:orderInCategory="2"
+        android:orderInCategory="20"
         android:checkable="true"
         app:showAsAction="never" />
 
@@ -41,7 +41,7 @@
     <item
         android:id="@+id/toggleSaveFormData"
         android:title="@string/saveFormData"
-        android:orderInCategory="3"
+        android:orderInCategory="30"
         android:checkable="true"
         app:showAsAction="never" />
         -->
     <item
         android:id="@+id/toggleCookies"
         android:title="@string/cookies"
-        android:orderInCategory="4"
+        android:orderInCategory="40"
         android:checkable="true"
         app:showAsAction="never" />
 
     <item
         android:id="@+id/clearDomStorage"
         android:title="@string/clear_dom_storage"
-        android:orderInCategory="5"
+        android:orderInCategory="50"
         app:showAsAction="never" />
 
     <item
         android:id="@+id/clearCookies"
         android:title="@string/clear_cookies"
-        android:orderInCategory="6"
-        app:showAsAction="never" />
-
-    <item
-        android:id="@+id/home"
-        android:title="@string/home"
-        android:orderInCategory="10"
-        app:showAsAction="never" />
-
-    <item
-        android:id="@+id/refresh"
-        android:title="@string/refresh"
-        android:orderInCategory="20"
-        app:showAsAction="never" />
-
-    <item
-        android:id="@+id/back"
-        android:title="@string/back"
-        android:orderInCategory="30"
-        app:showAsAction="never" />
-
-    <item
-        android:id="@+id/forward"
-        android:title="@string/forward"
-        android:orderInCategory="40"
-        app:showAsAction="never" />
-
-    <!-- tools:targetApi="11" is required because copy and paste was not available on earlier version of Android. -->
-    <item
-        android:id="@+id/copyURL"
-        android:title="@string/copy_url"
-        android:orderInCategory="50"
-        tools:targetApi="11"
-        app:showAsAction="never" />
-
-    <!-- tools:targetApi="11" is required because copy and paste was not available on earlier version of Android. -->
-    <item
-        android:id="@+id/pasteURL"
-        android:title="@string/paste_url"
         android:orderInCategory="60"
-        tools:targetApi="11"
         app:showAsAction="never" />
 
     <item
-        android:id="@+id/shareURL"
-        android:title="@string/share_url"
+        android:id="@+id/addToHomescreen"
+        android:title="@string/add_to_home_screen"
         android:orderInCategory="70"
         app:showAsAction="never" />
 
     <item
-        android:id="@+id/addToHomescreen"
-        android:title="@string/add_to_home_screen"
+        android:id="@+id/downloads"
+        android:title="@string/downloads"
         android:orderInCategory="80"
         app:showAsAction="never" />
 
     <item
-        android:id="@+id/downloads"
-        android:title="@string/downloads"
+        android:id="@+id/navigation"
+        android:title="@string/navigation"
         android:orderInCategory="90"
+        app:showAsAction="never" >
+        <menu>
+            <item
+                android:id="@+id/home"
+                android:title="@string/home"
+                android:orderInCategory="91"
+                app:showAsAction="never" />
+
+            <item
+                android:id="@+id/refresh"
+                android:title="@string/refresh"
+                android:orderInCategory="92"
+                app:showAsAction="never" />
+
+            <item
+                android:id="@+id/back"
+                android:title="@string/back"
+                android:orderInCategory="93"
+                app:showAsAction="never" />
+
+            <item
+                android:id="@+id/forward"
+                android:title="@string/forward"
+                android:orderInCategory="94"
+                app:showAsAction="never" />
+        </menu>
+    </item>
+
+    <item
+        android:id="@+id/share"
+        android:title="@string/share"
+        android:orderInCategory="100"
         app:showAsAction="never" />
 
     <item
         android:id="@+id/settings"
         android:title="@string/settings"
-        android:orderInCategory="100"
+        android:orderInCategory="110"
         app:showAsAction="never" />
 
     <item
         android:id="@+id/about"
         android:title="@string/about"
-        android:orderInCategory="110"
+        android:orderInCategory="120"
         app:showAsAction="never" />
 
     <item
         android:id="@+id/clearAndExit"
         android:title="@string/clear_and_exit"
-        android:orderInCategory="120"
+        android:orderInCategory="130"
         app:showAsAction="never" />
 </menu>
index e6d9c2fdfdf2a097d7d27f43c2db2541c731652d..ea122f1e05c7ee9f84dbf8e429247637be696ea6 100644 (file)
     <string name="cookies">Cookies</string>
     <string name="clear_dom_storage">Clear DOM Storage</string>
     <string name="clear_cookies">Clear Cookies</string>
+    <string name="add_to_home_screen">Add to Home Screen</string>
+    <string name="downloads">Downloads</string>
+    <string name="navigation">Navigation</string>
     <string name="home">Home</string>
     <string name="refresh">Refresh</string>
     <string name="back">Back</string>
     <string name="forward">Forward</string>
-    <string name="copy_url">Copy URL</string>
-    <string name="paste_url">Paste URL</string>
-    <string name="share_url">Share URL</string>
-    <string name="add_to_home_screen">Add to Home Screen</string>
-    <string name="downloads">Downloads</string>
+    <string name="share">Share</string>
     <string name="settings">Settings</string>
     <string name="about">About</string>
     <string name="clear_and_exit">Clear and Exit</string>