]> gitweb.stoutner.com Git - PrivacyBrowserAndroid.git/commitdiff
Move favoriteIcon, urlTextBox, and progressBar to a custom view in the app bar.
authorSoren Stoutner <soren@stoutner.com>
Thu, 29 Oct 2015 23:09:50 +0000 (16:09 -0700)
committerSoren Stoutner <soren@stoutner.com>
Thu, 29 Oct 2015 23:09:50 +0000 (16:09 -0700)
app/src/main/java/com/stoutner/privacybrowser/Webview.java
app/src/main/res/layout/activity_webview.xml
app/src/main/res/layout/app_bar.xml [new file with mode: 0644]
app/src/main/res/menu/menu_webview.xml
app/src/main/res/values/strings.xml

index fb72f87ce2e414d1ad55f8238c97f0560d7486a6..7e87fdfdde415fd4de5765fd526c4988b3cd0fa5 100644 (file)
@@ -15,6 +15,7 @@ import android.view.Menu;
 import android.view.MenuItem;
 import android.view.View;
 import android.view.ViewTreeObserver;
+import android.view.Window;
 import android.view.inputmethod.InputMethodManager;
 import android.webkit.WebChromeClient;
 import android.webkit.WebView;
@@ -45,17 +46,24 @@ public class Webview extends AppCompatActivity {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.activity_webview);
 
-        urlTextBox = (EditText) findViewById(R.id.urlTextBox);
         swipeToRefresh = (SwipeRefreshLayout) findViewById(R.id.swipeRefreshLayoutContainer);
         mainWebView = (WebView) findViewById(R.id.mainWebView);
-        progressBar = (ProgressBar) findViewById(R.id.progressBar);
-        favoriteIcon = (ImageView) findViewById(R.id.favoriteIcon);
 
-        // Remove the title from the action bar.
         final ActionBar actionBar = getSupportActionBar();
         if (actionBar != null) {
+            // Remove the title from the action bar.
             actionBar.setDisplayShowTitleEnabled(false);
-            // actionBar.setHideOnContentScrollEnabled(true);
+
+            // Add the custom app_bar layout, which shows the favoriteIcon, urlTextBar, and progressBar.
+            actionBar.setCustomView(R.layout.app_bar);
+            actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
+
+            // Initialize the variables for favoriteIcon, urlTextBox, and progressBar
+            favoriteIcon = (ImageView) actionBar.getCustomView().findViewById(R.id.favoriteIcon);
+            urlTextBox = (EditText) actionBar.getCustomView().findViewById(R.id.urlTextBox);
+            progressBar = (ProgressBar) actionBar.getCustomView().findViewById(R.id.progressBar);
+
+            //actionBar.setHideOnContentScrollEnabled(true);
         }
 
         // Implement swipe down to refresh.
index 5613cef023a5c805024daf0042d7061372fb1275..28c0552b1b217053a1615049162cfe319e096097 100644 (file)
@@ -1,69 +1,15 @@
+<!-- SwipeRefreshLayout allows the user to swipe down to refresh. -->
 <android.support.v4.widget.SwipeRefreshLayout
     android:id="@+id/swipeRefreshLayoutContainer"
     xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
     android:layout_height="match_parent">
-    <!-- SwipeRefreshLayout allows the user to swipe down to refresh. -->
 
-    <RelativeLayout
-        android:id="@+id/relativeLayoutContainer"
-        xmlns:android="http://schemas.android.com/apk/res/android"
-        xmlns:tools="http://schemas.android.com/tools"
+    <WebView
+        android:id="@+id/mainWebView"
         android:layout_width="match_parent"
         android:layout_height="match_parent"
-        tools:context=".Webview" >
-
-        <!-- FrameLayout lets the ProgressBar float on top of urlTextBox. -->
-        <FrameLayout
-            android:id="@+id/addressBarFrameLayout"
-            android:layout_width="match_parent"
-            android:layout_height="wrap_content">
-
-            <LinearLayout
-                android:id="@+id/addressBarLinearLayout"
-                android:layout_width="match_parent"
-                android:layout_height="wrap_content"
-                android:orientation="horizontal">
-
-                <ImageView
-                    android:id="@+id/favoriteIcon"
-                    android:src="@drawable/ic_language_black_24dp"
-                    android:layout_width="wrap_content"
-                    android:layout_height="wrap_content"
-                    android:layout_gravity="center" />
-
-                <!-- android:inputType="textUri" sets the keyboard to have a go arrow. -->
-                <!-- android:layout_weight="1" makes urlTextBox take up all the remaining space. -->
-                <EditText
-                    android:id="@+id/urlTextBox"
-                    android:layout_width="0dp"
-                    android:layout_weight="1"
-                    android:layout_height="wrap_content"
-                    android:inputType="textUri"
-                    android:imeOptions="actionGo" />
-            </LinearLayout>
-
-            <!-- android:max changes the maximum ProgressBar value from 10000 to 100 to match progress percentage. -->
-            <ProgressBar
-                android:id="@+id/progressBar"
-                style="?android:attr/progressBarStyleHorizontal"
-                android:layout_width="fill_parent"
-                android:layout_height="7dp"
-                android:layout_gravity="bottom"
-                android:max="100"
-                android:progressTint="#FF0097FF"
-                android:progressBackgroundTint="#FFFFFFFF"
-                android:visibility="gone" />
-        </FrameLayout>
-
-        <WebView
-            android:id="@+id/mainWebView"
-            android:layout_width="match_parent"
-            android:layout_height="match_parent"
-            android:layout_below="@id/addressBarFrameLayout"
-            android:focusable="true"
-            android:focusableInTouchMode="true" />
-
-    </RelativeLayout>
+        android:focusable="true"
+        android:focusableInTouchMode="true" />
 
 </android.support.v4.widget.SwipeRefreshLayout>
diff --git a/app/src/main/res/layout/app_bar.xml b/app/src/main/res/layout/app_bar.xml
new file mode 100644 (file)
index 0000000..ece3f5d
--- /dev/null
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<!-- FrameLayout lets the ProgressBar float on top of urlTextBox. -->
+<FrameLayout
+    android:id="@+id/addressBarFrameLayout"
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="wrap_content">
+
+    <LinearLayout
+        android:id="@+id/addressBarLinearLayout"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:orientation="horizontal">
+
+        <ImageView
+            android:id="@+id/favoriteIcon"
+            android:src="@drawable/ic_language_black_24dp"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_gravity="center"
+            android:contentDescription="@string/favorite_icon"/>
+
+        <!-- android:inputType="textUri" sets the keyboard to have a go arrow. -->
+        <!-- android:layout_weight="1" makes urlTextBox take up all the remaining space. -->
+        <EditText
+            android:id="@+id/urlTextBox"
+            android:layout_width="0dp"
+            android:layout_weight="1"
+            android:layout_height="wrap_content"
+            android:inputType="textUri"
+            android:imeOptions="actionGo" />
+    </LinearLayout>
+
+    <!-- android:max changes the maximum ProgressBar value from 10000 to 100 to match progress percentage. -->
+    <ProgressBar
+        android:id="@+id/progressBar"
+        style="?android:attr/progressBarStyleHorizontal"
+        android:layout_width="fill_parent"
+        android:layout_height="7dp"
+        android:layout_gravity="bottom"
+        android:max="100"
+        android:progressTint="#FF0097FF"
+        android:progressBackgroundTint="#FFFFFFFF"
+        android:visibility="gone" />
+</FrameLayout>
\ No newline at end of file
index 2a8923dcdfc3e3326f40300912d4fd2842ad96d1..fddbcc68ecb41883c45eecd4e1aabcd6352d7b6c 100644 (file)
@@ -9,19 +9,19 @@
         android:title="@string/home"
         android:orderInCategory="100"
         android:icon="@drawable/ic_home_black_24dp"
-        app:showAsAction="ifRoom" />
+        app:showAsAction="never" />
 
     <item
         android:id="@+id/back"
         android:title="@string/back"
         android:orderInCategory="200"
         android:icon="@drawable/ic_back"
-        app:showAsAction="ifRoom" />
+        app:showAsAction="never" />
 
     <item
         android:id="@+id/forward"
         android:title="@string/forward"
         android:orderInCategory="300"
         android:icon="@drawable/ic_forward"
-        app:showAsAction="ifRoom" />
+        app:showAsAction="never" />
 </menu>
index c51a4a269dc19c6d9360b52e8d0c6854aab220b4..a87e46d45f60305efc16b590af8537fb18da3e04 100644 (file)
@@ -1,13 +1,13 @@
 <resources>
-    // Activities.
+    <!-- Activities. -->
     <string name="privacy_browser">Privacy Browser</string>
 
-    // Menu.
+    <!-- Custom App Bar. -->
+    <string name="favorite_icon">Favorite Icon</string>
+
+    <!-- Menu. -->
     <string name="home">Home</string>
     <string name="back">Back</string>
     <string name="forward">Forward</string>
 
-    // Layout.
-    <string name="go_button">Go</string>
-
 </resources>