X-Git-Url: https://gitweb.stoutner.com/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacybrowser%2Factivities%2FMainWebViewActivity.java;h=1a77420d89b673938509a1a75335c53a492498cd;hb=e48f4376e2d4c86f76c60dc167df052170f2e5d0;hp=6e1189bb8736697e351d6616b6f81ac136823ca2;hpb=d9b68b83e414c8d02227b195e6398e8f92fe22c8;p=PrivacyBrowserAndroid.git 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 6e1189bb..1a77420d 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java +++ b/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java @@ -221,14 +221,11 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation // `translucentNavigationBarOnFullscreen` is used in `onCreate()` and `applyAppSettings()`. private boolean translucentNavigationBarOnFullscreen; - // `proxyThroughOrbot` is used in `onCreate()` and `applyAppSettings()`. - private boolean proxyThroughOrbot; - // `currentDomainName` is used in `onCreate(), `onNavigationItemSelected()`, and `applyDomainSettings()`. private String currentDomainName; - // `pendingUrl` is used in `onCreate()` and `applyAppSettings()`. - private static String pendingUrl; + // `waitingForOrbot` is used in `onCreate()` and `applyAppSettings()`. + private boolean waitingForOrbot; // `waitingForOrbotData` is used in `onCreate()` and `applyAppSettings()`. private String waitingForOrbotHTMLString; @@ -313,10 +310,10 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation // Set `waitingForOrbotHTMLString`. waitingForOrbotHTMLString = "

" + getString(R.string.waiting_for_orbot) + "

"; - // Initialize `currentDomainName`, `pendingUrl`, and `orbotStatus`. + // Initialize `currentDomainName`, `orbotStatus`, and `waitingForOrbot`. currentDomainName = ""; - pendingUrl = ""; orbotStatus = "unknown"; + waitingForOrbot = false; // Create an Orbot status `BroadcastReceiver`. BroadcastReceiver orbotStatusBroadcastReceiver = new BroadcastReceiver() { @@ -325,19 +322,10 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation // Store the content of the status message in `orbotStatus`. orbotStatus = intent.getStringExtra("org.torproject.android.intent.extra.STATUS"); - // If we are waiting on `pendingUrl`, load it now that Orbot is connected. - if (orbotStatus.equals("ON") && !pendingUrl.isEmpty()) { - - // Wait 500 milliseconds, because Orbot isn't really ready yet. - try { - Thread.sleep(500); - } catch (InterruptedException exception) { - // Do nothing. - } - - // Copy `pendingUrl` to `formattedUrlString` and reset `pendingUrl` to be empty. - formattedUrlString = pendingUrl; - pendingUrl = ""; + // If we are waiting on Orbot, load the website now that Orbot is connected. + if (orbotStatus.equals("ON") && waitingForOrbot) { + // Reset `waitingForOrbot`. + waitingForOrbot = false; // Load `formattedUrlString loadUrl(formattedUrlString); @@ -647,7 +635,7 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation webViewTitle = getString(R.string.no_title); // Check to see if we are waiting on Orbot. - if (pendingUrl.isEmpty()) { // We are not waiting on Orbot, so we need to process the URL. + if (!waitingForOrbot) { // We are not waiting on Orbot, so we need to process the URL. // We need to update `formattedUrlString` at the beginning of the load, so that if the user toggles JavaScript during the load the new website is reloaded. formattedUrlString = url; @@ -685,7 +673,7 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation } // Update `urlTextBox` and apply domain settings if not waiting on Orbot. - if (pendingUrl.isEmpty()) { // We are not waiting on Orbot, so we need to process the URL. + if (!waitingForOrbot) { // Check to see if `WebView` has set `url` to be `about:blank`. if (url.equals("about:blank")) { // `WebView` is blank, so `formattedUrlString` should be `""` and `urlTextBox` should display a hint. // Set `formattedUrlString` to `""`. @@ -879,9 +867,6 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation // Initialize `webViewTitle`. webViewTitle = getString(R.string.no_title); - // Apply the app settings from the shared preferences. - applyAppSettings(); - // Initialize `favoriteIconBitmap`. We have to use `ContextCompat` until API >= 21. Drawable favoriteIconDrawable = ContextCompat.getDrawable(getApplicationContext(), R.drawable.world); BitmapDrawable favoriteIconBitmapDrawable = (BitmapDrawable) favoriteIconDrawable; @@ -890,12 +875,15 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation // If the favorite icon is null, load the default. if (favoriteIconBitmap == null) { favoriteIconBitmap = favoriteIconDefaultBitmap; + } - // Load `formattedUrlString` if we are not proxying through Orbot and waiting for Orbot to connect. - if (!(proxyThroughOrbot && !orbotStatus.equals("ON"))) { + // Apply the app settings from the shared preferences. + applyAppSettings(); + + // Load `formattedUrlString` if we are not waiting for Orbot to connect. + if (!waitingForOrbot) { loadUrl(formattedUrlString); } - } } @@ -999,6 +987,11 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation // Prepare the font size title and current size menu item. switch (fontSize) { + case 25: + fontSizeTitle = getResources().getString(R.string.font_size) + " - " + getResources().getString(R.string.twenty_five_percent); + selectedFontSizeMenuItem = menu.findItem(R.id.fontSizeTwentyFivePercent); + break; + case 50: fontSizeTitle = getResources().getString(R.string.font_size) + " - " + getResources().getString(R.string.fifty_percent); selectedFontSizeMenuItem = menu.findItem(R.id.fontSizeFiftyPercent); @@ -1203,6 +1196,10 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation Snackbar.make(findViewById(R.id.main_webview), R.string.form_data_deleted, Snackbar.LENGTH_SHORT).show(); return true; + case R.id.fontSizeTwentyFivePercent: + mainWebView.getSettings().setTextZoom(25); + return true; + case R.id.fontSizeFiftyPercent: mainWebView.getSettings().setTextZoom(50); return true; @@ -1834,7 +1831,7 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation } @Override - public void onResume() { + public void onResume() { // `onResume()` also runs every time the app starts after `onCreate()` and `onStart()`. super.onResume(); // Resume JavaScript (if enabled). @@ -2146,7 +2143,7 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation adBlockerEnabled = sharedPreferences.getBoolean("block_ads", true); incognitoModeEnabled = sharedPreferences.getBoolean("incognito_mode", false); boolean doNotTrackEnabled = sharedPreferences.getBoolean("do_not_track", false); - proxyThroughOrbot = sharedPreferences.getBoolean("proxy_through_orbot", false); + boolean proxyThroughOrbot = sharedPreferences.getBoolean("proxy_through_orbot", false); fullScreenBrowsingModeEnabled = sharedPreferences.getBoolean("enable_full_screen_browsing_mode", false); hideSystemBarsOnFullscreen = sharedPreferences.getBoolean("hide_system_bars", false); translucentNavigationBarOnFullscreen = sharedPreferences.getBoolean("translucent_navigation_bar", true); @@ -2181,8 +2178,8 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation // Display a message to the user if we are waiting on Orbot. if (!orbotStatus.equals("ON")) { - // Save `formattedUrlString` in `pendingUrl`. - pendingUrl = formattedUrlString; + // Set `waitingForOrbot`. + waitingForOrbot = true; // Load a waiting page. `null` specifies no encoding, which defaults to ASCII. mainWebView.loadData(waitingForOrbotHTMLString, "text/html", null); @@ -2213,11 +2210,8 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation // Reset the proxy to default. The host is `""` and the port is `"0"`. OrbotProxyHelper.setProxy(getApplicationContext(), this, "", "0"); - // Reset `pendingUrl` if we are currently waiting for Orbot to connect. - if (!pendingUrl.isEmpty()) { - formattedUrlString = pendingUrl; - pendingUrl = ""; - } + // Reset `waitingForOrbot. + waitingForOrbot = false; } // Set swipe to refresh. @@ -2263,8 +2257,10 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation // Reset `inFullScreenBrowsingMode` to `false`. inFullScreenBrowsingMode = false; - // Show the `appBar`. - appBar.show(); + // Show the `appBar` if `findOnPageLinearLayout` is not visible. + if (findOnPageLinearLayout.getVisibility() == View.GONE) { + appBar.show(); + } // Show the `BannerAd` in the free flavor. if (BuildConfig.FLAVOR.contentEquals("free")) {