- // Initialize the foreground color spans for highlighting the URLs. We have to use the deprecated `getColor()` until API >= 23.
- redColorSpan = new ForegroundColorSpan(getResources().getColor(R.color.red_a700));
- initialGrayColorSpan = new ForegroundColorSpan(getResources().getColor(R.color.gray_500));
- finalGrayColorSpan = new ForegroundColorSpan(getResources().getColor(R.color.gray_500));
-
- // Get handles for the URL views.
- EditText urlEditText = findViewById(R.id.url_edittext);
-
- // Remove the formatting from `urlTextBar` when the user is editing the text.
- urlEditText.setOnFocusChangeListener((View v, boolean hasFocus) -> {
- if (hasFocus) { // The user is editing the URL text box.
- // Remove the highlighting.
- urlEditText.getText().removeSpan(redColorSpan);
- urlEditText.getText().removeSpan(initialGrayColorSpan);
- urlEditText.getText().removeSpan(finalGrayColorSpan);
- } else { // The user has stopped editing the URL text box.
- // Move to the beginning of the string.
- urlEditText.setSelection(0);
-
- // Reapply the highlighting.
- highlightUrlText();
- }
- });
-
- // Set the go button on the keyboard to load the URL in `urlTextBox`.
- urlEditText.setOnKeyListener((View v, int keyCode, KeyEvent event) -> {
- // If the event is a key-down event on the `enter` button, load the URL.
- if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
- // Load the URL into the mainWebView and consume the event.
- loadUrlFromTextBox();
-
- // If the enter key was pressed, consume the event.
- return true;
- } else {
- // If any other key was pressed, do not consume the event.
- return false;
- }
- });
-
- // Initialize the Orbot status and the waiting for Orbot trackers.
- orbotStatus = "unknown";
- waitingForOrbot = false;
-
- // Create an Orbot status `BroadcastReceiver`.
- orbotStatusBroadcastReceiver = new BroadcastReceiver() {
- @Override
- public void onReceive(Context context, Intent intent) {
- // Store the content of the status message in `orbotStatus`.
- orbotStatus = intent.getStringExtra("org.torproject.android.intent.extra.STATUS");
-
- // If Privacy Browser is waiting on Orbot, load the website now that Orbot is connected.
- if (orbotStatus.equals("ON") && waitingForOrbot) {
- // Reset the waiting for Orbot status.
- waitingForOrbot = false;
-
- // Get the intent that started the app.
- Intent launchingIntent = getIntent();
-
- // Get the information from the intent.
- String launchingIntentAction = launchingIntent.getAction();
- Uri launchingIntentUriData = launchingIntent.getData();
-
- // If the intent action is a web search, perform the search.
- if ((launchingIntentAction != null) && launchingIntentAction.equals(Intent.ACTION_WEB_SEARCH)) {
- // Create an encoded URL string.
- String encodedUrlString;
-
- // Sanitize the search input and convert it to a search.
- try {
- encodedUrlString = URLEncoder.encode(launchingIntent.getStringExtra(SearchManager.QUERY), "UTF-8");
- } catch (UnsupportedEncodingException exception) {
- encodedUrlString = "";
- }
-
- // Load the completed search URL.
- loadUrl(searchURL + encodedUrlString);
- } else if (launchingIntentUriData != null){ // Check to see if the intent contains a new URL.
- // Load the URL from the intent.
- loadUrl(launchingIntentUriData.toString());
- } else { // The is no URL in the intent.
- // Select the homepage based on the proxy through Orbot status.
- if (proxyThroughOrbot) {
- // Load the Tor homepage.
- loadUrl(sharedPreferences.getString("tor_homepage", getString(R.string.tor_homepage_default_value)));
- } else {
- // Load the normal homepage.
- loadUrl(sharedPreferences.getString("homepage", getString(R.string.homepage_default_value)));
- }
- }
- }
- }
- };
-
- // Register `orbotStatusBroadcastReceiver` on `this` context.
- this.registerReceiver(orbotStatusBroadcastReceiver, new IntentFilter("org.torproject.android.intent.action.STATUS"));
-
- // Get handles for views that need to be modified.
- DrawerLayout drawerLayout = findViewById(R.id.drawerlayout);
- NavigationView navigationView = findViewById(R.id.navigationview);
- TabLayout tabLayout = findViewById(R.id.tablayout);
- SwipeRefreshLayout swipeRefreshLayout = findViewById(R.id.swiperefreshlayout);
- ViewPager webViewPager = findViewById(R.id.webviewpager);
- ListView bookmarksListView = findViewById(R.id.bookmarks_drawer_listview);
- FloatingActionButton launchBookmarksActivityFab = findViewById(R.id.launch_bookmarks_activity_fab);
- FloatingActionButton createBookmarkFolderFab = findViewById(R.id.create_bookmark_folder_fab);
- FloatingActionButton createBookmarkFab = findViewById(R.id.create_bookmark_fab);
- EditText findOnPageEditText = findViewById(R.id.find_on_page_edittext);
-