From: Soren Stoutner Date: Sat, 6 Feb 2016 05:01:57 +0000 (-0700) Subject: Refactor the App Bar. X-Git-Tag: v1.0~7 X-Git-Url: https://gitweb.stoutner.com/?a=commitdiff_plain;h=4ba6de8b83fee7e5259ff516e63c3ce785bee843;p=PrivacyBrowserAndroid.git Refactor the App Bar. --- diff --git a/app/src/main/java/com/stoutner/privacybrowser/MainWebView.java b/app/src/main/java/com/stoutner/privacybrowser/MainWebView.java index b0176a3f..4ca7320a 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/MainWebView.java +++ b/app/src/main/java/com/stoutner/privacybrowser/MainWebView.java @@ -37,6 +37,7 @@ import android.support.v4.app.DialogFragment; import android.support.v7.app.ActionBar; import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatDialogFragment; +import android.support.v7.widget.Toolbar; import android.util.Patterns; import android.view.KeyEvent; import android.view.Menu; @@ -59,6 +60,7 @@ import java.net.MalformedURLException; import java.net.URL; import java.net.URLEncoder; +// We need to use AppCompatActivity from android.support.v7.app.AppCompatActivity to have access to the SupportActionBar until the minimum API is >= 21. public class MainWebView extends AppCompatActivity implements CreateHomeScreenShortcut.CreateHomeScreenSchortcutListener { // favoriteIcon is public static so it can be accessed from CreateHomeScreenShortcut. public static Bitmap favoriteIcon; @@ -95,23 +97,26 @@ public class MainWebView extends AppCompatActivity implements CreateHomeScreenSh protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_webview); + Toolbar toolbar = (Toolbar) findViewById(R.id.appBar); + setSupportActionBar(toolbar); final FrameLayout fullScreenVideoFrameLayout = (FrameLayout) findViewById(R.id.fullScreenVideoFrameLayout); final Activity mainWebViewActivity = this; - final ActionBar actionBar = getSupportActionBar(); + // We need to use the SupportActionBar from android.support.v7.app.ActionBar until the minimum API is >= 21. + final ActionBar appBar = getSupportActionBar(); mainWebView = (WebView) findViewById(R.id.mainWebView); - if (actionBar != null) { - // Remove the title from the action bar. - actionBar.setDisplayShowTitleEnabled(false); + if (appBar != null) { + // Remove the title from the app bar. + appBar.setDisplayShowTitleEnabled(false); - // 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); + // Add the custom url_bar layout, which shows the favoriteIcon, urlTextBar, and progressBar. + appBar.setCustomView(R.layout.url_bar); + appBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM); // Set the "go" button on the keyboard to load the URL in urlTextBox. - urlTextBox = (EditText) actionBar.getCustomView().findViewById(R.id.urlTextBox); + urlTextBox = (EditText) appBar.getCustomView().findViewById(R.id.urlTextBox); urlTextBox.setOnKeyListener(new View.OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { // If the event is a key-down event on the "enter" button, load the URL. @@ -164,9 +169,9 @@ public class MainWebView extends AppCompatActivity implements CreateHomeScreenSh // Update the progress bar when a page is loading. @Override public void onProgressChanged(WebView view, int progress) { - // Make sure that actionBar is not null. - if (actionBar != null) { - ProgressBar progressBar = (ProgressBar) actionBar.getCustomView().findViewById(R.id.progressBar); + // Make sure that appBar is not null. + if (appBar != null) { + ProgressBar progressBar = (ProgressBar) appBar.getCustomView().findViewById(R.id.progressBar); progressBar.setProgress(progress); if (progress < 100) { progressBar.setVisibility(View.VISIBLE); @@ -182,9 +187,9 @@ public class MainWebView extends AppCompatActivity implements CreateHomeScreenSh // Save a copy of the favorite icon for use if a shortcut is added to the home screen. favoriteIcon = icon; - // Place the favorite icon in the actionBar if it is not null. - if (actionBar != null) { - ImageView imageViewFavoriteIcon = (ImageView) actionBar.getCustomView().findViewById(R.id.favoriteIcon); + // Place the favorite icon in the appBar if it is not null. + if (appBar != null) { + ImageView imageViewFavoriteIcon = (ImageView) appBar.getCustomView().findViewById(R.id.favoriteIcon); imageViewFavoriteIcon.setImageBitmap(Bitmap.createScaledBitmap(icon, 64, 64, true)); } } @@ -192,8 +197,8 @@ public class MainWebView extends AppCompatActivity implements CreateHomeScreenSh // Enter full screen video @Override public void onShowCustomView(View view, CustomViewCallback callback) { - if (actionBar != null) { - actionBar.hide(); + if (appBar != null) { + appBar.hide(); } fullScreenVideoFrameLayout.addView(view); @@ -224,8 +229,8 @@ public class MainWebView extends AppCompatActivity implements CreateHomeScreenSh // Exit full screen video public void onHideCustomView() { - if (actionBar != null) { - actionBar.show(); + if (appBar != null) { + appBar.show(); } mainWebView.setVisibility(View.VISIBLE); diff --git a/app/src/main/res/layout/activity_webview.xml b/app/src/main/res/layout/activity_webview.xml index 7b091e5d..93cab654 100644 --- a/app/src/main/res/layout/activity_webview.xml +++ b/app/src/main/res/layout/activity_webview.xml @@ -1,7 +1,7 @@ - - + android:layout_height="match_parent" > + + + + + + + diff --git a/app/src/main/res/layout/app_bar.xml b/app/src/main/res/layout/app_bar.xml deleted file mode 100644 index 12d4d59b..00000000 --- a/app/src/main/res/layout/app_bar.xml +++ /dev/null @@ -1,67 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/url_bar.xml b/app/src/main/res/layout/url_bar.xml new file mode 100644 index 00000000..8ff3f3ed --- /dev/null +++ b/app/src/main/res/layout/url_bar.xml @@ -0,0 +1,67 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index e33adcc1..8fe826ff 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -20,7 +20,10 @@ + #FF000000 + #FF0091EA #FF64DD17 #FFD50000 + #FFFFFFFF #FFFFD600 \ No newline at end of file diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index f46fa1c3..2c1e1c94 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -20,9 +20,9 @@ - -