X-Git-Url: https://gitweb.stoutner.com/?p=PrivacyBrowserAndroid.git;a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacybrowser%2Factivities%2FMainWebViewActivity.java;h=0a61ce0a7298460c21b9a6dd334774f6dc24ece5;hp=b54888e2b03fe8521a752d578698ccb1da8e9d89;hb=df8b520d10c3fa31b603ff7c50670ab1f0728d2f;hpb=fa5bfd542337d3aff87271af18272768312e1306 diff --git a/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java b/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java index b54888e2..0a61ce0a 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java +++ b/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java @@ -447,6 +447,11 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook private ForegroundColorSpan initialGrayColorSpan; private ForegroundColorSpan finalGrayColorSpan; + // The drawer header padding variables are used in `onCreate()` and `onConfigurationChanged()`. + private int drawerHeaderPaddingLeftAndRight; + private int drawerHeaderPaddingTop; + private int drawerHeaderPaddingBottom; + // `sslErrorHandler` is used in `onCreate()`, `onSslErrorCancel()`, and `onSslErrorProceed`. private SslErrorHandler sslErrorHandler; @@ -912,11 +917,11 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook float screenDensity = resources.getDisplayMetrics().density; // Calculate the drawer header padding. This is used to move the text in the drawer headers below any cutouts. - int drawerHeaderPaddingLeftAndRight = (int) (15 * screenDensity); - int drawerHeaderPaddingTop = statusBarPixelSize + (int) (4 * screenDensity); - int drawerHeaderPaddingBottom = (int) (8 * screenDensity); + drawerHeaderPaddingLeftAndRight = (int) (15 * screenDensity); + drawerHeaderPaddingTop = statusBarPixelSize + (int) (4 * screenDensity); + drawerHeaderPaddingBottom = (int) (8 * screenDensity); - // The drawer listener is used to update the navigation menu. + // The drawer listener is used to update the navigation menu.` drawerLayout.addDrawerListener(new DrawerLayout.DrawerListener() { @Override public void onDrawerSlide(@NonNull View drawerView, float slideOffset) { @@ -937,9 +942,15 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook TextView navigationHeaderTextView = findViewById(R.id.navigationText); TextView bookmarksHeaderTextView = findViewById(R.id.bookmarks_title_textview); - // Apply the calculated drawer paddings. This moves the text in the header below any cutouts. - navigationHeaderTextView.setPadding(drawerHeaderPaddingLeftAndRight, drawerHeaderPaddingTop, drawerHeaderPaddingLeftAndRight, drawerHeaderPaddingBottom); - bookmarksHeaderTextView.setPadding(drawerHeaderPaddingLeftAndRight, drawerHeaderPaddingTop, drawerHeaderPaddingLeftAndRight, drawerHeaderPaddingBottom); + // Apply the navigation header paddings if the view is not null (sometimes it is null if another activity has already started). This moves the text in the header below any cutouts. + if (navigationHeaderTextView != null) { + navigationHeaderTextView.setPadding(drawerHeaderPaddingLeftAndRight, drawerHeaderPaddingTop, drawerHeaderPaddingLeftAndRight, drawerHeaderPaddingBottom); + } + + // Apply the bookmarks header paddings if the view is not null (sometimes it is null if another activity has already started). This moves the text in the header below any cutouts. + if (bookmarksHeaderTextView != null) { + bookmarksHeaderTextView.setPadding(drawerHeaderPaddingLeftAndRight, drawerHeaderPaddingTop, drawerHeaderPaddingLeftAndRight, drawerHeaderPaddingBottom); + } // Update the back, forward, history, and requests menu items. navigationBackMenuItem.setEnabled(mainWebView.canGoBack()); @@ -3164,7 +3175,19 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); - // Reload the ad for the free flavor if we not in full screen mode. + // Get the status bar pixel size. + int statusBarResourceId = getResources().getIdentifier("status_bar_height", "dimen", "android"); + int statusBarPixelSize = getResources().getDimensionPixelSize(statusBarResourceId); + + // Get the resource density. + float screenDensity = getResources().getDisplayMetrics().density; + + // Recalculate the drawer header padding. + drawerHeaderPaddingLeftAndRight = (int) (15 * screenDensity); + drawerHeaderPaddingTop = statusBarPixelSize + (int) (4 * screenDensity); + drawerHeaderPaddingBottom = (int) (8 * screenDensity); + + // Reload the ad for the free flavor if not in full screen mode. if (BuildConfig.FLAVOR.contentEquals("free") && !inFullScreenBrowsingMode) { // Reload the ad. The AdView is destroyed and recreated, which changes the ID, every time it is reloaded to handle possible rotations. AdHelper.loadAd(findViewById(R.id.adview), getApplicationContext(), getString(R.string.ad_unit_id));